shave some bytes

This commit is contained in:
4am 2021-10-27 13:06:04 -04:00
parent f77bf4fb3b
commit e2a907e75b
9 changed files with 68 additions and 89 deletions

View File

@ -159,7 +159,9 @@ index: md asmfx asmprelaunch
# precompute indexed files for slideshows # precompute indexed files for slideshows
# #
[ -f build/SLIDESHOW.IDX ] || ((for f in res/SS/*; do \ [ -f build/SLIDESHOW.IDX ] || ((for f in res/SS/*; do \
bin/buildokvs.sh < "$$f" > "build/SS/$$(basename $$f)"; \ [ $$(echo "$$(basename $$f)" | cut -c-3) = "ACT" ] && \
bin/buildaction.sh build/DISPLAY.CONF < "$$f" > "build/SS/$$(basename $$f)" || \
bin/buildokvs.sh < "$$f" > "build/SS/$$(basename $$f)"; \
echo "$$(basename $$f)"; \ echo "$$(basename $$f)"; \
done) | bin/buildindexedfile.sh -p -a build/TOTAL.DATA build/SS > build/SLIDESHOW.IDX) done) | bin/buildindexedfile.sh -p -a build/TOTAL.DATA build/SS > build/SLIDESHOW.IDX)
[ -f build/MINIATTRACT.IDX ] || ((for f in res/ATTRACT/*; do \ [ -f build/MINIATTRACT.IDX ] || ((for f in res/ATTRACT/*; do \

31
bin/buildaction.sh Executable file
View File

@ -0,0 +1,31 @@
#!/bin/bash
# make temp file with just the key/value pairs (strip blank lines, comments, eof marker)
records=$(mktemp)
awk '!/^$|^#|^\[/' > "$records"
# make temp assembly source file that represents the binary OKVS data structure
source=$(mktemp)
(echo "*=0" # dummy program counter for assembler
echo "!le16 $(wc -l <"$records"), 0" # OKVS header
while IFS="=" read -r key value; do
[ -n "$value" ] && filename="$value" || filename="$key"
displayname=$(awk -F= '/,'"$filename"'=/ { print $2 }' "$1")
echo "!byte ${#key}+${#value}+${#displayname}+4" # OKVS record length
echo "!byte ${#key}" # OKVS key length
echo "!text \"$key\"" # OKVS key
echo "!byte ${#value}" # OKVS value length
echo "!text \"$value\"" # OKVS value
echo "!byte ${#displayname}"
echo "!text \"$displayname\""
done < "$records") > "$source"
# assemble temp source file into binary OKVS data structure, then output that
out=$(mktemp)
acme -o "$out" "$source"
cat "$out"
# clean up
rm "$out"
rm "$source"
rm "$records"

View File

@ -6,8 +6,9 @@
; YE OLDE GRAND UNIFIED MEMORY MAP ; YE OLDE GRAND UNIFIED MEMORY MAP
; ;
; LC RAM BANK 1 ; LC RAM BANK 1
; D000..E7FE - persistent data structures (gGlobalPrefsStore, gGamesListStore) ; D000..E2F8 - persistent data structures (gGlobalPrefsStore, gGamesListStore)
; E9EE..FFEE - main program code ; ...unused...
; EA2A..FFEE - main program code
; FFEF..FFF9 - API functions and global constants available for main program ; FFEF..FFF9 - API functions and global constants available for main program
; code, prelaunchers, transition effects, &c. ; code, prelaunchers, transition effects, &c.
; (LoadFileDirect, Wait/UnwaitForVBL, MockingboardStuff, MachineStatus) ; (LoadFileDirect, Wait/UnwaitForVBL, MockingboardStuff, MachineStatus)

View File

@ -94,91 +94,32 @@ GlueLaunchRTS
; check if an arbitrary game exists, for some definition of 'exists', while ; check if an arbitrary game exists, for some definition of 'exists', while
; in the middle of a slideshow ; in the middle of a slideshow
; ;
; /!\ This function assumes that gSlideshowStore exists and is populated, ; in: A/Y points to a key in gSlideshowStore
; which is generally only true during the callback function of a slideshow
;
; in: A/Y points to game filename
; out: C clear if game exists, and ; out: C clear if game exists, and
; $WINDEX = game index, and ; $WINDEX = game index, and
; A/Y points to game display name + game info bitfield ; A/Y points to game display name
; C set if game can't be found by any means ; C set if game can't be found by any means
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
FindGameInActionSlideshow FindGameInActionSlideshow
+ST16 @sskey +ST16 @slideshowKey
jsr FindGame jsr FindGame
bcc GetGameDisplayName bcc @GetGameDisplayName
; if the game was not found, try getting the value of the current record from ; if the game was not found, try getting the value of the current record from
; gSlideshowStore (some games have multiple action screenshots, in which case ; gSlideshowStore (some games have multiple action screenshots, in which case
; the key is only the screenshot filename, and the value is the actual game ; the key is only the screenshot filename, and the value is the actual game
; filename) ; filename)
jsr okvs_get jsr okvs_get
!word gSlideshowStore !word gSlideshowStore
@sskey !word $FDFD ; SMC @slideshowKey
!word $FDFD ; SMC
jsr FindGame jsr FindGame
bcs GlueLaunchRTS bcs GlueLaunchRTS
; /!\ execution falls through here to GetGameDisplayName
;------------------------------------------------------------------------------ @GetGameDisplayName
; GetGameDisplayName +LD16 @slideshowKey
; lookup or construct the display name for a specific game jsr okvs_get_current
; jsr okvs_get_current_PTR_is_already_set
; in: A/Y contains address of a key in gGamesListStore
; out: A/Y contains address of game display name + game info bitfield
; (this might be just the corresponding value in gGamesListStore,
; or it might be a temporary buffer in main memory that we constructed
; out of thin air)
; gValLen possibly clobbered (up to gValLen+MaxInputLength)
; X preserved
; C clear
;------------------------------------------------------------------------------
GetGameDisplayName
+ST16 SAVE
jsr okvs_get_current ; get value for this key
; (PTR) -> truncated game display name + info bitfield
; Y = 0
lda (PTR), y ; A = length of truncated game display name + info bitfield
lsr ;;cmp #1 ; 1 means there's no title, just info bitfield (1 byte)
beq +
+LD16 PTR +LD16 PTR
clc
rts
+ ; game display name is truncated, we must expand it
iny ; Y = 1
lda (PTR), y ; A = game info bitfield
pha ; save on stack
dey
lda (SAVE), y ; A = length of key
tay
iny
sty @len
sty gValLen
lda #$24 ; BIT opcode
sta @or ; first character remains capitalized
ldy #1
- lda (SAVE), y
cmp #$49 ; 'I'
bne +
cmp gValLen-1,y
beq ++ ; preserve 'II' casing
+ cmp #$2E
bne @or
lda #$20 ; convert '.' to ' '
@or ora #$20 ; SMC (opcode)
++ sta gValLen, y
cmp #$20
bne +
lda #$24 ; first character after ' ' remains capitalized
+HIDE_NEXT_2_BYTES
+ lda #$09 ; OR opcode
sta @or
@next iny
@len=*+1
cpy #$FD ; SMC
bne -
pla
sta gValLen, y
+LDADDR gValLen
clc
rts rts
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------

View File

@ -395,6 +395,7 @@ okvs_iter_values
okvs_get_current okvs_get_current
; out: Y = 0 ; out: Y = 0
+ST16 PTR +ST16 PTR
okvs_get_current_PTR_is_already_set
jsr stepptr jsr stepptr
bne incptr bne incptr

View File

@ -85,10 +85,11 @@ ParseGamesList
@gatherValue @gatherValue
jsr IncAndGetChar jsr IncAndGetChar
cmp #$0A ; CR ends the value cmp #$0A ; CR ends the value
beq @endValue bne @gatherValue
sta gVal,x ; beq @endValue
inx ; sta gVal,x
bpl @gatherValue ; inx
; bpl @gatherValue
@endValue @endValue
pla ; pop cheat category pla ; pop cheat category
sta gVal,x ; store after game display name sta gVal,x ; store after game display name

View File

@ -215,7 +215,7 @@ DHGRActionCallback
; can't be played due to memory or joystick requirements, so we hide ; can't be played due to memory or joystick requirements, so we hide
; it from slideshows ; it from slideshows
bcs DHGRRTS bcs DHGRRTS
+ST16 SAVE ; (SAVE) -> game display name + game info bitfield +ST16 SAVE ; (SAVE) -> game display name
+LD16 WINDEX ; save game index in case user hits RETURN +LD16 WINDEX ; save game index in case user hits RETURN
+ST16 gGameToLaunch ; while it's visible (we'll launch it) +ST16 gGameToLaunch ; while it's visible (we'll launch it)
@ -245,18 +245,17 @@ DrawGameTitleInActionSlideshow
sta VTAB sta VTAB
lda #0 ; solid horizontal bar character lda #0 ; solid horizontal bar character
jsr @resetline jsr @resetline
lda (SAVE),y ; (SAVE) -> game display name, Y = 0, so A = display length + 1 lda (SAVE),y ; (SAVE) -> game display name, Y = 0, so A = display length
clc clc
adc #$02 adc #$03
sta gPathname sta gPathname
lda #7 ; top-right rounded corner character lda #7 ; top-right rounded corner character
jsr @drawline jsr @drawline
lda #" " lda #" "
jsr @resetline jsr @resetline
lda (SAVE),y ; A = display length + 1 lda (SAVE),y ; A = display length
tay tay
dey
- lda (SAVE),y - lda (SAVE),y
sta gPathname+1,y sta gPathname+1,y
dey dey

View File

@ -147,7 +147,7 @@ HGRActionCallback
bcs HGRRTS bcs HGRRTS
; found the game ; found the game
+ST16 SAVE ; (SAVE) -> game display name + game info bitfield +ST16 SAVE ; (SAVE) -> game display name
+LD16 WINDEX ; save game index in case user hits RETURN +LD16 WINDEX ; save game index in case user hits RETURN
+ST16 gGameToLaunch ; while it's visible (we'll launch it) +ST16 gGameToLaunch ; while it's visible (we'll launch it)

View File

@ -124,16 +124,19 @@ DrawUI
jsr GetGameToLaunch ; get current game, if any jsr GetGameToLaunch ; get current game, if any
bcs @doneWithLine2 ; if no game, nothing more to do on UI line 2 bcs @doneWithLine2 ; if no game, nothing more to do on UI line 2
jsr GetGameDisplayName +ST16 @fname
; A/Y -> game display name + bitfield of game info jsr okvs_get_current
iny ; Y = 1
lda (PTR), y ; A = game info bitfield
sta gGameToLaunchInfo
jsr okvs_get
!word gSearchStore
@fname !word $FDFD ; SMC
+ST16 PTR +ST16 PTR
ldy #0 ldy #0
lda (PTR),y ; A = game display name length + 1 lda (PTR), y
sta SAVE sta SAVE
tay inc SAVE
lda (PTR),y ; A = game info bitfield
sta gGameToLaunchInfo
ldy #0
- iny - iny
@printCursor @printCursor
lda #$FD ; SMC lda #$FD ; SMC