more flexible and less confusing return type.

git-svn-id: https://gambatte.svn.sourceforge.net/svnroot/gambatte@313 9dfb2916-2d38-0410-aef4-c5fe6c9ffc24
This commit is contained in:
sinamas 2012-02-01 23:41:52 +00:00
parent 4785515dac
commit 2c9679d7bc
8 changed files with 28 additions and 28 deletions

View File

@ -74,7 +74,7 @@ public:
const std::vector<VideoDialog::VideoSourceInfo> generateVideoSourceInfos();
bool load(const std::string &romfile, const unsigned flags) { return gb.load(romfile, flags); }
int load(const std::string &romfile, const unsigned flags) { return gb.load(romfile, flags); }
void setGameGenie(const std::string &codes) { gb.setGameGenie(codes); }
void setGameShark(const std::string &codes) { gb.setGameShark(codes); }
void reset() { gb.reset(); }

View File

@ -41,15 +41,15 @@ public:
*
* @param romfile Path to rom image file. Typically a .gbc, .gb, or .zip-file (if zip-support is compiled in).
* @param flags ORed combination of LoadFlags.
* @return true if failed to load ROM image.
* @return 0 on success, negative value on failure.
*/
bool load(const std::string &romfile, unsigned flags = 0);
int load(const std::string &romfile, unsigned flags = 0);
/** Emulates until at least 'samples' stereo sound samples are produced in the supplied buffer,
* or until a video frame has been drawn.
*
* There are 35112 stereo sound samples in a video frame.
* May run for uptil 2064 stereo samples too long.
* May run for up to 2064 stereo samples too long.
* A stereo sample consists of two native endian 2s complement 16-bit PCM samples,
* with the left sample preceding the right one. Usually casting soundBuf to/from
* short* is OK and recommended. The reason for not using a short* in the interface

View File

@ -74,7 +74,7 @@ public:
memory.setOsdElement(osdElement);
}
bool load(const std::string &romfile, bool forceDmg, bool multicartCompat) {
int load(const std::string &romfile, bool forceDmg, bool multicartCompat) {
return memory.loadROM(romfile, forceDmg, multicartCompat);
}

View File

@ -88,11 +88,11 @@ void GB::setSaveDir(const std::string &sdir) {
p_->cpu.setSaveDir(sdir);
}
bool GB::load(const std::string &romfile, const unsigned flags) {
int GB::load(const std::string &romfile, const unsigned flags) {
if (p_->cpu.loaded())
p_->cpu.saveSavedata();
const bool failed = p_->cpu.load(romfile, flags & FORCE_DMG, flags & MULTICART_COMPAT);
const int failed = p_->cpu.load(romfile, flags & FORCE_DMG, flags & MULTICART_COMPAT);
if (!failed) {
SaveState state;

View File

@ -383,7 +383,7 @@ class Mbc5 : public DefaultMbc {
unsigned char rambank;
bool enableRam;
static unsigned adjustedRombank(const unsigned bank) { return bank ? bank : bank | 1; }
static unsigned adjustedRombank(const unsigned bank) { return bank ? bank : 1; }
void setRambank() const { memptrs.setRambank(enableRam ? MemPtrs::READ_EN | MemPtrs::WRITE_EN : 0, rambank & (rambanks(memptrs) - 1)); }
void setRombank() const { memptrs.setRombank(adjustedRombank(rombank & (rombanks(memptrs) - 1))); }
@ -503,11 +503,11 @@ static unsigned pow2ceil(unsigned n) {
return n;
}
bool Cartridge::loadROM(const std::string &romfile, const bool forceDmg, const bool multicartCompat) {
int Cartridge::loadROM(const std::string &romfile, const bool forceDmg, const bool multicartCompat) {
const std::auto_ptr<File> rom(newFileInstance(romfile));
if (rom->fail())
return 1;
return -1;
unsigned rambanks = 1;
unsigned rombanks = 2;
@ -527,28 +527,28 @@ bool Cartridge::loadROM(const std::string &romfile, const bool forceDmg, const b
case 0x06: std::puts("MBC2 ROM+BATTERY loaded."); type = MBC2; break;
case 0x08: std::puts("Plain ROM with additional RAM loaded."); type = PLAIN; break;
case 0x09: std::puts("Plain ROM with additional RAM and Battery loaded."); type = PLAIN; break;
case 0x0B: std::puts("MM01 ROM not supported."); return 1;
case 0x0C: std::puts("MM01 ROM not supported."); return 1;
case 0x0D: std::puts("MM01 ROM not supported."); return 1;
case 0x0B: std::puts("MM01 ROM not supported."); return -1;
case 0x0C: std::puts("MM01 ROM not supported."); return -1;
case 0x0D: std::puts("MM01 ROM not supported."); return -1;
case 0x0F: std::puts("MBC3 ROM+TIMER+BATTERY loaded."); type = MBC3; break;
case 0x10: std::puts("MBC3 ROM+TIMER+RAM+BATTERY loaded."); type = MBC3; break;
case 0x11: std::puts("MBC3 ROM loaded."); type = MBC3; break;
case 0x12: std::puts("MBC3 ROM+RAM loaded."); type = MBC3; break;
case 0x13: std::puts("MBC3 ROM+RAM+BATTERY loaded."); type = MBC3; break;
case 0x15: std::puts("MBC4 ROM not supported."); return 1;
case 0x16: std::puts("MBC4 ROM not supported."); return 1;
case 0x17: std::puts("MBC4 ROM not supported."); return 1;
case 0x15: std::puts("MBC4 ROM not supported."); return -1;
case 0x16: std::puts("MBC4 ROM not supported."); return -1;
case 0x17: std::puts("MBC4 ROM not supported."); return -1;
case 0x19: std::puts("MBC5 ROM loaded."); type = MBC5; break;
case 0x1A: std::puts("MBC5 ROM+RAM loaded."); type = MBC5; break;
case 0x1B: std::puts("MBC5 ROM+RAM+BATTERY loaded."); type = MBC5; break;
case 0x1C: std::puts("MBC5+RUMBLE ROM not supported."); type = MBC5; break;
case 0x1D: std::puts("MBC5+RUMBLE+RAM ROM not suported."); type = MBC5; break;
case 0x1E: std::puts("MBC5+RUMBLE+RAM+BATTERY ROM not supported."); type = MBC5; break;
case 0xFC: std::puts("Pocket Camera ROM not supported."); return 1;
case 0xFD: std::puts("Bandai TAMA5 ROM not supported."); return 1;
case 0xFE: std::puts("HuC3 ROM not supported."); return 1;
case 0xFC: std::puts("Pocket Camera ROM not supported."); return -1;
case 0xFD: std::puts("Bandai TAMA5 ROM not supported."); return -1;
case 0xFE: std::puts("HuC3 ROM not supported."); return -1;
case 0xFF: std::puts("HuC1 ROM+RAM+BATTERY loaded."); type = HUC1; break;
default: std::puts("Wrong data-format, corrupt or unsupported ROM."); return 1;
default: std::puts("Wrong data-format, corrupt or unsupported ROM."); return -1;
}
/*switch (header[0x0148]) {
@ -564,7 +564,7 @@ bool Cartridge::loadROM(const std::string &romfile, const bool forceDmg, const b
case 0x52: rombanks = 72; break;
case 0x53: rombanks = 80; break;
case 0x54: rombanks = 96; break;
default: return 1;
default: return -1;
}
std::printf("rombanks: %u\n", rombanks);*/
@ -611,7 +611,7 @@ bool Cartridge::loadROM(const std::string &romfile, const bool forceDmg, const b
enforce8bit(memptrs.romdata(), rombanks * 0x4000ul);
if (rom->fail())
return 1;
return -1;
defaultSaveBasePath = stripExtension(romfile);

View File

@ -83,7 +83,7 @@ public:
void saveSavedata();
const std::string saveBasePath() const;
void setSaveDir(const std::string &dir);
bool loadROM(const std::string &romfile, bool forceDmg, bool multicartCompat);
int loadROM(const std::string &romfile, bool forceDmg, bool multicartCompat);
const char * romTitle() const { return reinterpret_cast<const char *>(memptrs.romdata() + 0x134); }
void setGameGenie(const std::string &codes);
};

View File

@ -964,15 +964,15 @@ void Memory::nontrivial_write(const unsigned P, const unsigned data, const unsig
ioamhram[P - 0xFE00] = data;
}
bool Memory::loadROM(const std::string &romfile, const bool forceDmg, const bool multicartCompat) {
if (cart.loadROM(romfile, forceDmg, multicartCompat))
return true;
int Memory::loadROM(const std::string &romfile, const bool forceDmg, const bool multicartCompat) {
if (const int fail = cart.loadROM(romfile, forceDmg, multicartCompat))
return fail;
sound.init(cart.isCgb());
display.reset(ioamhram, cart.isCgb());
interrupter.setGameShark(std::string());
return false;
return 0;
}
unsigned Memory::fillSoundBuffer(const unsigned long cycleCounter) {

View File

@ -129,7 +129,7 @@ public:
unsigned long event(unsigned long cycleCounter);
unsigned long resetCounters(unsigned long cycleCounter);
bool loadROM(const std::string &romfile, bool forceDmg, bool multicartCompat);
int loadROM(const std::string &romfile, bool forceDmg, bool multicartCompat);
void setSaveDir(const std::string &dir) { cart.setSaveDir(dir); }
void setInputGetter(InputGetter *getInput) {