;license:MIT ;(c) 2018 by 4am ; ; User interface - click/activation callbacks and key handlers for main screen ; ; Public functions ; - HandleKey ; ; (all callbacks are defined in view configuration blocks ; and triggered through UI actions or called from HandleKey) ; !zone { kGameRootDirectory ; length-prefixed pathname of game subdirectories !byte 2 !raw "Z/" kHintsRootDirectory ; length-prefixed pathname of hint files !byte 5 !raw "PRIZM/" kArtworkRootDirectory ; length-prefixed pathname of DHGR box art !byte 8 !raw "ARTWORK/" ; IDs of actions that do not correspond to WeeGUI view IDs have high bit set ID_SCROLLUP = $81 ID_SCROLLDOWN = $82 ID_X = $83 ID_Y = $84 ID_Z = $85 ; action keys for main screen (should correspond to button titles) .keys !byte $C7,ID_PLAY ; G !byte $E7,ID_PLAY ; g !byte $8D,ID_PLAY ; Return !byte $C8,ID_HINTS ; H !byte $E8,ID_HINTS ; h !byte $C1,ID_BOXART ; A !byte $E1,ID_BOXART ; a !byte $D3,ID_OPTIONS ; S !byte $F3,ID_OPTIONS ; s !byte $D0,ID_PREVIOUS ; P !byte $F0,ID_PREVIOUS ; p !byte $88,ID_PREVIOUS ; left arrow !byte $CE,ID_NEXT ; N !byte $EE,ID_NEXT ; n !byte $95,ID_NEXT ; right arrow !byte $8B,ID_SCROLLUP ; up arrow !byte $8A,ID_SCROLLDOWN ; down arrow !byte $D8,ID_X ; X !byte $F8,ID_X ; x !byte $D9,ID_Y ; Y !byte $F9,ID_Y ; y !byte $DA,ID_Z ; Z !byte $FA,ID_Z ; z .endkeys ;------------------------------------------------------------------------------ ; HandleKey ; handle keypress to activate various UI elements ; ; in: A contains key pressed ; out: all registers and flags clobbered ;------------------------------------------------------------------------------ HandleKey ldx #.endkeys-.keys - cmp .keys,x beq .foundKey dex dex bpl - .notFound jmp SoftBell ; unknown key, beep softly .foundKey lda .keys+1,x ; get ID associated with this key bpl .activateView ; ID < #$80 is a WeeGUI view, so activate it cmp #ID_X ; X, Y, and Z keys are part of beq .x ; an undocumented feature cmp #ID_Y beq .y cmp #ID_Z beq .z cmp #ID_SCROLLDOWN ; arrow keys scroll the description box beq .handleScrollDown .handleScrollUp lda #$01 !byte $2C ; hide next LDA .handleScrollDown lda #$FF pha ldx #WGSelectView lda #ID_DESCRIPTION jsr WeeGUI ldx #WGScrollYBy pla jsr WeeGUI bra .focusAndDoAction .activateView tax ldy gViewInUse,x beq .notFound ldx #WGSelectView jsr WeeGUI .focusAndDoAction ldx #WGViewFocus jsr WeeGUI ldx #WGViewFocusAction jsr WeeGUI ldx #WGViewUnfocus jmp WeeGUI .y lda .xyzzy cmp #1 beq .y1 cmp #4 bne .xyzzyReset beq .xyzzyGo .z lda .xyzzy cmp #2 beq .z1 cmp #3 beq .z2 bra .xyzzyReset .x lda #1 !byte $2C .y1 lda #2 !byte $2C .z1 lda #3 !byte $2C .z2 lda #4 !byte $2C .xyzzyReset lda #0 .xyzzyStoreAndExit sta .xyzzy jmp SoftBell .xyzzy !byte $00 .xyzzyGo jsr SaveGlobalPreferences jsr ResetPath +LDADDR kArtworkRootDirectory jsr AddToPath jsr SetPrefix !word gPathname bcs .xyzzyError jsr ResetPath +LDADDR .dhrslideFilename jsr AddToPath jsr LoadFile !word gPathname !word kSystemAddress !word kProDOSFileBuffer bcs .xyzzyError jsr ExitWeeGUI jmp kSystemAddress .xyzzyError jmp MainScreen .dhrslideFilename !byte 15 !raw "DHRSLIDE.SYSTEM" } !zone { GetCurrentGameIndex jsr okvs_get ; get shortname of current game !word gGlobalPrefsStore !word kLastPlayed +STAY + jsr okvs_get ; get numeric index !word gGamesListStore + !word $FDFD ; SMC rts ; X = index of current game callback_previous jsr GetCurrentGameIndex dex bpl + jsr okvs_len !word gGamesListStore tax dex + bra .loadNewGameInfoAndRepaint callback_next jsr GetCurrentGameIndex inx stx .n jsr okvs_len !word gGamesListStore ldx .n .n=*+1 cmp #$FD ; SMC bne .loadNewGameInfoAndRepaint ldx #0 .loadNewGameInfoAndRepaint stx + jsr okvs_nth !word gGamesListStore + !byte $FD ; SMC +STAY + jsr okvs_update !word gGlobalPrefsStore !word kLastPlayed + !word $FDFD ; SMC lda #1 sta gGlobalPrefsDirty ; will trigger a file write later sta gMainScreenPaintDirty ; will trigger a repaint later, in main run loop jmp LoadGameInfo ; load new game info first } callback_versions rts !zone { callback_boxart jsr okvs_get !word gOptionsStore !word kHasArtwork jsr okvs_as_boolean beq .boxartError lda #0 ; set Z flag always !cpu 65816 rep #2 ; clear Z flag on 65816 only !cpu 65c02 beq + ; skip GS-specific code on non-GS machines (required, will crash on //c, grr) lda $C029 and #$1F sta $C029 ; set GS NEWVIDEO mode to turn off linearize + jsr ResetPath +LDADDR kArtworkRootDirectory jsr AddToPath jsr okvs_get !word gGlobalPrefsStore !word kLastPlayed jsr AddToPath ; gPathname = 'ARTWORK/' + jsr LoadDHRFile ; load artwork from file !word gPathname !word kProDOSFileBuffer bcs .boxartError sta $C000 ; display double hi-res page 1 sta $C00D sta $C05E sta $C001 sta $C057 sta $C052 sta $C054 sta $C050 bit $C010 ; clear keyboard strobe ldx #WGClearPendingClick ; clear WeeGUI mouse strobe jsr WeeGUI .boxArtRunLoop ldx #WGPendingClick jsr WeeGUI cpx #$FF bne + ; X != #$FF -> user clicked mouse lda $C000 bpl .boxArtRunLoop + bit $C010 ; clear keyboard strobe ldx #WGClearPendingClick ; clear WeeGUI mouse strobe jsr WeeGUI sta $C051 ; back to text rts .boxartError jmp SoftBell } callback_options = OptionsDialog callback_clues = LaunchInterpreterWithHints callback_play = LaunchInterpreterWithGame callback_resume = LaunchInterpreterWithGame