-Couple of backup memory fixes

-Changed NDS_LoadROM so it takes two more additional arguements(backup memory type and size)
-Changed windows port so it preserves the setting for backup memory when loading a new rom, this should fix some backup memory corruption issues
This commit is contained in:
cyberwarriorx 2006-12-10 03:26:01 +00:00
parent dcdfbd1411
commit 326109d0c8
6 changed files with 44 additions and 25 deletions

View File

@ -167,7 +167,7 @@ enum
ROM_DSGBA
};
int NDS_LoadROM(const char *filename)
int NDS_LoadROM(const char *filename, int bmtype, u32 bmsize)
{
int i;
int type;
@ -247,6 +247,7 @@ int NDS_LoadROM(const char *filename)
else
strcpy(p+strlen(p)-4, ".sav");
mc_realloc(&MMU.bupmem, bmtype, bmsize);
mc_load_file(&MMU.bupmem, p);
free(p);

View File

@ -121,7 +121,7 @@ NDS_header * NDS_getROMHeader(void);
void NDS_setTouchPos(u16 x, u16 y);
void NDS_releasTouch(void);
int NDS_LoadROM(const char *filename);
int NDS_LoadROM(const char *filename, int bmtype, u32 bmsize);
void NDS_FreeROM(void);
void NDS_Reset(void);

View File

@ -50,7 +50,7 @@ int main(int argc, char ** argv) {
return 1;
}
if (NDS_LoadROM(argv[1]) < 0) {
if (NDS_LoadROM(argv[1], MC_TYPE_AUTODETECT, 1) < 0) {
fprintf(stderr, "error while loading %s\n", argv[1]);
return 2;
}

View File

@ -186,7 +186,7 @@ void About(GtkWidget* widget, gpointer data)
static int Open(const char *filename)
{
int i = NDS_LoadROM(filename);
int i = NDS_LoadROM(filename, MC_TYPE_AUTODETECT, 1);
return i;
}

View File

@ -161,6 +161,7 @@ void mc_realloc(memory_chip_t *mc, int type, u32 size)
void mc_load_file(memory_chip_t *mc, const char* filename)
{
long size;
int type;
FILE* file = fopen(filename, "rb+");
if(file == NULL)
{
@ -172,21 +173,24 @@ void mc_load_file(memory_chip_t *mc, const char* filename)
size = ftell(file);
fseek(file, 0, SEEK_SET);
if (size == MC_SIZE_4KBITS)
mc->type = MC_TYPE_EEPROM1;
else if (size == MC_SIZE_64KBITS)
mc->type = MC_TYPE_EEPROM2;
else if (size == MC_SIZE_256KBITS)
mc->type = MC_TYPE_FRAM;
else if (size == MC_SIZE_512KBITS)
mc->type = MC_TYPE_EEPROM2;
else if (size >= MC_SIZE_2MBITS)
mc->type = MC_TYPE_FLASH;
if (mc->type == MC_TYPE_AUTODETECT)
{
if (size == MC_SIZE_4KBITS)
type = MC_TYPE_EEPROM1;
else if (size == MC_SIZE_64KBITS)
type = MC_TYPE_EEPROM2;
else if (size == MC_SIZE_256KBITS)
type = MC_TYPE_FRAM;
else if (size == MC_SIZE_512KBITS)
type = MC_TYPE_EEPROM2;
else if (size >= MC_SIZE_2MBITS)
type = MC_TYPE_FLASH;
mc_realloc(mc, type, size);
}
mc->size = size;
mc_realloc(mc, mc->type, mc->size);
fread (mc->data, 1, mc->size, file);
if (size > mc->size)
size = mc->size;
fread (mc->data, 1, size, file);
mc->fp = file;
}

View File

@ -93,6 +93,8 @@ NULL
int autoframeskipenab=1;
int frameskiprate=0;
static int backupmemorytype=MC_TYPE_AUTODETECT;
static u32 backupmemorysize=1;
LRESULT CALLBACK SoundSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
LPARAM lParam);
@ -250,7 +252,7 @@ BOOL LoadROM(char * filename)
{
NDS_Pause();
if (NDS_LoadROM(filename) > 0)
if (NDS_LoadROM(filename, backupmemorytype, backupmemorysize) > 0)
return TRUE;
return FALSE;
@ -976,27 +978,39 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
case IDC_SAVETYPE1:
saver(MF_CHECKED,MF_UNCHECKED,MF_UNCHECKED,MF_UNCHECKED,MF_UNCHECKED,MF_UNCHECKED);
mc_realloc(&MMU.bupmem, MC_TYPE_AUTODETECT,1);
backupmemorytype = MC_TYPE_AUTODETECT;
backupmemorysize = 1;
mc_realloc(&MMU.bupmem, backupmemorytype,backupmemorysize);
return 0;
case IDC_SAVETYPE2:
saver(MF_UNCHECKED,MF_CHECKED,MF_UNCHECKED,MF_UNCHECKED,MF_UNCHECKED,MF_UNCHECKED);
mc_realloc(&MMU.bupmem, MC_TYPE_EEPROM1,MC_SIZE_4KBITS);
backupmemorytype = MC_TYPE_EEPROM1;
backupmemorysize = MC_SIZE_4KBITS;
mc_realloc(&MMU.bupmem, backupmemorytype,backupmemorysize);
return 0;
case IDC_SAVETYPE3:
saver(MF_UNCHECKED,MF_UNCHECKED,MF_CHECKED,MF_UNCHECKED,MF_UNCHECKED,MF_UNCHECKED);
mc_realloc(&MMU.bupmem, MC_TYPE_EEPROM2,MC_SIZE_64KBITS);
backupmemorytype = MC_TYPE_EEPROM2;
backupmemorysize = MC_SIZE_64KBITS;
mc_realloc(&MMU.bupmem, backupmemorytype,backupmemorysize);
return 0;
case IDC_SAVETYPE4:
saver(MF_UNCHECKED,MF_UNCHECKED,MF_UNCHECKED,MF_CHECKED,MF_UNCHECKED,MF_UNCHECKED);
mc_realloc(&MMU.bupmem, MC_TYPE_EEPROM2,MC_SIZE_512KBITS);
backupmemorytype = MC_TYPE_EEPROM2;
backupmemorysize = MC_SIZE_512KBITS;
mc_realloc(&MMU.bupmem, backupmemorytype,backupmemorysize);
return 0;
case IDC_SAVETYPE5:
saver(MF_UNCHECKED,MF_UNCHECKED,MF_UNCHECKED,MF_UNCHECKED,MF_CHECKED,MF_UNCHECKED);
mc_realloc(&MMU.bupmem, MC_TYPE_FRAM,MC_SIZE_256KBITS);
backupmemorytype = MC_TYPE_FRAM;
backupmemorysize = MC_SIZE_256KBITS;
mc_realloc(&MMU.bupmem, backupmemorytype,backupmemorysize);
return 0;
case IDC_SAVETYPE6:
saver(MF_UNCHECKED,MF_UNCHECKED,MF_UNCHECKED,MF_UNCHECKED,MF_UNCHECKED,MF_CHECKED);
mc_realloc(&MMU.bupmem, MC_TYPE_FLASH,MC_SIZE_2MBITS);
backupmemorytype = MC_TYPE_FLASH;
backupmemorysize = MC_SIZE_2MBITS;
mc_realloc(&MMU.bupmem, backupmemorytype,backupmemorysize);
return 0;
case IDM_RESET: