fix some crashes, shave some bytes

This commit is contained in:
Peter Ferrie 2021-10-13 15:58:26 -07:00
parent e34993178d
commit 4332cce869
26 changed files with 144 additions and 91 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -7,7 +7,7 @@
; ;
; LC RAM BANK 1 ; LC RAM BANK 1
; D000..E789 - persistent data structures (gGlobalPrefsStore, gGamesListStore) ; D000..E789 - persistent data structures (gGlobalPrefsStore, gGamesListStore)
; E911..FFF1 - main program code ; E981..FFF1 - main program code
; FFF2..FFF9 - API functions and global constants available for main program ; FFF2..FFF9 - API functions and global constants available for main program
; code, prelaunchers, transition effects, &c. ; code, prelaunchers, transition effects, &c.
; (Wait/UnwaitForVBL, MockingboardStuff, MachineStatus) ; (Wait/UnwaitForVBL, MockingboardStuff, MachineStatus)
@ -16,8 +16,8 @@
; LC RAM BANK 2 ; LC RAM BANK 2
; D000..D3FF - ProRWTS data ; D000..D3FF - ProRWTS data
; D400..D66F - ProRWTS code ; D400..D66F - ProRWTS code
; D670..DB95 - HGR font code & ProRWTS glue code ; D670..DB93 - HGR font code & ProRWTS glue code
; DB96..DBA5 - backup of stack (during gameplay and self-running demos) ; DB94..DBA3 - backup of stack (during gameplay and self-running demos)
; ...unused... ; ...unused...
; DBB4..DBFF - (de)acceleration function ; DBB4..DBFF - (de)acceleration function
; DC00..DFFF - HGR font data ; DC00..DFFF - HGR font data
@ -148,8 +148,7 @@ CHEATS_ENABLED = %00001000
iCurBlockLo = $D401 iCurBlockLo = $D401
iCurBlockHi = $D403 iCurBlockHi = $D403
iProDOS_enter = $D670 iProDOS_enter = $D670
LoadFileDirect = $DAF9 LoadFileDirect = $DAF6
iAuxReq = $DB1F
launchpatch = $D60E launchpatch = $D60E
iAddToPath = $FE78 iAddToPath = $FE78
itraverse = $D8D8 itraverse = $D8D8

View File

@ -30,8 +30,7 @@ gGameToLaunch
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
AnyGameSelected AnyGameSelected
+LD16 gGameToLaunch +LD16 gGameToLaunch
+CMP16 $FFFF +CMP16_NE $FFFF, ForceGoodResult
bne ForceGoodResult
rts ; CMP sets carry when equal rts ; CMP sets carry when equal
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
@ -136,9 +135,9 @@ GetGameDisplayName
+ST16 SAVE +ST16 SAVE
jsr okvs_get_current ; get value for this key jsr okvs_get_current ; get value for this key
; (PTR) -> truncated game display name + info bitfield ; (PTR) -> truncated game display name + info bitfield
ldy #0 ; Y = 0
lda (PTR), y ; A = length of truncated game display name + info bitfield lda (PTR), y ; A = length of truncated game display name + info bitfield
cmp #1 ; 1 means there's no title, just info bitfield (1 byte) lsr ;;cmp #1 ; 1 means there's no title, just info bitfield (1 byte)
beq + beq +
+LD16 PTR +LD16 PTR
clc clc

View File

@ -49,15 +49,8 @@
; gPathname clobbered ; gPathname clobbered
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
LoadFile LoadFile
+PARAMS_ON_STACK 6 ldx #7
+LDPARAM 1 bne .loadcommon
jsr SetPath
+LDPARAM 3
jsr AddToPath
+LDPARAMPTR 5, ldrlo ; set load address
jsr SwitchToBank2
jsr LoadFileInternal
jmp SwitchToBank1
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; LoadAuxFile ; LoadAuxFile
@ -74,16 +67,8 @@ LoadFile
; gPathname clobbered ; gPathname clobbered
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
LoadAuxFile LoadAuxFile
+PARAMS_ON_STACK 6 ldx #6
+LDPARAM 1 bne .loadcommon
jsr SetPath
+LDPARAM 3
jsr AddToPath
+LDPARAMPTR 5, ldrlo ; set load address
jsr SwitchToBank2
lda #1 ; request aux memory
jsr LoadFileAuxInternal
jmp SwitchToBank1
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; LoadDHRFile ; LoadDHRFile
@ -102,13 +87,44 @@ LoadAuxFile
; stack set to next instruction after parameters ; stack set to next instruction after parameters
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
LoadDHRFile LoadDHRFile
+PARAMS_ON_STACK 4 ldx #$84
.loadcommon
pla
sta PARAM
txa
pha
and #6
clc
adc PARAM
tay
pla
tax
pla
sta PARAM+1
adc #0
pha
tya
pha
txa
pha
+LDPARAM 1 +LDPARAM 1
jsr SetPath jsr SetPath
+LDPARAM 3 +LDPARAM 3
jsr AddToPath jsr AddToPath
jsr SwitchToBank2 plp
jsr LoadDHRFileInternal php
bmi +
+LDPARAMPTR 5, ldrlo ; set load address
+ jsr SwitchToBank2
plp
bmi ++
bcc +
jsr LoadFileInternal
jmp SwitchToBank1
+ ldx #1 ; request aux memory
jsr LoadFileAuxInternal
jmp SwitchToBank1
++ jsr LoadDHRFileInternal
jmp SwitchToBank1 jmp SwitchToBank1
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
@ -132,12 +148,8 @@ LoadDHRFile
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
LoadIndexedFile LoadIndexedFile
+PARAMS_ON_STACK 6 +PARAMS_ON_STACK 6
+LDPARAM 1 jsr @set_nameaddr
+ST16 @filename +LDPARAMPTR 5, zpword
+LDPARAM 3
+ST16 @address
+LDPARAM 5
+ST16 zpword
inc $BF0E ; disable ROM mapping on return inc $BF0E ; disable ROM mapping on return
ldx #2 ldx #2
ldy #0 ldy #0
@ -169,6 +181,19 @@ LoadIndexedFile
dec $BF0E ; re-enable ROM mapping on return dec $BF0E ; re-enable ROM mapping on return
jmp SwitchToBank1 jmp SwitchToBank1
@set_nameaddr
ldx #0
ldy #1
jsr +
iny
ldx #@address - @filename
+ lda (PARAM), y
sta @filename, x
iny
lda (PARAM), y
sta @filename + 1, x
rts
@c8_parms @c8_parms
!byte 3 !byte 3
@filename @filename

View File

@ -8,25 +8,26 @@
; and parse.prefs which handle bank switching for you. ; and parse.prefs which handle bank switching for you.
LoadFileInternal LoadFileInternal
lda #0 ; 0 = read into main memory ldx #0 ; 0 = read into main memory
LoadFileAuxInternal LoadFileAuxInternal
sta @auxreq+1 ; call with A=1 to load directly into aux memory
+LDADDR gPathname +LDADDR gPathname
!if RELBASE != $2000 { !if RELBASE != $2000 {
!ifdef PASS2 { !ifdef PASS2 {
} else { ;PASS2 } else { ;PASS2
!if * != LoadFileDirect { !if * != LoadFileDirect {
!error "LoadFileDirect=",*, ", fix constants.a" !error "LoadFileDirect=",*, ", fix constants.a, rebuild all src/demo and src/prelaunch"
} }
} }
} }
+ST16 namlo ; set filename +ST16 namlo ; set filename
txa
pha
jsr traverse ; go to subdirectory, set up filename for read jsr traverse ; go to subdirectory, set up filename for read
lda #cmdread ; read (instead of write) lda #cmdread ; read (instead of write)
sta reqcmd sta reqcmd
lsr lsr
sta auxreq sta auxreq
lda ldrlo+1 lda ldrhi
bne + ; if caller provided a load address, use it bne + ; if caller provided a load address, use it
sta sizelo ; otherwise query the load address from file metadata sta sizelo ; otherwise query the load address from file metadata
sta sizehi ; 0 = query load address sta sizehi ; 0 = query load address
@ -35,16 +36,7 @@ LoadFileAuxInternal
+ST16 ldrlo +ST16 ldrlo
+ lda #$FF ; read entire file (ProRWTS2 will figure out exact size) + lda #$FF ; read entire file (ProRWTS2 will figure out exact size)
sta sizehi sta sizehi
!if RELBASE != $2000 { pla
!ifdef PASS2 {
} else { ;PASS2
!if *+1 != iAuxReq {
!error "iAuxReq=",*+1, ", fix constants.a"
}
}
}
@auxreq
lda #0
sta auxreq sta auxreq
JumpOpen JumpOpen
jmp hddopendir ; exit via ProRWTS2 jmp hddopendir ; exit via ProRWTS2

View File

@ -1,5 +1,5 @@
;license:MIT ;license:MIT
;(c) 2018-2020 by 4am ;(c) 2018-2021 by 4am & qkumba
; ;
; common assembler macros (6502 compatible) ; common assembler macros (6502 compatible)
; ;
@ -123,37 +123,51 @@
} }
; compare a 16-bit value in A (low) and Y (high) to an absolute address ; compare a 16-bit value in A (low) and Y (high) to an absolute address
; branch to target if no match
; zeroes A! ; zeroes A!
!macro CMP16ADDR .addr { !macro CMP16ADDR_NE .addr, .target {
eor .addr eor .addr
bne + bne .target
cpy .addr+1 cpy .addr+1
+ bne .target
} }
; compare a 16-bit value in X (low) and Y (high) to an absolute address ; compare a 16-bit value in X (low) and Y (high) to an absolute address
!macro CPX16ADDR .addr { ; branch to target if no match
!macro CPX16ADDR_NE .addr, .target {
cpx .addr cpx .addr
bne + bne .target
cpy .addr+1 cpy .addr+1
bne .target
}
; compare a 16-bit value in A (low) and Y (high) to an immediate value
; branch to target if match
!macro CMP16_E .val, .target {
cmp #<.val
bne +
cpy #>.val
beq .target
+ +
} }
; compare a 16-bit value in A (low) and Y (high) to an immediate value ; compare a 16-bit value in A (low) and Y (high) to an immediate value
!macro CMP16 .val { ; branch to target if no match
!macro CMP16_NE .val, .target {
cmp #<.val cmp #<.val
bne + bne .target
cpy #>.val cpy #>.val
+ bne .target
} }
; compare a 16-bit value in X (low) and Y (high) against zero ; compare a 16-bit value in X (low) and Y (high) against zero
; branch to target if not zero
; requires LDX16 immediately prior, since Y comparison is implicit! ; requires LDX16 immediately prior, since Y comparison is implicit!
; destroys A! ; destroys A!
!macro CPX16_0 { !macro CPX16_0_NE .target {
bne + bne .target
txa txa
+ bne .target
} }
!macro LBPL .target { !macro LBPL .target {
@ -377,15 +391,17 @@
; load an external file by pathname ; load an external file by pathname
; LC RAM 2 MUST BE BANKED IN ; LC RAM 2 MUST BE BANKED IN
; LOW BYTE OF .addr MUST BE $00 ; LOW BYTE OF .addr MUST BE $00
; set .addr to $0000 to load anywhere in main
!macro LOAD_FILE_AT .filepath, .addr { !macro LOAD_FILE_AT .filepath, .addr {
lda #0 !if .addr > 0 {
sta iAuxReq ; read to main memory
lda #>.addr lda #>.addr
sta ldrhi sta ldrhi
}
lda iCurBlockLo lda iCurBlockLo
pha pha
lda iCurBlockHi lda iCurBlockHi
pha pha
ldx #0 ; read to main memory
+LDADDR .filepath +LDADDR .filepath
jsr LoadFileDirect jsr LoadFileDirect
pla pla

View File

@ -319,8 +319,7 @@ okvs_next
+ +
jsr okvs_len jsr okvs_len
+LD16 WINDEX +LD16 WINDEX
+CMP16ADDR WCOUNT +CMP16ADDR_NE WCOUNT, +
bne +
sta WINDEX sta WINDEX
sta WINDEX+1 sta WINDEX+1
+ +
@ -444,8 +443,7 @@ okvs_iter_values
lda (PTR),y lda (PTR),y
beq @exit ; no keys, exit immediately beq @exit ; no keys, exit immediately
+ +
+LDPARAM 3 +LDPARAMPTR 3, @callback
+ST16 @callback
jsr incptr4 jsr incptr4
; PTR -> first record ; PTR -> first record
lda #0 lda #0
@ -510,6 +508,7 @@ okvs_iter_values
; internal functions ; internal functions
okvs_get_current okvs_get_current
; out: Y = 0
+ST16 PTR +ST16 PTR
jsr stepptr jsr stepptr
bne incptr bne incptr

View File

@ -31,7 +31,7 @@
ParseKeyValueList ParseKeyValueList
+PARAMS_ON_STACK 5 +PARAMS_ON_STACK 5
+LDPARAM 1 +LDPARAM 1 ; not LDPARAMPTR, SetKeyPtr requires A/Y!
+ST16 @store2 +ST16 @store2
jsr SetKeyPtr jsr SetKeyPtr
ldy #5 ldy #5

View File

@ -1,5 +1,5 @@
;license:MIT ;license:MIT
;(c) 2018-2020 by 4am ;(c) 2018-2021 by 4am & qkumba
; ;
; Parser for global preferences file ; Parser for global preferences file
; ;
@ -113,12 +113,11 @@ PREFRTS rts
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
pref_get pref_get
+PARAMS_ON_STACK 4 +PARAMS_ON_STACK 4
+LDPARAMPTR 1, + jsr .set_store01
+LDPARAMPTR 3, .store1
jsr okvs_get ; look up pref key in prefs store, sets PTR to value jsr okvs_get ; look up pref key in prefs store, sets PTR to value
!word gGlobalPrefsStore !word gGlobalPrefsStore
+ !word $FDFD ; SMC .store0 !word $FDFD ; SMC
bcs .useDefaultValue ; if pref key is not found, use default value bcs .useDefaultValue ; if pref key is not found, use default value
ldx .store1+1 ldx .store1+1
beq PREFRTS ; if no OKVS to validate against, we're done beq PREFRTS ; if no OKVS to validate against, we're done
@ -137,6 +136,24 @@ pref_get
+LD16 .store1 +LD16 .store1
jmp okvs_nth jmp okvs_nth
.set_store01
ldx #0
lda #.store1 - .store0
.set_store23
pha
ldy #1
jsr +
iny
pla
tax
+ lda (PARAM), y
sta .store0, x
iny
lda (PARAM), y
sta .store0 + 1, x
rts
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; pref_set ; pref_set
; set pref value by pref key, serialize prefs, and write them to disk ; set pref value by pref key, serialize prefs, and write them to disk
@ -152,13 +169,14 @@ pref_get
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
pref_set pref_set
+PARAMS_ON_STACK 4 +PARAMS_ON_STACK 4
+LDPARAMPTR 1, + ldx #.store2 - .store0
+LDPARAMPTR 3, ++ lda #.store3 - .store0
jsr .set_store23
jsr okvs_update ; save that in prefs store jsr okvs_update ; save that in prefs store
!word gGlobalPrefsStore !word gGlobalPrefsStore
+ !word $FDFD ; SMC .store2 !word $FDFD ; SMC
++ !word $FDFD ; SMC .store3 !word $FDFD ; SMC
+LDADDR kGlobalPrefsBuffer ; clear prefs buffer +LDADDR kGlobalPrefsBuffer ; clear prefs buffer
+ST16 $FE +ST16 $FE

View File

@ -106,7 +106,8 @@ MiniAttractMode
jsr okvs_nth ; get the next module on the list jsr okvs_nth ; get the next module on the list
+ST16 SAVE +ST16 SAVE
jsr okvs_get_current ; get module type jsr okvs_get_current ; get module type
ldy #1 ; Y = 0
iny
lda (PTR),y lda (PTR),y
tax ; X = module type tax ; X = module type
+LD16 SAVE ; A/Y = address of module name +LD16 SAVE ; A/Y = address of module name
@ -150,11 +151,10 @@ RunAttractModule
jsr FindGame jsr FindGame
bcs ATTRTS ; if game doesn't exist, skip the demo bcs ATTRTS ; if game doesn't exist, skip the demo
+LD16 WINDEX +LD16 WINDEX
+CMP16 $FFFF +CMP16_E $FFFF, @nogame
beq +
+ST16 gGameToLaunch ; if this demo corresponds to a game, save its index +ST16 gGameToLaunch ; if this demo corresponds to a game, save its index
; in case user presses RETURN during the demo (we will launch the game) ; in case user presses RETURN during the demo (we will launch the game)
+ @nogame
jsr ClearScreens ; avoid seeing code load into the HGR page jsr ClearScreens ; avoid seeing code load into the HGR page
; (clobbers $106, must do now before loading prelaunch code) ; (clobbers $106, must do now before loading prelaunch code)
@ -191,6 +191,9 @@ RunAttractModule
!word $800 !word $800
+ !word $FDFD ; SMC + !word $FDFD ; SMC
pla ; restore module type pla ; restore module type
+HIDE_NEXT_2_BYTES
@dispatchSingle
adc #(@singleslo-@slideshowslo)-1
- and #$0F ; convert ASCII digit to int - and #$0F ; convert ASCII digit to int
tax tax
@ -201,10 +204,6 @@ RunAttractModule
+LD16 @key ; pass in module name +LD16 @key ; pass in module name
@jmp jmp $FDFD ; SMC @jmp jmp $FDFD ; SMC
@dispatchSingle
adc #(@singleslo-@slideshowslo)-1
bne - ; always branches
@slideshowslo @slideshowslo
!byte <HGRTitleSlideshow !byte <HGRTitleSlideshow
!byte <HGRActionSlideshow !byte <HGRActionSlideshow

View File

@ -27,7 +27,7 @@ SHRSlideshow
jsr okvs_iter jsr okvs_iter
!word gSlideshowStore !word gSlideshowStore
!word SHRArtworkCallback !word SHRArtworkCallback
jmp BlankHGR beq jmpblank ; always taken
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; SHRSlideshow ; SHRSlideshow
@ -53,6 +53,7 @@ SHRSingle
jsr DecompressSHR jsr DecompressSHR
jsr LoadSHRTransition jsr LoadSHRTransition
jsr ExecuteTransitionAtA000AndWait jsr ExecuteTransitionAtA000AndWait
jmpblank
jmp BlankHGR jmp BlankHGR
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------

View File

@ -47,8 +47,10 @@ kBrowseQuit = 11
@noKeyMatch @noKeyMatch
jsr IsSearchKey jsr IsSearchKey
!if kBrowseSearch > 0 {
bne @BrowseDispatch bne @BrowseDispatch
ldx #kBrowseSearch ldx #kBrowseSearch
}
; execution falls through here ; execution falls through here
@BrowseDispatch @BrowseDispatch
@ -67,8 +69,7 @@ OnBrowseSearch
OnBrowsePrevious OnBrowsePrevious
+LDX16 gGameToLaunch +LDX16 gGameToLaunch
+CPX16_0 +CPX16_0_NE @notFirstGame
bne @notFirstGame
+LDX16 GameCount +LDX16 GameCount
@notFirstGame @notFirstGame
+DEX16 +DEX16
@ -77,8 +78,7 @@ OnBrowsePrevious
OnBrowseNext OnBrowseNext
+LDX16 gGameToLaunch +LDX16 gGameToLaunch
+INX16 +INX16
+CPX16ADDR GameCount +CPX16ADDR_NE GameCount, notLastGame
bne notLastGame
ldx #0 ldx #0
ldy #0 ldy #0
notLastGame notLastGame

View File

@ -113,6 +113,11 @@ cscript /nologo bin\changebootloader.js "build\%DISK%" build\proboothd
goto :EOF goto :EOF
) )
if "%1" equ "demo" (
for %%q in (src\demo\*) do %acme% %1
goto :EOF
)
echo usage: %0 clean / asm / dsk echo usage: %0 clean / asm / dsk
goto :EOF goto :EOF