| 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 |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\r |
| 19 | */\r |
| 20 | \r |
| 21 | #include "mapinc.h"\r |
| 22 | \r |
| 23 | static uint16 latche, latcheinit;\r |
| 24 | static uint16 addrreg0, addrreg1;\r |
| 25 | static void(*WSync)(void);\r |
| 26 | static readfunc defread;\r |
| 27 | \r |
| 28 | static DECLFW(LatchWrite)\r |
| 29 | {\r |
| 30 | FCEU_printf("%04x:%02x\n",A,V);\r |
| 31 | latche=A;\r |
| 32 | WSync();\r |
| 33 | }\r |
| 34 | \r |
| 35 | static void LatchReset(void)\r |
| 36 | {\r |
| 37 | latche=latcheinit;\r |
| 38 | WSync();\r |
| 39 | }\r |
| 40 | \r |
| 41 | static void LatchPower(void)\r |
| 42 | {\r |
| 43 | latche=latcheinit;\r |
| 44 | WSync();\r |
| 45 | SetReadHandler(0x8000,0xFFFF,defread);\r |
| 46 | SetWriteHandler(addrreg0,addrreg1,LatchWrite);\r |
| 47 | }\r |
| 48 | \r |
| 49 | static void StateRestore(int version)\r |
| 50 | {\r |
| 51 | WSync();\r |
| 52 | }\r |
| 53 | \r |
| 54 | static void Latch_Init(CartInfo *info, void (*proc)(void), readfunc func, uint16 init, uint16 adr0, uint16 adr1)\r |
| 55 | {\r |
| 56 | latcheinit=init;\r |
| 57 | addrreg0=adr0;\r |
| 58 | addrreg1=adr1;\r |
| 59 | WSync=proc;\r |
| 60 | if(func)\r |
| 61 | defread=func;\r |
| 62 | else\r |
| 63 | defread=CartBR;\r |
| 64 | info->Power=LatchPower;\r |
| 65 | info->Reset=LatchReset;\r |
| 66 | GameStateRestore=StateRestore;\r |
| 67 | AddExState(&latche, 2, 0, "LATC");\r |
| 68 | }\r |
| 69 | \r |
| 70 | //------------------ UNLCC21 ---------------------------\r |
| 71 | \r |
| 72 | static void UNLCC21Sync(void)\r |
| 73 | {\r |
| 74 | setprg32(0x8000,0);\r |
| 75 | setchr8(latche&1);\r |
| 76 | setmirror(MI_0+((latche&2)>>1));\r |
| 77 | }\r |
| 78 | \r |
| 79 | void UNLCC21_Init(CartInfo *info)\r |
| 80 | { \r |
| 81 | Latch_Init(info, UNLCC21Sync, 0, 0, 0x8000, 0xFFFF);\r |
| 82 | }\r |
| 83 | \r |
| 84 | //------------------ BMCD1038 ---------------------------\r |
| 85 | \r |
| 86 | static uint8 dipswitch;\r |
| 87 | static void BMCD1038Sync(void)\r |
| 88 | {\r |
| 89 | if(latche&0x80)\r |
| 90 | {\r |
| 91 | setprg16(0x8000,(latche&0x70)>>4);\r |
| 92 | setprg16(0xC000,(latche&0x70)>>4);\r |
| 93 | }\r |
| 94 | else\r |
| 95 | setprg32(0x8000,(latche&0x60)>>5);\r |
| 96 | setchr8(latche&7);\r |
| 97 | setmirror(((latche&8)>>3)^1);\r |
| 98 | }\r |
| 99 | \r |
| 100 | static DECLFR(BMCD1038Read)\r |
| 101 | {\r |
| 102 | if(latche&0x100)\r |
| 103 | return dipswitch;\r |
| 104 | else\r |
| 105 | return CartBR(A);\r |
| 106 | }\r |
| 107 | \r |
| 108 | static void BMCD1038Reset(void)\r |
| 109 | {\r |
| 110 | dipswitch++;\r |
| 111 | dipswitch&=3; \r |
| 112 | }\r |
| 113 | \r |
| 114 | void BMCD1038_Init(CartInfo *info)\r |
| 115 | { \r |
| 116 | Latch_Init(info, BMCD1038Sync, BMCD1038Read, 0, 0x8000, 0xFFFF);\r |
| 117 | info->Reset=BMCD1038Reset;\r |
| 118 | AddExState(&dipswitch, 1, 0, "DIPSW");\r |
| 119 | }\r |
| 120 | \r |
| 121 | \r |
| 122 | //------------------ Map 058 ---------------------------\r |
| 123 | \r |
| 124 | static void BMCGK192Sync(void)\r |
| 125 | {\r |
| 126 | if(latche&0x40)\r |
| 127 | {\r |
| 128 | setprg16(0x8000,latche&7);\r |
| 129 | setprg16(0xC000,latche&7);\r |
| 130 | }\r |
| 131 | else\r |
| 132 | setprg32(0x8000,(latche>>1)&3);\r |
| 133 | setchr8((latche>>3)&7);\r |
| 134 | setmirror(((latche&0x80)>>7)^1);\r |
| 135 | }\r |
| 136 | \r |
| 137 | void BMCGK192_Init(CartInfo *info)\r |
| 138 | {\r |
| 139 | Latch_Init(info, BMCGK192Sync, 0, 0, 0x8000, 0xFFFF);\r |
| 140 | }\r |
| 141 | \r |
| 142 | //------------------ Map 200 ---------------------------\r |
| 143 | \r |
| 144 | static void M200Sync(void)\r |
| 145 | {\r |
| 146 | // FCEU_printf("A\n");\r |
| 147 | setprg16(0x8000,latche&7);\r |
| 148 | setprg16(0xC000,latche&7);\r |
| 149 | setchr8(latche&7);\r |
| 150 | setmirror((latche&8)>>3);\r |
| 151 | }\r |
| 152 | \r |
| 153 | void Mapper200_Init(CartInfo *info)\r |
| 154 | { \r |
| 155 | Latch_Init(info, M200Sync, 0, 0xff, 0x8000, 0xFFFF);\r |
| 156 | }\r |
| 157 | \r |
| 158 | //------------------ 190in1 ---------------------------\r |
| 159 | \r |
| 160 | static void BMC190in1Sync(void)\r |
| 161 | {\r |
| 162 | setprg16(0x8000,(latche>>2)&0x07);\r |
| 163 | setprg16(0xC000,(latche>>2)&0x07);\r |
| 164 | setchr8((latche>>2)&0x07);\r |
| 165 | setmirror((latche&1)^1);\r |
| 166 | }\r |
| 167 | \r |
| 168 | void BMC190in1_Init(CartInfo *info)\r |
| 169 | { \r |
| 170 | Latch_Init(info, BMC190in1Sync, 0, 0, 0x8000, 0xFFFF);\r |
| 171 | }\r |
| 172 | \r |