1 /* FCE Ultra - NES/Famicom Emulator
3 * Copyright notice for this file:
4 * Copyright (C) 1998 BERO
5 * Copyright (C) 2002 Xodnizel
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
24 static void FP_FASTAPASS(1) BandaiIRQHook(int a)
31 X6502_IRQBegin(FCEU_IQEXT);
32 //printf("IRQ: %d, %d\n",scanline,timestamp);
39 static DECLFW(Mapper16_write)
48 case 0x9: switch(V&3) {
49 case 0x00:MIRROR_SET2(1);break;
50 case 0x01:MIRROR_SET2(0);break;
51 case 0x02:onemir(0);break;
52 case 0x03:onemir(1);break;
55 case 0xA:X6502_IRQEnd(FCEU_IQEXT);
59 case 0xB:IRQLatch&=0xFF00; IRQLatch|=V;
61 case 0xC:IRQLatch&=0xFF; IRQLatch|=V<<8;
63 case 0xD: break;/* Serial EEPROM control port */
68 // 0-7: Lower bit of data selects which 256KB PRG block is in use.
69 // This seems to be a hack on the developers' part, so I'll make emulation
70 // of it a hack(I think the current PRG block would depend on whatever the
71 // lowest bit of the CHR bank switching register that corresponds to the
72 // last CHR address read).
74 static void PRGO(void)
76 uint32 base=(mapbyte1[0]&1)<<4;
77 ROM_BANK16(0x8000,(mapbyte2[0]&0xF)|base);
78 ROM_BANK16(0xC000,base|0xF);
81 static DECLFW(Mapper153_write)
95 case 0x9: switch(V&3) {
96 case 0x00:MIRROR_SET2(1);break;
97 case 0x01:MIRROR_SET2(0);break;
98 case 0x02:onemir(0);break;
99 case 0x03:onemir(1);break;
102 case 0xA:X6502_IRQEnd(FCEU_IQEXT);
106 case 0xB:IRQLatch&=0xFF00;
109 case 0xC:IRQLatch&=0xFF;
115 void Mapper16_init(void)
117 MapIRQHook=BandaiIRQHook;
118 SetWriteHandler(0x6000,0xFFFF,Mapper16_write);
121 void Mapper153_init(void)
123 MapIRQHook=BandaiIRQHook;
124 SetWriteHandler(0x8000,0xFFFF,Mapper153_write);
125 /* This mapper/board seems to have WRAM at $6000-$7FFF, so I'll let the
126 main ines code take care of that memory region. */
130 static uint8 BarcodeData[256];
131 static int BarcodeReadPos;
132 static int BarcodeCycleCount;
133 static uint32 BarcodeOut;
135 int FCEUI_DatachSet(const uint8 *rcode)
137 int prefix_parity_type[10][6] = {
138 {0,0,0,0,0,0}, {0,0,1,0,1,1}, {0,0,1,1,0,1}, {0,0,1,1,1,0},
139 {0,1,0,0,1,1}, {0,1,1,0,0,1}, {0,1,1,1,0,0}, {0,1,0,1,0,1},
140 {0,1,0,1,1,0}, {0,1,1,0,1,0}
142 int data_left_odd[10][7] = {
143 {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},
144 {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},
145 {0,1,1,0,1,1,1}, {0,0,0,1,0,1,1}
147 int data_left_even[10][7] = {
148 {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},
149 {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},
150 {0,0,0,1,0,0,1}, {0,0,1,0,1,1,1}
152 int data_right[10][7] = {
153 {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},
154 {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},
155 {1,0,0,1,0,0,0}, {1,1,1,0,1,0,0}
162 for(i=len=0;i<13;i++)
166 if((code[i]=rcode[i]-'0') > 9)
170 if(len!=13 && len!=12 && len!=8 && len!=7) return(0);
172 #define BS(x) BarcodeData[tmp_p]=x;tmp_p++
179 /* Left guard bars */
182 if(len==13 || len==12)
187 if(prefix_parity_type[code[0]][i])
191 BS(data_left_even[code[i+1]][j]);
197 BS(data_left_odd[code[i+1]][j]);
200 /* Center guard bars */
201 BS(0); BS(1); BS(0); BS(1); BS(0);
206 BS(data_right[code[i]][j]);
209 for(i=0;i<12;i++) csum+=code[i]*((i&1)?3:1);
210 csum=(10-(csum%10))%10;
211 //printf("%d\n",csum);
214 BS(data_right[csum][j]);
218 else if(len==8 || len==7)
222 for(i=0;i<7;i++) csum+=(i&1)?code[i]:(code[i]*3);
224 csum=(10-(csum%10))%10;
229 BS(data_left_odd[code[i]][j]);
233 /* Center guard bars */
234 BS(0); BS(1); BS(0); BS(1); BS(0);
239 BS(data_right[code[i]][j]);
243 { BS(data_right[csum][j]);}
247 /* Right guard bars */
263 static void FP_FASTAPASS(1) BarcodeIRQHook(int a)
267 BarcodeCycleCount+=a;
269 if(BarcodeCycleCount >= 1000)
271 BarcodeCycleCount -= 1000;
272 if(BarcodeData[BarcodeReadPos]==0xFF)
278 BarcodeOut=(BarcodeData[BarcodeReadPos]^1)<<3;
284 static DECLFR(Mapper157_read)
292 void Mapper157_init(void)
294 FCEUGameInfo.cspecial = SIS_DATACH;
295 MapIRQHook=BarcodeIRQHook;
296 SetWriteHandler(0x6000,0xFFFF,Mapper16_write);
297 SetReadHandler(0x6000,0x7FFF,Mapper157_read);