merge mappers from FCEU-mm
[fceu.git] / boards / KS7037.c
1 /* FCE Ultra - NES/Famicom Emulator\r
2  *\r
3  * Copyright notice for this file:\r
4  *  Copyright (C) 2011 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  * FDS Conversion\r
21  *\r
22  */\r
23 \r
24 #include "mapinc.h"\r
25 \r
26 static uint8 reg[8], cmd;\r
27 static uint8 *WRAM=NULL;\r
28 static uint32 WRAMSIZE;\r
29 \r
30 static void(*WSync)(void);\r
31 \r
32 static SFORMAT StateRegs[]=\r
33 {\r
34   {&cmd, 1, "CMD"},\r
35   {reg, 8, "REGS"},\r
36   {0}\r
37 };\r
38 \r
39 static void SyncKS7037(void)\r
40 {\r
41   setprg4r(0x10,0x6000,0);\r
42   setprg4(0x7000,15);\r
43   setprg8(0x8000,reg[6]);\r
44   setprg4(0xA000,~3);\r
45   setprg4r(0x10,0xB000,1);\r
46   setprg8(0xC000,reg[7]);\r
47   setprg8(0xE000,~0);\r
48   setchr8(0);\r
49   setmirrorw(reg[2]&1,reg[4]&1,reg[3]&1,reg[5]&1);\r
50 }\r
51 \r
52 static void SyncLH10(void)\r
53 {\r
54   setprg8(0x6000,~1);\r
55   setprg8(0x8000,reg[6]);\r
56   setprg8(0xA000,reg[7]);\r
57   setprg8r(0x10,0xC000,0);\r
58   setprg8(0xE000,~0);\r
59   setchr8(0);\r
60   setmirror(0);\r
61 }\r
62 \r
63 static DECLFW(UNLKS7037Write)\r
64 {\r
65   switch(A & 0xE001)\r
66   {\r
67     case 0x8000: cmd = V & 7; break;\r
68     case 0x8001: reg[cmd] = V; WSync(); break;\r
69   }\r
70 }\r
71 \r
72 static void UNLKS7037Power(void)\r
73 {\r
74   reg[0]=reg[1]=reg[2]=reg[3]=reg[4]=reg[5]=reg[6]=reg[7]=0;\r
75   WSync();\r
76   SetReadHandler(0x6000,0xFFFF,CartBR);\r
77   SetWriteHandler(0x6000,0x7FFF,CartBW);\r
78   SetWriteHandler(0x8000,0x9FFF,UNLKS7037Write);\r
79   SetWriteHandler(0xA000,0xBFFF,CartBW);\r
80   SetWriteHandler(0xC000,0xFFFF,UNLKS7037Write);\r
81 }\r
82 \r
83 static void LH10Power(void)\r
84 {\r
85   reg[0]=reg[1]=reg[2]=reg[3]=reg[4]=reg[5]=reg[6]=reg[7]=0;\r
86   WSync();\r
87   SetReadHandler(0x6000,0xFFFF,CartBR);\r
88   SetWriteHandler(0x8000,0xBFFF,UNLKS7037Write);\r
89   SetWriteHandler(0xC000,0xDFFF,CartBW);\r
90   SetWriteHandler(0xE000,0xFFFF,UNLKS7037Write);\r
91 }\r
92 \r
93 static void Close(void)\r
94 {\r
95   if(WRAM)\r
96     FCEU_gfree(WRAM);\r
97   WRAM=NULL;\r
98 }\r
99 \r
100 static void StateRestore(int version)\r
101 {\r
102   WSync();\r
103 }\r
104 \r
105 void UNLKS7037_Init(CartInfo *info)\r
106 {\r
107   info->Power=UNLKS7037Power;\r
108   info->Close=Close;\r
109   \r
110   WSync = SyncKS7037;\r
111 \r
112   WRAMSIZE=8192;\r
113   WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
114   SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
115   AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
116 \r
117   GameStateRestore=StateRestore;\r
118   AddExState(&StateRegs, ~0, 0, 0);\r
119 }\r
120 \r
121 void LH10_Init(CartInfo *info)\r
122 {\r
123   info->Power=LH10Power;\r
124   info->Close=Close;\r
125   \r
126   WSync = SyncLH10;\r
127 \r
128   WRAMSIZE=8192;\r
129   WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
130   SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
131   AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
132 \r
133   GameStateRestore=StateRestore;\r
134   AddExState(&StateRegs, ~0, 0, 0);\r
135 }\r