improve rom header handling

This commit is contained in:
Robin Jones 2023-06-07 16:00:05 +00:00
parent eb24ed40eb
commit 54f2f050b6
2 changed files with 21 additions and 21 deletions

View File

@ -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!

View File

@ -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;