| 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 | * NTDEC, ASDER games |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include "mapinc.h" |
| 25 | |
| 26 | static uint8 reg[8]; |
| 27 | static uint8 mirror, cmd, bank; |
| 28 | static uint8 *WRAM=NULL; |
| 29 | |
| 30 | static SFORMAT StateRegs[]= |
| 31 | { |
| 32 | {&cmd, 1, "CMD"}, |
| 33 | {&mirror, 1, "MIRR"}, |
| 34 | {&bank, 1, "BANK"}, |
| 35 | {reg, 8, "REGS"}, |
| 36 | {0} |
| 37 | }; |
| 38 | |
| 39 | static void Sync(void) |
| 40 | { |
| 41 | setmirror(mirror^1); |
| 42 | setprg8(0x8000,reg[0]); |
| 43 | setprg8(0xA000,reg[1]); |
| 44 | setchr2(0x0000,(reg[2]>>1)); |
| 45 | setchr2(0x0800,(reg[3]>>1)); |
| 46 | setchr1(0x1000,((bank&0x10)<<4)|reg[4]); |
| 47 | setchr1(0x1400,((bank&0x20)<<3)|reg[5]); |
| 48 | setchr1(0x1800,((bank&0x40)<<2)|reg[6]); |
| 49 | setchr1(0x1C00,((bank&0x80)<<1)|reg[7]); |
| 50 | } |
| 51 | |
| 52 | static DECLFW(M112Write) |
| 53 | { |
| 54 | switch(A) |
| 55 | { |
| 56 | case 0xe000: mirror=V&1; Sync(); ;break; |
| 57 | case 0x8000: cmd=V&7; break; |
| 58 | case 0xa000: reg[cmd]=V; Sync(); break; |
| 59 | case 0xc000: bank=V; Sync(); break; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | static void M112Close(void) |
| 64 | { |
| 65 | if(WRAM) |
| 66 | FCEU_gfree(WRAM); |
| 67 | WRAM = NULL; |
| 68 | } |
| 69 | |
| 70 | static void M112Power(void) |
| 71 | { |
| 72 | bank=0; |
| 73 | setprg16(0xC000,~0); |
| 74 | setprg8r(0x10,0x6000,0); |
| 75 | SetReadHandler(0x8000,0xFFFF,CartBR); |
| 76 | SetWriteHandler(0x8000,0xFFFF,M112Write); |
| 77 | SetWriteHandler(0x4020,0x5FFF,M112Write); |
| 78 | SetReadHandler(0x6000,0x7FFF,CartBR); |
| 79 | SetWriteHandler(0x6000,0x7FFF,CartBW); |
| 80 | } |
| 81 | |
| 82 | static void StateRestore(int version) |
| 83 | { |
| 84 | Sync(); |
| 85 | } |
| 86 | |
| 87 | void Mapper112_Init(CartInfo *info) |
| 88 | { |
| 89 | info->Power=M112Power; |
| 90 | info->Close=M112Close; |
| 91 | GameStateRestore=StateRestore; |
| 92 | WRAM=(uint8*)FCEU_gmalloc(8192); |
| 93 | SetupCartPRGMapping(0x10,WRAM,8192,1); |
| 94 | AddExState(WRAM, 8192, 0, "WRAM"); |
| 95 | AddExState(&StateRegs, ~0, 0, 0); |
| 96 | } |