psx_gpu: switch enhancement to 2048 width
[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 <string.h>
13#include "gpu.h"
14#include "cspace.h"
15#include "../../frontend/plugin_lib.h"
16
17static const struct rearmed_cbs *cbs;
18static void *screen_buf;
19
20int vout_init(void)
21{
22 return 0;
23}
24
25int vout_finish(void)
26{
27 return 0;
28}
29
30static void check_mode_change(void)
31{
32 static uint32_t old_status;
33 static int old_h;
34 int w = gpu.screen.hres;
35 int h = gpu.screen.h;
36
37 gpu.state.enhancement_active =
38 gpu.enhancement_bufer != NULL && gpu.state.enhancement_enable
39 && w <= 512 && h <= 256 && !gpu.status.rgb24;
40
41 if (gpu.state.enhancement_active) {
42 w *= 2;
43 h *= 2;
44 }
45
46 // width|rgb24 change?
47 if ((gpu.status.reg ^ old_status) & ((7<<16)|(1<<21)) || h != old_h)
48 {
49 old_status = gpu.status.reg;
50 old_h = h;
51
52 screen_buf = cbs->pl_vout_set_mode(w, h,
53 (gpu.status.rgb24 && !cbs->only_16bpp) ? 24 : 16);
54 }
55}
56
57static void blit(void)
58{
59 int x = gpu.screen.x & ~1; // alignment needed by blitter
60 int y = gpu.screen.y;
61 int w = gpu.screen.w;
62 int h = gpu.screen.h;
63 uint16_t *vram = gpu.vram;
64 int stride = gpu.screen.hres;
65 int vram_stride = 1024;
66 int vram_mask = 1024 * 512 - 1;
67 int fb_offs, doffs;
68 uint8_t *dest;
69
70 dest = (uint8_t *)screen_buf;
71 if (dest == NULL)
72 return;
73
74 if (gpu.state.enhancement_active) {
75 vram = gpu.enhancement_bufer;
76 x *= 2;
77 y *= 2;
78 w *= 2;
79 h *= 2;
80 stride *= 2;
81 vram_stride = 2048;
82 vram_mask = 2048 * 1024 - 1;
83 }
84 fb_offs = y * vram_stride + x;
85
86 // only do centering, at least for now
87 doffs = (stride - w) / 2 & ~1;
88
89 if (gpu.status.rgb24)
90 {
91 if (cbs->only_16bpp) {
92 dest += doffs * 2;
93 for (; h-- > 0; dest += stride * 2, fb_offs += vram_stride)
94 {
95 fb_offs &= vram_mask;
96 bgr888_to_rgb565(dest, vram + fb_offs, w * 3);
97 }
98 }
99 else {
100 dest += (doffs / 8) * 24;
101 for (; h-- > 0; dest += stride * 3, fb_offs += vram_stride)
102 {
103 fb_offs &= vram_mask;
104 bgr888_to_rgb888(dest, vram + fb_offs, w * 3);
105 }
106 }
107 }
108 else
109 {
110 dest += doffs * 2;
111 for (; h-- > 0; dest += stride * 2, fb_offs += vram_stride)
112 {
113 fb_offs &= vram_mask;
114 bgr555_to_rgb565(dest, vram + fb_offs, w * 2);
115 }
116 }
117
118 screen_buf = cbs->pl_vout_flip();
119}
120
121void vout_update(void)
122{
123 check_mode_change();
124 if (cbs->pl_vout_raw_flip)
125 cbs->pl_vout_raw_flip(gpu.screen.x, gpu.screen.y);
126 else
127 blit();
128}
129
130void vout_blank(void)
131{
132 check_mode_change();
133 if (cbs->pl_vout_raw_flip == NULL) {
134 int bytespp = gpu.status.rgb24 ? 3 : 2;
135 memset(screen_buf, 0, gpu.screen.hres * gpu.screen.h * bytespp);
136 screen_buf = cbs->pl_vout_flip();
137 }
138}
139
140long GPUopen(void **unused)
141{
142 gpu.frameskip.active = 0;
143 gpu.frameskip.frame_ready = 1;
144
145 cbs->pl_vout_open();
146 screen_buf = cbs->pl_vout_flip();
147 return 0;
148}
149
150long GPUclose(void)
151{
152 cbs->pl_vout_close();
153 return 0;
154}
155
156void vout_set_config(const struct rearmed_cbs *cbs_)
157{
158 cbs = cbs_;
159}
160
161// vim:shiftwidth=2:expandtab