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
; 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
; code, prelaunchers, transition effects, &c.
; (Wait/UnwaitForVBL, MockingboardStuff, MachineStatus)
@ -16,8 +16,8 @@
; LC RAM BANK 2
; D000..D3FF - ProRWTS data
; D400..D66F - ProRWTS code
; D670..DB95 - HGR font code & ProRWTS glue code
; DB96..DBA5 - backup of stack (during gameplay and self-running demos)
; D670..DB93 - HGR font code & ProRWTS glue code
; DB94..DBA3 - backup of stack (during gameplay and self-running demos)
; ...unused...
; DBB4..DBFF - (de)acceleration function
; DC00..DFFF - HGR font data
@ -148,8 +148,7 @@ CHEATS_ENABLED = %00001000
iCurBlockLo = $D401
iCurBlockHi = $D403
iProDOS_enter = $D670
LoadFileDirect = $DAF9
iAuxReq = $DB1F
LoadFileDirect = $DAF6
launchpatch = $D60E
iAddToPath = $FE78
itraverse = $D8D8

View File

@ -30,8 +30,7 @@ gGameToLaunch
;------------------------------------------------------------------------------
AnyGameSelected
+LD16 gGameToLaunch
+CMP16 $FFFF
bne ForceGoodResult
+CMP16_NE $FFFF, ForceGoodResult
rts ; CMP sets carry when equal
;------------------------------------------------------------------------------
@ -136,9 +135,9 @@ GetGameDisplayName
+ST16 SAVE
jsr okvs_get_current ; get value for this key
; (PTR) -> truncated game display name + info bitfield
ldy #0
; Y = 0
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 +
+LD16 PTR
clc

View File

@ -49,15 +49,8 @@
; gPathname clobbered
;------------------------------------------------------------------------------
LoadFile
+PARAMS_ON_STACK 6
+LDPARAM 1
jsr SetPath
+LDPARAM 3
jsr AddToPath
+LDPARAMPTR 5, ldrlo ; set load address
jsr SwitchToBank2
jsr LoadFileInternal
jmp SwitchToBank1
ldx #7
bne .loadcommon
;------------------------------------------------------------------------------
; LoadAuxFile
@ -74,16 +67,8 @@ LoadFile
; gPathname clobbered
;------------------------------------------------------------------------------
LoadAuxFile
+PARAMS_ON_STACK 6
+LDPARAM 1
jsr SetPath
+LDPARAM 3
jsr AddToPath
+LDPARAMPTR 5, ldrlo ; set load address
jsr SwitchToBank2
lda #1 ; request aux memory
jsr LoadFileAuxInternal
jmp SwitchToBank1
ldx #6
bne .loadcommon
;------------------------------------------------------------------------------
; LoadDHRFile
@ -102,13 +87,44 @@ LoadAuxFile
; stack set to next instruction after parameters
;------------------------------------------------------------------------------
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
jsr SetPath
+LDPARAM 3
jsr AddToPath
jsr SwitchToBank2
jsr LoadDHRFileInternal
plp
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
;------------------------------------------------------------------------------
@ -132,12 +148,8 @@ LoadDHRFile
;------------------------------------------------------------------------------
LoadIndexedFile
+PARAMS_ON_STACK 6
+LDPARAM 1
+ST16 @filename
+LDPARAM 3
+ST16 @address
+LDPARAM 5
+ST16 zpword
jsr @set_nameaddr
+LDPARAMPTR 5, zpword
inc $BF0E ; disable ROM mapping on return
ldx #2
ldy #0
@ -169,6 +181,19 @@ LoadIndexedFile
dec $BF0E ; re-enable ROM mapping on return
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
!byte 3
@filename

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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