This refactored default loading and moved it to game init.
The menu rendering is currently still broken.
call vblank_wait
call enableinterrupts
-
- ; init initial map
- call map_init
; main for gameply
#ifndef TEST_BUILD
; handles cursor sprite drawing
; handles file/new game selection
main_menu_update:
+ ld b, BTNSTART ; b = button mask
+ input_just
+ jr z, @no_new_game REL
+ ld bc, st_init_new_game
+ ret
+@no_new_game:
ldnull bc
ret
; inits main menu
; draws the menu screen to SCRN0
+ ; disables lcd and interrupts while it is
+ ; loading
main_menu_init:
+ call video_fade_out
+
+ call unit_load_default_player
+ ; load default map
+ ; to get the engine to load a tileset
+ call map_init
+
+ ld hl, STR_PRESS_START
+ ld de, SCRN0+128+2
+ call puts
+
+ ; hide window
+ ld a, 144
+ ld [RWY], a
+ ld [RWX], a
+
+ call video_fade_in
ldnull bc
ret
mem_init:
- ; clear wram
+ ; clear wram
ld a, 0
ld hl, WRAM
ld bc, WRAMLEN
call memset
+ ; set up rand
call rand_init
; copy shadow oam dma function
ld bc, shadow_oam_to_oam_end - shadow_oam_to_oam
call memcpy
- ; set up game mode
-
- call unit_load_default_player
- call game_init
+ ; set up mbc1
call mbc1_init
+
+ ; load initial game state
+ ld de, st_main_menu_init
+ ld hl, game_mode
+ ld bc, st_size
+ call memcpy
; copy delay to active template to wram
ld de, st_unit_delay_to_active_template
ret
-game_init:
- ld de, st_update_game
- ld hl, game_mode
- ld bc, st_size
- jp memcpy
-
; copies memory from one location to another
; inputs:
; de: source
STR_TEST:
.str "0123456789ABCDEF"
+.db 0
+
+STR_PRESS_START:
+.str "PRESS START"
.db 0
; print a 0-terminated string to the screen
; hl: the string
; de: tile location
puts:
-@loop:
ld a, [hl+]
cp a, 0
jr z, @done REL
add a, FONT_OFFSET
ld [de], a
inc de
- jr @loop REL
+ jr puts REL
@done:
ret
ld de, game_mode
jp st_update
+
+ ; sets up a new game
+ ; loads default player
+ ; fades out the screen
+ ; loads default map
+new_game_init:
+ call video_fade_out
+
+ call unit_load_default_player
+
+ ; init initial map
+ call map_init
+
+ call game_init
+ call video_fade_in
+ ret
+
+ ; geric game init call
+ ; sets up window
+ ; inits UI
+game_init:
+ ; set up UI
+ ld a, WINDOW_Y
+ ld [RWY], a
+ ld a, WINDOW_X
+ ld [RWX], a
+
+ call ui_init
+
+ ldnull bc
+ ret
+
+st_init_new_game:
+ st_def 0x00, new_game_init, st_update_game
st_update_game:
st_def 0x00, update_game, st_update_game
ld a, 0b11011000
ld [ROBP1], a
- call ui_init
-
- ld a, WINDOW_Y
- ld [RWY], a
- ld a, WINDOW_X
- ld [RWX], a
-
ret
; delays by n frames