1 /* FCE Ultra - NES/Famicom Emulator
\r
3 * Copyright notice for this file:
\r
4 * Copyright (C) 2007 CaH4e3
\r
5 * Copyright (C) 2011 FCEUX team
\r
7 * This program is free software; you can redistribute it and/or modify
\r
8 * it under the terms of the GNU General Public License as published by
\r
9 * the Free Software Foundation; either version 2 of the License, or
\r
10 * (at your option) any later version.
\r
12 * This program is distributed in the hope that it will be useful,
\r
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 * GNU General Public License for more details.
\r
17 * You should have received a copy of the GNU General Public License
\r
18 * along with this program; if not, write to the Free Software
\r
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
\r
25 //Famicom Jump 2 should get transformed to m153
\r
26 //All other games are not supporting EEPROM saving right now.
\r
27 //We may need to distinguish between 16 and 159 in order to know the EEPROM configuration.
\r
28 //Until then, we just return 0x00 from the EEPROM read
\r
32 static uint8 reg[16], is153;
\r
34 static int16 IRQCount, IRQLatch;
\r
36 static uint8 *WRAM=NULL;
\r
37 static uint32 WRAMSIZE;
\r
39 static SFORMAT StateRegs[]=
\r
43 {&IRQCount, 2, "IRQC"},
\r
44 {&IRQLatch, 2, "IRQL"}, // need for Famicom Jump II - Saikyou no 7 Nin (J) [!]
\r
48 static void BandaiIRQHook(int a)
\r
55 X6502_IRQBegin(FCEU_IQEXT);
\r
62 static void BandaiSync(void)
\r
66 int base=(reg[0]&1)<<4;
\r
68 setprg16(0x8000,(reg[8]&0x0F)|base);
\r
69 setprg16(0xC000,0x0F|base);
\r
74 for(i=0; i<8; i++) setchr1(i<<10,reg[i]);
\r
75 setprg16(0x8000,reg[8]);
\r
76 setprg16(0xC000,~0);
\r
80 case 0: setmirror(MI_V); break;
\r
81 case 1: setmirror(MI_H); break;
\r
82 case 2: setmirror(MI_0); break;
\r
83 case 3: setmirror(MI_1); break;
\r
87 static DECLFW(BandaiWrite)
\r
98 case 0x0A: X6502_IRQEnd(FCEU_IQEXT); IRQa=V&1; IRQCount=IRQLatch; break;
\r
99 case 0x0B: IRQLatch&=0xFF00; IRQLatch|=V; break;
\r
100 case 0x0C: IRQLatch&=0xFF; IRQLatch|=V<<8; break;
\r
101 case 0x0D: break;// Serial EEPROM control port
\r
110 static void BandaiPower(void)
\r
113 SetReadHandler(0x8000,0xFFFF,CartBR);
\r
114 SetWriteHandler(0x6000,0xFFFF,BandaiWrite);
\r
115 SetReadHandler(0x6000,0x7FFF,BandaiRead);
\r
118 static void M153Power(void)
\r
121 setprg8r(0x10,0x6000,0);
\r
122 SetReadHandler(0x6000,0x7FFF,CartBR);
\r
123 SetWriteHandler(0x6000,0x7FFF,CartBW);
\r
124 SetReadHandler(0x8000,0xFFFF,CartBR);
\r
125 SetWriteHandler(0x8000,0xFFFF,BandaiWrite);
\r
129 static void M153Close(void)
\r
136 static void StateRestore(int version)
\r
141 void Mapper16_Init(CartInfo *info)
\r
144 info->Power=BandaiPower;
\r
145 MapIRQHook=BandaiIRQHook;
\r
146 GameStateRestore=StateRestore;
\r
147 AddExState(&StateRegs, ~0, 0, 0);
\r
150 void Mapper159_Init(CartInfo *info)
\r
152 Mapper16_Init(info);
\r
156 void Mapper153_Init(CartInfo *info)
\r
159 info->Power=M153Power;
\r
160 info->Close=M153Close;
\r
161 MapIRQHook=BandaiIRQHook;
\r
164 WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);
\r
165 SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);
\r
166 AddExState(WRAM, WRAMSIZE, 0, "WRAM");
\r
170 info->SaveGame[0]=WRAM;
\r
171 info->SaveGameLen[0]=WRAMSIZE;
\r
174 GameStateRestore=StateRestore;
\r
175 AddExState(&StateRegs, ~0, 0, 0);
\r