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
36 extern INPUTC *FCEU_InitZapper(int w);
37 extern INPUTC *FCEU_InitPowerpad(int w);
38 extern INPUTC *FCEU_InitArkanoid(int w);
40 extern INPUTCFC *FCEU_InitArkanoidFC(void);
41 extern INPUTCFC *FCEU_InitSpaceShadow(void);
42 extern INPUTCFC *FCEU_InitFKB(void);
43 static uint8 joy_readbit[2];
44 static uint8 joy[4]={0,0,0,0};
45 static uint8 LastStrobe;
49 static int FSDisable=0; /* Set to 1 if NES-style four-player adapter is disabled. */
50 static int JPAttrib[2]={0,0};
51 static int JPType[2]={0,0};
52 static void *InputDataPtr[2];
54 static int JPAttribFC=0;
55 static int JPTypeFC=0;
56 static void *InputDataPtrFC;
58 void (*InputScanlineHook)(uint8 *buf, int line);
60 static INPUTC DummyJPort={0,0,0,0,0};
61 static INPUTC *JPorts[2]={&DummyJPort,&DummyJPort};
62 static INPUTCFC *FCExp=0;
64 static uint8 FP_FASTAPASS(1) ReadGPVS(int w)
72 ret = ((joy[w]>>(joy_readbit[w]))&1);
78 static uint8 FP_FASTAPASS(1) ReadGP(int w)
83 //ret = ((joy[w]>>(joy_readbit[w]))&1)|
84 //(((joy[w]>>(joy_readbit[w]+8))&1)<<1);
85 //if(joy_readbit[w]>8) ret=0;
87 ret = ((joy[w]>>(joy_readbit[w]))&1);
90 if(joy_readbit[w]>=8) ret|=1;
94 if(joy_readbit[w]==19-w) ret|=1;
100 static DECLFR(JPRead)
104 if(JPorts[A&1]->Read)
105 ret|=JPorts[A&1]->Read(A&1);
109 ret=FCExp->Read(A&1,ret);
112 dprintf("JPRead %02x", ret);
123 JPorts[0]->Write(V&1);
125 JPorts[1]->Write(V&1);
127 if((LastStrobe&1) && (!(V&1)))
129 /* This strobe code is just for convenience. If it were
130 with the code in input / *.c, it would more accurately represent
131 what's really going on. But who wants accuracy? ;)
132 Seriously, though, this shouldn't be a problem.
134 if(JPorts[0]->Strobe)
135 JPorts[0]->Strobe(0);
136 if(JPorts[1]->Strobe)
137 JPorts[1]->Strobe(1);
145 static void FP_FASTAPASS(1) StrobeGP(int w)
150 static INPUTC GPC={ReadGP,0,StrobeGP,0,0,0};
151 static INPUTC GPCVS={ReadGPVS,0,StrobeGP,0,0,0};
153 void DrawInput(uint8 *buf)
159 JPorts[x]->Draw(x,buf,JPAttrib[x]);
162 FCExp->Draw(buf,JPAttribFC);
165 void UpdateInput(void)
174 if(!x) joy[0]=*(uint16 *)InputDataPtr[0];
175 else joy[1]=*(uint16 *)InputDataPtr[1];
178 if(JPorts[x]->Update)
179 JPorts[x]->Update(x,InputDataPtr[x],JPAttrib[x]);
185 FCExp->Update(InputDataPtrFC,JPAttribFC);
187 if(FCEUGameInfo.type==GIT_VSUNI)
190 joy[0]=(joy[0]&0xC)|(joy[1]&0xF3);
191 joy[1]=(joy[1]&0xC)|(t&0xF3);
195 if(netplay) NetplayUpdate(&joy[0],&joy[1]);
197 if (current < 0) FCEUMOV_AddJoy(joy);
201 static DECLFR(VSUNIRead0)
206 ret|=(JPorts[0]->Read(0))&1;
214 static DECLFR(VSUNIRead1)
219 ret|=(JPorts[1]->Read(1))&1;
224 static void SLHLHook(uint8 *buf, int line)
229 if(JPorts[x]->SLHook)
230 JPorts[x]->SLHook(x,buf,line);
233 FCExp->SLHook(buf,line);
236 static void CheckSLHook(void)
239 if(JPorts[0]->SLHook || JPorts[1]->SLHook)
240 InputScanlineHook=SLHLHook;
243 InputScanlineHook=SLHLHook;
246 static void FASTAPASS(1) SetInputStuff(int x)
251 if(FCEUGameInfo.type==GIT_VSUNI)
256 case SI_ARKANOID:JPorts[x]=FCEU_InitArkanoid(x);break;
257 case SI_ZAPPER:JPorts[x]=FCEU_InitZapper(x);break;
258 case SI_POWERPAD:JPorts[x]=FCEU_InitPowerpad(x);break;
259 case SI_NONE:JPorts[x]=&DummyJPort;break;
265 static uint8 F4ReadBit[2];
266 static void StrobeFami4(void)
268 F4ReadBit[0]=F4ReadBit[1]=0;
271 static uint8 FP_FASTAPASS(2) ReadFami4(int w, uint8 ret)
275 ret |= ((joy[w]>>(F4ReadBit[w]+8))&1)<<1;
276 if(F4ReadBit[w]>=8) ret|=2;
282 static INPUTCFC FAMI4C={ReadFami4,0,StrobeFami4,0,0,0};
283 static void SetInputStuffFC(void)
287 case SIFC_NONE:FCExp=0;break;
288 case SIFC_ARKANOID:FCExp=FCEU_InitArkanoidFC();break;
289 case SIFC_SHADOW:FCExp=FCEU_InitSpaceShadow();break;
290 case SIFC_4PLAYER:FCExp=&FAMI4C;memset(&F4ReadBit,0,sizeof(F4ReadBit));break;
291 case SIFC_FKB:FCExp=FCEU_InitFKB();break;
296 // VS Unisystem code called after SetInputMap() hooks B4016. Need to
297 // rewrite code to make this more sane?
299 void InitializeInput(void)
301 memset(joy_readbit,0,sizeof(joy_readbit));
302 memset(joy,0,sizeof(joy));
305 if(FCEUGameInfo.type==GIT_VSUNI)
307 SetReadHandler(0x4016,0x4016,VSUNIRead0);
308 SetReadHandler(0x4017,0x4017,VSUNIRead1);
311 SetReadHandler(0x4016,0x4017,JPRead);
312 SetWriteHandler(0x4016,0x4016,B4016);
319 void FCEUI_SetInput(int port, int type, void *ptr, int attrib)
321 JPAttrib[port]=attrib;
323 InputDataPtr[port]=ptr;
327 void FCEUI_DisableFourScore(int s)
332 void FCEUI_SetInputFC(int type, void *ptr, int attrib)
341 #define FCEUNPCMD_RESET 0x01
342 #define FCEUNPCMD_POWER 0x02
344 #define FCEUNPCMD_VSUNICOIN 0x07
345 #define FCEUNPCMD_VSUNIDIP0 0x08
346 #define FCEUNPCMD_FDSINSERT 0x18
347 #define FCEUNPCMD_FDSSELECT 0x1A
350 void FCEU_DoSimpleCommand(int cmd)
354 // case FCEUNPCMD_FDSINSERT: FCEU_FDSInsert();break;
355 // case FCEUNPCMD_FDSSELECT: FCEU_FDSSelect();break;
356 // case FCEUNPCMD_FDSEJECT: FCEU_FDSEject();break;
357 // case FCEUNPCMD_VSUNICOIN: FCEU_VSUniCoin(); break;
358 // case FCEUNPCMD_VSUNIDIP0 ... (FCEUNPCMD_VSUNIDIP0 + 7): FCEU_VSUniToggleDIP(cmd - FCEUNPCMD_VSUNIDIP0);break;
359 case FCEUNPCMD_POWER: PowerNES();break;
360 case FCEUNPCMD_RESET: ResetNES();break;
361 default: printf("FCEU_DoSimpleCommand: can't handle cmd %i\n", cmd); break;
366 SFORMAT FCEUCTRL_STATEINFO[]={
367 { joy_readbit, 2, "JYRB"},
369 { &LastStrobe, 1, "LSTS"},