removing now unneeded dir from package
[drnoksnes] / snaporig.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 _SNAPORIG_H_
42 #define _SNAPORIG_H_
43
44 #define ORIG_SNAPSHOT_MAGIC "#!snes96"
45 #define ORIG_SNAPSHOT_VERSION 4
46
47 EXTERN_C bool8_32 S9xLoadOrigSnapshot (const char *filename);
48
49 struct SOrigCPUState{
50     uint32  Flags;
51     short  Cycles_old;
52     short  NextEvent_old;
53     uint8   CurrentFrame;
54     uint8   FastROMSpeed_old_old;
55     uint16   V_Counter_old;
56     bool8_32   BranchSkip;
57     bool8_32   NMIActive;
58     bool8_32   IRQActive;
59     bool8_32   WaitingForInterrupt;
60     bool8_32   InDMA;
61     uint8   WhichEvent;
62     uint8   *PC;
63     uint8   *PCBase;
64     uint16   MemSpeed_old;
65     uint16   MemSpeedx2_old;
66     uint16   FastROMSpeed_old;
67     bool8_32   FastDP;
68     uint8   *PCAtOpcodeStart;
69     uint8   *WaitAddress;
70     uint32  WaitCounter;
71     long   Cycles;
72     long   NextEvent;
73     long   V_Counter;
74     long   MemSpeed;
75     long   MemSpeedx2;
76     long   FastROMSpeed;
77 };
78
79 struct SOrigAPU
80 {
81     uint32 Cycles;
82     bool8_32  ShowROM;
83     uint8  Flags;
84     uint8  KeyedChannels;
85     uint8  OutPorts [4];
86     uint8  DSP [0x80];
87     uint8  ExtraRAM [64];
88     uint16  Timer [3];
89     uint16  TimerTarget [3];
90     bool8_32  TimerEnabled [3];
91     bool8_32  TimerValueWritten [3];
92 };
93
94 typedef union
95 {
96 #ifdef LSB_FIRST
97     struct { uint8 A, Y; } B;
98 #else
99     struct { uint8 Y, A; } B;
100 #endif
101     uint16 W;
102 } OrigYAndA;
103
104 struct SOrigAPURegisters{
105     uint8  P;
106     OrigYAndA YA;
107     uint8  X;
108     uint8  S;
109     uint16  PC;
110 };
111
112 #define ORIG_MAX_BUFFER_SIZE (1024 * 4)
113 #define NUM_CHANNELS    8
114
115 typedef struct {
116     int state;
117     int type;
118     short volume_left;
119     short volume_right;
120     int frequency;
121     int count;
122     signed short wave [ORIG_MAX_BUFFER_SIZE];
123     bool8_32 loop;
124     int envx;
125     short left_vol_level;
126     short right_vol_level;
127     short envx_target;
128     unsigned long int env_error;
129     unsigned long erate;
130     int direction;
131     unsigned long attack_rate;
132     unsigned long decay_rate;
133     unsigned long sustain_rate;
134     unsigned long release_rate;
135     unsigned long sustain_level;
136     signed short sample;
137     signed short decoded [16];
138     signed short previous [2];
139     uint16 sample_number;
140     bool8_32 last_block;
141     bool8_32 needs_decode;
142     uint32 block_pointer;
143     uint32 sample_pointer;
144     int *echo_buf_ptr;
145     int mode;
146     uint32 dummy [8];
147 } OrigChannel;
148
149 typedef struct
150 {
151     short master_volume_left;
152     short master_volume_right;
153     short echo_volume_left;
154     short echo_volume_right;
155     int echo_enable;
156     int echo_feedback;
157     int echo_ptr;
158     int echo_buffer_size;
159     int echo_write_enabled;
160     int echo_channel_enable;
161     int pitch_mod;
162     // Just incase they are needed in the future, for snapshot compatibility.
163     uint32 dummy [3];
164     OrigChannel channels [NUM_CHANNELS];
165 } SOrigSoundData;
166
167 struct SOrigOBJ
168 {
169     short HPos;
170     uint16  VPos;
171     uint16  Name;
172     uint8  VFlip;
173     uint8  HFlip;
174     uint8  Priority;
175     uint8  Palette;
176     uint8  Size;
177     uint8  Prev;
178     uint8  Next;
179 };
180
181 struct SOrigPPU {
182     uint8  BGMode;
183     uint8  BG3Priority;
184     uint8  Brightness;
185
186     struct {
187         bool8_32 High;
188         uint8 Increment;
189         uint16 Address;
190         uint16 Mask1;
191         uint16 FullGraphicCount;
192         uint16 Shift;
193     } VMA;
194
195     struct {
196         uint8 TileSize;
197         uint16 TileAddress;
198         uint8 Width;
199         uint8 Height;
200         uint16 SCBase;
201         uint16 VOffset;
202         uint16 HOffset;
203         bool8_32 ThroughMain;
204         bool8_32 ThroughSub;
205         uint8 BGSize;
206         uint16 NameBase;
207         uint16 SCSize;
208         bool8_32 Addition;
209     } BG [4];
210
211     bool8_32 CGFLIP;
212     uint16 CGDATA [256]; 
213     uint8 FirstSprite;
214     uint8 LastSprite;
215     struct SOrigOBJ OBJ [129];
216     uint8 OAMPriorityRotation;
217     uint16 OAMAddr;
218
219     uint8 OAMFlip;
220     uint16 OAMTileAddress;
221     uint16 IRQVBeamPos;
222     uint16 IRQHBeamPos;
223     uint16 VBeamPosLatched;
224     uint16 HBeamPosLatched;
225
226     uint8 HBeamFlip;
227     uint8 VBeamFlip;
228     uint8 HVBeamCounterLatched;
229
230     short MatrixA;
231     short MatrixB;
232     short MatrixC;
233     short MatrixD;
234     short CentreX;
235     short CentreY;
236     uint8  Joypad1ButtonReadPos;
237     uint8  Joypad2ButtonReadPos;
238
239     uint8  CGADD;
240     uint8  FixedColourRed;
241     uint8  FixedColourGreen;
242     uint8  FixedColourBlue;
243     uint16  SavedOAMAddr;
244     uint16  ScreenHeight;
245     uint32 WRAM;
246     uint8  BG_Forced;
247     bool8_32  ForcedBlanking;
248     bool8_32  OBJThroughMain;
249     bool8_32  OBJThroughSub;
250     uint8  OBJSizeSelect;
251     uint8  OBJNameSelect_old;
252     uint16  OBJNameBase;
253     bool8_32  OBJAddition;
254     uint8  OAMReadFlip;
255     uint8  OAMData [512 + 32];
256     bool8_32  VTimerEnabled;
257     bool8_32  HTimerEnabled;
258     short HTimerPosition;
259     uint8  Mosaic;
260     bool8_32  BGMosaic [4];
261     bool8_32  Mode7HFlip;
262     bool8_32  Mode7VFlip;
263     uint8  Mode7Repeat;
264     uint8  Window1Left;
265     uint8  Window1Right;
266     uint8  Window2Left;
267     uint8  Window2Right;
268     uint8  ClipCounts [6];
269     uint8  ClipLeftEdges [3][6];
270     uint8  ClipRightEdges [3][6];
271     uint8  ClipWindowOverlapLogic [6];
272     uint8  ClipWindow1Enable [6];
273     uint8  ClipWindow2Enable [6];
274     bool8_32  ClipWindow1Inside [6];
275     bool8_32  ClipWindow2Inside [6];
276     bool8_32  RecomputeClipWindows;
277     uint8  CGFLIPRead;
278     uint16  OBJNameSelect;
279     bool8_32  Need16x8Mulitply;
280     uint8  Joypad3ButtonReadPos;
281     uint8  MouseSpeed[2];
282 };
283
284 struct SOrigDMA {
285     bool8_32  TransferDirection;
286     bool8_32  AAddressFixed;
287     bool8_32  AAddressDecrement;
288     uint8  TransferMode;
289
290     uint8  ABank;
291     uint16  AAddress;
292     uint16  Address;
293     uint8  BAddress;
294
295     // General DMA only:
296     uint16  TransferBytes;
297
298     // H-DMA only:
299     bool8_32  HDMAIndirectAddressing;
300     uint16  IndirectAddress;
301     uint8  IndirectBank;
302     uint8  Repeat;
303     uint8  LineCount;
304     uint8  FirstLine;
305     bool8_32  JustStarted;
306 };
307
308 typedef union
309 {
310 #ifdef LSB_FIRST
311     struct { uint8 l,h; } B;
312 #else
313     struct { uint8 h,l; } B;
314 #endif
315     uint16 W;
316 } OrigPair;
317
318 struct SOrigRegisters{
319     uint8       PB;
320     uint8       DB;
321     OrigPair   P;
322     OrigPair   A;
323     OrigPair   D;
324     OrigPair   S;
325     OrigPair   X;
326     OrigPair   Y;
327     uint16       PC;
328 };
329
330 #endif