Add some more tools (experimentals) and some more better things, still a lot of thing to do...
This commit is contained in:
parent
bdbd7ee70f
commit
6bfc2d0d44
32
cel2wst.py
Normal file
32
cel2wst.py
Normal 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
51
map2wsm.py
Normal 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()
|
||||||
@ -78,8 +78,8 @@
|
|||||||
"asm": "samplesplash_vblank.s"
|
"asm": "samplesplash_vblank.s"
|
||||||
},
|
},
|
||||||
"sound": {
|
"sound": {
|
||||||
"channelwaves": "samplesplash_waves.bin",
|
"waves": "samplesplash_waves.bin",
|
||||||
"channeldata": {
|
"channelbin": {
|
||||||
"ch0": "samplesplash_ch0.bin",
|
"ch0": "samplesplash_ch0.bin",
|
||||||
"ch1": "samplesplash_ch1.bin",
|
"ch1": "samplesplash_ch1.bin",
|
||||||
"ch2": "",
|
"ch2": "",
|
||||||
|
|||||||
@ -102,8 +102,8 @@ class Tiles(object):
|
|||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.bpp = config["bpp"]
|
self.bpp = config["bpp"]
|
||||||
self.count = config["count"]
|
self.count = config["count"]
|
||||||
self.binfile = os.path.abspath(config["binfile"])
|
binfile = os.path.abspath(config["binfile"])
|
||||||
self.data = open(self.binfile, "rb").read()
|
self.data = open(binfile, "rb").read()
|
||||||
|
|
||||||
def get_size(self):
|
def get_size(self):
|
||||||
return len(self.data)
|
return len(self.data)
|
||||||
@ -111,14 +111,16 @@ class Tiles(object):
|
|||||||
def write(self, f):
|
def write(self, f):
|
||||||
f.write(self.data)
|
f.write(self.data)
|
||||||
|
|
||||||
|
|
||||||
class Tilemap(object):
|
class Tilemap(object):
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.vertical = Coordinates(config["vertical"])
|
self.vertical = Coordinates(config["vertical"])
|
||||||
self.horizontal = Coordinates(config["horizontal"])
|
self.horizontal = Coordinates(config["horizontal"])
|
||||||
self.height = config["height"]
|
self.height = config["height"]
|
||||||
self.width = config["width"]
|
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):
|
def get_size(self):
|
||||||
return len(self.data)
|
return len(self.data)
|
||||||
@ -135,12 +137,18 @@ class Tilemap(object):
|
|||||||
|
|
||||||
class VBlankCode(object):
|
class VBlankCode(object):
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.asmfile = os.path.abspath(config["asm"])
|
if "asm" in config:
|
||||||
self.binfile = os.path.splitext(self.asmfile)[0] + ".bin"
|
asmfile = os.path.abspath(config["asm"])
|
||||||
runcmd = "nasm -f bin -o {output} {input}".format(input=self.asmfile,
|
binfile = os.path.splitext(asmfile)[0] + ".bin"
|
||||||
output=self.binfile)
|
runcmd = "nasm -f bin -o {output} {input}".format(input=asmfile,
|
||||||
|
output=binfile)
|
||||||
os.system(runcmd)
|
os.system(runcmd)
|
||||||
self.data = open(self.binfile, "rb").read()
|
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):
|
def get_size(self):
|
||||||
return len(self.data)
|
return len(self.data)
|
||||||
@ -151,9 +159,10 @@ class VBlankCode(object):
|
|||||||
|
|
||||||
class Sound(object):
|
class Sound(object):
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.channelwaves = config["channelwaves"]
|
binfile = os.path.abspath(config["waves"])
|
||||||
self.waves = open(self.channelwaves, "rb").read()
|
self.waves = open(binfile, "rb").read()
|
||||||
self.channeldata = config["channeldata"]
|
|
||||||
|
channeldata = config["channelbin"]
|
||||||
self.chdata = {}
|
self.chdata = {}
|
||||||
|
|
||||||
self.chdata[0] = None
|
self.chdata[0] = None
|
||||||
@ -161,14 +170,15 @@ class Sound(object):
|
|||||||
self.chdata[2] = None
|
self.chdata[2] = None
|
||||||
self.chdata[3] = None
|
self.chdata[3] = None
|
||||||
|
|
||||||
if self.channeldata["ch0"] is not "":
|
#if channeldata["ch0"] is not "":
|
||||||
self.chdata[0] = open(self.channeldata["ch0"], "rb").read()
|
# binfile = os.path.abspath(channeldata["ch0"])
|
||||||
if self.channeldata["ch1"] is not "":
|
# self.chdata[0] = open(binfile, "rb").read()
|
||||||
self.chdata[1] = open(self.channeldata["ch1"], "rb").read()
|
#if channeldata["ch1"] is not "":
|
||||||
if self.channeldata["ch2"] is not "":
|
# self.chdata[1] = open(channeldata["ch1"], "rb").read()
|
||||||
self.chdata[2] = open(self.channeldata["ch2"], "rb").read()
|
#if channeldata["ch2"] is not "":
|
||||||
if self.channeldata["ch3"] is not "":
|
# self.chdata[2] = open(channeldata["ch2"], "rb").read()
|
||||||
self.chdata[3] = open(self.channeldata["ch3"], "rb").read()
|
#if channeldata["ch3"] is not "":
|
||||||
|
# self.chdata[3] = open(channeldata["ch3"], "rb").read()
|
||||||
|
|
||||||
def get_size(self):
|
def get_size(self):
|
||||||
return len(self.waves)
|
return len(self.waves)
|
||||||
@ -180,10 +190,18 @@ class Sound(object):
|
|||||||
|
|
||||||
|
|
||||||
class Palette(object):
|
class Palette(object):
|
||||||
def __init__(self, palette):
|
def __init__(self, config):
|
||||||
self.palettes = palette["palette"]
|
if "palette" in config:
|
||||||
self.bpp = palette["bpp"]
|
self.palettes = config["palette"]
|
||||||
self.flags = (len(self.palettes) // (2 << self.bpp)) & 0x1F
|
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:
|
if self.bpp == 2:
|
||||||
self.flags = self.flags | 0x80
|
self.flags = self.flags | 0x80
|
||||||
|
|
||||||
@ -191,8 +209,11 @@ class Palette(object):
|
|||||||
return len(self.palettes) * 2
|
return len(self.palettes) * 2
|
||||||
|
|
||||||
def write(self, f):
|
def write(self, f):
|
||||||
|
if self.palettes:
|
||||||
for p in self.palettes:
|
for p in self.palettes:
|
||||||
f.write(struct.pack("BB", p[0], (p[1] << 4) | p[2]))
|
f.write(struct.pack("BB", (p[1] << 4) | p[2], p[0]))
|
||||||
|
else:
|
||||||
|
f.write(self.data)
|
||||||
|
|
||||||
|
|
||||||
class BootSplash(object):
|
class BootSplash(object):
|
||||||
@ -212,7 +233,7 @@ class BootSplash(object):
|
|||||||
def write(self, filename):
|
def write(self, filename):
|
||||||
# This is the size of the start structure, used to calculate offset for
|
# This is the size of the start structure, used to calculate offset for
|
||||||
# all other data
|
# all other data
|
||||||
offset = 40
|
offset = 42
|
||||||
with open(filename, "wb") as f:
|
with open(filename, "wb") as f:
|
||||||
f.write(struct.pack("xxx"))
|
f.write(struct.pack("xxx"))
|
||||||
f.write(struct.pack("B", self._consoleFlags))
|
f.write(struct.pack("B", self._consoleFlags))
|
||||||
@ -263,6 +284,7 @@ class BootSplash(object):
|
|||||||
self._vblankcode.write(f)
|
self._vblankcode.write(f)
|
||||||
self._sound.write(f)
|
self._sound.write(f)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("-c", "--config", required=True, type=str, help="Configuration file")
|
parser.add_argument("-c", "--config", required=True, type=str, help="Configuration file")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user