Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Game metadata #292

Closed
Gadgetoid opened this issue Mar 11, 2020 · 3 comments
Closed

Game metadata #292

Gadgetoid opened this issue Mar 11, 2020 · 3 comments

Comments

@Gadgetoid
Copy link
Contributor

At some point or another we'll probably want to append game metadata to the end of .bin files (using a hypothetical new Python tool in the 32blit-tools package - https://github.com/pimoroni/32blit-tools).

This metadata could then be read by the firmware UI to display icons, titles and maybe even small preview images.

I did some thinking about this a while back and came up with:

#!/usr/bin/env python3

"""
const uint64_t blit_game_header = (uint64_t)"BLITGAME";

struct blit_game {
    const uint64_t header;
    int8ul header_version;
    rgba icon[32 * 32];
    char title[64];
    char description[256];
    char reserved[177];
    uint32_t version;
    uint16_t blocks;
};
"""

import argparse
import math
import sys
import zlib

from construct import this, Checksum, Rebuild, Padded, CString, Const, Struct, Int64ul, Int32ul, Int16ul, Int8ul, Array, GreedyBytes, Enum
from PIL import Image

image = Image.new('RGBA', (32, 32), (255, 255, 255, 0))
image = image.convert('RGBA')

asset_game = Struct(
    'header' / Const(int("".join(["{:02x}".format(ord(x)) for x in "BLITGAME"]), 16), Int64ul),
    'header_version' / Const(1, Int8ul),
    'icon' / Array(32 * 32 * 4, Int8ul),
    'title' / Padded(64, CString('utf8')),
    'description' / Padded(256, CString('utf8')),
    'reserved' / Const(bytes([0xFF] * 177)),
    'version' / Rebuild(Int32ul,
                        lambda data: 0xffffffff ^ zlib.crc32(data.data)),
    'blocks' / Int16ul,
    'data' / GreedyBytes
)

data = asset_game.build({
    'icon': image.tobytes(),
    'title': 'My 32blit game or something',
    'description': 'Some kind of description of my game',
    'version': 0x00000001,
    'blocks': 1,
    'data': bytes([0x66] * 256)
})

game = asset_game.parse(data)

print("Size: {:d}b".format(len(data)))
print("Flash pages used: {:d}".format(int(len(data) / 256.0)))
print("Flash blocks used: {:d}".format(math.ceil(len(data) / 256.0 / 64.0)))
print("Checksum: 0x{:08x}".format(game.version))
@Gadgetoid Gadgetoid added this to ROADMAP in tools / tooling Mar 11, 2020
@mgarcia-org
Copy link

mgarcia-org commented Mar 11, 2020

it would be great to have a way to bypass the menu with a default or autostart exe.app, when first turned on.
IE, using a specifically filename in the SD root, autostart.bin or debug.bin etc
Then, when exiting, going back to the actual menu.

Also, can this data be use to generate a nicer Emscripten web page?
Maybe make the description the last field and make it dynamic, so that it can be as big or small as the dev wants? ie include dev bio or game instructions or even HTML for webpage?

@Gadgetoid
Copy link
Contributor Author

I have started building tooling for metadata into the 32blit tool, proof of concept here - 32blit/32blit-tools#16

All fields are variable length and the max metadata payload size is a generous 65k.

@Gadgetoid
Copy link
Contributor Author

Closing, since we have a functional metadata proof of concept in 32blit and the tooling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants