blob: 459dda7c4ac4cc1738428b239105f4f930d447b5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
/*===================================================================*/
/* */
/* Mapper 43 (SMB2J) */
/* */
/*===================================================================*/
DWORD Map43_IRQ_Cnt;
BYTE Map43_IRQ_Enable;
/*-------------------------------------------------------------------*/
/* Initialize Mapper 43 */
/*-------------------------------------------------------------------*/
void Map43_Init()
{
/* Initialize Mapper */
MapperInit = Map43_Init;
/* Write to Mapper */
MapperWrite = Map43_Write;
/* Write to SRAM */
MapperSram = Map0_Sram;
/* Write to APU */
MapperApu = Map43_Apu;
/* Read from APU */
MapperReadApu = Map43_ReadApu;
/* Callback at VSync */
MapperVSync = Map0_VSync;
/* Callback at HSync */
MapperHSync = Map43_HSync;
/* Callback at PPU */
MapperPPU = Map0_PPU;
/* Callback at Rendering Screen ( 1:BG, 0:Sprite ) */
MapperRenderScreen = Map0_RenderScreen;
/* Set SRAM Banks */
SRAMBANK = ROMPAGE( 2 );
/* Set ROM Banks */
ROMBANK0 = ROMPAGE( 1 );
ROMBANK1 = ROMPAGE( 0 );
ROMBANK2 = ROMPAGE( 4 );
ROMBANK3 = ROMPAGE( 9 );
/* Initialize State Registers */
Map43_IRQ_Enable = 1;
Map43_IRQ_Cnt = 0;
/* Set PPU Banks */
if ( NesHeader.byVRomSize > 0 )
{
for ( int nPage = 0; nPage < 8; ++nPage )
PPUBANK[ nPage ] = VROMPAGE( nPage );
InfoNES_SetupChr();
}
/* Set up wiring of the interrupt pin */
K6502_Set_Int_Wiring( 1, 1 );
}
/*-------------------------------------------------------------------*/
/* Mapper 43 Read from APU Function */
/*-------------------------------------------------------------------*/
BYTE Map43_ReadApu( WORD wAddr )
{
if ( 0x5000 <= wAddr && wAddr < 0x6000 )
{
return ROM[ 0x2000*8 + 0x1000 + (wAddr - 0x5000) ];
}
return (BYTE)(wAddr >> 8);
}
/*-------------------------------------------------------------------*/
/* Mapper 43 Write to APU Function */
/*-------------------------------------------------------------------*/
void Map43_Apu( WORD wAddr, BYTE byData )
{
if( (wAddr&0xF0FF) == 0x4022 )
{
switch( byData&0x07 )
{
case 0x00:
case 0x02:
case 0x03:
case 0x04:
ROMBANK2 = ROMPAGE( 4 );
break;
case 0x01:
ROMBANK2 = ROMPAGE( 3 );
break;
case 0x05:
ROMBANK2 = ROMPAGE( 7 );
break;
case 0x06:
ROMBANK2 = ROMPAGE( 5 );
break;
case 0x07:
ROMBANK2 = ROMPAGE( 6 );
break;
}
}
}
/*-------------------------------------------------------------------*/
/* Mapper 43 Write Function */
/*-------------------------------------------------------------------*/
void Map43_Write( WORD wAddr, BYTE byData )
{
if( wAddr == 0x8122 ) {
if( byData&0x03 ) {
Map43_IRQ_Enable = 1;
} else {
Map43_IRQ_Cnt = 0;
Map43_IRQ_Enable = 0;
}
}
}
/*-------------------------------------------------------------------*/
/* Mapper 43 H-Sync Function */
/*-------------------------------------------------------------------*/
void Map43_HSync()
{
if( Map43_IRQ_Enable )
{
Map43_IRQ_Cnt += 114;
if( Map43_IRQ_Cnt >= 4096 ) {
Map43_IRQ_Cnt -= 4096;
IRQ_REQ;
}
}
}
|