From 4ec8084236c881f02fcea4df5dc0c8c08fc0fea8 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sun, 30 Nov 2025 07:20:16 +0100 Subject: [PATCH] map: Added pointer to tile id table to map header This means every map can now have a distinct table of tiledefs. --- src/defs.s | 1 + src/levels.s | 2 +- src/macros.inc | 2 ++ src/map.s | 17 ++++++++++++++++- src/wram.s | 1 + 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/defs.s b/src/defs.s index 3d56155..74b7e4d 100644 --- a/src/defs.s +++ b/src/defs.s @@ -92,6 +92,7 @@ .de map_tile_bank1_ptr, 2 .de map_tile_bank2_ptr, 2 .de map_tile_bank3_ptr, 2 +.de map_tile_id_table, 2 .de map_header_size, 0 ; the map header is followed by MAP_W * MAP_H bytes .de map_tiles, MAP_W * MAP_H diff --git a/src/levels.s b/src/levels.s index 3831820..62477fd 100644 --- a/src/levels.s +++ b/src/levels.s @@ -13,7 +13,7 @@ ; where each tile has values and its current state. The map can be drawn from this. l1: - mapdef 0, map_r_nop, 0, 0, 0, bank8000, bank8800, bank8C00, bank9000 + mapdef 0, map_r_nop, 0, 0, 0, bank8000, bank8800, bank8C00, bank9000, tile_id_table .db TWL, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS diff --git a/src/macros.inc b/src/macros.inc index 3855ba7..c6a2299 100644 --- a/src/macros.inc +++ b/src/macros.inc @@ -161,6 +161,7 @@ $1: ; $7: tile bank 1 ; $8: tile bank 2 ; $9: tile bank 3 + ; $10: tile id table #macro mapdef .db $1 dw $2 @@ -171,6 +172,7 @@ $1: dw $7 dw $8 dw $9 + dw $10 #endmacro ; define a tile diff --git a/src/map.s b/src/map.s index baaa292..4667a0a 100644 --- a/src/map.s +++ b/src/map.s @@ -55,6 +55,15 @@ map_load: ; inputs: ; de: map ptr map_tiles_load: + ld hl, map_tile_id_table + add hl, de + ; store tile id table + ; in map_tile_id_table + ld a, [hl+] + ld [map_tmp_tile_id_table], a + ld a, [hl+] + ld [map_tmp_tile_id_table+1], a + ld hl, map_tiles add hl, de push hl @@ -76,9 +85,15 @@ map_tiles_load: push hl add a, a ; * 2 because it is a ptr table - ld hl, tile_id_table ld b, 0 ld c, a + + ld hl, tile_id_table + ld a, [map_tmp_tile_id_table] + ld l, a + ld a, [map_tmp_tile_id_table+1] + ld h, a + add hl, bc ; hl = ptr offset ; load ptr into de (source) diff --git a/src/wram.s b/src/wram.s index 026b41d..f37419a 100644 --- a/src/wram.s +++ b/src/wram.s @@ -87,6 +87,7 @@ map: .adv 2 ; ptr to top left corner of SCRN ; where the map should be drawn map_vram_tl: .adv 2 +map_tmp_tile_id_table: .adv 2 ; ptr to current tile to be updated tiles: .adv t_size * MAP_TILES -- 2.30.2