more 0.98.15-like timing, but sound glitches
[fceu.git] / mappers / 16.c
CommitLineData
c62d2810 1/* FCE Ultra - NES/Famicom Emulator
2 *
3 * Copyright notice for this file:
4 * Copyright (C) 1998 BERO
5 * Copyright (C) 2002 Ben Parnell
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#include "mapinc.h"
23
24static void FP_FASTAPASS(1) BandaiIRQHook(int a)
25{
26 if(IRQa)
27 {
28 IRQCount-=a;
29 if(IRQCount<0)
30 {
31 X6502_IRQBegin(FCEU_IQEXT);
32 //printf("IRQ: %d, %d\n",scanline,timestamp);
33 IRQa=0;
34 IRQCount=0xFFFF;
35 }
36 }
37}
38
39static DECLFW(Mapper16_write)
40{
41 A&=0xF;
42
43 if(A<=0x7)
44 VROM_BANK1(A<<10,V);
45 else if(A==0x8)
c0bf6f9f 46 {
c62d2810 47 ROM_BANK16(0x8000,V);
c0bf6f9f 48 X6502_Rebase();
49 }
c62d2810 50 else switch(A) {
51 case 0x9: switch(V&3) {
52 case 0x00:MIRROR_SET2(1);break;
53 case 0x01:MIRROR_SET2(0);break;
54 case 0x02:onemir(0);break;
55 case 0x03:onemir(1);break;
56 }
57 break;
58 case 0xA:X6502_IRQEnd(FCEU_IQEXT);
59 IRQa=V&1;
60 IRQCount=IRQLatch;
61 break;
62 case 0xB:IRQLatch&=0xFF00;
63 IRQLatch|=V;
64 break;
65 case 0xC:IRQLatch&=0xFF;
66 IRQLatch|=V<<8;
67 break;
68 case 0xD: break;/* Serial EEPROM control port */
69 }
70}
71
72// Famicom jump 2:
73// 0-7: Lower bit of data selects which 256KB PRG block is in use.
74// This seems to be a hack on the developers' part, so I'll make emulation
75// of it a hack(I think the current PRG block would depend on whatever the
76// lowest bit of the CHR bank switching register that corresponds to the
77// last CHR address read).
78
79static void PRGO(void)
80{
81 uint32 base=(mapbyte1[0]&1)<<4;
82 ROM_BANK16(0x8000,(mapbyte2[0]&0xF)|base);
83 ROM_BANK16(0xC000,base|0xF);
c0bf6f9f 84 X6502_Rebase();
c62d2810 85}
86
87static DECLFW(Mapper153_write)
88{
89 A&=0xF;
c0bf6f9f 90 if(A<=0x7)
c62d2810 91 {
92 mapbyte1[A&7]=V;
93 PRGO();
94 }
c0bf6f9f 95 else if(A==0x8)
c62d2810 96 {
97 mapbyte2[0]=V;
98 PRGO();
99 }
100 else switch(A) {
101 case 0x9: switch(V&3) {
102 case 0x00:MIRROR_SET2(1);break;
103 case 0x01:MIRROR_SET2(0);break;
104 case 0x02:onemir(0);break;
105 case 0x03:onemir(1);break;
106 }
107 break;
108 case 0xA:X6502_IRQEnd(FCEU_IQEXT);
109 IRQa=V&1;
110 IRQCount=IRQLatch;
111 break;
112 case 0xB:IRQLatch&=0xFF00;
113 IRQLatch|=V;
114 break;
115 case 0xC:IRQLatch&=0xFF;
116 IRQLatch|=V<<8;
117 break;
118 }
119}
120
121void Mapper16_init(void)
122{
123 MapIRQHook=BandaiIRQHook;
124 SetWriteHandler(0x6000,0xFFFF,Mapper16_write);
125}
126
127void Mapper153_init(void)
128{
129 MapIRQHook=BandaiIRQHook;
130 SetWriteHandler(0x8000,0xFFFF,Mapper153_write);
131 /* This mapper/board seems to have WRAM at $6000-$7FFF, so I'll let the
132 main ines code take care of that memory region. */
133}