From 729cc2feaf58935e88e2b64641dfc25b7e73be61 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Tue, 15 Jul 2025 17:46:49 +0200 Subject: [PATCH] main menu: added basic framework for menus This menu is currently not doing much. Moved palette loading to game_init and main_menu_init. --- src/mainmenu.s | 122 +++++++++++++++++++++++++++++++++++++++++---- src/strings.s | 16 ++++++ src/update.s | 11 ++++ src/video.s | 12 ++--- src/wram.s | 7 +++ tiles/bank8C00.inc | 16 +++--- 6 files changed, 156 insertions(+), 28 deletions(-) diff --git a/src/mainmenu.s b/src/mainmenu.s index dfcaf2b..df26ed9 100644 --- a/src/mainmenu.s +++ b/src/mainmenu.s @@ -1,14 +1,84 @@ - +#define MAIN_MENU_FILE_1_OFFSET 128+2 + +#define MENU_CURSOR_TILE 0xF5 + + + ; location table for cursor + ; y positon +main_menu_cursor_locations_y: +.db 40, 48, 56, 72 + +#define MAIN_MENU_CURSOR_MAX 3 + + ; fixed x position +#define main_menu_cursor_x 16 + ; update main menu state ; handles cursor sprite drawing ; handles file/new game selection main_menu_update: - ld b, BTNSTART ; b = button mask + ; clear oam + call shadow_oam_clear + + ; ensure the cursor is capped to MAX + ld a, [menu_cursor_index] + and a, MAIN_MENU_CURSOR_MAX + ld [menu_cursor_index], a + + ; draw cursor as sprite + ld d, 0 + ld a, [menu_cursor_index] + ld e, a ; de = cursor location offset + ld hl, main_menu_cursor_locations_y + add hl, de + ld a, [hl] ; a = y position + + ld hl, shadow_oam + ld [hl+], a ; write y + + ld a, main_menu_cursor_x + ld [hl+], a ; write x + + ; write tile + ld a, MENU_CURSOR_TILE + ld [hl+], a + + xor a, a + ld [hl], a ; write flags + + + ld b, BTNSTART | BTNA ; b = button mask input_just jr z, @no_new_game REL ld bc, st_init_new_game ret @no_new_game: + + ld b, BTNDOWN + input_held + jr z, @not_down REL + + ; cursor++ + ld a, [menu_cursor_index] + inc a + ld [menu_cursor_index], a + ld bc, st_main_menu_delay + ret +@not_down: + + + ld b, BTNUP + input_held + jr z, @not_up REL + + ; cursor-- + ld a, [menu_cursor_index] + dec a + ld [menu_cursor_index], a + ld bc, st_main_menu_delay + ret +@not_up: + ldnull bc ret @@ -17,17 +87,41 @@ main_menu_update: ; disables lcd and interrupts while it is ; loading main_menu_init: - call video_fade_out - + call next_vblank_wait + call lcd_off + + ; set up palettes + ; for main menu + ld a, 0b11000000 + ld [RBGP], a + + ld a, 0b11000000 + ld [ROBP0], a + + ld a, 0b11000000 + ld [ROBP1], a + call unit_load_default_player - ; load default map - ; to get the engine to load a tileset - call map_init + + ; load tile banks of default map + ld hl, default_map_header + call map_tile_banks_load - call lcd_off - ld hl, STR_PRESS_START - ld de, SCRN0+128+2 + ld hl, STR_FILE1 + ld de, SCRN0+MAIN_MENU_FILE_1_OFFSET + call puts + + ld hl, STR_FILE2 + ld de, SCRN0+MAIN_MENU_FILE_1_OFFSET+32 + call puts + + ld hl, STR_FILE3 + ld de, SCRN0+MAIN_MENU_FILE_1_OFFSET+64 + call puts + + ld hl, STR_DELETE + ld de, SCRN0+MAIN_MENU_FILE_1_OFFSET+128 call puts ; hide window @@ -35,13 +129,19 @@ main_menu_init: ld [RWY], a ld [RWX], a + ; set cursor index to 0 + xor a, a + ld [menu_cursor_index], a + call lcd_on - call video_fade_in ldnull bc ret st_main_menu_update: st_def 0x00, main_menu_update, st_main_menu_update +st_main_menu_delay: + st_def 16, st_null_fn, st_main_menu_update + st_main_menu_init: st_def 0x00, main_menu_init, st_main_menu_update diff --git a/src/strings.s b/src/strings.s index 32b78e1..18f8297 100644 --- a/src/strings.s +++ b/src/strings.s @@ -31,6 +31,22 @@ STR_TEST: STR_PRESS_START: .str "PRESS START" +.db 0 + +STR_FILE1: +.str "File 1" +.db 0 + +STR_FILE2: +.str "File 2" +.db 0 + +STR_FILE3: +.str "File 3" +.db 0 + +STR_DELETE: +.str "DELETE" .db 0 ; print a 0-terminated string to the screen diff --git a/src/update.s b/src/update.s index 1e00164..c72a775 100644 --- a/src/update.s +++ b/src/update.s @@ -63,6 +63,17 @@ game_init: call ui_init + ; set up palettes for + ; gameplay + ld a, BGP + ld [RBGP], a + + ld a, 0b11100100 + ld [ROBP0], a + + ld a, 0b11011000 + ld [ROBP1], a + ldnull bc ret diff --git a/src/video.s b/src/video.s index 8301bc6..c7f1ab4 100644 --- a/src/video.s +++ b/src/video.s @@ -128,15 +128,6 @@ video_init: ld d, UI_WINDOW_BACKGROUND call memset - ; set up bgp - ld a, BGP - ld [RBGP], a - - ld a, 0b11100100 - ld [ROBP0], a - - ld a, 0b11011000 - ld [ROBP1], a ret @@ -175,6 +166,9 @@ video_wait_n_frames: ; disables window video_fade_out: push_all + + ld a, [BGP] + ld [shadow_bgp], a ; disable winodw ld a, [RLCD] diff --git a/src/wram.s b/src/wram.s index b6a895a..826657b 100644 --- a/src/wram.s +++ b/src/wram.s @@ -10,6 +10,10 @@ shadow_oam_end: ; as storage scratch: .adv 16 + ; backup of RBGP + ; used by video fade in and fade out +shadow_bgp: .adv 1 + frame_ready: .adv 1 frame_count: .adv 1 @@ -33,6 +37,9 @@ status_text: .adv 32 ; if set to NULL do not read from this address demo_inputs: .adv 2 + ; menu cursor can be used by any in-game menu +menu_cursor_index: .adv 1 + ; offset into bg_update_queue bg_update_index: .adv 1 ; current entry bg_update_queue: .adv bge_size * BGE_MAX diff --git a/tiles/bank8C00.inc b/tiles/bank8C00.inc index 55b3259..bf12a2f 100644 --- a/tiles/bank8C00.inc +++ b/tiles/bank8C00.inc @@ -476,14 +476,14 @@ .chr 22222222 .chr 22222222 ; tile 53 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 +.chr 22332222 +.chr 22333222 +.chr 22333322 +.chr 22333332 +.chr 22333332 +.chr 22333322 +.chr 22333222 +.chr 22332222 ; tile 54 .chr 00000000 .chr 00000000 -- 2.30.2