-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlink.c
54 lines (42 loc) · 1.39 KB
/
link.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "link.h"
#include <string.h>
#include "state.h"
// bit 3 - 0000 1000
const natural SERIAL_INTERRUPT_MAP = 0x08;
/**
* Checks if gameboys serial control byte is indicating there is data to send.
* @param state gameboy state.
* @return true if gameboy is ready to transfer a byte.
*/
bool isRequestingTransfer() {
if (rootState.PlayerCount < 2) {
return false;
}
bool readyToSend = false;
for (byte i = 0; i < rootState.PlayerCount; i++) {
// If a game isn't ready, don't do anything yet.
// May be able to send even if this bit isn't set?
if (!rootState.Players[i].EmulationState.IsLinkTransferAvailable) {
return false;
}
// At least one game must be hosting the connection.
if (rootState.Players[i].EmulationState.IsLinkClockExternal) {
readyToSend = true;
}
}
return readyToSend;
}
/**
* Sends data between gameboy states, emulating serial link cable transfer.
* @param states the gameboys to send data between.
*/
void exchangeLinkData(GbState* states[2]) {
byte datum = states[0]->LinkData;
states[0]->LinkData = states[1]->LinkData;
states[1]->LinkData = datum;
states[0]->IsLinkTransferAvailable = false;
states[1]->IsLinkTransferAvailable = false;
// Prepare the serial interrupt
states[0]->LinkInterrupt = true;
states[1]->LinkInterrupt = true;
}