| 1 | /* FCE Ultra - NES/Famicom Emulator |
| 2 | * |
| 3 | * Copyright notice for this file: |
| 4 | * Copyright (C) 2002 Ben Parnell |
| 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 cmd mapbyte1[0] |
| 24 | #define mir mapbyte1[1] |
| 25 | #define rmode mapbyte1[2] |
| 26 | #define regsl mapbyte2 |
| 27 | #define regsh mapbyte3 |
| 28 | |
| 29 | static void RAMBO1_hb(void) |
| 30 | { |
| 31 | rmode=0; |
| 32 | if(IRQCount>=0) |
| 33 | { |
| 34 | IRQCount--; |
| 35 | if(IRQCount<0) |
| 36 | { |
| 37 | if(IRQa) |
| 38 | { |
| 39 | // printf("IRQ: %d\n",scanline); |
| 40 | rmode = 1; |
| 41 | X6502_IRQBegin(FCEU_IQEXT); |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | static void Synco(void) |
| 48 | { |
| 49 | int x; |
| 50 | |
| 51 | if(cmd&0x20) |
| 52 | { |
| 53 | setchr1(0x0000,regsl[0]); |
| 54 | setchr1(0x0800,regsl[1]); |
| 55 | setchr1(0x0400,regsh[0]); |
| 56 | setchr1(0x0c00,regsh[1]); |
| 57 | } |
| 58 | else |
| 59 | { |
| 60 | setchr2(0x0000,regsl[0]>>1); |
| 61 | setchr2(0x0800,regsl[1]>>1); |
| 62 | } |
| 63 | |
| 64 | for(x=0;x<4;x++) |
| 65 | setchr1(0x1000+x*0x400,regsl[2+x]); |
| 66 | |
| 67 | setprg8(0x8000,regsl[6]); |
| 68 | setprg8(0xA000,regsl[7]); |
| 69 | |
| 70 | setprg8(0xC000,regsh[7]); |
| 71 | } |
| 72 | |
| 73 | |
| 74 | static DECLFW(RAMBO1_write) |
| 75 | { |
| 76 | //if(A>=0xC000 && A<=0xFFFF) printf("$%04x:$%02x, %d, %d\n",A,V,scanline,timestamp); |
| 77 | switch(A&0xF001) |
| 78 | { |
| 79 | case 0xa000:mir=V&1; |
| 80 | setmirror(mir^1); |
| 81 | break; |
| 82 | case 0x8000:cmd = V; |
| 83 | break; |
| 84 | case 0x8001: |
| 85 | if((cmd&15)<8) |
| 86 | regsl[cmd&7]=V; |
| 87 | else |
| 88 | regsh[cmd&7]=V; |
| 89 | Synco(); |
| 90 | break; |
| 91 | case 0xc000:IRQLatch=V; |
| 92 | if(rmode==1) |
| 93 | { |
| 94 | IRQCount=IRQLatch; |
| 95 | } |
| 96 | break; |
| 97 | case 0xc001:rmode=1; |
| 98 | IRQCount=IRQLatch; |
| 99 | break; |
| 100 | case 0xE000:IRQa=0;X6502_IRQEnd(FCEU_IQEXT); |
| 101 | if(rmode==1) |
| 102 | {IRQCount=IRQLatch;} |
| 103 | break; |
| 104 | case 0xE001:IRQa=1; |
| 105 | if(rmode==1) |
| 106 | {IRQCount=IRQLatch;} |
| 107 | break; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | static void RAMBO1_Restore(int version) |
| 112 | { |
| 113 | if(version<74) |
| 114 | { |
| 115 | int x; |
| 116 | |
| 117 | x=mapbyte1[1]; // was MMC3_cmd |
| 118 | cmd=x; |
| 119 | |
| 120 | regsl[0]=CHRBankList[0]; |
| 121 | regsl[1]=CHRBankList[2]; |
| 122 | regsh[0]=CHRBankList[1]; |
| 123 | regsh[1]=CHRBankList[3]; |
| 124 | |
| 125 | for(x=0;x<4;x++) |
| 126 | regsl[2+x]=CHRBankList[4+x]; |
| 127 | |
| 128 | regsl[6]=PRGBankList[0]; |
| 129 | regsl[7]=PRGBankList[1]; |
| 130 | regsh[7]=PRGBankList[2]; |
| 131 | mir=Mirroring^1; |
| 132 | } |
| 133 | Synco(); |
| 134 | setmirror(mir^1); |
| 135 | } |
| 136 | |
| 137 | void Mapper64_init(void) |
| 138 | { |
| 139 | int x; |
| 140 | |
| 141 | for(x=0;x<8;x++) |
| 142 | regsl[x]=regsh[x]=~0; |
| 143 | cmd=0; |
| 144 | mir=0; |
| 145 | setmirror(1); |
| 146 | Synco(); |
| 147 | GameHBIRQHook=RAMBO1_hb; |
| 148 | GameStateRestore=RAMBO1_Restore; |
| 149 | SetWriteHandler(0x8000,0xffff,RAMBO1_write); |
| 150 | } |