spintcl.c
6.95 KB
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
#include <sys/types.h>
#include <sys/ipc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <tcl.h>
#include "os.h"
#include <PR/mbi.h>
#include "sys/u64gio.h"
#include <ultrahost.h>
#include "spin.h"
#include "spincontrol.h"
static int u64fd;
int SpinTclProj(ClientData data, Tcl_Interp *interp, int argc, char *argv[])
{
int i,fov,near,far;
float aspect;
SpinControl sp;
fov = atoi(argv[0]);
aspect = atof(argv[1]);
near = atoi(argv[2]);
far = atoi(argv[3]);
sp.type = SPIN_PROJ_TYPE;
sp.u_msg.proj.fov = fov;
sp.u_msg.proj.aspect = aspect;
sp.u_msg.proj.near = near;
sp.u_msg.proj.far = far;
uhWriteGame(u64fd, &sp, sizeof(SpinControl));
strcpy(interp->result, "SpinTclMouse passed");
return TCL_OK;
}
int SpinTclMouse(ClientData data, Tcl_Interp *interp, int argc, char *argv[])
{
int i,mouseX, mouseY;
int buttons;
SpinControl sp;
mouseX = atoi(argv[0]);
mouseY = atoi(argv[1]);
buttons = atoi(argv[2]);
sp.type = SPIN_MOUSE_TYPE;
sp.u_msg.mouse.x = mouseX;
sp.u_msg.mouse.y = mouseY;
sp.u_msg.mouse.buttons = buttons;
uhWriteGame(u64fd, &sp, sizeof(SpinControl));
strcpy(interp->result, "SpinTclMouse passed");
return TCL_OK;
}
int SpinTclModel(ClientData data, Tcl_Interp *interp, int argc, char *argv[])
{
int i,model;
SpinControl sp;
model = atoi(argv[0]);
sp.type = SPIN_MODEL_TYPE;
sp.u_msg.model.model = model;
uhWriteGame(u64fd, &sp, sizeof(SpinControl));
strcpy(interp->result, "SpinTclModel passed");
return TCL_OK;
}
Gfx dlbuf[2048];
Gfx *SpinTclGetDlistp( void )
{
return dlbuf;
}
void SpinTclDlist( Gfx *last_addr )
{
SpinControl sp;
int len;
len = (last_addr - dlbuf) * sizeof(Gfx);
sp.type = SPIN_DLIST_TYPE;
sp.u_msg.dlist.dlsize = len;
uhWriteGame(u64fd, &sp, sizeof(SpinControl));
uhWriteGame(u64fd, dlbuf, len);
}
int SpinTclTrap(ClientData data, Tcl_Interp *interp, int argc, char *argv[])
{
SpinControl sp;
int frames,type;
frames = atoi(argv[0]);
type = atoi(argv[1]);
sp.type = SPIN_TRAP_TYPE;
sp.u_msg.trap.trap = frames;
sp.u_msg.trap.type = type;
/*
* trap doesnt work in the real hardware
*/
uhWriteGame(u64fd,&sp, sizeof(SpinControl));
strcpy(interp->result, "SpinTclTrap passed");
return TCL_OK;
}
int SpinTclConnect(ClientData data, Tcl_Interp *interp, int argc, char *argv[])
{
int reply;
u64fd = uhOpenGame(DEV_U64_DATA);
if (u64fd == -1)
{
fprintf(stderr, "Spintcl: Unable to open %s ", DEV_U64_DATA);
perror("");
return TCL_ERROR;
}
fprintf(stderr, "Listening for game ready signal\n");
while (1)
{
uhReadGame(u64fd, &reply, 4);
if (reply == SPIN_READY)
break;
}
fprintf(stderr, "Received game ready signal\n");
return TCL_OK;
}
int SpinTclInit(Tcl_Interp *interp)
{
Tcl_CreateCommand(interp, "SpinTclConnect", SpinTclConnect, NULL, NULL);
Tcl_CreateCommand(interp, "SpinTclModel", SpinTclModel, NULL, NULL);
Tcl_CreateCommand(interp, "SpinTclMouse", SpinTclMouse, NULL, NULL);
Tcl_CreateCommand(interp, "SpinTclTrap", SpinTclTrap, NULL, NULL);
strcpy(interp->result, "SpinTclInit passed");
return TCL_OK;
}
/*
* Dump display list
*/
int dump_dl( Gfx *uidl)
{
unsigned int i, cmd;
/* dump UI display list */
fprintf(stderr,"\nDump of UI display list:\n\n");
i = 0;
do
{
cmd = uidl[i].words.w0;
cmd = (cmd & 0xff000000) >> 24;
switch (cmd)
{
case G_SPNOOP: fprintf(stderr,"%3d: G_SPNOOP\n", i); break;
case G_MTX: fprintf(stderr,"%3d: G_G_MTX\n", i); break;
case G_MOVEMEM: fprintf(stderr,"%3d: G_VIEWPORT or G_LIGHT (MOVEMEM)\n", i); break;
case G_VTX: fprintf(stderr,"%3d: G_VTX\n", i); break;
case G_DL: fprintf(stderr,"%3d: G_DL\n", i); break;
case 0xbf: fprintf(stderr,"%3d: G_TRI1\n", i); break;
case 0xbd: fprintf(stderr,"%3d: G_POPMTX\n", i); break;
case 0xbc: fprintf(stderr,"%3d: G_SEGMENT\n", i); break;
case 0xb7: fprintf(stderr,"%3d: G_SETGEOMETRYMODE\n", i); break;
case 0xb6: fprintf(stderr,"%3d: G_CLEARGEOMETRYMODE\n", i); break;
case 0xb5: fprintf(stderr,"%3d: G_LINE3D\n", i); break;
case 0xb4: fprintf(stderr,"%3d: G_PERSPNORMALIZE\n", i); break;
case 0xb3: fprintf(stderr,"%3d: G_RDPHALF_1\n", i); break;
case 0xb2: fprintf(stderr,"%3d: G_RDPHALF_2\n", i); break;
case G_NOOP: fprintf(stderr,"%3d: G_NOOP\n", i); break;
case G_SETCIMG: fprintf(stderr,"%3d: G_SETCIMG\n", i); break;
case G_SETZIMG: fprintf(stderr,"%3d: G_SETMIMG\n", i); break;
case G_SETTIMG: fprintf(stderr,"%3d: G_SETTIMG\n", i); break;
case G_SETCOMBINE: fprintf(stderr,"%3d: G_SETCOMBINE\n", i); break;
case G_SETENVCOLOR: fprintf(stderr,"%3d: G_SETENVCOLOR\n", i); break;
case G_SETPRIMCOLOR: fprintf(stderr,"%3d: G_SETPRIMCOLOR\n", i); break;
case G_SETBLENDCOLOR: fprintf(stderr,"%3d: G_SETBLENDCOLOR\n", i); break;
case G_SETFOGCOLOR: fprintf(stderr,"%3d: G_SETFOGCOLOR\n", i); break;
case G_SETFILLCOLOR: fprintf(stderr,"%3d: G_SETFILLCOLOR\n", i); break;
case G_FILLRECT: fprintf(stderr,"%3d: G_FILLRECT\n", i); break;
case G_SETTILE: fprintf(stderr,"%3d: G_SETTILE\n", i); break;
case G_LOADTILE: fprintf(stderr,"%3d: G_LOADTILE\n", i); break;
case G_LOADBLOCK: fprintf(stderr,"%3d: G_LOADBLOCK\n", i); break;
case G_SETTILESIZE: fprintf(stderr,"%3d: G_SETTILESIZE\n", i); break;
case G_LOADTLUT: fprintf(stderr,"%3d: G_LOADTLUT\n", i); break;
case G_RDPSETOTHERMODE: fprintf(stderr,"%3d: G_RDPSETOTHERMODE\n", i); break;
case G_SETPRIMDEPTH: fprintf(stderr,"%3d: G_SETPRIMDEPTH\n", i); break;
case G_SETSCISSOR: fprintf(stderr,"%3d: G_SETSCISSOR\n", i); break;
case G_SETCONVERT: fprintf(stderr,"%3d: G_SETCONVERT\n", i); break;
case G_SETKEYR: fprintf(stderr,"%3d: G_SETKEYR\n", i); break;
case G_SETKEYGB: fprintf(stderr,"%3d: G_SETKEYGB\n", i); break;
case G_RDPFULLSYNC: fprintf(stderr,"%3d: G_RDPFULLSYNC\n", i); break;
case G_RDPTILESYNC: fprintf(stderr,"%3d: G_RDPTILESYNC\n", i); break;
case G_RDPPIPESYNC: fprintf(stderr,"%3d: G_RDPPIPESYNC\n", i); break;
case G_RDPLOADSYNC: fprintf(stderr,"%3d: G_RDPLOADSYNC\n", i); break;
case G_TEXRECTFLIP: fprintf(stderr,"%3d: G_TEXRECTFLIP\n", i); break;
case G_TEXRECT: fprintf(stderr,"%3d: G_TEXRECT\n", i); break;
case 0xb8: fprintf(stderr,"%3d: G_ENDDL\n", i); break;
case 0xbb: fprintf(stderr,"%3d: G_TEXTURE\n", i); break;
case 0xba: fprintf(stderr,"%3d: G_SETOTHERMODE_H\n", i); break;
case 0xb9: fprintf(stderr,"%3d: G_SETOTHERMODE_L\n", i); break;
default: fprintf(stderr,"%3d: command %d not recognized\n", i, cmd); break;
}
fprintf(stderr,"W0 %08x w1 %08x\n", uidl[i].words.w0, uidl[i].words.w1);
i++;
} while (cmd != 0xb8 && i < 100);
}