fork of PCE focusing on macplus, supporting DaynaPort SCSI network emulation
1/*****************************************************************************
2 * pce *
3 *****************************************************************************/
4
5/*****************************************************************************
6 * File name: src/lib/initerm.c *
7 * Created: 2008-10-21 by Hampa Hug <hampa@hampa.ch> *
8 * Copyright: (C) 2008-2012 Hampa Hug <hampa@hampa.ch> *
9 *****************************************************************************/
10
11/*****************************************************************************
12 * This program is free software. You can redistribute it and / or modify it *
13 * under the terms of the GNU General Public License version 2 as published *
14 * by the Free Software Foundation. *
15 * *
16 * This program is distributed in the hope that it will be useful, but *
17 * WITHOUT ANY WARRANTY, without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
19 * Public License for more details. *
20 *****************************************************************************/
21
22
23#include <config.h>
24
25#include <string.h>
26
27#include <lib/initerm.h>
28#include <lib/log.h>
29#include <libini/libini.h>
30
31#include <drivers/video/terminal.h>
32
33
34/*
35 * Check if a terminal type is recognized
36 */
37static
38int trm_is_valid (const char *str)
39{
40 if (strcmp (str, "null") == 0) {
41 return (1);
42 }
43
44#ifdef PCE_ENABLE_X11
45 if (strcmp (str, "x11") == 0) {
46 return (1);
47 }
48#endif
49
50#ifdef PCE_ENABLE_SDL
51 if (strcmp (str, "sdl") == 0) {
52 return (1);
53 }
54#endif
55
56 return (0);
57}
58
59terminal_t *ini_get_terminal (ini_sct_t *ini, const char *def)
60{
61 unsigned scale;
62 unsigned min_w, min_h;
63 unsigned aspect_x, aspect_y;
64 int mouse_x[2], mouse_y[2];
65 const char *driver;
66 const char *esc;
67 ini_sct_t *sct;
68 terminal_t *trm;
69
70 trm = NULL;
71
72 sct = ini_next_sct (ini, NULL, "terminal");
73 ini_get_string (sct, "driver", &driver, "null");
74
75 if (def != NULL) {
76 while ((sct != NULL) && (strcmp (def, driver) != 0)) {
77 sct = ini_next_sct (ini, sct, "terminal");
78 ini_get_string (sct, "driver", &driver, "null");
79 }
80
81 driver = def;
82 }
83 else {
84 while ((sct != NULL) && (trm_is_valid (driver) == 0)) {
85 sct = ini_next_sct (ini, sct, "terminal");
86 ini_get_string (sct, "driver", &driver, "null");
87 }
88
89 if (sct == NULL) {
90 driver = "null";
91 }
92 }
93
94 ini_get_string (sct, "escape", &esc, NULL);
95 ini_get_uint16 (sct, "aspect_x", &aspect_x, 4);
96 ini_get_uint16 (sct, "aspect_y", &aspect_y, 3);
97 ini_get_uint16 (sct, "min_w", &min_w, 512);
98 ini_get_uint16 (sct, "min_h", &min_h, 384);
99 ini_get_uint16 (sct, "scale", &scale, 1);
100 ini_get_sint16 (sct, "mouse_mul_x", &mouse_x[0], 1);
101 ini_get_sint16 (sct, "mouse_div_x", &mouse_x[1], 1);
102 ini_get_sint16 (sct, "mouse_mul_y", &mouse_y[0], 1);
103 ini_get_sint16 (sct, "mouse_div_y", &mouse_y[1], 1);
104
105 pce_log_tag (MSG_INF, "TERM:",
106 "driver=%s ESC=%s aspect=%u/%u min_size=%u*%u scale=%u"
107 " mouse=[%u/%u %u/%u]\n",
108 driver,
109 (esc != NULL) ? esc : "ESC",
110 aspect_x, aspect_y,
111 min_w, min_h,
112 scale,
113 mouse_x[0], mouse_x[1], mouse_y[0], mouse_y[1]
114 );
115
116 if (strcmp (driver, "x11") == 0) {
117#ifdef PCE_ENABLE_X11
118 trm = xt_new (sct);
119
120 if (trm == NULL) {
121 pce_log (MSG_ERR, "*** setting up x11 terminal failed\n");
122 }
123#else
124 pce_log (MSG_ERR, "*** terminal driver 'x11' not supported\n");
125#endif
126 }
127 else if (strcmp (driver, "sdl") == 0) {
128#ifdef PCE_ENABLE_SDL1
129 trm = sdl_new (sct);
130
131 if (trm == NULL) {
132 pce_log (MSG_ERR, "*** setting up sdl1 terminal failed\n");
133 }
134#elif defined (PCE_ENABLE_SDL2)
135 trm = sdl2_new (sct);
136
137 if (trm == NULL) {
138 pce_log (MSG_ERR, "*** setting up sdl2 terminal failed\n");
139 }
140#else
141 pce_log (MSG_ERR, "*** terminal driver 'sdl' not supported\n");
142#endif
143 }
144 else if (strcmp (driver, "null") == 0) {
145 trm = null_new (sct);
146
147 if (trm == NULL) {
148 pce_log (MSG_ERR, "*** setting up null terminal failed\n");
149 }
150 }
151 else {
152 pce_log (MSG_ERR, "*** unknown terminal driver: %s\n", driver);
153 }
154
155 if (trm == NULL) {
156 pce_log (MSG_ERR, "*** no terminal found\n");
157 return (NULL);
158 }
159
160 if (esc != NULL) {
161 trm_set_escape_str (trm, esc);
162 }
163
164 trm_set_scale (trm, scale);
165 trm_set_min_size (trm, min_w, min_h);
166 trm_set_aspect_ratio (trm, aspect_x, aspect_y);
167 trm_set_mouse_scale (trm, mouse_x[0], mouse_x[1], mouse_y[0], mouse_y[1]);
168
169 return (trm);
170}