| 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 | * 7-in-1 Darkwing Duck, Snake, MagicBlock (PCB marked as "12 in 1")\r |
| 21 | */\r |
| 22 | \r |
| 23 | #include "mapinc.h"\r |
| 24 | \r |
| 25 | static uint8 reg[4];\r |
| 26 | static SFORMAT StateRegs[]=\r |
| 27 | {\r |
| 28 | {reg, 4, "REGS"},\r |
| 29 | {0}\r |
| 30 | };\r |
| 31 | \r |
| 32 | static void Sync(void)\r |
| 33 | {\r |
| 34 | uint8 bank = (reg[3]&3)<<3;\r |
| 35 | setchr4(0x0000, (reg[1]>>3)|(bank<<2));\r |
| 36 | setchr4(0x1000, (reg[2]>>3)|(bank<<2));\r |
| 37 | if(reg[3]&8)\r |
| 38 | {\r |
| 39 | setprg32(0x8000,((reg[2]&7)>>1)|bank);\r |
| 40 | }\r |
| 41 | else\r |
| 42 | {\r |
| 43 | setprg16(0x8000, (reg[1]&7)|bank);\r |
| 44 | setprg16(0xc000, 7|bank);\r |
| 45 | }\r |
| 46 | setmirror(((reg[3]&4)>>2)^1);\r |
| 47 | }\r |
| 48 | \r |
| 49 | static DECLFW(BMC12IN1Write)\r |
| 50 | {\r |
| 51 | switch(A)\r |
| 52 | {\r |
| 53 | case 0xafff: reg[0] = V; break;\r |
| 54 | case 0xbfff: reg[1] = V; break;\r |
| 55 | case 0xdfff: reg[2] = V; break;\r |
| 56 | case 0xefff: reg[3] = V; break;\r |
| 57 | }\r |
| 58 | Sync();\r |
| 59 | }\r |
| 60 | \r |
| 61 | static void BMC12IN1Power(void)\r |
| 62 | {\r |
| 63 | reg[0]=reg[1]=reg[2]=reg[3]=0;\r |
| 64 | Sync();\r |
| 65 | SetReadHandler(0x8000,0xFFFF,CartBR);\r |
| 66 | SetWriteHandler(0x8000,0xFFFF,BMC12IN1Write);\r |
| 67 | }\r |
| 68 | \r |
| 69 | static void StateRestore(int version)\r |
| 70 | {\r |
| 71 | Sync();\r |
| 72 | }\r |
| 73 | \r |
| 74 | void BMC12IN1_Init(CartInfo *info)\r |
| 75 | {\r |
| 76 | info->Power=BMC12IN1Power;\r |
| 77 | GameStateRestore=StateRestore;\r |
| 78 | AddExState(&StateRegs, ~0, 0, 0);\r |
| 79 | }\r |