std_visual.c
6.98 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
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
/**************************************************************************
* *
* 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. *
* *
*************************************************************************/
/*
* File: std_visual.c
* Creator: jeffd@sgi.com
* Create Date: Thu Jan 27 15:29:55 PST 1994
*
* This file implements the curses panels for interactive display.
*
*/
#include <curses.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <term.h>
#include <stdarg.h>
#include <stdio.h>
#include "rsp.h"
#include "rspctl.h"
#include "std_visual.h"
#include "vu.h"
#include "cop0.h"
#define MIN_CMD_WSIZE 2
#define MIN_REG_WSIZE 1
#define MAX_REG_WSIZE 39
#define MIN_OUT_WSIZE 3
static WINDOW *cmdWindow, *regWindow, *outWindow;
static int cmdRow, regRow, outRow;
static int cmdNumRows, regNumRows, outNumRows, numRows, numColumns;
static char *regLineBuf, *outLineBuf;
static int outLineCount;
static boolean doResize = FALSE;
boolean
rsp_VisualInit(void)
{
struct winsize win;
int rv;
initscr();
if ((ioctl(0, TIOCGWINSZ, &win) < 0) &&
(win.ws_row > 0) && (win.ws_col > 0)) {
numRows = win.ws_row;
numColumns = win.ws_col;
} else {
numRows = lines;
numColumns = columns;
}
if (numRows < (MIN_CMD_WSIZE+MIN_REG_WSIZE+MIN_OUT_WSIZE)) {
endwin();
fprintf(stderr, "rsp: not enough lines for visual mode\n");
return(FALSE);
}
if (((regLineBuf = (char *)malloc(numColumns)) == NULL) ||
((outLineBuf = (char *)malloc(3*numColumns)) == NULL)) {
endwin();
fprintf(stderr, "rsp: malloc failed\n");
return(FALSE);
}
/*
* Divvy up total number of lines among command,
* register view, and output window.
*/
cmdNumRows = MIN_CMD_WSIZE;
if (numRows - cmdNumRows >= MAX_REG_WSIZE + MIN_OUT_WSIZE) {
regNumRows = MAX_REG_WSIZE;
outNumRows = numRows - cmdNumRows - regNumRows; /* plenty 'o room */
} else {
outNumRows = MIN_OUT_WSIZE;
regNumRows = numRows - cmdNumRows - outNumRows;
}
cmdRow = 0;
regRow = cmdRow + cmdNumRows;
outRow = regRow + regNumRows;
cmdWindow = newwin(cmdNumRows, numColumns, cmdRow, 0);
regWindow = newwin(regNumRows, numColumns, regRow, 0);
outWindow = newwin(outNumRows, numColumns, outRow, 0);
wmove(regWindow, regNumRows-1, 0);
whline(regWindow, '-', numColumns);
wrefresh(regWindow);
wmove(cmdWindow, 0, 0);
waddstr(cmdWindow, "rsp> ");
wmove(cmdWindow, cmdNumRows-1, 0);
whline(cmdWindow, '-', numColumns);
wrefresh(cmdWindow);
scrollok(outWindow, TRUE);
outLineCount = 0;
return(TRUE);
}
int rsp_VisualGets(char *s, int n)
{
int i, j, c;
char *sp = s;
wmove(cmdWindow, 0, 5);
wclrtoeol(cmdWindow);
wrefresh(cmdWindow);
for (i = 0; i < n; i++) {
if ((c = wgetch(cmdWindow)) == ERR) {
if (!doResize)
break;
if (!rsp_VisualUpdate())
return(-1);
wmove(cmdWindow, 0, 5);
for (j = 0; j < sp-s; j++)
waddch(cmdWindow, s[j]);
wrefresh(cmdWindow);
continue;
}
if ((c == 8 || c == 127) && sp > s) { /* Backspace or delete */
sp--;
} else if ((*sp++ = c) == '\n') {
break;
}
}
if (s == sp)
return(-1);
*sp = '\0';
return(0);
}
#define outRegWindow(s) { if (lineCount >= regNumRows-1) { \
wrefresh(regWindow); \
wmove(cmdWindow, 0, 5); \
return(TRUE); \
} \
wmove(regWindow, lineCount++, 0); \
waddstr(regWindow, (s)); \
}
boolean
rsp_VisualUpdate(void)
{
int i, j;
i128 regValue;
i32 gpregValue;
u32 readRegValue, writeRegValue;
int lineCount = 0;
int numChars;
if (doResize) {
rsp_VisualCleanup();
if (!rsp_VisualInit()) {
return(FALSE);
}
doResize = FALSE;
}
sprintf(regLineBuf, "VAC = 0x%012llx VCO = 0x%04x VCC = 0x%04x",
rsp_ACC[0]&VU_ACC_MASK, rsp_VCO, rsp_VCC);
outRegWindow(regLineBuf);
for (i=1; i<8; i++) {
sprintf(regLineBuf, " 0x%012llx",rsp_ACC[i]&VU_ACC_MASK);
outRegWindow(regLineBuf);
}
outRegWindow("");
numChars = 0;
for (i=0; i < 32; i++) {
numChars += sprintf(regLineBuf + numChars,
"%sv%d = ", (i < 10 ? " " : ""), i);
regValue = rsp_VURGet(i);
for (j=0; j<16; j++) {
numChars += sprintf(regLineBuf + numChars, "%02x%s",regValue.b[j],
(j&rsp_VUSpacing)?" ":"" );
}
if ((i % 2) == 0) {
*(regLineBuf + numChars++) = ' ';
} else {
outRegWindow(regLineBuf);
numChars = 0;
}
}
outRegWindow("");
sprintf(regLineBuf, "PC = 0x%08x CTL = 0x%08x CLK = 0x%08x",
rsp_programCounter, rsp_controlReg, rsp_clock);
outRegWindow(regLineBuf);
sprintf(regLineBuf,
"DMA: Dmem = 0x%04x Dbus = 0x%06x Busy = %d Full = %d",
cop0_RegGet(0), cop0_RegGet(1),
(cop0_DmaBusy() ? 1 : 0), (cop0_DmaFull() ? 1 : 0));
outRegWindow(regLineBuf);
readRegValue = cop0_RegGet(2);
writeRegValue = cop0_RegGet(3);
sprintf(regLineBuf,
" Read Length = (%d,%d,%d) Write Length = (%d,%d,%d)",
readRegValue == -1 ? -1 : LINESTRIDE(readRegValue),
readRegValue == -1 ? -1 : LINECOUNT(readRegValue),
readRegValue == -1 ? -1 : BYTECOUNT(readRegValue),
writeRegValue == -1 ? -1 : LINESTRIDE(writeRegValue),
writeRegValue == -1 ? -1 : LINECOUNT(writeRegValue),
writeRegValue == -1 ? -1 : BYTECOUNT(writeRegValue));
outRegWindow(regLineBuf);
outRegWindow("");
numChars = 0;
for (i=0; i < 32; i++) {
gpregValue = rsp_SuGPRGet(i);
numChars += sprintf(regLineBuf + numChars, "%sr%d = 0x%08x ",
(i < 10 ? " " : ""), i, gpregValue);
if (((i+1) % 4) == 0) {
outRegWindow(regLineBuf);
numChars = 0;
}
}
wrefresh(regWindow);
wmove(cmdWindow, 0, 5);
return(TRUE);
}
void
rsp_VisualClear(void)
{
wclear(outWindow);
wmove(outWindow, 0, 0);
}
void
rsp_VisualPrint(FILE *out, char *fmt, va_list ap)
{
vsprintf(outLineBuf, fmt, ap);
waddstr(outWindow, outLineBuf);
wrefresh(outWindow);
}
void
rsp_VisualCleanup(void)
{
delwin(cmdWindow);
delwin(regWindow);
delwin(outWindow);
endwin();
free(regLineBuf);
free(outLineBuf);
}
int ViewFile(char *filename)
{
fprintf(stderr, "Function not supported in non-gl mode. \n");
fprintf(stderr, "bug Kevin to fix me \n");
return 1;
}
void
rsp_VisualResize(void)
{
doResize = TRUE;
}
void
rsp_VisualData (u32 datastart)
{
}
void
rsp_VisualSymbolTable (char *fn)
{
}
int
rsp_VisualNameInst(char *name)
{
return -1;
}