From 0bc38471b319a7b6368213f11a93ee26545d459d Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Wed, 12 Jul 2023 18:03:42 +0100 Subject: [PATCH] Add Expansion PAK information (#11) ## Description Adds Expansion PAK information to the menu ## Motivation and Context This is required by some ROM's and could cause a black screen upon boot. In future, this can be checked against to warn users. ## 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. - [ ] My change requires a change to the documentation. - [ ] 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 --- src/menu/rom_database.c | 49 ++++++++++++++++++++++++++++++++++++ src/menu/rom_database.h | 33 ++++++++++++++++-------- src/menu/views/file_info.c | 27 +++++++++++++++++++- src/menu/views/load.c | 27 ++++++++++++++++++-- src/menu/views/system_info.c | 5 ++++ 5 files changed, 127 insertions(+), 14 deletions(-) diff --git a/src/menu/rom_database.c b/src/menu/rom_database.c index cddc632b..76ddddce 100644 --- a/src/menu/rom_database.c +++ b/src/menu/rom_database.c @@ -168,3 +168,52 @@ uint8_t rom_db_match_save_type(rom_header_t rom_header) { return DB_SAVE_TYPE_NONE; //Nothing matched. } + +uint8_t rom_db_match_expansion_pak(rom_header_t rom_header) { + + static char *cart_ids[] = { + + // Expansion Pak Required + "DO", "DP", "ZS", // Donkey Kong, Dino Planet, Majoras Mask + + // Expansion Pak Suggested + "IJ", "PD", "SQ", // Indiana Jones, Perfect Dark, Starcraft + + // Expansion Pak Enhanced + "32", "F2", "MX", "NA", "Q2", "RE", "SD", "P3", "Y2", "TQ", // F-1 World Grand Prix II, Shadow Man, Excitebike 64, Rogue Squadron, Battle for Naboo, Quake 2, Resident Evil 2, etc. + + // Expansion Pak Known Faulty ( NTSC only ) + "SV", + + // Last entry + "!!" + + }; + static int exp_types[] = { + + // Expansion Pak Required + 0x01, 0x01, 0x01, + + // Expansion Pak Suggested + 0x02, 0x02, 0x02, + + // Expansion Pak Enhanced + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + + // Expansion Pak Known Faulty ( NTSC only ) + 0x04, + + // Last entry. + 0xff + }; + + for (int i = 0; exp_types[i] != 0xff; i++) { + + if (rom_header.metadata.unique_identifier == *(uint16_t *) cart_ids[i]) { + return exp_types[i]; + } + + } + + return DB_MEMORY_EXPANSION_NONE; +} diff --git a/src/menu/rom_database.h b/src/menu/rom_database.h index bf3d52c3..79f7ed2b 100644 --- a/src/menu/rom_database.h +++ b/src/menu/rom_database.h @@ -17,20 +17,30 @@ #define DB_SAVE_TYPE_INVALID 0xff typedef enum { - HB_SAVE_TYPE_NONE = 0x00, - HB_SAVE_TYPE_EEPROM_4K = 0x01, - HB_SAVE_TYPE_EEPROM_16K = 0x02, - HB_SAVE_TYPE_SRAM = 0x03, - HB_SAVE_TYPE_SRAM_BANKED = 0x04, - HB_SAVE_TYPE_FLASHRAM = 0x05, - HB_SAVE_TYPE_SRAM_128K = 0x06, + DB_MEMORY_EXPANSION_NONE = 0x00, + DB_MEMORY_EXPANSION_REQUIRED = 0x01, + DB_MEMORY_EXPANSION_SUGGESTED = 0x02, + DB_MEMORY_EXPANSION_ENHANCED = 0x03, + DB_MEMORY_EXPANSION_FAULTY = 0x04, +} rom_memorytype_t; + + +typedef enum { + HB_SAVE_TYPE_NONE = 0x00, + HB_SAVE_TYPE_EEPROM_4K = 0x01, + HB_SAVE_TYPE_EEPROM_16K = 0x02, + HB_SAVE_TYPE_SRAM = 0x03, + HB_SAVE_TYPE_SRAM_BANKED = 0x04, + HB_SAVE_TYPE_FLASHRAM = 0x05, + HB_SAVE_TYPE_SRAM_128K = 0x06, } homebrew_savetype_t; typedef enum { - ROM_BIG_ENDIAN = 2151092800U, - ROM_LITTLE_ENDIAN = 1074935680U, - ROM_MID_BIG_ENDIAN = 931151890U, - ROM_MID_LITTLE_ENDIAN = 306217015U + ROM_BIG_ENDIAN = 0x80371240, + ROM_LITTLE_ENDIAN = 0x40123780, + ROM_MID_BIG_ENDIAN = 0x37804012, + ROM_MID_LITTLE_ENDIAN = 0x12408037, + IPL_BIG_ENDIAN = 0x80270740, } rom_endian_type_t; //Rom Info @@ -96,5 +106,6 @@ typedef struct { rom_header_t file_read_rom_header(char *path); uint8_t rom_db_match_save_type(rom_header_t rom_header); +uint8_t rom_db_match_expansion_pak(rom_header_t rom_header); #endif diff --git a/src/menu/views/file_info.c b/src/menu/views/file_info.c index 4287db9d..07c9132d 100644 --- a/src/menu/views/file_info.c +++ b/src/menu/views/file_info.c @@ -14,6 +14,7 @@ static char *get_rom_endian_s (uint32_t endian) { switch (endian) { case ROM_BIG_ENDIAN: + case IPL_BIG_ENDIAN: return "Big (default)"; // expected break; case ROM_LITTLE_ENDIAN: @@ -85,6 +86,27 @@ static char *get_rom_savetype_s (uint8_t type) { } } +static char *get_rom_memorytype_s (uint8_t type) { + switch (type) + { + case DB_MEMORY_EXPANSION_REQUIRED: + return "Required"; + break; + case DB_MEMORY_EXPANSION_SUGGESTED: + return "Suggested"; + break; + case DB_MEMORY_EXPANSION_ENHANCED: + return "Enhanced"; + break; + case DB_MEMORY_EXPANSION_FAULTY: + return "May have issues"; + break; + default: + return "Not Required"; + break; + } +} + static char *get_file_type_s (void) { // TODO: should be at least a switch statement! if (str_endswith(info.fname, ".z64", false) || @@ -212,7 +234,10 @@ static void draw (menu_t *menu, surface_t *d) { uint8_t save_type = rom_db_match_save_type(temp_header); sprintf(str_buffer,"Save Type: %s\n", get_rom_savetype_s(save_type)); graphics_draw_text(d, x_start_position, y_position += font_vertical_pixels, str_buffer); - + y_position += (font_vertical_pixels * 2); + uint8_t memory_type = rom_db_match_expansion_pak(temp_header); + sprintf(str_buffer,"Expansion PAK: %s\n", get_rom_memorytype_s(memory_type)); + graphics_draw_text(d, x_start_position, y_position += font_vertical_pixels, str_buffer); //menu_fileinfo_draw_n64_rom_info(d); } diff --git a/src/menu/views/load.c b/src/menu/views/load.c index c6f84228..4613e910 100644 --- a/src/menu/views/load.c +++ b/src/menu/views/load.c @@ -14,6 +14,7 @@ static rom_header_t rom_header; static char *format_rom_endian (uint32_t endian) { switch (endian) { case ROM_BIG_ENDIAN: + case IPL_BIG_ENDIAN: return "Big (native)"; case ROM_LITTLE_ENDIAN: return "Little (unsupported)"; @@ -31,9 +32,9 @@ static char *format_rom_media_type (uint8_t media_type) { case N64_DISK: return "D - Disk"; case N64_CART_EXPANDABLE: - return "C - Cart Expandable"; + return "C - Cartridge (Expandable)"; case N64_DISK_EXPANDABLE: - return "E - Disk Expandable"; + return "E - Disk (Expandable)"; case N64_ALECK64: return "Z - Aleck64"; default: @@ -64,6 +65,27 @@ static char *format_rom_save_type (uint8_t save_type) { } } +static char *format_rom_memory_type (uint8_t memory_type) { + switch (memory_type) + { + case DB_MEMORY_EXPANSION_REQUIRED: + return "Required"; + break; + case DB_MEMORY_EXPANSION_SUGGESTED: + return "Suggested"; + break; + case DB_MEMORY_EXPANSION_ENHANCED: + return "Enhanced"; + break; + case DB_MEMORY_EXPANSION_FAULTY: + return "May have issues"; + break; + default: + return "Not required"; + break; + } +} + static flashcart_save_type_t convert_save_type (uint8_t save_type) { switch (save_type) { case DB_SAVE_TYPE_EEPROM_4K: @@ -162,6 +184,7 @@ static void draw (menu_t *menu, surface_t *d) { text_y += fragment_textf(text_x, text_y, "Version: %hhu", rom_header.version); text_y += fragment_textf(text_x, text_y, "Checksum: 0x%016llX", rom_header.checksum); text_y += fragment_textf(text_x, text_y, "ROM endian: %s", format_rom_endian(rom_header.endian)); + text_y += fragment_textf(text_x, text_y, "Expansion PAK: %s", format_rom_memory_type(rom_db_match_expansion_pak(rom_header))); // Actions bar text_y = layout->actions_y + layout->offset_text_y; diff --git a/src/menu/views/system_info.c b/src/menu/views/system_info.c index 115aa9c8..5b802f29 100644 --- a/src/menu/views/system_info.c +++ b/src/menu/views/system_info.c @@ -51,6 +51,11 @@ static void draw (menu_t *menu, surface_t *d) { vertical_position += font_vertical_pixels; + sprintf(str_buffer, "Expansion PAK is %sinserted\n", is_memory_expanded() ? "" : "not " ); + graphics_draw_text(d, horizontal_start_position, vertical_position += font_vertical_pixels, str_buffer); + + vertical_position += font_vertical_pixels; + int controllers = get_controllers_present(); sprintf(str_buffer, "JoyPad 1 is %sconnected\n", (controllers & CONTROLLER_1_INSERTED) ? "" : "not " );