From afb7a513b196e5a992bc0f9ebc0424d4089a8830 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Tue, 6 Jun 2023 16:54:47 +0100 Subject: [PATCH] Remove deprecated display things. Start rom information handling. --- src/main.c | 10 ++++++++-- src/menu/menu_fileinfo.c | 8 ++++---- src/menu/menu_info.c | 6 +++--- src/menu/menu_main.c | 12 +++++++++--- src/menu/rom_database.c | 22 ++++++++++++---------- src/menu/rom_database.h | 26 +++++++++++++++++++++++++- 6 files changed, 61 insertions(+), 23 deletions(-) diff --git a/src/main.c b/src/main.c index dbec27da..5d438566 100644 --- a/src/main.c +++ b/src/main.c @@ -17,11 +17,17 @@ static void init (void) { assertf(error != FLASHCART_ERROR_OUTDATED, "Outdated flashcart firmware"); assertf(error != FLASHCART_ERROR_UNSUPPORTED, "Unsupported flashcart"); assertf(error == FLASHCART_OK, "Unknown error while initializing flashcart"); - - display_init(RESOLUTION_512x240, DEPTH_16_BPP, 3, GAMMA_NONE, ANTIALIAS_RESAMPLE); + + controller_init(); + + display_close(); + display_init(RESOLUTION_640x240, DEPTH_16_BPP, 3, GAMMA_NONE, ANTIALIAS_RESAMPLE); + graphics_set_color(0xFFFFFFFF, 0x00000000); + graphics_set_default_font(); } static void deinit (void) { + display_close(); flashcart_deinit(); rdpq_close(); rspq_close(); diff --git a/src/menu/menu_fileinfo.c b/src/menu/menu_fileinfo.c index e6961277..fe507621 100644 --- a/src/menu/menu_fileinfo.c +++ b/src/menu/menu_fileinfo.c @@ -33,14 +33,14 @@ static char *get_file_type(FILINFO current_fileinfo) { } } -void menu_fileinfo_draw_header(display_context_t disp) { +void menu_fileinfo_draw_header(surface_t *disp) { graphics_draw_text(disp, (disp->width / 2) - 64, vertical_start_position, "FILE INFORMATION"); // centre = numchars * font_horizontal_pixels / 2 graphics_draw_line(disp,0,30,disp->width,30, 0xff); } -void menu_fileinfo_draw_footer(display_context_t disp) { +void menu_fileinfo_draw_footer(surface_t *disp) { graphics_draw_line(disp,0,disp->height - overscan_vertical_pixels - font_vertical_pixels,disp->width,disp->height - overscan_vertical_pixels - font_vertical_pixels, 0xff); graphics_draw_text(disp, (disp->width / 2) - 80,disp->height - overscan_vertical_pixels, "Press (B) to return!"); // centre = numchars * font_horizontal_pixels / 2 @@ -51,7 +51,7 @@ void menu_fileinfo(FILINFO current_fileinfo) { char str_buffer[1024]; - display_context_t disp = display_try_get(); + surface_t *disp = display_try_get(); graphics_fill_screen(disp, 0x00); menu_fileinfo_draw_header(disp); @@ -69,7 +69,7 @@ void menu_fileinfo(FILINFO current_fileinfo) { graphics_draw_text(disp, horizontal_start_position, vertical_position, "Attributes:"); sprintf(str_buffer, "%s%s%s%s%s\n", ((current_fileinfo.fattrib & AM_DIR) ? "Directory" : "File"), - ((current_fileinfo.fattrib & AM_RDO) ? " | Readonly" : ""), + ((current_fileinfo.fattrib & AM_RDO) ? " | ReadOnly" : ""), ((current_fileinfo.fattrib & AM_SYS) ? " | System" : ""), ((current_fileinfo.fattrib & AM_ARC) ? " | Archive" : ""), ((current_fileinfo.fattrib & AM_HID) ? " | Hidden" : "") diff --git a/src/menu/menu_info.c b/src/menu/menu_info.c index c77bf41b..b1499917 100644 --- a/src/menu/menu_info.c +++ b/src/menu/menu_info.c @@ -2,14 +2,14 @@ #include "menu_info.h" #include "menu_res_setup.h" -void menu_info_draw_header(display_context_t disp) { +void menu_info_draw_header(surface_t *disp) { graphics_draw_text(disp, (disp->width / 2) - 64, vertical_start_position, "MENU INFORMATION"); // centre = numchars * font_horizontal_pixels / 2 graphics_draw_line(disp,0,30,disp->width,30, 0xff); } -void menu_info_draw_footer(display_context_t disp) { +void menu_info_draw_footer(surface_t *disp) { graphics_draw_line(disp,0,disp->height - overscan_vertical_pixels - font_vertical_pixels,disp->width,disp->height - overscan_vertical_pixels - font_vertical_pixels, 0xff); graphics_draw_text(disp, (disp->width / 2) - 80,disp->height - overscan_vertical_pixels, "Press (B) to return!"); // centre = numchars * font_horizontal_pixels / 2 @@ -18,7 +18,7 @@ void menu_info_draw_footer(display_context_t disp) { void menu_info(void) { - display_context_t disp = display_try_get(); + surface_t *disp = display_try_get(); graphics_fill_screen(disp, 0x00); menu_info_draw_header(disp); diff --git a/src/menu/menu_main.c b/src/menu/menu_main.c index 7d4abe20..c2434e59 100644 --- a/src/menu/menu_main.c +++ b/src/menu/menu_main.c @@ -98,12 +98,15 @@ void menu_main_refresh (char *dir_path) { void menu_main_init (settings_t *settings) { // TODO: implement nice user interface here + surface_t *disp = display_try_get(); + graphics_draw_line(disp,0,30,disp->width,30, 0xff); + console_init(); console_set_debug(true); console_clear(); - controller_init(); + char *current_dir = settings->last_state.current_directory; char *last_dir = current_dir; @@ -150,13 +153,16 @@ void menu_main_init (settings_t *settings) { if (str_endswith(current_fileinfo.fname, ".z64") || str_endswith(current_fileinfo.fname, ".n64") || str_endswith(current_fileinfo.fname, ".v64") || str_endswith(current_fileinfo.fname, ".rom")) { printf("Loading N64 ROM type...\n"); printf("%s\n", current_fileinfo.fname); - assertf(flashcart_load_rom(current_fileinfo.fname) == FLASHCART_OK, "ROM load error"); + // FIXME: we now need the header ID and CRC HI... - // ed64_dma_read_rom(buff, 0, 1); + // f_read // crc_high = (buff[0x10] << 24) | (buff[0x11] << 16) | (buff[0x12] << 8) | (buff[0x13] << 0); // crc_low = (buff[0x14] << 24) | (buff[0x15] << 16) | (buff[0x16] << 8) | (buff[0x17] << 0); // id = (buff[0x3c] << 8) | buff[0x3d]; //assertf(flashcart_load_save("current_filename.sav", rom_db_match_save_type(id, crc), false) == FLASHCART_OK, "ROM load save error"); + + assertf(flashcart_load_rom(current_fileinfo.fname) == FLASHCART_OK, "ROM load error"); + break; //required! } else { diff --git a/src/menu/rom_database.c b/src/menu/rom_database.c index 7d2af14b..88f45b62 100644 --- a/src/menu/rom_database.c +++ b/src/menu/rom_database.c @@ -3,24 +3,26 @@ // TODO: make sure this can also handle an external input file. -uint8_t rom_db_match_save_type(uint16_t id, uint32_t crc) { //FIXME: the ID should be 4 chars (uint32) +uint8_t rom_db_match_save_type(rom_header_t rom_header) { // These are ordered to ensure they are handled correctly... // First: Match by the `ED` Developer ID // TODO: if appropriate this can be improved with other unused codes... e.g. | `AA` | `ZZ` - if (id == *(uint16_t *)"ED") { + if (rom_header.game_code.unique_code == *(uint16_t *)"ED") { + // FIXME: should probably just return the specified save type. return DB_SAVE_TYPE_CART_SPECIFIED; } // Second: Match the default entries for crc_high. - if (crc == 0xbcb1f89f)return DB_SAVE_TYPE_EEPROM_4K; // kirby v1.3 - if (crc == 0x46039fb4)return DB_SAVE_TYPE_EEPROM_16K; // kirby U - if (crc == 0x0d93ba11)return DB_SAVE_TYPE_EEPROM_16K; // kirby U - if (crc == 0xce84793d)return DB_SAVE_TYPE_SRAM; // donkey kong f2 - if (crc == 0x4cbc3b56)return DB_SAVE_TYPE_SRAM; // DMTJ 64DD game - if (crc == 0x0dd4abab)return DB_SAVE_TYPE_EEPROM_16K; // DK Retail kiosk demo (shares ID with Dinosaur planet, but hacks are unlikely)! - if (crc == 0xeb85ebc9)return DB_SAVE_TYPE_FLASHRAM; // DOUBUTSU BANCHOU (ANIMAL LEADER, Cubivore) - Contains no game ID + // FIXME: use full check code, or pad. + if (rom_header.check_code == 0xbcb1f89f)return DB_SAVE_TYPE_EEPROM_4K; // kirby v1.3 + if (rom_header.check_code == 0x46039fb4)return DB_SAVE_TYPE_EEPROM_16K; // kirby U + if (rom_header.check_code == 0x0d93ba11)return DB_SAVE_TYPE_EEPROM_16K; // kirby U + if (rom_header.check_code == 0xce84793d)return DB_SAVE_TYPE_SRAM; // donkey kong f2 + if (rom_header.check_code == 0x4cbc3b56)return DB_SAVE_TYPE_SRAM; // DMTJ 64DD game + if (rom_header.check_code == 0x0dd4abab)return DB_SAVE_TYPE_EEPROM_16K; // DK Retail kiosk demo (shares ID with Dinosaur planet, but hacks are unlikely)! + if (rom_header.check_code == 0xeb85ebc9)return DB_SAVE_TYPE_FLASHRAM; // DOUBUTSU BANCHOU (ANIMAL LEADER, Cubivore) - Contains no game ID // FIXME: we need to take into account the Category (first char) and the Region code (last char) before a general match of the ID. @@ -80,7 +82,7 @@ uint8_t rom_db_match_save_type(uint16_t id, uint32_t crc) { //FIXME: the ID sho for (int i = 0; save_types[i] != 0xff; i++) { - if (id == *(uint16_t *) cart_ids[i]) { + if (rom_header.game_code.unique_code == *(uint16_t *) cart_ids[i]) { i = save_types[i]; // i = i == 1 ? DB_SAVE_TYPE_EEPROM_4K : // i == 2 ? DB_SAVE_TYPE_EEPROM_16K : diff --git a/src/menu/rom_database.h b/src/menu/rom_database.h index 2194b6c3..44e658c7 100644 --- a/src/menu/rom_database.h +++ b/src/menu/rom_database.h @@ -11,4 +11,28 @@ #define DB_SAVE_TYPE_FLASHRAM 0x06 #define DB_SAVE_TYPE_CART_SPECIFIED 0x0f -uint8_t rom_db_match_save_type(uint16_t id, uint32_t crc); + +//Rom Info +// CheckCode 0x10, 8 bytes (sometimes refered to as CRC Hi and CRC Lo) +// GameTitle 0x20, 14 bytes +// GameCode -> +// CategoryCode 0x3b +// UniqueCode 0x3c and 0x3d +// DestinationCode 0x3e +// RomVersion 0x3f + +typedef struct { + char category_code; + uint16_t unique_code; + char destination_code; +} game_code_t; + +typedef struct { + uint64_t check_code; + char game_title[14]; + game_code_t game_code; + char version; +} rom_header_t; + + +uint8_t rom_db_match_save_type(rom_header_t rom_header);