main.c
6.51 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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/**************************************************************************
* *
* Copyright (C) 1994, Silicon Graphics, Inc. *
* *
* These coded instructions, statements, and computer programs contain *
* unpublished proprietary information of Silicon Graphics, Inc., and *
* are protected by Federal copyright law. They may not be disclosed *
* to third parties or copied or duplicated in any form, in whole or *
* in part, without the prior written consent of Silicon Graphics, Inc. *
* *
*************************************************************************/
/*
* Main routine of program. Sit and wait for display lists to be passed
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#ifdef __sgi__
#include <os.h>
#endif
#include <gu.h>
#include <sys/u64gio.h>
#include <ultrahost.h>
#include <signal.h>
#include "dlprint.h"
memNode *firstMemNode;
memNode *lastMemNode;
int inFD;
/*
* need to catch signals, and exit, to cause data that has been redirected
* to be flushed from buffer when program is killed
*/
void mySigHandler(int signo)
{
uhCloseGame(inFD);
exit(-1);
}
/*
* main routine.
*/
int main(int argc, char *argv[])
{
int bytesRead;
guDLPrintCB readBlk;
u8 *dataBlk;
memNode *node,*nextNode;
u32 flags;
u32 done = 0;
u32 server_mode = FALSE;
u64 *rdpData;
u8 *abiData;
char errMessage[256];
struct sigaction sigAct;
if(argc > 1)
{
if(argv[1][1] == 's')
server_mode = TRUE;
else
{
PRINTF("usage: -s servermode\n");
exit(-1);
}
}
/* Set up the signal handling */
#ifdef __sgi__
sigAct.sa_handler = (__sigret_t*)mySigHandler;
#else
sigAct.sa_handler = mySigHandler;
#endif
sigemptyset(&sigAct.sa_mask);
sigAct.sa_flags = 0;
if(sigaction(SIGCHLD,&sigAct,NULL) < 0)
{
perror("Unable to install signal handler SIGCHLD");
exit(-1);
}
if(sigaction(SIGINT,&sigAct,NULL) < 0)
{
perror("Unable to install signal handler SIGINT");
exit(-1);
}
if(sigaction(SIGTERM,&sigAct,NULL) < 0)
{
perror("Unable to install signal handler SIGTERM");
exit(-1);
}
if(sigaction(SIGQUIT,&sigAct,NULL) < 0)
{
perror("Unable to install signal handler SIGQUIT");
exit(-1);
}
inFD = uhOpenGame(DEV_U64_DATA);
if(inFD == -1)
{
sprintf(errMessage, "dlprint: unable to open %s", DEV_U64_DATA);
perror(errMessage);
exit(1);
}
while(!done)
{
bytesRead = uhReadGame(inFD, (void*)&readBlk, sizeof(readBlk) );
if(bytesRead != sizeof(readBlk))
{
printf("Failure reading readBlk, only got %d bytes\n",bytesRead);
exit(-1);
}
if(readBlk.dlType == GU_PARSE_STRING_TYPE)
{
rdpData = (u64*)malloc(readBlk.dataSize);
if(!rdpData)
{
printf("Unable to allocate memory for rdp data, needed %d bytes\n",readBlk.dataSize);
exit(-1);
}
bytesRead = uhReadGame(inFD, rdpData, readBlk.dataSize);
if(bytesRead != readBlk.dataSize)
{
printf("Failure reading dataBlk, only got %d bytes\n",bytesRead);
exit(-1);
}
if(!strncmp((char *) rdpData, "END DUMP", 8))
done = 1;
else
printf("%s", rdpData);
free(rdpData);
}
else if(readBlk.dlType == GU_PARSE_RDP_TYPE)
{
rdpData = (u64*)malloc(readBlk.dataSize);
if(!rdpData)
{
printf("Unable to allocate memory for rdp data, needed %d bytes\n",readBlk.dataSize);
exit(-1);
}
bytesRead = uhReadGame(inFD, rdpData, readBlk.dataSize);
if(bytesRead != readBlk.dataSize)
{
printf("Failure reading dataBlk, only got %d bytes\n",bytesRead);
exit(-1);
}
ParseRdpDL(rdpData, (u32)readBlk.dataSize, readBlk.flags);
if(!server_mode)
done = 1;
free(rdpData);
}
else if(readBlk.dlType == GU_PARSE_ABI_TYPE)
{
abiData = (u8*)malloc(readBlk.dataSize);
if(!abiData)
{
printf("Unable to allocate memory for abi data, needed %d bytes\n",readBlk.dataSize);
exit(-1);
}
bytesRead = uhReadGame(inFD, abiData, readBlk.dataSize);
if(bytesRead != readBlk.dataSize)
{
printf("Failure reading dataBlk, only got %d bytes\n",bytesRead);
exit(-1);
}
ParseAbiCL(abiData, (u32)readBlk.dataSize);
if(!server_mode)
done = 1;
free(abiData);
}
else if(readBlk.dlType == GU_PARSE_GBI_TYPE || readBlk.dlType == GU_PARSE_MEM_BLOCK)
{
node = (memNode*)malloc(sizeof(memNode));
if(!node)
{
printf("Unable to allocate memory for display list node\n");
exit(-1);
}
node->next = 0;
node->paddr = readBlk.paddr;
node->data = (u8*)malloc(readBlk.dataSize);
if(!node->data)
{
printf("Unable to allocate memory for data. Needed %d bytes\n",readBlk.dataSize);
exit(-1);
}
bytesRead = uhReadGame(inFD, node->data, readBlk.dataSize);
if(bytesRead != readBlk.dataSize)
{
printf("Failure reading dataBlk, only got %d bytes\n",bytesRead);
exit(-1);
}
if(lastMemNode) /* this is not the first node */
{
lastMemNode->next = (void*)node;
lastMemNode = node;
}
else /* this is the first nodes */
{
flags = (u32)readBlk.flags;
firstMemNode = node;
lastMemNode = node;
}
}
else if(readBlk.dlType == GU_PARSE_READY)
{
ParseGbiDL(flags);
PRINTF("Display list processing completed\n");
while(firstMemNode)
{
nextNode = (memNode*)firstMemNode->next;
free(firstMemNode->data);
free(firstMemNode);
firstMemNode = nextNode;
}
lastMemNode = 0;
if(!server_mode)
done = 1;
}
}
}