shave some bytes, fix VIDHD speaker behaviour

This commit is contained in:
Peter Ferrie
2020-11-09 10:45:03 -08:00
parent 1b90260631
commit 532ce58a16
4 changed files with 77 additions and 22 deletions

View File

@@ -7,7 +7,7 @@
; ;
; LC RAM BANK 1 ; LC RAM BANK 1
; D000..E908 - persistent data structures (gGlobalPrefsStore, gGamesListStore) ; 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 ; FFF2..FFF9 - API functions and global constants available for main program
; code, prelaunchers, transition effects, &c. ; code, prelaunchers, transition effects, &c.
; (Wait/UnwaitForVBL, MockingboardStuff, MachineStatus) ; (Wait/UnwaitForVBL, MockingboardStuff, MachineStatus)
@@ -15,10 +15,10 @@
; ;
; LC RAM BANK 2 ; LC RAM BANK 2
; D000..D3FF - ProRWTS data ; D000..D3FF - ProRWTS data
; D400..D66D - ProRWTS code ; D400..D677 - ProRWTS code
; D66E..DBA2 - HGR font code & ProRWTS glue code ; D678..DB9D - HGR font code & ProRWTS glue code
; DBA3..DBB2 - backup of stack (during gameplay and self-running demos) ; DB9E..DBAD - backup of stack (during gameplay and self-running demos)
; ...unused... yes, just one byte to spare ; ...unused...
; DBB4..DBFF - (de)acceleration function ; DBB4..DBFF - (de)acceleration function
; DC00..DFFF - HGR font data ; DC00..DFFF - HGR font data
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------

View File

@@ -60,12 +60,24 @@
ldy .ptr+1 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) ; store a 16-bit value from A (low) and Y (high)
!macro ST16 .ptr { !macro ST16 .ptr {
sta .ptr sta .ptr
sty .ptr+1 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) ; decrement a 16-bit value in A (low) and Y (high)
!macro DEC16 { !macro DEC16 {
sec 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) ; increment a 16-bit value in A (low) and Y (high)
!macro INC16 { !macro INC16 {
clc 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 ; compare a 16-bit value in A (low) and Y (high) to an absolute address
!macro CMP16ADDR .addr { !macro CMP16ADDR .addr {
cmp .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 ; compare a 16-bit value in A (low) and Y (high) to an immediate value
!macro CMP16 .val { !macro CMP16 .val {
cmp #<.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 { !macro LBPL .target {
bmi + bmi +
jmp .target jmp .target

View File

@@ -128,10 +128,20 @@ BlankSHR
sta WRITEAUXMEM ; writes go to auxmem sta WRITEAUXMEM ; writes go to auxmem
lda #$00 ; enable auxmem-to-bank-E1 shadowing on IIgs ldx #$00 ; enable auxmem-to-bank-E1 shadowing on IIgs
sta SHADOW 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 ldx #$80
jsr ClearMem jsr ClearMem

View File

@@ -66,24 +66,23 @@ OnBrowseSearch
jmp SearchMode jmp SearchMode
OnBrowsePrevious OnBrowsePrevious
+LD16 gGameToLaunch +LDX16 gGameToLaunch
+CMP16 0 +CPX16_0
bne @notFirstGame bne @notFirstGame
+LD16 GameCount +LDX16 GameCount
@notFirstGame @notFirstGame
+DEC16 +DEX16
+ST16 gGameToLaunch jmp notLastGame
jmp OnBrowseChanged
OnBrowseNext OnBrowseNext
+LD16 gGameToLaunch +LDX16 gGameToLaunch
+INC16 +INX16
+CMP16ADDR GameCount +CPX16ADDR GameCount
bne @notLastGame bne notLastGame
lda #0 ldx #0
tay ldy #0
@notLastGame notLastGame
+ST16 gGameToLaunch +STX16 gGameToLaunch
jmp OnBrowseChanged jmp OnBrowseChanged
OnBrowseLaunch OnBrowseLaunch