gpus: return DMA word count to avoid 1 list walk
[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
e64dc4c5 12#include "../../frontend/plugin_lib.h"
13#include "../../frontend/arm_utils.h"
14#include "../../frontend/pcnt.h"
b60f2812 15
16// misc globals
b60f2812 17long lLowerpart;
b60f2812 18BOOL bCheckMask = FALSE;
a96a5eb2 19unsigned short sSetMask;
20unsigned long lSetMask;
b60f2812 21
b60f2812 22static void blit(void)
23{
69f0df9c 24 int px = PSXDisplay.DisplayPosition.x & ~1; // XXX: align needed by bgr*_to_...
16f7d5e7 25 int py = PSXDisplay.DisplayPosition.y;
b60f2812 26 int w = PreviousPSXDisplay.Range.x1;
27 int h = PreviousPSXDisplay.DisplayMode.y;
1972732a 28 int pitch = PreviousPSXDisplay.DisplayMode.x;
16f7d5e7 29 unsigned short *srcs = psxVuw + py * 1024 + px;
b60f2812 30 unsigned char *dest = pl_fbdev_buf;
31
a327967e 32 if (w <= 0)
33 return;
34
f3a63e25 35#ifndef MAEMO
1972732a 36 pitch *= PSXDisplay.RGB24 ? 3 : 2;
f3a63e25 37#else
38 // n900 doesn't do rgb24 for some reason
39 pitch *= 2;
40 #define bgr888_to_rgb888 bgr888_to_rgb565
41#endif
1972732a 42
b60f2812 43 // account for centering
44 h -= PreviousPSXDisplay.Range.y0;
45 dest += PreviousPSXDisplay.Range.y0 / 2 * pitch;
16f7d5e7 46 dest += (PreviousPSXDisplay.Range.x0 & ~3) * 2; // must align here too..
b60f2812 47
1972732a 48 if (PSXDisplay.RGB24)
49 {
50 for (; h-- > 0; dest += pitch, srcs += 1024)
51 {
52 bgr888_to_rgb888(dest, srcs, w * 3);
53 }
54 }
55 else
b60f2812 56 {
b60f2812 57 for (; h-- > 0; dest += pitch, srcs += 1024)
58 {
a327967e 59 bgr555_to_rgb565(dest, srcs, w * 2);
b60f2812 60 }
61 }
62}
63
b60f2812 64void DoBufferSwap(void)
65{
f2019b6e 66 static int fbw, fbh, fb24bpp;
72228559 67
16f7d5e7 68 if (PreviousPSXDisplay.DisplayMode.x == 0 || PreviousPSXDisplay.DisplayMode.y == 0)
b60f2812 69 return;
70
d352cde2 71 /* careful if rearranging this code, we try to set mode and flip
72 * to get the hardware apply both changes at the same time */
16f7d5e7 73 if (PreviousPSXDisplay.DisplayMode.x != fbw || PreviousPSXDisplay.DisplayMode.y != fbh
f2019b6e 74 || PSXDisplay.RGB24 != fb24bpp) {
16f7d5e7 75 fbw = PreviousPSXDisplay.DisplayMode.x;
76 fbh = PreviousPSXDisplay.DisplayMode.y;
b60f2812 77 fb24bpp = PSXDisplay.RGB24;
78 pl_fbdev_set_mode(fbw, fbh, fb24bpp ? 24 : 16);
79 }
80
72228559 81 pcnt_start(PCNT_BLIT);
b60f2812 82 blit();
72228559 83 pcnt_end(PCNT_BLIT);
14dffdb7 84
72228559 85 pl_fbdev_flip();
b60f2812 86}
87
a96a5eb2 88void DoClearScreenBuffer(void)
b60f2812 89{
90}
91
b60f2812 92unsigned long ulInitDisplay(void)
93{
6d1a1ac2 94 if (pl_fbdev_open() != 0)
b60f2812 95 return 0;
96
97 return 1; /* ok */
98}
99
100void CloseDisplay(void)
101{
6d1a1ac2 102 pl_fbdev_close();
b60f2812 103}