| 1 | /* FCE Ultra - NES/Famicom Emulator |
| 2 | * |
| 3 | * Copyright notice for this file: |
| 4 | * Copyright (C) 2005 CaH4e3 |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | |
| 21 | #include "mapinc.h" |
| 22 | #include "mmc3.h" |
| 23 | |
| 24 | static uint8 lut[256]={ |
| 25 | 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09, |
| 26 | 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x51, 0x41, 0x11, 0x01, 0x51, 0x41, 0x11, 0x01, |
| 27 | 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09, |
| 28 | 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x51, 0x41, 0x11, 0x01, 0x51, 0x41, 0x11, 0x01, |
| 29 | 0x00, 0x10, 0x40, 0x50, 0x00, 0x10, 0x40, 0x50,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 30 | 0x08, 0x18, 0x48, 0x58, 0x08, 0x18, 0x48, 0x58,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 31 | 0x00, 0x10, 0x40, 0x50, 0x00, 0x10, 0x40, 0x50,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 32 | 0x08, 0x18, 0x48, 0x58, 0x08, 0x18, 0x48, 0x58,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 33 | 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x58, 0x48, 0x18, 0x08, 0x58, 0x48, 0x18, 0x08, |
| 34 | 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x50, 0x40, 0x10, 0x00, 0x50, 0x40, 0x10, 0x00, |
| 35 | 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x58, 0x48, 0x18, 0x08, 0x58, 0x48, 0x18, 0x08, |
| 36 | 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x50, 0x40, 0x10, 0x00, 0x50, 0x40, 0x10, 0x00, |
| 37 | 0x01, 0x11, 0x41, 0x51, 0x01, 0x11, 0x41, 0x51,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 38 | 0x09, 0x19, 0x49, 0x59, 0x09, 0x19, 0x49, 0x59,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 39 | 0x01, 0x11, 0x41, 0x51, 0x01, 0x11, 0x41, 0x51,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 40 | 0x09, 0x19, 0x49, 0x59, 0x09, 0x19, 0x49, 0x59,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 41 | }; |
| 42 | |
| 43 | static void M208PW(uint32 A, uint8 V) |
| 44 | { |
| 45 | setprg32(0x8000,EXPREGS[5]); |
| 46 | } |
| 47 | |
| 48 | static DECLFW(M208Write) |
| 49 | { |
| 50 | EXPREGS[5]=(V&0x1)|((V>>3)&0x2); |
| 51 | FixMMC3PRG(MMC3_cmd); |
| 52 | } |
| 53 | |
| 54 | static DECLFW(M208ProtWrite) |
| 55 | { |
| 56 | if(A<=0x57FF) |
| 57 | EXPREGS[4]=V; |
| 58 | else |
| 59 | EXPREGS[(A&0x03)]=V^lut[EXPREGS[4]]; |
| 60 | } |
| 61 | |
| 62 | static DECLFR(M208ProtRead) |
| 63 | { |
| 64 | return(EXPREGS[(A&0x3)]); |
| 65 | } |
| 66 | |
| 67 | static void M208Power(void) |
| 68 | { |
| 69 | EXPREGS[5]=3; |
| 70 | GenMMC3Power(); |
| 71 | SetWriteHandler(0x4800,0x4FFF,M208Write); |
| 72 | SetWriteHandler(0x5000,0x5fff,M208ProtWrite); |
| 73 | SetReadHandler(0x5800,0x5FFF,M208ProtRead); |
| 74 | SetReadHandler(0x8000,0xffff,CartBR); |
| 75 | } |
| 76 | |
| 77 | void Mapper208_Init(CartInfo *info) |
| 78 | { |
| 79 | GenMMC3_Init(info, 128, 256, 0, 0); |
| 80 | pwrap=M208PW; |
| 81 | info->Power=M208Power; |
| 82 | AddExState(EXPREGS, 6, 0, "EXPR"); |
| 83 | } |