From bfe01750b6c3eda387ef0d812550b0e81d84b8e9 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Fri, 20 Jun 2025 16:31:12 +0200 Subject: [PATCH] map: refactoring map loader --- src/defs.s | 12 ++++++++++++ src/map.s | 12 ++++++------ src/unit.s | 16 ++++++++++------ src/wram.s | 14 ++++++++++---- 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/src/defs.s b/src/defs.s index 2b7a6ff..62a08db 100644 --- a/src/defs.s +++ b/src/defs.s @@ -222,6 +222,18 @@ .de map_flags_3, 1 .de map_flags_4, 1 .de map_bg_ptr, 2 + ; ptr to mape state to be loaded +.de map_state_ptr, 2 + ; amount of entires in actor table +.de map_actor_table_len, 1 + ; ptr to actor table + ; actor table is a list of pointers to actor + ; templates +.de map_actor_table_ptr, 2 + ; pointers to tile banks to be loaded +.de map_tile_bank0_ptr, 2 +.de map_tile_bank1_ptr, 2 +.de map_tile_bank2_ptr, 2 ; special text commands diff --git a/src/map.s b/src/map.s index b768182..348a33e 100644 --- a/src/map.s +++ b/src/map.s @@ -16,7 +16,7 @@ map_init: ; b: tile index map_get_tile: ; current map - ld hl, state_cells + ld hl, map ld d, 0 ld e, MAP_W * c_size @@ -69,8 +69,8 @@ tile_map_bg_load: ; first clear push_all - ld hl, state_cells - ld bc, state_cells_end - state_cells + ld hl, map + ld bc, map_end - map ld d, 0 call memset @@ -82,7 +82,7 @@ tile_map_bg_load: ; de = loop counter ld de, MAP_SIZE ; bc = destination - ld hl, state_cells + ld hl, map ; hl = c_tile @loop: @@ -115,7 +115,7 @@ cells_draw_all: ld de, MAP_SIZE ld bc, SCRN0 - ld hl, state_cells + ld hl, map ; hl = c_tile @loop: @@ -141,7 +141,7 @@ cells_draw_all: ; sets up some actors for debug purposes map_load_demo_actors: ; load a single demo actor into p0 units - ld de, unit_demo_1 + ld de, unit_player ld hl, p0_units ld bc, act_size call memcpy diff --git a/src/unit.s b/src/unit.s index 1339831..4a47585 100644 --- a/src/unit.s +++ b/src/unit.s @@ -63,13 +63,17 @@ unit_update_draw: call_hl ret +unit_player_init: + ldnull bc + ret + unit_demo_1_init: ldnull bc ret ; inputs ; de: actor -unit_demo_1_update: +unit_player_update: push de ld hl, act_oam_flags add hl, de @@ -787,8 +791,8 @@ unit_get_inventory: unit_get_equipment: ret -unit_demo_1: - st_def 0x00, unit_demo_1_init, st_unit_idle +unit_player: + st_def 0x00, unit_player_init, st_unit_idle act_def ACT_T_DEMO_1, 0, 2, 2, 0 act_stat_def1 1, 1, 1, 1, 1, 1 act_stat_def2 1, 1, 1, 1, 1, 1, 1, 1 @@ -796,7 +800,7 @@ unit_demo_1: act_inventory_empty act_equipment_empty act_effects_empty - act_st_def NULL, NULL, st_unit_demo_1_update, st_unit_idle + act_st_def NULL, NULL, st_unit_player_update, st_unit_idle act_def_draw unit_draw, 0x84, 0 act_rt_def @@ -826,8 +830,8 @@ unit_demo_3: act_def_draw unit_draw, 0x84, 0 act_rt_def -st_unit_demo_1_update: - st_def 0x00, unit_demo_1_update, st_unit_demo_1_update +st_unit_player_update: + st_def 0x00, unit_player_update, st_unit_player_update st_unit_demo_1_cpu_update: st_def 0x00, unit_demo_1_cpu_update, st_unit_demo_1_cpu_update diff --git a/src/wram.s b/src/wram.s index fdd33a1..92a80e6 100644 --- a/src/wram.s +++ b/src/wram.s @@ -74,10 +74,16 @@ scroll_move_x: .adv 1 scroll_y: .adv 1 scroll_x: .adv 1 -; units for p0 and p1 +; units +; player_unit (unit 0) is reserved +player_unit: .adv 0 p0_units: .adv act_size * UNITS_MAX - -state_cells: .adv c_size * MAP_SIZE -state_cells_end: + + ; map tiles and collision data +map: .adv c_size * MAP_SIZE +map_end: + + ; mape state machine +map_st: .adv st_size state_end: -- 2.30.2