With this article, I'd like to cover a ScreenMode that little known, yet fairly useful and fast for some kinds of effects. It can be seen in the Rotozoomer included in the Traschcan 3 diskmag intro.
This ScreenMode is actually a merger of 2 previous ScreenModes, the 1 bitplane chunky used in the World of Commodore demo by Sanity and the 6 bitplane chunky used in the Dawn intro by Artwork.
The first step is really simple, first the memory and screen configuration:
We want to have a way to easily plot 2 physical pixels in one operation -- this is doable using the following bit of code. Its working principle is to decompose the X coord into 2 parts, one to identify byte to modify (d0 in the example) and another for the bits inside the the byte (d2 in the example).
; d0 = x
; d1 = y
; a0 = start of screen area
plotpixel1:
lea plotpixel1_table,a1
muls.w #40,d1
add.l d1,a0 ; a0 = start of scanline
move.w d0,d2
and.w #3,d2 ; d2 = pixels to draw inside a byte, from 0 to 3
eor.w d2,d0
lsr.w #2,d0 ; d0 = byte offset inside scanline
move.b (a1,d2.w),d3
or.b d3,(a0,d0.w)
rts
plotpixel1_table:
dc.b $c0 ; bits = 11 00 00 00
dc.b $30 ; bits = 00 11 00 00
dc.b $0c ; bits = 00 00 11 00
dc.b $03 ; bits = 00 00 00 11
We have to do a more complex memory and screen configuration:
In this format, we will use 8 palette entries to simulate a 4 color screen, we get these combinations:
And finally, we need a more complex version of the routine above, so that it can plot the correct color at the correct place:
; d0 = x
; d1 = y
; d3 = color 0-3
; a0 = start of screen area
plotpixe2:
lea plotpixel2_table,a1
lea colorexpand,a2
muls.w #40,d1
add.l d1,a0 ; a0 = start of scanline
move.w d0,d2
and.w #3,d2 ; d2 = pixels to draw inside a byte, from 0 to 3
eor.w d2,d0
lsr.w #2,d0 ; d0 = byte offset inside scanline
move.b (a2,d3.w),d3 ; expand wanted color to all possible positions...
and.b (a1,d2.w),d3 ; ... and keep only the position we want to change.
or.b d3,(a0,d0.w)
rts
color_expand_table:
dc.b $00 ; bits = 00 00 00 00
dc.b $55 ; bits = 01 01 01 01
dc.b $aa ; bits = 10 10 10 10
dc.b $ff ; bits = 11 11 11 11
plotpixel2_table:
dc.b $c0 ; bits = 11 00 00 00
dc.b $30 ; bits = 00 11 00 00
dc.b $0c ; bits = 00 00 11 00
dc.b $03 ; bits = 00 00 00 11