summaryrefslogtreecommitdiff
path: root/src/snaporig.h
blob: e8b77be7484e8ea752c330c0c6eedc1c8782f074 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
/*
 * Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
 *
 * (c) Copyright 1996 - 2001 Gary Henderson (gary.henderson@ntlworld.com) and
 *                           Jerremy Koot (jkoot@snes9x.com)
 *
 * Super FX C emulator code
 * (c) Copyright 1997 - 1999 Ivar (ivar@snes9x.com) and
 *                           Gary Henderson.
 * Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_.
 *
 * DSP1 emulator code (c) Copyright 1998 Ivar, _Demo_ and Gary Henderson.
 * C4 asm and some C emulation code (c) Copyright 2000 zsKnight and _Demo_.
 * C4 C code (c) Copyright 2001 Gary Henderson (gary.henderson@ntlworld.com).
 *
 * DOS port code contains the works of other authors. See headers in
 * individual files.
 *
 * Snes9x homepage: http://www.snes9x.com
 *
 * Permission to use, copy, modify and distribute Snes9x in both binary and
 * source form, for non-commercial purposes, is hereby granted without fee,
 * providing that this license information and copyright notice appear with
 * all copies and any derived work.
 *
 * This software is provided 'as-is', without any express or implied
 * warranty. In no event shall the authors be held liable for any damages
 * arising from the use of this software.
 *
 * Snes9x is freeware for PERSONAL USE only. Commercial users should
 * seek permission of the copyright holders first. Commercial use includes
 * charging money for Snes9x or software derived from Snes9x.
 *
 * The copyright holders request that bug fixes and improvements to the code
 * should be forwarded to them so everyone can benefit from the modifications
 * in future versions.
 *
 * Super NES and Super Nintendo Entertainment System are trademarks of
 * Nintendo Co., Limited and its subsidiary companies.
 */
#ifndef _SNAPORIG_H_
#define _SNAPORIG_H_

#define ORIG_SNAPSHOT_MAGIC "#!snes96"
#define ORIG_SNAPSHOT_VERSION 4

EXTERN_C bool8_32 S9xLoadOrigSnapshot(const char* filename);

struct SOrigCPUState
{
   uint32  Flags;
   short  Cycles_old;
   short  NextEvent_old;
   uint8   CurrentFrame;
   uint8   FastROMSpeed_old_old;
   uint16   V_Counter_old;
   bool8_32   BranchSkip;
   bool8_32   NMIActive;
   bool8_32   IRQActive;
   bool8_32   WaitingForInterrupt;
   bool8_32   InDMA;
   uint8   WhichEvent;
   uint8*   PC;
   uint8*   PCBase;
   uint16   MemSpeed_old;
   uint16   MemSpeedx2_old;
   uint16   FastROMSpeed_old;
   bool8_32   FastDP;
   uint8*   PCAtOpcodeStart;
   uint8*   WaitAddress;
   uint32  WaitCounter;
   long   Cycles;
   long   NextEvent;
   long   V_Counter;
   long   MemSpeed;
   long   MemSpeedx2;
   long   FastROMSpeed;
};

struct SOrigAPU
{
   uint32 Cycles;
   bool8_32  ShowROM;
   uint8  Flags;
   uint8  KeyedChannels;
   uint8  OutPorts [4];
   uint8  DSP [0x80];
   uint8  ExtraRAM [64];
   uint16  Timer [3];
   uint16  TimerTarget [3];
   bool8_32  TimerEnabled [3];
   bool8_32  TimerValueWritten [3];
};

typedef union
{
#ifdef MSB_FIRST
   struct
   {
      uint8 Y, A;
   } B;
#else
   struct
   {
      uint8 A, Y;
   } B;
#endif
   uint16 W;
} OrigYAndA;

struct SOrigAPURegisters
{
   uint8  P;
   OrigYAndA YA;
   uint8  X;
   uint8  S;
   uint16  PC;
};

#define ORIG_MAX_BUFFER_SIZE (1024 * 4)
#define NUM_CHANNELS    8

typedef struct
{
   int state;
   int type;
   short volume_left;
   short volume_right;
   int frequency;
   int count;
   signed short wave [ORIG_MAX_BUFFER_SIZE];
   bool8_32 loop;
   int envx;
   short left_vol_level;
   short right_vol_level;
   short envx_target;
   unsigned long int env_error;
   unsigned long erate;
   int direction;
   unsigned long attack_rate;
   unsigned long decay_rate;
   unsigned long sustain_rate;
   unsigned long release_rate;
   unsigned long sustain_level;
   signed short sample;
   signed short decoded [16];
   signed short previous [2];
   uint16 sample_number;
   bool8_32 last_block;
   bool8_32 needs_decode;
   uint32 block_pointer;
   uint32 sample_pointer;
   int* echo_buf_ptr;
   int mode;
   uint32 dummy [8];
} OrigChannel;

typedef struct
{
   short master_volume_left;
   short master_volume_right;
   short echo_volume_left;
   short echo_volume_right;
   int echo_enable;
   int echo_feedback;
   int echo_ptr;
   int echo_buffer_size;
   int echo_write_enabled;
   int echo_channel_enable;
   int pitch_mod;
   // Just incase they are needed in the future, for snapshot compatibility.
   uint32 dummy [3];
   OrigChannel channels [NUM_CHANNELS];
} SOrigSoundData;

struct SOrigOBJ
{
   short HPos;
   uint16  VPos;
   uint16  Name;
   uint8  VFlip;
   uint8  HFlip;
   uint8  Priority;
   uint8  Palette;
   uint8  Size;
   uint8  Prev;
   uint8  Next;
};

struct SOrigPPU
{
   uint8  BGMode;
   uint8  BG3Priority;
   uint8  Brightness;

   struct
   {
      bool8_32 High;
      uint8 Increment;
      uint16 Address;
      uint16 Mask1;
      uint16 FullGraphicCount;
      uint16 Shift;
   } VMA;

   struct
   {
      uint8 TileSize;
      uint16 TileAddress;
      uint8 Width;
      uint8 Height;
      uint16 SCBase;
      uint16 VOffset;
      uint16 HOffset;
      bool8_32 ThroughMain;
      bool8_32 ThroughSub;
      uint8 BGSize;
      uint16 NameBase;
      uint16 SCSize;
      bool8_32 Addition;
   } BG [4];

   bool8_32 CGFLIP;
   uint16 CGDATA [256];
   uint8 FirstSprite;
   uint8 LastSprite;
   struct SOrigOBJ OBJ [129];
   uint8 OAMPriorityRotation;
   uint16 OAMAddr;

   uint8 OAMFlip;
   uint16 OAMTileAddress;
   uint16 IRQVBeamPos;
   uint16 IRQHBeamPos;
   uint16 VBeamPosLatched;
   uint16 HBeamPosLatched;

   uint8 HBeamFlip;
   uint8 VBeamFlip;
   uint8 HVBeamCounterLatched;

   short MatrixA;
   short MatrixB;
   short MatrixC;
   short MatrixD;
   short CentreX;
   short CentreY;
   uint8  Joypad1ButtonReadPos;
   uint8  Joypad2ButtonReadPos;

   uint8  CGADD;
   uint8  FixedColourRed;
   uint8  FixedColourGreen;
   uint8  FixedColourBlue;
   uint16  SavedOAMAddr;
   uint16  ScreenHeight;
   uint32 WRAM;
   uint8  BG_Forced;
   bool8_32  ForcedBlanking;
   bool8_32  OBJThroughMain;
   bool8_32  OBJThroughSub;
   uint8  OBJSizeSelect;
   uint8  OBJNameSelect_old;
   uint16  OBJNameBase;
   bool8_32  OBJAddition;
   uint8  OAMReadFlip;
   uint8  OAMData [512 + 32];
   bool8_32  VTimerEnabled;
   bool8_32  HTimerEnabled;
   short HTimerPosition;
   uint8  Mosaic;
   bool8_32  BGMosaic [4];
   bool8_32  Mode7HFlip;
   bool8_32  Mode7VFlip;
   uint8  Mode7Repeat;
   uint8  Window1Left;
   uint8  Window1Right;
   uint8  Window2Left;
   uint8  Window2Right;
   uint8  ClipCounts [6];
   uint8  ClipLeftEdges [3][6];
   uint8  ClipRightEdges [3][6];
   uint8  ClipWindowOverlapLogic [6];
   uint8  ClipWindow1Enable [6];
   uint8  ClipWindow2Enable [6];
   bool8_32  ClipWindow1Inside [6];
   bool8_32  ClipWindow2Inside [6];
   bool8_32  RecomputeClipWindows;
   uint8  CGFLIPRead;
   uint16  OBJNameSelect;
   bool8_32  Need16x8Mulitply;
   uint8  Joypad3ButtonReadPos;
   uint8  MouseSpeed[2];
};

struct SOrigDMA
{
   bool8_32  TransferDirection;
   bool8_32  AAddressFixed;
   bool8_32  AAddressDecrement;
   uint8  TransferMode;

   uint8  ABank;
   uint16  AAddress;
   uint16  Address;
   uint8  BAddress;

   // General DMA only:
   uint16  TransferBytes;

   // H-DMA only:
   bool8_32  HDMAIndirectAddressing;
   uint16  IndirectAddress;
   uint8  IndirectBank;
   uint8  Repeat;
   uint8  LineCount;
   uint8  FirstLine;
   bool8_32  JustStarted;
};

typedef union
{
#ifdef MSB_FIRST
   struct
   {
      uint8 h, l;
   } B;
#else
   struct
   {
      uint8 l, h;
   } B;
#endif
   uint16 W;
} OrigPair;

struct SOrigRegisters
{
   uint8       PB;
   uint8       DB;
   OrigPair   P;
   OrigPair   A;
   OrigPair   D;
   OrigPair   S;
   OrigPair   X;
   OrigPair   Y;
   uint16       PC;
};

#endif