a bit smaller, a bit faster

This commit is contained in:
Peter Ferrie 2019-09-23 17:01:42 -07:00
parent 3a6cd6a258
commit 8798b5becf
10 changed files with 398 additions and 414 deletions

View File

@ -9,7 +9,7 @@
; D000..E5F4 - persistent data structures (per-game cheat categories,
; gGlobalPrefsStore, gGamesListStore)
; ...unused...
; EC77..FFF9 - main program code
; EC85..FFF9 - main program code
; FFFA..FFFF - NMI, reset, IRQ vectors
;
; LC RAM BANK 2

View File

@ -96,21 +96,19 @@ gGameToLaunch=*+1
ldx gGameToLaunch
ldy gCheatsAvailable,x ; are there any cheats for this game?
beq @noCheats
bne @Cheats
@noCheats
lda #<kStandardPrelaunch ; no game-specific prelaunch file, so
sta @pfile
lda #>kStandardPrelaunch ; load standard prelaunch file instead
sta @pfile+1
@Cheats
jsr LoadFile ; cheats are enabled and this game has a prelaunch
!word kPrelaunchDirectory ; file that will set up the cheats, so load that
@pfile !word $FDFD ; SMC
!word $0106
jmp @loadedPrelaunch
@noCheats
jsr LoadFile ; no game-specific prelaunch file, so
!word kPrelaunchDirectory ; load standard prelaunch file instead
!word kStandardPrelaunch
!word $0106
@loadedPrelaunch
ldx #1 ; construct path to game's startup file
sec ; which is always /X/game/game
!byte $2c

View File

@ -133,14 +133,13 @@ okvs_append
sta (PTR),y ; increment number of keys
iny
lda (PTR),y ; get address of next free space
pha
tax
iny
lda (PTR),y
sta PTR+1
sta SAVE+1
pla
sta PTR
sta SAVE
stx PTR
stx SAVE
; PTR -> new record
; SAVE -> new record
jsr incptr2
@ -149,10 +148,9 @@ okvs_append
+STAY SRC ; SRC -> new key to copy
ldy #0
lda (SRC),y
clc
adc #1
sta KEYLEN
tay
iny
sty KEYLEN
- dey ; copy new key
lda (SRC),y
sta (PTR),y
@ -170,13 +168,12 @@ okvs_append
+STAY SRC ; SRC -> new value to copy
ldy #7
lda (PARAM),y ; get max length of value
bne +
ldy #0
lda (SRC),y ; no max, use actual length instead
clc
adc #1
+ sta VALUELEN
tay
bne +
lda (SRC),y ; no max, use actual length instead
tay
iny
+ sty VALUELEN
- dey
lda (SRC),y
sta (PTR),y
@ -203,12 +200,11 @@ okvs_append
tax ; X = new OKVS length
jsr GetStoreAddress
; PTR -> store
ldy #1
lda SRC
ldy #2
- lda SRC-1,y
sta (PTR),y ; update next-free-space pointer in head
iny
lda SRC+1
sta (PTR),y
dey
bne -
rts
;------------------------------------------------------------------------------
@ -307,9 +303,9 @@ okvs_next
inx
stx SAVE
jsr okvs_len
cmp SAVE
eor SAVE
bne +
ldx #$00
tax
+
+LDAY PARAM
; execution falls through here
@ -331,14 +327,14 @@ okvs_nth
jsr incptr3
; PTR -> first record
txa
pha
beq @found
pha
- jsr derefptr
dex
bne -
@found jsr incptr2
pla
tax
@found jsr incptr2
+LDAY PTR
rts
@ -462,10 +458,8 @@ okvs_iter_values
incptr3 jsr incptr
incptr2 jsr incptr
incptr
; preserves A and X
ldy PTR
iny
sty PTR
; preserves A, X, and Y
inc PTR
bne +
inc PTR+1
+ rts

View File

@ -33,35 +33,23 @@ ParseKeyValueList
+LDPARAM 1
+STAY @store2
jsr okvs_init ; reset key/value store
+LDPARAM 3
+STAY $FE
jsr SetKeyPtr
ldy #5
lda (PARAM),y
sta @maxLength
ldy #0
lda ($FE),y
pha
iny
lda ($FE),y
tay
pla
sec
sbc #$01
sta $FE
bcs +
dey
+ sty $FF
ldy #$00 ; index into ($FE) pointing to current character
@newkey ldx #$00 ; X = index into current key
stx gValLen ; initialize value length (in case this line has no value)
beq @emptyline ; always branches
@skipLine ; skip to CR
jsr IncAndGetChar
cmp #$0D ; CR
bne @skipLine
@emptyline
jsr IncAndGetChar
cmp #$0D ; CR in first position (blank line) -> no key
beq @newkey
beq @emptyline
cmp #$23 ; '#' starts a comment -> no key, skip to CR
beq @skipLine
cmp #$5B ; '[' ends the parsing
@ -105,11 +93,31 @@ ParseKeyValueList
clc
bcc @newkey ; always branches
@skipLine ; skip to CR
jsr IncAndGetChar
cmp #$0D ; CR
bne @skipLine
beq @newkey ; always branches
;------------------------------------------------------------------------------
; SetKeyPtr
;
; in: PARAM set
; out: okvs initialised
; ($FE) -> buffer
;------------------------------------------------------------------------------
SetKeyPtr
jsr okvs_init ; reset key/value store
+LDPARAM 3
+STAY $FE
ldy #1
lda ($FE),y
tax
dey
lda ($FE),y
bne +
dex
stx $FF
+ tax
dex
stx $FE
rts
;------------------------------------------------------------------------------
; IncAndGetChar

View File

@ -29,30 +29,19 @@ ParseGamesList
+LDPARAM 1
+STAY @store2
jsr okvs_init ; reset key/value store
+LDPARAM 3
+STAY $FE
ldy #0
lda ($FE),y
pha
iny
lda ($FE),y
tay
pla
sec
sbc #$01
sta $FE
bcs +
dey
+ sty $FF
jsr SetKeyPtr
ldy #$00 ; index into ($FE) pointing to current character
beq @newkey ; always branches
@skipLine ; skip to CR
jsr IncAndGetChar
cmp #$0D ; CR
bne @skipLine
@newkey ldx #$00 ; X = index into current key
@emptyline
jsr IncAndGetChar ; get first filter character ('1' if game requires joystick)
cmp #$0D ; ignore blank line
beq @newkey
beq @emptyline
cmp #$5B ; '[' ends the parsing
beq @exit
cmp #$30 ; '0' -> no filtering on joystick
@ -109,10 +98,4 @@ ParseGamesList
clc
bcc @newkey ; always branches
@skipLine ; skip to CR
jsr IncAndGetChar
cmp #$0D ; CR
bne @skipLine
beq @newkey ; always branches
@exit rts

View File

@ -167,23 +167,25 @@ pref_set
@addString
+STAY $00
ldx #0
ldy #0
lda ($00),y
beq ++
clc
adc #$01
sta MAX
beq +
tax
inx
stx MAX
iny
- lda ($00),y
sta ($FE,x)
+ iny
inc $FE
sta ($FE),y
iny
cpy MAX
bne -
tya
clc
adc $FE
sta $FE
bne +
inc $FF
+ cpy MAX
bne -
++ rts
+ rts
@kEquals !byte 1
!raw "="

View File

@ -19,333 +19,333 @@ buffer = first_zp+2 ;word
ProDOS_enter
!set CloseHandles = @imp_close
stx ProDOS_savedX+1
sty ProDOS_savedY+1
jsr @swap_zp
pla
tay
pla
sta @fetchaddr+1
pla
sta @fetchaddr+2
jsr @fetchbyte
sta @request+1
jsr @fetchbyte
sta packet
jsr @fetchbyte
sta packet+1
lda @fetchaddr+2
pha
lda @fetchaddr+1
pha
tya
pha
stx ProDOS_savedX+1
sty ProDOS_savedY+1
jsr @swap_zp
pla
tay
pla
sta @fetchaddr+1
pla
sta @fetchaddr+2
jsr @fetchbyte
sta @request+1
jsr @fetchbyte
sta packet
jsr @fetchbyte
sta packet+1
lda @fetchaddr+2
pha
lda @fetchaddr+1
pha
tya
pha
@request
lda #$d1
cmp #$80
beq @do_readblock
cmp #$81
beq @do_writeblock
cmp #$c4
beq @do_getattrib
cmp #$c6
beq @do_nothing
cmp #$c7
beq @do_prefix
cmp #$c8
beq @do_open
cmp #$ca
beq @do_read
cmp #$cb
beq @do_write
cmp #$cc
beq @do_close
cmp #$ce
beq @do_seek
cmp #$d1
;;bne @do_fatal
lda #$d1
cmp #$80
beq @do_readblock
cmp #$81
beq @do_writeblock
cmp #$c4
beq @do_getattrib
cmp #$c6
beq @do_nothing
cmp #$c7
beq @do_prefix
cmp #$c8
beq @do_open
cmp #$ca
beq @do_read
cmp #$cb
beq @do_write
cmp #$cc
beq @do_close
cmp #$ce
beq @do_seek
cmp #$d1
;; bne @do_fatal
@do_eof
jmp @imp_eof
jmp @imp_eof
@do_readblock
@do_writeblock
jmp @imp_rdwrblock
jmp @imp_rdwrblock
@do_getattrib
jmp @imp_getattrib
jmp @imp_getattrib
@do_nothing
jmp @restore_zp
jmp @restore_zp
@do_prefix
jmp @imp_prefix
jmp @imp_prefix
@do_open
jmp @imp_open
jmp @imp_open
@do_read
jmp @imp_read
jmp @imp_read
@do_write
jmp @imp_write
jmp @imp_write
@do_close
jsr @imp_close ;subroutine special case because of dual-use
jmp @restore_zp
jsr @imp_close ;subroutine special case because of dual-use
jmp @restore_zp
@do_seek
jmp @imp_seek
jmp @imp_seek
@do_fatal
;;jmp ProDOS_fatal
;; jmp ProDOS_fatal
@imp_rdwrblock
and #$7f
tay
iny
sty @rdwrop+1
ldx #$44
ldy #2
jsr @setbuffer
iny
lda (packet), y
tax
iny
lda (packet), y
and #$7f
tay
iny
sty @rdwrop+1
ldx #$44
ldy #2
jsr @setbuffer
iny
lda (packet), y
tax
iny
lda (packet), y
@rdwrop
ldy #$d1 ; SMC
jsr hddseekrd+2
bcc @jmp_zp2 ;always
ldy #$d1 ; SMC
jsr hddseekrd+2
bcc @jmp_zp2 ;always
@imp_getattrib
lda packet+1
pha
lda packet
pha
ldx #namlo
jsr @setbuffer1
lda #$60
sta attribpatch
jsr hddopendir
lda #$10
sta attribpatch
pla
sta packet
pla
sta packet+1
ldy #5
lda ldrlo2
sta (packet), y
iny
lda ldrlo2+1
sta (packet), y
ldy #$13
lda (bloklo), y
tax
iny
lda (bloklo), y
ldy #9
sta (packet), y
txa
dey
sta (packet), y
lda packet+1
pha
lda packet
pha
ldx #namlo
jsr @setbuffer1
lda #$60
sta attribpatch
jsr hddopendir
lda #$10
sta attribpatch
pla
sta packet
pla
sta packet+1
ldy #5
lda ldrlo2
sta (packet), y
iny
lda ldrlo2+1
sta (packet), y
ldy #$13
lda (bloklo), y
tax
iny
lda (bloklo), y
ldy #9
sta (packet), y
txa
dey
sta (packet), y
@jmp_zp2
jmp @restore_zp
jmp @restore_zp
@imp_prefix
ldx #buffer
jsr @setbuffer1
ldy ProDOS_prefix
iny
iny
tya
pha
dey
ldx #buffer
jsr @setbuffer1
ldy ProDOS_prefix
iny
iny
tya
pha
dey
@copy_prefix
lda ProDOS_prefix, y
iny
sta (buffer), y
dey
dey
bne @copy_prefix
pla
sta (buffer), y
lda #'/'
iny
sta (buffer), y
bne @jmp_zp2
lda ProDOS_prefix, y
iny
sta (buffer), y
dey
dey
bne @copy_prefix
pla
sta (buffer), y
lda #'/'
iny
sta (buffer), y
bne @jmp_zp2
@imp_open
ldx #namlo
jsr @setbuffer1
iny
inc @handles+1
ldx #namlo
jsr @setbuffer1
iny
inc @handles+1
@handles
ldx #0
iny
lda (packet), y
sta @handle-1, x
jsr @patch_buffer
iny
lda #1
sta (packet), y
lda #0
sta reqcmd
sta sizehi
sta sizelo
jsr hddopendir
lda #0
sta blkidx
beq @jmp_zp ;always
ldx #0
iny
lda (packet), y
sta @handle-1, x
jsr @patch_buffer
iny
lda #1
sta (packet), y
lda #0
sta reqcmd
sta sizehi
sta sizelo
jsr hddopendir
lda #0
sta blkidx
beq @jmp_zp ;always
@imp_seek
jsr @set_rdwrbuff
lda #0
sta blkidx
sta blkofflo
sta blkoffhi
sta reqcmd
jsr @reset
ldx sizelo
beq @seek64
sta sizehi
sta sizelo
jsr @seekreset
inc ldrlo
bne @seek64
inc ldrhi
jsr @set_rdwrbuff
lda #0
sta blkidx
sta blkofflo
sta blkoffhi
sta reqcmd
jsr @reset
ldx sizelo
beq @seek64
sta sizehi
sta sizelo
jsr @seekreset
inc ldrlo
bne @seek64
inc ldrhi
@seek64
lda ldrhi
sta sizehi
lda ldrlo
sta sizelo
jsr @seekreset
lda ldrhi
ora ldrlo
bne @jmp_zp
dec blkidx
beq @jmp_zp ;always
lda ldrhi
sta sizehi
lda ldrlo
sta sizelo
jsr @seekreset
lda ldrhi
ora ldrlo
bne @jmp_zp
dec blkidx
beq @jmp_zp ;always
@seekreset
jsr hddrdwrpart
jsr hddrdwrpart
@reset
lda #$ff
sta blefthi
sta bleftlo
rts
lda #$ff
sta blefthi
sta bleftlo
rts
@imp_read
clc
clc
@imp_write
php
lda #cmdread
adc #0
sta reqcmd
jsr @set_rdwrbuff
plp
bcc @skip_align
lda sizelo
adc #$fe
lda sizehi
adc #1
and #$fe
sta sizehi
lda bleftlo
adc #$ff
lda blefthi
adc #1
and #$fe
sta blefthi
php
lda #cmdread
adc #0
sta reqcmd
jsr @set_rdwrbuff
plp
bcc @skip_align
lda sizelo
adc #$fe
lda sizehi
adc #1
and #$fe
sta sizehi
lda bleftlo
adc #$ff
lda blefthi
adc #1
and #$fe
sta blefthi
@skip_align
jsr hddrdwrpart
ldy #6
lda sizelo2
sta (packet), y
iny
lda sizehi2
sta (packet), y
jsr hddrdwrpart
ldy #6
lda sizelo2
sta (packet), y
iny
lda sizehi2
sta (packet), y
@jmp_zp
jmp @restore_zp
jmp @restore_zp
@imp_eof
ldy #2
lda bleftlo
sta (packet), y
iny
lda blefthi
sta (packet), y
bcs @restore_zp ;always
ldy #2
lda bleftlo
sta (packet), y
iny
lda blefthi
sta (packet), y
bcs @restore_zp ;always
@imp_close
lda @handles+1
beq @close_ret
dec @handles+1
bne @close_ret
lda #>hddencbuf
lda @handles+1
beq @close_ret
dec @handles+1
bne @close_ret
lda #>hddencbuf
@patch_buffer
sta encbufpatch1+1
sta encbufpatch2+1
tax
inx
stx dirbufpatch1+1
inx
stx dirbufpatch2+2
stx dirbufpatch3+2
stx dirbufpatch4+2
stx dirbufpatch6+1
stx dirbufpatch7+2
stx dirbufpatch9+2
stx dirbufpatch10+1
inx
stx dirbufpatch5+2
stx dirbufpatch8+2
sta encbufpatch1+1
sta encbufpatch2+1
tax
inx
stx dirbufpatch1+1
inx
stx dirbufpatch2+2
stx dirbufpatch3+2
stx dirbufpatch4+2
stx dirbufpatch6+1
stx dirbufpatch7+2
stx dirbufpatch9+2
stx dirbufpatch10+1
inx
stx dirbufpatch5+2
stx dirbufpatch8+2
@close_ret
rts
rts
@fetchbyte
inc @fetchaddr+1
bne @fetchaddr
inc @fetchaddr+2
inc @fetchaddr+1
bne @fetchaddr
inc @fetchaddr+2
@fetchaddr
lda $d1d1
rts
lda $d1d1
rts
@set_rdwrbuff
ldy #1
lda (packet), y
tax
lda @handle-1, x
jsr @patch_buffer
ldx #ldrlo
iny
jsr @setbuffer
ldx #sizelo
iny
!byte $2c
ldy #1
lda (packet), y
tax
lda @handle-1, x
jsr @patch_buffer
ldx #ldrlo
iny
jsr @setbuffer
ldx #sizelo
iny
!byte $2c
@setbuffer1
ldy #1
ldy #1
@setbuffer
lda (packet), y
sta $0,x
iny
lda (packet), y
sta $1,x
rts
lda (packet), y
sta $0,x
iny
lda (packet), y
sta $1,x
rts
@swap_zp
ldx #last_zp-first_zp
ldx #last_zp-first_zp
@save_zp
lda first_zp,x
ldy @saved_zp,x
sta @saved_zp,x
sty first_zp,x
dex
bpl @save_zp
rts
lda first_zp,x
ldy @saved_zp,x
sta @saved_zp,x
sty first_zp,x
dex
bpl @save_zp
rts
@restore_zp
jsr @swap_zp
jmp ProDOS_exit
jsr @swap_zp
jmp ProDOS_exit
@handle
!byte 0, 0 ;only up to two handles at a time
!byte 0, 0 ;only up to two handles at a time
@saved_zp
!fill (last_zp - first_zp) + 1
!fill (last_zp - first_zp) + 1
;------------------------------------------------------------------------------
; traverse [private]
@ -477,55 +477,55 @@ promote
!pseudopc $bf00 {
php
sei
bit $c083
!byte $24
bit $c083
!byte $24
!if * != $bf06 {
!error "$BF06 misplaced (",*,")"
}
rts ;clock interface, must be RTS on real ProDOS if program uses $20x
bit $c083
jmp ProDOS_enter
bit $c083
jmp ProDOS_enter
ProDOS_exit
ProDOS_savedX
ldx #$d1
ldx #$d1
plp
clc
bcc ProDOS_savedY
bcc ProDOS_savedY
!if * != $bf13 {
!error "$BF13 misplaced (",*,")"
}
!byte $c1
!word $c2d1, $c3d1, $c4d1, $c5d1, $c6d1, $c7d1
ProDOS_savedY
ldy #$d1
sta $c082
lda #0
ldy #$d1
sta $c082
lda #0
rts
!if * > $bf30 {
!error "$BF30 misplaced (",*,")"
} else {
!if * != $bf30 {
!fill $bf30-*
!fill $bf30-*
}
}
ProDOS_unit
!byte $d1
!byte $d1
ProDOS_fatal ;only for debugging, will be removed
;; bit $c081
;; pha
;; jsr $fe89
;; jsr $fe93
;; pla
;; jsr $fdda
;; jmp $ff65
;; bit $c081
;; pha
;; jsr $fe89
;; jsr $fe93
;; pla
;; jsr $fdda
;; jmp $ff65
;;*=$bf58
;; !fill $18 ;filled by init instead
;; !fill $18 ;filled by init instead
ProDOS_prefix=$bfd0
; !fill $2e
; !fill $2e
}
end_promote
@ -541,32 +541,32 @@ end_promote
;------------------------------------------------------------------------------
SaveOrRestoreScreenHoles
lda #4
sta namhi
ldx #0
stx namlo
sta bloklo
-- ldy #$78
- lda (namlo),y
pha
lda holey_stuff,x
lda #4
sta namhi
ldx #0
stx namlo
sta bloklo
-- ldy #$78
- lda (namlo),y
pha
lda holey_stuff,x
holepatch ;sta->lda
lda (namlo),y
pla
sta holey_stuff,x
inx
tya
eor #$80
tay
bmi -
iny
bpl -
inc namhi
dec bloklo
bne --
rts
lda (namlo),y
pla
sta holey_stuff,x
inx
tya
eor #$80
tay
bmi -
iny
bpl -
inc namhi
dec bloklo
bne --
rts
holey_stuff
!fill 64
!fill 64
LoadFileInternal
+LDADDR gPathname

View File

@ -119,13 +119,13 @@ kRootDirectory=*+1
; execution falls through here
AddToPath
+STAY PTR
ldx gPathname ; current pathname length
ldy #0
lda (PTR),y ; length of this segment
beq @done
tay
iny
sty MAX
ldx gPathname ; current pathname length
ldy #$01
- lda (PTR),y
sta gPathname+1,x
@ -133,6 +133,6 @@ AddToPath
iny
cpy MAX
bcc -
@done
stx gPathname
@done
rts

View File

@ -59,10 +59,9 @@ TextRankCallback
cmp InputLength
bcc ++
sta gamelength
lda #0
sta runningscore
sta runningscore+1
ldy #1
sty runningscore
sty runningscore+1
iny
sty startat
- sty i
lda (zpword),y

View File

@ -133,8 +133,7 @@ MiniAttractMode
RunAttractModule
+STAY @key
+STAY @key2
txa
cmp #$30
cpx #$30
bne @NotDemo
; Self-running demos are loaded into main memory and executed.
@ -175,6 +174,7 @@ RunAttractModule
; not a demo, so maybe a slideshow or single screenshot
@NotDemo
txa
cmp #$41 ; numbers are slideshow modules,
bcs @dispatchSingle ; letters are single files