-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapper221.cpp
302 lines (278 loc) · 8.31 KB
/
mapper221.cpp
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/* Nintendulator Mapper DLLs
* Copyright (C) 2002-2011 QMT Productions
*
* $URL$
* $Id$
*/
#include "..\DLL\d_iNES.h"
#include "..\Hardware\h_MMC5p.h"
#include "resource.h"
namespace
{
HWND ConfigWindow;
unsigned long CRCtable[256];
int initialized = 0;
void InitCRC (void)
{
const unsigned long poly = 0xEDB88320;
unsigned long n;
if (initialized)
return;
for (int i = 0; i < 256; i++)
{
n = i;
for (int j = 0; j < 8; j++)
{
if (n & 1)
n = (n >> 1) ^ poly;
else n >>= 1;
}
CRCtable[i] = n;
}
initialized = 1;
}
unsigned long CalcCRC (unsigned char *data, int len)
{
unsigned long CRC = 0xFFFFFFFF;
InitCRC();
for (int i = 0; i < len; i++)
CRC = (CRC >> 8) ^ CRCtable[(CRC ^ data[i]) & 0xFF];
return CRC ^ 0xFFFFFFFF;
}
struct
{
unsigned long CRC;
int SRAMconf;
} MMC5Carts[23] = {
// ELROM
{0x95CA9EC7,MMC5p::WRAM_0KB_0KB}, // Castlevania III - Dracula's Curse (U)
{0x51D2112F,MMC5p::WRAM_0KB_0KB}, // Laser Invasion (U)
{0x255B129C,MMC5p::WRAM_0KB_0KB}, // Gun Sight (J)
{0xCD9ACF43,MMC5p::WRAM_0KB_0KB}, // Metal Slader Glory (J)
{0xD979C8B7,MMC5p::WRAM_0KB_0KB}, // Uchuu Keibitai SDF (J)
// EKROM
{0xE7C72DBB,MMC5p::WRAM_8KB_0KB}, // Gemfire (U)
{0x57F33F70,MMC5p::WRAM_8KB_0KB}, // Royal Blood (J)
{0x5D9D9891,MMC5p::WRAM_8KB_0KB}, // Just Breed (J)
{0xE91548D8,MMC5p::WRAM_8KB_0KB}, // Shin 4 Nin Uchi Mahjong - Yakuman Tengoku (J)
// ETROM
{0x2B548D75,MMC5p::WRAM_8KB_8KB}, // Bandit Kings of Ancient China (U)
{0xE6C28C5F,MMC5p::WRAM_8KB_8KB}, // Suikoden - Tenmei no Chikai (J)
{0x2F50BD38,MMC5p::WRAM_8KB_8KB}, // L'Empereur (U)
{0x57E3218B,MMC5p::WRAM_8KB_8KB}, // L'Empereur (J)
{0xB56958D1,MMC5p::WRAM_8KB_8KB}, // Nobunaga's Ambition 2 (U)
{0x98C8E090,MMC5p::WRAM_8KB_8KB}, // Nobunaga no Yabou - Sengoku Gunyuu Den (J)
{0xCD35E2E9,MMC5p::WRAM_8KB_8KB}, // Uncharted Waters (U)
{0xF4CD4998,MMC5p::WRAM_8KB_8KB}, // Daikoukai Jidai (J)
{0x8FA95456,MMC5p::WRAM_8KB_8KB}, // Ishin no Arashi (J)
// EWROM
{0x11EAAD26,MMC5p::WRAM_32KB_0KB}, // Romance of the Three Kingdoms II (U)
{0x286613D8,MMC5p::WRAM_32KB_0KB}, // Nobunaga no Yabou - Bushou Fuuun Roku (J)
{0x95BA5733,MMC5p::WRAM_32KB_0KB}, // Sangokushi 2 (J)
{0xF4120E58,MMC5p::WRAM_32KB_0KB}, // Aoki Ookami to Shiroki Mejika - Genchou Hishi (J)
};
int CheckSRAM (void)
{
int orig, size = MMC5p::WRAM_MAXOPTS;
unsigned long CRC;
// If the ROM is NES 2.0, look at the PRG RAM size byte
if (ROM->INES_Version == 2)
{
switch (ROM->INES2_PRGRAM)
{
// officially supported boards
case 0x00: return MMC5p::WRAM_0KB_0KB; break; // ELROM
case 0x70: return MMC5p::WRAM_8KB_0KB; break; // EKROM
case 0x77: return MMC5p::WRAM_8KB_8KB; break; // ETROM
case 0x90: return MMC5p::WRAM_32KB_0KB; break; // EWROM
// unofficial combinations, but actually supported by MMC5
case 0x07: return MMC5p::WRAM_0KB_8KB; break;
case 0x09: return MMC5p::WRAM_0KB_32KB; break;
case 0x79: return MMC5p::WRAM_8KB_32KB; break;
case 0x97: return MMC5p::WRAM_32KB_8KB; break;
case 0x99: return MMC5p::WRAM_32KB_32KB; break;
case 0xB0:
case 0x0B:
case 0xBB: return MMC5p::WRAM_64KB_64KB; break;
case 0xC0:
case 0x0C:
case 0xCC: return MMC5p::WRAM_128KB_128KB; break;
case 0xD0:
case 0x0D:
case 0xDD: return MMC5p::WRAM_256KB_256KB; break;
case 0xE0:
case 0x0E:
case 0xEE: return MMC5p::WRAM_512KB_512KB; break;
// none of the above
default:
EMU->DbgOut(_T("NES 2.0 SRAM sizes specified are not supported by the MMC5! Attempting ROM CRC32 lookup..."));
break;
}
}
orig = EMU->GetPRG_ROM4(8);
EMU->SetPRG_ROM4(8, 0);
CRC = CalcCRC(EMU->GetPRG_Ptr4(8), ROM->INES_PRGSize << 14);
for (int i = 0; i < 23; i++)
if (MMC5Carts[i].CRC == CRC)
size = MMC5Carts[i].SRAMconf;
if (orig == -1)
EMU->SetPRG_OB4(8);
else EMU->SetPRG_ROM4(8, orig);
return size;
}
void SetSRAM (void);
INT_PTR CALLBACK ConfigProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
switch (MMC5p::GetRAMSize())
{
default:
case MMC5p::WRAM_0KB_0KB: CheckRadioButton(hDlg, IDC_MAPPER5_0_0, IDC_MAPPER5_32_32, IDC_MAPPER5_0_0); break;
case MMC5p::WRAM_0KB_8KB: CheckRadioButton(hDlg, IDC_MAPPER5_0_0, IDC_MAPPER5_32_32, IDC_MAPPER5_0_8); break;
case MMC5p::WRAM_0KB_32KB: CheckRadioButton(hDlg, IDC_MAPPER5_0_0, IDC_MAPPER5_32_32, IDC_MAPPER5_0_32); break;
case MMC5p::WRAM_8KB_0KB: CheckRadioButton(hDlg, IDC_MAPPER5_0_0, IDC_MAPPER5_32_32, IDC_MAPPER5_8_0); break;
case MMC5p::WRAM_8KB_8KB: CheckRadioButton(hDlg, IDC_MAPPER5_0_0, IDC_MAPPER5_32_32, IDC_MAPPER5_8_8); break;
case MMC5p::WRAM_8KB_32KB: CheckRadioButton(hDlg, IDC_MAPPER5_0_0, IDC_MAPPER5_32_32, IDC_MAPPER5_8_32); break;
case MMC5p::WRAM_32KB_0KB: CheckRadioButton(hDlg, IDC_MAPPER5_0_0, IDC_MAPPER5_32_32, IDC_MAPPER5_32_0); break;
case MMC5p::WRAM_32KB_8KB: CheckRadioButton(hDlg, IDC_MAPPER5_0_0, IDC_MAPPER5_32_32, IDC_MAPPER5_32_8); break;
case MMC5p::WRAM_32KB_32KB:CheckRadioButton(hDlg, IDC_MAPPER5_0_0, IDC_MAPPER5_32_32, IDC_MAPPER5_32_32); break;
}
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
if (IsDlgButtonChecked(hDlg, IDC_MAPPER5_0_0) == BST_CHECKED)
MMC5p::SetRAMSize(MMC5p::WRAM_0KB_0KB);
else if (IsDlgButtonChecked(hDlg, IDC_MAPPER5_0_8) == BST_CHECKED)
MMC5p::SetRAMSize(MMC5p::WRAM_0KB_8KB);
else if (IsDlgButtonChecked(hDlg, IDC_MAPPER5_0_32) == BST_CHECKED)
MMC5p::SetRAMSize(MMC5p::WRAM_0KB_32KB);
else if (IsDlgButtonChecked(hDlg, IDC_MAPPER5_8_0) == BST_CHECKED)
MMC5p::SetRAMSize(MMC5p::WRAM_8KB_0KB);
else if (IsDlgButtonChecked(hDlg, IDC_MAPPER5_8_8) == BST_CHECKED)
MMC5p::SetRAMSize(MMC5p::WRAM_8KB_8KB);
else if (IsDlgButtonChecked(hDlg, IDC_MAPPER5_8_32) == BST_CHECKED)
MMC5p::SetRAMSize(MMC5p::WRAM_8KB_32KB);
else if (IsDlgButtonChecked(hDlg, IDC_MAPPER5_32_0) == BST_CHECKED)
MMC5p::SetRAMSize(MMC5p::WRAM_32KB_0KB);
else if (IsDlgButtonChecked(hDlg, IDC_MAPPER5_32_8) == BST_CHECKED)
MMC5p::SetRAMSize(MMC5p::WRAM_32KB_8KB);
else if (IsDlgButtonChecked(hDlg, IDC_MAPPER5_32_32) == BST_CHECKED)
MMC5p::SetRAMSize(MMC5p::WRAM_32KB_32KB);
SetSRAM();
MMC5p::SyncPRG();
MessageBox(hWnd, _T("Please perform a SOFT reset to ensure proper functionality!"), _T("INES.DLL"), MB_OK);
case IDCANCEL:
ConfigWindow = NULL;
DestroyWindow(hDlg);
return TRUE;
}
break;
}
return FALSE;
}
unsigned char MAPINT Config (CFG_TYPE mode, unsigned char data)
{
switch (mode)
{
case CFG_WINDOW:
if (data)
{
if (ConfigWindow)
break;
ConfigWindow = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_MAPPER5), hWnd, ConfigProc);
SetWindowPos(ConfigWindow, hWnd, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE);
}
else return FALSE;
break;
case CFG_QUERY:
break;
case CFG_CMD:
break;
}
return 0;
}
void SetSRAM (void)
{
switch (MMC5p::GetRAMSize())
{
case MMC5p::WRAM_0KB_0KB:
case MMC5p::WRAM_0KB_8KB:
case MMC5p::WRAM_0KB_32KB:
break;
case MMC5p::WRAM_8KB_0KB:
case MMC5p::WRAM_8KB_8KB:
case MMC5p::WRAM_8KB_32KB:
if (ROM->INES_Flags & 0x02)
EMU->Set_SRAMSize(8192);
break;
case MMC5p::WRAM_32KB_0KB:
case MMC5p::WRAM_32KB_8KB:
case MMC5p::WRAM_32KB_32KB:
if (ROM->INES_Flags & 0x02)
EMU->Set_SRAMSize(32768);
break;
//these might be excessive
case MMC5p::WRAM_64KB_64KB:
if (ROM->INES_Flags & 0x02)
EMU->Set_SRAMSize(65536);
break;
case MMC5p::WRAM_128KB_128KB:
if (ROM->INES_Flags & 0x02)
EMU->Set_SRAMSize(131072);
break;
case MMC5p::WRAM_256KB_256KB:
if (ROM->INES_Flags & 0x02)
EMU->Set_SRAMSize(262144);
break;
case MMC5p::WRAM_512KB_512KB:
if (ROM->INES_Flags & 0x02)
EMU->Set_SRAMSize(524288);
break;
case MMC5p::WRAM_MAXOPTS:
MMC5p::SetRAMSize(MMC5p::WRAM_32KB_8KB);
if (ROM->INES_Flags & 0x02)
EMU->Set_SRAMSize(32768);
EMU->DbgOut(_T("Unable to determine SRAM size for this game, falling back to 32KB/8KB! Please set it via the GAME menu!"));
break;
}
}
BOOL MAPINT Load (void)
{
MMC5p::Load(CheckSRAM());
SetSRAM();
ConfigWindow = NULL;
return TRUE;
}
void MAPINT Reset (RESET_TYPE ResetType)
{
MMC5p::Reset(ResetType);
}
void MAPINT Unload (void)
{
MMC5p::Unload();
if (ConfigWindow)
{
DestroyWindow(ConfigWindow);
ConfigWindow = NULL;
}
}
uint8 MapperNum = 221;
} // namespace
const MapperInfo MapperInfo_221 =
{
&MapperNum,
_T("MMC5+"),
COMPAT_FULL,
Load,
Reset,
Unload,
NULL,
MMC5p::PPUCycle,
MMC5p::SaveLoad,
MMC5p::MapperSnd,
Config
};