31
32
#include "resources.h"
33
34
#include "video-resources.h"
34
35
#include "video-color.h"
36
37
#include "videoarch.h"
40
41
video_resources_t video_resources =
42
1000, 1100, 1100, 880,
47
static int set_color_saturation(resource_value_t v, void *param)
55
video_resources.color_saturation = val;
56
return video_color_update_palette();
59
static int set_color_contrast(resource_value_t v, void *param)
67
video_resources.color_contrast = val;
68
return video_color_update_palette();
71
static int set_color_brightness(resource_value_t v, void *param)
79
video_resources.color_brightness = val;
80
return video_color_update_palette();
83
static int set_color_gamma(resource_value_t v, void *param)
91
video_resources.color_gamma = val;
92
return video_color_update_palette();
43
1000, 1100, 1100, 880, 500,
47
int video_resources_init(void)
49
return video_arch_resources_init();
52
void video_resources_shutdown(void)
54
video_arch_resources_shutdown();
57
/*-----------------------------------------------------------------------*/
58
/* Per chip resources. */
60
struct video_resource_chip_s {
61
struct video_canvas_s **canvas;
62
video_chip_cap_t *video_chip_cap;
63
int double_scan_enabled;
64
int double_size_enabled;
66
int fullscreen_enabled;
67
char *fullscreen_device;
68
int fullscreen_double_size_enabled;
69
int fullscreen_double_scan_enabled;
70
int fullscreen_mode[FULLSCREEN_MAXDEV];
71
int external_palette_enabled;
72
char *external_palette_name;
74
typedef struct video_resource_chip_s video_resource_chip_t;
76
static void video_resources_update_ui(video_resource_chip_t *video_resource_chip);
78
struct video_resource_chip_mode_s {
79
video_resource_chip_t *resource_chip;
82
typedef struct video_resource_chip_mode_s video_resource_chip_mode_t;
84
static int set_double_size_enabled(resource_value_t v, void *param)
86
video_resource_chip_t *video_resource_chip;
87
video_chip_cap_t *video_chip_cap;
88
cap_render_t *cap_render;
89
video_canvas_t *canvas;
91
video_resource_chip = (video_resource_chip_t *)param;
92
video_chip_cap = video_resource_chip->video_chip_cap;
93
canvas = *(video_resource_chip->canvas);
96
cap_render = &video_chip_cap->double_mode;
98
cap_render = &video_chip_cap->single_mode;
100
canvas->videoconfig->rendermode = cap_render->rmode;
102
if (cap_render->sizex > 1
103
&& (video_chip_cap->dsize_limit_width == 0
104
|| canvas->draw_buffer->canvas_width
105
<= video_chip_cap->dsize_limit_width))
106
canvas->videoconfig->doublesizex = 1;
108
canvas->videoconfig->doublesizex = 0;
110
if (cap_render->sizey > 1
111
&& (video_chip_cap->dsize_limit_height == 0
112
|| canvas->draw_buffer->canvas_height
113
<= video_chip_cap->dsize_limit_height))
114
canvas->videoconfig->doublesizey = 1;
116
canvas->videoconfig->doublesizey = 0;
118
/* FIXME: Kludge needed until kind of render and dimensions are
119
separated from `rendermode' (which is overloaded currently). */
120
if (canvas->videoconfig->rendermode == VIDEO_RENDER_RGB_2X2) {
121
if (canvas->videoconfig->doublesizex == 0)
122
canvas->videoconfig->rendermode = VIDEO_RENDER_RGB_1X2;
123
if (canvas->videoconfig->doublesizex == 0
124
&& canvas->videoconfig->doublesizey == 0)
125
canvas->videoconfig->rendermode = VIDEO_RENDER_RGB_1X1;
128
if (video_resource_chip->double_size_enabled != (int)v
129
&& canvas->initialized
130
&& canvas->viewport->update_canvas > 0) {
131
video_viewport_resize(canvas);
134
video_resource_chip->double_size_enabled = (int)v;
136
video_resources_update_ui(video_resource_chip);
141
static const char *vname_chip_size[] = { "DoubleSize", NULL };
143
static resource_t resources_chip_size[] =
145
{ NULL, RES_INTEGER, (resource_value_t)0, NULL,
146
set_double_size_enabled, NULL },
150
static int set_double_scan_enabled(resource_value_t v, void *param)
152
video_resource_chip_t *video_resource_chip;
153
video_canvas_t *canvas;
155
video_resource_chip = (video_resource_chip_t *)param;
156
canvas = *(video_resource_chip->canvas);
158
video_resource_chip->double_scan_enabled = (int)v;
159
canvas->videoconfig->doublescan = (int)v;
161
if (canvas->initialized)
162
video_canvas_refresh_all(canvas);
164
video_resources_update_ui(video_resource_chip);
169
static const char *vname_chip_scan[] = { "DoubleScan", NULL };
171
static resource_t resources_chip_scan[] =
173
{ NULL, RES_INTEGER, (resource_value_t)1, NULL,
174
set_double_scan_enabled, NULL },
178
static int set_scale2x_enabled(resource_value_t v, void *param)
180
video_resource_chip_t *video_resource_chip;
181
video_canvas_t *canvas;
183
video_resource_chip = (video_resource_chip_t *)param;
184
canvas = *(video_resource_chip->canvas);
186
video_resource_chip->scale2x_enabled = (int)v;
187
canvas->videoconfig->scale2x = (int)v;
189
if (canvas->initialized)
190
video_canvas_refresh_all(canvas);
192
video_resources_update_ui(video_resource_chip);
197
static const char *vname_chip_scale2x[] = { "Scale2x", NULL };
199
static resource_t resources_chip_scale2x[] =
201
{ NULL, RES_INTEGER, (resource_value_t)0, NULL,
202
set_scale2x_enabled, NULL },
206
static int set_fullscreen_enabled(resource_value_t v, void *param)
208
video_resource_chip_t *video_resource_chip;
209
video_chip_cap_t *video_chip_cap;
210
video_canvas_t *canvas;
212
video_resource_chip = (video_resource_chip_t *)param;
213
video_chip_cap = video_resource_chip->video_chip_cap;
214
canvas = *(video_resource_chip->canvas);
216
video_resource_chip->fullscreen_enabled = (int)v;
218
if (canvas->initialized)
219
return (video_chip_cap->fullscreen.enable)(canvas, (int)v);
224
static int set_fullscreen_double_size_enabled(resource_value_t v, void *param)
226
video_resource_chip_t *video_resource_chip;
227
video_chip_cap_t *video_chip_cap;
228
video_canvas_t *canvas;
230
video_resource_chip = (video_resource_chip_t *)param;
231
video_chip_cap = video_resource_chip->video_chip_cap;
232
canvas = *(video_resource_chip->canvas);
234
video_resource_chip->fullscreen_double_size_enabled = (int)v;
236
return (video_chip_cap->fullscreen.double_size)(canvas, (int)v);
239
static int set_fullscreen_double_scan_enabled(resource_value_t v, void *param)
241
video_resource_chip_t *video_resource_chip;
242
video_chip_cap_t *video_chip_cap;
243
video_canvas_t *canvas;
245
video_resource_chip = (video_resource_chip_t *)param;
246
video_chip_cap = video_resource_chip->video_chip_cap;
247
canvas = *(video_resource_chip->canvas);
249
video_resource_chip->fullscreen_double_scan_enabled = (int)v;
251
return (video_chip_cap->fullscreen.double_scan)(canvas, (int)v);
254
static int set_fullscreen_device(resource_value_t v, void *param)
256
video_resource_chip_t *video_resource_chip;
257
video_chip_cap_t *video_chip_cap;
258
video_canvas_t *canvas;
260
video_resource_chip = (video_resource_chip_t *)param;
261
video_chip_cap = video_resource_chip->video_chip_cap;
262
canvas = *(video_resource_chip->canvas);
264
if (util_string_set(&video_resource_chip->fullscreen_device,
268
return (video_chip_cap->fullscreen.device)(canvas, (const char *)v);
271
static const char *vname_chip_fullscreen[] = {
272
"Fullscreen", "FullscreenDoubleSize", "FullscreenDoubleScan",
273
"FullscreenDevice", NULL
276
static resource_t resources_chip_fullscreen[] =
278
{ NULL, RES_INTEGER, (resource_value_t)0, NULL,
279
set_fullscreen_enabled, NULL },
280
{ NULL, RES_INTEGER, (resource_value_t)0, NULL,
281
set_fullscreen_double_size_enabled, NULL },
282
{ NULL, RES_INTEGER, (resource_value_t)0, NULL,
283
set_fullscreen_double_scan_enabled, NULL },
284
{ NULL, RES_STRING, (resource_value_t)NULL, NULL,
285
set_fullscreen_device, NULL },
289
static int set_fullscreen_mode(resource_value_t v, void *param)
291
video_resource_chip_mode_t *video_resource_chip_mode;
292
video_resource_chip_t *video_resource_chip;
293
video_chip_cap_t *video_chip_cap;
294
video_canvas_t *canvas;
298
video_resource_chip_mode = (video_resource_chip_mode_t *)param;
299
video_resource_chip = video_resource_chip_mode->resource_chip;
300
video_chip_cap = video_resource_chip->video_chip_cap;
301
canvas = *(video_resource_chip->canvas);
303
device = video_resource_chip_mode->device;
305
video_resource_chip->fullscreen_mode[device] = (int)v;
307
return (video_chip_cap->fullscreen.mode[device])(canvas, (int)v);
310
static const char *vname_chip_fullscreen_mode[] = { "FullscreenMode", NULL };
312
static resource_t resources_chip_fullscreen_mode[] =
314
{ NULL, RES_INTEGER, (resource_value_t)0, NULL,
315
set_fullscreen_mode, NULL },
95
319
static int set_ext_palette(resource_value_t v, void *param)
97
video_resources.ext_palette = (int)v;
98
return video_color_update_palette();
321
video_resource_chip_t *video_resource_chip;
322
video_chip_cap_t *video_chip_cap;
323
video_canvas_t *canvas;
325
video_resource_chip = (video_resource_chip_t *)param;
326
video_chip_cap = video_resource_chip->video_chip_cap;
327
canvas = *(video_resource_chip->canvas);
329
video_resource_chip->external_palette_enabled = (int)v;
330
canvas->videoconfig->external_palette = (unsigned int)v;
332
return video_color_update_palette(canvas);
101
335
static int set_palette_file_name(resource_value_t v, void *param)
103
util_string_set(&video_resources.palette_file_name, (char *)v);
104
return video_color_update_palette();
108
/* remove this once all ports have implemented this ui function */
109
#define ui_update_pal_ctrls(a)
112
static int set_delayloop_emulation(resource_value_t v, void *param)
114
int old = video_resources.delayloop_emulation;
115
video_resources.delayloop_emulation = (int)v;
117
if (video_color_update_palette() < 0) {
118
video_resources.delayloop_emulation = old;
119
ui_update_pal_ctrls(video_resources.delayloop_emulation);
122
ui_update_pal_ctrls(video_resources.delayloop_emulation);
127
static int set_pal_emulation(resource_value_t v, void *param)
129
int old = video_resources.pal_emulation;
130
video_resources.pal_emulation = (int)v;
132
if (video_color_update_palette() < 0) {
133
video_resources.pal_emulation = old;
140
static resource_t resources[] =
142
{ "ExternalPalette", RES_INTEGER, (resource_value_t)0,
143
(resource_value_t *)&video_resources.ext_palette,
337
video_resource_chip_t *video_resource_chip;
338
video_canvas_t *canvas;
340
video_resource_chip = (video_resource_chip_t *)param;
341
canvas = *(video_resource_chip->canvas);
343
util_string_set(&(video_resource_chip->external_palette_name), (char *)v);
344
canvas->videoconfig->external_palette_name
345
= video_resource_chip->external_palette_name;
347
return video_color_update_palette(canvas);
350
static const char *vname_chip_palette[] = { "PaletteFile", "ExternalPalette",
353
static resource_t resources_chip_palette[] =
355
{ NULL, RES_STRING, NULL, NULL,
356
set_palette_file_name, NULL },
357
{ NULL, RES_INTEGER, (resource_value_t)0, NULL,
144
358
set_ext_palette, NULL },
145
{ "PaletteFile", RES_STRING, (resource_value_t)"default",
146
(resource_value_t *)&video_resources.palette_file_name,
147
set_palette_file_name, NULL },
151
static resource_t resources_pal[] =
153
{ "ColorSaturation", RES_INTEGER, (resource_value_t)1000,
154
(resource_value_t *)&video_resources.color_saturation,
155
set_color_saturation, NULL },
156
{ "ColorContrast", RES_INTEGER, (resource_value_t)1000,
157
(resource_value_t *)&video_resources.color_contrast,
158
set_color_contrast, NULL },
159
{ "ColorBrightness", RES_INTEGER, (resource_value_t)1000,
160
(resource_value_t *)&video_resources.color_brightness,
161
set_color_brightness, NULL },
162
{ "ColorGamma", RES_INTEGER, (resource_value_t)880,
163
(resource_value_t *)&video_resources.color_gamma,
164
set_color_gamma, NULL },
165
{ "DelayLoopEmulation", RES_INTEGER, (resource_value_t)0,
166
(resource_value_t *)&video_resources.delayloop_emulation,
167
set_delayloop_emulation, NULL },
168
{ "PALEmulation", RES_INTEGER, (resource_value_t)0,
169
(resource_value_t *)&video_resources.pal_emulation,
170
set_pal_emulation, NULL },
174
int video_resources_init(int mode)
179
case VIDEO_RESOURCES_MONOCHROME:
180
result = resources_register(resources);
182
case VIDEO_RESOURCES_PAL:
183
case VIDEO_RESOURCES_PAL_NOFAKE:
184
result = resources_register(resources)
185
| resources_register(resources_pal);
189
return result | video_arch_init_resources();
362
int video_resources_chip_init(const char *chipname,
363
struct video_canvas_s **canvas,
364
video_chip_cap_t *video_chip_cap)
367
video_resource_chip_t *resource_chip;
370
= (video_resource_chip_t *)lib_calloc(1, sizeof(video_resource_chip_t));
371
(*canvas)->video_resource_chip = resource_chip;
373
video_render_initconfig((*canvas)->videoconfig);
374
(*canvas)->videoconfig->cap = video_chip_cap;
376
/* Set single size render as default. */
377
(*canvas)->videoconfig->rendermode = video_chip_cap->single_mode.rmode;
378
(*canvas)->videoconfig->doublesizex
379
= video_chip_cap->single_mode.sizex > 1 ? 1 : 0;
380
(*canvas)->videoconfig->doublesizey
381
= video_chip_cap->single_mode.sizey > 1 ? 1 : 0;
383
resource_chip->canvas = canvas;
384
resource_chip->video_chip_cap = video_chip_cap;
386
if (video_chip_cap->dscan_allowed != 0) {
387
resources_chip_scan[0].name
388
= util_concat(chipname, vname_chip_scan[0], NULL);
389
resources_chip_scan[0].value_ptr
390
= (resource_value_t *)&(resource_chip->double_scan_enabled);
391
resources_chip_scan[0].param = (void *)resource_chip;
392
if (resources_register(resources_chip_scan) < 0)
395
lib_free((char *)(resources_chip_scan[0].name));
398
if (video_chip_cap->scale2x_allowed != 0) {
399
resources_chip_scale2x[0].name
400
= util_concat(chipname, vname_chip_scale2x[0], NULL);
401
resources_chip_scale2x[0].value_ptr
402
= (resource_value_t *)&(resource_chip->scale2x_enabled);
403
resources_chip_scale2x[0].param = (void *)resource_chip;
404
if (resources_register(resources_chip_scale2x) < 0)
407
lib_free((char *)(resources_chip_scale2x[0].name));
410
if (video_chip_cap->dsize_allowed != 0) {
411
resources_chip_size[0].name
412
= util_concat(chipname, vname_chip_size[0], NULL);
413
resources_chip_size[0].factory_value
414
= (resource_value_t)video_chip_cap->dsize_default;
415
resources_chip_size[0].value_ptr
416
= (resource_value_t *)&(resource_chip->double_size_enabled);
417
resources_chip_size[0].param = (void *)resource_chip;
418
if (resources_register(resources_chip_size) < 0)
421
lib_free((char *)(resources_chip_size[0].name));
424
if (video_chip_cap->fullscreen.device_num > 0) {
425
video_resource_chip_mode_t *resource_chip_mode;
427
resources_chip_fullscreen[0].name
428
= util_concat(chipname, vname_chip_fullscreen[0], NULL);
429
resources_chip_fullscreen[0].value_ptr
430
= (resource_value_t *)&(resource_chip->fullscreen_enabled);
431
resources_chip_fullscreen[0].param = (void *)resource_chip;
433
resources_chip_fullscreen[1].name
434
= util_concat(chipname, vname_chip_fullscreen[1], NULL);
435
resources_chip_fullscreen[1].value_ptr
436
= (resource_value_t *)&(resource_chip->fullscreen_double_size_enabled);
437
resources_chip_fullscreen[1].param = (void *)resource_chip;
439
resources_chip_fullscreen[2].name
440
= util_concat(chipname, vname_chip_fullscreen[2], NULL);
441
resources_chip_fullscreen[2].value_ptr
442
= (resource_value_t *)&(resource_chip->fullscreen_double_scan_enabled);
443
resources_chip_fullscreen[2].param = (void *)resource_chip;
445
resources_chip_fullscreen[3].name
446
= util_concat(chipname, vname_chip_fullscreen[3], NULL);
447
resources_chip_fullscreen[3].factory_value
448
= (resource_value_t)(video_chip_cap->fullscreen.device_name[0]);
449
resources_chip_fullscreen[3].value_ptr
450
= (resource_value_t *)&(resource_chip->fullscreen_device);
451
resources_chip_fullscreen[3].param = (void *)resource_chip;
453
if (resources_register(resources_chip_fullscreen) < 0)
456
lib_free((char *)(resources_chip_fullscreen[0].name));
457
lib_free((char *)(resources_chip_fullscreen[1].name));
458
lib_free((char *)(resources_chip_fullscreen[2].name));
459
lib_free((char *)(resources_chip_fullscreen[3].name));
461
for (i = 0; i < video_chip_cap->fullscreen.device_num; i++) {
462
resource_chip_mode = (video_resource_chip_mode_t *)lib_malloc(
463
sizeof(video_resource_chip_mode_t));
464
resource_chip_mode->resource_chip = resource_chip;
465
resource_chip_mode->device = i;
467
resources_chip_fullscreen_mode[0].name
468
= util_concat(chipname,
469
video_chip_cap->fullscreen.device_name[i],
470
vname_chip_fullscreen_mode[0], NULL);
471
resources_chip_fullscreen_mode[0].value_ptr
472
= (resource_value_t *)&(resource_chip->fullscreen_mode[i]);
473
resources_chip_fullscreen_mode[0].param
474
= (void *)resource_chip_mode;
476
if (resources_register(resources_chip_fullscreen_mode) < 0)
479
lib_free((char *)(resources_chip_fullscreen_mode[0].name));
483
resources_chip_palette[0].name
484
= util_concat(chipname, vname_chip_palette[0], NULL);
485
resources_chip_palette[0].factory_value
486
= (resource_value_t)video_chip_cap->external_palette_name;
487
resources_chip_palette[0].value_ptr
488
= (resource_value_t *)&(resource_chip->external_palette_name);
489
resources_chip_palette[0].param = (void *)resource_chip;
491
if (video_chip_cap->internal_palette_allowed != 0) {
492
resources_chip_palette[1].name
493
= util_concat(chipname, vname_chip_palette[1], NULL);
494
resources_chip_palette[1].value_ptr
495
= (resource_value_t *)&(resource_chip->external_palette_enabled);
496
resources_chip_palette[1].param = (void *)resource_chip;
498
resources_chip_palette[1].name = NULL;
499
resource_chip->external_palette_enabled = 1;
500
(*canvas)->videoconfig->external_palette = 1;
503
if (resources_register(resources_chip_palette) < 0)
506
lib_free((char *)(resources_chip_palette[0].name));
507
if (video_chip_cap->internal_palette_allowed != 0)
508
lib_free((char *)(resources_chip_palette[1].name));
513
void video_resources_chip_shutdown(struct video_canvas_s *canvas)
515
lib_free(canvas->video_resource_chip->external_palette_name);
516
lib_free(canvas->video_resource_chip);
519
void video_resources_update_ui(video_resource_chip_t *video_resource_chip)
522
int ui_doublescan_enabled, ui_scale2x_enabled;
524
if (video_resource_chip->video_chip_cap->palemulation_allowed)
525
resources_get_value("PALEmulation", &pal_enabled);
527
if (video_resource_chip->double_size_enabled != 0) {
529
ui_doublescan_enabled = 1;
530
ui_scale2x_enabled = 0;
531
} else if (video_resource_chip->scale2x_enabled != 0) {
532
ui_doublescan_enabled = 0;
533
ui_scale2x_enabled = 1;
535
ui_doublescan_enabled = 1;
536
ui_scale2x_enabled = 1;
539
ui_doublescan_enabled = 0;
540
ui_scale2x_enabled = 0;
543
ui_enable_chip resources(ui_doublescan_enabled, ui_scale2x_enabled);