mirror of
https://github.com/open-goal/jak-project
synced 2026-09-09 12:14:10 -04:00
Merge branch 'master' of https://github.com/water111/jak-project into w/ir
This commit is contained in:
+2
-3
@@ -76,11 +76,10 @@ add_executable(gk ${RUNTIME_SOURCE} main.cpp)
|
||||
# can be used to test other things.
|
||||
add_library(runtime ${RUNTIME_SOURCE})
|
||||
|
||||
|
||||
IF (WIN32)
|
||||
# set stuff for windows
|
||||
target_link_libraries(gk mman)
|
||||
target_link_libraries(gk cross_sockets mman)
|
||||
ELSE()
|
||||
# set stuff for other systems
|
||||
target_link_libraries(gk pthread)
|
||||
target_link_libraries(gk cross_sockets pthread)
|
||||
ENDIF()
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
*/
|
||||
|
||||
#include <cstring>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "game/sce/libscf.h"
|
||||
#include "kboot.h"
|
||||
@@ -152,21 +155,14 @@ void KernelCheckAndDispatch() {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
ClearPending();
|
||||
#endif
|
||||
|
||||
// if the listener function changed, it means the kernel ran it, so we should notify compiler.
|
||||
if (MasterDebug && ListenerFunction->value != old_listener) {
|
||||
SendAck();
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
Sleep(1000); // todo - remove this
|
||||
#elif __linux__
|
||||
usleep(1000);
|
||||
#endif
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(1000));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,6 @@ void kdsnetm_init_globals() {
|
||||
protoBlock.reset();
|
||||
}
|
||||
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
/*!
|
||||
* Register GOAL DECI2 Protocol Driver with DECI2 service
|
||||
* DONE, EXACT
|
||||
@@ -222,4 +220,3 @@ void GoalProtoStatus() {
|
||||
Msg(6, "gproto: got %d %d\n", protoBlock.most_recent_event, protoBlock.most_recent_param);
|
||||
Msg(6, "gproto: %d %d\n", protoBlock.last_receive_size, protoBlock.send_remaining);
|
||||
}
|
||||
#endif
|
||||
@@ -51,8 +51,6 @@ extern GoalProtoBlock protoBlock;
|
||||
*/
|
||||
void kdsnetm_init_globals();
|
||||
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
/*!
|
||||
* Register GOAL DECI2 Protocol Driver with DECI2 service
|
||||
* DONE, EXACT
|
||||
@@ -65,8 +63,6 @@ void InitGoalProto();
|
||||
*/
|
||||
void ShutdownGoalProto();
|
||||
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* Handle a DECI2 Protocol Event for the GOAL Proto.
|
||||
* Called by the DECI2 Protocol driver
|
||||
@@ -74,8 +70,6 @@ void ShutdownGoalProto();
|
||||
*/
|
||||
void GoalProtoHandler(int event, int param, void* data);
|
||||
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
/*!
|
||||
* Low level DECI2 send
|
||||
* Will block until send is complete.
|
||||
@@ -83,7 +77,6 @@ void GoalProtoHandler(int event, int param, void* data);
|
||||
* removed
|
||||
*/
|
||||
s32 SendFromBufferD(s32 p1, u64 p2, char* data, s32 size);
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* Print GOAL Protocol status
|
||||
|
||||
@@ -71,10 +71,7 @@ void ClearPending() {
|
||||
Ptr<char> msg = OutputBufArea.cast<char>() + sizeof(GoalMessageHeader);
|
||||
auto size = strlen(msg.c());
|
||||
// note - if size is ever greater than 2^16 this will cause an issue.
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
SendFromBuffer(msg.c(), size);
|
||||
#endif
|
||||
clear_output();
|
||||
}
|
||||
|
||||
@@ -87,10 +84,7 @@ void ClearPending() {
|
||||
if (send_size > 64000) {
|
||||
send_size = 64000;
|
||||
}
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
SendFromBufferD(2, 0, msg, send_size);
|
||||
#endif
|
||||
size -= send_size;
|
||||
msg += send_size;
|
||||
}
|
||||
@@ -109,11 +103,9 @@ void ClearPending() {
|
||||
*/
|
||||
void SendAck() {
|
||||
if (MasterDebug) {
|
||||
#ifdef __linux__
|
||||
SendFromBufferD(u16(ListenerMessageKind::MSG_ACK), protoBlock.msg_id,
|
||||
AckBufArea + sizeof(GoalMessageHeader),
|
||||
strlen(AckBufArea + sizeof(GoalMessageHeader)));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,4 +156,4 @@ void ProcessListenerMessage(Ptr<char> msg) {
|
||||
break;
|
||||
}
|
||||
SendAck();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,10 +329,7 @@ int InitMachine() {
|
||||
// }
|
||||
|
||||
if (MasterDebug) { // connect to GOAL compiler
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
InitGoalProto();
|
||||
#endif
|
||||
}
|
||||
|
||||
printf("InitSound\n");
|
||||
@@ -362,10 +359,7 @@ int ShutdownMachine() {
|
||||
StopIOP();
|
||||
CloseListener();
|
||||
ShutdownSound();
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
ShutdownGoalProto();
|
||||
#endif
|
||||
Msg(6, "kernel: machine shutdown");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -52,8 +52,6 @@ u32 ReceiveToBuffer(char* buff) {
|
||||
return msg_size;
|
||||
}
|
||||
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
/*!
|
||||
* Do a DECI2 send and block until it is complete.
|
||||
* The message type is OUTPUT
|
||||
@@ -62,7 +60,6 @@ u32 ReceiveToBuffer(char* buff) {
|
||||
s32 SendFromBuffer(char* buff, s32 size) {
|
||||
return SendFromBufferD(u16(ListenerMessageKind::MSG_OUTPUT), 0, buff, size);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* Just prepare the Ack buffer, doesn't actually connect.
|
||||
|
||||
+3
-12
@@ -12,7 +12,9 @@
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
#include <chrono>
|
||||
#include <cstring>
|
||||
#include <thread>
|
||||
|
||||
#include "runtime.h"
|
||||
#include "system/SystemThread.h"
|
||||
@@ -45,11 +47,6 @@
|
||||
|
||||
u8* g_ee_main_mem = nullptr;
|
||||
|
||||
/*!
|
||||
* TODO-WINDOWS
|
||||
* runtime.cpp - Deci2Listener has been disabled for now, pending rewriting for Windows.
|
||||
*/
|
||||
|
||||
namespace {
|
||||
|
||||
/*!
|
||||
@@ -57,8 +54,6 @@ namespace {
|
||||
*/
|
||||
|
||||
void deci2_runner(SystemThreadInterface& iface) {
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
// callback function so the server knows when to give up and shutdown
|
||||
std::function<bool()> shutdown_callback = [&]() { return iface.get_want_exit(); };
|
||||
|
||||
@@ -89,10 +84,9 @@ void deci2_runner(SystemThreadInterface& iface) {
|
||||
server.run();
|
||||
} else {
|
||||
// no connection yet. Do a sleep so we don't spam checking the listener.
|
||||
usleep(50000);
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(50000));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// EE System
|
||||
@@ -236,10 +230,7 @@ u32 exec_runtime(int argc, char** argv) {
|
||||
// step 1: sce library prep
|
||||
iop::LIBRARY_INIT();
|
||||
ee::LIBRARY_INIT_sceCd();
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
ee::LIBRARY_INIT_sceDeci2();
|
||||
#endif
|
||||
ee::LIBRARY_INIT_sceSif();
|
||||
|
||||
// step 2: system prep
|
||||
|
||||
@@ -12,14 +12,11 @@
|
||||
namespace ee {
|
||||
|
||||
namespace {
|
||||
// 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
|
||||
|
||||
@@ -27,8 +24,6 @@ Deci2Driver* sending_driver; // currently sending protocol drive
|
||||
* Initialize the library.
|
||||
*/
|
||||
void LIBRARY_INIT_sceDeci2() {
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
// reset protocols
|
||||
for (auto& p : protocols) {
|
||||
p = Deci2Driver();
|
||||
@@ -36,15 +31,12 @@ void LIBRARY_INIT_sceDeci2() {
|
||||
protocol_count = 0;
|
||||
server = nullptr;
|
||||
sending_driver = nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* Run any pending requested sends.
|
||||
*/
|
||||
void LIBRARY_sceDeci2_run_sends() {
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
for (auto& prot : protocols) {
|
||||
if (prot.active && prot.pending_send == 'H') {
|
||||
sending_driver = &prot;
|
||||
@@ -54,17 +46,13 @@ void LIBRARY_sceDeci2_run_sends() {
|
||||
(prot.handler)(DECI2_WRITEDONE, 0, prot.opt);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* Register a Deci2Server with this library.
|
||||
*/
|
||||
void LIBRARY_sceDeci2_register(::Deci2Server* s) {
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
server = s;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -73,8 +61,6 @@ 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)) {
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
server->lock();
|
||||
Deci2Driver drv;
|
||||
drv.protocol = protocol;
|
||||
@@ -93,20 +79,14 @@ s32 sceDeci2Open(u16 protocol, void* opt, void (*handler)(s32 event, s32 param,
|
||||
}
|
||||
|
||||
return drv.id;
|
||||
#elif _WIN32
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* Deactivate a DECI2 protocol by socket descriptor.
|
||||
*/
|
||||
s32 sceDeci2Close(s32 s) {
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
assert(s - 1 < protocol_count);
|
||||
protocols[s - 1].active = false;
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -114,12 +94,9 @@ s32 sceDeci2Close(s32 s) {
|
||||
* Start a send.
|
||||
*/
|
||||
s32 sceDeci2ReqSend(s32 s, char dest) {
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
assert(s - 1 < protocol_count);
|
||||
auto& proto = protocols[s - 1];
|
||||
proto.pending_send = dest;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -128,8 +105,6 @@ s32 sceDeci2ReqSend(s32 s, char dest) {
|
||||
* Returns after data is copied.
|
||||
*/
|
||||
s32 sceDeci2ExRecv(s32 s, void* buf, u16 len) {
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
assert(s - 1 < protocol_count);
|
||||
protocols[s - 1].recv_size = len;
|
||||
auto avail = protocols[s - 1].available_to_receive;
|
||||
@@ -140,17 +115,12 @@ s32 sceDeci2ExRecv(s32 s, void* buf, u16 len) {
|
||||
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) {
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
assert(s - 1 < protocol_count);
|
||||
if (!sending_driver) {
|
||||
printf("sceDeci2ExSend called at illegal time!\n");
|
||||
@@ -162,8 +132,5 @@ s32 sceDeci2ExSend(s32 s, void* buf, u16 len) {
|
||||
|
||||
server->send_data(buf, len);
|
||||
return len;
|
||||
#elif _WIN32
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
} // namespace ee
|
||||
|
||||
+48
-44
@@ -4,15 +4,22 @@
|
||||
* Works with deci2.cpp (sceDeci2) to implement the networking on target
|
||||
*/
|
||||
|
||||
// TODO-WINDOWS
|
||||
#ifdef __linux__
|
||||
|
||||
#include <cstdio>
|
||||
#include <cassert>
|
||||
#include <utility>
|
||||
|
||||
// TODO - i think im not including the dependency right..?
|
||||
#include "common/cross_sockets/xsocket.h"
|
||||
|
||||
#ifdef __linux
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <unistd.h>
|
||||
#include <cassert>
|
||||
#include <utility>
|
||||
#elif _WIN32
|
||||
#include <Windows.h>
|
||||
#include <WinSock2.h>
|
||||
#include <WS2tcpip.h>
|
||||
#endif
|
||||
|
||||
#include "common/listener_common.h"
|
||||
#include "common/versions.h"
|
||||
@@ -33,67 +40,58 @@ Deci2Server::~Deci2Server() {
|
||||
|
||||
delete[] buffer;
|
||||
|
||||
if (server_fd >= 0) {
|
||||
close(server_fd);
|
||||
}
|
||||
|
||||
if (new_sock >= 0) {
|
||||
close(new_sock);
|
||||
}
|
||||
close_server_socket();
|
||||
close_socket(new_sock);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Start waiting for the Listener to connect
|
||||
*/
|
||||
bool Deci2Server::init() {
|
||||
server_fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (server_fd < 0) {
|
||||
server_fd = -1;
|
||||
server_socket = open_socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (server_socket < 0) {
|
||||
server_socket = -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef __linux
|
||||
int server_socket_opt = SO_REUSEADDR | SO_REUSEPORT;
|
||||
#elif _WIN32
|
||||
int server_socket_opt = SO_EXCLUSIVEADDRUSE;
|
||||
#endif
|
||||
|
||||
int opt = 1;
|
||||
if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, &opt, sizeof(opt))) {
|
||||
printf("[Deci2Server] Failed to setsockopt 1\n");
|
||||
close(server_fd);
|
||||
server_fd = -1;
|
||||
if (set_socket_option(server_socket, SOL_SOCKET, server_socket_opt, &opt, sizeof(opt)) < 0) {
|
||||
close_server_socket();
|
||||
return false;
|
||||
}
|
||||
printf("[Deci2Server] Created Socket Options\n");
|
||||
|
||||
int one = 1;
|
||||
if (setsockopt(server_fd, SOL_TCP, TCP_NODELAY, &one, sizeof(one))) {
|
||||
printf("[Deci2Server] Failed to setsockopt 2\n");
|
||||
close(server_fd);
|
||||
server_fd = -1;
|
||||
if (set_socket_option(server_socket, TCP_SOCKET_LEVEL, TCP_NODELAY, &opt, sizeof(opt)) < 0) {
|
||||
close_server_socket();
|
||||
return false;
|
||||
}
|
||||
printf("[Deci2Server] Created TCP Socket Options\n");
|
||||
|
||||
timeval timeout = {};
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = 100000;
|
||||
|
||||
if (setsockopt(server_fd, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout)) < 0) {
|
||||
printf("[Deci2Server] Failed to setsockopt 3\n");
|
||||
close(server_fd);
|
||||
server_fd = -1;
|
||||
if (set_socket_timeout(server_socket, 100000) < 0) {
|
||||
close_server_socket();
|
||||
return false;
|
||||
}
|
||||
printf("[Deci2Server] Created Socket Timeout\n");
|
||||
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_addr.s_addr = INADDR_ANY;
|
||||
addr.sin_port = htons(DECI2_PORT);
|
||||
|
||||
if (bind(server_fd, (sockaddr*)&addr, sizeof(addr)) < 0) {
|
||||
if (bind(server_socket, (sockaddr*)&addr, sizeof(addr)) < 0) {
|
||||
printf("[Deci2Server] Failed to bind\n");
|
||||
close(server_fd);
|
||||
server_fd = -1;
|
||||
close_server_socket();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (listen(server_fd, 0) < 0) {
|
||||
if (listen(server_socket, 0) < 0) {
|
||||
printf("[Deci2Server] Failed to listen\n");
|
||||
close(server_fd);
|
||||
server_fd = -1;
|
||||
close_server_socket();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -104,6 +102,11 @@ bool Deci2Server::init() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void Deci2Server::close_server_socket() {
|
||||
close_socket(server_socket);
|
||||
server_socket = -1;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Return true if the listener is connected.
|
||||
*/
|
||||
@@ -129,7 +132,7 @@ void Deci2Server::send_data(void* buf, u16 len) {
|
||||
} else {
|
||||
uint16_t prog = 0;
|
||||
while (prog < len) {
|
||||
auto wrote = write(new_sock, (char*)(buf) + prog, len - prog);
|
||||
int wrote = write_to_socket(new_sock, (char*)(buf) + prog, len - prog);
|
||||
prog += wrote;
|
||||
if (!server_connected || want_exit()) {
|
||||
unlock();
|
||||
@@ -186,7 +189,7 @@ void Deci2Server::run() {
|
||||
|
||||
while (got < desired_size) {
|
||||
assert(got + desired_size < BUFFER_SIZE);
|
||||
auto x = read(new_sock, buffer + got, desired_size - got);
|
||||
auto x = read_from_socket(new_sock, buffer + got, desired_size - got);
|
||||
if (want_exit()) {
|
||||
return;
|
||||
}
|
||||
@@ -237,7 +240,7 @@ void Deci2Server::run() {
|
||||
|
||||
// receive from network
|
||||
if (hdr->rsvd < hdr->len) {
|
||||
auto x = read(new_sock, buffer + hdr->rsvd, hdr->len - hdr->rsvd);
|
||||
auto x = read_from_socket(new_sock, buffer + hdr->rsvd, hdr->len - hdr->rsvd);
|
||||
if (want_exit()) {
|
||||
return;
|
||||
}
|
||||
@@ -256,13 +259,14 @@ void Deci2Server::run() {
|
||||
void Deci2Server::accept_thread_func() {
|
||||
socklen_t l = sizeof(addr);
|
||||
while (!kill_accept_thread) {
|
||||
new_sock = accept(server_fd, (sockaddr*)&addr, &l);
|
||||
// TODO - might want to do a WSAStartUp call here as well, else it won't be balanced on the
|
||||
// close
|
||||
new_sock = accept(server_socket, (sockaddr*)&addr, &l);
|
||||
if (new_sock >= 0) {
|
||||
u32 versions[2] = {versions::GOAL_VERSION_MAJOR, versions::GOAL_VERSION_MINOR};
|
||||
send(new_sock, &versions, 8, 0); // todo, check result?
|
||||
write_to_socket(new_sock, (char*)&versions, 8); // todo, check result?
|
||||
server_connected = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -4,11 +4,14 @@
|
||||
* Works with deci2.cpp (sceDeci2) to implement the networking on target
|
||||
*/
|
||||
|
||||
#ifdef __linux__
|
||||
#ifndef JAK1_DECI2SERVER_H
|
||||
#define JAK1_DECI2SERVER_H
|
||||
|
||||
#ifdef __linux
|
||||
#include <netinet/in.h>
|
||||
#elif _WIN32
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
@@ -32,11 +35,12 @@ class Deci2Server {
|
||||
void run();
|
||||
|
||||
private:
|
||||
void close_server_socket();
|
||||
void accept_thread_func();
|
||||
bool kill_accept_thread = false;
|
||||
char* buffer = nullptr;
|
||||
int server_fd = -1;
|
||||
sockaddr_in addr;
|
||||
int server_socket = -1;
|
||||
struct sockaddr_in addr = {};
|
||||
int new_sock = -1;
|
||||
bool server_initialized = false;
|
||||
bool accept_thread_running = false;
|
||||
@@ -52,4 +56,3 @@ class Deci2Server {
|
||||
};
|
||||
|
||||
#endif // JAK1_DECI2SERVER_H
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user