25 #define PS2SS_GIF_AD 0x0e
27 #define PS2SS_GIFTAG(NLOOP,EOP,PRE,PRIM,FLG,NREG) \
28 ((u64)(NLOOP) << 0) | \
29 ((u64)(EOP) << 15) | \
30 ((u64)(PRE) << 46) | \
31 ((u64)(PRIM) << 47) | \
32 ((u64)(FLG) << 58) | \
35 #define PS2SS_GSBITBLTBUF_SET(sbp, sbw, spsm, dbp, dbw, dpsm) \
36 ((u64)(sbp) | ((u64)(sbw) << 16) | \
37 ((u64)(spsm) << 24) | ((u64)(dbp) << 32) | \
38 ((u64)(dbw) << 48) | ((u64)(dpsm) << 56))
40 #define PS2SS_GSTRXREG_SET(rrw, rrh) \
41 ((u64)(rrw) | ((u64)(rrh) << 32))
43 #define PS2SS_GSTRXPOS_SET(ssax, ssay, dsax, dsay, dir) \
44 ((u64)(ssax) | ((u64)(ssay) << 16) | \
45 ((u64)(dsax) << 32) | ((u64)(dsay) << 48) | \
48 #define PS2SS_GSTRXDIR_SET(xdr) ((u64)(xdr))
50 #define PS2SS_GSBITBLTBUF 0x50
51 #define PS2SS_GSFINISH 0x61
52 #define PS2SS_GSTRXPOS 0x51
53 #define PS2SS_GSTRXREG 0x52
54 #define PS2SS_GSTRXDIR 0x53
56 #define PS2SS_GSPSMCT32 0
57 #define PS2SS_GSPSMCT24 1
58 #define PS2SS_GSPSMCT16 2
60 #define PS2SS_D1_CHCR ((volatile unsigned int *)(0x10009000))
61 #define PS2SS_D1_MADR ((volatile unsigned int *)(0x10009010))
62 #define PS2SS_D1_QWC ((volatile unsigned int *)(0x10009020))
63 #define PS2SS_D1_TADR ((volatile unsigned int *)(0x10009030))
64 #define PS2SS_D1_ASR0 ((volatile unsigned int *)(0x10009040))
65 #define PS2SS_D1_ASR1 ((volatile unsigned int *)(0x10009050))
67 #define PS2SS_CSR_FINISH (1 << 1)
68 #define PS2SS_GS_CSR ((volatile u64 *)(0x12001000))
69 #define PS2SS_GS_BUSDIR ((volatile u64 *)(0x12001040))
71 #define PS2SS_VIF1_STAT ((volatile u32 *)(0x10003c00))
72 #define PS2SS_VIF1_STAT_FDR (1<< 23)
73 #define PS2SS_VIF1_MSKPATH3(mask) ((u32)(mask) | ((u32)0x06 << 24))
74 #define PS2SS_VIF1_NOP 0
75 #define PS2SS_VIF1_FLUSHA (((u32)0x13 << 24))
76 #define PS2SS_VIF1_DIRECT(count) ((u32)(count) | ((u32)(0x50) << 24))
77 #define PS2SS_VIF1_FIFO ((volatile u128 *)(0x10005000))
84 int ps2_screenshot_file(
const char* pFilename,
unsigned int VramAdress,
85 unsigned int Width,
unsigned int Height,
unsigned int Psm )
89 static u32 in_buffer[1024 * 4];
90 static u32 out_buffer[1024 * 4];
92 unsigned char header[18] =
94 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0,
100 s16 *p_header = (s16 *)&header;
102 file_handle = open( pFilename, O_CREAT|O_WRONLY );
111 p_header[6] = (s16) Width;
112 p_header[7] = (s16) Height;
114 write (file_handle, (
void *)&header, 18);
118 for (y = 0; y < Height; y++)
120 u32 *p_out = (u32 *)&out_buffer;
121 ps2_screenshot(in_buffer, VramAdress, 0, (Height - 1) - y, Width, 1, Psm);
123 if (Psm == PS2SS_GSPSMCT16)
126 u16* p_in = (u16*)&in_buffer;
128 for (x = 0; x < Width; x++)
130 u32 r = (p_in[x] & 31) << 3;
131 u32 g = ((p_in[x] >> 5) & 31) << 3;
132 u32 b = ((p_in[x] >> 10) & 31) << 3;
133 p_out[x] = (((u8)0xff)<<24)|(r<<16)|(g<<8)|b;
137 if (Psm == PS2SS_GSPSMCT24)
140 u8* p_in = (u8*)&in_buffer;
142 for( x = 0; x < Width; x++ )
147 p_out[x] = (((u8)0xff)<<24)|(r<<16)|(g<<8)|b;
152 u8 *p_in = (u8 *) &in_buffer;
155 for(x = 0; x < Width; x++)
161 p_out[x] = (a << 24) | (r << 16) | (g << 8) | b;
165 write(file_handle, p_out, Width * 4);
182 unsigned int y,
unsigned int Width,
unsigned int Height,
188 } enable_path3 ALIGNED(16) = {
189 {PS2SS_VIF1_MSKPATH3(0), PS2SS_VIF1_NOP, PS2SS_VIF1_NOP, PS2SS_VIF1_NOP}
192 u32 dma_chain[20*2] ALIGNED(16);
193 u32* p_dma32 = (u32*)&dma_chain;
194 u64 *p_dma64 = (u64*)(p_dma32 + 4);
201 if( Psm == PS2SS_GSPSMCT16 )
202 uQSize = ((Width*Height*2)/16);
203 else if( Psm == PS2SS_GSPSMCT24 )
204 uQSize = ((Width*Height*3)/16);
206 uQSize = (Width*Height*4)/16;
210 p_dma32[0] = PS2SS_VIF1_NOP;
211 p_dma32[1] = PS2SS_VIF1_MSKPATH3(0x8000);
212 p_dma32[2] = PS2SS_VIF1_FLUSHA;
213 p_dma32[3] = PS2SS_VIF1_DIRECT(6);
217 p_dma64[0] = PS2SS_GIFTAG(5, 1, 0, 0, 0, 1);
218 p_dma64[1] = PS2SS_GIF_AD;
220 p_dma64[2] = PS2SS_GSBITBLTBUF_SET(VramAdress, Width/64, Psm, 0, 0, Psm);
221 p_dma64[3] = PS2SS_GSBITBLTBUF;
223 p_dma64[4] = PS2SS_GSTRXPOS_SET(x, y, 0, 0, 0);
224 p_dma64[5] = PS2SS_GSTRXPOS;
226 p_dma64[6] = PS2SS_GSTRXREG_SET(Width, Height);
227 p_dma64[7] = PS2SS_GSTRXREG;
230 p_dma64[9] = PS2SS_GSFINISH;
232 p_dma64[10] = PS2SS_GSTRXDIR_SET(1);
233 p_dma64[11] = PS2SS_GSTRXDIR;
235 prev_imr = GsPutIMR(GsGetIMR() | 0x0200);
236 prev_chcr = *PS2SS_D1_CHCR;
238 if( (*PS2SS_D1_CHCR & 0x0100) != 0 )
243 *PS2SS_GS_CSR = PS2SS_CSR_FINISH;
250 *PS2SS_D1_MADR = (u32)p_dma32;
251 *PS2SS_D1_CHCR = 0x101;
257 while( *PS2SS_D1_CHCR & 0x0100 );
258 while( ( *PS2SS_GS_CSR & PS2SS_CSR_FINISH ) == 0 );
262 while( (*PS2SS_VIF1_STAT & (0x1f000000) ) );
266 *PS2SS_VIF1_STAT = PS2SS_VIF1_STAT_FDR;
267 *PS2SS_GS_BUSDIR = (u64)0x00000001;
271 *PS2SS_D1_QWC = uQSize;
272 *PS2SS_D1_MADR = (u32)pDest;
273 *PS2SS_D1_CHCR = 0x100;
279 while ( *PS2SS_D1_CHCR & 0x0100 );
280 *PS2SS_D1_CHCR = prev_chcr;
282 *PS2SS_VIF1_STAT = 0;
283 *PS2SS_GS_BUSDIR = (u64)0;
287 GsPutIMR( prev_imr );
288 *PS2SS_GS_CSR = PS2SS_CSR_FINISH;
293 *PS2SS_VIF1_FIFO = enable_path3.value;