levels: Added tile loader
authorLukas Krickl <lukas@krickl.dev>
Thu, 30 Oct 2025 08:55:59 +0000 (09:55 +0100)
committerLukas Krickl <lukas@krickl.dev>
Thu, 30 Oct 2025 08:55:59 +0000 (09:55 +0100)
src/levels.s
src/map.s
src/tiles.s

index 0d392c87c5f877c2d6d67172b9a5491fffa9ae40..63cd581c76b42f363a4b132e49a11dd9dbcb164e 100644 (file)
@@ -6,16 +6,16 @@ level_def_to_tile:
        dw tile_food
        
        ; tile grass
-.def int TGS = 0
+.def int TGS = TT_EMPTY
 
        ; tile player hive
-.def int TPH = 1
+.def int TPH = TT_PLAYER_HIVE
 
        ; tile enemy hive
-.def int TEH = 2
+.def int TEH = TT_ENEMY_HIVE
 
        ; tile food
-.def int TFD = 3
+.def int TFD = TT_FOOD
 
        ; level definitions
        ; levels always have a header
@@ -27,6 +27,7 @@ level_def_to_tile:
 
 l1:
        mapdef 0, map_r_nop, bank8000, bank8800, bank8C00, bank9000
+       .db TPH, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
        .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
        .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
        .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
@@ -34,12 +35,11 @@ l1:
        .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
        .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
        .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
+       .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TFD, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
        .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
        .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
        .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
        .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
        .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
        .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
-       .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
-       .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
-       .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
+       .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TEH
index 5d9be9fdcd2834d27933e4d5844a675bff83055c..4e41567ec1c13c1b554abbc95b7cecd0cd1cdd51 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -20,12 +20,14 @@ map_load:
        push de
        call map_tile_banks_load
        pop de
+       push de
+       call map_tiles_load
+       pop de
 
        call lcd_on
        call vblank_wait
        call enableinterrupts
 
-
        call map_full_draw
        call player_init
        call ui_init
@@ -37,6 +39,61 @@ map_load:
 
        ret
        
+       ; loads a tileset
+       ; into the tile buffer
+       ; inputs:
+       ;               de: map ptr
+map_tiles_load:
+       ld hl, map_tiles
+       add hl, de
+       push hl
+       pop de
+       ; de = first tile to load
+       
+       ; hl = first tile in buffer
+       ld hl, tiles
+       
+       ld bc, MAP_TILES ; loop counter
+@load_loop:
+               ; load a tile
+               ld a, [de]
+               inc de ; next tile
+
+               ; load tile ptr from map
+               push de
+               push bc
+               
+               push hl
+               add a, a ; * 2 because it is a ptr table
+               ld hl, tile_id_table
+               ld b, 0
+               ld c, a
+               add hl, bc ; hl = ptr offset
+
+               ; load ptr into de (source)
+               ld a, [hl+]
+               ld e, a
+               ld a, [hl+]
+               ld d, a
+               pop hl ; hl = destination
+
+               ; copy a tile
+               ld bc, t_size
+               call memcpy
+               ; hl is now next 
+               pop bc
+               pop de
+
+       
+               ; loop counter--
+               dec bc
+               ld a, b
+               or a, c
+               cp a, 0 ; done?
+       jp nz, @load_loop
+
+       ret
+       
        ; loads all tile banks 
        ; for a specific map
        ; inputs:
index 00a37703fb86c25c9090df1052eab988a8e37562..5a9afad719f76cdeffde4b1ec5017c745607f5f3 100644 (file)
@@ -1,9 +1,9 @@
        ; tile definitions
 
 #define GFX_GRASS 0x00
-#define GFX_PHIVE 0x00
-#define GFX_EHIVE 0x00
-#define GFX_FOOD 0x00
+#define GFX_PHIVE 0x01
+#define GFX_EHIVE 0x02
+#define GFX_FOOD 0x03
        
        ; updates a tile with its 
        ; routine
@@ -57,6 +57,16 @@ tile_update_enemy_hive:
        ;               de: tile
 tile_update_food:
        ret
+       
+       ; maps from tile ids 
+       ; to tile presets
+tile_id_table:
+       dw tile_grass
+       dw tile_grass 
+       dw tile_player_hive
+       dw tile_grass 
+       dw tile_enemy_hive
+       dw tile_food
 
 
 tile_grass: