maemo: clean up and integrate
[pcsx_rearmed.git] / plugins / dfxvideo / draw_fb.c
CommitLineData
b60f2812 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
b60f2812 10#include "gpu.h"
b60f2812 11
12#include "plugin_lib.h"
72228559 13#include "pcnt.h"
b60f2812 14
15// misc globals
b60f2812 16long lLowerpart;
b60f2812 17BOOL bCheckMask = FALSE;
a96a5eb2 18unsigned short sSetMask;
19unsigned long lSetMask;
b60f2812 20
a327967e 21#ifndef __arm__
22#define bgr555_to_rgb565 memcpy
1972732a 23#define bgr888_to_rgb888 memcpy
a327967e 24#endif
b60f2812 25
26static void blit(void)
27{
a327967e 28 extern void bgr555_to_rgb565(void *dst, void *src, int bytes);
1972732a 29 extern void bgr888_to_rgb888(void *dst, void *src, int bytes);
16f7d5e7 30 int px = PSXDisplay.DisplayPosition.x & ~3; // XXX: align needed by bgr*_to_...
31 int py = PSXDisplay.DisplayPosition.y;
b60f2812 32 int w = PreviousPSXDisplay.Range.x1;
33 int h = PreviousPSXDisplay.DisplayMode.y;
1972732a 34 int pitch = PreviousPSXDisplay.DisplayMode.x;
16f7d5e7 35 unsigned short *srcs = psxVuw + py * 1024 + px;
b60f2812 36 unsigned char *dest = pl_fbdev_buf;
37
a327967e 38 if (w <= 0)
39 return;
40
16f7d5e7 41 // TODO: clear border if centering?
b60f2812 42
1972732a 43 pitch *= PSXDisplay.RGB24 ? 3 : 2;
44
b60f2812 45 // account for centering
46 h -= PreviousPSXDisplay.Range.y0;
47 dest += PreviousPSXDisplay.Range.y0 / 2 * pitch;
16f7d5e7 48 dest += (PreviousPSXDisplay.Range.x0 & ~3) * 2; // must align here too..
b60f2812 49
1972732a 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
b60f2812 58 {
b60f2812 59 for (; h-- > 0; dest += pitch, srcs += 1024)
60 {
a327967e 61 bgr555_to_rgb565(dest, srcs, w * 2);
b60f2812 62 }
63 }
64}
65
b60f2812 66void DoBufferSwap(void)
67{
f2019b6e 68 static int fbw, fbh, fb24bpp;
72228559 69
16f7d5e7 70 if (PreviousPSXDisplay.DisplayMode.x == 0 || PreviousPSXDisplay.DisplayMode.y == 0)
b60f2812 71 return;
72
d352cde2 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 */
16f7d5e7 75 if (PreviousPSXDisplay.DisplayMode.x != fbw || PreviousPSXDisplay.DisplayMode.y != fbh
f2019b6e 76 || PSXDisplay.RGB24 != fb24bpp) {
16f7d5e7 77 fbw = PreviousPSXDisplay.DisplayMode.x;
78 fbh = PreviousPSXDisplay.DisplayMode.y;
b60f2812 79 fb24bpp = PSXDisplay.RGB24;
80 pl_fbdev_set_mode(fbw, fbh, fb24bpp ? 24 : 16);
81 }
82
72228559 83 pcnt_start(PCNT_BLIT);
b60f2812 84 blit();
72228559 85 pcnt_end(PCNT_BLIT);
14dffdb7 86
72228559 87 pl_fbdev_flip();
b60f2812 88}
89
a96a5eb2 90void DoClearScreenBuffer(void)
b60f2812 91{
92}
93
b60f2812 94unsigned long ulInitDisplay(void)
95{
6d1a1ac2 96 if (pl_fbdev_open() != 0)
b60f2812 97 return 0;
98
99 return 1; /* ok */
100}
101
102void CloseDisplay(void)
103{
6d1a1ac2 104 pl_fbdev_close();
b60f2812 105}
106