2 * Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
4 * (c) Copyright 1996 - 2001 Gary Henderson (gary.henderson@ntlworld.com) and
5 * Jerremy Koot (jkoot@snes9x.com)
7 * Super FX C emulator code
8 * (c) Copyright 1997 - 1999 Ivar (ivar@snes9x.com) and
10 * Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_.
12 * DSP1 emulator code (c) Copyright 1998 Ivar, _Demo_ and Gary Henderson.
13 * C4 asm and some C emulation code (c) Copyright 2000 zsKnight and _Demo_.
14 * C4 C code (c) Copyright 2001 Gary Henderson (gary.henderson@ntlworld.com).
16 * DOS port code contains the works of other authors. See headers in
19 * Snes9x homepage: http://www.snes9x.com
21 * Permission to use, copy, modify and distribute Snes9x in both binary and
22 * source form, for non-commercial purposes, is hereby granted without fee,
23 * providing that this license information and copyright notice appear with
24 * all copies and any derived work.
26 * This software is provided 'as-is', without any express or implied
27 * warranty. In no event shall the authors be held liable for any damages
28 * arising from the use of this software.
30 * Snes9x is freeware for PERSONAL USE only. Commercial users should
31 * seek permission of the copyright holders first. Commercial use includes
32 * charging money for Snes9x or software derived from Snes9x.
34 * The copyright holders request that bug fixes and improvements to the code
35 * should be forwarded to them so everyone can benefit from the modifications
38 * Super NES and Super Nintendo Entertainment System are trademarks of
39 * Nintendo Co., Limited and its subsidiary companies.
44 #define VERSION "1.39"
50 #include "..\wsnes9x.h"
51 #include "..\zlib\zlib.h"
58 #if defined(USE_GLIDE) && !defined(GFX_MULTI_FORMAT)
59 #define GFX_MULTI_FORMAT
62 #define ROM_NAME_LEN 23
69 #define READ_STREAM(p,l,s) gzread (s,p,l)
70 #define WRITE_STREAM(p,l,s) gzwrite (s,p,l)
71 #define OPEN_STREAM(f,m) gzopen (f,m)
72 #define CLOSE_STREAM(s) gzclose (s)
73 #define SEEK_STREAM(p,r,s) gzseek(s,p,r)
76 #define STREAM long * //F_HANDLE *
77 #define READ_STREAM(p,l,s) gp32_fread ((unsigned char*)p,(long)l,s)
78 #define WRITE_STREAM(p,l,s) gp32_fwrite ((unsigned char*)p,(long)l,s)
79 #define OPEN_STREAM(f,m) gp32_fopen ((char*)f,(char*)m)
80 #define CLOSE_STREAM(s) gp32_fclose (s)
81 #define SEEK_STREAM(p,r,s) gp32_fseek(p,r,s)
85 #define READ_STREAM(p,l,s) fread (p,1,l,s)
86 #define WRITE_STREAM(p,l,s) fwrite (p,1,l,s)
87 #define OPEN_STREAM(f,m) fopen (f,m)
88 #define CLOSE_STREAM(s) fclose (s)
89 #define SEEK_STREAM(p,r,s) fseek(s,p,r)
90 #define FROM_CURRENT SEEK_CUR
95 /* SNES screen width and height */
96 #define SNES_WIDTH 256
97 #define SNES_HEIGHT 224
98 #define SNES_HEIGHT_EXTENDED 239
99 #define IMAGE_WIDTH (Settings.SupportHiRes ? SNES_WIDTH * 2 : SNES_WIDTH)
100 #define IMAGE_HEIGHT (Settings.SupportHiRes ? SNES_HEIGHT_EXTENDED * 2 : SNES_HEIGHT_EXTENDED)
102 #define SNES_MAX_NTSC_VCOUNTER 262
103 #define SNES_MAX_PAL_VCOUNTER 312
104 #define SNES_HCOUNTER_MAX 342
105 #define SPC700_TO_65C816_RATIO 2
106 #define AUTO_FRAMERATE 200
108 #define PPU_IGNORE_FIXEDCOLCHANGES (1<<0)
109 #define PPU_IGNORE_WINDOW (1<<1)
110 #define PPU_IGNORE_ADDSUB (1<<2)
111 #define PPU_IGNORE_PALWRITE (1<<3)
112 #define GFX_IGNORE_OBJ (1<<4)
113 #define GFX_IGNORE_BG0 (1<<5)
114 #define GFX_IGNORE_BG1 (1<<6)
115 #define GFX_IGNORE_BG2 (1<<7)
116 #define GFX_IGNORE_BG3 (1<<8)
118 // NTSC master clock signal 21.47727MHz
119 // PPU: master clock / 4
120 // 1 / PPU clock * 342 -> 63.695us
121 // 63.695us / (1 / 3.579545MHz) -> 228 cycles per scanline
122 // From Earth Worm Jim: APU executes an average of 65.14285714 cycles per
123 // scanline giving an APU clock speed of 1.022731096MHz
125 // PAL master clock signal 21.28137MHz
126 // PPU: master clock / 4
127 // 1 / PPU clock * 342 -> 64.281us
128 // 64.281us / (1 / 3.546895MHz) -> 228 cycles per scanline.
130 //#define SNES_SCANLINE_TIME (63.695e-6)
131 //#define SNES_CLOCK_SPEED (3579545)
133 //#define SNES_CLOCK_LEN (1.0 / SNES_CLOCK_SPEED)
136 //#define SNES_CYCLES_PER_SCANLINE ((uint32) ((SNES_SCANLINE_TIME / SNES_CLOCK_LEN) * 6 + 0.5))
137 #define SNES_CYCLES_PER_SCANLINE ((uint32)(228*6))
139 #define SNES_CYCLES_PER_SCANLINE ((uint32) (SNES_SCANLINE_TIME / SNES_CLOCK_LEN + 0.5))
142 #define SNES_TR_MASK (1 << 4)
143 #define SNES_TL_MASK (1 << 5)
144 #define SNES_X_MASK (1 << 6)
145 #define SNES_A_MASK (1 << 7)
146 #define SNES_RIGHT_MASK (1 << 8)
147 #define SNES_LEFT_MASK (1 << 9)
148 #define SNES_DOWN_MASK (1 << 10)
149 #define SNES_UP_MASK (1 << 11)
150 #define SNES_START_MASK (1 << 12)
151 #define SNES_SELECT_MASK (1 << 13)
152 #define SNES_Y_MASK (1 << 14)
153 #define SNES_B_MASK (1 << 15)
163 SNES_MAX_CONTROLLER_OPTIONS
166 #define DEBUG_MODE_FLAG (1 << 0)
167 #define TRACE_FLAG (1 << 1)
168 #define SINGLE_STEP_FLAG (1 << 2)
169 #define BREAK_FLAG (1 << 3)
170 #define SCAN_KEYS_FLAG (1 << 4)
171 #define SAVE_SNAPSHOT_FLAG (1 << 5)
172 #define DELAYED_NMI_FLAG (1 << 6)
173 #define NMI_FLAG (1 << 7)
174 #define PROCESS_SOUND_FLAG (1 << 8)
175 #define FRAME_ADVANCE_FLAG (1 << 9)
176 #define DELAYED_NMI_FLAG2 (1 << 10)
177 #define IRQ_PENDING_FLAG (1 << 11)
181 #define SLOW_ONE_CYCLE 8
182 #define TWO_CYCLES 12
185 #define SLOW_ONE_CYCLE 1
190 #undef MEMMAP_BLOCK_SIZE
191 #define MEMMAP_BLOCK_SIZE (0x1000)
192 #undef MEMMAP_NUM_BLOCKS
193 #define MEMMAP_NUM_BLOCKS (0x1000000 / MEMMAP_BLOCK_SIZE)
197 bool8 BranchSkip; //4
200 bool8 WaitingForInterrupt; //7
201 struct SRegisters Regs; //8
214 uint8 *PCAtOpcodeStart; //36
215 uint8 *WaitAddress; //40
216 uint32 WaitCounter; //44
217 int32 NextEvent; //48
218 int32 V_Counter; //52
220 int32 MemSpeedx2; //60
221 int32 FastROMSpeed; //64
222 uint32 AutoSaveTimer; //68
223 uint32 NMITriggerPoint; //72
224 uint32 NMICycleCount; //76
225 uint32 IRQCycleCount; //80
228 uint8 WhichEvent; //85
229 bool8 SRAMModified; //86
230 bool8 BRKTriggered; //87
231 uint32 _ARM_asm_reserved_1; //88 to stock current jmp table
232 bool8 TriedInterleavedMode2; //92
233 bool8 _ARM_asm_padding1[3]; //93
235 uint8* Memory_Map; //96
236 uint8* Memory_WriteMap; //100
237 uint8* Memory_MemorySpeed; //104
238 uint8* Memory_BlockIsRAM; //108
239 uint8* Memory_SRAM; //112
240 uint8* Memory_BWRAM; //116
241 uint16 Memory_SRAMMask; //120
242 bool8 APU_APUExecuting; //122
243 bool8 _ARM_asm_padding2; //123
244 uint32 _PALMSOS_R9; //124
245 uint32 _PALMSOS_R10; //128
246 int32 APU_Cycles; //132 notaz
250 #define HBLANK_START_EVENT 0
251 #define HBLANK_END_EVENT 1
252 #define HTIMER_BEFORE_EVENT 2
253 #define HTIMER_AFTER_EVENT 3
260 uint8 SoundSkipMethod;
263 long CyclesPercentage;
273 bool8 TraceUnknownRegisters;
278 bool8 JoystickEnabled;
280 // ROM timing options (see also H_Max above)
285 uint32 FrameTimeNTSC;
294 bool8 ForceInterleaved;
295 bool8 ForceInterleaved2;
296 bool8 ForceNotInterleaved;
298 // Peripherial options
300 bool8 ForceNoSuperFX;
313 uint32 ControllerOption;
315 bool8 ShutdownMaster;
316 bool8 MultiPlayer5Master;
317 bool8 SuperScopeMaster;
326 uint32 SoundPlaybackRate;
330 bool8 SixteenBitSound;
332 int SoundMixInterval;
333 bool8 SoundEnvelopeHeightReading;
334 bool8 DisableSoundEcho;
335 bool8 DisableSampleCaching;
336 bool8 DisableMasterVolume;
338 bool8 InterpolatedSound;
341 // bool8 NextAPUEnabled;
342 uint8 AltSampleDecode;
349 bool8 Mode7Interpolate;
351 // SNES graphics options
353 bool8 DisableGraphicWindows;
354 bool8 ForceTransparency;
355 bool8 ForceNoTransparency;
357 bool8 DisplayFrameRate;
362 char ServerName [128];
366 int32 AutoSaveDelay; // Time in seconds before S-RAM auto-saved if modified.
369 uint32 TurboSkipFrames;
370 uint32 AutoMaxSkipFrames;
373 // Fixes for individual games
374 uint32 StrikeGunnerOffsetHack;
379 bool8 WrestlemaniaArcade;
380 bool8 BS; // Japanese Satellite System games.
382 uint8 APURAMInitialValue;
392 struct SSNESGameFixes
394 uint8 NeedInit0x2137;
395 uint8 umiharakawaseFix;
396 uint8 alienVSpredetorFix;
397 uint8 APU_OutPorts_ReturnValueFix;
398 uint8 Old_Read0x4200;
399 uint8 _0x213E_ReturnValue;
400 uint8 TouhaidenControllerFix;
401 uint8 SoundEnvelopeHeightReading2;
402 uint8 SRAMInitialValue;
406 extern struct SSettings Settings;
407 extern struct SCPUState CPU;
408 extern struct SSNESGameFixes SNESGameFixes;
409 extern char String [513];
412 void S9xMessage (int type, int number, const char *message);
413 void S9xLoadSDD1Data ();
417 PAUSE_NETPLAY_CONNECT = (1 << 0),
418 PAUSE_TOGGLE_FULL_SCREEN = (1 << 1),
419 PAUSE_EXIT = (1 << 2),
420 PAUSE_MENU = (1 << 3),
421 PAUSE_INACTIVE_WINDOW = (1 << 4),
422 PAUSE_WINDOW_ICONISED = (1 << 5),
423 PAUSE_RESTORE_GUI = (1 << 6),
424 PAUSE_FREEZE_FILE = (1 << 7)
426 void S9xSetPause (uint32 mask);
427 void S9xClearPause (uint32 mask);