Commit 5c04ad6b authored by Scott Duensing's avatar Scott Duensing

IIgs stencil blitting is working!

parent 436314f3
......@@ -25,15 +25,14 @@
case on
gen on
GlobalData data
ScTable ds 400 ; 400 bytes for 200 scanline offsets
StTable ds 50 ; 50 bytes for 25 stencil table offsets
MaTable ds 256 ; 4 bit stencil to mask word table
VblRate ds 2 ; Either 5 or 6 depending on PAL or NTSC.
VblTime ds 2 ; Integer Counter
end
;----------------------------------------
; Blit an 8x8 block to (almost) anywhere on a surface.
;----------------------------------------
......@@ -136,10 +135,9 @@ t equ 5 ; Temp
xc equ 7 ; X Counter
yc equ 9 ; Y Counter
stenO equ 11 ; Stencil Buffer Offset
stenB equ 13 ; Stencil Buffer Data - bits - two bytes, but we only use one
maskW equ 15 ; Actual mask bytes for pixels
stenB equ 13 ; Stencil bit pattern
jsubroutine (4:surface,4:tiles,4:stencil,2:sx,2:sy,2:tx,2:ty),16
jsubroutine (4:surface,4:tiles,4:stencil,2:sx,2:sy,2:tx,2:ty),14
using GlobalData
; Find offset into tile memory
......@@ -182,7 +180,6 @@ maskW equ 15 ; Actual mask bytes for pixels
adc sx ; Add x position to address offset
sta stenO ; Offset to start of mask data
lda #0 ; Load 0 into X and Y counters
sta xc
sta yc
......@@ -192,36 +189,23 @@ stenTop ldy stenO ; Load byte at stencil offset
xba ; Shift it into the high byte
sta stenB ; Put it in to the stencil byte
; Convert stencil byte to mask word (4 pixels)
blitTop ldx #4 ; How many pixels to process?
lda #$ffff ; Initially, the mask word is all one bits
sta maskW
nextNib lda stenB ; Load stencil byte into accumulator
asl a ; Shift first bit out of stencil byte into C
sta stenB ; Update stencil byte
bcc pixOn ; If C is clear, we draw the pixel (opposite of the mask data)
lda maskW ; Load mask word into accumulator
asl a ; Shift mask word over a pixel (4 bits)
asl a
asl a
asl a
; or #$0000 ; Do not draw pixel - mask it off
sta maskW ; Store updated mask word
jmp nextPix ; Start next pixel
pixOn lda maskW ; Load mask word into accumulator
asl a ; Shift mask word over a pixel (4 bits)
blitTop lda stenB ; Load stencil bit pattern
tax ; Copy to x
asl a ; Shift up a nibble for next time
asl a
asl a
asl a
ora #$000f ; Draw pixel
sta maskW ; Store updated mask word
nextPix dex ; Decrement pixel counter in X
bne nextNib ; Not zero? Do next nibble/pixel
sta stenB ; Save for next pass
txa ; Load original stencil byte back back
xba ; Flip what we want into LSB
and #$00f0 ; Mask off top nibble
lsr a ; Shift it down to low nibble but multiplied by 2
lsr a
lsr a
; lsr a
tay ; Put it in y
lda MaTable,y ; Load mask word
; Draw four pixels
lda maskW ; Load mask word
xba ; Flip MSB and LSB
ldy target ; Load Y register with target pixel offset
and [surface],y ; AND target pixels with mask word
ldy source ; Load Y register with source pixel offset
......@@ -368,15 +352,13 @@ drawTop phy ; Keep Y for later
end
;===============================================================================================
;
;----------------------------------------
; Arc3D line-drawing code
; By Andy McFadden
; Adapted from code by the FTA.
;
; Draws from (clpx0,clpy0) to (clpx1,clpy1) (output of a clipping routine).
;
;----------------------------------------
asmDrawLine start
x0 equ 1
......@@ -881,7 +863,6 @@ __o13 equ *-2
fx_done brl Exit
;
; common exit point
;
......@@ -1367,13 +1348,18 @@ StackPtr ds 2 ; Space for SP
; Builds a table of scanline offsets
;----------------------------------------
asmStart start
jsubroutine (2:id,2:hertz)
stenB equ 1 ; Stencil byte (only lower nibble is used)
stenC equ 3 ; Stencil byte counter
maskW equ 5 ; Mask word
jsubroutine (2:id,2:hertz),6
using GlobalData
ldy #0 ; Load 0 into y register
lda #0 ; Load 0 into accumulator
clc ; Clear carry flag
tScan anop
tScan anop ; Build scanline table
sta ScTable,y ; Store accumulator in ScTable+x
adc #160 ; Add 160 to accumulator (320 pixels / 2 pixels per byte)
iny ; Increment y
......@@ -1384,8 +1370,7 @@ tScan anop
ldy #0 ; Load 0 into y register
lda #0 ; Load 0 into accumulator
clc ; Clear carry flag
tSten anop
tSten anop ; Build stencil cell table
sta StTable,y ; Store accumulator in StencilTable+x
adc #320 ; Add 320 to accumulator (8 lines * 40 bytes)
iny ; Increment y
......@@ -1393,6 +1378,52 @@ tSten anop
cpy #50 ; Compare y to 50 (25 stencil cell offsets)
bcc tSten ; Repeat Stencil Table Loop until we do all 25 cells
; Convert stencil byte to mask word (4 pixels)
clc ; Clear carry flag
ldy #0 ; Load 0 into y register
lda #0 ; Stencil bits starting point
sta stenC
tMask ldx #4 ; How many pixels to process?
lda #$ffff ; Initially, the mask word is all one bits
sta maskW
lda stenC ; Put counter in bits
xba ; Swap MSB and LSB
asl a ; Shift mask word over a nibble
asl a
asl a
asl a
sta stenB
nextNib lda stenB ; Load stencil byte into accumulator
asl a ; Shift first bit out of stencil byte into C
sta stenB ; Update stencil byte
bcc pixOn ; If C is clear, we draw the pixel (opposite of the mask data)
lda maskW ; Load mask word into accumulator
asl a ; Shift mask word over a pixel (4 bits)
asl a
asl a
asl a
; or #$0000 ; Do not draw pixel - mask it off
sta maskW ; Store updated mask word
jmp nextPix ; Start next pixel
pixOn lda maskW ; Load mask word into accumulator
asl a ; Shift mask word over a pixel (4 bits)
asl a
asl a
asl a
ora #$000f ; Draw pixel
sta maskW ; Store updated mask word
nextPix dex ; Decrement pixel counter in X
bne nextNib ; Not zero? Do next nibble/pixel
xba ; Flip MSB and LSB
sta MaTable,y ; Store accumulator (maskW) in table
lda stenC ; Increment stencil bit pattern counter
inc a
sta stenC ; Store for the next pass
iny ; Increment y - two bytes
iny ; Increment y
cpy #256 ; Compare y to 512 (128 stencil patterns)
bcc tMask ; Repeat Mask Table Loop until we do all 128 bit patterns
lda hertz ; Store refresh rate / 10 in VblCount and VblRate
sta >VblRate
......
......@@ -132,3 +132,14 @@
.j
rtl
mend
MACRO
&lab jnibswap
asl a
adc #$80
rol a
asl a
adc #$80
rol a
mend
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment