From: Lukas Krickl Date: Thu, 30 Oct 2025 08:55:59 +0000 (+0100) Subject: levels: Added tile loader X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=346f5fbfa8a36f61b4a3684502c3c562f70f61e4;p=gbrg%2F.git levels: Added tile loader --- diff --git a/src/levels.s b/src/levels.s index 0d392c8..63cd581 100644 --- a/src/levels.s +++ b/src/levels.s @@ -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 diff --git a/src/map.s b/src/map.s index 5d9be9f..4e41567 100644 --- 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: diff --git a/src/tiles.s b/src/tiles.s index 00a3770..5a9afad 100644 --- a/src/tiles.s +++ b/src/tiles.s @@ -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: