c62d2810 |
1 | /* FCE Ultra - NES/Famicom Emulator |
2 | * |
3 | * Copyright notice for this file: |
d97315ac |
4 | * Copyright (C) 2002 Xodnizel |
c62d2810 |
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 | |
d97315ac |
23 | |
24 | /*void Mapper83_init(void) |
25 | { |
26 | |
27 | } |
28 | */ |
29 | static void FP_FASTAPASS(1) m83IRQHook(int a) |
c62d2810 |
30 | { |
31 | if(IRQa) |
32 | { |
33 | IRQCount-=a; |
34 | if(IRQCount<0) |
35 | { |
d97315ac |
36 | X6502_IRQBegin(FCEU_IQEXT); |
c62d2810 |
37 | IRQa=0; |
38 | IRQCount=0xFFFF; |
39 | } |
40 | } |
41 | } |
42 | |
43 | static DECLFW(wrlow) |
44 | { |
45 | mapbyte4[A&3]=V; |
46 | } |
47 | |
48 | static DECLFR(rdlow) |
49 | { |
50 | return mapbyte4[A&3]; |
51 | } |
52 | |
53 | static void m83prg(void) |
54 | { |
d97315ac |
55 | ROM_BANK16(0x8000,(mapbyte1[0]&0x3F)); |
c62d2810 |
56 | ROM_BANK16(0xC000,(mapbyte1[0]&0x30)|0xF); |
57 | } |
58 | |
59 | static void m83chr(void) |
60 | { |
e2d0dd92 |
61 | // if(0) |
62 | // { |
63 | // VROM_BANK2(0x0000,mapbyte2[0]); |
64 | // VROM_BANK2(0x0800,mapbyte2[1]); |
65 | // VROM_BANK2(0x1000,mapbyte2[6]); |
66 | // VROM_BANK2(0x1800,mapbyte2[7]); |
67 | // } |
68 | // else |
69 | // { |
70 | int x; |
71 | for(x=0;x<8;x++) |
72 | VROM_BANK1(x*0x400,mapbyte2[x]|((mapbyte1[0]&0x30)<<4)); |
73 | // } |
c62d2810 |
74 | } |
75 | |
76 | static DECLFW(Mapper83_write) |
77 | { |
78 | //printf("$%04x:$%02x\n",A,V); |
79 | switch(A) |
80 | { |
81 | case 0x8000: |
82 | case 0xB000: |
83 | case 0xB0FF: |
84 | case 0xB1FF: |
85 | { |
86 | mapbyte1[0]=V; |
87 | m83prg(); |
88 | m83chr(); |
89 | } |
90 | break; |
91 | case 0x8100: |
e2d0dd92 |
92 | mapbyte3[0]=V&0x80; |
c62d2810 |
93 | switch(V&0x3) |
94 | { |
95 | case 0x00:MIRROR_SET2(1);break; |
96 | case 0x01:MIRROR_SET2(0);break; |
97 | case 0x02:onemir(0);break; |
98 | case 0x03:onemir(1);break; |
99 | } |
100 | break; |
d97315ac |
101 | case 0x8200:IRQCount&=0xFF00;IRQCount|=V;X6502_IRQEnd(FCEU_IQEXT);break; |
e2d0dd92 |
102 | case 0x8201:IRQa=mapbyte3[0];IRQCount&=0xFF;IRQCount|=V<<8;break; |
d97315ac |
103 | case 0x8300:ROM_BANK8(0x8000,V);break; |
104 | case 0x8301:ROM_BANK8(0xA000,V);break; |
105 | case 0x8302:ROM_BANK8(0xC000,V);break; |
c62d2810 |
106 | case 0x8310:mapbyte2[0]=V;m83chr();break; |
107 | case 0x8311:mapbyte2[1]=V;m83chr();break; |
108 | case 0x8312:mapbyte2[2]=V;m83chr();break; |
109 | case 0x8313:mapbyte2[3]=V;m83chr();break; |
110 | case 0x8314:mapbyte2[4]=V;m83chr();break; |
111 | case 0x8315:mapbyte2[5]=V;m83chr();break; |
112 | case 0x8316:mapbyte2[6]=V;m83chr();break; |
113 | case 0x8317:mapbyte2[7]=V;m83chr();break; |
d97315ac |
114 | case 0x8318:mapbyte1[1]=V;m83prg();break; |
c62d2810 |
115 | } |
116 | // printf("$%04x:$%02x, $%04x\n",A,V,X.PC.W); |
d97315ac |
117 | |
c62d2810 |
118 | } |
119 | |
120 | void Mapper83_init(void) |
121 | { |
c62d2810 |
122 | ROM_BANK8(0xc000,0x1e); |
123 | ROM_BANK8(0xe000,0x1f); |
124 | |
125 | MapIRQHook=m83IRQHook; |
126 | |
127 | SetReadHandler(0x5100,0x5103,rdlow); |
128 | SetWriteHandler(0x5100,0x5103,wrlow); |
129 | SetWriteHandler(0x8000,0xffff,Mapper83_write); |
d97315ac |
130 | mapbyte1[1]=0xF; |
c62d2810 |
131 | } |