mirror of
https://github.com/a2-4am/pitch-dark.git
synced 2025-01-06 01:30:48 +00:00
217 lines
6.1 KiB
Plaintext
217 lines
6.1 KiB
Plaintext
;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 {
|
|
; 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 $D6,ID_VERSIONS ; V
|
|
!byte $F6,ID_VERSIONS ; v
|
|
!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
|
|
jmp SimulateClick
|
|
|
|
;------------------------------------------------------------------------------
|
|
; XYZZY handler
|
|
;------------------------------------------------------------------------------
|
|
.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"
|
|
}
|
|
|
|
;------------------------------------------------------------------------------
|
|
; button callbacks
|
|
;------------------------------------------------------------------------------
|
|
!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_options = OptionsDialog
|
|
callback_play = LaunchInterpreterWithGame
|
|
callback_resume = LaunchInterpreterWithGame
|
|
callback_boxart = DisplayArtwork
|
|
callback_hints = LaunchInterpreterWithHints
|
|
callback_versions = VersionsDialog
|