| 1 | /* FCE Ultra - NES/Famicom Emulator\r |
| 2 | *\r |
| 3 | * Copyright notice for this file:\r |
| 4 | * Copyright (C) 2005 CaH4e3\r |
| 5 | * Copyright (C) 2009 qeed\r |
| 6 | *\r |
| 7 | * This program is free software; you can redistribute it and/or modify\r |
| 8 | * it under the terms of the GNU General Public License as published by\r |
| 9 | * the Free Software Foundation; either version 2 of the License, or\r |
| 10 | * (at your option) any later version.\r |
| 11 | *\r |
| 12 | * This program is distributed in the hope that it will be useful,\r |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of\r |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r |
| 15 | * GNU General Public License for more details.\r |
| 16 | *\r |
| 17 | * You should have received a copy of the GNU General Public License\r |
| 18 | * along with this program; if not, write to the Free Software\r |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r |
| 20 | *\r |
| 21 | * BMC 42-in-1 "reset switch" + "select switch"\r |
| 22 | *\r |
| 23 | */\r |
| 24 | \r |
| 25 | #include "mapinc.h"\r |
| 26 | \r |
| 27 | static uint8 isresetbased = 0;\r |
| 28 | static uint8 latche[2], reset;\r |
| 29 | static SFORMAT StateRegs[]=\r |
| 30 | {\r |
| 31 | {&reset, 1, "RST"},\r |
| 32 | {latche, 2, "LATC"},\r |
| 33 | {0}\r |
| 34 | };\r |
| 35 | \r |
| 36 | static void Sync(void)\r |
| 37 | {\r |
| 38 | uint8 bank;\r |
| 39 | if(isresetbased)\r |
| 40 | bank = (latche[0]&0x1f)|(reset<<5)|((latche[1]&1)<<6);\r |
| 41 | else\r |
| 42 | bank = (latche[0]&0x1f)|((latche[0]&0x80)>>2)|((latche[1]&1)<<6);\r |
| 43 | if(!(latche[0] & 0x20))\r |
| 44 | setprg32(0x8000,bank >> 1);\r |
| 45 | else\r |
| 46 | {\r |
| 47 | setprg16(0x8000,bank);\r |
| 48 | setprg16(0xC000,bank);\r |
| 49 | }\r |
| 50 | setmirror((latche[0]>>6)&1);\r |
| 51 | setchr8(0);\r |
| 52 | }\r |
| 53 | \r |
| 54 | static DECLFW(M226Write)\r |
| 55 | {\r |
| 56 | latche[A & 1] = V;\r |
| 57 | Sync();\r |
| 58 | }\r |
| 59 | \r |
| 60 | static void M226Power(void)\r |
| 61 | {\r |
| 62 | latche[0] = latche[1] = reset = 0;\r |
| 63 | Sync();\r |
| 64 | SetWriteHandler(0x8000,0xFFFF,M226Write);\r |
| 65 | SetReadHandler(0x8000,0xFFFF,CartBR);\r |
| 66 | }\r |
| 67 | \r |
| 68 | static void StateRestore(int version)\r |
| 69 | {\r |
| 70 | Sync();\r |
| 71 | }\r |
| 72 | \r |
| 73 | void Mapper226_Init(CartInfo *info)\r |
| 74 | {\r |
| 75 | isresetbased = 0;\r |
| 76 | info->Power=M226Power;\r |
| 77 | AddExState(&StateRegs, ~0, 0, 0);\r |
| 78 | GameStateRestore=StateRestore;\r |
| 79 | }\r |
| 80 | \r |
| 81 | static void BMC42in1Reset(void)\r |
| 82 | {\r |
| 83 | reset ^= 1;\r |
| 84 | Sync();\r |
| 85 | }\r |
| 86 | \r |
| 87 | void BMC42in1r_Init(CartInfo *info)\r |
| 88 | {\r |
| 89 | isresetbased = 1;\r |
| 90 | info->Power=M226Power;\r |
| 91 | info->Reset=BMC42in1Reset;\r |
| 92 | AddExState(&StateRegs, ~0, 0, 0);\r |
| 93 | GameStateRestore=StateRestore;\r |
| 94 | }\r |