diff options
author | Juan J. Martinez <jjm@usebox.net> | 2021-05-18 07:39:11 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2021-05-18 07:39:11 +0100 |
commit | 62b312980033bad470531905f2bcdb3b46cc1c14 (patch) | |
tree | 844116f633031c46620835b8ca2b444ecd5fda42 /tools | |
parent | 2ffda6c5bc972f15f1b45a9c746cbc7bb41febe8 (diff) | |
download | beeper-int-zx-62b312980033bad470531905f2bcdb3b46cc1c14.tar.gz beeper-int-zx-62b312980033bad470531905f2bcdb3b46cc1c14.zip |
Added a sfx2h tool
Diffstat (limited to 'tools')
-rw-r--r-- | tools/sfx2h.md | 51 | ||||
-rwxr-xr-x | tools/sfx2h.py | 60 |
2 files changed, 111 insertions, 0 deletions
diff --git a/tools/sfx2h.md b/tools/sfx2h.md new file mode 100644 index 0000000..bfd6b88 --- /dev/null +++ b/tools/sfx2h.md @@ -0,0 +1,51 @@ +# sfx2h.py + +This tool requires Python 3 and can generate a C include file from a sfx file +as saved by `sfxed`. + +Being Python is easier to modify and adapt to your own needs! + +Example: +``` +sfx2h.py ../test.sfx sounds +``` + +Will generate: +``` + +/* file: ../example/test.sfx */ +#ifndef SOUNDS_H_ +#define SOUNDS_H_ + +#include "beeper.h" + +enum sounds_enum { + SOUNDS_LASER = 1, + SOUNDS_ZAP, + SOUNDS_DRILL, + SOUNDS_EXPLO, +}; + +#ifdef LOCAL + +const struct beeper_sfx sounds[] = { +{ 0x01, 0x20, 0x78, 0xfc, 0x00 }, +{ 0x02, 0x10, 0x0c, 0x00, 0x00 }, +{ 0x01, 0x20, 0x01, 0x00, 0x00 }, +{ 0x02, 0x20, 0x80, 0xff, 0x00 }, +}; + +#else +extern const struct beeper_sfx sounds[]; +#endif +#endif // SOUNDS_H_ +``` + +You can include it normally on any C file, just remember to define `LOCAL` +before included in the module containing the data (only once!). + +## CAVEATS + +* Is not perfuming exhaustive checks on the effects' names or the provided id +* `LOCAL` is not undefined after used + diff --git a/tools/sfx2h.py b/tools/sfx2h.py new file mode 100755 index 0000000..b76bbfc --- /dev/null +++ b/tools/sfx2h.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 + +from argparse import ArgumentParser + +__version__ = "1.0" + + +def main(): + + parser = ArgumentParser(description="SFXv1 to H converter", + epilog="Copyright (C) 2021 Juan J Martinez <jjm@usebox.net>", + ) + + parser.add_argument("--version", action="version", + version="%(prog)s " + __version__) + parser.add_argument("file", help="file to convert") + parser.add_argument("id", help="variable to use") + + args = parser.parse_args() + + with open(args.file, "rt") as fd: + lines = fd.readlines() + + header = lines.pop(0) + if header != ";SFXv1\n": + parser.error("The file doesn't seem to be a valid SFV v1 file") + + names = [] + data = [] + for line in lines: + b = line.strip().split(" ") + names.append(b[0].upper()) + data.append([int(byt) & 0xff for byt in b[1:]]) + + include = "%s_H_" % args.id.upper() + print("/* file: %s */" % args.file) + print("#ifndef %s" % include) + print("#define %s\n" % include) + + print("#include \"beeper.h\"\n") + + print("enum %s_enum {" % args.id) + print("\t%s_%s = 1," % (args.id.upper(), names[0].upper())) + for n in names[1:]: + print("\t%s_%s," % (args.id.upper(), n.upper())) + print("};\n") + + print("#ifdef LOCAL\n") + print("const struct beeper_sfx %s[] = {" % args.id) + for d in data: + print("{ %s }," % ', '.join(["0x%02x" % b for b in d])) + print("};\n") + print("#else") + print("extern const struct beeper_sfx %s[];" % args.id) + print("#endif") + print("#endif // %s" % include) + + +if __name__ == "__main__": + main() |