-
Notifications
You must be signed in to change notification settings - Fork 0
/
F3DEX 2.cs
677 lines (531 loc) · 25.8 KB
/
F3DEX 2.cs
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
using Microsoft.SqlServer.Server;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using static System.Net.WebRequestMethods;
using System.Threading.Tasks;
namespace F3DSharp
{
public class F3DEX2
{
public uint[] GetIndexes(int IndexA, int IndexB, int IndexC)
{
return new uint[] { Convert.ToUInt32(IndexA), Convert.ToUInt32(IndexB), Convert.ToUInt32(IndexC) };
}
public byte[] BigEndian(byte[] Input)
{
Array.Reverse(Input);
return Input;
}
public byte[] BigEndian(Double Value)
{
byte[] Input = BitConverter.GetBytes(Value);
Array.Reverse(Input);
return Input;
}
public byte[] BigEndian(Single Value)
{
byte[] Input = BitConverter.GetBytes(Value);
Array.Reverse(Input);
return Input;
}
public byte[] BigEndian(UInt16 Value)
{
byte[] Input = BitConverter.GetBytes(Value);
Array.Reverse(Input);
return Input;
}
public byte[] BigEndian(UInt32 Value)
{
byte[] Input = BitConverter.GetBytes(Value);
Array.Reverse(Input);
return Input;
}
public byte[] BigEndian(Int16 Value)
{
byte[] Input = BitConverter.GetBytes(Value);
Array.Reverse(Input);
return Input;
}
public byte[] BigEndian(Int32 Value)
{
byte[] Input = BitConverter.GetBytes(Value);
Array.Reverse(Input);
return Input;
}
public byte[] BigEndian(Int64 Value)
{
byte[] Input = BitConverter.GetBytes(Value);
Array.Reverse(Input);
return Input;
}
public byte[] BigEndian(UInt64 Value)
{
byte[] Input = BitConverter.GetBytes(Value);
Array.Reverse(Input);
return Input;
}
public UInt32 TXL2WORDS(UInt32 Txls, UInt32 BTxl)
{
return Math.Max(1, ((Txls) * (BTxl) / 8));
}
public UInt32 CALCDXT(UInt32 Width, UInt32 BTxl)
{
return (((1 << 11) + TXL2WORDS(Width, BTxl) - 1) / (TXL2WORDS(Width, BTxl)));
}
public UInt32 TXL2WORDS_4b(UInt32 Txls)
{
return Math.Max(1, ((Txls) / 16));
}
public UInt32 CALCDXT_4b(UInt32 Width)
{
return (((1 << 11) + TXL2WORDS_4b(Width) - 1) / (TXL2WORDS_4b(Width)));
}
/*
#define TXL2WORDS(txls, b_txl) MAX(1, ((txls)*(b_txl)/8))
#define CALC_DXT(width, b_txl) \
(((1 << G_TX_DXT_FRAC) + TXL2WORDS(width, b_txl) - 1) / \
TXL2WORDS(width, b_txl))
#define TXL2WORDS_4b(txls) MAX(1, ((txls)/16))
#define CALC_DXT_4b(width) \
(((1 << G_TX_DXT_FRAC) + TXL2WORDS_4b(width) - 1) / \
TXL2WORDS_4b(width))
*/
public UInt32 GCCc0w0(UInt32 saRGB0, UInt32 mRGB0, UInt32 saA0, UInt32 mA0)
{
return Convert.ToUInt32(Convert.ToUInt32((saRGB0 & 0xF) << 20) | Convert.ToUInt32((mRGB0 & 0x1F) << 15) | Convert.ToUInt32((saA0 & 0x7) << 12) | Convert.ToUInt32((mA0 & 0x7) << 9));
}
public UInt32 GCCc1w0(UInt32 saRGB1, UInt32 mRGB1)
{
return Convert.ToUInt32(Convert.ToUInt32((saRGB1 & 0xF) << 5) | Convert.ToUInt32(mRGB1 & 0x1F));
}
public UInt32 GCCc0w1(UInt32 sbRGB0, UInt32 aRGB0, UInt32 sbA0, UInt32 aA0)
{
return Convert.ToUInt32(Convert.ToUInt32((sbRGB0 & 0xF) << 28) | Convert.ToUInt32((aRGB0 & 0x7) << 15) | Convert.ToUInt32((sbA0 & 0x7) << 12) | Convert.ToUInt32((aA0 & 0x7) << 9));
}
public UInt32 GCCc1w1(UInt32 sbRGB1, UInt32 saA1, UInt32 mA1, UInt32 aRGB1, UInt32 sbA1, UInt32 aA1)
{
return Convert.ToUInt32(Convert.ToUInt32((sbRGB1 & 0xF) << 24) | Convert.ToUInt32((saA1 & 0x7) << 21) | Convert.ToUInt32((mA1 & 0x7) << 18) | Convert.ToUInt32((aRGB1 & 0x7) << 6) | Convert.ToUInt32((sbA1 & 0x7) << 3) | Convert.ToUInt32(aA1 & 0x7));
}
public byte[] gsSP1Triangle_w1(uint[] VertIndexes)
{
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(Convert.ToUInt32((((VertIndexes[2] * 2) & 0xFF) << 16) | (((VertIndexes[1] * 2) & 0xFF) << 8) | ((VertIndexes[0] * 2) & 0xFF)))
));
return memoryStream.ToArray();
}
public byte[] gsSP1Triangle(uint[] VertIndexesA)
{
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(Convert.ToUInt32(F3DEX2_OpCodes.G_TRI1 | BitConverter.ToUInt32(BigEndian(gsSP1Triangle_w1(VertIndexesA)), 0)))
));
binaryWriter.Write(
Convert.ToInt32(0)
);
return memoryStream.ToArray();
}
public byte[] gsSP2Triangles(uint[] VertIndexesA, uint[] VertIndexesB)
{
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(Convert.ToUInt32(F3DEX2_OpCodes.G_TRI2 | BitConverter.ToUInt32(BigEndian(gsSP1Triangle_w1(VertIndexesA)), 0)))
));
binaryWriter.Write(
gsSP1Triangle_w1(VertIndexesB)
);
return memoryStream.ToArray();
}
public byte[] gsSPCullDisplayList(uint StartIndex, uint EndIndex)
{
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(Convert.ToUInt32(F3DEX2_OpCodes.G_CULLDL | (( StartIndex * 2 ) & 0xFFFF) ))
));
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(((EndIndex * 2) & 0xFFFF))
));
return memoryStream.ToArray();
}
public byte[] gsSPDisplayList(uint Address)
{
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(F3DEX2_OpCodes.G_DL)
));
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(Address)
));
return memoryStream.ToArray();
}
public byte[] gsSPEndDisplayList()
{
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(F3DEX2_OpCodes.G_ENDDL)
));
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(0)
));
return memoryStream.ToArray();
}
public byte[] gsSPVertex(UInt32 Address, UInt32 Count, UInt32 Index)
{
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(Convert.ToUInt32(F3DEX2_OpCodes.G_VTX | (( Count & 0xFF) << 12 ) | ((((Count) + (Index)) & 0x7F) <<1 ) ))
));
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(Convert.ToUInt32(Address))
));
return memoryStream.ToArray();
}
public byte[] gsDPSetTile(UInt32 Format, UInt32 Size, UInt32 Line, UInt32 TMem, UInt32 Tile, UInt32 Palette, UInt32 CMT, UInt32 MaskT, UInt32 ShiftT, UInt32 CMS, UInt32 MaskS, UInt32 ShiftS)
{
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(Convert.ToUInt32(F3DEX2_OpCodes.G_SETTILE | ((Format & 0x7) << 21) | ((Size & 0x3) << 19) | ((Line & 0x1FF) << 9) | (TMem & 0x1FF)))
));
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(Convert.ToUInt32(((Tile & 0x7) << 24) | ((Palette & 0xF) << 20) | ((CMT & 0x3) << 18) | ((MaskT & 0xF) << 14) |
((ShiftT & 0xF) << 10) | ((CMS & 0x3) << 8) | ((MaskS & 0xF) << 4) | ((ShiftS & 0xF))))
));
return memoryStream.ToArray();
}
public byte[] gsSPTexture(UInt32 S, UInt32 T, UInt32 Level, UInt32 Tile, UInt32 OnFlag)
{
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(F3DEX2_OpCodes.G_TEXTURE | ((Level & 0x7) << 11) | ((Tile & 0x7) << 8) | ((OnFlag & 0x7F) << 1) )
));
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(Convert.ToUInt32((S & 0xFFFF) << 16) | (T & 0xFFFF))
));
return memoryStream.ToArray();
}
public byte[] gsDPLoadTLUTCmd(UInt32 Tile, UInt32 Count)
{
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(F3DEX2_OpCodes.G_LOADTLUT)
));
binaryWriter.Write(BigEndian(
BitConverter.GetBytes((Tile & 0x07) << 24 | (Count & 0x3FF) << 14)
));
return memoryStream.ToArray();
}
/*
*
* #define gsDPLoadTLUT_pal256(dram) \
\
gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, dram), \
gsDPTileSync(), \
gsDPSetTile(0, 0, 0, 256, \
G_TX_LOADTILE, 0 , 0, 0, 0, 0, 0, 0), \
gsDPLoadSync(), \
gsDPLoadTLUTCmd(G_TX_LOADTILE, 255), \
gsDPPipeSync()
*/
public byte[] gsDPLoadTLUT_pal256(UInt32 Palette, UInt32 DRAM)
{
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
binaryWriter.Write(gsDPSetTextureImage(F3DEX2_Parameters.G_IM_FMT_RGBA, F3DEX2_Parameters.G_IM_SIZ_16b, 1, DRAM));
binaryWriter.Write(gsDPTileSync());
binaryWriter.Write(gsDPSetTile(0, 0, 0, 256, F3DEX2_OpCodes.G_TX_LOADTILE, 0, 0, 0, 0, 0, 0, 0));
binaryWriter.Write(gsDPLoadSync());
binaryWriter.Write(gsDPLoadTLUTCmd(F3DEX2_OpCodes.G_TX_LOADTILE, 255));
binaryWriter.Write(gsDPPipeSync());
return memoryStream.ToArray();
}
public byte[] gsDPLoadTLUT_pal16(UInt32 Palette, UInt32 DRAM)
{
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
binaryWriter.Write(gsDPSetTextureImage(F3DEX2_Parameters.G_IM_FMT_RGBA, F3DEX2_Parameters.G_IM_SIZ_16b, 1, DRAM));
binaryWriter.Write(gsDPTileSync());
binaryWriter.Write(gsDPSetTile(0, 0, 0, (256 + (((Palette) & 0x0F) * 16)), F3DEX2_OpCodes.G_TX_LOADTILE, 0, 0, 0, 0, 0, 0, 0));
binaryWriter.Write(gsDPLoadSync());
binaryWriter.Write(gsDPLoadTLUTCmd(F3DEX2_OpCodes.G_TX_LOADTILE, 15));
binaryWriter.Write(gsDPPipeSync());
return memoryStream.ToArray();
}
public byte[] gsDPSetTextureLUT(UInt32 Type)
{
return gsSPSetOtherMode(F3DEX2_OpCodes.G_SETOTHERMODE_H, Convert.ToUInt32(F3DEX2_Parameters.G_MDSFT_TEXTLUT), 2, Type);
}
public byte[] gsSPSetOtherMode(UInt32 Command, UInt32 Soft, UInt32 Len, UInt32 Data)
{
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(Command | (((32 - Soft - Len) & 0xFF) << 8) | ((Len -1) & 0xFF))
));
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(Data)
));
return memoryStream.ToArray();
}
public byte[] gsDPPipeSync()
{
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(Convert.ToUInt32(F3DEX2_OpCodes.G_RDPPIPESYNC))
));
binaryWriter.Write(0);
return memoryStream.ToArray();
}
public byte[] gsDPSetRenderMode(UInt32 ModeA, UInt32 ModeB)
{
return gsSPSetOtherMode(F3DEX2_OpCodes.G_SETOTHERMODE_L, Convert.ToUInt32(F3DEX2_Parameters.G_MDSFT_RENDERMODE), 29, ModeA | ModeB);
}
public byte[] gsDPSetCombineLERP(UInt32[] GCCA, UInt32[] GCCB)
{
//UInt32 a0, UInt32 b0, UInt32 c0, UInt32 d0, UInt32 Aa0, UInt32 Ab0, UInt32 Ac0, UInt32 Ad0 ----GCCA
//UInt32 a1, UInt32 b1, UInt32 c1, UInt32 d1, UInt32 Aa1, UInt32 Ab1, UInt32 Ac1, UInt32 Ad1 ----GCCB
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(F3DEX2_OpCodes.G_SETCOMBINE | Convert.ToUInt32((GCCc0w0(GCCA[0], GCCA[2], GCCA[4], GCCA[6]) | GCCc1w0(GCCB[0], GCCB[2])) & 0xFFFFFF))
));
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(Convert.ToUInt32(GCCc0w1(GCCA[1], GCCA[3], GCCA[5], GCCA[7]) | GCCc1w1(GCCB[1], GCCB[4], GCCB[6], GCCB[3], GCCB[5], GCCB[5])))
));
return memoryStream.ToArray();
}
public byte[] gsDPSetCombineMode(UInt32[] ModeA, UInt32[] ModeB)
{
return gsDPSetCombineLERP(ModeA, ModeB);
}
public byte[] gsDPTileSync()
{
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(F3DEX2_OpCodes.G_RDPTILESYNC)
));
binaryWriter.Write(0);
return memoryStream.ToArray();
}
public byte[] gsDPLoadSync()
{
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(F3DEX2_OpCodes.G_RDPLOADSYNC)
));
binaryWriter.Write(0);
return memoryStream.ToArray();
}
public byte[] gsSPGeometryMode(UInt32 ClearMode, UInt32 SetMode)
{
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(Convert.ToUInt32(F3DEX2_OpCodes.G_GEOMETRYMODE) | (ClearMode & 0xFFFFFF) )
));
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(Convert.ToUInt32(SetMode))
));
return memoryStream.ToArray();
}
public byte[] gsSPClearGeometryMode(UInt32 ClearMode)
{
return gsSPGeometryMode(ClearMode, 0);
}
public byte[] gsSPSetGeometryMode(UInt32 SetMode)
{
return gsSPGeometryMode(0, SetMode);
}
public byte[] gsDPLoadBlock(UInt32 Tile, UInt32 ULS, UInt32 ULT, UInt32 LRS, UInt32 DXT)
{
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(Convert.ToUInt32(F3DEX2_OpCodes.G_LOADBLOCK | ((ULS & 0xFFF) << 12) | (ULT & 0xFFF)))
));
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(Convert.ToUInt32(((Tile & 0x7) << 24) | ((Math.Min(LRS, 2047) & 0xFFF) << 12) | (DXT & 0xFFF)))
));
return memoryStream.ToArray();
}
public byte[] gsDPLoadTileGeneric(UInt32 Command, UInt32 Tile, UInt32 ULS, UInt32 ULT, UInt32 LRS, UInt32 LRT)
{
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(Command | ((ULS & 0xFFF) << 12) | ((ULT & 0xFFF) << 12))
));
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(((Tile & 0x7) << 24) | ((LRS & 0xFFF) << 12) | (LRT & 0xFFF))
));
return memoryStream.ToArray();
}
public byte[] gsDPSetTileSize(UInt32 Tile, UInt32 ULS, UInt32 ULT, UInt32 LRS, UInt32 LRT)
{
return gsDPLoadTileGeneric(F3DEX2_OpCodes.G_SETTILESIZE, Tile, ULS, ULT, LRS, LRT);
}
public byte[] gsSetImage(UInt32 Command, UInt32 Format, UInt32 Size, uint Width, UInt32 Address)
{
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(Convert.ToUInt32(Command | ((Format & 0x7) << 21) | ((Size & 0x3) << 19) | ((Width - 1) & 0xFFF)))
));
binaryWriter.Write(BigEndian(
BitConverter.GetBytes(Address)
));
return memoryStream.ToArray();
}
public byte[] gsDPSetColorImage(UInt32 Format, UInt32 Size, uint Width, UInt32 Address)
{
return gsSetImage(F3DEX2_OpCodes.G_SETCIMG, Format, Size, Width, Address);
}
public byte[] gsDPSetTextureImage(UInt32 Format, UInt32 Size, uint Width, UInt32 Address)
{
return gsSetImage(F3DEX2_OpCodes.G_SETTIMG, Format, Size, Width, Address);
}
public byte[] gsNinSetupTileDescription(UInt32 TextureFormat, UInt32 Size, uint Width, uint Height, uint TextureMemory, uint Tile, uint CS, uint MS, uint SS, uint CT, uint MT, uint ST)
{
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
binaryWriter.Write(
gsDPTileSync()
);
binaryWriter.Write(
gsDPSetTile(TextureFormat, Size, ((Width * F3DEX2_Parameters.G_IM_ArrayLineBytes[(int)Size]) + 7) >> 3, TextureMemory, Tile, 0, CT, MT, ST, CS, MS, SS)
);
binaryWriter.Write(
gsDPSetTileSize(Tile, 0, 0, (Width - 1) << (int)F3DEX2_Parameters.G_TEXTURE_IMAGE_FRAC, (Height - 1) << (int)F3DEX2_Parameters.G_TEXTURE_IMAGE_FRAC)
);
return memoryStream.ToArray();
}
public byte[] gsNinLoadTextureImage(UInt32 TextureAddress, UInt32 TextureFormat, UInt32 Size, uint Width, uint Height, uint TextureMemory, uint Tile)
{
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
UInt32[] ByteSize = { 0, 1, 2, 4 };
binaryWriter.Write(
gsDPSetTextureImage(TextureFormat, Size, 1, TextureAddress)
);
binaryWriter.Write(
gsDPTileSync()
); ;
binaryWriter.Write(
gsDPSetTile(TextureFormat, Size, 0, TextureMemory, Tile, 0, 0, 0, 0, 0, 0, 0)
);
binaryWriter.Write(
gsDPLoadSync()
); ;
binaryWriter.Write(
gsDPLoadBlock(Tile, 0, 0, ((Width * Height) - 1), CALCDXT(Width, ByteSize[Size]))
);
return memoryStream.ToArray();
}
public byte[] gsDPLoadTextureBlock(UInt32 TextureAddress, UInt32 TextureFormat, UInt32 Size, uint Width, uint Height, uint PaletteBanks, uint CS, uint MS, uint SS, uint CT, uint MT, uint ST)
{
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
UInt32[] INCRSize = { 3, 1, 0, 0 };
Int32[] ShiftSize = { 2, 1, 0, 0 };
UInt32[] LoadBlockSize = { 2, 2, 2, 4 };
UInt32[] ByteSize = { 0, 1, 2, 4 };
binaryWriter.Write(gsDPSetTextureImage(TextureFormat, LoadBlockSize[Size], 1, TextureAddress));
binaryWriter.Write(gsDPSetTile(TextureFormat, LoadBlockSize[Size], 0, 0, 7, 0, CT, MT, ST, CS, MS, SS));
binaryWriter.Write(gsDPLoadSync());
binaryWriter.Write(gsDPLoadBlock(7, 0, 0, (((Width * Height) + INCRSize[Size]) >> ShiftSize[Size]) - 1, CALCDXT(Width, ByteSize[Size])));
binaryWriter.Write(gsDPPipeSync());
binaryWriter.Write(gsDPSetTile(TextureFormat, Size, ((((Width) * ByteSize[Size]) + 7) >> 3), 0, 0, PaletteBanks, CT, MT, ST, CS, MS, SS));
binaryWriter.Write(gsDPSetTileSize(0, 0, 0,
((Width) - 1) << Convert.ToInt32(F3DEX2_Parameters.G_TEXTURE_IMAGE_FRAC),
((Height) - 1) << Convert.ToInt32(F3DEX2_Parameters.G_TEXTURE_IMAGE_FRAC)));
return memoryStream.ToArray();
}
public byte[] gsDPLoadTextureBlock_4b(UInt32 TextureAddress, UInt32 TextureFormat, uint Width, uint Height, uint PaletteBanks, uint CS, uint MS, uint SS, uint CT, uint MT, uint ST)
{
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
UInt32[] INCRSize = { 3, 1, 0, 0 };
Int32[] ShiftSize = { 2, 1, 0, 0 };
UInt32[] LoadBlockSize = { 2, 2, 2, 4 };
UInt32[] ByteSize = { 0, 1, 2, 4 };
binaryWriter.Write(gsDPSetTextureImage(TextureFormat, F3DEX2_Parameters.G_IM_SIZ_16b, 1, TextureAddress));
binaryWriter.Write(gsDPSetTile(TextureFormat, F3DEX2_Parameters.G_IM_SIZ_16b, 0, 0, 7, 0, CT, MT, ST, CS, MS, SS));
binaryWriter.Write(gsDPLoadSync());
binaryWriter.Write(gsDPLoadBlock(7, 0, 0, (((Width * Height) + 3) >> 2) - 1, CALCDXT_4b(Width)));
binaryWriter.Write(gsDPPipeSync());
binaryWriter.Write(gsDPSetTile(TextureFormat, F3DEX2_Parameters.G_IM_SIZ_4b, ((((Width) >> 1) + 7) >> 3),
0, F3DEX2_OpCodes.G_TX_RENDERTILE, PaletteBanks, CT, MT, ST, CS, MS, SS));
binaryWriter.Write(gsDPSetTileSize(F3DEX2_OpCodes.G_TX_RENDERTILE, 0, 0,
((Width) - 1) << Convert.ToInt32(F3DEX2_Parameters.G_TEXTURE_IMAGE_FRAC),
((Height) - 1) << Convert.ToInt32(F3DEX2_Parameters.G_TEXTURE_IMAGE_FRAC)));
return memoryStream.ToArray();
}
public byte[] gsDPLoadTile(UInt32 Tile, UInt32 ULS, UInt32 ULT, UInt32 LRS, UInt32 LRT)
{
return gsDPLoadTileGeneric(F3DEX2_OpCodes.G_LOADTILE, Tile, ULS, ULT, LRS, LRT);
}
public byte[] gsDPLoadTextureTile_4b(UInt32 TextureAddress, UInt32 TextureFormat, UInt32 TWidth, UInt32 THeight, UInt32 ULS, UInt32 ULT, UInt32 LRS, UInt32 LRT, UInt32 PAL, UInt32 CMS, UInt32 CMT, UInt32 MaskS, UInt32 MaskT, UInt32 ShiftS, UInt32 ShiftT)
{
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
UInt32[] INCRSize = { 3, 1, 0, 0 };
Int32[] ShiftSize = { 2, 1, 0, 0 };
UInt32[] LoadBlockSize = { 2, 2, 2, 4 };
UInt32[] ByteSize = { 0, 1, 2, 4 };
binaryWriter.Write(gsDPSetTextureImage(TextureFormat, F3DEX2_Parameters.G_IM_SIZ_8b, ((TWidth) >> 1), TextureAddress));
binaryWriter.Write(gsDPSetTile(TextureFormat, F3DEX2_Parameters.G_IM_SIZ_8b,
(((((LRS) - (ULS) + 1) >> 1) + 7) >> 3), 0, F3DEX2_OpCodes.G_TX_LOADTILE, 0, CMT, MaskT, ShiftT, CMS, MaskS, ShiftS));
binaryWriter.Write(gsDPLoadSync());
binaryWriter.Write(gsDPLoadTile(F3DEX2_OpCodes.G_TX_LOADTILE,
(ULS << 1),
(ULT << 2),
(LRS << 1),
(LRT << 2)));
binaryWriter.Write(gsDPPipeSync());
binaryWriter.Write(gsDPSetTile(TextureFormat, F3DEX2_Parameters.G_IM_SIZ_4b, (((((LRS) - (ULS) + 1) >> 1) + 7) >> 3), 0,
F3DEX2_OpCodes.G_TX_RENDERTILE, PAL, CMT, MaskT, ShiftT, CMS, MaskS, ShiftS));
binaryWriter.Write(gsDPSetTileSize(F3DEX2_OpCodes.G_TX_RENDERTILE,
(ULS << 2),
(ULT << 2),
(LRS << 2),
(LRT << 2)));
return memoryStream.ToArray();
}
/*
#define gDPLoadTextureBlock(pkt, timg, fmt, siz, width, height, \
pal, cms, cmt, masks, maskt, shifts, shiftt) \
{ \
gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \
gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, \
0 , cmt, maskt, shiftt, cms, masks, shifts); \
gDPLoadSync(pkt); \
gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \
(((width)*(height) + siz##_INCR) >> siz##_SHIFT) -1, \
CALC_DXT(width, siz##_BYTES)); \
gDPPipeSync(pkt); \
gDPSetTile(pkt, fmt, siz, \
(((width) * siz##_LINE_BYTES)+7)>>3, 0, \
G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \
shifts); \
gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \
((width)-1) << G_TEXTURE_IMAGE_FRAC, \
((height)-1) << G_TEXTURE_IMAGE_FRAC) \
}
*/
}
}