From: Lukas Krickl Date: Fri, 20 Jun 2025 17:30:38 +0000 (+0200) Subject: unit: code cleanup X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=326e33c95d6daca82d41b82356c911da7efa9fba;p=gbrg%2F.git unit: code cleanup --- diff --git a/src/actortables.s b/src/actortables.s index 51c2261..331ecc8 100644 --- a/src/actortables.s +++ b/src/actortables.s @@ -1,4 +1,9 @@ +#include "unit_demo.s" + default_map_actor_table: .db 2 ; size dw unit_demo_2 dw unit_demo_3 + + + diff --git a/src/player.s b/src/player.s index 822a4a6..a2d31fc 100644 --- a/src/player.s +++ b/src/player.s @@ -1,2 +1,56 @@ .def int CURSOR_TILE = 0x04 + ; 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_init: + ldnull bc + ret + + ; inputs + ; de: actor +unit_player_update: + push de + ld hl, act_oam_flags + add hl, de + ld a, [hl] + or a, OAM_FXFLIP + ld [hl], a + pop de + + + push de + call unit_handle_inputs + pop de + + push de + call unit_scroll_center + pop de + + ret + + +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 + act_attr_def_empty + act_inventory_empty + act_equipment_empty + act_effects_empty + act_st_def NULL, NULL, st_unit_player_update, st_unit_idle + act_def_draw unit_draw, 0x84, 0 + act_rt_def + +st_unit_player_update: + st_def 0x00, unit_player_update, st_unit_player_update diff --git a/src/unit.s b/src/unit.s index b837c43..a04511c 100644 --- a/src/unit.s +++ b/src/unit.s @@ -63,44 +63,6 @@ unit_update_draw: call_hl ret -unit_player_init: - ldnull bc - ret - -unit_demo_1_init: - ldnull bc - ret - - ; inputs - ; de: actor -unit_player_update: - push de - ld hl, act_oam_flags - add hl, de - ld a, [hl] - or a, OAM_FXFLIP - ld [hl], a - pop de - - - push de - call unit_handle_inputs - pop de - - push de - call unit_scroll_center - pop de - - ret - - ; cpu controllerd unit update -unit_demo_1_cpu_update: - push de - call unit_handle_cpu_inputs - pop de - - ret - unit_handle_cpu_inputs: ; pick where to go call roll_d16 @@ -791,63 +753,6 @@ unit_get_inventory: 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 - act_stat_def1 1, 1, 1, 1, 1, 1 - act_stat_def2 1, 1, 1, 1, 1, 1, 1, 1 - act_attr_def_empty - act_inventory_empty - act_equipment_empty - act_effects_empty - act_st_def NULL, NULL, st_unit_player_update, st_unit_idle - act_def_draw unit_draw, 0x84, 0 - act_rt_def - -unit_demo_2: - st_def 0x00, unit_demo_1_init, st_unit_idle - act_def ACT_T_DEMO_1, 0, 3, 3, 0 - act_stat_def1 1, 1, 1, 1, 1, 1 - act_stat_def2 1, 1, 1, 1, 1, 1, 1, 1 - act_attr_def_empty - act_inventory_empty - act_equipment_empty - act_effects_empty - act_st_def NULL, NULL, st_unit_demo_1_cpu_update, st_unit_idle - act_def_draw unit_draw, 0x84, 0 - act_rt_def - -unit_demo_3: - st_def 0x00, unit_demo_1_init, st_unit_idle - act_def ACT_T_DEMO_1, 0, 4, 4, 0 - act_stat_def1 1, 1, 1, 1, 1, 1 - act_stat_def2 1, 1, 1, 1, 1, 1, 1, 1 - act_attr_def_empty - act_inventory_empty - act_equipment_empty - act_effects_empty - act_st_def NULL, NULL, st_unit_demo_1_cpu_update, st_unit_idle - act_def_draw unit_draw, 0x84, 0 - act_rt_def - -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 - st_unit_idle: st_def 0x00, unit_idle, st_unit_idle diff --git a/src/unit_demo.s b/src/unit_demo.s new file mode 100644 index 0000000..21ada6b --- /dev/null +++ b/src/unit_demo.s @@ -0,0 +1,43 @@ + +unit_demo_1_init: + ldnull bc + ret + + ; cpu controllerd unit update +unit_demo_1_cpu_update: + push de + call unit_handle_cpu_inputs + pop de + + ret + +unit_demo_2: + st_def 0x00, unit_demo_1_init, st_unit_idle + act_def ACT_T_DEMO_1, 0, 3, 3, 0 + act_stat_def1 1, 1, 1, 1, 1, 1 + act_stat_def2 1, 1, 1, 1, 1, 1, 1, 1 + act_attr_def_empty + act_inventory_empty + act_equipment_empty + act_effects_empty + act_st_def NULL, NULL, st_unit_demo_1_cpu_update, st_unit_idle + act_def_draw unit_draw, 0x84, 0 + act_rt_def + +unit_demo_3: + st_def 0x00, unit_demo_1_init, st_unit_idle + act_def ACT_T_DEMO_1, 0, 4, 4, 0 + act_stat_def1 1, 1, 1, 1, 1, 1 + act_stat_def2 1, 1, 1, 1, 1, 1, 1, 1 + act_attr_def_empty + act_inventory_empty + act_equipment_empty + act_effects_empty + act_st_def NULL, NULL, st_unit_demo_1_cpu_update, st_unit_idle + act_def_draw unit_draw, 0x84, 0 + act_rt_def + + +st_unit_demo_1_cpu_update: + st_def 0x00, unit_demo_1_cpu_update, st_unit_demo_1_cpu_update +