gpu_unai: fix clear masking
[pcsx_rearmed.git] / plugins / gpu_unai / gpu_raster_image.h
index 87d2151..7c9eb4d 100644 (file)
  *   51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA.           *
  ***************************************************************************/
 
+#ifndef __GPU_UNAI_GPU_RASTER_IMAGE_H__
+#define __GPU_UNAI_GPU_RASTER_IMAGE_H__
+
 ///////////////////////////////////////////////////////////////////////////////
 #ifndef USE_GPULIB
 void gpuLoadImage(PtrUnion packet)
 {
        u16 x0, y0, w0, h0;
-       x0 = packet.U2[2] & 1023;
-       y0 = packet.U2[3] & 511;
-       w0 = packet.U2[4];
-       h0 = packet.U2[5];
+       x0 = le16_to_u16(packet.U2[2]) & 1023;
+       y0 = le16_to_u16(packet.U2[3]) & 511;
+       w0 = le16_to_u16(packet.U2[4]);
+       h0 = le16_to_u16(packet.U2[5]);
 
        if ((y0 + h0) > FRAME_HEIGHT)
        {
@@ -39,7 +42,7 @@ void gpuLoadImage(PtrUnion packet)
        gpu_unai.dma.py = 0;
        gpu_unai.dma.x_end = w0;
        gpu_unai.dma.y_end = h0;
-       gpu_unai.dma.pvram = &((u16*)gpu_unai.vram)[x0+(y0*1024)];
+       gpu_unai.dma.pvram = &gpu_unai.vram[x0+(y0*1024)];
 
        gpu_unai.GPU_GP1 |= 0x08000000;
 }
@@ -50,10 +53,10 @@ void gpuLoadImage(PtrUnion packet)
 void gpuStoreImage(PtrUnion packet)
 {
        u16 x0, y0, w0, h0;
-       x0 = packet.U2[2] & 1023;
-       y0 = packet.U2[3] & 511;
-       w0 = packet.U2[4];
-       h0 = packet.U2[5];
+       x0 = le16_to_u16(packet.U2[2]) & 1023;
+       y0 = le16_to_u16(packet.U2[3]) & 511;
+       w0 = le16_to_u16(packet.U2[4]);
+       h0 = le16_to_u16(packet.U2[5]);
 
        if ((y0 + h0) > FRAME_HEIGHT)
        {
@@ -65,7 +68,7 @@ void gpuStoreImage(PtrUnion packet)
        gpu_unai.dma.py = 0;
        gpu_unai.dma.x_end = w0;
        gpu_unai.dma.y_end = h0;
-       gpu_unai.dma.pvram = &((u16*)gpu_unai.vram)[x0+(y0*1024)];
+       gpu_unai.dma.pvram = &gpu_unai.vram[x0+(y0*1024)];
        
        gpu_unai.GPU_GP1 |= 0x08000000;
 }
@@ -75,12 +78,12 @@ void gpuMoveImage(PtrUnion packet)
 {
        u32 x0, y0, x1, y1;
        s32 w0, h0;
-       x0 = packet.U2[2] & 1023;
-       y0 = packet.U2[3] & 511;
-       x1 = packet.U2[4] & 1023;
-       y1 = packet.U2[5] & 511;
-       w0 = packet.U2[6];
-       h0 = packet.U2[7];
+       x0 = le16_to_u16(packet.U2[2]) & 1023;
+       y0 = le16_to_u16(packet.U2[3]) & 511;
+       x1 = le16_to_u16(packet.U2[4]) & 1023;
+       y1 = le16_to_u16(packet.U2[5]) & 511;
+       w0 = le16_to_u16(packet.U2[6]);
+       h0 = le16_to_u16(packet.U2[7]);
 
        if( (x0==x1) && (y0==y1) ) return;
        if ((w0<=0) || (h0<=0)) return;
@@ -91,7 +94,7 @@ void gpuMoveImage(PtrUnion packet)
        
        if (((y0+h0)>512)||((x0+w0)>1024)||((y1+h0)>512)||((x1+w0)>1024))
        {
-               u16 *psxVuw=gpu_unai.vram;
+               le16_t *psxVuw=gpu_unai.vram;
                s32 i,j;
            for(j=0;j<h0;j++)
                 for(i=0;i<w0;i++)
@@ -100,8 +103,8 @@ void gpuMoveImage(PtrUnion packet)
        }
        else if ((x0&1)||(x1&1))
        {
-               u16 *lpDst, *lpSrc;
-               lpDst = lpSrc = (u16*)gpu_unai.vram;
+               le16_t *lpDst, *lpSrc;
+               lpDst = lpSrc = gpu_unai.vram;
                lpSrc += FRAME_OFFSET(x0, y0);
                lpDst += FRAME_OFFSET(x1, y1);
                x1 = FRAME_WIDTH - w0;
@@ -114,8 +117,8 @@ void gpuMoveImage(PtrUnion packet)
        }
        else
        {
-               u32 *lpDst, *lpSrc;
-               lpDst = lpSrc = (u32*)(void*)gpu_unai.vram;
+               le32_t *lpDst, *lpSrc;
+               lpDst = lpSrc = (le32_t *)gpu_unai.vram;
                lpSrc += ((FRAME_OFFSET(x0, y0))>>1);
                lpDst += ((FRAME_OFFSET(x1, y1))>>1);
                if (w0&1)
@@ -124,7 +127,7 @@ void gpuMoveImage(PtrUnion packet)
                        w0>>=1;
                        if (!w0) {
                                do {
-                                       *((u16*)lpDst) = *((u16*)lpSrc);
+                                       *((le16_t*)lpDst) = *((le16_t*)lpSrc);
                                        lpDst += x1;
                                        lpSrc += x1;
                                } while (--h0);
@@ -132,7 +135,7 @@ void gpuMoveImage(PtrUnion packet)
                        do {
                                x0=w0;
                                do { *lpDst++ = *lpSrc++; } while (--x0);
-                               *((u16*)lpDst) = *((u16*)lpSrc);
+                               *((le16_t*)lpDst) = *((le16_t*)lpSrc);
                                lpDst += x1;
                                lpSrc += x1;
                        } while (--h0);
@@ -154,11 +157,11 @@ void gpuMoveImage(PtrUnion packet)
 void gpuClearImage(PtrUnion packet)
 {
        s32   x0, y0, w0, h0;
-       x0 = packet.S2[2];
-       y0 = packet.S2[3];
-       w0 = packet.S2[4] & 0x3ff;
-       h0 = packet.S2[5] & 0x3ff;
-        
+       x0 = le16_to_s16(packet.U2[2]);
+       y0 = le16_to_s16(packet.U2[3]);
+       w0 = le16_to_s16(packet.U2[4]) & 0x3ff;
+       h0 = le16_to_s16(packet.U2[5]) & 0x1ff;
+
        w0 += x0;
        if (x0 < 0) x0 = 0;
        if (w0 > FRAME_WIDTH) w0 = FRAME_WIDTH;
@@ -173,11 +176,11 @@ void gpuClearImage(PtrUnion packet)
        #ifdef ENABLE_GPU_LOG_SUPPORT
                fprintf(stdout,"gpuClearImage(x0=%d,y0=%d,w0=%d,h0=%d)\n",x0,y0,w0,h0);
        #endif
-       
+
        if (x0&1)
        {
-               u16* pixel = (u16*)gpu_unai.vram + FRAME_OFFSET(x0, y0);
-               u16 rgb = GPU_RGB16(packet.U4[0]);
+               le16_t* pixel = gpu_unai.vram + FRAME_OFFSET(x0, y0);
+               le16_t rgb = u16_to_le16(GPU_RGB16(le32_to_u32(packet.U4[0])));
                y0 = FRAME_WIDTH - w0;
                do {
                        x0=w0;
@@ -187,9 +190,9 @@ void gpuClearImage(PtrUnion packet)
        }
        else
        {
-               u32* pixel = (u32*)gpu_unai.vram + ((FRAME_OFFSET(x0, y0))>>1);
-               u32 rgb = GPU_RGB16(packet.U4[0]);
-               rgb |= (rgb<<16);
+               le32_t* pixel = (le32_t*)gpu_unai.vram + ((FRAME_OFFSET(x0, y0))>>1);
+               u32 _rgb = GPU_RGB16(le32_to_u32(packet.U4[0]));
+               le32_t rgb = u32_to_le32(_rgb | (_rgb << 16));
                if (w0&1)
                {
                        y0 = (FRAME_WIDTH - w0 +1)>>1;
@@ -197,7 +200,7 @@ void gpuClearImage(PtrUnion packet)
                        do {
                                x0=w0;
                                do { *pixel++ = rgb; } while (--x0);
-                               *((u16*)pixel) = (u16)rgb;
+                               *((u16*)pixel) = (u16)le32_raw(rgb);
                                pixel += y0;
                        } while (--h0);
                }
@@ -213,3 +216,5 @@ void gpuClearImage(PtrUnion packet)
                }
        }
 }
+
+#endif /* __GPU_UNAI_GPU_RASTER_IMAGE_H__ */