From de04d0b588911cc99362451eb9120d57e58abaf6 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Tue, 16 Dec 2025 14:28:26 +0100 Subject: [PATCH] map: Added template maps for dungeon drawing Added example of map draw loader --- makefile | 4 ++- maps/far_wall.inc | 16 +++++++++++ maps/{spawn.inc => l1.inc} | 0 maps/near_wall.inc | 16 +++++++++++ maps/newat_wall.inc | 16 +++++++++++ src/defs.s | 4 +++ src/levels.s | 2 +- src/map.s | 19 ++++++++++++- src/player.s | 13 ++++++--- src/tiles.s | 6 +++++ src/update.s | 55 ++++++++++++++++++++++++++++++++++++++ src/wram.s | 2 ++ tools/tmx2map.py | 5 +++- 13 files changed, 151 insertions(+), 7 deletions(-) create mode 100644 maps/far_wall.inc rename maps/{spawn.inc => l1.inc} (100%) create mode 100644 maps/near_wall.inc create mode 100644 maps/newat_wall.inc diff --git a/makefile b/makefile index 3c397fa..80c3fc5 100644 --- a/makefile +++ b/makefile @@ -20,4 +20,6 @@ tiles: .PHONY: maps maps: - ./tools/tmx2map.py assets/maps/l1.tmx > maps/spawn.inc + ./tools/tmx2map.py assets/maps/near_wall.tmx 1 > maps/near_wall.inc + ./tools/tmx2map.py assets/maps/far_wall.tmx 1 > maps/far_wall.inc + ./tools/tmx2map.py assets/maps/l1.tmx > maps/l1.inc diff --git a/maps/far_wall.inc b/maps/far_wall.inc new file mode 100644 index 0000000..07fc901 --- /dev/null +++ b/maps/far_wall.inc @@ -0,0 +1,16 @@ +; this map was generated by tmx2map.py + +.db 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 +.db 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 +.db 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 +.db 0x0, 0x1, 0x2, 0x3, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x4, 0x5, 0x6, 0x7 +.db 0x10, 0x12, 0x12, 0x13, 0x0, 0x1, 0x2, 0x3, 0x11, 0x11, 0x11, 0x11, 0x4, 0x5, 0x6, 0x7, 0x14, 0x12, 0x12, 0x20 +.db 0x10, 0x12, 0x12, 0x12, 0x10, 0x12, 0x12, 0x13, 0x15, 0x21, 0x21, 0x16, 0x14, 0x12, 0x12, 0x20, 0x12, 0x12, 0x12, 0x20 +.db 0x10, 0x12, 0x12, 0x12, 0x10, 0x12, 0x12, 0x12, 0x10, 0x12, 0x12, 0x20, 0x12, 0x12, 0x12, 0x20, 0x12, 0x12, 0x12, 0x20 +.db 0x10, 0x12, 0x12, 0x12, 0x10, 0x12, 0x12, 0x23, 0x25, 0x22, 0x22, 0x26, 0x24, 0x12, 0x12, 0x20, 0x12, 0x12, 0x12, 0x20 +.db 0x10, 0x12, 0x12, 0x23, 0x30, 0x31, 0x32, 0x33, 0x17, 0x17, 0x5a, 0x17, 0x34, 0x35, 0x36, 0x37, 0x24, 0x12, 0x12, 0x20 +.db 0x30, 0x31, 0x32, 0x33, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x34, 0x35, 0x36, 0x37 +.db 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x17, 0x17, 0x17, 0x17 +.db 0x17, 0x17, 0x70, 0x71, 0x72, 0x73, 0x74, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17 +.db 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17 +.db 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17 diff --git a/maps/spawn.inc b/maps/l1.inc similarity index 100% rename from maps/spawn.inc rename to maps/l1.inc diff --git a/maps/near_wall.inc b/maps/near_wall.inc new file mode 100644 index 0000000..8788c81 --- /dev/null +++ b/maps/near_wall.inc @@ -0,0 +1,16 @@ +; this map was generated by tmx2map.py + +.db 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 +.db 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 +.db 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 +.db 0x0, 0x1, 0x2, 0x3, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x4, 0x5, 0x6, 0x7 +.db 0x10, 0x12, 0x12, 0x13, 0x15, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x16, 0x14, 0x12, 0x12, 0x20 +.db 0x10, 0x12, 0x12, 0x12, 0x10, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x20, 0x12, 0x12, 0x12, 0x20 +.db 0x10, 0x12, 0x12, 0x12, 0x10, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x20, 0x12, 0x12, 0x12, 0x20 +.db 0x10, 0x12, 0x12, 0x12, 0x10, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x20, 0x12, 0x12, 0x12, 0x20 +.db 0x10, 0x12, 0x12, 0x23, 0x25, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x26, 0x24, 0x12, 0x12, 0x20 +.db 0x30, 0x31, 0x32, 0x33, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x34, 0x35, 0x36, 0x37 +.db 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x17, 0x17, 0x17, 0x17 +.db 0x17, 0x17, 0x70, 0x71, 0x72, 0x73, 0x74, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17 +.db 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17 +.db 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17 diff --git a/maps/newat_wall.inc b/maps/newat_wall.inc new file mode 100644 index 0000000..9a0e205 --- /dev/null +++ b/maps/newat_wall.inc @@ -0,0 +1,16 @@ +; this map was generated by tmx2map.py + +.db 0x9, 0xd, 0xd, 0xd, 0xd, 0xd, 0xd, 0xd, 0xd, 0xd, 0xd, 0xd, 0xd, 0xd, 0xd, 0xd, 0xd, 0xd, 0xd, 0x5 +.db 0xb, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0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0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0x7 +.db 0xb, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0x7 +.db 0xa, 0xe, 0xe, 0xe, 0xe, 0xe, 0xe, 0xe, 0xe, 0xe, 0xe, 0xe, 0xe, 0xe, 0xe, 0xe, 0xe, 0xe, 0xe, 0x6 diff --git a/src/defs.s b/src/defs.s index 2fa99ce..cc2879d 100644 --- a/src/defs.s +++ b/src/defs.s @@ -31,6 +31,10 @@ #define MAP_H 14 #define MAP_TILES (MAP_W * MAP_H) +#define RENDER_BUF_W 20 +#define RENDER_BUF_H 14 +#define RENDER_BUF_TILES (RENDER_BUF_W * RENDER_BUF_H) + ; actor type enum .se 0 .de ACT_T_NULL, 1 diff --git a/src/levels.s b/src/levels.s index 57eb1f5..e5da4d7 100644 --- a/src/levels.s +++ b/src/levels.s @@ -10,7 +10,7 @@ l1: mapdef MAP_F_DO_FULL_REDRAW, map_r_nop, 0, tile_banks_default -#include "spawn.inc" +#include "l1.inc" tile_banks_default: dw bank8000 diff --git a/src/map.s b/src/map.s index 9f382e0..7d615fa 100644 --- a/src/map.s +++ b/src/map.s @@ -33,11 +33,13 @@ map_load: call map_tile_banks_load pop de - call map_full_draw call lcd_on call vblank_wait call enableinterrupts + + call map_full_draw + call update_render ret @@ -260,9 +262,24 @@ map_get_tile: ; draws a full map copy into the current map view buffer ; bsed on the current location the player is facing ; the map render buffer is then written to the screen + ; 1) load near or far wall into render_buffer (near if forward wall is on next tile) + ; 2) determine exits on all other walls forward + ; 3) draw exits in pre-determined locations + ; 4) set render state ; inputs: ; [map] + ; returns: + ; render_buffer: new map data to be drawn + ; transferts to redraw state map_full_draw: + ; draw template for now + ld de, far_wall + ld hl, render_buffer + ld bc, RENDER_BUF_TILES + call memcpy + + ; 4) go to render state + call update_render ret ; nop map rotuine diff --git a/src/player.s b/src/player.s index 869b5ab..ec430a9 100644 --- a/src/player.s +++ b/src/player.s @@ -78,7 +78,7 @@ player_handle_move: ld de, player call act_can_move ld de, player - call nz, act_move_forward + call nz, player_move_forward @not_up: ld b, DIRDOWN @@ -88,7 +88,14 @@ player_handle_move: ld de, player call act_can_move ld de, player - call nz, act_move_back + call nz, player_move_back @not_down: - ret + +player_move_forward: + call act_move_forward + jp map_full_draw + +player_move_back: + call act_move_back + jp map_full_draw diff --git a/src/tiles.s b/src/tiles.s index a9648db..d00c3dd 100644 --- a/src/tiles.s +++ b/src/tiles.s @@ -4,3 +4,9 @@ ; fallback tile tile_null: tiledef 0, 0, 0, 0 + +far_wall: +#include "far_wall.inc" + +near_wall: +#include "near_wall.inc" diff --git a/src/update.s b/src/update.s index d973817..6c04bfe 100644 --- a/src/update.s +++ b/src/update.s @@ -20,6 +20,61 @@ update_game: ret + ; draws a single tile + ; inputs: + ; de: render_buffer + ; hl: SCRN +#macro update_render_draw + ld a, [de] + inc de + ld [hl+], a +#endmacro + +update_render: + call disableinterrupts + ; TODO: this should be smooth... + ld b, RENDER_BUF_H ; loop counter + ld de, render_buffer + ld hl, SCRN0 + call next_vblank_wait + + ; copy buffer into SCRN0 + ; TODO: we should do this off-screen in SCRN1 and then switch +@render_loop: + update_render_draw + update_render_draw + update_render_draw + update_render_draw + update_render_draw + update_render_draw + update_render_draw + update_render_draw + update_render_draw + update_render_draw + update_render_draw + update_render_draw + update_render_draw + update_render_draw + update_render_draw + update_render_draw + update_render_draw + update_render_draw + update_render_draw + update_render_draw + + call next_vblank_wait + + push de + ld de, 12 ; next row + add hl, de + pop de + + dec b + jp nz, @render_loop + + call enableinterrupts + ret + new_game: ld de, l1 call map_load diff --git a/src/wram.s b/src/wram.s index 9694cc1..0423976 100644 --- a/src/wram.s +++ b/src/wram.s @@ -121,3 +121,5 @@ update_tile_vram: .adv 2 ; ptr to last draw_tile_prep update_tile_ptr: .adv 2 + +render_buffer: .adv RENDER_BUF_TILES diff --git a/tools/tmx2map.py b/tools/tmx2map.py index 2d95728..5f15673 100755 --- a/tools/tmx2map.py +++ b/tools/tmx2map.py @@ -7,7 +7,7 @@ TILE_SIZE = 8 MAP_W = 20 if len(sys.argv) < 2: - print("Usage: tmx2map.py ") + print("Usage: tmx2map.py [tile_offset]") sys.exit(-1) @@ -15,6 +15,9 @@ src = sys.argv[1] tile_offset = 97 +if len(sys.argv) > 2: + tile_offset = int(sys.argv[2]) + def print_bg_data(data): print("; this map was generated by tmx2map.py") split = data.split(",") -- 2.30.2