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
34 extern int cpu_repeat;
35 extern int cpu_lastval;
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 uint16 joy[4]={0,0,0,0};
50 static int FSDisable=0; /* Set to 1 if NES-style four-player adapter is disabled. */
51 static int JPAttrib[2]={0,0};
52 static int JPType[2]={0,0};
53 static void *InputDataPtr[2];
55 static int JPAttribFC=0;
56 static int JPTypeFC=0;
57 static void *InputDataPtrFC;
59 void (*InputScanlineHook)(uint8 *buf, int line);
61 static INPUTC DummyJPort={0,0,0,0,0};
62 static INPUTC *JPorts[2]={&DummyJPort,&DummyJPort};
63 static INPUTCFC *FCExp=0;
65 static uint8 FP_FASTAPASS(1) ReadGPVS(int w)
73 ret = ((joy[w]>>(joy_readbit[w]))&1);
79 static uint8 FP_FASTAPASS(1) ReadGP(int w)
84 //ret = ((joy[w]>>(joy_readbit[w]))&1)|
85 //(((joy[w]>>(joy_readbit[w]+8))&1)<<1);
86 //if(joy_readbit[w]>8) ret=0;
88 ret = ((joy[w]>>(joy_readbit[w]))&1);
91 if(joy_readbit[w]>=8) ret|=1;
95 if(joy_readbit[w]==19-w) ret|=1;
101 static DECLFR(JPRead)
105 #ifdef DEBUG_ASM_6502
106 if (cpu_repeat) return cpu_lastval;
108 if(JPorts[A&1]->Read)
109 ret|=JPorts[A&1]->Read(A&1);
113 ret=FCExp->Read(A&1,ret);
116 #ifdef DEBUG_ASM_6502
129 JPorts[0]->Write(V&1);
131 JPorts[1]->Write(V&1);
133 if((PSG[0x16]&1) && (!(V&1)))
135 /* This strobe code is just for convenience. If it were
136 with the code in input / *.c, it would more accurately represent
137 what's really going on. But who wants accuracy? ;)
138 Seriously, though, this shouldn't be a problem.
140 if(JPorts[0]->Strobe)
141 JPorts[0]->Strobe(0);
142 if(JPorts[1]->Strobe)
143 JPorts[1]->Strobe(1);
151 static void FP_FASTAPASS(1) StrobeGP(int w)
156 static INPUTC GPC={ReadGP,0,StrobeGP,0,0,0};
157 static INPUTC GPCVS={ReadGPVS,0,StrobeGP,0,0,0};
159 void DrawInput(uint8 *buf)
165 JPorts[x]->Draw(x,buf,JPAttrib[x]);
168 FCExp->Draw(buf,JPAttribFC);
171 void UpdateInput(void)
180 if(!x) joy[0]=*(uint16 *)InputDataPtr[0];
181 else joy[1]=*(uint16 *)InputDataPtr[1];
184 if(JPorts[x]->Update)
185 JPorts[x]->Update(x,InputDataPtr[x],JPAttrib[x]);
191 FCExp->Update(InputDataPtrFC,JPAttribFC);
193 if(FCEUGameInfo.type==GIT_VSUNI)
196 joy[0]=(joy[0]&0xC)|(joy[1]&0xF3);
197 joy[1]=(joy[1]&0xC)|(t&0xF3);
201 if(netplay) NetplayUpdate(&joy[0],&joy[1]);
203 if (current < 0) FCEUMOV_AddJoy(joy);
207 static DECLFR(VSUNIRead0)
212 ret|=(JPorts[0]->Read(0))&1;
220 static DECLFR(VSUNIRead1)
225 ret|=(JPorts[1]->Read(1))&1;
230 static void SLHLHook(uint8 *buf, int line)
235 if(JPorts[x]->SLHook)
236 JPorts[x]->SLHook(x,buf,line);
239 FCExp->SLHook(buf,line);
242 static void CheckSLHook(void)
245 if(JPorts[0]->SLHook || JPorts[1]->SLHook)
246 InputScanlineHook=SLHLHook;
249 InputScanlineHook=SLHLHook;
252 static void FASTAPASS(1) SetInputStuff(int x)
257 if(FCEUGameInfo.type==GIT_VSUNI)
262 case SI_ARKANOID:JPorts[x]=FCEU_InitArkanoid(x);break;
263 case SI_ZAPPER:JPorts[x]=FCEU_InitZapper(x);break;
264 case SI_POWERPAD:JPorts[x]=FCEU_InitPowerpad(x);break;
265 case SI_NONE:JPorts[x]=&DummyJPort;break;
271 static uint8 F4ReadBit[2];
272 static void StrobeFami4(void)
274 F4ReadBit[0]=F4ReadBit[1]=0;
277 static uint8 FP_FASTAPASS(2) ReadFami4(int w, uint8 ret)
281 ret |= ((joy[w]>>(F4ReadBit[w]+8))&1)<<1;
282 if(F4ReadBit[w]>=8) ret|=2;
288 static INPUTCFC FAMI4C={ReadFami4,0,StrobeFami4,0,0,0};
289 static void SetInputStuffFC(void)
293 case SIFC_NONE:FCExp=0;break;
294 case SIFC_ARKANOID:FCExp=FCEU_InitArkanoidFC();break;
295 case SIFC_SHADOW:FCExp=FCEU_InitSpaceShadow();break;
296 case SIFC_4PLAYER:FCExp=&FAMI4C;memset(&F4ReadBit,0,sizeof(F4ReadBit));break;
297 case SIFC_FKB:FCExp=FCEU_InitFKB();break;
302 // VS Unisystem code called after SetInputMap() hooks B4016. Need to
303 // rewrite code to make this more sane?
305 void InitializeInput(void)
307 memset(joy_readbit,0,sizeof(joy_readbit));
308 memset(joy,0,sizeof(joy));
310 if(FCEUGameInfo.type==GIT_VSUNI)
312 SetReadHandler(0x4016,0x4016,VSUNIRead0);
313 SetReadHandler(0x4017,0x4017,VSUNIRead1);
316 SetReadHandler(0x4016,0x4017,JPRead);
317 SetWriteHandler(0x4016,0x4016,B4016);
324 void FCEUI_SetInput(int port, int type, void *ptr, int attrib)
326 JPAttrib[port]=attrib;
328 InputDataPtr[port]=ptr;
332 void FCEUI_DisableFourScore(int s)
337 void FCEUI_SetInputFC(int type, void *ptr, int attrib)