Remove deprecated display things.

Start rom information handling.
This commit is contained in:
Robin Jones 2023-06-06 16:54:47 +01:00
parent 8b58e5c62d
commit afb7a513b1
6 changed files with 61 additions and 23 deletions

View File

@ -18,10 +18,16 @@ static void init (void) {
assertf(error != FLASHCART_ERROR_UNSUPPORTED, "Unsupported flashcart"); assertf(error != FLASHCART_ERROR_UNSUPPORTED, "Unsupported flashcart");
assertf(error == FLASHCART_OK, "Unknown error while initializing 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) { static void deinit (void) {
display_close();
flashcart_deinit(); flashcart_deinit();
rdpq_close(); rdpq_close();
rspq_close(); rspq_close();

View File

@ -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_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); 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_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 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]; char str_buffer[1024];
display_context_t disp = display_try_get(); surface_t *disp = display_try_get();
graphics_fill_screen(disp, 0x00); graphics_fill_screen(disp, 0x00);
menu_fileinfo_draw_header(disp); 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:"); graphics_draw_text(disp, horizontal_start_position, vertical_position, "Attributes:");
sprintf(str_buffer, "%s%s%s%s%s\n", sprintf(str_buffer, "%s%s%s%s%s\n",
((current_fileinfo.fattrib & AM_DIR) ? "Directory" : "File"), ((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_SYS) ? " | System" : ""),
((current_fileinfo.fattrib & AM_ARC) ? " | Archive" : ""), ((current_fileinfo.fattrib & AM_ARC) ? " | Archive" : ""),
((current_fileinfo.fattrib & AM_HID) ? " | Hidden" : "") ((current_fileinfo.fattrib & AM_HID) ? " | Hidden" : "")

View File

@ -2,14 +2,14 @@
#include "menu_info.h" #include "menu_info.h"
#include "menu_res_setup.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_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); 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_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 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) { void menu_info(void) {
display_context_t disp = display_try_get(); surface_t *disp = display_try_get();
graphics_fill_screen(disp, 0x00); graphics_fill_screen(disp, 0x00);
menu_info_draw_header(disp); menu_info_draw_header(disp);

View File

@ -98,12 +98,15 @@ void menu_main_refresh (char *dir_path) {
void menu_main_init (settings_t *settings) { void menu_main_init (settings_t *settings) {
// TODO: implement nice user interface here // 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_init();
console_set_debug(true); console_set_debug(true);
console_clear(); console_clear();
controller_init();
char *current_dir = settings->last_state.current_directory; char *current_dir = settings->last_state.current_directory;
char *last_dir = current_dir; 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")) { 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("Loading N64 ROM type...\n");
printf("%s\n", current_fileinfo.fname); 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... // 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_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); // crc_low = (buff[0x14] << 24) | (buff[0x15] << 16) | (buff[0x16] << 8) | (buff[0x17] << 0);
// id = (buff[0x3c] << 8) | buff[0x3d]; // 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_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! break; //required!
} }
else { else {

View File

@ -3,24 +3,26 @@
// TODO: make sure this can also handle an external input file. // 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... // These are ordered to ensure they are handled correctly...
// First: Match by the `ED` Developer ID // First: Match by the `ED` Developer ID
// TODO: if appropriate this can be improved with other unused codes... e.g. | `AA` | `ZZ` // 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; return DB_SAVE_TYPE_CART_SPECIFIED;
} }
// Second: Match the default entries for crc_high. // Second: Match the default entries for crc_high.
if (crc == 0xbcb1f89f)return DB_SAVE_TYPE_EEPROM_4K; // kirby v1.3 // FIXME: use full check code, or pad.
if (crc == 0x46039fb4)return DB_SAVE_TYPE_EEPROM_16K; // kirby U if (rom_header.check_code == 0xbcb1f89f)return DB_SAVE_TYPE_EEPROM_4K; // kirby v1.3
if (crc == 0x0d93ba11)return DB_SAVE_TYPE_EEPROM_16K; // kirby U if (rom_header.check_code == 0x46039fb4)return DB_SAVE_TYPE_EEPROM_16K; // kirby U
if (crc == 0xce84793d)return DB_SAVE_TYPE_SRAM; // donkey kong f2 if (rom_header.check_code == 0x0d93ba11)return DB_SAVE_TYPE_EEPROM_16K; // kirby U
if (crc == 0x4cbc3b56)return DB_SAVE_TYPE_SRAM; // DMTJ 64DD game if (rom_header.check_code == 0xce84793d)return DB_SAVE_TYPE_SRAM; // donkey kong f2
if (crc == 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 == 0x4cbc3b56)return DB_SAVE_TYPE_SRAM; // DMTJ 64DD game
if (crc == 0xeb85ebc9)return DB_SAVE_TYPE_FLASHRAM; // DOUBUTSU BANCHOU (ANIMAL LEADER, Cubivore) - Contains no game ID 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. // 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++) { 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 = save_types[i];
// i = i == 1 ? DB_SAVE_TYPE_EEPROM_4K : // i = i == 1 ? DB_SAVE_TYPE_EEPROM_4K :
// i == 2 ? DB_SAVE_TYPE_EEPROM_16K : // i == 2 ? DB_SAVE_TYPE_EEPROM_16K :

View File

@ -11,4 +11,28 @@
#define DB_SAVE_TYPE_FLASHRAM 0x06 #define DB_SAVE_TYPE_FLASHRAM 0x06
#define DB_SAVE_TYPE_CART_SPECIFIED 0x0f #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);