million-perfect-letters/src/ui.main.menu.a

158 lines
4.8 KiB
Plaintext
Raw Normal View History

2020-04-22 20:41:59 +00:00
;license:MIT
2022-01-18 18:46:15 +00:00
;(c) 2020-2 by 4am
2020-04-22 20:41:59 +00:00
;
; main menu
2020-04-22 20:41:59 +00:00
;
; Public functions:
2020-09-24 02:24:49 +00:00
; - MainMenuEventLoop
2020-04-22 20:41:59 +00:00
;
2020-07-10 01:20:08 +00:00
; Codes returned by event handlers
kStayOnMainMenu = 0
kQuit = 1
2020-07-10 01:20:08 +00:00
kMainMenuKeys ; must keep in sync with kMainMenuKeyHandlersLo/Hi arrays
; except for last byte ($00) which doesn't need an associated handler
!byte $8D ; Return
!byte $C3 ; C
!byte $E3 ; c
!byte $D3 ; S
!byte $F3 ; s
2022-01-18 02:34:13 +00:00
!byte $93 ; Ctrl-S
!byte $C4 ; D
!byte $E4 ; d
!byte $D1 ; Q
!byte $F1 ; q
!byte $9B ; Esc
2020-07-10 01:20:08 +00:00
!byte $00
kMainMenuKeyHandlersLo
!byte <MainMenuEventReturn
!byte <MainMenuEventC
!byte <MainMenuEventC
!byte <MainMenuEventS
!byte <MainMenuEventS
2022-01-18 02:34:13 +00:00
!byte <MainMenuEventS
!byte <MainMenuEventD
!byte <MainMenuEventD
2020-07-10 01:20:08 +00:00
!byte <MainMenuEventQ
!byte <MainMenuEventQ
!byte <MainMenuEventQ
kMainMenuKeyHandlersHi
!byte >MainMenuEventReturn
!byte >MainMenuEventC
!byte >MainMenuEventC
!byte >MainMenuEventS
!byte >MainMenuEventS
2022-01-18 02:34:13 +00:00
!byte >MainMenuEventS
!byte >MainMenuEventD
!byte >MainMenuEventD
2020-07-10 01:20:08 +00:00
!byte >MainMenuEventQ
!byte >MainMenuEventQ
!byte >MainMenuEventQ
2020-09-24 02:24:49 +00:00
;------------------------------------------------------------------------------
; MainMenuEventLoop
; display main menu
;
2020-04-22 20:41:59 +00:00
; 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
; (will happen if key is pressed during title screen, or
; if user returns to main menu from any other screen)
; out: Z = 0
2020-09-24 02:24:49 +00:00
;------------------------------------------------------------------------------
MainMenuEventLoop
2020-05-04 02:36:06 +00:00
bcc +
2020-07-10 01:20:08 +00:00
jsr DrawMainMenuTitle
+ jsr DrawMainMenuText
2020-05-05 01:46:19 +00:00
bit CLEARKBD
@musicloop
+LDADDR kMainMenuKeys
+ST16 $EE
2020-05-04 02:36:06 +00:00
+LDADDR MainMenuMusic
jsr PlaySound
bpl @musicloop ; music played to completion, no keypress, so start over
2020-05-04 02:36:06 +00:00
bit CLEARKBD
2020-10-02 01:35:55 +00:00
sta gLastKeyPressed
2020-07-10 01:20:08 +00:00
ldx #0
@keyloop
ldy kMainMenuKeys, x
beq @musicloop ; key has no associated handler, so ignore it
2020-07-10 01:20:08 +00:00
cpy gLastKeyPressed
beq @dispatch
2020-07-10 01:20:08 +00:00
inx
bne @keyloop ; always branches
@dispatch
lda kMainMenuKeyHandlersLo, x
2020-07-10 01:20:08 +00:00
sta @j+1
lda kMainMenuKeyHandlersHi, x
sta @j+2
@j jsr $FDFD ; SMC
beq MainMenuEventLoop
2020-05-04 02:36:06 +00:00
rts
2020-07-10 01:20:08 +00:00
MainMenuEventReturn
sec ; C=1 to trigger full redraw of 'select world' page
jsr SelectWorldEventLoop
jmp StayOnMainMenuWithFullRefresh
2020-07-10 01:20:08 +00:00
MainMenuEventD
jsr RunDemo
jmp StayOnMainMenuWithFullRefresh
2020-07-10 01:20:08 +00:00
MainMenuEventC
2020-05-04 16:56:05 +00:00
jsr AboutPage
StayOnMainMenuWithFullRefresh
ldx #kStayOnMainMenu ; Z=1 so caller will stay in main menu event loop
2020-07-10 01:20:08 +00:00
sec ; C=1 so caller will do a full screen refresh
rts
MainMenuEventS
jsr ToggleSoundPref
2020-07-10 01:20:08 +00:00
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 #kQuit ; Z=0 so caller will exit main menu event loop
2020-07-10 01:20:08 +00:00
rts
DrawMainMenuTitle
2020-04-22 20:41:59 +00:00
jsr Home
2020-04-28 02:45:54 +00:00
lda #1
sta GlobalLeftMargin
2020-04-22 20:41:59 +00:00
ldy #3
- ldx #1
lda sTitleLine1-2, y
2020-04-22 20:41:59 +00:00
jsr DrawLargeCharacter
inx
lda sTitleLine2-2, y
2020-04-22 20:41:59 +00:00
jsr DrawLargeCharacter
inx
lda sTitleLine3-2, y
2020-04-22 20:41:59 +00:00
jsr DrawLargeCharacter
iny
cpy #$0A
bne -
2020-05-04 02:34:12 +00:00
rts
2020-07-10 01:20:08 +00:00
DrawMainMenuText
+PRINT_AT sAsterisk, 2, 30
+PRINT_AT sVersion, 11, 26
+PRINT_AT sMainMenuPlay, 15, 10
+PRINT_AT sMainMenuSound, 16, 10
2020-05-05 01:46:19 +00:00
lda gSoundPref
beq @theSoundOfSilence
+LDADDR sMainMenuSoundOn
2020-05-05 01:46:19 +00:00
bne + ; always branches
@theSoundOfSilence
+LDADDR sMainMenuSoundOff
2020-05-05 01:46:19 +00:00
+ jsr DrawHeavySilkString
+PRINT_AT sMainMenuAbout, 17, 10
+PRINT_AT sMainMenuDemo, 18, 10
+PRINT_AT sMainMenuQuit, 19, 10
+PRINT_AT sMainMenuDisclaimer, 23, 0
2020-04-24 03:39:00 +00:00
rts