initial upstream import
[drnoksnes] / dsp1_gp32.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 _DSP1_H_
42 #define _DSP1_H_
43
44 // Simple vector and matrix types
45 typedef double MATRIX[3][3];
46 typedef double VECTOR[3];
47
48 enum AttitudeMatrix { MatrixA, MatrixB, MatrixC };
49
50 struct SDSP1 {
51     bool8 waiting4command;
52     bool8 first_parameter;
53     uint8 command;
54     uint32 in_count;
55     uint32 in_index;
56     uint32 out_count;
57     uint32 out_index;
58     uint16 parameters [10];
59     uint16 output [10];
60
61     // Attitude matrices
62     MATRIX vMa;
63     MATRIX vMb;
64     MATRIX vMc;
65     
66     // Matrix and translaton vector for
67     // transforming a 3D position into the global coordinate system,
68     // from the view space coordinate system.
69     MATRIX vM;
70     VECTOR vT;
71
72     // Focal distance
73     double vFov;
74
75     // A precalculated value for optimization
76     double vPlaneD;
77     
78     // Raster position of horizon
79     double vHorizon;
80
81     // Convert a 2D screen coordinate to a 3D ground coordinate in global coordinate system.
82     void ScreenToGround(VECTOR &v, double X2d, double Y2d);
83
84     MATRIX &GetMatrix( AttitudeMatrix Matrix );
85 };
86
87 ///////////////// DSP Commands ////////////////////
88
89 // DSP1 Command 02h
90 struct DSP1_Parameter
91 {
92     DSP1_Parameter( int16 Fx, int16 Fy, int16 Fz,
93                       uint16 Lfe, uint16 Les,
94                       int8 Aas, int8 Azs );
95
96     // Raster number of imaginary center
97     int16 Vof;  // -32768 ~ +32767
98
99     // Raster number representing
100     // horizontal line.
101     int16 Vva;  // -32768 ~ +32767
102
103     // X,Y coordinate of the point
104     // projected on the center of the screen
105     // (ground coordinate)
106     int16 Cx;   // -32768 ~ +32767
107     int16 Cy;   // -32768 ~ +32767
108 };
109
110 // DSP1 Command 0Ah
111 struct DSP1_Raster
112 {
113     DSP1_Raster( int16 Vs );
114
115     // Linear transformation matrix elements
116     // for each raster
117     int16 An;
118     int16 Bn;
119     int16 Cn;
120     int16 Dn;
121 };
122
123 // DSP1 Command 06h
124 struct DSP1_Project
125 {
126     DSP1_Project( int16 x, int16 y, int16 z );
127
128     int16 H;
129     int16 V;
130     int16 M;
131 };
132
133 // DSP1 Command 0Eh
134 struct DSP1_Target
135 {
136     DSP1_Target( int16 h, int16 v );
137
138     int16 X;
139     int16 Y;
140 };
141
142 // DSP1 Command 04h
143 struct DSP1_Triangle
144 {
145     DSP1_Triangle (int16 Theta, int16 r );
146     int16 S;
147     int16 C;
148 };
149
150 // DSP1 Command 08h
151 struct DSP1_Radius
152 {
153     DSP1_Radius( int16 x, int16 y, int16 z );
154     int16 Ll;
155     int16 Lh;
156 };
157
158 // DSP1 Command 18h
159 int16 DSP1_Range( int16 x, int16 y, int16 z, int16 r );
160
161 // DSP1 Command 28h
162 int16 DSP1_Distance( int16 x, int16 y, int16 z );
163
164 // DSP1 Command 0Ch
165 struct DSP1_Rotate
166 {
167     DSP1_Rotate (int16 A, int16 x1, int16 y1);
168
169     int16 x2;
170     int16 y2;
171 };
172
173 // DSP1 Command 1Ch
174 struct DSP1_Polar
175 {
176     DSP1_Polar( int8 Za, int8 Xa, int8 Ya, int16 x, int16 y, int16 z );
177
178     int16 X;
179     int16 Y;
180     int16 Z;
181 };
182
183 // DSP1 Command 01h, 11h and 21h
184 void DSP1_Attitude( int16 m, int8 Za, int8 Xa, int8 Ya, AttitudeMatrix Matrix );
185
186 // DSP1 Command 0Dh, 1Dh and 2Dh
187 struct DSP1_Objective
188 {
189     DSP1_Objective( int16 x, int16 y, int16 z, AttitudeMatrix Matrix );
190
191     int16 F;
192     int16 L;
193     int16 U;
194 };
195
196 // DSP1 Command 03h, 13h and 23h
197 struct DSP1_Subjective
198 {
199     DSP1_Subjective( int16 F, int16 L, int16 U, AttitudeMatrix Matrix );
200
201     int16 X;
202     int16 Y;
203     int16 Z;
204 };
205
206 // DSP1 Command 0Bh, 1Bh and 2Bh
207 int16 DSP1_Scalar( int16 x, int16 y, int16 z, AttitudeMatrix Matrix );
208
209 // DSP1 Command 14h
210 struct DSP1_Gyrate
211 {
212     DSP1_Gyrate( int8 Zi, int8 Xi, int8 Yi,
213                  int8 dU, int8 dF, int8 dL );
214
215     int8 Z0;
216     int8 X0;
217     int8 Y0;
218 };
219
220 // DSP1 Command 00h
221 int16 DSP1_Multiply( int16 k, int16 I );
222
223 // DSP1 Command 10h
224 struct DSP1_Inverse
225 {
226     DSP1_Inverse( int16 a, int16 b );
227
228     int16 A;
229     int16 B;
230 };
231
232 START_EXTERN_C
233 void S9xResetDSP1 ();
234 uint8 S9xGetDSP (uint16 Address);
235 void S9xSetDSP (uint8 Byte, uint16 Address);
236 END_EXTERN_C
237
238 #ifndef __GP32__ 
239 extern struct SDSP1 DSP1;
240 #else
241 extern "C" struct SDSP1 DSP1;
242 #endif
243
244 #endif