map: Added pointer to tile id table to map header
authorLukas Krickl <lukas@krickl.dev>
Sun, 30 Nov 2025 06:20:16 +0000 (07:20 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sun, 30 Nov 2025 06:20:16 +0000 (07:20 +0100)
This means every map can now have a distinct table of tiledefs.

src/defs.s
src/levels.s
src/macros.inc
src/map.s
src/wram.s

index 3d56155e30723c7dade775568d1fce20bc87cdf7..74b7e4d063b215eb5eb4769add8c3c27348f8a84 100644 (file)
@@ -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
index 3831820515bf964602ae67c289f6533dbbaef784..62477fdae8715b3e5f33e28dff19cd71f8da0a3f 100644 (file)
@@ -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
index 3855ba747bcbcde9886a464b7f157bc0e6e90112..c6a2299d482700feaf45da0dd4b7cef5469a3107 100644 (file)
@@ -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
index baaa29232cd882ad0fc8f62dc745b361cb48bbf4..4667a0ac11d1e3d94a0e6975d109bbb4d014b805 100644 (file)
--- 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)
index 026b41d57f6b12358a4dbb1293c97ea928c9c243..f37419a33da81af87bb94628b508998b6731dc43 100644 (file)
@@ -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