amex/ds.c: Read optional region code

This commit is contained in:
Tau 2019-03-04 18:38:37 -05:00
parent bc297b2480
commit 72f28e40b0

View File

@ -37,7 +37,8 @@ enum {
struct ds_eeprom { struct ds_eeprom {
uint32_t crc32; uint32_t crc32;
uint8_t unk_04[5]; uint8_t unk_04[4];
uint8_t region;
char serial_no[17]; char serial_no[17];
uint8_t unk_1A[6]; uint8_t unk_1A[6];
}; };
@ -62,36 +63,22 @@ static HANDLE ds_fd;
HRESULT ds_hook_init(void) HRESULT ds_hook_init(void)
{ {
HRESULT hr; HRESULT hr;
int region;
FILE *f; FILE *f;
char c;
int i;
region = 0x01; /* Japan; use this default if ds.txt read fails */
memset(&ds_eeprom, 0, sizeof(ds_eeprom)); memset(&ds_eeprom, 0, sizeof(ds_eeprom));
f = fopen(ds_serial_file, "r"); f = fopen(ds_serial_file, "r");
if (f != NULL) { if (f != NULL) {
i = 0; fscanf(f, "%16s %x", ds_eeprom.serial_no, &region);
for (;;) {
if (feof(f) || i >= sizeof(ds_eeprom.serial_no) - 1) {
break;
}
c = getc(f);
if (isspace(c)) {
break;
}
ds_eeprom.serial_no[i++] = c;
}
fclose(f); fclose(f);
} else { } else {
dprintf("Failed to open %s\n", ds_serial_file); dprintf("Failed to open %s\n", ds_serial_file);
} }
ds_eeprom.region = region;
ds_eeprom.crc32 = crc32(&ds_eeprom.unk_04, 0x1C, 0); ds_eeprom.crc32 = crc32(&ds_eeprom.unk_04, 0x1C, 0);
hr = iohook_push_handler(ds_handle_irp); hr = iohook_push_handler(ds_handle_irp);