From c36bd4197e5161c0af19df7a2306c445a291c351 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Sun, 17 Sep 2023 09:38:42 +0100 Subject: [PATCH] Add ability for 3 letter ID for boxart (#47) ## Description Allows boxart to be 3 letters by checking the "media type" if required. It continues to be compatible with 2 letters. Also update sodium64 rom address (changed in https://github.com/Hydr8gon/sodium64/commit/d006af487073cb16be1cd8e230ff30bf722500b6). ## Motivation and Context Fixes an issue for at least `DZ` which shares the same ID between Dezaemon 3D for the 64DD and Duke Nukem: Zero Hour Cartridge. ## How Has This Been Tested? ## Screenshots ## Types of changes - [x] Improvement (non-breaking change that adds a new feature) - [ ] Bug fix (fixes an issue) - [ ] Breaking change (breaking change) - [ ] Config and build (change in the configuration and build system, has no impact on code or features) ## Checklist: - [x] My code follows the code style of this project. - [x] My change requires a change to the documentation. - [x] I have updated the documentation accordingly. - [ ] I have added tests to cover my changes. - [ ] All new and existing tests passed. Signed-off-by: GITHUB_USER --- README.md | 6 ++++-- src/menu/cart_load.c | 2 +- src/menu/components.h | 2 +- src/menu/components/boxart.c | 11 ++++++++--- src/menu/views/load_rom.c | 2 +- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 0a2e9978..ab278946 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,10 @@ The aim is to replace [Altra64](https://github.com/networkfusion/altra64) and [E #### ROM Boxart To use boxart, you need to place png files of size 158x112 in the folder `/menu/boxart` on the SD card. -Each file must be named according to the 2 letter ROM ID. e.g. for goldeneye, this would be `GE.png`. -A known set of PNG files can be downloaded [here](https://mega.nz/file/6cNGwSqI#8X5ukb65n3YMlGaUtSOGXkKo9HxVnnMOgqn94Epcr7w). +Each file must be named according to the 2 letter ROM ID, or 3 letter ROM ID including media type. +i.e. for GoldenEye 2 letters, this would be `GE.png`. +i.e. for GoldenEye 3 letters, this would be `NGE.png`. +A known set of PNG files using 2 letter ID's can be downloaded [here](https://mega.nz/file/6cNGwSqI#8X5ukb65n3YMlGaUtSOGXkKo9HxVnnMOgqn94Epcr7w). #### Emulator support Emulators should be added to the `/emulators` directory on the SD card. diff --git a/src/menu/cart_load.c b/src/menu/cart_load.c index 366ce259..62f4bc73 100644 --- a/src/menu/cart_load.c +++ b/src/menu/cart_load.c @@ -91,7 +91,6 @@ cart_load_err_t cart_load_emulator (menu_t *menu, cart_load_emu_type_t emu_type, case CART_LOAD_EMU_TYPE_SNES: path_push(path, "sodium64.z64"); save_type = FLASHCART_SAVE_TYPE_SRAM; - emulated_rom_offset = 0x104000; break; case CART_LOAD_EMU_TYPE_GAMEBOY: path_push(path, "gb.v64"); @@ -124,6 +123,7 @@ cart_load_err_t cart_load_emulator (menu_t *menu, cart_load_emu_type_t emu_type, switch (emu_type) { case CART_LOAD_EMU_TYPE_SNES: + // The emulator expects the header to be removed from the ROM being uploaded. emulated_file_offset = ((file_get_size(path_get(path)) & 0x3FF) == 0x200) ? 0x200 : 0; break; default: diff --git a/src/menu/components.h b/src/menu/components.h index 858b9763..10a8437d 100644 --- a/src/menu/components.h +++ b/src/menu/components.h @@ -59,7 +59,7 @@ typedef struct { surface_t *image; } component_boxart_t; -component_boxart_t *component_boxart_init (uint16_t id); +component_boxart_t *component_boxart_init (uint8_t media_type, uint16_t id); void component_boxart_free (component_boxart_t *b); void component_boxart_draw (component_boxart_t *b); diff --git a/src/menu/components/boxart.c b/src/menu/components/boxart.c index 411e8bbb..6419c1cf 100644 --- a/src/menu/components/boxart.c +++ b/src/menu/components/boxart.c @@ -4,6 +4,7 @@ #include "../path.h" #include "../png_decoder.h" #include "constants.h" +#include "utils/fs.h" #define BOXART_DIRECTORY "sd:/menu/boxart" @@ -16,14 +17,18 @@ static void png_decoder_callback (png_err_t err, surface_t *decoded_image, void } -component_boxart_t *component_boxart_init (uint16_t id) { +component_boxart_t *component_boxart_init (uint8_t media_type, uint16_t id) { component_boxart_t *b = calloc(1, sizeof(component_boxart_t)); if (b) { b->loading = true; + char *path = alloca(strlen(BOXART_DIRECTORY) + 1 + 7 + 1); // allocate for the largest path. + sprintf(path, "%s/%c%c%c.png", BOXART_DIRECTORY, (media_type & 0xFF), ((id >> 8) & 0xFF), (id & 0xFF)); - char *path = alloca(strlen(BOXART_DIRECTORY) + 1 + 6 + 1); - sprintf(path, "%s/%c%c.png", BOXART_DIRECTORY, ((id >> 8) & 0xFF), (id & 0xFF)); + // if the file does not exist, also check for just the id. + if (!file_exists(path)) { + sprintf(path, "%s/%c%c.png", BOXART_DIRECTORY, ((id >> 8) & 0xFF), (id & 0xFF)); + } if (png_decoder_start(path, BOXART_WIDTH, BOXART_HEIGHT, png_decoder_callback, b) != PNG_OK) { free(b); diff --git a/src/menu/views/load_rom.c b/src/menu/views/load_rom.c index d5828c1d..55d2c8b3 100644 --- a/src/menu/views/load_rom.c +++ b/src/menu/views/load_rom.c @@ -250,7 +250,7 @@ void view_load_rom_init (menu_t *menu) { rom_header = file_read_rom_header(path_get(path)); - boxart = component_boxart_init(rom_header.metadata.unique_identifier); + boxart = component_boxart_init(rom_header.metadata.media_type, rom_header.metadata.unique_identifier); path_free(path); }