Enable Naomi eeprom reading and writing

This commit is contained in:
Flyinghead 2018-07-09 16:24:37 +02:00
parent 18b2d8273f
commit 6df46b1d83
2 changed files with 29 additions and 11 deletions

View File

@ -3,6 +3,7 @@
#include "maple_helper.h" #include "maple_helper.h"
#include "maple_devs.h" #include "maple_devs.h"
#include "maple_cfg.h" #include "maple_cfg.h"
#include "cfg/cfg.h"
#include <time.h> #include <time.h>
#if _ANDROID #if _ANDROID
@ -989,6 +990,23 @@ void printState(u32 cmd, u32* buffer_in, u32 buffer_in_len)
} }
} }
#ifdef SAVE_EPPROM
static string get_eeprom_file_path()
{
char image_path[512];
cfgLoadStr("config", "image", image_path, "naomi_boot.bin");
string eeprom_file = image_path;
size_t lastindex = eeprom_file.find_last_of("/");
if (lastindex != npos)
eeprom_file = eeprom_file.substr(lastindex + 1);
lastindex = eeprom_file.find_last_of(".");
if (lastindex != npos)
eeprom_file = eeprom_file.substr(0, lastindex);
eeprom_file = eeprom_file + ".eeprom";
return get_writable_data_path("/data/") + eeprom_file;
}
#endif
/* /*
Sega Dreamcast Controller Sega Dreamcast Controller
No error checking of any kind, but works just fine No error checking of any kind, but works just fine
@ -1295,16 +1313,16 @@ struct maple_naomi_jamma : maple_sega_controller
memcpy(EEPROM + address, buffer_in_b + 4, size); memcpy(EEPROM + address, buffer_in_b + 4, size);
#ifdef SAVE_EPPROM #ifdef SAVE_EPPROM
wchar eeprom_file[512]; string eeprom_file = get_eeprom_file_path();
host.ConfigLoadStr(L"emu", L"gamefile", eeprom_file, L""); FILE* f = fopen(eeprom_file.c_str(), "wb");
wcscat(eeprom_file, L".eeprom");
FILE* f = _wfopen(eeprom_file, L"wb");
if (f) if (f)
{ {
fwrite(EEPROM, 1, 0x80, f); fwrite(EEPROM, 1, 0x80, f);
fclose(f); fclose(f);
wprintf(L"SAVED EEPROM to %s\n", eeprom_file); printf("Saved EEPROM to %s\n", eeprom_file.c_str());
} }
else
printf("EEPROM SAVE FAILED to %s\n", eeprom_file.c_str());
#endif #endif
} }
return (7); return (7);
@ -1314,16 +1332,16 @@ struct maple_naomi_jamma : maple_sega_controller
if (!EEPROM_loaded) if (!EEPROM_loaded)
{ {
EEPROM_loaded = true; EEPROM_loaded = true;
wchar eeprom_file[512]; string eeprom_file = get_eeprom_file_path();
host.ConfigLoadStr(L"emu", L"gamefile", eeprom_file, L""); FILE* f = fopen(eeprom_file.c_str(), "rb");
wcscat(eeprom_file, L".eeprom");
FILE* f = _wfopen(eeprom_file, L"rb");
if (f) if (f)
{ {
fread(EEPROM, 1, 0x80, f); fread(EEPROM, 1, 0x80, f);
fclose(f); fclose(f);
wprintf(L"LOADED EEPROM from %s\n", eeprom_file); printf("Loaded EEPROM from %s\n", eeprom_file.c_str());
} }
else
printf("EEPROM file not found at %s\n", eeprom_file.c_str());
} }
#endif #endif
//printf("EEprom READ ?\n"); //printf("EEprom READ ?\n");

View File

@ -334,7 +334,7 @@ endif
EXECUTABLE_STRIPPED=nosym-reicast.elf EXECUTABLE_STRIPPED=nosym-reicast.elf
ifdef NAOMI ifdef NAOMI
CFLAGS += -D TARGET_NAOMI CFLAGS += -D TARGET_NAOMI -D SAVE_EPPROM
DC_PLATFORM=naomi DC_PLATFORM=naomi
EXECUTABLE=reicast_naomi.elf EXECUTABLE=reicast_naomi.elf
EXECUTABLE_NAME=reicast-naomi EXECUTABLE_NAME=reicast-naomi