forked from libretro/RetroArch
-
Notifications
You must be signed in to change notification settings - Fork 2
/
video_crt_switch.c
206 lines (172 loc) · 5.03 KB
/
video_crt_switch.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/* CRT SwitchRes Core
* Copyright (C) 2018 Alphanu / Ben Templeman.
*
* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2017 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stddef.h>
#include <string.h>
#include <stdlib.h>
#include "video_driver.h"
#include "video_crt_switch.h"
#include "video_display_server.h"
static unsigned ra_core_width = 0;
static unsigned ra_core_height = 0;
static unsigned ra_tmp_width = 0;
static unsigned ra_tmp_height = 0;
static unsigned ra_set_core_hz = 0;
static unsigned orig_width = 0;
static unsigned orig_height = 0;
static int crt_center_adjust = 0;
static bool first_run = true;
static float ra_tmp_core_hz = 0.0f;
static float fly_aspect = 0.0f;
static float ra_core_hz = 0.0f;
static void crt_check_first_run(void)
{
if (!first_run)
return;
first_run = false;
}
static void switch_crt_hz(void)
{
if (ra_core_hz == ra_tmp_core_hz)
return;
/* set hz float to an int for windows switching */
if (ra_core_hz < 100)
{
if (ra_core_hz < 53)
ra_set_core_hz = 50;
if (ra_core_hz >= 53 && ra_core_hz < 57)
ra_set_core_hz = 55;
if (ra_core_hz >= 57)
ra_set_core_hz = 60;
}
if (ra_core_hz > 100)
{
if (ra_core_hz < 106)
ra_set_core_hz = 120;
if (ra_core_hz >= 106 && ra_core_hz < 114)
ra_set_core_hz = 110;
if (ra_core_hz >= 114)
ra_set_core_hz = 120;
}
video_monitor_set_refresh_rate(ra_set_core_hz);
ra_tmp_core_hz = ra_core_hz;
}
void crt_aspect_ratio_switch(unsigned width, unsigned height)
{
/* send aspect float to videeo_driver */
fly_aspect = (float)width / height;
video_driver_set_aspect_ratio_value((float)fly_aspect);
}
static void switch_res_crt(unsigned width, unsigned height)
{
if (height > 100)
{
video_display_server_set_resolution(width, height,
ra_set_core_hz, ra_core_hz, crt_center_adjust);
video_driver_apply_state_changes();
}
}
/* Create correct aspect to fit video if resolution does not exist */
static void crt_screen_setup_aspect(unsigned width, unsigned height)
{
switch_crt_hz();
/* get original resolution of core */
if (height == 4)
{
/* detect menu only */
if (width < 1920)
width = 320;
height = 240;
crt_aspect_ratio_switch(width, height);
}
if (height < 200 && height != 144)
{
crt_aspect_ratio_switch(width, height);
height = 200;
}
if (height > 200)
crt_aspect_ratio_switch(width, height);
if (height == 144 && ra_set_core_hz == 50)
{
height = 288;
crt_aspect_ratio_switch(width, height);
}
if (height > 200 && height < 224)
{
crt_aspect_ratio_switch(width, height);
height = 224;
}
if (height > 224 && height < 240)
{
crt_aspect_ratio_switch(width, height);
height = 240;
}
if (height > 240 && height < 255)
{
crt_aspect_ratio_switch(width, height);
height = 254;
}
if (height == 528 && ra_set_core_hz == 60)
{
crt_aspect_ratio_switch(width, height);
height = 480;
}
if (height >= 240 && height < 255 && ra_set_core_hz == 55)
{
crt_aspect_ratio_switch(width, height);
height = 254;
}
switch_res_crt(width, height);
}
void crt_switch_res_core(unsigned width, unsigned height, float hz, unsigned crt_mode, int crt_switch_center_adjust)
{
/* ra_core_hz float passed from within
* void video_driver_monitor_adjust_system_rates(void) */
ra_core_width = width;
ra_core_height = height;
ra_core_hz = hz;
crt_center_adjust = crt_switch_center_adjust;
if (crt_mode == 2)
{
if (hz > 53)
ra_core_hz = hz * 2;
if (hz <= 53)
ra_core_hz = 120.0f;
}
crt_check_first_run();
/* Detect resolution change and switch */
if (
(ra_tmp_height != ra_core_height) ||
(ra_core_width != ra_tmp_width)
)
crt_screen_setup_aspect(width, height);
ra_tmp_height = ra_core_height;
ra_tmp_width = ra_core_width;
/* Check if aspect is correct, if notchange */
if (video_driver_get_aspect_ratio() != fly_aspect)
{
video_driver_set_aspect_ratio_value((float)fly_aspect);
video_driver_apply_state_changes();
}
}
void crt_video_restore(void)
{
if (first_run)
return;
first_run = true;
}