mirror of https://github.com/bsnes-emu/bsnes.git
47 lines
1.1 KiB
C++
47 lines
1.1 KiB
C++
#include <sfc/sfc.hpp>
|
|
|
|
namespace SuperFamicom {
|
|
|
|
#include "gamepad/gamepad.cpp"
|
|
#include "mouse/mouse.cpp"
|
|
#include "super-multitap/super-multitap.cpp"
|
|
#include "super-scope/super-scope.cpp"
|
|
#include "justifier/justifier.cpp"
|
|
|
|
Controller::Controller(bool port) : port(port) {
|
|
if(!handle()) create(Controller::Enter, 1);
|
|
}
|
|
|
|
Controller::~Controller() {
|
|
scheduler.remove(*this);
|
|
}
|
|
|
|
auto Controller::Enter() -> void {
|
|
while(true) {
|
|
scheduler.synchronize();
|
|
if(peripherals.controllerPort1->active()) peripherals.controllerPort1->main();
|
|
if(peripherals.controllerPort2->active()) peripherals.controllerPort2->main();
|
|
}
|
|
}
|
|
|
|
auto Controller::main() -> void {
|
|
step(1);
|
|
synchronize(cpu);
|
|
}
|
|
|
|
auto Controller::iobit() -> bool {
|
|
switch(port) {
|
|
case Controller::Port1: return cpu.pio() & 0x40;
|
|
case Controller::Port2: return cpu.pio() & 0x80;
|
|
}
|
|
}
|
|
|
|
auto Controller::iobit(bool data) -> void {
|
|
switch(port) {
|
|
case Controller::Port1: bus.write(0x4201, (cpu.pio() & ~0x40) | (data << 6)); break;
|
|
case Controller::Port2: bus.write(0x4201, (cpu.pio() & ~0x80) | (data << 7)); break;
|
|
}
|
|
}
|
|
|
|
}
|