rdp2read.c
46.8 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
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
/**************************************************************************
* *
* 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: rdp2read.c
* Creator: hsa@sgi.com
* Create Date: Wed Jul 27 13:25:47 PDT 1994
*
* This program reads in a RDP command stream and prints out a 'readable'
* version of it. Also does some checks for common errors in the
* display list.
*
*/
#include <stdio.h>
#include <unistd.h>
#ifdef __sgi__
#include <bstring.h>
#endif
#include <string.h>
#include "mbi.h"
#define UsageString "<rdp binfile> [<ramfile>]"
#ifndef TRUE
# define TRUE 1
#endif
#ifndef FALSE
# define FALSE 0
#endif
#ifndef ABS
#define ABS(x) ((x) > 0 ? (x) : (-(x)))
#endif
#ifndef MAX
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#endif
#define MAX_HISTORY 40
#define STL_PREC (1 << 21)
#define W_PREC ((unsigned)(1 << 31))
#define Z_PREC (1 << 16)
#define RGBA_PREC (1 << 16)
#define MAX_COORD_X ((float) (1 << 11) - 1)
#define MIN_COORD_X (- (float) (1 << 11))
#define MAX_COORD_Y ((float) (1 << 11) - 1)
#define MIN_COORD_Y (- (float) (1 << 11))
#define D_COMBINE "combine"
#define D_TEX0 "tex0"
#define D_TEX1 "tex1"
#define D_PRIM "prim"
#define D_SHADE "shade"
#define D_ENV "env"
#define D_CENTER "center"
#define D_SCALE "scale"
#define D_COMB_ALPHA "combined_alpha"
#define D_TEX0_ALPHA "tex0_alpha"
#define D_TEX1_ALPHA "tex1_alpha"
#define D_PRIM_ALPHA "prim_alpha"
#define D_SHADE_ALPHA "shade_alpha"
#define D_ENV_ALPHA "env_alpha"
#define D_LOD_FRAC "lod_frac"
#define D_PRIM_LOD_FRAC "prim_lod_frac"
#define D_NOISE "noise"
#define D_CONV_K4 "k4"
#define D_CONV_K5 "k5"
#define D_ONE_PT_OH "1.0"
#define D_ZERO "0.0"
#ifdef __sgi__
typedef unsigned char u8;
typedef unsigned short int u16;
typedef unsigned long int u32;
#endif
typedef int bool;
typedef char i8;
typedef short int i16;
typedef long int i32;
typedef struct {
struct {
unsigned int cmd: 8; /* command */
unsigned int tile: 3; /* tile number */
unsigned int npa: 1; /* non-primitive attribute command */
unsigned int prim: 1; /* primitive command */
unsigned int lbt: 1; /* load block/tile command */
unsigned int sts: 1; /* set tile/tile size command */
} pc[MAX_HISTORY]; /* previous commands, circular buffer */
int curr_cmd; /* index of current command */
int n_cmd; /* number of commands processed so far */
} SyncWarnings;
/*
* G l o b a l s
*/
static u8 DRAM[2048 * 1024];
static bool do_verbose = FALSE;
static u32 NumPrimitives = 0;
static SyncWarnings SyncW;
static int nWarnings = 0;
static int nErrors = 0;
static int nClocks = 0;
static int nPrimClocks = 0;
static int nAttClocks = 0;
static int nLoadClocks = 0;
static int nSyncClocks = 0;
/*
* F u n c t i o n s
*/
/*
* Classify command as non-primitive attribute, which are
* not buffered and so must be explicitly synced.
*/
static int
is_npa_cmd( int cmd )
{
switch(cmd)
{
case G_NOOP:
case G_SETCIMG:
case G_SETZIMG:
case G_SETTIMG:
case G_SETCOMBINE:
case G_SETENVCOLOR:
case G_SETBLENDCOLOR:
case G_SETFOGCOLOR:
case G_SETFILLCOLOR:
case G_RDPSETOTHERMODE:
/* case G_SETSCISSOR: */
case G_SETCONVERT:
case G_SETKEYR:
case G_SETKEYGB:
return(1);
default:
return(0);
}
}
/*
* Classify as triangle command
*/
static int
is_tri_cmd( int cmd )
{
switch(cmd)
{
case G_TRI_FILL:
case G_TRI_SHADE:
case G_TRI_TXTR:
case G_TRI_SHADE_TXTR:
case G_TRI_FILL_ZBUFF:
case G_TRI_SHADE_ZBUFF:
case G_TRI_TXTR_ZBUFF:
case G_TRI_SHADE_TXTR_ZBUFF:
return(1);
default:
return(0);
}
}
/*
* classify as texture rectangle command
*/
static int
is_tex_rect_cmd( int cmd )
{
switch(cmd)
{
case G_TEXRECTFLIP:
case G_TEXRECT:
return(1);
default:
return(0);
}
}
/*
* Classify as rectangle command
*/
static int
is_rect_cmd( int cmd )
{
if(is_tex_rect_cmd(cmd) || cmd == G_FILLRECT)
return(1);
else
return(0);
}
/*
* Classify command as load block or load tile
*/
static int
is_lbt_cmd( int cmd )
{
switch(cmd)
{
case G_LOADTILE:
case G_LOADBLOCK:
case G_LOADTLUT:
return(1);
default:
return(0);
}
}
/*
* classify comand as primitive
*/
static int
is_prim_cmd( int cmd )
{
if(is_rect_cmd(cmd) || is_tri_cmd(cmd) || is_lbt_cmd(cmd))
return(1);
else
return(0);
}
/*
* Classify command as set_tile or set_tile_size
*/
static int
is_sts_cmd( int cmd )
{
switch(cmd)
{
case G_SETTILE:
case G_SETTILESIZE:
return(1);
default:
return(0);
}
}
/*
* Search through last MAX_HISTORY commands, looking for primitive
* command and noting if pipe or full sync command was found first.
*/
static int
no_sync_since_prim( void )
{
int indx, i, sync_found = 0, prim_found = 0;
if(SyncW.n_cmd < 1)
return(0);
indx = SyncW.curr_cmd - 1;
if(indx < 0)
indx = MAX_HISTORY - 1;
for(i = 0; i < SyncW.n_cmd; i++)
{
/* printf("SyncW.pc[%d].cmd = %d\n", indx, SyncW.pc[indx].cmd); */
if(SyncW.pc[indx].cmd == G_RDPFULLSYNC ||
SyncW.pc[indx].cmd == G_RDPPIPESYNC)
++sync_found;
else if(SyncW.pc[indx].prim)
{
++prim_found;
break;
}
--indx;
if(indx < 0)
indx = MAX_HISTORY-1;
}
/* printf("sync_found = %d\n", sync_found); */
return(!sync_found && prim_found);
}
/*
* Search through last MAX_HISTORY commands, looking for primitive
* command and noting if load sync command was found first.
*/
static int
no_load_sync_since_prim( void )
{
int indx, i, sync_found = 0, prim_found = 0;
if(SyncW.n_cmd < 1)
return(0);
indx = SyncW.curr_cmd - 1;
if(indx < 0)
indx = MAX_HISTORY - 1;
for(i = 0; i < SyncW.n_cmd; i++)
{
/* printf("SyncW.pc[%d].cmd = %d\n", indx, SyncW.pc[indx].cmd); */
if(SyncW.pc[indx].cmd == G_RDPLOADSYNC ||
SyncW.pc[indx].cmd == G_RDPFULLSYNC ||
SyncW.pc[indx].cmd == G_RDPPIPESYNC)
++sync_found;
else if(SyncW.pc[indx].prim)
{
++prim_found;
break;
}
--indx;
if(indx < 0)
indx = MAX_HISTORY-1;
}
/* printf("sync_found = %d\n", sync_found); */
return(!sync_found && prim_found);
}
/*
* Search through last MAX_HISTORY commands, looking for primitive
* command and noting if tile sync command was found before primitive
* referencing given tile number.
*/
static int
no_tile_sync_since_prim( int tile )
{
int indx, i, sync_found = 0, prim_found = 0;
if(SyncW.n_cmd < 1)
return(0);
indx = SyncW.curr_cmd - 1;
if(indx < 0)
indx = MAX_HISTORY - 1;
for(i = 0; i < SyncW.n_cmd; i++)
{
/* printf("SyncW.pc[%d].cmd = %d\n", indx, SyncW.pc[indx].cmd); */
if(SyncW.pc[indx].cmd == G_RDPTILESYNC ||
SyncW.pc[indx].cmd == G_RDPFULLSYNC ||
SyncW.pc[indx].cmd == G_RDPPIPESYNC ||
SyncW.pc[indx].cmd == G_RDPLOADSYNC)
++sync_found;
else if(SyncW.pc[indx].prim && (SyncW.pc[indx].tile == tile))
{
++prim_found;
break;
}
--indx;
if(indx < 0)
indx = MAX_HISTORY-1;
}
/* printf("sync_found = %d\n", sync_found); */
return(!sync_found && prim_found);
}
/*
* check_for_syncs:
*
* Check current command against recent history of commands
*/
static void
check_for_syncs( void )
{
int cur_cmd;
int tile;
cur_cmd = SyncW.pc[SyncW.curr_cmd].cmd;
tile = SyncW.pc[SyncW.curr_cmd].tile;
/* if current command is non-prim attribute,
and no pipe/full sync since last primitive,
print warning.
*/
if(is_npa_cmd(cur_cmd) && no_sync_since_prim())
{
printf("******* WARNING: no pipe or full sync between last primitive and current\n");
printf("******* attribute change.\n\n");
++nWarnings;
}
/* if current command is load block/tile, and no load
sync between last primitive and current command,
print warning.
*/
if(is_lbt_cmd(cur_cmd) && no_load_sync_since_prim())
{
printf("******* WARNING: no load sync between last primitive and current\n");
printf("******* load.\n\n");
++nWarnings;
}
/* if current command is set tile/tile_size, and previous
primitive used that tile, and no tile sync before
current command, print warning.
*/
if(is_sts_cmd(cur_cmd) && no_tile_sync_since_prim(tile))
{
printf("******* WARNING: no tile sync between last primitive that used this tile(%d)\n", tile);
printf("******* and current tile setting.\n\n");
++nWarnings;
}
}
static void
dump_edge_coef(FILE *in, u32 gfx0, u32 gfx1)
{
i8 dir, level, tile;
i16 YL, YM, YH;
float yl, ym, yh;
i32 XL, XH, XM;
float xl, xh, xm;
i32 DxLDy, DxHDy, DxMDy;
float dxhdy, dxldy, dxmdy;
u32 buffer[8];
float x[3], y[3], area, dy1, dy2, add_area, sub_area;
int i, appx_clks;
float dx1, dx2;
dir = (gfx0 & 0x00800000) >> 23;
level = (gfx0 & 0x00380000) >> 19;
tile = (gfx0 & 0x00070000) >> 16;
YL = (gfx0 & 0x0000ffff);
YM = ((gfx1 & 0xffff0000) >> 16);
YH = (gfx1 & 0x0000ffff);
fread(buffer, sizeof(u32), 6, in); /* we already have gfx0, gfx1... */
XL = *((i32 *) &(buffer[0]));
DxLDy = *((i32 *) &(buffer[1]));
XH = *((i32 *) &(buffer[2]));
DxHDy = *((i32 *) &(buffer[3]));
XM = *((i32 *) &(buffer[4]));
DxMDy = *((i32 *) &(buffer[5]));
yl = (float)YL/4.0;
ym = (float)YM/4.0;
yh = (float)YH/4.0;
xl = (float)XL / 65536.0;
xm = (float)XM / 65536.0;
xh = (float)XH / 65536.0;
dxhdy = (float) DxHDy / 65536.0;
dxldy = (float) DxLDy / 65536.0;
dxmdy = (float) DxMDy / 65536.0;
fprintf(stdout,"\n\t Edge coefficients:\n");
fprintf(stdout,"\t\tdir = %d level = %d tile = %d\n",
dir, level, tile);
fprintf(stdout,"\t\tYL = %04hx\tYM = %04hx\tYH = %04hx\n",
YL, YM, YH);
fprintf(stdout,"\t\t %8.3f\t %8.3f\t %8.3f\n", yl, ym, yh);
fprintf(stdout,"\t\tXL = %08x\tDxLDy = %08x\n", XL, DxLDy);
fprintf(stdout,"\t\t %8.3f\t %8.3f\n", xl, dxldy);
fprintf(stdout,"\t\tXH = %08x\tDxHDy = %08x\n", XH, DxHDy);
fprintf(stdout,"\t\t %8.3f\t %8.3f\n", xh, dxhdy);
fprintf(stdout,"\t\tXM = %08x\tDxMDy = %08x\n", XM, DxMDy);
fprintf(stdout,"\t\t %8.3f\t %8.3f\n", xm, dxmdy);
y[0] = yh;
y[1] = ym;
y[2] = yl;
x[0] = xh + (yh - (int)yh) * dxhdy;
x[1] = xl;
x[2] = xh + dxhdy * (yl - yh);
for(area = i = 0; i < 3; i++)
area += x[i] * y[(i+1) % 3] - y[i] * x[(i+1) % 3];
area /= 2.0;
area = ABS(area);
dx1 = ABS(dxhdy - dxmdy);
dx2 = ABS(dxhdy - dxldy);
dy1 = (9.0 / dx1);
dy2 = (9.0 / dx2);
/* if no span > 9 pixels, clamp to min span size for all spans */
if(dy1 > (ym - yh) || dy2 > (yl - ym))
{
sub_area = area;
add_area = 9 * (yl - yh);
}
else /* find area of sub triangle whose spans are all less than 9 pixels */
{
sub_area = (4.5 * dy1 + 4.5 * dy2);
add_area = ((dy1 + dy2) * 9.0);
}
appx_clks = 22 + area + add_area - sub_area ;
nPrimClocks += appx_clks;
fprintf(stdout,"\t\t dy1......................... %f\n", dy1);
fprintf(stdout,"\t\t dy2......................... %f\n", dy2);
fprintf(stdout,"\t\t x0 (%f) y0 (%f)\n", x[0], y[0]);
fprintf(stdout,"\t\t x1 (%f) y1 (%f)\n", x[1], y[1]);
fprintf(stdout,"\t\t x2 (%f) y2 (%f)\n", x[2], y[2]);
fprintf(stdout,"\t\t number of spans............. %d\n", (int)(yl - yh));
fprintf(stdout,"\t\t area........................ %f\n", area);
fprintf(stdout,"\t\t add area.................... %f\n", add_area );
fprintf(stdout,"\t\t sub area.................... %f\n", sub_area );
fprintf(stdout,"\t\t appx. num clocks............ %d\n", appx_clks );
fprintf(stdout,"\t\t %% overhead.................. %f\n",
(float)(appx_clks - area) / (float) appx_clks * 100.0 );
/*
* check for illegal X/Y magnitude
*/
if(xl > MAX_COORD_X || xl < MIN_COORD_X)
{
fprintf(stdout,"\n\t\t ****** ERROR, xl(%f) out of range (%f,%f)\n",
xl, MIN_COORD_X, MAX_COORD_X);
nErrors++;
}
if(xh > MAX_COORD_X || xh < MIN_COORD_X)
{
fprintf(stdout,"\n\t\t ****** ERROR, xh(%f) out of range (%f,%f)\n",
xh, MIN_COORD_X, MAX_COORD_X);
nErrors++;
}
if(xm > MAX_COORD_X || xm < MIN_COORD_X)
{
fprintf(stdout,"\n\t\t ****** ERROR, xm(%f) out of range (%f,%f)\n",
xm, MIN_COORD_X, MAX_COORD_X);
nErrors++;
}
if(yl > MAX_COORD_Y || yl < MIN_COORD_Y)
{
fprintf(stdout,"\n\t\t ****** ERROR, yl(%f) out of range (%f,%f)\n",
yl, MIN_COORD_Y, MAX_COORD_Y);
nErrors++;
}
if(yh > MAX_COORD_Y || yh < MIN_COORD_Y)
{
fprintf(stdout,"\n\t\t ****** ERROR, yh(%f) out of range (%f,%f)\n",
yh, MIN_COORD_Y, MAX_COORD_Y);
nErrors++;
}
if(ym > MAX_COORD_Y || ym < MIN_COORD_Y)
{
fprintf(stdout,"\n\t\t ****** ERROR, ym(%f) out of range (%f,%f)\n",
ym, MIN_COORD_Y, MAX_COORD_Y);
nErrors++;
}
/*
* check for illegal slope/yh combinations
*/
if(dir == 1) /* left major */
{
if((dxmdy < dxhdy) && (YH != YM) ) {
fprintf(stdout,"\n\t\t ****** WARNING, dxmdy < dxhdy for left major triangle\n");
++nWarnings;
}
if((dxldy > dxmdy) && (YH != YM) ) {
fprintf(stdout,"\n\t\t ****** WARNING, dxldy > dxmdy for left major triangle\n");
++nWarnings;
}
}
else /* right major */
{
if((dxhdy < dxmdy) && (YH != YM)) {
fprintf(stdout,"\n\t\t ****** WARNING, dxhdy < dxmdy for right major triangle\n");
++nWarnings;
}
if((dxmdy > dxldy) && (YH != YM) ) {
fprintf(stdout,"\n\t\t ****** WARNING, dxmdy > dxldy for right major triangle\n");
++nWarnings;
}
}
if(YM < YH) {
fprintf(stdout,"\n\t\t ****** WARNING, YM < YH\n");
++nWarnings;
}
if(YL < YH) {
fprintf(stdout,"\n\t\t ****** WARNING, YL < YH\n");
++nWarnings;
}
if(YL < YM) {
fprintf(stdout,"\n\t\t ****** WARNING, YL < YM\n");
++nWarnings;
}
}
static void
dump_shade_coef(FILE *in)
{
u16 buffer[32];
i32 red, green, blue, alpha;
i32 DrDx, DgDx, DbDx, DaDx;
i32 DrDe, DgDe, DbDe, DaDe;
i32 DrDy, DgDy, DbDy, DaDy;
fread(buffer, sizeof(u16), 32, in);
red = buffer[0] << 16; red |= buffer[8];
green = buffer[1] << 16; green |= buffer[9];
blue = buffer[2] << 16; blue |= buffer[10];
alpha = buffer[3] << 16; alpha |= buffer[11];
DrDx = buffer[4] << 16; DrDx |= buffer[12];
DgDx = buffer[5] << 16; DgDx |= buffer[13];
DbDx = buffer[6] << 16; DbDx |= buffer[14];
DaDx = buffer[7] << 16; DaDx |= buffer[15];
DrDe = buffer[16] << 16; DrDe |= buffer[24];
DgDe = buffer[17] << 16; DgDe |= buffer[25];
DbDe = buffer[18] << 16; DbDe |= buffer[26];
DaDe = buffer[19] << 16; DaDe |= buffer[27];
DrDy = buffer[20] << 16; DrDy |= buffer[28];
DgDy = buffer[21] << 16; DgDy |= buffer[29];
DbDy = buffer[22] << 16; DbDy |= buffer[30];
DaDy = buffer[23] << 16; DaDy |= buffer[31];
fprintf(stdout,"\n\t Shade coefficients:\n");
fprintf(stdout,"\t\t red %08x green %08x blue %08x alpha %08x\n",
red, green, blue, alpha);
fprintf(stdout,"\t\t R %8.6f\t G %8.6f\n",
(float) red / RGBA_PREC, (float) green / RGBA_PREC);
fprintf(stdout,"\t\t B %8.6f\t A %8.6f\n",
(float) blue / RGBA_PREC, (float) alpha / RGBA_PREC);
fprintf(stdout,"\n");
fprintf(stdout,"\t\t DrDx %08x DgDx %08x DbDx %08x DaDx %08x\n",
DrDx, DgDx, DbDx, DaDx);
fprintf(stdout,"\t\t dRdX %8.6f\t dGdX %8.6f\n",
(float) DrDx / RGBA_PREC, (float) DgDx / RGBA_PREC);
fprintf(stdout,"\t\t dBdX %8.6f\t dBdX %8.6f\n",
(float) DbDx / RGBA_PREC, (float) DaDx / RGBA_PREC);
fprintf(stdout,"\n");
fprintf(stdout,"\t\t DrDe %08x DgDe %08x DbDe %08x DaDe %08x\n",
DrDe, DgDe, DbDe, DaDe);
fprintf(stdout,"\t\t dRdE %8.6f\t dGdE %8.6f\n",
(float) DrDe / RGBA_PREC, (float) DgDe / RGBA_PREC);
fprintf(stdout,"\t\t dBdE %8.6f\t dAdE %8.6f\n",
(float) DbDe / RGBA_PREC, (float) DaDe / RGBA_PREC);
fprintf(stdout,"\n");
fprintf(stdout,"\t\t DrDy %08x DgDy %08x DbDy %08x DaDy %08x\n",
DrDy, DgDy, DbDy, DaDy);
fprintf(stdout,"\t\t dRdY %8.6f\t dGdY %8.6f\n",
(float) DrDy / RGBA_PREC, (float) DgDy / RGBA_PREC);
fprintf(stdout,"\t\t dBdY %8.6f\t dAdY %8.6f\n",
(float) DbDy / RGBA_PREC, (float) DaDy / RGBA_PREC);
fprintf(stdout,"\n");
}
static void
dump_txtr_coef(FILE *in)
{
u16 buffer[32];
u32 gfx0, gfx1;
int s, t, w, l;
int dxs, dxt, dxw, dxl;
int des, det, dew, del;
int dys, dyt, dyw, dyl;
fread(buffer, sizeof(u16), 32, in);
s = buffer[0] << 16; s |= buffer[8];
t = buffer[1] << 16; t |= buffer[9];
w = buffer[2] << 16; w |= buffer[10];
l = buffer[3] << 16; l |= buffer[11];
dxs = buffer[4] << 16; dxs |= buffer[12];
dxt = buffer[5] << 16; dxt |= buffer[13];
dxw = buffer[6] << 16; dxw |= buffer[14];
dxl = buffer[7] << 16; dxl |= buffer[15];
des = buffer[16] << 16; des |= buffer[24];
det = buffer[17] << 16; det |= buffer[25];
dew = buffer[18] << 16; dew |= buffer[26];
del = buffer[19] << 16; del |= buffer[27];
dys = buffer[20] << 16; dys |= buffer[28];
dyt = buffer[21] << 16; dyt |= buffer[29];
dyw = buffer[22] << 16; dyw |= buffer[30];
dyl = buffer[23] << 16; dyl |= buffer[31];
fprintf(stdout,"\n\t Texture coefficients:\n");
fprintf(stdout,"\t\t S %08x T %08x W %08x L %08x\n", s, t, w, l);
fprintf(stdout,"\t\t S %8.6f\t T %8.6f\n", (float) s / STL_PREC, (float) t / STL_PREC);
fprintf(stdout,"\t\t W %8.6f\t L %8.6f\n", (float) w / W_PREC, (float) l / STL_PREC);
fprintf(stdout,"\n");
fprintf(stdout,"\t\t dSdX %08x dTdX %08x dWdX %08x dLdX %08x\n", dxs, dxt, dxw, dxl);
fprintf(stdout,"\t\t dSdX %8.6f\t dTdX %8.6f\n", (float) dxs / STL_PREC, (float) dxt / STL_PREC);
fprintf(stdout,"\t\t dWdX %8.6f\t dLdX %8.6f\n", (float) dxw / W_PREC, (float) dxl / STL_PREC);
fprintf(stdout,"\n");
fprintf(stdout,"\t\t dSdE %08x dTdE %08x dWdE %08x dLdE %08x\n", des, det, dew, del);
fprintf(stdout,"\t\t dSdE %8.6f\t dTdE %8.6f\n", (float) des / STL_PREC, (float) det / STL_PREC);
fprintf(stdout,"\t\t dWdE %8.6f\t dLdE %8.6f\n", (float) dew / W_PREC, (float) del / STL_PREC);
fprintf(stdout,"\n");
fprintf(stdout,"\t\t dSdY %08x dTdY %08x dWdY %08x dLdY %08x\n", dys, dyt, dyw, dyl);
fprintf(stdout,"\t\t dSdY %8.6f\t dTdY %8.6f\n", (float) dys / STL_PREC, (float) dyt / STL_PREC);
fprintf(stdout,"\t\t dWdY %8.6f\t dLdY %8.6f\n", (float) dyw / W_PREC, (float) dyl / STL_PREC);
}
static void
dump_zbuff_coef(FILE *in)
{
u32 buffer[4];
int z, dxz, dez, dyz;
fread(buffer, sizeof(u32), 4, in);
z = buffer[0];
dxz = buffer[1];
dez = buffer[2];
dyz = buffer[3];
fprintf(stdout,"\n\t Z-buffer coefficients:\n");
fprintf(stdout,"\t\t Z %08x dZdX %08x dZdE %08x dZdY %08x\n", z, dxz, dez, dyz);
fprintf(stdout,"\t\t Z %8.6f\t dZdX %8.6f\n", (float) z / 65536.0, (float) dxz / 65536.0);
fprintf(stdout,"\t\t dZdE %8.6f\t dZdY %8.6f\n", (float) dez / 65536.0, (float) dyz / 65536.0);
}
/*
* suba_decode: convert select to string
*/
static char *
suba_decode(int sel)
{
switch(sel)
{
case 0: return(D_COMBINE);
case 1: return(D_TEX0);
case 2: return(D_TEX1);
case 3: return(D_PRIM);
case 4: return(D_SHADE);
case 5: return(D_ENV);
case 6: return(D_ONE_PT_OH);
case 7: return(D_NOISE);
default: return(D_ZERO);
}
}
/*
* subb_decode: convert select to string
*/
static char *
subb_decode(int sel)
{
switch(sel)
{
case 0: return(D_COMBINE);
case 1: return(D_TEX0);
case 2: return(D_TEX1);
case 3: return(D_PRIM);
case 4: return(D_SHADE);
case 5: return(D_ENV);
case 6: return(D_CENTER);
case 7: return(D_CONV_K4);
default: return(D_ZERO);
}
}
/*
* mul_decode: convert select to string
*/
static char *
mul_decode(int sel)
{
switch(sel)
{
case 0: return(D_COMBINE);
case 1: return(D_TEX0);
case 2: return(D_TEX1);
case 3: return(D_PRIM);
case 4: return(D_SHADE);
case 5: return(D_ENV);
case 6: return(D_SCALE);
case 7: return(D_COMB_ALPHA);
case 8: return(D_TEX0_ALPHA);
case 9: return(D_TEX1_ALPHA);
case 10: return(D_PRIM_ALPHA);
case 11: return(D_SHADE_ALPHA);
case 12: return(D_ENV_ALPHA);
case 13: return(D_LOD_FRAC);
case 14: return(D_PRIM_LOD_FRAC);
case 15: return(D_CONV_K5);
default: return(D_ZERO);
}
}
/*
* add_decode: convert select to string
*/
static char *
add_decode(int sel)
{
switch(sel & 7)
{
case 0: return(D_COMBINE);
case 1: return(D_TEX0);
case 2: return(D_TEX1);
case 3: return(D_PRIM);
case 4: return(D_SHADE);
case 5: return(D_ENV);
case 6: return(D_ONE_PT_OH);
case 7: return(D_ZERO);
}
}
/*
* a_subab_decode: convert select to string
*/
static char *
a_subab_decode(int sel)
{
switch(sel & 7)
{
case 0: return(D_COMB_ALPHA);
case 1: return(D_TEX0_ALPHA);
case 2: return(D_TEX1_ALPHA);
case 3: return(D_PRIM_ALPHA);
case 4: return(D_SHADE_ALPHA);
case 5: return(D_ENV_ALPHA);
case 6: return(D_ONE_PT_OH);
case 7: return(D_ZERO);
}
}
/*
* a_mul_decode: convert select to string
*/
static char *
a_mul_decode(int sel)
{
switch(sel & 7)
{
case 0: return(D_LOD_FRAC);
case 1: return(D_TEX0_ALPHA);
case 2: return(D_TEX1_ALPHA);
case 3: return(D_PRIM_ALPHA);
case 4: return(D_SHADE_ALPHA);
case 5: return(D_ENV_ALPHA);
case 6: return(D_PRIM_LOD_FRAC);
case 7: return(D_ZERO);
}
}
/*
* a_add_decode: convert select to string
*/
static char *
a_add_decode(int sel)
{
switch(sel & 7)
{
case 0: return(D_COMB_ALPHA);
case 1: return(D_TEX0_ALPHA);
case 2: return(D_TEX1_ALPHA);
case 3: return(D_PRIM_ALPHA);
case 4: return(D_SHADE_ALPHA);
case 5: return(D_ENV_ALPHA);
case 6: return(D_ONE_PT_OH);
case 7: return(D_ZERO);
}
}
static void
dump_setcombine(u32 gfx0, u32 gfx1)
{
union {
struct {
unsigned int pad0: 2;
unsigned int cmd: 6;
unsigned int suba_r0: 4;
unsigned int mult_r0: 5;
unsigned int suba_a0: 3;
unsigned int mult_a0: 3;
unsigned int suba_r1: 4;
unsigned int mult_r1: 5;
} bf;
u32 word;
} w0;
union {
struct {
unsigned int subb_r0: 4;
unsigned int subb_r1: 4;
unsigned int suba_a1: 3;
unsigned int mult_a1: 3;
unsigned int adds_r0: 3;
unsigned int subb_a0: 3;
unsigned int adds_a0: 3;
unsigned int adds_r1: 3;
unsigned int subb_a1: 3;
unsigned int adds_a1: 3;
} bf;
u32 word;
} w1;
unsigned int suba, subb, mul, add;
char *dsuba, *dsubb, *dmul, *dadd;
w0.word = gfx0;
w1.word = gfx1;
suba = w0.bf.suba_r0;
subb = w1.bf.subb_r0;
mul = w0.bf.mult_r0;
add = w1.bf.adds_r0;
fprintf(stdout,"\n\t Red/Green/Blue Controls, Cycle 0:\n");
dsuba = suba_decode(suba);
dsubb = subb_decode(subb);
dmul = mul_decode(mul);
dadd = add_decode(add);
fprintf(stdout,"\t\t (%s - %s) * %s + %s\n", dsuba, dsubb, dmul, dadd);
suba = w0.bf.suba_r1;
subb = w1.bf.subb_r1;
mul = w0.bf.mult_r1;
add = w1.bf.adds_r1;
fprintf(stdout,"\n\t Red/Green/Blue Controls, Cycle 1:\n");
dsuba = suba_decode(suba);
dsubb = subb_decode(subb);
dmul = mul_decode(mul);
dadd = add_decode(add);
fprintf(stdout,"\t\t (%s - %s) * %s + %s\n", dsuba, dsubb, dmul, dadd);
suba = w0.bf.suba_a0;
subb = w1.bf.subb_a0;
mul = w0.bf.mult_a0;
add = w1.bf.adds_a0;
fprintf(stdout,"\n\t Alpha Controls, Cycle 0:\n");
dsuba = a_subab_decode(suba);
dsubb = a_subab_decode(subb);
dmul = a_mul_decode(mul);
dadd = a_add_decode(add);
fprintf(stdout,"\t\t (%s - %s) * %s + %s\n", dsuba, dsubb, dmul, dadd);
suba = w1.bf.suba_a1;
subb = w1.bf.subb_a1;
mul = w1.bf.mult_a1;
add = w1.bf.adds_a1;
fprintf(stdout,"\n\t Alpha Controls, Cycle 1:\n");
dsuba = a_subab_decode(suba);
dsubb = a_subab_decode(subb);
dmul = a_mul_decode(mul);
dadd = a_add_decode(add);
fprintf(stdout,"\t\t (%s - %s) * %s + %s\n", dsuba, dsubb, dmul, dadd);
}
/*
* Dump other modes
*/
static void
dump_setother(u32 gfx0, u32 gfx1)
{
union {
struct {
unsigned int pad0: 2;
unsigned int cmd: 6;
unsigned int atomic: 1;
unsigned int dither_en: 1;
unsigned int cycle_type: 2;
unsigned int persp_tex_en: 1;
unsigned int detail_tex_en: 1;
unsigned int sharpen_tex_en: 1;
unsigned int tex_lod_en: 1;
unsigned int en_tlut: 1;
unsigned int tlut_type: 1;
unsigned int sample_type: 1;
unsigned int mid_texel: 1;
unsigned int bi_lerp_0: 1;
unsigned int bi_lerp_1: 1;
unsigned int convert_one: 1;
unsigned int key_en: 1;
unsigned int blend_mask: 8;
} bf;
u32 word;
} w0;
union {
struct {
unsigned int b_m1a_0: 2;
unsigned int b_m1a_1: 2;
unsigned int b_m1b_0: 2;
unsigned int b_m1b_1: 2;
unsigned int b_m2a_0: 2;
unsigned int b_m2a_1: 2;
unsigned int b_m2b_0: 2;
unsigned int b_m2b_1: 2;
unsigned int texture_edge_mode: 1;
unsigned int force_blend: 1;
unsigned int alpha_cvg_select: 1;
unsigned int cvg_times_alpha: 1;
unsigned int z_mode: 2;
unsigned int cvg_dest: 2;
unsigned int color_on_cvg: 1;
unsigned int image_read_en: 1;
unsigned int z_update_en: 1;
unsigned int z_compare_en: 1;
unsigned int antialias_en: 1;
unsigned int z_source_sel: 1;
unsigned int dither_alpha_en: 1;
unsigned int alpha_compare_en: 1;
} bf;
u32 word;
} w1;
w0.word = gfx0;
w1.word = gfx1;
fprintf(stdout,"\t\t atomic primitive ..... %d\n", w0.bf.atomic);
fprintf(stdout,"\t\t dither_enable......... %d\n", w0.bf.dither_en);
fprintf(stdout,"\t\t cycle_type............ %d ", w0.bf.cycle_type);
if(w0.bf.cycle_type == 0) fprintf(stdout,"(one cycle)\n");
else if(w0.bf.cycle_type == 1) fprintf(stdout,"(two cycle)\n");
else if(w0.bf.cycle_type == 2) fprintf(stdout,"(copy)\n");
else fprintf(stdout,"(fill)\n");
fprintf(stdout,"\t\t persp_tex_en.......... %d\n", w0.bf.persp_tex_en);
fprintf(stdout,"\t\t detail_tex_en......... %d\n", w0.bf.detail_tex_en);
fprintf(stdout,"\t\t sharpen_tex_en........ %d\n", w0.bf.sharpen_tex_en);
fprintf(stdout,"\t\t tex_lod_en............ %d\n", w0.bf.tex_lod_en);
fprintf(stdout,"\t\t en_tlut............... %d\n", w0.bf.en_tlut);
fprintf(stdout,"\t\t tlut_type............. %d\n", w0.bf.tlut_type);
fprintf(stdout,"\t\t sample_type........... %d\n", w0.bf.sample_type);
fprintf(stdout,"\t\t mid_texel............. %d\n", w0.bf.mid_texel);
fprintf(stdout,"\t\t bi_lerp_0............. %d\n", w0.bf.bi_lerp_0);
fprintf(stdout,"\t\t bi_lerp_1............. %d\n", w0.bf.bi_lerp_1);
fprintf(stdout,"\t\t convert_one........... %d\n", w0.bf.convert_one);
fprintf(stdout,"\t\t key_en................ %d\n", w0.bf.key_en);
fprintf(stdout,"\t\t blend_mask............ 0x%0.2x\n", w0.bf.blend_mask);
fprintf(stdout,"\n\t Blend Mux Controls, Cycle 0: ");
fprintf(stdout,"(%d, %d, %d, %d)\n", w1.bf.b_m1a_0, w1.bf.b_m1b_0, w1.bf.b_m2a_0,
w1.bf.b_m2b_0);
fprintf(stdout,"\t\t blend mult 1a......... ");
switch(w1.bf.b_m1a_0)
{
case 0: fprintf(stdout,"pixel/blend color\n");
break;
case 1: fprintf(stdout,"memory color\n");
break;
case 2: fprintf(stdout,"blend reg color\n");
break;
case 3: fprintf(stdout,"fog color\n");
break;
}
fprintf(stdout,"\t\t blend mult 1b......... ");
switch(w1.bf.b_m1b_0)
{
case 0: fprintf(stdout,"pixel alpha\n");
break;
case 1: fprintf(stdout,"fog alpha\n");
break;
case 2: fprintf(stdout,"shade alpha\n");
break;
case 3: fprintf(stdout,"0.0\n");
break;
}
fprintf(stdout,"\t\t blend mult 2a......... ");
switch(w1.bf.b_m2a_0)
{
case 0: fprintf(stdout,"pixel/blend color\n");
break;
case 1: fprintf(stdout,"memory color\n");
break;
case 2: fprintf(stdout,"blend reg color\n");
break;
case 3: fprintf(stdout,"fog color\n");
break;
}
fprintf(stdout,"\t\t blend mult 2b......... ");
switch(w1.bf.b_m2b_0)
{
case 0: fprintf(stdout,"1.0 - <1b input>\n");
break;
case 1: fprintf(stdout,"memory alpha\n");
break;
case 2: fprintf(stdout,"1.0\n");
break;
case 3: fprintf(stdout,"0.0\n");
break;
}
fprintf(stdout,"\n\t Blend Mux Controls, Cycle 1: ");
fprintf(stdout,"(%d, %d, %d, %d)\n", w1.bf.b_m1a_1, w1.bf.b_m1b_1, w1.bf.b_m2a_1,
w1.bf.b_m2b_1);
fprintf(stdout,"\t\t blend mult 1a......... ");
switch(w1.bf.b_m1a_1)
{
case 0: fprintf(stdout,"pixel/blend color\n");
break;
case 1: fprintf(stdout,"memory color\n");
break;
case 2: fprintf(stdout,"blend reg color\n");
break;
case 3: fprintf(stdout,"fog color\n");
break;
}
fprintf(stdout,"\t\t blend mult 1b......... ");
switch(w1.bf.b_m1b_1)
{
case 0: fprintf(stdout,"pixel alpha\n");
break;
case 1: fprintf(stdout,"fog alpha\n");
break;
case 2: fprintf(stdout,"shade alpha\n");
break;
case 3: fprintf(stdout,"0.0\n");
break;
}
fprintf(stdout,"\t\t blend mult 2a......... ");
switch(w1.bf.b_m2a_1)
{
case 0: fprintf(stdout,"pixel/blend color\n");
break;
case 1: fprintf(stdout,"memory color\n");
break;
case 2: fprintf(stdout,"blend reg color\n");
break;
case 3: fprintf(stdout,"fog color\n");
break;
}
fprintf(stdout,"\t\t blend mult 2b......... ");
switch(w1.bf.b_m2b_1)
{
case 0: fprintf(stdout,"1.0 - <1b input>\n");
break;
case 1: fprintf(stdout,"memory alpha\n");
break;
case 2: fprintf(stdout,"1.0\n");
break;
case 3: fprintf(stdout,"0.0\n");
break;
}
fprintf(stdout,"\n");
fprintf(stdout,"\t\t texture_edge_mode..... %d\n", w1.bf.texture_edge_mode);
fprintf(stdout,"\t\t force_blend........... %d\n", w1.bf.force_blend);
fprintf(stdout,"\t\t alpha_cvg_select...... %d\n", w1.bf.alpha_cvg_select);
fprintf(stdout,"\t\t cvg_times_alpha....... %d\n", w1.bf.cvg_times_alpha);
fprintf(stdout,"\t\t z_mode................ ");
switch(w1.bf.z_mode)
{
case 0: fprintf(stdout,"opaque\n");
break;
case 1: fprintf(stdout,"interpenetrating\n");
break;
case 2: fprintf(stdout,"transparent\n");
break;
case 3: fprintf(stdout,"decal\n");
break;
}
fprintf(stdout,"\t\t cvg_dest.............. ");
switch(w1.bf.cvg_dest)
{
case 0: fprintf(stdout,"clamp(normal)\n");
break;
case 1: fprintf(stdout,"wrap\n");
break;
case 2: fprintf(stdout,"zap(force to full cvg)\n");
break;
case 3: fprintf(stdout,"save(don't overwrite mem cvg)\n");
break;
}
fprintf(stdout,"\t\t color_on_cvg.......... %d\n", w1.bf.color_on_cvg);
fprintf(stdout,"\t\t image_read_en......... %d\n", w1.bf.image_read_en);
fprintf(stdout,"\t\t z_update_en........... %d\n", w1.bf.z_update_en);
fprintf(stdout,"\t\t z_compare_en.......... %d\n", w1.bf.z_compare_en);
fprintf(stdout,"\t\t antialias_en.......... %d\n", w1.bf.antialias_en);
fprintf(stdout,"\t\t z_source_sel.......... %s\n",
w1.bf.z_source_sel ? "prim z" : "pixel z");
fprintf(stdout,"\t\t dither_alpha_en....... %d\n", w1.bf.dither_alpha_en);
fprintf(stdout,"\t\t alpha_compare_en...... %d\n", w1.bf.alpha_compare_en);
}
static void
dump_texrect(FILE *in, u32 gfx0, u32 gfx1)
{
u32 buffer[4];
Gtexrect *texrp;
float xl, yl, xh, yh;
float area;
buffer[0] = gfx0;
buffer[1] = gfx1;
fread(&buffer[2], sizeof(u32), 2, in); /* we already have gfx0, gfx1... */
fprintf(stdout,"\t\t\t\t\t%08x %08x\n",buffer[2],buffer[3]);
texrp = (Gtexrect *) &(buffer[0]);
xl = (float)texrp->xl / 4.0;
xh = (float)texrp->xh / 4.0;
yl = (float)texrp->yl / 4.0;
yh = (float)texrp->yh / 4.0;
fprintf(stdout,"\t\tile = %d\n", texrp->tile);
fprintf(stdout,"\t\txl = %f yl = %f xh = %f yh = %f\n",
xl, yl, xh, yh);
fprintf(stdout,"\t\ts = %f t = %f dsdx = %f dtdy = %f\n",
(float)texrp->s / 32.0, (float)texrp->t / 32.0,
(float)texrp->dsdx / 1024.0, (float)texrp->dtdy / 1024.0);
area = (xl - xh) * (yl - yh);
fprintf(stdout,"\t\t area........................ %f\n", area);
nPrimClocks += area;
}
/*
* Parse and dump a RDP-type display list command.
*/
static void
read_rdp(u32 gfx0, u32 gfx1, FILE *in)
{
u32 addr, buffer[20];
int i0, i1, i2, i3;
char op, b0, tstring[32];
float area;
Gsetimg *imgp;
Gsetcombine *combp;
Gsetcolor *scolp;
Gfillrect *fillrp;
Gsettile *stilep;
Gloadtile *ltilep;
Gloadtlut *ltlutp;
/* every command has at least 64-bits... */
buffer[0] = gfx0;
buffer[1] = gfx1;
op = (char) ((gfx0 & 0xff000000) >> 24);
/*
* Classify command for next sync check
*/
SyncW.pc[SyncW.curr_cmd].cmd = op;
SyncW.pc[SyncW.curr_cmd].npa = is_npa_cmd(op);
SyncW.pc[SyncW.curr_cmd].prim = is_prim_cmd(op);
SyncW.pc[SyncW.curr_cmd].sts = is_sts_cmd(op);
SyncW.pc[SyncW.curr_cmd].lbt = is_lbt_cmd(op);
/* save tile number */
if(is_tex_rect_cmd(op) || is_lbt_cmd(op) || is_sts_cmd(op))
SyncW.pc[SyncW.curr_cmd].tile = ((gfx1 & 0x07000000) >> 24);
else if(is_tri_cmd(op))
SyncW.pc[SyncW.curr_cmd].tile = ((gfx0 & 0x00070000) >> 16);
else
SyncW.pc[SyncW.curr_cmd].tile = 0;
check_for_syncs();
/* increment/clamp indexes */
++SyncW.curr_cmd;
if(SyncW.curr_cmd > (MAX_HISTORY-1))
SyncW.curr_cmd = 0;
++SyncW.n_cmd;
if(SyncW.n_cmd > MAX_HISTORY)
SyncW.n_cmd = MAX_HISTORY;
/*
* Formatted Dump of each command
*/
switch (op) {
case (char) G_SETCIMG:
fprintf(stdout,"\tSETCIMG ");
fprintf(stdout,"\t\t\t%08x %08x\n",gfx0,gfx1);
imgp = (Gsetimg *) &(buffer[0]);
fprintf(stdout,"\t\tfmt = %d siz = %d wd = %d ptr = %08x\n",
imgp->fmt, imgp->siz, imgp->wd, gfx1);
++nAttClocks;
break;
case (char) G_SETZIMG:
fprintf(stdout,"\tSETZIMG ");
fprintf(stdout,"\t\t\t%08x %08x\n",gfx0,gfx1);
imgp = (Gsetimg *) &(buffer[0]);
fprintf(stdout,"\t\tfmt = %d siz = %d wd = %d ptr = %08x\n",
imgp->fmt, imgp->siz, imgp->wd, gfx1);
++nAttClocks;
break;
case (char) G_SETTIMG:
fprintf(stdout,"\tSETTIMG ");
fprintf(stdout,"\t\t\t%08x %08x\n",gfx0,gfx1);
imgp = (Gsetimg *) &(buffer[0]);
fprintf(stdout,"\t\tfmt = %d siz = %d wd = %d ptr = %08x\n",
imgp->fmt, imgp->siz, imgp->wd, gfx1);
++nAttClocks;
break;
case (char) G_SETCOMBINE:
fprintf(stdout,"\tSETCOMBINE ");
fprintf(stdout,"\t\t\t%08x %08x\n",gfx0,gfx1);
dump_setcombine(gfx0, gfx1);
++nAttClocks;
break;
case (char) G_SETENVCOLOR:
fprintf(stdout,"\tSETENVCOLOR ");
fprintf(stdout,"\t\t\t%08x %08x\n",gfx0,gfx1);
scolp = (Gsetcolor *) &(buffer[0]);
fprintf(stdout,"\t\tc = %08x\n", scolp->color);
++nAttClocks;
break;
case (char) G_SETPRIMCOLOR:
fprintf(stdout,"\tSETPRIMCOLOR ");
fprintf(stdout,"\t\t\t%08x %08x\n",gfx0,gfx1);
scolp = (Gsetcolor *) &(buffer[0]);
fprintf(stdout,"\t\tprim_min_lev = %d prim_lev = %d c = %08x\n",
scolp->prim_min_level, scolp->prim_level, scolp->color);
++nAttClocks;
break;
case (char) G_SETBLENDCOLOR:
fprintf(stdout,"\tSETBLENDCOLOR ");
fprintf(stdout,"\t\t\t%08x %08x\n",gfx0,gfx1);
scolp = (Gsetcolor *) &(buffer[0]);
fprintf(stdout,"\t\tc = %08x\n", scolp->color);
++nAttClocks;
break;
case (char) G_SETFOGCOLOR:
fprintf(stdout,"\tSETFOGCOLOR ");
fprintf(stdout,"\t\t\t%08x %08x\n",gfx0,gfx1);
scolp = (Gsetcolor *) &(buffer[0]);
fprintf(stdout,"\t\tc = %08x\n", scolp->color);
++nAttClocks;
break;
case (char) G_SETFILLCOLOR:
fprintf(stdout,"\tSETFILLCOLOR ");
fprintf(stdout,"\t\t\t%08x %08x\n",gfx0,gfx1);
scolp = (Gsetcolor *) &(buffer[0]);
fprintf(stdout,"\t\tc = %08x\n", scolp->color);
++nAttClocks;
break;
case (char) G_FILLRECT:
fprintf(stdout,"\tFILLRECT ");
fprintf(stdout,"\t\t\t%08x %08x\n",gfx0,gfx1);
fillrp = (Gfillrect *) &(buffer[0]);
fprintf(stdout,"\t\tulx = %d uly = %d lrx = %d lry = %d\n",
fillrp->x1, fillrp->y1, fillrp->x0, fillrp->y0);
area = MAX((fillrp->x0 - fillrp->x1) * (fillrp->y0 - fillrp->y1),
9 * (fillrp->y0 - fillrp->y1));
nPrimClocks += (int) area;
break;
case (char) G_SETTILE:
fprintf(stdout,"\tSETTILE ");
fprintf(stdout,"\t\t\t%08x %08x\n",gfx0,gfx1);
stilep = (Gsettile *) &(buffer[0]);
fprintf(stdout,"\t\tfmt = %d siz = %d line = %d tmem = %08x\n",
stilep->fmt, stilep->siz, stilep->line, stilep->tmem);
fprintf(stdout,"\t\ttile = %d pal = %d ct = %d mt = %d\n",
stilep->tile, stilep->palette, stilep->ct, stilep->mt);
fprintf(stdout,"\t\tmaskt = %d shiftt = %d cs = %d ms = %d masks = %d shifts = %d\n",
stilep->maskt, stilep->shiftt, stilep->cs, stilep->ms,
stilep->masks, stilep->shifts);
++nAttClocks;
break;
case (char) G_LOADTILE:
fprintf(stdout,"\tLOADTILE ");
fprintf(stdout,"\t\t\t%08x %08x prim #%04d\n",gfx0,gfx1,NumPrimitives++);
ltilep = (Gloadtile *) &(buffer[0]);
fprintf(stdout,"\t\tsl = %f tl = %f tile = %d sh = %f th = %f\n",
(float)ltilep->sl / 4.0, (float)ltilep->tl / 4.0, ltilep->tile,
(float)ltilep->sh / 4.0, (float)ltilep->th / 4.0);
break;
case (char) G_LOADBLOCK:
fprintf(stdout,"\tLOADBLOCK ");
fprintf(stdout,"\t\t\t%08x %08x prim #%04d\n",gfx0,gfx1,NumPrimitives++);
/* same as load tile... */
ltilep = (Gloadblock *) &(buffer[0]);
fprintf(stdout,"\t\tsl = %f tl = %f tile = %d sh = %f dxt = %f\n",
(float)ltilep->sl, (float)ltilep->tl, ltilep->tile,
(float)ltilep->sh, (float)ltilep->th / (float) (1 << 11));
break;
case (char) G_SETTILESIZE:
fprintf(stdout,"\tSETTILESIZE ");
fprintf(stdout,"\t\t\t%08x %08x\n",gfx0,gfx1);
/* same as load tile... */
ltilep = (Gsettilesize *) &(buffer[0]);
fprintf(stdout,"\t\tsl = %f tl = %f tile = %d sh = %f th = %f\n",
(float)ltilep->sl / 4.0, (float)ltilep->tl / 4.0, ltilep->tile,
(float)ltilep->sh / 4.0, (float)ltilep->th / 4.0);
++nAttClocks;
break;
case (char) G_LOADTLUT:
fprintf(stdout,"\tLOADTLUT ");
fprintf(stdout,"\t\t\t%08x %08x prim #%04d\n",gfx0,gfx1,NumPrimitives++);
ltlutp = (Gloadtlut *) &(buffer[0]);
fprintf(stdout,"\t\tsl = %f tl = %f tile = %d sh = %f th = %f\n",
(float)ltlutp->sl / 4.0, (float)ltlutp->tl / 4.0, ltlutp->tile,
(float)ltlutp->sh / 4.0, (float)ltlutp->th / 4.0);
break;
case (char) G_RDPSETOTHERMODE:
fprintf(stdout,"\tRDPSETOTHERMODE ");
fprintf(stdout,"\t\t%08x %08x\n",gfx0,gfx1);
dump_setother(gfx0, gfx1);
++nAttClocks;
break;
case (char) G_SETPRIMDEPTH:
fprintf(stdout,"\tSETPRIMDEPTH ");
fprintf(stdout,"\t\t\t%08x %08x\n",gfx0,gfx1);
i0 = gfx1 >> 16;
i1 = (gfx1 << 16) >> 16;
fprintf(stdout,"\t\tprimZ = %d primDelZ = %d\n", i0, i1);
++nAttClocks;
break;
case (char) G_SETSCISSOR:
fprintf(stdout,"\tSETSCISSOR ");
fprintf(stdout,"\t\t\t%08x %08x\n",gfx0,gfx1);
i0 = (gfx0 & 0x00fff000) >> 12;
i1 = (gfx0 & 0x00000fff);
i2 = (gfx1 & 0x00fff000) >> 12;
i3 = (gfx1 & 0x00000fff);
fprintf(stdout,"\t\txH = %.3f yH = %.3f xL = %.3f yL = %.3f\n",
(float)i0 / 4.0, (float)i1 / 4.0, (float)i2 / 4.0, (float)i3 / 4.0);
fprintf(stdout,"\t\tulx = %.3f uly = %.3f lrx = %.3f lry = %.3f\n",
(float)i0 / 4.0, (float)i1 / 4.0, (float)i2 / 4.0, (float)i3 / 4.0);
if (gfx1 & 0x02000000) {
fprintf(stdout, "\t\tscissor field ON, ");
if (gfx1 & 0x01000000)
fprintf(stdout, "keep odd lines\n");
else
fprintf(stdout, "keep even lines\n");
} else {
fprintf(stdout, "\t\tscissor field OFF\n");
}
++nAttClocks;
break;
case (char) G_SETCONVERT:
fprintf(stdout,"\tSETCONVERT ");
fprintf(stdout,"\t\t\t%08x %08x\n",gfx0,gfx1);
/* do something... */
++nAttClocks;
break;
case (char) G_SETKEYR:
fprintf(stdout,"\tSETKEYR ");
fprintf(stdout,"\t\t\t%08x %08x\n",gfx0,gfx1);
/* do something... */
++nAttClocks;
break;
case (char) G_SETKEYGB:
fprintf(stdout,"\tSETKEYGB ");
fprintf(stdout,"\t\t\t%08x %08x\n",gfx0,gfx1);
/* do something... */
++nAttClocks;
break;
case (char) G_RDPFULLSYNC:
fprintf(stdout,"\tRDPFULLSYNC ");
fprintf(stdout,"\t\t\t%08x %08x\n",gfx0,gfx1);
/* do something... */
nSyncClocks += 43;
break;
case (char) G_RDPTILESYNC:
fprintf(stdout,"\tRDPTILESYNC ");
fprintf(stdout,"\t\t\t%08x %08x\n",gfx0,gfx1);
/* do something... */
nSyncClocks += 28;
break;
case (char) G_RDPPIPESYNC:
fprintf(stdout,"\tRDPPIPESYNC ");
fprintf(stdout,"\t\t\t%08x %08x\n",gfx0,gfx1);
/* do something... */
nSyncClocks += 43;
break;
case (char) G_RDPLOADSYNC:
fprintf(stdout,"\tRDPLOADSYNC ");
fprintf(stdout,"\t\t\t%08x %08x\n",gfx0,gfx1);
/* do something... */
nSyncClocks += 18;
break;
case (char) G_NOOP:
fprintf(stdout,"\tNOOP ");
fprintf(stdout,"\t\t\t%08x %08x\n",gfx0,gfx1);
nAttClocks++;
break;
case (char) G_TEXRECTFLIP:
fprintf(stdout,"\tTEXRECTFLIP ");
fprintf(stdout,"\t\t\t%08x %08x prim #%04d\n",gfx0,gfx1,NumPrimitives++);
dump_texrect(in, gfx0, gfx1);
break;
case (char) G_TEXRECT:
fread(&buffer[2], sizeof(u32), 2, in); /* we already have gfx0, gfx1... */
fprintf(stdout,"\tTEXRECT ");
fprintf(stdout,"\t\t\t%08x %08x prim #%04d\n",gfx0,gfx1, NumPrimitives++);
dump_texrect(in, gfx0, gfx1);
break;
case (char) G_TRI_FILL:
fprintf(stdout,"\tG_TRI_FILL ");
fprintf(stdout,"\t\t\t%08x %08x prim #%04d\n",gfx0,gfx1, NumPrimitives++);
dump_edge_coef(in, gfx0, gfx1);
break;
case (char) G_TRI_SHADE:
fprintf(stdout,"\tG_TRI_SHADE ");
fprintf(stdout,"\t\t\t%08x %08x prim #%04d\n",gfx0,gfx1, NumPrimitives++);
dump_edge_coef(in, gfx0, gfx1);
dump_shade_coef(in);
break;
case (char) G_TRI_TXTR:
fprintf(stdout,"\tG_TRI_TXTR ");
fprintf(stdout,"\t\t\t%08x %08x prim #%04d\n",gfx0,gfx1, NumPrimitives++);
dump_edge_coef(in, gfx0, gfx1);
dump_txtr_coef(in);
break;
case (char) G_TRI_SHADE_TXTR:
fprintf(stdout,"\tG_TRI_SHADE_TXTR ");
fprintf(stdout,"\t\t\t%08x %08x prim #%04d\n",gfx0,gfx1, NumPrimitives++);
dump_edge_coef(in, gfx0, gfx1);
dump_shade_coef(in);
dump_txtr_coef(in);
break;
case (char) G_TRI_FILL_ZBUFF:
fprintf(stdout,"\tG_TRI_FILL_ZBUFF ");
fprintf(stdout,"\t\t\t%08x %08x prim #%04d\n",gfx0,gfx1,NumPrimitives++);
dump_edge_coef(in, gfx0, gfx1);
dump_zbuff_coef(in);
break;
case (char) G_TRI_SHADE_ZBUFF:
fprintf(stdout,"\tG_TRI_SHADE_ZBUFF ");
fprintf(stdout,"\t\t\t%08x %08x prim #%04d\n",gfx0,gfx1,NumPrimitives++);
dump_edge_coef(in, gfx0, gfx1);
dump_shade_coef(in);
dump_zbuff_coef(in);
break;
case (char) G_TRI_TXTR_ZBUFF:
fprintf(stdout,"\tG_TRI_TXTR_ZBUFF ");
fprintf(stdout,"\t\t\t%08x %08x prim #%04d\n",gfx0,gfx1, NumPrimitives++);
dump_edge_coef(in, gfx0, gfx1);
dump_txtr_coef(in);
dump_zbuff_coef(in);
break;
case (char) G_TRI_SHADE_TXTR_ZBUFF:
fprintf(stdout,"\tG_TRI_SHADE_TXTR_ZBUFF ");
fprintf(stdout,"\t\t\t%08x %08x prim #%04d\n",gfx0,gfx1, NumPrimitives++);
dump_edge_coef(in, gfx0, gfx1);
dump_shade_coef(in);
dump_txtr_coef(in);
dump_zbuff_coef(in);
break;
default:
fprintf(stdout,"\tUNKNOWN %02x ",op);
fprintf(stdout,"\t\t\t%08x %08x\n",gfx0,gfx1);
fprintf(stdout,"\n\t\t ****** ERROR, unknown command\n");
nErrors++;
nAttClocks++;
break;
}
fprintf(stdout,"\n");
}
/*
* main routine.
*/
int
main(int argc, char *argv[])
{
FILE *dram_file, *bin_file;
u32 gfx0, gfx1, *gfxp;
int i;
bool do_stdin = FALSE;
while ((argc > 1) && (argv[1][0] == '-')) {
switch(argv[1][1]) {
case 'v':
do_verbose = FALSE;
break;
case '-':
do_stdin = TRUE;
break;
default:
fprintf(stderr,"%s : unknown argument [%s].\n",argv[0],argv[1]);
break;
}
argc--;
argv++;
}
if (argc < 2 && !do_stdin) {
fprintf(stderr,"usage: %s %s.\n",argv[0],UsageString);
exit(-1);
}
if (do_stdin) {
bin_file = stdin;
} else {
if ((bin_file=fopen(argv[1],"r"))==NULL) {
fprintf(stderr,"can't open bin file [%s].\n",argv[1]);
exit(-1);
}
}
if (argc > 2) {
if ((dram_file=fopen(argv[2],"r"))==NULL) {
fprintf(stderr,"can't open DRAM file [%s].\n",argv[2]);
exit(-1);
}
fprintf(stderr,"loading DRAM data.");
gfxp = (u32 *) &(DRAM[0]);
i = 0;
while (!feof(dram_file)) {
if ((i % 1048576) == 0)
fprintf(stderr,".");
fread(gfxp, sizeof(u32), 1, dram_file);
gfxp++;
i += 4;
}
fprintf(stderr,"done.\n");
fclose(dram_file);
}
fprintf(stdout,"\n\t\tReadable dump of RDP file [%s]:\n\n",argv[1]);
fprintf(stdout,
"------------------------------------------------------------------------------\n");
fread(&gfx0, sizeof(u32), 1, bin_file);
fread(&gfx1, sizeof(u32), 1, bin_file);
while (!feof(bin_file)) {
read_rdp(gfx0, gfx1, bin_file);
fread(&gfx0, sizeof(u32), 1, bin_file);
fread(&gfx1, sizeof(u32), 1, bin_file);
}
fprintf(stdout,
"\n------------------------------------------------------------------------------\n");
fprintf(stdout, "Number of Warnings: %d\n", nWarnings);
fprintf(stdout, "Number of Errors: %d\n", nErrors);
fprintf(stdout, "Number of Sync Clocks (approximate): %d\n", nSyncClocks);
fprintf(stdout, "Number of Att Clocks (approximate): %d\n", nAttClocks);
fprintf(stdout, "Number of Prim Clocks (approximate): %d\n", nPrimClocks);
fprintf(stdout, "Number of Load Clocks (approximate): Not Implemented\n", nLoadClocks);
fprintf(stdout, " ------\n");
fprintf(stdout, "Number of Total Clocks (approximate): %d\n", nSyncClocks +
nAttClocks + nPrimClocks + nLoadClocks);
}