386f5371 |
1 | /* FCE Ultra - NES/Famicom Emulator\r |
2 | *\r |
3 | * Copyright notice for this file:\r |
4 | * Copyright (C) 2006 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 |
386f5371 |
19 | */\r |
20 | \r |
21 | #include "mapinc.h"\r |
22 | \r |
23 | static uint16 addrreg;\r |
24 | static uint8 datareg;\r |
25 | static uint8 busy;\r |
26 | static SFORMAT StateRegs[]=\r |
27 | {\r |
43725da7 |
28 | {&addrreg, 2, "AREG"},\r |
29 | {&datareg, 1, "DREG"},\r |
386f5371 |
30 | {&busy, 1, "BUSY"},\r |
31 | {0}\r |
32 | };\r |
33 | \r |
34 | static void Sync(void)\r |
35 | {\r |
36 | uint16 base=((addrreg&0x60)>>2)|((addrreg&0x100)>>3); \r |
37 | setprg16(0x8000,(datareg&7)|base);\r |
38 | setprg16(0xC000,7|base);\r |
39 | setmirror(((addrreg&2)>>1)^1);\r |
40 | }\r |
41 | \r |
42 | static DECLFW(BMCT262Write)\r |
43 | {\r |
44 | if(busy||(A==0x8000))\r |
45 | datareg=V;\r |
46 | else\r |
47 | {\r |
48 | addrreg=A;\r |
49 | busy=1;\r |
50 | }\r |
51 | Sync();\r |
52 | }\r |
53 | \r |
54 | static void BMCT262Power(void)\r |
55 | {\r |
56 | setchr8(0);\r |
57 | SetWriteHandler(0x8000,0xFFFF,BMCT262Write);\r |
58 | SetReadHandler(0x8000,0xFFFF,CartBR);\r |
59 | busy=0;\r |
60 | addrreg=0;\r |
61 | datareg=0xff;\r |
62 | Sync();\r |
63 | }\r |
64 | \r |
65 | static void BMCT262Reset(void)\r |
66 | {\r |
67 | busy=0;\r |
68 | addrreg=0;\r |
69 | datareg=0;\r |
70 | Sync();\r |
71 | }\r |
72 | \r |
73 | static void BMCT262Restore(int version)\r |
74 | {\r |
75 | Sync();\r |
76 | }\r |
77 | \r |
78 | void BMCT262_Init(CartInfo *info)\r |
79 | {\r |
80 | info->Power=BMCT262Power;\r |
81 | info->Reset=BMCT262Reset;\r |
82 | GameStateRestore=BMCT262Restore;\r |
83 | AddExState(&StateRegs, ~0, 0, 0);\r |
84 | }\r |