| 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | |
| 21 | #include "mapinc.h" |
| 22 | |
| 23 | #define rg mapbyte1 |
| 24 | |
| 25 | static void DoSync(uint32 A) |
| 26 | { |
| 27 | uint32 S = A & 1; |
| 28 | uint32 p = (A >> 2) & 0x1F; |
| 29 | p += (A&0x100) ? 0x20 : 0; |
| 30 | uint32 o = (A>>7)&1; |
| 31 | uint32 L = (A>>9)&1; |
| 32 | |
| 33 | if (o && !S ) |
| 34 | { |
| 35 | ROM_BANK16(0x8000,p); |
| 36 | ROM_BANK16(0xC000,p); |
| 37 | } |
| 38 | if (o && S ) |
| 39 | { |
| 40 | ROM_BANK16(0x8000,p); |
| 41 | ROM_BANK16(0xC000,p+1); |
| 42 | } |
| 43 | if (!o && !S && !L ) |
| 44 | { |
| 45 | ROM_BANK16(0x8000,p); |
| 46 | ROM_BANK16(0xC000,p&0x38); |
| 47 | } |
| 48 | if (!o && S && !L ) |
| 49 | { |
| 50 | ROM_BANK16(0x8000,p&0x3E); |
| 51 | ROM_BANK16(0xC000,p&0x38); |
| 52 | } |
| 53 | if (!o && !S && L) |
| 54 | { |
| 55 | ROM_BANK16(0x8000,p); |
| 56 | ROM_BANK16(0xC000,p|7); |
| 57 | } |
| 58 | if (!o && S && L ) |
| 59 | { |
| 60 | ROM_BANK16(0x8000,p&0x3E); |
| 61 | ROM_BANK16(0xC000,p|7); |
| 62 | } |
| 63 | |
| 64 | rg[0]=A; |
| 65 | rg[1]=A>>8; |
| 66 | |
| 67 | MIRROR_SET((A>>1)&1); |
| 68 | } |
| 69 | |
| 70 | static DECLFW(Mapper227_write) |
| 71 | { |
| 72 | DoSync(A); |
| 73 | } |
| 74 | |
| 75 | static void M227Reset(void) |
| 76 | { |
| 77 | DoSync(0); |
| 78 | } |
| 79 | |
| 80 | static void M227Restore(int version) |
| 81 | { |
| 82 | DoSync(rg[0]|(rg[1]<<8)); |
| 83 | } |
| 84 | |
| 85 | void Mapper227_init(void) |
| 86 | { |
| 87 | SetWriteHandler(0x8000,0xffff,Mapper227_write); |
| 88 | MapperReset=M227Reset; |
| 89 | GameStateRestore=M227Restore; |
| 90 | M227Reset(); |
| 91 | } |