Esc during play returns to Select World page

This commit is contained in:
4am 2022-01-18 09:17:46 -05:00
parent 1252f054b0
commit 905b567ee1
5 changed files with 162 additions and 132 deletions

View File

@ -23,64 +23,9 @@ Start ; X = Mockingboard slot (from init)
jsr InitSound
jsr LoadProgressFromDisk
jsr TitlePage
@GoToMainMenu
; 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
; A = world ID
bcc +
jsr EnableAccelerator
jmp Quit
+
sta gWorldID
jsr MaybeLoadWorldFromDisk
bcs @GoToMainMenu
jsr LoadProgressFromMemory
; A = next puzzle ID
@Play
sta gPuzzleID
ldx gWorldID
lda kWorldLeftMargins, x
sta GlobalLeftMargin
lda kPuzzleWidths, x
jsr InitPuzzleStorage
jsr InitPuzzleSound
ldx gPuzzleID
jsr LoadPuzzleFromMemory
lda #0
sta gSelectedLogicalColumn
jsr DrawPuzzleChrome
jsr DrawPuzzle
jsr AnimatePuzzleIntoPlace
jsr DrawColumnSelectionIndicator
jsr PlayEventLoop
cpx #kCompletedPuzzle
bne +
jsr AnimatePuzzleCompleted
ldx gPuzzleID
jsr MarkPuzzleCompleted
; A = next puzzle ID
; X = number of puzzles completed
jsr MaybeShowInterstitial
bcc @Play
bcs @GoToMainMenu
+
cpx #kRequestedSkip
bne +
ldx gPuzzleID
jsr MarkPuzzleSkipped
jmp @Play
+
cpx #kRequestedRestart
bne +
jsr Home
lda gPuzzleID
jmp @Play
+
sec ; C=1 triggers full redraw
bcs @GoToMainMenu
!source "src/ui.strings.a"
!source "src/ui.title.a"

View File

@ -181,7 +181,7 @@ DemoCode
; run self-running demo until keypress or completion
;
; in: none
; out: C = 1
; out: Z = 0
; all other registers & flags clobbered
;------------------------------------------------------------------------------
RunDemo

View File

@ -9,8 +9,7 @@
; Codes returned by event handlers
kStayOnMainMenu = 0
kRequestedQuit = 1
kStartPlaying = 2
kQuit = 1
kMainMenuKeys ; must keep in sync with kMainMenuKeyHandlersLo/Hi arrays
; except for last byte ($00) which doesn't need an associated handler
@ -61,10 +60,8 @@ kMainMenuKeyHandlersHi
; (will happen if animated title screen runs to completion)
; C set if full screen clear & redraw is required
; (will happen if key is pressed during title screen, or
; if user returns to main menu from play or any other screen)
; out: C clear if user selected a world to play, and
; A = world ID
; C set if user selected quit
; if user returns to main menu from any other screen)
; out: Z = 0
;------------------------------------------------------------------------------
MainMenuEventLoop
bcc +
@ -82,11 +79,11 @@ MainMenuEventLoop
ldx #0
@keyloop
ldy kMainMenuKeys, x
beq @musicloop
beq @musicloop ; key has no associated handler, so ignore it
cpy gLastKeyPressed
beq @dispatch
inx
bne @keyloop
bne @keyloop ; always branches
@dispatch
lda kMainMenuKeyHandlersLo, x
sta @j+1
@ -97,20 +94,18 @@ MainMenuEventLoop
rts
MainMenuEventReturn
jsr SelectWorld
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
sec ; C=1 to trigger full redraw of 'select world' page
jsr SelectWorldEventLoop
jmp StayOnMainMenuWithFullRefresh
MainMenuEventD
jsr RunDemo
bne + ; always branches
jmp StayOnMainMenuWithFullRefresh
MainMenuEventC
jsr AboutPage
+ ldx #kStayOnMainMenu ; Z=1 so caller will stay in main menu event loop
StayOnMainMenuWithFullRefresh
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
@ -121,8 +116,7 @@ MainMenuEventS
rts
MainMenuEventQ
ldx #kRequestedQuit ; Z=0 so caller will exit main menu event loop
sec ; C=1 so grand-caller will call MLI quit
ldx #kQuit ; Z=0 so caller will exit main menu event loop
rts
DrawMainMenuTitle

View File

@ -16,7 +16,7 @@ kKeepPlaying = 0 ; This code is checked with BEQ/BNE, so it
kCompletedPuzzle = 1 ; All non-zero codes will exit play event loop
kRequestedRestart = 2 ; with the code in X so caller knows what happened
kRequestedSkip = 3
kReturnToMainMenu = 4
kReturnToSelectWorld = 4
gSelectedLogicalColumn
!byte 0
@ -125,7 +125,7 @@ PlayEventLoop
rts
PlayEventEsc
ldx #kReturnToMainMenu ; caller will exit play event loop
ldx #kReturnToSelectWorld ; caller will exit play event loop
rts
PlayEventCtrlR

View File

@ -4,22 +4,162 @@
; select world screen
;
; Public functions:
; - SelectWorld
; - SelectWorldEventLoop
;
counter = $F2
selectedworld = $F3
; Codes returned by event handlers
kStayOnSelectWorld = 0
kReturnToMainMenu = 1
kSelectWorldKeys ; must keep in sync with kSelectWorldKeyHandlersLo/Hi arrays
; except for last byte ($00) which doesn't need an associated handler
!byte $8D ; Return
!byte $8B ; up arrow
!byte $88 ; left arrow
!byte $8A ; down arrow
!byte $95 ; right arrow
!byte $9B ; Esc
!byte $00
kSelectWorldKeyHandlersLo
!byte <SelectWorldEventReturn
!byte <SelectWorldEventUp
!byte <SelectWorldEventUp
!byte <SelectWorldEventDown
!byte <SelectWorldEventDown
!byte <SelectWorldEventEsc
kSelectWorldKeyHandlersHi
!byte >SelectWorldEventReturn
!byte >SelectWorldEventUp
!byte >SelectWorldEventUp
!byte >SelectWorldEventDown
!byte >SelectWorldEventDown
!byte >SelectWorldEventEsc
;------------------------------------------------------------------------------
; SelectWorld
; SelectWorldEventLoop
; allow user to select world for playing
;
; in: none
; out: C clear if world was selected, and
; A = 0-based world ID
; C set if no world was selected and A is undefined
; in: C clear if screen is already drawn
; (will happen if key was dispatched and handled its own redraw)
; C set if full screen clear & redraw is required
; (will happen if key is pressed during title screen, or
; if user returns to main menu from any other screen)
; out: Z = 0
;------------------------------------------------------------------------------
SelectWorld
SelectWorldEventLoop
bcc +
jsr DrawSelectWorldText
+ bit CLEARKBD
@keyloop
lda KBD
bpl @keyloop
bit CLEARKBD
sta gLastKeyPressed
ldx #0
- ldy kSelectWorldKeys, x
beq @keyloop ; key has no associated handler, so ignore it
cpy gLastKeyPressed
beq @dispatch
inx
bne - ; always branches
@dispatch
lda kSelectWorldKeyHandlersLo, x
sta @j+1
lda kSelectWorldKeyHandlersHi, x
sta @j+2
@j jsr $FDFD ; SMC
beq SelectWorldEventLoop
rts
SelectWorldEventReturn
jsr Home
lda selectedworld
sta gWorldID
jsr MaybeLoadWorldFromDisk
bcs SelectWorldEventEsc
jsr LoadProgressFromMemory
; A = next puzzle ID
@Play
sta gPuzzleID
ldx gWorldID
lda kWorldLeftMargins, x
sta GlobalLeftMargin
lda kPuzzleWidths, x
jsr InitPuzzleStorage
jsr InitPuzzleSound
ldx gPuzzleID
jsr LoadPuzzleFromMemory
lda #0
sta gSelectedLogicalColumn
jsr DrawPuzzleChrome
jsr DrawPuzzle
jsr AnimatePuzzleIntoPlace
jsr DrawColumnSelectionIndicator
jsr PlayEventLoop
cpx #kCompletedPuzzle
bne +
jsr AnimatePuzzleCompleted
ldx gPuzzleID
jsr MarkPuzzleCompleted
; A = next puzzle ID
; X = number of puzzles completed
jsr MaybeShowInterstitial
bcc @Play
bcs @DonePlay
+
cpx #kRequestedSkip
bne +
ldx gPuzzleID
jsr MarkPuzzleSkipped
jmp @Play
+
cpx #kRequestedRestart
bne @DonePlay
jsr Home
lda gPuzzleID
jmp @Play
@DonePlay
ldx #kStayOnSelectWorld
sec
rts
SelectWorldEventEsc
ldx #kReturnToMainMenu
sec
rts
SelectWorldEventUp
jsr RedrawPreviouslySelectedWorld
ldx selectedworld
bne +
ldx #12
+ dex
stx selectedworld
jsr DrawNewlySelectedWorld
ldx #kStayOnSelectWorld
clc
rts
SelectWorldEventDown
jsr RedrawPreviouslySelectedWorld
ldx selectedworld
cpx #11
bne +
ldx #$FF
+ inx
stx selectedworld
jsr DrawNewlySelectedWorld
ldx #kStayOnSelectWorld
clc
rts
DrawSelectWorldText
jsr Home
jsr UpdateWorldPercents
+LDADDR kWorldDescriptions
@ -51,57 +191,8 @@ SelectWorld
lda counter
cmp #12
bcc -
+PRINT_AT sWorldHelp, 23, 0
bit CLEARKBD
@selectWorldLoop
lda KBD
bpl @selectWorldLoop
bit CLEARKBD
and #$7F
cmp #$0B ; up arrow
beq @eventUpArrow
cmp #$0A ; down arrow
beq @eventDownArrow
cmp #$08 ; left arrow
beq @eventLeftArrow
cmp #$15 ; right arrow
beq @eventRightArrow
cmp #$0D
beq @eventReturn
cmp #$1B
beq @eventEsc
rts
@eventReturn
jsr Home
lda selectedworld
clc
rts
@eventEsc
sec
rts
@eventLeftArrow
@eventUpArrow
jsr RedrawPreviouslySelectedWorld
ldx selectedworld
bne +
ldx #12
+ dex
stx selectedworld
jsr DrawNewlySelectedWorld
jmp @selectWorldLoop
@eventRightArrow
@eventDownArrow
jsr RedrawPreviouslySelectedWorld
ldx selectedworld
cpx #11
bne +
ldx #$FF
+ inx
stx selectedworld
jsr DrawNewlySelectedWorld
jmp @selectWorldLoop
RedrawPreviouslySelectedWorld
lda selectedworld