From 28a0a8398086b34d7dfbf248c6f7ff77d1c228f2 Mon Sep 17 00:00:00 2001 From: 4am Date: Tue, 8 Oct 2019 13:19:20 -0400 Subject: [PATCH] shave some bytes --- src/4cade.a | 25 +++--- src/constants.a | 2 +- src/glue.font.a | 11 +-- src/glue.prorwts2.a | 46 +++++------ src/okvs.a | 2 +- src/parse.prefs.a | 158 +++++++++++++++++++------------------- src/ui.animation.a | 1 + src/ui.attract.hgr.a | 2 +- src/ui.common.a | 49 +++++++++++- src/ui.credits.a | 3 +- src/ui.font.a | 2 +- src/ui.offscreen.a | 3 +- src/ui.search.mode.a | 176 ++++++++++++++++--------------------------- 13 files changed, 246 insertions(+), 234 deletions(-) diff --git a/src/4cade.a b/src/4cade.a index 0d7f4325f..23cb2a5a3 100644 --- a/src/4cade.a +++ b/src/4cade.a @@ -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 @@ -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 diff --git a/src/constants.a b/src/constants.a index 4f55234ea..a7a6842c5 100644 --- a/src/constants.a +++ b/src/constants.a @@ -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 diff --git a/src/glue.font.a b/src/glue.font.a index 33a4740e7..0c1b77201 100644 --- a/src/glue.font.a +++ b/src/glue.font.a @@ -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 @@ -29,11 +35,6 @@ DrawCenteredString jsr DrawCenteredStringInternal jmp SwitchToBank1 -DrawString - jsr SwitchToBank2 - jsr DrawStringInternal - jmp SwitchToBank1 - DrawBuffer jsr SwitchToBank2 jsr DrawBufferInternal diff --git a/src/glue.prorwts2.a b/src/glue.prorwts2.a index bac773785..9f0b02789 100644 --- a/src/glue.prorwts2.a +++ b/src/glue.prorwts2.a @@ -4,9 +4,12 @@ ; ProRWTS2 glue functions ; ; Public functions +; - SaveSmallFile ; - LoadFile ; - LoadDHRFile -; - SaveSmallFile +; +; Public variables +; - gRootDirectory ; ; A general note about paths: ; @@ -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 @@ -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 diff --git a/src/okvs.a b/src/okvs.a index 73aa699d9..fe807889d 100644 --- a/src/okvs.a +++ b/src/okvs.a @@ -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 diff --git a/src/parse.prefs.a b/src/parse.prefs.a index 786e75bb0..a1d277def 100644 --- a/src/parse.prefs.a +++ b/src/parse.prefs.a @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src/ui.animation.a b/src/ui.animation.a index b3ca1cdaa..381ca6a01 100644 --- a/src/ui.animation.a +++ b/src/ui.animation.a @@ -6,6 +6,7 @@ ; - MaybeAnimateTitle ; + ; /!\ execution falls through from ui.search.mode/FindMatchingTitle MaybeAnimateTitle ; out: C clear lda OffscreenPage diff --git a/src/ui.attract.hgr.a b/src/ui.attract.hgr.a index 70554ffed..e8f330caf 100644 --- a/src/ui.attract.hgr.a +++ b/src/ui.attract.hgr.a @@ -174,4 +174,4 @@ HGRActionCallback sta gPathname,y +LDADDR gPathname sec - jmp DrawString + ; /!\ execution falls through to glue.font/DrawString diff --git a/src/ui.common.a b/src/ui.common.a index 00cd6d1db..f6b7380e1 100644 --- a/src/ui.common.a +++ b/src/ui.common.a @@ -8,6 +8,8 @@ ; - Home ; - BlankHGR ; - BlankDHGR +; - IsSearchKey +; - IsUpDownOrRightArrow ; - ExecuteTransitionAndWait ; - WaitForKeyFor30Seconds ; - CoverFade @@ -114,7 +116,7 @@ BlankHGR jsr Home jsr ClearHGR1 ; clear hi-res screen 1 bit PAGE1 ; show hi-res screen 1 (now blank) - ; execution falls through here + ; /!\execution falls through here to HGRMode ;------------------------------------------------------------------------------ ; HGRMode ; twiddles softswitches to set HGR mode (does not set page 1 or 2) @@ -128,6 +130,49 @@ HGRMode bit $C050 rts +;------------------------------------------------------------------------------ +; IsSearchKey +; test whether accumulator contains a key that might trigger a new textrank +; search +; +; in: A = key +; out: A &= 0x7F +; Y preserved +; X clobbered +; Z = 1 if this is a search key +; Z = 0 if this is not a search key +;------------------------------------------------------------------------------ +IsSearchKey + and #$7F ; strip high bit for search characters + cmp #$30 ; control keys and punctuation ignored + bcc @badkey + cmp #$3A ; numbers are good input + bcc @goodkey + cmp #$41 ; more punctuation (also ignored) + bcc @badkey + cmp #$5B ; uppercase letters are good input + bcs + + ora #$20 ; convert uppercase letters to lowercase +@goodkey + ldx #0 + rts + ++ cmp #$61 ; more punctuation (also ignored) + bcc @badkey + cmp #$7B ; lowercase letters are good input + bcc @goodkey +@badkey + ldx #1 + rts + +IsUpDownOrRightArrow + cmp #$8B ; up arrow + beq @done + cmp #$95 ; right arrow + beq @done + cmp #$8A ; down arrow +@done rts + ;------------------------------------------------------------------------------ ; ExecuteTransitionAndWait ; call transition effect code (address passed in) and wait a period of time @@ -181,7 +226,7 @@ WaitForKeyFor30Seconds bne @loop dec Timeout+2 bne @loop - ; execution falls through here + ; /!\ execution falls through here to CoverFade CoverFade jsr LoadCoverOffscreen jsr ShowOtherPage diff --git a/src/ui.credits.a b/src/ui.credits.a index 98c85c610..14341c714 100644 --- a/src/ui.credits.a +++ b/src/ui.credits.a @@ -32,7 +32,7 @@ Help jsr ShowOtherPage jsr WaitForKeyFor30Seconds cmp #$88 - beq + + beq BrowseMode cmp #$83 beq - jsr IsUpDownOrRightArrow @@ -40,4 +40,3 @@ Help jsr IsSearchKey beq - bne -- -+ jmp BrowseMode diff --git a/src/ui.font.a b/src/ui.font.a index 27f6c13d6..1a9031e1e 100644 --- a/src/ui.font.a +++ b/src/ui.font.a @@ -126,7 +126,7 @@ DrawStringInternal inc PTR+1 + +LDAY PTR -; note: execution falls through here + ; /!\ execution falls through here to DrawBufferInternal DrawBufferInternal ; A/Y contains address of character buffer diff --git a/src/ui.offscreen.a b/src/ui.offscreen.a index a12abf21f..c6f106fd6 100644 --- a/src/ui.offscreen.a +++ b/src/ui.offscreen.a @@ -134,8 +134,7 @@ ClearHGR1 ResyncPage jsr ToggleOffscreenPage - ; execution falls through here - + ; /!\ execution falls through here to ShowOtherPage ;------------------------------------------------------------------------------ ; ShowOtherPage ; switch to the HGR page that is not currently showing diff --git a/src/ui.search.mode.a b/src/ui.search.mode.a index bf7cd48e2..c103c6645 100644 --- a/src/ui.search.mode.a +++ b/src/ui.search.mode.a @@ -5,9 +5,69 @@ ; ; Public functions ; - SearchMode -; - IsSearchKey ; +; indices into InputDispatchTable +kInputSearch = 0 +kInputClear = 1 +kInputBack = 2 +kInputBrowse = 3 +kInputTab = 4 +kInputLaunch = 5 +kInputHelp = 6 +kInputCredits = 7 +kInputCheat = 8 +kInputError = 9 + +InputDispatchTableLo + !byte OnSearch + !byte >OnClear + !byte >OnBack + !byte >BrowseMode + !byte >OnTab + !byte >OnLaunch + !byte >Help + !byte >Credits + !byte >OnCheat + !byte >OnError + +kNumInputKeys = 10 ; number of entries in next 2 tables (each) +InputKeys + !byte $83 ; Ctrl-C = toggle cheat mode + !byte $A6 ; '&' = credits + !byte $AF ; '/' = help + !byte $BF ; '?' = help + !byte $A0 ; Space = mini attract mode + !byte $89 ; TAB = mini attract mode + !byte $88 ; left arrow = delete (may as well, since + ; popular emulators remap this anyway) + !byte $FF ; backspace = delete + !byte $8D ; ENTER = launch current game (if any) + !byte $9B ; Esc = clear input buffer (if any) + ; or switch to mega attract mode +InputKeyDispatch + !byte kInputCheat + !byte kInputCredits + !byte kInputHelp + !byte kInputHelp + !byte kInputTab + !byte kInputTab + !byte kInputBack + !byte kInputBack + !byte kInputLaunch + !byte kInputClear + .noKeyMatch jsr IsSearchKey beq .foundSearchKey @@ -15,7 +75,7 @@ +HIDE_NEXT_2_BYTES .foundSearchKey ldx #kInputSearch - ; execution falls through here + ; execution falls through here to .InputDispatch .InputDispatch ldy InputDispatchTableLo,x sty .j+1 @@ -111,10 +171,10 @@ OnSearch beq OnError sta InputBuffer,x inc InputLength - ; execution falls through here + ; execution falls through here to OnInputChanged OnInputChanged lda InputLength - bne @findMatchingTitle + bne FindMatchingTitle ; no input, reset params and UI ldx #$FF stx gGameToLaunch ; no game selected @@ -123,7 +183,7 @@ OnInputChanged clc rts -@findMatchingTitle +FindMatchingTitle jsr SwitchToBank2 jsr EnableAcceleratorAndSwitchToBank1 @@ -156,108 +216,4 @@ OnError @noload jsr DrawUI jsr SwitchToBank2 jsr DisableAcceleratorAndSwitchToBank1 - jmp MaybeAnimateTitle - -;------------------------------------------------------------------------------ -; IsSearchKey -; test whether accumulator contains a key that might trigger a new textrank -; search -; -; in: A = key -; out: A &= 0x7F -; Y preserved -; X clobbered -; Z = 1 if this is a search key -; Z = 0 if this is not a search key -;------------------------------------------------------------------------------ -IsSearchKey - and #$7F ; strip high bit for search characters - cmp #$30 ; control keys and punctuation ignored - bcc @badkey - cmp #$3A ; numbers are good input - bcc @goodkey - cmp #$41 ; more punctuation (also ignored) - bcc @badkey - cmp #$5B ; uppercase letters are good input - bcs + - ora #$20 ; convert uppercase letters to lowercase -@goodkey - ldx #0 - rts - -+ cmp #$61 ; more punctuation (also ignored) - bcc @badkey - cmp #$7B ; lowercase letters are good input - bcc @goodkey -@badkey - ldx #1 - rts - -IsUpDownOrRightArrow - cmp #$8B ; up arrow - beq @done - cmp #$95 ; right arrow - beq @done - cmp #$8A ; down arrow -@done rts - -; indices into InputDispatchTable -kInputSearch = 0 -kInputClear = 1 -kInputBack = 2 -kInputBrowse = 3 -kInputTab = 4 -kInputLaunch = 5 -kInputHelp = 6 -kInputCredits = 7 -kInputCheat = 8 -kInputError = 9 - -InputDispatchTableLo - !byte OnSearch - !byte >OnClear - !byte >OnBack - !byte >BrowseMode - !byte >OnTab - !byte >OnLaunch - !byte >Help - !byte >Credits - !byte >OnCheat - !byte >OnError - -kNumInputKeys = 10 ; number of entries in next 2 tables (each) -InputKeys - !byte $83 ; Ctrl-C = toggle cheat mode - !byte $A6 ; '&' = credits - !byte $AF ; '/' = help - !byte $BF ; '?' = help - !byte $A0 ; Space = mini attract mode - !byte $89 ; TAB = mini attract mode - !byte $88 ; left arrow = delete (may as well, since - ; popular emulators remap this anyway) - !byte $FF ; backspace = delete - !byte $8D ; ENTER = launch current game (if any) - !byte $9B ; Esc = clear input buffer (if any) - ; or switch to mega attract mode -InputKeyDispatch - !byte kInputCheat - !byte kInputCredits - !byte kInputHelp - !byte kInputHelp - !byte kInputTab - !byte kInputTab - !byte kInputBack - !byte kInputBack - !byte kInputLaunch - !byte kInputClear + ; /!\ execution falls through to ui.animation/MaybeAnimateTitle