merge mappers from FCEU-mm
[fceu.git] / boards / lh53.c
CommitLineData
386f5371 1/* FCE Ultra - NES/Famicom Emulator\r
2 *\r
3 * Copyright notice for this file:\r
4 * Copyright (C) 2007 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
43725da7 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
19 *\r
20 * FDS Conversion\r
21 *\r
386f5371 22 */\r
23\r
24#include "mapinc.h"\r
25\r
43725da7 26static uint8 reg, IRQa;\r
27static int32 IRQCount;\r
386f5371 28static uint8 *WRAM=NULL;\r
29static uint32 WRAMSIZE;\r
30\r
31static SFORMAT StateRegs[]=\r
32{\r
43725da7 33 {&reg, 1, "REG"},\r
34 {&IRQa, 1, "IRQA"},\r
35 {&IRQCount, 4, "IRQC"},\r
386f5371 36 {0}\r
37};\r
38\r
39static void Sync(void)\r
40{\r
41 setchr8(0);\r
43725da7 42 setprg8(0x6000,reg);\r
43 setprg8(0x8000,0xc);\r
44 setprg4(0xa000,(0xd<<1));\r
45 setprg2(0xb000,(0xd<<2)+2);\r
46 setprg2r(0x10,0xb800,4);\r
47 setprg2r(0x10,0xc000,5);\r
48 setprg2r(0x10,0xc800,6);\r
49 setprg2r(0x10,0xd000,7);\r
50 setprg2(0xd800,(0xe<<2)+3);\r
51 setprg8(0xe000,0xf);\r
386f5371 52}\r
53\r
43725da7 54static DECLFW(LH53RamWrite)\r
386f5371 55{\r
43725da7 56 WRAM[(A-0xB800)&0x1FFF]=V;\r
386f5371 57}\r
58\r
43725da7 59static DECLFW(LH53Write)\r
386f5371 60{\r
43725da7 61 reg=V;\r
386f5371 62 Sync();\r
63}\r
64\r
43725da7 65static DECLFW(LH53IRQaWrite)\r
386f5371 66{\r
43725da7 67 IRQa = V&2;\r
68 IRQCount = 0;\r
69 if(!IRQa)\r
70 X6502_IRQEnd(FCEU_IQEXT);\r
386f5371 71}\r
72\r
43725da7 73static void FP_FASTAPASS(1) LH53IRQ(int a)\r
74{\r
75 if(IRQa)\r
76 {\r
77 IRQCount+=a;\r
78 if(IRQCount>7560)\r
79 X6502_IRQBegin(FCEU_IQEXT);\r
80 }\r
81}\r
82\r
83static void LH53Power(void)\r
84{\r
85 Sync();\r
86 SetReadHandler(0x6000,0xFFFF,CartBR);\r
87 SetWriteHandler(0xB800,0xD7FF,LH53RamWrite);\r
88 SetWriteHandler(0xE000,0xEFFF,LH53IRQaWrite);\r
89 SetWriteHandler(0xF000,0xFFFF,LH53Write);\r
90}\r
91\r
92static void LH53Close(void)\r
386f5371 93{\r
94 if(WRAM)\r
95 FCEU_gfree(WRAM);\r
96 WRAM=NULL;\r
97}\r
98\r
99static void StateRestore(int version)\r
100{\r
101 Sync();\r
102}\r
103\r
43725da7 104void LH53_Init(CartInfo *info)\r
386f5371 105{\r
43725da7 106 info->Power=LH53Power;\r
107 info->Close=LH53Close;\r
108 MapIRQHook=LH53IRQ;\r
386f5371 109 GameStateRestore=StateRestore;\r
110\r
111 WRAMSIZE=8192;\r
112 WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
113 SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
114 AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
386f5371 115\r
116 AddExState(&StateRegs, ~0, 0, 0);\r
117}\r