Repository navigation
Expand file tree
/
Copy pathta_vtx.cpp
More file actions
1795 lines (1480 loc) · 38.7 KB
/
Copy pathta_vtx.cpp
File metadata and controls
1795 lines (1480 loc) · 38.7 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
/*
This file is part of libswirl
*/
#include "license/bsd"
/*
TA-VTX handling
Parsing of the TA stream and generation of vertex data !
*/
#include "ta.h"
#include "ta_ctx.h"
#include "pvr_mem.h"
#include "Renderer_if.h"
u32 ta_type_lut[256];
#define TACALL DYNACALL
#ifdef RELEASE
#undef verify
#define verify(x)
#endif
#define PLD(ptr,offs) // __asm __volatile ( "pld [%0, #" #offs "]\n"::"r" (ptr): );
#if HOST_CPU==CPU_X86
extern u32 TA_VTXC,TA_SPRC,TA_EOSC,TA_PPC,TA_SPC,TA_EOLC,TA_V64HC;
#define TA_VTX (TA_VTXC++)
#define TA_SPR (TA_SPRC++)
#define TA_EOS (TA_EOSC++)
#define TA_PP (TA_PPC++)
#define TA_SP (TA_SPC++)
#define TA_EOL (TA_EOLC++)
#define TA_V64H (TA_V64HC++)
#else
#define TA_VTX
#define TA_SPR
#define TA_EOS
#define TA_PP
#define TA_SP
#define TA_EOL
#define TA_V64H
#endif
//cache state vars
u32 tileclip_val=0;
u8 f32_su8_tbl[65536];
/*
__forceinline
u8 float_to_satu8(float val)
{
return f32_su8_tbl[((u32&)val)>>16];
}
*/
#define float_to_satu8(val) f32_su8_tbl[((u32&)val)>>16]
/*
This uses just 1k of lookup, but does more calcs
The full 64k table will be much faster -- as only a small sub-part of it will be used anyway (the same 1k)
*/
u8 float_to_satu8_2(float val)
{
s32 vl=(s32&)val>>16;
u32 m1=(vl-0x3b80)>>31; //1 if smaller 0x3b80 or negative
u32 m2=(vl-0x3f80)>>31; //1 if smaller 0x3f80 or negative
u32 vo=vl-0x3b80;
vo &= (~m1>>22);
return f32_su8_tbl[0x3b80+vo] | (~m2>>24);
}
#define saturate01(x) (((s32&)x)<0?0:(s32&)x>0x3f800000?1:x)
u8 float_to_satu8_math(float val)
{
return u8(saturate01(val)*255);
}
//vdec state variables
ModTriangle* lmr=0;
PolyParam nullPP;
PolyParam* CurrentPP=&nullPP;
List<PolyParam>* CurrentPPlist;
//TA state vars
DECL_ALIGN(4) u8 FaceBaseColor[4];
DECL_ALIGN(4) u8 FaceOffsColor[4];
DECL_ALIGN(4) u8 FaceBaseColor1[4];
DECL_ALIGN(4) u8 FaceOffsColor1[4];
DECL_ALIGN(4) u32 SFaceBaseColor;
DECL_ALIGN(4) u32 SFaceOffsColor;
//splitter function lookup
extern u32 ta_type_lut[256];
void TA_ListCont();
void TA_ListInit();
void TA_SoftReset();
//hehe
//as it seems, bit 1,2 are type, bit 0 is mod volume :p
//misc ones
const u32 ListType_None=-1;
const u32 SZ32=1;
const u32 SZ64=2;
#include "ta_structs.h"
typedef Ta_Dma* DYNACALL TaListFP(Ta_Dma* data,Ta_Dma* data_end);
typedef void TACALL TaPolyParamFP(void* ptr);
//#define TaCmd ((TaListFP*&)sh4rcb.tacmd_void)
TaListFP* TaCmd;
u32 CurrentList;
TaListFP* VerxexDataFP;
bool ListIsFinished[5];
f32 f16(u16 v)
{
u32 z=v<<16;
return *(f32*)&z;
}
#if HOST_CPU==CPU_X86
extern u32 TA_VTX_O;
#define TA_VTX_OVH(n) (TA_VTX_O+=n);
#else
#define TA_VTX_OVH(n)
#endif
#define vdrc vd_rc
//Splitter function (normally ta_dma_main , modified for split dma's)
//extern TaListFP* TaCmd;
static Renderer* renderer;
template<u32 instance>
class FifoSplitter
{
public:
static void ta_list_start(u32 new_list)
{
verify(CurrentList==ListType_None);
//verify(ListIsFinished[new_list]==false);
//printf("Starting list %d\n",new_list);
CurrentList=new_list;
StartList(CurrentList);
}
static Ta_Dma* DYNACALL NullVertexData(Ta_Dma* data,Ta_Dma* data_end)
{
printf("TA: Invalid state, ignoring VTX data\n");
return data+SZ32;
}
//part : 0 fill all data , 1 fill upper 32B , 2 fill lower 32B
//Poly decoder , will be moved to pvr code
template <u32 poly_type,u32 part>
__forceinline
static Ta_Dma* TACALL ta_handle_poly(Ta_Dma* data,Ta_Dma* data_end)
{
TA_VertexParam* vp=(TA_VertexParam*)data;
u32 rv=0;
if (part==2)
{
TA_V64H;
TaCmd=ta_main;
}
switch (poly_type)
{
#define ver_32B_def(num) \
case num : {\
AppendPolyVertex##num(&vp->vtx##num);\
rv=SZ32; TA_VTX; }\
break;
//32b , always in one pass :)
ver_32B_def(0);//(Non-Textured, Packed Color)
ver_32B_def(1);//(Non-Textured, Floating Color)
ver_32B_def(2);//(Non-Textured, Intensity)
ver_32B_def(3);//(Textured, Packed Color)
ver_32B_def(4);//(Textured, Packed Color, 16bit UV)
ver_32B_def(7);//(Textured, Intensity)
ver_32B_def(8);//(Textured, Intensity, 16bit UV)
ver_32B_def(9);//(Non-Textured, Packed Color, with Two Volumes)
ver_32B_def(10);//(Non-Textured, Intensity, with Two Volumes)
#undef ver_32B_def
#define ver_64B_def(num) \
case num : {\
/*process first half*/\
if (part!=2)\
{\
TA_VTX;\
rv+=SZ32;\
AppendPolyVertex##num##A(&vp->vtx##num##A);\
}\
/*process second half*/\
if (part==0)\
{\
AppendPolyVertex##num##B(&vp->vtx##num##B);\
rv+=SZ32;\
}\
else if (part==2)\
{\
AppendPolyVertex##num##B((TA_Vertex##num##B*)data);\
rv+=SZ32;\
}\
}\
break;
//64b , may be on 2 pass
ver_64B_def(5);//(Textured, Floating Color)
ver_64B_def(6);//(Textured, Floating Color, 16bit UV)
ver_64B_def(11);//(Textured, Packed Color, with Two Volumes)
ver_64B_def(12);//(Textured, Packed Color, 16bit UV, with Two Volumes)
ver_64B_def(13);//(Textured, Intensity, with Two Volumes)
ver_64B_def(14);//(Textured, Intensity, 16bit UV, with Two Volumes)
#undef ver_64B_def
}
return data+rv;
};
//Code Splitter/routers
//helper function for dummy dma's.Handles 32B and then switches to ta_main for next data
static Ta_Dma* TACALL ta_dummy_32(Ta_Dma* data,Ta_Dma* data_end)
{
TaCmd=ta_main;
return data+SZ32;
}
static Ta_Dma* TACALL ta_modvolB_32(Ta_Dma* data,Ta_Dma* data_end)
{
AppendModVolVertexB((TA_ModVolB*)data);
TaCmd=ta_main;
return data+SZ32;
}
static Ta_Dma* TACALL ta_mod_vol_data(Ta_Dma* data,Ta_Dma* data_end)
{
TA_VertexParam* vp=(TA_VertexParam*)data;
TA_VTX;
if (data==data_end)
{
AppendModVolVertexA(&vp->mvolA);
//32B more needed , 32B done :)
TaCmd=ta_modvolB_32;
return data+SZ32;
}
else
{
//all 64B done
AppendModVolVertexA(&vp->mvolA);
AppendModVolVertexB(&vp->mvolB);
return data+SZ64;
}
}
static Ta_Dma* TACALL ta_spriteB_data(Ta_Dma* data,Ta_Dma* data_end)
{
TA_V64H;
//32B more needed , 32B done :)
TaCmd=ta_main;
AppendSpriteVertexB((TA_Sprite1B*)data);
return data+SZ32;
}
static Ta_Dma* TACALL ta_sprite_data(Ta_Dma* data,Ta_Dma* data_end)
{
TA_SPR;
verify(data->pcw.ParaType==ParamType_Vertex_Parameter);
if (data==data_end)
{
//32B more needed , 32B done :)
TaCmd=ta_spriteB_data;
TA_VertexParam* vp=(TA_VertexParam*)data;
AppendSpriteVertexA(&vp->spr1A);
return data+SZ32;
}
else
{
TA_VertexParam* vp=(TA_VertexParam*)data;
AppendSpriteVertexA(&vp->spr1A);
AppendSpriteVertexB(&vp->spr1B);
//all 64B doneisimooooo la la la :*iiiiii niarj
return data+SZ64;
}
}
template <u32 poly_type,u32 poly_size>
static Ta_Dma* TACALL ta_poly_data(Ta_Dma* data,Ta_Dma* data_end)
{
__assume(data<=data_end);
//If SZ64 && 32 bytes
#define IS_FIST_HALF ((poly_size!=SZ32) && (data==data_end))
//If SZ32 && >=32 bytes
//If SZ64 && > 32 bytes
#define HAS_FULL_DATA (poly_size==SZ32 ? (data<=data_end) : (data<data_end))
#define ITER verify(data->pcw.ParaType==ParamType_Vertex_Parameter);\
PLD(data,128); \
ta_handle_poly<poly_type,0>(data,0); \
if (data->pcw.EndOfStrip) \
goto strip_end; \
data+=poly_size;
if (IS_FIST_HALF)
goto fist_half;
do
{
ITER
} while (HAS_FULL_DATA);
if (IS_FIST_HALF)
{
fist_half:
ta_handle_poly<poly_type,1>(data,0);
if (data->pcw.EndOfStrip) EndPolyStrip();
TaCmd=ta_handle_poly<poly_type,2>;
data+=SZ32;
}
return data;
strip_end:
TaCmd=ta_main;
if (data->pcw.EndOfStrip)
EndPolyStrip();
TA_EOS;
return data+poly_size;
}
static void TACALL AppendPolyParam2Full(void* vpp)
{
Ta_Dma* pp=(Ta_Dma*)vpp;
AppendPolyParam2A((TA_PolyParam2A*)&pp[0]);
AppendPolyParam2B((TA_PolyParam2B*)&pp[1]);
}
static void TACALL AppendPolyParam4Full(void* vpp)
{
Ta_Dma* pp=(Ta_Dma*)vpp;
AppendPolyParam4A((TA_PolyParam4A*)&pp[0]);
AppendPolyParam4B((TA_PolyParam4B*)&pp[1]);
}
//Second part of poly data
template <int t>
static Ta_Dma* TACALL ta_poly_B_32(Ta_Dma* data,Ta_Dma* data_end)
{
if (t==2)
AppendPolyParam2B((TA_PolyParam2B*)data);
else
AppendPolyParam4B((TA_PolyParam4B*)data);
TaCmd=ta_main;
return data+SZ32;
}
public:
//Group_En bit seems ignored, thanks p1pkin
#define group_EN() /*if (data->pcw.Group_En) */{ TileClipMode(data->pcw.User_Clip);}
static Ta_Dma* TACALL ta_main(Ta_Dma* data,Ta_Dma* data_end)
{
do
{
PLD(data,128);
switch (data->pcw.ParaType)
{
//Control parameter
//32Bw3
case ParamType_End_Of_List:
{
if (CurrentList==ListType_None)
{
CurrentList=data->pcw.ListType;
//printf("End_Of_List : list error\n");
}
else
{
//end of list should be all 0's ...
EndList(CurrentList);//end a list olny if it was realy started
}
//printf("End list %X\n",CurrentList);
ListIsFinished[CurrentList]=true;
CurrentList=ListType_None;
VerxexDataFP=NullVertexData;
data+=SZ32;
TA_EOL;
}
break;
//32B
case ParamType_User_Tile_Clip:
{
SetTileClip(data->data_32[3]&63,data->data_32[4]&31,data->data_32[5]&63,data->data_32[6]&31);
data+=SZ32;
}
break;
//32B
case ParamType_Object_List_Set:
{
printf("Unsupported list type: ParamType_Object_List_Set\n"); // NAOMI Virtual on Oratorio Tangram
// *cough* ignore it :p
data+=SZ32;
}
break;
//Global Parameter
//ModVolue :32B
//PolyType :32B/64B
case ParamType_Polygon_or_Modifier_Volume:
{
TA_PP;
group_EN();
//Yep , C++ IS lame & limited
#include "ta_const_df.h"
if (CurrentList==ListType_None)
ta_list_start(data->pcw.ListType); //start a list ;)
if (IsModVolList(CurrentList))
{
//accept mod data
StartModVol((TA_ModVolParam*)data);
VerxexDataFP=ta_mod_vol_data;
data+=SZ32;
}
else
{
u32 uid=ta_type_lut[data->pcw.obj_ctrl];
u32 psz=uid>>30;
u32 pdid=(u8)(uid);
u32 ppid=(u8)(uid>>8);
VerxexDataFP=ta_poly_data_lut[pdid];
if (data != data_end || psz==1)
{
//poly , 32B/64B
ta_poly_param_lut[ppid](data);
data+=psz;
}
else
{
//AppendPolyParam64A((TA_PolyParamA*)data);
//64b , first part
ta_poly_param_a_lut[ppid](data);
//Handle next 32B ;)
TaCmd=ta_poly_param_b_lut[ppid];
data+=SZ32;
}
}
}
break;
//32B
//Sets Sprite info , and switches to ta_sprite_data function
case ParamType_Sprite:
{
TA_SP;
group_EN();
if (CurrentList==ListType_None)
ta_list_start(data->pcw.ListType); //start a list ;)
VerxexDataFP=ta_sprite_data;
//printf("Sprite \n");
AppendSpriteParam((TA_SpriteParam*)data);
data+=SZ32;
}
break;
//Variable size
case ParamType_Vertex_Parameter:
//log ("vtx");
{
//printf("VTX:0x%08X\n",VerxexDataFP);
//verify(VerxexDataFP!=NullVertexData);
data=VerxexDataFP(data,data_end);
}
break;
//not handled
//Assumed to be 32B
case 3:
case 6:
{
die("Unhandled parameter");
data+=SZ32;
}
break;
}
}
while(data<=data_end);
return data;
}
//Fill in lookup table
FifoSplitter()
{
renderer = nullptr;
for (int i=0;i<256;i++)
{
PCW pcw;
pcw.obj_ctrl=i;
u32 rv= poly_data_type_id(pcw);
u32 type= poly_header_type_size(pcw);
if (type& 0x80)
rv|=(SZ64<<30);
else
rv|=(SZ32<<30);
rv|=(type&0x7F)<<8;
ta_type_lut[i]=rv;
}
VerxexDataFP = NullVertexData;
}
/*
Volume,Col_Type,Texture,Offset,Gouraud,16bit_UV
0 0 0 (0) x invalid Polygon Type 0 Polygon Type 0
0 0 1 x x 0 Polygon Type 0 Polygon Type 3
0 0 1 x x 1 Polygon Type 0 Polygon Type 4
0 1 0 (0) x invalid Polygon Type 0 Polygon Type 1
0 1 1 x x 0 Polygon Type 0 Polygon Type 5
0 1 1 x x 1 Polygon Type 0 Polygon Type 6
0 2 0 (0) x invalid Polygon Type 1 Polygon Type 2
0 2 1 0 x 0 Polygon Type 1 Polygon Type 7
0 2 1 0 x 1 Polygon Type 1 Polygon Type 8
0 2 1 1 x 0 Polygon Type 2 Polygon Type 7
0 2 1 1 x 1 Polygon Type 2 Polygon Type 8
0 3 0 (0) x invalid Polygon Type 0 Polygon Type 2
0 3 1 x x 0 Polygon Type 0 Polygon Type 7
0 3 1 x x 1 Polygon Type 0 Polygon Type 8
1 0 0 (0) x invalid Polygon Type 3 Polygon Type 9
1 0 1 x x 0 Polygon Type 3 Polygon Type 11
1 0 1 x x 1 Polygon Type 3 Polygon Type 12
1 2 0 (0) x invalid Polygon Type 4 Polygon Type 10
1 2 1 x x 0 Polygon Type 4 Polygon Type 13
1 2 1 x x 1 Polygon Type 4 Polygon Type 14
1 3 0 (0) x invalid Polygon Type 3 Polygon Type 10
1 3 1 x x 0 Polygon Type 3 Polygon Type 13
1 3 1 x x 1 Polygon Type 3 Polygon Type 14
Sprites :
(0) (0) 0 (0) (0) invalid Sprite Sprite Type 0
(0) (0) 1 x (0) (1) Sprite Sprite Type 1
*/
//helpers 0-14
static u32 poly_data_type_id(PCW pcw)
{
if (pcw.Texture)
{
//textured
if (pcw.Volume==0)
{ //single volume
if (pcw.Col_Type==0)
{
if (pcw.UV_16bit==0)
return 3; //(Textured, Packed Color , 32b uv)
else
return 4; //(Textured, Packed Color , 16b uv)
}
else if (pcw.Col_Type==1)
{
if (pcw.UV_16bit==0)
return 5; //(Textured, Floating Color , 32b uv)
else
return 6; //(Textured, Floating Color , 16b uv)
}
else
{
if (pcw.UV_16bit==0)
return 7; //(Textured, Intensity , 32b uv)
else
return 8; //(Textured, Intensity , 16b uv)
}
}
else
{
//two volumes
if (pcw.Col_Type==0)
{
if (pcw.UV_16bit==0)
return 11; //(Textured, Packed Color, with Two Volumes)
else
return 12; //(Textured, Packed Color, 16bit UV, with Two Volumes)
}
else if (pcw.Col_Type==1)
{
//die ("invalid");
return 0xFFFFFFFF;
}
else
{
if (pcw.UV_16bit==0)
return 13; //(Textured, Intensity, with Two Volumes)
else
return 14; //(Textured, Intensity, 16bit UV, with Two Volumes)
}
}
}
else
{
//non textured
if (pcw.Volume==0)
{ //single volume
if (pcw.Col_Type==0)
return 0; //(Non-Textured, Packed Color)
else if (pcw.Col_Type==1)
return 1; //(Non-Textured, Floating Color)
else
return 2; //(Non-Textured, Intensity)
}
else
{
//two volumes
if (pcw.Col_Type==0)
return 9; //(Non-Textured, Packed Color, with Two Volumes)
else if (pcw.Col_Type==1)
{
//die ("invalid");
return 0xFFFFFFFF;
}
else
{
return 10; //(Non-Textured, Intensity, with Two Volumes)
}
}
}
}
//0-4 | 0x80
static u32 poly_header_type_size(PCW pcw)
{
if (pcw.Volume == 0)
{
if ( pcw.Col_Type<2 ) //0,1
{
return 0 | 0; //Polygon Type 0 -- SZ32
}
else if ( pcw.Col_Type == 2 )
{
if (pcw.Texture)
{
if (pcw.Offset)
{
return 2 | 0x80; //Polygon Type 2 -- SZ64
}
else
{
return 1 | 0; //Polygon Type 1 -- SZ32
}
}
else
{
return 1 | 0; //Polygon Type 1 -- SZ32
}
}
else //col_type ==3
{
return 0 | 0; //Polygon Type 0 -- SZ32
}
}
else
{
if ( pcw.Col_Type==0 ) //0
{
return 3 | 0; //Polygon Type 3 -- SZ32
}
else if ( pcw.Col_Type==2 ) //2
{
return 4 | 0x80; //Polygon Type 4 -- SZ64
}
else if ( pcw.Col_Type==3 ) //3
{
return 3 | 0; //Polygon Type 3 -- SZ32
}
else
{
return 0xFFDDEEAA;//die ("data->pcw.Col_Type==1 && volume ==1");
}
}
}
void vdec_init(Renderer* renderer)
{
::renderer = renderer;
VDECInit();
TaCmd=ta_main;
CurrentList = ListType_None;
ListIsFinished[0]=ListIsFinished[1]=ListIsFinished[2]=ListIsFinished[3]=ListIsFinished[4]=false;
}
__forceinline
static void SetTileClip(u32 xmin,u32 ymin,u32 xmax,u32 ymax)
{
u32 rv=tileclip_val & 0xF0000000;
rv|=xmin; //6 bits
rv|=xmax<<6; //6 bits
rv|=ymin<<12; //5 bits
rv|=ymax<<17; //5 bits
tileclip_val=rv;
}
__forceinline
static void TileClipMode(u32 mode)
{
tileclip_val=(tileclip_val&(~0xF0000000)) | (mode<<28);
}
//list handling
__forceinline
static void StartList(u32 ListType)
{
if (ListType==ListType_Opaque)
CurrentPPlist=&vdrc.global_param_op;
else if (ListType==ListType_Punch_Through)
CurrentPPlist=&vdrc.global_param_pt;
else if (ListType==ListType_Translucent)
CurrentPPlist=&vdrc.global_param_tr;
CurrentPP=&nullPP;
}
__forceinline
static void EndList(u32 ListType)
{
CurrentPP=&nullPP;
CurrentPPlist=0;
if (ListType == ListType_Opaque_Modifier_Volume || ListType == ListType_Translucent_Modifier_Volume)
EndModVol();
}
/*
if (CurrentPP==0 || CurrentPP->pcw.full!=pp->pcw.full || \
CurrentPP->tcw.full!=pp->tcw.full || \
CurrentPP->tsp.full!=pp->tsp.full || \
CurrentPP->isp.full!=pp->isp.full ) \
*/
//Polys -- update code on sprites if that gets updated too --
template<class T>
static void glob_param_bdc_(T* pp)
{
if (CurrentPP->pcw.full!=pp->pcw.full ||
CurrentPP->tcw.full!=pp->tcw.full ||
CurrentPP->tsp.full!=pp->tsp.full ||
CurrentPP->isp.full!=pp->isp.full )
{
PolyParam* d_pp=CurrentPP;
if (CurrentPP->count!=0)
{
d_pp=CurrentPPlist->Append();
CurrentPP=d_pp;
}
d_pp->first=vdrc.idx.used();
d_pp->count=0;
d_pp->isp=pp->isp;
d_pp->tsp=pp->tsp;
d_pp->tcw=pp->tcw;
d_pp->pcw=pp->pcw;
d_pp->tileclip=tileclip_val;
d_pp->texid = -1;
if (d_pp->pcw.Texture) {
d_pp->texid = renderer->GetTexture(d_pp->tsp,d_pp->tcw);
}
d_pp->tsp1.full = -1;
d_pp->tcw1.full = -1;
d_pp->texid1 = -1;
}
}
#define glob_param_bdc(pp) glob_param_bdc_( (TA_PolyParam0*)pp)
#define poly_float_color_(to,a,r,g,b) \
to[0] = float_to_satu8(r); \
to[1] = float_to_satu8(g); \
to[2] = float_to_satu8(b); \
to[3] = float_to_satu8(a);
#define poly_float_color(to,src) \
poly_float_color_(to,pp->src##A,pp->src##R,pp->src##G,pp->src##B)
//poly param handling
__forceinline
static void TACALL AppendPolyParam0(void* vpp)
{
TA_PolyParam0* pp=(TA_PolyParam0*)vpp;
glob_param_bdc(pp);
}
__forceinline
static void TACALL AppendPolyParam1(void* vpp)
{
TA_PolyParam1* pp=(TA_PolyParam1*)vpp;
glob_param_bdc(pp);
poly_float_color(FaceBaseColor,FaceColor);
}
__forceinline
static void TACALL AppendPolyParam2A(void* vpp)
{
TA_PolyParam2A* pp=(TA_PolyParam2A*)vpp;
glob_param_bdc(pp);
}
__forceinline
static void TACALL AppendPolyParam2B(void* vpp)
{
TA_PolyParam2B* pp=(TA_PolyParam2B*)vpp;
poly_float_color(FaceBaseColor,FaceColor);
poly_float_color(FaceOffsColor,FaceOffset);
}
__forceinline
static void TACALL AppendPolyParam3(void* vpp)
{
TA_PolyParam3* pp=(TA_PolyParam3*)vpp;
glob_param_bdc(pp);
CurrentPP->tsp1.full = pp->tsp1.full;
CurrentPP->tcw1.full = pp->tcw1.full;
if (pp->pcw.Texture)
CurrentPP->texid1 = renderer->GetTexture(pp->tsp1, pp->tcw1);
}
__forceinline
static void TACALL AppendPolyParam4A(void* vpp)
{
TA_PolyParam4A* pp=(TA_PolyParam4A*)vpp;
glob_param_bdc(pp);
CurrentPP->tsp1.full = pp->tsp1.full;
CurrentPP->tcw1.full = pp->tcw1.full;
if (pp->pcw.Texture)
CurrentPP->texid1 = renderer->GetTexture(pp->tsp1, pp->tcw1);
}
__forceinline
static void TACALL AppendPolyParam4B(void* vpp)
{
TA_PolyParam4B* pp=(TA_PolyParam4B*)vpp;
poly_float_color(FaceBaseColor, FaceColor0);
poly_float_color(FaceBaseColor1, FaceColor1);
}
//Poly Strip handling
//We unite Strips together by duplicating the [last,first].On odd sized strips
//a second [first] vert is needed to make sure Culling works fine :)
__forceinline
static void EndPolyStrip()
{
CurrentPP->count=vdrc.idx.used() - CurrentPP->first;
if (CurrentPPlist==&vdrc.global_param_tr)
{
PolyParam* d_pp =CurrentPPlist->Append();
*d_pp=*CurrentPP;
CurrentPP=d_pp;
d_pp->first=vdrc.idx.used();
d_pp->count=0;
}
else
{
int vbase=vdrc.verts.used();
*vdrc.idx.Append()=vbase-1;
*vdrc.idx.Append()=vbase;
if (CurrentPP->count&1)
*vdrc.idx.Append()=vbase;
}
}
static inline void update_fz(float z)
{
if ((s32&)vdrc.fZ_max<(s32&)z && (s32&)z<0x49800000)
vdrc.fZ_max=z;
}
//Poly Vertex handlers
//Append vertex base
template<class T>
static Vertex* vert_cvt_base_(T* vtx)
{
f32 invW=vtx->xyz[2];
*vdrc.idx.Append()=vdrc.verts.used();
Vertex* cv=vdrc.verts.Append();
cv->x=vtx->xyz[0];
cv->y=vtx->xyz[1];
cv->z=invW;
update_fz(invW);
return cv;
}
#define vert_cvt_base Vertex* cv=vert_cvt_base_((TA_Vertex0*)vtx)
//Resume vertex base (for B part)
#define vert_res_base \
Vertex* cv=vdrc.verts.LastPtr();
//uv 16/32
#define vert_uv_32(u_name,v_name) \
cv->u = (vtx->u_name);\
cv->v = (vtx->v_name);
#define vert_uv_16(u_name,v_name) \
cv->u = f16(vtx->u_name);\
cv->v = f16(vtx->v_name);
#define vert_uv1_32(u_name,v_name) \
cv->u1 = (vtx->u_name);\
cv->v1 = (vtx->v_name);
#define vert_uv1_16(u_name,v_name) \
cv->u1 = f16(vtx->u_name);\
cv->v1 = f16(vtx->v_name);
//Color conversions
#define vert_packed_color_(to,src) \
{ \
u32 t=src; \
to[2] = (u8)(t);t>>=8;\
to[1] = (u8)(t);t>>=8;\
to[0] = (u8)(t);t>>=8;\
to[3] = (u8)(t); \
}
#define vert_float_color_(to,a,r,g,b) \
to[0] = float_to_satu8(r); \
to[1] = float_to_satu8(g); \
to[2] = float_to_satu8(b); \
to[3] = float_to_satu8(a);
//Macros to make thins easier ;)
#define vert_packed_color(to,src) \
vert_packed_color_(cv->to,vtx->src);
#define vert_float_color(to,src) \
vert_float_color_(cv->to,vtx->src##A,vtx->src##R,vtx->src##G,vtx->src##B)