b60f2812 |
1 | /* |
76f7048e |
2 | * (C) notaz, 2010-2011 |
b60f2812 |
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 | |
62d7fa95 |
12 | #include "../gpulib/cspace.h" |
e64dc4c5 |
13 | #include "../../frontend/plugin_lib.h" |
e64dc4c5 |
14 | #include "../../frontend/pcnt.h" |
b60f2812 |
15 | |
16 | // misc globals |
b60f2812 |
17 | long lLowerpart; |
b60f2812 |
18 | BOOL bCheckMask = FALSE; |
a96a5eb2 |
19 | unsigned short sSetMask; |
20 | unsigned long lSetMask; |
b60f2812 |
21 | |
76f7048e |
22 | static void blit(void *vout_buf) |
b60f2812 |
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; |
76f7048e |
30 | unsigned char *dest = vout_buf; |
b60f2812 |
31 | |
a327967e |
32 | if (w <= 0) |
33 | return; |
34 | |
4ea7de6a |
35 | pitch *= (PSXDisplay.RGB24 && !rcbs->only_16bpp) ? 3 : 2; |
1972732a |
36 | |
b60f2812 |
37 | // account for centering |
38 | h -= PreviousPSXDisplay.Range.y0; |
39 | dest += PreviousPSXDisplay.Range.y0 / 2 * pitch; |
16f7d5e7 |
40 | dest += (PreviousPSXDisplay.Range.x0 & ~3) * 2; // must align here too.. |
b60f2812 |
41 | |
1972732a |
42 | if (PSXDisplay.RGB24) |
43 | { |
4ea7de6a |
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 |
1972732a |
52 | { |
4ea7de6a |
53 | for (; h-- > 0; dest += pitch, srcs += 1024) |
54 | { |
55 | bgr888_to_rgb565(dest, srcs, w * 3); |
56 | } |
1972732a |
57 | } |
58 | } |
59 | else |
b60f2812 |
60 | { |
b60f2812 |
61 | for (; h-- > 0; dest += pitch, srcs += 1024) |
62 | { |
a327967e |
63 | bgr555_to_rgb565(dest, srcs, w * 2); |
b60f2812 |
64 | } |
65 | } |
66 | } |
67 | |
b60f2812 |
68 | void DoBufferSwap(void) |
69 | { |
f2019b6e |
70 | static int fbw, fbh, fb24bpp; |
76f7048e |
71 | static void *vout_buf; |
72228559 |
72 | |
16f7d5e7 |
73 | if (PreviousPSXDisplay.DisplayMode.x == 0 || PreviousPSXDisplay.DisplayMode.y == 0) |
b60f2812 |
74 | return; |
75 | |
d352cde2 |
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 */ |
16f7d5e7 |
78 | if (PreviousPSXDisplay.DisplayMode.x != fbw || PreviousPSXDisplay.DisplayMode.y != fbh |
f2019b6e |
79 | || PSXDisplay.RGB24 != fb24bpp) { |
16f7d5e7 |
80 | fbw = PreviousPSXDisplay.DisplayMode.x; |
81 | fbh = PreviousPSXDisplay.DisplayMode.y; |
b60f2812 |
82 | fb24bpp = PSXDisplay.RGB24; |
76f7048e |
83 | vout_buf = rcbs->pl_vout_set_mode(fbw, fbh, fb24bpp ? 24 : 16); |
b60f2812 |
84 | } |
85 | |
72228559 |
86 | pcnt_start(PCNT_BLIT); |
55b0eeea |
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); |
72228559 |
91 | pcnt_end(PCNT_BLIT); |
14dffdb7 |
92 | |
76f7048e |
93 | vout_buf = rcbs->pl_vout_flip(); |
b60f2812 |
94 | } |
95 | |
a96a5eb2 |
96 | void DoClearScreenBuffer(void) |
b60f2812 |
97 | { |
98 | } |
99 | |
b60f2812 |
100 | unsigned long ulInitDisplay(void) |
101 | { |
76f7048e |
102 | if (rcbs->pl_vout_open() != 0) |
b60f2812 |
103 | return 0; |
104 | |
105 | return 1; /* ok */ |
106 | } |
107 | |
108 | void CloseDisplay(void) |
109 | { |
76f7048e |
110 | rcbs->pl_vout_close(); |
b60f2812 |
111 | } |