1 /** \file   uidebug.c
2  * \brief   Debug menu dialogs
3  *
4  * \author  Bas Wassink <b.wassink@ziggo.nl>
5  */
6 
7 /*
8  * $VICERES AutoPlaybackFrames  all
9  * $VICERES TraceMode           all
10  */
11 
12 /*
13  * This file is part of VICE, the Versatile Commodore Emulator.
14  * See README for copyright notice.
15  *
16  *  This program is free software; you can redistribute it and/or modify
17  *  it under the terms of the GNU General Public License as published by
18  *  the Free Software Foundation; either version 2 of the License, or
19  *  (at your option) any later version.
20  *
21  *  This program is distributed in the hope that it will be useful,
22  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
23  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  *  GNU General Public License for more details.
25  *
26  *  You should have received a copy of the GNU General Public License
27  *  along with this program; if not, write to the Free Software
28  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
29  *  02111-1307  USA.
30  *
31  */
32 
33 #include "vice.h"
34 #include <gtk/gtk.h>
35 
36 #include <stdio.h>
37 #include <string.h>
38 #include <gtk/gtk.h>
39 
40 #include "basedialogs.h"
41 #include "basewidgets.h"
42 #include "debug_gtk3.h"
43 #include "drive.h"
44 #include "machine.h"
45 #include "resources.h"
46 #include "ui.h"
47 #include "vsync.h"
48 #include "widgethelpers.h"
49 
50 #include "uidebug.h"
51 
52 
53 /** \brief  List of debug trace modes
54  */
55 static const vice_gtk3_radiogroup_entry_t trace_modes[] = {
56     { "Normal",     DEBUG_NORMAL },
57     { "Small",      DEBUG_SMALL },
58     { "History",    DEBUG_HISTORY },
59     { "Autoplay",   DEBUG_AUTOPLAY },
60     { NULL, -1 }
61 };
62 
63 
64 /** \brief  Create widget to control number of autoplayback frames
65  *
66  * \return  GtkGrid
67  */
create_playback_widget(void)68 static GtkWidget *create_playback_widget(void)
69 {
70     GtkWidget *grid;
71     GtkWidget *label;
72     GtkWidget *spin;
73 
74     grid = gtk_grid_new();
75     gtk_grid_set_column_spacing(GTK_GRID(grid), 16);
76 
77     label = gtk_label_new("Auto playback frames");
78     gtk_widget_set_halign(label, GTK_ALIGN_START);
79     gtk_grid_attach(GTK_GRID(grid), label, 0, 0, 1, 1);
80 
81     spin = vice_gtk3_resource_spin_int_new("AutoPlaybackFrames",
82             0, 65536, 10);
83     gtk_grid_attach(GTK_GRID(grid), spin, 1, 0, 1,1);
84 
85     gtk_widget_show_all(grid);
86     return grid;
87 }
88 
89 
90 /** \brief  Create widget to control trace mode
91  *
92  * \return  GtkGrid
93  */
create_trace_widget(void)94 static GtkWidget *create_trace_widget(void)
95 {
96     GtkWidget *grid;
97     GtkWidget *group;
98 
99     grid = uihelpers_create_grid_with_label("Select CPU/Drive trace mode", 1);
100     group = vice_gtk3_resource_radiogroup_new("TraceMode", trace_modes,
101             GTK_ORIENTATION_VERTICAL);
102     g_object_set(group, "margin-left", 16, NULL);
103     gtk_grid_attach(GTK_GRID(grid), group, 0, 1, 1, 1);
104 
105     gtk_widget_show_all(grid);
106     return grid;
107 }
108 
109 
110 /** \brief  Create dialog to control trace mode
111  *
112  * \param[in]   parent  parent widget
113  *
114  * \return  GtkDialog
115  */
create_trace_mode_dialog(void)116 static GtkWidget *create_trace_mode_dialog(void)
117 {
118     GtkWidget *dialog;
119     GtkWidget *content;
120 
121     dialog = gtk_dialog_new_with_buttons("Select trace mode",
122             ui_get_active_window(), GTK_DIALOG_MODAL,
123             "Close", GTK_RESPONSE_CLOSE,
124             NULL);
125 
126     content = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
127     gtk_container_add(GTK_CONTAINER(content), create_trace_widget());
128 
129     return dialog;
130 }
131 
132 
133 /** \brief  Create dialog to control playback frames
134  *
135  * \param[in]   parent  parent widget
136  *
137  * \return  GtkDialog
138  */
create_playback_frames_dialog(void)139 static GtkWidget *create_playback_frames_dialog(void)
140 {
141     GtkWidget *dialog;
142     GtkWidget *content;
143 
144     dialog = gtk_dialog_new_with_buttons("Set auto playback frames",
145             ui_get_active_window(), GTK_DIALOG_MODAL,
146             "Close", GTK_RESPONSE_CLOSE,
147             NULL);
148 
149     content = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
150     gtk_container_add(GTK_CONTAINER(content), create_playback_widget());
151 
152     return dialog;
153 }
154 
155 
156 /** \brief  Handler for the 'response' event of the trace mode dialog
157  *
158  * \param[in,out]   dialog      dialog triggering the event
159  * \param[in]       response_id response ID
160  * \param[in]       extra event data (unused)
161  */
on_response_trace_mode(GtkDialog * dialog,gint response_id,gpointer data)162 static void on_response_trace_mode(GtkDialog *dialog,
163                                    gint response_id,
164                                    gpointer data)
165 {
166     debug_gtk3("got response %d.", response_id);
167     if (response_id == GTK_RESPONSE_CLOSE) {
168         gtk_widget_destroy(GTK_WIDGET(dialog));
169     }
170 }
171 
172 
173 /** \brief  Handler for the 'response' event of the playback frames dialog
174  *
175  * \param[in,out]   dialog      dialog triggering the event
176  * \param[in]       response_id response ID
177  * \param[in]       extra event data (unused)
178  */
on_response_playback_frames(GtkDialog * dialog,gint response_id,gpointer data)179 static void on_response_playback_frames(GtkDialog *dialog,
180                                         gint response_id,
181                                         gpointer data)
182 {
183     debug_gtk3("got response %d.", response_id);
184     if (response_id == GTK_RESPONSE_CLOSE) {
185         gtk_widget_destroy(GTK_WIDGET(dialog));
186     }
187 }
188 
189 
190 
191 /** \brief  Callback for the 'Debug' -> 'Trace mode' menu item
192  *
193  * \param[in]   widget      parent widget (ignored)
194  * \param[in]   user_data   extra data for the callback
195  */
uidebug_trace_mode_callback(GtkWidget * widget,gpointer user_data)196 void uidebug_trace_mode_callback(GtkWidget *widget, gpointer user_data)
197 {
198     GtkWidget *dialog;
199 
200     dialog = create_trace_mode_dialog();
201     g_signal_connect(dialog, "response",
202             G_CALLBACK(on_response_trace_mode), NULL);
203     gtk_widget_show_all(dialog);
204 }
205 
206 
207 /** \brief  Callback for the 'Debug' -> 'Autoplay playback frames' menu item
208 *
209 * \param[in]   widget      parent widget (ignored)
210 * \param[in]   user_data   extra data for the callback
211 */
uidebug_playback_frames_callback(GtkWidget * widget,gpointer user_data)212 void uidebug_playback_frames_callback(GtkWidget *widget, gpointer user_data)
213 {
214     GtkWidget *dialog;
215 
216     dialog = create_playback_frames_dialog();
217     g_signal_connect(dialog, "response",
218             G_CALLBACK(on_response_playback_frames), NULL);
219     gtk_widget_show_all(dialog);
220 
221 }
222