| 1 | /* FCE Ultra - NES/Famicom Emulator |
| 2 | * |
| 3 | * Copyright notice for this file: |
| 4 | * Copyright (C) 1998 BERO |
| 5 | * Copyright (C) 2002 Ben Parnell |
| 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 | #include <string.h> |
| 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 | DECLFW(Mapper7_write) |
| 51 | { |
| 52 | ROM_BANK32(V&0xF); |
| 53 | onemir((V>>4)&1); |
| 54 | latche=V; |
| 55 | } |
| 56 | |
| 57 | void Mapper7_init(void) |
| 58 | { |
| 59 | onemir(0); |
| 60 | ROM_BANK32(0); |
| 61 | SetWriteHandler(0x8000,0xFFFF,Mapper7_write); |
| 62 | AddExState(&latche, 1, 0, "LATC"); |
| 63 | } |
| 64 | |
| 65 | DECLFW(Mapper11_write) |
| 66 | { |
| 67 | ROM_BANK32(V); |
| 68 | VROM_BANK8(V>>4); |
| 69 | latche=V; |
| 70 | } |
| 71 | |
| 72 | void Mapper11_init(void) |
| 73 | { |
| 74 | ROM_BANK32(0); |
| 75 | SetWriteHandler(0x8000,0xFFFF,Mapper11_write); |
| 76 | AddExState(&latche, 1, 0, "LATC"); |
| 77 | } |
| 78 | |
| 79 | static DECLFW(Mapper13_write) |
| 80 | { |
| 81 | setchr4r(0x10,0x1000,V&3); |
| 82 | setprg32(0x8000,(V>>4)&3); |
| 83 | latche=V; |
| 84 | } |
| 85 | |
| 86 | static void Mapper13_StateRestore(int version) |
| 87 | { |
| 88 | setchr4r(0x10,0x0000,0); |
| 89 | setchr4r(0x10,0x1000,latche&3); |
| 90 | setprg32(0x8000,(latche>>4)&3); |
| 91 | } |
| 92 | |
| 93 | void Mapper13_init(void) |
| 94 | { |
| 95 | SetWriteHandler(0x8000,0xFFFF,Mapper13_write); |
| 96 | GameStateRestore=Mapper13_StateRestore; |
| 97 | AddExState(&latche, 1, 0, "LATC"); |
| 98 | AddExState(MapperExRAM, 16384, 0, "CHRR"); |
| 99 | SetupCartCHRMapping(0x10, MapperExRAM, 16384, 1); |
| 100 | |
| 101 | latche=0; |
| 102 | Mapper13_StateRestore(VERSION_NUMERIC); |
| 103 | } |
| 104 | |
| 105 | DECLFW(Mapper34_write) |
| 106 | { |
| 107 | switch(A) |
| 108 | { |
| 109 | case 0x7FFD:ROM_BANK32(V);break; |
| 110 | case 0x7FFE:VROM_BANK4(0x0000,V);break; |
| 111 | case 0x7fff:VROM_BANK4(0x1000,V);break; |
| 112 | } |
| 113 | if(A>=0x8000) |
| 114 | ROM_BANK32(V); |
| 115 | } |
| 116 | |
| 117 | void Mapper34_init(void) |
| 118 | { |
| 119 | SetWriteHandler(0x7ffd,0xffff,Mapper34_write); |
| 120 | } |
| 121 | |
| 122 | DECLFW(Mapper66_write) |
| 123 | { |
| 124 | VROM_BANK8(V&0xF); |
| 125 | ROM_BANK32((V>>4)); |
| 126 | latche=V; |
| 127 | } |
| 128 | |
| 129 | void Mapper66_init(void) |
| 130 | { |
| 131 | ROM_BANK32(0); |
| 132 | SetWriteHandler(0x6000,0xffff,Mapper66_write); |
| 133 | AddExState(&latche, 1, 0, "LATC"); |
| 134 | } |
| 135 | |
| 136 | DECLFW(Mapper152_write) |
| 137 | { |
| 138 | ROM_BANK16(0x8000,(V>>4)&0x7); |
| 139 | VROM_BANK8(V&0xF); |
| 140 | onemir((V>>7)&1); /* Saint Seiya...hmm. */ |
| 141 | latche=V; |
| 142 | } |
| 143 | |
| 144 | void Mapper152_init(void) |
| 145 | { |
| 146 | onemir(0); |
| 147 | SetWriteHandler(0x6000,0xffff,Mapper152_write); |
| 148 | AddExState(&latche, 1, 0, "LATC"); |
| 149 | } |
| 150 | |
| 151 | static DECLFW(Mapper70_write) |
| 152 | { |
| 153 | ROM_BANK16(0x8000,V>>4); |
| 154 | VROM_BANK8(V&0xF); |
| 155 | latche=V; |
| 156 | } |
| 157 | |
| 158 | void Mapper70_init(void) |
| 159 | { |
| 160 | SetWriteHandler(0x6000,0xffff,Mapper70_write); |
| 161 | AddExState(&latche, 1, 0, "LATC"); |
| 162 | } |
| 163 | /* Should be two separate emulation functions for this "mapper". Sigh. URGE TO KILL RISING. */ |
| 164 | static DECLFW(Mapper78_write) |
| 165 | { |
| 166 | //printf("$%04x:$%02x\n",A,V); |
| 167 | ROM_BANK16(0x8000,V&0x7); |
| 168 | VROM_BANK8(V>>4); |
| 169 | onemir((V>>3)&1); |
| 170 | latche=V; |
| 171 | } |
| 172 | |
| 173 | void Mapper78_init(void) |
| 174 | { |
| 175 | SetWriteHandler(0x8000,0xffff,Mapper78_write); |
| 176 | AddExState(&latche, 1, 0, "LATC"); |
| 177 | } |
| 178 | |
| 179 | DECLFW(Mapper87_write) |
| 180 | { |
| 181 | VROM_BANK8(V>>1); |
| 182 | latche=V; |
| 183 | } |
| 184 | |
| 185 | void Mapper87_init(void) |
| 186 | { |
| 187 | SetWriteHandler(0x6000,0xffff,Mapper87_write); |
| 188 | AddExState(&latche, 1, 0, "LATC"); |
| 189 | } |
| 190 | |
| 191 | DECLFW(Mapper93_write) |
| 192 | { |
| 193 | ROM_BANK16(0x8000,V>>4); |
| 194 | MIRROR_SET(V&1); |
| 195 | latche=V; |
| 196 | } |
| 197 | |
| 198 | void Mapper93_init(void) |
| 199 | { |
| 200 | SetWriteHandler(0x8000,0xffff,Mapper93_write); |
| 201 | AddExState(&latche, 1, 0, "LATC"); |
| 202 | } |
| 203 | |
| 204 | |
| 205 | DECLFW(Mapper94_write) |
| 206 | { |
| 207 | ROM_BANK16(0x8000,V>>2); |
| 208 | latche=V; |
| 209 | } |
| 210 | |
| 211 | void Mapper94_init(void) |
| 212 | { |
| 213 | SetWriteHandler(0x8000,0xffff,Mapper94_write); |
| 214 | AddExState(&latche, 1, 0, "LATC"); |
| 215 | } |
| 216 | |
| 217 | /* I might want to add some code to the mapper 96 PPU hook function |
| 218 | to not change CHR banks if the attribute table is being accessed, |
| 219 | if I make emulation a little more accurate in the future. |
| 220 | */ |
| 221 | |
| 222 | static uint8 M96LA; |
| 223 | static DECLFW(Mapper96_write) |
| 224 | { |
| 225 | latche=V; |
| 226 | setprg32(0x8000,V&3); |
| 227 | setchr4r(0x10,0x0000,(latche&4)|M96LA); |
| 228 | setchr4r(0x10,0x1000,(latche&4)|3); |
| 229 | } |
| 230 | |
| 231 | static void FP_FASTAPASS(1) M96Hook(uint32 A) |
| 232 | { |
| 233 | if((A&0x3000)!=0x2000) |
| 234 | return; |
| 235 | M96LA=(A>>8)&3; |
| 236 | setchr4r(0x10,0x0000,(latche&4)|M96LA); |
| 237 | } |
| 238 | |
| 239 | static void M96Sync() |
| 240 | { |
| 241 | setprg32(0x8000,latche&3); |
| 242 | setchr4r(0x10,0x0000,(latche&4)|M96LA); |
| 243 | setchr4r(0x10,0x1000,(latche&4)|3); |
| 244 | } |
| 245 | |
| 246 | void Mapper96_init(void) |
| 247 | { |
| 248 | SetWriteHandler(0x8000,0xffff,Mapper96_write); |
| 249 | PPU_hook=M96Hook; |
| 250 | AddExState(&latche, 1, 0, "LATC"); |
| 251 | AddExState(&M96LA, 1, 0, "LAVA"); |
| 252 | SetupCartCHRMapping(0x10, MapperExRAM, 32768, 1); |
| 253 | latche=M96LA=0; |
| 254 | M96Sync(); |
| 255 | GameStateRestore=M96Sync; |
| 256 | } |
| 257 | |
| 258 | static DECLFW(Mapper140_write) |
| 259 | { |
| 260 | VROM_BANK8(V&0xF); |
| 261 | ROM_BANK32((V>>4)&0xF); |
| 262 | } |
| 263 | |
| 264 | void Mapper140_init(void) |
| 265 | { |
| 266 | ROM_BANK32(0); |
| 267 | SetWriteHandler(0x6000,0x7FFF,Mapper140_write); |
| 268 | } |
| 269 | |
| 270 | static void M185Sync() |
| 271 | { |
| 272 | int x; |
| 273 | |
| 274 | if(!(mapbyte1[0]&3)) |
| 275 | // if(!(mapbyte1[0]==0x21)) |
| 276 | { |
| 277 | for(x=0;x<8;x++) |
| 278 | setchr1r(0x10,x<<10,0); |
| 279 | } |
| 280 | else |
| 281 | setchr8(0); |
| 282 | } |
| 283 | |
| 284 | static DECLFW(Mapper185_write) |
| 285 | { |
| 286 | mapbyte1[0]=V; |
| 287 | M185Sync(); |
| 288 | // printf("Wr: $%04x:$%02x\n",A,V); |
| 289 | } |
| 290 | |
| 291 | void Mapper185_init(void) |
| 292 | { |
| 293 | memset(MapperExRAM,0xFF,1024); |
| 294 | MapStateRestore=M185Sync; |
| 295 | mapbyte1[0]=0; |
| 296 | M185Sync(); |
| 297 | |
| 298 | SetupCartCHRMapping(0x10,MapperExRAM,1024,0); |
| 299 | SetWriteHandler(0x8000,0xFFFF,Mapper185_write); |
| 300 | } |