Update to bsnes v007a release.

[No changelog available]
This commit is contained in:
byuu 2005-06-13 04:34:10 +00:00
parent 09b326ae86
commit ea38ea2537
14 changed files with 115 additions and 134 deletions

View File

@ -1,4 +1,4 @@
#[bsnes v0.007 configuration file]
#[bsnes v0.007a configuration file]
#[video mode]
# 0: 256x224w

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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(size > sram_size) {
memcpy(sram_data, buffer, sram_size);
} else {
memset(sram_data, 0, sram_size);
memcpy(sram_data, buffer, size);
}
rf->read(&sram_data, sram_size);
}
uint32 bROM::save_sram(uint8 **buffer) {
uint8 *t;
if(rom_loaded == false)return 0;
if(!sram_size)return 0;
void bROM::save_sram(Writer *wf) {
if(rom_loaded == false)return;
if(!sram_size)return;
if(*buffer) {
t = (uint8*)memalloc(sram_size, "bROM::save_sram");
memcpy(t, sram_data, sram_size);
*buffer = t;
}
return sram_size;
wf->write(sram_data, sram_size);
}
void bROM::load_rom(Reader *rf) {
@ -176,12 +165,6 @@ end:
case 6:sram_size = 64 * 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 Type : %s", (mapper == LOROM)?"LoROM":"HiROM");

View File

@ -8,13 +8,13 @@ enum { LOROM = 0, HIROM = 1 };
uint8 *data, *sram_data;
uint8 mapper;
uint32 size, sram_size;
void load_rom(Reader *rf);
void load_sram(uint8 *buffer, uint32 size);
uint32 save_sram(uint8 **buffer);
void unload();
uint8 read (uint32 addr);
void write(uint32 addr, byte value);
void write_protect(bool yn);
void load_rom(Reader *rf);
void load_sram(Reader *rf);
void save_sram(Writer *wf);
void unload();
uint8 read (uint32 addr);
void write(uint32 addr, byte value);
void write_protect(bool yn);
bROM();
~bROM();

View File

@ -11,11 +11,11 @@ enum { WRAP_NONE = 0, WRAP_BANK = 1, WRAP_PAGE = 2 };
class ROM : public Memory {
public:
virtual void load_rom(Reader *rf) = 0;
virtual void load_sram(uint8 *buffer, uint32 size) = 0;
virtual uint32 save_sram(uint8 **buffer) = 0;
virtual void unload() = 0;
virtual void write_protect(bool yn) = 0;
virtual void load_rom(Reader *rf) = 0;
virtual void load_sram(Reader *rf) = 0;
virtual void save_sram(Writer *wf) = 0;
virtual void unload() = 0;
virtual void write_protect(bool yn) = 0;
};
class MMIO : public Memory {

View File

@ -1,24 +1,38 @@
#include "../base.h"
bool FileReader::open(char *fn) {
/* is the filename too short to be a file? */
if(strlen(fn) < 4)return false;
uint32 FileReader::size() {
return fsize;
}
int i;
for(i=strlen(fn) - 1;i>=0;i--) {
if(fn[i] == '.')break;
/*
This function will allocate memory even if open() fails.
This is needed so that when SRAM files do not exist, the
memory for the SRAM data will be allocated still.
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);
}
if(fn[i] != '.')return false;
char *filetype = fn + i;
/* make sure we support this file format before loading it */
if(stricmp(filetype, ".smc") &&
stricmp(filetype, ".swc") &&
stricmp(filetype, ".fig") &&
stricmp(filetype, ".ufo") &&
stricmp(filetype, ".gd3") &&
stricmp(filetype, ".078"))return false;
*buffer = data;
}
bool FileReader::open(uint8 type, char *fn) {
fp = fopen(fn, "rb");
if(!fp)return false;
@ -26,12 +40,7 @@ char *filetype = fn + i;
fsize = ftell(fp);
fseek(fp, 0, SEEK_SET);
if(!stricmp(filetype, ".smc") ||
!stricmp(filetype, ".swc") ||
!stricmp(filetype, ".fig") ||
!stricmp(filetype, ".ufo") ||
!stricmp(filetype, ".gd3") ||
!stricmp(filetype, ".078")) {
if(type == TYPE_ROM) {
/* remove header if it exists */
if((fsize & 0xfff) == 0x200) {
fsize -= 0x200;
@ -48,29 +57,23 @@ char *filetype = fn + i;
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() {
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);
}

View File

@ -10,11 +10,33 @@ FILE *fp;
uint32 fsize;
public:
enum {
TYPE_ROM = 0,
TYPE_SRAM = 1
};
uint32 size();
void read(uint8 **buffer, uint32 length = 0);
bool open(char *fn);
bool open(uint8 type, char *fn);
void close();
FileReader() { fp = 0; fsize = 0; }
~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); }
};

View File

@ -67,32 +67,3 @@ va_list args;
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;
}

View File

@ -22,23 +22,19 @@ bool ROMImage::load() {
dprintf("* Loading [%s]...", rom_fn);
Reader *rf = new FileReader();
FileReader *f_rf = static_cast<FileReader*>(rf);
if(!f_rf->open(rom_fn)) {
FileReader *rf = new FileReader();
if(!rf->open(FileReader::TYPE_ROM, rom_fn)) {
alert("Error loading image file [%s]!", rom_fn);
return false;
}
mem_bus->rom->load_rom(rf);
f_rf->close();
delete rf;
mem_bus->rom->load_rom(static_cast<Reader*>(rf));
rf->close();
uint8 *sram_data;
uint32 sram_size;
sram_size = load_file(sram_fn, &sram_data);
if(sram_size) {
mem_bus->rom->load_sram(sram_data, sram_size);
memfree(sram_data);
}
rf->open(FileReader::TYPE_SRAM, sram_fn);
mem_bus->rom->load_sram(static_cast<Reader*>(rf));
rf->close();
delete(rf);
file_loaded = true;
bsnes->debugger_activate();
@ -48,13 +44,12 @@ uint32 sram_size;
void ROMImage::unload() {
if(file_loaded == false)return;
uint8 *sram_data;
uint32 sram_size;
sram_size = mem_bus->rom->save_sram(&sram_data);
if(sram_size) {
save_file(sram_fn, sram_data, sram_size);
memfree(sram_data);
}
FileWriter *wf = new FileWriter();
wf->open(sram_fn);
mem_bus->rom->save_sram(static_cast<Writer*>(wf));
wf->close();
delete(wf);
file_loaded = false;
bsnes->debugger_deactivate();

View File

@ -1,5 +1,5 @@
#define INTERFACE_MAIN
#define BSNES_VERSION "0.007"
#define BSNES_VERSION "0.007a"
#include "winmain.h"
#include "../base.h"
@ -34,11 +34,18 @@ void term_snes() {
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) {
MSG msg;
string cfg_fn;
_getcwd(cfg_fn, 4096);
cfg_fn += "\\bsnes.cfg";
get_config_fn(cfg_fn);
cfg.load(cfg_fn);
meminit();
fps_timer = new fpstimer();