aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAstatin <[email protected]>2025-09-03 14:27:00 +0200
committerAstatin <[email protected]>2025-09-03 14:27:00 +0200
commita893988c10736d324330fbdcacabd6ac862500e1 (patch)
tree41b5b85a90489803e1319fe8049fc765f341d33b
parenta1b6da7fa43627a08b8bc75a48805ec96fc77583 (diff)
Add a post assembly script to round up ROM size (fixes ROM banking on some emulator)
-rw-r--r--Makefile1
-rw-r--r--init.gbasm2
-rw-r--r--map/loading/dungeoninfos.gbasm2
-rw-r--r--map/maps/test.ldtk2
-rw-r--r--map/maps/test/png/Level_0.pngbin0 -> 9470 bytes
-rw-r--r--scripts/round-rom-size.py34
-rw-r--r--sprites/bg/moss.pngbin187 -> 190 bytes
-rw-r--r--tileset.gbasm2
8 files changed, 39 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index c5af677..e038331 100644
--- a/Makefile
+++ b/Makefile
@@ -24,6 +24,7 @@ map/maps.gbasm: $(subst .ldtk,.map.gbasm,$(wildcard ./map/maps/*.ldtk))
build/main.rom: build/main.rom.unsigned
cp build/main.rom.unsigned build/main.rom
python scripts/set_checksums.py build/main.rom
+ python scripts/round-rom-size.py build/main.rom
build/main.rom.unsigned: main.gbasm tileset.gbasm text.gbasm dialogues/text.gbasm map/maps.gbasm $(wildcard ./*.gbasm) $(wildcard ./**/*.gbasm) $(wildcard ./**/**/*.gbasm) $(wildcard ./music/*.vgm)
mkdir -p build
diff --git a/init.gbasm b/init.gbasm
index 9495df7..08fab8f 100644
--- a/init.gbasm
+++ b/init.gbasm
@@ -32,7 +32,7 @@ Header:
.Licensee_code_new: .DB $00, $00
.SGB_Flag: .DB $00
.MBC: .DB $01
-.ROM_size: .DB $08
+.ROM_size: .DB $00 ; Will be set after assembly by build scripts
.RAM_size: .DB $00 ; The .sav cartridge kind of ram
.Destination_code: .DB $01 ; Overseas
.Licensee_code_old: .DB $00
diff --git a/map/loading/dungeoninfos.gbasm b/map/loading/dungeoninfos.gbasm
index 7d00d1a..bc46100 100644
--- a/map/loading/dungeoninfos.gbasm
+++ b/map/loading/dungeoninfos.gbasm
@@ -86,10 +86,10 @@ Load_Dungeon_Infos: ; pointer to Dungeon struct in HL, bank in A
RET
Load_Dungeon_Spawn_patterns: ; pointer to Dungeon struct in HL bank in A
+ .CHANGE_BANK_TO_A
LD A, $mem_dungeon_flags
BIT 2, A
RET Z
- .CHANGE_BANK_TO_A
LD A, L
ADD $0a
LD L, A
diff --git a/map/maps/test.ldtk b/map/maps/test.ldtk
index 65c4999..56b5fbb 100644
--- a/map/maps/test.ldtk
+++ b/map/maps/test.ldtk
@@ -30,7 +30,7 @@
"externalLevels": false,
"exportTiled": false,
"simplifiedExport": false,
- "imageExportMode": "None",
+ "imageExportMode": "OneImagePerLevel",
"exportLevelBg": true,
"pngFilePattern": null,
"backupOnSave": false,
diff --git a/map/maps/test/png/Level_0.png b/map/maps/test/png/Level_0.png
new file mode 100644
index 0000000..e2518e3
--- /dev/null
+++ b/map/maps/test/png/Level_0.png
Binary files differ
diff --git a/scripts/round-rom-size.py b/scripts/round-rom-size.py
new file mode 100644
index 0000000..a59a11f
--- /dev/null
+++ b/scripts/round-rom-size.py
@@ -0,0 +1,34 @@
+import sys
+import os
+
+if len(sys.argv) != 2:
+ raise ValueError("Rom file must be specified as first argument")
+
+rom_filename = sys.argv[1]
+current_filesize = os.path.getsize(rom_filename)
+
+i = 0
+for n in range(0, 9):
+ if current_filesize <= 32768 * (1 << n):
+ break
+ i += 1
+
+missing = (32768 * (1 << i)) - current_filesize
+
+print("Original file size =", current_filesize, "bytes")
+print("ROM size =", hex(i), "({} bytes)".format(32768 * (1 << i)))
+
+rom_file = open(rom_filename, 'r+b')
+
+rom_file.seek(0x148)
+
+rom_file.write(bytes(bytearray([i])))
+
+rom_file.close()
+
+rom_file = open(rom_filename, 'a+b')
+
+
+rom_file.write(bytes(bytearray([0]*missing)))
+
+rom_file.close()
diff --git a/sprites/bg/moss.png b/sprites/bg/moss.png
index 4e5f07c..a91d996 100644
--- a/sprites/bg/moss.png
+++ b/sprites/bg/moss.png
Binary files differ
diff --git a/tileset.gbasm b/tileset.gbasm
index 32410a3..d1126a7 100644
--- a/tileset.gbasm
+++ b/tileset.gbasm
@@ -77,7 +77,7 @@ BG_Tile_Image_Data:
.DB $00, $00, $00, $00, $00, $00, $00, $00, $33, $00, $7f, $00, $dd, $00, $00, $00 ; 0x49
; Moss
- .DB $00, $00, $00, $01, $00, $03, $03, $1c, $1f, $20, $3b, $40, $3f, $40, $77, $88 ; 0x4a
+ .DB $00, $00, $00, $01, $01, $02, $01, $1c, $1f, $20, $3b, $40, $3f, $40, $77, $88 ; 0x4a
.DB $00, $00, $00, $e0, $e0, $1c, $dc, $02, $fc, $02, $f4, $0a, $fa, $01, $be, $01 ; 0x4b
.DB $7f, $80, $33, $40, $7f, $80, $5f, $80, $6d, $90, $3b, $40, $1f, $20, $00, $1f ; 0x4c
.DB $fe, $01, $76, $01, $fe, $01, $9c, $42, $f0, $0c, $e0, $10, $a0, $10, $00, $e0 ; 0x4d