-
Notifications
You must be signed in to change notification settings - Fork 5
/
GSLocalMemory.h
921 lines (730 loc) · 28.4 KB
/
GSLocalMemory.h
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
/*
* Copyright (C) 2007-2009 Gabest
* http://www.gabest.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#pragma once
#include "GS.h"
#include "GSTables.h"
#include "GSVector.h"
#include "GSBlock.h"
#include "GSClut.h"
#ifndef _CX11_
#include "GSThread.h"
#endif
class GSOffset : public GSAlignedClass<32>
{
public:
__aligned(struct, 32) Block
{
short row[256]; // yn (n = 0 8 16 ...)
short* col; // blockOffset*
};
__aligned(struct, 32) Pixel
{
int row[4096]; // yn (n = 0 1 2 ...) NOTE: this wraps around above 2048, only transfers should address the upper half (dark cloud 2 inventing)
int* col[8]; // rowOffset*
};
union {uint32 hash; struct {uint32 bp:14, bw:6, psm:6;};};
Block block;
Pixel pixel;
GSOffset(uint32 bp, uint32 bw, uint32 psm);
virtual ~GSOffset();
enum {EOP = 0xffffffff};
uint32* GetPages(const GSVector4i& rect, uint32* pages = NULL, GSVector4i* bbox = NULL);
GSVector4i* GetPagesAsBits(const GSVector4i& rect, GSVector4i* pages = NULL, GSVector4i* bbox = NULL); // free returned value with _aligned_free
};
struct GSPixelOffset
{
// 16 bit offsets (m_vm16[...])
GSVector2i row[2048]; // f yn | z yn
GSVector2i col[2048]; // f xn | z xn
uint32 hash;
uint32 fbp, zbp, fpsm, zpsm, bw;
};
struct GSPixelOffset4
{
// 16 bit offsets (m_vm16[...])
GSVector2i row[2048]; // f yn | z yn (n = 0 1 2 ...)
GSVector2i col[512]; // f xn | z xn (n = 0 4 8 ...)
uint32 hash;
uint32 fbp, zbp, fpsm, zpsm, bw;
};
class GSLocalMemory : public GSAlignedClass<32>
{
public:
typedef uint32 (*pixelAddress)(int x, int y, uint32 bp, uint32 bw);
typedef void (GSLocalMemory::*writePixel)(int x, int y, uint32 c, uint32 bp, uint32 bw);
typedef void (GSLocalMemory::*writeFrame)(int x, int y, uint32 c, uint32 bp, uint32 bw);
typedef uint32 (GSLocalMemory::*readPixel)(int x, int y, uint32 bp, uint32 bw) const;
typedef uint32 (GSLocalMemory::*readTexel)(int x, int y, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA) const;
typedef void (GSLocalMemory::*writePixelAddr)(uint32 addr, uint32 c);
typedef void (GSLocalMemory::*writeFrameAddr)(uint32 addr, uint32 c);
typedef uint32 (GSLocalMemory::*readPixelAddr)(uint32 addr) const;
typedef uint32 (GSLocalMemory::*readTexelAddr)(uint32 addr, const GIFRegTEXA& TEXA) const;
typedef void (GSLocalMemory::*writeImage)(int& tx, int& ty, const uint8* src, int len, GIFRegBITBLTBUF& BITBLTBUF, GIFRegTRXPOS& TRXPOS, GIFRegTRXREG& TRXREG);
typedef void (GSLocalMemory::*readImage)(int& tx, int& ty, uint8* dst, int len, GIFRegBITBLTBUF& BITBLTBUF, GIFRegTRXPOS& TRXPOS, GIFRegTRXREG& TRXREG) const;
typedef void (GSLocalMemory::*readTexture)(const GSOffset* RESTRICT off, const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA);
typedef void (GSLocalMemory::*readTextureBlock)(uint32 bp, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA) const;
__aligned(struct, 128) psm_t
{
pixelAddress pa, bn;
readPixel rp;
readPixelAddr rpa;
writePixel wp;
writePixelAddr wpa;
readTexel rt;
readTexelAddr rta;
writeFrameAddr wfa;
writeImage wi;
readImage ri;
readTexture rtx, rtxP;
readTextureBlock rtxb, rtxbP;
uint16 bpp, trbpp, pal, fmt;
GSVector2i bs, pgs;
int* rowOffset[8];
short* blockOffset;
uint8 msk;
};
static psm_t m_psm[64];
static const int m_vmsize = 1024 * 1024 * 4;
uint8* m_vm8;
uint16* m_vm16;
uint32* m_vm32;
GSClut m_clut;
protected:
static uint32 pageOffset32[32][32][64];
static uint32 pageOffset32Z[32][32][64];
static uint32 pageOffset16[32][64][64];
static uint32 pageOffset16S[32][64][64];
static uint32 pageOffset16Z[32][64][64];
static uint32 pageOffset16SZ[32][64][64];
static uint32 pageOffset8[32][64][128];
static uint32 pageOffset4[32][128][128];
static int rowOffset32[4096];
static int rowOffset32Z[4096];
static int rowOffset16[4096];
static int rowOffset16S[4096];
static int rowOffset16Z[4096];
static int rowOffset16SZ[4096];
static int rowOffset8[2][4096];
static int rowOffset4[2][4096];
static short blockOffset32[256];
static short blockOffset32Z[256];
static short blockOffset16[256];
static short blockOffset16S[256];
static short blockOffset16Z[256];
static short blockOffset16SZ[256];
static short blockOffset8[256];
static short blockOffset4[256];
__forceinline static uint32 Expand24To32(uint32 c, const GIFRegTEXA& TEXA)
{
return (((!TEXA.AEM | (c & 0xffffff)) ? TEXA.TA0 : 0) << 24) | (c & 0xffffff);
}
__forceinline static uint32 Expand16To32(uint16 c, const GIFRegTEXA& TEXA)
{
return (((c & 0x8000) ? TEXA.TA1 : (!TEXA.AEM | c) ? TEXA.TA0 : 0) << 24) | ((c & 0x7c00) << 9) | ((c & 0x03e0) << 6) | ((c & 0x001f) << 3);
}
// TODO
friend class GSClut;
//
hash_map<uint32, GSOffset*> m_omap;
hash_map<uint32, GSPixelOffset*> m_pomap;
hash_map<uint32, GSPixelOffset4*> m_po4map;
hash_map<uint64, vector<GSVector2i>*> m_p2tmap;
public:
GSLocalMemory();
virtual ~GSLocalMemory();
GSOffset* GetOffset(uint32 bp, uint32 bw, uint32 psm);
GSPixelOffset* GetPixelOffset(const GIFRegFRAME& FRAME, const GIFRegZBUF& ZBUF);
GSPixelOffset4* GetPixelOffset4(const GIFRegFRAME& FRAME, const GIFRegZBUF& ZBUF);
vector<GSVector2i>* GetPage2TileMap(const GIFRegTEX0& TEX0);
// address
static uint32 BlockNumber32(int x, int y, uint32 bp, uint32 bw)
{
return bp + (y & ~0x1f) * bw + ((x >> 1) & ~0x1f) + blockTable32[(y >> 3) & 3][(x >> 3) & 7];
}
static uint32 BlockNumber16(int x, int y, uint32 bp, uint32 bw)
{
return bp + ((y >> 1) & ~0x1f) * bw + ((x >> 1) & ~0x1f) + blockTable16[(y >> 3) & 7][(x >> 4) & 3];
}
static uint32 BlockNumber16S(int x, int y, uint32 bp, uint32 bw)
{
return bp + ((y >> 1) & ~0x1f) * bw + ((x >> 1) & ~0x1f) + blockTable16S[(y >> 3) & 7][(x >> 4) & 3];
}
static uint32 BlockNumber8(int x, int y, uint32 bp, uint32 bw)
{
// ASSERT((bw & 1) == 0); // allowed for mipmap levels
return bp + ((y >> 1) & ~0x1f) * (bw >> 1) + ((x >> 2) & ~0x1f) + blockTable8[(y >> 4) & 3][(x >> 4) & 7];
}
static uint32 BlockNumber4(int x, int y, uint32 bp, uint32 bw)
{
// ASSERT((bw & 1) == 0); // allowed for mipmap levels
return bp + ((y >> 2) & ~0x1f) * (bw >> 1) + ((x >> 2) & ~0x1f) + blockTable4[(y >> 4) & 7][(x >> 5) & 3];
}
static uint32 BlockNumber32Z(int x, int y, uint32 bp, uint32 bw)
{
return bp + (y & ~0x1f) * bw + ((x >> 1) & ~0x1f) + blockTable32Z[(y >> 3) & 3][(x >> 3) & 7];
}
static uint32 BlockNumber16Z(int x, int y, uint32 bp, uint32 bw)
{
return bp + ((y >> 1) & ~0x1f) * bw + ((x >> 1) & ~0x1f) + blockTable16Z[(y >> 3) & 7][(x >> 4) & 3];
}
static uint32 BlockNumber16SZ(int x, int y, uint32 bp, uint32 bw)
{
return bp + ((y >> 1) & ~0x1f) * bw + ((x >> 1) & ~0x1f) + blockTable16SZ[(y >> 3) & 7][(x >> 4) & 3];
}
uint8* BlockPtr(uint32 bp) const
{
ASSERT(bp < 16384);
return &m_vm8[bp << 8];
}
uint8* BlockPtr32(int x, int y, uint32 bp, uint32 bw) const
{
return &m_vm8[BlockNumber32(x, y, bp, bw) << 8];
}
uint8* BlockPtr16(int x, int y, uint32 bp, uint32 bw) const
{
return &m_vm8[BlockNumber16(x, y, bp, bw) << 8];
}
uint8* BlockPtr16S(int x, int y, uint32 bp, uint32 bw) const
{
return &m_vm8[BlockNumber16S(x, y, bp, bw) << 8];
}
uint8* BlockPtr8(int x, int y, uint32 bp, uint32 bw) const
{
return &m_vm8[BlockNumber8(x, y, bp, bw) << 8];
}
uint8* BlockPtr4(int x, int y, uint32 bp, uint32 bw) const
{
return &m_vm8[BlockNumber4(x, y, bp, bw) << 8];
}
uint8* BlockPtr32Z(int x, int y, uint32 bp, uint32 bw) const
{
return &m_vm8[BlockNumber32Z(x, y, bp, bw) << 8];
}
uint8* BlockPtr16Z(int x, int y, uint32 bp, uint32 bw) const
{
return &m_vm8[BlockNumber16Z(x, y, bp, bw) << 8];
}
uint8* BlockPtr16SZ(int x, int y, uint32 bp, uint32 bw) const
{
return &m_vm8[BlockNumber16SZ(x, y, bp, bw) << 8];
}
static uint32 PixelAddressOrg32(int x, int y, uint32 bp, uint32 bw)
{
return (BlockNumber32(x, y, bp, bw) << 6) + columnTable32[y & 7][x & 7];
}
static uint32 PixelAddressOrg16(int x, int y, uint32 bp, uint32 bw)
{
return (BlockNumber16(x, y, bp, bw) << 7) + columnTable16[y & 7][x & 15];
}
static uint32 PixelAddressOrg16S(int x, int y, uint32 bp, uint32 bw)
{
return (BlockNumber16S(x, y, bp, bw) << 7) + columnTable16[y & 7][x & 15];
}
static uint32 PixelAddressOrg8(int x, int y, uint32 bp, uint32 bw)
{
return (BlockNumber8(x, y, bp, bw) << 8) + columnTable8[y & 15][x & 15];
}
static uint32 PixelAddressOrg4(int x, int y, uint32 bp, uint32 bw)
{
return (BlockNumber4(x, y, bp, bw) << 9) + columnTable4[y & 15][x & 31];
}
static uint32 PixelAddressOrg32Z(int x, int y, uint32 bp, uint32 bw)
{
return (BlockNumber32Z(x, y, bp, bw) << 6) + columnTable32[y & 7][x & 7];
}
static uint32 PixelAddressOrg16Z(int x, int y, uint32 bp, uint32 bw)
{
return (BlockNumber16Z(x, y, bp, bw) << 7) + columnTable16[y & 7][x & 15];
}
static uint32 PixelAddressOrg16SZ(int x, int y, uint32 bp, uint32 bw)
{
return (BlockNumber16SZ(x, y, bp, bw) << 7) + columnTable16[y & 7][x & 15];
}
static __forceinline uint32 PixelAddress32(int x, int y, uint32 bp, uint32 bw)
{
uint32 page = (bp >> 5) + (y >> 5) * bw + (x >> 6);
uint32 word = (page << 11) + pageOffset32[bp & 0x1f][y & 0x1f][x & 0x3f];
return word;
}
static __forceinline uint32 PixelAddress16(int x, int y, uint32 bp, uint32 bw)
{
uint32 page = (bp >> 5) + (y >> 6) * bw + (x >> 6);
uint32 word = (page << 12) + pageOffset16[bp & 0x1f][y & 0x3f][x & 0x3f];
return word;
}
static __forceinline uint32 PixelAddress16S(int x, int y, uint32 bp, uint32 bw)
{
uint32 page = (bp >> 5) + (y >> 6) * bw + (x >> 6);
uint32 word = (page << 12) + pageOffset16S[bp & 0x1f][y & 0x3f][x & 0x3f];
return word;
}
static __forceinline uint32 PixelAddress8(int x, int y, uint32 bp, uint32 bw)
{
// ASSERT((bw & 1) == 0); // allowed for mipmap levels
uint32 page = (bp >> 5) + (y >> 6) * (bw >> 1) + (x >> 7);
uint32 word = (page << 13) + pageOffset8[bp & 0x1f][y & 0x3f][x & 0x7f];
return word;
}
static __forceinline uint32 PixelAddress4(int x, int y, uint32 bp, uint32 bw)
{
// ASSERT((bw & 1) == 0); // allowed for mipmap levels
uint32 page = (bp >> 5) + (y >> 7) * (bw >> 1) + (x >> 7);
uint32 word = (page << 14) + pageOffset4[bp & 0x1f][y & 0x7f][x & 0x7f];
return word;
}
static __forceinline uint32 PixelAddress32Z(int x, int y, uint32 bp, uint32 bw)
{
uint32 page = (bp >> 5) + (y >> 5) * bw + (x >> 6);
uint32 word = (page << 11) + pageOffset32Z[bp & 0x1f][y & 0x1f][x & 0x3f];
return word;
}
static __forceinline uint32 PixelAddress16Z(int x, int y, uint32 bp, uint32 bw)
{
uint32 page = (bp >> 5) + (y >> 6) * bw + (x >> 6);
uint32 word = (page << 12) + pageOffset16Z[bp & 0x1f][y & 0x3f][x & 0x3f];
return word;
}
static __forceinline uint32 PixelAddress16SZ(int x, int y, uint32 bp, uint32 bw)
{
uint32 page = (bp >> 5) + (y >> 6) * bw + (x >> 6);
uint32 word = (page << 12) + pageOffset16SZ[bp & 0x1f][y & 0x3f][x & 0x3f];
return word;
}
// pixel R/W
__forceinline uint32 ReadPixel32(uint32 addr) const
{
return m_vm32[addr];
}
__forceinline uint32 ReadPixel24(uint32 addr) const
{
return m_vm32[addr] & 0x00ffffff;
}
__forceinline uint32 ReadPixel16(uint32 addr) const
{
return (uint32)m_vm16[addr];
}
__forceinline uint32 ReadPixel8(uint32 addr) const
{
return (uint32)m_vm8[addr];
}
__forceinline uint32 ReadPixel4(uint32 addr) const
{
return (m_vm8[addr >> 1] >> ((addr & 1) << 2)) & 0x0f;
}
__forceinline uint32 ReadPixel8H(uint32 addr) const
{
return m_vm32[addr] >> 24;
}
__forceinline uint32 ReadPixel4HL(uint32 addr) const
{
return (m_vm32[addr] >> 24) & 0x0f;
}
__forceinline uint32 ReadPixel4HH(uint32 addr) const
{
return (m_vm32[addr] >> 28) & 0x0f;
}
__forceinline uint32 ReadFrame24(uint32 addr) const
{
return 0x80000000 | (m_vm32[addr] & 0xffffff);
}
__forceinline uint32 ReadFrame16(uint32 addr) const
{
uint32 c = (uint32)m_vm16[addr];
return ((c & 0x8000) << 16) | ((c & 0x7c00) << 9) | ((c & 0x03e0) << 6) | ((c & 0x001f) << 3);
}
__forceinline uint32 ReadPixel32(int x, int y, uint32 bp, uint32 bw) const
{
return ReadPixel32(PixelAddress32(x, y, bp, bw));
}
__forceinline uint32 ReadPixel24(int x, int y, uint32 bp, uint32 bw) const
{
return ReadPixel24(PixelAddress32(x, y, bp, bw));
}
__forceinline uint32 ReadPixel16(int x, int y, uint32 bp, uint32 bw) const
{
return ReadPixel16(PixelAddress16(x, y, bp, bw));
}
__forceinline uint32 ReadPixel16S(int x, int y, uint32 bp, uint32 bw) const
{
return ReadPixel16(PixelAddress16S(x, y, bp, bw));
}
__forceinline uint32 ReadPixel8(int x, int y, uint32 bp, uint32 bw) const
{
return ReadPixel8(PixelAddress8(x, y, bp, bw));
}
__forceinline uint32 ReadPixel4(int x, int y, uint32 bp, uint32 bw) const
{
return ReadPixel4(PixelAddress4(x, y, bp, bw));
}
__forceinline uint32 ReadPixel8H(int x, int y, uint32 bp, uint32 bw) const
{
return ReadPixel8H(PixelAddress32(x, y, bp, bw));
}
__forceinline uint32 ReadPixel4HL(int x, int y, uint32 bp, uint32 bw) const
{
return ReadPixel4HL(PixelAddress32(x, y, bp, bw));
}
__forceinline uint32 ReadPixel4HH(int x, int y, uint32 bp, uint32 bw) const
{
return ReadPixel4HH(PixelAddress32(x, y, bp, bw));
}
__forceinline uint32 ReadPixel32Z(int x, int y, uint32 bp, uint32 bw) const
{
return ReadPixel32(PixelAddress32Z(x, y, bp, bw));
}
__forceinline uint32 ReadPixel24Z(int x, int y, uint32 bp, uint32 bw) const
{
return ReadPixel24(PixelAddress32Z(x, y, bp, bw));
}
__forceinline uint32 ReadPixel16Z(int x, int y, uint32 bp, uint32 bw) const
{
return ReadPixel16(PixelAddress16Z(x, y, bp, bw));
}
__forceinline uint32 ReadPixel16SZ(int x, int y, uint32 bp, uint32 bw) const
{
return ReadPixel16(PixelAddress16SZ(x, y, bp, bw));
}
__forceinline uint32 ReadFrame24(int x, int y, uint32 bp, uint32 bw) const
{
return ReadFrame24(PixelAddress32(x, y, bp, bw));
}
__forceinline uint32 ReadFrame16(int x, int y, uint32 bp, uint32 bw) const
{
return ReadFrame16(PixelAddress16(x, y, bp, bw));
}
__forceinline uint32 ReadFrame16S(int x, int y, uint32 bp, uint32 bw) const
{
return ReadFrame16(PixelAddress16S(x, y, bp, bw));
}
__forceinline uint32 ReadFrame24Z(int x, int y, uint32 bp, uint32 bw) const
{
return ReadFrame24(PixelAddress32Z(x, y, bp, bw));
}
__forceinline uint32 ReadFrame16Z(int x, int y, uint32 bp, uint32 bw) const
{
return ReadFrame16(PixelAddress16Z(x, y, bp, bw));
}
__forceinline uint32 ReadFrame16SZ(int x, int y, uint32 bp, uint32 bw) const
{
return ReadFrame16(PixelAddress16SZ(x, y, bp, bw));
}
__forceinline void WritePixel32(uint32 addr, uint32 c)
{
m_vm32[addr] = c;
}
__forceinline void WritePixel24(uint32 addr, uint32 c)
{
m_vm32[addr] = (m_vm32[addr] & 0xff000000) | (c & 0x00ffffff);
}
__forceinline void WritePixel16(uint32 addr, uint32 c)
{
m_vm16[addr] = (uint16)c;
}
__forceinline void WritePixel8(uint32 addr, uint32 c)
{
m_vm8[addr] = (uint8)c;
}
__forceinline void WritePixel4(uint32 addr, uint32 c)
{
int shift = (addr & 1) << 2; addr >>= 1;
m_vm8[addr] = (uint8)((m_vm8[addr] & (0xf0 >> shift)) | ((c & 0x0f) << shift));
}
__forceinline void WritePixel8H(uint32 addr, uint32 c)
{
m_vm32[addr] = (m_vm32[addr] & 0x00ffffff) | (c << 24);
}
__forceinline void WritePixel4HL(uint32 addr, uint32 c)
{
m_vm32[addr] = (m_vm32[addr] & 0xf0ffffff) | ((c & 0x0f) << 24);
}
__forceinline void WritePixel4HH(uint32 addr, uint32 c)
{
m_vm32[addr] = (m_vm32[addr] & 0x0fffffff) | ((c & 0x0f) << 28);
}
__forceinline void WriteFrame16(uint32 addr, uint32 c)
{
uint32 rb = c & 0x00f800f8;
uint32 ga = c & 0x8000f800;
WritePixel16(addr, (ga >> 16) | (rb >> 9) | (ga >> 6) | (rb >> 3));
}
__forceinline void WritePixel32(int x, int y, uint32 c, uint32 bp, uint32 bw)
{
WritePixel32(PixelAddress32(x, y, bp, bw), c);
}
__forceinline void WritePixel24(int x, int y, uint32 c, uint32 bp, uint32 bw)
{
WritePixel24(PixelAddress32(x, y, bp, bw), c);
}
__forceinline void WritePixel16(int x, int y, uint32 c, uint32 bp, uint32 bw)
{
WritePixel16(PixelAddress16(x, y, bp, bw), c);
}
__forceinline void WritePixel16S(int x, int y, uint32 c, uint32 bp, uint32 bw)
{
WritePixel16(PixelAddress16S(x, y, bp, bw), c);
}
__forceinline void WritePixel8(int x, int y, uint32 c, uint32 bp, uint32 bw)
{
WritePixel8(PixelAddress8(x, y, bp, bw), c);
}
__forceinline void WritePixel4(int x, int y, uint32 c, uint32 bp, uint32 bw)
{
WritePixel4(PixelAddress4(x, y, bp, bw), c);
}
__forceinline void WritePixel8H(int x, int y, uint32 c, uint32 bp, uint32 bw)
{
WritePixel8H(PixelAddress32(x, y, bp, bw), c);
}
__forceinline void WritePixel4HL(int x, int y, uint32 c, uint32 bp, uint32 bw)
{
WritePixel4HL(PixelAddress32(x, y, bp, bw), c);
}
__forceinline void WritePixel4HH(int x, int y, uint32 c, uint32 bp, uint32 bw)
{
WritePixel4HH(PixelAddress32(x, y, bp, bw), c);
}
__forceinline void WritePixel32Z(int x, int y, uint32 c, uint32 bp, uint32 bw)
{
WritePixel32(PixelAddress32Z(x, y, bp, bw), c);
}
__forceinline void WritePixel24Z(int x, int y, uint32 c, uint32 bp, uint32 bw)
{
WritePixel24(PixelAddress32Z(x, y, bp, bw), c);
}
__forceinline void WritePixel16Z(int x, int y, uint32 c, uint32 bp, uint32 bw)
{
WritePixel16(PixelAddress16Z(x, y, bp, bw), c);
}
__forceinline void WritePixel16SZ(int x, int y, uint32 c, uint32 bp, uint32 bw)
{
WritePixel16(PixelAddress16SZ(x, y, bp, bw), c);
}
__forceinline void WriteFrame16(int x, int y, uint32 c, uint32 bp, uint32 bw)
{
WriteFrame16(PixelAddress16(x, y, bp, bw), c);
}
__forceinline void WriteFrame16S(int x, int y, uint32 c, uint32 bp, uint32 bw)
{
WriteFrame16(PixelAddress16S(x, y, bp, bw), c);
}
__forceinline void WriteFrame16Z(int x, int y, uint32 c, uint32 bp, uint32 bw)
{
WriteFrame16(PixelAddress16Z(x, y, bp, bw), c);
}
__forceinline void WriteFrame16SZ(int x, int y, uint32 c, uint32 bp, uint32 bw)
{
WriteFrame16(PixelAddress16SZ(x, y, bp, bw), c);
}
__forceinline void WritePixel32(uint8* RESTRICT src, uint32 pitch, GSOffset* off, const GSVector4i& r)
{
src -= r.left * sizeof(uint32);
for(int y = r.top; y < r.bottom; y++, src += pitch)
{
uint32* RESTRICT s = (uint32*)src;
uint32* RESTRICT d = &m_vm32[off->pixel.row[y]];
int* RESTRICT col = off->pixel.col[0];
for(int x = r.left; x < r.right; x++)
{
d[col[x]] = s[x];
}
}
}
__forceinline void WritePixel24(uint8* RESTRICT src, uint32 pitch, GSOffset* off, const GSVector4i& r)
{
src -= r.left * sizeof(uint32);
for(int y = r.top; y < r.bottom; y++, src += pitch)
{
uint32* RESTRICT s = (uint32*)src;
uint32* RESTRICT d = &m_vm32[off->pixel.row[y]];
int* RESTRICT col = off->pixel.col[0];
for(int x = r.left; x < r.right; x++)
{
d[col[x]] = (d[col[x]] & 0xff000000) | (s[x] & 0x00ffffff);
}
}
}
__forceinline void WritePixel16(uint8* RESTRICT src, uint32 pitch, GSOffset* off, const GSVector4i& r)
{
src -= r.left * sizeof(uint16);
for(int y = r.top; y < r.bottom; y++, src += pitch)
{
uint16* RESTRICT s = (uint16*)src;
uint16* RESTRICT d = &m_vm16[off->pixel.row[y]];
int* RESTRICT col = off->pixel.col[0];
for(int x = r.left; x < r.right; x++)
{
d[col[x]] = s[x];
}
}
}
__forceinline void WriteFrame16(uint8* RESTRICT src, uint32 pitch, GSOffset* off, const GSVector4i& r)
{
src -= r.left * sizeof(uint32);
for(int y = r.top; y < r.bottom; y++, src += pitch)
{
uint32* RESTRICT s = (uint32*)src;
uint16* RESTRICT d = &m_vm16[off->pixel.row[y]];
int* RESTRICT col = off->pixel.col[0];
for(int x = r.left; x < r.right; x++)
{
uint32 rb = s[x] & 0x00f800f8;
uint32 ga = s[x] & 0x8000f800;
d[col[x]] = (uint16)((ga >> 16) | (rb >> 9) | (ga >> 6) | (rb >> 3));
}
}
}
__forceinline uint32 ReadTexel32(uint32 addr, const GIFRegTEXA& TEXA) const
{
return m_vm32[addr];
}
__forceinline uint32 ReadTexel24(uint32 addr, const GIFRegTEXA& TEXA) const
{
return Expand24To32(m_vm32[addr], TEXA);
}
__forceinline uint32 ReadTexel16(uint32 addr, const GIFRegTEXA& TEXA) const
{
return Expand16To32(m_vm16[addr], TEXA);
}
__forceinline uint32 ReadTexel8(uint32 addr, const GIFRegTEXA& TEXA) const
{
return m_clut[ReadPixel8(addr)];
}
__forceinline uint32 ReadTexel4(uint32 addr, const GIFRegTEXA& TEXA) const
{
return m_clut[ReadPixel4(addr)];
}
__forceinline uint32 ReadTexel8H(uint32 addr, const GIFRegTEXA& TEXA) const
{
return m_clut[ReadPixel8H(addr)];
}
__forceinline uint32 ReadTexel4HL(uint32 addr, const GIFRegTEXA& TEXA) const
{
return m_clut[ReadPixel4HL(addr)];
}
__forceinline uint32 ReadTexel4HH(uint32 addr, const GIFRegTEXA& TEXA) const
{
return m_clut[ReadPixel4HH(addr)];
}
__forceinline uint32 ReadTexel32(int x, int y, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA) const
{
return ReadTexel32(PixelAddress32(x, y, TEX0.TBP0, TEX0.TBW), TEXA);
}
__forceinline uint32 ReadTexel24(int x, int y, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA) const
{
return ReadTexel24(PixelAddress32(x, y, TEX0.TBP0, TEX0.TBW), TEXA);
}
__forceinline uint32 ReadTexel16(int x, int y, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA) const
{
return ReadTexel16(PixelAddress16(x, y, TEX0.TBP0, TEX0.TBW), TEXA);
}
__forceinline uint32 ReadTexel16S(int x, int y, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA) const
{
return ReadTexel16(PixelAddress16S(x, y, TEX0.TBP0, TEX0.TBW), TEXA);
}
__forceinline uint32 ReadTexel8(int x, int y, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA) const
{
return ReadTexel8(PixelAddress8(x, y, TEX0.TBP0, TEX0.TBW), TEXA);
}
__forceinline uint32 ReadTexel4(int x, int y, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA) const
{
return ReadTexel4(PixelAddress4(x, y, TEX0.TBP0, TEX0.TBW), TEXA);
}
__forceinline uint32 ReadTexel8H(int x, int y, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA) const
{
return ReadTexel8H(PixelAddress32(x, y, TEX0.TBP0, TEX0.TBW), TEXA);
}
__forceinline uint32 ReadTexel4HL(int x, int y, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA) const
{
return ReadTexel4HL(PixelAddress32(x, y, TEX0.TBP0, TEX0.TBW), TEXA);
}
__forceinline uint32 ReadTexel4HH(int x, int y, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA) const
{
return ReadTexel4HH(PixelAddress32(x, y, TEX0.TBP0, TEX0.TBW), TEXA);
}
__forceinline uint32 ReadTexel32Z(int x, int y, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA) const
{
return ReadTexel32(PixelAddress32Z(x, y, TEX0.TBP0, TEX0.TBW), TEXA);
}
__forceinline uint32 ReadTexel24Z(int x, int y, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA) const
{
return ReadTexel24(PixelAddress32Z(x, y, TEX0.TBP0, TEX0.TBW), TEXA);
}
__forceinline uint32 ReadTexel16Z(int x, int y, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA) const
{
return ReadTexel16(PixelAddress16Z(x, y, TEX0.TBP0, TEX0.TBW), TEXA);
}
__forceinline uint32 ReadTexel16SZ(int x, int y, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA) const
{
return ReadTexel16(PixelAddress16SZ(x, y, TEX0.TBP0, TEX0.TBW), TEXA);
}
//
template<int psm, int bsx, int bsy, int alignment>
void WriteImageColumn(int l, int r, int y, int h, const uint8* src, int srcpitch, const GIFRegBITBLTBUF& BITBLTBUF);
template<int psm, int bsx, int bsy, int alignment>
void WriteImageBlock(int l, int r, int y, int h, const uint8* src, int srcpitch, const GIFRegBITBLTBUF& BITBLTBUF);
template<int psm, int bsx, int bsy>
void WriteImageLeftRight(int l, int r, int y, int h, const uint8* src, int srcpitch, const GIFRegBITBLTBUF& BITBLTBUF);
template<int psm, int bsx, int bsy, int trbpp>
void WriteImageTopBottom(int l, int r, int y, int h, const uint8* src, int srcpitch, const GIFRegBITBLTBUF& BITBLTBUF);
template<int psm, int bsx, int bsy, int trbpp>
void WriteImage(int& tx, int& ty, const uint8* src, int len, GIFRegBITBLTBUF& BITBLTBUF, GIFRegTRXPOS& TRXPOS, GIFRegTRXREG& TRXREG);
void WriteImage24(int& tx, int& ty, const uint8* src, int len, GIFRegBITBLTBUF& BITBLTBUF, GIFRegTRXPOS& TRXPOS, GIFRegTRXREG& TRXREG);
void WriteImage8H(int& tx, int& ty, const uint8* src, int len, GIFRegBITBLTBUF& BITBLTBUF, GIFRegTRXPOS& TRXPOS, GIFRegTRXREG& TRXREG);
void WriteImage4HL(int& tx, int& ty, const uint8* src, int len, GIFRegBITBLTBUF& BITBLTBUF, GIFRegTRXPOS& TRXPOS, GIFRegTRXREG& TRXREG);
void WriteImage4HH(int& tx, int& ty, const uint8* src, int len, GIFRegBITBLTBUF& BITBLTBUF, GIFRegTRXPOS& TRXPOS, GIFRegTRXREG& TRXREG);
void WriteImage24Z(int& tx, int& ty, const uint8* src, int len, GIFRegBITBLTBUF& BITBLTBUF, GIFRegTRXPOS& TRXPOS, GIFRegTRXREG& TRXREG);
void WriteImageX(int& tx, int& ty, const uint8* src, int len, GIFRegBITBLTBUF& BITBLTBUF, GIFRegTRXPOS& TRXPOS, GIFRegTRXREG& TRXREG);
// TODO: ReadImage32/24/...
void ReadImageX(int& tx, int& ty, uint8* dst, int len, GIFRegBITBLTBUF& BITBLTBUF, GIFRegTRXPOS& TRXPOS, GIFRegTRXREG& TRXREG) const;
// * => 32
void ReadTexture32(const GSOffset* RESTRICT off, const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA);
void ReadTexture24(const GSOffset* RESTRICT off, const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA);
void ReadTexture16(const GSOffset* RESTRICT off, const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA);
void ReadTexture8(const GSOffset* RESTRICT off, const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA);
void ReadTexture4(const GSOffset* RESTRICT off, const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA);
void ReadTexture8H(const GSOffset* RESTRICT off, const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA);
void ReadTexture4HL(const GSOffset* RESTRICT off, const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA);
void ReadTexture4HH(const GSOffset* RESTRICT off, const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA);
void ReadTexture(const GSOffset* RESTRICT off, const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA);
void ReadTextureBlock32(uint32 bp, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA) const;
void ReadTextureBlock24(uint32 bp, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA) const;
void ReadTextureBlock16(uint32 bp, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA) const;
void ReadTextureBlock8(uint32 bp, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA) const;
void ReadTextureBlock4(uint32 bp, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA) const;
void ReadTextureBlock8H(uint32 bp, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA) const;
void ReadTextureBlock4HL(uint32 bp, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA) const;
void ReadTextureBlock4HH(uint32 bp, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA) const;
// pal ? 8 : 32
void ReadTexture8P(const GSOffset* RESTRICT off, const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA);
void ReadTexture4P(const GSOffset* RESTRICT off, const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA);
void ReadTexture8HP(const GSOffset* RESTRICT off, const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA);
void ReadTexture4HLP(const GSOffset* RESTRICT off, const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA);
void ReadTexture4HHP(const GSOffset* RESTRICT off, const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA);
void ReadTextureBlock8P(uint32 bp, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA) const;
void ReadTextureBlock4P(uint32 bp, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA) const;
void ReadTextureBlock8HP(uint32 bp, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA) const;
void ReadTextureBlock4HLP(uint32 bp, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA) const;
void ReadTextureBlock4HHP(uint32 bp, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA) const;
//
template<typename T> void ReadTexture(const GSOffset* RESTRICT off, const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA);
//
void SaveBMP(const string& fn, uint32 bp, uint32 bw, uint32 psm, int w, int h);
};