pitch-dark/src/ui.main.keys.a

273 lines
7.5 KiB
Plaintext
Raw Normal View History

2018-02-07 14:05:24 +00:00
;license:MIT
;(c) 2018 by 4am
;
2018-03-27 20:55:31 +00:00
; User interface - click/activation callbacks and key handlers for main screen
2018-02-07 14:05:24 +00:00
;
; Public functions
; - HandleKey
;
2018-03-27 20:55:31 +00:00
; (all callbacks are defined in view configuration blocks
2018-02-07 14:05:24 +00:00
; and triggered through UI actions or called from HandleKey)
;
!zone {
2018-03-29 02:49:51 +00:00
kGameRootDirectory ; length-prefixed pathname of game subdirectories
2018-02-21 21:00:31 +00:00
!byte 2
!raw "Z/"
2018-03-29 02:49:51 +00:00
kHintsRootDirectory ; length-prefixed pathname of hint files
2018-03-16 18:17:45 +00:00
!byte 5
!raw "PRIZM/"
2018-02-21 21:00:31 +00:00
kArtworkRootDirectory ; length-prefixed pathname of DHGR box art
!byte 8
!raw "ARTWORK/"
2018-03-27 20:55:31 +00:00
; 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)
2018-02-07 14:05:24 +00:00
.keys
2018-02-24 20:25:41 +00:00
!byte $C7,ID_PLAY ; G
!byte $E7,ID_PLAY ; g
!byte $8D,ID_PLAY ; Return
2018-02-24 20:25:41 +00:00
!byte $C8,ID_CLUES ; H
!byte $E8,ID_CLUES ; h
!byte $C1,ID_BOXART ; A
!byte $E1,ID_BOXART ; a
!byte $D3,ID_OPTIONS ; S
2018-03-01 16:06:00 +00:00
!byte $F3,ID_OPTIONS ; s
2018-02-24 20:25:41 +00:00
!byte $D0,ID_PREVIOUS ; P
!byte $F0,ID_PREVIOUS ; p
!byte $88,ID_PREVIOUS ; left arrow
2018-02-07 14:05:24 +00:00
!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
2018-03-22 20:06:31 +00:00
!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
2018-02-07 14:05:24 +00:00
.endkeys
;------------------------------------------------------------------------------
; HandleKey
; handle keypress to activate various UI elements
;
; in: A contains key pressed
; out: all registers and flags clobbered
2018-02-07 14:05:24 +00:00
;------------------------------------------------------------------------------
HandleKey
ldx #.endkeys-.keys
2018-02-07 14:05:24 +00:00
- cmp .keys,x
beq .foundKey
2018-02-07 14:05:24 +00:00
dex
dex
bpl -
2018-03-29 02:49:51 +00:00
jmp SoftBell ; unknown key, beep softly
.foundKey
2018-03-29 02:49:51 +00:00
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
2018-03-22 20:06:31 +00:00
cmp #ID_Y
beq .y
cmp #ID_Z
beq .z
2018-03-29 02:49:51 +00:00
cmp #ID_SCROLLDOWN ; arrow keys scroll the description box
beq .handleScrollDown
.handleScrollUp
lda #$01
!byte $2C ; hide next LDA
.handleScrollDown
lda #$FF
pha
2018-02-07 14:05:24 +00:00
ldx #WGSelectView
lda #ID_DESCRIPTION
2018-02-07 14:05:24 +00:00
jsr WeeGUI
ldx #WGScrollYBy
pla
jsr WeeGUI
bra .focusAndDoAction
.activateView
ldx #WGSelectView
jsr WeeGUI
.focusAndDoAction
2018-02-07 14:05:24 +00:00
ldx #WGViewFocus
jsr WeeGUI
ldx #WGViewFocusAction
jsr WeeGUI
ldx #WGViewUnfocus
jmp WeeGUI
2018-03-22 20:06:31 +00:00
.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
ldx #WGClearScreen
jsr WeeGUI
jsr SaveGlobalPreferences
jsr ResetPath
2018-03-29 02:49:51 +00:00
+LDADDR kArtworkRootDirectory
2018-03-22 20:06:31 +00:00
jsr AddToPath
jsr SetPrefix
!word gPathname
2018-03-23 17:44:34 +00:00
bcs .xyzzyError
2018-03-22 20:06:31 +00:00
jsr ResetPath
2018-03-29 02:49:51 +00:00
+LDADDR .dhrslideFilename
2018-03-22 20:06:31 +00:00
jsr AddToPath
jsr LoadFile
!word gPathname
2018-03-23 17:44:34 +00:00
!word kSystemAddress
2018-03-22 20:06:31 +00:00
!word kProDOSFileBuffer
2018-03-23 17:44:34 +00:00
bcs .xyzzyError
2018-03-22 20:06:31 +00:00
jsr ExitWeeGUI
2018-03-23 17:44:34 +00:00
jmp kSystemAddress
.xyzzyError
jmp MainScreen
2018-03-22 20:06:31 +00:00
.dhrslideFilename
!byte 15
!raw "DHRSLIDE.SYSTEM"
2018-02-21 21:00:31 +00:00
}
2018-02-21 21:00:31 +00:00
!zone {
GetCurrentGameIndex
jsr okvs_get ; get shortname of current game
!word gGlobalPrefsStore
!word kLastPlayed
2018-03-29 02:49:51 +00:00
+STAY +
jsr okvs_get ; get numeric index
!word gGamesListStore
2018-03-29 02:49:51 +00:00
+ !word $FDFD ; SMC
rts ; X = index of current game
2018-02-07 14:05:24 +00:00
callback_previous
jsr GetCurrentGameIndex
dex
2018-02-07 14:05:24 +00:00
bpl +
jsr okvs_len
!word gGamesListStore
2018-03-26 17:17:35 +00:00
tax
dex
+ bra .loadNewGameInfoAndRepaint
2018-03-29 02:49:51 +00:00
callback_next
jsr GetCurrentGameIndex
inx
stx .n
jsr okvs_len
!word gGamesListStore
ldx .n
.n=*+1
cmp #$FD ; SMC
bne .loadNewGameInfoAndRepaint
ldx #0
.loadNewGameInfoAndRepaint
2018-03-29 02:49:51 +00:00
stx +
jsr okvs_nth
!word gGamesListStore
2018-03-29 02:49:51 +00:00
+ !byte $FD ; SMC
+STAY +
2018-03-26 17:17:35 +00:00
jsr okvs_update
!word gGlobalPrefsStore
2018-03-26 17:17:35 +00:00
!word kLastPlayed
2018-03-29 02:49:51 +00:00
+ !word $FDFD ; SMC
2018-03-27 20:31:01 +00:00
lda #1
sta gNeedToSavePrefs
2018-02-07 14:05:24 +00:00
jsr LoadGameInfo
jmp RepaintSomeViews
2018-02-21 21:00:31 +00:00
}
2018-02-24 20:25:41 +00:00
callback_versions
rts
2018-03-16 18:17:45 +00:00
2018-02-21 21:00:31 +00:00
!zone {
callback_boxart
2018-02-24 20:25:41 +00:00
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
2018-03-31 15:25:42 +00:00
+
jsr ResetPath
+LDADDR kArtworkRootDirectory
jsr AddToPath
jsr okvs_get
!word gGlobalPrefsStore
!word kLastPlayed
jsr AddToPath ; gPathname = 'ARTWORK/<game shortname>'
2018-02-24 20:25:41 +00:00
+ jsr LoadDHRFile ; load artwork from file
2018-02-21 21:00:31 +00:00
!word gPathname
!word kProDOSFileBuffer
2018-03-23 17:44:34 +00:00
bcs .boxartError
2018-02-21 21:00:31 +00:00
sta $C000 ; display double hi-res page 1
sta $C00D
sta $C05E
2018-03-31 15:25:42 +00:00
sta $C001
2018-02-21 21:00:31 +00:00
sta $C057
sta $C052
sta $C054
sta $C050
2018-03-31 16:31:49 +00:00
bit $C010 ; clear keyboard strobe
ldx #WGClearPendingClick ; clear WeeGUI mouse strobe
2018-03-31 15:50:37 +00:00
jsr WeeGUI
2018-03-31 16:31:49 +00:00
.boxArtRunLoop
2018-03-31 15:50:37 +00:00
ldx #WGPendingClick
jsr WeeGUI
cpx #$FF
2018-03-31 16:31:49 +00:00
bne + ; X != #$FF -> user clicked mouse
2018-03-31 15:50:37 +00:00
lda $C000
2018-03-31 16:31:49 +00:00
bpl .boxArtRunLoop
+ bit $C010 ; clear keyboard strobe
ldx #WGClearPendingClick ; clear WeeGUI mouse strobe
2018-03-31 15:50:37 +00:00
jsr WeeGUI
2018-03-31 15:25:42 +00:00
sta $C051 ; back to text
2018-02-21 21:00:31 +00:00
rts
2018-03-23 17:44:34 +00:00
.boxartError
2018-03-16 18:17:45 +00:00
jmp SoftBell
2018-02-21 21:00:31 +00:00
}
2018-03-31 15:25:42 +00:00
callback_options = OptionsDialog
callback_clues = LaunchInterpreterWithHints
callback_play = LaunchInterpreterWithGame