Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libsnes/bsnes/snes/chip/icd2/interface/interface.cpp
2 views
1
#ifdef ICD2_CPP
2
3
//called on rendered lines 0-143 (not on Vblank lines 144-153)
4
void ICD2::lcdScanline() {
5
if((GameBoy::lcd.status.ly & 7) == 0) {
6
lcd.row = (lcd.row + 1) & 3;
7
}
8
9
unsigned offset = (lcd.row * 160 * 8) + ((GameBoy::lcd.status.ly & 7) * 160);
10
memcpy(lcd.buffer + offset, GameBoy::lcd.screen + GameBoy::lcd.status.ly * 160, 160 * sizeof(uint16));
11
}
12
13
void ICD2::joypWrite(bool p15, bool p14) {
14
//joypad handling
15
if(p15 == 1 && p14 == 1) {
16
if(joyp15lock == 0 && joyp14lock == 0) {
17
joyp15lock = 1;
18
joyp14lock = 1;
19
joyp_id = (joyp_id + 1) & 3;
20
}
21
}
22
23
if(p15 == 0 && p14 == 1) joyp15lock = 0;
24
if(p15 == 1 && p14 == 0) joyp14lock = 0;
25
26
//packet handling
27
if(p15 == 0 && p14 == 0) { //pulse
28
pulselock = false;
29
packetoffset = 0;
30
bitoffset = 0;
31
strobelock = true;
32
packetlock = false;
33
return;
34
}
35
36
if(pulselock) return;
37
38
if(p15 == 1 && p14 == 1) {
39
strobelock = false;
40
return;
41
}
42
43
if(strobelock) {
44
if(p15 == 1 || p14 == 1) { //malformed packet
45
packetlock = false;
46
pulselock = true;
47
bitoffset = 0;
48
packetoffset = 0;
49
} else {
50
return;
51
}
52
}
53
54
//p15:1, p14:0 = 0
55
//p15:0, p14:1 = 1
56
bool bit = (p15 == 0);
57
strobelock = true;
58
59
if(packetlock) {
60
if(p15 == 1 && p14 == 0) {
61
if((joyp_packet[0] >> 3) == 0x11) {
62
mlt_req = joyp_packet[1] & 3;
63
if(mlt_req == 2) mlt_req = 3;
64
joyp_id = 0;
65
}
66
67
if(packetsize < 64) packet[packetsize++] = joyp_packet;
68
packetlock = false;
69
pulselock = true;
70
}
71
return;
72
}
73
74
bitdata = (bit << 7) | (bitdata >> 1);
75
if(++bitoffset < 8) return;
76
77
bitoffset = 0;
78
joyp_packet[packetoffset] = bitdata;
79
if(++packetoffset < 16) return;
80
packetlock = true;
81
}
82
83
void ICD2::videoRefresh(const uint16_t *data) {
84
}
85
86
void ICD2::audioSample(int16_t center, int16_t left, int16_t right) {
87
audio.coprocessor_sample(left, right);
88
}
89
90
bool ICD2::inputPoll(unsigned id) {
91
GameBoy::cpu.status.mlt_req = joyp_id & mlt_req;
92
93
unsigned data = 0x00;
94
switch(joyp_id & mlt_req) {
95
case 0: data = ~r6004; break;
96
case 1: data = ~r6005; break;
97
case 2: data = ~r6006; break;
98
case 3: data = ~r6007; break;
99
}
100
101
switch((GameBoy::Input)id) {
102
case GameBoy::Input::Start: return data & 0x80;
103
case GameBoy::Input::Select: return data & 0x40;
104
case GameBoy::Input::B: return data & 0x20;
105
case GameBoy::Input::A: return data & 0x10;
106
case GameBoy::Input::Down: return data & 0x08;
107
case GameBoy::Input::Up: return data & 0x04;
108
case GameBoy::Input::Left: return data & 0x02;
109
case GameBoy::Input::Right: return data & 0x01;
110
}
111
112
return 0;
113
}
114
115
void* ICD2::allocSharedMemory(const char* memtype, size_t amt, int initialByte) { return SNES::interface()->allocSharedMemory(memtype, amt, initialByte); }
116
void ICD2::freeSharedMemory(void* ptr) { SNES::interface()->freeSharedMemory(ptr); }
117
118
#endif
119
120