aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/extract-data-pod.c2
-rw-r--r--tools/generate-sysroot.c69
2 files changed, 70 insertions, 1 deletions
diff --git a/tools/extract-data-pod.c b/tools/extract-data-pod.c
index 50beadc..c9d8cc0 100644
--- a/tools/extract-data-pod.c
+++ b/tools/extract-data-pod.c
@@ -18,7 +18,7 @@ static inline void ensure(bool cond, char const *msg) {
}
}
-int main(int argc, char *argv[argc + 1]) {
+int main(int argc, char *argv[argc]) {
if (argc != 3) {
printf("Usage: %s <pico8.js> <data.pod>\n", argv[0]);
return EXIT_FAILURE;
diff --git a/tools/generate-sysroot.c b/tools/generate-sysroot.c
new file mode 100644
index 0000000..7bd31dc
--- /dev/null
+++ b/tools/generate-sysroot.c
@@ -0,0 +1,69 @@
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static inline void check(bool cond, char const *msg) {
+ if (!cond) {
+ perror(msg);
+ exit(EXIT_FAILURE);
+ }
+}
+
+static void write_sysroot_data(char const *name, char const *file) {
+ FILE *f = fopen(file, "rb");
+ check(f, "fopen(input)");
+
+ check(fseek(f, 0, SEEK_END) == 0, "fseek(end)");
+ size_t size = ftell(f);
+ check(fseek(f, 0, SEEK_SET) == 0, "fseek(start)");
+
+ printf("struct pw_sysroot_data %s = {\n", name);
+ printf(" .len = %zu,\n", size);
+ printf(" .data = {\n");
+
+ size_t total = 0;
+ size_t n;
+ uint8_t data[16];
+ while ((n = fread(data, 1, sizeof(data), f))) {
+ total += n;
+
+ printf(" ");
+ for (size_t i = 0; i < n; i++) {
+ printf(" 0x%02x,", data[i]);
+ }
+ printf("\n");
+ }
+
+ printf(" },\n};\n");
+
+ check(total == size, "fread(input)");
+ check(fclose(f) == 0, "fclose(input)");
+}
+
+int main(int argc, char *argv[argc]) {
+ if (argc != 2) {
+ printf("Usage: %s <sysroot>\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ printf("// This file is automatically generated, do not edit by hand.\n");
+ printf("// clang-format off\n");
+ printf("#include \"sysroot.h\"\n");
+
+ struct {
+ char const *name;
+ char const *file;
+ } entries[] = {
+ {"pw_sysroot_pico8_wasm", "pico8.wasm"},
+ {"pw_sysroot_pico8_data_pod", "pico8.data.pod"},
+ {"pw_sysroot_boot_rom", "boot.p8.rom"},
+ };
+ for (size_t i = 0; i < sizeof entries / sizeof entries[0]; i++) {
+ char file[256];
+ snprintf(file, sizeof(file), "%s/%s", argv[1], entries[i].file);
+ write_sysroot_data(entries[i].name, file);
+ }
+
+ return EXIT_SUCCESS;
+}