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