fix some build issues and warnings
[pcsx_rearmed.git] / plugins / gpulib / vout_pl.c
... / ...
CommitLineData
1/*
2 * video output handling using plugin_lib
3 * (C) GraÅžvydas "notaz" Ignotas, 2011
4 *
5 * This work is licensed under the terms of any of these licenses
6 * (at your option):
7 * - GNU GPL, version 2 or later.
8 * - GNU LGPL, version 2.1 or later.
9 * See the COPYING file in the top-level directory.
10 */
11
12#include "gpu.h"
13#include "cspace.h"
14#include "../../frontend/plugin_lib.h"
15
16static const struct rearmed_cbs *cbs;
17static void *screen_buf;
18
19int vout_init(void)
20{
21 return 0;
22}
23
24int vout_finish(void)
25{
26 return 0;
27}
28
29static void check_mode_change(void)
30{
31 static uint32_t old_status;
32 static int old_h;
33
34 // width|rgb24 change?
35 if ((gpu.status.reg ^ old_status) & ((7<<16)|(1<<21)) || gpu.screen.h != old_h)
36 {
37 old_status = gpu.status.reg;
38 old_h = gpu.screen.h;
39 screen_buf = cbs->pl_vout_set_mode(gpu.screen.hres, gpu.screen.h,
40 (gpu.status.rgb24 && !cbs->only_16bpp) ? 24 : 16);
41 }
42}
43
44static void blit(void)
45{
46 int x = gpu.screen.x & ~1; // alignment needed by blitter
47 int y = gpu.screen.y;
48 int w = gpu.screen.w;
49 int h = gpu.screen.h;
50 uint16_t *vram = gpu.vram;
51 int stride = gpu.screen.hres;
52 int fb_offs, doffs;
53 uint8_t *dest;
54
55 fb_offs = y * 1024 + x;
56 dest = (uint8_t *)screen_buf;
57
58 // only do centering, at least for now
59 doffs = (stride - w) / 2 & ~1;
60
61 if (gpu.status.rgb24)
62 {
63 if (cbs->only_16bpp) {
64 dest += doffs * 2;
65 for (; h-- > 0; dest += stride * 2, fb_offs += 1024)
66 {
67 fb_offs &= 1024*512-1;
68 bgr888_to_rgb565(dest, vram + fb_offs, w * 3);
69 }
70 }
71 else {
72 dest += (doffs / 8) * 24;
73 for (; h-- > 0; dest += stride * 3, fb_offs += 1024)
74 {
75 fb_offs &= 1024*512-1;
76 bgr888_to_rgb888(dest, vram + fb_offs, w * 3);
77 }
78 }
79 }
80 else
81 {
82 dest += doffs * 2;
83 for (; h-- > 0; dest += stride * 2, fb_offs += 1024)
84 {
85 fb_offs &= 1024*512-1;
86 bgr555_to_rgb565(dest, vram + fb_offs, w * 2);
87 }
88 }
89
90 screen_buf = cbs->pl_vout_flip();
91}
92
93void vout_update(void)
94{
95 check_mode_change();
96 if (cbs->pl_vout_raw_flip)
97 cbs->pl_vout_raw_flip(gpu.screen.x, gpu.screen.y);
98 else
99 blit();
100}
101
102long GPUopen(void **unused)
103{
104 gpu.frameskip.active = 0;
105 gpu.frameskip.frame_ready = 1;
106
107 cbs->pl_vout_open();
108 screen_buf = cbs->pl_vout_flip();
109 return 0;
110}
111
112long GPUclose(void)
113{
114 cbs->pl_vout_close();
115 return 0;
116}
117
118void vout_set_config(const struct rearmed_cbs *cbs_)
119{
120 cbs = cbs_;
121}
122
123// vim:shiftwidth=2:expandtab