diff options
| author | Nicholas Rodrigues Lordello <[email protected]> | 2026-10-29 13:22:28 +0100 |
|---|---|---|
| committer | Nicholas Rodrigues Lordello <[email protected]> | 2026-10-29 13:33:26 +0100 |
| commit | 838d75bce98ca5a1f90f762e80d2aa649d4e0642 (patch) | |
| tree | 06d661dd944d80632aa80a9f605a679779575dc5 /src/cart.c | |
| parent | e51027a576a07ffb41b6e7d2bfc3aade6ae091d7 (diff) | |
Minor Fixes
Diffstat (limited to 'src/cart.c')
| -rw-r--r-- | src/cart.c | 59 |
1 files changed, 36 insertions, 23 deletions
@@ -10,7 +10,7 @@ static bool cart_file_path(struct pw_cart_file *file, char const *dir, char const *filename, char const *ext) { if (!pw_pathjoin(file->path, PW_CART_PATH_MAX, dir, filename, NULL) || !pw_stripext(file->name, PW_CART_NAME_MAX, filename, ext)) { - SDL_SetError("invalid cart file name %s", filename); + SDL_SetError("invalid file name %s", filename); return false; } @@ -48,22 +48,24 @@ struct pw_carts *pw_carts_list(char const *dir) { goto error; } - size_t count = (size_t)icount; - if (count > SIZE_MAX / sizeof(struct pw_cart_file)) { + size_t max_count = (size_t)icount; + if (max_count > SIZE_MAX / sizeof(struct pw_cart_file)) { goto error; } - carts = SDL_malloc(sizeof(*carts) + count * sizeof(*carts->files)); + carts = SDL_malloc(sizeof(*carts) + max_count * sizeof(*carts->files)); if (!carts) { goto error; } - carts->count = 0; - for (size_t i = 0; i < count; i++) { - struct pw_cart_file *file = &carts->files[i]; + size_t count = 0; + for (size_t i = 0; i < max_count; i++) { + struct pw_cart_file *file = &carts->files[count]; if (!cart_file_path(file, dir, cartfiles[i], ".png")) { - goto error; + SDL_LogWarn(0, "unsupported cart file: %s", SDL_GetError()); + continue; } + count++; } carts->count = count; @@ -140,20 +142,10 @@ struct pw_cart_png *pw_cart_png_init(SDL_Renderer *renderer) { goto error; } - union pw_png_pixel *image = pw_png_load( - pw_sysroot_unknown_p8_png.data, pw_sysroot_unknown_p8_png.size, - PW_CART_PNG_WIDTH, PW_CART_PNG_HEIGHT); - if (!image) { + if (!pw_cart_png_reset(png)) { goto error; } - bool ok = blit_image(image, png->texture); - SDL_free(image); - if (!ok) { - goto error; - } - - SDL_zeroa(png->rom); return png; error: @@ -247,17 +239,38 @@ cleanup: bool pw_cart_png_load(struct pw_cart_file *file, struct pw_cart_png *png) { if (!file) { - SDL_InvalidParamError("file"); - return false; + return SDL_InvalidParamError("file"); } if (!png) { - SDL_InvalidParamError("png"); - return false; + return SDL_InvalidParamError("png"); } return load_cart_png(file->path, png->texture, png->rom); } +bool pw_cart_png_reset(struct pw_cart_png *png) { + if (!png) { + return SDL_InvalidParamError("png"); + } + + union pw_png_pixel *image = pw_png_load( + pw_sysroot_unknown_p8_png.data, pw_sysroot_unknown_p8_png.size, + PW_CART_PNG_WIDTH, PW_CART_PNG_HEIGHT); + if (!image) { + SDL_LogCritical(0, "unexpected error parsing builtin unknown cart PNG"); + return false; + } + + bool ok = blit_image(image, png->texture); + SDL_free(image); + if (!ok) { + return false; + } + + SDL_zeroa(png->rom); + return true; +} + static struct pw_fs_node_buffer *embedded_cart(struct pw_fs_entry *e, char const **filename) { static char const cart_dir[] = "user_data/carts/"; |
