refactor okvs_nth

This commit is contained in:
4am 2019-09-20 19:27:16 -04:00
parent 7448f196d7
commit 634f8cd688
8 changed files with 70 additions and 87 deletions

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

@ -287,36 +287,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 +294,53 @@ 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
; X = next record index
; Z = 0
; all other flags clobbered
; PARAM clobbered
; PTR clobbered
; SRC clobbered
; SAVE clobbered
;------------------------------------------------------------------------------
okvs_next
+STAY @store1
+STAY @store2
inx
stx SAVE
jsr okvs_len
@store1 !word $FDFD ; SMC
ldx SAVE
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 #0
+
+LDAY @store1
; 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 +470,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

@ -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
@ -95,11 +92,10 @@ MiniAttractMode
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