mirror of
https://github.com/a2-4am/4cade.git
synced 2024-11-27 08:50:01 +00:00
shave one byte per game(!) and a bit more
This commit is contained in:
parent
f197debcbe
commit
488aaf99c2
@ -379,7 +379,10 @@ CopyDevs
|
|||||||
!word gGlobalPrefsStore
|
!word gGlobalPrefsStore
|
||||||
!word -
|
!word -
|
||||||
!byte 16
|
!byte 16
|
||||||
+LD16 SRC ; (SRC) points to free space after the OKVS data structure we just created
|
+LD16 SAVE
|
||||||
|
+ST16 PTR
|
||||||
|
jsr stepptr
|
||||||
|
+LD16 PTR ; (PTR) points to free space after the OKVS data structure we just created
|
||||||
+ST16 gGamesListStore ; save pointer to free space for next store
|
+ST16 gGamesListStore ; save pointer to free space for next store
|
||||||
|
|
||||||
jsr LoadFile ; load games list file into $8200
|
jsr LoadFile ; load games list file into $8200
|
||||||
@ -391,6 +394,9 @@ CopyDevs
|
|||||||
!word -
|
!word -
|
||||||
|
|
||||||
!ifndef RELEASE {
|
!ifndef RELEASE {
|
||||||
|
+LD16 SAVE
|
||||||
|
+ST16 PTR
|
||||||
|
jsr stepptr
|
||||||
+READ_ROM_NO_WRITE
|
+READ_ROM_NO_WRITE
|
||||||
lda #40
|
lda #40
|
||||||
sta $21
|
sta $21
|
||||||
@ -398,9 +404,9 @@ CopyDevs
|
|||||||
sta $24
|
sta $24
|
||||||
dec $25
|
dec $25
|
||||||
jsr $FC22
|
jsr $FC22
|
||||||
lda SRC+1
|
lda PTR+1
|
||||||
jsr $FDDA
|
jsr $FDDA
|
||||||
lda SRC
|
lda PTR
|
||||||
jsr $FDDA
|
jsr $FDDA
|
||||||
+READ_RAM1_WRITE_RAM1
|
+READ_RAM1_WRITE_RAM1
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
; YE OLDE GRAND UNIFIED MEMORY MAP
|
; YE OLDE GRAND UNIFIED MEMORY MAP
|
||||||
;
|
;
|
||||||
; LC RAM BANK 1
|
; LC RAM BANK 1
|
||||||
; D000..E90F - persistent data structures (gGlobalPrefsStore, gGamesListStore)
|
; D000..E790 - persistent data structures (gGlobalPrefsStore, gGamesListStore)
|
||||||
; E92D..FFF1 - main program code
|
; E93F..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)
|
||||||
|
108
src/okvs.a
108
src/okvs.a
@ -1,5 +1,5 @@
|
|||||||
;license:MIT
|
;license:MIT
|
||||||
;(c) 2018-2020 by 4am
|
;(c) 2018-2020 by 4am/qkumba
|
||||||
;
|
;
|
||||||
; Ordered key/value store (6502 compatible)(256+ records compatible)
|
; Ordered key/value store (6502 compatible)(256+ records compatible)
|
||||||
;
|
;
|
||||||
@ -34,10 +34,10 @@
|
|||||||
; There is no range checking because this is assembly.
|
; There is no range checking because this is assembly.
|
||||||
|
|
||||||
; All functions take the starting address of the store's data buffer in
|
; All functions take the starting address of the store's data buffer in
|
||||||
; memory, so there can be multiple independent stores at one time. The next-
|
; memory, so there can be multiple independent stores at one time. Only the
|
||||||
; record pointers are actual memory addresses, so stores are not easily
|
; size of a record is stored, so stores are easily relocatable. append() will
|
||||||
; relocatable. append() will happily extend the store's data buffer without
|
; happily extend the store's data buffer without limit. There is no overflow
|
||||||
; limit. There is no overflow protection because this is assembly.
|
; protection because this is assembly.
|
||||||
;
|
;
|
||||||
; There is no sort() function.
|
; There is no sort() function.
|
||||||
;
|
;
|
||||||
@ -56,9 +56,9 @@
|
|||||||
; ...Record...
|
; ...Record...
|
||||||
;
|
;
|
||||||
; Record
|
; Record
|
||||||
; +0 next-record pointer (word)
|
; +0 record length (including this field)
|
||||||
; +2 key length
|
; +1 key length
|
||||||
; +3 key
|
; +2 key
|
||||||
; +K+2 value length (actual length, not max length)
|
; +K+2 value length (actual length, not max length)
|
||||||
; +K+3 value
|
; +K+3 value
|
||||||
; ... filler bytes up to value max length (set at append() time)
|
; ... filler bytes up to value max length (set at append() time)
|
||||||
@ -160,7 +160,7 @@ okvs_append
|
|||||||
stx SAVE
|
stx SAVE
|
||||||
; PTR -> new record
|
; PTR -> new record
|
||||||
; SAVE -> new record
|
; SAVE -> new record
|
||||||
jsr incptr2
|
jsr incptr
|
||||||
; PTR -> space for new key
|
; PTR -> space for new key
|
||||||
+LDPARAMPTR 3, SRC ; SRC -> new key to copy
|
+LDPARAMPTR 3, SRC ; SRC -> new key to copy
|
||||||
ldy #0
|
ldy #0
|
||||||
@ -188,8 +188,8 @@ okvs_append
|
|||||||
tay
|
tay
|
||||||
lda (SRC),y ; no max, use actual length instead
|
lda (SRC),y ; no max, use actual length instead
|
||||||
tax
|
tax
|
||||||
inx
|
+ inx
|
||||||
+ tay
|
tay
|
||||||
- lda (SRC),y
|
- lda (SRC),y
|
||||||
sta (PTR),y
|
sta (PTR),y
|
||||||
dey
|
dey
|
||||||
@ -199,27 +199,22 @@ okvs_append
|
|||||||
txa
|
txa
|
||||||
clc
|
clc
|
||||||
adc PTR
|
adc PTR
|
||||||
sta SRC
|
tax
|
||||||
bcc +
|
lda PTR+1
|
||||||
inc PTR+1
|
adc #0
|
||||||
+ lda PTR+1
|
pha
|
||||||
sta SRC+1 ; SRC -> byte after this record
|
+ jsr GetStoreAddress
|
||||||
+LD16 SAVE
|
|
||||||
+ST16 PTR ; PTR -> this record again
|
|
||||||
ldy #0
|
|
||||||
lda SRC ; update next-record pointer
|
|
||||||
sta (PTR),y
|
|
||||||
iny
|
|
||||||
lda SRC+1
|
|
||||||
sta (PTR),y
|
|
||||||
jsr GetStoreAddress
|
|
||||||
; PTR -> store
|
; PTR -> store
|
||||||
ldy #2
|
pla
|
||||||
lda SRC-2,y
|
ldy #3
|
||||||
sta (PTR),y ; update next-free-space pointer in head
|
sta (PTR),y ; update next-free-space pointer in head
|
||||||
iny
|
dey
|
||||||
lda SRC-2,y
|
txa
|
||||||
sta (PTR),y
|
sta (PTR),y
|
||||||
|
sec
|
||||||
|
sbc SAVE
|
||||||
|
ldy #0
|
||||||
|
sta (SAVE),y ; set record length
|
||||||
rts
|
rts
|
||||||
|
|
||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
@ -269,11 +264,12 @@ okvs_get
|
|||||||
sty KEYLEN
|
sty KEYLEN
|
||||||
@matchRecordLoop
|
@matchRecordLoop
|
||||||
+LD16 PTR
|
+LD16 PTR
|
||||||
clc
|
tax
|
||||||
adc #2
|
inx
|
||||||
bcc +
|
bne +
|
||||||
iny ; DEST -> key of this record
|
iny
|
||||||
+ +ST16 DEST
|
+ stx DEST ; DEST -> key of this record
|
||||||
|
sty DEST+1
|
||||||
ldy #0
|
ldy #0
|
||||||
@matchKeyLoop
|
@matchKeyLoop
|
||||||
lda (SRC),y
|
lda (SRC),y
|
||||||
@ -291,7 +287,7 @@ KEYLEN = *+1
|
|||||||
+LD16 PTR
|
+LD16 PTR
|
||||||
clc
|
clc
|
||||||
rts
|
rts
|
||||||
@next jsr derefptr ; PTR -> next record
|
@next jsr stepptr ; PTR -> next record
|
||||||
inc WINDEX
|
inc WINDEX
|
||||||
bne +
|
bne +
|
||||||
inc WINDEX+1
|
inc WINDEX+1
|
||||||
@ -305,17 +301,6 @@ KEYLEN = *+1
|
|||||||
@fail sec
|
@fail sec
|
||||||
rts
|
rts
|
||||||
|
|
||||||
okvs_get_current
|
|
||||||
+ST16 PTR
|
|
||||||
ldy #0
|
|
||||||
lda (PTR),y
|
|
||||||
clc
|
|
||||||
adc PTR
|
|
||||||
sta PTR
|
|
||||||
bcc +
|
|
||||||
inc PTR+1
|
|
||||||
+ jmp incptr
|
|
||||||
|
|
||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
; okvs_next
|
; okvs_next
|
||||||
; get (N+1)th key, with wraparound
|
; get (N+1)th key, with wraparound
|
||||||
@ -362,7 +347,7 @@ okvs_nth
|
|||||||
+LD16 WINDEX
|
+LD16 WINDEX
|
||||||
+ST16 SAVE
|
+ST16 SAVE
|
||||||
jmp @next
|
jmp @next
|
||||||
- jsr derefptr
|
- jsr stepptr
|
||||||
@next
|
@next
|
||||||
lda SAVE
|
lda SAVE
|
||||||
dec SAVE
|
dec SAVE
|
||||||
@ -372,7 +357,7 @@ okvs_nth
|
|||||||
dec SAVE+1
|
dec SAVE+1
|
||||||
tay
|
tay
|
||||||
bne -
|
bne -
|
||||||
jsr incptr2
|
jsr incptr
|
||||||
+LD16 PTR
|
+LD16 PTR
|
||||||
ldx #0
|
ldx #0
|
||||||
rts
|
rts
|
||||||
@ -467,13 +452,13 @@ okvs_iter_values
|
|||||||
sta WINDEX
|
sta WINDEX
|
||||||
sta WINDEX+1
|
sta WINDEX+1
|
||||||
@loop
|
@loop
|
||||||
lda #2 ; for iter, skip length = 2
|
lda #1 ; for iter, skip length = 1
|
||||||
@branch bne + ; SMC (iter_values puts a BIT here, so no branch)
|
@branch bne + ; SMC (iter_values puts a BIT here, so no branch)
|
||||||
; for iter_values, skip length = length(key) + 2 + 1
|
; for iter_values, skip length = length(key) + 1 + 1
|
||||||
tay ;;ldy #2
|
tay ;;ldy #1
|
||||||
lda (PTR),y ; A = length of key
|
lda (PTR),y ; A = length of key
|
||||||
clc
|
clc
|
||||||
adc #3 ; skip over pointer to next record (2 bytes) + key length (1 byte)
|
adc #2 ; skip over record length (1 byte) + key length (1 byte)
|
||||||
+ sta @skiplen
|
+ sta @skiplen
|
||||||
lda WCOUNT+1 ; save WCOUNT on stack
|
lda WCOUNT+1 ; save WCOUNT on stack
|
||||||
pha
|
pha
|
||||||
@ -508,7 +493,7 @@ okvs_iter_values
|
|||||||
sta WCOUNT
|
sta WCOUNT
|
||||||
pla
|
pla
|
||||||
sta WCOUNT+1
|
sta WCOUNT+1
|
||||||
jsr derefptr ; PTR -> next record
|
jsr stepptr ; PTR -> next record
|
||||||
inc WINDEX
|
inc WINDEX
|
||||||
bne +
|
bne +
|
||||||
inc WINDEX+1
|
inc WINDEX+1
|
||||||
@ -524,6 +509,11 @@ okvs_iter_values
|
|||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
; internal functions
|
; internal functions
|
||||||
|
|
||||||
|
okvs_get_current
|
||||||
|
+ST16 PTR
|
||||||
|
jsr stepptr
|
||||||
|
bne incptr
|
||||||
|
|
||||||
incptr4 jsr incptr2
|
incptr4 jsr incptr2
|
||||||
incptr2 jsr incptr
|
incptr2 jsr incptr
|
||||||
incptr
|
incptr
|
||||||
@ -560,3 +550,15 @@ derefptr
|
|||||||
pla
|
pla
|
||||||
sta PTR+1
|
sta PTR+1
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
stepptr
|
||||||
|
; out: Y = 0
|
||||||
|
; preserves X
|
||||||
|
ldy #0
|
||||||
|
lda (PTR),y
|
||||||
|
clc
|
||||||
|
adc PTR
|
||||||
|
sta PTR
|
||||||
|
bcc +
|
||||||
|
inc PTR+1
|
||||||
|
+ rts
|
||||||
|
Loading…
Reference in New Issue
Block a user