Fix table initialization and bank preservateion in _BltRange

This commit is contained in:
Lucas Scharenbroich 2021-07-10 15:38:42 -05:00
parent cd9eeaf899
commit ab9a2682db
4 changed files with 98 additions and 64 deletions

View File

@ -4,7 +4,7 @@
; ;
; * 13 banks of memory for the blitter ; * 13 banks of memory for the blitter
; * 1 bank of memory for the second background ; * 1 bank of memory for the second background
; * 1 bank of memory for the second background mask ; * 1 bank of memory for the second background alt/mask
; ;
; * $01/2000 - $01/9FFF for the shadow screen ; * $01/2000 - $01/9FFF for the shadow screen
; * $00/2000 - $00/9FFF for the fixed background ; * $00/2000 - $00/9FFF for the fixed background
@ -16,38 +16,38 @@
mx %00 mx %00
MemInit PushLong #0 ; space for result MemInit PushLong #0 ; space for result
PushLong #$008000 ; size (32k) PushLong #$008000 ; size (32k)
PushWord UserId PushWord UserId
PushWord #%11000000_00010111 ; Fixed location PushWord #%11000000_00010111 ; Fixed location
PushLong #$002000 PushLong #$002000
_NewHandle ; returns LONG Handle on stack _NewHandle ; returns LONG Handle on stack
plx ; base address of the new handle plx ; base address of the new handle
pla ; high address 00XX of the new handle (bank) pla ; high address 00XX of the new handle (bank)
_Deref _Deref
stx Buff00 stx Buff00
sta Buff00+2 sta Buff00+2
PushLong #0 ; space for result PushLong #0 ; space for result
PushLong #$008000 ; size (32k) PushLong #$008000 ; size (32k)
PushWord UserId PushWord UserId
PushWord #%11000000_00010111 ; Fixed location PushWord #%11000000_00010111 ; Fixed location
PushLong #$012000 PushLong #$012000
_NewHandle ; returns LONG Handle on stack _NewHandle ; returns LONG Handle on stack
plx ; base address of the new handle plx ; base address of the new handle
pla ; high address 00XX of the new handle (bank) pla ; high address 00XX of the new handle (bank)
_Deref _Deref
stx Buff01 stx Buff01
sta Buff01+2 sta Buff01+2
PushLong #0 ; space for result PushLong #0 ; space for result
PushLong #$000A00 ; size (10 pages) PushLong #$000A00 ; size (10 pages)
PushWord UserId PushWord UserId
PushWord #%11000000_00010101 ; Page-aligned, fixed bank PushWord #%11000000_00010101 ; Page-aligned, fixed bank
PushLong #$000000 PushLong #$000000
_NewHandle ; returns LONG Handle on stack _NewHandle ; returns LONG Handle on stack
plx ; base address of the new handle plx ; base address of the new handle
pla ; high address 00XX of the new handle (bank) pla ; high address 00XX of the new handle (bank)
_Deref _Deref
stx ZeroPage stx ZeroPage
sta ZeroPage+2 sta ZeroPage+2
@ -61,27 +61,42 @@ MemInit PushLong #0 ; space for result
]step equ ]step+4 ]step equ ]step+4
--^ --^
; Fill in a tables with the adddress of all 208 scanlines across all 13 banks
ldx #0 ldx #0
ldy #0 ldy #0
lda BlitBuff+2,y ; Copy the high word first :bloop
lda BlitBuff+2,y ; Copy the high word first
]step equ 0 ]step equ 0
lup 16 lup 16
sta BTableHigh+]step+2,x ; 16 lines per bank sta BTableHigh+]step,x ; 16 lines per bank
sta BTableHigh+]step+2+{208*2},x ; 16 lines per bank sta BTableHigh+]step+{208*2},x ; 16 lines per bank
]step equ ]step+4 ]step equ ]step+2
--^ --^
lda BlitBuff,y lda BlitBuff,y
sta BTableLow,x sta BTableLow,x
sta BTableLow+{208*2},x sta BTableLow+{208*2},x
clc clc
]step equ 0 ]step equ 2
lup 15 lup 15
adc #$1000 adc #$1000
sta BTableLow+]step,x sta BTableLow+]step,x
sta BTableLow+]step+{208*2},x sta BTableLow+]step+{208*2},x
]step equ ]step+4 ]step equ ]step+2
--^ --^
txa
adc #16*2 ; move to the next chunk of BTableHigh and BTableLow
tax
tya
adc #4 ; move to the next bank address
tay
cmp #4*13
bcs :exit
brl :bloop
:exit
rts rts
Buff00 ds 4 Buff00 ds 4
@ -95,12 +110,12 @@ AllocOneBank PushLong #0
PushWord UserId PushWord UserId
PushWord #%11000000_00011100 PushWord #%11000000_00011100
PushLong #0 PushLong #0
_NewHandle ; returns LONG Handle on stack _NewHandle ; returns LONG Handle on stack
plx ; base address of the new handle plx ; base address of the new handle
pla ; high address 00XX of the new handle (bank) pla ; high address 00XX of the new handle (bank)
xba ; swap accumulator bytes to XX00 xba ; swap accumulator bytes to XX00
sta :bank+2 ; store as bank for next op (overwrite $XX00) sta :bank+2 ; store as bank for next op (overwrite $XX00)
:bank ldal $000001,X ; recover the bank address in A=XX/00 :bank ldal $000001,X ; recover the bank address in A=XX/00
rts rts
; Variation that return pointer in the X/A registers (X = low, A = high) ; Variation that return pointer in the X/A registers (X = low, A = high)
@ -110,8 +125,8 @@ AllocOneBank2 PushLong #0
PushWord #%11000000_00011100 PushWord #%11000000_00011100
PushLong #0 PushLong #0
_NewHandle _NewHandle
plx ; base address of the new handle plx ; base address of the new handle
pla ; high address 00XX of the new handle (bank) pla ; high address 00XX of the new handle (bank)
_Deref _Deref
rts rts
@ -163,6 +178,14 @@ ShutDown rts

View File

@ -63,20 +63,20 @@ tiledata ext
; one-second timer is generally just used for counters and as a handy ; one-second timer is generally just used for counters and as a handy
; frames-per-second trigger. ; frames-per-second trigger.
PushLong #0 ; PushLong #0
pea $0015 ; Get the existing 1-second interrupt handler and save ; pea $0015 ; Get the existing 1-second interrupt handler and save
_GetVector ; _GetVector
PullLong OldOneSecVec ; PullLong OldOneSecVec
;
pea $0015 ; Set the new handler and enable interrupts ; pea $0015 ; Set the new handler and enable interrupts
PushLong #OneSecHandler ; PushLong #OneSecHandler
_SetVector ; _SetVector
;
pea $0006 ; pea $0006
_IntSource ; _IntSource
;
PushLong #VBLTASK ; Also register a Heart Beat Task ; PushLong #VBLTASK ; Also register a Heart Beat Task
_SetHeartBeat ; _SetHeartBeat
; Start up the graphics engine... ; Start up the graphics engine...
@ -84,9 +84,12 @@ tiledata ext
jsr BlitInit ; Initialize the memory jsr BlitInit ; Initialize the memory
jsr GrafInit ; Initialize the graphics screen jsr GrafInit ; Initialize the graphics screen
ldx #6 ; Gameboy Advance size ldx #9 ; Special debug size
jsr SetScreenMode jsr SetScreenMode
; ldx #6 ; Gameboy Advance size
; jsr SetScreenMode
; Load a picture and copy it into Bank $E1. Then turn on the screen. ; Load a picture and copy it into Bank $E1. Then turn on the screen.
jsr AllocOneBank ; Alloc 64KB for Load/Unpack jsr AllocOneBank ; Alloc 64KB for Load/Unpack
@ -134,15 +137,15 @@ EvtLoop
; Exit code ; Exit code
Exit Exit
pea $0007 ; disable 1-second interrupts ; pea $0007 ; disable 1-second interrupts
_IntSource ; _IntSource
;
PushLong #VBLTASK ; Remove our heartbeat task ; PushLong #VBLTASK ; Remove our heartbeat task
_DelHeartBeat ; _DelHeartBeat
;
pea $0015 ; pea $0015
PushLong OldOneSecVec ; Reset the interrupt vector ; PushLong OldOneSecVec ; Reset the interrupt vector
_SetVector ; _SetVector
PushWord UserId ; Deallocate all of our memory PushWord UserId ; Deallocate all of our memory
_DisposeAll _DisposeAll
@ -163,15 +166,15 @@ Fatal brk $00
; 7. Game Boy Advanced : 30 x 20 240 x 160 (19,200 bytes ( 60.0%)) ; 7. Game Boy Advanced : 30 x 20 240 x 160 (19,200 bytes ( 60.0%))
; 8. Ancient Land of Y's : 36 x 16 288 x 128 (18,432 bytes ( 57.6%)) ; 8. Ancient Land of Y's : 36 x 16 288 x 128 (18,432 bytes ( 57.6%))
; 9. Game Boy Color : 20 x 18 160 x 144 (11,520 bytes ( 36.0%)) ; 9. Game Boy Color : 20 x 18 160 x 144 (11,520 bytes ( 36.0%))
; ; 10. DEBUG : 40 x 1 320 x 1
; X=mode number ; X=mode number
]ScreenModeWidth dw 320,272,256,256,280,256,240,288,160 ]ScreenModeWidth dw 320,272,256,256,280,256,240,288,160,320
]ScreenModeHeight dw 200,192,200,176,160,160,160,128,144 ]ScreenModeHeight dw 200,192,200,176,160,160,160,128,144,1
SetScreenMode cpx #8 SetScreenMode cpx #9
bcc :rangeOk bcc :rangeOk
ldx #8 ldx #9
:rangeOk txa :rangeOk txa
asl asl
@ -279,7 +282,6 @@ DoFrame
jsr SetBG0XPos jsr SetBG0XPos
jsr Render ; Render the play field jsr Render ; Render the play field
rts rts
; Load a simple picture format onto the SHR screen ; Load a simple picture format onto the SHR screen
@ -632,6 +634,10 @@ qtRec adrl $0000

View File

@ -13,6 +13,7 @@ _BltRange
:exit_ptr equ tmp0 :exit_ptr equ tmp0
:jmp_low_save equ tmp2 :jmp_low_save equ tmp2
phb ; preserve the bank register
clc` clc`
dey dey
@ -81,5 +82,8 @@ stk_save lda #0000 ; load the stack
sta [:exit_ptr],y sta [:exit_ptr],y
rep #$20 rep #$20
plb ; restore the bank
rts rts

View File

@ -32,7 +32,7 @@ SetBG0XPos
; performed in order. ; performed in order.
; ;
; Experimental -- this is a parameterized version that does not rely on direct page ; Experimental -- this is a parameterized version that does not rely on direct page
; state variabled for input and attempts to be more optimized. ; state variables for input and attempts to be more optimized.
; ;
; A = starting virtual line in the code field (0 - 207) ; A = starting virtual line in the code field (0 - 207)
; X = number of lines to render (0 - 200) ; X = number of lines to render (0 - 200)
@ -533,5 +533,6 @@ SetCodeEntry