aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNicholas Rodrigues Lordello <[email protected]>2026-09-17 12:09:55 +0200
committerNicholas Rodrigues Lordello <[email protected]>2026-09-17 12:10:35 +0200
commit7d54f3115d5acd58352a095206869d7b7d908d5f (patch)
tree66b43cedbfb0a322d99c96568490c5b00b2f0435 /src
parent674abec04cc06de1b451d4efbbb52ca8b202beee (diff)
Generate Sysroot in Build Directory
This is a mouthful! We now generate `sysroot.c` **and** its corresponding header file `sysroot.h`. We also made a few modifications to the Makefile to better support out builds: - We now output to `build/` - this plays nicer with tooling as that is the typical directory created by CMake, and helps with things like `compile_commands.json` being automagically picked up by `clangd`. - We now have a recipe for building a `compile_commands.json` file, so that `clangd` can provide LSP support out-of-the box. It works by creating a small wrapper `ccj` compiler that adds the required `-MJ <path>` option to clang. This is an adhoc solution to avoid pulling in additional build dependencies to the project, and works well enough :)
Diffstat (limited to 'src')
-rw-r--r--src/picow.c23
-rw-r--r--src/sysroot.h16
2 files changed, 15 insertions, 24 deletions
diff --git a/src/picow.c b/src/picow.c
index 346ee65..731eff1 100644
--- a/src/picow.c
+++ b/src/picow.c
@@ -1,3 +1,4 @@
+#include <limits.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
@@ -14,7 +15,7 @@
static void usage(char const *name) {
// clang-format off
- printf("Usage: %s [-s <sysroot>] [-c <carts>] [-v[v[v]]]\n", name);
+ printf("Usage: %s [-c <carts>] [-v[v[v]]]\n", name);
printf(" -c <carts> Carts directory. Defaults to 'carts'.\n");
printf(" -v[v[v]] Increasingly verbose logging.\n");
// clang-format on
@@ -70,7 +71,7 @@ struct pw_appstate {
struct pw_pxtexture cartpng;
struct pw_gamepad gamepads[8];
struct pw_cart cart;
- char (*carts)[256];
+ char (*carts)[PATH_MAX];
int ncarts;
int cartidx;
int cartidx2;
@@ -80,10 +81,9 @@ struct pw_appstate {
enum pw_scene scene2;
};
-#define FAIL(msg) \
- (SDL_LogCritical(0, msg ". %s", SDL_GetError()), SDL_APP_FAILURE)
-#define FAILF(msg, ...) \
- (SDL_LogCritical(0, msg ". %s", __VA_ARGS__, SDL_GetError()), SDL_APP_FAILURE)
+#define FAIL(msg, ...) \
+ (SDL_LogCritical(0, msg ". %s", ##__VA_ARGS__, SDL_GetError()), \
+ SDL_APP_FAILURE)
static bool init_pxtexture(SDL_Renderer *renderer, struct pw_pxtexture *texture,
int w, int h) {
@@ -602,20 +602,27 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv) {
char **cartfiles = SDL_GlobDirectory(
carts, "*.p8.png", SDL_GLOB_CASEINSENSITIVE, &state->ncarts);
- if (cartfiles != NULL) {
+ if (cartfiles != NULL && state->ncarts > 0) {
// Unfortunately, SDL returns files without the leading path, so we need to
// manually pre-pend it to each found cart.
state->carts = SDL_calloc(state->ncarts, sizeof *state->carts);
for (int i = 0; i < state->ncarts; i++) {
SDL_strlcat(state->carts[i], carts, sizeof *state->carts);
SDL_strlcat(state->carts[i], "/", sizeof *state->carts);
- SDL_strlcat(state->carts[i], cartfiles[i], sizeof *state->carts);
+ size_t clen =
+ SDL_strlcat(state->carts[i], cartfiles[i], sizeof *state->carts);
+ if (clen + 1 >= PATH_MAX) {
+ return FAIL("invalid cart path '%s'", cartfiles[i]);
+ }
}
SDL_free(cartfiles);
if (!load_cart(&state->cartpng, &state->cart, state->carts[0])) {
return FAIL("unable to load cart");
}
+ } else if (cartfiles != NULL) {
+ SDL_LogWarn(0, "empty carts directory");
+ SDL_free(cartfiles);
} else {
SDL_LogWarn(0, "failed to read carts directory. %s", SDL_GetError());
state->ncarts = 0;
diff --git a/src/sysroot.h b/src/sysroot.h
deleted file mode 100644
index 8321d29..0000000
--- a/src/sysroot.h
+++ /dev/null
@@ -1,16 +0,0 @@
-#ifndef _PICOW_SYSROOT_H_
-#define _PICOW_SYSROOT_H_
-
-#include <stddef.h>
-#include <stdint.h>
-
-struct pw_sysroot_data {
- size_t len;
- uint8_t data[];
-};
-
-extern struct pw_sysroot_data pico8_wasm;
-extern struct pw_sysroot_data pico8_data_pod;
-extern struct pw_sysroot_data unknown_p8_png;
-
-#endif