mirror of
https://github.com/a2-4am/pitch-dark.git
synced 2024-09-27 19:57:56 +00:00
198 lines
5.9 KiB
Plaintext
198 lines
5.9 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)
|
|
;
|
|
|
|
; 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)
|
|
kMainKeys
|
|
!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
|
|
!byte $BF,ID_ABOUT ; ?
|
|
_endMainKeys
|
|
|
|
;------------------------------------------------------------------------------
|
|
; HandleKey
|
|
; handle keypresses in main screen
|
|
;
|
|
; in: A contains key pressed
|
|
; out: all registers and flags clobbered
|
|
;------------------------------------------------------------------------------
|
|
HandleKey
|
|
ldx #(_endMainKeys-kMainKeys)-2
|
|
- cmp kMainKeys,x
|
|
beq @found
|
|
dex
|
|
dex
|
|
bpl -
|
|
@error jmp SoftBell ; unknown key, beep softly
|
|
@found lda kMainKeys+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 @down
|
|
lda #$01
|
|
+HIDE_NEXT_2_BYTES
|
|
@down lda #$FF
|
|
pha
|
|
ldx #WGSelectView
|
|
lda #ID_DESCRIPTION
|
|
jsr WeeGUI
|
|
ldx #WGScrollYBy
|
|
pla
|
|
jsr WeeGUI
|
|
bra @click
|
|
@activateView
|
|
tax
|
|
ldy gViewInUse,x
|
|
beq @error
|
|
ldx #WGSelectView
|
|
jsr WeeGUI
|
|
@click jmp SimulateClick
|
|
|
|
;------------------------------------------------------------------------------
|
|
; XYZZY handler
|
|
;------------------------------------------------------------------------------
|
|
@y lda @xyzzyCounter
|
|
cmp #1
|
|
beq @y1
|
|
cmp #4
|
|
bne @xyzzyReset
|
|
beq @xyzzyGo
|
|
@z lda @xyzzyCounter
|
|
cmp #2
|
|
beq @z1
|
|
cmp #3
|
|
beq @z2
|
|
bra @xyzzyReset
|
|
@x lda #1
|
|
+HIDE_NEXT_2_BYTES
|
|
@y1 lda #2
|
|
+HIDE_NEXT_2_BYTES
|
|
@z1 lda #3
|
|
+HIDE_NEXT_2_BYTES
|
|
@z2 lda #4
|
|
+HIDE_NEXT_2_BYTES
|
|
@xyzzyReset
|
|
lda #0
|
|
sta @xyzzyCounter
|
|
bra @error
|
|
@xyzzyCounter
|
|
!byte 0
|
|
@xyzzyGo
|
|
jsr SaveGlobalPreferences
|
|
jsr ResetPath
|
|
+LDADDR kArtworkRootDirectory
|
|
jsr AddToPath
|
|
|
|
jsr SetPrefix ; must set ProDOS prefix to directory where DHGR files actually are
|
|
!word gPathname ; (DHRSLIDE does not look in subdirectories)
|
|
bcs @error
|
|
|
|
jsr ResetPath
|
|
+LDADDR kDHRSLIDEFilename
|
|
jsr AddToPath
|
|
|
|
jsr LoadFile ; load DHRSLIDE program at $2000
|
|
!word gPathname
|
|
!word kSystemAddress
|
|
!word kProDOSFileBuffer
|
|
|
|
jsr ExitWeeGUI ; shut down WeeGUI
|
|
jmp kSystemAddress ; exit via DHRSLIDE
|
|
|
|
kDHRSLIDEFilename
|
|
!byte 15
|
|
!raw "DHRSLIDE.SYSTEM"
|
|
|
|
;------------------------------------------------------------------------------
|
|
; button callbacks
|
|
;------------------------------------------------------------------------------
|
|
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
|