release r2, update credits
[fceu.git] / boards / famicombox.c
1 /* FCE Ultra - NES/Famicom Emulator\r
2  *\r
3  * Copyright notice for this file:\r
4  *  Copyright (C) 2009 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 regs[8];\r
24 static uint8 *WRAM = NULL;\r
25 static uint32 WRAMSIZE;\r
26 \r
27 static SFORMAT StateRegs[]=\r
28 {\r
29   {regs, 8, "REGS"},\r
30   {0}\r
31 };\r
32 \r
33 static void Sync(void)\r
34 {\r
35   setprg2r(0x10,0x0800,0);\r
36   setprg2r(0x10,0x1000,1);\r
37   setprg2r(0x10,0x1800,2);\r
38   setprg8r(0x10,0x6000,1);\r
39   setprg16(0x8000,0);\r
40   setprg16(0xC000,~0);\r
41   setchr8(0);\r
42 }\r
43 \r
44 //static DECLFW(SSSNROMWrite)\r
45 //{\r
46 //  CartBW(A,V);\r
47 //}\r
48 \r
49 static DECLFW(SSSNROMWrite)\r
50 {\r
51   //FCEU_printf("write %04x %02x\n",A,V);\r
52   //regs[A&7] = V;\r
53 }\r
54 \r
55 static DECLFR(SSSNROMRead)\r
56 {\r
57   //FCEU_printf("read %04x\n",A);\r
58   switch(A&7) {\r
59   case 0: return regs[0]=0xff;   // clear all exceptions\r
60   case 2: return 0xc0; // DIP selftest + freeplay\r
61   case 3: return 0x00; // 0, 1 - attract\r
62                        // 2\r
63                        // 4    - menu\r
64                        // 8    - self check and game casette check\r
65                        // 10   - lock?\r
66                        // 20   - game title & count display\r
67   case 7: return 0x22; // TV type, key not turned, relay B\r
68   default: return 0;\r
69   }\r
70 }\r
71 \r
72 static void SSSNROMPower(void)\r
73 {\r
74   regs[0]=regs[1]=regs[2]=regs[3]=regs[4]=regs[5]=regs[6]=0;\r
75   regs[7]=0xff;\r
76   Sync();\r
77   memset(WRAM,0x00,WRAMSIZE);\r
78 //  SetWriteHandler(0x0000,0x1FFF,SSSNROMRamWrite);\r
79   SetReadHandler(0x0800,0x1FFF,CartBR);\r
80   SetWriteHandler(0x0800,0x1FFF,CartBW);\r
81   SetReadHandler(0x5000,0x5FFF,SSSNROMRead);\r
82   SetWriteHandler(0x5000,0x5FFF,SSSNROMWrite);\r
83   SetReadHandler(0x6000,0x7FFF,CartBR);\r
84   SetWriteHandler(0x6000,0x7FFF,CartBW);\r
85   SetReadHandler(0x8000,0xFFFF,CartBR);\r
86 }\r
87 \r
88 static void SSSNROMReset(void)\r
89 {\r
90   regs[1]=regs[2]=regs[3]=regs[4]=regs[5]=regs[6]=0;\r
91 }\r
92 \r
93 static void SSSNROMClose(void)\r
94 {\r
95   if(WRAM)\r
96     FCEU_gfree(WRAM);\r
97   WRAM=NULL;\r
98 }\r
99 \r
100 static void SSSNROMIRQHook(void)\r
101 {\r
102 //  X6502_IRQBegin(FCEU_IQEXT);\r
103 }\r
104 \r
105 static void StateRestore(int version)\r
106 {\r
107   Sync();\r
108 }\r
109 \r
110 void SSSNROM_Init(CartInfo *info)\r
111 {\r
112   info->Reset=SSSNROMReset;\r
113   info->Power=SSSNROMPower;\r
114   info->Close=SSSNROMClose;\r
115   GameHBIRQHook=SSSNROMIRQHook;\r
116   GameStateRestore=StateRestore;\r
117 \r
118   WRAMSIZE=16384;\r
119   WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
120   SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
121 \r
122   AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
123   AddExState(&StateRegs, ~0, 0, 0);\r
124 }\r