refactor main menu

This commit is contained in:
4am 2020-07-09 21:20:08 -04:00
parent 71bf804647
commit 7cdf223a9f
4 changed files with 130 additions and 60 deletions

View File

@ -93,7 +93,8 @@ InitPuzzleSound
rts
PlayNextChord
; out: preserves A
; out: preserves X
txa
pha
lda gWorldID
asl
@ -121,14 +122,17 @@ PlayNextChord
pla
jsr PlaySound
pla
tax
rts
PlayFinalChord
; out: preserves A
; out: preserves X
txa
pha
+LD16 kFinalChord
jsr PlaySound
pla
tax
rts
;------------------------------------------------------------------------------

View File

@ -23,18 +23,20 @@ Start
jsr InitSound
jsr LoadProgressFromDisk
jsr TitlePage
; C set if main menu requires full redraw (e.g. title sequence ended prematurely)
@GoToMainMenu
jsr MainMenu
; C is set now if main menu requires full redraw
; (e.g. title sequence ended prematurely, or we're
; returning from another screen)
jsr MainMenuEventLoop
bcc +
jmp Quit
+ sta gWorldID
jsr MaybeLoadWorldFromDisk ; A = world ID from selection page
bcc @PlayNext
jmp $FF59 ; TODO
@PlayNext
+
; A = world ID (from MainMenu)
sta gWorldID
jsr MaybeLoadWorldFromDisk
bcs @GoToMainMenu
jsr LoadProgressFromMemory
; A = next puzzle ID
; A = next puzzle ID (from LoadProgressFromMemory)
@Play
sta gPuzzleID
ldx gWorldID
@ -51,21 +53,23 @@ Start
jsr ClearAndDrawPuzzle
jsr AnimatePuzzleIntoPlace
jsr DrawColumnSelectionIndicator
jsr PlayEventLoop
cmp #kCompletedPuzzle
cpx #kCompletedPuzzle
bne +
jsr AnimatePuzzleCompleted
ldx gPuzzleID
jsr MarkPuzzleCompleted
; A - next puzzle ID
; A = next puzzle ID (from MarkPuzzleCompleted)
jmp @Play
+ cmp #kRequestedRestart
+
cpx #kRequestedRestart
bne +
jsr Home
lda gPuzzleID
jmp @Play
+
sec
sec ; full redraw
bcs @GoToMainMenu
!source "src/ui.title.a"

View File

@ -7,7 +7,44 @@
; - MainMenu
;
MainMenu
; Codes returned by event handlers
kStayOnMainMenu = 0
kRequestedQuit = 1
kStartPlaying = 2
kMainMenuKeys ; must keep in sync with kMainMenuKeyHandlersLo/Hi arrays
; except for last byte ($00) which doesn't need an associated handler
!byte $0D ; Return
!byte $43 ; C/c
!byte $03 ; Ctrl-C
!byte $53 ; S/s
!byte $13 ; Ctrl-S
!byte $51 ; Q/q
!byte $11 ; Ctrl-Q
!byte $1B ; Esc
!byte $00
kMainMenuKeyHandlersLo
!byte <MainMenuEventReturn
!byte <MainMenuEventC
!byte <MainMenuEventC
!byte <MainMenuEventS
!byte <MainMenuEventS
!byte <MainMenuEventQ
!byte <MainMenuEventQ
!byte <MainMenuEventQ
kMainMenuKeyHandlersHi
!byte >MainMenuEventReturn
!byte >MainMenuEventC
!byte >MainMenuEventC
!byte >MainMenuEventS
!byte >MainMenuEventS
!byte >MainMenuEventQ
!byte >MainMenuEventQ
!byte >MainMenuEventQ
MainMenuEventLoop
; in: C clear if screen is already cleared and title is already drawn
; (will happen if animated title screen runs to completion)
; C set if full screen clear & redraw is required
@ -17,42 +54,68 @@ MainMenu
; A = world ID
; C set if user selected quit
bcc +
jsr @drawMenuTitle
+ jsr @drawMenuText
@menuloop
jsr DrawMainMenuTitle
+ jsr DrawMainMenuText
bit CLEARKBD
+LDADDR MainMenuMusic
jsr LoopSound
bit CLEARKBD
and #$7F
cmp #$0D ; Return
beq @eventReturn
cmp #$01 ; Ctrl-A
beq @eventCtrlA
cmp #$13 ; Ctrl-S
beq @eventCtrlS
cmp #$1B ; Esc
bne @menuloop
;@eventEsc
sec
cmp #$7B
bcs +
cmp #$61
bcc +
sbc #$20 ; a-z -> A-Z
+ sta gLastKeyPressed
ldx #0
- ldy kMainMenuKeys, x
beq MainMenuEventLoop
cpy gLastKeyPressed
beq @dispatch
inx
bne -
beq MainMenuEventLoop
@dispatch
lda kMainMenuKeyHandlersLo, x
sta @j+1
lda kMainMenuKeyHandlersHi, x
sta @j+2
@j jsr $FDFD ; SMC
beq MainMenuEventLoop
rts
@eventReturn
MainMenuEventReturn
jsr SelectWorld
bcs MainMenu
rts ; return to caller with A = world ID
@eventCtrlA
bcs + ; in next event handler
ldx #kStartPlaying ; Z=0 so caller will exit main menu event loop
; C=0 so grand-caller will start playing
; A=world ID (from SelectWorld)
rts
MainMenuEventC
jsr AboutPage
sec
bcs MainMenu
@eventCtrlS
+ ldx #kStayOnMainMenu ; Z=1 so caller will stay in main menu event loop
sec ; C=1 so caller will do a full screen refresh
rts
MainMenuEventS
lda gSoundPref
eor #$01
sta gSoundPref
jsr SavePrefs
jsr ReinitSoundAfterPrefChange
clc
bcc MainMenu
@drawMenuTitle
ldx #kStayOnMainMenu ; Z=1 so caller will stay in main menu event loop
clc ; C=0 so caller will only do a partial screen refresh
rts
MainMenuEventQ
ldx #kRequestedQuit ; Z=0 so caller will exit main menu event loop
sec ; C=1 so grand-caller will call MLI quit
rts
DrawMainMenuTitle
jsr Home
lda #1
sta GlobalLeftMargin
@ -70,7 +133,8 @@ MainMenu
cpy #$0A
bne -
rts
@drawMenuText
DrawMainMenuText
+PRINT_AT asterisk, 2, 30
+PRINT_AT version, 11, 26
+PRINT_AT menuline_play, 15, 10
@ -270,11 +334,11 @@ menuline_sound_off
!byte 4
!raw "OFF)"
menuline_about
!byte 16
!raw "CTRL-A.....ABOUT"
!byte 18
!raw "CTRL-C.....CREDITS"
menuline_quit
!byte 15
!raw " ESC.....QUIT"
!raw "CTRL-Q.....QUIT"
disclaimer
!byte 40
!raw "* NOT GUARANTEED, ACTUAL COUNT MAY VARY."

View File

@ -11,11 +11,11 @@
; - AnimatePuzzleCompleted
;
; Codes returned by play event handlers
; Codes returned by event handlers
kKeepPlaying = 0 ; This code is checked with BEQ/BNE, so it must be 0
kCompletedPuzzle = 1 ; All non-zero codes will exit play event loop
kRequestedRestart = 2 ; with the code in A so caller knows what happened
kPressedEsc = 3
kRequestedRestart = 2 ; with the code in X so caller knows what happened
kReturnToMainMenu = 3
gSelectedLogicalColumn
!byte 0
@ -72,7 +72,7 @@ kPlayKeyHandlersHi
;
; in: puzzle has been loaded into memory, drawn on screen, animated, &c.
; and is ready to play
; out: A = reason why event loop ended (see list above)
; out: X = reason why event loop ended (see list above)
; all other registers and flags clobbered
;------------------------------------------------------------------------------
PlayEventLoop
@ -112,11 +112,11 @@ PlayEventLoop
rts
PlayEventEsc
lda #kPressedEsc ; caller will exit play event loop
ldx #kReturnToMainMenu ; caller will exit play event loop
rts
PlayEventCtrlR
lda #kRequestedRestart ; caller will exit play event loop
ldx #kRequestedRestart ; caller will exit play event loop
rts
PlayEventReturn
@ -124,7 +124,7 @@ PlayEventReturn
beq +
jsr EraseColumnSelectionIndicator
jmp MoveToFirstColumn
+ lda #kKeepPlaying
+ ldx #kKeepPlaying
rts
PlayEventUpArrow
@ -141,7 +141,7 @@ PlayEventDownArrow
CantMove
jsr SoftBell
KeepPlaying
lda #kKeepPlaying
ldx #kKeepPlaying
rts
+ jsr ScrollDown
CheckAfterArrow
@ -161,7 +161,7 @@ PlayEventLeftArrow
+ dey
sty gSelectedLogicalColumn
jsr DrawColumnSelectionIndicator
lda #kKeepPlaying
ldx #kKeepPlaying
rts
PlayEventRightArrow
@ -174,7 +174,7 @@ MoveToFirstColumn
ldy #0
+ sty gSelectedLogicalColumn
jsr DrawColumnSelectionIndicator
lda #kKeepPlaying
ldx #kKeepPlaying
rts
- jsr PlayNextChord
@ -184,7 +184,7 @@ PlayEventLetter
jsr FindLetterInColumn
bcc +
jsr SoftBell ; didn't find letter, we're done
lda #kKeepPlaying
ldx #kKeepPlaying
rts
+ beq PlayEventRightArrow ; found letter but it's already on center row, we're done, exit through right arrow handler
bmi @up ; scroll up or down ONCE, then reassess
@ -198,7 +198,7 @@ PlayEventLetter
jsr MarkTargetWord ; show that we've finished a word
jsr CheckForPuzzleComplete
beq - ; if puzzle isn't complete, check if more scrolling is required
jmp PlayFinalChord ; puzzle is complete, play final sound and return to caller with A = kCompletedPuzzle
jmp PlayFinalChord ; puzzle is complete, play final sound and return to caller with X = kCompletedPuzzle
MarkTargetWord
; in: none
@ -226,12 +226,12 @@ MarkTargetWord
CheckForPuzzleComplete
; in: none
; out: A = play event loop code
; out: X = play event loop code
jsr IsPuzzleComplete
bcs +
lda #kCompletedPuzzle
+HIDE_NEXT_2_BYTES
+ lda #kKeepPlaying
ldx #kCompletedPuzzle
rts
+ ldx #kKeepPlaying
rts
;------------------------------------------------------------------------------
@ -243,8 +243,6 @@ CheckForPuzzleComplete
; out: all registers and flags clobbered
;------------------------------------------------------------------------------
ClearAndDrawPuzzle
; jsr Home
; bit TEXTMODE
jsr DrawThinLines
+LDADDR puzzle_data0
+ST16 $FE