Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libsnes/bsnes/snes/controller/controller.cpp
2 views
1
#include <snes/snes.hpp>
2
3
#define CONTROLLER_CPP
4
namespace SNES {
5
6
#include "gamepad/gamepad.cpp"
7
#include "multitap/multitap.cpp"
8
#include "mouse/mouse.cpp"
9
#include "superscope/superscope.cpp"
10
#include "justifier/justifier.cpp"
11
#include "usart/usart.cpp"
12
13
void Controller::Enter() {
14
if(co_active() == input.port1->thread) input.port1->enter();
15
if(co_active() == input.port2->thread) input.port2->enter();
16
}
17
18
void Controller::enter() {
19
while(true) step(1);
20
}
21
22
void Controller::step(unsigned clocks) {
23
clock += clocks * (uint64)cpu.frequency;
24
synchronize_cpu();
25
}
26
27
void Controller::synchronize_cpu() {
28
if(CPU::Threaded == true) {
29
if(clock >= 0 && scheduler.sync != Scheduler::SynchronizeMode::All) co_switch(cpu.thread);
30
} else {
31
while(clock >= 0) cpu.enter();
32
}
33
}
34
35
bool Controller::iobit() {
36
switch(port) {
37
case Controller::Port1: return cpu.pio() & 0x40;
38
case Controller::Port2: return cpu.pio() & 0x80;
39
}
40
}
41
42
void Controller::iobit(bool data) {
43
switch(port) {
44
case Controller::Port1: bus.write(0x4201, (cpu.pio() & ~0x40) | (data << 6)); break;
45
case Controller::Port2: bus.write(0x4201, (cpu.pio() & ~0x80) | (data << 7)); break;
46
}
47
}
48
49
void Controller::serialize(serializer& s) {
50
Processor::serialize(s);
51
//Save a zero block.
52
unsigned char blockzeroes[SaveSize] = {0};
53
s.array(blockzeroes, SaveSize);
54
}
55
56
Controller::Controller(bool port) : port(port) {
57
if(!thread) create(Controller::Enter, 1);
58
}
59
60
61
}
62
63