blMain.tcl 61.1 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
##################### Blender #######################################
toplevel .bl

frame .bl.topF
frame .bl.stateF
frame .bl.muxesF
frame .bl.cyc0ColorF -relief ridge -borderwidth 2
frame .bl.cyc1ColorF -relief ridge -borderwidth 2

frame .bl.modeBitsF -relief ridge -borderwidth 2
frame .bl.modeBitsF1 
frame .bl.modeBitsF2

frame .bl.ditherF -relief ridge -borderwidth 4

frame .bl.colorF -relief ridge -borderwidth 4
frame .bl.blendColorF
frame .bl.blendRedF 
frame .bl.blendGreenF 
frame .bl.blendBlueF 
frame .bl.blendAlphaF

frame .bl.fogColorF
frame .bl.fogRedF 
frame .bl.fogGreenF 
frame .bl.fogBlueF 
frame .bl.fogAlphaF

frame .bl.primDepthF -relief ridge -borderwidth 4
frame .bl.primZF
frame .bl.primDeltaZF

frame .bl.presetF -relief ridge -borderwidth 2
frame .bl.cycle0cycle1presetF
#--------------------------- bl Modes ------------------------------------

######### IMP NOTE about the bl mode bits #######################################
# the procs associated with these buttons are also called from the preset mode	#
# buttons. When they're called from there, the lines that clear and then set	#
# that particular bit in the modeword are redundant since the bit has already	#
# been set in the modeWord. This clearing and setting is only useful when the	#
# proc is called by its respective button. Any additions to this proc should	#
# be done keeping this in mind otherwise weird interactions can occur. e.g.	#
# clearing and setting the bit in both modewords can play havoc since then	#
# if we're in two cycle mode, modeword 0 should be able to have all its		#
# mode bits (except those that set muxes) to be not set. What happens in 	#
# this case is that if the modeword1 has a bit say aaEn set it propagates that 	#
# bit to modeword 0.								#
#################################################################################

checkbutton .bl.aaEnCB -width 13 -text "aaEn" -variable blAaEn -command CblAaEn
set blAaEn 0

proc CblAaEn {} {
	global fptr record blAaEn
	global blCycle0ModeWord blCycle1ModeWord AA_EN

	# set modeword based on CB selection
	set blCycle1ModeWord [expr $blCycle1ModeWord & ~($AA_EN)]
	set blCycle0ModeWord [expr $blCycle0ModeWord & ~($AA_EN)]

        if {$blAaEn == 1} {
		set blCycle1ModeWord [expr $blCycle1ModeWord | $AA_EN]
		set blCycle0ModeWord [expr $blCycle0ModeWord | $AA_EN]
	}

	if {$record == 1} {
                puts $fptr "set blAaEn $blAaEn"
		puts $fptr "CblAaEn"
        }
	callback_blCycle
	callback_send_dl
}


checkbutton .bl.zCmpEnCB -width 13 -text "zCmpEn" -variable blZcmpEn -command CblZcmpEn
#set blZcmpEn 0

proc CblZcmpEn {} {
	global fptr record blZcmpEn
	global blCycle0ModeWord blCycle1ModeWord Z_CMP

	# set modeword based on CB selection
	set blCycle1ModeWord [expr $blCycle1ModeWord & ~($Z_CMP)]
	set blCycle0ModeWord [expr $blCycle0ModeWord & ~($Z_CMP)]

        if {$blZcmpEn == 1} {
		set blCycle1ModeWord [expr $blCycle1ModeWord | $Z_CMP]
		set blCycle0ModeWord [expr $blCycle0ModeWord | $Z_CMP]
	}

	if {$record == 1} {
		puts $fptr "set blZcmpEn $blZcmpEn"
		puts $fptr "CblZcmpEn"
	}
	callback_blCycle
	callback_send_dl
}
		
checkbutton .bl.zUpdEnCB -width 13 -text "zUpdEn" -variable blZupdEn -command CblZupdEn
#set blZupdEn 0

proc CblZupdEn {} {
	global fptr record blZupdEn
	global blCycle0ModeWord blCycle1ModeWord Z_UPD

	# set modeword based on CB selection
	set blCycle1ModeWord [expr $blCycle1ModeWord & ~($Z_UPD)]
	set blCycle0ModeWord [expr $blCycle0ModeWord & ~($Z_UPD)]

        if {$blZupdEn == 1} {
		set blCycle1ModeWord [expr $blCycle1ModeWord | $Z_UPD]
		set blCycle0ModeWord [expr $blCycle0ModeWord | $Z_UPD]
	}

	if {$record == 1} {
                puts $fptr "set blZupdEn $blZupdEn"
		puts $fptr "CblZupdEn"
        }
	callback_blCycle
	callback_send_dl
}


checkbutton .bl.imRdEnCB -width 13 -text "imRdEn" -variable blImRdEn -command CblImRdEn
#set blImRdEn 0

proc CblImRdEn {} {
	global fptr record blImRdEn
	global blCycle0ModeWord blCycle1ModeWord IM_RD

	# set modeword based on CB selection
	set blCycle1ModeWord [expr $blCycle1ModeWord & ~($IM_RD)]
	set blCycle0ModeWord [expr $blCycle0ModeWord & ~($IM_RD)]

        if {$blImRdEn == 1} {
		set blCycle1ModeWord [expr $blCycle1ModeWord | $IM_RD]
		set blCycle0ModeWord [expr $blCycle0ModeWord | $IM_RD]
	}

        if {$record == 1} {
                puts $fptr "set blImRdEn $blImRdEn"
		puts $fptr "CblImRdEn"
        }
	callback_blCycle
	callback_send_dl
}


menubutton .bl.cvgDestMB -width 15 -textvariable LblCvgDest -relief  raised  \
-menu .bl.cvgDestMB.menu -bg LightGray -activebackground LightGray

menu .bl.cvgDestMB.menu 
.bl.cvgDestMB.menu add radiobutton -label "clamp" -command CblCvgDest -variable blCvgDest -value 0
.bl.cvgDestMB.menu add radiobutton -label "wrap" -command CblCvgDest -variable blCvgDest -value 1
.bl.cvgDestMB.menu add radiobutton -label "full" -command CblCvgDest -variable blCvgDest -value 2
.bl.cvgDestMB.menu add radiobutton -label "save" -command CblCvgDest -variable blCvgDest -value 3

set blCvgDest 0
set LblCvgDest clamp

proc CblCvgDest {} {
	global LblCvgDest blCvgDest
	global fptr record
	global blCycle0ModeWord blCycle1ModeWord
	global CVG_DST_MASK CVG_DST_WRAP CVG_DST_FULL CVG_DST_SAVE

	# set modeword based on CB selection
	set blCycle1ModeWord [expr $blCycle1ModeWord & ~($CVG_DST_MASK)]
	set blCycle0ModeWord [expr $blCycle0ModeWord & ~($CVG_DST_MASK)]

        switch $blCvgDest {
		1 {set blCycle1ModeWord [expr $blCycle1ModeWord | $CVG_DST_WRAP] 
		   set blCycle0ModeWord [expr $blCycle0ModeWord | $CVG_DST_WRAP] }
		2 {set blCycle1ModeWord [expr $blCycle1ModeWord | $CVG_DST_FULL]
		   set blCycle0ModeWord [expr $blCycle0ModeWord | $CVG_DST_FULL] }
		3 {set blCycle1ModeWord [expr $blCycle1ModeWord | $CVG_DST_SAVE]
		   set blCycle0ModeWord [expr $blCycle0ModeWord | $CVG_DST_SAVE] }
	}

  	switch $blCvgDest {
		0 {set LblCvgDest clamp}
		1 {set LblCvgDest wrap}
		2 {set LblCvgDest full}
		3 {set LblCvgDest save}
  	}

  	if {$record == 1} {
		puts $fptr "set blCvgDest $blCvgDest"
		puts $fptr "CblCvgDest"
  	}
	callback_blCycle
	callback_send_dl
}


checkbutton .bl.colOnCvgCB -width 13 -text "colOnCvg" -variable blColOnCvg -command CblColOnCvg

proc CblColOnCvg {} {
	global fptr record blColOnCvg
	global blCycle0ModeWord blCycle1ModeWord CLR_ON_CVG

	# set modeword based on CB selection
	set blCycle1ModeWord [expr $blCycle1ModeWord & ~($CLR_ON_CVG)]
	set blCycle0ModeWord [expr $blCycle0ModeWord & ~($CLR_ON_CVG)]

        if {$blColOnCvg == 1} {
		set blCycle1ModeWord [expr $blCycle1ModeWord | $CLR_ON_CVG]
		set blCycle0ModeWord [expr $blCycle0ModeWord | $CLR_ON_CVG]
	}

        if {$record == 1} {
                puts $fptr "set blColOnCvg $blColOnCvg"
		puts $fptr "CblColOnCvg"
        }
	callback_blCycle
	callback_send_dl
}

checkbutton .bl.cvgXalphaCB -width 13 -text "cvgXalpha" -variable blCvgXalpha -command CblCvgXalpha

proc CblCvgXalpha {} {
	global fptr record blCvgXalpha
	global blCycle0ModeWord blCycle1ModeWord CVG_X_ALPHA

	# set modeword based on CB selection
	set blCycle1ModeWord [expr $blCycle1ModeWord & ~($CVG_X_ALPHA)]
	set blCycle0ModeWord [expr $blCycle0ModeWord & ~($CVG_X_ALPHA)]

        if {$blCvgXalpha == 1} {
		set blCycle1ModeWord [expr $blCycle1ModeWord | $CVG_X_ALPHA]
		set blCycle0ModeWord [expr $blCycle0ModeWord | $CVG_X_ALPHA]
	}

	if {$record == 1} {
                puts $fptr "set blCvgXalpha $blCvgXalpha"
		puts $fptr "CblCvgXalpha"
        }
	callback_blCycle
	callback_send_dl
}

checkbutton .bl.alphaCvgSelCB -width 13 -text "alphaCvgSel" -variable blAlphaCvgSel -command CblAlphaCvgSel

proc CblAlphaCvgSel {} {
	global fptr record blAlphaCvgSel
	global blCycle0ModeWord blCycle1ModeWord ALPHA_CVG_SEL

	# set modeword based on CB selection
	set blCycle1ModeWord [expr $blCycle1ModeWord & ~($ALPHA_CVG_SEL)]
	set blCycle0ModeWord [expr $blCycle0ModeWord & ~($ALPHA_CVG_SEL)]

        if {$blAlphaCvgSel == 1} {
		set blCycle1ModeWord [expr $blCycle1ModeWord | $ALPHA_CVG_SEL]
		set blCycle0ModeWord [expr $blCycle0ModeWord | $ALPHA_CVG_SEL]
	}

	if {$record == 1} {
                puts $fptr "set blAlphaCvgSel $blAlphaCvgSel"
		puts $fptr "CblAlphaCvgSel"
        }
	callback_blCycle
	callback_send_dl
}

checkbutton .bl.forceBlendCB -width 13 -text "forceBlend" -variable blForceBlend -command CblForceBlend

proc CblForceBlend {} {
	global fptr record blForceBlend
	global blCycle0ModeWord blCycle1ModeWord FORCE_BL

	# set modeword based on CB selection
	set blCycle1ModeWord [expr $blCycle1ModeWord & ~($FORCE_BL)]
	set blCycle0ModeWord [expr $blCycle0ModeWord & ~($FORCE_BL)]

        if {$blForceBlend == 1} {
		set blCycle1ModeWord [expr $blCycle1ModeWord | $FORCE_BL]
		set blCycle0ModeWord [expr $blCycle0ModeWord | $FORCE_BL]
	}

	if {$record == 1} {
                puts $fptr "set blForceBlend $blForceBlend"
		puts $fptr "CblForceBlend"
        }
	callback_blCycle
	callback_send_dl
}

#checkbutton .bl.zModeCB -width 13 -text "zMode" -variable blZmode -command CblZmode
#
#proc CblZmode {} {
#	global fptr record blZmode
#
#	if {$record == 1} {
#                puts $fptr "set blZmode $blZmode"
#		puts $fptr "CblZmode"
#        }
#}

	

menubutton .bl.zModeMB -width 15 -textvariable LblZmode -relief  raised  \
-menu .bl.zModeMB.menu -bg LightGray -activebackground LightGray

menu .bl.zModeMB.menu 
.bl.zModeMB.menu add radiobutton -label "opaque" -command CblZmode -variable blZmode -value 0
.bl.zModeMB.menu add radiobutton -label "inter" -command CblZmode -variable blZmode -value 1
.bl.zModeMB.menu add radiobutton -label "trans" -command CblZmode -variable blZmode -value 2
.bl.zModeMB.menu add radiobutton -label "decal" -command CblZmode -variable blZmode -value 3

#set blZmode 0
#set LblZmode clamp

proc CblZmode {} {
	global LblZmode blZmode
	global fptr record
	global blCycle0ModeWord blCycle1ModeWord
	global ZMODE_MASK ZMODE_INTER ZMODE_XLU ZMODE_DEC

	# set modeword based on CB selection
	set blCycle1ModeWord [expr $blCycle1ModeWord & ~($ZMODE_MASK)]
	set blCycle0ModeWord [expr $blCycle0ModeWord & ~($ZMODE_MASK)]

        switch $blZmode {
		1 {set blCycle1ModeWord [expr $blCycle1ModeWord | $ZMODE_INTER]
		   set blCycle0ModeWord [expr $blCycle0ModeWord | $ZMODE_INTER] }
		2 {set blCycle1ModeWord [expr $blCycle1ModeWord | $ZMODE_XLU]
		   set blCycle0ModeWord [expr $blCycle0ModeWord | $ZMODE_XLU] }
		3 {set blCycle1ModeWord [expr $blCycle1ModeWord | $ZMODE_DEC]
		   set blCycle0ModeWord [expr $blCycle0ModeWord | $ZMODE_DEC] }
	}

  switch $blZmode {
	0 {set LblZmode opaque}
	1 {set LblZmode inter}
	2 {set LblZmode trans}
	3 {set LblZmode decal}
  }

  if {$record == 1} {
	puts $fptr "set blZmode $blZmode"
	puts $fptr "CblZmode"
  }
	callback_blCycle
	callback_send_dl
}


checkbutton .bl.texEdgeModeCB -width 13 -text "texEdgeMode" -variable blTexEdgeMode -command CblTexEdgeMode

proc CblTexEdgeMode {} {
	global fptr record blTexEdgeMode
	global blCycle0ModeWord blCycle1ModeWord TEX_EDGE

#        puts "Inside CblTexEdgeMode : blTexEdgeMode = $blTexEdgeMode"
	# set modeword based on CB selection
	set blCycle1ModeWord [expr $blCycle1ModeWord & ~($TEX_EDGE)]
	set blCycle0ModeWord [expr $blCycle0ModeWord & ~($TEX_EDGE)]

        if {$blTexEdgeMode == 1} {
		set blCycle1ModeWord [expr $blCycle1ModeWord | $TEX_EDGE]
		set blCycle0ModeWord [expr $blCycle0ModeWord | $TEX_EDGE]
	}
	
	if {$record == 1} {
                puts $fptr "set blTexEdgeMode $blTexEdgeMode"
		puts $fptr "CblTexEdgeMode"
        }
	callback_blCycle
	callback_send_dl
}

checkbutton .bl.alphaCompEnCB -width 13 -text "alphaCompEn" -variable blAlphaCompEn -command CblAlphaCompEn

proc CblAlphaCompEn {} {
	global fptr record blAlphaCompEn
	global blCycle0ModeWord blCycle1ModeWord A_CMP_EN

	# set modeword based on CB selection
	set blCycle1ModeWord [expr $blCycle1ModeWord & ~($A_CMP_EN)]
	set blCycle0ModeWord [expr $blCycle0ModeWord & ~($A_CMP_EN)]

        if {$blAlphaCompEn == 1} {
		set blCycle1ModeWord [expr $blCycle1ModeWord | $A_CMP_EN]
		set blCycle0ModeWord [expr $blCycle0ModeWord | $A_CMP_EN]
	}
	
	 if {$record == 1} {
                puts $fptr "set blAlphaCompEn $blAlphaCompEn"
		puts $fptr "CblAlphaCompEn"
        }
	callback_blCycle
	callback_send_dl
}

checkbutton .bl.dithAlphaEnCB -width 13 -text "dithAlphaEn" -variable blDithAlphaEn -command CblDithAlphaEn

proc CblDithAlphaEn {} {
	global fptr record blDithAlphaEn
	global blCycle0ModeWord blCycle1ModeWord A_DITH_EN

	# set modeword based on CB selection
	set blCycle1ModeWord [expr $blCycle1ModeWord & ~($A_DITH_EN)]
	set blCycle0ModeWord [expr $blCycle0ModeWord & ~($A_DITH_EN)]

        if {$blDithAlphaEn == 1} {
		set blCycle1ModeWord [expr $blCycle1ModeWord | $A_DITH_EN]
		set blCycle0ModeWord [expr $blCycle0ModeWord | $A_DITH_EN]
	}
	
	if {$record == 1} {
                puts $fptr "set blDithAlphaEn $blDithAlphaEn"
		puts $fptr "CblDithAlphaEn"
        }
	callback_blCycle
	callback_send_dl
}

checkbutton .bl.zSrcSelCB -width 13 -textvariable LzSrcSel -variable blZsrcSel -command CblZsrcSel

proc CblZsrcSel {} {
	global fptr record blZsrcSel LzSrcSel
	global blCycle0ModeWord blCycle1ModeWord Z_SRC_SEL

	# set modeword based on CB selection
	set blCycle1ModeWord [expr $blCycle1ModeWord & ~($Z_SRC_SEL)]
	set blCycle0ModeWord [expr $blCycle0ModeWord & ~($Z_SRC_SEL)]

        if {$blZsrcSel == 1} {
		set blCycle1ModeWord [expr $blCycle1ModeWord | $Z_SRC_SEL]
		set blCycle0ModeWord [expr $blCycle0ModeWord | $Z_SRC_SEL]
	}
	
        if {$blZsrcSel == 1} {
		set LzSrcSel "zSrcPrim"
	} else {
		set LzSrcSel "zSrcPixel"
	}

	if {$record == 1} {
                puts $fptr "set blZsrcSel $blZsrcSel"
		puts $fptr "CblZsrcSel"
        }
	callback_blCycle
	callback_send_dl
}
#--------------------------dither Modes--------------------------------------
label .bl.alphaDitherL -text "alphaDither"
menubutton .bl.alphaDitherMB -textvariable LblAlphaDither -width 9 -relief raised -menu .bl.alphaDitherMB.menu -bg LightGray -activebackground LightGray
menu .bl.alphaDitherMB.menu
.bl.alphaDitherMB.menu add radiobutton -label "pattern" -command CalphaDither -variable blAlphaDither -value 0
.bl.alphaDitherMB.menu add radiobutton -label "~pattern" -command CalphaDither -variable blAlphaDither -value 1
.bl.alphaDitherMB.menu add radiobutton -label "Noise" -command CalphaDither -variable blAlphaDither -value 2
.bl.alphaDitherMB.menu add radiobutton -label "Off" -command CalphaDither -variable blAlphaDither -value 3

proc CalphaDither {} {
	global fptr record
	global LblAlphaDither dPattern
	global blAlphaDither

	switch $blAlphaDither {
		0 {set LblAlphaDither $dPattern }
		1 {set LblAlphaDither "~ $dPattern" }
		2 {set LblAlphaDither "noise" }
		3 {set LblAlphaDither "Off" }
	}

	if {$record == 1} {
                puts $fptr "set blAlphaDither $blAlphaDither"
                puts $fptr "CalphaDither"
        }

	callback_blAlphaDither
	callback_send_dl
}



label .bl.rgbDitherL -text "rgbDither"
menubutton .bl.rgbDitherMB -textvariable LblRgbDither -width 9 -relief raised -menu .bl.rgbDitherMB.menu -bg LightGray -activebackground LightGray
menu .bl.rgbDitherMB.menu
.bl.rgbDitherMB.menu add radiobutton -label "MagicSq" -command CrgbDither -variable blRgbDither -value 0
.bl.rgbDitherMB.menu add radiobutton -label "Bayer" -command CrgbDither -variable blRgbDither -value 1
.bl.rgbDitherMB.menu add radiobutton -label "Noise" -command CrgbDither -variable blRgbDither -value 2
.bl.rgbDitherMB.menu add radiobutton -label "Off" -command CrgbDither -variable blRgbDither -value 3

proc CrgbDither {} {
	global fptr record
	global LblRgbDither LblAlphaDither
	global blRgbDither blAlphaDither dPattern

	switch $blRgbDither {
		0 {set LblRgbDither "MagicSq" 
		   set dPattern "MagicSq" }

		1 {set LblRgbDither "Bayer" 
		   set dPattern "Bayer" }

		2 {set LblRgbDither "Noise"
		   set dPattern "MagicSq" }

		3 {set LblRgbDither "Off"
		   set dPattern "Bayer" }
	}

	CalphaDither

	if {$record == 1} {
                puts $fptr "set blRgbDither $blRgbDither"
                puts $fptr "set blAlphaDither $blAlphaDither"
                puts $fptr "CrgbDither"
        }

	callback_blRgbDither
	callback_send_dl
}



label .bl.videoAAFilterL -text "vidDithFilt"
checkbutton .bl.videoAAFilterCB -width 9 -text "vidAAFilt" -variable blVideoAAFilter -command CblVideoAAFilter

proc CblVideoAAFilter {} {
  global blVideoAAFilter
  global spindso fptr record

  if {$blVideoAAFilter == 0}  {
	$spindso call SpinTclModel 104
  } else { 
    if {$blVideoAAFilter == 1}  {
	$spindso call SpinTclModel 105
    }
  }
  if {$record == 1} {
	if {$blVideoAAFilter == 0} {
	  puts $fptr "$spindso call SpinTclModel 104"
	  puts $fptr "set blVideoAAFilter 0"
	} else {
	  if {$blVideoAAFilter == 1} {
	    puts $fptr "$spindso call SpinTclModel 105"
	    puts $fptr "set blVideoAAFilter 1"
          }
	}
  }
}

label .bl.videoDitherFilterL -text "vidDithFilt"
checkbutton .bl.videoDitherFilterCB -width 10 -text "vidDithFilt" -variable blVideoDitherFilter -command CblVideoDitherFilter

proc CblVideoDitherFilter {} {
  global blVideoDitherFilter
  global spindso fptr record

  if {$blVideoDitherFilter == 0}  {
	$spindso call SpinTclModel 100
  } else { 
    if {$blVideoDitherFilter == 1}  {
	$spindso call SpinTclModel 101
    }
  }

  if {$record == 1} {
	if {$blVideoDitherFilter == 0} {
	  puts $fptr "$spindso call SpinTclModel 100"
	  puts $fptr "set blVideoDitherFilter 0"
	} else {
	  if {$blVideoDitherFilter == 1} {
	    puts $fptr "$spindso call SpinTclModel 101"
	    puts $fptr "set blVideoDitherFilter 1"
          }
	}
  }
}


label .bl.frameBufferSizeL -text "cfbSize"
checkbutton .bl.frameBufferSizeCB -width 9 -text "cfbSize32" -variable blFrameBufferSize -command CblFrameBufferSize

proc CblFrameBufferSize {} {
  global blFrameBufferSize
  global blRgbDither blAlphaDither blVideoDitherFilter
  global spindso fptr record

  if {$blFrameBufferSize == 0}  {
	set blRgbDither 1
	CrgbDither
	set blAlphaDither 1
	CalphaDither
	set blVideoDitherFilter 1
	CblVideoDitherFilter
	$spindso call SpinTclModel 102
	if {$record == 1} {
		puts $fptr "set blRgbDither 1"
		puts $fptr "CrgbDither"
		puts $fptr "set blAlphaDither 1"
		puts $fptr "CalphaDither"
		puts $fptr "set blVideoDitherFilter 1"
		puts $fptr "CblVideoDitherFilter"
		puts $fptr "$spindso call SpinTclModel 102"
		puts $fptr "set blFrameBufferSize 0"
	}
	
  } else { 
    if {$blFrameBufferSize == 1}  {
	set blRgbDither 3
	CrgbDither
	set blAlphaDither 3
	CalphaDither
	set blVideoDitherFilter 0
	CblVideoDitherFilter
	$spindso call SpinTclModel 103
	if {$record == 1} {
		puts $fptr "set blRgbDither 3"
		puts $fptr "CrgbDither"
		puts $fptr "set blAlphaDither 3"
		puts $fptr "CalphaDither"
		puts $fptr "set blVideoDitherFilter 0"
		puts $fptr "CblVideoDitherFilter"
		puts $fptr "$spindso call SpinTclModel 103"
		puts $fptr "set blFrameBufferSize 1"
	}
    }
  }
}

set blFrameBufferSize 0
CblFrameBufferSize
#--------------------------Blend Color--------------------------------------

checkbutton .bl.fbShiftL -width 15 -text "frameBuf shift " -variable fbShiftEnable -command fbShiftEnableProc
entry .bl.fbShiftE -width 3 -relief sunken -textvariable fbShift

proc fbShiftEnableProc {} {
    global fbShiftEnable
    global spindso fptr record

  if {$fbShiftEnable == 0}  {
	$spindso call SpinTclModel 118
  } else { 
    if {$fbShiftEnable == 1}  {
	$spindso call SpinTclModel 119
    }
  }
  if {$record == 1} {
	if {$fbShiftEnable == 0} {
	  puts $fptr "$spindso call SpinTclModel 118"
	  puts $fptr "set fbShiftEnable 0"
	} else {
	  if {$fbShiftEnable == 1} {
	    puts $fptr "$spindso call SpinTclModel 119"
	    puts $fptr "set fbShiftEnable 1"
          }
	}
  }

}

set fbShift 0

proc CblfbShift value {
	global fbShift fptr
	set blBlendColorRed $value
	if {$record == 1} {
		puts $fptr ".bl.blendColorRedS set $blBlendColorRed"
	}

	callback_blBlendColor
	callback_send_dl
}

bind .bl.fbShiftE <Return> {
 if {$fbShift > 255} {set fbShift 255}
 if {$fbShift < 0} {set fbShift 0}
	if {$record == 1} {
                puts $fptr "set fbShift $fbShift"
		puts $fptr "$spindso call SpinTclModel [expr $fbShift + 110]"
        }
	$spindso call SpinTclModel [expr $fbShift + 110]
	focus none
}



label .bl.blendColorL -width 11 -text "Blend Color"

scale .bl.blendColorRedS -label Red -from 0 -to 255 -length 181 -orient horizontal -command CblBlendColorRed

entry .bl.blendColorRedE -width 3 -relief sunken -textvariable blBlendColorRed
bind .bl.blendColorRedE <Return> {
	if {$blBlendColorRed > 255} {set blBlendColorRed 255}
	if {$blBlendColorRed < 0} {set blBlendColorRed 0}
	.bl.blendColorRedS set $blBlendColorRed
	focus none
}

#.bl.blendColorRedS set 128

proc CblBlendColorRed value {
	global blBlendColorRed
	global fptr record
	set blBlendColorRed $value
	if {$record == 1} {
		puts $fptr ".bl.blendColorRedS set $blBlendColorRed"
	}
	callback_blBlendColor
	callback_send_dl
}

scale .bl.blendColorBlueS -label Blue -from 0 -to 255 -length 181 -orient horizontal -command CblBlendColorBlue

entry .bl.blendColorBlueE -width 3 -relief sunken -textvariable blBlendColorBlue
bind .bl.blendColorBlueE <Return> {
	if {$blBlendColorBlue > 255} {set blBlendColorBlue 255}
	if {$blBlendColorBlue < 0} {set blBlendColorBlue 0}
	.bl.blendColorBlueS set $blBlendColorBlue
	focus none
}
#.bl.blendColorBlueS set 128

proc CblBlendColorBlue value {
	global blBlendColorBlue
	global fptr record
	set blBlendColorBlue $value
	if {$record == 1} {
		puts $fptr ".bl.blendColorBlueS set $blBlendColorBlue"
	}
	callback_blBlendColor
	callback_send_dl
}

scale .bl.blendColorAlphaS -label Alpha -from 0 -to 255 -length 181 -orient horizontal -command CblBlendColorAlpha

entry .bl.blendColorAlphaE -width 3 -relief sunken -textvariable blBlendColorAlpha
bind .bl.blendColorAlphaE <Return> {
	if {$blBlendColorAlpha > 255} {set blBlendColorAlpha 255}
	if {$blBlendColorAlpha < 0} {set blBlendColorAlpha 0}
	.bl.blendColorAlphaS set $blBlendColorAlpha
	focus none
}
#.bl.blendColorAlphaS set 128

proc CblBlendColorAlpha value {
	global blBlendColorAlpha
	global fptr record
	set blBlendColorAlpha $value
	if {$record == 1} {
		puts $fptr ".bl.blendColorAlphaS set $blBlendColorAlpha"
	}
	callback_blBlendColor
	callback_send_dl
}

scale .bl.blendColorGreenS -label Green -from 0 -to 255 -length 181 -orient horizontal -command CblBlendColorGreen

entry .bl.blendColorGreenE -width 3 -relief sunken -textvariable blBlendColorGreen
bind .bl.blendColorGreenE <Return> {
	if {$blBlendColorGreen > 255} {set blBlendColorGreen 255}
	if {$blBlendColorGreen < 0} {set blBlendColorGreen 0}
	.bl.blendColorGreenS set $blBlendColorGreen
	focus none
}
#.bl.blendColorGreenS set 128

proc CblBlendColorGreen value {
	global blBlendColorGreen
	global fptr record
	set blBlendColorGreen $value
	if {$record == 1} {
		puts $fptr ".bl.blendColorGreenS set $blBlendColorGreen"
	}
	callback_blBlendColor
	callback_send_dl
}
#---------------------------Fog Color------------------------------------
label .bl.fogColorL -width 11 -text "Fog Color"

scale .bl.fogColorRedS -label Red -from 0 -to 255 -length 181 -orient horizontal -command CblFogColorRed

entry .bl.fogColorRedE -width 3 -relief sunken -textvariable blFogColorRed
bind .bl.fogColorRedE <Return> {
	if {$blFogColorRed > 255} {set blFogColorRed 255}
	if {$blFogColorRed < 0} {set blFogColorRed 0}
	.bl.fogColorRedS set $blFogColorRed
	focus none
}

#.bl.fogColorRedS set 128

proc CblFogColorRed value {
	global blFogColorRed
	global fptr record
	set blFogColorRed $value
	if {$record == 1} {
		puts $fptr ".bl.fogColorRedS set $blFogColorRed"
	}
	callback_blFogColor
	callback_send_dl
}

scale .bl.fogColorBlueS -label Blue -from 0 -to 255 -length 181 -orient horizontal -command CblFogColorBlue

entry .bl.fogColorBlueE -width 3 -relief sunken -textvariable blFogColorBlue
bind .bl.fogColorBlueE <Return> {
	if {$blFogColorBlue > 255} {set blFogColorBlue 255}
	if {$blFogColorBlue < 0} {set blFogColorBlue 0}
	.bl.fogColorBlueS set $blFogColorBlue
	focus none
}
#.bl.fogColorBlueS set 128

proc CblFogColorBlue value {
	global blFogColorBlue
	global fptr record
	set blFogColorBlue $value
	if {$record == 1} {
		puts $fptr ".bl.fogColorBlueS set $blFogColorBlue"
	}
	callback_blFogColor
	callback_send_dl
}

scale .bl.fogColorAlphaS -label Alpha -from 0 -to 255 -length 181 -orient horizontal -command CblFogColorAlpha

entry .bl.fogColorAlphaE -width 3 -relief sunken -textvariable blFogColorAlpha
bind .bl.fogColorAlphaE <Return> {
	if {$blFogColorAlpha > 255} {set blFogColorAlpha 255}
	if {$blFogColorAlpha < 0} {set blFogColorAlpha 0}
	.bl.fogColorAlphaS set $blFogColorAlpha
	focus none
}
#.bl.fogColorAlphaS set 128

proc CblFogColorAlpha value {
	global blFogColorAlpha
	global fptr record
	set blFogColorAlpha $value
	if {$record == 1} {
		puts $fptr ".bl.fogColorAlphaS set $blFogColorAlpha"
	}
	callback_blFogColor
	callback_send_dl
}

scale .bl.fogColorGreenS -label Green -from 0 -to 255 -length 181 -orient horizontal -command CblFogColorGreen

entry .bl.fogColorGreenE -width 3 -relief sunken -textvariable blFogColorGreen
bind .bl.fogColorGreenE <Return> {
	if {$blFogColorGreen > 255} {set blFogColorGreen 255}
	if {$blFogColorGreen < 0} {set blFogColorGreen 0}
	.bl.fogColorGreenS set $blFogColorGreen
	focus none
}
#.bl.fogColorGreenS set 128

proc CblFogColorGreen value {
	global blFogColorGreen
	global fptr record
	set blFogColorGreen $value
	if {$record == 1} {
		puts $fptr ".bl.fogColorGreenS set $blFogColorGreen"
	}
	callback_blFogColor
	callback_send_dl
}

#---------------------------Z delta Z ----------------------------------------
label .bl.primZL -width 11 -text "Prim Depth"

scale .bl.primZS -label Z -from 0 -to 65535 -length 393 -orient horizontal -command CblPrimZ

entry .bl.primZE -width 6 -relief sunken -textvariable blPrimZ
bind .bl.primZE <Return> {
        if {$blPrimZ > 65535} {set blPrimZ 65535}
        if {$blPrimZ < 0} {set blPrimZ 0}
        .bl.primZS set $blPrimZ
        focus none
}

proc CblPrimZ value {
        global blPrimZ
        global fptr record
        set blPrimZ $value
        if {$record == 1} {
                puts $fptr ".bl.primZS set $blPrimZ"
        }
        callback_blPrim
        callback_send_dl
}

label .bl.primDeltaZL -width 11 -text "Prim Depth"

scale .bl.primDeltaZS -label "delta Z" -from 0 -to 65535 -length 393 -orient horizontal -command CblPrimDeltaZ

entry .bl.primDeltaZE -width 6 -relief sunken -textvariable blPrimDeltaZ
bind .bl.primDeltaZE <Return> {
        if {$blPrimDeltaZ > 65535} {set blPrimDeltaZ 65535}
        if {$blPrimDeltaZ < 0} {set blPrimDeltaZ 0}
        .bl.primDeltaZS set $blPrimDeltaZ
        focus none
}

proc CblPrimDeltaZ value {
        global blPrimDeltaZ
        global fptr record
        set blPrimDeltaZ $value
        if {$record == 1} {
                puts $fptr ".bl.primDeltaZS set $blPrimDeltaZ"
        }
        callback_blPrim
        callback_send_dl
}



#---------------------------BL Muxes--------------------------------------
#---------------------------Utility functions-----------------------------
set M1A1_SH 30
set M1B1_SH 26 
set M2A1_SH 22
set M2B1_SH 18

set M1A2_SH 28
set M1B2_SH 24 
set M2A2_SH 20
set M2B2_SH 16

set AA_EN           0x8
set Z_CMP           0x10
set Z_UPD           0x20
set IM_RD           0x40
set CLR_ON_CVG      0x80
set CVG_DST_CLAMP   0
set CVG_DST_WRAP    0x100
set CVG_DST_FULL    0x200
set CVG_DST_SAVE    0x300
set CVG_DST_MASK    0x300
set CVG_DST_SH      8
set ZMODE_OPA       0
set ZMODE_INTER     0x400
set ZMODE_XLU       0x800
set ZMODE_DEC       0xc00
set ZMODE_MASK      0xc00
set ZMODE_SH	    10
set CVG_X_ALPHA     0x1000
set ALPHA_CVG_SEL   0x2000
set FORCE_BL        0x4000
set TEX_EDGE        0x8000
set A_CMP_EN	    0x0001
set A_DITH_EN 	    0x0002
set Z_SRC_SEL 	    0x0004


proc getBLcolorLabelA val {
  switch $val {
	0 {return "Bl/Pix Color"}
	1 {return "Mem Color"}
	2 {return "Blend Color"}
	3 {return "Fog Color"}
  }
}

proc getBLcolorLabelB val {
  switch $val {
	0 {return "Pixel Alpha"}
	1 {return "Prim Alpha"}
	2 {return "Shade Alpha"}
 	3 {return "0.0"}
  }
}

proc getBLcolorLabelC val {
  switch $val {
	0 {return "Bl/Pix Color"}
	1 {return "Mem Color"}
	2 {return "Blend Color"}
	3 {return "Fog Color"}
  }
}

proc getBLcolorLabelD val {
  switch $val {
	0 {return "1.0 - A"}
	1 {return "Mem Alpha"}
 	2 {return "1.0"}
 	3 {return "0.0"}
  }
}

label .bl.cycle0ColorL -width 11 -text "Cycle0 Blend"

label .bl.cycle0ColorL( -width 5 -text "=   ("

menubutton .bl.cycle0ColorAMB -textvariable LblCycle0ColorA -width 12 \
-relief  raised -menu .bl.cycle0ColorAMB.menu -bg LightGray \
-activebackground LightGray -disabledforeground DarkGray

menu .bl.cycle0ColorAMB.menu
.bl.cycle0ColorAMB.menu add radiobutton -label "Blend/Pix Color" -command CblCycle0ColorA  -variable blCycle0ColorA -value 0
.bl.cycle0ColorAMB.menu add radiobutton -label "Mem Color" -command CblCycle0ColorA -variable blCycle0ColorA -value 1
.bl.cycle0ColorAMB.menu add radiobutton -label "Blend Color" -command CblCycle0ColorA -variable blCycle0ColorA -value 2
.bl.cycle0ColorAMB.menu add radiobutton -label "Fog Color" -command CblCycle0ColorA -variable blCycle0ColorA -value 3

#set blCycle0ColorA 2
#set LblCycle0ColorA "Tex1 Color"

proc CblCycle0ColorA {} {
     global LblCycle0ColorA blCycle0ColorA
     global fptr record
     global blCycle0ModeWord
     global M1A1_SH
     global rspCycleType blCycle1ColorA

     set blCycle0ModeWord [expr $blCycle0ModeWord & ~(3 << $M1A1_SH)]
     set blCycle0ModeWord [expr $blCycle0ModeWord | ($blCycle0ColorA << $M1A1_SH)]

     set LblCycle0ColorA  [getBLcolorLabelA $blCycle0ColorA]

     if {$record == 1} {
	puts $fptr "set blCycle0ColorA $blCycle0ColorA"
	puts $fptr "CblCycle0ColorA"
     }
    
     if {$rspCycleType == 0} {
	set blCycle1ColorA $blCycle0ColorA
	CblCycle1ColorA
     }
	
	callback_blCycle
	callback_send_dl
}


label .bl.cycle0ColorLX1 -width 1 -text "X"
label .bl.cycle0ColorLX2 -width 1 -text "X"

menubutton .bl.cycle0ColorBMB -textvariable LblCycle0ColorB -width 12 \
-relief  raised -menu .bl.cycle0ColorBMB.menu -bg LightGray \
-activebackground LightGray -disabledforeground DarkGray

menu .bl.cycle0ColorBMB.menu
.bl.cycle0ColorBMB.menu add radiobutton -label "Pixel Alpha" -command CblCycle0ColorB -variable blCycle0ColorB -value 0
.bl.cycle0ColorBMB.menu add radiobutton -label "Prim Alpha" -command CblCycle0ColorB -variable blCycle0ColorB -value 1
.bl.cycle0ColorBMB.menu add radiobutton -label "Shade Alpha" -command CblCycle0ColorB -variable blCycle0ColorB -value 2
.bl.cycle0ColorBMB.menu add radiobutton -label "0.0" -command CblCycle0ColorB -variable blCycle0ColorB -value 3

#set blCycle0ColorB "Tex0 Color"
#set LblCycle0ColorB "Tex0 Color"

proc CblCycle0ColorB {} {
     global LblCycle0ColorB blCycle0ColorB
     global fptr record
     global blCycle0ModeWord M1B1_SH
     global rspCycleType blCycle1ColorB

     set blCycle0ModeWord [expr $blCycle0ModeWord & ~(3 << $M1B1_SH)]
     set blCycle0ModeWord [expr $blCycle0ModeWord | ($blCycle0ColorB << $M1B1_SH)]

     set LblCycle0ColorB  [getBLcolorLabelB $blCycle0ColorB]

     if {$record == 1} {
	puts $fptr "set blCycle0ColorB $blCycle0ColorB"
	puts $fptr "CblCycle0ColorB"
     }
     if {$rspCycleType == 0} {
	set blCycle1ColorB $blCycle0ColorB
	CblCycle1ColorB
     }
	callback_blCycle
	callback_send_dl
}

label .bl.cycle0ColorL+ -width 1 -text "+"

menubutton .bl.cycle0ColorCMB -textvariable LblCycle0ColorC -width 12 \
-relief  raised -menu .bl.cycle0ColorCMB.menu -bg LightGray \
-activebackground LightGray -disabledforeground DarkGray

menu .bl.cycle0ColorCMB.menu
.bl.cycle0ColorCMB.menu add radiobutton -label "Blend/Pix Color" -command CblCycle0ColorC -variable blCycle0ColorC -value 0
.bl.cycle0ColorCMB.menu add radiobutton -label "Mem Color" -command CblCycle0ColorC -variable blCycle0ColorC -value 1
.bl.cycle0ColorCMB.menu add radiobutton -label "Blend Color" -command CblCycle0ColorC -variable blCycle0ColorC -value 2
.bl.cycle0ColorCMB.menu add radiobutton -label "Fog Color" -command CblCycle0ColorC -variable blCycle0ColorC -value 3

#set blCycle0ColorC 13
#set LblCycle0ColorC "LOD Frac"

proc CblCycle0ColorC {} {
     global LblCycle0ColorC blCycle0ColorC
     global fptr record
     global blCycle0ModeWord M2A1_SH
     global rspCycleType blCycle1ColorC

     set blCycle0ModeWord [expr $blCycle0ModeWord & ~(3 << $M2A1_SH)]
     set blCycle0ModeWord [expr $blCycle0ModeWord | ($blCycle0ColorC << $M2A1_SH)]

     set LblCycle0ColorC  [getBLcolorLabelC $blCycle0ColorC]

     if {$record == 1} {
	puts $fptr "set blCycle0ColorC $blCycle0ColorC"
	puts $fptr "CblCycle0ColorC"
     }

     if {$rspCycleType == 0} {
	set blCycle1ColorC $blCycle0ColorC
	CblCycle1ColorC
     }

	callback_blCycle
	callback_send_dl
}

label .bl.cycle0ColorL) -width 5 -text ") / ("

menubutton .bl.cycle0ColorDMB -textvariable LblCycle0ColorD -width 12 \
-relief  raised -menu .bl.cycle0ColorDMB.menu -bg LightGray \
-activebackground LightGray -disabledforeground DarkGray

menu .bl.cycle0ColorDMB.menu
.bl.cycle0ColorDMB.menu add radiobutton -label "1.0 - A" -command CblCycle0ColorD -variable blCycle0ColorD -value 0
.bl.cycle0ColorDMB.menu add radiobutton -label "Mem Alpha" -command CblCycle0ColorD -variable blCycle0ColorD -value 1
.bl.cycle0ColorDMB.menu add radiobutton -label "1.0" -command CblCycle0ColorD -variable blCycle0ColorD -value 2
.bl.cycle0ColorDMB.menu add radiobutton -label "0.0" -command CblCycle0ColorD -variable blCycle0ColorD -value 3

#set blCycle0ColorD 1
#set LblCycle0ColorD "Tex0 Color"

proc CblCycle0ColorD {} {
     global LblCycle0ColorD blCycle0ColorD
     global fptr record
     global blCycle0ModeWord M2B1_SH
     global rspCycleType blCycle1ColorD

     set blCycle0ModeWord [expr $blCycle0ModeWord & ~(3 << $M2B1_SH)]
     set blCycle0ModeWord [expr $blCycle0ModeWord | ($blCycle0ColorD << $M2B1_SH)]

     set LblCycle0ColorD  [getBLcolorLabelD $blCycle0ColorD]

     if {$record == 1} {
	puts $fptr "set blCycle0ColorD $blCycle0ColorD"
	puts $fptr "CblCycle0ColorD"
     }

     if {$rspCycleType == 0} {
	set blCycle1ColorD $blCycle0ColorD
	CblCycle1ColorD
     }
	callback_blCycle
	callback_send_dl
}

label .bl.cycle0ColorL1+ -width 1 -text "+"
label .bl.cycle0ColorL1) -width 1 -text ")"

label .bl.cycle0ColorBL -width 11 -textvariable LblCycle0ColorB
label .bl.cycle0ColorDL -width 11 -textvariable LblCycle0ColorD

#---------------------------------------------------------------------------#
label .bl.cycle1ColorL -width 11 -text "Cycle1 Blend"

label .bl.cycle1ColorL( -width 5 -text "=   ("

menubutton .bl.cycle1ColorAMB -textvariable LblCycle1ColorA -width 12 \
-relief  raised -menu .bl.cycle1ColorAMB.menu -bg LightGray \
-activebackground LightGray -disabledforeground DarkGray

menu .bl.cycle1ColorAMB.menu
.bl.cycle1ColorAMB.menu add radiobutton -label "Blend/Pix Color" -command CblCycle1ColorA  -variable blCycle1ColorA -value 0
.bl.cycle1ColorAMB.menu add radiobutton -label "Mem Color" -command CblCycle1ColorA -variable blCycle1ColorA -value 1
.bl.cycle1ColorAMB.menu add radiobutton -label "Blend Color" -command CblCycle1ColorA -variable blCycle1ColorA -value 2
.bl.cycle1ColorAMB.menu add radiobutton -label "Fog Color" -command CblCycle1ColorA -variable blCycle1ColorA -value 3

#set blCycle1ColorA 2
#set LblCycle1ColorA "Tex1 Color"

proc CblCycle1ColorA {} {
     global LblCycle1ColorA blCycle1ColorA
     global fptr record
     global blCycle1ModeWord M1A2_SH

     set blCycle1ModeWord [expr $blCycle1ModeWord & ~(3 << $M1A2_SH)]
     set blCycle1ModeWord [expr $blCycle1ModeWord | ($blCycle1ColorA << $M1A2_SH)]

     set LblCycle1ColorA  [getBLcolorLabelA $blCycle1ColorA]

     if {$record == 1} {
	puts $fptr "set blCycle1ColorA $blCycle1ColorA"
	puts $fptr "CblCycle1ColorA"
     }
	callback_blCycle
	callback_send_dl
}


label .bl.cycle1ColorLX1 -width 1 -text "X"
label .bl.cycle1ColorLX2 -width 1 -text "X"

menubutton .bl.cycle1ColorBMB -textvariable LblCycle1ColorB -width 12 \
-relief  raised -menu .bl.cycle1ColorBMB.menu -bg LightGray \
-activebackground LightGray -disabledforeground DarkGray

menu .bl.cycle1ColorBMB.menu
.bl.cycle1ColorBMB.menu add radiobutton -label "Pixel Alpha" -command CblCycle1ColorB -variable blCycle1ColorB -value 0
.bl.cycle1ColorBMB.menu add radiobutton -label "Prim Alpha" -command CblCycle1ColorB -variable blCycle1ColorB -value 1
.bl.cycle1ColorBMB.menu add radiobutton -label "Shade Alpha" -command CblCycle1ColorB -variable blCycle1ColorB -value 2
.bl.cycle1ColorBMB.menu add radiobutton -label "0.0" -command CblCycle1ColorB -variable blCycle1ColorB -value 3

#set blCycle1ColorB "Tex0 Color"
#set LblCycle1ColorB "Tex0 Color"

proc CblCycle1ColorB {} {
     global LblCycle1ColorB blCycle1ColorB
     global fptr record
     global blCycle1ModeWord M1B2_SH

     set blCycle1ModeWord [expr $blCycle1ModeWord & ~(3 << $M1B2_SH)]
     set blCycle1ModeWord [expr $blCycle1ModeWord | ($blCycle1ColorB << $M1B2_SH)]
     set LblCycle1ColorB  [getBLcolorLabelB $blCycle1ColorB]
     if {$record == 1} {
	puts $fptr "set blCycle1ColorB $blCycle1ColorB"
	puts $fptr "CblCycle1ColorB"
     }
	callback_blCycle
	callback_send_dl
}

label .bl.cycle1ColorL+ -width 1 -text "+"

menubutton .bl.cycle1ColorCMB -textvariable LblCycle1ColorC -width 12 \
-relief  raised -menu .bl.cycle1ColorCMB.menu -bg LightGray \
-activebackground LightGray -disabledforeground DarkGray

menu .bl.cycle1ColorCMB.menu
.bl.cycle1ColorCMB.menu add radiobutton -label "Blend/Pix Color" -command CblCycle1ColorC -variable blCycle1ColorC -value 0
.bl.cycle1ColorCMB.menu add radiobutton -label "Mem Color" -command CblCycle1ColorC -variable blCycle1ColorC -value 1
.bl.cycle1ColorCMB.menu add radiobutton -label "Blend Color" -command CblCycle1ColorC -variable blCycle1ColorC -value 2
.bl.cycle1ColorCMB.menu add radiobutton -label "Fog Color" -command CblCycle1ColorC -variable blCycle1ColorC -value 3

#set blCycle1ColorC 13
#set LblCycle1ColorC "LOD Frac"

proc CblCycle1ColorC {} {
     global LblCycle1ColorC blCycle1ColorC
     global fptr record
     global blCycle1ModeWord M2A2_SH

     set blCycle1ModeWord [expr $blCycle1ModeWord & ~(3 << $M2A2_SH)]
     set blCycle1ModeWord [expr $blCycle1ModeWord | ($blCycle1ColorC << $M2A2_SH)]

     set LblCycle1ColorC  [getBLcolorLabelC $blCycle1ColorC]

     if {$record == 1} {
	puts $fptr "set blCycle1ColorC $blCycle1ColorC"
	puts $fptr "CblCycle1ColorC"
     }
	callback_blCycle
	callback_send_dl
}

label .bl.cycle1ColorL) -width 5 -text ") / ("

menubutton .bl.cycle1ColorDMB -textvariable LblCycle1ColorD -width 12 \
-relief  raised -menu .bl.cycle1ColorDMB.menu -bg LightGray \
-activebackground LightGray -disabledforeground DarkGray

menu .bl.cycle1ColorDMB.menu
.bl.cycle1ColorDMB.menu add radiobutton -label "1.0 - A" -command CblCycle1ColorD -variable blCycle1ColorD -value 0
.bl.cycle1ColorDMB.menu add radiobutton -label "Mem Alpha" -command CblCycle1ColorD -variable blCycle1ColorD -value 1
.bl.cycle1ColorDMB.menu add radiobutton -label "1.0" -command CblCycle1ColorD -variable blCycle1ColorD -value 2
.bl.cycle1ColorDMB.menu add radiobutton -label "0.0" -command CblCycle1ColorD -variable blCycle1ColorD -value 3

#set blCycle1ColorD 1
#set LblCycle1ColorD "Tex0 Color"

proc CblCycle1ColorD {} {
     global LblCycle1ColorD blCycle1ColorD
     global fptr record
     global blCycle1ModeWord M2B2_SH

     set blCycle1ModeWord [expr $blCycle1ModeWord & ~(3 << $M2B2_SH)]
     set blCycle1ModeWord [expr $blCycle1ModeWord | ($blCycle1ColorD << $M2B2_SH)]

     set LblCycle1ColorD  [getBLcolorLabelD $blCycle1ColorD]

     if {$record == 1} {
	puts $fptr "set blCycle1ColorD $blCycle1ColorD"
	puts $fptr "CblCycle1ColorD"
     }
	callback_blCycle
	callback_send_dl
}

label .bl.cycle1ColorL1+ -width 1 -text "+"
label .bl.cycle1ColorL1) -width 1 -text ")"

label .bl.cycle1ColorBL -width 11 -textvariable LblCycle1ColorB
label .bl.cycle1ColorDL -width 11 -textvariable LblCycle1ColorD

#--------------------preset modes-------------------------------------------------

set file blModes0
set fptr [open $file r]

while  {[gets $fptr line] >= 0} {
	lappend blCycle0ModeList [expr $line]
}

set file blModes1
set fptr [open $file r]

while  {[gets $fptr line] >= 0} {
	lappend blCycle1ModeList [expr $line]
}

set blCycle0presetColorA {0 1 2 3 4 5}
set blCycle0presetColorB {0 1 2 3 4 5}
set blCycle0presetColorC {0 1 2 3 4 5}
set blCycle0presetColorD {0 1 2 3 4 5}

set blCycle1presetColorA {0 1 2 3 4 5}
set blCycle1presetColorB {0 1 2 3 4 5}
set blCycle1presetColorC {0 1 2 3 4 5}
set blCycle1presetColorD {0 1 2 3 4 5}

proc get_blCycle0presetLabel val {
  switch $val {
	0 {return AA_ZB_OPA_SURF}
	1 {return AA_ZB_XLU_SURF}
	2 {return AA_ZB_OPA_DECAL}
	3 {return AA_ZB_XLU_DECAL}
	4 {return AA_ZB_OPA_INTER}
	5 {return AA_ZB_XLU_INTER}
	6 {return AA_ZB_XLU_LINE}
	7 {return AA_ZB_DEC_LINE}
	8 {return AA_ZB_TEX_EDGE}
	9 {return AA_ZB_TEX_INTER}
	10 {return AA_ZB_SUB_SURF}
	11 {return AA_ZB_PCL_SURF}
	12 {return AA_ZB_OPA_TERR}
	13 {return AA_ZB_TEX_TERR}
	14 {return AA_ZB_SUB_TERR}
	15 {return AA_OPA_SURF}
	16 {return AA_XLU_SURF}
	17 {return AA_XLU_LINE}
	18 {return AA_DEC_LINE}
	19 {return AA_TEX_EDGE}
	20 {return AA_SUB_SURF}
	21 {return AA_PCL_SURF}
	22 {return AA_OPA_TERR}
	23 {return AA_TEX_TERR}
	24 {return AA_SUB_TERR}
	25 {return ZB_OPA_SURF}
	26 {return ZB_XLU_SURF}
	27 {return ZB_OPA_DECAL}
	28 {return ZB_XLU_DECAL}
	29 {return ZB_CLD_SURF}
	30 {return ZB_OVL_SURF}
	31 {return ZB_PCL_SURF}
	32 {return OPA_SURF}
	33 {return XLU_SURF}
	34 {return CLD_SURF}
	35 {return PCL_SURF}
	36 {return FOG_SHADE_A}
	37 {return FOG_PRIM_A}
	38 {return PASS}
  }
}


proc get_blCycle1presetLabel val {
  switch $val {
	0 {return AA_ZB_OPA_SURF2}
	1 {return AA_ZB_XLU_SURF2}
	2 {return AA_ZB_OPA_DECAL2}
	3 {return AA_ZB_XLU_DECAL2}
	4 {return AA_ZB_OPA_INTER2}
	5 {return AA_ZB_XLU_INTER2}
	6 {return AA_ZB_XLU_LINE2}
	7 {return AA_ZB_DEC_LINE2}
	8 {return AA_ZB_TEX_EDGE2}
	9 {return AA_ZB_TEX_INTER2}
	10 {return AA_ZB_SUB_SURF2}
	11 {return AA_ZB_PCL_SURF2}
	12 {return ZB_OPA_TERR2}
	13 {return ZB_TEX_TERR2}
	14 {return ZB_SUB_TERR2}
	15 {return AA_OPA_SURF2}
	16 {return AA_XLU_SURF2}
	17 {return AA_XLU_LINE2}
	18 {return AA_DEC_LINE2}
	19 {return AA_TEX_EDGE2}
	20 {return AA_SUB_SURF2}
	21 {return AA_PCL_SURF2}
	22 {return AA_OPA_TERR2}
	23 {return AA_TEX_TERR2}
	24 {return AA_SUB_TERR2}
	25 {return ZB_OPA_SURF2}
	26 {return ZB_XLU_SURF2}
	27 {return ZB_OPA_DECAL2}
	28 {return ZB_XLU_DECAL2}
	29 {return ZB_CLD_SURF2}
	30 {return ZB_OVL_SURF2}
	31 {return ZB_PCL_SURF2}
	32 {return OPA_SURF2}
	33 {return XLU_SURF2}
	34 {return CLD_SURF2}
	35 {return PCL_SURF2}
  }
}


label .bl.cycle0presetL -width 11 -text "Cycle0 Modes"

menubutton .bl.cycle0presetMB -textvariable LblCycle0preset -width 22 \
-relief  raised -menu .bl.cycle0presetMB.menu -bg LightGray \
-activebackground LightGray -disabledforeground DarkGray

menu .bl.cycle0presetMB.menu
.bl.cycle0presetMB.menu add radiobutton -label "AA_ZB_OPA_SURF" -command CblCycle0preset -variable blCycle0preset -value 0
.bl.cycle0presetMB.menu add radiobutton -label "AA_ZB_XLU_SURF" -command CblCycle0preset -variable blCycle0preset -value 1
.bl.cycle0presetMB.menu add radiobutton -label "AA_ZB_OPA_DECAL" -command CblCycle0preset -variable blCycle0preset -value 2
.bl.cycle0presetMB.menu add radiobutton -label "AA_ZB_XLU_DECAL" -command CblCycle0preset -variable blCycle0preset -value 3
.bl.cycle0presetMB.menu add radiobutton -label "AA_ZB_OPA_INTER" -command CblCycle0preset -variable blCycle0preset -value 4
.bl.cycle0presetMB.menu add radiobutton -label "AA_ZB_XLU_INTER" -command CblCycle0preset -variable blCycle0preset -value 5
.bl.cycle0presetMB.menu add radiobutton -label "AA_ZB_XLU_LINE" -command CblCycle0preset -variable blCycle0preset -value 6
.bl.cycle0presetMB.menu add radiobutton -label "AA_ZB_DEC_LINE" -command CblCycle0preset -variable blCycle0preset -value 7
.bl.cycle0presetMB.menu add radiobutton -label "AA_ZB_TEX_EDGE" -command CblCycle0preset -variable blCycle0preset -value 8
.bl.cycle0presetMB.menu add radiobutton -label "AA_ZB_TEX_INTER" -command CblCycle0preset -variable blCycle0preset -value 9
.bl.cycle0presetMB.menu add radiobutton -label "AA_ZB_SUB_SURF" -command CblCycle0preset -variable blCycle0preset -value 10
.bl.cycle0presetMB.menu add radiobutton -label "AA_ZB_PCL_SURF" -command CblCycle0preset -variable blCycle0preset -value 11
.bl.cycle0presetMB.menu add radiobutton -label "AA_ZB_OPA_TERR" -command CblCycle0preset -variable blCycle0preset -value 12
.bl.cycle0presetMB.menu add radiobutton -label "AA_ZB_TEX_TERR" -command CblCycle0preset -variable blCycle0preset -value 13
.bl.cycle0presetMB.menu add radiobutton -label "AA_ZB_SUB_TERR" -command CblCycle0preset -variable blCycle0preset -value 14
.bl.cycle0presetMB.menu add radiobutton -label "AA_OPA_SURF" -command CblCycle0preset -variable blCycle0preset -value 15
.bl.cycle0presetMB.menu add radiobutton -label "AA_XLU_SURF" -command CblCycle0preset -variable blCycle0preset -value 16
.bl.cycle0presetMB.menu add radiobutton -label "AA_XLU_LINE" -command CblCycle0preset -variable blCycle0preset -value 17
.bl.cycle0presetMB.menu add radiobutton -label "AA_DEC_LINE" -command CblCycle0preset -variable blCycle0preset -value 18
.bl.cycle0presetMB.menu add radiobutton -label "AA_TEX_EDGE" -command CblCycle0preset -variable blCycle0preset -value 19
.bl.cycle0presetMB.menu add radiobutton -label "AA_SUB_SURF" -command CblCycle0preset -variable blCycle0preset -value 20
.bl.cycle0presetMB.menu add radiobutton -label "AA_PCL_SURF" -command CblCycle0preset -variable blCycle0preset -value 21
.bl.cycle0presetMB.menu add radiobutton -label "AA_OPA_TERR" -command CblCycle0preset -variable blCycle0preset -value 22
.bl.cycle0presetMB.menu add radiobutton -label "AA_TEX_TERR" -command CblCycle0preset -variable blCycle0preset -value 23
.bl.cycle0presetMB.menu add radiobutton -label "AA_SUB_TERR" -command CblCycle0preset -variable blCycle0preset -value 24
.bl.cycle0presetMB.menu add radiobutton -label "ZB_OPA_SURF" -command CblCycle0preset -variable blCycle0preset -value 25
.bl.cycle0presetMB.menu add radiobutton -label "ZB_XLU_SURF" -command CblCycle0preset -variable blCycle0preset -value 26
.bl.cycle0presetMB.menu add radiobutton -label "ZB_OPA_DECAL" -command CblCycle0preset -variable blCycle0preset -value 27
.bl.cycle0presetMB.menu add radiobutton -label "ZB_XLU_DECAL" -command CblCycle0preset -variable blCycle0preset -value 28
.bl.cycle0presetMB.menu add radiobutton -label "ZB_CLD_SURF" -command CblCycle0preset -variable blCycle0preset -value 29
.bl.cycle0presetMB.menu add radiobutton -label "ZB_OVL_SURF" -command CblCycle0preset -variable blCycle0preset -value 30
.bl.cycle0presetMB.menu add radiobutton -label "ZB_PCL_SURF" -command CblCycle0preset -variable blCycle0preset -value 31
.bl.cycle0presetMB.menu add radiobutton -label "OPA_SURF" -command CblCycle0preset -variable blCycle0preset -value 32
.bl.cycle0presetMB.menu add radiobutton -label "XLU_SURF" -command CblCycle0preset -variable blCycle0preset -value 33
.bl.cycle0presetMB.menu add radiobutton -label "CLD_SURF" -command CblCycle0preset -variable blCycle0preset -value 34
.bl.cycle0presetMB.menu add radiobutton -label "PCL_SURF" -command CblCycle0preset -variable blCycle0preset -value 35
.bl.cycle0presetMB.menu add radiobutton -label "FOG_SHADE_A" -command CblCycle0preset -variable blCycle0preset -value 36
.bl.cycle0presetMB.menu add radiobutton -label "FOG_PRIM_A" -command CblCycle0preset -variable blCycle0preset -value 37
.bl.cycle0presetMB.menu add radiobutton -label "PASS" -command CblCycle0preset -variable blCycle0preset -value 38

proc CblCycle0preset {} {
     global blCycle0preset LblCycle0preset	
     global blCycle1preset LblCycle1preset	
     global fptr record
     global blCycle0ModeList blCycle1ModeList blCycle0ModeWord blCycle1ModeWord
     global blCycle0presetColorA blCycle0presetColorB blCycle0presetColorC blCycle0presetColorD
     global blCycle0ColorA blCycle0ColorB blCycle0ColorC blCycle0ColorD
     global M1A1_SH M1B1_SH M2A1_SH M2B1_SH
     global AA_EN Z_CMP Z_UPD IM_RD CLR_ON_CVG CVG_X_ALPHA ALPHA_CVG_SEL FORCE_BL ZMODE_MASK ZMODE_SH TEX_EDGE CVG_DST_MASK CVG_DST_SH A_CMP_EN A_DITH_EN Z_SRC_SEL
     global blAaEn blZcmpEn blZupdEn blImRdEn blCvgDest blColOnCvg blCvgXalpha blAlphaCvgSel blForceBlend blZmode blTexEdgeMode blAlphaCompEn blDithAlphaEn blZsrcSel
     global rspCycleType blCycle1preset

     set LblCycle0preset [get_blCycle0presetLabel $blCycle0preset]

     set blCycle0ModeWord [lindex $blCycle0ModeList $blCycle0preset]
     set blCycle1ModeWord [lindex $blCycle1ModeList $blCycle1preset]


     if {$rspCycleType == 0} {
	set blCycle1preset $blCycle0preset
	CblCycle1preset
     }

     # shift and AND instead of ANDing and then shifting since all shifts
     # in TCL are arithmetic shifts and a set MSB can screw up results
     set blCycle0ColorA [expr (($blCycle0ModeWord >> $M1A1_SH) & 3) ]
     set blCycle0ColorB [expr (($blCycle0ModeWord >> $M1B1_SH) & 3) ]
     set blCycle0ColorC [expr (($blCycle0ModeWord >> $M2A1_SH) & 3) ]
     set blCycle0ColorD [expr (($blCycle0ModeWord >> $M2B1_SH) & 3) ]

     set blAaEn [expr ((($blCycle0ModeWord | $blCycle1ModeWord) & $AA_EN) && 1)]
     set blZcmpEn [expr ((($blCycle0ModeWord | $blCycle1ModeWord) & $Z_CMP) && 1)]
     set blZupdEn [expr ((($blCycle0ModeWord | $blCycle1ModeWord) & $Z_UPD) && 1)]
     set blImRdEn [expr ((($blCycle0ModeWord | $blCycle1ModeWord) & $IM_RD) && 1)]
     set blColOnCvg [expr ((($blCycle0ModeWord | $blCycle1ModeWord) & $CLR_ON_CVG) && 1)]
     set blCvgDest [expr ((($blCycle0ModeWord | $blCycle1ModeWord) & $CVG_DST_MASK)>>  $CVG_DST_SH)]
     set blCvgXalpha [expr ((($blCycle0ModeWord | $blCycle1ModeWord) & $CVG_X_ALPHA) && 1)]
     set blAlphaCvgSel [expr ((($blCycle0ModeWord | $blCycle1ModeWord) & $ALPHA_CVG_SEL) && 1)]
     set blForceBlend [expr ((($blCycle0ModeWord | $blCycle1ModeWord) & $FORCE_BL) && 1)]
     set blZmode [expr ((($blCycle0ModeWord | $blCycle1ModeWord) & $ZMODE_MASK) >> $ZMODE_SH)]
     set blTexEdgeMode [expr ((($blCycle0ModeWord | $blCycle1ModeWord) & $TEX_EDGE) && 1)]
     set blAlphaCompEn [expr ((($blCycle0ModeWord | $blCycle1ModeWord) & $A_CMP_EN) && 1)]
     set blDithAlphaEn [expr ((($blCycle0ModeWord | $blCycle1ModeWord) & $A_DITH_EN) && 1)]
     set blZsrcSel [expr ((($blCycle0ModeWord | $blCycle1ModeWord) & $Z_SRC_SEL) && 1)]

     # call the corresponding procs mainly for recording functionality
     CblAaEn
     CblZcmpEn
     CblZupdEn
     CblImRdEn
     CblCvgDest
     CblColOnCvg
     CblCvgXalpha
     CblAlphaCvgSel
     CblForceBlend
     CblZmode
     CblTexEdgeMode
     CblAlphaCompEn
     CblDithAlphaEn
     CblZsrcSel

     CblCycle0ColorA
     CblCycle0ColorB
     CblCycle0ColorC
     CblCycle0ColorD


     if {$record == 1} {
	puts $fptr "set blCycle0preset $blCycle0preset"
	puts $fptr "set LblCycle0preset $LblCycle0preset"
     }
}


label .bl.cycle1presetL -width 11 -text "Cycle1 Modes"

menubutton .bl.cycle1presetMB -textvariable LblCycle1preset -width 22 \
-relief  raised -menu .bl.cycle1presetMB.menu -bg LightGray \
-activebackground LightGray -disabledforeground DarkGray

menu .bl.cycle1presetMB.menu
.bl.cycle1presetMB.menu add radiobutton -label "AA_ZB_OPA_SURF2" -command CblCycle1preset -variable blCycle1preset -value 0
.bl.cycle1presetMB.menu add radiobutton -label "AA_ZB_XLU_SURF2" -command CblCycle1preset -variable blCycle1preset -value 1
.bl.cycle1presetMB.menu add radiobutton -label "AA_ZB_OPA_DECAL2" -command CblCycle1preset -variable blCycle1preset -value 2
.bl.cycle1presetMB.menu add radiobutton -label "AA_ZB_XLU_DECAL2" -command CblCycle1preset -variable blCycle1preset -value 3
.bl.cycle1presetMB.menu add radiobutton -label "AA_ZB_OPA_INTER2" -command CblCycle1preset -variable blCycle1preset -value 4
.bl.cycle1presetMB.menu add radiobutton -label "AA_ZB_XLU_INTER2" -command CblCycle1preset -variable blCycle1preset -value 5
.bl.cycle1presetMB.menu add radiobutton -label "AA_ZB_XLU_LINE2" -command CblCycle1preset -variable blCycle1preset -value 6
.bl.cycle1presetMB.menu add radiobutton -label "AA_ZB_DEC_LINE2" -command CblCycle1preset -variable blCycle1preset -value 7
.bl.cycle1presetMB.menu add radiobutton -label "AA_ZB_TEX_EDGE2" -command CblCycle1preset -variable blCycle1preset -value 8
.bl.cycle1presetMB.menu add radiobutton -label "AA_ZB_TEX_INTER2" -command CblCycle1preset -variable blCycle1preset -value 9
.bl.cycle1presetMB.menu add radiobutton -label "AA_ZB_SUB_SURF2" -command CblCycle1preset -variable blCycle1preset -value 10
.bl.cycle1presetMB.menu add radiobutton -label "AA_ZB_PCL_SURF2" -command CblCycle1preset -variable blCycle1preset -value 11
.bl.cycle1presetMB.menu add radiobutton -label "AA_ZB_OPA_TERR2" -command CblCycle1preset -variable blCycle1preset -value 12
.bl.cycle1presetMB.menu add radiobutton -label "AA_ZB_TEX_TERR2" -command CblCycle1preset -variable blCycle1preset -value 13
.bl.cycle1presetMB.menu add radiobutton -label "AA_ZB_SUB_TERR2" -command CblCycle1preset -variable blCycle1preset -value 14
.bl.cycle1presetMB.menu add radiobutton -label "AA_OPA_SURF2" -command CblCycle1preset -variable blCycle1preset -value 15
.bl.cycle1presetMB.menu add radiobutton -label "AA_XLU_SURF2" -command CblCycle1preset -variable blCycle1preset -value 16
.bl.cycle1presetMB.menu add radiobutton -label "AA_XLU_LINE2" -command CblCycle1preset -variable blCycle1preset -value 17
.bl.cycle1presetMB.menu add radiobutton -label "AA_DEC_LINE2" -command CblCycle1preset -variable blCycle1preset -value 18
.bl.cycle1presetMB.menu add radiobutton -label "AA_TEX_EDGE2" -command CblCycle1preset -variable blCycle1preset -value 19
.bl.cycle1presetMB.menu add radiobutton -label "AA_SUB_SURF2" -command CblCycle1preset -variable blCycle1preset -value 20
.bl.cycle1presetMB.menu add radiobutton -label "AA_PCL_SURF2" -command CblCycle1preset -variable blCycle1preset -value 21
.bl.cycle1presetMB.menu add radiobutton -label "AA_OPA_TERR2" -command CblCycle1preset -variable blCycle1preset -value 22
.bl.cycle1presetMB.menu add radiobutton -label "AA_TEX_TERR2" -command CblCycle1preset -variable blCycle1preset -value 23
.bl.cycle1presetMB.menu add radiobutton -label "AA_SUB_TERR2" -command CblCycle1preset -variable blCycle1preset -value 24
.bl.cycle1presetMB.menu add radiobutton -label "ZB_OPA_SURF2" -command CblCycle1preset -variable blCycle1preset -value 25
.bl.cycle1presetMB.menu add radiobutton -label "ZB_XLU_SURF2" -command CblCycle1preset -variable blCycle1preset -value 26
.bl.cycle1presetMB.menu add radiobutton -label "ZB_OPA_DECAL2" -command CblCycle1preset -variable blCycle1preset -value 27
.bl.cycle1presetMB.menu add radiobutton -label "ZB_XLU_DECAL2" -command CblCycle1preset -variable blCycle1preset -value 28
.bl.cycle1presetMB.menu add radiobutton -label "ZB_CLD_SURF2" -command CblCycle1preset -variable blCycle1preset -value 29
.bl.cycle1presetMB.menu add radiobutton -label "ZB_OVL_SURF2" -command CblCycle1preset -variable blCycle1preset -value 30
.bl.cycle1presetMB.menu add radiobutton -label "ZB_PCL_SURF2" -command CblCycle1preset -variable blCycle1preset -value 31
.bl.cycle1presetMB.menu add radiobutton -label "OPA_SURF2" -command CblCycle1preset -variable blCycle1preset -value 32
.bl.cycle1presetMB.menu add radiobutton -label "XLU_SURF2" -command CblCycle1preset -variable blCycle1preset -value 33
.bl.cycle1presetMB.menu add radiobutton -label "CLD_SURF2" -command CblCycle1preset -variable blCycle1preset -value 34
.bl.cycle1presetMB.menu add radiobutton -label "PCL_SURF2" -command CblCycle1preset -variable blCycle1preset -value 35

proc CblCycle1preset {} {
     global blCycle1preset LblCycle1preset
     global blCycle0preset LblCycle0preset
     global fptr record
     global blCycle0ModeList blCycle1ModeList blCycle1ModeWord blCycle0ModeWord
     global blCycle1presetColorA blCycle1presetColorB blCycle1presetColorC blCycle1presetColorD
     global blCycle1ColorA blCycle1ColorB blCycle1ColorC blCycle1ColorD
     global M1A2_SH M1B2_SH M2A2_SH M2B2_SH
     global AA_EN Z_CMP Z_UPD IM_RD CLR_ON_CVG CVG_X_ALPHA ALPHA_CVG_SEL FORCE_BL ZMODE_MASK ZMODE_SH TEX_EDGE CVG_DST_MASK CVG_DST_SH A_CMP_EN A_DITH_EN Z_SRC_SEL
     global blAaEn blZcmpEn blZupdEn blImRdEn blCvgDest blColOnCvg blCvgXalpha blAlphaCvgSel blForceBlend blZmode blTexEdgeMode blAlphaCompEn blDithAlphaEn blZsrcSel

     set LblCycle1preset [get_blCycle1presetLabel $blCycle1preset]

     set blCycle1ModeWord [lindex $blCycle1ModeList $blCycle1preset]
     set blCycle0ModeWord [lindex $blCycle0ModeList $blCycle0preset]

     # shift and AND instead of ANDing and then shifting since all shifts
     # in TCL are arithmetic shifts and a set MSB can screw up results
     set blCycle1ColorA [expr (($blCycle1ModeWord >> $M1A2_SH) & 3) ]
     set blCycle1ColorB [expr (($blCycle1ModeWord >> $M1B2_SH) & 3) ]
     set blCycle1ColorC [expr (($blCycle1ModeWord >> $M2A2_SH) & 3) ]
     set blCycle1ColorD [expr (($blCycle1ModeWord >> $M2B2_SH) & 3) ]

#    set blCycle1ColorA [expr ($blCycle1ModeWord & (3 << $M1A2_SH)) >> $M1A2_SH ]
#    set blCycle1ColorB [expr ($blCycle1ModeWord & (3 << $M1B2_SH)) >> $M1B2_SH ]
#    set blCycle1ColorC [expr ($blCycle1ModeWord & (3 << $M2A2_SH)) >> $M2A2_SH ]
#    set blCycle1ColorD [expr ($blCycle1ModeWord & (3 << $M2B2_SH)) >> $M2B2_SH ]

     set blAaEn [expr ((($blCycle0ModeWord | $blCycle1ModeWord) & $AA_EN) && 1)]
     set blZcmpEn [expr ((($blCycle0ModeWord | $blCycle1ModeWord) & $Z_CMP) && 1)]
     set blZupdEn [expr ((($blCycle0ModeWord | $blCycle1ModeWord) & $Z_UPD) && 1)]
     set blImRdEn [expr ((($blCycle0ModeWord | $blCycle1ModeWord) & $IM_RD) && 1)]
     set blColOnCvg [expr ((($blCycle0ModeWord | $blCycle1ModeWord) & $CLR_ON_CVG) && 1)]
     set blCvgDest [expr ((($blCycle0ModeWord | $blCycle1ModeWord) & $CVG_DST_MASK)>>  $CVG_DST_SH)]
     set blCvgXalpha [expr ((($blCycle0ModeWord | $blCycle1ModeWord) & $CVG_X_ALPHA) && 1)]
     set blAlphaCvgSel [expr ((($blCycle0ModeWord | $blCycle1ModeWord) & $ALPHA_CVG_SEL) && 1)]
     set blForceBlend [expr ((($blCycle0ModeWord | $blCycle1ModeWord) & $FORCE_BL) && 1)]
     set blZmode [expr ((($blCycle0ModeWord | $blCycle1ModeWord) & $ZMODE_MASK) >> $ZMODE_SH)]
     set blTexEdgeMode [expr ((($blCycle0ModeWord | $blCycle1ModeWord) & $TEX_EDGE) && 1)]
     set blAlphaCompEn [expr ((($blCycle0ModeWord | $blCycle1ModeWord) & $A_CMP_EN) && 1)]
     set blDithAlphaEn [expr ((($blCycle0ModeWord | $blCycle1ModeWord) & $A_DITH_EN) && 1)]
     set blZsrcSel [expr ((($blCycle0ModeWord | $blCycle1ModeWord) & $Z_SRC_SEL) && 1)]

     #puts "blTexEdgeMode = $blTexEdgeMode"

     CblAaEn
     CblZcmpEn
     CblZupdEn
     CblImRdEn
     CblCvgDest
     CblColOnCvg
     CblCvgXalpha
     CblAlphaCvgSel
     CblForceBlend
     CblZmode
     CblTexEdgeMode
     CblAlphaCompEn
     CblDithAlphaEn
     CblZsrcSel

     CblCycle1ColorA
     CblCycle1ColorB
     CblCycle1ColorC
     CblCycle1ColorD
     
     if {$record == 1} {
	puts $fptr "set blCycle1preset $blCycle1preset"
	puts $fptr "set LblCycle1preset $LblCycle1preset"
     }
}

set blCycle0ModeWord 0
set blCycle1ModeWord 0
#
set blCycle0preset 0
#    CblCycle0preset
#
set blCycle1preset 0
#    CblCycle1preset

#----------------------------------------------------------------------------

pack .bl.aaEnCB .bl.zCmpEnCB .bl.zUpdEnCB .bl.imRdEnCB .bl.cvgDestMB .bl.colOnCvgCB .bl.cvgXalphaCB -in .bl.modeBitsF1 -side left -fill y -padx 1m -pady 1m

pack .bl.alphaCvgSelCB .bl.forceBlendCB .bl.zModeMB .bl.texEdgeModeCB .bl.alphaCompEnCB .bl.dithAlphaEnCB .bl.zSrcSelCB -in .bl.modeBitsF2 -side left -fill y -padx 1m -pady 1m

pack .bl.modeBitsF1 .bl.modeBitsF2  -in .bl.modeBitsF -side top -fill x -padx 1m -pady 1m

pack .bl.cycle0ColorL .bl.cycle0ColorL( .bl.cycle0ColorAMB .bl.cycle0ColorLX1 .bl.cycle0ColorBMB .bl.cycle0ColorL+ .bl.cycle0ColorCMB .bl.cycle0ColorLX2 .bl.cycle0ColorDMB .bl.cycle0ColorL) .bl.cycle0ColorBL .bl.cycle0ColorL1+ .bl.cycle0ColorDL .bl.cycle0ColorL1)  -in .bl.cyc0ColorF -side left -fill y -padx 1m -pady 1m

pack .bl.cycle1ColorL .bl.cycle1ColorL( .bl.cycle1ColorAMB .bl.cycle1ColorLX1 .bl.cycle1ColorBMB .bl.cycle1ColorL+ .bl.cycle1ColorCMB .bl.cycle1ColorLX2 .bl.cycle1ColorDMB  .bl.cycle1ColorL) .bl.cycle1ColorBL .bl.cycle1ColorL1+ .bl.cycle1ColorDL .bl.cycle1ColorL1) -in .bl.cyc1ColorF -side left -fill y -padx 1m -pady 1m

pack .bl.cyc0ColorF .bl.cyc1ColorF -in .bl.muxesF -side top -fill x -pady 1m

pack .bl.blendColorRedS .bl.blendColorRedE -in .bl.blendRedF -side left -padx 1m
pack .bl.blendColorGreenS .bl.blendColorGreenE -in .bl.blendGreenF -side left -padx 1m
pack .bl.blendColorBlueS .bl.blendColorBlueE -in .bl.blendBlueF -side left -padx 1m
pack .bl.blendColorAlphaS .bl.blendColorAlphaE -in .bl.blendAlphaF -side left -padx 1m
pack .bl.blendColorL .bl.blendRedF .bl.blendGreenF .bl.blendBlueF .bl.blendAlphaF -in .bl.blendColorF -side left -fill y -padx 1m

pack .bl.fogColorRedS .bl.fogColorRedE -in .bl.fogRedF -side left -padx 1m
pack .bl.fogColorGreenS .bl.fogColorGreenE -in .bl.fogGreenF -side left -padx 1m
pack .bl.fogColorBlueS .bl.fogColorBlueE -in .bl.fogBlueF -side left -padx 1m
pack .bl.fogColorAlphaS .bl.fogColorAlphaE -in .bl.fogAlphaF -side left -padx 1m
pack .bl.fogColorL .bl.fogRedF .bl.fogGreenF .bl.fogBlueF .bl.fogAlphaF -in .bl.fogColorF -side left -fill y -padx 1m

pack .bl.primZS .bl.primZE -in .bl.primZF -side left -padx 1m
pack .bl.primDeltaZS .bl.primDeltaZE -in .bl.primDeltaZF -side left -padx 1m
pack .bl.primZL .bl.primZF .bl.primDeltaZF -in .bl.primDepthF -side left -fill y -padx 1m

pack .bl.rgbDitherL .bl.rgbDitherMB .bl.alphaDitherL .bl.alphaDitherMB .bl.videoAAFilterL .bl.videoAAFilterCB .bl.videoDitherFilterL .bl.videoDitherFilterCB .bl.frameBufferSizeL .bl.frameBufferSizeCB -in .bl.ditherF -side left -fill y -padx 2m

pack .bl.blendColorF .bl.fogColorF -in .bl.colorF -side top -fill x -pady 1m


pack .bl.cycle0presetL .bl.cycle0presetMB .bl.cycle1presetL .bl.cycle1presetMB .bl.fbShiftL .bl.fbShiftE -in .bl.cycle0cycle1presetF -side left -fill y -padx 5m
pack .bl.cycle0cycle1presetF -in .bl.presetF -side top -fill x -pady 1m

pack .bl.ditherF .bl.colorF .bl.primDepthF -in .bl.stateF -side top -fill x -pady 1m

pack .bl.stateF .bl.modeBitsF .bl.muxesF .bl.presetF -in .bl.topF -side top -fill x -pady 1m
pack .bl.topF