Using mmap for cart sram/eeprom files.
This commit is contained in:
parent
ee50803d33
commit
1130abeb9c
@ -329,8 +329,6 @@ void ws_memory_init(uint8 *rom, uint32 wsRomSize)
|
||||
ws_romHeader=ws_rom_getHeader(ws_rom,romSize);
|
||||
ws_rom_checksum=ws_romHeader->checksum;
|
||||
internalRam=(uint8*)malloc(0x10000);
|
||||
ws_staticRam=(uint8*)malloc(0x10000);
|
||||
externalEeprom=(uint8*)malloc(131072);//ws_rom_eepromSize(ws_rom,romSize));
|
||||
sramAddressMask=ws_rom_sramSize(ws_rom,romSize)-1;
|
||||
externalEepromAddressMask=ws_rom_eepromSize(ws_rom,romSize)-1;
|
||||
|
||||
@ -401,9 +399,9 @@ void ws_memory_reset(void)
|
||||
void ws_memory_done(void)
|
||||
{
|
||||
//free(ws_rom);
|
||||
free(ws_staticRam);
|
||||
//free(ws_staticRam);
|
||||
free(internalRam);
|
||||
free(externalEeprom);
|
||||
//free(externalEeprom);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@ -450,42 +448,3 @@ uint16 memory_getRomCrc(void)
|
||||
{
|
||||
return(ws_rom_checksum);
|
||||
}
|
||||
|
||||
|
||||
void ws_sram_load(char *path)
|
||||
{
|
||||
FILE *f;
|
||||
//size_t read;
|
||||
|
||||
f = fopen(path, "r");
|
||||
|
||||
if (NULL == f)
|
||||
{
|
||||
memset(ws_staticRam, 0, 0x10000);
|
||||
return;
|
||||
}
|
||||
|
||||
/*read = */fread(ws_staticRam, 1, 0x8000, f);
|
||||
//fprintf(log_get(), "read 0x%x (of 0x%x?) bytes of save ram from %s\n", read, ws_rom_sramSize(ws_rom, romSize), path);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
void ws_sram_save(char *path)
|
||||
{
|
||||
FILE *f;
|
||||
//size_t wrote;
|
||||
|
||||
f = fopen(path, "wb");
|
||||
|
||||
if (NULL == f)
|
||||
{
|
||||
fprintf(log_get(), "error opening %s for writing save ram. (%s)\n", path, strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
/*wrote = */fwrite(ws_staticRam, 1, 0x8000, f);
|
||||
fflush(f);
|
||||
//fprintf(log_get(), "wrote 0x%x bytes of save ram to %s\n", wrote, path);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
|
||||
@ -12,21 +12,21 @@
|
||||
#ifndef __MEMORY_H__
|
||||
#define __MEMORY_H__
|
||||
|
||||
extern uint8 *ws_staticRam;
|
||||
extern uint8 *internalRam;
|
||||
extern uint8 *externalEeprom;
|
||||
extern uint8_t *ws_staticRam;
|
||||
extern uint8_t *internalRam;
|
||||
extern uint8_t *externalEeprom;
|
||||
|
||||
void ws_memory_init(uint8 *rom, uint32 romSize);
|
||||
void ws_memory_init(uint8 *rom, uint32_t romSize);
|
||||
void ws_memory_reset(void);
|
||||
uint8 *memory_getRom(void);
|
||||
uint32 memory_getRomSize(void);
|
||||
uint16 memory_getRomCrc(void);
|
||||
uint8_t *memory_getRom(void);
|
||||
uint32_t memory_getRomSize(void);
|
||||
uint16_t memory_getRomCrc(void);
|
||||
void ws_memory_done(void);
|
||||
void memory_load(int fp);
|
||||
void memory_save(int fp);
|
||||
|
||||
void ws_sram_load(char *path);
|
||||
void ws_sram_save(char *path);
|
||||
char *create_file(char *filename, uint32_t size);
|
||||
char *load_file(char *filename);
|
||||
|
||||
void dump_memory();
|
||||
|
||||
|
||||
@ -54,6 +54,8 @@ uint32 ws_cyclesByLine=0;
|
||||
uint32 vblank_count=0;
|
||||
|
||||
char *ws_sram_path = NULL;
|
||||
char *ws_ieep_path = NULL;
|
||||
char *ws_rom_path = NULL;
|
||||
extern int ws_sram_dirty;
|
||||
extern int ws_gpu_forceColorSystemBool;
|
||||
extern int ws_gpu_forceMonoSystemBool;
|
||||
@ -72,8 +74,8 @@ extern int ws_gpu_forceMonoSystemBool;
|
||||
void ws_patchRom(void)
|
||||
{
|
||||
|
||||
uint8 *rom=memory_getRom();
|
||||
uint32 romSize=memory_getRomSize();
|
||||
uint8_t *rom=memory_getRom();
|
||||
uint32_t romSize=memory_getRomSize();
|
||||
|
||||
fprintf(log_get(),"developper Id: 0x%.2x\nGame Id: 0x%.2x\n",rom[romSize-10],rom[romSize-8]);
|
||||
|
||||
@ -111,8 +113,8 @@ void ws_patchRom(void)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int ws_init(char *rompath)
|
||||
{
|
||||
uint8 *rom;
|
||||
uint32 romSize;
|
||||
uint8_t *rom;
|
||||
uint32_t romSize;
|
||||
|
||||
if ((rom=ws_rom_load(rompath,&romSize))==NULL)
|
||||
{
|
||||
@ -133,9 +135,31 @@ int ws_init(char *rompath)
|
||||
}
|
||||
}
|
||||
|
||||
ws_memory_init(rom,romSize);
|
||||
ws_memory_init(rom, romSize);
|
||||
ws_patchRom();
|
||||
ws_sram_load(ws_sram_path);
|
||||
ws_staticRam = (uint8_t *)load_file(ws_ieep_path);
|
||||
if (ws_staticRam == NULL)
|
||||
{
|
||||
ws_staticRam = (uint8_t *)create_file(ws_sram_path, 0x10000);
|
||||
}
|
||||
|
||||
if (ws_staticRam == NULL)
|
||||
{
|
||||
printf("Card SRAM load error!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
externalEeprom = (uint8_t *)load_file(ws_ieep_path);
|
||||
if (externalEeprom == NULL)
|
||||
{
|
||||
externalEeprom = (uint8_t *)create_file(ws_ieep_path, 0x100000);
|
||||
}
|
||||
if (externalEeprom == NULL)
|
||||
{
|
||||
printf("Card EEPROM load error!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ws_io_init();
|
||||
ws_audio_init();
|
||||
ws_gpu_init();
|
||||
@ -274,7 +298,7 @@ int ws_executeLine(int16 *framebuffer, int renderLine)
|
||||
|
||||
if (drawWholeScreen && ws_sram_dirty)
|
||||
{
|
||||
ws_sram_save(ws_sram_path);
|
||||
//ws_sram_save(ws_sram_path);
|
||||
ws_sram_dirty = 0;
|
||||
}
|
||||
|
||||
|
||||
@ -30,4 +30,9 @@ int ws_loadState(char *statepath);
|
||||
int ws_saveState(char *statepath);
|
||||
void ws_done(void);
|
||||
|
||||
extern char *ws_sram_path;
|
||||
extern char *ws_ieep_path;
|
||||
extern char *ws_rom_path;
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user