Small initialization and jsr/jsl updates

This commit is contained in:
Lucas Scharenbroich 2021-08-26 16:12:08 -05:00
parent 4af66fa13a
commit 69c6104742
11 changed files with 146 additions and 232 deletions

View File

@ -17,8 +17,8 @@
tiledata ext tiledata ext
; Feature flags ; Feature flags
NO_INTERRUPTS equ 1 ; turn off for crossrunner debugging NO_INTERRUPTS equ 1 ; turn off for crossrunner debugging
NO_MUSIC equ 1 ; turn music + tool loading off NO_MUSIC equ 1 ; turn music + tool loading off
; Typical init ; Typical init
phk phk
@ -30,24 +30,25 @@ NO_MUSIC equ 1 ; turn music + tool loadi
jsl SetScreenMode jsl SetScreenMode
; Set up our level data ; Set up our level data
jsr BG0SetUp ; jsr BG0SetUp
jsr BG1SetUp ; jsr BG1SetUp
; Allocate room to load data ; Allocate room to load data
jsl AllocBank ; Alloc 64KB for Load/Unpack ; jsl AllocBank ; Alloc 64KB for Load/Unpack
sta BankLoad ; Store "Bank Pointer" ; sta BankLoad ; Store "Bank Pointer"
jsr MovePlayerToOrigin ; Put the player at the beginning of the map ; jsr MovePlayerToOrigin ; Put the player at the beginning of the map
lda #DIRTY_BIT_BG0_REFRESH ; Redraw all of the tiles on the next Render ; lda #DIRTY_BIT_BG0_REFRESH ; Redraw all of the tiles on the next Render
ora #DIRTY_BIT_BG1_REFRESH ; ora #DIRTY_BIT_BG1_REFRESH
tsb DirtyBits ; tsb DirtyBits
; lda #$FFFF
jsl Render jsl Render
EvtLoop EvtLoop
jsl ReadControl jsl ReadControl
and #$007F ; Ignore the buttons for now and #$007F ; Ignore the buttons for now
cmp #'q' cmp #'q'
bne :1 bne :1
@ -68,17 +69,17 @@ EvtLoop
jsr DumpBanks jsr DumpBanks
bra EvtLoop bra EvtLoop
:3 cmp #'f' ; render a 'f'rame :3 cmp #'f' ; render a 'f'rame
bne :4 bne :4
jsl Render jsl Render
bra EvtLoop bra EvtLoop
:4 cmp #'h' ; Show the 'h'eads up display :4 cmp #'h' ; Show the 'h'eads up display
bne :5 bne :5
jsr DoHUP jsr DoHUP
bra EvtLoop bra EvtLoop
:5 cmp #'1' ; User selects a new screen size :5 cmp #'1' ; User selects a new screen size
bcc :6 bcc :6
cmp #'9'+1 cmp #'9'+1
bcs :6 bcs :6
@ -86,7 +87,7 @@ EvtLoop
sbc #'1' sbc #'1'
tax tax
jsl SetScreenMode jsl SetScreenMode
jsr MovePlayerToOrigin ; jsr MovePlayerToOrigin
brl EvtLoop brl EvtLoop
:6 cmp #'t' :6 cmp #'t'
@ -94,7 +95,7 @@ EvtLoop
jsr DoTiles jsr DoTiles
brl EvtLoop brl EvtLoop
:7 cmp #$15 ; left = $08, right = $15, up = $0B, down = $0A :7 cmp #$15 ; left = $08, right = $15, up = $0B, down = $0A
bne :8 bne :8
lda #1 lda #1
jsr MoveRight jsr MoveRight
@ -150,13 +151,13 @@ StartMusic
pea #MusicFile pea #MusicFile
_NTPLoadOneMusic _NTPLoadOneMusic
pea $0001 ; loop pea $0001 ; loop
_NTPPlayMusic _NTPPlayMusic
rts rts
; Position the screen with the botom-left corner of the tilemap visible ; Position the screen with the botom-left corner of the tilemap visible
MovePlayerToOrigin MovePlayerToOrigin
lda #0 ; Set the player's position lda #0 ; Set the player's position
jsl SetBG0XPos jsl SetBG0XPos
lda #0 lda #0
jsl SetBG1XPos jsl SetBG1XPos
@ -198,8 +199,8 @@ DoHUP
ldx #{160-12*4} ldx #{160-12*4}
ldy #$7777 ldy #$7777
jsr DrawString jsr DrawString
lda OneSecondCounter ; Number of elapsed seconds lda OneSecondCounter ; Number of elapsed seconds
ldx #{160-4*4} ; Render the word 4 charaters from right edge ldx #{160-4*4} ; Render the word 4 charaters from right edge
jsr DrawWord jsr DrawWord
lda #TicksStr lda #TicksStr
@ -220,7 +221,7 @@ DoTiles
:column equ 3 :column equ 3
:tile equ 5 :tile equ 5
pea $0000 ; Allocate local variable space pea $0000 ; Allocate local variable space
pea $0000 pea $0000
pea $0000 pea $0000
@ -250,7 +251,7 @@ DoTiles
cmp #26 cmp #26
bcc :rowloop bcc :rowloop
pla ; restore the stack pla ; restore the stack
pla pla
pla pla
rts rts
@ -264,7 +265,7 @@ DoLoadBG1
ldx BankLoad ldx BankLoad
lda #0 lda #0
ldy BG1DataBank ldy BG1DataBank
jsr CopyBinToBG1 jsl CopyBinToBG1
lda BankLoad lda BankLoad
ldx #BG1AltDataFile ldx #BG1AltDataFile
@ -273,7 +274,7 @@ DoLoadBG1
ldx BankLoad ldx BankLoad
lda #0 lda #0
ldy BG1AltBank ldy BG1AltBank
jsr CopyBinToBG1 jsl CopyBinToBG1
rts rts
@ -283,18 +284,18 @@ DoLoadFG
ldx #FGName ldx #FGName
jsr LoadFile jsr LoadFile
ldx BankLoad ; Copy it into the code field ldx BankLoad ; Copy it into the code field
lda #0 lda #0
jsr CopyBinToField jsl CopyBinToField
rts rts
; Load a simple picture format onto the SHR screen ; Load a simple picture format onto the SHR screen
DoLoadPic DoLoadPic
lda BankLoad lda BankLoad
ldx #ImageName ; Load+Unpack Boot Picture ldx #ImageName ; Load+Unpack Boot Picture
jsr LoadPicture ; X=Name, A=Bank to use for loading jsr LoadPicture ; X=Name, A=Bank to use for loading
ldx BankLoad ; Copy it into the code field ldx BankLoad ; Copy it into the code field
lda #0 lda #0
jsl CopyPicToField jsl CopyPicToField
rts rts
@ -335,43 +336,43 @@ DefaultPalette dw $0E51,$0EDB,$0000,$068F,$0BF1,$00A0,$0EEE,$0777,$
; Graphics helpers ; Graphics helpers
LoadPicture LoadPicture
jsr LoadFile ; X=Nom Image, A=Banc de chargement XX/00 jsr LoadFile ; X=Nom Image, A=Banc de chargement XX/00
bcc :loadOK bcc :loadOK
rts rts
:loadOK :loadOK
jsr UnpackPicture ; A=Packed Size jsr UnpackPicture ; A=Packed Size
rts rts
UnpackPicture sta UP_PackedSize ; Size of Packed Data UnpackPicture sta UP_PackedSize ; Size of Packed Data
lda #$8000 ; Size of output Data Buffer lda #$8000 ; Size of output Data Buffer
sta UP_UnPackedSize sta UP_UnPackedSize
lda BankLoad ; Banc de chargement / Decompression lda BankLoad ; Banc de chargement / Decompression
sta UP_Packed+1 ; Packed Data sta UP_Packed+1 ; Packed Data
clc clc
adc #$0080 adc #$0080
stz UP_UnPacked ; On remet a zero car modifie par l'appel stz UP_UnPacked ; On remet a zero car modifie par l'appel
stz UP_UnPacked+2 stz UP_UnPacked+2
sta UP_UnPacked+1 ; Unpacked Data buffer sta UP_UnPacked+1 ; Unpacked Data buffer
PushWord #0 ; Space for Result : Number of bytes unpacked PushWord #0 ; Space for Result : Number of bytes unpacked
PushLong UP_Packed ; Pointer to buffer containing the packed data PushLong UP_Packed ; Pointer to buffer containing the packed data
PushWord UP_PackedSize ; Size of the Packed Data PushWord UP_PackedSize ; Size of the Packed Data
PushLong #UP_UnPacked ; Pointer to Pointer to unpacked buffer PushLong #UP_UnPacked ; Pointer to Pointer to unpacked buffer
PushLong #UP_UnPackedSize ; Pointer to a Word containing size of unpacked data PushLong #UP_UnPackedSize ; Pointer to a Word containing size of unpacked data
_UnPackBytes _UnPackBytes
pla ; Number of byte unpacked pla ; Number of byte unpacked
rts rts
UP_Packed hex 00000000 ; Address of Packed Data UP_Packed hex 00000000 ; Address of Packed Data
UP_PackedSize hex 0000 ; Size of Packed Data UP_PackedSize hex 0000 ; Size of Packed Data
UP_UnPacked hex 00000000 ; Address of Unpacked Data Buffer (modified) UP_UnPacked hex 00000000 ; Address of Unpacked Data Buffer (modified)
UP_UnPackedSize hex 0000 ; Size of Unpacked Data Buffer (modified) UP_UnPackedSize hex 0000 ; Size of Unpacked Data Buffer (modified)
; Basic I/O function to load files ; Basic I/O function to load files
LoadFile LoadFile
stx openRec+4 ; X=File, A=Bank (high word) assumed zero for low stx openRec+4 ; X=File, A=Bank (high word) assumed zero for low
stz readRec+4 stz readRec+4
sta readRec+6 sta readRec+6
jsr ClearBankLoad jsr ClearBankLoad
@ -393,7 +394,7 @@ LoadFile
:closeFile _CloseGS closeRec :closeFile _CloseGS closeRec
clc clc
lda eofRec+4 ; File Size lda eofRec+4 ; File Size
rts rts
:openReadErr jsr :closeFile :openReadErr jsr :closeFile
@ -426,22 +427,22 @@ BG1AltDataFile strl '1/bg1b.bin'
ImageName strl '1/test.pic' ImageName strl '1/test.pic'
FGName strl '1/fg1.bin' FGName strl '1/fg1.bin'
openRec dw 2 ; pCount openRec dw 2 ; pCount
ds 2 ; refNum ds 2 ; refNum
adrl FGName ; pathname adrl FGName ; pathname
eofRec dw 2 ; pCount eofRec dw 2 ; pCount
ds 2 ; refNum ds 2 ; refNum
ds 4 ; eof ds 4 ; eof
readRec dw 4 ; pCount readRec dw 4 ; pCount
ds 2 ; refNum ds 2 ; refNum
ds 4 ; dataBuffer ds 4 ; dataBuffer
ds 4 ; requestCount ds 4 ; requestCount
ds 4 ; transferCount ds 4 ; transferCount
closeRec dw 1 ; pCount closeRec dw 1 ; pCount
ds 2 ; refNum ds 2 ; refNum
qtRec adrl $0000 qtRec adrl $0000
da $00 da $00
@ -453,36 +454,3 @@ qtRec adrl $0000
PUT App.TileMapBG0.s PUT App.TileMapBG0.s
PUT App.TileMapBG1.s PUT App.TileMapBG1.s

View File

@ -45,9 +45,15 @@ EngineStartUp ENT
rtl rtl
EngineShutDown ENT EngineShutDown ENT
phb
phk
plb
jsr IntShutDown jsr IntShutDown
jsr SoundShutDown jsr SoundShutDown
jsr ToolShutDown jsr ToolShutDown
plb
rtl rtl
ToolStartUp ToolStartUp
@ -221,6 +227,11 @@ EngineReset
stz TileMapPtr stz TileMapPtr
stz TileMapPtr+2 stz TileMapPtr+2
stz BG1TileMapWidth
stz BG1TileMapHeight
stz BG1TileMapPtr
stz BG1TileMapPtr+2
stz OneSecondCounter stz OneSecondCounter
]step equ 0 ]step equ 0

View File

@ -108,13 +108,3 @@ DIRTY_BIT_BG1_X equ $0004
DIRTY_BIT_BG1_Y equ $0008 DIRTY_BIT_BG1_Y equ $0008
DIRTY_BIT_BG0_REFRESH equ $0010 DIRTY_BIT_BG0_REFRESH equ $0010
DIRTY_BIT_BG1_REFRESH equ $0020 DIRTY_BIT_BG1_REFRESH equ $0020

View File

@ -121,7 +121,3 @@ WaitForVBL sep #$20
bpl :wait2 ; spin until transition into VBL bpl :wait2 ; spin until transition into VBL
rep #$20 rep #$20
rts rts

View File

@ -84,8 +84,6 @@ _Render
jsr _ApplyBG0XPos ; Patch the PEA instructions with exit BRA opcode jsr _ApplyBG0XPos ; Patch the PEA instructions with exit BRA opcode
jsr _ApplyBG1XPos ; Patch the PEA instructions with exit BRA opcode jsr _ApplyBG1XPos ; Patch the PEA instructions with exit BRA opcode
; Copy any tiles that have come into view
; The code fields are locked in now and reder to be rendered ; The code fields are locked in now and reder to be rendered
jsr ShadowOff jsr ShadowOff
@ -126,31 +124,3 @@ _Render
stz DirtyBits stz DirtyBits
rts rts

View File

@ -49,6 +49,12 @@ _UpdateBG0TileMap
:BlkX equ tmp12 :BlkX equ tmp12
:BlkY equ tmp13 :BlkY equ tmp13
lda TileMapPtr ; Do nothing if no data is set
ora TileMapPtr+2
bne :valid
rts
:valid
lda StartY ; calculate the tile index of the current location lda StartY ; calculate the tile index of the current location
lsr lsr
lsr lsr
@ -390,6 +396,12 @@ _UpdateBG1TileMap
:Top equ tmp2 :Top equ tmp2
:Bottom equ tmp3 :Bottom equ tmp3
lda BG1TileMapPtr ; Do nothing if no data is set
ora BG1TileMapPtr+2
bne :valid
rts
:valid
lda BG1StartY ; calculate the tile index of the current location lda BG1StartY ; calculate the tile index of the current location
lsr lsr
lsr lsr
@ -648,19 +660,3 @@ _DrawRectBG1
pla pla
rts rts

View File

@ -62,6 +62,7 @@ InitTimers
; A = timer slot ID if C = 0 ; A = timer slot ID if C = 0
AddTimer ENT AddTimer ENT
phb phb
php ; Save the input parameters php ; Save the input parameters
phx phx
pha pha
@ -135,6 +136,7 @@ RemoveTimer ENT
:exit :exit
plb plb
rtl rtl
; Execute the timer functions ; Execute the timer functions
DoTimers ENT DoTimers ENT
phb phb
@ -241,5 +243,6 @@ _DoTimers

View File

@ -1,7 +1,7 @@
; Support routinges for the primary background ; Support routinges for the primary background
_InitBG0 _InitBG0
jsr _ApplyBG0YPos lda #DIRTY_BIT_BG0_X+DIRTY_BIT_BG0_Y
jsr _ApplyBG0XPos tsb DirtyBits
rts rts
; Copy a raw data file into the code field ; Copy a raw data file into the code field
@ -53,7 +53,7 @@ _CopyBinToField
stz :line_cnt stz :line_cnt
:rloop :rloop
lda :line_cnt ; get the pointer to the code field line lda :line_cnt ; get the pointer to the code field line
asl asl
tax tax
@ -63,90 +63,88 @@ _CopyBinToField
sta :dstptr+2 sta :dstptr+2
; ldx #162 ; move backwards in the code field ; ldx #162 ; move backwards in the code field
ldy #0 ; move forward in the image data ldy #0 ; move forward in the image data
lda #82 ; keep a running column count lda #82 ; keep a running column count
sta :col_cnt sta :col_cnt
:cloop :cloop
phy phy
lda [:srcptr],y ; load the picture data lda [:srcptr],y ; load the picture data
cmp :mask_color cmp :mask_color
beq :transparent ; a value of $0000 is transparent beq :transparent ; a value of $0000 is transparent
jsr :toMask ; Infer a mask value for this. If it's $0000, then jsr :toMask ; Infer a mask value for this. If it's $0000, then
cmp #$0000 cmp #$0000
bne :mixed ; the data is solid, otherwise mixed bne :mixed ; the data is solid, otherwise mixed
; This is a solid word ; This is a solid word
:solid :solid
lda [:srcptr],y lda [:srcptr],y
pha ; Save the data pha ; Save the data
lda Col2CodeOffset,y ; Get the offset to the code from the line start lda Col2CodeOffset,y ; Get the offset to the code from the line start
tay tay
lda #$00F4 ; PEA instruction lda #$00F4 ; PEA instruction
sta [:dstptr],y sta [:dstptr],y
iny iny
pla pla
sta [:dstptr],y ; PEA operand sta [:dstptr],y ; PEA operand
bra :next bra :next
:transparent :transparent
lda :mask_color ; Make sure we actually have to mask lda :mask_color ; Make sure we actually have to mask
cmp #$A5A5 cmp #$A5A5
beq :solid beq :solid
lda Col2CodeOffset,y ; Get the offset to the code from the line start lda Col2CodeOffset,y ; Get the offset to the code from the line start
tay tay
lda #$B1 ; LDA (dp),y lda #$B1 ; LDA (dp),y
sta [:dstptr],y sta [:dstptr],y
iny iny
lda 1,s ; load the saved Y-index lda 1,s ; load the saved Y-index
ora #$4800 ; put a PHA after the offset ora #$4800 ; put a PHA after the offset
sta [:dstptr],y sta [:dstptr],y
bra :next bra :next
:mixed :mixed
sta :mask ; Save the mask sta :mask ; Save the mask
lda [:srcptr],y ; Refetch the screen data lda [:srcptr],y ; Refetch the screen data
sta :data sta :data
tyx tyx
lda Col2CodeOffset,y ; Get the offset into the code field lda Col2CodeOffset,y ; Get the offset into the code field
tay tay
lda #$4C ; JMP exception lda #$4C ; JMP exception
sta [:dstptr],y sta [:dstptr],y
iny iny
lda JTableOffset,x ; Get the address offset and add to the base address lda JTableOffset,x ; Get the address offset and add to the base address
clc clc
adc :dstptr adc :dstptr
sta [:dstptr],y sta [:dstptr],y
ldy JTableOffset,x ; This points to the code fragment ldy JTableOffset,x ; This points to the code fragment
lda 1,s ; load the offset lda 1,s ; load the offset
xba xba
ora #$00B1 ora #$00B1
sta [:dstptr],y ; write the LDA (--),y instruction sta [:dstptr],y ; write the LDA (--),y instruction
iny iny
iny iny
iny ; advance to the AND #imm operand iny ; advance to the AND #imm operand
lda :mask lda :mask
sta [:dstptr],y sta [:dstptr],y
iny iny
iny iny
iny ; advance to the ORA #imm operand iny ; advance to the ORA #imm operand
lda :mask lda :mask
eor #$FFFF ; invert the mask to clear up the data eor #$FFFF ; invert the mask to clear up the data
and :data and :data
sta [:dstptr],y sta [:dstptr],y
:next :next
ply ply
; dex
; dex
iny iny
iny iny
@ -167,10 +165,10 @@ _CopyBinToField
:exit :exit
rts rts
:toMask pha ; save original :toMask pha ; save original
lda 1,s lda 1,s
eor :mask_color ; only identical bits produce zero eor :mask_color ; only identical bits produce zero
and #$F000 and #$F000
beq *+7 beq *+7
pea #$0000 pea #$0000
@ -212,7 +210,7 @@ _CopyBinToField
sta 1,s sta 1,s
pla pla
sta 1,s ; pop the saved word sta 1,s ; pop the saved word
pla pla
rts rts
@ -245,7 +243,7 @@ _CopyPicToField
stz :line_cnt stz :line_cnt
:rloop :rloop
lda :line_cnt ; get the pointer to the code field line lda :line_cnt ; get the pointer to the code field line
asl asl
tax tax
@ -255,76 +253,76 @@ _CopyPicToField
sta :dstptr+2 sta :dstptr+2
; ldx #162 ; move backwards in the code field ; ldx #162 ; move backwards in the code field
ldy #0 ; move forward in the image data ldy #0 ; move forward in the image data
lda #80 ; keep a running column count lda #80 ; keep a running column count
; lda #82 ; keep a running column count ; lda #82 ; keep a running column count
sta :col_cnt sta :col_cnt
:cloop :cloop
phy phy
lda [:srcptr],y ; load the picture data lda [:srcptr],y ; load the picture data
beq :transparent ; a value of $0000 is transparent beq :transparent ; a value of $0000 is transparent
jsr :toMask ; Infer a mask value for this. If it's $0000, then jsr :toMask ; Infer a mask value for this. If it's $0000, then
bne :mixed ; the data is solid, otherwise mixed bne :mixed ; the data is solid, otherwise mixed
; This is a solid word ; This is a solid word
lda [:srcptr],y lda [:srcptr],y
pha ; Save the data pha ; Save the data
lda Col2CodeOffset,y ; Get the offset to the code from the line start lda Col2CodeOffset,y ; Get the offset to the code from the line start
tay tay
lda #$00F4 ; PEA instruction lda #$00F4 ; PEA instruction
sta [:dstptr],y sta [:dstptr],y
iny iny
pla pla
sta [:dstptr],y ; PEA operand sta [:dstptr],y ; PEA operand
bra :next bra :next
:transparent :transparent
lda Col2CodeOffset,y ; Get the offset to the code from the line start lda Col2CodeOffset,y ; Get the offset to the code from the line start
tay tay
lda #$B1 ; LDA (dp),y lda #$B1 ; LDA (dp),y
sta [:dstptr],y sta [:dstptr],y
iny iny
lda 1,s ; load the saved Y-index lda 1,s ; load the saved Y-index
ora #$4800 ; put a PHA after the offset ora #$4800 ; put a PHA after the offset
sta [:dstptr],y sta [:dstptr],y
bra :next bra :next
:mixed :mixed
sta :mask ; Save the mask sta :mask ; Save the mask
lda [:srcptr],y ; Refetch the screen data lda [:srcptr],y ; Refetch the screen data
sta :data sta :data
tyx tyx
lda Col2CodeOffset,y ; Get the offset into the code field lda Col2CodeOffset,y ; Get the offset into the code field
tay tay
lda #$4C ; JMP exception lda #$4C ; JMP exception
sta [:dstptr],y sta [:dstptr],y
iny iny
lda JTableOffset,x ; Get the address offset and add to the base address lda JTableOffset,x ; Get the address offset and add to the base address
clc clc
adc :dstptr adc :dstptr
sta [:dstptr],y sta [:dstptr],y
ldy JTableOffset,x ; This points to the code fragment ldy JTableOffset,x ; This points to the code fragment
lda 1,s ; load the offset lda 1,s ; load the offset
xba xba
ora #$00B1 ora #$00B1
sta [:dstptr],y ; write the LDA (--),y instruction sta [:dstptr],y ; write the LDA (--),y instruction
iny iny
iny iny
iny ; advance to the AND #imm operand iny ; advance to the AND #imm operand
lda :mask lda :mask
sta [:dstptr],y sta [:dstptr],y
iny iny
iny iny
iny ; advance to the ORA #imm operand iny ; advance to the ORA #imm operand
lda :data lda :data
sta [:dstptr],y sta [:dstptr],y
@ -379,8 +377,3 @@ _CopyPicToField
bra *+5 bra *+5
ora #$000F ora #$000F
rts rts

View File

@ -95,4 +95,3 @@ stk_save lda #0000 ; load the stack
; we don't do anything sprite related; just call function pointers provided to us. ; we don't do anything sprite related; just call function pointers provided to us.
_RenderSprites _RenderSprites
rts rts

View File

@ -345,7 +345,6 @@ _ApplyBG0XPos
; Special note, the SaveOpcode function stores the opcode *within* the code field as it is ; Special note, the SaveOpcode function stores the opcode *within* the code field as it is
; used in odd-aligned cases to determine how to draw the 8-bit value on the left edge of the ; used in odd-aligned cases to determine how to draw the 8-bit value on the left edge of the
; screen ; screen
; y is already set to :base_address ; y is already set to :base_address
tax ; :draw_count_x2 tax ; :draw_count_x2
lda :exit_address ; Save from this location lda :exit_address ; Save from this location

View File

@ -637,14 +637,3 @@ snippets lup 82
]index equ ]index+1 ]index equ ]index+1
--^ --^
top top