From d8645188e0e65e541dbe50cd387de0463116ab65 Mon Sep 17 00:00:00 2001 From: 4am Date: Thu, 19 Apr 2018 14:41:39 -0400 Subject: [PATCH] centralize gViewInUse, refactor out HandleUpDownRadio --- src/ui.common.a | 88 +++++++++++++++++++++++++++++++++++++++++++---- src/ui.main.a | 2 -- src/ui.options.a | 2 +- src/ui.resume.a | 42 ++++++++++------------ src/ui.versions.a | 74 +++++++-------------------------------- 5 files changed, 113 insertions(+), 95 deletions(-) diff --git a/src/ui.common.a b/src/ui.common.a index f3af2b2..e338ba2 100644 --- a/src/ui.common.a +++ b/src/ui.common.a @@ -21,6 +21,9 @@ ; - kStringCancel ; +gViewInUse + !byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + kStringOK !byte $0F ; 'O' inverse !byte 139,0 @@ -28,6 +31,10 @@ kStringCancel !byte $03 ; 'C' inverse !text "ancel",0 +; IDs of actions that do not correspond to WeeGUI view IDs have high bit set +ID_RADIO_PREVIOUS = $81 +ID_RADIO_NEXT = $82 + ;------------------------------------------------------------------------------ ; HardResetWeeGUI ; super-resets all WeeGUI views by creating 16 dummy views (which clears their @@ -44,6 +51,9 @@ HardResetWeeGUI +STAY PARAM0 - ldx #WGCreateView jsr WeeGUI ; create dummy views to reset state on all views + ldx @kHardResetDummyView + lda #0 + sta gViewInUse,x dec @kHardResetDummyView bpl - ldx #WGResetAll ; reset WeeGUI (destroys everything we just created) @@ -106,8 +116,11 @@ CreateButton @type=*+1 ldx #$FD ; SMC jsr WeeGUI - ldx #WGViewSetRawTitle + lda (PARAM0) + tax lda #1 + sta gViewInUse,x + ldx #WGViewSetRawTitle sta PARAM0 jmp WeeGUI @@ -128,6 +141,10 @@ CreateDialog +STAY PARAM0 ldx #WGCreateView ; create frame jsr WeeGUI + lda (PARAM0) + tax + lda #1 + sta gViewInUse,x +LDPARAM 3 +STAY PARAM0 @@ -212,18 +229,24 @@ SimulateClick ; WeeGUI has no way to query the type of a view, so this function takes the ; lower and upper IDs and all views within that range are presumed to be ; radio buttons. -; WeeGUI has no way to query if a view is in use, so all views within the -; given range are presumed to exist and be initialized properly. +; WeeGUI has no way to query if a view is in use, so each view within the +; given range must either (a) be in use, or (b) have had its state set to 0 +; (perhaps by calling HardResetWeeGUI earlier). ; ; in: WeeGUI initialized -; A contains WeeGUI view ID of first radio button -; Y contains 1 greater than the WeeGUI view ID of last radio button +; X = WeeGUI view ID of first radio button +; Y = WeeGUI view ID of last radio button ; out: C clear -> A contains WeeGUI view ID of selected radio button ; C set -> error, there is no selected radio button -; all other registers and flags clobbered +; Y preserved +; X clobbered +; other flags clobbered ;------------------------------------------------------------------------------ GetCheckedRadioButton + iny sty @max + dey + txa - pha ldx #WGSelectView jsr WeeGUI @@ -242,6 +265,59 @@ GetCheckedRadioButton clc rts +;------------------------------------------------------------------------------ +; HandleUpDownRadio +; +; in: WeeGUI initialized +; A = action ID (#ID_RADIO_PREVIOUS or #ID_RADIO_NEXT) +; X = WeeGUI view ID of first radio button +; Y = WeeGUI view ID of last radio button +; out: all registers and flags clobbered +;------------------------------------------------------------------------------ +HandleUpDownRadio + sta @action ; action ID >= #$80 is a screen-specific action, so stash it for now + stx @first + sty @last + jsr GetCheckedRadioButton ; A = WeeGUI view ID of currently checked radio button + ldx #WGSelectView ; uncheck it and repaint it + jsr WeeGUI + stz PARAM0 + ldx #WGSetState + jsr WeeGUI + ldx #WGPaintView + jsr WeeGUI +@findNewLoop +@action=*+1 + ldx #$FD + cpx #ID_RADIO_PREVIOUS + beq @up +@last=*+1 + cmp #$FD + bcs + + inc ; move to next + +HIDE_NEXT_2_BYTES +@first=*+1 ++ lda #$FD ; move to first + bra @checkNew +@up dec ; tentatively move to previous + cmp @first + bcs @checkNew + lda @last ; nope, we were already on the first, so move to last +@checkNew + tax + ldy gViewInUse,x ; if new radio is unused, move again + beq @findNewLoop + ldx #WGSelectView ; check new radio button and repaint it + jsr WeeGUI + ldx #WGViewFocus + jsr WeeGUI + ldx #WGSetState + lda #1 + sta PARAM0 + jsr WeeGUI + ldx #WGPaintView + jmp WeeGUI + ;------------------------------------------------------------------------------ ; CreateNullTerminatedString ; Copy a length-prefixed string to kNullTerminatedBuffer and null-terminate it. diff --git a/src/ui.main.a b/src/ui.main.a index 048d510..4691097 100644 --- a/src/ui.main.a +++ b/src/ui.main.a @@ -24,8 +24,6 @@ ID_DESCRIPTION = 9 gMainScreenPaintDirty !byte 0 -gViewInUse - !byte 0,1,1,1,1,0,0,0,0,0,0,0,0,0,0 kInfoPaintWidth = 65 kDescriptionPaintWidth = 78 diff --git a/src/ui.options.a b/src/ui.options.a index 43151d6..a5de3cc 100644 --- a/src/ui.options.a +++ b/src/ui.options.a @@ -46,7 +46,7 @@ OptionsDialog txs jsr HardResetWeeGUI - jsr CreateDialog ; create frame and OK/Cancel buttons + jsr CreateDialog ; create decorated frame !word kViewOptionsFrame !word kStringOptionsFrame diff --git a/src/ui.resume.a b/src/ui.resume.a index 748e9c2..a7356f2 100644 --- a/src/ui.resume.a +++ b/src/ui.resume.a @@ -21,9 +21,6 @@ ID_RESUME_NEWGAME = 9 ID_RESUME_OK = 10 ID_RESUME_CANCEL = 11 -gResumeViewInUse - !byte 1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0 - ; action keys for options screen kResumeKeys !byte $CF,ID_RESUME_OK ; O @@ -42,16 +39,12 @@ kResumeKeys !byte $B7,ID_RESUME_SLOT7 ; 7 !byte $CE,ID_RESUME_NEWGAME ; N !byte $EE,ID_RESUME_NEWGAME ; n - !byte $88,ID_RESUME_PREVIOUS; left arrow - !byte $95,ID_RESUME_NEXT ; right arrow - !byte $8B,ID_RESUME_PREVIOUS; up arrow - !byte $8A,ID_RESUME_NEXT ; down arrow + !byte $88,ID_RADIO_PREVIOUS ; left arrow + !byte $95,ID_RADIO_NEXT ; right arrow + !byte $8B,ID_RADIO_PREVIOUS ; up arrow + !byte $8A,ID_RADIO_NEXT ; down arrow _endResumeKeys -; IDs of actions that do not correspond to WeeGUI view IDs have high bit set -ID_RESUME_PREVIOUS = $81 -ID_RESUME_NEXT = $82 - ;------------------------------------------------------------------------------ ; ResumeDialog ; call WeeGUI to create and paint 'resume game' screen, and run to completion @@ -64,11 +57,6 @@ ResumeDialog txs jsr HardResetWeeGUI - ldx #ID_RESUME_SLOT7 -- stz gResumeViewInUse,x ; reset flags for which radio buttons are in use - dex - bne - - jsr LoadSavedGameInfo ; call ZINFO to get the information we need for this dialog lda gSavedGamesSlotsInUse ; populated by LoadSavedGameInfo @@ -88,7 +76,7 @@ ResumeDialog inc sta kViewResumeCancel+2 ; Cancel top - jsr CreateDialog + jsr CreateDialog ; create decorated frame !word kViewResumeFrame !word kStringResumeFrame @@ -155,19 +143,26 @@ ResumeDialog ; out: all registers and flags clobbered ;------------------------------------------------------------------------------ HandleResumeKey +; A = key pressed +; out: all registers and flags clobbered ldx #_endResumeKeys-kResumeKeys - cmp kResumeKeys,x beq @found dex dex bpl - - jmp SoftBell -@found - ; TODO need to handle up and down arrow keys like versions dialog - lda kResumeKeys+1,x +@error jmp SoftBell +@found lda kResumeKeys+1,x ; get action ID associated with this key + bmi @updown + tax ; action ID < #$80 is a WeeGUI view, so activate it + ldy gViewInUse,x + beq @error ldx #WGSelectView jsr WeeGUI jmp SimulateClick +@updown ldx #ID_RESUME_SLOT0 + ldy #ID_RESUME_NEWGAME + jmp HandleUpDownRadio ;------------------------------------------------------------------------------ ; CreateResumeRadioCallback @@ -182,7 +177,6 @@ HandleResumeKey CreateResumeRadioCallback +STAY PTR lda (PTR) - sta gResumeViewInUse+1,x ; mark whether this view is in use (hotkeys activate based on this array) beq @exit ; length=0 means this slot is unused, so we're done lda PTR @@ -241,8 +235,8 @@ iResumeVTAB ; out: exits via LaunchInterpreterWithGame ;------------------------------------------------------------------------------ ResumeOKCallback - lda #ID_RESUME_SLOT0 - ldy #ID_RESUME_NEWGAME+1 + ldx #ID_RESUME_SLOT0 + ldy #ID_RESUME_NEWGAME jsr GetCheckedRadioButton ; returns A = WeeGUI view ID cmp #ID_RESUME_NEWGAME bne + diff --git a/src/ui.versions.a b/src/ui.versions.a index 60da97b..1056628 100644 --- a/src/ui.versions.a +++ b/src/ui.versions.a @@ -21,9 +21,6 @@ ID_VERSIONS_9 = 9 ID_VERSIONS_OK = 10 ID_VERSIONS_CANCEL = 11 -gVersionsViewInUse - !byte 1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0 - ; action keys for versions screen kVersionsKeys !byte $CF,ID_VERSIONS_OK ; O @@ -41,16 +38,12 @@ kVersionsKeys !byte $B7,ID_VERSIONS_7 ; 7 !byte $B8,ID_VERSIONS_8 ; 8 !byte $B9,ID_VERSIONS_9 ; 9 - !byte $88,ID_VERSIONS_PREVIOUS ; left arrow - !byte $95,ID_VERSIONS_NEXT ; right arrow - !byte $8B,ID_VERSIONS_PREVIOUS ; up arrow - !byte $8A,ID_VERSIONS_NEXT ; down arrow + !byte $88,ID_RADIO_PREVIOUS ; left arrow + !byte $95,ID_RADIO_NEXT ; right arrow + !byte $8B,ID_RADIO_PREVIOUS ; up arrow + !byte $8A,ID_RADIO_NEXT ; down arrow _endVersionsKeys -; IDs of actions that do not correspond to WeeGUI view IDs have high bit set -ID_VERSIONS_PREVIOUS = $81 -ID_VERSIONS_NEXT = $82 - ;------------------------------------------------------------------------------ ; VersionsDialog ; call WeeGUI to create and paint 'select version' dialog, and run to completion @@ -64,11 +57,6 @@ VersionsDialog txs jsr HardResetWeeGUI - ldx #ID_VERSIONS_9 -- stz gVersionsViewInUse,x ; reset flags for which radio buttons are in use (1-9) - dex - bne - - jsr okvs_len !word gVersionsStore sta iNumVersions @@ -87,7 +75,7 @@ VersionsDialog inc sta kViewVersionsCancel+2 ; Cancel top = OK top + 2 - jsr CreateDialog + jsr CreateDialog ; create decorated frame !word kViewVersionsFrame !word kStringVersionsFrame @@ -99,8 +87,6 @@ VersionsDialog ldx #0 ; X = index of radio button (0-based) .createRadioLoop phx - lda #1 - sta gVersionsViewInUse+1,x ; mark this view as in use so hotkeys will activate txa asl tax @@ -186,43 +172,14 @@ HandleVersionsKey @found lda kVersionsKeys+1,x ; get action ID associated with this key bmi @updown tax ; action ID < #$80 is a WeeGUI view, so activate it - ldy gVersionsViewInUse,x + ldy gViewInUse,x beq @error ldx #WGSelectView jsr WeeGUI jmp SimulateClick -@updown pha ; action ID >= #$80 is a screen-specific action, so stash it for now - jsr GetCheckedVersion ; figure out which radio button is checked - ldx #WGSelectView ; uncheck it and repaint it - jsr WeeGUI - stz PARAM0 - ldx #WGSetState - jsr WeeGUI - ldx #WGPaintView - jsr WeeGUI - plx ; X = action ID (pushed earlier from A) - cpx #ID_VERSIONS_PREVIOUS - beq @up - cmp iNumVersions ; find 'next' view ID (wrapping around to 1) - bcs + - inc - +HIDE_NEXT_2_BYTES -+ lda #1 - bra @checkNewVersion -@up dec - bne @checkNewVersion - lda iNumVersions -@checkNewVersion - ldx #WGSelectView ; check new radio button and repaint it - jsr WeeGUI - ldx #WGViewFocus - jsr WeeGUI - ldx #WGSetState - lda #1 - sta PARAM0 - jsr WeeGUI - ldx #WGPaintView - jmp WeeGUI +@updown ldx #ID_VERSIONS_1 + ldy iNumVersions + jmp HandleUpDownRadio PrintVersionLabelCallback ; called via okvs_iter_values @@ -239,17 +196,10 @@ iVersionsVTAB inc iVersionsVTAB rts -GetCheckedVersion - lda #ID_VERSIONS_1 - pha - clc - adc iNumVersions ; iNumVersions was populated in VersionsDialog and hasn't changed since - tay - pla - jmp GetCheckedRadioButton - VersionsOKCallback - jsr GetCheckedVersion + ldx #ID_VERSIONS_1 + ldy iNumVersions + jsr GetCheckedRadioButton ; figure out which radio button is checked dec sta @n jsr okvs_nth