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,6 +159,8 @@ index: md asmfx asmprelaunch
# precompute indexed files for slideshows
#
[ -f build/SLIDESHOW.IDX ] || ((for f in res/SS/*; do \
[ $$(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)"; \
done) | bin/buildindexedfile.sh -p -a build/TOTAL.DATA build/SS > build/SLIDESHOW.IDX)

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
;
; LC RAM BANK 1
; D000..E7FE - persistent data structures (gGlobalPrefsStore, gGamesListStore)
; E9EE..FFEE - main program code
; D000..E2F8 - persistent data structures (gGlobalPrefsStore, gGamesListStore)
; ...unused...
; EA2A..FFEE - main program code
; FFEF..FFF9 - API functions and global constants available for main program
; code, prelaunchers, transition effects, &c.
; (LoadFileDirect, Wait/UnwaitForVBL, MockingboardStuff, MachineStatus)

View File

@ -94,91 +94,32 @@ GlueLaunchRTS
; check if an arbitrary game exists, for some definition of 'exists', while
; in the middle of a slideshow
;
; /!\ This function assumes that gSlideshowStore exists and is populated,
; which is generally only true during the callback function of a slideshow
;
; in: A/Y points to game filename
; in: A/Y points to a key in gSlideshowStore
; out: C clear if game exists, 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
;------------------------------------------------------------------------------
FindGameInActionSlideshow
+ST16 @sskey
+ST16 @slideshowKey
jsr FindGame
bcc GetGameDisplayName
bcc @GetGameDisplayName
; 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
; the key is only the screenshot filename, and the value is the actual game
; filename)
jsr okvs_get
!word gSlideshowStore
@sskey !word $FDFD ; SMC
@slideshowKey
!word $FDFD ; SMC
jsr FindGame
bcs GlueLaunchRTS
; /!\ execution falls through here to GetGameDisplayName
;------------------------------------------------------------------------------
; GetGameDisplayName
; lookup or construct the display name for a specific game
;
; 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 +
@GetGameDisplayName
+LD16 @slideshowKey
jsr okvs_get_current
jsr okvs_get_current_PTR_is_already_set
+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
;------------------------------------------------------------------------------

View File

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

View File

@ -85,10 +85,11 @@ ParseGamesList
@gatherValue
jsr IncAndGetChar
cmp #$0A ; CR ends the value
beq @endValue
sta gVal,x
inx
bpl @gatherValue
bne @gatherValue
; beq @endValue
; sta gVal,x
; inx
; bpl @gatherValue
@endValue
pla ; pop cheat category
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
; it from slideshows
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
+ST16 gGameToLaunch ; while it's visible (we'll launch it)
@ -245,18 +245,17 @@ DrawGameTitleInActionSlideshow
sta VTAB
lda #0 ; solid horizontal bar character
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
adc #$02
adc #$03
sta gPathname
lda #7 ; top-right rounded corner character
jsr @drawline
lda #" "
jsr @resetline
lda (SAVE),y ; A = display length + 1
lda (SAVE),y ; A = display length
tay
dey
- lda (SAVE),y
sta gPathname+1,y
dey

View File

@ -147,7 +147,7 @@ HGRActionCallback
bcs HGRRTS
; 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
+ST16 gGameToLaunch ; while it's visible (we'll launch it)

View File

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