aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAstatin <[email protected]>2024-10-31 16:12:46 +0900
committerAstatin <[email protected]>2024-10-31 16:12:46 +0900
commit0a203e404468bb0822657d309ca8168bae2fd24b (patch)
tree64fb814c8992d9f9b329d7215fa868bcb868e7bf
parenta69ff95615b9ef4ed1ef2e0dbe42bf64b36e25b0 (diff)
Add script to generate dialogue data from text
-rw-r--r--Makefile5
-rw-r--r--dialogues.gbasm8
-rw-r--r--dialogues.gbtxt3
-rw-r--r--main.gbasm6
-rw-r--r--scripts/generate_from_gbtxt.py54
-rw-r--r--tiles.gbasm1
6 files changed, 71 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index 002e53b..1f2ccc5 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,10 @@ all: run
tileset.gbasm: ./scripts/generate-tiledata.py $(wildcard ./sprites/**/*)
python ./scripts/generate-tiledata.py > tileset.gbasm
-build/main.rom: main.gbasm tileset.gbasm
+dialogues.gbasm: ./dialogues.gbtxt ./scripts/generate_from_gbtxt.py
+ python ./scripts/generate_from_gbtxt.py dialogues.gbtxt > dialogues.gbasm
+
+build/main.rom: main.gbasm tileset.gbasm dialogues.gbasm
mkdir -p build
gbasm $< $@
diff --git a/dialogues.gbasm b/dialogues.gbasm
new file mode 100644
index 0000000..71054d2
--- /dev/null
+++ b/dialogues.gbasm
@@ -0,0 +1,8 @@
+Lain_Text:
+.DB 0x95, 0x8a, 0x92, 0x97, 0x0, 0x92, 0x9c, 0x0, 0x8c, 0x9e, 0x9d, 0x8e, 0xa5, 0xff
+Owl_Text:
+.DB 0x98, 0xa0, 0x95, 0x0, 0x92, 0x9c, 0x0, 0x8c, 0x9e, 0x9d, 0x8e, 0xa4, 0xff
+Auz_Text:
+.DB 0xa0, 0x92, 0x9d, 0x8c, 0x91, 0x0, 0x92, 0x9c, 0x0, 0x8c, 0x9e, 0x9d, 0x8e, 0xa7, 0xff
+Astatin_Text:
+.DB 0x96, 0x8e, 0xaa, 0x0, 0xa9, 0x92, 0xa8, 0x96, 0x0, 0x97, 0x98, 0x9d, 0x0, 0x8c, 0x9e, 0x9d, 0x8e, 0xa9, 0xff
diff --git a/dialogues.gbtxt b/dialogues.gbtxt
new file mode 100644
index 0000000..13fa017
--- /dev/null
+++ b/dialogues.gbtxt
@@ -0,0 +1,3 @@
+Lain_Text: Lain is cute!
+Owl_Text: Owl is cute!
+Auz_Text: Witch is cute!
diff --git a/main.gbasm b/main.gbasm
index d8c3c92..7048e5f 100644
--- a/main.gbasm
+++ b/main.gbasm
@@ -21,9 +21,6 @@ New_Dungeon:
HALT
JP =Wait_for_VRAM.loop
-Text_Astatin:
- .DB 0x8a, 0x9c, 0x9d, 0x8a, 0x9d, 0x92, 0x97, 0xff
-
VBLANK_Entrypoint:
; Window enable
LD A, $reg_lcd_controller
@@ -44,7 +41,7 @@ VBLANK_Entrypoint:
INC HL
- LD BC, =Text_Astatin
+ LD BC, =Astatin_Text
CALL =Print_str
CALL =Display_Prepared_Block
@@ -93,3 +90,4 @@ STAT_Entrypoint:
.INCLUDE "entity/collisions.gbasm"
.INCLUDE "entity/display.gbasm"
.INCLUDE "tileset.gbasm"
+.INCLUDE "dialogues.gbasm"
diff --git a/scripts/generate_from_gbtxt.py b/scripts/generate_from_gbtxt.py
new file mode 100644
index 0000000..f31ed04
--- /dev/null
+++ b/scripts/generate_from_gbtxt.py
@@ -0,0 +1,54 @@
+import sys
+
+if len(sys.argv) < 2:
+ raise ValueError("Must have gbtxt file in first argument")
+
+gbtxt_filename = sys.argv[1]
+
+gbtxt_file = open(gbtxt_filename, 'r')
+
+
+def ascii_to_gbtext_format(c):
+ c = c.upper()
+ match c:
+ case c if c <= '9' and c >= '0':
+ return ord(c) - ord('0') + 0x80
+ case c if c <= 'Z' and c >= 'A':
+ return ord(c) - ord('A') + 0x80 + 10
+ case ':':
+ return 0xaa
+ case '"':
+ return 0xa9
+ case "'":
+ return 0xa8
+ case ',':
+ return 0xa7
+ case '?':
+ return 0xa6
+ case '!':
+ return 0xa5
+ case '.':
+ return 0xa4
+ case ' ':
+ return 0x00
+ case _:
+ raise ValueError("Char \"" + c + "\" is not in the allowed charset")
+
+for line in gbtxt_file:
+ line = line.strip()
+
+ if len(line) == 0:
+ continue
+
+ if line[0] == '#':
+ continue
+
+ if not ':' in line:
+ raise ValueError("Text without label is not allowed")
+
+ label = line[:line.index(':') + 1]
+ text = line[line.index(':') + 1:].strip()
+
+ print(label)
+
+ print(".DB", ", ".join([hex(ascii_to_gbtext_format(c)) for c in text]) + ", 0xff")
diff --git a/tiles.gbasm b/tiles.gbasm
index 1d8c03a..fbe6fdc 100644
--- a/tiles.gbasm
+++ b/tiles.gbasm
@@ -10,7 +10,6 @@ Load_Tile:
CALL =memcpy
RET
-
Load_Number_Font: ; Load number font into the tilemap at tiles 0x10-0x1f
LD HL, $8800
LD DE, =Font_Data