1 /***************************************************************************
2 * Copyright (C) 2010 PCSX4ALL Team *
3 * Copyright (C) 2010 Unai *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA. *
19 ***************************************************************************/
21 ///////////////////////////////////////////////////////////////////////////////
23 void gpuLoadImage(PtrUnion packet)
26 x0 = packet.U2[2] & 1023;
27 y0 = packet.U2[3] & 511;
31 if ((y0 + h0) > FRAME_HEIGHT)
33 h0 = FRAME_HEIGHT - y0;
36 gpu_unai.dma.FrameToWrite = ((w0)&&(h0));
40 gpu_unai.dma.x_end = w0;
41 gpu_unai.dma.y_end = h0;
42 gpu_unai.dma.pvram = &((u16*)gpu_unai.vram)[x0+(y0*1024)];
44 gpu_unai.GPU_GP1 |= 0x08000000;
48 ///////////////////////////////////////////////////////////////////////////////
50 void gpuStoreImage(PtrUnion packet)
53 x0 = packet.U2[2] & 1023;
54 y0 = packet.U2[3] & 511;
58 if ((y0 + h0) > FRAME_HEIGHT)
60 h0 = FRAME_HEIGHT - y0;
62 gpu_unai.dma.FrameToRead = ((w0)&&(h0));
66 gpu_unai.dma.x_end = w0;
67 gpu_unai.dma.y_end = h0;
68 gpu_unai.dma.pvram = &((u16*)gpu_unai.vram)[x0+(y0*1024)];
70 gpu_unai.GPU_GP1 |= 0x08000000;
74 void gpuMoveImage(PtrUnion packet)
78 x0 = packet.U2[2] & 1023;
79 y0 = packet.U2[3] & 511;
80 x1 = packet.U2[4] & 1023;
81 y1 = packet.U2[5] & 511;
85 if( (x0==x1) && (y0==y1) ) return;
86 if ((w0<=0) || (h0<=0)) return;
88 #ifdef ENABLE_GPU_LOG_SUPPORT
89 fprintf(stdout,"gpuMoveImage(x0=%u,y0=%u,x1=%u,y1=%u,w0=%d,h0=%d)\n",x0,y0,x1,y1,w0,h0);
92 if (((y0+h0)>512)||((x0+w0)>1024)||((y1+h0)>512)||((x1+w0)>1024))
94 u16 *psxVuw=gpu_unai.vram;
98 psxVuw [(1024*((y1+j)&511))+((x1+i)&0x3ff)]=
99 psxVuw[(1024*((y0+j)&511))+((x0+i)&0x3ff)];
101 else if ((x0&1)||(x1&1))
104 lpDst = lpSrc = (u16*)gpu_unai.vram;
105 lpSrc += FRAME_OFFSET(x0, y0);
106 lpDst += FRAME_OFFSET(x1, y1);
107 x1 = FRAME_WIDTH - w0;
110 do { *lpDst++ = *lpSrc++; } while (--x0);
118 lpDst = lpSrc = (u32*)(void*)gpu_unai.vram;
119 lpSrc += ((FRAME_OFFSET(x0, y0))>>1);
120 lpDst += ((FRAME_OFFSET(x1, y1))>>1);
123 x1 = (FRAME_WIDTH - w0 +1)>>1;
127 *((u16*)lpDst) = *((u16*)lpSrc);
134 do { *lpDst++ = *lpSrc++; } while (--x0);
135 *((u16*)lpDst) = *((u16*)lpSrc);
142 x1 = (FRAME_WIDTH - w0)>>1;
146 do { *lpDst++ = *lpSrc++; } while (--x0);
154 void gpuClearImage(PtrUnion packet)
159 w0 = packet.S2[4] & 0x3ff;
160 h0 = packet.S2[5] & 0x3ff;
164 if (w0 > FRAME_WIDTH) w0 = FRAME_WIDTH;
169 if (h0 > FRAME_HEIGHT) h0 = FRAME_HEIGHT;
173 #ifdef ENABLE_GPU_LOG_SUPPORT
174 fprintf(stdout,"gpuClearImage(x0=%d,y0=%d,w0=%d,h0=%d)\n",x0,y0,w0,h0);
179 u16* pixel = (u16*)gpu_unai.vram + FRAME_OFFSET(x0, y0);
180 u16 rgb = GPU_RGB16(packet.U4[0]);
181 y0 = FRAME_WIDTH - w0;
184 do { *pixel++ = rgb; } while (--x0);
190 u32* pixel = (u32*)gpu_unai.vram + ((FRAME_OFFSET(x0, y0))>>1);
191 u32 rgb = GPU_RGB16(packet.U4[0]);
195 y0 = (FRAME_WIDTH - w0 +1)>>1;
199 do { *pixel++ = rgb; } while (--x0);
200 *((u16*)pixel) = (u16)rgb;
206 y0 = (FRAME_WIDTH - w0)>>1;
210 do { *pixel++ = rgb; } while (--x0);