Browse code

Update snes9x code from 1.53 to 1.6.0.

Notable differences from upstream:
* Did not use the same #include setup for the new byuu apu and instead chose to do things more traditionally, as the latter is also much easier to deal with in Visual Studio than just including .cpp files into other .cpp files...
* MSU1 support not included (I see no need for this in a plugin meant to be used for original SNES music).
* The dynamic rate control on the APU not included (I also see no need for it in this plugin).
* The extra resamplers I added in were removed as the original hermite resampler was folded into a single non-inhertiable resampler.
* Bits of cleanup.

Naram Qashat authored on 2021/04/19 21:20:36
Showing 1 changed files
... ...
@@ -1,179 +1,8 @@
1
-/***********************************************************************************
1
+/*****************************************************************************\
2 2
   Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
3
-
4
-  (c) Copyright 1996 - 2002  Gary Henderson (gary.henderson@ntlworld.com),
5
-                             Jerremy Koot (jkoot@snes9x.com)
6
-
7
-  (c) Copyright 2002 - 2004  Matthew Kendora
8
-
9
-  (c) Copyright 2002 - 2005  Peter Bortas (peter@bortas.org)
10
-
11
-  (c) Copyright 2004 - 2005  Joel Yliluoma (http://iki.fi/bisqwit/)
12
-
13
-  (c) Copyright 2001 - 2006  John Weidman (jweidman@slip.net)
14
-
15
-  (c) Copyright 2002 - 2006  funkyass (funkyass@spam.shaw.ca),
16
-                             Kris Bleakley (codeviolation@hotmail.com)
17
-
18
-  (c) Copyright 2002 - 2010  Brad Jorsch (anomie@users.sourceforge.net),
19
-                             Nach (n-a-c-h@users.sourceforge.net),
20
-
21
-  (c) Copyright 2002 - 2011  zones (kasumitokoduck@yahoo.com)
22
-
23
-  (c) Copyright 2006 - 2007  nitsuja
24
-
25
-  (c) Copyright 2009 - 2011  BearOso,
26
-                             OV2
27
-
28
-
29
-  BS-X C emulator code
30
-  (c) Copyright 2005 - 2006  Dreamer Nom,
31
-                             zones
32
-
33
-  C4 x86 assembler and some C emulation code
34
-  (c) Copyright 2000 - 2003  _Demo_ (_demo_@zsnes.com),
35
-                             Nach,
36
-                             zsKnight (zsknight@zsnes.com)
37
-
38
-  C4 C++ code
39
-  (c) Copyright 2003 - 2006  Brad Jorsch,
40
-                             Nach
41
-
42
-  DSP-1 emulator code
43
-  (c) Copyright 1998 - 2006  _Demo_,
44
-                             Andreas Naive (andreasnaive@gmail.com),
45
-                             Gary Henderson,
46
-                             Ivar (ivar@snes9x.com),
47
-                             John Weidman,
48
-                             Kris Bleakley,
49
-                             Matthew Kendora,
50
-                             Nach,
51
-                             neviksti (neviksti@hotmail.com)
52
-
53
-  DSP-2 emulator code
54
-  (c) Copyright 2003         John Weidman,
55
-                             Kris Bleakley,
56
-                             Lord Nightmare (lord_nightmare@users.sourceforge.net),
57
-                             Matthew Kendora,
58
-                             neviksti
59
-
60
-  DSP-3 emulator code
61
-  (c) Copyright 2003 - 2006  John Weidman,
62
-                             Kris Bleakley,
63
-                             Lancer,
64
-                             z80 gaiden
65
-
66
-  DSP-4 emulator code
67
-  (c) Copyright 2004 - 2006  Dreamer Nom,
68
-                             John Weidman,
69
-                             Kris Bleakley,
70
-                             Nach,
71
-                             z80 gaiden
72
-
73
-  OBC1 emulator code
74
-  (c) Copyright 2001 - 2004  zsKnight,
75
-                             pagefault (pagefault@zsnes.com),
76
-                             Kris Bleakley
77
-                             Ported from x86 assembler to C by sanmaiwashi
78
-
79
-  SPC7110 and RTC C++ emulator code used in 1.39-1.51
80
-  (c) Copyright 2002         Matthew Kendora with research by
81
-                             zsKnight,
82
-                             John Weidman,
83
-                             Dark Force
84
-
85
-  SPC7110 and RTC C++ emulator code used in 1.52+
86
-  (c) Copyright 2009         byuu,
87
-                             neviksti
88
-
89
-  S-DD1 C emulator code
90
-  (c) Copyright 2003         Brad Jorsch with research by
91
-                             Andreas Naive,
92
-                             John Weidman
93
-
94
-  S-RTC C emulator code
95
-  (c) Copyright 2001 - 2006  byuu,
96
-                             John Weidman
97
-
98
-  ST010 C++ emulator code
99
-  (c) Copyright 2003         Feather,
100
-                             John Weidman,
101
-                             Kris Bleakley,
102
-                             Matthew Kendora
103
-
104
-  Super FX x86 assembler emulator code
105
-  (c) Copyright 1998 - 2003  _Demo_,
106
-                             pagefault,
107
-                             zsKnight
108
-
109
-  Super FX C emulator code
110
-  (c) Copyright 1997 - 1999  Ivar,
111
-                             Gary Henderson,
112
-                             John Weidman
113
-
114
-  Sound emulator code used in 1.5-1.51
115
-  (c) Copyright 1998 - 2003  Brad Martin
116
-  (c) Copyright 1998 - 2006  Charles Bilyue'
117
-
118
-  Sound emulator code used in 1.52+
119
-  (c) Copyright 2004 - 2007  Shay Green (gblargg@gmail.com)
120
-
121
-  SH assembler code partly based on x86 assembler code
122
-  (c) Copyright 2002 - 2004  Marcus Comstedt (marcus@mc.pp.se)
123
-
124
-  2xSaI filter
125
-  (c) Copyright 1999 - 2001  Derek Liauw Kie Fa
126
-
127
-  HQ2x, HQ3x, HQ4x filters
128
-  (c) Copyright 2003         Maxim Stepin (maxim@hiend3d.com)
129
-
130
-  NTSC filter
131
-  (c) Copyright 2006 - 2007  Shay Green
132
-
133
-  GTK+ GUI code
134
-  (c) Copyright 2004 - 2011  BearOso
135
-
136
-  Win32 GUI code
137
-  (c) Copyright 2003 - 2006  blip,
138
-                             funkyass,
139
-                             Matthew Kendora,
140
-                             Nach,
141
-                             nitsuja
142
-  (c) Copyright 2009 - 2011  OV2
143
-
144
-  Mac OS GUI code
145
-  (c) Copyright 1998 - 2001  John Stiles
146
-  (c) Copyright 2001 - 2011  zones
147
-
148
-
149
-  Specific ports contains the works of other authors. See headers in
150
-  individual files.
151
-
152
-
153
-  Snes9x homepage: http://www.snes9x.com/
154
-
155
-  Permission to use, copy, modify and/or distribute Snes9x in both binary
156
-  and source form, for non-commercial purposes, is hereby granted without
157
-  fee, providing that this license information and copyright notice appear
158
-  with all copies and any derived work.
159
-
160
-  This software is provided 'as-is', without any express or implied
161
-  warranty. In no event shall the authors be held liable for any damages
162
-  arising from the use of this software or it's derivatives.
163
-
164
-  Snes9x is freeware for PERSONAL USE only. Commercial users should
165
-  seek permission of the copyright holders first. Commercial use includes,
166
-  but is not limited to, charging money for Snes9x or software derived from
167
-  Snes9x, including Snes9x or derivatives in commercial game bundles, and/or
168
-  using Snes9x as a promotion for your commercial product.
169
-
170
-  The copyright holders request that bug fixes and improvements to the code
171
-  should be forwarded to them so everyone can benefit from the modifications
172
-  in future versions.
173
-
174
-  Super NES and Super Nintendo Entertainment System are trademarks of
175
-  Nintendo Co., Limited and its subsidiary companies.
176
- ***********************************************************************************/
3
+                This file is licensed under the Snes9x License.
4
+   For further information, consult the LICENSE file in the root directory.
5
+\*****************************************************************************/
177 6
 
178 7
 #include <algorithm>
179 8
 #include "snes9x.h"
... ...
@@ -188,8 +17,7 @@ static void S9xSoftResetCPU()
188 17
 	CPU.V_Counter = 0;
189 18
 	CPU.Flags &= DEBUG_MODE_FLAG | TRACE_FLAG;
190 19
 	CPU.PCBase = nullptr;
191
-	CPU.NMILine = CPU.IRQLine = CPU.IRQTransition = CPU.IRQLastState = false;
192
-	CPU.IRQPending = Timings.IRQPendCount;
20
+	CPU.NMIPending = CPU.IRQLine = CPU.IRQTransition = false;
193 21
 	CPU.MemSpeed = SLOW_ONE_CYCLE;
194 22
 	CPU.MemSpeedx2 = SLOW_ONE_CYCLE * 2;
195 23
 	CPU.FastROMSpeed = SLOW_ONE_CYCLE;
... ...
@@ -218,6 +46,9 @@ static void S9xSoftResetCPU()
218 46
 	Timings.H_Max = Timings.H_Max_Master;
219 47
 	Timings.V_Max = Timings.V_Max_Master;
220 48
 	Timings.NMITriggerPos = 0xffff;
49
+	Timings.NextIRQTimer = 0x0fffffff;
50
+	Timings.IRQFlagChanging = IRQ_NONE;
51
+
221 52
 	Timings.WRAMRefreshPos = Model->_5A22 == 2 ? SNES_WRAM_REFRESH_HC_v2 : SNES_WRAM_REFRESH_HC_v1;
222 53
 
223 54
 	S9xSetPCBase(Registers.PC.xPBPC);
Browse code

[SNSF] Replaced most uses of fill/copy with fill_n/copy_n, and a few other minor code cleanups.

Naram Qashat authored on 2013/05/27 22:34:22
Showing 1 changed files
... ...
@@ -218,10 +218,7 @@ static void S9xSoftResetCPU()
218 218
 	Timings.H_Max = Timings.H_Max_Master;
219 219
 	Timings.V_Max = Timings.V_Max_Master;
220 220
 	Timings.NMITriggerPos = 0xffff;
221
-	if (Model->_5A22 == 2)
222
-		Timings.WRAMRefreshPos = SNES_WRAM_REFRESH_HC_v2;
223
-	else
224
-		Timings.WRAMRefreshPos = SNES_WRAM_REFRESH_HC_v1;
221
+	Timings.WRAMRefreshPos = Model->_5A22 == 2 ? SNES_WRAM_REFRESH_HC_v2 : SNES_WRAM_REFRESH_HC_v1;
225 222
 
226 223
 	S9xSetPCBase(Registers.PC.xPBPC);
227 224
 
... ...
@@ -242,9 +239,9 @@ static void S9xResetCPU()
242 239
 
243 240
 void S9xReset()
244 241
 {
245
-	std::fill(&Memory.RAM[0], &Memory.RAM[0x20000], 0x55);
246
-	std::fill(&Memory.VRAM[0], &Memory.VRAM[0x10000], 0);
247
-	std::fill(&Memory.FillRAM[0], &Memory.FillRAM[0x8000], 0);
242
+	std::fill_n(&Memory.RAM[0], 0x20000, 0x55);
243
+	std::fill_n(&Memory.VRAM[0], 0x10000, 0);
244
+	std::fill_n(&Memory.FillRAM[0], 0x8000, 0);
248 245
 
249 246
 	S9xResetCPU();
250 247
 	S9xResetPPU();
Browse code

[SNSF] Massive code cleanup, as well as removing as much unused code/variables as possible.

Naram Qashat authored on 2013/05/23 06:02:16
Showing 1 changed files
... ...
@@ -175,64 +175,42 @@
175 175
   Nintendo Co., Limited and its subsidiary companies.
176 176
  ***********************************************************************************/
177 177
 
178
+#include <algorithm>
178 179
 #include "snes9x.h"
179 180
 #include "memmap.h"
180 181
 #include "dma.h"
181 182
 #include "apu/apu.h"
182
-//#include "fxemu.h"
183
-#include "sdd1.h"
184
-//#include "srtc.h"
185
-//#include "snapshot.h"
186
-//#include "cheats.h"
187
-//#include "logger.h"
188
-#ifdef DEBUGGER
189
-#include "debug.h"
190
-#endif
191
-
192
-//static void S9xResetCPU();
193
-//static void S9xSoftResetCPU();
194 183
 
195 184
 static void S9xSoftResetCPU()
196 185
 {
197 186
 	CPU.Cycles = 182; // Or 188. This is the cycle count just after the jump to the Reset Vector.
198 187
 	CPU.PrevCycles = CPU.Cycles;
199 188
 	CPU.V_Counter = 0;
200
-	CPU.Flags = CPU.Flags & (DEBUG_MODE_FLAG | TRACE_FLAG);
201
-	CPU.PCBase = NULL;
202
-	CPU.NMILine = false;
203
-	CPU.IRQLine = false;
204
-	CPU.IRQTransition = false;
205
-	CPU.IRQLastState = false;
206
-	CPU.IRQExternal = false;
189
+	CPU.Flags &= DEBUG_MODE_FLAG | TRACE_FLAG;
190
+	CPU.PCBase = nullptr;
191
+	CPU.NMILine = CPU.IRQLine = CPU.IRQTransition = CPU.IRQLastState = false;
207 192
 	CPU.IRQPending = Timings.IRQPendCount;
208 193
 	CPU.MemSpeed = SLOW_ONE_CYCLE;
209 194
 	CPU.MemSpeedx2 = SLOW_ONE_CYCLE * 2;
210 195
 	CPU.FastROMSpeed = SLOW_ONE_CYCLE;
211
-	CPU.InDMA = false;
212
-	CPU.InHDMA = false;
213
-	CPU.InDMAorHDMA = false;
214
-	CPU.InWRAMDMAorHDMA = false;
196
+	CPU.InDMA = CPU.InHDMA = CPU.InDMAorHDMA = CPU.InWRAMDMAorHDMA = false;
215 197
 	CPU.HDMARanInDMA = 0;
216 198
 	CPU.CurrentDMAorHDMAChannel = -1;
217 199
 	CPU.WhichEvent = HC_RENDER_EVENT;
218 200
 	CPU.NextEvent  = Timings.RenderPos;
219 201
 	CPU.WaitingForInterrupt = false;
220
-	CPU.AutoSaveTimer = 0;
221
-	CPU.SRAMModified = false;
222 202
 
223
-	Registers.PBPC = 0;
224
-	Registers.PB = 0;
225
-	Registers.PCw = S9xGetWord(0xfffc);
226
-	OpenBus = Registers.PCh;
203
+	Registers.PC.xPBPC = 0;
204
+	Registers.PC.B.xPB = 0;
205
+	Registers.PC.W.xPC = S9xGetWord(0xfffc);
206
+	OpenBus = Registers.PC.B.xPCh;
227 207
 	Registers.D.W = 0;
228 208
 	Registers.DB = 0;
229
-	Registers.SH = 1;
230
-	Registers.SL -= 3;
231
-	Registers.XH = 0;
232
-	Registers.YH = 0;
209
+	Registers.S.B.h = 1;
210
+	Registers.S.B.l -= 3;
211
+	Registers.X.B.h = Registers.Y.B.h = 0;
233 212
 
234
-	ICPU.ShiftedPB = 0;
235
-	ICPU.ShiftedDB = 0;
213
+	ICPU.ShiftedPB = ICPU.ShiftedDB = 0;
236 214
 	SetFlags(MemoryFlag | IndexFlag | IRQ | Emulation);
237 215
 	ClearFlags(Decimal);
238 216
 
... ...
@@ -245,7 +223,7 @@ static void S9xSoftResetCPU()
245 223
 	else
246 224
 		Timings.WRAMRefreshPos = SNES_WRAM_REFRESH_HC_v1;
247 225
 
248
-	S9xSetPCBase(Registers.PBPC);
226
+	S9xSetPCBase(Registers.PC.xPBPC);
249 227
 
250 228
 	ICPU.S9xOpcodes = S9xOpcodesE1;
251 229
 	ICPU.S9xOpLengths = S9xOpLengthsM1X1;
... ...
@@ -256,82 +234,20 @@ static void S9xSoftResetCPU()
256 234
 static void S9xResetCPU()
257 235
 {
258 236
 	S9xSoftResetCPU();
259
-	Registers.SL = 0xff;
260
-	Registers.P.W = 0;
261
-	Registers.A.W = 0;
262
-	Registers.X.W = 0;
263
-	Registers.Y.W = 0;
237
+	Registers.S.B.l = 0xff;
238
+	Registers.P.W = Registers.A.W = Registers.X.W = Registers.Y.W = 0;
264 239
 	SetFlags(MemoryFlag | IndexFlag | IRQ | Emulation);
265 240
 	ClearFlags(Decimal);
266 241
 }
267 242
 
268 243
 void S9xReset()
269 244
 {
270
-	/*S9xResetSaveTimer(false);
271
-	S9xResetLogger();*/
272
-
273
-	memset(Memory.RAM, 0x55, 0x20000);
274
-	memset(Memory.VRAM, 0x00, 0x10000);
275
-	ZeroMemory(Memory.FillRAM, 0x8000);
276
-
277
-	/*if (Settings.BS)
278
-		S9xResetBSX();*/
245
+	std::fill(&Memory.RAM[0], &Memory.RAM[0x20000], 0x55);
246
+	std::fill(&Memory.VRAM[0], &Memory.VRAM[0x10000], 0);
247
+	std::fill(&Memory.FillRAM[0], &Memory.FillRAM[0x8000], 0);
279 248
 
280 249
 	S9xResetCPU();
281 250
 	S9xResetPPU();
282 251
 	S9xResetDMA();
283 252
 	S9xResetAPU();
284
-
285
-	/*if (Settings.DSP)
286
-		S9xResetDSP();
287
-	if (Settings.SuperFX)
288
-		S9xResetSuperFX();
289
-	if (Settings.SA1)
290
-		S9xSA1Init();*/
291
-	if (Settings.SDD1)
292
-		S9xResetSDD1();
293
-	/*if (Settings.SPC7110)
294
-		S9xResetSPC7110();
295
-	if (Settings.C4)
296
-		S9xInitC4();
297
-	if (Settings.OBC1)
298
-		S9xResetOBC1();
299
-	if (Settings.SRTC)
300
-		S9xResetSRTC();
301
-
302
-	S9xInitCheatData();*/
303
-}
304
-
305
-void S9xSoftReset()
306
-{
307
-	//S9xResetSaveTimer(false);
308
-
309
-	ZeroMemory(Memory.FillRAM, 0x8000);
310
-
311
-	/*if (Settings.BS)
312
-		S9xResetBSX();*/
313
-
314
-	S9xSoftResetCPU();
315
-	S9xSoftResetPPU();
316
-	S9xResetDMA();
317
-	S9xSoftResetAPU();
318
-
319
-	/*if (Settings.DSP)
320
-		S9xResetDSP();
321
-	if (Settings.SuperFX)
322
-		S9xResetSuperFX();
323
-	if (Settings.SA1)
324
-		S9xSA1Init();*/
325
-	if (Settings.SDD1)
326
-		S9xResetSDD1();
327
-	/*if (Settings.SPC7110)
328
-		S9xResetSPC7110();
329
-	if (Settings.C4)
330
-		S9xInitC4();
331
-	if (Settings.OBC1)
332
-		S9xResetOBC1();
333
-	if (Settings.SRTC)
334
-		S9xResetSRTC();
335
-
336
-	S9xInitCheatData();*/
337 253
 }
Browse code

Import actual code.

Naram Qashat authored on 2013/03/26 02:41:19
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,337 @@
1
+/***********************************************************************************
2
+  Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
3
+
4
+  (c) Copyright 1996 - 2002  Gary Henderson (gary.henderson@ntlworld.com),
5
+                             Jerremy Koot (jkoot@snes9x.com)
6
+
7
+  (c) Copyright 2002 - 2004  Matthew Kendora
8
+
9
+  (c) Copyright 2002 - 2005  Peter Bortas (peter@bortas.org)
10
+
11
+  (c) Copyright 2004 - 2005  Joel Yliluoma (http://iki.fi/bisqwit/)
12
+
13
+  (c) Copyright 2001 - 2006  John Weidman (jweidman@slip.net)
14
+
15
+  (c) Copyright 2002 - 2006  funkyass (funkyass@spam.shaw.ca),
16
+                             Kris Bleakley (codeviolation@hotmail.com)
17
+
18
+  (c) Copyright 2002 - 2010  Brad Jorsch (anomie@users.sourceforge.net),
19
+                             Nach (n-a-c-h@users.sourceforge.net),
20
+
21
+  (c) Copyright 2002 - 2011  zones (kasumitokoduck@yahoo.com)
22
+
23
+  (c) Copyright 2006 - 2007  nitsuja
24
+
25
+  (c) Copyright 2009 - 2011  BearOso,
26
+                             OV2
27
+
28
+
29
+  BS-X C emulator code
30
+  (c) Copyright 2005 - 2006  Dreamer Nom,
31
+                             zones
32
+
33
+  C4 x86 assembler and some C emulation code
34
+  (c) Copyright 2000 - 2003  _Demo_ (_demo_@zsnes.com),
35
+                             Nach,
36
+                             zsKnight (zsknight@zsnes.com)
37
+
38
+  C4 C++ code
39
+  (c) Copyright 2003 - 2006  Brad Jorsch,
40
+                             Nach
41
+
42
+  DSP-1 emulator code
43
+  (c) Copyright 1998 - 2006  _Demo_,
44
+                             Andreas Naive (andreasnaive@gmail.com),
45
+                             Gary Henderson,
46
+                             Ivar (ivar@snes9x.com),
47
+                             John Weidman,
48
+                             Kris Bleakley,
49
+                             Matthew Kendora,
50
+                             Nach,
51
+                             neviksti (neviksti@hotmail.com)
52
+
53
+  DSP-2 emulator code
54
+  (c) Copyright 2003         John Weidman,
55
+                             Kris Bleakley,
56
+                             Lord Nightmare (lord_nightmare@users.sourceforge.net),
57
+                             Matthew Kendora,
58
+                             neviksti
59
+
60
+  DSP-3 emulator code
61
+  (c) Copyright 2003 - 2006  John Weidman,
62
+                             Kris Bleakley,
63
+                             Lancer,
64
+                             z80 gaiden
65
+
66
+  DSP-4 emulator code
67
+  (c) Copyright 2004 - 2006  Dreamer Nom,
68
+                             John Weidman,
69
+                             Kris Bleakley,
70
+                             Nach,
71
+                             z80 gaiden
72
+
73
+  OBC1 emulator code
74
+  (c) Copyright 2001 - 2004  zsKnight,
75
+                             pagefault (pagefault@zsnes.com),
76
+                             Kris Bleakley
77
+                             Ported from x86 assembler to C by sanmaiwashi
78
+
79
+  SPC7110 and RTC C++ emulator code used in 1.39-1.51
80
+  (c) Copyright 2002         Matthew Kendora with research by
81
+                             zsKnight,
82
+                             John Weidman,
83
+                             Dark Force
84
+
85
+  SPC7110 and RTC C++ emulator code used in 1.52+
86
+  (c) Copyright 2009         byuu,
87
+                             neviksti
88
+
89
+  S-DD1 C emulator code
90
+  (c) Copyright 2003         Brad Jorsch with research by
91
+                             Andreas Naive,
92
+                             John Weidman
93
+
94
+  S-RTC C emulator code
95
+  (c) Copyright 2001 - 2006  byuu,
96
+                             John Weidman
97
+
98
+  ST010 C++ emulator code
99
+  (c) Copyright 2003         Feather,
100
+                             John Weidman,
101
+                             Kris Bleakley,
102
+                             Matthew Kendora
103
+
104
+  Super FX x86 assembler emulator code
105
+  (c) Copyright 1998 - 2003  _Demo_,
106
+                             pagefault,
107
+                             zsKnight
108
+
109
+  Super FX C emulator code
110
+  (c) Copyright 1997 - 1999  Ivar,
111
+                             Gary Henderson,
112
+                             John Weidman
113
+
114
+  Sound emulator code used in 1.5-1.51
115
+  (c) Copyright 1998 - 2003  Brad Martin
116
+  (c) Copyright 1998 - 2006  Charles Bilyue'
117
+
118
+  Sound emulator code used in 1.52+
119
+  (c) Copyright 2004 - 2007  Shay Green (gblargg@gmail.com)
120
+
121
+  SH assembler code partly based on x86 assembler code
122
+  (c) Copyright 2002 - 2004  Marcus Comstedt (marcus@mc.pp.se)
123
+
124
+  2xSaI filter
125
+  (c) Copyright 1999 - 2001  Derek Liauw Kie Fa
126
+
127
+  HQ2x, HQ3x, HQ4x filters
128
+  (c) Copyright 2003         Maxim Stepin (maxim@hiend3d.com)
129
+
130
+  NTSC filter
131
+  (c) Copyright 2006 - 2007  Shay Green
132
+
133
+  GTK+ GUI code
134
+  (c) Copyright 2004 - 2011  BearOso
135
+
136
+  Win32 GUI code
137
+  (c) Copyright 2003 - 2006  blip,
138
+                             funkyass,
139
+                             Matthew Kendora,
140
+                             Nach,
141
+                             nitsuja
142
+  (c) Copyright 2009 - 2011  OV2
143
+
144
+  Mac OS GUI code
145
+  (c) Copyright 1998 - 2001  John Stiles
146
+  (c) Copyright 2001 - 2011  zones
147
+
148
+
149
+  Specific ports contains the works of other authors. See headers in
150
+  individual files.
151
+
152
+
153
+  Snes9x homepage: http://www.snes9x.com/
154
+
155
+  Permission to use, copy, modify and/or distribute Snes9x in both binary
156
+  and source form, for non-commercial purposes, is hereby granted without
157
+  fee, providing that this license information and copyright notice appear
158
+  with all copies and any derived work.
159
+
160
+  This software is provided 'as-is', without any express or implied
161
+  warranty. In no event shall the authors be held liable for any damages
162
+  arising from the use of this software or it's derivatives.
163
+
164
+  Snes9x is freeware for PERSONAL USE only. Commercial users should
165
+  seek permission of the copyright holders first. Commercial use includes,
166
+  but is not limited to, charging money for Snes9x or software derived from
167
+  Snes9x, including Snes9x or derivatives in commercial game bundles, and/or
168
+  using Snes9x as a promotion for your commercial product.
169
+
170
+  The copyright holders request that bug fixes and improvements to the code
171
+  should be forwarded to them so everyone can benefit from the modifications
172
+  in future versions.
173
+
174
+  Super NES and Super Nintendo Entertainment System are trademarks of
175
+  Nintendo Co., Limited and its subsidiary companies.
176
+ ***********************************************************************************/
177
+
178
+#include "snes9x.h"
179
+#include "memmap.h"
180
+#include "dma.h"
181
+#include "apu/apu.h"
182
+//#include "fxemu.h"
183
+#include "sdd1.h"
184
+//#include "srtc.h"
185
+//#include "snapshot.h"
186
+//#include "cheats.h"
187
+//#include "logger.h"
188
+#ifdef DEBUGGER
189
+#include "debug.h"
190
+#endif
191
+
192
+//static void S9xResetCPU();
193
+//static void S9xSoftResetCPU();
194
+
195
+static void S9xSoftResetCPU()
196
+{
197
+	CPU.Cycles = 182; // Or 188. This is the cycle count just after the jump to the Reset Vector.
198
+	CPU.PrevCycles = CPU.Cycles;
199
+	CPU.V_Counter = 0;
200
+	CPU.Flags = CPU.Flags & (DEBUG_MODE_FLAG | TRACE_FLAG);
201
+	CPU.PCBase = NULL;
202
+	CPU.NMILine = false;
203
+	CPU.IRQLine = false;
204
+	CPU.IRQTransition = false;
205
+	CPU.IRQLastState = false;
206
+	CPU.IRQExternal = false;
207
+	CPU.IRQPending = Timings.IRQPendCount;
208
+	CPU.MemSpeed = SLOW_ONE_CYCLE;
209
+	CPU.MemSpeedx2 = SLOW_ONE_CYCLE * 2;
210
+	CPU.FastROMSpeed = SLOW_ONE_CYCLE;
211
+	CPU.InDMA = false;
212
+	CPU.InHDMA = false;
213
+	CPU.InDMAorHDMA = false;
214
+	CPU.InWRAMDMAorHDMA = false;
215
+	CPU.HDMARanInDMA = 0;
216
+	CPU.CurrentDMAorHDMAChannel = -1;
217
+	CPU.WhichEvent = HC_RENDER_EVENT;
218
+	CPU.NextEvent  = Timings.RenderPos;
219
+	CPU.WaitingForInterrupt = false;
220
+	CPU.AutoSaveTimer = 0;
221
+	CPU.SRAMModified = false;
222
+
223
+	Registers.PBPC = 0;
224
+	Registers.PB = 0;
225
+	Registers.PCw = S9xGetWord(0xfffc);
226
+	OpenBus = Registers.PCh;
227
+	Registers.D.W = 0;
228
+	Registers.DB = 0;
229
+	Registers.SH = 1;
230
+	Registers.SL -= 3;
231
+	Registers.XH = 0;
232
+	Registers.YH = 0;
233
+
234
+	ICPU.ShiftedPB = 0;
235
+	ICPU.ShiftedDB = 0;
236
+	SetFlags(MemoryFlag | IndexFlag | IRQ | Emulation);
237
+	ClearFlags(Decimal);
238
+
239
+	Timings.InterlaceField = false;
240
+	Timings.H_Max = Timings.H_Max_Master;
241
+	Timings.V_Max = Timings.V_Max_Master;
242
+	Timings.NMITriggerPos = 0xffff;
243
+	if (Model->_5A22 == 2)
244
+		Timings.WRAMRefreshPos = SNES_WRAM_REFRESH_HC_v2;
245
+	else
246
+		Timings.WRAMRefreshPos = SNES_WRAM_REFRESH_HC_v1;
247
+
248
+	S9xSetPCBase(Registers.PBPC);
249
+
250
+	ICPU.S9xOpcodes = S9xOpcodesE1;
251
+	ICPU.S9xOpLengths = S9xOpLengthsM1X1;
252
+
253
+	S9xUnpackStatus();
254
+}
255
+
256
+static void S9xResetCPU()
257
+{
258
+	S9xSoftResetCPU();
259
+	Registers.SL = 0xff;
260
+	Registers.P.W = 0;
261
+	Registers.A.W = 0;
262
+	Registers.X.W = 0;
263
+	Registers.Y.W = 0;
264
+	SetFlags(MemoryFlag | IndexFlag | IRQ | Emulation);
265
+	ClearFlags(Decimal);
266
+}
267
+
268
+void S9xReset()
269
+{
270
+	/*S9xResetSaveTimer(false);
271
+	S9xResetLogger();*/
272
+
273
+	memset(Memory.RAM, 0x55, 0x20000);
274
+	memset(Memory.VRAM, 0x00, 0x10000);
275
+	ZeroMemory(Memory.FillRAM, 0x8000);
276
+
277
+	/*if (Settings.BS)
278
+		S9xResetBSX();*/
279
+
280
+	S9xResetCPU();
281
+	S9xResetPPU();
282
+	S9xResetDMA();
283
+	S9xResetAPU();
284
+
285
+	/*if (Settings.DSP)
286
+		S9xResetDSP();
287
+	if (Settings.SuperFX)
288
+		S9xResetSuperFX();
289
+	if (Settings.SA1)
290
+		S9xSA1Init();*/
291
+	if (Settings.SDD1)
292
+		S9xResetSDD1();
293
+	/*if (Settings.SPC7110)
294
+		S9xResetSPC7110();
295
+	if (Settings.C4)
296
+		S9xInitC4();
297
+	if (Settings.OBC1)
298
+		S9xResetOBC1();
299
+	if (Settings.SRTC)
300
+		S9xResetSRTC();
301
+
302
+	S9xInitCheatData();*/
303
+}
304
+
305
+void S9xSoftReset()
306
+{
307
+	//S9xResetSaveTimer(false);
308
+
309
+	ZeroMemory(Memory.FillRAM, 0x8000);
310
+
311
+	/*if (Settings.BS)
312
+		S9xResetBSX();*/
313
+
314
+	S9xSoftResetCPU();
315
+	S9xSoftResetPPU();
316
+	S9xResetDMA();
317
+	S9xSoftResetAPU();
318
+
319
+	/*if (Settings.DSP)
320
+		S9xResetDSP();
321
+	if (Settings.SuperFX)
322
+		S9xResetSuperFX();
323
+	if (Settings.SA1)
324
+		S9xSA1Init();*/
325
+	if (Settings.SDD1)
326
+		S9xResetSDD1();
327
+	/*if (Settings.SPC7110)
328
+		S9xResetSPC7110();
329
+	if (Settings.C4)
330
+		S9xInitC4();
331
+	if (Settings.OBC1)
332
+		S9xResetOBC1();
333
+	if (Settings.SRTC)
334
+		S9xResetSRTC();
335
+
336
+	S9xInitCheatData();*/
337
+}