some movies fixed
[fceu.git] / mappers / 64.c
CommitLineData
c62d2810 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
29static 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
47static 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]);
c0bf6f9f 71 X6502_Rebase();
c62d2810 72}
73
74
75static DECLFW(RAMBO1_write)
76{
77 //if(A>=0xC000 && A<=0xFFFF) printf("$%04x:$%02x, %d, %d\n",A,V,scanline,timestamp);
78 switch(A&0xF001)
79 {
80 case 0xa000:mir=V&1;
81 setmirror(mir^1);
82 break;
83 case 0x8000:cmd = V;
84 break;
85 case 0x8001:
86 if((cmd&15)<8)
87 regsl[cmd&7]=V;
88 else
89 regsh[cmd&7]=V;
90 Synco();
91 break;
92 case 0xc000:IRQLatch=V;
93 if(rmode==1)
94 {
95 IRQCount=IRQLatch;
96 }
97 break;
98 case 0xc001:rmode=1;
99 IRQCount=IRQLatch;
100 break;
101 case 0xE000:IRQa=0;X6502_IRQEnd(FCEU_IQEXT);
102 if(rmode==1)
103 {IRQCount=IRQLatch;}
104 break;
105 case 0xE001:IRQa=1;
106 if(rmode==1)
107 {IRQCount=IRQLatch;}
108 break;
c0bf6f9f 109 }
c62d2810 110}
111
112static void RAMBO1_Restore(int version)
113{
114 if(version<74)
115 {
116 int x;
117
118 x=mapbyte1[1]; // was MMC3_cmd
119 cmd=x;
120
121 regsl[0]=CHRBankList[0];
122 regsl[1]=CHRBankList[2];
123 regsh[0]=CHRBankList[1];
124 regsh[1]=CHRBankList[3];
125
126 for(x=0;x<4;x++)
127 regsl[2+x]=CHRBankList[4+x];
128
129 regsl[6]=PRGBankList[0];
130 regsl[7]=PRGBankList[1];
131 regsh[7]=PRGBankList[2];
132 mir=Mirroring^1;
133 }
134 Synco();
135 setmirror(mir^1);
136}
137
138void Mapper64_init(void)
139{
140 int x;
141
142 for(x=0;x<8;x++)
143 regsl[x]=regsh[x]=~0;
144 cmd=0;
145 mir=0;
146 setmirror(1);
147 Synco();
148 GameHBIRQHook=RAMBO1_hb;
149 GameStateRestore=RAMBO1_Restore;
150 SetWriteHandler(0x8000,0xffff,RAMBO1_write);
151}