std_gfx.c
34.9 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
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
/**************************************************************************
* *
* 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_gfx.c
* Creator: lk@sgi.com
* Create Date: Mon Aug 1 21:54:32 PDT 1994
*
* This file implements the graphics panels for interactive display.
*
*/
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <gl/gl.h>
#include <gl/device.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
#define MAXSRCFILES 16
#define MAXSRCLINES 16384
#define MAXNAMESTR 1024
#define MAXHIST 10
#define MAXDAT 8
#define CHARHEIGHT 15
#define CHARWIDTH 9
#define MAXLINELEN 512
#define SCROLLBACK 256
#define rsp_BREAK_COUNT_MAX 32 /* XXX Should get it from rspctl.c */
#define CODEMODE_DIS 0
#define CODEMODE_FILE 1
#define DATAMODE_HEX 0
#define DATAMODE_SIGNED 1
#define DATAMODE_UNSIGNED 2
#define DATAMODE_VERTEX 3
void rsp_VisualData (u32 datastart);
static int GetSrcFile (u32 addr);
static int cmdWin, regWin, outWin, lstWin, datWin[MAXDAT];
static long outHeight, outLeft, outBottom, lstLeft, lstBottom;
static long lstBar, lstTotalLines;
static long datLeft[MAXDAT], datBottom[MAXDAT], datBar[MAXDAT];
static long datNumRows[MAXDAT], datHeight[MAXDAT], datWidth[MAXDAT];
static int outBar, datNumWin;
static int lstNumRows;
static long lstWidth, lstHeight;
static int cmdNumRows, regNumRows, outNumRows, numRows, numColumns;
static char regLineBuf[MAXLINELEN], *outLineBuf[SCROLLBACK];
static int outLineCount;
static boolean doResize = FALSE;
static char cmdStr[MAXLINELEN], cmdHist[MAXHIST][MAXLINELEN];
static int cmdLen, cmdPos, cmdHistNum, cmdHistPtr;
static long curWin;
static u32 oldPC, dataaddr;
static int mousedown, codemode, datMode[MAXDAT];
static char regOld[64][80], regNew[64][80], regChanged[64][80];
static char symFile[MAXSRCFILES][128];
static int symNumFiles, symFileNum[1024], symLineNum[1024], symCurFile;
static char nameStr[MAXNAMESTR][16];
static int nameNumStr;
static char *nameInst[1024][64], *nameCurr[64];
static int srcNumLines, srcNumMalloc;
static char *srcLine[MAXSRCLINES];
extern boolean Clear_Breakpoints;
extern unsigned int ForegroundColor;
extern unsigned int BackgroundColor;
extern unsigned int UpdateColor;
extern unsigned int HighlightColor;
static void
cmdLeftChar (void)
{
if (cmdPos > 0) {
cmdPos--;
}
}
static void
cmdRightChar (void)
{
if (cmdPos < cmdLen) {
cmdPos++;
}
}
static void
cmdLeftWord (void)
{
if (cmdPos > 0) {
do {
cmdPos--;
} while (cmdPos > 0 && cmdStr[cmdPos] == ' ');
while (cmdPos > 0 && cmdStr[cmdPos - 1] != ' ') {
cmdPos--;
}
}
}
static void
cmdRightWord (void)
{
if (cmdPos < cmdLen) {
while (cmdPos < cmdLen && cmdStr[cmdPos] != ' ') {
cmdPos++;
}
while (cmdPos < cmdLen && cmdStr[cmdPos] == ' ') {
cmdPos++;
}
}
}
static void
cmdDeleteChar (void)
{
if (cmdPos < cmdLen) {
strcpy (cmdStr + cmdPos, cmdStr + cmdPos + 1);
cmdLen--;
}
}
static void
cmdDeleteWord (void)
{
int savepos;
savepos = cmdPos;
cmdRightWord ();
if (cmdPos != savepos) {
strcpy (cmdStr + savepos, cmdStr + cmdPos);
cmdLen -= cmdPos - savepos;
cmdPos = savepos;
}
}
static void
cmdTranspose (void)
{
char tmpchar;
if (cmdPos > 0 && cmdPos < cmdLen) {
tmpchar = cmdStr[cmdPos - 1];
cmdStr[cmdPos - 1] = cmdStr[cmdPos];
cmdStr[cmdPos] = tmpchar;
}
}
static void
cmdUpHistory (void)
{
if ((cmdHistNum + 1) % MAXHIST != cmdHistPtr) {
cmdHistPtr = (cmdHistPtr + MAXHIST - 1) % MAXHIST;
strcpy (cmdStr, cmdHist[cmdHistPtr]);
cmdLen = strlen (cmdStr);
cmdPos = cmdLen;
}
}
static void
cmdDownHistory (void)
{
if (cmdHistPtr != cmdHistNum) {
cmdHistPtr = (cmdHistPtr + 1) % MAXHIST;
strcpy (cmdStr, cmdHist[cmdHistPtr]);
cmdLen = strlen (cmdStr);
cmdPos = cmdLen;
}
}
static void
cmdInsertChar (char ch)
{
memmove (cmdStr + cmdPos + 1, cmdStr + cmdPos, cmdLen - cmdPos);
cmdStr[cmdPos] = ch;
cmdLen++;
cmdPos++;
}
static void
cmdEnterHistory (char *line)
{
if (line[0] != '\0') {
strcpy (cmdHist[cmdHistNum], line);
cmdHistNum = (cmdHistNum + 1) % MAXHIST;
}
}
static void
lstSetBar (void)
{
int line;
if (codemode == CODEMODE_FILE) {
line = GetSrcFile (rsp_programCounter);
if (line != -1) {
lstBar = line - lstNumRows / 2;
}
}
/* GetSrcFile() may change codemode to CODEMODE_DIS */
if (codemode == CODEMODE_DIS) {
lstBar = (rsp_programCounter - 0x04001000) / 4 - lstNumRows / 2;
}
}
static void
cmdRedraw (void)
{
char buf[MAXLINELEN];
int width;
winset (cmdWin);
/*cpack (0x00ffffff); */
cpack(BackgroundColor);
clear ();
cpack (0x0000ff00);
sprintf (buf, "rsp> %s", cmdStr);
buf[cmdPos + 5] = '\0';
width = strwidth (buf);
if (curWin == 0) {
recti (5 + width, 4, 5 + width + 8, 4 + CHARHEIGHT);
} else {
rectfi (5 + width, 4, 5 + width + 8, 4 + CHARHEIGHT);
}
/* cpack (0x00000000); */
cpack(ForegroundColor);
sprintf (buf, "rsp> %s", cmdStr);
cmov2i (5, CHARHEIGHT);
charstr (buf);
swapbuffers ();
}
#define outRegWindow(s) strcpy (regNew[lineCount++], s);
static void
regDrawNew (void)
{
int i, j;
i128 regValue;
i32 gpregValue;
u32 readRegValue, writeRegValue;
int lineCount = 0;
int numChars, pcIndex;
pcIndex = (rsp_programCounter - 0x04001000) / 4;
if (pcIndex < 0 || pcIndex >= 1024) {
pcIndex = 0;
}
sprintf (regLineBuf, "VAC = 0x%012llx VCO = 0x%04x VCC = 0x%04x VCE = 0x%04x",
rsp_ACC[0]&VU_ACC_MASK, rsp_VCO, rsp_VCC, rsp_VCE);
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,
"%5.5s:", nameInst[pcIndex][i + 32]);
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, "%9.9s:%08x ",
nameInst[pcIndex][i], gpregValue);
if (((i + 1) % 4) == 0) {
outRegWindow (regLineBuf);
numChars = 0;
}
}
}
regDiff (void)
{
int i, j;
regDrawNew ();
for (i = 0; i < 64; i++) {
for (j = 0; j < 80; j++) {
regChanged[i][j] = regOld[i][j] != regNew[i][j];
regOld[i][j] = regNew[i][j];
}
}
}
static void
regRedraw (void)
{
int i, j, x, y;
winset (regWin);
/* cpack (0x00ffffff); */
cpack(BackgroundColor);
clear ();
regDrawNew ();
/* cpack (0x00ffff00); */
cpack(UpdateColor);
for (i = 0; i < 64; i++) {
y = i * CHARHEIGHT + 4;
for (j = 0; j < 80; j++) {
x = j * CHARWIDTH + 4;
if (regChanged[i][j]) {
rectfi (x, y, x + CHARWIDTH - 1, y + CHARHEIGHT - 1);
}
}
}
/* cpack (0x00000000); */
cpack(ForegroundColor);
for (i = 0; i < 64; i++) {
cmov2i (5, (i + 1) * CHARHEIGHT);
charstr (regNew[i]);
}
swapbuffers ();
}
static void
outRedraw (void)
{
int i, line, y, width;
winset (outWin);
/* cpack (0x00ffffff); */
cpack(BackgroundColor);
clear ();
/* cpack (0x00000000); */
cpack(ForegroundColor);
for (i = 0; i < outNumRows; i++) {
line = SCROLLBACK - outNumRows + i - outBar;
if (line >= 0 && line < SCROLLBACK) {
cmov2i (15, (i + 1) * CHARHEIGHT);
charstr (outLineBuf[line]);
}
}
move2i (10, 0);
draw2i (10, outHeight);
y = outHeight - outBar * outHeight / (SCROLLBACK - outNumRows);
recti (1, y - 1, 8, y - 20);
/* XXX I'm not sure we should have a cursor in this window: */
cpack (0x0000ff00);
width = strwidth (outLineBuf[SCROLLBACK - 1]) + 14;
y = (outNumRows + outBar - 1) * CHARHEIGHT + 4;
rectfi (width, y, width + 8, y + CHARHEIGHT);
swapbuffers ();
}
int ViewFile(char *filename)
{
int index = 0;
while(index < symNumFiles)
{
if (!strcmp(symFile[index], filename))
{
LoadSrcFile(index);
return 1;
}
index++;
}
rsp_fprintf(stdout, "File %s not found \n", filename);
ringbell();
return 1;
}
int
LoadSrcFile (int filenum)
{
FILE *f;
int line, pos;
char buf[MAXLINELEN], *fn, *s;
fn = symFile[filenum];
f = fopen (fn, "r");
if (f == NULL) {
rsp_fprintf(stdout,"Cannot open source file \"%s\".\n", fn);
return 0;
}
winset (lstWin);
sprintf (buf, "source (%s)", fn);
wintitle (buf);
line = 0;
while (1) {
if (line >= MAXSRCLINES) {
rsp_fprintf(stdout,"Source file \"%s\" has too many lines.\n", fn);
fclose (f);
return 0;
}
if (line >= srcNumMalloc) {
srcLine[srcNumMalloc++] = (char *)malloc (MAXLINELEN);
}
if (fgets (buf, MAXLINELEN - 1, f) == NULL) {
break;
}
buf[MAXLINELEN - 1] = '\0';
/* Remove trailing \n: */
buf[strlen (buf) - 1] = '\0';
/* Expand tabs: */
pos = 0;
for (s = buf; *s; s++) {
if (*s == '\t') {
do {
srcLine[line][pos++] = ' ';
} while (pos % 8 != 0);
} else {
srcLine[line][pos++] = *s;
}
}
srcLine[line][pos] = '\0';
line++;
}
srcNumLines = line;
lstTotalLines = line;
symCurFile = filenum;
fclose (f);
return 1;
}
static int
GetSrcFile (u32 addr)
{
int i, index;
if (addr < 0x04001000 || addr >= 0x04002000) {
rsp_fprintf(stdout,"Invalid PC address: 0x%08x\n", addr);
return 0;
}
index = (addr - 0x04001000) / 4;
if (symFileNum[index] == -1) {
rsp_fprintf(stdout,"No source information for address: 0x%08x\n", addr);
codemode = CODEMODE_DIS;
return -1;
}
if (symFileNum[index] != symCurFile) {
if (!LoadSrcFile (symFileNum[index])) {
return -1;
}
}
return symLineNum[index];
}
static void
lstRedraw (void)
{
u32 addr, value, breakaddr[rsp_BREAK_COUNT_MAX];
int enabled[rsp_BREAK_COUNT_MAX];
int i, j, y, y2, nbrk, line, pcline, index;
char cmd[32];
char buf[MAXLINELEN];
nbrk = rsp_ProcessorBreakpointGetAll (breakaddr, enabled);
winset (lstWin);
/* cpack (0x00ffffff); */
cpack(BackgroundColor);
clear ();
/* cpack (0x00000000); */
cpack(ForegroundColor);
move2i (10, 0);
draw2i (10, lstHeight);
if (codemode == CODEMODE_DIS) {
/* Draw PC green bar: */
cpack (0x0000ff00);
y = ((rsp_programCounter - 0x04001000) / 4 - lstBar) * CHARHEIGHT + 3;
rectfi (11, y, lstWidth, y + CHARHEIGHT);
y = (rsp_programCounter - 0x04001000) * lstHeight / 4096;
move2i (0, y);
draw2i (9, y);
move2i (0, y+1);
draw2i (9, y+1);
/* Draw red breakpoints: */
for (i = 0; i < nbrk; i++) {
if (breakaddr[i] == rsp_programCounter) {
if (enabled[i]) {
cpack (0x0000ffff);
} else {
continue;
}
} else {
if (enabled[i]) {
cpack (0x000000ff);
} else {
/* Changed this, kluster */
if (!Clear_Breakpoints)
cpack (0x0000007f);
else
/* cpack (0x00ffffff); */
cpack(BackgroundColor);
}
}
y = ((breakaddr[i] - 0x04001000) / 4 - lstBar) * CHARHEIGHT + 3;
rectfi (11, y, lstWidth, y + CHARHEIGHT);
y = (breakaddr[i] - 0x04001000) * lstHeight / 4096;
move2i (0, y);
draw2i (9, y);
move2i (0, y+1);
draw2i (9, y+1);
}
/* cpack (0x00000000); */
cpack(ForegroundColor);
addr = 0x04001000 + lstBar * 4;
for (i = 0; i < lstNumRows; i++, addr += 4) {
if (addr < 0x04001000 || addr >= 0x04002000) {
continue;
}
value = rsp_ExamineMemory (addr);
rsp_DisasmInst (value, cmd, addr);
cmov2i (16, (i + 1) * CHARHEIGHT);
sprintf (buf, "0x%08x: 0x%08x %s", addr, value, cmd);
charstr (buf);
}
} else {
/* Draw PC green bar: */
index = (rsp_programCounter - 0x04001000) / 4;
if (symFileNum[index] == symCurFile) {
pcline = symLineNum[index];
cpack (0x0000ff00);
y = (pcline - lstBar) * CHARHEIGHT + 3;
rectfi (11, y, lstWidth, y + CHARHEIGHT);
y = pcline * lstHeight / lstTotalLines;
move2i (0, y);
draw2i (9, y);
move2i (0, y+1);
draw2i (9, y+1);
}
/* Draw red breakpoints: */
for (i = 0; i < nbrk; i++) {
index = (breakaddr[i] - 0x04001000) / 4;
if (symFileNum[index] != symCurFile) {
continue;
}
if (breakaddr[i] == rsp_programCounter) {
if (enabled[i]) {
/* cpack (0x0000ffff); */
cpack(HighlightColor);
} else {
continue;
}
} else {
if (enabled[i]) {
cpack (0x000000ff);
} else {
/* changed this, kluster */
if (!Clear_Breakpoints)
cpack (0x0000007f);
else
/* cpack (0x00ffffff); */
cpack(BackgroundColor);
}
}
y = (symLineNum[index] - lstBar) * CHARHEIGHT + 3;
rectfi (11, y, lstWidth, y + CHARHEIGHT);
y = symLineNum[index] * lstHeight / lstTotalLines;
move2i (0, y);
draw2i (9, y);
move2i (0, y+1);
draw2i (9, y+1);
}
/* cpack (0x00000000); */
cpack(ForegroundColor);
if (pcline == -1) {
swapbuffers ();
return;
}
for (i = 0; i < lstNumRows; i++) {
line = lstBar + i;
if (line < 0 || line >= srcNumLines) {
continue;
}
cmov2i (16, (i + 1) * CHARHEIGHT);
charstr (srcLine[line]);
}
}
/* cpack (0x00000000); */
cpack(ForegroundColor);
y = lstBar * lstHeight / lstTotalLines;
y2 = (lstBar + lstNumRows + 1) * lstHeight / lstTotalLines;
recti (1, y, 8, y2);
swapbuffers ();
}
static int
datIsWindow (int winid)
{
int i;
for (i = 0; i < datNumWin; i++) {
if (winid == datWin[i]) {
return i;
}
}
return -1;
}
static void
datRedraw (int win)
{
u32 addr, value1, value2, value3, value4;
int i, j, y, y2, nbrk;
char buf[MAXLINELEN];
winset (datWin[win]);
/* cpack (0x00ffffff); */
cpack(BackgroundColor);
clear ();
/* cpack (0x00000000); */
cpack(ForegroundColor);
move2i (10, 0);
draw2i (10, datHeight[win]);
y = ((int)datBar[win] - (int)dataaddr) * datHeight[win] / 4096;
y2 = ((int)datBar[win] + (datNumRows[win] - 1)*16 - (int)dataaddr) *
datHeight[win] / 4096;
recti (1, y, 8, y2);
addr = datBar[win];
for (i = 0; i < datNumRows[win]; i++, addr += 16) {
if (addr < dataaddr || addr >= dataaddr + 4096) {
continue;
}
value1 = rsp_ExamineMemory (addr);
value2 = rsp_ExamineMemory (addr + 4);
value3 = rsp_ExamineMemory (addr + 8);
value4 = rsp_ExamineMemory (addr + 12);
cmov2i (16, (i + 1) * CHARHEIGHT);
switch (datMode[win]) {
case DATAMODE_HEX:
sprintf (buf,
"0x%08x: %04x %04x %04x %04x %04x %04x %04x %04x",
addr,
value1 >> 16, value1 & 0xffff,
value2 >> 16, value2 & 0xffff,
value3 >> 16, value3 & 0xffff,
value4 >> 16, value4 & 0xffff);
break;
case DATAMODE_SIGNED:
sprintf (buf,"0x%08x: %6d %6d %6d %6d %6d %6d %6d %6d",
addr,
(int)(signed short)(value1 >> 16),
(int)(signed short)(value1 & 0xffff),
(int)(signed short)(value2 >> 16),
(int)(signed short)(value2 & 0xffff),
(int)(signed short)(value3 >> 16),
(int)(signed short)(value3 & 0xffff),
(int)(signed short)(value4 >> 16),
(int)(signed short)(value4 & 0xffff));
break;
case DATAMODE_UNSIGNED:
sprintf (buf,"0x%08x: %5u %5u %5u %5u %5u %5u %5u %5u",
addr,
value1 >> 16, value1 & 0xffff,
value2 >> 16, value2 & 0xffff,
value3 >> 16, value3 & 0xffff,
value4 >> 16, value4 & 0xffff);
break;
case DATAMODE_VERTEX:
if ((addr - dataaddr) % 32 == 0) {
sprintf (buf, "0x%08x: x=%g, y=%g, z=%g, w=%g",
addr,
(signed short)(value1 >> 16) + (1/65536.0) *
(unsigned short)(value3 >> 16),
(signed short)(value1 & 0xffff) + (1/65536.0) *
(unsigned short)(value3 & 0xffff),
(signed short)(value2 >> 16) + (1/65536.0) *
(unsigned short)(value4 >> 16),
(signed short)(value2 & 0xffff) + (1/65536.0) *
(unsigned short)(value4 & 0xffff));
} else {
sprintf (buf, "0x%08x: scr=(%d,%d), tex=(%d,%d), "
"cc=0x%x, <%d,%d,%d,%d>",
addr,
(signed int)(unsigned short)(value1 >> 16),
(signed int)(unsigned short)(value1 & 0xffff),
(signed int)(unsigned short)(value2 >> 16),
(signed int)(unsigned short)(value2 & 0xffff),
(signed int)(unsigned char)(value3 >> 24),
(signed int)(unsigned char)((value4 >> 16) & 0xff),
(signed int)(unsigned char)((value4 >> 24) & 0xff),
(signed int)(unsigned char)((value3 >> 0) & 0xff),
(signed int)(unsigned char)((value3 >> 8) & 0xff));
}
break;
}
charstr (buf);
}
swapbuffers ();
}
static void
datNewWindow (int copyfrom, int split)
{
if (datNumWin == MAXDAT) {
ringbell ();
return;
}
if (copyfrom != -1) {
if (split) {
prefposition (
datLeft[copyfrom],
datLeft[copyfrom] + datWidth[copyfrom],
datBottom[copyfrom],
datBottom[copyfrom] + datHeight[copyfrom] / 2 - 20);
} else {
prefposition (
datLeft[copyfrom] + 20,
datLeft[copyfrom] + datWidth[copyfrom] + 20,
datBottom[copyfrom] - 20,
datBottom[copyfrom] + datHeight[copyfrom] - 20);
}
} else {
prefposition (736 + datNumWin * 20, 1270 + datNumWin * 20,
10 - datNumWin * 20, 460 - datNumWin * 20);
}
datWin[datNumWin] = winopen ("data");
winconstraints ();
RGBmode ();
doublebuffer ();
gconfig ();
getorigin (&datLeft[datNumWin], &datBottom[datNumWin]);
getsize (&datWidth[datNumWin], &datHeight[datNumWin]);
ortho2 (0, datWidth[datNumWin], datHeight[datNumWin], 0);
datNumRows[datNumWin] = datHeight[datNumWin] / CHARHEIGHT;
if (copyfrom != -1) {
datMode[datNumWin] = datMode[copyfrom];
datBar[datNumWin] = datBar[copyfrom];
} else {
datMode[datNumWin] = DATAMODE_HEX;
}
qenter (REDRAW, datWin[datNumWin]);
datNumWin++;
if (split) {
winset (datWin[copyfrom]);
winposition (
datLeft[copyfrom],
datLeft[copyfrom] + datWidth[copyfrom],
datBottom[copyfrom] + datHeight[copyfrom] / 2 + 20,
datBottom[copyfrom] + datHeight[copyfrom]);
}
}
static void
rsp_SymbolInit(void)
{
int i;
symNumFiles = 0;
for (i = 0; i < 1024; i++) {
symFileNum[i] = -1;
symLineNum[i] = -1;
}
codemode = CODEMODE_DIS;
symCurFile = -1;
lstBar = 0;
lstTotalLines = 1024;
}
boolean
rsp_VisualInit(void)
{
long x, y;
int i, j;
foreground ();
prefposition (10, 720, 960, 985);
cmdWin = winopen ("command input");
RGBmode ();
doublebuffer ();
gconfig ();
getsize (&x, &y);
ortho2 (0, x, y, 0);
cmdNumRows = y / CHARHEIGHT;
prefposition (10, 720, 340, 920);
regWin = winopen ("registers");
RGBmode ();
doublebuffer ();
gconfig ();
getsize (&x, &y);
ortho2 (0, x, y, 0);
regNumRows = y / CHARHEIGHT;
prefposition (10, 720, 10, 300);
outWin = winopen ("command output");
RGBmode ();
doublebuffer ();
gconfig ();
getorigin (&outLeft, &outBottom);
getsize (&x, &outHeight);
ortho2 (0, x, outHeight, 0);
outNumRows = outHeight / CHARHEIGHT;
prefposition (736, 1270, 500, 985);
lstWin = winopen ("source");
winconstraints ();
RGBmode ();
doublebuffer ();
gconfig ();
getorigin (&lstLeft, &lstBottom);
getsize (&lstWidth, &lstHeight);
ortho2 (0, lstWidth, lstHeight, 0);
lstNumRows = lstHeight / CHARHEIGHT;
datNewWindow (-1, 0);
datNumWin = 1;
qdevice (KEYBD);
qdevice (LEFTMOUSE);
qdevice (MIDDLEMOUSE);
qdevice (RIGHTMOUSE);
qdevice (MOUSEY);
qdevice (LEFTARROWKEY);
qdevice (RIGHTARROWKEY);
qdevice (UPARROWKEY);
qdevice (DOWNARROWKEY);
qdevice (WINQUIT);
qdevice (WINSHUT);
qdevice (WINFREEZE);
qdevice (WINTHAW);
numColumns = 80;
numRows = 25;
outBar = 0;
curWin = 0;
rsp_VisualData (0x04000000);
srcNumLines = 0;
srcNumMalloc = 0;
rsp_SymbolInit ();
for (i = 0; i < SCROLLBACK; i++) {
outLineBuf[i] = (char *)malloc(MAXLINELEN);
outLineBuf[i][0] = '\0';
}
for (i = 0; i < 32; i++) {
sprintf (nameStr[i], "$%d", i);
sprintf (nameStr[i+32], "$v%d", i);
}
nameNumStr = 64;
for (i = 0; i < 64; i++) {
nameCurr[i] = nameStr[i];
}
for (j = 0; j < 1024; j++) {
for (i = 0; i < 64; i++) {
nameInst[j][i] = nameCurr[i];
}
}
/* Cause sometimes the window doesn't get the redraw msg: */
qenter (REDRAW, cmdWin);
qenter (REDRAW, regWin);
qenter (REDRAW, outWin);
qenter (REDRAW, lstWin);
for (i = 0; i < datNumWin; i++) {
qenter (REDRAW, datWin[i]);
}
regDiff (); /* So 0's aren't highlighted */
regDiff ();
return(TRUE);
}
static int
HandleDevice (long dev, short val)
{
int i, j, x, y, pcfile, menu, win;
u32 addr;
long pup;
char buf[MAXLINELEN];
switch (dev) {
case REDRAW:
winset (val);
if (val == cmdWin) {
cmdRedraw ();
} else if (val == regWin) {
regRedraw ();
} else if (val == outWin) {
outRedraw ();
} else if (val == lstWin) {
reshapeviewport ();
getorigin (&lstLeft, &lstBottom);
getsize (&lstWidth, &lstHeight);
ortho2 (0, lstWidth, lstHeight, 0);
lstNumRows = lstHeight / CHARHEIGHT;
lstRedraw ();
} else if ((win = datIsWindow (val)) != -1) {
reshapeviewport ();
getorigin (&datLeft[win], &datBottom[win]);
getsize (&datWidth[win], &datHeight[win]);
ortho2 (0, datWidth[win], datHeight[win], 0);
datNumRows[win] = datHeight[win] / CHARHEIGHT;
datRedraw (win);
}
break;
case INPUTCHANGE:
curWin = val;
cmdRedraw ();
break;
case RIGHTMOUSE:
if (!val) {
break;
}
if (curWin == cmdWin) {
pup = newpup ();
addtopup (pup, "Commands %t");
addtopup (pup, "Step");
addtopup (pup, "Continue");
addtopup (pup, "Run");
addtopup (pup, "Info %l");
addtopup (pup, "Quit");
menu = dopup (pup);
freepup (pup);
switch (menu) {
case 1: strcpy (cmdStr, "step"); return 1;
case 2: strcpy (cmdStr, "continue"); return 1;
case 3: strcpy (cmdStr, "run"); return 1;
case 4: strcpy (cmdStr, "info"); return 1;
case 5: strcpy (cmdStr, "quit"); return 1;
}
} else if (curWin == lstWin) {
pup = newpup ();
addtopup (pup, "Source Options %t");
if (rsp_GetVerbose ()) {
addtopup (pup, "Silent");
} else {
addtopup (pup, "Verbose");
}
if (codemode == CODEMODE_DIS) {
addtopup (pup, "View source");
} else {
addtopup (pup, "View disassembly %l");
pcfile = symFileNum[(rsp_programCounter - 0x04001000) / 4];
for (i = 0; i < symNumFiles; i++) {
sprintf (buf, "%s%s", symFile[i],
(pcfile == i) ? " (PC)":"");
addtopup (pup, buf);
}
}
menu = dopup (pup);
if (menu == 1) {
rsp_SetVerbose (!rsp_GetVerbose ());
} else if (menu == 2) {
if (codemode == CODEMODE_DIS) {
if (symNumFiles == 0) {
rsp_fprintf(stdout,"No symbol information.\n");
ringbell ();
} else {
codemode = CODEMODE_FILE;
}
} else {
codemode = CODEMODE_DIS;
}
lstSetBar ();
lstRedraw ();
} else if (menu > 2) {
LoadSrcFile (menu - 3);
if (symCurFile == pcfile) {
lstSetBar ();
} else {
lstBar = 0;
}
lstRedraw ();
}
freepup (pup);
} else if ((win = datIsWindow (curWin)) != -1) {
pup = newpup ();
addtopup (pup, "Data Options %t");
addtopup (pup, "View as hex");
addtopup (pup, "View as signed decimal");
addtopup (pup, "View as unsigned decimal");
addtopup (pup, "View as vertices %l");
addtopup (pup, "Clone window");
addtopup (pup, "Split window");
menu = dopup (pup);
switch (menu) {
case 1: datMode[win] = DATAMODE_HEX; break;
case 2: datMode[win] = DATAMODE_SIGNED; break;
case 3: datMode[win] = DATAMODE_UNSIGNED; break;
case 4: datMode[win] = DATAMODE_VERTEX; break;
case 5: datNewWindow (win, 0); break;
case 6: datNewWindow (win, 1); break;
}
freepup (pup);
datRedraw (win);
} else {
pup = newpup ();
addtopup (pup, "No Options for This Window %t");
dopup (pup);
freepup (pup);
}
break;
case MIDDLEMOUSE:
/* Repeat last command */
if (val) {
strcpy (cmdStr, "");
return 1;
}
break;
case LEFTMOUSE:
if (val) {
if (curWin == outWin) {
x = getvaluator (MOUSEX) - outLeft;
if (x < 10) {
mousedown = TRUE;
}
} else if (curWin == lstWin) {
x = getvaluator (MOUSEX) - lstLeft;
y = getvaluator (MOUSEY) - lstBottom;
if (x < 10) {
mousedown = TRUE;
} else {
y = (lstHeight - y - 5) / CHARHEIGHT;
if (codemode == CODEMODE_DIS) {
addr = 0x04001000 + (lstBar + y) * 4;
} else {
for (i = 0; i < 1024; i++) {
if (symFileNum[i] == symCurFile &&
symLineNum[i] == lstBar + y) {
addr = 0x04001000 + i * 4;
break;
}
}
if (i == 1024) {
rsp_fprintf(stdout,"No code for that line.\n");
ringbell();
break;
}
}
i = rsp_ProcessorBreakpointCheck (addr);
if (i == 0) {
rsp_ProcessorBreakpointInstall (addr, TRUE);
} else {
j = rsp_ProcessorBreakpointNumber (addr);
rsp_ProcessorBreakpointEnable (j, i == 2);
}
lstRedraw ();
break;
}
} else if ((win = datIsWindow (curWin)) != -1) {
x = getvaluator (MOUSEX) - datLeft[win];
if (x < 10) {
mousedown = TRUE;
}
}
} else {
mousedown = FALSE;
}
/*FALLTHROUGH*/
case MOUSEY:
if (mousedown) {
if (curWin == outWin) {
y = getvaluator (MOUSEY) - outBottom;
outBar = y * (SCROLLBACK - outNumRows) / outHeight;
if (outBar < 0) {
outBar = 0;
}
if (outBar > SCROLLBACK - outNumRows) {
outBar = SCROLLBACK - outNumRows;
}
if (qtest () != MOUSEY) {
outRedraw ();
}
} else if (curWin == lstWin) {
y = lstHeight - getvaluator (MOUSEY) + lstBottom;
lstBar = y * lstTotalLines / lstHeight - lstNumRows / 2;
if (qtest () != MOUSEY) {
lstRedraw ();
}
} else if ((win = datIsWindow (curWin)) != -1) {
y = datHeight[win] - getvaluator (MOUSEY) + datBottom[win];
datBar[win] = (y * 256 / datHeight[win] - datNumRows[win] /
2) * 16 + dataaddr;
if (qtest () != MOUSEY) {
datRedraw (win);
}
}
}
break;
case WINSHUT:
if ((win = datIsWindow (val)) != -1) {
winclose (datWin[win]);
for (i = win; i < datNumWin - 1; i++) {
datWin[i] = datWin[i + 1];
datLeft[i] = datLeft[i + 1];
datBottom[i] = datBottom[i + 1];
datBar[i] = datBar[i + 1];
datNumRows[i] = datNumRows[i + 1];
datHeight[i] = datHeight[i + 1];
datWidth[i] = datWidth[i + 1];
datMode[i] = datMode[i + 1];
}
datNumWin--;
if (datNumWin == 0) {
strcpy (cmdStr, "quit");
return 1;
}
} else {
strcpy (cmdStr, "quit");
return 1;
}
break;
case WINQUIT:
strcpy (cmdStr, "quit");
return 1;
}
return 0;
}
int rsp_VisualGets(char *s, int n)
{
long dev;
int altkey;
short val;
cmdLen = 0;
cmdPos = 0;
cmdHistPtr = cmdHistNum;
cmdStr[0] = '\0';
cmdHist[cmdHistPtr][0] = '\0';
cmdRedraw ();
while (TRUE) {
dev = qread (&val);
altkey = getbutton (LEFTALTKEY) || getbutton (RIGHTALTKEY);
if (dev == KEYBD) {
if (val == '\r') {
strcpy (s, cmdStr);
strcat (s, "\n");
cmdEnterHistory (cmdStr);
return 0;
} else if (val == 27) { /* ESC */
return -1;
} else if (val == '\b' || val == 127) { /* Backspace or delete */
if (cmdPos > 0) {
cmdLeftChar ();
cmdDeleteChar ();
}
} else if (val == 4) { /* ^D */
cmdDeleteChar ();
} else if (val == 1) { /* ^A */
cmdPos = 0;
} else if (val == 2) { /* ^B */
cmdLeftChar ();
} else if (val == 5) { /* ^E */
cmdPos = cmdLen;
} else if (val == 6) { /* ^F */
cmdRightChar ();
} else if (val == 14) { /* ^N */
cmdDownHistory ();
} else if (val == 16) { /* ^P */
cmdUpHistory ();
} else if (val == 20) { /* ^T */
cmdTranspose ();
} else if (val == 'b' && altkey) {
cmdLeftWord ();
} else if (val == 'd' && altkey) {
cmdDeleteWord ();
} else if (val == 'f' && altkey) {
cmdRightWord ();
} else if (cmdLen < n) {
cmdInsertChar (val);
}
cmdStr[cmdLen] = '\0';
cmdRedraw ();
} else if (dev == LEFTARROWKEY) {
if (val) {
if (getbutton (CTRLKEY)) {
cmdLeftWord ();
} else {
cmdLeftChar ();
}
cmdRedraw ();
}
} else if (dev == RIGHTARROWKEY) {
if (val) {
if (getbutton (CTRLKEY)) {
cmdRightWord ();
} else {
cmdRightChar ();
}
cmdRedraw ();
}
} else if (dev == UPARROWKEY) {
if (val) {
cmdUpHistory ();
cmdRedraw ();
}
} else if (dev == DOWNARROWKEY) {
if (val) {
cmdDownHistory ();
cmdRedraw ();
}
} else {
if (HandleDevice (dev, val)) {
strcpy (s, cmdStr);
strcat (s, "\n");
cmdEnterHistory (cmdStr);
return 0;
}
}
}
}
boolean
rsp_VisualUpdate(void)
{
long dev;
short val;
int i;
while (qtest ()) {
dev = qread (&val);
if (dev == KEYBD) {
if (val == 27 || val == 3) { /* Stop running process */
rsp_controlReg = Flag(rsp_controlReg, rsp_CtlHaltMask);
}
} else {
HandleDevice (dev, val);
}
}
if (rsp_GetVerbose ()) {
if (rsp_programCounter != oldPC) {
oldPC = rsp_programCounter;
lstSetBar ();
}
/* XXX: Maybe this regDiff() should only happen if the PC changes: */
regDiff ();
regRedraw ();
lstRedraw ();
for (i = 0; i < datNumWin; i++) {
datRedraw (i);
}
}
return TRUE;
}
void
rsp_VisualClear(void)
{
}
void
rsp_VisualPrint(FILE *out, char *fmt, va_list ap)
{
int i, j, len, lastlen;
char *last, buf[MAXLINELEN];
vsprintf (buf, fmt, ap);
len = strlen (buf);
last = outLineBuf[SCROLLBACK - 1];
lastlen = strlen (last);
for (i = 0; i < len; i++) {
if (buf[i] == '\n') {
last = outLineBuf[0];
for (j = 0; j < SCROLLBACK - 1; j++) {
outLineBuf[j] = outLineBuf[j + 1];
}
outLineBuf[SCROLLBACK - 1] = last;
lastlen = 0;
} else {
last[lastlen] = buf[i];
lastlen++;
}
last[lastlen] = '\0';
}
outRedraw ();
}
void
rsp_VisualCleanup(void)
{
}
void
rsp_VisualResize(void)
{
}
void
rsp_VisualData (u32 datastart)
{
char buf[MAXLINELEN];
int i;
dataaddr = datastart;
for (i = 0; i < datNumWin; i++) {
datBar[i] = dataaddr;
winset (datWin[i]);
sprintf (buf, "data (0x%08x - 0x%08x)", dataaddr, dataaddr + 4096);
wintitle (buf);
datRedraw (i);
}
}
void
rsp_VisualSymbolTable (char *fn)
{
FILE *f;
int i, line, reg;
char buf[256], filename[128], symname[128];
u32 addr;
f = fopen (fn, "r");
if (f == NULL) {
rsp_fprintf(stdout,"Could not open table file \"%s\".\n", fn);
return;
}
codemode = CODEMODE_FILE;
while (fgets (buf, 256, f) != NULL) {
if (sscanf (buf, "line 0x%x %s %d", &addr, &filename, &line) == 3) {
if (addr < 0x04001000 || addr >= 0x04002000) {
rsp_fprintf(stdout,"Invalid address in symbol table: 0x%08x.\n",
addr);
break;
}
while (filename[0] == '.' && filename[1] == '/') {
strcpy (filename, filename + 2);
}
addr = (addr - 0x04001000) / 4;
for (i = 0; i < symNumFiles; i++) {
if (strcmp (filename, symFile[i]) == 0) {
break;
}
}
if (i == symNumFiles) {
if (symNumFiles == MAXSRCFILES) {
rsp_fprintf(stdout,"Too many different files in symbol "
"table.\n");
break;
}
strcpy (symFile[i], filename);
symNumFiles++;
}
symFileNum[addr] = i;
symLineNum[addr] = line - 1;
for (i = 0; i < 64; i++) {
nameInst[addr][i] = nameCurr[i];
}
} else if (sscanf (buf, "sname %s %d", &symname, ®) == 2) {
for (i = 0; i < nameNumStr; i++) {
if (strcmp (nameStr[i], symname) == 0) {
break;
}
}
if (i == nameNumStr) {
if (nameNumStr == MAXNAMESTR) {
fprintf (stderr, "Too many names for registers.\n");
break;
}
strcpy (nameStr[i], symname);
nameNumStr++;
}
nameCurr[reg] = nameStr[i];
} else if (sscanf (buf, "vname %s %d", &symname, ®) == 2) {
for (i = 0; i < nameNumStr; i++) {
if (strcmp (nameStr[i], symname) == 0) {
break;
}
}
if (i == nameNumStr) {
if (nameNumStr == MAXNAMESTR) {
fprintf (stderr, "Too many names for registers.\n");
break;
}
strcpy (nameStr[i], symname);
nameNumStr++;
}
nameCurr[reg + 32] = nameStr[i];
} else if (sscanf (buf, "unname %s", &symname) == 1) {
for (i = 0; i < 64; i++) {
if (strcmp (nameCurr[i], symname) == 0) {
break;
}
}
if (i == 64) {
fprintf (stderr, "Unnamed symbol not found (%s) in file [%s] at line %d.\n", symname, filename, line);
} else {
nameCurr[i] = nameStr[i];
}
} else if (sscanf (buf, "entry %s", &symname) == 1) {
} else if (sscanf (buf, "end %s", &symname) == 1) {
} else {
break;
}
}
lstSetBar ();
fclose (f);
}
/*
* return register number if name matches a register name
* if no names matched return -1
* if name is ambiguous return -2
*/
int
rsp_VisualNameInst(char *name)
{
int pcIndex, regnum, regreturn=-1, gotone=0;;
pcIndex = (rsp_programCounter - 0x04001000) / 4;
for (regnum=0; regnum<64; regnum++)
if (!strncmp(name,nameInst[pcIndex][regnum],strlen(name))) {
if (gotone)
regreturn=-2;
else {
regreturn=regnum;
gotone=1;
}
}
return regreturn;
}