| 1 | /* FCE Ultra - NES/Famicom Emulator |
| 2 | * |
| 3 | * Copyright notice for this file: |
| 4 | * Copyright (C) 2002 Xodnizel |
| 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
| 21 | #include "mapinc.h" |
| 22 | |
| 23 | //16 bits of ram in total |
| 24 | //only use bottom 4 bits as ram though |
| 25 | static uint8 mapper228_ram[4]; |
| 26 | |
| 27 | static SFORMAT StateRegs[]= |
| 28 | { |
| 29 | { mapper228_ram, 4, "MAPPER_RAM" }, |
| 30 | { 0 } |
| 31 | }; |
| 32 | |
| 33 | static DECLFR(Mapper228_read) |
| 34 | { |
| 35 | return mapper228_ram[A & 3] & 0xF; |
| 36 | } |
| 37 | |
| 38 | static DECLFW(Mapper228_write) |
| 39 | { |
| 40 | uint32 page, pagel, pageh; |
| 41 | |
| 42 | //write to ram |
| 43 | if (A < 0x6000) |
| 44 | { |
| 45 | mapper228_ram[A & 3] = V; |
| 46 | return; |
| 47 | } |
| 48 | MIRROR_SET((A >> 13) & 1); |
| 49 | page = (A >> 7) & 0x3F; |
| 50 | |
| 51 | if( (page & 0x30) == 0x30) |
| 52 | page -= 0x10; |
| 53 | |
| 54 | pagel = pageh = (page << 1) + (((A >> 6) & 1) & ((A >> 5) & 1)); |
| 55 | pageh += ((A >> 5) & 1) ^ 1; |
| 56 | |
| 57 | ROM_BANK16(0x8000,pagel); |
| 58 | ROM_BANK16(0xC000,pageh); |
| 59 | VROM_BANK8( (V&0x3) | ((A&0xF)<<2) ); |
| 60 | } |
| 61 | |
| 62 | static void A52Reset(void) |
| 63 | { |
| 64 | Mapper228_write(0x8000, 0); |
| 65 | } |
| 66 | |
| 67 | void Mapper228_init(void) |
| 68 | { |
| 69 | MapperReset=A52Reset; |
| 70 | A52Reset(); |
| 71 | SetWriteHandler(0x8000, 0xFFFF, Mapper228_write); |
| 72 | SetWriteHandler(0x4020, 0x5FFF, Mapper228_write); |
| 73 | SetReadHandler (0x4020, 0x5FFF, Mapper228_read); |
| 74 | AddExState(StateRegs, ~0, 0, 0); |
| 75 | } |
| 76 | |