minor filename fixes
[drnoksnes] / snes9x.h
1 /*
2  * Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
3  *
4  * (c) Copyright 1996 - 2001 Gary Henderson (gary.henderson@ntlworld.com) and
5  *                           Jerremy Koot (jkoot@snes9x.com)
6  *
7  * Super FX C emulator code 
8  * (c) Copyright 1997 - 1999 Ivar (ivar@snes9x.com) and
9  *                           Gary Henderson.
10  * Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_.
11  *
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).
15  *
16  * DOS port code contains the works of other authors. See headers in
17  * individual files.
18  *
19  * Snes9x homepage: http://www.snes9x.com
20  *
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.
25  *
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.
29  *
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.
33  *
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
36  * in future versions.
37  *
38  * Super NES and Super Nintendo Entertainment System are trademarks of
39  * Nintendo Co., Limited and its subsidiary companies.
40  */
41 #ifndef _SNES9X_H_
42 #define _SNES9X_H_
43
44 #define VERSION "1.39"
45
46 #include <stdio.h>
47 #include <stdlib.h>
48 #include "port.h"
49 #include "65c816.h"
50 #include "messages.h"
51
52 #if defined(USE_GLIDE) && !defined(GFX_MULTI_FORMAT)
53 #define GFX_MULTI_FORMAT
54 #endif
55
56 #define ROM_NAME_LEN 23
57
58 #define STREAM FILE *
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
65
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)
72
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
78
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)
88
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
95
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.
100
101 //#define SNES_SCANLINE_TIME (63.695e-6)
102 //#define SNES_CLOCK_SPEED (3579545)
103
104 //#define SNES_CLOCK_LEN (1.0 / SNES_CLOCK_SPEED)
105
106 #ifdef VAR_CYCLES
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))
109 #else
110 #define SNES_CYCLES_PER_SCANLINE ((uint32) (SNES_SCANLINE_TIME / SNES_CLOCK_LEN + 0.5))
111 #endif
112
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)
125
126 enum {
127     SNES_MULTIPLAYER5,
128     SNES_JOYPAD,
129     SNES_MOUSE_SWAPPED,
130     SNES_MOUSE,
131     SNES_SUPERSCOPE,
132         SNES_JUSTIFIER,
133         SNES_JUSTIFIER_2,
134     SNES_MAX_CONTROLLER_OPTIONS
135 };
136
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)
149
150 #ifdef VAR_CYCLES
151 #define ONE_CYCLE 6
152 #define SLOW_ONE_CYCLE 8
153 #define TWO_CYCLES 12
154 #else
155 #define ONE_CYCLE 1
156 #define SLOW_ONE_CYCLE 1
157 #define TWO_CYCLES 2
158 #endif
159
160
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)
165
166 struct SCPUState{
167     uint32  Flags;                                      //0
168     bool8   BranchSkip;                         //4
169     bool8   NMIActive;                          //5
170     bool8   IRQActive;                          //6
171     bool8   WaitingForInterrupt;        //7
172     struct SRegisters Regs;                     //8
173                 //uint8  PB;                            //8
174                 //uint8  DB;                            //9
175                 //pair   P;                                     //10
176                 //pair   A;                                     //12
177                 //pair   D;                                     //14
178                 //pair   X;                                     //16
179                 //pair   S;                                     //18
180                 //pair   Y;                                     //20
181             //uint16 PC;                                //22
182     uint8   *PC;                                        //24
183     int32   Cycles;                                     //28
184     uint8   *PCBase;                            //32
185     uint8   *PCAtOpcodeStart;           //36
186     uint8   *WaitAddress;                       //40
187     uint32  WaitCounter;                        //44
188     int32   NextEvent;                          //48
189     int32   V_Counter;                          //52
190     int32   MemSpeed;                           //56
191     int32   MemSpeedx2;                         //60
192         int32   FastROMSpeed;                   //64
193     uint32 AutoSaveTimer;               //68
194     uint32 NMITriggerPoint;             //72
195     uint32 NMICycleCount;                       //76
196     uint32 IRQCycleCount;                       //80
197
198     bool8   InDMA;                                      //84
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
205     
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
216 };
217
218
219 #define HBLANK_START_EVENT 0
220 #define HBLANK_END_EVENT 1
221 #define HTIMER_BEFORE_EVENT 2
222 #define HTIMER_AFTER_EVENT 3
223 #define NO_EVENT 4
224
225 struct SSettings{
226     // CPU options
227     bool8  APUEnabled;
228     bool8  Shutdown;
229     uint8  SoundSkipMethod;
230     long   H_Max;
231     long   HBlankStart;
232     long   CyclesPercentage;
233     bool8  DisableIRQ;
234     bool8  Paused;
235     bool8  ForcedPause;
236     bool8  StopEmulation;
237
238     // Tracing options
239     bool8  TraceDMA;
240     bool8  TraceHDMA;
241     bool8  TraceVRAM;
242     bool8  TraceUnknownRegisters;
243     bool8  TraceDSP;
244
245     // Joystick options
246     bool8  SwapJoypads;
247     bool8  JoystickEnabled;
248
249     // ROM timing options (see also H_Max above)
250     bool8  ForcePAL;
251     bool8  ForceNTSC;
252     bool8  PAL;
253     uint32 FrameTimePAL;
254     uint32 FrameTimeNTSC;
255     uint32 FrameTime;
256     uint32 SkipFrames;
257
258     // ROM image options
259     bool8  ForceLoROM;
260     bool8  ForceHiROM;
261     bool8  ForceHeader;
262     bool8  ForceNoHeader;
263     bool8  ForceInterleaved;
264     bool8  ForceInterleaved2;
265     bool8  ForceNotInterleaved;
266
267     // Peripherial options
268     bool8  ForceSuperFX;
269     bool8  ForceNoSuperFX;
270     bool8  ForceDSP1;
271     bool8  ForceNoDSP1;
272     bool8  ForceSA1;
273     bool8  ForceNoSA1;
274     bool8  ForceC4;
275     bool8  ForceNoC4;
276     bool8  ForceSDD1;
277     bool8  ForceNoSDD1;
278     bool8  MultiPlayer5;
279     bool8  Mouse;
280     bool8  SuperScope;
281     bool8  SRTC;
282     uint32 ControllerOption;
283     
284     bool8  ShutdownMaster;
285     bool8  MultiPlayer5Master;
286     bool8  SuperScopeMaster;
287     bool8  MouseMaster;
288     bool8  SuperFX;
289     bool8  DSP1Master;
290     bool8  SA1;
291     bool8  C4;
292     bool8  SDD1;
293
294     // Sound options
295     uint32 SoundPlaybackRate;
296     bool8  TraceSoundDSP;
297     bool8  Stereo;
298     bool8  ReverseStereo;
299     bool8  SixteenBitSound;
300     int    SoundBufferSize;
301     int    SoundMixInterval;
302     bool8  SoundEnvelopeHeightReading;
303     bool8  DisableSoundEcho;
304     bool8  DisableSampleCaching;
305     bool8  DisableMasterVolume;
306     bool8  SoundSync;
307     bool8  InterpolatedSound;
308     bool8  ThreadSound;
309     bool8  Mute;
310 //    bool8  NextAPUEnabled;
311     uint8  AltSampleDecode;
312     bool8  FixFrequency;
313     
314     // Graphics options
315     bool8  SixteenBit;
316     bool8  Transparency;
317     bool8  SupportHiRes;
318     bool8  Mode7Interpolate;
319
320     // SNES graphics options
321     bool8  BGLayering;
322     bool8  DisableGraphicWindows;
323     bool8  ForceTransparency;
324     bool8  ForceNoTransparency;
325     bool8  DisableHDMA;
326     bool8  DisplayFrameRate;
327
328     // Others
329     bool8  NetPlay;
330     bool8  NetPlayServer;
331     char   ServerName [128];
332     int    Port;
333     bool8  GlideEnable;
334     bool8  OpenGLEnable;
335     int32  AutoSaveDelay; // Time in seconds before S-RAM auto-saved if modified.
336     bool8  ApplyCheats;
337     bool8  TurboMode;
338     uint32 TurboSkipFrames;
339     uint32 AutoMaxSkipFrames;
340         uint32 os9x_hack;
341     
342 // Fixes for individual games
343     uint32 StrikeGunnerOffsetHack;
344     bool8  ChuckRock;
345     bool8  StarfoxHack;
346     bool8  WinterGold;
347     bool8  Dezaemon;
348     bool8  WrestlemaniaArcade;
349     bool8  BS;  // Japanese Satellite System games.
350     bool8  DaffyDuck;
351     uint8  APURAMInitialValue;
352     bool8  SDD1Pack;
353     
354         // notaz
355         uint32 GfxLayerMask;
356
357 // Hacks
358         bool8   HacksEnabled;
359         bool8   HacksFilter;
360 };
361
362 struct SSNESGameFixes
363 {
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;
373 };
374
375 START_EXTERN_C
376 extern struct SSettings Settings;
377 extern struct SCPUState CPU;
378 extern struct SSNESGameFixes SNESGameFixes;
379 extern char String [513];
380
381 void S9xExit ();
382 void S9xMessage (int type, int number, const char *message);
383 void S9xLoadSDD1Data ();
384 END_EXTERN_C
385
386 enum {
387     PAUSE_NETPLAY_CONNECT = (1 << 0),
388     PAUSE_TOGGLE_FULL_SCREEN = (1 << 1),
389     PAUSE_EXIT = (1 << 2),
390     PAUSE_MENU = (1 << 3),
391     PAUSE_INACTIVE_WINDOW = (1 << 4),
392     PAUSE_WINDOW_ICONISED = (1 << 5),
393     PAUSE_RESTORE_GUI = (1 << 6),
394     PAUSE_FREEZE_FILE = (1 << 7)
395 };
396 void S9xSetPause (uint32 mask);
397 void S9xClearPause (uint32 mask);
398
399 #endif