d97315ac |
1 | /* FCE Ultra - NES/Famicom Emulator\r |
2 | *\r |
3 | * Copyright notice for this file:\r |
4 | * Copyright (C) 2005 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 | #include "mmc3.h"\r |
23 | \r |
24 | static uint8 *CHRRAM = NULL;\r |
25 | static uint8 resetmode;\r |
26 | static int masko8[8]={63,31,15,1,3,0,0,0};\r |
27 | \r |
28 | static void Super24PW(uint32 A, uint8 V)\r |
29 | {\r |
30 | uint32 NV=V&masko8[EXPREGS[0]&7];\r |
31 | NV|=(EXPREGS[1]<<1);\r |
32 | setprg8r((NV>>6)&0xF,A,NV);\r |
33 | }\r |
34 | \r |
35 | static void Super24CW(uint32 A, uint8 V)\r |
36 | {\r |
37 | if(EXPREGS[0]&0x20)\r |
38 | setchr1r(0x10,A,V);\r |
39 | else\r |
40 | {\r |
41 | uint32 NV=V|(EXPREGS[2]<<3);\r |
42 | setchr1r((NV>>9)&0xF,A,NV);\r |
43 | }\r |
44 | }\r |
45 | \r |
46 | static DECLFW(Super24Write)\r |
47 | {\r |
48 | switch(A)\r |
49 | {\r |
50 | case 0x5FF0: EXPREGS[0]=V;\r |
51 | FixMMC3PRG(MMC3_cmd);\r |
52 | FixMMC3CHR(MMC3_cmd);\r |
53 | break;\r |
54 | case 0x5FF1: EXPREGS[1]=V;\r |
55 | FixMMC3PRG(MMC3_cmd);\r |
56 | break;\r |
57 | case 0x5FF2: EXPREGS[2]=V;\r |
58 | FixMMC3CHR(MMC3_cmd);\r |
59 | break;\r |
60 | }\r |
61 | }\r |
62 | \r |
63 | static DECLFW(Super24IRQ)\r |
64 | {\r |
65 | switch(A&0xE001)\r |
66 | {\r |
67 | case 0xc000: IRQLatch=V;\r |
68 | if(resetmode==1)\r |
69 | IRQCount=IRQLatch;\r |
70 | break;\r |
71 | case 0xc001: resetmode=1;\r |
72 | IRQCount=IRQLatch;\r |
73 | break;\r |
74 | case 0xE000: IRQa=0;\r |
75 | X6502_IRQEnd(FCEU_IQEXT);\r |
76 | if(resetmode==1)\r |
77 | IRQCount=IRQLatch;\r |
78 | break;\r |
79 | case 0xE001: IRQa=1;\r |
80 | if(resetmode==1)\r |
81 | IRQCount=IRQLatch;\r |
82 | break;\r |
83 | }\r |
84 | }\r |
85 | \r |
86 | static void Super24HB(void)\r |
87 | {\r |
88 | resetmode=0;\r |
89 | if(IRQCount!=0)\r |
90 | {\r |
91 | IRQCount--;\r |
92 | if(IRQCount==0)\r |
93 | {\r |
94 | if(IRQa)\r |
95 | {\r |
96 | resetmode=1;\r |
97 | X6502_IRQBegin(FCEU_IQEXT);\r |
98 | }\r |
99 | }\r |
100 | }\r |
101 | }\r |
102 | \r |
103 | static void Super24Power(void)\r |
104 | {\r |
105 | EXPREGS[0]=0x24;\r |
106 | EXPREGS[1]=159;\r |
107 | EXPREGS[2]=0;\r |
108 | GenMMC3Power();\r |
109 | SetWriteHandler(0x5000,0x7FFF,Super24Write);\r |
110 | SetWriteHandler(0xC000,0xFFFF,Super24IRQ);\r |
111 | SetReadHandler(0x8000,0xFFFF,CartBR);\r |
112 | }\r |
113 | \r |
114 | static void Super24Reset(void)\r |
115 | {\r |
116 | EXPREGS[0]=0x24;\r |
117 | EXPREGS[1]=159;\r |
118 | EXPREGS[2]=0;\r |
119 | MMC3RegReset();\r |
120 | }\r |
121 | \r |
122 | static void Super24Close(void)\r |
123 | {\r |
124 | if(CHRRAM)\r |
125 | FCEU_gfree(CHRRAM);\r |
126 | CHRRAM = NULL;\r |
127 | }\r |
128 | \r |
129 | void Super24_Init(CartInfo *info)\r |
130 | {\r |
131 | info->Power=Super24Power;\r |
132 | info->Reset=Super24Reset;\r |
133 | info->Close=Super24Close;\r |
134 | cwrap=Super24CW;\r |
135 | pwrap=Super24PW;\r |
136 | CHRRAM=(uint8*)FCEU_gmalloc(8192);\r |
137 | SetupCartCHRMapping(0x10, CHRRAM, 8192, 1);\r |
138 | GameHBIRQHook=Super24HB;\r |
139 | AddExState(CHRRAM, 8192, 0, "CHRR");\r |
140 | AddExState(EXPREGS, 3, 0, "BIG2");\r |
141 | }\r |