diff --git a/samplesplash.json b/samplesplash.json index c347bcd..5854904 100644 --- a/samplesplash.json +++ b/samplesplash.json @@ -19,40 +19,43 @@ }, "color": 0 }, - "palette": [ - [0, 0, 0], - [15, 0, 0], - [0, 15, 0], - [15, 0, 15], - [0, 0, 0], - [15, 0, 0], - [0, 15, 0], - [15, 0, 15], - [0, 0, 0], - [15, 0, 0], - [0, 15, 0], - [15, 0, 15], - [0, 0, 0], - [15, 0, 0], - [0, 15, 0], - [15, 0, 15], - [0, 0, 0], - [15, 0, 0], - [0, 15, 0], - [15, 0, 15], - [0, 0, 0], - [15, 0, 0], - [0, 15, 0], - [15, 0, 15], - [0, 0, 0], - [15, 0, 0], - [0, 15, 0], - [15, 0, 15], - [0, 0, 0], - [15, 0, 0], - [0, 15, 0], - [15, 0, 15] - ], + "palette": { + "bpp": 1, + "palette": [ + [0, 0, 0], + [15, 0, 0], + [0, 15, 0], + [15, 0, 15], + [0, 0, 0], + [15, 0, 0], + [0, 15, 0], + [15, 0, 15], + [0, 0, 0], + [15, 0, 0], + [0, 15, 0], + [15, 0, 15], + [0, 0, 0], + [15, 0, 0], + [0, 15, 0], + [15, 0, 15], + [0, 0, 0], + [15, 0, 0], + [0, 15, 0], + [15, 0, 15], + [0, 0, 0], + [15, 0, 0], + [0, 15, 0], + [15, 0, 15], + [0, 0, 0], + [15, 0, 0], + [0, 15, 0], + [15, 0, 15], + [0, 0, 0], + [15, 0, 0], + [0, 15, 0], + [15, 0, 15] + ] + }, "tiles": { "bpp": 1, "count": 12, diff --git a/splashbuilder.py b/splashbuilder.py index 5804bde..cfda720 100644 --- a/splashbuilder.py +++ b/splashbuilder.py @@ -179,27 +179,36 @@ class Sound(object): f.write(self.waves) +class Palette(object): + def __init__(self, palette): + self.palettes = palette["palette"] + self.bpp = palette["bpp"] + self.flags = (len(self.palettes) // (2 << self.bpp)) & 0x1F + if self.bpp == 2: + self.flags = self.flags | 0x80 + + def get_size(self): + 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])) + + class BootSplash(object): def __init__(self, config_json): self._spriteCount = config_json["sprite"]["count"] self._animation = Animation(config_json["animation"]) self._consoleName = ConsoleName(config_json["consoleName"]) - self._palettes = config_json["palette"] + self._palettes = Palette(config_json["palette"]) self._tiles = Tiles(config_json["tiles"]) self._tilemap = Tilemap(config_json["tilemap"]) self._vblankcode = VBlankCode(config_json["vblankCode"]) self._sound = Sound(config_json["sound"]) - self._paletteSize = len(self._palettes) * 2 - print("Palette: ", self._paletteSize) - # Set bootsplash, and volume to 2 self._consoleFlags = 0x82 - def palettes_write(self, f): - for p in self._palettes: - f.write(struct.pack("BB", p[0], (p[1] << 4) | p[2])) - def write(self, filename): # This is the size of the start structure, used to calculate offset for # all other data @@ -212,12 +221,12 @@ class BootSplash(object): f.write(struct.pack("B", 1)) f.write(struct.pack("BB", self._animation.start, self._animation.end)) f.write(struct.pack("B", self._spriteCount)) - f.write(struct.pack("B", 0x00)) # Splash flags + f.write(struct.pack("B", self._palettes.flags)) # Splash flags f.write(struct.pack("B", self._tiles.count)) f.write(struct.pack("