mirror of
https://github.com/a2-4am/4cade.git
synced 2024-11-27 08:50:01 +00:00
refactor GetStoreAddress
This commit is contained in:
parent
003b6ad6f0
commit
a88f70f150
@ -9,7 +9,7 @@
|
|||||||
; D000..E4E9 - persistent data structures (gGlobalPrefsStore, gGamesListStore)
|
; D000..E4E9 - persistent data structures (gGlobalPrefsStore, gGamesListStore)
|
||||||
; ...end of data and start of code are approximate, in between is unused...
|
; ...end of data and start of code are approximate, in between is unused...
|
||||||
; ...if they ever overlap, things will go boom...
|
; ...if they ever overlap, things will go boom...
|
||||||
; E9FF..FFF9 - main program code
|
; EA09..FFF9 - main program code
|
||||||
; FFFA..FFFF - NMI, reset, IRQ vectors
|
; FFFA..FFFF - NMI, reset, IRQ vectors
|
||||||
;
|
;
|
||||||
; LC RAM BANK 2
|
; LC RAM BANK 2
|
||||||
|
74
src/okvs.a
74
src/okvs.a
@ -72,20 +72,20 @@
|
|||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
okvs_init
|
okvs_init
|
||||||
+PARAMS_ON_STACK 2
|
+PARAMS_ON_STACK 2
|
||||||
jsr SetPTRFromStackParams
|
jsr GetStoreAddress
|
||||||
ldy #0
|
; PTR -> store
|
||||||
|
; Y = 0
|
||||||
tya
|
tya
|
||||||
sta (PTR),y ; set number of keys
|
sta (PTR),y ; set number of keys in store to 0
|
||||||
|
|
||||||
iny ; set initial free space pointer
|
iny ; set next-free-space pointer to store + 3
|
||||||
ldx PTR+1
|
ldx PTR+1
|
||||||
lda PTR
|
lda PTR
|
||||||
clc
|
clc
|
||||||
adc #$03
|
adc #$03
|
||||||
bcc +
|
bcc +
|
||||||
inx
|
inx
|
||||||
+
|
+ sta (PTR),y
|
||||||
sta (PTR),y
|
|
||||||
iny
|
iny
|
||||||
txa
|
txa
|
||||||
sta (PTR),y
|
sta (PTR),y
|
||||||
@ -103,9 +103,10 @@ okvs_init
|
|||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
okvs_len
|
okvs_len
|
||||||
+PARAMS_ON_STACK 2
|
+PARAMS_ON_STACK 2
|
||||||
jsr SetPTRFromStackParams
|
jsr GetStoreAddress
|
||||||
ldy #0
|
; PTR -> store
|
||||||
lda (PTR),y
|
; Y = 0
|
||||||
|
lda (PTR),y ; A = number of keys in store
|
||||||
rts
|
rts
|
||||||
|
|
||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
@ -124,14 +125,15 @@ okvs_len
|
|||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
okvs_append
|
okvs_append
|
||||||
+PARAMS_ON_STACK 7
|
+PARAMS_ON_STACK 7
|
||||||
jsr SetPTRFromStackParams
|
jsr GetStoreAddress
|
||||||
ldy #0
|
; PTR -> store
|
||||||
lda (PTR),y
|
; Y = 0
|
||||||
|
lda (PTR),y ; A = number of keys in store
|
||||||
clc
|
clc
|
||||||
adc #1
|
adc #1
|
||||||
sta (PTR),y ; increment number of keys
|
sta (PTR),y ; increment number of keys
|
||||||
iny
|
iny
|
||||||
lda (PTR),y
|
lda (PTR),y ; get address of next free space
|
||||||
pha
|
pha
|
||||||
iny
|
iny
|
||||||
lda (PTR),y
|
lda (PTR),y
|
||||||
@ -200,10 +202,11 @@ okvs_append
|
|||||||
iny
|
iny
|
||||||
lda SRC+1
|
lda SRC+1
|
||||||
sta (PTR),y
|
sta (PTR),y
|
||||||
jsr SetPTRFromStackParams ; update next-free-space pointer in head of okvs
|
jsr GetStoreAddress
|
||||||
|
; PTR -> store
|
||||||
ldy #1
|
ldy #1
|
||||||
lda SRC
|
lda SRC
|
||||||
sta (PTR),y
|
sta (PTR),y ; update next-free-space pointer in head
|
||||||
iny
|
iny
|
||||||
lda SRC+1
|
lda SRC+1
|
||||||
sta (PTR),y
|
sta (PTR),y
|
||||||
@ -226,11 +229,12 @@ okvs_append
|
|||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
okvs_get
|
okvs_get
|
||||||
+PARAMS_ON_STACK 4
|
+PARAMS_ON_STACK 4
|
||||||
jsr SetPTRFromStackParams
|
jsr GetStoreAddress
|
||||||
ldy #0
|
; PTR -> store
|
||||||
lda (PTR),y
|
; Y = 0
|
||||||
|
lda (PTR),y ; A = number of keys in store
|
||||||
beq @fail ; no keys, fail immediately
|
beq @fail ; no keys, fail immediately
|
||||||
sta @maxkeys ; A = number of keys
|
sta @maxkeys
|
||||||
jsr incptr3
|
jsr incptr3
|
||||||
; PTR -> first record
|
; PTR -> first record
|
||||||
ldx #0
|
ldx #0
|
||||||
@ -293,7 +297,8 @@ okvs_get
|
|||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
okvs_nth
|
okvs_nth
|
||||||
+PARAMS_ON_STACK 3
|
+PARAMS_ON_STACK 3
|
||||||
jsr SetPTRFromStackParams
|
jsr GetStoreAddress
|
||||||
|
; PTR -> store
|
||||||
jsr incptr3
|
jsr incptr3
|
||||||
; PTR -> first record
|
; PTR -> first record
|
||||||
ldy #3
|
ldy #3
|
||||||
@ -366,15 +371,16 @@ okvs_update
|
|||||||
; $00/$01 clobbered
|
; $00/$01 clobbered
|
||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
okvs_iter
|
okvs_iter
|
||||||
lda #$D0
|
lda #$D0 ; 'BNE' opcode
|
||||||
+HIDE_NEXT_2_BYTES
|
+HIDE_NEXT_2_BYTES
|
||||||
okvs_iter_values
|
okvs_iter_values
|
||||||
lda #$24
|
lda #$24 ; 'BIT' opcode
|
||||||
sta @branch
|
sta @branch
|
||||||
+PARAMS_ON_STACK 4
|
+PARAMS_ON_STACK 4
|
||||||
jsr SetPTRFromStackParams
|
jsr GetStoreAddress
|
||||||
ldy #0
|
; PTR -> store
|
||||||
lda (PTR),y
|
; Y = 0
|
||||||
|
lda (PTR),y ; A = number of keys in store
|
||||||
beq @exit ; no keys, exit immediately
|
beq @exit ; no keys, exit immediately
|
||||||
sta @max
|
sta @max
|
||||||
+LDPARAM 3
|
+LDPARAM 3
|
||||||
@ -383,8 +389,9 @@ okvs_iter_values
|
|||||||
; PTR -> first record
|
; PTR -> first record
|
||||||
ldx #0
|
ldx #0
|
||||||
@loop
|
@loop
|
||||||
lda #2
|
lda #2 ; for iter, skip length = 2
|
||||||
@branch bne + ; SMC
|
@branch bne + ; SMC (iter_values puts a BIT here, so no branch)
|
||||||
|
; for iter_values, skip length = length(key) + 2 + 1
|
||||||
ldy #2
|
ldy #2
|
||||||
lda (PTR),y ; A = length of key
|
lda (PTR),y ; A = length of key
|
||||||
clc
|
clc
|
||||||
@ -432,7 +439,9 @@ incptr
|
|||||||
inc PTR+1
|
inc PTR+1
|
||||||
+ rts
|
+ rts
|
||||||
|
|
||||||
SetPTRFromStackParams
|
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)
|
||||||
; preserves X
|
; preserves X
|
||||||
ldy #1
|
ldy #1
|
||||||
lda (PARAM),y
|
lda (PARAM),y
|
||||||
@ -442,13 +451,14 @@ SetPTRFromStackParams
|
|||||||
sta PTR+1 ; PTR -> first parameter on stack
|
sta PTR+1 ; PTR -> first parameter on stack
|
||||||
; execution falls through here
|
; execution falls through here
|
||||||
derefptr
|
derefptr
|
||||||
|
; out: Y = 0
|
||||||
; preserves X
|
; preserves X
|
||||||
ldy #0
|
ldy #1
|
||||||
lda (PTR),y
|
lda (PTR),y
|
||||||
pha
|
pha
|
||||||
iny
|
dey
|
||||||
lda (PTR),y
|
lda (PTR),y
|
||||||
sta PTR+1
|
|
||||||
pla
|
|
||||||
sta PTR
|
sta PTR
|
||||||
|
pla
|
||||||
|
sta PTR+1
|
||||||
rts
|
rts
|
||||||
|
Loading…
Reference in New Issue
Block a user