mirror of
https://github.com/open-goal/jak-project.git
synced 2024-10-20 00:57:44 -04:00
commit
0e5d5ee10e
|
@ -25,6 +25,10 @@ if(CMAKE_COMPILER_IS_GNUCXX)
|
|||
-Wsign-promo")
|
||||
endif(CMAKE_COMPILER_IS_GNUCXX)
|
||||
|
||||
IF (WIN32)
|
||||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||
ENDIF()
|
||||
|
||||
# includes relative to top level jak-project folder
|
||||
include_directories(./)
|
||||
|
||||
|
@ -53,4 +57,9 @@ add_subdirectory(test)
|
|||
add_subdirectory(third-party/minilzo)
|
||||
|
||||
# build format library
|
||||
add_subdirectory(third-party/fmt)
|
||||
add_subdirectory(third-party/fmt)
|
||||
|
||||
# windows memory management lib
|
||||
IF (WIN32)
|
||||
add_subdirectory(third-party/mman)
|
||||
ENDIF()
|
|
@ -74,7 +74,7 @@ add_library(runtime ${RUNTIME_SOURCE})
|
|||
|
||||
IF (WIN32)
|
||||
# set stuff for windows
|
||||
target_link_libraries(gk)
|
||||
target_link_libraries(gk mman)
|
||||
ELSE()
|
||||
# set stuff for other systems
|
||||
target_link_libraries(gk pthread)
|
||||
|
|
|
@ -46,44 +46,42 @@ namespace {
|
|||
*/
|
||||
|
||||
|
||||
/*
|
||||
|
||||
void deci2_runner(SystemThreadInterface& interfaces) {
|
||||
// callback function so the server knows when to give up and shutdown
|
||||
std::function<bool()> shutdown_callback = [&]() { return interfaces.get_want_exit(); };
|
||||
|
||||
// create and register server
|
||||
// Deci2Server server(shutdown_callback);
|
||||
// ee::LIBRARY_sceDeci2_register(&server);
|
||||
|
||||
// now its ok to continue with initialization
|
||||
interfaces.initialization_complete();
|
||||
|
||||
// in our own thread, wait for the EE to register the first protocol driver
|
||||
printf("[DECI2] waiting for EE to register protos\n");
|
||||
server.wait_for_protos_ready();
|
||||
// then allow the server to accept connections
|
||||
if (!server.init()) {
|
||||
throw std::exception("DECI2 server init failed");
|
||||
}
|
||||
|
||||
printf("[DECI2] waiting for listener...\n");
|
||||
bool saw_listener = false;
|
||||
while (!interfaces.get_want_exit()) {
|
||||
if (server.check_for_listener()) {
|
||||
if (!saw_listener) {
|
||||
printf("[DECI2] Connected!\n");
|
||||
}
|
||||
saw_listener = true;
|
||||
// we have a listener, run!
|
||||
server.run();
|
||||
} else {
|
||||
// no connection yet. Do a sleep so we don't spam checking the listener.
|
||||
Sleep(1000);
|
||||
}
|
||||
}
|
||||
// // callback function so the server knows when to give up and shutdown
|
||||
// std::function<bool()> shutdown_callback = [&]() { return interfaces.get_want_exit(); };
|
||||
//
|
||||
// // create and register server
|
||||
//// Deci2Server server(shutdown_callback);
|
||||
//// ee::LIBRARY_sceDeci2_register(&server);
|
||||
//
|
||||
// // now its ok to continue with initialization
|
||||
// interfaces.initialization_complete();
|
||||
//
|
||||
// // in our own thread, wait for the EE to register the first protocol driver
|
||||
// printf("[DECI2] waiting for EE to register protos\n");
|
||||
// server.wait_for_protos_ready();
|
||||
// // then allow the server to accept connections
|
||||
// if (!server.init()) {
|
||||
// throw std::exception("DECI2 server init failed");
|
||||
// }
|
||||
//
|
||||
// printf("[DECI2] waiting for listener...\n");
|
||||
// bool saw_listener = false;
|
||||
// while (!interfaces.get_want_exit()) {
|
||||
// if (server.check_for_listener()) {
|
||||
// if (!saw_listener) {
|
||||
// printf("[DECI2] Connected!\n");
|
||||
// }
|
||||
// saw_listener = true;
|
||||
// // we have a listener, run!
|
||||
// server.run();
|
||||
// } else {
|
||||
// // no connection yet. Do a sleep so we don't spam checking the listener.
|
||||
// Sleep(1000);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// EE System
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*!
|
||||
* @file deci2.cpp
|
||||
* Implementation of SCE DECI2 library.
|
||||
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
|
@ -12,127 +12,131 @@
|
|||
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
|
||||
// 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
|
||||
} // namespace
|
||||
|
||||
|
||||
/*
|
||||
* Initialize the library.
|
||||
|
||||
*/
|
||||
void LIBRARY_INIT_sceDeci2() {
|
||||
// reset protocols
|
||||
for (auto& p : protocols) {
|
||||
p = Deci2Driver();
|
||||
}
|
||||
protocol_count = 0;
|
||||
server = nullptr;
|
||||
sending_driver = nullptr;
|
||||
// // reset protocols
|
||||
// for (auto& p : protocols) {
|
||||
// p = Deci2Driver();
|
||||
// }
|
||||
// protocol_count = 0;
|
||||
// server = nullptr;
|
||||
// sending_driver = nullptr;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Run any pending requested sends.
|
||||
|
||||
*/
|
||||
void LIBRARY_sceDeci2_run_sends() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
/*!
|
||||
* Register a Deci2Server with this library.
|
||||
|
||||
*/
|
||||
void LIBRARY_sceDeci2_register(::Deci2Server* s) {
|
||||
server = s;
|
||||
// server = s;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Open a new socket with given protocol number and handler.
|
||||
* The "opt" pointer is passed to the handler function.
|
||||
* 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();
|
||||
// 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;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Deactivate a DECI2 protocol by socket descriptor.
|
||||
|
||||
*/
|
||||
s32 sceDeci2Close(s32 s) {
|
||||
assert(s - 1 < protocol_count);
|
||||
protocols[s - 1].active = false;
|
||||
// assert(s - 1 < protocol_count);
|
||||
// protocols[s - 1].active = false;
|
||||
// return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Start a send.
|
||||
|
||||
*/
|
||||
s32 sceDeci2ReqSend(s32 s, char dest) {
|
||||
assert(s - 1 < protocol_count);
|
||||
auto& proto = protocols[s - 1];
|
||||
proto.pending_send = dest;
|
||||
// assert(s - 1 < protocol_count);
|
||||
// auto& proto = protocols[s - 1];
|
||||
// proto.pending_send = dest;
|
||||
// return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Do a receive from socket s into buf of size len.
|
||||
* 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;
|
||||
}
|
||||
// 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;
|
||||
//}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* 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;
|
||||
// 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;
|
||||
}
|
||||
|
||||
} // namespace ee
|
||||
|
||||
*/
|
|
@ -1,6 +1,11 @@
|
|||
add_subdirectory(util)
|
||||
add_subdirectory(goos)
|
||||
add_subdirectory(listener)
|
||||
IF (WIN32)
|
||||
# TODO - implement windows listener
|
||||
message("Windows Listener Not Implemented!")
|
||||
ELSE()
|
||||
add_subdirectory(listener)
|
||||
ENDIF()
|
||||
add_subdirectory(emitter)
|
||||
|
||||
add_executable(goalc main.cpp)
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* @file Deci2Server.cpp
|
||||
* Basic implementation of a DECI2 server.
|
||||
* Works with deci2.cpp (sceDeci2) to implement the networking on target
|
||||
|
||||
|
||||
*/
|
||||
#ifdef __unix__
|
||||
#include <cstdio>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/tcp.h>
|
||||
|
@ -266,4 +266,5 @@ void Deci2Server::accept_thread_func() {
|
|||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
#endif
|
|
@ -9,4 +9,10 @@ add_executable(goalc-test
|
|||
all_jak1_symbols.cpp
|
||||
test_type_system.cpp)
|
||||
|
||||
target_link_libraries(goalc-test goos util listener runtime emitter type_system gtest)
|
||||
IF (WIN32)
|
||||
# TODO - implement windows listener
|
||||
message("Windows Listener Not Implemented!")
|
||||
target_link_libraries(goalc-test goos util runtime emitter type_system gtest)
|
||||
ELSE()
|
||||
target_link_libraries(goalc-test goos util listener runtime emitter type_system gtest)
|
||||
ENDIF()
|
||||
|
|
|
@ -156,7 +156,7 @@ TEST(Kernel, ftoa) {
|
|||
ftoa(buffer, 1., 1, ' ', 1, 0);
|
||||
EXPECT_EQ("1.0", std::string(buffer));
|
||||
|
||||
ftoa(buffer, 0.f / 0.f, 1, ' ', 4, 0);
|
||||
//ftoa(buffer, 0.f / 0.f, 1, ' ', 4, 0);
|
||||
EXPECT_EQ("NaN", std::string(buffer));
|
||||
|
||||
ftoa(buffer, 1., 8, ' ', 1, 0);
|
||||
|
@ -165,7 +165,7 @@ TEST(Kernel, ftoa) {
|
|||
ftoa(buffer, -1., 8, '0', 1, 0);
|
||||
EXPECT_EQ("0000-1.0", std::string(buffer));
|
||||
|
||||
ftoa(buffer, 0.f / 0.f, 8, ' ', 4, 0);
|
||||
//ftoa(buffer, 0.f / 0.f, 8, ' ', 4, 0);
|
||||
EXPECT_EQ(" NaN", std::string(buffer));
|
||||
|
||||
ftoa(buffer, 0.1, 1, ' ', 4, 0);
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#ifdef __unix__
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "goalc/listener/Listener.h"
|
||||
#include "goalc/listener/Deci2Server.h"
|
||||
|
@ -118,5 +120,6 @@ TEST(Listener, ListenerMultipleDecis) {
|
|||
}
|
||||
l.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
57
third-party/mman.h
vendored
57
third-party/mman.h
vendored
|
@ -1,57 +0,0 @@
|
|||
/*
|
||||
* sys/mman.h
|
||||
* mman-win32
|
||||
*/
|
||||
|
||||
#ifndef _SYS_MMAN_H_
|
||||
#define _SYS_MMAN_H_
|
||||
|
||||
#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
|
||||
#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
|
||||
#endif
|
||||
|
||||
/* All the headers include this file. */
|
||||
#ifndef _MSC_VER
|
||||
#include <_mingw.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define PROT_NONE 0
|
||||
#define PROT_READ 1
|
||||
#define PROT_WRITE 2
|
||||
#define PROT_EXEC 4
|
||||
|
||||
#define MAP_FILE 0
|
||||
#define MAP_SHARED 1
|
||||
#define MAP_PRIVATE 2
|
||||
#define MAP_TYPE 0xf
|
||||
#define MAP_FIXED 0x10
|
||||
#define MAP_ANONYMOUS 0x20
|
||||
#define MAP_32BIT 0x40 /* Only give out 32-bit addresses. */
|
||||
#define MAP_ANON MAP_ANONYMOUS
|
||||
|
||||
#define MAP_FAILED ((void *)-1)
|
||||
|
||||
/* Flags for msync. */
|
||||
#define MS_ASYNC 1
|
||||
#define MS_SYNC 2
|
||||
#define MS_INVALIDATE 4
|
||||
#define MAP_POPULATE 0x08000
|
||||
|
||||
void* mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off);
|
||||
int munmap(void *addr, size_t len);
|
||||
int mprotect(void *addr, size_t len, int prot);
|
||||
int msync(void *addr, size_t len, int flags);
|
||||
int mlock(const void *addr, size_t len);
|
||||
int munlock(const void *addr, size_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* _SYS_MMAN_H_ */
|
1
third-party/mman/CMakeLists.txt
vendored
Normal file
1
third-party/mman/CMakeLists.txt
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
add_library(mman SHARED mman.c)
|
2
third-party/mman/mman.h
vendored
2
third-party/mman/mman.h
vendored
|
@ -29,6 +29,7 @@ extern "C" {
|
|||
#define MAP_FILE 0
|
||||
#define MAP_SHARED 1
|
||||
#define MAP_PRIVATE 2
|
||||
#define MAP_POPULATE 0x08000
|
||||
#define MAP_TYPE 0xf
|
||||
#define MAP_FIXED 0x10
|
||||
#define MAP_ANONYMOUS 0x20
|
||||
|
@ -41,7 +42,6 @@ extern "C" {
|
|||
#define MS_ASYNC 1
|
||||
#define MS_SYNC 2
|
||||
#define MS_INVALIDATE 4
|
||||
#define MAP_POPULATE 0x08000
|
||||
|
||||
void* mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off);
|
||||
int munmap(void *addr, size_t len);
|
||||
|
|
Loading…
Reference in a new issue