1 /*******************************************************************************
2 Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
4 (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and
5 Jerremy Koot (jkoot@snes9x.com)
7 (c) Copyright 2001 - 2004 John Weidman (jweidman@slip.net)
9 (c) Copyright 2002 - 2004 Brad Jorsch (anomie@users.sourceforge.net),
10 funkyass (funkyass@spam.shaw.ca),
11 Joel Yliluoma (http://iki.fi/bisqwit/)
12 Kris Bleakley (codeviolation@hotmail.com),
14 Nach (n-a-c-h@users.sourceforge.net),
15 Peter Bortas (peter@bortas.org) and
16 zones (kasumitokoduck@yahoo.com)
18 C4 x86 assembler and some C emulation code
19 (c) Copyright 2000 - 2003 zsKnight (zsknight@zsnes.com),
20 _Demo_ (_demo_@zsnes.com), and Nach
23 (c) Copyright 2003 Brad Jorsch
26 (c) Copyright 1998 - 2004 Ivar (ivar@snes9x.com), _Demo_, Gary Henderson,
27 John Weidman, neviksti (neviksti@hotmail.com),
28 Kris Bleakley, Andreas Naive
31 (c) Copyright 2003 Kris Bleakley, John Weidman, neviksti, Matthew Kendora, and
32 Lord Nightmare (lord_nightmare@users.sourceforge.net
35 (c) Copyright 2001 - 2004 zsKnight, pagefault (pagefault@zsnes.com) and
37 Ported from x86 assembler to C by sanmaiwashi
39 SPC7110 and RTC C++ emulator code
40 (c) Copyright 2002 Matthew Kendora with research by
41 zsKnight, John Weidman, and Dark Force
44 (c) Copyright 2003 Brad Jorsch with research by
45 Andreas Naive and John Weidman
48 (c) Copyright 2001 John Weidman
50 ST010 C++ emulator code
51 (c) Copyright 2003 Feather, Kris Bleakley, John Weidman and Matthew Kendora
53 Super FX x86 assembler emulator code
54 (c) Copyright 1998 - 2003 zsKnight, _Demo_, and pagefault
56 Super FX C emulator code
57 (c) Copyright 1997 - 1999 Ivar, Gary Henderson and John Weidman
60 SH assembler code partly based on x86 assembler code
61 (c) Copyright 2002 - 2004 Marcus Comstedt (marcus@mc.pp.se)
64 Specific ports contains the works of other authors. See headers in
67 Snes9x homepage: http://www.snes9x.com
69 Permission to use, copy, modify and distribute Snes9x in both binary and
70 source form, for non-commercial purposes, is hereby granted without fee,
71 providing that this license information and copyright notice appear with
72 all copies and any derived work.
74 This software is provided 'as-is', without any express or implied
75 warranty. In no event shall the authors be held liable for any damages
76 arising from the use of this software.
78 Snes9x is freeware for PERSONAL USE only. Commercial users should
79 seek permission of the copyright holders first. Commercial use includes
80 charging money for Snes9x or software derived from Snes9x.
82 The copyright holders request that bug fixes and improvements to the code
83 should be forwarded to them so everyone can benefit from the modifications
86 Super NES and Super Nintendo Entertainment System are trademarks of
87 Nintendo Co., Limited and its subsidiary companies.
88 *******************************************************************************/
94 * Client to server joypad update
101 * Server to client joypad update
104 * opcode 1 + num joypads (top 3 bits)
110 #define NP_VERSION 10
111 #define NP_JOYPAD_HIST_SIZE 120
112 #define NP_DEFAULT_PORT 6096
114 #define NP_MAX_CLIENTS 5
116 #define NP_SERV_MAGIC 'S'
117 #define NP_CLNT_MAGIC 'C'
119 #define NP_CLNT_HELLO 0
120 #define NP_CLNT_JOYPAD 1
121 #define NP_CLNT_RESET 2
122 #define NP_CLNT_PAUSE 3
123 #define NP_CLNT_LOAD_ROM 4
124 #define NP_CLNT_ROM_IMAGE 5
125 #define NP_CLNT_FREEZE_FILE 6
126 #define NP_CLNT_SRAM_DATA 7
127 #define NP_CLNT_READY 8
128 #define NP_CLNT_LOADED_ROM 9
129 #define NP_CLNT_RECEIVED_ROM_IMAGE 10
130 #define NP_CLNT_WAITING_FOR_ROM_IMAGE 11
132 #define NP_SERV_HELLO 0
133 #define NP_SERV_JOYPAD 1
134 #define NP_SERV_RESET 2
135 #define NP_SERV_PAUSE 3
136 #define NP_SERV_LOAD_ROM 4
137 #define NP_SERV_ROM_IMAGE 5
138 #define NP_SERV_FREEZE_FILE 6
139 #define NP_SERV_SRAM_DATA 7
140 #define NP_SERV_READY 8
144 volatile uint8 SendSequenceNum;
145 volatile uint8 ReceiveSequenceNum;
146 volatile bool8 Connected;
147 volatile bool8 SaidHello;
148 volatile bool8 Paused;
149 volatile bool8 Ready;
157 NP_SERVER_SEND_ROM_IMAGE,
159 NP_SERVER_SYNC_CLIENT,
160 NP_SERVER_SEND_FREEZE_FILE_ALL,
161 NP_SERVER_SEND_ROM_LOAD_REQUEST_ALL,
163 NP_SERVER_SEND_SRAM_ALL,
167 #define NP_MAX_TASKS 20
177 struct SNPClient Clients [NP_MAX_CLIENTS];
179 volatile struct NPServerTask TaskQueue [NP_MAX_TASKS];
180 volatile uint32 TaskHead;
181 volatile uint32 TaskTail;
189 bool8 SendROMImageOnConnect;
193 #define NP_MAX_ACTION_LEN 200
199 volatile uint8 MySequenceNum;
200 volatile uint8 ServerSequenceNum;
201 volatile bool8 Connected;
202 volatile bool8 Abort;
203 volatile uint8 Player;
204 volatile bool8 ClientsReady [NP_MAX_CLIENTS];
205 volatile bool8 ClientsPaused [NP_MAX_CLIENTS];
206 volatile bool8 Paused;
207 volatile bool8 PendingWait4Sync;
208 volatile uint8 PercentageComplete;
209 volatile bool8 Waiting4EmulationThread;
210 volatile bool8 Answer;
212 char *ServerHostName;
215 volatile uint32 JoypadWriteInd;
216 volatile uint32 JoypadReadInd;
217 uint32 Joypads [NP_JOYPAD_HIST_SIZE][NP_MAX_CLIENTS];
218 uint32 Frame [NP_JOYPAD_HIST_SIZE];
221 uint32 MaxBehindFrameCount;
222 char ActionMsg [NP_MAX_ACTION_LEN];
223 char ErrorMsg [NP_MAX_ACTION_LEN];
224 char WarningMsg [NP_MAX_ACTION_LEN];
227 extern struct SNetPlay NetPlay;
232 // NETPLAY_CLIENT_HELLO message format:
235 // ROMName (variable)
237 #define WRITE_LONG(p, v) { \
238 *((p) + 0) = (uint8) ((v) >> 24); \
239 *((p) + 1) = (uint8) ((v) >> 16); \
240 *((p) + 2) = (uint8) ((v) >> 8); \
241 *((p) + 3) = (uint8) ((v) >> 0); \
244 #define READ_LONG(p) \
245 ((((uint8) *((p) + 0)) << 24) | \
246 (((uint8) *((p) + 1)) << 16) | \
247 (((uint8) *((p) + 2)) << 8) | \
248 (((uint8) *((p) + 3)) << 0))
250 bool8 S9xNPConnectToServer (const char *server_name, int port,
251 const char *rom_name);
252 bool8 S9xNPWaitForHeartBeat ();
253 uint32 S9xNPGetJoypad (int which1);
254 bool8 S9xNPSendJoypadUpdate (uint32 joypad);
255 void S9xNPDisconnect ();
256 bool8 S9xNPInitialise ();
257 bool8 S9xNPSendData (int fd, const uint8 *data, int len);
258 bool8 S9xNPGetData (int fd, uint8 *data, int len);
260 void S9xNPSyncClients ();
261 void S9xNPStepJoypadHistory ();
263 void S9xNPResetJoypadReadPos ();
264 bool8 S9xNPSendReady (uint8 op = NP_CLNT_READY);
265 bool8 S9xNPSendPause (bool8 pause);
267 void S9xNPSetAction (const char *action, bool8 force = FALSE);
268 void S9xNPSetError (const char *error);
269 void S9xNPSetWarning (const char *warning);
270 void S9xNPDiscardHeartbeats ();
271 void S9xNPServerQueueSendingFreezeFile (const char *filename);
272 void S9xNPServerQueueSyncAll ();
273 void S9xNPServerQueueSendingROMImage ();
274 void S9xNPServerQueueSendingLoadROMRequest (const char *filename);
276 void S9xNPServerAddTask (uint32 task, void *data);
278 bool8 S9xNPStartServer (int port);
279 void S9xNPStopServer ();
281 #define S9xGetMilliTime timeGetTime
283 uint32 S9xGetMilliTime ();