From ebace1287de009d4af4e3559c25c432f3b87358e Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Thu, 30 Oct 2025 07:31:59 +0100 Subject: [PATCH] map: added stub for tiles --- src/defs.s | 27 +++++++++++++++++++- src/macros.inc | 69 +++++++++++--------------------------------------- src/tiles.s | 63 +++++++++++++++++++++++++++++++++++++++++++++ src/wram.s | 6 +++-- 4 files changed, 108 insertions(+), 57 deletions(-) diff --git a/src/defs.s b/src/defs.s index 05ddbda..a36c2f0 100644 --- a/src/defs.s +++ b/src/defs.s @@ -26,6 +26,7 @@ #define MAP_W 16 #define MAP_H 16 +#define MAP_TILES (MAP_W * MAP_H) ; actor type enum .se 0 @@ -59,10 +60,34 @@ .de map_tile_bank2_ptr, 2 .de map_tile_bank3_ptr, 2 .de map_header_size, 0 + ; the map header is followed by MAP_W * MAP_H bytes .de map_tiles, MAP_W * MAP_H .de map_size, 0 - ; the map header is followed by MAP_W * MAP_H bytes + ; tile type struct +.se 0 +.de TT_EMPTY, 1 +.de TT_PLAYER, 1 +.de TT_PLAYER_HIVE, 1 +.de TT_ENEMY, 1 +.de TT_ENEMY_HIVE, 1 +.de TT_FOOD, 1 + + ; tile struct +.se 0 +.de t_type, 1 +.de t_flags, 1 + ; based on type +.de t_resource, 1 + ; 2 bytes of custom state storage + ; to be used by tile routine +.de t_p0, 1 +.de t_state, 1 + ; graphical tile +.de t_tile, 1 +.de t_size, 0 + + ; alias for directions .def int DIRUP = BTNUP diff --git a/src/macros.inc b/src/macros.inc index 962d1ef..0961802 100644 --- a/src/macros.inc +++ b/src/macros.inc @@ -167,65 +167,26 @@ $1: dw $6 #endmacro - ; defines a new actor + ; define a tile ; inputs: ; $1: type ; $2: flags - ; $3: p0 - ; $4: hp - ; $5: armor -#macro actdef - .db $1, $2 - - ; placeholder for y, row and x - ; since those are set at runtime - .db 0, 0 - - .db $3 - - ; placeholder for state parameter - ; this is set by the actor update routine as needed - .db 0 - - .db $4, $5 - - ; placeholder for collision rectangle - ; since those are runtime values - .db 0, 0, 0, 0, 0 -#endmacro - - ; defines a rectangle - ; inputs: - ; $1: collision flags - ; $2: y - ; $3: y hi - ; $4: x - ; $5: h - ; $6: w -#macro recdef - .db $1, $2, $3, $4, $5, $6 + ; $3: resource count + ; $4: tile gfx +#macro tiledef + .db $1, $2, $3 + ; p0 and state + .db 0, 0 + .db $4 #endmacro - ; caps an underflow when carry is set - ; caps value to 0x00 + ; defines a new actor ; inputs: - ; af: value and carry flag -#macro capunderflow -.beginscope - jr nc, @no_underflow REL - xor a, a -@no_underflow: -.endscope -#endmacro + ; $1: type + ; $2: flags +#macro actdef + .db $1, $2 - ; caps an overflow when carry is set - ; caps value to 0xFF - ; inputs: - ; af: value and carry flag -#macro capoverflow -.beginscope -jr nc, @no_overflow REL - ld a, 0xFF -@no_overflow: -.endscope + ; placeholder for y, x p0 and state + .db 0, 0, 0, 0 #endmacro diff --git a/src/tiles.s b/src/tiles.s index adde0ee..00a3770 100644 --- a/src/tiles.s +++ b/src/tiles.s @@ -1,9 +1,72 @@ ; tile definitions +#define GFX_GRASS 0x00 +#define GFX_PHIVE 0x00 +#define GFX_EHIVE 0x00 +#define GFX_FOOD 0x00 + + ; updates a tile with its + ; routine + ; inputs: + ; de: tile +tile_update: + ret + + ; table of update routines + ; for each tile +tile_update_table: + dw tile_update_empty + dw tile_update_player + dw tile_update_player_hive + dw tile_update_enemy + dw tile_update_enemy_hive + dw tile_update_food + + ; updates empty tile + ; inputs: + ; de: tile +tile_update_empty: + ret + + ; updates player controlled tile + ; inputs: + ; de: tile +tile_update_player: + ret + + ; updates player hive + ; inputs: + ; de: tile +tile_update_player_hive: + ret + + ; updates enemy tile + ; inputs: + ; de: tile +tile_update_enemy: + ret + + ; updates enemy hive + ; inputs: + ; de: tile +tile_update_enemy_hive: + ret + + ; updates food tile + ; inputs: + ; de: tile +tile_update_food: + ret + + tile_grass: + tiledef TT_EMPTY, 0, 0, GFX_GRASS tile_player_hive: + tiledef TT_PLAYER_HIVE, 0, 0, GFX_PHIVE tile_enemy_hive: + tiledef TT_ENEMY_HIVE, 0, 0, GFX_EHIVE tile_food: + tiledef TT_FOOD, 0, 0, GFX_FOOD diff --git a/src/wram.s b/src/wram.s index d767394..1e7bc88 100644 --- a/src/wram.s +++ b/src/wram.s @@ -71,7 +71,9 @@ enemy: .adv act_size ; current map ptr map: .adv 2 - - + + ; ptr to current tile to be updated +tile_curr: .adv 2 +tiles: .adv t_size * MAP_TILES -- 2.30.2