From 0c03da85994930832f7da3cb7394188c84769040 Mon Sep 17 00:00:00 2001 From: Peter Ferrie Date: Wed, 27 Nov 2019 13:51:43 -0800 Subject: [PATCH] shave some bytes --- src/4cade.a | 15 +++++++++------ src/constants.a | 8 ++++---- src/glue.launch.a | 2 +- src/glue.launch.lc2.a | 4 ++-- src/glue.prorwts2.a | 3 +-- src/hw.accel.a | 36 +++++++++++------------------------- src/macros.a | 13 +++++++++++++ src/okvs.a | 9 +++------ src/parse.common.a | 16 +++++++--------- src/parse.prefs.a | 12 ++++-------- src/ui.attract.dhgr.a | 1 + src/ui.attract.gr.a | 4 +--- src/ui.browse.mode.a | 12 +++--------- src/ui.common.a | 2 +- src/ui.overlay.a | 9 +++++---- src/ui.search.mode.a | 10 +++------- src/ui.wait.a | 6 ++---- 17 files changed, 71 insertions(+), 91 deletions(-) diff --git a/src/4cade.a b/src/4cade.a index efa25ba22..eed22b3e8 100644 --- a/src/4cade.a +++ b/src/4cade.a @@ -41,6 +41,8 @@ FirstMover Reenter cld cli + ldx #$ff + txs ; so that we never trash the reset vector jsr SwitchToBank2 jsr DisableAccelerator ; back to 1 MHz (especially important on IIgs ; which restores default speed on Ctrl-Reset) @@ -67,11 +69,12 @@ RestoreStackNextTime sta RestoreStackNextTime + 1 ; restore the same stack twice ldx #$F1 -- lda STACKBASE - $F0,x ; restore stack +- lda STACKBASE - $EF,x ; restore stack sta $100,x inx bne - - ldx STACKBASE ; restore stack pointer +STACKPTR + ldx #$D1 ; SMC, restore stack pointer txs SwitchToBank1 +READ_RAM1_WRITE_RAM1 @@ -144,12 +147,12 @@ SwitchToBank2 !word Ignore ; IRQ vector ($FFFE-F) } LastMover -!if ((hdddataend & 255) > $ec) and ((hdddataend & 255) < $f0) { +!if ((hdddataend & 255) > $ec) and ((hdddataend & 255) < $f2) { ; in the unlikely event that a bit over 16 bytes are left in the page ; then use it for the stack - STACKBASE = (hdddataend + 15) and -16 + STACKBASE = ((hdddataend + 15) and -16) + 1 FONTSRC = * - !pseudopc STACKBASE + 16 { + !pseudopc STACKBASE + 15 { FONTDST = * !source "src/ui.font.data.lc2.a" COPYDST = * @@ -177,7 +180,7 @@ EvenLasterMover !source "src/glue.launch.lc2.a" !source "src/hw.accel.lc2.a" STACKBASE = * - LCRAM2_END = STACKBASE + 16 + LCRAM2_END = STACKBASE + 15 FONTDST = (LCRAM2_END + 255) and -256 } EvenLasterMover diff --git a/src/constants.a b/src/constants.a index da02376cc..46a5b3568 100644 --- a/src/constants.a +++ b/src/constants.a @@ -9,14 +9,14 @@ ; D000..E635 - persistent data structures (per-game cheat categories, ; gGlobalPrefsStore, gGamesListStore) ; ...unused... -; ECC6..FFF9 - main program code +; ECF3..FFF9 - main program code ; FFFA..FFFF - NMI, reset, IRQ vectors ; ; LC RAM BANK 2 ; D000..D3FF - ProRWTS data -; D400..D671 - ProRWTS code -; D672..DB6D - HGR font code & ProRWTS glue code -; DB6E..DB7D - backup of stack (during gameplay and self-running demos) +; D400..D66F - ProRWTS code +; D670..DB6B - HGR font code & ProRWTS glue code +; DB6B..DB79 - backup of stack (during gameplay and self-running demos) ; ...unused... ; DBB2..DBFF - (de)acceleration function ; DC00..DFFF - HGR font data diff --git a/src/glue.launch.a b/src/glue.launch.a index 000009896..c575f9e58 100644 --- a/src/glue.launch.a +++ b/src/glue.launch.a @@ -128,7 +128,7 @@ PlayGame ; and then finds the subdirectory name and game name right after it ; and attaches it to the path by overwriting the count byte - sec + ;;sec ; carry set by AddToPath lda gPathname sbc #kGameDirectoryLen sta gPathname+kGameDirectoryLen diff --git a/src/glue.launch.lc2.a b/src/glue.launch.lc2.a index 69fab9b5a..c439a020f 100644 --- a/src/glue.launch.lc2.a +++ b/src/glue.launch.lc2.a @@ -10,11 +10,11 @@ LaunchInternal ldy #$F1 - lda $100,y - sta STACKBASE - $F0,y ; back up stack + sta STACKBASE - $EF,y ; back up stack iny bne - tsx ; back up stack pointer - stx STACKBASE + stx STACKPTR + 1 sty RestoreStackNextTime + 1 ; tell |Reenter| to restore the stack and stack pointer diff --git a/src/glue.prorwts2.a b/src/glue.prorwts2.a index 7df0babdd..f49de96eb 100644 --- a/src/glue.prorwts2.a +++ b/src/glue.prorwts2.a @@ -52,8 +52,7 @@ LoadFile jsr SetPath +LDPARAM 3 jsr AddToPath - +LDPARAM 5 - +STAY ldrlo ; set load address + +LDPARAMPTR 5, ldrlo ; set load address jsr SwitchToBank2 jsr LoadFileInternal jmp SwitchToBank1 diff --git a/src/hw.accel.a b/src/hw.accel.a index b4344ac16..0951973b0 100644 --- a/src/hw.accel.a +++ b/src/hw.accel.a @@ -251,37 +251,24 @@ iicplus !pseudopc DisableAccelerator { ; cgga calls save X and Y regs but sets $0 to 0 ; (this will get a laugh from C programmers) - ldx $0 -!cpu 65c02 - phx -!cpu 6502 + lda $0 + pha + + ldy #(@endpokery - @jiggery) - 1 +@copyiicp + lda @jiggery,y + sta $106, y + dey + bpl @copyiicp php sei ; timing sensitive - jsr @jiggerypokery + jsr $106 plp ; restore interrupt state pla sta $0 rts -@jiggerypokery - tsx - ldy #(@endpokery - @jiggery) -@copyiicp - lda @jiggery-1,y - pha - dey - bne @copyiicp - txa - tsx - iny -!cpu 65c02 - phy - phx -!cpu 6502 - tax - rts - @jiggery +READ_ROM_NO_WRITE lda #CGGA_UNLOCK ; unlock to change @@ -296,7 +283,6 @@ iicplus !pseudopc DisableAccelerator { lda #CGGA_LOCK ; should lock after a change pha jsr cgga ; reads parm from stack, must JSR - txs +READ_RAM2_WRITE_RAM2 rts @endpokery @@ -385,4 +371,4 @@ FASTChip plp ; restore interrupt state rts -end_addon \ No newline at end of file +end_addon diff --git a/src/macros.a b/src/macros.a index 5f8dc29c5..efd9e3d7e 100644 --- a/src/macros.a +++ b/src/macros.a @@ -39,6 +39,19 @@ pla } +; for functions that take parameters on the stack +; load a 16-bit value from the parameters on the stack into A (low) and Y (high) +; then store it as new source +; (assumes PARAMS_ON_STACK was used first) +!macro LDPARAMPTR .offset,.dest { + ldy #.offset + lda (PARAM),y + sta .dest + iny + lda (PARAM),y + sta .dest+1 +} + ; load the address of .ptr into A (low) and Y (high) !macro LDADDR .ptr { lda #<.ptr diff --git a/src/okvs.a b/src/okvs.a index 61903aa23..8d6fa4fc5 100644 --- a/src/okvs.a +++ b/src/okvs.a @@ -144,8 +144,7 @@ okvs_append ; SAVE -> new record jsr incptr2 ; PTR -> space for new key - +LDPARAM 3 - +STAY SRC ; SRC -> new key to copy + +LDPARAMPTR 3, SRC ; SRC -> new key to copy ldy #0 lda (SRC),y tay @@ -163,8 +162,7 @@ okvs_append bcc + inc PTR+1 + ; PTR -> space for new value - +LDPARAM 5 - +STAY SRC ; SRC -> new value to copy + +LDPARAMPTR 5, SRC ; SRC -> new value to copy ldy #7 lda (PARAM),y ; get max length of value tax @@ -233,8 +231,7 @@ okvs_get jsr incptr3 ; PTR -> first record ldx #0 - +LDPARAM 3 - +STAY SRC ; SRC -> key we want to find + +LDPARAMPTR 3, SRC ; SRC -> key we want to find ldy #0 lda (SRC),y tay diff --git a/src/parse.common.a b/src/parse.common.a index cabe85be2..a2eaf4437 100644 --- a/src/parse.common.a +++ b/src/parse.common.a @@ -103,19 +103,17 @@ ParseKeyValueList SetKeyPtr jsr okvs_init ; reset key/value store - +LDPARAM 3 - +STAY $FE + +LDPARAMPTR 3, $FE - ldy #1 + ldy #0 lda ($FE),y tax - dey - lda ($FE),y bne + - dex - stx $FF -+ tax - dex + iny + lda ($FE),y + sta $FF + dec $FF ++ dex stx $FE rts diff --git a/src/parse.prefs.a b/src/parse.prefs.a index b56373d71..fad826e1e 100644 --- a/src/parse.prefs.a +++ b/src/parse.prefs.a @@ -113,10 +113,8 @@ PREFRTS rts ;------------------------------------------------------------------------------ pref_get +PARAMS_ON_STACK 4 - +LDPARAM 1 - +STAY + - +LDPARAM 3 - +STAY .store1 + +LDPARAMPTR 1, + + +LDPARAMPTR 3, .store1 jsr okvs_get ; look up pref key in prefs store !word gGlobalPrefsStore @@ -154,10 +152,8 @@ pref_get ;------------------------------------------------------------------------------ pref_set +PARAMS_ON_STACK 4 - +LDPARAM 1 - +STAY + - +LDPARAM 3 - +STAY ++ + +LDPARAMPTR 1, + + +LDPARAMPTR 3, ++ jsr okvs_update ; save that in prefs store !word gGlobalPrefsStore diff --git a/src/ui.attract.dhgr.a b/src/ui.attract.dhgr.a index 6e864c655..0009dafe4 100644 --- a/src/ui.attract.dhgr.a +++ b/src/ui.attract.dhgr.a @@ -98,6 +98,7 @@ BlankHGR ;------------------------------------------------------------------------------ HGRMode bit $C057 +GRMode bit $C052 bit $C050 DHGRRTS rts diff --git a/src/ui.attract.gr.a b/src/ui.attract.gr.a index 05a6eff91..e984babc6 100644 --- a/src/ui.attract.gr.a +++ b/src/ui.attract.gr.a @@ -64,9 +64,7 @@ BlankGR bne @loop bit PAGE1 bit $C056 ; set GR mode - bit $C052 - bit $C050 - rts + jmp GRMode ;------------------------------------------------------------------------------ ; .LoadGRTransition [private] diff --git a/src/ui.browse.mode.a b/src/ui.browse.mode.a index 113f91301..683f4d0c3 100644 --- a/src/ui.browse.mode.a +++ b/src/ui.browse.mode.a @@ -33,7 +33,7 @@ kBrowseLaunch = 5 kBrowseHelp = 6 kBrowseCredits = 7 kBrowseCheat = 8 -kSoftBell = 9 +kSoftBell = 9 ; must match kInputError ldy #kNumBrowseKeys - dey @@ -45,15 +45,9 @@ kSoftBell = 9 @noKeyMatch jsr IsSearchKey - beq + - ldx #kSoftBell ; beep on invalid input -!if kBrowseSearch > 0 { - +HIDE_NEXT_2_BYTES -+ + bne @BrowseDispatch ldx #kBrowseSearch -} else { -+ -} + ; execution falls through here @BrowseDispatch ldy BrowseDispatchTableLo,x diff --git a/src/ui.common.a b/src/ui.common.a index 4148a3dac..6170077bc 100644 --- a/src/ui.common.a +++ b/src/ui.common.a @@ -125,7 +125,7 @@ IsSearchKey cmp #$7B ; lowercase letters are good input bcc @goodkey @badkey - ldx #1 + ldx #kInputError ; also #kSoftBell rts ;------------------------------------------------------------------------------ diff --git a/src/ui.overlay.a b/src/ui.overlay.a index f97090e1e..b44dec6d8 100644 --- a/src/ui.overlay.a +++ b/src/ui.overlay.a @@ -141,7 +141,7 @@ DrawUI tax lda #$09 ; rounded bottom-right character sta UILine1,x - ldy #1 ; fill the proper width with spaces + iny ; fill the proper width with spaces lda #$20 ; space character - inx sta UILine1,x @@ -221,14 +221,15 @@ DrawUI +LDADDR gPathname jsr DrawCenteredString ; draw cheat UI line 2 -@uidone jmp ShowOtherPage +@uidone clc + jmp ShowOtherPage CheckCheats ldy #kCheatsEnabled ldx gGameToLaunch - cpx #$FF + inx beq + - ldy gCheatsAvailable,x + ldy gCheatsAvailable-1,x + lda kCheatDescriptionLo,y sta SAVE diff --git a/src/ui.search.mode.a b/src/ui.search.mode.a index ebbe98d60..16439915d 100644 --- a/src/ui.search.mode.a +++ b/src/ui.search.mode.a @@ -71,8 +71,6 @@ InputKeyDispatch .noKeyMatch jsr IsSearchKey - beq .foundSearchKey - ldx #kInputError !if kInputSearch > 0 { +HIDE_NEXT_2_BYTES .foundSearchKey @@ -108,8 +106,8 @@ SearchMode jsr ResyncPage lda KBD jsr IsSearchKey - beq .SearchModeInputLoop - bit CLEARKBD + lda CLEARKBD - kInputError,X + ; clear strobe if key was bad .SearchModeInputLoop jsr WaitForKeyFor30Seconds @@ -181,9 +179,7 @@ OnInputChanged dex stx gGameToLaunch ; no game selected jsr LoadTitleOffscreen - jsr DrawUIWithoutDots - clc - rts + jmp DrawUIWithoutDots FindMatchingTitle jsr SwitchToBank2 diff --git a/src/ui.wait.a b/src/ui.wait.a index 6a009a03e..dd749afd1 100644 --- a/src/ui.wait.a +++ b/src/ui.wait.a @@ -84,10 +84,8 @@ CoverFade jsr LoadCoverOffscreen jsr ShowOtherPage lda OffscreenPage - bne + - jsr LoadCoverOffscreen - jsr ShowOtherPage -+ jsr LoadFile ; load transition effect code at $6000 + beq CoverFade + jsr LoadFile ; load transition effect code at $6000 !word kFXDirectory !word kCoverFadeFile !word $6000