From eb3b4cb991a7159687936dd554fc65caba7e6a05 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Thu, 21 Aug 2025 08:56:35 +0200 Subject: [PATCH] exits: removed rerferences to existing exit tables This is the first step for the exti system rework. --- maps/map_bc.s | 1 - maps/map_be.s | 1 - maps/map_bw.s | 1 - maps/map_c.s | 1 - maps/map_ce.s | 1 - maps/map_cw.s | 1 - maps/map_tc.s | 1 - maps/map_te.s | 1 - maps/map_tw.s | 1 - src/defs.s | 20 ++------ src/exittables.s | 59 ----------------------- src/map.s | 18 ------- src/player.s | 121 ++++++----------------------------------------- src/wram.s | 2 - tools/tms2map.py | 5 -- 15 files changed, 17 insertions(+), 217 deletions(-) diff --git a/maps/map_bc.s b/maps/map_bc.s index 65fd2ea..0d9c1cd 100644 --- a/maps/map_bc.s +++ b/maps/map_bc.s @@ -9,7 +9,6 @@ dw bank8000 dw bank8800 dw bank8C00 dw bank9000 -dw map_bc_exit_table map_bc_bg: diff --git a/maps/map_be.s b/maps/map_be.s index 9563a23..151bc9a 100644 --- a/maps/map_be.s +++ b/maps/map_be.s @@ -9,7 +9,6 @@ dw bank8000 dw bank8800 dw bank8C00 dw bank9000 -dw map_be_exit_table map_be_bg: diff --git a/maps/map_bw.s b/maps/map_bw.s index 4d47b49..11ffaa1 100644 --- a/maps/map_bw.s +++ b/maps/map_bw.s @@ -9,7 +9,6 @@ dw bank8000 dw bank8800 dw bank8C00 dw bank9000 -dw map_bw_exit_table map_bw_bg: diff --git a/maps/map_c.s b/maps/map_c.s index 77b9b6b..eff1eea 100644 --- a/maps/map_c.s +++ b/maps/map_c.s @@ -9,7 +9,6 @@ dw bank8000 dw bank8800 dw bank8C00 dw bank9000 -dw map_c_exit_table map_c_bg: diff --git a/maps/map_ce.s b/maps/map_ce.s index 229addf..cc69515 100644 --- a/maps/map_ce.s +++ b/maps/map_ce.s @@ -9,7 +9,6 @@ dw bank8000 dw bank8800 dw bank8C00 dw bank9000 -dw map_ce_exit_table map_ce_bg: diff --git a/maps/map_cw.s b/maps/map_cw.s index d9bbd83..54d29a6 100644 --- a/maps/map_cw.s +++ b/maps/map_cw.s @@ -9,7 +9,6 @@ dw bank8000 dw bank8800 dw bank8C00 dw bank9000 -dw map_cw_exit_table map_cw_bg: diff --git a/maps/map_tc.s b/maps/map_tc.s index 54526d5..12fe21d 100644 --- a/maps/map_tc.s +++ b/maps/map_tc.s @@ -9,7 +9,6 @@ dw bank8000 dw bank8800 dw bank8C00 dw bank9000 -dw map_tc_exit_table map_tc_bg: diff --git a/maps/map_te.s b/maps/map_te.s index e89f838..38ae4ce 100644 --- a/maps/map_te.s +++ b/maps/map_te.s @@ -9,7 +9,6 @@ dw bank8000 dw bank8800 dw bank8C00 dw bank9000 -dw map_te_exit_table map_te_bg: diff --git a/maps/map_tw.s b/maps/map_tw.s index 8a56c20..00dd49a 100644 --- a/maps/map_tw.s +++ b/maps/map_tw.s @@ -9,7 +9,6 @@ dw bank8000 dw bank8800 dw bank8C00 dw bank9000 -dw map_tw_exit_table map_tw_bg: diff --git a/src/defs.s b/src/defs.s index 23e5aea..849af37 100644 --- a/src/defs.s +++ b/src/defs.s @@ -86,10 +86,9 @@ .se 1 .de CF_COLLISION, 1 ; exit flag - ; if this flag is set - ; the upper nibble is - ; an index into the current map's - ; exit table + ; flags this tile as a valid exit + ; must be at the edge of the map + ; TODO: maybe add a special exit as a default .de CF_EXIT, 2 .de CF_DOOR, 4 ; if this flag is set do not @@ -297,10 +296,6 @@ .de map_tile_bank1_ptr, 2 .de map_tile_bank2_ptr, 2 .de map_tile_bank3_ptr, 2 - - ; pointer to exit table - ; -.de map_exit_table_ptr, 2 .de map_header_size, 0 ; map actor table struct @@ -309,15 +304,6 @@ ; list of be pointers to actors .de map_actor_table_act_ptrs, 0 - ; map exit flags -.se 1 - ; if these flags are set goto_y and - ; goto_x are treated as relative offsets - ; instead of absolute tile positions -.de EXITF_GOTOY_REL, 1 -.de EXITF_GOTOX_REL, 2 - -.def int EXITF_GOTOXY_REL = EXITF_GOTOY_REL | EXITF_GOTOX_REL ; map exit table entry struct .se 0 diff --git a/src/exittables.s b/src/exittables.s index ad25915..e69de29 100644 --- a/src/exittables.s +++ b/src/exittables.s @@ -1,59 +0,0 @@ -; exit tables: -; down: 0 -; left: 1 -; right: 2 -; up: 3 - -map_tc_exit_table: -exit_def EXITF_GOTOXY_REL, BTNDOWN, -15, 0, map_c_header -exit_def EXITF_GOTOXY_REL, BTNLEFT, 0, 15, map_tw_header -exit_def EXITF_GOTOXY_REL, BTNRIGHT, 0, -15, map_te_header -exit_def EXITF_GOTOXY_REL, BTNUP, 15, 0, map_c_header - -map_te_exit_table: -exit_def EXITF_GOTOXY_REL, BTNDOWN, -15, 0, map_ce_header -exit_def EXITF_GOTOXY_REL, BTNLEFT, 0, 15, map_tc_header -exit_def EXITF_GOTOXY_REL, BTNRIGHT, 0, -15, map_c_header -exit_def EXITF_GOTOXY_REL, BTNUP, 15, 0, map_c_header - -map_tw_exit_table: -exit_def EXITF_GOTOXY_REL, BTNDOWN, -15, 0, map_cw_header -exit_def EXITF_GOTOXY_REL, BTNLEFT, 0, 15, map_c_header -exit_def EXITF_GOTOXY_REL, BTNRIGHT, 0, -15, map_tc_header -exit_def EXITF_GOTOXY_REL, BTNUP, 15, 0, map_c_header - -map_c_exit_table: -exit_def EXITF_GOTOXY_REL, BTNDOWN, -15, 0, map_bc_header -exit_def EXITF_GOTOXY_REL, BTNLEFT, 0, 15, map_cw_header -exit_def EXITF_GOTOXY_REL, BTNRIGHT, 0, -15, map_ce_header -exit_def EXITF_GOTOXY_REL, BTNUP, 15, 0, map_tc_header - -map_ce_exit_table: -exit_def EXITF_GOTOXY_REL, BTNDOWN, -15, 0, map_be_header -exit_def EXITF_GOTOXY_REL, BTNLEFT, 0, 15, map_c_header -exit_def EXITF_GOTOXY_REL, BTNRIGHT, 0, -15, map_c_header -exit_def EXITF_GOTOXY_REL, BTNUP, 15, 0, map_te_header - -map_cw_exit_table: -exit_def EXITF_GOTOXY_REL, BTNDOWN, -15, 0, map_bw_header -exit_def EXITF_GOTOXY_REL, BTNLEFT, 0, 15, map_c_header -exit_def EXITF_GOTOXY_REL, BTNRIGHT, 0, -15, map_c_header -exit_def EXITF_GOTOXY_REL, BTNUP, 15, 0, map_tw_header - -map_bc_exit_table: -exit_def EXITF_GOTOXY_REL, BTNDOWN, -15, 0, map_c_header -exit_def EXITF_GOTOXY_REL, BTNLEFT, 0, 15, map_bw_header -exit_def EXITF_GOTOXY_REL, BTNRIGHT, 0, -15, map_be_header -exit_def EXITF_GOTOXY_REL, BTNUP, 15, 0, map_c_header - -map_be_exit_table: -exit_def EXITF_GOTOXY_REL, BTNDOWN, -15, 0, map_c_header -exit_def EXITF_GOTOXY_REL, BTNLEFT, 0, 15, map_bc_header -exit_def EXITF_GOTOXY_REL, BTNRIGHT, 0, -15, map_bc_header -exit_def EXITF_GOTOXY_REL, BTNUP, 15, 0, map_ce_header - -map_bw_exit_table: -exit_def EXITF_GOTOXY_REL, BTNDOWN, -15, 0, map_c_header -exit_def EXITF_GOTOXY_REL, BTNLEFT, 0, 15, map_c_header -exit_def EXITF_GOTOXY_REL, BTNRIGHT, 0, -15, map_bc_header -exit_def EXITF_GOTOXY_REL, BTNUP, 15, 0, map_cw_header diff --git a/src/map.s b/src/map.s index 3cbf128..22afe0d 100644 --- a/src/map.s +++ b/src/map.s @@ -56,10 +56,6 @@ map_load: push hl call map_tile_banks_load pop hl - - push hl - call map_load_exit_table - pop hl ret @@ -342,20 +338,6 @@ map_tile_banks_load: ret - ; loads the exit table - ; inputs: - ; hl: map ptr -map_load_exit_table: - ld de, map_exit_table_ptr - add hl, de ; hl = exit table - - ld a, [hl+] - ld [map_exit_table], a - ld a, [hl] - ld [map_exit_table+1], a - - ret - ; draws all cells currently loaded to the screen ; only call during blank! map_draw_all: diff --git a/src/player.s b/src/player.s index 330e895..b7f9d38 100644 --- a/src/player.s +++ b/src/player.s @@ -110,7 +110,7 @@ unit_player_remove_door: ld a, 0x48 ; roof tile ; clear map ld [hl+], a - ld a, CF_COVERED + ld a, CF_EXIT ld [hl], a ld hl, act_rt_collision_pos_y @@ -128,9 +128,15 @@ unit_player_remove_door: ; checks the current tile ; and checks for exit flags + ; if an exit flag is set, checks if + ; the player is in position y == 0 + ; y == MAP_H-1, x == 0 or x == MAP_W-1 + ; to determine where to take the player + ; the direction moving the player oob must be pressed to move the player ; inputs: ; de: actor unit_check_exit_hit: + push de ld hl, act_pos_y add hl, de ; hl = actor_y @@ -143,100 +149,27 @@ unit_check_exit_hit: ; a = flags ld b, a ; b = flags for later use and a, CF_EXIT + pop de ret z ; if not we bail ; now it's time to look up - ; the exit - - ; de = exit ptr - ld de, map_exit_table - ld a, [de] - ld l, a - inc de - ld a, [de] - ld h, a - ; hl = first entry in exit table - ld a, b ; a = flags - and a, 0xF0 ; we only care about the upper nibble - swap a ; a = exit table offset - cp a, 0 ; do not do this if a == 0 - jr z, @done_calculate_ptr REL - - ; add exit size to de a times - ld de, exit_size -@calculate_ptr: - add hl, de - dec a - jr nz, @calculate_ptr REL -@done_calculate_ptr: + ; the exit's position - ; hl == the exit table entry - ; check if input is required - - inc hl ; hl = required input - ld a, [hl] - dec hl ; hl = exit flags - - cp a, 0 - jr z, @skip_input_check REL - ; if inputs is not 0 we check button state - ld b, a ; b = button mask - input_held - ret z ; if not input bail -@skip_input_check: +@load_map: ; fade out call video_fade_out + + ; TODO: adjust player map cursor - ; now we can load the map - - ; load map ptr - push hl - ld de, exit_to - add hl, de ; hl = map ptr - - - ld a, [hl+] - ld c, a - ld a, [hl] - ld h, a - ld a, c - ld l, a ; hl = map header ptr - call map_load - - pop bc ; bc = exit table now - ; finally adjust player position + ; generate new map + call mapgen ; hl = player ld hl, player_unit ld de, act_pos_y add hl, de ; hl = y pos - ; adjust y position - ld a, [bc] - and a, EXITF_GOTOY_REL - - inc bc - inc bc ; bc = y adjust - ld a, [bc] - dec bc - dec bc - call z, map_exit_absolute_adjust - call nz, map_exit_relative_adjust - - inc hl ; hl = x pos - - ; adjust x position - ld a, [bc] - and a, EXITF_GOTOX_REL - - inc bc - inc bc - inc bc ; bc = x adjust - ld a, [bc] - call z, map_exit_absolute_adjust - call nz, map_exit_relative_adjust - ; scroll to player's position ld de, player_unit @@ -251,32 +184,6 @@ unit_check_exit_hit: ret - ; adjusts player position to aboslute - ; position - ; inputs: - ; hl: player_y or player_x - ; a: new y or new x - ; preserves all registers and flags -map_exit_absolute_adjust: - ld [hl], a - ret - - ; adjusts player position by a relative - ; position offset - ; inputs: - ; hl: player_y or player_x - ; a: new y or new x - ; preserves all registers and flags -map_exit_relative_adjust: - push_all - - ld b, a - ld a, [hl] - add a, b - ld [hl], a - - pop_all - ret ; player attack state ; inputs: diff --git a/src/wram.s b/src/wram.s index 4db82bc..d157d9c 100644 --- a/src/wram.s +++ b/src/wram.s @@ -181,8 +181,6 @@ map_end: ; mape state machine map_st: .adv st_size - ; current exit table ptr -map_exit_table: .adv 2 ; ptr to the last map header used map_header: .adv 2 diff --git a/tools/tms2map.py b/tools/tms2map.py index 2706b45..2328276 100755 --- a/tools/tms2map.py +++ b/tools/tms2map.py @@ -13,7 +13,6 @@ tile_bank0 = "bank8000" tile_bank1 = "bank8800" tile_bank2 = "bank8C00" tile_bank3 = "bank9000" -exit_table = "map_c_exit_table" actor_table_ptr = "map_actor_table_null" map_name = "noname" NAME_LEN = 8 @@ -108,7 +107,6 @@ def print_header(name): print("dw " + tile_bank1) print("dw " + tile_bank2) print("dw " + tile_bank3) - print("dw " + exit_table) print("") def get_flag(tile): @@ -138,7 +136,6 @@ def get_map_props(root): global tile_bank2 global tile_bank3 global map_name - global exit_table for child in root: if child.tag == "properties": @@ -159,8 +156,6 @@ def get_map_props(root): tile_bank3 = value elif name == 'map_name': map_name = value - elif name == 'exit_table': - exit_table = value return -- 2.30.2