map: refactoring map loader
authorLukas Krickl <lukas@krickl.dev>
Fri, 20 Jun 2025 14:31:12 +0000 (16:31 +0200)
committerLukas Krickl <lukas@krickl.dev>
Fri, 20 Jun 2025 14:31:12 +0000 (16:31 +0200)
src/defs.s
src/map.s
src/unit.s
src/wram.s

index 2b7a6fff9675d76fb3c7f168c14f2d4047a6ed05..62a08db20aefd42f43bb92723827d843e73f44f0 100644 (file)
 .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
 
index b768182f7990049f058efc256e2c89a4b1320ecd..348a33e9fee59dce4b36bf3f5ebff6a4a5b09f99 100644 (file)
--- 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
index 13398316d4d499b4b5b93bb61b38790d199d1e66..4a47585081e3d8aada750017f9ec8dbc1762c3f8 100644 (file)
@@ -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
index fdd33a17c17a0c30754b0b19e37eaa75005e3836..92a80e61a636b6b8648b7cd7ce538563e25806e2 100644 (file)
@@ -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: