;license:MIT ;(c) 2020-2 by 4am ; ; main menu ; ; Public functions: ; - MainMenuEventLoop ; ; Codes returned by event handlers kStayOnMainMenu = 0 kQuit = 1 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 !byte $93 ; Ctrl-S !byte $C4 ; D !byte $E4 ; d !byte $D1 ; Q !byte $F1 ; q !byte $9B ; Esc !byte $00 kMainMenuKeyHandlersLo !byte MainMenuEventReturn !byte >MainMenuEventC !byte >MainMenuEventC !byte >MainMenuEventS !byte >MainMenuEventS !byte >MainMenuEventS !byte >MainMenuEventD !byte >MainMenuEventD !byte >MainMenuEventQ !byte >MainMenuEventQ !byte >MainMenuEventQ ;------------------------------------------------------------------------------ ; MainMenuEventLoop ; display main menu ; ; 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 ;------------------------------------------------------------------------------ MainMenuEventLoop bcc + jsr DrawMainMenuTitle + jsr DrawMainMenuText bit CLEARKBD @musicloop +LDADDR kMainMenuKeys +ST16 $EE +LDADDR MainMenuMusic jsr PlaySound bpl @musicloop ; music played to completion, no keypress, so start over bit CLEARKBD sta gLastKeyPressed ldx #0 @keyloop ldy kMainMenuKeys, x beq @musicloop ; key has no associated handler, so ignore it cpy gLastKeyPressed beq @dispatch inx bne @keyloop ; always branches @dispatch lda kMainMenuKeyHandlersLo, x sta @j+1 lda kMainMenuKeyHandlersHi, x sta @j+2 @j jsr $FDFD ; SMC beq MainMenuEventLoop rts MainMenuEventReturn sec ; C=1 to trigger full redraw of 'select world' page jsr SelectWorldEventLoop jmp StayOnMainMenuWithFullRefresh MainMenuEventD jsr RunDemo jmp StayOnMainMenuWithFullRefresh MainMenuEventC jsr AboutPage 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 MainMenuEventS jsr ToggleSoundPref 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 rts DrawMainMenuTitle jsr Home lda #1 sta GlobalLeftMargin ldy #3 - ldx #1 lda sTitleLine1-2, y jsr DrawLargeCharacter inx lda sTitleLine2-2, y jsr DrawLargeCharacter inx lda sTitleLine3-2, y jsr DrawLargeCharacter iny cpy #$0A bne - rts DrawMainMenuText +PRINT_AT sAsterisk, 2, 30 +PRINT_AT sVersion, 11, 26 +PRINT_AT sMainMenuPlay, 15, 10 +PRINT_AT sMainMenuSound, 16, 10 lda gSoundPref beq @theSoundOfSilence +LDADDR sMainMenuSoundOn bne + ; always branches @theSoundOfSilence +LDADDR sMainMenuSoundOff + jsr DrawHeavySilkString +PRINT_AT sMainMenuAbout, 17, 10 +PRINT_AT sMainMenuDemo, 18, 10 +PRINT_AT sMainMenuQuit, 19, 10 +PRINT_AT sMainMenuDisclaimer, 23, 0 rts