1 /* FCE Ultra - NES/Famicom Emulator
\r
3 * Copyright notice for this file:
\r
4 * Copyright (C) 2007 CaH4e3
\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
26 static uint8 reg[16], is153;
\r
28 static int16 IRQCount, IRQLatch;
\r
30 static uint8 *WRAM=NULL;
\r
31 static uint32 WRAMSIZE;
\r
33 static SFORMAT StateRegs[]=
\r
37 {&IRQCount, 2, "IRQC"},
\r
38 {&IRQLatch, 2, "IRQL"}, // need for Famicom Jump II - Saikyou no 7 Nin (J) [!]
\r
42 static void FP_FASTAPASS(1) BandaiIRQHook(int a)
\r
49 X6502_IRQBegin(FCEU_IQEXT);
\r
56 static void BandaiSync(void)
\r
61 for(i=0; i<8; i++) setchr1(i<<10,reg[i]);
\r
67 int base=(reg[0]&1)<<4;
\r
68 setprg16(0x8000,(reg[8]&0x0F)|base);
\r
69 setprg16(0xC000,0x0F|base);
\r
73 setprg16(0x8000,reg[8]);
\r
74 setprg16(0xC000,~0);
\r
78 case 0: setmirror(MI_V); break;
\r
79 case 1: setmirror(MI_H); break;
\r
80 case 2: setmirror(MI_0); break;
\r
81 case 3: setmirror(MI_1); break;
\r
85 static DECLFW(BandaiWrite)
\r
96 case 0x0A: X6502_IRQEnd(FCEU_IQEXT); IRQa=V&1; IRQCount=IRQLatch; break;
\r
97 case 0x0B: IRQLatch&=0xFF00; IRQLatch|=V; break;
\r
98 case 0x0C: IRQLatch&=0xFF; IRQLatch|=V<<8; break;
\r
99 case 0x0D: break;// Serial EEPROM control port
\r
103 static void BandaiPower(void)
\r
106 SetReadHandler(0x8000,0xFFFF,CartBR);
\r
107 SetWriteHandler(0x6000,0xFFFF,BandaiWrite);
\r
110 static void StateRestore(int version)
\r
115 void Mapper16_Init(CartInfo *info)
\r
118 info->Power=BandaiPower;
\r
119 MapIRQHook=BandaiIRQHook;
\r
120 GameStateRestore=StateRestore;
\r
121 AddExState(&StateRegs, ~0, 0, 0);
\r
125 // 0-7: Lower bit of data selects which 256KB PRG block is in use.
\r
126 // This seems to be a hack on the developers' part, so I'll make emulation
\r
127 // of it a hack(I think the current PRG block would depend on whatever the
\r
128 // lowest bit of the CHR bank switching register that corresponds to the
\r
129 // last CHR address read).
\r
131 static void M153Power(void)
\r
134 setprg8r(0x10,0x6000,0);
\r
135 SetReadHandler(0x6000,0x7FFF,CartBR);
\r
136 SetWriteHandler(0x6000,0x7FFF,CartBW);
\r
137 SetReadHandler(0x8000,0xFFFF,CartBR);
\r
138 SetWriteHandler(0x8000,0xFFFF,BandaiWrite);
\r
142 static void M153Close(void)
\r
149 void Mapper153_Init(CartInfo *info)
\r
152 info->Power=M153Power;
\r
153 info->Close=M153Close;
\r
154 MapIRQHook=BandaiIRQHook;
\r
157 WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);
\r
158 SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);
\r
159 AddExState(WRAM, WRAMSIZE, 0, "WRAM");
\r
163 info->SaveGame[0]=WRAM;
\r
164 info->SaveGameLen[0]=WRAMSIZE;
\r
167 GameStateRestore=StateRestore;
\r
168 AddExState(&StateRegs, ~0, 0, 0);
\r
171 // Datach Barcode Battler
\r
173 static uint8 BarcodeData[256];
\r
174 static int BarcodeReadPos;
\r
175 static int BarcodeCycleCount;
\r
176 static uint32 BarcodeOut;
\r
178 int FCEUI_DatachSet(const uint8 *rcode)
\r
180 int prefix_parity_type[10][6] = {
\r
181 {0,0,0,0,0,0}, {0,0,1,0,1,1}, {0,0,1,1,0,1}, {0,0,1,1,1,0},
\r
182 {0,1,0,0,1,1}, {0,1,1,0,0,1}, {0,1,1,1,0,0}, {0,1,0,1,0,1},
\r
183 {0,1,0,1,1,0}, {0,1,1,0,1,0}
\r
185 int data_left_odd[10][7] = {
\r
186 {0,0,0,1,1,0,1}, {0,0,1,1,0,0,1}, {0,0,1,0,0,1,1}, {0,1,1,1,1,0,1},
\r
187 {0,1,0,0,0,1,1}, {0,1,1,0,0,0,1}, {0,1,0,1,1,1,1}, {0,1,1,1,0,1,1},
\r
188 {0,1,1,0,1,1,1}, {0,0,0,1,0,1,1}
\r
190 int data_left_even[10][7] = {
\r
191 {0,1,0,0,1,1,1}, {0,1,1,0,0,1,1}, {0,0,1,1,0,1,1}, {0,1,0,0,0,0,1},
\r
192 {0,0,1,1,1,0,1}, {0,1,1,1,0,0,1}, {0,0,0,0,1,0,1}, {0,0,1,0,0,0,1},
\r
193 {0,0,0,1,0,0,1}, {0,0,1,0,1,1,1}
\r
195 int data_right[10][7] = {
\r
196 {1,1,1,0,0,1,0}, {1,1,0,0,1,1,0}, {1,1,0,1,1,0,0}, {1,0,0,0,0,1,0},
\r
197 {1,0,1,1,1,0,0}, {1,0,0,1,1,1,0}, {1,0,1,0,0,0,0}, {1,0,0,0,1,0,0},
\r
198 {1,0,0,1,0,0,0}, {1,1,1,0,1,0,0}
\r
205 for(i=len=0;i<13;i++)
\r
207 if(!rcode[i]) break;
\r
208 if((code[i]=rcode[i]-'0') > 9)
\r
212 if(len!=13 && len!=12 && len!=8 && len!=7) return(0);
\r
214 #define BS(x) BarcodeData[tmp_p]=x;tmp_p++
\r
221 /* Left guard bars */
\r
222 BS(1); BS(0); BS(1);
\r
224 if(len==13 || len==12)
\r
229 if(prefix_parity_type[code[0]][i])
\r
233 BS(data_left_even[code[i+1]][j]);
\r
239 BS(data_left_odd[code[i+1]][j]);
\r
242 /* Center guard bars */
\r
243 BS(0); BS(1); BS(0); BS(1); BS(0);
\r
248 BS(data_right[code[i]][j]);
\r
251 for(i=0;i<12;i++) csum+=code[i]*((i&1)?3:1);
\r
252 csum=(10-(csum%10))%10;
\r
255 BS(data_right[csum][j]);
\r
259 else if(len==8 || len==7)
\r
263 for(i=0;i<7;i++) csum+=(i&1)?code[i]:(code[i]*3);
\r
265 csum=(10-(csum%10))%10;
\r
270 BS(data_left_odd[code[i]][j]);
\r
274 /* Center guard bars */
\r
275 BS(0); BS(1); BS(0); BS(1); BS(0);
\r
280 BS(data_right[code[i]][j]);
\r
284 { BS(data_right[csum][j]);}
\r
288 /* Right guard bars */
\r
289 BS(1); BS(0); BS(1);
\r
302 BarcodeCycleCount=0;
\r
306 static void FP_FASTAPASS(1) BarcodeIRQHook(int a)
\r
310 BarcodeCycleCount+=a;
\r
312 if(BarcodeCycleCount >= 1000)
\r
314 BarcodeCycleCount -= 1000;
\r
315 if(BarcodeData[BarcodeReadPos]==0xFF)
\r
321 BarcodeOut=(BarcodeData[BarcodeReadPos]^1)<<3;
\r
327 static DECLFR(BarcodeRead)
\r
332 static void M157Power(void)
\r
334 BarcodeData[0]=0xFF;
\r
337 BarcodeCycleCount=0;
\r
341 SetWriteHandler(0x6000,0xFFFF,BandaiWrite);
\r
342 SetReadHandler(0x6000,0x7FFF,BarcodeRead);
\r
343 SetReadHandler(0x8000,0xFFFF,CartBR);
\r
346 void Mapper157_Init(CartInfo *info)
\r
349 info->Power=M157Power;
\r
350 MapIRQHook=BarcodeIRQHook;
\r
352 GameInfo->cspecial = SIS_DATACH;
\r
354 GameStateRestore=StateRestore;
\r
355 AddExState(&StateRegs, ~0, 0, 0);
\r