1 /* FCE Ultra - NES/Famicom Emulator
\r
3 * Copyright notice for this file:
\r
4 * Copyright (C) 2002 Ben Parnell
\r
6 * This program is free software; you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation; either version 2 of the License, or
\r
9 * (at your option) any later version.
\r
11 * This program is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with this program; if not, write to the Free Software
\r
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
29 #include "netplay.h"
\r
31 int netplay=0; /* 1 if we are a server */
\r
32 /* 2 if we need a host */
\r
33 static uint8 netjoy[4]; // controller stuff.
\r
35 static void NetError(void)
\r
37 FCEU_DispMessage("Network error/connection lost!");
\r
38 // FCEUD_PrintError("Network error/connection lost!");
\r
40 FCEUD_NetworkClose();
\r
43 void KillNetplay(void)
\r
47 FCEUD_NetworkClose();
\r
52 int InitNetplay(void)
\r
54 if(!FCEUD_NetworkConnect())
\r
55 {NetError();return 0;}
\r
56 netplay=FSettings.NetworkPlay;
\r
57 memset(netjoy,0,sizeof(netjoy));
\r
61 void NetplayUpdate(uint16 *joyp1, uint16 *joyp2)
\r
64 if(netplay==1) // We're the server
\r
70 t=FCEUD_NetworkRecvData(&netjoy[2],1,0);
\r
71 if(!t) {NetError();return;}
\r
72 if(t!=-1) goto loopo;
\r
75 memcpy(buf,netjoy,4);
\r
76 buf[4]=CommandQueue;
\r
78 if(!FCEUD_NetworkSendData(buf,5)) {NetError();return;}
\r
81 DoCommand(CommandQueue);
\r
85 else if(netplay==2) // We're connected to a host (we're second player)
\r
87 uint8 ja=(*joyp1)|(*joyp1>>8)|(*joyp2)|(*joyp2>>8);
\r
88 if(!FCEUD_NetworkSendData(&ja,1)) {NetError();return;}
\r
89 if(!FCEUD_NetworkRecvData(buf,5,1)) {NetError();return;}
\r
91 memcpy(netjoy,buf,4);
\r
92 if(buf[4]) DoCommand(buf[4]);
\r
94 *joyp1=netjoy[0]|(netjoy[1]<<8);
\r
95 *joyp2=netjoy[2]|(netjoy[3]<<8);
\r