23 PROTOTYPE =
"const Uint8"
28 MEMCONTENT_VERSION_ID = 2
34 "HICKUP.M65": (
"hickup",
None ),
35 "COLOURRAM.BIN": (
"cramutils",
None ),
36 "BANNER.M65": (
"banner",
"BANNER.M65" ),
37 "FREEZER.M65": (
"freezer",
"FREEZER.M65" ),
38 "ONBOARD.M65": (
"onboard",
"ONBOARD.M65" ),
39 "mega65.rom": (
"initrom",
None ),
41 "AUDIOMIX.M65": (
"audiomix",
"AUDIOMIX.M65" ),
42 "C64THUMB.M65": (
"c64thumb",
"C64THUMB.M65" ),
43 "C65THUMB.M65": (
"c65thumb",
"C65THUMB.M65" ),
44 "ROMLOAD.M65": (
"romload",
"ROMLOAD.M65" ),
45 "SPRITED.M65": (
"sprited",
"SPRITED.M65" ),
46 "charrom.bin": (
"chrwom",
None ),
47 "MAKEDISK.M65": (
"makedisk",
"MAKEDISK.M65" ),
50 HEADER =
"""/* !THIS IS A GENERATED FILE! DO NOT EDIT!
51 * Instead, say 'make recreatememcontent' to re-generate this file
52 * from binary data from the MEGA65 project. Please note, that MEGA65 is
53 * an open source, GNU/GPL project, like Xemu. Thus, it's valid
54 * to use binaries from it, as it's from the compiled version of MEGA65
55 * which is available in source form at https://github.com/MEGA65/mega65-core
56 * always, as per GNU/GPL. */
64 out +=
"0x{:02X}".format(data[ct])
74 if __name__ ==
"__main__":
75 if len(set(FILE_DB.values())) != len(FILE_DB):
76 sys.stderr.write(
"Internal DB problem, redundancy in FILE_DB!\n")
79 sys.stderr.write(
"Bad usage.\n")
84 in_files = sys.argv[3:]
87 h_data +=
"#ifndef XEMU_MEGA65_{}_INCLUDED\n".format(h_file.upper().replace(
".",
"_"))
88 h_data +=
"#define XEMU_MEGA65_{}_INCLUDED\n".format(h_file.upper().replace(
".",
"_"))
89 h_data +=
"""\n// This must be incremented by ONE every time, when memcontent.c changes, or even
90 // if sdcontent.c is changed in a way to write new files, new content, or whatever
91 // to the SD-card as part of the "update system files" process. Edit this in the python generator though, not in this file!
92 #define MEMCONTENT_VERSION_ID {}\n\n""".format(MEMCONTENT_VERSION_ID)
93 c_data +=
"#include \"xemu/emutools_basicdefs.h\"\n"
94 c_data +=
"#include \"memcontent.h\"\n\n"
95 h_data +=
"// Special structure array for system files update on the SD-image\n"
96 c_data +=
"// Special structure array for system files update on the SD-image\n"
97 on_sd = sorted([k
for k, v
in FILE_DB.items()
if v[1]
is not None])
98 h_data +=
"struct meminitdata_sdfiles_st { const Uint8 *p; const char *fn; const int size; };\n"
99 h_data +=
"#define MEMINITDATA_SDFILES_ITEMS {}\n".format(len(on_sd))
100 h_data +=
"extern const struct meminitdata_sdfiles_st meminitdata_sdfiles_db[MEMINITDATA_SDFILES_ITEMS];\n"
101 c_data +=
"const struct meminitdata_sdfiles_st meminitdata_sdfiles_db[MEMINITDATA_SDFILES_ITEMS] = {\n"
102 print(
"Adding files also as SD-content: {}".format(
" ".join(on_sd)))
105 c_data +=
" meminitdata_{}, \"{}\", MEMINITDATA_{}_SIZE ".format(FILE_DB[a][0], FILE_DB[a][1].upper(), FILE_DB[a][0].upper())
109 fn_base = fn.split(
"/")[-1]
110 if fn_base
not in FILE_DB:
111 sys.stderr.write(
"Unknown file encountered: {}\n".format(fn))
113 fn_id = FILE_DB[fn_base][0]
114 if fn_id
in files_done:
115 sys.stderr.write(
"ERROR: file {} is used more than once by id \"{}\"!\n".format(fn, fn_id))
117 files_done.add(fn_id)
118 with open(fn,
"rb")
as data:
120 print(
"Using file {} (${:X} bytes) as {} ...".format(fn, len(data), fn_id))
122 sys.stderr.write(
"ERROR: file {} is zero byte long!\n".format(fn))
124 h_data +=
"\n// Generated as \"{}\" from file {} (${:X} bytes)\n".format(fn_id, fn, len(data))
125 h_data +=
"#define MEMINITDATA_{}_SIZE 0x{:X}\n".format(fn_id.upper(), len(data))
126 h_data +=
"extern {} meminitdata_{}[MEMINITDATA_{}_SIZE];\n".format(PROTOTYPE, fn_id, fn_id.upper())
127 c_data +=
"\n// Generated as \"{}\" from file {} (${:X} bytes)\n".format(fn_id, fn, len(data))
128 c_data +=
"{} meminitdata_{}[MEMINITDATA_{}_SIZE] = {};\n".format(PROTOTYPE, fn_id, fn_id.upper(),
bin_dump(data))
129 h_data +=
"\n#endif\n"
131 with open(c_file,
"wt")
as f: f.write(c_data)
132 with open(h_file,
"wt")
as f: f.write(h_data)
133 for k, v
in FILE_DB.items():
134 if v[0]
not in files_done:
135 print(
"Warning: entity {} was not specified (via filename {})\n".format(v[0], k))