Add files via upload
This commit is contained in:
parent
6e5eaba155
commit
e65393ec57
|
@ -29,9 +29,9 @@ GBEXPORT void gambatte_destroy(GB *g)
|
||||||
delete g;
|
delete g;
|
||||||
}
|
}
|
||||||
|
|
||||||
GBEXPORT int gambatte_load(GB *g, const char *romfiledata, unsigned romfilelength, long long now, unsigned flags)
|
GBEXPORT int gambatte_load(GB *g, const char *romfiledata, unsigned romfilelength, const char *biosfiledata, unsigned biosfilelength, long long now, unsigned flags)
|
||||||
{
|
{
|
||||||
int ret = g->load(romfiledata, romfilelength, now, flags);
|
int ret = g->load(romfiledata, romfilelength, biosfiledata, biosfilelength, now, flags);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,8 +96,12 @@ public:
|
||||||
memory.setRTCCallback(callback);
|
memory.setRTCCallback(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
int load(const char *romfiledata, unsigned romfilelength, bool forceDmg, bool multicartCompat) {
|
void reset_bios(int setting) {
|
||||||
return memory.loadROM(romfiledata, romfilelength, forceDmg, multicartCompat);
|
memory.bios_reset(setting);
|
||||||
|
}
|
||||||
|
|
||||||
|
int load(const char *romfiledata, unsigned romfilelength, const char *biosfiledata, unsigned biosfilelength, bool forceDmg, bool multicartCompat) {
|
||||||
|
return memory.loadROM(romfiledata, romfilelength, biosfiledata, biosfilelength, forceDmg, multicartCompat);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool loaded() const { return memory.loaded(); }
|
bool loaded() const { return memory.loaded(); }
|
||||||
|
|
|
@ -94,7 +94,15 @@ void GB::reset(const std::uint32_t now) {
|
||||||
|
|
||||||
SaveState state;
|
SaveState state;
|
||||||
p_->cpu.setStatePtrs(state);
|
p_->cpu.setStatePtrs(state);
|
||||||
setInitState(state, p_->cpu.isCgb(), p_->gbaCgbMode, now);
|
if (use_bios)
|
||||||
|
{
|
||||||
|
p_->cpu.reset_bios(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
setInitState(state, p_->cpu.isCgb(), p_->gbaCgbMode, now, use_bios);
|
||||||
p_->cpu.loadState(state);
|
p_->cpu.loadState(state);
|
||||||
if (length > 0)
|
if (length > 0)
|
||||||
{
|
{
|
||||||
|
@ -136,16 +144,17 @@ void GB::setRTCCallback(std::uint32_t (*callback)()) {
|
||||||
p_->cpu.setRTCCallback(callback);
|
p_->cpu.setRTCCallback(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
int GB::load(const char *romfiledata, unsigned romfilelength, const std::uint32_t now, const unsigned flags) {
|
int GB::load(const char *romfiledata, unsigned romfilelength, const char *biosfiledata, unsigned biosfilelength, const std::uint32_t now, const unsigned flags) {
|
||||||
//if (p_->cpu.loaded())
|
//if (p_->cpu.loaded())
|
||||||
// p_->cpu.saveSavedata();
|
// p_->cpu.saveSavedata();
|
||||||
|
|
||||||
const int failed = p_->cpu.load(romfiledata, romfilelength, flags & FORCE_DMG, flags & MULTICART_COMPAT);
|
const int failed = p_->cpu.load(romfiledata, romfilelength, biosfiledata, biosfilelength, flags & FORCE_DMG, flags & MULTICART_COMPAT);
|
||||||
|
use_bios = biosfilelength > 0 ? true : false;
|
||||||
|
|
||||||
if (!failed) {
|
if (!failed) {
|
||||||
SaveState state;
|
SaveState state;
|
||||||
p_->cpu.setStatePtrs(state);
|
p_->cpu.setStatePtrs(state);
|
||||||
setInitState(state, p_->cpu.isCgb(), p_->gbaCgbMode = flags & GBA_CGB, now);
|
setInitState(state, p_->cpu.isCgb(), p_->gbaCgbMode = flags & GBA_CGB, now, use_bios);
|
||||||
p_->cpu.loadState(state);
|
p_->cpu.loadState(state);
|
||||||
//p_->cpu.loadSavedata();
|
//p_->cpu.loadSavedata();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1146,7 +1146,7 @@ static void setInitialDmgIoamhram(unsigned char *const ioamhram) {
|
||||||
|
|
||||||
} // anon namespace
|
} // anon namespace
|
||||||
|
|
||||||
void gambatte::setInitState(SaveState &state, const bool cgb, const bool gbaCgbMode, const std::uint32_t now) {
|
void gambatte::setInitState(SaveState &state, const bool cgb, const bool gbaCgbMode, const std::uint32_t now, bool boot_bios) {
|
||||||
static const unsigned char cgbObjpDump[0x40] = {
|
static const unsigned char cgbObjpDump[0x40] = {
|
||||||
0x00, 0x00, 0xF2, 0xAB,
|
0x00, 0x00, 0xF2, 0xAB,
|
||||||
0x61, 0xC2, 0xD9, 0xBA,
|
0x61, 0xC2, 0xD9, 0xBA,
|
||||||
|
@ -1166,7 +1166,26 @@ void gambatte::setInitState(SaveState &state, const bool cgb, const bool gbaCgbM
|
||||||
0x83, 0x40, 0x0B, 0x77
|
0x83, 0x40, 0x0B, 0x77
|
||||||
};
|
};
|
||||||
|
|
||||||
state.cpu.cycleCounter = cgb ? 0x102A0 : 0x102A0 + 0x8D2C;
|
if (boot_bios)
|
||||||
|
{
|
||||||
|
state.cpu.PC = 0x00;
|
||||||
|
state.cpu.SP = 0xFFFF;
|
||||||
|
state.cpu.A = 0;
|
||||||
|
state.cpu.B = 0;
|
||||||
|
state.cpu.C = 0x0;
|
||||||
|
state.cpu.D = 0x0;
|
||||||
|
state.cpu.E = 0x0;
|
||||||
|
state.cpu.F = 0x0;
|
||||||
|
state.cpu.H = 0x0;
|
||||||
|
state.cpu.L = 0x0;
|
||||||
|
state.cpu.skip = false;
|
||||||
|
state.cpu.cycleCounter = 0;
|
||||||
|
state.mem.ioamhram.ptr[0x140] = 0x00;
|
||||||
|
state.mem.ioamhram.ptr[0x104] = 0x00;
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
state.cpu.PC = 0x100;
|
state.cpu.PC = 0x100;
|
||||||
state.cpu.SP = 0xFFFE;
|
state.cpu.SP = 0xFFFE;
|
||||||
state.cpu.A = cgb * 0x10 | 0x01;
|
state.cpu.A = cgb * 0x10 | 0x01;
|
||||||
|
@ -1178,10 +1197,16 @@ void gambatte::setInitState(SaveState &state, const bool cgb, const bool gbaCgbM
|
||||||
state.cpu.H = 0x01;
|
state.cpu.H = 0x01;
|
||||||
state.cpu.L = 0x4D;
|
state.cpu.L = 0x4D;
|
||||||
state.cpu.skip = false;
|
state.cpu.skip = false;
|
||||||
|
setInitialVram(state.mem.vram.ptr, cgb);
|
||||||
|
state.cpu.cycleCounter = cgb ? 0x102A0 : 0x102A0 + 0x8D2C;
|
||||||
|
state.mem.ioamhram.ptr[0x140] = 0x91;
|
||||||
|
state.mem.ioamhram.ptr[0x104] = 0x1C;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
std::memset(state.mem.sram.ptr, 0xFF, state.mem.sram.getSz());
|
std::memset(state.mem.sram.ptr, 0xFF, state.mem.sram.getSz());
|
||||||
|
|
||||||
setInitialVram(state.mem.vram.ptr, cgb);
|
|
||||||
|
|
||||||
if (cgb) {
|
if (cgb) {
|
||||||
setInitialCgbWram(state.mem.wram.ptr);
|
setInitialCgbWram(state.mem.wram.ptr);
|
||||||
|
@ -1191,8 +1216,6 @@ void gambatte::setInitState(SaveState &state, const bool cgb, const bool gbaCgbM
|
||||||
setInitialDmgIoamhram(state.mem.ioamhram.ptr);
|
setInitialDmgIoamhram(state.mem.ioamhram.ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
state.mem.ioamhram.ptr[0x104] = 0x1C;
|
|
||||||
state.mem.ioamhram.ptr[0x140] = 0x91;
|
|
||||||
state.mem.ioamhram.ptr[0x144] = 0x00;
|
state.mem.ioamhram.ptr[0x144] = 0x00;
|
||||||
|
|
||||||
state.mem.divLastUpdate = 0;
|
state.mem.divLastUpdate = 0;
|
||||||
|
@ -1258,7 +1281,6 @@ void gambatte::setInitState(SaveState &state, const bool cgb, const bool gbaCgbM
|
||||||
state.ppu.oldWy = state.mem.ioamhram.get()[0x14A];
|
state.ppu.oldWy = state.mem.ioamhram.get()[0x14A];
|
||||||
state.ppu.pendingLcdstatIrq = false;
|
state.ppu.pendingLcdstatIrq = false;
|
||||||
|
|
||||||
|
|
||||||
state.spu.cycleCounter = 0x1000 | (state.cpu.cycleCounter >> 1 & 0xFFF); // spu.cycleCounter >> 12 & 7 represents the frame sequencer position.
|
state.spu.cycleCounter = 0x1000 | (state.cpu.cycleCounter >> 1 & 0xFFF); // spu.cycleCounter >> 12 & 7 represents the frame sequencer position.
|
||||||
|
|
||||||
state.spu.ch1.sweep.counter = SoundUnit::COUNTER_DISABLED;
|
state.spu.ch1.sweep.counter = SoundUnit::COUNTER_DISABLED;
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace gambatte {
|
namespace gambatte {
|
||||||
void setInitState(struct SaveState &state, bool cgb, bool gbaCgbMode, std::uint32_t now);
|
void setInitState(struct SaveState &state, bool cgb, bool gbaCgbMode, std::uint32_t now, bool boot_bios);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -868,6 +868,11 @@ void Memory::nontrivial_ff_write(const unsigned P, unsigned data, const unsigned
|
||||||
ioamhram[0x14F] = 0xFE | data;
|
ioamhram[0x14F] = 0xFE | data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
case 0x50:
|
||||||
|
// this is the register that turns off the bootrom
|
||||||
|
// it can only ever be written to once (with 1) once boot rom finishes
|
||||||
|
cart.bios_remap(data);
|
||||||
return;
|
return;
|
||||||
case 0x51:
|
case 0x51:
|
||||||
dmaSource = data << 8 | (dmaSource & 0xFF);
|
dmaSource = data << 8 | (dmaSource & 0xFF);
|
||||||
|
@ -1008,8 +1013,8 @@ void Memory::nontrivial_write(const unsigned P, const unsigned data, const unsig
|
||||||
ioamhram[P - 0xFE00] = data;
|
ioamhram[P - 0xFE00] = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Memory::loadROM(const char *romfiledata, unsigned romfilelength, const bool forceDmg, const bool multicartCompat) {
|
int Memory::loadROM(const char *romfiledata, unsigned romfilelength, const char *biosfiledata, unsigned biosfilelength, const bool forceDmg, const bool multicartCompat) {
|
||||||
if (const int fail = cart.loadROM(romfiledata, romfilelength, forceDmg, multicartCompat))
|
if (const int fail = cart.loadROM(romfiledata, romfilelength, biosfiledata, biosfilelength, forceDmg, multicartCompat))
|
||||||
return fail;
|
return fail;
|
||||||
|
|
||||||
sound.init(cart.isCgb());
|
sound.init(cart.isCgb());
|
||||||
|
|
|
@ -87,6 +87,10 @@ public:
|
||||||
bool loaded() const { return cart.loaded(); }
|
bool loaded() const { return cart.loaded(); }
|
||||||
const char * romTitle() const { return cart.romTitle(); }
|
const char * romTitle() const { return cart.romTitle(); }
|
||||||
|
|
||||||
|
void bios_reset(int setting) {
|
||||||
|
nontrivial_ff_write(0x50, setting, 0);
|
||||||
|
}
|
||||||
|
|
||||||
int debugGetLY() const { return display.debugGetLY(); }
|
int debugGetLY() const { return display.debugGetLY(); }
|
||||||
|
|
||||||
void setStatePtrs(SaveState &state);
|
void setStatePtrs(SaveState &state);
|
||||||
|
@ -244,7 +248,7 @@ public:
|
||||||
unsigned long event(unsigned long cycleCounter);
|
unsigned long event(unsigned long cycleCounter);
|
||||||
unsigned long resetCounters(unsigned long cycleCounter);
|
unsigned long resetCounters(unsigned long cycleCounter);
|
||||||
|
|
||||||
int loadROM(const char *romfiledata, unsigned romfilelength, bool forceDmg, bool multicartCompat);
|
int loadROM(const char *romfiledata, unsigned romfilelength, const char *biosfiledata, unsigned biosfilelength, bool forceDmg, bool multicartCompat);
|
||||||
|
|
||||||
void setInputGetter(unsigned (*getInput)()) {
|
void setInputGetter(unsigned (*getInput)()) {
|
||||||
this->getInput = getInput;
|
this->getInput = getInput;
|
||||||
|
|
|
@ -38,7 +38,7 @@ struct SaveState {
|
||||||
void set(T *ptr, const unsigned long sz) { this->ptr = ptr; this->sz = sz; }
|
void set(T *ptr, const unsigned long sz) { this->ptr = ptr; this->sz = sz; }
|
||||||
|
|
||||||
friend class SaverList;
|
friend class SaverList;
|
||||||
friend void setInitState(SaveState &, bool, bool, std::uint32_t);
|
friend void setInitState(SaveState &, bool, bool, std::uint32_t, bool);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CPU {
|
struct CPU {
|
||||||
|
|
Loading…
Reference in New Issue