updated bords/mappers/stuff to 0.98.15, lots of them got broken, asmcore support...
[fceu.git] / boards / 112.c
1 /* FCE Ultra - NES/Famicom Emulator
2  *
3  * Copyright notice for this file:
4  *  Copyright (C) 2005 CaH4e3
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "mapinc.h"
22
23 static uint8 reg[8];
24 static uint8 mirror, cmd;
25 static uint8 *WRAM=NULL;
26 static SFORMAT StateRegs[]=
27 {
28   {&cmd, 1, "CMD"},
29   {&mirror, 1, "MIRR"},
30   {reg, 8, "REGS"},
31   {0}
32 };
33
34 static void Sync(void)
35 {
36   setmirror(mirror^1);
37   setprg8(0x8000,reg[0]);
38   setprg8(0xA000,reg[1]);
39   setchr2(0x0000,reg[2]>>1);
40   setchr2(0x0800,reg[3]>>1);
41   setchr1(0x1000,reg[4]);
42   setchr1(0x1400,reg[5]);
43   setchr1(0x1800,reg[6]);
44   setchr1(0x1C00,reg[7]);
45 }
46
47 static DECLFW(M112Write)
48 {
49   switch(A)
50   {
51     case 0xe000: mirror=V&1; Sync(); ;break;
52     case 0x8000: cmd=V&7; break;
53     case 0xa000: reg[cmd]=V; Sync(); break;
54   }
55 }
56
57 static void M112Close(void)
58 {
59   if(WRAM)
60     FCEU_gfree(WRAM);
61   WRAM = NULL;
62 }
63
64 static void M112Power(void)
65 {
66   Sync();
67   setprg16(0xC000,~0);
68   setprg8r(0x10,0x6000,0);
69   SetReadHandler(0x8000,0xFFFF,CartBR);
70   SetWriteHandler(0x8000,0xFFFF,M112Write);
71   SetReadHandler(0x6000,0x7FFF,CartBR);
72   SetWriteHandler(0x6000,0x7FFF,CartBW);
73 }
74
75 static void StateRestore(int version)
76 {
77   Sync();
78 }
79
80 void Mapper112_Init(CartInfo *info)
81 {
82   info->Power=M112Power;
83   info->Close=M112Close;
84   GameStateRestore=StateRestore;
85   WRAM=(uint8*)FCEU_gmalloc(8192);
86   SetupCartPRGMapping(0x10,WRAM,8192,1);
87   AddExState(WRAM, 8192, 0, "WRAM");
88   AddExState(&StateRegs, ~0, 0, 0);
89 }