1 /** \file   c64ui.c
2  * \brief   Native GTK3 C64 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 "c64model.h"
35 #include "crtcontrolwidget.h"
36 #include "machinemodelwidget.h"
37 #include "sampler.h"
38 #include "ui.h"
39 #include "uimachinewindow.h"
40 #include "settings_sampler.h"
41 #include "vicii.h"
42 #include "videomodelwidget.h"
43 #include "widgethelpers.h"
44 #include "settings_model.h"
45 
46 #include "clockportdevicewidget.h"
47 #include "clockport.h"
48 
49 #include "reu.h"
50 #include "reuwidget.h"
51 #include "cartridge.h"
52 #include "ramcartwidget.h"
53 #include "dqbbwidget.h"
54 #include "expertwidget.h"
55 #include "isepicwidget.h"
56 #include "gmod2widget.h"
57 #include "mmcrwidget.h"
58 #include "mmc64widget.h"
59 #include "retroreplaywidget.h"
60 #include "easyflashwidget.h"
61 #include "rrnetmk3widget.h"
62 #include "uicart.h"
63 #include "carthelpers.h"
64 #include "machine.h"
65 #include "tapecart.h"
66 #include "tapeportdeviceswidget.h"
67 #include "crtpreviewwidget.h"
68 
69 #include "c64ui.h"
70 
71 
72 /** \brief  List of C64 models
73  *
74  * Used in the machine-model widget
75  */
76 static const char *c64_model_list[] = {
77     "C64 PAL", "C64C PAL", "C64 old PAL",
78     "C64 NTSC", "C64C NTSC", "C64 old NTSC",
79     "Drean",
80     "C64 SX PAL", "C64 SX NTSC",
81     "Japanese", "C64 GS",
82     "PET64 PAL", "PET64 NTSC",
83     "Ultimax", 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 c64_vicii_models[] = {
92     { "PAL",        MACHINE_SYNC_PAL },
93     { "NTSC",       MACHINE_SYNC_NTSC },
94     { "Old NTSC",   MACHINE_SYNC_NTSCOLD },
95     { "PAL-N",      MACHINE_SYNC_PALN },
96     { NULL, -1 }
97 };
98 
99 
100 /** \brief  Identify the canvas used to create a window
101  *
102  * \param[in]   canvas  video canvas
103  *
104  * \return  window index on success, -1 on failure
105  */
identify_canvas(video_canvas_t * canvas)106 static int identify_canvas(video_canvas_t *canvas)
107 {
108     if (canvas != vicii_get_canvas()) {
109         return -1;
110     }
111 
112     return PRIMARY_WINDOW;
113 }
114 
115 /** \brief  Create CRT controls widget for \a target window
116  *
117  * \param[in]   target_window   target window index
118  *
119  * \return  GtkGrid
120  */
create_crt_widget(int target_window)121 static GtkWidget *create_crt_widget(int target_window)
122 {
123     return crt_control_widget_create(NULL, "VICII", TRUE);
124 }
125 
126 /** \brief  Pre-initialize the UI before the canvas window gets created
127  *
128  * \return  0 on success, -1 on failure
129  */
c64ui_init_early(void)130 int c64ui_init_early(void)
131 {
132     ui_machine_window_init();
133     ui_set_identify_canvas_func(identify_canvas);
134     ui_set_create_controls_widget_func(create_crt_widget);
135     return 0;
136 }
137 
138 
139 /** \brief  Initialize the UI
140  *
141  * \return  0 on success, -1 on failure
142  */
c64ui_init(void)143 int c64ui_init(void)
144 {
145     machine_model_widget_getter(c64model_get);
146     machine_model_widget_setter(c64model_set);
147     machine_model_widget_set_models(c64_model_list);
148 
149     video_model_widget_set_title("VIC-II model");
150     video_model_widget_set_resource("MachineVideoStandard");
151     video_model_widget_set_models(c64_vicii_models);
152 
153     settings_sampler_set_devices_getter(sampler_get_devices);
154 
155     /* work around VSID again */
156     clockport_device_widget_set_devices((void *)clockport_supported_devices);
157 
158     /* I/O extension function pointers */
159     carthelpers_set_functions(
160             cartridge_save_image,
161             cartridge_flush_image,
162             cartridge_type_enabled,
163             cartridge_enable,
164             cartridge_disable);
165 
166     /* uicart_set_detect_func(cartridge_detect); only cbm2/plus4 */
167     uicart_set_list_func(cartridge_get_info_list);
168     uicart_set_attach_func(cartridge_attach_image);
169     uicart_set_freeze_func(cartridge_trigger_freeze);
170     uicart_set_detach_func(cartridge_detach_image);
171     uicart_set_default_func(cartridge_set_default);
172     uicart_set_filename_func(cartridge_current_filename);
173     uicart_set_wipe_func(cartridge_wipe_filename);
174 
175     /* set tapecart flush function */
176     tapeport_devices_widget_set_tapecart_flush_func(tapecart_flush_tcrt);
177 
178     /* set C64 model_get function */
179     settings_model_widget_set_model_func(c64model_get);
180 
181     /* crt preview widget functions */
182     crt_preview_widget_set_open_func(crt_open);
183     crt_preview_widget_set_chip_func(crt_read_chip_header);
184     return 0;
185 }
186 
187 
188 /** \brief  Shut down the UI
189  */
c64ui_shutdown(void)190 void c64ui_shutdown(void)
191 {
192     /* NOP */
193 }
194