1 /** file c128ui.c
2 * \brief Native GTK3 C128 UI
3 *
4 * \author Marco van den Heuvel <blackystardust68@yahoo.com>
5 * \author Bas Wassink <b.wassink@ziggo.nl>
6 */
7
8 /*
9 * This file is part of VICE, the Versatile Commodore Emulator.
10 * See README for copyright notice.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25 * 02111-1307 USA.
26 *
27 */
28
29 #include "vice.h"
30
31 #include <stdio.h>
32
33 #include "debug_gtk3.h"
34 #include "c128model.h"
35 #include "crtcontrolwidget.h"
36 #include "machine.h"
37 #include "machinemodelwidget.h"
38 #include "resources.h"
39 #include "sampler.h"
40 #include "ui.h"
41 #include "uimachinewindow.h"
42 #include "settings_sampler.h"
43 #include "vdc.h"
44 #include "vicii.h"
45 #include "videomodelwidget.h"
46 #include "widgethelpers.h"
47
48 #include "clockportdevicewidget.h"
49 #include "clockport.h"
50
51 #include "cartridge.h"
52 #include "reu.h"
53 #include "reuwidget.h"
54 #include "ramcartwidget.h"
55 #include "dqbbwidget.h"
56 #include "expertwidget.h"
57 #include "isepicwidget.h"
58 #include "gmod2widget.h"
59 #include "mmcrwidget.h"
60 #include "mmc64widget.h"
61 #include "retroreplaywidget.h"
62 #include "easyflashwidget.h"
63 #include "rrnetmk3widget.h"
64 #include "uicart.h"
65 #include "carthelpers.h"
66 #include "tapecart.h"
67 #include "tapeportdeviceswidget.h"
68 #include "c128model.h"
69 #include "settings_model.h"
70
71 #include "c128ui.h"
72
73
74 /** \brief List of C128 models
75 *
76 * Used in the machine-model widget
77 */
78 static const char *c128_model_list[] = {
79 "C128 PAL",
80 "C128D PAL",
81 "C128 NTSC",
82 "C128D NTSC",
83 NULL
84 };
85
86
87 /** \brief List of VIC-II models
88 *
89 * Used in the VIC-II model widget
90 */
91 static const vice_gtk3_radiogroup_entry_t c128_vicii_models[] = {
92 { "PAL", MACHINE_SYNC_PAL },
93 { "NTSC", MACHINE_SYNC_NTSC },
94 { NULL, -1 }
95 };
96
97
98 /** \brief Identify the canvas used to create a window
99 *
100 * \param[in] canvas video canvas
101 *
102 * \return window index on success, -1 on failure
103 */
identify_canvas(video_canvas_t * canvas)104 static int identify_canvas(video_canvas_t *canvas)
105 {
106 /* XXX: Functions in the common code number the
107 * windows in the opposite order.
108 */
109 if (canvas == vicii_get_canvas()) {
110 return PRIMARY_WINDOW;
111 }
112 if (canvas == vdc_get_canvas()) {
113 return SECONDARY_WINDOW;
114 }
115
116 return -1;
117 }
118
119 /** \brief Create CRT controls widget for \a target window
120 *
121 * \param[in] target_window target window index
122 *
123 * \return GtkGrid
124 */
create_crt_widget(int target_window)125 static GtkWidget *create_crt_widget(int target_window)
126 {
127 if (target_window == PRIMARY_WINDOW) {
128 return crt_control_widget_create(NULL, "VICII", TRUE);
129 } else {
130 return crt_control_widget_create(NULL, "VDC", TRUE);
131 }
132 }
133
134 /** \brief Pre-initialize the UI before the canvas windows get created
135 *
136 * \return 0 on success, -1 on failure
137 */
c128ui_init_early(void)138 int c128ui_init_early(void)
139 {
140 ui_machine_window_init();
141 ui_set_identify_canvas_func(identify_canvas);
142 ui_set_create_controls_widget_func(create_crt_widget);
143 return 0;
144 }
145
146
147 /** \brief Initialize the UI
148 *
149 * \return 0 on success, -1 on failure
150 */
c128ui_init(void)151 int c128ui_init(void)
152 {
153 int eighty;
154
155 machine_model_widget_getter(c128model_get);
156 machine_model_widget_setter(c128model_set);
157 machine_model_widget_set_models(c128_model_list);
158
159 video_model_widget_set_title("VIC-II model");
160 video_model_widget_set_resource("MachineVideoStandard");
161 video_model_widget_set_models(c128_vicii_models);
162
163 settings_sampler_set_devices_getter(sampler_get_devices);
164 clockport_device_widget_set_devices((void *)clockport_supported_devices);
165
166 /* I/O extension function pointers */
167 carthelpers_set_functions(
168 cartridge_save_image,
169 cartridge_flush_image,
170 cartridge_type_enabled,
171 cartridge_enable,
172 cartridge_disable);
173
174 /* uicart_set_detect_func(cartridge_detect); only cbm2/plus4 */
175 uicart_set_list_func(cartridge_get_info_list);
176 uicart_set_attach_func(cartridge_attach_image);
177 uicart_set_freeze_func(cartridge_trigger_freeze);
178 uicart_set_detach_func(cartridge_detach_image);
179 uicart_set_default_func(cartridge_set_default);
180 uicart_set_filename_func(cartridge_current_filename);
181 uicart_set_wipe_func(cartridge_wipe_filename);
182
183 /* set tapecart flush function */
184 tapeport_devices_widget_set_tapecart_flush_func(tapecart_flush_tcrt);
185
186 /* set model getter for the model settings dialog */
187 settings_model_widget_set_model_func(c128model_get);
188
189 /* push VDC display to front depending on 40/80 key */
190 if (resources_get_int("C128ColumnKey", &eighty) >= 0) {
191 debug_gtk3("got 80 col mode: %d.", eighty);
192
193 if (!eighty) {
194 GtkWidget *window = ui_get_window_by_index(1); /* VDC */
195 if (window != NULL) {
196 /* this is a bit dubious, but it seems any bring-to-front code
197 * has been removed from gtk3, so we just force the VDC window
198 * to front and immediately disable this, still keeping the
199 * VDC window as the top level window, but allowing moving
200 * the VICII in front of it.
201 */
202 gtk_window_set_keep_above(GTK_WINDOW(window), TRUE);
203 gtk_window_set_keep_above(GTK_WINDOW(window), FALSE);
204 }
205 }
206 }
207 return 0;
208 }
209
210
211 /** \brief Shut down the UI
212 */
c128ui_shutdown(void)213 void c128ui_shutdown(void)
214 {
215 /* NOP */
216 }
217