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"
52 #if defined(USE_GLIDE) && !defined(GFX_MULTI_FORMAT)
53 #define GFX_MULTI_FORMAT
56 #define ROM_NAME_LEN 23
59 #define READ_STREAM(p,l,s) fread (p,1,l,s)
60 #define WRITE_STREAM(p,l,s) fwrite (p,1,l,s)
61 #define OPEN_STREAM(f,m) fopen (f,m)
62 #define CLOSE_STREAM(s) fclose (s)
63 #define SEEK_STREAM(p,r,s) fseek(s,p,r)
64 #define FROM_CURRENT SEEK_CUR
66 /* SNES screen width and height */
67 #define SNES_WIDTH 256
68 #define SNES_HEIGHT 224
69 #define SNES_HEIGHT_EXTENDED 239
70 #define IMAGE_WIDTH (Settings.SupportHiRes ? SNES_WIDTH * 2 : SNES_WIDTH)
71 #define IMAGE_HEIGHT (Settings.SupportHiRes ? SNES_HEIGHT_EXTENDED * 2 : SNES_HEIGHT_EXTENDED)
73 #define SNES_MAX_NTSC_VCOUNTER 262
74 #define SNES_MAX_PAL_VCOUNTER 312
75 #define SNES_HCOUNTER_MAX 342
76 #define SPC700_TO_65C816_RATIO 2
77 #define AUTO_FRAMERATE 200
79 #define PPU_IGNORE_FIXEDCOLCHANGES (1<<0)
80 #define PPU_IGNORE_WINDOW (1<<1)
81 #define PPU_IGNORE_ADDSUB (1<<2)
82 #define PPU_IGNORE_PALWRITE (1<<3)
83 #define GFX_IGNORE_OBJ (1<<4)
84 #define GFX_IGNORE_BG0 (1<<5)
85 #define GFX_IGNORE_BG1 (1<<6)
86 #define GFX_IGNORE_BG2 (1<<7)
87 #define GFX_IGNORE_BG3 (1<<8)
89 // NTSC master clock signal 21.47727MHz
90 // PPU: master clock / 4
91 // 1 / PPU clock * 342 -> 63.695us
92 // 63.695us / (1 / 3.579545MHz) -> 228 cycles per scanline
93 // From Earth Worm Jim: APU executes an average of 65.14285714 cycles per
94 // scanline giving an APU clock speed of 1.022731096MHz
96 // PAL master clock signal 21.28137MHz
97 // PPU: master clock / 4
98 // 1 / PPU clock * 342 -> 64.281us
99 // 64.281us / (1 / 3.546895MHz) -> 228 cycles per scanline.
101 //#define SNES_SCANLINE_TIME (63.695e-6)
102 //#define SNES_CLOCK_SPEED (3579545)
104 //#define SNES_CLOCK_LEN (1.0 / SNES_CLOCK_SPEED)
107 //#define SNES_CYCLES_PER_SCANLINE ((uint32) ((SNES_SCANLINE_TIME / SNES_CLOCK_LEN) * 6 + 0.5))
108 #define SNES_CYCLES_PER_SCANLINE ((uint32)(228*6))
110 #define SNES_CYCLES_PER_SCANLINE ((uint32) (SNES_SCANLINE_TIME / SNES_CLOCK_LEN + 0.5))
113 #define SNES_TR_MASK (1 << 4)
114 #define SNES_TL_MASK (1 << 5)
115 #define SNES_X_MASK (1 << 6)
116 #define SNES_A_MASK (1 << 7)
117 #define SNES_RIGHT_MASK (1 << 8)
118 #define SNES_LEFT_MASK (1 << 9)
119 #define SNES_DOWN_MASK (1 << 10)
120 #define SNES_UP_MASK (1 << 11)
121 #define SNES_START_MASK (1 << 12)
122 #define SNES_SELECT_MASK (1 << 13)
123 #define SNES_Y_MASK (1 << 14)
124 #define SNES_B_MASK (1 << 15)
134 SNES_MAX_CONTROLLER_OPTIONS
137 #define DEBUG_MODE_FLAG (1 << 0)
138 #define TRACE_FLAG (1 << 1)
139 #define SINGLE_STEP_FLAG (1 << 2)
140 #define BREAK_FLAG (1 << 3)
141 #define SCAN_KEYS_FLAG (1 << 4)
142 #define SAVE_SNAPSHOT_FLAG (1 << 5)
143 #define DELAYED_NMI_FLAG (1 << 6)
144 #define NMI_FLAG (1 << 7)
145 #define PROCESS_SOUND_FLAG (1 << 8)
146 #define FRAME_ADVANCE_FLAG (1 << 9)
147 #define DELAYED_NMI_FLAG2 (1 << 10)
148 #define IRQ_PENDING_FLAG (1 << 11)
152 #define SLOW_ONE_CYCLE 8
153 #define TWO_CYCLES 12
156 #define SLOW_ONE_CYCLE 1
161 #undef MEMMAP_BLOCK_SIZE
162 #define MEMMAP_BLOCK_SIZE (0x1000)
163 #undef MEMMAP_NUM_BLOCKS
164 #define MEMMAP_NUM_BLOCKS (0x1000000 / MEMMAP_BLOCK_SIZE)
168 bool8 BranchSkip; //4
171 bool8 WaitingForInterrupt; //7
172 struct SRegisters Regs; //8
185 uint8 *PCAtOpcodeStart; //36
186 uint8 *WaitAddress; //40
187 uint32 WaitCounter; //44
188 int32 NextEvent; //48
189 int32 V_Counter; //52
191 int32 MemSpeedx2; //60
192 int32 FastROMSpeed; //64
193 uint32 AutoSaveTimer; //68
194 uint32 NMITriggerPoint; //72
195 uint32 NMICycleCount; //76
196 uint32 IRQCycleCount; //80
199 uint8 WhichEvent; //85
200 bool8 SRAMModified; //86
201 bool8 BRKTriggered; //87
202 uint32 _ARM_asm_reserved_1; //88 to stock current jmp table
203 bool8 TriedInterleavedMode2; //92
204 bool8 _ARM_asm_padding1[3]; //93
206 uint8* Memory_Map; //96
207 uint8* Memory_WriteMap; //100
208 uint8* Memory_MemorySpeed; //104
209 uint8* Memory_BlockIsRAM; //108
210 uint8* Memory_SRAM; //112
211 uint8* Memory_BWRAM; //116
212 uint16 Memory_SRAMMask; //120
213 bool8 APU_APUExecuting; //122
214 bool8 _ARM_asm_padding2; //123
215 int32 APU_Cycles; //124 notaz
219 #define HBLANK_START_EVENT 0
220 #define HBLANK_END_EVENT 1
221 #define HTIMER_BEFORE_EVENT 2
222 #define HTIMER_AFTER_EVENT 3
229 uint8 SoundSkipMethod;
232 long CyclesPercentage;
242 bool8 TraceUnknownRegisters;
247 bool8 JoystickEnabled;
249 // ROM timing options (see also H_Max above)
254 uint32 FrameTimeNTSC;
263 bool8 ForceInterleaved;
264 bool8 ForceInterleaved2;
265 bool8 ForceNotInterleaved;
267 // Peripherial options
269 bool8 ForceNoSuperFX;
282 uint32 ControllerOption;
284 bool8 ShutdownMaster;
285 bool8 MultiPlayer5Master;
286 bool8 SuperScopeMaster;
295 uint32 SoundPlaybackRate;
299 bool8 SixteenBitSound;
301 int SoundMixInterval;
302 bool8 SoundEnvelopeHeightReading;
303 bool8 DisableSoundEcho;
304 bool8 DisableSampleCaching;
305 bool8 DisableMasterVolume;
307 bool8 InterpolatedSound;
310 // bool8 NextAPUEnabled;
311 uint8 AltSampleDecode;
318 bool8 Mode7Interpolate;
320 // SNES graphics options
322 bool8 DisableGraphicWindows;
323 bool8 ForceTransparency;
324 bool8 ForceNoTransparency;
326 bool8 DisplayFrameRate;
331 char ServerName [128];
335 int32 AutoSaveDelay; // Time in seconds before S-RAM auto-saved if modified.
338 uint32 TurboSkipFrames;
339 uint32 AutoMaxSkipFrames;
342 // Fixes for individual games
343 uint32 StrikeGunnerOffsetHack;
348 bool8 WrestlemaniaArcade;
349 bool8 BS; // Japanese Satellite System games.
351 uint8 APURAMInitialValue;
362 struct SSNESGameFixes
364 uint8 NeedInit0x2137;
365 uint8 umiharakawaseFix;
366 uint8 alienVSpredetorFix;
367 uint8 APU_OutPorts_ReturnValueFix;
368 uint8 Old_Read0x4200;
369 uint8 _0x213E_ReturnValue;
370 uint8 TouhaidenControllerFix;
371 uint8 SoundEnvelopeHeightReading2;
372 uint8 SRAMInitialValue;
376 extern struct SSettings Settings;
377 extern struct SCPUState CPU;
378 extern struct SSNESGameFixes SNESGameFixes;
379 extern char String [513];
382 void S9xMessage (int type, int number, const char *message);
383 void S9xLoadSDD1Data ();
388 PAUSE_NETPLAY_CONNECT = (1 << 0),
389 PAUSE_TOGGLE_FULL_SCREEN = (1 << 1),
390 PAUSE_EXIT = (1 << 2),
391 PAUSE_MENU = (1 << 3),
392 PAUSE_INACTIVE_WINDOW = (1 << 4),
393 PAUSE_WINDOW_ICONISED = (1 << 5),
394 PAUSE_RESTORE_GUI = (1 << 6),
395 PAUSE_FREEZE_FILE = (1 << 7)
397 void S9xSetPause (uint32 mask);
398 void S9xClearPause (uint32 mask);
405 /** The default freeze filename (base.frz.gz) */
412 /** This routine allows to get path to files whose name depends on the basename
413 * of the current ROM.
414 * Note that FILE_FREEZE is currently not implemented here.
415 * @param file see enum FileTypes.
416 * @return wanted filepath. Do not free the returned string.
418 const char *S9xGetFilename(enum FileTypes file);