.db 0, 0, 0, 0 ; flags
dw default_map_bg
dw st_map_null
-dw map_actor_table_null
+dw default_map_actor_table
dw bank8000
dw bank8800
dw bank9000
--- /dev/null
+default_map_actor_table:
+.db 2 ; size
+dw unit_demo_2
+dw unit_demo_3
.de ACT_T_CURSOR, 1
.de ACT_T_DEMO_1, 1
- ; actor struct
+ ; actor struct (unit's are instances of actors)
; actor structs are basically just states
; to define an actor the following macros must be used in order
; st_def
; maps to map property actor_table_ptr
.de map_actor_table_ptr, 2
; pointers to tile banks to be loaded
- ; maps to map property bank0, bank1, bank2
+ ; maps to map property tile_bank0, tile_bank1, tile_bank2
.de map_tile_bank0_ptr, 2
.de map_tile_bank1_ptr, 2
.de map_tile_bank2_ptr, 2
+
+ ; map actor table struct
+.se 0
+.de map_actor_table_len, 1
+ ; list of be pointers to actors
+.de map_actor_table_act_ptrs, 0
+
; special text commands
; consumes the command
#include "effect.s"
#include "text.s"
#include "stats.s"
+#include "actortables.s"
; fill bank
.fill 0, 0x7FFF - $
; initial map setup
map_init:
ld hl, default_map_header
- call tile_map_load
- call cells_draw_all
+ ; loads a new map
+ ; inputs:
+ ; hl: map ptr
+map_load:
+ push hl
+ call map_tiles_load
+
+ pop hl
+ push hl
+ call map_state_load
+ pop hl
+
+ push hl
+ call map_actors_load
+ pop hl
+
+ call map_draw_all
ret
ret
- ; loads a map
+ ; loads map tiles
; inputs:
; hl: map header
-tile_map_load:
+map_tiles_load:
; load bg ptr
ld de, map_bg_ptr
add hl, de ; hl = bg_ptr
jr nz, @loop REL
ret
+
+ ; loads a map's state
+ ; inputs:
+ ; hl: map ptr
+map_state_load:
+ ld de, map_state_ptr
+ add hl, de ; hl = state ptr ptr
+
+ ld a, [hl+]
+ ld e, a
+ ld a, [hl]
+ ld d, a
+ ; de = state ptr
+ ld hl, map_st
+ ld bc, st_size
+ call memcpy
+
+ ret
+
+ ; loads a map's actor table
+ ; starting at p0_actors+1 (0 is reserved for player)
+ ; inputs:
+ ; hl: map ptr
+map_actors_load:
+ ; first clear actor table except player
+ push hl
+ ld hl, p0_units + act_size
+ ld bc, act_size * (UNITS_MAX - 1)
+ ld d, 0
+ call memset
+ pop hl
+
+ ld de, map_actor_table_ptr
+ add hl, de ; hl = actor table ptr
+
+ ld a, [hl+]
+ ld e, a
+ ld a, [hl]
+ ld d, a
+ ; de = actor table
+
+ ; load actor count
+ ld a, [de]
+ inc de ; de = first actor ptr
+
+ ; load starting at slot 1
+ ; hl = dst
+ ld hl, p0_units + act_size
+ @loop:
+ ; load next actor
+ push af
+ push hl
+
+ ; load ptr
+ ld a, [de]
+ ld b, a
+ inc de
+ ld a, [de]
+ inc de
+ ; save de for now
+ ; de = next ptr
+ push de
+
+ ; set src ptr
+ ld e, b
+ ld d, a
+ ; de = str ptr
+ ; hl = dst already
+ ld bc, act_size
+ call memcpy
+
+
+ ; copy
+
+ pop de
+ pop hl
+ push de
+ ; move to next actor destination
+ ld de, act_size
+ add hl, de
+ pop de
+
+ pop af
+ ; i--
+ dec a
+ jr nz, @loop REL
+
+ ; hand over control to a unit
+ ld de, p_empty_unit
+ call unit_next_request
+ ret
; draws all cells currently loaded to the screen
; only call during blank!
-cells_draw_all:
+map_draw_all:
; de = loop counter
ld de, MAP_SIZE
; set up game mode
- call map_load_demo_actors
+ call unit_load_default_player
call game_init
call mbc1_init
unit_get_equipment:
ret
+ ; loads the default player unit
+ ; and hands over control
+unit_load_default_player:
+ ld de, unit_player
+ ld hl, p0_units
+ ld bc, act_size
+ call memcpy
+
+ ld de, p_empty_unit
+ call unit_next_request
+ ret
+
unit_player:
st_def 0x00, unit_player_init, st_unit_idle
act_def ACT_T_DEMO_1, 0, 2, 2, 0
; clear oam
call shadow_oam_clear
+ ; update map state
+ ld de, map_st
+ call st_update
+
ld hl, p0_units
call units_update
get_flag(child)
def get_map_props(root):
- global state_ptr, actor_table_ptr, tile_bank0, tile_bank1, tile_bank2
+ global state_ptr
+ global actor_table_ptr
+ global tile_bank0
+ global tile_bank1
+ global tile_bank2
+
for child in root:
if child.tag == "properties":
for prop in child:
if name == 'state_ptr':
state_ptr = value
elif name == 'actor_table_ptr':
- actor_table_ptr = value
+ actor_table_ptr = value
elif name == 'tile_bank0':
tile_bank0 = value
elif name == 'tile_bank1':