main menu: added basic framework for menus
authorLukas Krickl <lukas@krickl.dev>
Tue, 15 Jul 2025 15:46:49 +0000 (17:46 +0200)
committerLukas Krickl <lukas@krickl.dev>
Tue, 15 Jul 2025 15:46:49 +0000 (17:46 +0200)
This menu is currently not doing much.
Moved palette loading to game_init and main_menu_init.

src/mainmenu.s
src/strings.s
src/update.s
src/video.s
src/wram.s
tiles/bank8C00.inc

index dfcaf2bd8fe7f72f9d4bec6d24cd9e5d3e1021ee..df26ed9d349b4626f079c27576da60324d5a6fe9 100644 (file)
@@ -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
index 32b78e1df2115e4e77c28aa5c63d1bdab64603ba..18f8297c9de35d5338a3cfeb0e685e1342e7358e 100644 (file)
@@ -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 
index 1e001648af6ec185ea3b80f2445a56dc03f1a51d..c72a775e07fd94ffc95b5b2ebe95f9c471459617 100644 (file)
@@ -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
 
index 8301bc617417b581fb2584dbb4c2769dca096b92..c7f1ab41615edd9c1287b4c8377a2bca8f918ae6 100644 (file)
@@ -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]
index b6a895a8cf9c3f720e132e371425f977bc1e2638..826657ba2183e2b380f72d9b9cce63fa461321c6 100644 (file)
@@ -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 
index 55b32596de32b129f63a9f306b36ac39e7e501ec..bf12a2ffcc0dfa76d121dcec99807f1dd89fffd1 100644 (file)
 .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