psx_gpu: consolidate C code, implement exnhancement asm
[pcsx_rearmed.git] / plugins / dfxvideo / draw_pl.c
... / ...
CommitLineData
1/*
2 * (C) notaz, 2010-2011
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 "../gpulib/cspace.h"
13#include "../../frontend/plugin_lib.h"
14#include "../../frontend/pcnt.h"
15
16// misc globals
17long lLowerpart;
18BOOL bCheckMask = FALSE;
19unsigned short sSetMask;
20unsigned long lSetMask;
21
22static void blit(void *vout_buf)
23{
24 int px = PSXDisplay.DisplayPosition.x & ~1; // XXX: align needed by bgr*_to_...
25 int py = PSXDisplay.DisplayPosition.y;
26 int w = PreviousPSXDisplay.Range.x1;
27 int h = PreviousPSXDisplay.DisplayMode.y;
28 int pitch = PreviousPSXDisplay.DisplayMode.x;
29 unsigned short *srcs = psxVuw + py * 1024 + px;
30 unsigned char *dest = vout_buf;
31
32 if (w <= 0)
33 return;
34
35 pitch *= (PSXDisplay.RGB24 && !rcbs->only_16bpp) ? 3 : 2;
36
37 // account for centering
38 h -= PreviousPSXDisplay.Range.y0;
39 dest += PreviousPSXDisplay.Range.y0 / 2 * pitch;
40 dest += (PreviousPSXDisplay.Range.x0 & ~3) * 2; // must align here too..
41
42 if (PSXDisplay.RGB24)
43 {
44 if (!rcbs->only_16bpp)
45 {
46 for (; h-- > 0; dest += pitch, srcs += 1024)
47 {
48 bgr888_to_rgb888(dest, srcs, w * 3);
49 }
50 }
51 else
52 {
53 for (; h-- > 0; dest += pitch, srcs += 1024)
54 {
55 bgr888_to_rgb565(dest, srcs, w * 3);
56 }
57 }
58 }
59 else
60 {
61 for (; h-- > 0; dest += pitch, srcs += 1024)
62 {
63 bgr555_to_rgb565(dest, srcs, w * 2);
64 }
65 }
66}
67
68void DoBufferSwap(void)
69{
70 static int fbw, fbh, fb24bpp;
71 static void *vout_buf;
72
73 if (PreviousPSXDisplay.DisplayMode.x == 0 || PreviousPSXDisplay.DisplayMode.y == 0)
74 return;
75
76 /* careful if rearranging this code, we try to set mode and flip
77 * to get the hardware apply both changes at the same time */
78 if (PreviousPSXDisplay.DisplayMode.x != fbw || PreviousPSXDisplay.DisplayMode.y != fbh
79 || PSXDisplay.RGB24 != fb24bpp) {
80 fbw = PreviousPSXDisplay.DisplayMode.x;
81 fbh = PreviousPSXDisplay.DisplayMode.y;
82 fb24bpp = PSXDisplay.RGB24;
83 vout_buf = rcbs->pl_vout_set_mode(fbw, fbh, fb24bpp ? 24 : 16);
84 }
85
86 pcnt_start(PCNT_BLIT);
87 if (rcbs->pl_vout_raw_flip != NULL)
88 rcbs->pl_vout_raw_flip(PSXDisplay.DisplayPosition.x, PSXDisplay.DisplayPosition.y);
89 else
90 blit(vout_buf);
91 pcnt_end(PCNT_BLIT);
92
93 vout_buf = rcbs->pl_vout_flip();
94}
95
96void DoClearScreenBuffer(void)
97{
98}
99
100unsigned long ulInitDisplay(void)
101{
102 if (rcbs->pl_vout_open() != 0)
103 return 0;
104
105 return 1; /* ok */
106}
107
108void CloseDisplay(void)
109{
110 rcbs->pl_vout_close();
111}