Path: blob/master/libsnes/bsnes/snes/controller/controller.cpp
2 views
#include <snes/snes.hpp>12#define CONTROLLER_CPP3namespace SNES {45#include "gamepad/gamepad.cpp"6#include "multitap/multitap.cpp"7#include "mouse/mouse.cpp"8#include "superscope/superscope.cpp"9#include "justifier/justifier.cpp"10#include "usart/usart.cpp"1112void Controller::Enter() {13if(co_active() == input.port1->thread) input.port1->enter();14if(co_active() == input.port2->thread) input.port2->enter();15}1617void Controller::enter() {18while(true) step(1);19}2021void Controller::step(unsigned clocks) {22clock += clocks * (uint64)cpu.frequency;23synchronize_cpu();24}2526void Controller::synchronize_cpu() {27if(CPU::Threaded == true) {28if(clock >= 0 && scheduler.sync != Scheduler::SynchronizeMode::All) co_switch(cpu.thread);29} else {30while(clock >= 0) cpu.enter();31}32}3334bool Controller::iobit() {35switch(port) {36case Controller::Port1: return cpu.pio() & 0x40;37case Controller::Port2: return cpu.pio() & 0x80;38}39}4041void Controller::iobit(bool data) {42switch(port) {43case Controller::Port1: bus.write(0x4201, (cpu.pio() & ~0x40) | (data << 6)); break;44case Controller::Port2: bus.write(0x4201, (cpu.pio() & ~0x80) | (data << 7)); break;45}46}4748void Controller::serialize(serializer& s) {49Processor::serialize(s);50//Save a zero block.51unsigned char blockzeroes[SaveSize] = {0};52s.array(blockzeroes, SaveSize);53}5455Controller::Controller(bool port) : port(port) {56if(!thread) create(Controller::Enter, 1);57}585960}616263