mirror of
https://github.com/SAT-R/sa2.git
synced 2026-10-28 09:43:38 +00:00
some progress
This commit is contained in:
1 parent
688b142404
commit
ce6ff9cfeb
8 files changed
+220
-14
No files matched your search
Vendored
+2
-1
@@ -365,7 +365,8 @@
|
||||
"recordings.h": "c",
|
||||
"bg_palette_effects.h": "c",
|
||||
"palettes.h": "c",
|
||||
"dma.h": "c"
|
||||
"dma.h": "c",
|
||||
"inet.h": "c"
|
||||
},
|
||||
"asm-code-lens.donated": true,
|
||||
"editor.formatOnSave": true,
|
||||
|
||||
@@ -10,21 +10,21 @@
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
#define FATAL_ERROR(format, ...) \
|
||||
do { \
|
||||
fprintf(stderr, format, __VA_ARGS__); \
|
||||
exit(1); \
|
||||
} while (0)
|
||||
#define FATAL_ERROR(format, ...) \
|
||||
do { \
|
||||
fprintf(stderr, format, __VA_ARGS__); \
|
||||
exit(1); \
|
||||
} while (0)
|
||||
|
||||
#define UNUSED
|
||||
|
||||
#else
|
||||
|
||||
#define FATAL_ERROR(format, ...) \
|
||||
do { \
|
||||
fprintf(stderr, format, ##__VA_ARGS__); \
|
||||
exit(1); \
|
||||
} while (0)
|
||||
#define FATAL_ERROR(format, ...) \
|
||||
do { \
|
||||
fprintf(stderr, format, ##__VA_ARGS__); \
|
||||
exit(1); \
|
||||
} while (0)
|
||||
|
||||
#define UNUSED __attribute__((__unused__))
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef GUARD_SA2_PLATFORM_H
|
||||
#define GUARD_SA2_PLATFORM_H
|
||||
|
||||
#include "gba/types.h"
|
||||
|
||||
PACKED(NetworkPacket, {
|
||||
u16 sioData;
|
||||
u8 sioId;
|
||||
});
|
||||
|
||||
#endif
|
||||
@@ -23,4 +23,6 @@ extern void Platform_RLDecompressUnsafe(unsigned char *src, unsigned char *dest)
|
||||
|
||||
extern void Platform_QueueAudio(const void *data, u32 numBytes);
|
||||
|
||||
extern void Platform_SioSend(void);
|
||||
|
||||
#endif // GUARD_SA2_PLATFORM_H
|
||||
Vendored
+48
@@ -0,0 +1,48 @@
|
||||
import socket
|
||||
import threading
|
||||
|
||||
HEADER = 64
|
||||
PORT = 5100
|
||||
SERVER = "127.0.0.1"
|
||||
print(SERVER)
|
||||
ADDR = (SERVER, PORT)
|
||||
FORMAT = 'UTF-8'
|
||||
|
||||
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
server.bind(ADDR)
|
||||
|
||||
clients: list[socket.socket] = []
|
||||
|
||||
def handle_client(conn, addr):
|
||||
print(f"[NEW CONNECTION] {addr} connected.")
|
||||
connected = True
|
||||
while connected:
|
||||
msg = conn.recv(17)
|
||||
|
||||
if len(msg) < 17:
|
||||
break
|
||||
|
||||
print("Broadcasting", msg)
|
||||
|
||||
#for client in clients:
|
||||
#client.send(msg)
|
||||
|
||||
print(f"[{addr}] {msg}")
|
||||
|
||||
clients.remove(conn)
|
||||
conn.close()
|
||||
|
||||
|
||||
def start():
|
||||
server.listen()
|
||||
print(f"[LISTENING] Server is listening on {SERVER}")
|
||||
while True:
|
||||
conn, addr = server.accept()
|
||||
clients.append(conn)
|
||||
thread = threading.Thread(target=handle_client, args=(conn, addr))
|
||||
thread.start()
|
||||
print(f"[ACTIVE CONNECTIONS] {threading.activeCount() - 1}")
|
||||
|
||||
|
||||
print("[STARTING] server is starting...")
|
||||
start()
|
||||
@@ -2,6 +2,10 @@
|
||||
#include "multi_sio.h"
|
||||
#include "sio32_multi_load.h"
|
||||
|
||||
#if PORTABLE
|
||||
#include "platform/platform.h"
|
||||
#endif
|
||||
|
||||
static const char sMultiSioLibVer[] = "MultiSio4Sio32Load010528";
|
||||
|
||||
#ifdef MULTI_SIO_DI_FUNC_FAST
|
||||
@@ -222,6 +226,9 @@ void MultiSioIntr(void)
|
||||
gMultiSioArea.nextSendBufp = bufpTmp;
|
||||
} else if (gMultiSioArea.sendBufCounter >= 0) { // Set Send Data
|
||||
((struct SioMultiCnt *)REG_ADDR_SIOCNT)->data = gMultiSioArea.currentSendBufp[gMultiSioArea.sendBufCounter];
|
||||
#if PORTABLE
|
||||
Platform_SioSend();
|
||||
#endif
|
||||
}
|
||||
if (gMultiSioArea.sendBufCounter < (s32)(sizeof(struct MultiSioPacket) / 2 - 1))
|
||||
++gMultiSioArea.sendBufCounter;
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "platform/network.h"
|
||||
#include "global.h"
|
||||
|
||||
int sockfd = 0;
|
||||
|
||||
char recvBuff[sizeof(NetworkPacket)];
|
||||
|
||||
int initClient(void)
|
||||
{
|
||||
int n = 0;
|
||||
char serverAddress[] = "127.0.0.1";
|
||||
struct sockaddr_in serv_addr;
|
||||
|
||||
memset(recvBuff, '0', sizeof(recvBuff));
|
||||
|
||||
/* a socket is created through call to socket() function */
|
||||
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
||||
printf("\n Error : Could not create socket \n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
memset(&serv_addr, '0', sizeof(serv_addr));
|
||||
|
||||
serv_addr.sin_family = AF_INET;
|
||||
serv_addr.sin_port = htons(5100);
|
||||
|
||||
if (inet_pton(AF_INET, serverAddress, &serv_addr.sin_addr) <= 0) {
|
||||
printf("\n inet_pton error occured\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Information like IP address of the remote host and its port is
|
||||
* bundled up in a structure and a call to function connect() is made
|
||||
* which tries to connect this socket with the socket (IP address and port)
|
||||
* of the remote host
|
||||
*/
|
||||
if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
|
||||
printf("\n Error : Connect Failed \n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void clientSend(u8 sioId, u16 data)
|
||||
{
|
||||
NetworkPacket packet;
|
||||
packet.sioData = data;
|
||||
packet.sioId = sioId;
|
||||
write(sockfd, &packet, sizeof(NetworkPacket));
|
||||
}
|
||||
|
||||
NetworkPacket *clientRecv(void)
|
||||
{
|
||||
int n = 0;
|
||||
|
||||
/* Once the sockets are connected, the server sends the data (date+time)
|
||||
* on clients socket through clients socket descriptor and client can read it
|
||||
* through normal read call on the its socket descriptor.
|
||||
*/
|
||||
while ((n = read(sockfd, recvBuff, sizeof(NetworkPacket)) > 0)) {
|
||||
recvBuff[n] = 0;
|
||||
if (fputs(recvBuff, stdout) == EOF) {
|
||||
printf("\n Error : Fputs error\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (n < 0) {
|
||||
printf("\n Read error \n");
|
||||
return NULL;
|
||||
}
|
||||
return (NetworkPacket *)(&recvBuff);
|
||||
}
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "lib/agb_flash/flash_internal.h"
|
||||
#include "platform/shared/dma.h"
|
||||
#include "platform/shared/input.h"
|
||||
#include "platform/network.h"
|
||||
|
||||
#if ENABLE_AUDIO
|
||||
#include "platform/shared/audio/cgb_audio.h"
|
||||
@@ -120,6 +121,11 @@ void *Platform_malloc(int numBytes) { return HeapAlloc(GetProcessHeap(), HEAP_GE
|
||||
void Platform_free(void *ptr) { HeapFree(GetProcessHeap(), 0, ptr); }
|
||||
#endif
|
||||
|
||||
extern int initClient(void);
|
||||
extern NetworkPacket *clientRecv(void);
|
||||
extern void clientSend(u8 sioId, u16 data);
|
||||
int SioRecvLoop(void *);
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const char *headlessEnv = getenv("HEADLESS");
|
||||
@@ -128,15 +134,30 @@ int main(int argc, char **argv)
|
||||
headless = true;
|
||||
}
|
||||
|
||||
const char *parentEnv = getenv("SIO_PARENT");
|
||||
const char *sioIdEnv = getenv("SIO_ID");
|
||||
int sioId = -1;
|
||||
if (sioIdEnv) {
|
||||
sioId = atoi(sioIdEnv);
|
||||
if (sioId > MULTI_SIO_PLAYERS_MAX - 1 || sioId < 0) {
|
||||
fprintf(stderr, "Invalid SIO ID %i\n", sioId);
|
||||
}
|
||||
}
|
||||
|
||||
if (parentEnv && strcmp(parentEnv, "true") == 0) {
|
||||
SIO_MULTI_CNT->id = 0;
|
||||
if (sioId != -1) {
|
||||
SIO_MULTI_CNT->id = sioId;
|
||||
SIO_MULTI_CNT->si = 1;
|
||||
SIO_MULTI_CNT->sd = 1;
|
||||
SIO_MULTI_CNT->enable = false;
|
||||
}
|
||||
|
||||
if (sioId != -1) {
|
||||
printf("Connecting to server as %i\n", sioId);
|
||||
if (initClient() != 0) {
|
||||
fprintf(stderr, "Could not connect to server\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Open an output console on Windows
|
||||
#if (defined _WIN32) && (DEBUG != 0)
|
||||
AllocConsole();
|
||||
@@ -162,6 +183,14 @@ int main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (sioId != -1) {
|
||||
if (sioId == 0) {
|
||||
printf("Starting sio receiver thread\n");
|
||||
SDL_CreateThread(SioRecvLoop, "test", NULL);
|
||||
}
|
||||
// SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data);
|
||||
}
|
||||
|
||||
#ifdef TITLE_BAR
|
||||
const char *title = STR(TITLE_BAR);
|
||||
#else
|
||||
@@ -257,6 +286,30 @@ int main(int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Platform_SioSend(void)
|
||||
{
|
||||
printf("SIO SEND %i\n", SIO_MULTI_CNT->data);
|
||||
clientSend(SIO_MULTI_CNT->id, SIO_MULTI_CNT->data);
|
||||
}
|
||||
|
||||
int SioRecvLoop(void *_)
|
||||
{
|
||||
while (1) {
|
||||
NetworkPacket *packet = clientRecv();
|
||||
if (packet == NULL) {
|
||||
printf("Received NULL\n");
|
||||
continue;
|
||||
}
|
||||
printf("Received %i, %i\n", packet->sioId, packet->sioData);
|
||||
|
||||
u8 sioId = packet->sioId;
|
||||
u16 data = packet->sioData;
|
||||
|
||||
((u16 *)REG_ADDR_SIOMLT_RECV)[sioId] = data;
|
||||
gIntrTable[INTR_INDEX_SIO]();
|
||||
}
|
||||
}
|
||||
|
||||
bool newFrameRequested = FALSE;
|
||||
|
||||
// Every GBA frame we process the SDL events and render the number of times
|
||||
@@ -271,6 +324,7 @@ void VBlankIntrWait(void)
|
||||
RunDMAs(DMA_VBLANK); \
|
||||
if (REG_DISPSTAT & DISPSTAT_VBLANK_INTR) \
|
||||
gIntrTable[INTR_INDEX_VBLANK](); \
|
||||
gIntrTable[INTR_INDEX_SIO](); \
|
||||
REG_DISPSTAT &= ~INTR_FLAG_VBLANK; \
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user