Add Expansion PAK information (#11)

<!--- Provide a general summary of your changes in the Title above -->

## Description
<!--- Describe your changes in detail -->
Adds Expansion PAK information to the menu

## Motivation and Context
<!--- What does this sample do? What problem does it solve? -->
<!--- If it fixes/closes/resolves an open issue, please link to the
issue here -->
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?
<!-- (if applicable) -->
<!--- Please describe in detail how you tested your sample/changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->

## Screenshots
<!-- (if appropriate): -->

## Types of changes
<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [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:
<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
- [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.

<!--- It would be nice if you could sign off your contribution by
replacing the name with your GitHub user name and GitHub email contact.
-->
Signed-off-by: GITHUB_USER <GITHUB_USER_EMAIL>
This commit is contained in:
Robin Jones 2023-07-12 18:03:42 +01:00 committed by GitHub
parent a7c7373d9f
commit 0bc38471b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 127 additions and 14 deletions

View File

@ -168,3 +168,52 @@ uint8_t rom_db_match_save_type(rom_header_t rom_header) {
return DB_SAVE_TYPE_NONE; //Nothing matched. 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;
}

View File

@ -17,20 +17,30 @@
#define DB_SAVE_TYPE_INVALID 0xff #define DB_SAVE_TYPE_INVALID 0xff
typedef enum { typedef enum {
HB_SAVE_TYPE_NONE = 0x00, DB_MEMORY_EXPANSION_NONE = 0x00,
HB_SAVE_TYPE_EEPROM_4K = 0x01, DB_MEMORY_EXPANSION_REQUIRED = 0x01,
HB_SAVE_TYPE_EEPROM_16K = 0x02, DB_MEMORY_EXPANSION_SUGGESTED = 0x02,
HB_SAVE_TYPE_SRAM = 0x03, DB_MEMORY_EXPANSION_ENHANCED = 0x03,
HB_SAVE_TYPE_SRAM_BANKED = 0x04, DB_MEMORY_EXPANSION_FAULTY = 0x04,
HB_SAVE_TYPE_FLASHRAM = 0x05, } rom_memorytype_t;
HB_SAVE_TYPE_SRAM_128K = 0x06,
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; } homebrew_savetype_t;
typedef enum { typedef enum {
ROM_BIG_ENDIAN = 2151092800U, ROM_BIG_ENDIAN = 0x80371240,
ROM_LITTLE_ENDIAN = 1074935680U, ROM_LITTLE_ENDIAN = 0x40123780,
ROM_MID_BIG_ENDIAN = 931151890U, ROM_MID_BIG_ENDIAN = 0x37804012,
ROM_MID_LITTLE_ENDIAN = 306217015U ROM_MID_LITTLE_ENDIAN = 0x12408037,
IPL_BIG_ENDIAN = 0x80270740,
} rom_endian_type_t; } rom_endian_type_t;
//Rom Info //Rom Info
@ -96,5 +106,6 @@ typedef struct {
rom_header_t file_read_rom_header(char *path); 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_save_type(rom_header_t rom_header);
uint8_t rom_db_match_expansion_pak(rom_header_t rom_header);
#endif #endif

View File

@ -14,6 +14,7 @@ static char *get_rom_endian_s (uint32_t endian) {
switch (endian) switch (endian)
{ {
case ROM_BIG_ENDIAN: case ROM_BIG_ENDIAN:
case IPL_BIG_ENDIAN:
return "Big (default)"; // expected return "Big (default)"; // expected
break; break;
case ROM_LITTLE_ENDIAN: 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) { static char *get_file_type_s (void) {
// TODO: should be at least a switch statement! // TODO: should be at least a switch statement!
if (str_endswith(info.fname, ".z64", false) || 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); uint8_t save_type = rom_db_match_save_type(temp_header);
sprintf(str_buffer,"Save Type: %s\n", get_rom_savetype_s(save_type)); 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); 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); //menu_fileinfo_draw_n64_rom_info(d);
} }

View File

@ -14,6 +14,7 @@ static rom_header_t rom_header;
static char *format_rom_endian (uint32_t endian) { static char *format_rom_endian (uint32_t endian) {
switch (endian) { switch (endian) {
case ROM_BIG_ENDIAN: case ROM_BIG_ENDIAN:
case IPL_BIG_ENDIAN:
return "Big (native)"; return "Big (native)";
case ROM_LITTLE_ENDIAN: case ROM_LITTLE_ENDIAN:
return "Little (unsupported)"; return "Little (unsupported)";
@ -31,9 +32,9 @@ static char *format_rom_media_type (uint8_t media_type) {
case N64_DISK: case N64_DISK:
return "D - Disk"; return "D - Disk";
case N64_CART_EXPANDABLE: case N64_CART_EXPANDABLE:
return "C - Cart Expandable"; return "C - Cartridge (Expandable)";
case N64_DISK_EXPANDABLE: case N64_DISK_EXPANDABLE:
return "E - Disk Expandable"; return "E - Disk (Expandable)";
case N64_ALECK64: case N64_ALECK64:
return "Z - Aleck64"; return "Z - Aleck64";
default: 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) { static flashcart_save_type_t convert_save_type (uint8_t save_type) {
switch (save_type) { switch (save_type) {
case DB_SAVE_TYPE_EEPROM_4K: 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, "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, "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, "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 // Actions bar
text_y = layout->actions_y + layout->offset_text_y; text_y = layout->actions_y + layout->offset_text_y;

View File

@ -51,6 +51,11 @@ static void draw (menu_t *menu, surface_t *d) {
vertical_position += font_vertical_pixels; 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(); int controllers = get_controllers_present();
sprintf(str_buffer, "JoyPad 1 is %sconnected\n", (controllers & CONTROLLER_1_INSERTED) ? "" : "not " ); sprintf(str_buffer, "JoyPad 1 is %sconnected\n", (controllers & CONTROLLER_1_INSERTED) ? "" : "not " );