1 /* FCE Ultra - NES/Famicom Emulator
3 * Copyright notice for this file:
4 * Copyright (C) 1998 BERO
5 * Copyright (C) 2002 Ben Parnell
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38 extern INPUTC *FCEU_InitZapper(int w);
39 extern INPUTC *FCEU_InitPowerpad(int w);
40 extern INPUTC *FCEU_InitArkanoid(int w);
42 extern INPUTCFC *FCEU_InitArkanoidFC(void);
43 extern INPUTCFC *FCEU_InitSpaceShadow(void);
44 extern INPUTCFC *FCEU_InitFKB(void);
45 static uint8 joy_readbit[2];
46 static uint8 joy[4]={0,0,0,0};
47 static uint8 LastStrobe;
51 static int FSDisable=0; /* Set to 1 if NES-style four-player adapter is disabled. */
52 static int JPAttrib[2]={0,0};
53 static int JPType[2]={0,0};
54 static void *InputDataPtr[2];
56 static int JPAttribFC=0;
57 static int JPTypeFC=0;
58 static void *InputDataPtrFC;
60 void (*InputScanlineHook)(uint8 *buf, int line);
62 static INPUTC DummyJPort={0,0,0,0,0};
63 static INPUTC *JPorts[2]={&DummyJPort,&DummyJPort};
64 static INPUTCFC *FCExp=0;
66 /* This function is a quick hack to get the NSF player to use emulated gamepad
69 uint8 FCEU_GetJoyJoy(void)
71 return(joy[0]|joy[1]|joy[2]|joy[3]);
74 static uint8 FP_FASTAPASS(1) ReadGPVS(int w)
82 ret = ((joy[w]>>(joy_readbit[w]))&1);
88 static uint8 FP_FASTAPASS(1) ReadGP(int w)
93 //ret = ((joy[w]>>(joy_readbit[w]))&1)|
94 //(((joy[w]>>(joy_readbit[w]+8))&1)<<1);
95 //if(joy_readbit[w]>8) ret=0;
97 ret = ((joy[w]>>(joy_readbit[w]))&1);
100 if(joy_readbit[w]>=8) ret|=1;
104 if(joy_readbit[w]==19-w) ret|=1;
110 static DECLFR(JPRead)
114 if(JPorts[A&1]->Read)
115 ret|=JPorts[A&1]->Read(A&1);
119 ret=FCExp->Read(A&1,ret);
122 dprintf("JPRead %02x", ret);
133 JPorts[0]->Write(V&1);
135 JPorts[1]->Write(V&1);
137 if((LastStrobe&1) && (!(V&1)))
139 /* This strobe code is just for convenience. If it were
140 with the code in input / *.c, it would more accurately represent
141 what's really going on. But who wants accuracy? ;)
142 Seriously, though, this shouldn't be a problem.
144 if(JPorts[0]->Strobe)
145 JPorts[0]->Strobe(0);
146 if(JPorts[1]->Strobe)
147 JPorts[1]->Strobe(1);
155 static void FP_FASTAPASS(1) StrobeGP(int w)
160 static INPUTC GPC={ReadGP,0,StrobeGP,0,0,0};
161 static INPUTC GPCVS={ReadGPVS,0,StrobeGP,0,0,0};
163 void DrawInput(uint8 *buf)
169 JPorts[x]->Draw(x,buf,JPAttrib[x]);
172 FCExp->Draw(buf,JPAttribFC);
175 void UpdateInput(void)
184 if(!x) joy[0]=*(uint16 *)InputDataPtr[0];
185 else joy[1]=*(uint16 *)InputDataPtr[1];
188 if(JPorts[x]->Update)
189 JPorts[x]->Update(x,InputDataPtr[x],JPAttrib[x]);
195 FCExp->Update(InputDataPtrFC,JPAttribFC);
197 if(FCEUGameInfo.type==GIT_VSUNI)
200 joy[0]=(joy[0]&0xC)|(joy[1]&0xF3);
201 joy[1]=(joy[1]&0xC)|(t&0xF3);
205 if(netplay) NetplayUpdate(&joy[0],&joy[1]);
207 if (current < 0) FCEUMOV_AddJoy(joy);
208 else framecount++; // for debug
209 //FlushCommandQueue();
212 static DECLFR(VSUNIRead0)
217 ret|=(JPorts[0]->Read(0))&1;
225 static DECLFR(VSUNIRead1)
230 ret|=(JPorts[1]->Read(1))&1;
235 static void SLHLHook(uint8 *buf, int line)
240 if(JPorts[x]->SLHook)
241 JPorts[x]->SLHook(x,buf,line);
244 FCExp->SLHook(buf,line);
247 static void CheckSLHook(void)
250 if(JPorts[0]->SLHook || JPorts[1]->SLHook)
251 InputScanlineHook=SLHLHook;
254 InputScanlineHook=SLHLHook;
257 static void FASTAPASS(1) SetInputStuff(int x)
262 if(FCEUGameInfo.type==GIT_VSUNI)
267 case SI_ARKANOID:JPorts[x]=FCEU_InitArkanoid(x);break;
268 case SI_ZAPPER:JPorts[x]=FCEU_InitZapper(x);break;
269 case SI_POWERPADA:JPorts[x]=FCEU_InitPowerpad(x);break;
270 case SI_NONE:JPorts[x]=&DummyJPort;break;
276 static uint8 F4ReadBit[2];
277 static void StrobeFami4(void)
279 F4ReadBit[0]=F4ReadBit[1]=0;
282 static uint8 FP_FASTAPASS(2) ReadFami4(int w, uint8 ret)
286 ret |= ((joy[w]>>(F4ReadBit[w]+8))&1)<<1;
287 if(F4ReadBit[w]>=8) ret|=2;
293 static INPUTCFC FAMI4C={ReadFami4,0,StrobeFami4,0,0,0};
294 static void SetInputStuffFC(void)
298 case SIFC_NONE:FCExp=0;break;
299 case SIFC_ARKANOID:FCExp=FCEU_InitArkanoidFC();break;
300 case SIFC_SHADOW:FCExp=FCEU_InitSpaceShadow();break;
301 case SIFC_4PLAYER:FCExp=&FAMI4C;memset(&F4ReadBit,0,sizeof(F4ReadBit));break;
302 case SIFC_FKB:FCExp=FCEU_InitFKB();break;
307 // VS Unisystem code called after SetInputMap() hooks B4016. Need to
308 // rewrite code to make this more sane?
310 void InitializeInput(void)
312 memset(joy_readbit,0,sizeof(joy_readbit));
313 memset(joy,0,sizeof(joy));
316 if(FCEUGameInfo.type==GIT_VSUNI)
318 SetReadHandler(0x4016,0x4016,VSUNIRead0);
319 SetReadHandler(0x4017,0x4017,VSUNIRead1);
322 SetReadHandler(0x4016,0x4017,JPRead);
323 SetWriteHandler(0x4016,0x4016,B4016);
330 void FCEUI_SetInput(int port, int type, void *ptr, int attrib)
332 JPAttrib[port]=attrib;
334 InputDataPtr[port]=ptr;
338 void FCEUI_DisableFourScore(int s)
343 void FCEUI_SetInputFC(int type, void *ptr, int attrib)
351 void FCEU_DoSimpleCommand(int cmd)
355 case FCEUNPCMD_FDSINSERT: FCEU_FDSInsert();break;
356 case FCEUNPCMD_FDSSELECT: FCEU_FDSSelect();break;
357 // case FCEUNPCMD_FDSEJECT: FCEU_FDSEject();break;
358 case FCEUNPCMD_VSUNICOIN: FCEU_VSUniCoin(); break;
359 case FCEUNPCMD_VSUNIDIP0 ... (FCEUNPCMD_VSUNIDIP0 + 7): FCEU_VSUniToggleDIP(cmd - FCEUNPCMD_VSUNIDIP0);break;
360 case FCEUNPCMD_POWER: PowerNES();break;
361 case FCEUNPCMD_RESET: ResetNES();break;
362 default: printf("FCEU_DoSimpleCommand: can't handle cmd %i\n", cmd); break;
366 void FCEU_QSimpleCommand(int cmd)
369 // FCEUNET_SendCommand(cmd, 0);
373 // if(!FCEUMOV_IsPlaying())
374 // FCEU_DoSimpleCommand(cmd);
376 // FCEUMOV_AddCommand(cmd);
378 FCEU_DoSimpleCommand(cmd);
379 // if(FCEUMOV_IsRecording())
380 // FCEUMOV_AddCommand(cmd);
384 void FCEUI_FDSSelect(void)
386 FCEU_QSimpleCommand(FCEUNPCMD_FDSSELECT);
389 int FCEUI_FDSInsert(void)
391 FCEU_QSimpleCommand(FCEUNPCMD_FDSINSERT);
396 int FCEUI_FDSEject(void)
398 FCEU_QSimpleCommand(FCEUNPCMD_FDSEJECT);
402 void FCEUI_VSUniToggleDIP(int w)
404 FCEU_QSimpleCommand(FCEUNPCMD_VSUNIDIP0 + w);
407 void FCEUI_VSUniCoin(void)
409 FCEU_QSimpleCommand(FCEUNPCMD_VSUNICOIN);
412 void FCEUI_ResetNES(void)
414 FCEU_QSimpleCommand(FCEUNPCMD_RESET);
417 void FCEUI_PowerNES(void)
419 FCEU_QSimpleCommand(FCEUNPCMD_POWER);
424 SFORMAT FCEUCTRL_STATEINFO[]={
425 { joy_readbit, 2, "JYRB"},
427 { &LastStrobe, 1, "LSTS"},