1 /* FCE Ultra - NES/Famicom Emulator
\r
3 * Copyright notice for this file:
\r
4 * Copyright (C) 2002 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
23 static uint8 prg_reg;
\r
24 static uint8 chr_reg;
\r
26 static uint8 sim0reg, sim0bit, sim0byte, sim0parity, sim0bcnt;
\r
27 static uint16 sim0data;
\r
28 static uint8 sim0array[128] =
\r
30 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
\r
31 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
\r
32 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
\r
33 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
\r
34 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
\r
35 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
\r
36 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
\r
37 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0xAA,
\r
40 static SFORMAT StateRegs[]=
\r
42 {&prg_reg, 1, "PREG"},
\r
43 {&chr_reg, 1, "CREG"},
\r
47 static void Sync(void)
\r
49 setprg32(0x8000, prg_reg);
\r
53 static void StateRestore(int version)
\r
58 static DECLFW(M216WriteHi)
\r
60 // FCEU_printf("%04x:%04x\n",A,V);
\r
62 chr_reg=(A&0x0E)>>1;
\r
66 static DECLFW(M216Write5000)
\r
68 // FCEU_printf("WRITE: %04x:%04x\n",A,V);
\r
72 sim0bit=sim0byte=sim0parity=0;
\r
73 sim0data=sim0array[0];
\r
76 else if(sim0reg&0x20)
\r
82 static DECLFR(M216Read5000)
\r
86 sim0reg=(sim0reg^(sim0reg<<1))&0x40;
\r
94 // sim0data=((sim0array[sim0byte]<<(sim0bit))&0x80)>>1;
\r
95 sim0out=(sim0data&1)<<6;
\r
98 sim0parity+=sim0data;
\r
100 else if(sim0bit==8)
\r
103 sim0out=sim0parity&1;
\r
105 else if(sim0bit==9)
\r
107 if(sim0byte==sim0bcnt)
\r
113 sim0data=sim0array[sim0byte];
\r
117 // FCEU_printf("READ: %04x (%04x-%02x,%04x)\n",A,X.PC,sim0out,sim0byte);
\r
122 static void Power(void)
\r
127 SetReadHandler(0x8000,0xFFFF,CartBR);
\r
128 SetWriteHandler(0x8000,0xFFFF,M216WriteHi);
\r
129 SetWriteHandler(0x5000,0x5000,M216Write5000);
\r
130 SetReadHandler(0x5000,0x5000,M216Read5000);
\r
134 void Mapper216_Init(CartInfo *info)
\r
137 GameStateRestore=StateRestore;
\r
138 AddExState(&StateRegs, ~0, 0, 0);
\r