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 | * Gimmick Bootleg\r |
21 | */\r |
22 | \r |
23 | #include "mapinc.h"\r |
24 | \r |
25 | static uint8 prg[4];\r |
26 | static uint8 chr[8];\r |
27 | static uint8 IRQCount;\r |
28 | static uint8 IRQPre;\r |
29 | static uint8 IRQa;\r |
30 | \r |
31 | static SFORMAT StateRegs[]=\r |
32 | {\r |
33 | {prg, 4, "PRG"},\r |
34 | {chr, 8, "CHR"},\r |
35 | {&IRQCount, 1, "IRQCOUNT"},\r |
36 | {&IRQPre, 1, "IRQPRE"},\r |
37 | {&IRQa, 1, "IRQA"},\r |
38 | {0}\r |
39 | };\r |
40 | \r |
41 | static void SyncPrg(void)\r |
42 | {\r |
43 | setprg8(0x6000,0);\r |
44 | setprg8(0x8000,prg[0]);\r |
45 | setprg8(0xA000,prg[1]);\r |
46 | setprg8(0xC000,prg[2]);\r |
47 | setprg8(0xE000,~0);\r |
48 | }\r |
49 | \r |
50 | static void SyncChr(void)\r |
51 | {\r |
52 | int i;\r |
53 | for(i=0; i<8; i++)\r |
54 | setchr1(i<<10,chr[i]);\r |
55 | }\r |
56 | \r |
57 | static void StateRestore(int version)\r |
58 | {\r |
59 | SyncPrg();\r |
60 | SyncChr();\r |
61 | }\r |
62 | \r |
63 | static DECLFW(M183Write)\r |
64 | {\r |
65 | if(((A&0xF80C)>=0xB000)&&((A&0xF80C)<=0xE00C))\r |
66 | {\r |
67 | uint8 index=(((A&0x7000)>>11)-6)|((A&8)>>3);\r |
68 | chr[index]=(chr[index]&(0xF0>>(A&4)))|((V&0x0F)<<(A&4));\r |
69 | SyncChr();\r |
70 | }\r |
71 | else switch (A&0xF80C)\r |
72 | {\r |
73 | case 0x8800: prg[0]=V; SyncPrg(); break;\r |
74 | case 0xA800: prg[1]=V; SyncPrg(); break;\r |
75 | case 0xA000: prg[2]=V; SyncPrg(); break;\r |
76 | case 0x9800: switch (V&3)\r |
77 | {\r |
78 | case 0: setmirror(MI_V); break;\r |
79 | case 1: setmirror(MI_H); break;\r |
80 | case 2: setmirror(MI_0); break;\r |
81 | case 3: setmirror(MI_1); break;\r |
82 | }\r |
83 | break;\r |
84 | case 0xF000: IRQCount=((IRQCount&0xF0)|(V&0xF)); break;\r |
85 | case 0xF004: IRQCount=((IRQCount&0x0F)|((V&0xF)<<4)); break;\r |
86 | case 0xF008: IRQa=V; if(!V)IRQPre=0; X6502_IRQEnd(FCEU_IQEXT); break;\r |
87 | case 0xF00C: IRQPre=16; break;\r |
88 | }\r |
89 | }\r |
90 | \r |
91 | static void M183IRQCounter(void)\r |
92 | {\r |
93 | if(IRQa)\r |
94 | {\r |
95 | IRQCount++;\r |
96 | if((IRQCount-IRQPre)==238)\r |
97 | X6502_IRQBegin(FCEU_IQEXT);\r |
98 | }\r |
99 | }\r |
100 | \r |
101 | static void M183Power(void)\r |
102 | {\r |
103 | IRQPre=IRQCount=IRQa=0;\r |
104 | SetReadHandler(0x8000,0xFFFF,CartBR);\r |
105 | SetWriteHandler(0x8000,0xFFFF,M183Write);\r |
106 | SetReadHandler(0x6000,0x7FFF,CartBR);\r |
107 | SyncPrg();\r |
108 | SyncChr();\r |
109 | }\r |
110 | \r |
111 | void Mapper183_Init(CartInfo *info)\r |
112 | {\r |
113 | info->Power=M183Power;\r |
114 | GameHBIRQHook=M183IRQCounter;\r |
115 | GameStateRestore=StateRestore;\r |
116 | AddExState(&StateRegs, ~0, 0, 0);\r |
117 | }\r |