From 532ce58a16c6d8ce087887d7b9d5848f7faa8b59 Mon Sep 17 00:00:00 2001 From: Peter Ferrie Date: Mon, 9 Nov 2020 10:45:03 -0800 Subject: [PATCH] shave some bytes, fix VIDHD speaker behaviour --- src/constants.a | 10 +++++----- src/macros.a | 46 ++++++++++++++++++++++++++++++++++++++++++++ src/ui.attract.shr.a | 16 ++++++++++++--- src/ui.browse.mode.a | 27 +++++++++++++------------- 4 files changed, 77 insertions(+), 22 deletions(-) diff --git a/src/constants.a b/src/constants.a index 2efcf894e..a26622eee 100644 --- a/src/constants.a +++ b/src/constants.a @@ -7,7 +7,7 @@ ; ; LC RAM BANK 1 ; D000..E908 - persistent data structures (gGlobalPrefsStore, gGamesListStore) -; E909..FFF1 - main program code +; E912..FFF1 - main program code ; FFF2..FFF9 - API functions and global constants available for main program ; code, prelaunchers, transition effects, &c. ; (Wait/UnwaitForVBL, MockingboardStuff, MachineStatus) @@ -15,10 +15,10 @@ ; ; LC RAM BANK 2 ; D000..D3FF - ProRWTS data -; D400..D66D - ProRWTS code -; D66E..DBA2 - HGR font code & ProRWTS glue code -; DBA3..DBB2 - backup of stack (during gameplay and self-running demos) -; ...unused... yes, just one byte to spare +; D400..D677 - ProRWTS code +; D678..DB9D - HGR font code & ProRWTS glue code +; DB9E..DBAD - backup of stack (during gameplay and self-running demos) +; ...unused... ; DBB4..DBFF - (de)acceleration function ; DC00..DFFF - HGR font data ;------------------------------------------------------------------------------ diff --git a/src/macros.a b/src/macros.a index b76d93fa0..92c649b06 100755 --- a/src/macros.a +++ b/src/macros.a @@ -60,12 +60,24 @@ ldy .ptr+1 } +; load a 16-bit value into X (low) and Y (high) +!macro LDX16 .ptr { + ldx .ptr + ldy .ptr+1 +} + ; store a 16-bit value from A (low) and Y (high) !macro ST16 .ptr { sta .ptr sty .ptr+1 } +; store a 16-bit value from X (low) and Y (high) +!macro STX16 .ptr { + stx .ptr + sty .ptr+1 +} + ; decrement a 16-bit value in A (low) and Y (high) !macro DEC16 { sec @@ -75,6 +87,15 @@ + } +; decrement a 16-bit value in X (low) and Y (high) +; destroys A! +!macro DEX16 { + txa + bne + + dey ++ dex +} + ; increment a 16-bit value in A (low) and Y (high) !macro INC16 { clc @@ -84,6 +105,14 @@ + } +; increment a 16-bit value in X (low) and Y (high) +!macro INX16 { + inx + bne + + iny ++ +} + ; compare a 16-bit value in A (low) and Y (high) to an absolute address !macro CMP16ADDR .addr { cmp .addr @@ -92,6 +121,14 @@ + } +; compare a 16-bit value in X (low) and Y (high) to an absolute address +!macro CPX16ADDR .addr { + cpx .addr + bne + + cpy .addr+1 ++ +} + ; compare a 16-bit value in A (low) and Y (high) to an immediate value !macro CMP16 .val { cmp #<.val @@ -100,6 +137,15 @@ + } +; compare a 16-bit value in X (low) and Y (high) against zero +; requires LDX16 immediately prior, since Y comparison is implicit! +; destroys A! +!macro CPX16_0 { + bne + + txa ++ +} + !macro LBPL .target { bmi + jmp .target diff --git a/src/ui.attract.shr.a b/src/ui.attract.shr.a index fac37298b..e862c2013 100644 --- a/src/ui.attract.shr.a +++ b/src/ui.attract.shr.a @@ -128,10 +128,20 @@ BlankSHR sta WRITEAUXMEM ; writes go to auxmem - lda #$00 ; enable auxmem-to-bank-E1 shadowing on IIgs - sta SHADOW + ldx #$00 ; enable auxmem-to-bank-E1 shadowing on IIgs + stx SHADOW - lda #$20 ; clear $2000..$9FFF in auxmem +; VIDHD-SPECIFIC HACK HERE! +; On the II/II+/IIe, all $C03x are aliases for $C030, i.e. the speaker. +; Any single access of the speaker register requires a second access within a short +; time to balance the level if we want to avoid an audible click, which we do here. +; Since we can't read from SHADOW before writing to it (VidHD will crash the machine +; if we do that - ask us how we know), we have to balance the speaker access by +; accessing a speaker address explicitly because let's not make VIDHD angry. +; Hence the write to SPEAKER. Do not remove. + stx SPEAKER + + lsr ; clear $2000..$9FFF in auxmem ldx #$80 jsr ClearMem diff --git a/src/ui.browse.mode.a b/src/ui.browse.mode.a index 2a2075876..5ce427d83 100644 --- a/src/ui.browse.mode.a +++ b/src/ui.browse.mode.a @@ -66,24 +66,23 @@ OnBrowseSearch jmp SearchMode OnBrowsePrevious - +LD16 gGameToLaunch - +CMP16 0 + +LDX16 gGameToLaunch + +CPX16_0 bne @notFirstGame - +LD16 GameCount + +LDX16 GameCount @notFirstGame - +DEC16 - +ST16 gGameToLaunch - jmp OnBrowseChanged + +DEX16 + jmp notLastGame OnBrowseNext - +LD16 gGameToLaunch - +INC16 - +CMP16ADDR GameCount - bne @notLastGame - lda #0 - tay -@notLastGame - +ST16 gGameToLaunch + +LDX16 gGameToLaunch + +INX16 + +CPX16ADDR GameCount + bne notLastGame + ldx #0 + ldy #0 +notLastGame + +STX16 gGameToLaunch jmp OnBrowseChanged OnBrowseLaunch