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 #ifndef __GPU_UNAI_GPU_RASTER_IMAGE_H__
22 #define __GPU_UNAI_GPU_RASTER_IMAGE_H__
24 ///////////////////////////////////////////////////////////////////////////////
26 void gpuLoadImage(PtrUnion packet)
29 x0 = le16_to_u16(packet.U2[2]) & 1023;
30 y0 = le16_to_u16(packet.U2[3]) & 511;
31 w0 = le16_to_u16(packet.U2[4]);
32 h0 = le16_to_u16(packet.U2[5]);
34 if ((y0 + h0) > FRAME_HEIGHT)
36 h0 = FRAME_HEIGHT - y0;
39 gpu_unai.dma.FrameToWrite = ((w0)&&(h0));
43 gpu_unai.dma.x_end = w0;
44 gpu_unai.dma.y_end = h0;
45 gpu_unai.dma.pvram = &gpu_unai.vram[x0+(y0*1024)];
47 gpu_unai.GPU_GP1 |= 0x08000000;
51 ///////////////////////////////////////////////////////////////////////////////
53 void gpuStoreImage(PtrUnion packet)
56 x0 = le16_to_u16(packet.U2[2]) & 1023;
57 y0 = le16_to_u16(packet.U2[3]) & 511;
58 w0 = le16_to_u16(packet.U2[4]);
59 h0 = le16_to_u16(packet.U2[5]);
61 if ((y0 + h0) > FRAME_HEIGHT)
63 h0 = FRAME_HEIGHT - y0;
65 gpu_unai.dma.FrameToRead = ((w0)&&(h0));
69 gpu_unai.dma.x_end = w0;
70 gpu_unai.dma.y_end = h0;
71 gpu_unai.dma.pvram = &gpu_unai.vram[x0+(y0*1024)];
73 gpu_unai.GPU_GP1 |= 0x08000000;
77 void gpuMoveImage(PtrUnion packet)
81 x0 = le16_to_u16(packet.U2[2]) & 1023;
82 y0 = le16_to_u16(packet.U2[3]) & 511;
83 x1 = le16_to_u16(packet.U2[4]) & 1023;
84 y1 = le16_to_u16(packet.U2[5]) & 511;
85 w0 = le16_to_u16(packet.U2[6]);
86 h0 = le16_to_u16(packet.U2[7]);
88 if( (x0==x1) && (y0==y1) ) return;
89 if ((w0<=0) || (h0<=0)) return;
91 #ifdef ENABLE_GPU_LOG_SUPPORT
92 fprintf(stdout,"gpuMoveImage(x0=%u,y0=%u,x1=%u,y1=%u,w0=%d,h0=%d)\n",x0,y0,x1,y1,w0,h0);
95 if (((y0+h0)>512)||((x0+w0)>1024)||((y1+h0)>512)||((x1+w0)>1024))
97 le16_t *psxVuw=gpu_unai.vram;
101 psxVuw [(1024*((y1+j)&511))+((x1+i)&0x3ff)]=
102 psxVuw[(1024*((y0+j)&511))+((x0+i)&0x3ff)];
104 else if ((x0&1)||(x1&1))
106 le16_t *lpDst, *lpSrc;
107 lpDst = lpSrc = gpu_unai.vram;
108 lpSrc += FRAME_OFFSET(x0, y0);
109 lpDst += FRAME_OFFSET(x1, y1);
110 x1 = FRAME_WIDTH - w0;
113 do { *lpDst++ = *lpSrc++; } while (--x0);
120 le32_t *lpDst, *lpSrc;
121 lpDst = lpSrc = (le32_t *)gpu_unai.vram;
122 lpSrc += ((FRAME_OFFSET(x0, y0))>>1);
123 lpDst += ((FRAME_OFFSET(x1, y1))>>1);
126 x1 = (FRAME_WIDTH - w0 +1)>>1;
130 *((le16_t*)lpDst) = *((le16_t*)lpSrc);
137 do { *lpDst++ = *lpSrc++; } while (--x0);
138 *((le16_t*)lpDst) = *((le16_t*)lpSrc);
145 x1 = (FRAME_WIDTH - w0)>>1;
149 do { *lpDst++ = *lpSrc++; } while (--x0);
157 void gpuClearImage(PtrUnion packet)
160 x0 = le16_to_s16(packet.U2[2]);
161 y0 = le16_to_s16(packet.U2[3]);
162 w0 = le16_to_s16(packet.U2[4]) & 0x3ff;
163 h0 = le16_to_s16(packet.U2[5]) & 0x1ff;
167 if (w0 > FRAME_WIDTH) w0 = FRAME_WIDTH;
172 if (h0 > FRAME_HEIGHT) h0 = FRAME_HEIGHT;
176 #ifdef ENABLE_GPU_LOG_SUPPORT
177 fprintf(stdout,"gpuClearImage(x0=%d,y0=%d,w0=%d,h0=%d)\n",x0,y0,w0,h0);
182 le16_t* pixel = gpu_unai.vram + FRAME_OFFSET(x0, y0);
183 le16_t rgb = u16_to_le16(GPU_RGB16(le32_to_u32(packet.U4[0])));
184 y0 = FRAME_WIDTH - w0;
187 do { *pixel++ = rgb; } while (--x0);
193 le32_t* pixel = (le32_t*)gpu_unai.vram + ((FRAME_OFFSET(x0, y0))>>1);
194 u32 _rgb = GPU_RGB16(le32_to_u32(packet.U4[0]));
195 le32_t rgb = u32_to_le32(_rgb | (_rgb << 16));
198 y0 = (FRAME_WIDTH - w0 +1)>>1;
202 do { *pixel++ = rgb; } while (--x0);
203 *((u16*)pixel) = (u16)le32_raw(rgb);
209 y0 = (FRAME_WIDTH - w0)>>1;
213 do { *pixel++ = rgb; } while (--x0);
220 #endif /* __GPU_UNAI_GPU_RASTER_IMAGE_H__ */