refactor glue.zinfo with hybrid prefixed and suffixed strings, resize resume dialog based on slots in use

This commit is contained in:
4am 2018-04-17 13:17:55 -04:00
parent 42d4c858de
commit af84a96823
2 changed files with 83 additions and 127 deletions

View File

@ -102,14 +102,20 @@ zparse
jsr AddToPathWithHighBit ; add final piece of information (moves or time, depending on how we got here) jsr AddToPathWithHighBit ; add final piece of information (moves or time, depending on how we got here)
+LDADDR kRightParen +LDADDR kRightParen
jsr AddToPathWithHighBit ; add ')' jsr AddToPathWithHighBit ; add ')'
+LDADDR kNullByte
jsr AddToPath ; add 0x00
; execution falls through here ; execution falls through here
.saveAndMoveToNextSlot .saveAndMoveToNextSlot
plx plx
phx phx
txa
ora #$30
sta kSlotNumber
lda gPathname lda gPathname
beq + beq +
lda #1 lda #9
+ sta kSlotName ; set length of key (0 if value is empty, otherwise 8) + sta kSlotName ; set length of key (0 if value is empty, otherwise 9)
jsr okvs_append ; add this key/value to saved games store (used by ResumeDialog) jsr okvs_append ; add this key/value to saved games store (used by ResumeDialog)
!word gSavedGamesStore !word gSavedGamesStore
@ -138,8 +144,10 @@ kZINFOFilename
!raw "ZINFO.SYSTEM" !raw "ZINFO.SYSTEM"
kSlotName kSlotName
!byte 1 !byte 9
!text " " !text " Slot "
kSlotNumber
!text "x:",0 ; ends with null byte on purpose
kLeftParen kLeftParen
!byte 2 !byte 2
@ -148,6 +156,8 @@ kLeftParen
kRightParen kRightParen
!byte 1 !byte 1
!text ")" !text ")"
kNullByte
!byte 1,0
kSlash kSlash
!byte 1 !byte 1

View File

@ -69,18 +69,22 @@ ResumeDialog
jsr LoadSavedGameInfo jsr LoadSavedGameInfo
; TODO call ZINFO and calculate proper height lda gSavedGamesSlotsInUse
ldy #3 asl
sty kViewResumeFrame+3 ; frame top clc
iny adc #3
sty .resumeVTAB ; top of first radio button sta kViewResumeFrame+5 ; frame visible height = 3 + (2 * usedSlots)
sty kViewResumeOK+2 ; OK top sta kViewResumeFrame+7 ; frame height
iny lda #11
iny sec
sty kViewResumeCancel+2 ; Cancel top sbc gSavedGamesSlotsInUse
ldy #19 sta kViewResumeFrame+3 ; frame top = 11 - usedSlots
sty kViewResumeFrame+5 ; frame visible height inc
sty kViewResumeFrame+7 ; frame height sta iResumeVTAB ; top of first radio button
sta kViewResumeOK+2 ; OK top
inc
inc
sta kViewResumeCancel+2 ; Cancel top
jsr CreateDialog jsr CreateDialog
!word kViewResumeFrame !word kViewResumeFrame
@ -95,6 +99,8 @@ ResumeDialog
!word gSavedGamesStore !word gSavedGamesStore
!word CreateResumeRadioCallback !word CreateResumeRadioCallback
lda iResumeVTAB
sta kViewResumeNewGameTop
jsr CreateRadio jsr CreateRadio
!word kViewResumeNewGame !word kViewResumeNewGame
@ -120,7 +126,7 @@ ResumeDialog
jsr WeeGUI jsr WeeGUI
lda #1 ; WeeGUI radio buttons are limited to 15 characters, so we lda #1 ; WeeGUI radio buttons are limited to 15 characters, so we
sta .resumeVTAB ; print the longer labels separately sta iResumeVTAB ; print the longer labels separately
jsr okvs_iter_values jsr okvs_iter_values
!word gSavedGamesStore !word gSavedGamesStore
!word PrintResumeLabelCallback !word PrintResumeLabelCallback
@ -138,45 +144,57 @@ ResumeDialog
; internal functions ; internal functions
CreateResumeRadioCallback CreateResumeRadioCallback
; called via okvs_iter
; X = index (0-based) into gSavedGamesStore, which is also the slot number ; X = index (0-based) into gSavedGamesStore, which is also the slot number
; A/Y points to caption (length-prefixed, 0 if slot is unused and should be skipped) ; A/Y points to okvs record key, which we use as the radio button caption
; (length-prefixed and null-terminated, length=0 if slot is unused and should be skipped)
; ;
+STAY SAVE +STAY PTR
lda (SAVE) lda (PTR)
sta gResumeViewInUse+1,x ; mark whether this view is in use (hotkeys activate based on this array) sta gResumeViewInUse+1,x ; mark whether this view is in use (hotkeys activate based on this array)
beq .createResumeRadioDone; 0-length key means this slot is unused, so we're done beq .createResumeRadioDone; length=0 means this slot is unused, so we're done
txa
asl lda PTR
tax inc ; skip over length byte
lda kViewResumeArray,x bne +
ldy kViewResumeArray+1,x iny
+STAY + +
+STAY SRC +STAY kViewResumeRadioCaption ; A/Y -> null-terminated string, which is what WeeGUI wants
ldy #2 inx
lda .resumeVTAB stx kViewResumeRadioSlot ; WeeGUI view ID = X + 1
sta (SRC),y ; radio button top = frame top + 1 + (2 * X) lda iResumeVTAB
sta kViewResumeRadioTop ; radio button top = frame top + 1 + (2 * X)
jsr CreateRadio ; create radio button for this version (will print label later) jsr CreateRadio ; create radio button for this version (will print label later)
+ !word $FDFD ; SMC !word kViewResumeRadio
inc .resumeVTAB inc iResumeVTAB
inc .resumeVTAB inc iResumeVTAB
.createResumeRadioDone .createResumeRadioDone
rts rts
PrintResumeLabelCallback PrintResumeLabelCallback
+STAY SAVE ; called via okvs_iter_values
lda (SAVE) ; X = index (0-based) into gSavedGamesStore, which is also the slot number
beq .printVersionLabelDone ; A/Y points to okvs record value, which we use as a printable label
ldx #44 ; (length-prefixed and null-terminated, length=0 if slot is unused and should be skipped)
lda SAVE +STAY PTR
jsr CreateNullTerminatedString lda (PTR)
beq .printResumeLabelDone ; length=0 means this slot is unused, so we're done
lda PTR
inc ; skip over length byte
bne +
iny
+
+STAY .printResumeLabel ; A/Y -> null-terminated string
jsr PrintAt jsr PrintAt
!byte 13 ; htab (constant) !byte 14 ; htab (constant)
.resumeVTAB iResumeVTAB
!byte $FD ; SMC !byte $FD ; SMC
!word kNullTerminatedBuffer .printResumeLabel
inc .resumeVTAB !word $FDFD ; SMC
inc .resumeVTAB inc iResumeVTAB
.printVersionLabelDone inc iResumeVTAB
.printResumeLabelDone
rts rts
HandleResumeKey HandleResumeKey
@ -224,94 +242,22 @@ kViewResumeCancel
!word callback_resume_cancel ; callback !word callback_resume_cancel ; callback
!word kStringCancel ; caption !word kStringCancel ; caption
kViewResumeArray kViewResumeRadio ; reused for each slot
!word kViewResumeSlot0 kViewResumeRadioSlot
!word kViewResumeSlot1 !byte $FD ; view ID (SMC)
!word kViewResumeSlot2
!word kViewResumeSlot3
!word kViewResumeSlot4
!word kViewResumeSlot5
!word kViewResumeSlot6
!word kViewResumeSlot7
kViewResumeSlot0
!byte ID_RESUME_SLOT0 ; view ID
!byte 8 ; left !byte 8 ; left
!byte 4 ; top kViewResumeRadioTop
!word kStringSlot0 ; caption !byte $FD ; top (SMC)
kViewResumeRadioCaption
kViewResumeSlot1 !word $FDFD ; caption (SMC)
!byte ID_RESUME_SLOT1 ; view ID
!byte 8 ; left
!byte 6 ; top
!word kStringSlot1 ; caption
kViewResumeSlot2
!byte ID_RESUME_SLOT2 ; view ID
!byte 8 ; left
!byte 8 ; top
!word kStringSlot2 ; caption
kViewResumeSlot3
!byte ID_RESUME_SLOT3 ; view ID
!byte 8 ; left
!byte 10 ; top
!word kStringSlot3 ; caption
kViewResumeSlot4
!byte ID_RESUME_SLOT4 ; view ID
!byte 8 ; left
!byte 12 ; top
!word kStringSlot4 ; caption
kViewResumeSlot5
!byte ID_RESUME_SLOT5 ; view ID
!byte 8 ; left
!byte 14 ; top
!word kStringSlot5 ; caption
kViewResumeSlot6
!byte ID_RESUME_SLOT6 ; view ID
!byte 8 ; left
!byte 16 ; top
!word kStringSlot6 ; caption
kViewResumeSlot7
!byte ID_RESUME_SLOT7 ; view ID
!byte 8 ; left
!byte 18 ; top
!word kStringSlot7 ; caption
kViewResumeNewGame kViewResumeNewGame
!byte ID_RESUME_NEWGAME ; view ID !byte ID_RESUME_NEWGAME ; view ID
!byte 8 ; left !byte 8 ; left
!byte 20 ; top kViewResumeNewGameTop
!byte $FD ; top (SMC)
!word kStringNewGame ; caption !word kStringNewGame ; caption
kStringSlot0
!text " Slot ",$30,":",0
kStringSlot1
!text " Slot ",$31,":",0
kStringSlot2
!text " Slot ",$32,":",0
kStringSlot3
!text " Slot ",$33,":",0
kStringSlot4
!text " Slot ",$34,":",0
kStringSlot5
!text " Slot ",$35,":",0
kStringSlot6
!text " Slot ",$36,":",0
kStringSlot7
!text " Slot ",$37,":",0
kStringNewGame kStringNewGame
!text " Start ",110,"ew game",0 !text " Start ",110,"ew game",0
} }