mmuhack, 6502 tweaks, fskip
[fceu.git] / mappers / 90.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 tkcom1 mapbyte1[1]
24#define tkcom2 mapbyte1[2]
25
26#define prgb mapbyte2
27#define unkl (mapbyte2+4)
28#define chrlow mapbyte3
29#define chrhigh mapbyte4
30
31static uint8 tekker=0x80;
32
33static DECLFR(tekread)
34{
35 return tekker;
36}
37
38static void tekprom(void)
39{
40 switch(tkcom1&3)
41 {
42 case 1: // 16 KB
43 ROM_BANK16(0x8000,prgb[0]);
44 ROM_BANK16(0xC000,prgb[2]);
45 break;
46
47 case 2: //2 = 8 KB ??
48 case 3:
49 ROM_BANK8(0x8000,prgb[0]);
50 ROM_BANK8(0xa000,prgb[1]);
51 ROM_BANK8(0xc000,prgb[2]);
52 ROM_BANK8(0xe000,prgb[3]);
53 break;
54 }
55}
56
57static void tekvrom(void)
58{
59 int x;
60 switch(tkcom1&0x18)
61 {
62 case 0x00: // 8KB
63 VROM_BANK8(chrlow[0]|(chrhigh[0]<<8));
64 break;
65 case 0x08: // 4KB
66 for(x=0;x<8;x+=4)
67 VROM_BANK4(x<<10,chrlow[x]|(chrhigh[x]<<8));
68 break;
69 case 0x10: // 2KB
70 for(x=0;x<8;x+=2)
71 VROM_BANK2(x<<10,chrlow[x]|(chrhigh[x]<<8));
72 break;
73 case 0x18: // 1KB
74 for(x=0;x<8;x++)
75 VROM_BANK1(x<<10,chrlow[x]|(chrhigh[x]<<8));
76 break;
77 }
78}
79
80static DECLFW(Mapper90_write)
81{
82 A&=0xF007;
83
84 if(A>=0x8000 && A<=0x8003)
85 {
86 prgb[A&3]=V;
87 tekprom();
88 }
89 else if(A>=0x9000 && A<=0x9007)
90 {
91 chrlow[A&7]=V;
92 tekvrom();
93 }
94 else if(A>=0xa000 && A<=0xa007)
95 {
96 chrhigh[A&7]=V;
97 tekvrom();
98 }
99 else if(A>=0xb000 && A<=0xb003)
100 {
101 unkl[A&3]=V;
102 }
103 else switch(A)
104 {
105 case 0xc004:
106 case 0xc000:IRQLatch=V;break;
107
108 case 0xc005:
109 case 0xc001:X6502_IRQEnd(FCEU_IQEXT);
110 IRQCount=V;break;
111 case 0xc006:
112 case 0xc002:X6502_IRQEnd(FCEU_IQEXT);
113 IRQa=0;
114 IRQCount=IRQLatch;
115 break;
116 case 0xc007:
117 case 0xc003:IRQa=1;break;
118
119 case 0xd000:tkcom1=V;break;
120 case 0xd001:switch(V&3){
121 case 0x00:MIRROR_SET(0);break;
122 case 0x01:MIRROR_SET(1);break;
123 case 0x02:onemir(0);break;
124 case 0x03:onemir(1);break;
125 }
126 break;
127 break;
128 }
129}
130
131static void Mapper90_hb(void)
132{
133 if(IRQa)
134 {
135 if(IRQCount)
136 {
137 IRQCount--;
138 if(!IRQCount)
139 {
140 X6502_IRQBegin(FCEU_IQEXT);
141 IRQCount=IRQLatch;
142 }
143 }
144 }
145}
146
147void Mapper90_init(void)
148{
149 tekker^=0x80;
150 SetWriteHandler(0x8000,0xffff,Mapper90_write);
151 SetReadHandler(0x5000,0x5000,tekread);
152 GameHBIRQHook=Mapper90_hb;
153}
154