2011-10-05 09:37:00 +00:00
|
|
|
//SUNSOFT-5B
|
|
|
|
|
|
|
|
struct Sunsoft5B : Board {
|
2015-12-05 05:44:49 +00:00
|
|
|
Sunsoft5B(Markup::Node& document) : Board(document) {
|
|
|
|
}
|
2011-10-05 09:37:00 +00:00
|
|
|
|
2015-12-05 05:44:49 +00:00
|
|
|
struct Pulse {
|
|
|
|
auto clock() -> void {
|
|
|
|
if(--counter == 0) {
|
|
|
|
counter = frequency << 4;
|
|
|
|
duty ^= 1;
|
|
|
|
}
|
|
|
|
output = duty ? volume : (uint4)0;
|
|
|
|
if(disable) output = 0;
|
|
|
|
}
|
2011-10-05 09:37:00 +00:00
|
|
|
|
Update to v102r02 release.
byuu says:
Changelog:
- I caved on the `samples[] = {0.0}` thing, but I'm very unhappy about it
- if it's really invalid C++, then GCC needs to stop accepting it
in strict `-std=c++14` mode
- Emulator::Interface::Information::resettable is gone
- Emulator::Interface::reset() is gone
- FC, SFC, MD cores updated to remove soft reset behavior
- split GameBoy::Interface into GameBoyInterface,
GameBoyColorInterface
- split WonderSwan::Interface into WonderSwanInterface,
WonderSwanColorInterface
- PCE: fixed off-by-one scanline error [hex_usr]
- PCE: temporary hack to prevent crashing when VDS is set to < 2
- hiro: Cocoa: removed (u)int(#) constants; converted (u)int(#)
types to (u)int_(#)t types
- icarus: replaced usage of unique with strip instead (so we don't
mess up frameworks on macOS)
- libco: added macOS-specific section marker [Ryphecha]
So ... the major news this time is the removal of the soft reset
behavior. This is a major!! change that results in a 100KiB diff file,
and it's very prone to accidental mistakes!! If anyone is up for
testing, or even better -- looking over the code changes between v102r01
and v102r02 and looking for any issues, please do so. Ideally we'll want
to test every NES mapper type and every SNES coprocessor type by loading
said games and power cycling to make sure the games are all cleanly
resetting. It's too big of a change for me to cover there not being any
issues on my own, but this is truly critical code, so yeah ... please
help if you can.
We technically lose a bit of hardware documentation here. The soft reset
events do all kinds of interesting things in all kinds of different
chips -- or at least they do on the SNES. This is obviously not ideal.
But in the process of removing these portions of code, I found a few
mistakes I had made previously. It simplifies resetting the system state
a lot when not trying to have all the power() functions call the reset()
functions to share partial functionality.
In the future, the goal will be to come up with a way to add back in the
soft reset behavior via keyboard binding as with the Master System core.
What's going to have to happen is that the key binding will have to send
a "reset pulse" to every emulated chip, and those chips are going to
have to act independently to power() instead of reusing functionality.
We'll get there eventually, but there's many things of vastly greater
importance to work on right now, so it'll be a while. The information
isn't lost ... we'll just have to pull it out of v102 when we are ready.
Note that I left the SNES reset vector simulation code in, even though
it's not possible to trigger, for the time being.
Also ... the Super Game Boy core is still disconnected. To be honest, it
totally slipped my mind when I released v102 that it wasn't connected
again yet. This one's going to be pretty tricky to be honest. I'm
thinking about making a third GameBoy::Interface class just for SGB, and
coming up with some way of bypassing platform-> calls when in this
mode.
2017-01-22 21:04:26 +00:00
|
|
|
auto power() -> void {
|
2015-12-05 05:44:49 +00:00
|
|
|
disable = 1;
|
|
|
|
frequency = 1;
|
|
|
|
volume = 0;
|
2011-10-05 09:37:00 +00:00
|
|
|
|
2015-12-05 05:44:49 +00:00
|
|
|
counter = 0;
|
|
|
|
duty = 0;
|
|
|
|
output = 0;
|
|
|
|
}
|
2011-10-05 09:37:00 +00:00
|
|
|
|
2015-12-05 05:44:49 +00:00
|
|
|
auto serialize(serializer& s) -> void {
|
|
|
|
s.integer(disable);
|
|
|
|
s.integer(frequency);
|
|
|
|
s.integer(volume);
|
2011-10-05 09:37:00 +00:00
|
|
|
|
2015-12-05 05:44:49 +00:00
|
|
|
s.integer(counter);
|
|
|
|
s.integer(duty);
|
|
|
|
s.integer(output);
|
2011-10-05 09:37:00 +00:00
|
|
|
}
|
|
|
|
|
2015-12-05 05:44:49 +00:00
|
|
|
bool disable;
|
|
|
|
uint12 frequency;
|
|
|
|
uint4 volume;
|
2011-10-05 09:37:00 +00:00
|
|
|
|
2015-12-05 05:44:49 +00:00
|
|
|
uint16 counter; //12-bit countdown + 4-bit phase
|
|
|
|
uint1 duty;
|
|
|
|
uint4 output;
|
|
|
|
} pulse[3];
|
2011-10-05 09:37:00 +00:00
|
|
|
|
2015-12-05 05:44:49 +00:00
|
|
|
auto main() -> void {
|
2016-06-27 13:07:57 +00:00
|
|
|
if(irqCounterEnable) {
|
|
|
|
if(--irqCounter == 0xffff) {
|
|
|
|
cpu.irqLine(irqEnable);
|
2011-10-05 09:37:00 +00:00
|
|
|
}
|
2016-02-09 11:51:12 +00:00
|
|
|
}
|
2011-10-05 09:37:00 +00:00
|
|
|
|
2016-02-09 11:51:12 +00:00
|
|
|
pulse[0].clock();
|
|
|
|
pulse[1].clock();
|
|
|
|
pulse[2].clock();
|
|
|
|
int16 output = dac[pulse[0].output] + dac[pulse[1].output] + dac[pulse[2].output];
|
2016-06-27 13:07:57 +00:00
|
|
|
apu.setSample(-output);
|
2011-10-05 09:37:00 +00:00
|
|
|
|
2016-02-09 11:51:12 +00:00
|
|
|
tick();
|
2011-10-05 09:37:00 +00:00
|
|
|
}
|
|
|
|
|
2016-06-27 13:07:57 +00:00
|
|
|
auto readPRG(uint addr) -> uint8 {
|
2015-12-05 05:44:49 +00:00
|
|
|
if(addr < 0x6000) return cpu.mdr();
|
|
|
|
|
|
|
|
uint8 bank = 0x3f; //((addr & 0xe000) == 0xe000
|
2016-06-27 13:07:57 +00:00
|
|
|
if((addr & 0xe000) == 0x6000) bank = prgBank[0];
|
|
|
|
if((addr & 0xe000) == 0x8000) bank = prgBank[1];
|
|
|
|
if((addr & 0xe000) == 0xa000) bank = prgBank[2];
|
|
|
|
if((addr & 0xe000) == 0xc000) bank = prgBank[3];
|
2011-10-05 09:37:00 +00:00
|
|
|
|
2016-06-27 13:07:57 +00:00
|
|
|
bool ramEnable = bank & 0x80;
|
|
|
|
bool ramSelect = bank & 0x40;
|
2015-12-05 05:44:49 +00:00
|
|
|
bank &= 0x3f;
|
2011-10-05 09:37:00 +00:00
|
|
|
|
2016-06-27 13:07:57 +00:00
|
|
|
if(ramSelect) {
|
|
|
|
if(!ramEnable) return cpu.mdr();
|
2015-12-05 05:44:49 +00:00
|
|
|
return prgram.data[addr & 0x1fff];
|
|
|
|
}
|
2011-10-05 09:37:00 +00:00
|
|
|
|
2015-12-05 05:44:49 +00:00
|
|
|
addr = (bank << 13) | (addr & 0x1fff);
|
|
|
|
return prgrom.read(addr);
|
2011-10-05 09:37:00 +00:00
|
|
|
}
|
|
|
|
|
2016-06-27 13:07:57 +00:00
|
|
|
auto writePRG(uint addr, uint8 data) -> void {
|
2015-12-05 05:44:49 +00:00
|
|
|
if((addr & 0xe000) == 0x6000) {
|
|
|
|
prgram.data[addr & 0x1fff] = data;
|
|
|
|
}
|
2011-10-05 09:37:00 +00:00
|
|
|
|
2015-12-05 05:44:49 +00:00
|
|
|
if(addr == 0x8000) {
|
2016-06-27 13:07:57 +00:00
|
|
|
mmuPort = data & 0x0f;
|
2015-12-05 05:44:49 +00:00
|
|
|
}
|
2011-10-05 09:37:00 +00:00
|
|
|
|
2015-12-05 05:44:49 +00:00
|
|
|
if(addr == 0xa000) {
|
2016-06-27 13:07:57 +00:00
|
|
|
switch(mmuPort) {
|
|
|
|
case 0: chrBank[0] = data; break;
|
|
|
|
case 1: chrBank[1] = data; break;
|
|
|
|
case 2: chrBank[2] = data; break;
|
|
|
|
case 3: chrBank[3] = data; break;
|
|
|
|
case 4: chrBank[4] = data; break;
|
|
|
|
case 5: chrBank[5] = data; break;
|
|
|
|
case 6: chrBank[6] = data; break;
|
|
|
|
case 7: chrBank[7] = data; break;
|
|
|
|
case 8: prgBank[0] = data; break;
|
|
|
|
case 9: prgBank[1] = data; break;
|
|
|
|
case 10: prgBank[2] = data; break;
|
|
|
|
case 11: prgBank[3] = data; break;
|
2015-12-05 05:44:49 +00:00
|
|
|
case 12: mirror = data & 3; break;
|
|
|
|
case 13:
|
2016-06-27 13:07:57 +00:00
|
|
|
irqEnable = data & 0x80;
|
|
|
|
irqCounterEnable = data & 0x01;
|
|
|
|
if(irqEnable == 0) cpu.irqLine(0);
|
2015-12-05 05:44:49 +00:00
|
|
|
break;
|
2016-06-27 13:07:57 +00:00
|
|
|
case 14: irqCounter = (irqCounter & 0xff00) | (data << 0); break;
|
|
|
|
case 15: irqCounter = (irqCounter & 0x00ff) | (data << 8); break;
|
2015-12-05 05:44:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xc000) {
|
2016-06-27 13:07:57 +00:00
|
|
|
apuPort = data & 0x0f;
|
2015-12-05 05:44:49 +00:00
|
|
|
}
|
2011-10-05 09:37:00 +00:00
|
|
|
|
2015-12-05 05:44:49 +00:00
|
|
|
if(addr == 0xe000) {
|
2016-06-27 13:07:57 +00:00
|
|
|
switch(apuPort) {
|
2015-12-05 05:44:49 +00:00
|
|
|
case 0: pulse[0].frequency = (pulse[0].frequency & 0xff00) | (data << 0); break;
|
|
|
|
case 1: pulse[0].frequency = (pulse[0].frequency & 0x00ff) | (data << 8); break;
|
|
|
|
case 2: pulse[1].frequency = (pulse[1].frequency & 0xff00) | (data << 0); break;
|
|
|
|
case 3: pulse[1].frequency = (pulse[1].frequency & 0x00ff) | (data << 8); break;
|
|
|
|
case 4: pulse[2].frequency = (pulse[2].frequency & 0xff00) | (data << 0); break;
|
|
|
|
case 5: pulse[2].frequency = (pulse[2].frequency & 0x00ff) | (data << 8); break;
|
|
|
|
case 7:
|
|
|
|
pulse[0].disable = data & 0x01;
|
|
|
|
pulse[1].disable = data & 0x02;
|
|
|
|
pulse[2].disable = data & 0x04;
|
|
|
|
break;
|
|
|
|
case 8: pulse[0].volume = data & 0x0f; break;
|
|
|
|
case 9: pulse[1].volume = data & 0x0f; break;
|
|
|
|
case 10: pulse[2].volume = data & 0x0f; break;
|
|
|
|
}
|
2011-10-05 09:37:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-27 13:07:57 +00:00
|
|
|
auto addrCHR(uint addr) -> uint {
|
2015-12-05 05:44:49 +00:00
|
|
|
uint8 bank = (addr >> 10) & 7;
|
2016-06-27 13:07:57 +00:00
|
|
|
return (chrBank[bank] << 10) | (addr & 0x03ff);
|
2011-10-05 09:37:00 +00:00
|
|
|
}
|
|
|
|
|
2016-06-27 13:07:57 +00:00
|
|
|
auto addrCIRAM(uint addr) -> uint {
|
2015-12-05 05:44:49 +00:00
|
|
|
switch(mirror) {
|
|
|
|
case 0: return ((addr & 0x0400) >> 0) | (addr & 0x03ff); //vertical
|
|
|
|
case 1: return ((addr & 0x0800) >> 1) | (addr & 0x03ff); //horizontal
|
|
|
|
case 2: return 0x0000 | (addr & 0x03ff); //first
|
|
|
|
case 3: return 0x0400 | (addr & 0x03ff); //second
|
2011-10-05 09:37:00 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-05 05:44:49 +00:00
|
|
|
|
2016-06-27 13:07:57 +00:00
|
|
|
auto readCHR(uint addr) -> uint8 {
|
|
|
|
if(addr & 0x2000) return ppu.readCIRAM(addrCIRAM(addr));
|
|
|
|
return Board::readCHR(addrCHR(addr));
|
2015-12-05 05:44:49 +00:00
|
|
|
}
|
|
|
|
|
2016-06-27 13:07:57 +00:00
|
|
|
auto writeCHR(uint addr, uint8 data) -> void {
|
|
|
|
if(addr & 0x2000) return ppu.writeCIRAM(addrCIRAM(addr), data);
|
|
|
|
return Board::writeCHR(addrCHR(addr), data);
|
2011-10-05 09:37:00 +00:00
|
|
|
}
|
2015-12-05 05:44:49 +00:00
|
|
|
|
|
|
|
auto power() -> void {
|
Update to v102r02 release.
byuu says:
Changelog:
- I caved on the `samples[] = {0.0}` thing, but I'm very unhappy about it
- if it's really invalid C++, then GCC needs to stop accepting it
in strict `-std=c++14` mode
- Emulator::Interface::Information::resettable is gone
- Emulator::Interface::reset() is gone
- FC, SFC, MD cores updated to remove soft reset behavior
- split GameBoy::Interface into GameBoyInterface,
GameBoyColorInterface
- split WonderSwan::Interface into WonderSwanInterface,
WonderSwanColorInterface
- PCE: fixed off-by-one scanline error [hex_usr]
- PCE: temporary hack to prevent crashing when VDS is set to < 2
- hiro: Cocoa: removed (u)int(#) constants; converted (u)int(#)
types to (u)int_(#)t types
- icarus: replaced usage of unique with strip instead (so we don't
mess up frameworks on macOS)
- libco: added macOS-specific section marker [Ryphecha]
So ... the major news this time is the removal of the soft reset
behavior. This is a major!! change that results in a 100KiB diff file,
and it's very prone to accidental mistakes!! If anyone is up for
testing, or even better -- looking over the code changes between v102r01
and v102r02 and looking for any issues, please do so. Ideally we'll want
to test every NES mapper type and every SNES coprocessor type by loading
said games and power cycling to make sure the games are all cleanly
resetting. It's too big of a change for me to cover there not being any
issues on my own, but this is truly critical code, so yeah ... please
help if you can.
We technically lose a bit of hardware documentation here. The soft reset
events do all kinds of interesting things in all kinds of different
chips -- or at least they do on the SNES. This is obviously not ideal.
But in the process of removing these portions of code, I found a few
mistakes I had made previously. It simplifies resetting the system state
a lot when not trying to have all the power() functions call the reset()
functions to share partial functionality.
In the future, the goal will be to come up with a way to add back in the
soft reset behavior via keyboard binding as with the Master System core.
What's going to have to happen is that the key binding will have to send
a "reset pulse" to every emulated chip, and those chips are going to
have to act independently to power() instead of reusing functionality.
We'll get there eventually, but there's many things of vastly greater
importance to work on right now, so it'll be a while. The information
isn't lost ... we'll just have to pull it out of v102 when we are ready.
Note that I left the SNES reset vector simulation code in, even though
it's not possible to trigger, for the time being.
Also ... the Super Game Boy core is still disconnected. To be honest, it
totally slipped my mind when I released v102 that it wasn't connected
again yet. This one's going to be pretty tricky to be honest. I'm
thinking about making a third GameBoy::Interface class just for SGB, and
coming up with some way of bypassing platform-> calls when in this
mode.
2017-01-22 21:04:26 +00:00
|
|
|
for(int n : range(16)) {
|
2015-12-05 05:44:49 +00:00
|
|
|
double volume = 1.0 / pow(2, 1.0 / 2 * (15 - n));
|
|
|
|
dac[n] = volume * 8192.0;
|
|
|
|
}
|
2011-10-05 09:37:00 +00:00
|
|
|
|
2016-06-27 13:07:57 +00:00
|
|
|
mmuPort = 0;
|
|
|
|
apuPort = 0;
|
2015-12-05 05:44:49 +00:00
|
|
|
|
2016-06-27 13:07:57 +00:00
|
|
|
for(auto& n : prgBank) n = 0;
|
|
|
|
for(auto& n : chrBank) n = 0;
|
2015-12-05 05:44:49 +00:00
|
|
|
mirror = 0;
|
2016-06-27 13:07:57 +00:00
|
|
|
irqEnable = 0;
|
|
|
|
irqCounterEnable = 0;
|
|
|
|
irqCounter = 0;
|
2011-10-05 09:37:00 +00:00
|
|
|
|
Update to v102r02 release.
byuu says:
Changelog:
- I caved on the `samples[] = {0.0}` thing, but I'm very unhappy about it
- if it's really invalid C++, then GCC needs to stop accepting it
in strict `-std=c++14` mode
- Emulator::Interface::Information::resettable is gone
- Emulator::Interface::reset() is gone
- FC, SFC, MD cores updated to remove soft reset behavior
- split GameBoy::Interface into GameBoyInterface,
GameBoyColorInterface
- split WonderSwan::Interface into WonderSwanInterface,
WonderSwanColorInterface
- PCE: fixed off-by-one scanline error [hex_usr]
- PCE: temporary hack to prevent crashing when VDS is set to < 2
- hiro: Cocoa: removed (u)int(#) constants; converted (u)int(#)
types to (u)int_(#)t types
- icarus: replaced usage of unique with strip instead (so we don't
mess up frameworks on macOS)
- libco: added macOS-specific section marker [Ryphecha]
So ... the major news this time is the removal of the soft reset
behavior. This is a major!! change that results in a 100KiB diff file,
and it's very prone to accidental mistakes!! If anyone is up for
testing, or even better -- looking over the code changes between v102r01
and v102r02 and looking for any issues, please do so. Ideally we'll want
to test every NES mapper type and every SNES coprocessor type by loading
said games and power cycling to make sure the games are all cleanly
resetting. It's too big of a change for me to cover there not being any
issues on my own, but this is truly critical code, so yeah ... please
help if you can.
We technically lose a bit of hardware documentation here. The soft reset
events do all kinds of interesting things in all kinds of different
chips -- or at least they do on the SNES. This is obviously not ideal.
But in the process of removing these portions of code, I found a few
mistakes I had made previously. It simplifies resetting the system state
a lot when not trying to have all the power() functions call the reset()
functions to share partial functionality.
In the future, the goal will be to come up with a way to add back in the
soft reset behavior via keyboard binding as with the Master System core.
What's going to have to happen is that the key binding will have to send
a "reset pulse" to every emulated chip, and those chips are going to
have to act independently to power() instead of reusing functionality.
We'll get there eventually, but there's many things of vastly greater
importance to work on right now, so it'll be a while. The information
isn't lost ... we'll just have to pull it out of v102 when we are ready.
Note that I left the SNES reset vector simulation code in, even though
it's not possible to trigger, for the time being.
Also ... the Super Game Boy core is still disconnected. To be honest, it
totally slipped my mind when I released v102 that it wasn't connected
again yet. This one's going to be pretty tricky to be honest. I'm
thinking about making a third GameBoy::Interface class just for SGB, and
coming up with some way of bypassing platform-> calls when in this
mode.
2017-01-22 21:04:26 +00:00
|
|
|
pulse[0].power();
|
|
|
|
pulse[1].power();
|
|
|
|
pulse[2].power();
|
2015-12-05 05:44:49 +00:00
|
|
|
}
|
2011-10-05 09:37:00 +00:00
|
|
|
|
2015-12-05 05:44:49 +00:00
|
|
|
auto serialize(serializer& s) -> void {
|
|
|
|
Board::serialize(s);
|
2011-10-05 09:37:00 +00:00
|
|
|
|
2016-06-27 13:07:57 +00:00
|
|
|
s.integer(mmuPort);
|
|
|
|
s.integer(apuPort);
|
2011-10-05 09:37:00 +00:00
|
|
|
|
2016-06-27 13:07:57 +00:00
|
|
|
s.array(prgBank);
|
|
|
|
s.array(chrBank);
|
2015-12-05 05:44:49 +00:00
|
|
|
s.integer(mirror);
|
2016-06-27 13:07:57 +00:00
|
|
|
s.integer(irqEnable);
|
|
|
|
s.integer(irqCounterEnable);
|
|
|
|
s.integer(irqCounter);
|
2011-10-05 09:37:00 +00:00
|
|
|
|
2015-12-05 05:44:49 +00:00
|
|
|
pulse[0].serialize(s);
|
|
|
|
pulse[1].serialize(s);
|
|
|
|
pulse[2].serialize(s);
|
|
|
|
}
|
2011-10-05 09:37:00 +00:00
|
|
|
|
2016-06-27 13:07:57 +00:00
|
|
|
uint4 mmuPort;
|
|
|
|
uint4 apuPort;
|
2011-10-05 09:37:00 +00:00
|
|
|
|
2016-06-27 13:07:57 +00:00
|
|
|
uint8 prgBank[4];
|
|
|
|
uint8 chrBank[8];
|
2015-12-05 05:44:49 +00:00
|
|
|
uint2 mirror;
|
2016-06-27 13:07:57 +00:00
|
|
|
bool irqEnable;
|
|
|
|
bool irqCounterEnable;
|
|
|
|
uint16 irqCounter;
|
2011-10-05 09:37:00 +00:00
|
|
|
|
2015-12-05 05:44:49 +00:00
|
|
|
int16 dac[16];
|
2011-10-05 09:37:00 +00:00
|
|
|
};
|