aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Rodrigues Lordello <[email protected]>2025-05-24 12:23:55 +0200
committerNicholas Rodrigues Lordello <[email protected]>2025-05-24 12:23:55 +0200
commit47a60f0f1c71d6e5bca5d8ee72f0ad7c63e1817c (patch)
treec9bb5aea4d3edcd082b3b14bad48002f81cf3c11
parent775d758653a196184ee4e572185a9092eb72c0d8 (diff)
Changed Boot Sequence
We now have a "sysroot" folder with a "boot" cart, and a separate "carts" folder containing the games.
-rw-r--r--.gitignore6
-rw-r--r--Makefile30
-rw-r--r--include/picow.h3
-rw-r--r--platform/sdl/main.c47
4 files changed, 39 insertions, 47 deletions
diff --git a/.gitignore b/.gitignore
index a5bad17..cacd8e0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,8 @@
-export/
+carts/*.html
+carts/*.js
+carts/*.wasm
+carts/*.p8.png
+carts/*.p8.rom
system/
target/
tools/*.exe
diff --git a/Makefile b/Makefile
index 25c9f65..5acae68 100644
--- a/Makefile
+++ b/Makefile
@@ -12,34 +12,38 @@ platform/sdl/picow: platform/sdl/main.c src/picow.c src/png.c include/picow.h
.PHONY: system
system: system/pico8.data.pod system/pico8.wasm system/boot.p8.rom ;
-system/pico8.data.pod: export/pico8.js tools/extract-data-pod.exe system/.dir
+system/pico8.data.pod: carts/pico8.js tools/extract-data-pod.exe
+ @mkdir -p system
tools/extract-data-pod.exe $< $@
-system/pico8.wasm: export/pico8.wasm system/.dir
+system/pico8.wasm: carts/pico8.wasm
+ @mkdir -p system
cp $< $@
-system/boot.p8.rom: carts/boot.p8 system/.dir
- $(PICO8) $< -export $@
+system/boot.p8.rom: carts/boot.p8.rom
+ @mkdir -p system
+ cp $< $@
-export/%.html export/%.js export/%.wasm: export/%.w ;
-export/%.w: carts/%.p8 export/.dir
+carts/%.html carts/%.js carts/%.wasm: carts/%.w ;
+carts/%.w: carts/%.p8
$(PICO8) $< -export "-w $(@:.w=.html)"
-export/%.p8.png: carts/%.p8 export/.dir
+carts/%.p8.png: carts/%.p8
$(PICO8) $< -export $@
-export/%.p8.rom: carts/%.p8 export/.dir
+carts/%.p8.rom: carts/%.p8
$(PICO8) $< -export $@
tools/%.exe: tools/%.c
$(CC) -o $@ $<
-.INTERMEDIATE: export/.dir system/.dir
-%/.dir:
- @mkdir -p $(dir $@)
- @touch $@
-
.PHONY: check
check:
@$(CLANG_FORMAT) -i include/*.h src/*.c platform/*/*.c tools/*.c
@$(CLANG_TIDY) src/*.c --checks=all --header-filter=include/ -- -Iinclude/ -Ilib/
+
+.PHONY: clean
+clean:
+ rm -r carts/*.html carts/*.js carts/*.wasm carts/*.p8.png carts/*.p8.rom
+ rm -f tools/*.exe
+ rm -rf system/
diff --git a/include/picow.h b/include/picow.h
index f1b6aab..e3f1e03 100644
--- a/include/picow.h
+++ b/include/picow.h
@@ -43,8 +43,7 @@ union pw_gamepad {
};
struct pw_state {
- size_t ncarts;
- struct pw_cart *carts;
+ struct pw_cart boot;
union pw_gamepad gamepads[8];
};
diff --git a/platform/sdl/main.c b/platform/sdl/main.c
index 7887b3f..f2dcb31 100644
--- a/platform/sdl/main.c
+++ b/platform/sdl/main.c
@@ -8,14 +8,11 @@
static void usage(char const *name) {
// clang-format off
- printf("Usage: %s [-s <sysroot>] [-P] [-v[v[v]]] <cart.rom>[:<name>]...\n", name);
- printf(" -s <sysroot> The root directory with PICO-8 system files ('pico8.wasm'\n");
- printf(" and 'pico8.data.pod'). Defaults to 'system'.\n");
- printf(" -v[v[v]] Increasingly verbose logging.\n");
- printf(" cart.rom[:name] Cart rom to load, optionally with a cart name. Name will\n");
- printf(" default to the file's basename minus the '.rom' extension.\n");
- printf(" Can be specified multiple times for multi-carts, where the\n");
- printf(" first cart is what is initially loaded.\n");
+ printf("Usage: %s [-s <sysroot>] [-c <carts>] [-v[v[v]]]\n", name);
+ printf(" -s <sysroot> The root directory with PICO-8 system files ('pico8.wasm',\n");
+ printf(" 'pico8.data.pod', and 'boot.p8.rom'). Defaults to 'system'.\n");
+ printf(" -c <carts> Carts directory. Defaults to 'carts'.\n");
+ printf(" -v[v[v]] Increasingly verbose logging.\n");
// clang-format on
}
@@ -243,6 +240,11 @@ static SDL_AppResult handle_button(struct appstate *state,
static SDL_AppResult handle_keyboard(struct appstate *state,
SDL_KeyboardEvent *event) {
+ switch (event->key) {
+ case SDLK_ESCAPE:
+ case SDLK_Q:
+ return SDL_APP_SUCCESS;
+ }
return SDL_APP_CONTINUE;
}
@@ -266,10 +268,11 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv) {
}
char *sysroot = "system";
+ char *carts = "carts";
SDL_LogPriority logp = SDL_GetLogPriority(0);
int c;
- while ((c = getopt(argc, argv, "hs:v")) != -1) {
+ while ((c = getopt(argc, argv, "hs:c:v")) != -1) {
switch (c) {
case 'h':
usage(argv[0]);
@@ -277,6 +280,9 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv) {
case 's':
sysroot = optarg;
break;
+ case 'c':
+ carts = optarg;
+ break;
case 'v':
logp--;
if (logp == SDL_LOG_PRIORITY_INVALID) {
@@ -291,20 +297,6 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv) {
}
SDL_SetLogPriority(0, logp);
- state->picow.ncarts = argc - optind;
- if (state->picow.ncarts == 0) {
- fprintf(stderr, "ERROR: must specify at least one cart.\n");
- return SDL_APP_FAILURE;
- }
-
- state->picow.carts = SDL_malloc(sizeof(struct pw_cart[state->picow.ncarts]));
- for (int i = 0; i < state->picow.ncarts; i++) {
- char *s = argv[optind + i];
- if (!load_cart(&state->picow.carts[i], s)) {
- return FAILF("could not load cart '%s'", s);
- }
- }
-
if (!SDL_CreateWindowAndRenderer("PICO-w", 512, 512,
SDL_WINDOW_HIGH_PIXEL_DENSITY |
SDL_WINDOW_RESIZABLE,
@@ -360,13 +352,7 @@ SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) {
return handle_button(state, &event->gbutton);
case SDL_EVENT_KEY_DOWN:
case SDL_EVENT_KEY_UP:
- switch (event->key.key) {
- case SDLK_ESCAPE:
- case SDLK_Q:
- return SDL_APP_SUCCESS;
- default:
- return handle_keyboard(state, &event->key);
- }
+ return handle_keyboard(state, &event->key);
}
return SDL_APP_CONTINUE;
}
@@ -380,7 +366,6 @@ void SDL_AppQuit(void *appstate, SDL_AppResult result) {
SDL_DestroyTexture(state->framebuffer);
SDL_DestroyRenderer(state->renderer);
SDL_DestroyWindow(state->window);
- SDL_free(state->picow.carts);
SDL_free(state);
SDL_Log(0, "bye");