| 1 | /* FCE Ultra - NES/Famicom Emulator |
| 2 | * |
| 3 | * Copyright notice for this file: |
| 4 | * Copyright (C) 1998 BERO |
| 5 | * Copyright (C) 2002 Xodnizel |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | */ |
| 21 | |
| 22 | #include "mapinc.h" |
| 23 | |
| 24 | static uint8 latche; |
| 25 | |
| 26 | //static DECLFW(Mapper2_write) |
| 27 | //{ |
| 28 | // latche=V; |
| 29 | // ROM_BANK16(0x8000,V); |
| 30 | //} |
| 31 | // |
| 32 | //void Mapper2_init(void) |
| 33 | //{ |
| 34 | // SetWriteHandler(0x8000,0xFFFF,Mapper2_write); |
| 35 | // AddExState(&latche, 1, 0, "LATC"); |
| 36 | //} |
| 37 | |
| 38 | //static DECLFW(Mapper3_write) |
| 39 | //{ |
| 40 | // VROM_BANK8(V); |
| 41 | // latche=V; |
| 42 | //} |
| 43 | |
| 44 | //void Mapper3_init(void) |
| 45 | //{ |
| 46 | // SetWriteHandler(0x8000,0xFFFF,Mapper3_write); |
| 47 | // AddExState(&latche, 1, 0, "LATC"); |
| 48 | //} |
| 49 | |
| 50 | static DECLFW(Mapper7_write) |
| 51 | { |
| 52 | // FCEU_printf("%04x,%04x\n",A,V); |
| 53 | ROM_BANK32(V&0xF); |
| 54 | onemir((V>>4)&1); |
| 55 | latche=V; |
| 56 | } |
| 57 | |
| 58 | void Mapper7_init(void) |
| 59 | { |
| 60 | onemir(0); |
| 61 | ROM_BANK32(0); |
| 62 | SetWriteHandler(0x8000,0xFFFF,Mapper7_write); |
| 63 | AddExState(&latche, 1, 0, "LATC"); |
| 64 | } |
| 65 | |
| 66 | static DECLFW(Mapper11_write) |
| 67 | { |
| 68 | ROM_BANK32(V&0xF); |
| 69 | VROM_BANK8(V>>4); |
| 70 | latche=V; |
| 71 | } |
| 72 | |
| 73 | void Mapper11_init(void) |
| 74 | { |
| 75 | ROM_BANK32(0); |
| 76 | SetWriteHandler(0x8000,0xFFFF,Mapper11_write); |
| 77 | AddExState(&latche, 1, 0, "LATC"); |
| 78 | } |
| 79 | void Mapper144_init(void) |
| 80 | { |
| 81 | ROM_BANK32(0); |
| 82 | SetWriteHandler(0x8001,0xFFFF,Mapper11_write); |
| 83 | AddExState(&latche, 1, 0, "LATC"); |
| 84 | |
| 85 | } |
| 86 | //static DECLFW(Mapper13_write) |
| 87 | //{ |
| 88 | // setchr4r(0x10,0x1000,V&3); |
| 89 | // setprg32(0x8000,(V>>4)&3); |
| 90 | // latche=V; |
| 91 | //} |
| 92 | |
| 93 | //static void Mapper13_StateRestore(int version) |
| 94 | //{ |
| 95 | // setchr4r(0x10,0x0000,0); |
| 96 | // setchr4r(0x10,0x1000,latche&3); |
| 97 | // setprg32(0x8000,(latche>>4)&3); |
| 98 | //} |
| 99 | |
| 100 | //void Mapper13_init(void) |
| 101 | //{ |
| 102 | // SetWriteHandler(0x8000,0xFFFF,Mapper13_write); |
| 103 | // GameStateRestore=Mapper13_StateRestore; |
| 104 | // AddExState(&latche, 1, 0, "LATC"); |
| 105 | // AddExState(MapperExRAM, 16384, 0, "CHRR"); |
| 106 | // SetupCartCHRMapping(0x10, MapperExRAM, 16384, 1); |
| 107 | // latche=0; |
| 108 | // Mapper13_StateRestore(FCEU_VERSION_NUMERIC); |
| 109 | //} |
| 110 | |
| 111 | static DECLFW(Mapper34_write) |
| 112 | { |
| 113 | switch(A) |
| 114 | { |
| 115 | case 0x7FFD:ROM_BANK32(V);break; |
| 116 | case 0x7FFE:VROM_BANK4(0x0000,V);break; |
| 117 | case 0x7fff:VROM_BANK4(0x1000,V);break; |
| 118 | } |
| 119 | if(A>=0x8000) |
| 120 | ROM_BANK32(V); |
| 121 | } |
| 122 | |
| 123 | void Mapper34_init(void) |
| 124 | { |
| 125 | ROM_BANK32(0); |
| 126 | SetWriteHandler(0x7ffd,0xffff,Mapper34_write); |
| 127 | } |
| 128 | |
| 129 | DECLFW(Mapper66_write) |
| 130 | { |
| 131 | VROM_BANK8(V&0xF); |
| 132 | ROM_BANK32((V>>4)); |
| 133 | latche=V; |
| 134 | } |
| 135 | |
| 136 | void Mapper66_init(void) |
| 137 | { |
| 138 | ROM_BANK32(0); |
| 139 | SetWriteHandler(0x6000,0xffff,Mapper66_write); |
| 140 | AddExState(&latche, 1, 0, "LATC"); |
| 141 | } |
| 142 | |
| 143 | DECLFW(Mapper152_write) |
| 144 | { |
| 145 | ROM_BANK16(0x8000,(V>>4)&0x7); |
| 146 | VROM_BANK8(V&0xF); |
| 147 | onemir((V>>7)&1); /* Saint Seiya...hmm. */ |
| 148 | latche=V; |
| 149 | } |
| 150 | |
| 151 | void Mapper152_init(void) |
| 152 | { |
| 153 | onemir(0); |
| 154 | SetWriteHandler(0x6000,0xffff,Mapper152_write); |
| 155 | AddExState(&latche, 1, 0, "LATC"); |
| 156 | } |
| 157 | |
| 158 | static DECLFW(Mapper70_write) |
| 159 | { |
| 160 | ROM_BANK16(0x8000,V>>4); |
| 161 | VROM_BANK8(V&0xF); |
| 162 | latche=V; |
| 163 | } |
| 164 | |
| 165 | void Mapper70_init(void) |
| 166 | { |
| 167 | SetWriteHandler(0x6000,0xffff,Mapper70_write); |
| 168 | AddExState(&latche, 1, 0, "LATC"); |
| 169 | } |
| 170 | /* Should be two separate emulation functions for this "mapper". Sigh. URGE TO KILL RISING. */ |
| 171 | static DECLFW(Mapper78_write) |
| 172 | { |
| 173 | //printf("$%04x:$%02x\n",A,V&0x8); |
| 174 | ROM_BANK16(0x8000,V&0x7); |
| 175 | VROM_BANK8(V>>4); |
| 176 | onemir((V>>3)&1); |
| 177 | latche=V; |
| 178 | } |
| 179 | |
| 180 | void Mapper78_init(void) |
| 181 | { |
| 182 | SetWriteHandler(0x8000,0xffff,Mapper78_write); |
| 183 | AddExState(&latche, 1, 0, "LATC"); |
| 184 | } |
| 185 | |
| 186 | DECLFW(Mapper87_write) |
| 187 | { |
| 188 | VROM_BANK8(V>>1); |
| 189 | latche=V; |
| 190 | } |
| 191 | |
| 192 | void Mapper87_init(void) |
| 193 | { |
| 194 | SetWriteHandler(0x6000,0xffff,Mapper87_write); |
| 195 | AddExState(&latche, 1, 0, "LATC"); |
| 196 | } |
| 197 | |
| 198 | DECLFW(Mapper93_write) |
| 199 | { |
| 200 | ROM_BANK16(0x8000,V>>4); |
| 201 | MIRROR_SET(V&1); |
| 202 | latche=V; |
| 203 | } |
| 204 | |
| 205 | void Mapper93_init(void) |
| 206 | { |
| 207 | SetWriteHandler(0x8000,0xffff,Mapper93_write); |
| 208 | AddExState(&latche, 1, 0, "LATC"); |
| 209 | } |
| 210 | |
| 211 | |
| 212 | DECLFW(Mapper94_write) |
| 213 | { |
| 214 | ROM_BANK16(0x8000,V>>2); |
| 215 | latche=V; |
| 216 | } |
| 217 | |
| 218 | void Mapper94_init(void) |
| 219 | { |
| 220 | SetWriteHandler(0x8000,0xffff,Mapper94_write); |
| 221 | AddExState(&latche, 1, 0, "LATC"); |
| 222 | } |
| 223 | |
| 224 | /* I might want to add some code to the mapper 96 PPU hook function |
| 225 | to not change CHR banks if the attribute table is being accessed, |
| 226 | if I make emulation a little more accurate in the future. |
| 227 | */ |
| 228 | |
| 229 | static uint8 M96LA; |
| 230 | static DECLFW(Mapper96_write) |
| 231 | { |
| 232 | latche=V; |
| 233 | setprg32(0x8000,V&3); |
| 234 | setchr4r(0x10,0x0000,(latche&4)|M96LA); |
| 235 | setchr4r(0x10,0x1000,(latche&4)|3); |
| 236 | } |
| 237 | |
| 238 | static void FP_FASTAPASS(1) M96Hook(uint32 A) |
| 239 | { |
| 240 | if((A&0x3000)!=0x2000) return; |
| 241 | //if((A&0x3ff)>=0x3c0) return; |
| 242 | M96LA=(A>>8)&3; |
| 243 | setchr4r(0x10,0x0000,(latche&4)|M96LA); |
| 244 | } |
| 245 | |
| 246 | static void M96Sync(int v) |
| 247 | { |
| 248 | setprg32(0x8000,latche&3); |
| 249 | setchr4r(0x10,0x0000,(latche&4)|M96LA); |
| 250 | setchr4r(0x10,0x1000,(latche&4)|3); |
| 251 | } |
| 252 | |
| 253 | void Mapper96_init(void) |
| 254 | { |
| 255 | SetWriteHandler(0x8000,0xffff,Mapper96_write); |
| 256 | PPU_hook=M96Hook; |
| 257 | AddExState(&latche, 1, 0, "LATC"); |
| 258 | AddExState(&M96LA, 1, 0, "LAVA"); |
| 259 | SetupCartCHRMapping(0x10, MapperExRAM, 32768, 1); |
| 260 | latche=M96LA=0; |
| 261 | M96Sync(0); |
| 262 | setmirror(MI_0); |
| 263 | GameStateRestore=M96Sync; |
| 264 | } |
| 265 | |
| 266 | static DECLFW(Mapper140_write) |
| 267 | { |
| 268 | VROM_BANK8(V&0xF); |
| 269 | ROM_BANK32((V>>4)&0xF); |
| 270 | } |
| 271 | |
| 272 | void Mapper140_init(void) |
| 273 | { |
| 274 | ROM_BANK32(0); |
| 275 | SetWriteHandler(0x6000,0x7FFF,Mapper140_write); |
| 276 | } |
| 277 | |
| 278 | static void M185Sync(int version) |
| 279 | { |
| 280 | // on off |
| 281 | //1 0x0F, 0xF0 - Bird Week |
| 282 | //2 0x33, 0x00 - B-Wings |
| 283 | //3 0x11, 0x00 - Mighty Bomb Jack |
| 284 | //4 0x22, 0x20 - Sansuu 1 Nen, Sansuu 2 Nen |
| 285 | //5 0xFF, 0x00 - Sansuu 3 Nen |
| 286 | //6 0x21, 0x13 - Spy vs Spy |
| 287 | |
| 288 | // if((mapbyte1[0]&3)==1) // 6, 3 |
| 289 | // if(mapbyte1[0]&1) // 1, 2, 3, 5 |
| 290 | // if(mapbyte1[0]&2) // 1, 2, 4, 5, |
| 291 | if((mapbyte1[0]&2)||((mapbyte1[0]&3)==1)) // 1, 2, 3, 4, 5 |
| 292 | setchr8(0); |
| 293 | else |
| 294 | setchr8r(0x10,0); |
| 295 | } |
| 296 | |
| 297 | static DECLFW(Mapper185_write) |
| 298 | { |
| 299 | mapbyte1[0]=V; |
| 300 | M185Sync(0); |
| 301 | } |
| 302 | |
| 303 | void Mapper185_init(void) |
| 304 | { |
| 305 | int x; |
| 306 | for(x=0;x<8192;x++) |
| 307 | MapperExRAM[x]=0xff; |
| 308 | MapStateRestore=M185Sync; |
| 309 | mapbyte1[0]=0; |
| 310 | M185Sync(0); |
| 311 | SetupCartCHRMapping(0x10,MapperExRAM,8192,0); |
| 312 | SetWriteHandler(0x8000,0xFFFF,Mapper185_write); |
| 313 | } |
| 314 | |
| 315 | |
| 316 | static DECLFW(M156Write) |
| 317 | { |
| 318 | if(A>=0xc000 && A<=0xC003) |
| 319 | VROM_BANK1((A&3)*1024,V); |
| 320 | else if(A>=0xc008 && A<=0xc00b) |
| 321 | VROM_BANK1(0x1000+(A&3)*1024,V); |
| 322 | if(A==0xc010) ROM_BANK16(0x8000,V); |
| 323 | // printf("$%04x:$%02x\n",A,V); |
| 324 | } |
| 325 | |
| 326 | void Mapper156_init(void) |
| 327 | { |
| 328 | onemir(0); |
| 329 | SetWriteHandler(0xc000,0xc010,M156Write); |
| 330 | } |
| 331 | |
| 332 | static DECLFW(m107w) |
| 333 | { |
| 334 | ROM_BANK32((V>>1)&0x3); |
| 335 | VROM_BANK8(V&0x7); |
| 336 | } |
| 337 | |
| 338 | void Mapper107_init(void) |
| 339 | { |
| 340 | SetWriteHandler(0x8000,0xffff,m107w); |
| 341 | } |
| 342 | |