aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/GPU2D.cpp2
-rw-r--r--src/NDS.cpp2
-rw-r--r--src/Platform.h5
-rw-r--r--src/Wifi.cpp25
-rw-r--r--src/Wifi.h2
-rw-r--r--src/wx/Platform.cpp78
6 files changed, 111 insertions, 3 deletions
diff --git a/src/GPU2D.cpp b/src/GPU2D.cpp
index 0b3afd0..a61d00c 100644
--- a/src/GPU2D.cpp
+++ b/src/GPU2D.cpp
@@ -387,7 +387,7 @@ void GPU2D::DrawScanline(u32 line)
if (line > 192)
{
for (int i = 0; i < 256; i++)
- dst[i] = 0xFF3F3F3F;
+ dst[i] = 0xFFFFFFFF;
return;
}
diff --git a/src/NDS.cpp b/src/NDS.cpp
index 4c57bb6..8a3d13e 100644
--- a/src/NDS.cpp
+++ b/src/NDS.cpp
@@ -130,6 +130,7 @@ bool Init()
if (!SPU::Init()) return false;
if (!SPI::Init()) return false;
if (!RTC::Init()) return false;
+ if (!Wifi::Init()) return false;
return true;
}
@@ -150,6 +151,7 @@ void DeInit()
SPU::DeInit();
SPI::DeInit();
RTC::DeInit();
+ Wifi::DeInit();
}
diff --git a/src/Platform.h b/src/Platform.h
index 9814d14..6f2e252 100644
--- a/src/Platform.h
+++ b/src/Platform.h
@@ -19,10 +19,13 @@
#ifndef PLATFORM_H
#define PLATFORM_H
+#include "types.h"
+
namespace Platform
{
-//
+bool MP_Init();
+void MP_DeInit();
}
diff --git a/src/Wifi.cpp b/src/Wifi.cpp
index d454dd0..668af14 100644
--- a/src/Wifi.cpp
+++ b/src/Wifi.cpp
@@ -21,6 +21,7 @@
#include "NDS.h"
#include "SPI.h"
#include "Wifi.h"
+#include "Platform.h"
namespace Wifi
@@ -47,6 +48,8 @@ u16 RFData1;
u16 RFData2;
u32 RFRegs[0x40];
+bool MPInited;
+
// multiplayer host TX sequence:
// 1. preamble
@@ -74,6 +77,19 @@ u32 RFRegs[0x40];
// * work out how power saving works, there are oddities
+bool Init()
+{
+ MPInited = false;
+
+ return true;
+}
+
+void DeInit()
+{
+ if (MPInited)
+ Platform::MP_DeInit();
+}
+
void Reset()
{
memset(RAM, 0, 0x2000);
@@ -448,9 +464,18 @@ void Write(u32 addr, u16 val)
// schedule timer event when the clock is enabled
// TODO: check whether this resets USCOUNT (and also which other events can reset it)
if ((IOPORT(W_PowerUS) & 0x0001) && !(val & 0x0001))
+ {
NDS::ScheduleEvent(NDS::Event_Wifi, true, 33, USTimer, 0);
+ if (!MPInited)
+ {
+ Platform::MP_Init();
+ MPInited = true;
+ }
+ }
else if (!(IOPORT(W_PowerUS) & 0x0001) && (val & 0x0001))
+ {
NDS::CancelEvent(NDS::Event_Wifi);
+ }
break;
case W_USCountCnt: val &= 0x0001; break;
diff --git a/src/Wifi.h b/src/Wifi.h
index d28fda7..b590704 100644
--- a/src/Wifi.h
+++ b/src/Wifi.h
@@ -140,6 +140,8 @@ enum
};
+bool Init();
+void DeInit();
void Reset();
void USTimer(u32 param);
diff --git a/src/wx/Platform.cpp b/src/wx/Platform.cpp
index 482b886..3beca2f 100644
--- a/src/wx/Platform.cpp
+++ b/src/wx/Platform.cpp
@@ -17,14 +17,90 @@
*/
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include "../Platform.h"
+#ifdef __WXMSW__
+ #include <winsock2.h>
+ #include <ws2tcpip.h>
+ #define socket_t SOCKET
+ #define sockaddr_t SOCKADDR
+ #define pcap_dev_name description
+#else
+ #include <unistd.h>
+ #include <arpa/inet.h>
+ #include <sys/socket.h>
+ #define socket_t int
+ #define sockaddr_t struct sockaddr
+ #define closesocket close
+ #define pcap_dev_name name
+#endif
+
+#ifndef INVALID_SOCKET
+#define INVALID_SOCKET (socket_t)-1
+#endif
+
namespace Platform
{
-//
+socket_t MPSocket;
+sockaddr_t MPSendAddr;
+
+
+bool MP_Init()
+{
+ BOOL opt_true = TRUE;
+ int res;
+
+ MPSocket = socket(AF_INET, SOCK_DGRAM, 0);
+ if (MPSocket < 0)
+ {
+ return false;
+ }
+
+ res = setsockopt(MPSocket, SOL_SOCKET, SO_REUSEADDR, (const char*)&opt_true, sizeof(BOOL));
+ if (res < 0)
+ {
+ closesocket(MPSocket);
+ MPSocket = INVALID_SOCKET;
+ return false;
+ }
+
+ sockaddr_t saddr;
+ saddr.sa_family = AF_INET;
+ *(u32*)&saddr.sa_data[2] = htonl(INADDR_ANY);
+ *(u16*)&saddr.sa_data[0] = htons(7064);
+ res = bind(MPSocket, &saddr, sizeof(sockaddr_t));
+ if (res < 0)
+ {
+ closesocket(MPSocket);
+ MPSocket = INVALID_SOCKET;
+ return false;
+ }
+
+ res = setsockopt(MPSocket, SOL_SOCKET, SO_BROADCAST, (const char*)&opt_true, sizeof(BOOL));
+ if (res < 0)
+ {
+ closesocket(MPSocket);
+ MPSocket = INVALID_SOCKET;
+ return false;
+ }
+
+ MPSendAddr.sa_family = AF_INET;
+ *(u32*)&MPSendAddr.sa_data[2] = htonl(INADDR_BROADCAST);
+ *(u16*)&MPSendAddr.sa_data[0] = htons(7064);
+
+ return true;
+}
+
+void MP_DeInit()
+{
+ if (MPSocket >= 0)
+ closesocket(MPSocket);
+}
}