mirror of
https://github.com/open-goal/jak-project
synced 2026-08-16 13:17:34 -04:00
Add a bunch of #ifdefs to keep things working as expected on linux
This commit is contained in:
+96
-69
@@ -12,47 +12,59 @@
|
||||
namespace ee {
|
||||
|
||||
namespace {
|
||||
// constexpr int MAX_DECI2_PROTOCOLS = 4;
|
||||
// Deci2Driver protocols[MAX_DECI2_PROTOCOLS]; // info for each deci2 protocol registered
|
||||
// int protocol_count; // number of registered protocols
|
||||
// Deci2Driver* sending_driver; // currently sending protocol driver
|
||||
//::Deci2Server* server; // the server to send data to
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
constexpr int MAX_DECI2_PROTOCOLS = 4;
|
||||
Deci2Driver protocols[MAX_DECI2_PROTOCOLS]; // info for each deci2 protocol registered
|
||||
int protocol_count; // number of registered protocols
|
||||
Deci2Driver* sending_driver; // currently sending protocol driver
|
||||
::Deci2Server* server; // the server to send data to
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
|
||||
/*
|
||||
* Initialize the library.
|
||||
*/
|
||||
void LIBRARY_INIT_sceDeci2() {
|
||||
// // reset protocols
|
||||
// for (auto& p : protocols) {
|
||||
// p = Deci2Driver();
|
||||
// }
|
||||
// protocol_count = 0;
|
||||
// server = nullptr;
|
||||
// sending_driver = nullptr;
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
// reset protocols
|
||||
for (auto& p : protocols) {
|
||||
p = Deci2Driver();
|
||||
}
|
||||
protocol_count = 0;
|
||||
server = nullptr;
|
||||
sending_driver = nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* Run any pending requested sends.
|
||||
*/
|
||||
void LIBRARY_sceDeci2_run_sends() {
|
||||
return;
|
||||
// for (auto& prot : protocols) {
|
||||
// if (prot.active && prot.pending_send == 'H') {
|
||||
// sending_driver = &prot;
|
||||
// (prot.handler)(DECI2_WRITE, 0, prot.opt);
|
||||
// sending_driver = nullptr;
|
||||
// prot.pending_send = 0;
|
||||
// (prot.handler)(DECI2_WRITEDONE, 0, prot.opt);
|
||||
// }
|
||||
//}
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
for (auto& prot : protocols) {
|
||||
if (prot.active && prot.pending_send == 'H') {
|
||||
sending_driver = &prot;
|
||||
(prot.handler)(DECI2_WRITE, 0, prot.opt);
|
||||
sending_driver = nullptr;
|
||||
prot.pending_send = 0;
|
||||
(prot.handler)(DECI2_WRITEDONE, 0, prot.opt);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* Register a Deci2Server with this library.
|
||||
*/
|
||||
void LIBRARY_sceDeci2_register(::Deci2Server* s) {
|
||||
// server = s;
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
server = s;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -61,34 +73,40 @@ void LIBRARY_sceDeci2_register(::Deci2Server* s) {
|
||||
* I don't know why it's like this.
|
||||
*/
|
||||
s32 sceDeci2Open(u16 protocol, void* opt, void (*handler)(s32 event, s32 param, void* opt)) {
|
||||
// server->lock();
|
||||
// Deci2Driver drv;
|
||||
// drv.protocol = protocol;
|
||||
// drv.opt = opt;
|
||||
// drv.handler = handler;
|
||||
// drv.id = protocol_count + 1;
|
||||
// drv.active = true;
|
||||
// protocols[protocol_count++] = drv;
|
||||
// printf("[DECI2] Add new protocol driver %d for 0x%x\n", drv.id, drv.protocol);
|
||||
// server->unlock();
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
server->lock();
|
||||
Deci2Driver drv;
|
||||
drv.protocol = protocol;
|
||||
drv.opt = opt;
|
||||
drv.handler = handler;
|
||||
drv.id = protocol_count + 1;
|
||||
drv.active = true;
|
||||
protocols[protocol_count++] = drv;
|
||||
printf("[DECI2] Add new protocol driver %d for 0x%x\n", drv.id, drv.protocol);
|
||||
server->unlock();
|
||||
|
||||
// if (protocol_count == 1) {
|
||||
// // if we have our first protocol, inform the server we are ready to receive!
|
||||
// // then the server will accept incoming data.
|
||||
// server->send_proto_ready(protocols, &protocol_count);
|
||||
//}
|
||||
if (protocol_count == 1) {
|
||||
// if we have our first protocol, inform the server we are ready to receive!
|
||||
// then the server will accept incoming data.
|
||||
server->send_proto_ready(protocols, &protocol_count);
|
||||
}
|
||||
|
||||
// return drv.id;
|
||||
return drv.id;
|
||||
#elif _WIN32
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* Deactivate a DECI2 protocol by socket descriptor.
|
||||
*/
|
||||
s32 sceDeci2Close(s32 s) {
|
||||
// assert(s - 1 < protocol_count);
|
||||
// protocols[s - 1].active = false;
|
||||
// return 1;
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
assert(s - 1 < protocol_count);
|
||||
protocols[s - 1].active = false;
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -96,10 +114,12 @@ s32 sceDeci2Close(s32 s) {
|
||||
* Start a send.
|
||||
*/
|
||||
s32 sceDeci2ReqSend(s32 s, char dest) {
|
||||
// assert(s - 1 < protocol_count);
|
||||
// auto& proto = protocols[s - 1];
|
||||
// proto.pending_send = dest;
|
||||
// return 0;
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
assert(s - 1 < protocol_count);
|
||||
auto& proto = protocols[s - 1];
|
||||
proto.pending_send = dest;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -108,35 +128,42 @@ s32 sceDeci2ReqSend(s32 s, char dest) {
|
||||
* Returns after data is copied.
|
||||
*/
|
||||
s32 sceDeci2ExRecv(s32 s, void* buf, u16 len) {
|
||||
// assert(s - 1 < protocol_count);
|
||||
// protocols[s - 1].recv_size = len;
|
||||
// auto avail = protocols[s - 1].available_to_receive;
|
||||
// if (len <= avail) {
|
||||
// memcpy(buf, protocols[s - 1].recv_buffer, len);
|
||||
// return len;
|
||||
//} else {
|
||||
// printf("[DECI2] Error: ExRecv %d, only %d available!\n", len, avail);
|
||||
// return -1;
|
||||
//}
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
assert(s - 1 < protocol_count);
|
||||
protocols[s - 1].recv_size = len;
|
||||
auto avail = protocols[s - 1].available_to_receive;
|
||||
if (len <= avail) {
|
||||
memcpy(buf, protocols[s - 1].recv_buffer, len);
|
||||
return len;
|
||||
} else {
|
||||
printf("[DECI2] Error: ExRecv %d, only %d available!\n", len, avail);
|
||||
return -1;
|
||||
}
|
||||
#elif _WIN32
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* Do a send.
|
||||
*/
|
||||
s32 sceDeci2ExSend(s32 s, void* buf, u16 len) {
|
||||
// assert(s - 1 < protocol_count);
|
||||
// if (!sending_driver) {
|
||||
// printf("sceDeci2ExSend called at illegal time!\n");
|
||||
// }
|
||||
//
|
||||
// if (&protocols[s - 1] != sending_driver) {
|
||||
// printf("sceDeci2ExSend called with the wrong socket!\n");
|
||||
// }
|
||||
//
|
||||
// server->send_data(buf, len);
|
||||
// return len;
|
||||
return 0;
|
||||
}
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
assert(s - 1 < protocol_count);
|
||||
if (!sending_driver) {
|
||||
printf("sceDeci2ExSend called at illegal time!\n");
|
||||
}
|
||||
|
||||
if (&protocols[s - 1] != sending_driver) {
|
||||
printf("sceDeci2ExSend called with the wrong socket!\n");
|
||||
}
|
||||
|
||||
server->send_data(buf, len);
|
||||
return len;
|
||||
#elif _WIN32
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
} // namespace ee
|
||||
|
||||
Reference in New Issue
Block a user