bsnes/higan/ws/system/system.cpp
Tim Allen bf90bdfcc8 Update to v101r31 release.
byuu says:

Changelog:

  - converted Emulator::Interface::Bind to Emulator::Platform
  - temporarily disabled SGB hooks
  - SMS: emulated Game Gear palette (latching word-write behavior not
    implemented yet)
  - SMS: emulated Master System 'Reset' button, Game Gear 'Start' button
  - SMS: removed reset() functionality, driven by the mappable input now
    instead
  - SMS: split interface class in two: one for Master System, one for
    Game Gear
  - SMS: emulated Game Gear video cropping to 160x144
  - PCE: started on HuC6280 CPU core—so far only registers, NOP
    instruction has been implemented

Errata:

  - Super Game Boy support is broken and thus disabled
  - if you switch between Master System and Game Gear without
    restarting, bad things happen:
      - SMS→GG, no video output on the GG
      - GG→SMS, no input on the SMS

I'm not sure what's causing the SMS\<-\>GG switch bug, having a hard
time debugging it. Help would be very much appreciated, if anyone's up
for it. Otherwise I'll keep trying to track it down on my end.
2017-01-13 12:15:45 +11:00

136 lines
3.3 KiB
C++

#include <ws/ws.hpp>
namespace WonderSwan {
System system;
Scheduler scheduler;
Cheat cheat;
#include "io.cpp"
#include "video.cpp"
#include "serialization.cpp"
auto System::init() -> void {
assert(interface != nullptr);
}
auto System::term() -> void {
}
auto System::load(Emulator::Interface* interface, Model model) -> bool {
_model = model;
if(auto fp = platform->open(ID::System, "manifest.bml", File::Read, File::Required)) {
information.manifest = fp->reads();
} else return false;
auto document = BML::unserialize(information.manifest);
//note: IPLROM is currently undumped; otherwise we'd load it here ...
if(auto node = document["system/eeprom"]) {
eeprom.setName(node["name"].text());
eeprom.setSize(node["size"].natural() / sizeof(uint16));
eeprom.erase();
//initialize user-data section
for(uint addr = 0x0030; addr <= 0x003a; addr++) eeprom[addr] = 0x0000;
if(auto fp = platform->open(ID::System, eeprom.name(), File::Read)) {
fp->read(eeprom.data(), eeprom.size());
}
}
if(!cartridge.load()) return false;
serializeInit();
_orientation = cartridge.information.orientation;
this->interface = interface;
return _loaded = true;
}
auto System::save() -> void {
if(!loaded()) return;
cartridge.save();
}
auto System::unload() -> void {
if(!loaded()) return;
eeprom.setName("");
eeprom.setSize(0);
cartridge.unload();
_loaded = false;
}
auto System::power() -> void {
Emulator::video.reset();
Emulator::video.setInterface(interface);
configureVideoPalette();
configureVideoEffects();
Emulator::audio.reset();
Emulator::audio.setInterface(interface);
scheduler.reset();
bus.power();
iram.power();
eeprom.power();
cpu.power();
ppu.power();
apu.power();
cartridge.power();
scheduler.primary(cpu);
bus.map(this, 0x0060);
bus.map(this, 0x00ba, 0x00be);
r.unknown = 0;
r.format = 0;
r.depth = 0;
r.color = 0;
}
auto System::run() -> void {
if(scheduler.enter() == Scheduler::Event::Frame) ppu.refresh();
pollKeypad();
}
auto System::runToSave() -> void {
scheduler.synchronize(cpu);
scheduler.synchronize(ppu);
scheduler.synchronize(apu);
scheduler.synchronize(cartridge);
}
auto System::pollKeypad() -> void {
uint port = !_orientation ? ID::Port::HardwareHorizontal : ID::Port::HardwareVertical;
uint device = ID::Device::Controls;
bool rotate = keypad.rotate;
keypad.y1 = platform->inputPoll(port, device, 0);
keypad.y2 = platform->inputPoll(port, device, 1);
keypad.y3 = platform->inputPoll(port, device, 2);
keypad.y4 = platform->inputPoll(port, device, 3);
keypad.x1 = platform->inputPoll(port, device, 4);
keypad.x2 = platform->inputPoll(port, device, 5);
keypad.x3 = platform->inputPoll(port, device, 6);
keypad.x4 = platform->inputPoll(port, device, 7);
keypad.b = platform->inputPoll(port, device, 8);
keypad.a = platform->inputPoll(port, device, 9);
keypad.start = platform->inputPoll(port, device, 10);
keypad.rotate = platform->inputPoll(port, device, 11);
if(keypad.y1 || keypad.y2 || keypad.y3 || keypad.y4
|| keypad.x1 || keypad.x2 || keypad.x3 || keypad.x4
|| keypad.b || keypad.a || keypad.start
) {
cpu.raise(CPU::Interrupt::Input);
}
if(!rotate && keypad.rotate) {
_orientation = !_orientation;
}
}
}