updated bords/mappers/stuff to 0.98.15, lots of them got broken, asmcore support...
[fceu.git] / boards / bonza.c
1 /* FCE Ultra - NES/Famicom Emulator\r
2  *\r
3  * Copyright notice for this file:\r
4  *  Copyright (C) 2002 CaH4e3\r
5  *\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
10  *\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
15  *\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
19  */\r
20 \r
21 #include "mapinc.h"\r
22 \r
23 static uint8 prg_reg;\r
24 static uint8 chr_reg;\r
25 \r
26 static uint8 sim0reg, sim0bit, sim0byte, sim0parity, sim0bcnt;\r
27 static uint16 sim0data;\r
28 static uint8 sim0array[128] =\r
29 {\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
38 };\r
39 \r
40 static SFORMAT StateRegs[]=\r
41 {\r
42   {&prg_reg, 1, "PREG"},\r
43   {&chr_reg, 1, "CREG"},\r
44   {0}\r
45 };\r
46 \r
47 static void Sync(void)\r
48 {\r
49   setprg32(0x8000, prg_reg);\r
50   setchr8(chr_reg);\r
51 }\r
52 \r
53 static void StateRestore(int version)\r
54 {\r
55   Sync();\r
56 }\r
57 \r
58 static DECLFW(M216WriteHi)\r
59 {\r
60 // FCEU_printf("%04x:%04x\n",A,V);\r
61   prg_reg=A&1;\r
62   chr_reg=(A&0x0E)>>1;\r
63   Sync();\r
64 }\r
65 \r
66 static DECLFW(M216Write5000)\r
67 {\r
68 // FCEU_printf("WRITE: %04x:%04x\n",A,V);\r
69   sim0reg=V;\r
70   if(!sim0reg)\r
71   {\r
72     sim0bit=sim0byte=sim0parity=0;\r
73     sim0data=sim0array[0];\r
74     sim0bcnt=0x80;\r
75   }\r
76   else if(sim0reg&0x20)\r
77   {\r
78     sim0bcnt=0x20;\r
79   }\r
80 }\r
81 \r
82 static DECLFR(M216Read5000)\r
83 {\r
84   if(sim0reg&0x60)\r
85   {\r
86     sim0reg=(sim0reg^(sim0reg<<1))&0x40;\r
87     return sim0reg;\r
88   }\r
89   else\r
90   {\r
91     uint8 sim0out=0;\r
92     if(sim0bit<8)\r
93     {\r
94 //       sim0data=((sim0array[sim0byte]<<(sim0bit))&0x80)>>1;\r
95       sim0out=(sim0data&1)<<6;\r
96       sim0data>>=1;\r
97       sim0bit++;\r
98       sim0parity+=sim0data;\r
99     }\r
100     else if(sim0bit==8)\r
101     {\r
102       sim0bit++;\r
103       sim0out=sim0parity&1;\r
104     }\r
105     else if(sim0bit==9)\r
106     {\r
107       if(sim0byte==sim0bcnt)\r
108         sim0out=0x60;\r
109       else\r
110       {\r
111         sim0bit=0;\r
112         sim0byte++;\r
113         sim0data=sim0array[sim0byte];\r
114         sim0out=0;\r
115       }\r
116     }\r
117 //    FCEU_printf("READ: %04x (%04x-%02x,%04x)\n",A,X.PC,sim0out,sim0byte);\r
118     return sim0out;\r
119   }\r
120 }\r
121 \r
122 static void Power(void)\r
123 {\r
124   prg_reg = 0;\r
125   chr_reg = 0;\r
126   Sync();\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
131 }\r
132 \r
133 \r
134 void Mapper216_Init(CartInfo *info)\r
135 {\r
136   info->Power=Power;\r
137   GameStateRestore=StateRestore;\r
138   AddExState(&StateRegs, ~0, 0, 0);\r
139 }\r