From 54f2f050b6a80c5eb0e058094cc78e4fab1046b5 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Wed, 7 Jun 2023 16:00:05 +0000 Subject: [PATCH] improve rom header handling --- src/menu/menu_main.c | 34 +++++++++++++++++----------------- src/menu/rom_database.h | 8 ++++---- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/menu/menu_main.c b/src/menu/menu_main.c index 67e3f942..ccb7abad 100644 --- a/src/menu/menu_main.c +++ b/src/menu/menu_main.c @@ -29,31 +29,31 @@ rom_header_t file_read_rom_header(char *path) { printf("Error loading rom file header\n"); } - rom_header_t rom_header; // malloc(size); + rom_header_t *rom_header = malloc(sizeof(rom_header_t)); fseek(fp, 0x10, SEEK_SET); - fread(&rom_header.checksum, sizeof(uint64_t), 1, fp); + fread(&(rom_header->checksum), sizeof(uint64_t), 1, fp); fseek(fp, 0x20, SEEK_SET); - fread(&rom_header.title, sizeof(rom_header.title), 1, fp); - //fseek(fp, 0x3b, SEEK_SET); - //fread(&media_type, sizeof(char), 1, fp); + fread(&(rom_header->title), sizeof(rom_header->title), 1, fp); + fseek(fp, 0x3b, SEEK_SET); + //fread(&(rom_header->metadata.media_type), sizeof(rom_header->metadata.media_type), 1, fp); fseek(fp, 0x3c, SEEK_SET); - fread(&rom_header.metadata.unique_identifier, sizeof(rom_header.metadata.unique_identifier), 1, fp); - //fseek(fp, 0x3e, SEEK_SET); - //fread(&destination_market, sizeof(char), 1, fp); - // fseek(fp, 0x3f, SEEK_SET); - // fread(&version, sizeof(uint8_t), 1, fp); + fread(&(rom_header->metadata.unique_identifier), sizeof(rom_header->metadata.unique_identifier), 1, fp); + fseek(fp, 0x3e, SEEK_SET); + //fread(&(rom_header->metadata.destination_market), sizeof(rom_header->metadata.destination_market), 1, fp); + fseek(fp, 0x3f, SEEK_SET); + //fread(&(rom_header->version), sizeof(rom_header->version), 1, fp); fclose(fp); - printf("ROM checksum: %llu\n", rom_header.checksum); - printf("ROM title: %s\n", rom_header.title); - //printf("ROM media type code: %s\n", (char *) &media_type); - printf("ROM unique id: %s\n", (char *) &rom_header.metadata.unique_identifier); - //printf("ROM dest market code: %s\n", (char *) &rom_header.metadata.destination_market); - //printf("ROM version: %hu\n", rom_header.version); + printf("ROM checksum: %llu\n", rom_header->checksum); + printf("ROM title: %s\n", rom_header->title); + printf("ROM media type: %c\n", rom_header->metadata.media_type); + printf("ROM unique id: %.2s\n", (char*)&(rom_header->metadata.unique_identifier)); + printf("ROM dest market: %c\n", rom_header->metadata.destination_market); + printf("ROM version: %hhu\n", rom_header->version); - return rom_header; + return *rom_header; } // FIXME: use newlib rather than fatfs to do this! diff --git a/src/menu/rom_database.h b/src/menu/rom_database.h index 75ab6846..c4956810 100644 --- a/src/menu/rom_database.h +++ b/src/menu/rom_database.h @@ -61,16 +61,16 @@ // } rom_destination_market_t; typedef struct { - // rom_media_type_t media_type; + uint8_t media_type; // rom_media_type_t uint16_t unique_identifier; - // char destination_market; //rom_destination_market_t + uint8_t destination_market; //rom_destination_market_t } rom_metadata_t; typedef struct { uint64_t checksum; - char title[14]; + uint8_t title[14]; rom_metadata_t metadata; - // uint8_t version; + uint8_t version; } rom_header_t;