fix some alignment issues
[pcsx_rearmed.git] / plugins / dfxvideo / draw_fb.c
1 /*
2  * (C) notaz, 2010
3  *
4  * This work is licensed under the terms of the GNU GPLv2 or later.
5  * See the COPYING file in the top-level directory.
6  */
7
8 #define _IN_DRAW
9
10 #include "gpu.h"
11
12 #include "plugin_lib.h"
13 #include "pcnt.h"
14
15 // misc globals
16 long           lLowerpart;
17 BOOL           bCheckMask = FALSE;
18 unsigned short sSetMask;
19 unsigned long  lSetMask;
20
21 #ifndef __arm__
22 #define bgr555_to_rgb565 memcpy
23 #define bgr888_to_rgb888 memcpy
24 #endif
25
26 static void blit(void)
27 {
28  extern void bgr555_to_rgb565(void *dst, void *src, int bytes);
29  extern void bgr888_to_rgb888(void *dst, void *src, int bytes);
30  int px = PSXDisplay.DisplayPosition.x & ~3; // XXX: align needed by bgr*_to_...
31  int py = PSXDisplay.DisplayPosition.y;
32  int w = PreviousPSXDisplay.Range.x1;
33  int h = PreviousPSXDisplay.DisplayMode.y;
34  int pitch = PreviousPSXDisplay.DisplayMode.x;
35  unsigned short *srcs = psxVuw + py * 1024 + px;
36  unsigned char *dest = pl_fbdev_buf;
37
38  if (w <= 0)
39    return;
40
41  // TODO: clear border if centering?
42
43  pitch *= PSXDisplay.RGB24 ? 3 : 2;
44
45  // account for centering
46  h -= PreviousPSXDisplay.Range.y0;
47  dest += PreviousPSXDisplay.Range.y0 / 2 * pitch;
48  dest += (PreviousPSXDisplay.Range.x0 & ~3) * 2; // must align here too..
49
50  if (PSXDisplay.RGB24)
51  {
52    for (; h-- > 0; dest += pitch, srcs += 1024)
53    {
54      bgr888_to_rgb888(dest, srcs, w * 3);
55    }
56  }
57  else
58  {
59    for (; h-- > 0; dest += pitch, srcs += 1024)
60    {
61      bgr555_to_rgb565(dest, srcs, w * 2);
62    }
63  }
64 }
65
66 void DoBufferSwap(void)
67 {
68  static int fbw, fbh, fb24bpp;
69
70  if (PreviousPSXDisplay.DisplayMode.x == 0 || PreviousPSXDisplay.DisplayMode.y == 0)
71   return;
72
73  /* careful if rearranging this code, we try to set mode and flip
74   * to get the hardware apply both changes at the same time */
75  if (PreviousPSXDisplay.DisplayMode.x != fbw || PreviousPSXDisplay.DisplayMode.y != fbh
76      || PSXDisplay.RGB24 != fb24bpp) {
77   fbw = PreviousPSXDisplay.DisplayMode.x;
78   fbh = PreviousPSXDisplay.DisplayMode.y;
79   fb24bpp = PSXDisplay.RGB24;
80   pl_fbdev_set_mode(fbw, fbh, fb24bpp ? 24 : 16);
81  }
82
83  pcnt_start(PCNT_BLIT);
84  blit();
85  pcnt_end(PCNT_BLIT);
86
87  pl_fbdev_flip();
88 }
89
90 void DoClearScreenBuffer(void)
91 {
92 }
93
94 unsigned long ulInitDisplay(void)
95 {
96  if (pl_fbdev_open() != 0)
97   return 0;
98
99  return 1; /* ok */
100 }
101
102 void CloseDisplay(void)
103 {
104  pl_fbdev_close();
105 }
106