cdrom: change pause timing again
[pcsx_rearmed.git] / plugins / gpu_senquack / gpu_raster_image.h
1 /***************************************************************************
2  *   Copyright (C) 2010 PCSX4ALL Team                                      *
3  *   Copyright (C) 2010 Unai                                               *
4  *                                                                         *
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.                                   *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #ifndef __GPU_UNAI_GPU_RASTER_IMAGE_H__
22 #define __GPU_UNAI_GPU_RASTER_IMAGE_H__
23
24 ///////////////////////////////////////////////////////////////////////////////
25 #ifndef USE_GPULIB
26 void gpuLoadImage(PtrUnion packet)
27 {
28         u16 x0, y0, w0, h0;
29         x0 = packet.U2[2] & 1023;
30         y0 = packet.U2[3] & 511;
31         w0 = packet.U2[4];
32         h0 = packet.U2[5];
33
34         if ((y0 + h0) > FRAME_HEIGHT)
35         {
36                 h0 = FRAME_HEIGHT - y0;
37         }
38
39         gpu_senquack.dma.FrameToWrite = ((w0)&&(h0));
40
41         gpu_senquack.dma.px = 0;
42         gpu_senquack.dma.py = 0;
43         gpu_senquack.dma.x_end = w0;
44         gpu_senquack.dma.y_end = h0;
45         gpu_senquack.dma.pvram = &((u16*)gpu_senquack.vram)[x0+(y0*1024)];
46
47         gpu_senquack.GPU_GP1 |= 0x08000000;
48 }
49 #endif // !USE_GPULIB
50
51 ///////////////////////////////////////////////////////////////////////////////
52 #ifndef USE_GPULIB
53 void gpuStoreImage(PtrUnion packet)
54 {
55         u16 x0, y0, w0, h0;
56         x0 = packet.U2[2] & 1023;
57         y0 = packet.U2[3] & 511;
58         w0 = packet.U2[4];
59         h0 = packet.U2[5];
60
61         if ((y0 + h0) > FRAME_HEIGHT)
62         {
63                 h0 = FRAME_HEIGHT - y0;
64         }
65         gpu_senquack.dma.FrameToRead = ((w0)&&(h0));
66
67         gpu_senquack.dma.px = 0;
68         gpu_senquack.dma.py = 0;
69         gpu_senquack.dma.x_end = w0;
70         gpu_senquack.dma.y_end = h0;
71         gpu_senquack.dma.pvram = &((u16*)gpu_senquack.vram)[x0+(y0*1024)];
72         
73         gpu_senquack.GPU_GP1 |= 0x08000000;
74 }
75 #endif // !USE_GPULIB
76
77 void gpuMoveImage(PtrUnion packet)
78 {
79         u32 x0, y0, x1, y1;
80         s32 w0, h0;
81         x0 = packet.U2[2] & 1023;
82         y0 = packet.U2[3] & 511;
83         x1 = packet.U2[4] & 1023;
84         y1 = packet.U2[5] & 511;
85         w0 = packet.U2[6];
86         h0 = packet.U2[7];
87
88         if( (x0==x1) && (y0==y1) ) return;
89         if ((w0<=0) || (h0<=0)) return;
90         
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);
93         #endif
94         
95         if (((y0+h0)>512)||((x0+w0)>1024)||((y1+h0)>512)||((x1+w0)>1024))
96         {
97                 u16 *psxVuw=gpu_senquack.vram;
98                 s32 i,j;
99             for(j=0;j<h0;j++)
100                  for(i=0;i<w0;i++)
101                   psxVuw [(1024*((y1+j)&511))+((x1+i)&0x3ff)]=
102                    psxVuw[(1024*((y0+j)&511))+((x0+i)&0x3ff)];
103         }
104         else if ((x0&1)||(x1&1))
105         {
106                 u16 *lpDst, *lpSrc;
107                 lpDst = lpSrc = (u16*)gpu_senquack.vram;
108                 lpSrc += FRAME_OFFSET(x0, y0);
109                 lpDst += FRAME_OFFSET(x1, y1);
110                 x1 = FRAME_WIDTH - w0;
111                 do {
112                         x0=w0;
113                         do { *lpDst++ = *lpSrc++; } while (--x0);
114                         lpDst += x1;
115                         lpSrc += x1;
116                 } while (--h0);
117         }
118         else
119         {
120                 u32 *lpDst, *lpSrc;
121                 lpDst = lpSrc = (u32*)(void*)gpu_senquack.vram;
122                 lpSrc += ((FRAME_OFFSET(x0, y0))>>1);
123                 lpDst += ((FRAME_OFFSET(x1, y1))>>1);
124                 if (w0&1)
125                 {
126                         x1 = (FRAME_WIDTH - w0 +1)>>1;
127                         w0>>=1;
128                         if (!w0) {
129                                 do {
130                                         *((u16*)lpDst) = *((u16*)lpSrc);
131                                         lpDst += x1;
132                                         lpSrc += x1;
133                                 } while (--h0);
134                         } else
135                         do {
136                                 x0=w0;
137                                 do { *lpDst++ = *lpSrc++; } while (--x0);
138                                 *((u16*)lpDst) = *((u16*)lpSrc);
139                                 lpDst += x1;
140                                 lpSrc += x1;
141                         } while (--h0);
142                 }
143                 else
144                 {
145                         x1 = (FRAME_WIDTH - w0)>>1;
146                         w0>>=1;
147                         do {
148                                 x0=w0;
149                                 do { *lpDst++ = *lpSrc++; } while (--x0);
150                                 lpDst += x1;
151                                 lpSrc += x1;
152                         } while (--h0);
153                 }
154         }
155 }
156
157 void gpuClearImage(PtrUnion packet)
158 {
159         s32   x0, y0, w0, h0;
160         x0 = packet.S2[2];
161         y0 = packet.S2[3];
162         w0 = packet.S2[4] & 0x3ff;
163         h0 = packet.S2[5] & 0x3ff;
164          
165         w0 += x0;
166         if (x0 < 0) x0 = 0;
167         if (w0 > FRAME_WIDTH) w0 = FRAME_WIDTH;
168         w0 -= x0;
169         if (w0 <= 0) return;
170         h0 += y0;
171         if (y0 < 0) y0 = 0;
172         if (h0 > FRAME_HEIGHT) h0 = FRAME_HEIGHT;
173         h0 -= y0;
174         if (h0 <= 0) return;
175
176         #ifdef ENABLE_GPU_LOG_SUPPORT
177                 fprintf(stdout,"gpuClearImage(x0=%d,y0=%d,w0=%d,h0=%d)\n",x0,y0,w0,h0);
178         #endif
179         
180         if (x0&1)
181         {
182                 u16* pixel = (u16*)gpu_senquack.vram + FRAME_OFFSET(x0, y0);
183                 u16 rgb = GPU_RGB16(packet.U4[0]);
184                 y0 = FRAME_WIDTH - w0;
185                 do {
186                         x0=w0;
187                         do { *pixel++ = rgb; } while (--x0);
188                         pixel += y0;
189                 } while (--h0);
190         }
191         else
192         {
193                 u32* pixel = (u32*)gpu_senquack.vram + ((FRAME_OFFSET(x0, y0))>>1);
194                 u32 rgb = GPU_RGB16(packet.U4[0]);
195                 rgb |= (rgb<<16);
196                 if (w0&1)
197                 {
198                         y0 = (FRAME_WIDTH - w0 +1)>>1;
199                         w0>>=1;
200                         do {
201                                 x0=w0;
202                                 do { *pixel++ = rgb; } while (--x0);
203                                 *((u16*)pixel) = (u16)rgb;
204                                 pixel += y0;
205                         } while (--h0);
206                 }
207                 else
208                 {
209                         y0 = (FRAME_WIDTH - w0)>>1;
210                         w0>>=1;
211                         do {
212                                 x0=w0;
213                                 do { *pixel++ = rgb; } while (--x0);
214                                 pixel += y0;
215                         } while (--h0);
216                 }
217         }
218 }
219
220 #endif /* __GPU_UNAI_GPU_RASTER_IMAGE_H__ */