mirror of https://github.com/bsnes-emu/bsnes.git
parent
09b326ae86
commit
ea38ea2537
|
@ -1,4 +1,4 @@
|
||||||
#[bsnes v0.007 configuration file]
|
#[bsnes v0.007a configuration file]
|
||||||
|
|
||||||
#[video mode]
|
#[video mode]
|
||||||
# 0: 256x224w
|
# 0: 256x224w
|
||||||
|
|
BIN
bsnes_g2.exe
BIN
bsnes_g2.exe
Binary file not shown.
BIN
demo_1.smc
BIN
demo_1.smc
Binary file not shown.
BIN
demo_1.srm
BIN
demo_1.srm
Binary file not shown.
BIN
demo_2.smc
BIN
demo_2.smc
Binary file not shown.
BIN
demo_2.srm
BIN
demo_2.srm
Binary file not shown.
|
@ -113,28 +113,17 @@ uint32 b, w;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void bROM::load_sram(uint8 *buffer, uint32 size) {
|
void bROM::load_sram(Reader *rf) {
|
||||||
if(rom_loaded == false)return;
|
if(rom_loaded == false)return;
|
||||||
|
|
||||||
if(size > sram_size) {
|
rf->read(&sram_data, sram_size);
|
||||||
memcpy(sram_data, buffer, sram_size);
|
|
||||||
} else {
|
|
||||||
memset(sram_data, 0, sram_size);
|
|
||||||
memcpy(sram_data, buffer, size);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 bROM::save_sram(uint8 **buffer) {
|
void bROM::save_sram(Writer *wf) {
|
||||||
uint8 *t;
|
if(rom_loaded == false)return;
|
||||||
if(rom_loaded == false)return 0;
|
if(!sram_size)return;
|
||||||
if(!sram_size)return 0;
|
|
||||||
|
|
||||||
if(*buffer) {
|
wf->write(sram_data, sram_size);
|
||||||
t = (uint8*)memalloc(sram_size, "bROM::save_sram");
|
|
||||||
memcpy(t, sram_data, sram_size);
|
|
||||||
*buffer = t;
|
|
||||||
}
|
|
||||||
return sram_size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void bROM::load_rom(Reader *rf) {
|
void bROM::load_rom(Reader *rf) {
|
||||||
|
@ -176,12 +165,6 @@ end:
|
||||||
case 6:sram_size = 64 * 1024;break;
|
case 6:sram_size = 64 * 1024;break;
|
||||||
case 7:sram_size = 128 * 1024;break;
|
case 7:sram_size = 128 * 1024;break;
|
||||||
}
|
}
|
||||||
if(sram_size) {
|
|
||||||
sram_data = (uint8*)memalloc(sram_size, "bROM::sram_data");
|
|
||||||
memset(sram_data, 0, sram_size);
|
|
||||||
} else {
|
|
||||||
sram_data = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
dprintf("Image Name : \"%s\"", cart_title);
|
dprintf("Image Name : \"%s\"", cart_title);
|
||||||
dprintf("Image Type : %s", (mapper == LOROM)?"LoROM":"HiROM");
|
dprintf("Image Type : %s", (mapper == LOROM)?"LoROM":"HiROM");
|
||||||
|
|
|
@ -9,8 +9,8 @@ uint8 *data, *sram_data;
|
||||||
uint8 mapper;
|
uint8 mapper;
|
||||||
uint32 size, sram_size;
|
uint32 size, sram_size;
|
||||||
void load_rom(Reader *rf);
|
void load_rom(Reader *rf);
|
||||||
void load_sram(uint8 *buffer, uint32 size);
|
void load_sram(Reader *rf);
|
||||||
uint32 save_sram(uint8 **buffer);
|
void save_sram(Writer *wf);
|
||||||
void unload();
|
void unload();
|
||||||
uint8 read (uint32 addr);
|
uint8 read (uint32 addr);
|
||||||
void write(uint32 addr, byte value);
|
void write(uint32 addr, byte value);
|
||||||
|
|
|
@ -12,8 +12,8 @@ enum { WRAP_NONE = 0, WRAP_BANK = 1, WRAP_PAGE = 2 };
|
||||||
class ROM : public Memory {
|
class ROM : public Memory {
|
||||||
public:
|
public:
|
||||||
virtual void load_rom(Reader *rf) = 0;
|
virtual void load_rom(Reader *rf) = 0;
|
||||||
virtual void load_sram(uint8 *buffer, uint32 size) = 0;
|
virtual void load_sram(Reader *rf) = 0;
|
||||||
virtual uint32 save_sram(uint8 **buffer) = 0;
|
virtual void save_sram(Writer *wf) = 0;
|
||||||
virtual void unload() = 0;
|
virtual void unload() = 0;
|
||||||
virtual void write_protect(bool yn) = 0;
|
virtual void write_protect(bool yn) = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,24 +1,38 @@
|
||||||
#include "../base.h"
|
#include "../base.h"
|
||||||
|
|
||||||
bool FileReader::open(char *fn) {
|
uint32 FileReader::size() {
|
||||||
/* is the filename too short to be a file? */
|
return fsize;
|
||||||
if(strlen(fn) < 4)return false;
|
|
||||||
|
|
||||||
int i;
|
|
||||||
for(i=strlen(fn) - 1;i>=0;i--) {
|
|
||||||
if(fn[i] == '.')break;
|
|
||||||
}
|
}
|
||||||
if(fn[i] != '.')return false;
|
|
||||||
|
|
||||||
char *filetype = fn + i;
|
/*
|
||||||
/* make sure we support this file format before loading it */
|
This function will allocate memory even if open() fails.
|
||||||
if(stricmp(filetype, ".smc") &&
|
This is needed so that when SRAM files do not exist, the
|
||||||
stricmp(filetype, ".swc") &&
|
memory for the SRAM data will be allocated still.
|
||||||
stricmp(filetype, ".fig") &&
|
|
||||||
stricmp(filetype, ".ufo") &&
|
|
||||||
stricmp(filetype, ".gd3") &&
|
|
||||||
stricmp(filetype, ".078"))return false;
|
|
||||||
|
|
||||||
|
The memory is flushed to 0x00 when no file is opened.
|
||||||
|
*/
|
||||||
|
void FileReader::read(uint8 **buffer, uint32 length) {
|
||||||
|
uint8 *data;
|
||||||
|
if(length == 0) {
|
||||||
|
/* read the entire file into RAM */
|
||||||
|
data = (uint8*)memalloc(fsize);
|
||||||
|
memset(data, 0, fsize);
|
||||||
|
if(fp)fread(data, 1, fsize, fp);
|
||||||
|
} else if(length > fsize) {
|
||||||
|
/* read the entire file into RAM, pad the rest with 0x00s */
|
||||||
|
data = (uint8*)memalloc(length);
|
||||||
|
memset(data, 0, length);
|
||||||
|
if(fp)fread(data, 1, fsize, fp);
|
||||||
|
} else { //fsize >= length
|
||||||
|
/* read as much of the file as possible, truncate the rest */
|
||||||
|
data = (uint8*)memalloc(length);
|
||||||
|
memset(data, 0, length);
|
||||||
|
if(fp)fread(data, 1, length, fp);
|
||||||
|
}
|
||||||
|
*buffer = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FileReader::open(uint8 type, char *fn) {
|
||||||
fp = fopen(fn, "rb");
|
fp = fopen(fn, "rb");
|
||||||
if(!fp)return false;
|
if(!fp)return false;
|
||||||
|
|
||||||
|
@ -26,12 +40,7 @@ char *filetype = fn + i;
|
||||||
fsize = ftell(fp);
|
fsize = ftell(fp);
|
||||||
fseek(fp, 0, SEEK_SET);
|
fseek(fp, 0, SEEK_SET);
|
||||||
|
|
||||||
if(!stricmp(filetype, ".smc") ||
|
if(type == TYPE_ROM) {
|
||||||
!stricmp(filetype, ".swc") ||
|
|
||||||
!stricmp(filetype, ".fig") ||
|
|
||||||
!stricmp(filetype, ".ufo") ||
|
|
||||||
!stricmp(filetype, ".gd3") ||
|
|
||||||
!stricmp(filetype, ".078")) {
|
|
||||||
/* remove header if it exists */
|
/* remove header if it exists */
|
||||||
if((fsize & 0xfff) == 0x200) {
|
if((fsize & 0xfff) == 0x200) {
|
||||||
fsize -= 0x200;
|
fsize -= 0x200;
|
||||||
|
@ -48,29 +57,23 @@ char *filetype = fn + i;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileReader::read(uint8 **buffer, uint32 length) {
|
|
||||||
uint8 *data;
|
|
||||||
if(length == 0) {
|
|
||||||
/* read the entire file into RAM */
|
|
||||||
data = (uint8*)memalloc(fsize);
|
|
||||||
fread(data, 1, fsize, fp);
|
|
||||||
} else if(length > fsize) {
|
|
||||||
/* read the entire file into RAM, pad the rest with 0x00s */
|
|
||||||
data = (uint8*)memalloc(length);
|
|
||||||
memset(data, 0, length);
|
|
||||||
fread(data, 1, fsize, fp);
|
|
||||||
} else { //fsize >= length
|
|
||||||
/* read as much of the file as possible, truncate the rest */
|
|
||||||
data = (uint8*)memalloc(length);
|
|
||||||
fread(data, 1, length, fp);
|
|
||||||
}
|
|
||||||
*buffer = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32 FileReader::size() {
|
|
||||||
return fsize;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FileReader::close() {
|
void FileReader::close() {
|
||||||
if(fp)fclose(fp);
|
if(fp)fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileWriter::write(uint8 *buffer, uint32 length) {
|
||||||
|
if(!fp)return;
|
||||||
|
|
||||||
|
fwrite(buffer, 1, length, fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FileWriter::open(char *fn) {
|
||||||
|
fp = fopen(fn, "wb");
|
||||||
|
if(!fp)return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileWriter::close() {
|
||||||
|
if(fp)fclose(fp);
|
||||||
|
}
|
||||||
|
|
|
@ -10,11 +10,33 @@ FILE *fp;
|
||||||
uint32 fsize;
|
uint32 fsize;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum {
|
||||||
|
TYPE_ROM = 0,
|
||||||
|
TYPE_SRAM = 1
|
||||||
|
};
|
||||||
uint32 size();
|
uint32 size();
|
||||||
void read(uint8 **buffer, uint32 length = 0);
|
void read(uint8 **buffer, uint32 length = 0);
|
||||||
bool open(char *fn);
|
bool open(uint8 type, char *fn);
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
FileReader() { fp = 0; fsize = 0; }
|
FileReader() { fp = 0; fsize = 0; }
|
||||||
~FileReader() { if(fp)fclose(fp); }
|
~FileReader() { if(fp)fclose(fp); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Writer {
|
||||||
|
public:
|
||||||
|
virtual void write(uint8 *buffer, uint32 length);
|
||||||
|
};
|
||||||
|
|
||||||
|
class FileWriter : public Writer {
|
||||||
|
private:
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void write(uint8 *buffer, uint32 length);
|
||||||
|
bool open(char *fn);
|
||||||
|
void close();
|
||||||
|
|
||||||
|
FileWriter() { fp = 0; }
|
||||||
|
~FileWriter() { if(fp)fclose(fp); }
|
||||||
|
};
|
||||||
|
|
|
@ -67,32 +67,3 @@ va_list args;
|
||||||
w_console->write(str, Console::DEBUG_MESSAGE);
|
w_console->write(str, Console::DEBUG_MESSAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 load_file(char *fn, uint8 **buffer) {
|
|
||||||
FILE *fp;
|
|
||||||
uint8 *data;
|
|
||||||
int fsize;
|
|
||||||
fp = fopen(fn, "rb");
|
|
||||||
if(!fp)return 0;
|
|
||||||
fseek(fp, 0, SEEK_END);
|
|
||||||
fsize = ftell(fp);
|
|
||||||
if(!fsize) {
|
|
||||||
fclose(fp);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
fseek(fp, 0, SEEK_SET);
|
|
||||||
data = (uint8*)memalloc(fsize);
|
|
||||||
fread(data, 1, fsize, fp);
|
|
||||||
fclose(fp);
|
|
||||||
*buffer = data;
|
|
||||||
return fsize;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool save_file(char *fn, uint8 *data, uint32 size) {
|
|
||||||
FILE *fp;
|
|
||||||
fp = fopen(fn, "wb");
|
|
||||||
if(!fp)return false;
|
|
||||||
fwrite(data, 1, size, fp);
|
|
||||||
fclose(fp);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
|
@ -22,23 +22,19 @@ bool ROMImage::load() {
|
||||||
|
|
||||||
dprintf("* Loading [%s]...", rom_fn);
|
dprintf("* Loading [%s]...", rom_fn);
|
||||||
|
|
||||||
Reader *rf = new FileReader();
|
FileReader *rf = new FileReader();
|
||||||
FileReader *f_rf = static_cast<FileReader*>(rf);
|
if(!rf->open(FileReader::TYPE_ROM, rom_fn)) {
|
||||||
if(!f_rf->open(rom_fn)) {
|
|
||||||
alert("Error loading image file [%s]!", rom_fn);
|
alert("Error loading image file [%s]!", rom_fn);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
mem_bus->rom->load_rom(rf);
|
mem_bus->rom->load_rom(static_cast<Reader*>(rf));
|
||||||
f_rf->close();
|
rf->close();
|
||||||
delete rf;
|
|
||||||
|
|
||||||
uint8 *sram_data;
|
rf->open(FileReader::TYPE_SRAM, sram_fn);
|
||||||
uint32 sram_size;
|
mem_bus->rom->load_sram(static_cast<Reader*>(rf));
|
||||||
sram_size = load_file(sram_fn, &sram_data);
|
rf->close();
|
||||||
if(sram_size) {
|
|
||||||
mem_bus->rom->load_sram(sram_data, sram_size);
|
delete(rf);
|
||||||
memfree(sram_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
file_loaded = true;
|
file_loaded = true;
|
||||||
bsnes->debugger_activate();
|
bsnes->debugger_activate();
|
||||||
|
@ -48,13 +44,12 @@ uint32 sram_size;
|
||||||
void ROMImage::unload() {
|
void ROMImage::unload() {
|
||||||
if(file_loaded == false)return;
|
if(file_loaded == false)return;
|
||||||
|
|
||||||
uint8 *sram_data;
|
FileWriter *wf = new FileWriter();
|
||||||
uint32 sram_size;
|
wf->open(sram_fn);
|
||||||
sram_size = mem_bus->rom->save_sram(&sram_data);
|
mem_bus->rom->save_sram(static_cast<Writer*>(wf));
|
||||||
if(sram_size) {
|
wf->close();
|
||||||
save_file(sram_fn, sram_data, sram_size);
|
delete(wf);
|
||||||
memfree(sram_data);
|
|
||||||
}
|
|
||||||
file_loaded = false;
|
file_loaded = false;
|
||||||
bsnes->debugger_deactivate();
|
bsnes->debugger_deactivate();
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#define INTERFACE_MAIN
|
#define INTERFACE_MAIN
|
||||||
#define BSNES_VERSION "0.007"
|
#define BSNES_VERSION "0.007a"
|
||||||
#include "winmain.h"
|
#include "winmain.h"
|
||||||
#include "../base.h"
|
#include "../base.h"
|
||||||
|
|
||||||
|
@ -34,11 +34,18 @@ void term_snes() {
|
||||||
if(snes) { delete(snes); snes = 0; }
|
if(snes) { delete(snes); snes = 0; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void get_config_fn(string &str) {
|
||||||
|
char *t = (char*)malloc(4096);
|
||||||
|
_getcwd(t, 4095);
|
||||||
|
str = t;
|
||||||
|
free(t);
|
||||||
|
str += "\\bsnes.cfg";
|
||||||
|
}
|
||||||
|
|
||||||
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
|
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
|
||||||
MSG msg;
|
MSG msg;
|
||||||
string cfg_fn;
|
string cfg_fn;
|
||||||
_getcwd(cfg_fn, 4096);
|
get_config_fn(cfg_fn);
|
||||||
cfg_fn += "\\bsnes.cfg";
|
|
||||||
cfg.load(cfg_fn);
|
cfg.load(cfg_fn);
|
||||||
meminit();
|
meminit();
|
||||||
fps_timer = new fpstimer();
|
fps_timer = new fpstimer();
|
||||||
|
|
Loading…
Reference in New Issue