-
Notifications
You must be signed in to change notification settings - Fork 2
/
stripheader.c
1038 lines (895 loc) · 45.8 KB
/
stripheader.c
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
///////////////////////////////////////////////////////////
// _____ _____ __ _____ _____ ___ ___ //
// | __| | | | | | __ | |_ | | | //
// |__ | | |__|- -| __ -| | _|_| | | //
// |_____|__|__|_____|_____|_____| |___|_|___| //
// //
///////////////////////////////////////////////////////////
// Strip header library 2.0 //
// //
// This library is used to generate and update strip //
// headers for use with the SEGA Dreamcast hardware in //
// an OpenGL-like manner. //
// //
// Author: Anton Norgren (Tvspelsfreak) (2011) //
///////////////////////////////////////////////////////////
#include "stripheader.h"
/////////////////////////////////////////////////////
// Parameter control word //
/////////////////////////////////////////////////////
// Type, bits 31-29
#define PCW_TYPE_SHIFT 29
#define PCW_TYPE_END_OF_LIST (0 << PCW_TYPE_SHIFT)
#define PCW_TYPE_USER_TILE_CLIP (1 << PCW_TYPE_SHIFT)
#define PCW_TYPE_OBJECT_LIST_SET (2 << PCW_TYPE_SHIFT)
#define PCW_TYPE_POLYGON (4 << PCW_TYPE_SHIFT)
#define PCW_TYPE_MODIFIER (4 << PCW_TYPE_SHIFT)
#define PCW_TYPE_SPRITE (5 << PCW_TYPE_SHIFT)
#define PCW_TYPE_MASK (7 << PCW_TYPE_SHIFT)
// List, bits 26-24
#define PCW_LIST_SHIFT 24
#define PCW_LIST_OP_POLYGON (0 << PCW_LIST_SHIFT)
#define PCW_LIST_OP_MODIFIER (1 << PCW_LIST_SHIFT)
#define PCW_LIST_TR_POLYGON (2 << PCW_LIST_SHIFT)
#define PCW_LIST_TR_MODIFIER (3 << PCW_LIST_SHIFT)
#define PCW_LIST_PT_POLYGON (4 << PCW_LIST_SHIFT)
#define PCW_LIST_MASK (7 << PCW_LIST_SHIFT)
// Update strip length & user clip, bit 23
#define PCW_UPDATE_GROUP_SHIFT 23
#define PCW_UPDATE_GROUP_OFF (0 << PCW_UPDATE_GROUP_SHIFT)
#define PCW_UPDATE_GROUP_ON (1 << PCW_UPDATE_GROUP_SHIFT)
#define PCW_UPDATE_GROUP_MASK (1 << PCW_UPDATE_GROUP_SHIFT)
// Strip length, bits 19-18
#define PCW_STRIP_LENGTH_SHIFT 18
#define PCW_STRIP_LENGTH_1 (0 << PCW_STRIP_LENGTH_SHIFT)
#define PCW_STRIP_LENGTH_2 (1 << PCW_STRIP_LENGTH_SHIFT)
#define PCW_STRIP_LENGTH_4 (2 << PCW_STRIP_LENGTH_SHIFT)
#define PCW_STRIP_LENGTH_6 (3 << PCW_STRIP_LENGTH_SHIFT)
#define PCW_STRIP_LENGTH_MASK (3 << PCW_STRIP_LENGTH_SHIFT)
// User clip, bits 17-16
#define PCW_USER_CLIP_SHIFT 16
#define PCW_USER_CLIP_DISABLE (0 << PCW_USER_CLIP_SHIFT)
#define PCW_USER_CLIP_INSIDE (2 << PCW_USER_CLIP_SHIFT)
#define PCW_USER_CLIP_OUTSIDE (3 << PCW_USER_CLIP_SHIFT)
#define PCW_USER_CLIP_MASK (3 << PCW_USER_CLIP_SHIFT)
// Enable modifiers (for polygons), bit 7
#define PCW_MODIFIER_SHIFT 7
#define PCW_MODIFIER_DISABLE (0 << PCW_MODIFIER_SHIFT)
#define PCW_MODIFIER_ENABLE (1 << PCW_MODIFIER_SHIFT)
#define PCW_MODIFIER_MASK (1 << PCW_MODIFIER_SHIFT)
// Modifier type (for polygons), bit 6
#define PCW_MODIFIER_TYPE_SHIFT 6
#define PCW_MODIFIER_TYPE_SHADOW (0 << PCW_MODIFIER_TYPE_SHIFT)
#define PCW_MODIFIER_TYPE_NORMAL (1 << PCW_MODIFIER_TYPE_SHIFT)
#define PCW_MODIFIER_TYPE_MASK (1 << PCW_MODIFIER_TYPE_SHIFT)
// Last triangle in volume (for modifiers), bit 6
#define PCW_MODIFIER_TRIANGLE_SHIFT 6
#define PCW_MODIFIER_TRIANGLE (0 << PCW_MODIFIER_TRIANGLE_SHIFT)
#define PCW_MODIFIER_TRIANGLE_LAST (1 << PCW_MODIFIER_TRIANGLE_SHIFT)
#define PCW_MODIFIER_TRIANGLE_MASK (1 << PCW_MODIFIER_TRIANGLE_SHIFT)
// Color type, bits 5-4
#define PCW_COLOR_TYPE_SHIFT 4
#define PCW_COLOR_TYPE_PACKED (0 << PCW_COLOR_TYPE_SHIFT)
#define PCW_COLOR_TYPE_FLOAT (1 << PCW_COLOR_TYPE_SHIFT)
#define PCW_COLOR_TYPE_INTENSITY (2 << PCW_COLOR_TYPE_SHIFT)
#define PCW_COLOR_TYPE_PREV_INTENSITY (3 << PCW_COLOR_TYPE_SHIFT)
#define PCW_COLOR_TYPE_MASK (3 << PCW_COLOR_TYPE_SHIFT)
// Texture enable, bit 3
#define PCW_TEXTURE_SHIFT 3
#define PCW_TEXTURE_DISABLE (0 << PCW_TEXTURE_SHIFT)
#define PCW_TEXTURE_ENABLE (1 << PCW_TEXTURE_SHIFT)
#define PCW_TEXTURE_MASK (1 << PCW_TEXTURE_SHIFT)
// Offset color enable, bit 2
#define PCW_OFFSET_COLOR_SHIFT 2
#define PCW_OFFSET_COLOR_DISABLE (0 << PCW_OFFSET_COLOR_SHIFT)
#define PCW_OFFSET_COLOR_ENABLE (1 << PCW_OFFSET_COLOR_SHIFT)
#define PCW_OFFSET_COLOR_MASK (1 << PCW_OFFSET_COLOR_SHIFT)
// Shading, bit 1
#define PCW_SHADING_SHIFT 1
#define PCW_SHADING_FLAT (0 << PCW_SHADING_SHIFT)
#define PCW_SHADING_GOURAUD (1 << PCW_SHADING_SHIFT)
#define PCW_SHADING_MASK (1 << PCW_SHADING_SHIFT)
// UV, bit 0
#define PCW_UV_SHIFT 0
#define PCW_UV_32BIT (0 << PCW_UV_SHIFT)
#define PCW_UV_16BIT (1 << PCW_UV_SHIFT)
#define PCW_UV_MASK (1 << PCW_UV_SHIFT)
/////////////////////////////////////////////////////
// ISP/TSP instruction word //
/////////////////////////////////////////////////////
// Depth compare (for polygons), bits 31-29
#define ISP_TSP_DEPTH_COMPARE_SHIFT 29
#define ISP_TSP_DEPTH_COMPARE_NEVER (0 << ISP_TSP_DEPTH_COMPARE_SHIFT)
#define ISP_TSP_DEPTH_COMPARE_LESS (1 << ISP_TSP_DEPTH_COMPARE_SHIFT)
#define ISP_TSP_DEPTH_COMPARE_EQUAL (2 << ISP_TSP_DEPTH_COMPARE_SHIFT)
#define ISP_TSP_DEPTH_COMPARE_LESS_OR_EQUAL (3 << ISP_TSP_DEPTH_COMPARE_SHIFT)
#define ISP_TSP_DEPTH_COMPARE_GREATER (4 << ISP_TSP_DEPTH_COMPARE_SHIFT)
#define ISP_TSP_DEPTH_COMPARE_NOT_EQUAL (5 << ISP_TSP_DEPTH_COMPARE_SHIFT)
#define ISP_TSP_DEPTH_COMPARE_GREATER_OR_EQUAL (6 << ISP_TSP_DEPTH_COMPARE_SHIFT)
#define ISP_TSP_DEPTH_COMPARE_ALWAYS (7 << ISP_TSP_DEPTH_COMPARE_SHIFT)
#define ISP_TSP_DEPTH_COMPARE_MASK (7 << ISP_TSP_DEPTH_COMPARE_SHIFT)
// Volume instruction (for modifiers), bits 31-29
#define ISP_TSP_VOLUME_INSTRUCTION_SHIFT 29
#define ISP_TSP_VOLUME_INSTRUCTION_NORMAL (0 << ISP_TSP_VOLUME_INSTRUCTION_SHIFT)
#define ISP_TSP_VOLUME_INSTRUCTION_INSIDE_LAST (1 << ISP_TSP_VOLUME_INSTRUCTION_SHIFT)
#define ISP_TSP_VOLUME_INSTRUCTION_OUTSIDE_LAST (2 << ISP_TSP_VOLUME_INSTRUCTION_SHIFT)
#define ISP_TSP_VOLUME_INSTRUCTION_MASK (7 << ISP_TSP_VOLUME_INSTRUCTION_SHIFT)
// Cull mode (for polygons and modifiers), bits 28-27
#define ISP_TSP_CULL_MODE_SHIFT 27
#define ISP_TSP_CULL_MODE_NONE (0 << ISP_TSP_CULL_MODE_SHIFT)
#define ISP_TSP_CULL_MODE_SMALL (1 << ISP_TSP_CULL_MODE_SHIFT)
#define ISP_TSP_CULL_MODE_COUNTER_CLOCKWISE (2 << ISP_TSP_CULL_MODE_SHIFT)
#define ISP_TSP_CULL_MODE_CLOCKWISE (3 << ISP_TSP_CULL_MODE_SHIFT)
#define ISP_TSP_CULL_MODE_MASK (3 << ISP_TSP_CULL_MODE_SHIFT)
// Z write disable, bit 26
#define ISP_TSP_Z_WRITE_SHIFT 26
#define ISP_TSP_Z_WRITE_ENABLE (0 << ISP_TSP_Z_WRITE_SHIFT)
#define ISP_TSP_Z_WRITE_DISABLE (1 << ISP_TSP_Z_WRITE_SHIFT)
#define ISP_TSP_Z_WRITE_MASK (1 << ISP_TSP_Z_WRITE_SHIFT)
// DCalc control, bit 20
#define ISP_TSP_DCALC_SHIFT 20
#define ISP_TSP_DCALC_DISABLE (0 << ISP_TSP_DCALC_SHIFT)
#define ISP_TSP_DCALC_ENABLE (1 << ISP_TSP_DCALC_SHIFT)
#define ISP_TSP_DCALC_MASK (1 << ISP_TSP_DCALC_SHIFT)
/////////////////////////////////////////////////////
// TSP instruction word //
/////////////////////////////////////////////////////
// SRC Alpha instruction, bits 31-29
#define TSP_SRC_ALPHA_INSTR_SHIFT 29
#define TSP_SRC_ALPHA_INSTR_ZERO (0 << TSP_SRC_ALPHA_INSTR_SHIFT)
#define TSP_SRC_ALPHA_INSTR_ONE (1 << TSP_SRC_ALPHA_INSTR_SHIFT)
#define TSP_SRC_ALPHA_INSTR_DST_COLOR (2 << TSP_SRC_ALPHA_INSTR_SHIFT)
#define TSP_SRC_ALPHA_INSTR_INVERSE_DST_COLOR (3 << TSP_SRC_ALPHA_INSTR_SHIFT)
#define TSP_SRC_ALPHA_INSTR_SRC_ALPHA (4 << TSP_SRC_ALPHA_INSTR_SHIFT)
#define TSP_SRC_ALPHA_INSTR_INVERSE_SRC_ALPHA (5 << TSP_SRC_ALPHA_INSTR_SHIFT)
#define TSP_SRC_ALPHA_INSTR_DST_ALPHA (6 << TSP_SRC_ALPHA_INSTR_SHIFT)
#define TSP_SRC_ALPHA_INSTR_INVERSE_DST_ALPHA (7 << TSP_SRC_ALPHA_INSTR_SHIFT)
#define TSP_SRC_ALPHA_INSTR_MASK (7 << TSP_SRC_ALPHA_INSTR_SHIFT)
// DST Alpha instruction, bits 28-26
#define TSP_DST_ALPHA_INSTR_SHIFT 26
#define TSP_DST_ALPHA_INSTR_ZERO (0 << TSP_DST_ALPHA_INSTR_SHIFT)
#define TSP_DST_ALPHA_INSTR_ONE (1 << TSP_DST_ALPHA_INSTR_SHIFT)
#define TSP_DST_ALPHA_INSTR_DST_COLOR (2 << TSP_DST_ALPHA_INSTR_SHIFT)
#define TSP_DST_ALPHA_INSTR_INVERSE_DST_COLOR (3 << TSP_DST_ALPHA_INSTR_SHIFT)
#define TSP_DST_ALPHA_INSTR_SRC_ALPHA (4 << TSP_DST_ALPHA_INSTR_SHIFT)
#define TSP_DST_ALPHA_INSTR_INVERSE_SRC_ALPHA (5 << TSP_DST_ALPHA_INSTR_SHIFT)
#define TSP_DST_ALPHA_INSTR_DST_ALPHA (6 << TSP_DST_ALPHA_INSTR_SHIFT)
#define TSP_DST_ALPHA_INSTR_INVERSE_DST_ALPHA (7 << TSP_DST_ALPHA_INSTR_SHIFT)
#define TSP_DST_ALPHA_INSTR_MASK (7 << TSP_DST_ALPHA_INSTR_SHIFT)
// SRC select enable, bit 25
#define TSP_SRC_SELECT_SHIFT 25
#define TSP_SRC_SELECT_DISABLE (0 << TSP_SRC_SELECT_SHIFT)
#define TSP_SRC_SELECT_ENABLE (1 << TSP_SRC_SELECT_SHIFT)
#define TSP_SRC_SELECT_MASK (1 << TSP_SRC_SELECT_SHIFT)
// DST select enable, bit 24
#define TSP_DST_SELECT_SHIFT 24
#define TSP_DST_SELECT_DISABLE (0 << TSP_DST_SELECT_SHIFT)
#define TSP_DST_SELECT_ENABLE (1 << TSP_DST_SELECT_SHIFT)
#define TSP_DST_SELECT_MASK (1 << TSP_DST_SELECT_SHIFT)
// Fog mode, bits 23-22
#define TSP_FOG_MODE_SHIFT 22
#define TSP_FOG_MODE_LOOKUP_TABLE (0 << TSP_FOG_MODE_SHIFT)
#define TSP_FOG_MODE_PER_VERTEX (1 << TSP_FOG_MODE_SHIFT)
#define TSP_FOG_MODE_DISABLE (2 << TSP_FOG_MODE_SHIFT)
#define TSP_FOG_MODE_LOOKUP_TABLE_2 (3 << TSP_FOG_MODE_SHIFT)
#define TSP_FOG_MODE_MASK (3 << TSP_FOG_MODE_SHIFT)
// Color clamp enable, bit 21
#define TSP_COLOR_CLAMP_SHIFT 21
#define TSP_COLOR_CLAMP_DISABLE (0 << TSP_COLOR_CLAMP_SHIFT)
#define TSP_COLOR_CLAMP_ENABLE (1 << TSP_COLOR_CLAMP_SHIFT)
#define TSP_COLOR_CLAMP_MASK (1 << TSP_COLOR_CLAMP_SHIFT)
// Alpha enable, bit 20
#define TSP_ALPHA_SHIFT 20
#define TSP_ALPHA_DISABLE (0 << TSP_ALPHA_SHIFT)
#define TSP_ALPHA_ENABLE (1 << TSP_ALPHA_SHIFT)
#define TSP_ALPHA_MASK (1 << TSP_ALPHA_SHIFT)
// Texture alpha enable, bit 19
#define TSP_TEXTURE_ALPHA_SHIFT 19
#define TSP_TEXTURE_ALPHA_DISABLE (1 << TSP_TEXTURE_ALPHA_SHIFT)
#define TSP_TEXTURE_ALPHA_ENABLE (0 << TSP_TEXTURE_ALPHA_SHIFT)
#define TSP_TEXTURE_ALPHA_MASK (1 << TSP_TEXTURE_ALPHA_SHIFT)
// Flip UV, bits 18-17
#define TSP_UV_FLIP_SHIFT 17
#define TSP_UV_FLIP_NONE (0 << TSP_UV_FLIP_SHIFT)
#define TSP_UV_FLIP_V (1 << TSP_UV_FLIP_SHIFT)
#define TSP_UV_FLIP_U (2 << TSP_UV_FLIP_SHIFT)
#define TSP_UV_FLIP_UV (3 << TSP_UV_FLIP_SHIFT)
#define TSP_UV_FLIP_MASK (3 << TSP_UV_FLIP_SHIFT)
// Clamp UV, bits 16-15
#define TSP_UV_CLAMP_SHIFT 15
#define TSP_UV_CLAMP_NONE (0 << TSP_UV_CLAMP_SHIFT)
#define TSP_UV_CLAMP_V (1 << TSP_UV_CLAMP_SHIFT)
#define TSP_UV_CLAMP_U (2 << TSP_UV_CLAMP_SHIFT)
#define TSP_UV_CLAMP_UV (3 << TSP_UV_CLAMP_SHIFT)
#define TSP_UV_CLAMP_MASK (3 << TSP_UV_CLAMP_SHIFT)
// Texture filter, bits 14-13
#define TSP_TEXTURE_FILTER_SHIFT 13
#define TSP_TEXTURE_FILTER_POINT (0 << TSP_TEXTURE_FILTER_SHIFT)
#define TSP_TEXTURE_FILTER_BILINEAR (1 << TSP_TEXTURE_FILTER_SHIFT)
#define TSP_TEXTURE_FILTER_TRILINEAR_PASS_A (2 << TSP_TEXTURE_FILTER_SHIFT)
#define TSP_TEXTURE_FILTER_TRILINEAR_PASS_B (3 << TSP_TEXTURE_FILTER_SHIFT)
#define TSP_TEXTURE_FILTER_MASK (3 << TSP_TEXTURE_FILTER_SHIFT)
// Texture super sampling enable, bit 12
#define TSP_SUPER_SAMPLING_SHIFT 12
#define TSP_SUPER_SAMPLING_DISABLE (0 << TSP_SUPER_SAMPLING_SHIFT)
#define TSP_SUPER_SAMPLING_ENABLE (1 << TSP_SUPER_SAMPLING_SHIFT)
#define TSP_SUPER_SAMPLING_MASK (1 << TSP_SUPER_SAMPLING_SHIFT)
// Mipmap adjust, bits 11-8
#define TSP_MIPMAP_ADJUST_SHIFT 8
#define TSP_MIPMAP_ADJUST_0_25 (1 << TSP_MIPMAP_ADJUST_SHIFT)
#define TSP_MIPMAP_ADJUST_0_50 (2 << TSP_MIPMAP_ADJUST_SHIFT)
#define TSP_MIPMAP_ADJUST_0_75 (3 << TSP_MIPMAP_ADJUST_SHIFT)
#define TSP_MIPMAP_ADJUST_1_00 (4 << TSP_MIPMAP_ADJUST_SHIFT)
#define TSP_MIPMAP_ADJUST_1_25 (5 << TSP_MIPMAP_ADJUST_SHIFT)
#define TSP_MIPMAP_ADJUST_1_50 (6 << TSP_MIPMAP_ADJUST_SHIFT)
#define TSP_MIPMAP_ADJUST_1_75 (7 << TSP_MIPMAP_ADJUST_SHIFT)
#define TSP_MIPMAP_ADJUST_2_00 (8 << TSP_MIPMAP_ADJUST_SHIFT)
#define TSP_MIPMAP_ADJUST_2_25 (9 << TSP_MIPMAP_ADJUST_SHIFT)
#define TSP_MIPMAP_ADJUST_2_50 (10 << TSP_MIPMAP_ADJUST_SHIFT)
#define TSP_MIPMAP_ADJUST_2_75 (11 << TSP_MIPMAP_ADJUST_SHIFT)
#define TSP_MIPMAP_ADJUST_3_00 (12 << TSP_MIPMAP_ADJUST_SHIFT)
#define TSP_MIPMAP_ADJUST_3_25 (13 << TSP_MIPMAP_ADJUST_SHIFT)
#define TSP_MIPMAP_ADJUST_3_50 (14 << TSP_MIPMAP_ADJUST_SHIFT)
#define TSP_MIPMAP_ADJUST_3_75 (15 << TSP_MIPMAP_ADJUST_SHIFT)
#define TSP_MIPMAP_ADJUST_MASK (15 << TSP_MIPMAP_ADJUST_SHIFT)
// Texture shading instruction, bits 7-6
#define TSP_TEXTURE_INSTRUCTION_SHIFT 6
#define TSP_TEXTURE_INSTRUCTION_DECAL (0 << TSP_TEXTURE_INSTRUCTION_SHIFT)
#define TSP_TEXTURE_INSTRUCTION_MODULATE (1 << TSP_TEXTURE_INSTRUCTION_SHIFT)
#define TSP_TEXTURE_INSTRUCTION_DECAL_ALPHA (2 << TSP_TEXTURE_INSTRUCTION_SHIFT)
#define TSP_TEXTURE_INSTRUCTION_MODULATE_ALPHA (3 << TSP_TEXTURE_INSTRUCTION_SHIFT)
#define TSP_TEXTURE_INSTRUCTION_MASK (3 << TSP_TEXTURE_INSTRUCTION_SHIFT)
// Texture U size, bits 5-3
#define TSP_TEXTURE_U_SIZE_SHIFT 3
#define TSP_TEXTURE_U_SIZE_8 (0 << TSP_TEXTURE_U_SIZE_SHIFT)
#define TSP_TEXTURE_U_SIZE_16 (1 << TSP_TEXTURE_U_SIZE_SHIFT)
#define TSP_TEXTURE_U_SIZE_32 (2 << TSP_TEXTURE_U_SIZE_SHIFT)
#define TSP_TEXTURE_U_SIZE_64 (3 << TSP_TEXTURE_U_SIZE_SHIFT)
#define TSP_TEXTURE_U_SIZE_128 (4 << TSP_TEXTURE_U_SIZE_SHIFT)
#define TSP_TEXTURE_U_SIZE_256 (5 << TSP_TEXTURE_U_SIZE_SHIFT)
#define TSP_TEXTURE_U_SIZE_512 (6 << TSP_TEXTURE_U_SIZE_SHIFT)
#define TSP_TEXTURE_U_SIZE_1024 (7 << TSP_TEXTURE_U_SIZE_SHIFT)
#define TSP_TEXTURE_U_SIZE_MASK (7 << TSP_TEXTURE_U_SIZE_SHIFT)
// Texture V size, bits 2-0
#define TSP_TEXTURE_V_SIZE_SHIFT 0
#define TSP_TEXTURE_V_SIZE_8 (0 << TSP_TEXTURE_V_SIZE_SHIFT)
#define TSP_TEXTURE_V_SIZE_16 (1 << TSP_TEXTURE_V_SIZE_SHIFT)
#define TSP_TEXTURE_V_SIZE_32 (2 << TSP_TEXTURE_V_SIZE_SHIFT)
#define TSP_TEXTURE_V_SIZE_64 (3 << TSP_TEXTURE_V_SIZE_SHIFT)
#define TSP_TEXTURE_V_SIZE_128 (4 << TSP_TEXTURE_V_SIZE_SHIFT)
#define TSP_TEXTURE_V_SIZE_256 (5 << TSP_TEXTURE_V_SIZE_SHIFT)
#define TSP_TEXTURE_V_SIZE_512 (6 << TSP_TEXTURE_V_SIZE_SHIFT)
#define TSP_TEXTURE_V_SIZE_1024 (7 << TSP_TEXTURE_V_SIZE_SHIFT)
#define TSP_TEXTURE_V_SIZE_MASK (7 << TSP_TEXTURE_V_SIZE_SHIFT)
/////////////////////////////////////////////////////
// Texture control word //
/////////////////////////////////////////////////////
// Mipmapped, bit 31
#define TCW_MIPMAP_SHIFT 31
#define TCW_MIPMAP_DISABLED (0 << TCW_MIPMAP_SHIFT)
#define TCW_MIPMAP_ENABLED (1 << TCW_MIPMAP_SHIFT)
#define TCW_MIPMAP_MASK (1 << TCW_MIPMAP_SHIFT)
// VQ compressed, bit 30
#define TCW_VQ_COMPRESSED_SHIFT 30
#define TCW_VQ_COMPRESSED_DISABLED (0 << TCW_VQ_COMPRESSED_SHIFT)
#define TCW_VQ_COMPRESSED_ENABLED (1 << TCW_VQ_COMPRESSED_SHIFT)
#define TCW_VQ_COMPRESSED_MASK (1 << TCW_VQ_COMPRESSED_SHIFT)
// Texture format, bits 29-27
#define TCW_PIXEL_FORMAT_SHIFT 27
#define TCW_PIXEL_FORMAT_ARGB1555 (0 << TCW_PIXEL_FORMAT_SHIFT)
#define TCW_PIXEL_FORMAT_RGB565 (1 << TCW_PIXEL_FORMAT_SHIFT)
#define TCW_PIXEL_FORMAT_ARGB4444 (2 << TCW_PIXEL_FORMAT_SHIFT)
#define TCW_PIXEL_FORMAT_YUV422 (3 << TCW_PIXEL_FORMAT_SHIFT)
#define TCW_PIXEL_FORMAT_BUMP_MAP (4 << TCW_PIXEL_FORMAT_SHIFT)
#define TCW_PIXEL_FORMAT_PAL_4BPP (5 << TCW_PIXEL_FORMAT_SHIFT)
#define TCW_PIXEL_FORMAT_PAL_8BPP (6 << TCW_PIXEL_FORMAT_SHIFT)
#define TCW_PIXEL_FORMAT_MASK (7 << TCW_PIXEL_FORMAT_SHIFT)
// Twiddled (for non-paletted textures), bit 26
#define TCW_TWIDDLED_SHIFT 26
#define TCW_TWIDDLED_DISABLED (1 << TCW_TWIDDLED_SHIFT)
#define TCW_TWIDDLED_ENABLED (0 << TCW_TWIDDLED_SHIFT)
#define TCW_TWIDDLED_MASK (1 << TCW_TWIDDLED_SHIFT)
// Stride enable (for non-paletted textures), bit 25
#define TCW_STRIDE_SHIFT 25
#define TCW_STRIDE_DISABLED (0 << TCW_STRIDE_SHIFT)
#define TCW_STRIDE_ENABLED (1 << TCW_STRIDE_SHIFT)
#define TCW_STRIDE_MASK (1 << TCW_STRIDE_SHIFT)
// Palette index (for paletted textures), bits 26-21
#define TCW_PALETTE_INDEX_4BPP_SHIFT 21
#define TCW_PALETTE_INDEX_4BPP_MASK (63 << TCW_PALETTE_INDEX_4BPP_SHIFT)
#define TCW_PALETTE_INDEX_8BPP_SHIFT 25
#define TCW_PALETTE_INDEX_8BPP_MASK (63 << TCW_PALETTE_INDEX_8BPP_SHIFT)
// Texture address, bits 20-0
#define TCW_TEXTURE_ADDRESS(addr) ((((uint32)(void*)(addr))&0x7fffff)>>3)
#define TCW_TEXTURE_ADDRESS_MASK (0x000FFFFF)
/*
===============================================================================
ERROR HANDLER FUNCTIONS
===============================================================================
*/
static void (*_error_handler)(SHERROR, const char* fnname) = NULL;
void shErrorHandler( void (*hnd)(SHERROR, const char* fnname) )
{
_error_handler = hnd;
}
static inline void report_error( SHERROR err, const char* fnname )
{
if ( _error_handler != NULL )
(*_error_handler)( err, fnname );
}
/*
===============================================================================
STRIP HEADER UTILITIES
===============================================================================
*/
// Used to index the "words" array of a strip header
#define PCW 0
#define ISPTSP 1
#define TSP0 2
#define TCW0 3
#define TSP1 4
#define TCW1 5
// There's an "allowed" system in place to make sure bits aren't set for
// header types where they cannot be changed.
// These will help a lot for setting up "allowed masks".
#define BIT(n) (1<<(n))
// All polygon types
#define TYPES_POLYGON (BIT(0)|BIT(1)|BIT(2)|BIT(3)|BIT(4)|BIT(5)|BIT(6)|BIT(7)|BIT(8)|BIT(9)|BIT(10)|BIT(11)|BIT(12)|BIT(13)|BIT(14))
// All sprite types
#define TYPES_SPRITE (BIT(15)|BIT(16))
// Modifier type
#define TYPES_MODIFIER (BIT(17))
// Polygons and sprites
#define TYPES_POLYSPRITE (TYPES_POLYGON|TYPES_SPRITE)
// All types
#define TYPES_ALL (TYPES_POLYGON|TYPES_SPRITE|TYPES_MODIFIER)
// Textured types
#define TYPES_TEXTURED (BIT(3)|BIT(4)|BIT(5)|BIT(6)|BIT(7)|BIT(8)|BIT(11)|BIT(12)|BIT(13)|BIT(14)|BIT(16))
// Types affected by cheap shadow modifiers
#define TYPES_SHADOW (BIT(0)|BIT(1)|BIT(2)|BIT(3)|BIT(4)|BIT(5)|BIT(6)|BIT(7)|BIT(8))
// Types affected by two-parameter modifiers
#define TYPES_POLYGON_2 (BIT(9)|BIT(10)|BIT(11)|BIT(12)|BIT(13)|BIT(14))
// Textured types affected by two-parameter modifiers
#define TYPES_TEXTURED_2 (TYPES_POLYGON_2 & TYPES_TEXTURED)
// Intensity color types
#define TYPES_INTENSITY (BIT(2)|BIT(7)|BIT(8)|BIT(10)|BIT(13)|BIT(14))
// Returns 1 if bit <type> can be found in bitfield <types>, otherwise 0.
static inline int check_allowed( uint32 type, uint32 types )
{
return ( ( types & BIT(type) ) != 0 );
}
// The following two functions are "safe" ways of setting boolean and generic values
// of a header. These are the meat of the lib as most other functions use them.
// Most errors are probably cought here as well. While I'd definitely prefer to
// do the error handling at a higher level to avoid passing top level functions
// everywhere, the amount of top level error checking would just be insane.
static int set_boolean_safe( stripheader_t* hdr, const char* fnname, int cond, int affected_word, uint32 allowed_types, uint32 bitmask, uint32 tval, uint32 fval )
{
if ( hdr->type > 17 )
{
report_error( SH_ERROR_INVALID_TYPE, fnname );
return 0;
}
if ( !check_allowed( hdr->type, allowed_types ) )
{
report_error( SH_ERROR_NOT_ALLOWED, fnname );
return 0;
}
hdr->words[ affected_word ] &= ~bitmask;
hdr->words[ affected_word ] |= ( cond ? tval : fval );
return 1;
}
static int set_generic_safe( stripheader_t* hdr, const char* fnname, int affected_word, uint32 allowed_types, uint32 bitmask, uint32 shift, uint32 value )
{
if ( hdr->type > 17 )
{
report_error( SH_ERROR_INVALID_TYPE, fnname );
return 0;
}
if ( !check_allowed( hdr->type, allowed_types ) )
{
report_error( SH_ERROR_NOT_ALLOWED, fnname );
return 0;
}
hdr->words[ affected_word ] &= ~bitmask;
hdr->words[ affected_word ] |= ( ( value << shift ) & bitmask );
return 1;
}
// Default parameter control words (just OR in the list and you're set)
static const uint32 default_pcw[18] =
{
/*00*/ PCW_TYPE_POLYGON | PCW_UPDATE_GROUP_ON | PCW_STRIP_LENGTH_2 | PCW_COLOR_TYPE_PACKED | PCW_MODIFIER_DISABLE | PCW_MODIFIER_TYPE_SHADOW | PCW_TEXTURE_DISABLE | PCW_SHADING_GOURAUD,
/*01*/ PCW_TYPE_POLYGON | PCW_UPDATE_GROUP_ON | PCW_STRIP_LENGTH_2 | PCW_COLOR_TYPE_FLOAT | PCW_MODIFIER_DISABLE | PCW_MODIFIER_TYPE_SHADOW | PCW_TEXTURE_DISABLE | PCW_SHADING_GOURAUD,
/*02*/ PCW_TYPE_POLYGON | PCW_UPDATE_GROUP_ON | PCW_STRIP_LENGTH_2 | PCW_COLOR_TYPE_INTENSITY | PCW_MODIFIER_DISABLE | PCW_MODIFIER_TYPE_SHADOW | PCW_TEXTURE_DISABLE | PCW_SHADING_GOURAUD,
/*03*/ PCW_TYPE_POLYGON | PCW_UPDATE_GROUP_ON | PCW_STRIP_LENGTH_2 | PCW_COLOR_TYPE_PACKED | PCW_MODIFIER_DISABLE | PCW_MODIFIER_TYPE_SHADOW | PCW_TEXTURE_ENABLE | PCW_SHADING_GOURAUD | PCW_UV_32BIT,
/*04*/ PCW_TYPE_POLYGON | PCW_UPDATE_GROUP_ON | PCW_STRIP_LENGTH_2 | PCW_COLOR_TYPE_PACKED | PCW_MODIFIER_DISABLE | PCW_MODIFIER_TYPE_SHADOW | PCW_TEXTURE_ENABLE | PCW_SHADING_GOURAUD | PCW_UV_16BIT,
/*05*/ PCW_TYPE_POLYGON | PCW_UPDATE_GROUP_ON | PCW_STRIP_LENGTH_2 | PCW_COLOR_TYPE_FLOAT | PCW_MODIFIER_DISABLE | PCW_MODIFIER_TYPE_SHADOW | PCW_TEXTURE_ENABLE | PCW_SHADING_GOURAUD | PCW_UV_32BIT,
/*06*/ PCW_TYPE_POLYGON | PCW_UPDATE_GROUP_ON | PCW_STRIP_LENGTH_2 | PCW_COLOR_TYPE_FLOAT | PCW_MODIFIER_DISABLE | PCW_MODIFIER_TYPE_SHADOW | PCW_TEXTURE_ENABLE | PCW_SHADING_GOURAUD | PCW_UV_16BIT,
/*07*/ PCW_TYPE_POLYGON | PCW_UPDATE_GROUP_ON | PCW_STRIP_LENGTH_2 | PCW_COLOR_TYPE_INTENSITY | PCW_MODIFIER_DISABLE | PCW_MODIFIER_TYPE_SHADOW | PCW_TEXTURE_ENABLE | PCW_SHADING_GOURAUD | PCW_UV_32BIT,
/*08*/ PCW_TYPE_POLYGON | PCW_UPDATE_GROUP_ON | PCW_STRIP_LENGTH_2 | PCW_COLOR_TYPE_INTENSITY | PCW_MODIFIER_DISABLE | PCW_MODIFIER_TYPE_SHADOW | PCW_TEXTURE_ENABLE | PCW_SHADING_GOURAUD | PCW_UV_16BIT,
/*09*/ PCW_TYPE_POLYGON | PCW_UPDATE_GROUP_ON | PCW_STRIP_LENGTH_2 | PCW_COLOR_TYPE_PACKED | PCW_MODIFIER_ENABLE | PCW_MODIFIER_TYPE_NORMAL | PCW_TEXTURE_DISABLE | PCW_SHADING_GOURAUD,
/*10*/ PCW_TYPE_POLYGON | PCW_UPDATE_GROUP_ON | PCW_STRIP_LENGTH_2 | PCW_COLOR_TYPE_INTENSITY | PCW_MODIFIER_ENABLE | PCW_MODIFIER_TYPE_NORMAL | PCW_TEXTURE_DISABLE | PCW_SHADING_GOURAUD,
/*11*/ PCW_TYPE_POLYGON | PCW_UPDATE_GROUP_ON | PCW_STRIP_LENGTH_2 | PCW_COLOR_TYPE_PACKED | PCW_MODIFIER_ENABLE | PCW_MODIFIER_TYPE_NORMAL | PCW_TEXTURE_ENABLE | PCW_SHADING_GOURAUD | PCW_UV_32BIT,
/*12*/ PCW_TYPE_POLYGON | PCW_UPDATE_GROUP_ON | PCW_STRIP_LENGTH_2 | PCW_COLOR_TYPE_PACKED | PCW_MODIFIER_ENABLE | PCW_MODIFIER_TYPE_NORMAL | PCW_TEXTURE_ENABLE | PCW_SHADING_GOURAUD | PCW_UV_16BIT,
/*13*/ PCW_TYPE_POLYGON | PCW_UPDATE_GROUP_ON | PCW_STRIP_LENGTH_2 | PCW_COLOR_TYPE_INTENSITY | PCW_MODIFIER_ENABLE | PCW_MODIFIER_TYPE_NORMAL | PCW_TEXTURE_ENABLE | PCW_SHADING_GOURAUD | PCW_UV_32BIT,
/*14*/ PCW_TYPE_POLYGON | PCW_UPDATE_GROUP_ON | PCW_STRIP_LENGTH_2 | PCW_COLOR_TYPE_INTENSITY | PCW_MODIFIER_ENABLE | PCW_MODIFIER_TYPE_NORMAL | PCW_TEXTURE_ENABLE | PCW_SHADING_GOURAUD | PCW_UV_16BIT,
/*15*/ PCW_TYPE_SPRITE | PCW_UPDATE_GROUP_ON | PCW_STRIP_LENGTH_2 | PCW_COLOR_TYPE_PACKED | PCW_TEXTURE_DISABLE | PCW_SHADING_FLAT,
/*16*/ PCW_TYPE_SPRITE | PCW_UPDATE_GROUP_ON | PCW_STRIP_LENGTH_2 | PCW_COLOR_TYPE_PACKED | PCW_TEXTURE_ENABLE | PCW_SHADING_FLAT | PCW_UV_16BIT,
/*17*/ PCW_TYPE_MODIFIER | PCW_MODIFIER_TRIANGLE
};
// Default isp/tsp words
static const uint32 default_isptsp = ISP_TSP_DEPTH_COMPARE_GREATER_OR_EQUAL | ISP_TSP_CULL_MODE_NONE | ISP_TSP_Z_WRITE_ENABLE | ISP_TSP_DCALC_DISABLE;
static const uint32 default_isptsp_mod = ISP_TSP_VOLUME_INSTRUCTION_NORMAL | ISP_TSP_CULL_MODE_NONE;
// Default tsp words
#define TSP_BASE ( TSP_SRC_SELECT_DISABLE | TSP_DST_SELECT_DISABLE | TSP_FOG_MODE_DISABLE | TSP_COLOR_CLAMP_DISABLE | TSP_UV_FLIP_NONE | TSP_UV_CLAMP_NONE | TSP_TEXTURE_FILTER_POINT | TSP_SUPER_SAMPLING_DISABLE | TSP_MIPMAP_ADJUST_1_00 )
static const uint32 default_tsp_alpha = TSP_BASE | TSP_ALPHA_ENABLE | TSP_TEXTURE_ALPHA_ENABLE | TSP_SRC_ALPHA_INSTR_SRC_ALPHA | TSP_DST_ALPHA_INSTR_INVERSE_SRC_ALPHA | TSP_TEXTURE_INSTRUCTION_MODULATE_ALPHA;
static const uint32 default_tsp_noalpha = TSP_BASE | TSP_ALPHA_DISABLE | TSP_TEXTURE_ALPHA_DISABLE | TSP_SRC_ALPHA_INSTR_ONE | TSP_DST_ALPHA_INSTR_ZERO | TSP_TEXTURE_INSTRUCTION_MODULATE;
/*
===============================================================================
STRIP HEADER METHODS
===============================================================================
*/
int shInit( stripheader_t* hdr, uint32 type, pvr_list_t list, const texture_t* tex0, const texture_t* tex1 )
{
if ( type > 17 )
{
report_error( SH_ERROR_INVALID_TYPE, __func__ );
return 0;
}
// Type 17 (modifier volume) doesn't need to initialize anything
// but the pcw and isptsp word. So there's no point in doing full
// initialization if that's the case.
if ( type == 17 )
{
// Make sure modifiers have a modifier list specified
if ( list == PVR_LIST_OP_POLY || list == PVR_LIST_TR_POLY || list == PVR_LIST_PT_POLY )
{
report_error( SH_ERROR_INVALID_LIST, __func__ );
return 0;
}
// Start with a cleared header
memset( hdr, 0, sizeof(stripheader_t) );
// Set the header type, PCW and ISP/TSP words
hdr->type = type;
hdr->words[PCW] = default_pcw[type] | ( list << PCW_LIST_SHIFT );
hdr->words[ISPTSP] = default_isptsp_mod;
}
// Every other type needs full initialization
else
{
int twoparam, textured;
// Make sure polygons and sprites have non-modifier lists specified
if ( list == PVR_LIST_OP_MOD || list == PVR_LIST_TR_MOD )
{
report_error( SH_ERROR_INVALID_LIST, __func__ );
return 0;
}
// Set the header type, PCW and ISP/TSP word
hdr->type = type;
hdr->words[PCW] = default_pcw[type] | ( list << PCW_LIST_SHIFT );
hdr->words[ISPTSP] = default_isptsp;
// These will make the rest easier
twoparam = ( hdr->words[PCW] & PCW_MODIFIER_TYPE_MASK ) == PCW_MODIFIER_TYPE_NORMAL;
textured = ( hdr->words[PCW] & PCW_TEXTURE_MASK ) == PCW_TEXTURE_ENABLE;
// Set texture & shading words
hdr->words[TSP0] = ( ( list > PVR_LIST_OP_MOD ) ? default_tsp_alpha : default_tsp_noalpha );
hdr->words[TSP1] = ( twoparam ? hdr->words[TSP0] : 0 );
// Set texture control words
if ( textured )
{
shTexture( hdr, tex0 );
if ( twoparam )
shTexture2( hdr, tex1 );
else
hdr->words[TCW1] = 0;
}
else
{
hdr->words[TCW0] = 0;
hdr->words[TCW1] = 0;
}
// Clear this one as well, just to be nice.. :)
hdr->unused = 0;
// Clear colors to white
hdr->color0[0] = hdr->color0[1] = hdr->color0[2] = hdr->color0[3] = 1.0f;
hdr->color1[0] = hdr->color1[1] = hdr->color1[2] = hdr->color1[3] = 1.0f;
}
return 1;
}
// Generic enable/disable method so we don't have to do this large
// switch statement twice.
static int set_enabled( stripheader_t* hdr, const char* fnname, SHCAPABILITY cap, int enable )
{
switch ( cap )
{
case SH_AFFECTED_BY_MODIFIER:
return set_boolean_safe( hdr, fnname, enable, PCW, TYPES_SHADOW, PCW_MODIFIER_MASK, PCW_MODIFIER_ENABLE, PCW_MODIFIER_DISABLE );
case SH_SMOOTH_SHADING:
return set_boolean_safe( hdr, fnname, enable, PCW, TYPES_POLYGON, PCW_SHADING_MASK, PCW_SHADING_GOURAUD, PCW_SHADING_FLAT );
case SH_OFFSET_COLOR:
return set_boolean_safe( hdr, fnname, enable, PCW, TYPES_TEXTURED, PCW_OFFSET_COLOR_MASK, PCW_OFFSET_COLOR_ENABLE, PCW_OFFSET_COLOR_DISABLE );
case SH_USE_PREVIOUS_COLOR:
return set_boolean_safe( hdr, fnname, enable, PCW, TYPES_INTENSITY, PCW_COLOR_TYPE_MASK, PCW_COLOR_TYPE_PREV_INTENSITY, PCW_COLOR_TYPE_INTENSITY );
case SH_DCALC_CONTROL:
return set_boolean_safe( hdr, fnname, enable, ISPTSP, TYPES_TEXTURED, ISP_TSP_DCALC_MASK, ISP_TSP_DCALC_ENABLE, ISP_TSP_DCALC_DISABLE );
case SH_ALPHA:
return set_boolean_safe( hdr, fnname, enable, TSP0, TYPES_POLYSPRITE, TSP_ALPHA_MASK, TSP_ALPHA_ENABLE, TSP_ALPHA_DISABLE );
case SH_ALPHA_2:
return set_boolean_safe( hdr, fnname, enable, TSP1, TYPES_POLYGON_2, TSP_ALPHA_MASK, TSP_ALPHA_ENABLE, TSP_ALPHA_DISABLE );
case SH_SRC_SELECT:
return set_boolean_safe( hdr, fnname, enable, TSP0, TYPES_POLYSPRITE, TSP_SRC_SELECT_MASK, TSP_SRC_SELECT_ENABLE, TSP_SRC_SELECT_DISABLE );
case SH_SRC_SELECT_2:
return set_boolean_safe( hdr, fnname, enable, TSP1, TYPES_POLYGON_2, TSP_SRC_SELECT_MASK, TSP_SRC_SELECT_ENABLE, TSP_SRC_SELECT_DISABLE );
case SH_DST_SELECT:
return set_boolean_safe( hdr, fnname, enable, TSP0, TYPES_POLYSPRITE, TSP_DST_SELECT_MASK, TSP_DST_SELECT_ENABLE, TSP_DST_SELECT_DISABLE );
case SH_DST_SELECT_2:
return set_boolean_safe( hdr, fnname, enable, TSP1, TYPES_POLYGON_2, TSP_DST_SELECT_MASK, TSP_DST_SELECT_ENABLE, TSP_DST_SELECT_DISABLE );
case SH_TEXTURE_ALPHA:
return set_boolean_safe( hdr, fnname, enable, TSP0, TYPES_TEXTURED, TSP_TEXTURE_ALPHA_MASK, TSP_TEXTURE_ALPHA_ENABLE, TSP_TEXTURE_ALPHA_DISABLE );
case SH_TEXTURE_ALPHA_2:
return set_boolean_safe( hdr, fnname, enable, TSP1, TYPES_TEXTURED_2, TSP_TEXTURE_ALPHA_MASK, TSP_TEXTURE_ALPHA_ENABLE, TSP_TEXTURE_ALPHA_DISABLE );
case SH_TEX_SUPER_SAMPLING:
return set_boolean_safe( hdr, fnname, enable, TSP0, TYPES_TEXTURED, TSP_SUPER_SAMPLING_MASK, TSP_SUPER_SAMPLING_ENABLE, TSP_SUPER_SAMPLING_DISABLE );
case SH_TEX_SUPER_SAMPLING_2:
return set_boolean_safe( hdr, fnname, enable, TSP1, TYPES_TEXTURED_2, TSP_SUPER_SAMPLING_MASK, TSP_SUPER_SAMPLING_ENABLE, TSP_SUPER_SAMPLING_DISABLE );
}
report_error( SH_ERROR_CAPABILITY, fnname );
return 0;
}
int shEnable( stripheader_t* hdr, SHCAPABILITY cap ) { return set_enabled( hdr, __func__, cap, 1 ); }
int shDisable( stripheader_t* hdr, SHCAPABILITY cap ) { return set_enabled( hdr, __func__, cap, 0 ); }
// These are all straightforward enough
int shCullMode( stripheader_t* hdr, SHCULLMODE mode )
{
return set_generic_safe( hdr, __func__, ISPTSP, TYPES_ALL, ISP_TSP_CULL_MODE_MASK, ISP_TSP_CULL_MODE_SHIFT, mode );
}
int shFogMode( stripheader_t* hdr, SHFOGMODE mode )
{
return set_generic_safe( hdr, __func__, TSP0, TYPES_POLYSPRITE, TSP_FOG_MODE_MASK, TSP_FOG_MODE_SHIFT, mode );
}
int shFogMode2( stripheader_t* hdr, SHFOGMODE mode )
{
return set_generic_safe( hdr, __func__, TSP1, TYPES_POLYGON_2, TSP_FOG_MODE_MASK, TSP_FOG_MODE_SHIFT, mode );
}
int shMipmapAdjust( stripheader_t* hdr, SHMIPMAPADJUST adjust )
{
return set_generic_safe( hdr, __func__, TSP0, TYPES_TEXTURED, TSP_MIPMAP_ADJUST_MASK, TSP_MIPMAP_ADJUST_SHIFT, adjust );
}
int shMipmapAdjust2( stripheader_t* hdr, SHMIPMAPADJUST adjust )
{
return set_generic_safe( hdr, __func__, TSP1, TYPES_TEXTURED_2, TSP_MIPMAP_ADJUST_MASK, TSP_MIPMAP_ADJUST_SHIFT, adjust );
}
int shTextureFilter( stripheader_t* hdr, SHTEXTUREFILTER filter )
{
return set_generic_safe( hdr, __func__, TSP0, TYPES_TEXTURED, TSP_TEXTURE_FILTER_MASK, TSP_TEXTURE_FILTER_SHIFT, filter );
}
int shTextureFilter2( stripheader_t* hdr, SHTEXTUREFILTER filter )
{
return set_generic_safe( hdr, __func__, TSP1, TYPES_TEXTURED_2, TSP_TEXTURE_FILTER_MASK, TSP_TEXTURE_FILTER_SHIFT, filter );
}
int shBlendFunc( stripheader_t* hdr, SHBLENDFUNC src, SHBLENDFUNC dst )
{
return set_generic_safe( hdr, __func__, TSP0, TYPES_POLYSPRITE, TSP_SRC_ALPHA_INSTR_MASK, TSP_SRC_ALPHA_INSTR_SHIFT, src ) &&
set_generic_safe( hdr, __func__, TSP0, TYPES_POLYSPRITE, TSP_DST_ALPHA_INSTR_MASK, TSP_DST_ALPHA_INSTR_SHIFT, dst );
}
int shBlendFunc2( stripheader_t* hdr, SHBLENDFUNC src, SHBLENDFUNC dst )
{
return set_generic_safe( hdr, __func__, TSP1, TYPES_POLYGON_2, TSP_SRC_ALPHA_INSTR_MASK, TSP_SRC_ALPHA_INSTR_SHIFT, src ) &&
set_generic_safe( hdr, __func__, TSP1, TYPES_POLYGON_2, TSP_DST_ALPHA_INSTR_MASK, TSP_DST_ALPHA_INSTR_SHIFT, dst );
}
int shModifierInstruction( stripheader_t* hdr, SHMODIFIERINSTRUCTION instr )
{
// Need to set both both the instruction and the "last triangle in volume" flag.
return set_boolean_safe( hdr, __func__, instr != SH_MODIFIER_NORMAL, PCW, TYPES_MODIFIER, PCW_MODIFIER_TRIANGLE_MASK, PCW_MODIFIER_TRIANGLE_LAST, PCW_MODIFIER_TRIANGLE ) &&
set_generic_safe( hdr, __func__, ISPTSP, TYPES_MODIFIER, ISP_TSP_VOLUME_INSTRUCTION_MASK, ISP_TSP_VOLUME_INSTRUCTION_SHIFT, instr );
}
int shPalette( stripheader_t* hdr, uint32 index )
{
const uint32 format = hdr->words[TCW0] & TCW_PIXEL_FORMAT_MASK;
switch ( format )
{
case TCW_PIXEL_FORMAT_PAL_4BPP:
if ( index < 64 )
return set_generic_safe( hdr, __func__, TCW0, TYPES_TEXTURED, TCW_PALETTE_INDEX_4BPP_MASK, TCW_PALETTE_INDEX_4BPP_SHIFT, index );
report_error( SH_ERROR_PALETTE_OUT_OF_BOUNDS, __func__ );
break;
case TCW_PIXEL_FORMAT_PAL_8BPP:
if ( index < 4 )
return set_generic_safe( hdr, __func__, TCW0, TYPES_TEXTURED, TCW_PALETTE_INDEX_8BPP_MASK, TCW_PALETTE_INDEX_8BPP_SHIFT, index );
report_error( SH_ERROR_PALETTE_OUT_OF_BOUNDS, __func__ );
break;
default:
report_error( SH_ERROR_NOT_PALETTED, __func__ );
break;
}
return 0;
}
int shPalette2( stripheader_t* hdr, uint32 index )
{
const uint32 format = hdr->words[TCW0] & TCW_PIXEL_FORMAT_MASK;
switch ( format )
{
case TCW_PIXEL_FORMAT_PAL_4BPP:
if ( index < 64 )
return set_generic_safe( hdr, __func__, TCW1, TYPES_TEXTURED_2, TCW_PALETTE_INDEX_4BPP_MASK, TCW_PALETTE_INDEX_4BPP_SHIFT, index );
report_error( SH_ERROR_PALETTE_OUT_OF_BOUNDS, __func__ );
break;
case TCW_PIXEL_FORMAT_PAL_8BPP:
if ( index < 4 )
return set_generic_safe( hdr, __func__, TCW1, TYPES_TEXTURED_2, TCW_PALETTE_INDEX_8BPP_MASK, TCW_PALETTE_INDEX_8BPP_SHIFT, index );
report_error( SH_ERROR_PALETTE_OUT_OF_BOUNDS, __func__ );
break;
default:
report_error( SH_ERROR_NOT_PALETTED, __func__ );
break;
}
return 0;
}
// This method will do what's needed to set a texture. This involves generating
// a texture control word and setting the texture size flags in the tsp word.
// hdr: Pointer to header that is to be modified
// tsp: Index of tsp word (either TSP0 or TSP1)
// tcw: Index of tcw (either TCW0 or TCW1)
// allowed: Bitfield of allowed types
// tex: Texture to set. If given NULL, this method will simply clear all affected bits.
// Returns 1 on success or 0 on failure.
static int set_texture( stripheader_t* hdr, const char* fnname, int tsp, int tcw, uint32 allowed, const texture_t* tex )
{
// Make sure this operation is allowed
if ( !check_allowed( hdr->type, allowed ) )
{
//dbglog( DBG_DEBUG, "%u\n", hdr->type );
report_error( SH_ERROR_NOT_ALLOWED, fnname );
return 0;
}
// Clear texture size bits in tsp word
hdr->words[tsp] &= ~TSP_TEXTURE_U_SIZE_MASK;
hdr->words[tsp] &= ~TSP_TEXTURE_V_SIZE_MASK;
// Clear texture control word
hdr->words[tcw] = 0;
if ( tex != NULL )
{
uint32 tmp = 0;
int paletted = 0;
switch ( tex->width )
{
case 8: tmp |= TSP_TEXTURE_U_SIZE_8; break;
case 16: tmp |= TSP_TEXTURE_U_SIZE_16; break;
case 32: tmp |= TSP_TEXTURE_U_SIZE_32; break;
case 64: tmp |= TSP_TEXTURE_U_SIZE_64; break;
case 128: tmp |= TSP_TEXTURE_U_SIZE_128; break;
case 256: tmp |= TSP_TEXTURE_U_SIZE_256; break;
case 512: tmp |= TSP_TEXTURE_U_SIZE_512; break;
case 1024: tmp |= TSP_TEXTURE_U_SIZE_1024; break;
default:
report_error( SH_ERROR_TEXTURE_SIZE, fnname );
return 0;
}
switch ( tex->height )
{
case 8: tmp |= TSP_TEXTURE_V_SIZE_8; break;
case 16: tmp |= TSP_TEXTURE_V_SIZE_16; break;
case 32: tmp |= TSP_TEXTURE_V_SIZE_32; break;
case 64: tmp |= TSP_TEXTURE_V_SIZE_64; break;
case 128: tmp |= TSP_TEXTURE_V_SIZE_128; break;
case 256: tmp |= TSP_TEXTURE_V_SIZE_256; break;
case 512: tmp |= TSP_TEXTURE_V_SIZE_512; break;
case 1024: tmp |= TSP_TEXTURE_V_SIZE_1024; break;
default:
report_error( SH_ERROR_TEXTURE_SIZE, fnname );
return 0;
}
// Set texture sizes in tsp word
hdr->words[tsp] |= tmp;
// Mipmap and compression flags
hdr->words[tcw] |= ( ( tex->flags & TEXFLAG_MIPMAPPED ) ? TCW_MIPMAP_ENABLED : TCW_MIPMAP_DISABLED );
hdr->words[tcw] |= ( ( tex->flags & TEXFLAG_COMPRESSED ) ? TCW_VQ_COMPRESSED_ENABLED : TCW_VQ_COMPRESSED_DISABLED );
// Format
switch ( tex->format )
{
case TEXFMT_RGB565: hdr->words[tcw] |= TCW_PIXEL_FORMAT_RGB565; paletted = 0; break;
case TEXFMT_ARGB1555: hdr->words[tcw] |= TCW_PIXEL_FORMAT_ARGB1555; paletted = 0; break;
case TEXFMT_ARGB4444: hdr->words[tcw] |= TCW_PIXEL_FORMAT_ARGB4444; paletted = 0; break;
case TEXFMT_PAL4BPP: hdr->words[tcw] |= TCW_PIXEL_FORMAT_PAL_4BPP; paletted = 1; break;
case TEXFMT_PAL8BPP: hdr->words[tcw] |= TCW_PIXEL_FORMAT_PAL_8BPP; paletted = 1; break;
}
if ( paletted )
{
// Paletted textures are assumed to be twiddled and doesn't allow stride.
// This is because these settings occupy the same bits as palette index.
}
else
{
// Twiddle and stride flags
hdr->words[tcw] |= ( ( tex->flags & TEXFLAG_TWIDDLED ) ? TCW_TWIDDLED_ENABLED : TCW_TWIDDLED_DISABLED );
hdr->words[tcw] |= TCW_STRIDE_DISABLED;
}
// Texture address
hdr->words[tcw] |= TCW_TEXTURE_ADDRESS( tex->vram_ptr );
}
return 1;
}
int shTexture( stripheader_t* hdr, const texture_t* tex ) { return set_texture( hdr, __func__, TSP0, TCW0, TYPES_TEXTURED, tex ); }
int shTexture2( stripheader_t* hdr, const texture_t* tex ) { return set_texture( hdr, __func__, TSP1, TCW1, TYPES_TEXTURED_2, tex ); }
int shBaseColor( stripheader_t* hdr, float a, float r, float g, float b )
{
if ( check_allowed( hdr->type, TYPES_INTENSITY | TYPES_SPRITE ) )
{
hdr->color0[0] = a;
hdr->color0[1] = r;
hdr->color0[2] = g;
hdr->color0[3] = b;
return 1;
}
report_error( SH_ERROR_NOT_ALLOWED, __func__ );
return 0;
}
int shBaseColor2( stripheader_t* hdr, float a, float r, float g, float b )
{
if ( check_allowed( hdr->type, TYPES_INTENSITY & TYPES_POLYGON_2 ) )
{
hdr->color1[0] = a;
hdr->color1[1] = r;
hdr->color1[2] = g;
hdr->color1[3] = b;
return 1;
}
report_error( SH_ERROR_NOT_ALLOWED, __func__ );
return 0;
}
int shSpriteColor( stripheader_t* hdr, uint8 *const color) {
hdr->sprColor[0] = color[3];
hdr->sprColor[1] = color[0];
hdr->sprColor[2] = color[1];
hdr->sprColor[3] = color[2];
return 1;
}
int shOffsetColor( stripheader_t* hdr, float a, float r, float g, float b )
{
if ( check_allowed( hdr->type, ( TYPES_INTENSITY | TYPES_SPRITE ) & TYPES_TEXTURED ) && !check_allowed( hdr->type, TYPES_POLYGON_2 ) )
{
hdr->color1[0] = a;
hdr->color1[1] = r;
hdr->color1[2] = g;
hdr->color1[3] = b;
return 1;
}
report_error( SH_ERROR_NOT_ALLOWED, __func__ );
return 0;
}
/***** Commit ****************************************************************/
#define PREFETCH(addr) __asm__ __volatile__("pref @%0" : : "r" (addr))
// TODO: Remove all 0 writes perhaps? Dunno if the pvr cares about those.
int shCommit( stripheader_t* header, uint32* ptr )
{
int size_in_words = 0;
// Quit now if the header is invalid
if ( header->type > 17 )
{
report_error( SH_ERROR_INVALID_TYPE, __func__ );
return 0;
}
switch ( header->type )
{
case 0:
case 1:
case 3:
case 4:
case 5:
case 6:
case 17:
ptr += 8;
*--ptr = 0;
*--ptr = 0;
*--ptr = 0;
*--ptr = 0;
size_in_words = 8;
break;
case 2:
ptr += 8;
*(float*)--ptr = header->color0[3]; // Doesn't matter when using previous face color
*(float*)--ptr = header->color0[2]; // Doesn't matter when using previous face color
*(float*)--ptr = header->color0[1]; // Doesn't matter when using previous face color
*(float*)--ptr = header->color0[0]; // Doesn't matter when using previous face color
size_in_words = 8;
break;
case 7:
case 8:
if ( ( ( header->words[PCW] & PCW_COLOR_TYPE_MASK ) == PCW_COLOR_TYPE_INTENSITY ) &&
( ( header->words[PCW] & PCW_OFFSET_COLOR_MASK ) == PCW_OFFSET_COLOR_ENABLE ) )
{
ptr += 16;
*(float*)--ptr = header->color1[3];
*(float*)--ptr = header->color1[2];
*(float*)--ptr = header->color1[1];
*(float*)--ptr = header->color1[0];
*(float*)--ptr = header->color0[3];
*(float*)--ptr = header->color0[2];
*(float*)--ptr = header->color0[1];
*(float*)--ptr = header->color0[0];
PREFETCH( (void*)ptr );
*--ptr = 0;
*--ptr = 0;
*--ptr = 0;
*--ptr = 0;
size_in_words = 16;
}
else
{
ptr += 8;
*(float*)--ptr = header->color0[3]; // Doesn't matter when using previous face color
*(float*)--ptr = header->color0[2]; // Doesn't matter when using previous face color
*(float*)--ptr = header->color0[1]; // Doesn't matter when using previous face color
*(float*)--ptr = header->color0[0]; // Doesn't matter when using previous face color
size_in_words = 8;
}
break;
case 9:
case 11:
case 12:
ptr += 8;
*--ptr = 0;
*--ptr = 0;
*--ptr = header->words[TCW1];
*--ptr = header->words[TSP1];
size_in_words = 8;
break;
case 10:
case 13:
case 14:
if ( ( header->words[PCW] & PCW_COLOR_TYPE_MASK ) == PCW_COLOR_TYPE_INTENSITY )
{
ptr += 16;
*(float*)--ptr = header->color1[3];
*(float*)--ptr = header->color1[2];
*(float*)--ptr = header->color1[1];
*(float*)--ptr = header->color1[0];
*(float*)--ptr = header->color0[3];
*(float*)--ptr = header->color0[2];
*(float*)--ptr = header->color0[1];
*(float*)--ptr = header->color0[0];
PREFETCH( (void*)ptr );
*--ptr = 0;
*--ptr = 0;
*--ptr = header->words[TCW1];
*--ptr = header->words[TSP1];
size_in_words = 16;
}
else
{
ptr += 8;
*--ptr = 0;