This commit is contained in:
Peter Ferrie 2019-09-20 16:53:55 -07:00
commit 699185d678
12 changed files with 80 additions and 111 deletions

View File

@ -206,8 +206,8 @@ OneTimeSetup
!word gGamesListStore
!word -
+LDADDR gGamesListStore
jsr okvs_len
!word gGamesListStore
sta GameCount
sta SAVE

View File

@ -9,7 +9,7 @@
; D000..E5F4 - persistent data structures (per-game cheat categories,
; gGlobalPrefsStore, gGamesListStore)
; ...unused...
; EA5C..FFF9 - main program code
; EABB..FFF9 - main program code
; FFFA..FFFF - NMI, reset, IRQ vectors
;
; LC RAM BANK 2

View File

@ -74,21 +74,19 @@ GetGameDisplayName
PlayGameFromSearch
PlayGameFromBrowse
; in: X = game index
stx +
+LDADDR gGamesListStore
jsr okvs_nth
!word gGamesListStore
+ !byte $FD ; SMC
; A/Y = address of game filename
jmp .Go
bne .Go ; always branches
PlayGameFromAttract
; in: none
jsr LoadAndParseAttractModeConf
+LDADDR gAttractModeStore
gCurrentAttractIndex=*+1
ldx #$FD ; set in MegaAttractMode
jsr okvs_nth ; get filename of current attract-mode module
!word gAttractModeStore
gCurrentAttractIndex
!byte $FD ; set in MegaAttractMode
+STAY @key
jsr okvs_get
!word gAttractModeStore
@ -109,10 +107,11 @@ gCurrentAttractIndex
; we reached here by pressing <RETURN> during a slideshow
; gSlideshowStore is still in memory, and gCurrentlyVisibleSlideshowIndex
; is the index into gSlideshowStore of the picture that is being displayed
+LDADDR gSlideshowStore
gCurrentlyVisibleSlideshowIndex=*+1
ldx #$FD ; set in HGRTitleCallback, HGRActionCallback, DHGRTitleCallback
jsr okvs_nth
!word gSlideshowStore
gCurrentlyVisibleSlideshowIndex
!byte $FD ; set in HGRTitleCallback, HGRActionCallback, DHGRTitleCallback
+STAY @sskey
+STAY @sskey2
jsr okvs_get

View File

@ -64,15 +64,13 @@
;------------------------------------------------------------------------------
; okvs_init
;
; in: stack contains 2 bytes of parameters:
; +1 [word] handle to storage space
; in: A/Y = handle to storage space
; out: $00/$01 clobbered
; $02/$03 clobbered
; all registers clobbered
;------------------------------------------------------------------------------
okvs_init
+PARAMS_ON_STACK 2
jsr GetStoreAddress
jsr GetStoreAddressFromAY
; PTR -> store
; Y = 0
tya
@ -94,16 +92,15 @@ okvs_init
;------------------------------------------------------------------------------
; okvs_len
;
; in: stack contains 2 bytes of parameters:
; +1 [word] handle to storage space
; in: A/Y = handle to storage space
; out: A contains number of keys in this store
; X, Y clobbered
; X preserved
; Y clobbered
; $00/$01 clobbered
; $02/$03 clobbered
;------------------------------------------------------------------------------
okvs_len
+PARAMS_ON_STACK 2
jsr GetStoreAddress
jsr GetStoreAddressFromAY
; PTR -> store
; Y = 0
lda (PTR),y ; A = number of keys in store
@ -287,36 +284,6 @@ okvs_get
@fail sec
rts
;------------------------------------------------------------------------------
; okvs_nth
; get (N)th key
;
; in: stack contains 3 bytes of parameters:
; +1 [word] handle to storage space
; +3 [byte] numeric index
; out: A/Y = lo/hi address of nth key
; all other registers and flags clobbered
; $00/$01 clobbered
; $02/$03 clobbered
; $04/$05 clobbered
;------------------------------------------------------------------------------
okvs_nth
+PARAMS_ON_STACK 3
jsr GetStoreAddress
; PTR -> store
jsr incptr3
; PTR -> first record
ldy #3
lda (PARAM),y
tax ; X = numeric index of key to get
beq @found
- jsr derefptr
dex
bne -
@found jsr incptr2
+LDAY PTR
rts
;------------------------------------------------------------------------------
; okvs_next
; get (N+1)th key, with wraparound
@ -324,28 +291,46 @@ okvs_nth
; in: A/Y = handle to storage space
; X = record index
; out: A/Y = lo/hi address of (X+1)th key, or first key if X was the last record
; all other registers and flags clobbered
; PARAM clobbered
; PTR clobbered
; SRC clobbered
; X = next record index
; SAVE clobbered
; see okvs_nth for other exit conditions
;------------------------------------------------------------------------------
okvs_next
+STAY @store1
+STAY @store2
inx
stx SAVE
+STAY PARAM
jsr okvs_len
@store1 !word $FDFD ; SMC
cmp SAVE
beq +
lda SAVE
+HIDE_NEXT_2_BYTES
+ lda #0
sta @n
jsr okvs_nth
@store2 !word $FDFD ; SMC
@n !byte $FD ; SMC
bne +
ldx #$FF
+ inx
+LDAY PARAM
; execution falls through here
;------------------------------------------------------------------------------
; okvs_nth
; get (N)th key
;
; in: A/Y = handle to storage space
; X = record index
; out: A/Y = lo/hi address of nth key
; X preserved
; Z = 0
; all other flags clobbered
; PTR clobbered
;------------------------------------------------------------------------------
okvs_nth
jsr GetStoreAddressFromAY
; PTR -> store
jsr incptr3
; PTR -> first record
txa
pha
beq @found
- jsr derefptr
dex
bne -
@found jsr incptr2
pla
tax
+LDAY PTR
rts
;------------------------------------------------------------------------------
@ -475,6 +460,10 @@ incptr
inc PTR+1
+ rts
GetStoreAddressFromAY
+STAY PTR
jmp derefptr
GetStoreAddress
; in: PARAM = address of stack params (any PARAMS_ON_STACK macro will do this)
; out: PTR = address of store (always the first parameter on stack)

View File

@ -32,8 +32,8 @@ ParseKeyValueList
+PARAMS_ON_STACK 5
+LDPARAM 1
+STAY @store1
+STAY @store2
jsr okvs_init ; reset key/value store
+LDPARAM 3
+STAY $FE
@ -55,8 +55,6 @@ ParseKeyValueList
bcs +
dey
+ sty $FF
jsr okvs_init ; reset key/value store
@store1 !word $FDFD ; SMC
ldy #$00 ; index into ($FE) pointing to current character
@newkey ldx #$00 ; X = index into current key

View File

@ -28,8 +28,8 @@ ParseGamesList
+PARAMS_ON_STACK 4
+LDPARAM 1
+STAY @store1
+STAY @store2
jsr okvs_init ; reset key/value store
+LDPARAM 3
+STAY $FE
@ -47,8 +47,6 @@ ParseGamesList
bcs +
dey
+ sty $FF
jsr okvs_init ; reset key/value store
@store1 !word $FDFD ; SMC
ldy #$00 ; index into ($FE) pointing to current character
@newkey ldx #$00 ; X = index into current key

View File

@ -67,14 +67,13 @@ pref_get
+STAY @prefkey
+LDPARAM 3
+STAY @store1
+STAY @store2
jsr okvs_get ; look up pref key in prefs store
!word gGlobalPrefsStore
@prefkey !word $FDFD ; SMC
bcs .useDefaultValue ; if pref key is not found, use default value
ldx @store2+1
beq @done
ldx @store1+1
beq @done ; if no OKVS to validate against, we're done
+STAY +
+STAY PTR
ldy #0
@ -83,14 +82,12 @@ pref_get
jsr okvs_get ; check whether the pref value exists as a key in the passed-in store
@store1 !word $FDFD ; SMC
+ !word $FDFD ; SMC
bcc +
.useDefaultValue ; find first key in passed store and use that as a default value
bcc + ; found key, continue
.useDefaultValue ; did not find key, use first key in passed store as a default value
ldx #0
+ stx @n
+
+LDAY @store1
jsr okvs_nth
@store2 !word $FDFD ; SMC
@n !byte $FD ; SMC
ldx @n
@done rts
;------------------------------------------------------------------------------

View File

@ -73,7 +73,6 @@ DHGRSingle
!word gDFXStore
+STAY @filename ; A/Y = filename (don't load file yet)
; X = index of the transition in DFX store
+LDADDR gDFXStore
jsr okvs_next ; get transition after this one
+STAY +

View File

@ -177,7 +177,6 @@ HGRSingle
!word gFXStore
+STAY @filename ; A/Y = filename (don't load file yet)
; X = index of the transition in FX store
+LDADDR gFXStore
jsr okvs_next ; get transition after this one
+STAY +

View File

@ -68,15 +68,12 @@ MegaAttractMode
; assume all of main memory has been clobbered
;------------------------------------------------------------------------------
MiniAttractMode
stx +
+LDADDR gGamesListStore
jsr okvs_nth
+STAY @fname
jsr BlankHGR
jsr okvs_nth
!word gGamesListStore
+ !byte $FD ; SMC
+STAY @fname
lda #0
sta @MiniAttractIndex
@loop
@ -90,16 +87,15 @@ MiniAttractMode
!word -
!byte 0
+LDADDR gAttractModeStore
jsr okvs_len
!word gAttractModeStore
cmp @MiniAttractIndex
beq @exit ; we've run through all modules, so exit to caller
lda @MiniAttractIndex
sta +
@MiniAttractIndex=*+1
ldx #$FD ; SMC
+LDADDR gAttractModeStore
jsr okvs_nth ; get the next module on the list
!word gAttractModeStore
+ !byte $FD ; SMC
+STAY @key
jsr okvs_get ; get module type
@ -117,8 +113,6 @@ MiniAttractMode
lda KBD
bpl @loop
@exit rts
@MiniAttractIndex
!byte $FD
;------------------------------------------------------------------------------
; RunAttractModule

View File

@ -97,10 +97,8 @@ GameCount = *+1
ldx BrowseSelectedIndex
; execution falls through here
.OnBrowseChanged
stx @index
+LDADDR gGamesListStore
jsr okvs_nth ; get the name of the new game
!word gGamesListStore
@index !byte $FD
+STAY @key
+STAY @key2
jsr GetOffscreenAddress ; load new title screenshot offscreen
@ -134,11 +132,11 @@ GameCount = *+1
sta UI_ToPlay,x
dex
bpl -
ldx @index
jsr BuildUILine1WithNoDots ; build UI line 1 with bars and other shapes
ldx @index
jsr DrawSearchBarOffscreen ; actually draw the UI (offscreen)
jmp ShowOtherPage ; now show everything at once
ldx BrowseSelectedIndex
jsr BuildUILine1WithNoDots; build UI line 1 with bars and other shapes
ldx BrowseSelectedIndex
jsr DrawSearchBarOffscreen; actually draw the UI (offscreen)
jmp ShowOtherPage ; now show everything at once
;------------------------------------------------------------------------------

View File

@ -152,14 +152,12 @@ SearchMode
dec InputLength ; ignore the last key typed
jmp .OnError ; beep and return
+
lda BestMatchIndex ; check if the new best match is the same
cmp SelectedIndex ; as the current best match
ldx BestMatchIndex ; check if the new best match is the same
cpx SelectedIndex ; as the current best match
php ; (we'll use this later to skip reloading)
sta SelectedIndex
sta @index
stx SelectedIndex
+LDADDR gGamesListStore
jsr okvs_nth ; get the name of the new best match
!word gGamesListStore
@index !byte $FD
+STAY @key
+STAY @key2
plp