| 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 | \r |
| 21 | #include "mapinc.h"\r |
| 22 | \r |
| 23 | static uint8 mode;\r |
| 24 | static uint8 DRegs[4];\r |
| 25 | \r |
| 26 | static SFORMAT StateRegs[]=\r |
| 27 | {\r |
| 28 | {DRegs, 4, "DREG"},\r |
| 29 | {0}\r |
| 30 | };\r |
| 31 | \r |
| 32 | static void Sync(void)\r |
| 33 | {\r |
| 34 | int base, bank;\r |
| 35 | base = ((DRegs[0]^DRegs[1])&0x10)<<1;\r |
| 36 | bank = (DRegs[2]^DRegs[3])&0x1f;\r |
| 37 | \r |
| 38 | if(DRegs[1]&0x08)\r |
| 39 | {\r |
| 40 | bank &= 0xfe;\r |
| 41 | if(mode==0)\r |
| 42 | {\r |
| 43 | setprg16(0x8000,base+bank+1);\r |
| 44 | setprg16(0xC000,base+bank+0);\r |
| 45 | }\r |
| 46 | else\r |
| 47 | {\r |
| 48 | setprg16(0x8000,base+bank+0);\r |
| 49 | setprg16(0xC000,base+bank+1);\r |
| 50 | }\r |
| 51 | }\r |
| 52 | else\r |
| 53 | {\r |
| 54 | if(DRegs[1]&0x04)\r |
| 55 | {\r |
| 56 | setprg16(0x8000,0x1f);\r |
| 57 | setprg16(0xC000,base+bank);\r |
| 58 | }\r |
| 59 | else\r |
| 60 | {\r |
| 61 | setprg16(0x8000,base+bank);\r |
| 62 | if(mode==0)\r |
| 63 | setprg16(0xC000,0x20);\r |
| 64 | else\r |
| 65 | setprg16(0xC000,0x07);\r |
| 66 | }\r |
| 67 | }\r |
| 68 | }\r |
| 69 | \r |
| 70 | static DECLFW(Mapper167_write)\r |
| 71 | {\r |
| 72 | DRegs[(A>>13)&0x03]=V;\r |
| 73 | Sync();\r |
| 74 | }\r |
| 75 | \r |
| 76 | static void StateRestore(int version)\r |
| 77 | {\r |
| 78 | Sync();\r |
| 79 | }\r |
| 80 | \r |
| 81 | void Mapper166_init(void)\r |
| 82 | {\r |
| 83 | mode=1;\r |
| 84 | DRegs[0]=DRegs[1]=DRegs[2]=DRegs[3]=0;\r |
| 85 | Sync();\r |
| 86 | SetWriteHandler(0x8000,0xFFFF,Mapper167_write);\r |
| 87 | GameStateRestore=StateRestore;\r |
| 88 | AddExState(&StateRegs, ~0, 0, 0);\r |
| 89 | }\r |
| 90 | \r |
| 91 | void Mapper167_init(void)\r |
| 92 | {\r |
| 93 | mode=0;\r |
| 94 | DRegs[0]=DRegs[1]=DRegs[2]=DRegs[3]=0;\r |
| 95 | Sync();\r |
| 96 | SetWriteHandler(0x8000,0xFFFF,Mapper167_write);\r |
| 97 | GameStateRestore=StateRestore;\r |
| 98 | AddExState(&StateRegs, ~0, 0, 0);\r |
| 99 | }\r |