frameskip, cleanups
[fceu.git] / mappers / 105.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
24#define MMC1_reg mapbyte1
25#define MMC1_buf mapbyte2[0]
26#define MMC1_sft mapbyte3[0]
27#define lastn mapbyte2[1]
28
29#define NWCDIP 0xE
30
31static void FP_FASTAPASS(1) NWCIRQHook(int a)
32{
33 if(!(MMC1_reg[1]&0x10))
34 {
35 IRQCount+=a;
36 if((IRQCount|(NWCDIP<<25))>=0x3e000000)
37 {
38 IRQCount=0;
39 X6502_IRQBegin(FCEU_IQEXT);
40 }
41 }
42}
43
44
45static void MMC1PRG(void)
46{
47 if(MMC1_reg[1]&8)
48 {
49 switch(MMC1_reg[0]&0xC)
50 {
51 case 0xC: ROM_BANK16(0x8000,8+(MMC1_reg[3]&7));
52 ROM_BANK16(0xC000,15);
53 break;
54 case 0x8: ROM_BANK16(0xC000,8+((MMC1_reg[3])&7));
55 ROM_BANK16(0x8000,8);
56 break;
57 case 0x0:
58 case 0x4:
59 ROM_BANK16(0x8000,8+(MMC1_reg[3]&6));
60 ROM_BANK16(0xc000,8+((MMC1_reg[3]&6)+1));
61 break;
62 }
63 }
64 else
65 {
66 ROM_BANK32((MMC1_reg[1]>>1)&3);
67 }
68}
69
70DECLFW(Mapper105_write)
71{
72 int n=(A>>13)-4;
73
74 if (V&0x80)
75 {
76 MMC1_sft=MMC1_buf=0;
77 return;
78 }
79
80 if(lastn!=n)
81 {
82 MMC1_sft=MMC1_buf=0;
83 }
84 lastn=n;
85
86 //MMC1_reg[n]&=~((1)<<(MMC1_sft));
87 MMC1_buf|=(V&1)<<(MMC1_sft++);
88
89 if (MMC1_sft==5)
90 {
91 if(n==3) V&=0xF;
92 else V&=0x1F;
93
94 MMC1_reg[n]=V=MMC1_buf;
95 MMC1_sft = MMC1_buf=0;
96
97 switch(n){
98 case 0:
99 switch(MMC1_reg[0]&3)
100 {
101 case 2: MIRROR_SET(0);break;
102 case 3: MIRROR_SET(1);break;
103 case 0: onemir(0);break;
104 case 1: onemir(1);break;
105 }
106 MMC1PRG();
107 break;
108 case 1:
109 if(MMC1_reg[1]&0x10)
110 {IRQCount=0;X6502_IRQEnd(FCEU_IQEXT);}
111 MMC1PRG();
112 break;
113 case 3:
114 MMC1PRG();
115 break;
116 }
117 }
118}
119
120
121void Mapper105_init(void)
122{
123 int i;
124 for(i=0;i<4;i++) MMC1_reg[i]=0;
125 MMC1_sft = MMC1_buf =0;
126 MMC1_reg[0]=0xC;
127 ROM_BANK32(0);
128 SetWriteHandler(0x8000,0xFFFF,Mapper105_write);
129 MapIRQHook=NWCIRQHook;
130}
131