Skip to content

Commit

Permalink
shave some bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
a2-4am committed Oct 8, 2019
1 parent 6868fe2 commit 28a0a83
Show file tree
Hide file tree
Showing 13 changed files with 246 additions and 234 deletions.
25 changes: 16 additions & 9 deletions src/4cade.a
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ Reenter
cld
cli
jsr SwitchToBank2
jsr DisableAccelerator
jsr DisableAccelerator ; back to 1 MHz (especially important on IIgs
; which restores default speed on Ctrl-Reset)
jsr CloseHandles ; close any open handles to restore ProRWTS
jsr SaveOrRestoreScreenHoles ; restore original screen hole contents
ldx #5
Expand Down Expand Up @@ -81,27 +82,33 @@ ResetVector ; 6 bytes, copied to $100
jmp Reenter

; these routines will only be called after relocating to language card
!source "src/ui.search.mode.a"
!source "src/ui.browse.mode.a"
!source "src/ui.search.mode.a" ; \__ execution falls through
!source "src/ui.animation.a" ; /

!source "src/ui.credits.a" ; \__ execution falls through
!source "src/ui.browse.mode.a" ; /

!source "src/prodos.path.a"
!source "src/ui.overlay.a"
!source "src/ui.offscreen.a"
!source "src/ui.animation.a"
!source "src/ui.credits.a"
!source "src/ui.attract.mode.a"
!source "src/ui.attract.hgr.a"
!source "src/ui.attract.dhgr.a"
!source "src/ui.attract.shr.a"
!source "src/ui.attract.gr.a"

!source "src/ui.attract.hgr.a" ; \__ execution falls through
!source "src/glue.font.a" ; /

!source "src/ui.cheats.a"
!source "src/glue.launch.a"
!source "src/glue.prorwts2.a"
!source "src/okvs.a"
!source "src/wait.a"
!source "src/textrank.a"
!source "src/parse.common.a"
!source "src/parse.prefs.a"
!source "src/glue.font.a"

!source "src/parse.prefs.a" ; \__ execution falls through
!source "src/glue.prorwts2.a" ; /

; add new files above here so ui.common stays last
!source "src/ui.common.a"
gAttractModeStore
Expand Down
2 changes: 1 addition & 1 deletion src/constants.a
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
; D000..E611 - persistent data structures (per-game cheat categories,
; gGlobalPrefsStore, gGamesListStore)
; ...unused...
; EBF5..FFF9 - main program code
; EC01..FFF9 - main program code
; FFFA..FFFF - NMI, reset, IRQ vectors
;
; LC RAM BANK 2
Expand Down
11 changes: 6 additions & 5 deletions src/glue.font.a
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
; - DrawBuffer
;

; /!\ execution falls through from ui.attract.hgr/HGRActionCallback
DrawString
jsr SwitchToBank2
jsr DrawStringInternal
jmp SwitchToBank1

DrawPage
jsr SwitchToBank2
jsr DrawPageInternal
Expand All @@ -29,11 +35,6 @@ DrawCenteredString
jsr DrawCenteredStringInternal
jmp SwitchToBank1

DrawString
jsr SwitchToBank2
jsr DrawStringInternal
jmp SwitchToBank1

DrawBuffer
jsr SwitchToBank2
jsr DrawBufferInternal
Expand Down
46 changes: 25 additions & 21 deletions src/glue.prorwts2.a
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
; ProRWTS2 glue functions
;
; Public functions
; - SaveSmallFile
; - LoadFile
; - LoadDHRFile
; - SaveSmallFile
;
; Public variables
; - gRootDirectory
;
; A general note about paths:
;
Expand All @@ -30,8 +33,25 @@
; 'FX/RIPPLE' points to a file named 'RIPPLE' in a directory named 'FX' in the
; PROGRAM ROOT DIRECTORY.

gRootDirectory
!word $FDFD
; /!\ execution falls through from parse.perfs/pref_set
;------------------------------------------------------------------------------
; SaveSmallFile
; Save a file into memory all at once, using ProRWTS2.
; /!\ Only first block (512 bytes) is written. Keep those files small. /!\
; /!\ All 512 bytes are written to disk. Clear buffer before calling. /!\
;
; supports paths, see note
;
; in: A/Y points to data buffer
; gPathname contains path+filename to write
; out: all flags clobbered
; all registers clobbered
;------------------------------------------------------------------------------
SaveSmallFile
+STAY ldrlo ; set data buffer address for ProRWTS2
jsr SwitchToBank2
jsr SaveSmallFileInternal
jmp SwitchToBank1

;------------------------------------------------------------------------------
; LoadFile
Expand Down Expand Up @@ -85,21 +105,5 @@ LoadDHRFile
jsr LoadDHRFileInternal
jmp SwitchToBank1

;------------------------------------------------------------------------------
; SaveSmallFile
; Save a file into memory all at once, using ProRWTS2.
; /!\ Only first block (512 bytes) is written. Keep those files small. /!\
; /!\ All 512 bytes are written to disk. Clear buffer before calling. /!\
;
; supports paths, see note
;
; in: A/Y points to data buffer
; gPathname contains path+filename to write
; out: all flags clobbered
; all registers clobbered
;------------------------------------------------------------------------------
SaveSmallFile
+STAY ldrlo ; set data buffer address for ProRWTS2
jsr SwitchToBank2
jsr SaveSmallFileInternal
jmp SwitchToBank1
gRootDirectory
!word $FDFD
2 changes: 1 addition & 1 deletion src/okvs.a
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ okvs_next
tax
+
+LDAY PARAM
; execution falls through here
; /!\ execution falls through here to okvs_nth
;------------------------------------------------------------------------------
; okvs_nth
; get (N)th key
Expand Down
158 changes: 79 additions & 79 deletions src/parse.prefs.a
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,58 @@ kCheat
!byte 5
!raw "CHEAT"

.kEquals !byte 1
!raw "="
.kLF !byte 1,$0D
.kFluff1 !byte .kFluff2-*-1
!raw "# Total Replay preferences file",$0D
!raw "# Do not edit by hand.",$0D
!raw "# Or do. I'm a comment, not a cop.",$0D
!byte $0D
!raw "# value=attract mode module listed in ATTRACT.CONF, or empty",$0D
.kFluff2 !byte .kFluff3-*-1
!byte $0D
!raw "# value=transition effect listed in FX.CONF, or empty",$0D
.kFluff3 !byte .kFluff4-*-1
!byte $0D
!raw "# value=transition effect listed in DFX.CONF, or empty",$0D
.kFluff4 !byte .kEOF-*-1
!byte $0D
!raw "# value=0 or 1",$0D
.kEOF !byte ._-*-1
!byte $0D
!raw "[eof]",$0D
._

.addStringFromStore
+STAY .key
jsr .addString
+LDADDR .kEquals
jsr .addString
jsr okvs_get
!word gGlobalPrefsStore
.key !word $FDFD ; SMC
jsr .addString
+LDADDR .kLF
; execution falls through here
.addString
+STAY $00
ldy #0
lda ($00),y
beq +
tay
clc
adc $FE
tax
- lda ($00),y
dey
sta ($FE),y
bne -
stx $FE
bcc +
inc $FF
+ rts

;------------------------------------------------------------------------------
; pref_get
; get pref value by pref key, and optionally validate that the pref value
Expand Down Expand Up @@ -61,31 +113,31 @@ kCheat
pref_get
+PARAMS_ON_STACK 4
+LDPARAM 1
+STAY @prefkey
+STAY +
+LDPARAM 3
+STAY @store1
+STAY .store1

jsr okvs_get ; look up pref key in prefs store
!word gGlobalPrefsStore
@prefkey !word $FDFD ; SMC
+ !word $FDFD ; SMC
bcs .useDefaultValue ; if pref key is not found, use default value
ldx @store1+1
beq @done ; if no OKVS to validate against, we're done
ldx .store1+1
beq .done ; if no OKVS to validate against, we're done
+STAY +
+STAY PTR
ldy #0
lda (PTR),y
beq .useDefaultValue ; if pref value is empty, use default value
jsr okvs_get ; check whether the pref value exists as a key in the passed-in store
@store1 !word $FDFD ; SMC
.store1 !word $FDFD ; SMC
+ !word $FDFD ; SMC
bcc + ; found key, continue
.useDefaultValue ; did not find key, use first key in passed store as a default value
ldx #0
+
+LDAY @store1
+LDAY .store1
jsr okvs_nth
@done rts
.done rts

;------------------------------------------------------------------------------
; pref_set
Expand All @@ -103,14 +155,14 @@ pref_get
pref_set
+PARAMS_ON_STACK 4
+LDPARAM 1
+STAY @prefkey
+STAY +
+LDPARAM 3
+STAY @prefval
+STAY ++

jsr okvs_update ; save that in prefs store
!word gGlobalPrefsStore
@prefkey !word $FDFD ; SMC
@prefval !word $FDFD ; SMC
+ !word $FDFD ; SMC
++ !word $FDFD ; SMC

+LDADDR kGlobalPrefsBuffer ; clear prefs buffer
+STAY $FE
Expand All @@ -126,82 +178,30 @@ pref_set
dec $FF
dec $FF

+LDADDR @kFluff1 ; serialize prefs into prefs buffer
jsr @addString
+LDADDR .kFluff1 ; serialize prefs into prefs buffer
jsr .addString
+LDADDR kNextAttract
jsr @addStringFromStore
jsr .addStringFromStore

+LDADDR @kFluff2
jsr @addString
+LDADDR .kFluff2
jsr .addString
+LDADDR kNextFX
jsr @addStringFromStore
jsr .addStringFromStore

+LDADDR @kFluff3
jsr @addString
+LDADDR .kFluff3
jsr .addString
+LDADDR kNextDFX
jsr @addStringFromStore
jsr .addStringFromStore

+LDADDR @kFluff4
jsr @addString
+LDADDR .kFluff4
jsr .addString
+LDADDR kCheat
jsr @addStringFromStore
jsr .addStringFromStore

+LDADDR @kEOF
jsr @addString
+LDADDR .kEOF
jsr .addString

+LDADDR kGlobalPrefsFilename ; write prefs buffer to file on disk
jsr SetPath
+LDAY kGlobalPrefsBuffer
jmp SaveSmallFile

@addStringFromStore
+STAY @key
jsr @addString
+LDADDR @kEquals
jsr @addString
jsr okvs_get
!word gGlobalPrefsStore
@key !word $FDFD ; SMC
jsr @addString
+LDADDR @kLF
; execution falls through here
@addString
+STAY $00
ldy #0
lda ($00),y
beq +
tay
clc
adc $FE
tax
- lda ($00),y
dey
sta ($FE),y
bne -
stx $FE
bcc +
inc $FF
+ rts

@kEquals !byte 1
!raw "="
@kLF !byte 1,$0D
@kFluff1 !byte @kFluff2-*-1
!raw "# Total Replay preferences file",$0D
!raw "# Do not edit by hand.",$0D
!raw "# Or do. I'm a comment, not a cop.",$0D
!byte $0D
!raw "# value=attract mode module listed in ATTRACT.CONF, or empty",$0D
@kFluff2 !byte @kFluff3-*-1
!byte $0D
!raw "# value=transition effect listed in FX.CONF, or empty",$0D
@kFluff3 !byte @kFluff4-*-1
!byte $0D
!raw "# value=transition effect listed in DFX.CONF, or empty",$0D
@kFluff4 !byte @kEOF-*-1
!byte $0D
!raw "# value=0 or 1",$0D
@kEOF !byte @_-*-1
!byte $0D
!raw "[eof]",$0D
@_
; /!\ execution falls through here to glue.prorwts/SaveSmallFile
1 change: 1 addition & 0 deletions src/ui.animation.a
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
; - MaybeAnimateTitle
;

; /!\ execution falls through from ui.search.mode/FindMatchingTitle
MaybeAnimateTitle
; out: C clear
lda OffscreenPage
Expand Down
2 changes: 1 addition & 1 deletion src/ui.attract.hgr.a
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,4 @@ HGRActionCallback
sta gPathname,y
+LDADDR gPathname
sec
jmp DrawString
; /!\ execution falls through to glue.font/DrawString

0 comments on commit 28a0a83

Please sign in to comment.