From ba65f6f2624e964fefd49b4df59423cc13c18f47 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Mon, 21 Oct 2024 20:38:34 +0200 Subject: [PATCH] Added script that converts tiled csv maps to in-game maps --- makefile | 4 ++++ maps/base_room.s | 4 ++++ src/map.s | 20 +------------------- src/video.s | 4 ++-- tools/tms2map.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 54 insertions(+), 21 deletions(-) create mode 100644 maps/base_room.s create mode 100755 tools/tms2map.py diff --git a/makefile b/makefile index ae213ba..e61f576 100644 --- a/makefile +++ b/makefile @@ -14,3 +14,7 @@ test: tiles: ./tools/png2chr.py assets/tiles0.png > tiles/tileset0.inc ./tools/png2chr.py assets/tiles1.png > tiles/tileset1.inc + +.PHONY: maps +maps: + ./tools/tms2map.py assets/maps/base.tmx base_room > maps/base_room.s diff --git a/maps/base_room.s b/maps/base_room.s new file mode 100644 index 0000000..85412dd --- /dev/null +++ b/maps/base_room.s @@ -0,0 +1,4 @@ +base_room_bg: +.db 0x60, 0x62, 0x62, 0x64, 0x40, 0x40, 0x66, 0x62, 0x62, 0x68, 0x4c, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x6a, 0x46, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0xe0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x48, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0xe2, 0x4c, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x6a, 0x6c, 0x4a, 0x4a, 0x42, 0x40, 0x40, 0x44, 0x4a, 0x4a, 0x6e +base_room_flags: +.db 0x1, 0x1, 0x1, 0x1, 0x0, 0x0, 0x1, 0x1, 0x1, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x1, 0x1, 0x1, 0x0, 0x0, 0x1, 0x1, 0x1, 0x1 diff --git a/src/map.s b/src/map.s index 369d981..837d5f4 100644 --- a/src/map.s +++ b/src/map.s @@ -146,22 +146,4 @@ room_draw: ; base room ; this can be copied and modified ; by the map gen -base_room: -.db TCORNUL, TWALLU1, TWALLU1, TDOORUL, TFLOOR1, TFLOOR1, TDOORUR, TWALLU1, TWALLU1, TCORNUR -.db TWALLL1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TWALLR1 -.db TDOORRL, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TDOORLL -.db TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1 -.db TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1 -.db TDOORRR, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TDOORLR -.db TWALLL1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TFLOOR1, TWALLR1 -.db TCORNBOL, TWALLD1, TWALLD1, TDOORDL, TFLOOR1, TFLOOR1, TDOORDR, TWALLD1, TWALLD1, TCORNBOR - ; tile flags for the room -base_room_flags: -.db RF_WALL, RF_WALL, RF_WALL, RF_WALL, 0, 0, RF_WALL, RF_WALL, RF_WALL, RF_WALL -.db RF_WALL, 0, 0, 0, 0, 0, 0, 0, 0, RF_WALL -.db RF_WALL, 0, 0, 0, 0, 0, 0, 0, 0, RF_WALL -.db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -.db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -.db RF_WALL, 0, 0, 0, 0, 0, 0, 0, 0, RF_WALL -.db RF_WALL, 0, 0, 0, 0, 0, 0, 0, 0, RF_WALL -.db RF_WALL, RF_WALL, RF_WALL, RF_WALL, 0, 0, RF_WALL, RF_WALL, RF_WALL, RF_WALL +#include "./maps/base_room.s" diff --git a/src/video.s b/src/video.s index c8871ee..06108ab 100644 --- a/src/video.s +++ b/src/video.s @@ -83,9 +83,9 @@ video_init: ; initial test map - ldlo a, base_room + ldlo a, base_room_bg ld [curr_room], a - ldhi a, base_room + ldhi a, base_room_bg ld [curr_room+1], a ldlo a, base_room_flags diff --git a/tools/tms2map.py b/tools/tms2map.py new file mode 100755 index 0000000..a2b866f --- /dev/null +++ b/tools/tms2map.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python + +import sys +import os +import xml.etree.ElementTree as ET + +if len(sys.argv) < 3: + print("Usage: tmx2map.py ") + sys.exit(-1) + +src = sys.argv[1] +name = sys.argv[2] + +def print_data(data, name, layer): + print(name + "_" + layer + ":") + print(".db ", end = ''); + split = data.split(",") + for i, byte in enumerate(split): + val = int(byte) + if val > 0: + val -= 1 + if layer == "bg": + og = val + val = 0x800 + ((val * 16) << 2) + val = (val & 0x0FF0) >> 4 + val -= int(2 * og % 16) + + end = ', ' + if i == len(split) - 1: + end = '\n' + print(hex(val), end=end) + +def convert(src, name): + tree = ET.parse(src) + root = tree.getroot() + for child in root: + if child.tag == "layer": + for data in child: + print_data(data.text, name, child.attrib['name']) + + + +convert(src, name) -- 2.30.2