Add some more tools (experimentals) and some more better things, still a lot of thing to do...

This commit is contained in:
Godzil 2019-10-04 18:19:30 +01:00
parent bdbd7ee70f
commit 6bfc2d0d44
4 changed files with 135 additions and 30 deletions

32
cel2wst.py Normal file
View File

@ -0,0 +1,32 @@
# GB CEL to WS Tile
import struct
import argparse
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--input", required=True, type=str, help="Input file")
parser.add_argument("-o", "--output", type=str, help="Output file", default="output.bin")
args = parser.parse_args()
with open(args.input, "rb") as f_in:
with open(args.output, "wb") as f_out:
for prout in range(6):
data = f_in.read(8*8)
print(type(data))
p0 = 0
p1 = 0
for y in range(8):
for x in range(8):
d = struct.unpack("B", data[y*8+x])[0]
p0 = p0 << 1
p0 |= 1 if d & 0x01 else 0
p1 = p1 << 1
p1 |= 1 if d & 0x02 else 0
f_out.write(struct.pack("BB", p0, p1))
p0 = 0
p1 = 0
if __name__ == "__main__":
main()

51
map2wsm.py Normal file
View File

@ -0,0 +1,51 @@
# Convert GB Map to WS Map
import struct
import argparse
"""
GP Map is done:
- width (4 bytes)
- height (4 bytes)
Tiles[] (2 bytes)
b11 - Vert mirror
b10 - Horz mirror
b9-b0 - tile number
"""
"""
WS Map is
b15 vert flip
b14 horz flip
b13 tile bank
b12-b9 palette
b8-b0 tile
"""
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--input", required=True, type=str, help="Input file")
parser.add_argument("-o", "--output", type=str, help="Output file", default="output.bin")
args = parser.parse_args()
with open(args.input, "rb") as f_in:
with open(args.output, "wb") as f_out:
data = f_in.read(4)
width = struct.unpack("<L", data)[0]
data = f_in.read(4)
height = struct.unpack("<L", data)[0]
print("Width: {w}\nHeight: {h}".format(w=width, h=height))
for i in range(width * height):
data = f_in.read(2)
tmp = struct.unpack("<H", data)[0]
v_flip = tmp & (1 << 11)
h_flip = tmp & (1 << 10)
tile = tmp & 0x1FF
out = (1 << 15) if v_flip else 0
out |= (1 << 14) if h_flip else 0
out |= (tile + 0x2E) & 0xFF
f_out.write(struct.pack("<H", out))
if __name__ == "__main__":
main()

View File

@ -78,8 +78,8 @@
"asm": "samplesplash_vblank.s"
},
"sound": {
"channelwaves": "samplesplash_waves.bin",
"channeldata": {
"waves": "samplesplash_waves.bin",
"channelbin": {
"ch0": "samplesplash_ch0.bin",
"ch1": "samplesplash_ch1.bin",
"ch2": "",

View File

@ -102,8 +102,8 @@ class Tiles(object):
def __init__(self, config):
self.bpp = config["bpp"]
self.count = config["count"]
self.binfile = os.path.abspath(config["binfile"])
self.data = open(self.binfile, "rb").read()
binfile = os.path.abspath(config["binfile"])
self.data = open(binfile, "rb").read()
def get_size(self):
return len(self.data)
@ -111,14 +111,16 @@ class Tiles(object):
def write(self, f):
f.write(self.data)
class Tilemap(object):
def __init__(self, config):
self.vertical = Coordinates(config["vertical"])
self.horizontal = Coordinates(config["horizontal"])
self.height = config["height"]
self.width = config["width"]
self.binfile = os.path.abspath(config["binfile"])
self.data = open(self.binfile, "rb").read()
binfile = os.path.abspath(config["binfile"])
self.data = open(binfile, "rb").read()
def get_size(self):
return len(self.data)
@ -135,12 +137,18 @@ class Tilemap(object):
class VBlankCode(object):
def __init__(self, config):
self.asmfile = os.path.abspath(config["asm"])
self.binfile = os.path.splitext(self.asmfile)[0] + ".bin"
runcmd = "nasm -f bin -o {output} {input}".format(input=self.asmfile,
output=self.binfile)
os.system(runcmd)
self.data = open(self.binfile, "rb").read()
if "asm" in config:
asmfile = os.path.abspath(config["asm"])
binfile = os.path.splitext(asmfile)[0] + ".bin"
runcmd = "nasm -f bin -o {output} {input}".format(input=asmfile,
output=binfile)
os.system(runcmd)
self.data = open(binfile, "rb").read()
elif "binfile" in config:
binfile = os.path.abspath(config["binfile"])
self.data = open(binfile, "rb").read()
else:
self.data = b"cb"
def get_size(self):
return len(self.data)
@ -151,9 +159,10 @@ class VBlankCode(object):
class Sound(object):
def __init__(self, config):
self.channelwaves = config["channelwaves"]
self.waves = open(self.channelwaves, "rb").read()
self.channeldata = config["channeldata"]
binfile = os.path.abspath(config["waves"])
self.waves = open(binfile, "rb").read()
channeldata = config["channelbin"]
self.chdata = {}
self.chdata[0] = None
@ -161,14 +170,15 @@ class Sound(object):
self.chdata[2] = None
self.chdata[3] = None
if self.channeldata["ch0"] is not "":
self.chdata[0] = open(self.channeldata["ch0"], "rb").read()
if self.channeldata["ch1"] is not "":
self.chdata[1] = open(self.channeldata["ch1"], "rb").read()
if self.channeldata["ch2"] is not "":
self.chdata[2] = open(self.channeldata["ch2"], "rb").read()
if self.channeldata["ch3"] is not "":
self.chdata[3] = open(self.channeldata["ch3"], "rb").read()
#if channeldata["ch0"] is not "":
# binfile = os.path.abspath(channeldata["ch0"])
# self.chdata[0] = open(binfile, "rb").read()
#if channeldata["ch1"] is not "":
# self.chdata[1] = open(channeldata["ch1"], "rb").read()
#if channeldata["ch2"] is not "":
# self.chdata[2] = open(channeldata["ch2"], "rb").read()
#if channeldata["ch3"] is not "":
# self.chdata[3] = open(channeldata["ch3"], "rb").read()
def get_size(self):
return len(self.waves)
@ -180,10 +190,18 @@ class Sound(object):
class Palette(object):
def __init__(self, palette):
self.palettes = palette["palette"]
self.bpp = palette["bpp"]
self.flags = (len(self.palettes) // (2 << self.bpp)) & 0x1F
def __init__(self, config):
if "palette" in config:
self.palettes = config["palette"]
self.data = None
elif "binfile" in config:
self.palettes = None
self.data = open(config["binfile"], "rb").read()
else:
self.data = b""
self.bpp = config["bpp"]
self.flags = (len(self.palettes) // (1 << self.bpp)) & 0x1F
if self.bpp == 2:
self.flags = self.flags | 0x80
@ -191,8 +209,11 @@ class Palette(object):
return len(self.palettes) * 2
def write(self, f):
for p in self.palettes:
f.write(struct.pack("BB", p[0], (p[1] << 4) | p[2]))
if self.palettes:
for p in self.palettes:
f.write(struct.pack("BB", (p[1] << 4) | p[2], p[0]))
else:
f.write(self.data)
class BootSplash(object):
@ -212,7 +233,7 @@ class BootSplash(object):
def write(self, filename):
# This is the size of the start structure, used to calculate offset for
# all other data
offset = 40
offset = 42
with open(filename, "wb") as f:
f.write(struct.pack("xxx"))
f.write(struct.pack("B", self._consoleFlags))
@ -263,6 +284,7 @@ class BootSplash(object):
self._vblankcode.write(f)
self._sound.write(f)
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-c", "--config", required=True, type=str, help="Configuration file")