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 vrctemp mapbyte1[0] |
24 | #define indox mapbyte1[1] |
25 | |
26 | static int acount=0; |
27 | |
28 | void KillOPL(void); |
29 | void UpdateOPL(int Count); |
30 | void vrc7translate(uint8 A, uint8 V); |
31 | void LoadOPL(void); |
32 | extern uint8 VRC7Instrument[16][8]; |
33 | extern uint8 VRC7Chan[3][6]; |
34 | |
35 | static INLINE void DaMirror(int V) |
36 | { |
37 | int salpo[4]={MI_V,MI_H,MI_0,MI_1}; |
38 | setmirror(salpo[V&3]); |
39 | } |
40 | |
41 | DECLFW(Mapper85_write) |
42 | { |
43 | A|=(A&8)<<1; |
44 | |
45 | if(A>=0xa000 && A<=0xDFFF) |
46 | { |
47 | A&=0xF010; |
48 | { |
49 | int x=((A>>4)&1)|((A-0xA000)>>11); |
50 | mapbyte3[x]=V; |
51 | setchr1(x<<10,V); |
52 | } |
53 | } |
54 | else if(A==0x9030) |
55 | { |
56 | if(FSettings.SndRate) |
57 | vrc7translate(indox,V); |
58 | GameExpSound.Fill=UpdateOPL; |
59 | } |
60 | else switch(A&0xF010) |
61 | { |
62 | case 0x8000:mapbyte2[0]=V;setprg8(0x8000,V);break; |
63 | case 0x8010:mapbyte2[1]=V;setprg8(0xa000,V);break; |
64 | case 0x9000:mapbyte2[2]=V;setprg8(0xc000,V);break; |
65 | case 0x9010:indox=V;break; |
66 | case 0xe000:mapbyte2[3]=V;DaMirror(V);break; |
67 | case 0xE010:IRQLatch=V; |
68 | break; |
69 | case 0xF000:IRQa=V&2; |
70 | vrctemp=V&1; |
71 | if(V&2) {IRQCount=IRQLatch;acount=0;} |
72 | break; |
73 | case 0xf010:if(vrctemp) IRQa=1; |
74 | else IRQa=0; |
75 | break; |
76 | } |
77 | } |
78 | |
79 | static void FP_FASTAPASS(1) KonamiIRQHook(int a) |
80 | { |
81 | if(IRQa) |
82 | { |
83 | acount+=(a<<1)+a; |
84 | if(acount>=339) |
85 | { |
86 | doagainbub:acount-=339;IRQCount++; |
87 | if(IRQCount&0x100) {TriggerIRQ();IRQCount=IRQLatch;} |
88 | if(acount>=339) goto doagainbub; |
89 | } |
90 | } |
91 | } |
92 | |
93 | void Mapper85_StateRestore(int version) |
94 | { |
95 | int x; |
96 | |
97 | if(version<72) |
98 | { |
99 | for(x=0;x<8;x++) |
100 | mapbyte3[x]=CHRBankList[x]; |
101 | for(x=0;x<3;x++) |
102 | mapbyte2[x]=PRGBankList[x]; |
103 | mapbyte2[3]=(Mirroring<0x10)?Mirroring:Mirroring-0xE; |
104 | } |
105 | |
106 | for(x=0;x<8;x++) |
107 | setchr1(x*0x400,mapbyte3[x]); |
108 | for(x=0;x<3;x++) |
109 | setprg8(0x8000+x*8192,mapbyte2[x]); |
110 | DaMirror(mapbyte2[3]); |
111 | LoadOPL(); |
112 | } |
113 | |
114 | static void M85SC(void) |
115 | { |
116 | KillOPL(); |
117 | } |
118 | |
119 | void VRC7_ESI(void) |
120 | { |
121 | if(FSettings.SndRate) |
122 | { |
123 | SetWriteHandler(0x9010,0x901F,Mapper85_write); |
124 | SetWriteHandler(0x9030,0x903F,Mapper85_write); |
125 | } |
126 | GameExpSound.RChange=M85SC; |
127 | } |
128 | |
129 | void Mapper85_init(void) |
130 | { |
131 | MapIRQHook=KonamiIRQHook; |
132 | SetWriteHandler(0x8000,0xffff,Mapper85_write); |
133 | GameStateRestore=Mapper85_StateRestore; |
134 | VRC7_ESI(); |
135 | if(!VROM_size) |
136 | SetupCartCHRMapping(0, CHRRAM, 8192, 1); |
137 | AddExState(VRC7Instrument, 16, 0, "VC7I"); |
138 | AddExState(VRC7Chan, sizeof(VRC7Chan), 0, "V7CH"); |
139 | |
140 | } |