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
58 /* SNES screen width and height */
59 #define SNES_WIDTH 256
60 #define SNES_HEIGHT 224
61 #define SNES_HEIGHT_EXTENDED 239
62 #define IMAGE_WIDTH (Settings.SupportHiRes ? SNES_WIDTH * 2 : SNES_WIDTH)
63 #define IMAGE_HEIGHT (Settings.SupportHiRes ? SNES_HEIGHT_EXTENDED * 2 : SNES_HEIGHT_EXTENDED)
65 #define SNES_MAX_NTSC_VCOUNTER 262
66 #define SNES_MAX_PAL_VCOUNTER 312
67 #define SNES_HCOUNTER_MAX 342
68 #define SPC700_TO_65C816_RATIO 2
69 #define AUTO_FRAMERATE 200
71 #define PPU_IGNORE_FIXEDCOLCHANGES (1<<0)
72 #define PPU_IGNORE_WINDOW (1<<1)
73 #define PPU_IGNORE_ADDSUB (1<<2)
74 #define PPU_IGNORE_PALWRITE (1<<3)
75 #define GFX_IGNORE_OBJ (1<<4)
76 #define GFX_IGNORE_BG0 (1<<5)
77 #define GFX_IGNORE_BG1 (1<<6)
78 #define GFX_IGNORE_BG2 (1<<7)
79 #define GFX_IGNORE_BG3 (1<<8)
81 // NTSC master clock signal 21.47727MHz
82 // PPU: master clock / 4
83 // 1 / PPU clock * 342 -> 63.695us
84 // 63.695us / (1 / 3.579545MHz) -> 228 cycles per scanline
85 // From Earth Worm Jim: APU executes an average of 65.14285714 cycles per
86 // scanline giving an APU clock speed of 1.022731096MHz
88 // PAL master clock signal 21.28137MHz
89 // PPU: master clock / 4
90 // 1 / PPU clock * 342 -> 64.281us
91 // 64.281us / (1 / 3.546895MHz) -> 228 cycles per scanline.
93 //#define SNES_SCANLINE_TIME (63.695e-6)
94 //#define SNES_CLOCK_SPEED (3579545)
96 //#define SNES_CLOCK_LEN (1.0 / SNES_CLOCK_SPEED)
99 //#define SNES_CYCLES_PER_SCANLINE ((uint32) ((SNES_SCANLINE_TIME / SNES_CLOCK_LEN) * 6 + 0.5))
100 #define SNES_CYCLES_PER_SCANLINE ((uint32)(228*6))
102 #define SNES_CYCLES_PER_SCANLINE ((uint32) (SNES_SCANLINE_TIME / SNES_CLOCK_LEN + 0.5))
105 #define SNES_TR_MASK (1 << 4)
106 #define SNES_TL_MASK (1 << 5)
107 #define SNES_X_MASK (1 << 6)
108 #define SNES_A_MASK (1 << 7)
109 #define SNES_RIGHT_MASK (1 << 8)
110 #define SNES_LEFT_MASK (1 << 9)
111 #define SNES_DOWN_MASK (1 << 10)
112 #define SNES_UP_MASK (1 << 11)
113 #define SNES_START_MASK (1 << 12)
114 #define SNES_SELECT_MASK (1 << 13)
115 #define SNES_Y_MASK (1 << 14)
116 #define SNES_B_MASK (1 << 15)
126 SNES_MAX_CONTROLLER_OPTIONS
129 #define DEBUG_MODE_FLAG (1 << 0)
130 #define TRACE_FLAG (1 << 1)
131 #define SINGLE_STEP_FLAG (1 << 2)
132 #define BREAK_FLAG (1 << 3)
133 #define SCAN_KEYS_FLAG (1 << 4)
134 #define SAVE_SNAPSHOT_FLAG (1 << 5)
135 #define DELAYED_NMI_FLAG (1 << 6)
136 #define NMI_FLAG (1 << 7)
137 #define PROCESS_SOUND_FLAG (1 << 8)
138 #define FRAME_ADVANCE_FLAG (1 << 9)
139 #define DELAYED_NMI_FLAG2 (1 << 10)
140 #define IRQ_PENDING_FLAG (1 << 11)
144 #define SLOW_ONE_CYCLE 8
145 #define TWO_CYCLES 12
148 #define SLOW_ONE_CYCLE 1
153 #undef MEMMAP_BLOCK_SIZE
154 #define MEMMAP_BLOCK_SIZE (0x1000)
155 #undef MEMMAP_NUM_BLOCKS
156 #define MEMMAP_NUM_BLOCKS (0x1000000 / MEMMAP_BLOCK_SIZE)
160 bool8 BranchSkip; //4
163 bool8 WaitingForInterrupt; //7
164 struct SRegisters Regs; //8
177 uint8 *PCAtOpcodeStart; //36
178 uint8 *WaitAddress; //40
179 uint32 WaitCounter; //44
180 int32 NextEvent; //48
181 int32 V_Counter; //52
183 int32 MemSpeedx2; //60
184 int32 FastROMSpeed; //64
185 uint32 AutoSaveTimer; //68
186 uint32 NMITriggerPoint; //72
187 uint32 NMICycleCount; //76
188 uint32 IRQCycleCount; //80
191 uint8 WhichEvent; //85
192 bool8 SRAMModified; //86
193 bool8 BRKTriggered; //87
194 uint32 _ARM_asm_reserved_1; //88 to stock current jmp table
195 bool8 TriedInterleavedMode2; //92
196 bool8 _ARM_asm_padding1[3]; //93
198 uint8* Memory_Map; //96
199 uint8* Memory_WriteMap; //100
200 uint8* Memory_MemorySpeed; //104
201 uint8* Memory_BlockIsRAM; //108
202 uint8* Memory_SRAM; //112
203 uint8* Memory_BWRAM; //116
204 uint16 Memory_SRAMMask; //120
205 bool8 APU_APUExecuting; //122
206 bool8 _ARM_asm_padding2; //123
207 int32 APU_Cycles; //124 notaz
211 #define HBLANK_START_EVENT 0
212 #define HBLANK_END_EVENT 1
213 #define HTIMER_BEFORE_EVENT 2
214 #define HTIMER_AFTER_EVENT 3
221 uint8 SoundSkipMethod;
224 long CyclesPercentage;
234 bool8 TraceUnknownRegisters;
239 bool8 JoystickEnabled;
241 // ROM timing options (see also H_Max above)
246 uint32 FrameTimeNTSC;
255 bool8 ForceInterleaved;
256 bool8 ForceInterleaved2;
257 bool8 ForceNotInterleaved;
259 // Peripherial options
261 bool8 ForceNoSuperFX;
274 uint32 ControllerOption;
276 bool8 ShutdownMaster;
277 bool8 MultiPlayer5Master;
278 bool8 SuperScopeMaster;
287 uint32 SoundPlaybackRate;
291 bool8 SixteenBitSound;
293 int SoundMixInterval;
294 bool8 SoundEnvelopeHeightReading;
295 bool8 DisableSoundEcho;
296 bool8 DisableSampleCaching;
297 bool8 DisableMasterVolume;
299 bool8 InterpolatedSound;
302 // bool8 NextAPUEnabled;
303 uint8 AltSampleDecode;
310 bool8 Mode7Interpolate;
312 // SNES graphics options
314 bool8 DisableGraphicWindows;
315 bool8 ForceTransparency;
316 bool8 ForceNoTransparency;
318 bool8 DisplayFrameRate;
323 char ServerName [128];
327 int32 AutoSaveDelay; // Time in seconds before S-RAM auto-saved if modified.
330 uint32 TurboSkipFrames;
331 uint32 AutoMaxSkipFrames;
334 // Fixes for individual games
335 uint32 StrikeGunnerOffsetHack;
340 bool8 WrestlemaniaArcade;
341 bool8 BS; // Japanese Satellite System games.
343 uint8 APURAMInitialValue;
354 struct SSNESGameFixes
356 uint8 NeedInit0x2137;
357 uint8 umiharakawaseFix;
358 uint8 alienVSpredetorFix;
359 uint8 APU_OutPorts_ReturnValueFix;
360 uint8 Old_Read0x4200;
361 uint8 _0x213E_ReturnValue;
362 uint8 TouhaidenControllerFix;
363 uint8 SoundEnvelopeHeightReading2;
364 uint8 SRAMInitialValue;
368 extern struct SSettings Settings;
369 extern struct SCPUState CPU;
370 extern struct SSNESGameFixes SNESGameFixes;
371 extern char String [513];
374 void S9xMessage (int type, int number, const char *message);
375 void S9xLoadSDD1Data ();
380 PAUSE_NETPLAY_CONNECT = (1 << 0),
381 PAUSE_TOGGLE_FULL_SCREEN = (1 << 1),
382 PAUSE_EXIT = (1 << 2),
383 PAUSE_MENU = (1 << 3),
384 PAUSE_INACTIVE_WINDOW = (1 << 4),
385 PAUSE_WINDOW_ICONISED = (1 << 5),
386 PAUSE_RESTORE_GUI = (1 << 6),
387 PAUSE_FREEZE_FILE = (1 << 7)
389 void S9xSetPause (uint32 mask);
390 void S9xClearPause (uint32 mask);
397 /** The default freeze filename (base.frz.gz) */
404 /** This routine allows to get path to files whose name depends on the basename
405 * of the current ROM.
406 * @param file see enum FileTypes.
407 * @return wanted filepath. Do not free the returned string.
409 const char *S9xGetFilename(enum FileTypes file);
410 /** Returns the path to freeze file for the selected quick save slot.
411 * @param slot slot number
412 * @return wanted filepath. Do not free the returned string.
414 const char *S9xGetQuickSaveFilename(unsigned int slot);