aboutsummaryrefslogtreecommitdiff
path: root/src/libui_sdl
diff options
context:
space:
mode:
Diffstat (limited to 'src/libui_sdl')
-rw-r--r--src/libui_sdl/DlgAudioSettings.cpp2
-rw-r--r--src/libui_sdl/DlgEmuSettings.cpp2
-rw-r--r--src/libui_sdl/DlgInputConfig.cpp2
-rw-r--r--src/libui_sdl/DlgWifiSettings.cpp2
-rw-r--r--src/libui_sdl/LAN_PCap.cpp2
-rw-r--r--src/libui_sdl/LAN_Socket.cpp66
-rw-r--r--src/libui_sdl/Platform.cpp2
-rw-r--r--src/libui_sdl/PlatformConfig.cpp123
-rw-r--r--src/libui_sdl/PlatformConfig.h69
-rw-r--r--src/libui_sdl/main.cpp2
10 files changed, 249 insertions, 23 deletions
diff --git a/src/libui_sdl/DlgAudioSettings.cpp b/src/libui_sdl/DlgAudioSettings.cpp
index 5fe4ebc..66bdf61 100644
--- a/src/libui_sdl/DlgAudioSettings.cpp
+++ b/src/libui_sdl/DlgAudioSettings.cpp
@@ -23,7 +23,7 @@
#include "libui/ui.h"
#include "../types.h"
-#include "../Config.h"
+#include "PlatformConfig.h"
#include "DlgAudioSettings.h"
diff --git a/src/libui_sdl/DlgEmuSettings.cpp b/src/libui_sdl/DlgEmuSettings.cpp
index 666ac35..7d774a0 100644
--- a/src/libui_sdl/DlgEmuSettings.cpp
+++ b/src/libui_sdl/DlgEmuSettings.cpp
@@ -22,7 +22,7 @@
#include "libui/ui.h"
#include "../types.h"
-#include "../Config.h"
+#include "PlatformConfig.h"
#include "DlgEmuSettings.h"
diff --git a/src/libui_sdl/DlgInputConfig.cpp b/src/libui_sdl/DlgInputConfig.cpp
index 1869ec0..513bd90 100644
--- a/src/libui_sdl/DlgInputConfig.cpp
+++ b/src/libui_sdl/DlgInputConfig.cpp
@@ -24,7 +24,7 @@
#include "libui/ui.h"
#include "../types.h"
-#include "../Config.h"
+#include "PlatformConfig.h"
#include "DlgInputConfig.h"
diff --git a/src/libui_sdl/DlgWifiSettings.cpp b/src/libui_sdl/DlgWifiSettings.cpp
index 76f3840..c1acb35 100644
--- a/src/libui_sdl/DlgWifiSettings.cpp
+++ b/src/libui_sdl/DlgWifiSettings.cpp
@@ -23,7 +23,7 @@
#include "libui/ui.h"
#include "../types.h"
-#include "../Config.h"
+#include "PlatformConfig.h"
#include "LAN_Socket.h"
#include "LAN_PCap.h"
diff --git a/src/libui_sdl/LAN_PCap.cpp b/src/libui_sdl/LAN_PCap.cpp
index 6f4fdca..d1c0dd9 100644
--- a/src/libui_sdl/LAN_PCap.cpp
+++ b/src/libui_sdl/LAN_PCap.cpp
@@ -25,7 +25,7 @@
#include <pcap/pcap.h>
#include "Wifi.h"
#include "LAN_PCap.h"
-#include "../Config.h"
+#include "PlatformConfig.h"
#ifdef __WIN32__
#include <iphlpapi.h>
diff --git a/src/libui_sdl/LAN_Socket.cpp b/src/libui_sdl/LAN_Socket.cpp
index 0ca60ca..9da5769 100644
--- a/src/libui_sdl/LAN_Socket.cpp
+++ b/src/libui_sdl/LAN_Socket.cpp
@@ -621,6 +621,8 @@ void TCP_SYNACK(TCPSocket* sock, u8* data, int len)
seqnum++;
sock->AckNum = seqnum;
+ printf("SYNACK SEQ=%08X|%08X\n", sock->SeqNum, sock->AckNum);
+
// ethernet
memcpy(out, &data[6], 6); out += 6;
memcpy(out, kServerMAC, 6); out += 6;
@@ -674,16 +676,18 @@ void TCP_SYNACK(TCPSocket* sock, u8* data, int len)
RXNum = 1;
}
-void TCP_ACK(TCPSocket* sock, u8* data, int len)
+void TCP_ACK(TCPSocket* sock, bool fin)
{
u8 resp[64];
u8* out = &resp[0];
- u8* ipheader = &data[0xE];
- u8* tcpheader = &data[0x22];
+ u16 flags = 0x5010;
+ if (fin) flags |= 0x0001;
+
+ printf("%sACK SEQ=%08X|%08X\n", fin?"FIN":" ", sock->SeqNum, sock->AckNum);
// ethernet
- memcpy(out, &data[6], 6); out += 6;
+ memcpy(out, Wifi::GetMAC(), 6); out += 6;
memcpy(out, kServerMAC, 6); out += 6;
*(u16*)out = htons(0x0800); out += 2;
@@ -698,16 +702,16 @@ void TCP_ACK(TCPSocket* sock, u8* data, int len)
*out++ = 0x80; // TTL
*out++ = 0x06; // protocol (TCP)
*(u16*)out = 0; out += 2; // checksum
- *(u32*)out = *(u32*)&ipheader[16]; out += 4; // source IP
- *(u32*)out = *(u32*)&ipheader[12]; out += 4; // destination IP
+ *(u32*)out = *(u32*)&sock->DestIP; out += 4; // source IP
+ *(u32*)out = htonl(kClientIP); out += 4; // destination IP
// TCP
u8* resp_tcpheader = out;
- *(u16*)out = *(u16*)&tcpheader[2]; out += 2; // source port
- *(u16*)out = *(u16*)&tcpheader[0]; out += 2; // destination port
+ *(u16*)out = htonl(sock->DestPort); out += 2; // source port
+ *(u16*)out = htonl(sock->SourcePort); out += 2; // destination port
*(u32*)out = htonl(sock->SeqNum); out += 4; // seq number
*(u32*)out = htonl(sock->AckNum); out += 4; // ack seq number
- *(u16*)out = htons(0x5010); out += 2; // flags (ACK)
+ *(u16*)out = htons(flags); out += 2; // flags
*(u16*)out = htons(0x7000); out += 2; // window size (uuuh)
*(u16*)out = 0; out += 2; // checksum
*(u16*)out = 0; out += 2; // urgent pointer
@@ -731,7 +735,7 @@ void TCP_BuildIncomingFrame(TCPSocket* sock, u8* data, int len)
u8* out = &resp[0];
if (len > 1536) return;
-
+printf("INCOMING SEQ=%08X|%08X\n", sock->SeqNum, sock->AckNum);
// ethernet
memcpy(out, Wifi::GetMAC(), 6); out += 6; // hurf
memcpy(out, kServerMAC, 6); out += 6;
@@ -774,6 +778,8 @@ void TCP_BuildIncomingFrame(TCPSocket* sock, u8* data, int len)
PacketLen = framelen;
memcpy(PacketBuffer, resp, PacketLen);
RXNum = 1;
+
+ sock->SeqNum += len;
}
void HandleTCPFrame(u8* data, int len)
@@ -789,6 +795,11 @@ void HandleTCPFrame(u8* data, int len)
u32 tcplen = ntohs(*(u16*)&ipheader[2]) - 0x14;
u32 tcpdatalen = tcplen - tcpheaderlen;
+ printf("tcpflags=%04X header=%d data=%d seq=%08X|%08X\n",
+ flags, tcpheaderlen, tcpdatalen,
+ ntohl(*(u32*)&tcpheader[4]),
+ ntohl(*(u32*)&tcpheader[8]));
+
if (flags & 0x002) // SYN
{
int sockid = -1;
@@ -796,7 +807,7 @@ void HandleTCPFrame(u8* data, int len)
for (int i = 0; i < (sizeof(TCPSocketList)/sizeof(TCPSocket)); i++)
{
sock = &TCPSocketList[i];
- if (sock->Status == 1 && !memcmp(&sock->DestIP, &ipheader[16], 4) &&
+ if (sock->Status != 0 && !memcmp(&sock->DestIP, &ipheader[16], 4) &&
sock->SourcePort == srcport && sock->DestPort == dstport)
{
printf("LANMAGIC: duplicate TCP socket\n");
@@ -846,7 +857,6 @@ void HandleTCPFrame(u8* data, int len)
struct sockaddr_in conn_addr;
memset(&conn_addr, 0, sizeof(conn_addr));
conn_addr.sin_family = AF_INET;
- //conn_addr.sin_addr.S_un.S_addr = *(u32*)&ipheader[16];
memcpy(&conn_addr.sin_addr, &ipheader[16], 4);
conn_addr.sin_port = htons(dstport);
if (connect(sock->Backend, (sockaddr*)&conn_addr, sizeof(conn_addr)) == SOCKET_ERROR)
@@ -866,7 +876,7 @@ void HandleTCPFrame(u8* data, int len)
for (int i = 0; i < (sizeof(TCPSocketList)/sizeof(TCPSocket)); i++)
{
sock = &TCPSocketList[i];
- if (sock->Status == 1 && !memcmp(&sock->DestIP, &ipheader[16], 4) &&
+ if (sock->Status != 0 && !memcmp(&sock->DestIP, &ipheader[16], 4) &&
sock->SourcePort == srcport && sock->DestPort == dstport)
{
sockid = i;
@@ -895,7 +905,7 @@ void HandleTCPFrame(u8* data, int len)
send(sock->Backend, (char*)tcpdata, tcpdatalen, 0);
// kind of a hack, there
- TCP_ACK(sock, data, len);
+ TCP_ACK(sock, false);
}
if (flags & 0x001) // FIN
@@ -1052,10 +1062,35 @@ int RecvPacket(u8* data)
u8 recvbuf[1024];
int recvlen = recv(sock->Backend, (char*)recvbuf, 1024, 0);
- if (recvlen < 1) continue;
+ if (recvlen < 1)
+ {
+ if (recvlen == 0)
+ {
+ // socket has closed from the other side
+ printf("TCP: socket %d closed from other side\n", i);
+ sock->Status = 2;
+ TCP_ACK(sock, true);
+ }
+ continue;
+ }
printf("TCP: socket %d receiving %d bytes\n", i, recvlen);
TCP_BuildIncomingFrame(sock, recvbuf, recvlen);
+
+ // debug
+ for (int j = 0; j < recvlen; j += 16)
+ {
+ int rem = recvlen - j;
+ if (rem > 16) rem = 16;
+ for (int k = 0; k < rem; k++)
+ {
+ printf("%02X ", recvbuf[k+j]);
+ }
+ printf("\n");
+ }
+
+ //recvlen = recv(sock->Backend, (char*)recvbuf, 1024, 0);
+ //if (recvlen == 0) printf("it closed immediately after\n");
}
for (int i = 0; i < (sizeof(UDPSocketList)/sizeof(UDPSocket)); i++)
@@ -1077,7 +1112,6 @@ int RecvPacket(u8* data)
}
u8 recvbuf[1024];
- //int recvlen = recv(sock->Backend, (char*)recvbuf, 1024, 0);
sockaddr_t fromAddr;
socklen_t fromLen = sizeof(sockaddr_t);
int recvlen = recvfrom(sock->Backend, (char*)recvbuf, 1024, 0, &fromAddr, &fromLen);
diff --git a/src/libui_sdl/Platform.cpp b/src/libui_sdl/Platform.cpp
index 2c467ac..f5ec32e 100644
--- a/src/libui_sdl/Platform.cpp
+++ b/src/libui_sdl/Platform.cpp
@@ -21,7 +21,7 @@
#include <string.h>
#include <SDL2/SDL.h>
#include "../Platform.h"
-#include "../Config.h"
+#include "PlatformConfig.h"
#include "LAN_Socket.h"
#include "LAN_PCap.h"
diff --git a/src/libui_sdl/PlatformConfig.cpp b/src/libui_sdl/PlatformConfig.cpp
new file mode 100644
index 0000000..2daf746
--- /dev/null
+++ b/src/libui_sdl/PlatformConfig.cpp
@@ -0,0 +1,123 @@
+/*
+ Copyright 2016-2019 Arisotura
+
+ This file is part of melonDS.
+
+ melonDS is free software: you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation, either version 3 of the License, or (at your option)
+ any later version.
+
+ melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with melonDS. If not, see http://www.gnu.org/licenses/.
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include "PlatformConfig.h"
+
+namespace Config
+{
+
+int KeyMapping[12];
+int JoyMapping[12];
+
+int HKKeyMapping[HK_MAX];
+int HKJoyMapping[HK_MAX];
+
+int WindowWidth;
+int WindowHeight;
+int WindowMaximized;
+
+int ScreenRotation;
+int ScreenGap;
+int ScreenLayout;
+int ScreenSizing;
+int ScreenFilter;
+
+int LimitFPS;
+
+int DirectBoot;
+
+int SocketBindAnyAddr;
+char LANDevice[128];
+int DirectLAN;
+
+int SavestateRelocSRAM;
+
+int AudioVolume;
+int MicInputType;
+char MicWavPath[512];
+
+char LastROMFolder[512];
+
+
+ConfigEntry PlatformConfigFile[] =
+{
+ {"Key_A", 0, &KeyMapping[0], 32, NULL, 0},
+ {"Key_B", 0, &KeyMapping[1], 31, NULL, 0},
+ {"Key_Select", 0, &KeyMapping[2], 57, NULL, 0},
+ {"Key_Start", 0, &KeyMapping[3], 28, NULL, 0},
+ {"Key_Right", 0, &KeyMapping[4], 333, NULL, 0},
+ {"Key_Left", 0, &KeyMapping[5], 331, NULL, 0},
+ {"Key_Up", 0, &KeyMapping[6], 328, NULL, 0},
+ {"Key_Down", 0, &KeyMapping[7], 336, NULL, 0},
+ {"Key_R", 0, &KeyMapping[8], 54, NULL, 0},
+ {"Key_L", 0, &KeyMapping[9], 86, NULL, 0},
+ {"Key_X", 0, &KeyMapping[10], 17, NULL, 0},
+ {"Key_Y", 0, &KeyMapping[11], 30, NULL, 0},
+
+ {"Joy_A", 0, &JoyMapping[0], -1, NULL, 0},
+ {"Joy_B", 0, &JoyMapping[1], -1, NULL, 0},
+ {"Joy_Select", 0, &JoyMapping[2], -1, NULL, 0},
+ {"Joy_Start", 0, &JoyMapping[3], -1, NULL, 0},
+ {"Joy_Right", 0, &JoyMapping[4], -1, NULL, 0},
+ {"Joy_Left", 0, &JoyMapping[5], -1, NULL, 0},
+ {"Joy_Up", 0, &JoyMapping[6], -1, NULL, 0},
+ {"Joy_Down", 0, &JoyMapping[7], -1, NULL, 0},
+ {"Joy_R", 0, &JoyMapping[8], -1, NULL, 0},
+ {"Joy_L", 0, &JoyMapping[9], -1, NULL, 0},
+ {"Joy_X", 0, &JoyMapping[10], -1, NULL, 0},
+ {"Joy_Y", 0, &JoyMapping[11], -1, NULL, 0},
+
+ {"HKKey_Lid", 0, &HKKeyMapping[HK_Lid], 0x0E, NULL, 0},
+ {"HKKey_Mic", 0, &HKKeyMapping[HK_Mic], 0x35, NULL, 0},
+
+ {"HKJoy_Lid", 0, &HKJoyMapping[HK_Lid], -1, NULL, 0},
+ {"HKJoy_Mic", 0, &HKJoyMapping[HK_Mic], -1, NULL, 0},
+
+ {"WindowWidth", 0, &WindowWidth, 256, NULL, 0},
+ {"WindowHeight", 0, &WindowHeight, 384, NULL, 0},
+ {"WindowMax", 0, &WindowMaximized, 0, NULL, 0},
+
+ {"ScreenRotation", 0, &ScreenRotation, 0, NULL, 0},
+ {"ScreenGap", 0, &ScreenGap, 0, NULL, 0},
+ {"ScreenLayout", 0, &ScreenLayout, 0, NULL, 0},
+ {"ScreenSizing", 0, &ScreenSizing, 0, NULL, 0},
+ {"ScreenFilter", 0, &ScreenFilter, 1, NULL, 0},
+
+ {"LimitFPS", 0, &LimitFPS, 1, NULL, 0},
+
+ {"DirectBoot", 0, &DirectBoot, 1, NULL, 0},
+
+ {"SockBindAnyAddr", 0, &SocketBindAnyAddr, 0, NULL, 0},
+ {"LANDevice", 1, LANDevice, 0, "", 127},
+ {"DirectLAN", 0, &DirectLAN, 0, NULL, 0},
+
+ {"SavStaRelocSRAM", 0, &SavestateRelocSRAM, 0, NULL, 0},
+
+ {"AudioVolume", 0, &AudioVolume, 256, NULL, 0},
+ {"MicInputType", 0, &MicInputType, 1, NULL, 0},
+ {"MicWavPath", 1, MicWavPath, 0, "", 511},
+
+ {"LastROMFolder", 1, LastROMFolder, 0, "", 511},
+
+ {"", -1, NULL, 0, NULL, 0}
+};
+
+}
diff --git a/src/libui_sdl/PlatformConfig.h b/src/libui_sdl/PlatformConfig.h
new file mode 100644
index 0000000..ed31e18
--- /dev/null
+++ b/src/libui_sdl/PlatformConfig.h
@@ -0,0 +1,69 @@
+/*
+ Copyright 2016-2019 Arisotura
+
+ This file is part of melonDS.
+
+ melonDS is free software: you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation, either version 3 of the License, or (at your option)
+ any later version.
+
+ melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with melonDS. If not, see http://www.gnu.org/licenses/.
+*/
+
+#ifndef PLATFORMCONFIG_H
+#define PLATFORMCONFIG_H
+
+#include "../Config.h"
+
+enum
+{
+ HK_Lid = 0,
+ HK_Mic,
+
+ HK_MAX
+};
+
+namespace Config
+{
+
+extern int KeyMapping[12];
+extern int JoyMapping[12];
+
+extern int HKKeyMapping[HK_MAX];
+extern int HKJoyMapping[HK_MAX];
+
+extern int WindowWidth;
+extern int WindowHeight;
+extern int WindowMaximized;
+
+extern int ScreenRotation;
+extern int ScreenGap;
+extern int ScreenLayout;
+extern int ScreenSizing;
+extern int ScreenFilter;
+
+extern int LimitFPS;
+
+extern int DirectBoot;
+
+extern int SocketBindAnyAddr;
+extern char LANDevice[128];
+extern int DirectLAN;
+
+extern int SavestateRelocSRAM;
+
+extern int AudioVolume;
+extern int MicInputType;
+extern char MicWavPath[512];
+
+extern char LastROMFolder[512];
+
+}
+
+#endif // PLATFORMCONFIG_H
diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp
index 9c6b38b..25c7249 100644
--- a/src/libui_sdl/main.cpp
+++ b/src/libui_sdl/main.cpp
@@ -27,7 +27,7 @@
#include "../types.h"
#include "../melon_fopen.h"
#include "../version.h"
-#include "../Config.h"
+#include "PlatformConfig.h"
#include "DlgEmuSettings.h"
#include "DlgInputConfig.h"