1 /* ui.h: General UI event handling routines
2    Copyright (c) 2000-2004 Philip Kendall
3 
4    $Id: ui.h 4664 2012-02-12 11:51:01Z fredm $
5 
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10 
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15 
16    You should have received a copy of the GNU General Public License along
17    with this program; if not, write to the Free Software Foundation, Inc.,
18    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 
20    Author contact information:
21 
22    E-mail: philip-fuse@shadowmagic.org.uk
23 
24 */
25 
26 #ifndef FUSE_UI_H
27 #define FUSE_UI_H
28 
29 #include <stdarg.h>
30 
31 #ifdef HAVE_LIB_GLIB
32 #include <glib.h>
33 #endif
34 
35 #include <libspectrum.h>
36 
37 #include "compat.h"
38 #include "machines/specplus3.h"
39 #include "peripherals/disk/beta.h"
40 #include "peripherals/disk/disciple.h"
41 #include "peripherals/disk/opus.h"
42 #include "peripherals/disk/plusd.h"
43 #include "ui/scaler/scaler.h"
44 
45 /* The various severities of error level, increasing downwards */
46 typedef enum ui_error_level {
47 
48   UI_ERROR_INFO,		/* Informational message */
49   UI_ERROR_WARNING,		/* Something is wrong, but it's not that
50 				   important */
51   UI_ERROR_ERROR,		/* An actual error */
52 
53 } ui_error_level;
54 
55 int ui_init(int *argc, char ***argv);
56 int ui_event(void);
57 int ui_end(void);
58 
59 /* Error handling routines */
60 int ui_error( ui_error_level severity, const char *format, ... )
61      GCC_PRINTF( 2, 3 );
62 libspectrum_error ui_libspectrum_error( libspectrum_error error,
63 					const char *format, va_list ap );
64 int ui_verror( ui_error_level severity, const char *format, va_list ap );
65 int ui_error_specific( ui_error_level severity, const char *message );
66 void ui_error_frame( void );
67 
68 /* Callbacks used by the debugger */
69 int ui_debugger_activate( void );
70 int ui_debugger_deactivate( int interruptable );
71 int ui_debugger_update( void );
72 int ui_debugger_disassemble( libspectrum_word address );
73 
74 /* Reset anything in the UI which needs to be reset on machine selection */
75 int ui_widgets_reset( void );
76 
77 /* Functions defined in ../ui.c */
78 
79 /* Confirm whether we want to save some data before overwriting it */
80 typedef enum ui_confirm_save_t {
81 
82   UI_CONFIRM_SAVE_SAVE,		/* Save the data */
83   UI_CONFIRM_SAVE_DONTSAVE,	/* Don't save the data */
84   UI_CONFIRM_SAVE_CANCEL,	/* Cancel the action */
85 
86 } ui_confirm_save_t;
87 
88 ui_confirm_save_t ui_confirm_save( const char *format, ... )
89      GCC_PRINTF( 1, 2 );
90 ui_confirm_save_t ui_confirm_save_specific( const char *message );
91 
92 /* Confirm whether we want to change a joystick setting */
93 typedef enum ui_confirm_joystick_t {
94 
95   UI_CONFIRM_JOYSTICK_NONE,	        /* Don't map joystick */
96   UI_CONFIRM_JOYSTICK_KEYBOARD,	        /* Map the joystick to the keyboard */
97   UI_CONFIRM_JOYSTICK_JOYSTICK_1,	/* Map the joystick to joystick 1 */
98   UI_CONFIRM_JOYSTICK_JOYSTICK_2,	/* Map the joystick to joystick 2 */
99 
100 } ui_confirm_joystick_t;
101 
102 ui_confirm_joystick_t
103 ui_confirm_joystick( libspectrum_joystick libspectrum_type, int inputs );
104 
105 /* Mouse handling */
106 
107 extern int ui_mouse_present, ui_mouse_grabbed;
108 void ui_mouse_suspend( void );
109 void ui_mouse_resume( void );
110 void ui_mouse_button( int button, int down );
111 void ui_mouse_motion( int dx, int dy );
112 int ui_mouse_grab( int startup ); /* UI: grab, return 1 if done */
113 int ui_mouse_release( int suspend ); /* UI: ungrab, return 0 if done */
114 
115 /* Write the current tape out */
116 int ui_tape_write( void );
117 
118 /* Write a +3, Beta or +D disk out */
119 int ui_plus3_disk_write( specplus3_drive_number which, int saveas );
120 int ui_beta_disk_write( beta_drive_number which, int saveas );
121 int ui_opus_disk_write( opus_drive_number which, int saveas );
122 int ui_plusd_disk_write( plusd_drive_number which, int saveas );
123 int ui_disciple_disk_write( disciple_drive_number which, int saveas );
124 int ui_mdr_write( int which, int saveas );
125 
126 /* Get a rollback point from the given list */
127 int ui_get_rollback_point( GSList *points );
128 
129 /* Routines to (de)activate certain menu items */
130 
131 typedef enum ui_menu_item {
132 
133   UI_MENU_ITEM_FILE_MOVIE_RECORDING,
134   UI_MENU_ITEM_FILE_MOVIE_PAUSE,
135   UI_MENU_ITEM_MACHINE_PROFILER,
136   UI_MENU_ITEM_MEDIA_CARTRIDGE,
137   UI_MENU_ITEM_MEDIA_CARTRIDGE_DOCK,
138   UI_MENU_ITEM_MEDIA_CARTRIDGE_DOCK_EJECT,
139   UI_MENU_ITEM_MEDIA_IF1,
140   UI_MENU_ITEM_MEDIA_IF1_M1_EJECT,
141   UI_MENU_ITEM_MEDIA_IF1_M1_WP_SET,
142   UI_MENU_ITEM_MEDIA_IF1_M2_EJECT,
143   UI_MENU_ITEM_MEDIA_IF1_M2_WP_SET,
144   UI_MENU_ITEM_MEDIA_IF1_M3_EJECT,
145   UI_MENU_ITEM_MEDIA_IF1_M3_WP_SET,
146   UI_MENU_ITEM_MEDIA_IF1_M4_EJECT,
147   UI_MENU_ITEM_MEDIA_IF1_M4_WP_SET,
148   UI_MENU_ITEM_MEDIA_IF1_M5_EJECT,
149   UI_MENU_ITEM_MEDIA_IF1_M5_WP_SET,
150   UI_MENU_ITEM_MEDIA_IF1_M6_EJECT,
151   UI_MENU_ITEM_MEDIA_IF1_M6_WP_SET,
152   UI_MENU_ITEM_MEDIA_IF1_M7_EJECT,
153   UI_MENU_ITEM_MEDIA_IF1_M7_WP_SET,
154   UI_MENU_ITEM_MEDIA_IF1_M8_EJECT,
155   UI_MENU_ITEM_MEDIA_IF1_M8_WP_SET,
156   UI_MENU_ITEM_MEDIA_IF1_RS232_UNPLUG_R,
157   UI_MENU_ITEM_MEDIA_IF1_RS232_UNPLUG_T,
158   UI_MENU_ITEM_MEDIA_IF1_SNET_UNPLUG,
159   UI_MENU_ITEM_MEDIA_CARTRIDGE_IF2,
160   UI_MENU_ITEM_MEDIA_CARTRIDGE_IF2_EJECT,
161   UI_MENU_ITEM_MEDIA_DISK,
162   UI_MENU_ITEM_MEDIA_DISK_PLUS3,
163   UI_MENU_ITEM_MEDIA_DISK_PLUS3_A_EJECT,
164   UI_MENU_ITEM_MEDIA_DISK_PLUS3_A_FLIP_SET,
165   UI_MENU_ITEM_MEDIA_DISK_PLUS3_A_WP_SET,
166   UI_MENU_ITEM_MEDIA_DISK_PLUS3_B,
167   UI_MENU_ITEM_MEDIA_DISK_PLUS3_B_EJECT,
168   UI_MENU_ITEM_MEDIA_DISK_PLUS3_B_FLIP_SET,
169   UI_MENU_ITEM_MEDIA_DISK_PLUS3_B_WP_SET,
170   UI_MENU_ITEM_MEDIA_DISK_BETA,
171   UI_MENU_ITEM_MEDIA_DISK_BETA_A,
172   UI_MENU_ITEM_MEDIA_DISK_BETA_A_EJECT,
173   UI_MENU_ITEM_MEDIA_DISK_BETA_A_FLIP_SET,
174   UI_MENU_ITEM_MEDIA_DISK_BETA_A_WP_SET,
175   UI_MENU_ITEM_MEDIA_DISK_BETA_B,
176   UI_MENU_ITEM_MEDIA_DISK_BETA_B_EJECT,
177   UI_MENU_ITEM_MEDIA_DISK_BETA_B_FLIP_SET,
178   UI_MENU_ITEM_MEDIA_DISK_BETA_B_WP_SET,
179   UI_MENU_ITEM_MEDIA_DISK_BETA_C,
180   UI_MENU_ITEM_MEDIA_DISK_BETA_C_EJECT,
181   UI_MENU_ITEM_MEDIA_DISK_BETA_C_FLIP_SET,
182   UI_MENU_ITEM_MEDIA_DISK_BETA_C_WP_SET,
183   UI_MENU_ITEM_MEDIA_DISK_BETA_D,
184   UI_MENU_ITEM_MEDIA_DISK_BETA_D_EJECT,
185   UI_MENU_ITEM_MEDIA_DISK_BETA_D_FLIP_SET,
186   UI_MENU_ITEM_MEDIA_DISK_BETA_D_WP_SET,
187   UI_MENU_ITEM_MEDIA_DISK_PLUSD,
188   UI_MENU_ITEM_MEDIA_DISK_PLUSD_1,
189   UI_MENU_ITEM_MEDIA_DISK_PLUSD_1_EJECT,
190   UI_MENU_ITEM_MEDIA_DISK_PLUSD_1_FLIP_SET,
191   UI_MENU_ITEM_MEDIA_DISK_PLUSD_1_WP_SET,
192   UI_MENU_ITEM_MEDIA_DISK_PLUSD_2,
193   UI_MENU_ITEM_MEDIA_DISK_PLUSD_2_EJECT,
194   UI_MENU_ITEM_MEDIA_DISK_PLUSD_2_FLIP_SET,
195   UI_MENU_ITEM_MEDIA_DISK_PLUSD_2_WP_SET,
196   UI_MENU_ITEM_MEDIA_DISK_DISCIPLE,
197   UI_MENU_ITEM_MEDIA_DISK_DISCIPLE_1,
198   UI_MENU_ITEM_MEDIA_DISK_DISCIPLE_1_EJECT,
199   UI_MENU_ITEM_MEDIA_DISK_DISCIPLE_1_FLIP_SET,
200   UI_MENU_ITEM_MEDIA_DISK_DISCIPLE_1_WP_SET,
201   UI_MENU_ITEM_MEDIA_DISK_DISCIPLE_2,
202   UI_MENU_ITEM_MEDIA_DISK_DISCIPLE_2_EJECT,
203   UI_MENU_ITEM_MEDIA_DISK_DISCIPLE_2_FLIP_SET,
204   UI_MENU_ITEM_MEDIA_DISK_DISCIPLE_2_WP_SET,
205   UI_MENU_ITEM_MEDIA_DISK_OPUS,
206   UI_MENU_ITEM_MEDIA_DISK_OPUS_1,
207   UI_MENU_ITEM_MEDIA_DISK_OPUS_1_EJECT,
208   UI_MENU_ITEM_MEDIA_DISK_OPUS_1_FLIP_SET,
209   UI_MENU_ITEM_MEDIA_DISK_OPUS_1_WP_SET,
210   UI_MENU_ITEM_MEDIA_DISK_OPUS_2,
211   UI_MENU_ITEM_MEDIA_DISK_OPUS_2_EJECT,
212   UI_MENU_ITEM_MEDIA_DISK_OPUS_2_FLIP_SET,
213   UI_MENU_ITEM_MEDIA_DISK_OPUS_2_WP_SET,
214   UI_MENU_ITEM_MEDIA_IDE,
215   UI_MENU_ITEM_MEDIA_IDE_SIMPLE8BIT,
216   UI_MENU_ITEM_MEDIA_IDE_SIMPLE8BIT_MASTER_EJECT,
217   UI_MENU_ITEM_MEDIA_IDE_SIMPLE8BIT_SLAVE_EJECT,
218   UI_MENU_ITEM_MEDIA_IDE_ZXATASP,
219   UI_MENU_ITEM_MEDIA_IDE_ZXATASP_MASTER_EJECT,
220   UI_MENU_ITEM_MEDIA_IDE_ZXATASP_SLAVE_EJECT,
221   UI_MENU_ITEM_MEDIA_IDE_ZXCF,
222   UI_MENU_ITEM_MEDIA_IDE_ZXCF_EJECT,
223   UI_MENU_ITEM_MEDIA_IDE_DIVIDE,
224   UI_MENU_ITEM_MEDIA_IDE_DIVIDE_MASTER_EJECT,
225   UI_MENU_ITEM_MEDIA_IDE_DIVIDE_SLAVE_EJECT,
226   UI_MENU_ITEM_RECORDING,
227   UI_MENU_ITEM_RECORDING_ROLLBACK,
228   UI_MENU_ITEM_AY_LOGGING,
229   UI_MENU_ITEM_TAPE_RECORDING,
230 
231 } ui_menu_item;
232 
233 int ui_menu_activate( ui_menu_item item, int active );
234 int ui_menu_item_set_active( const char *path, int active );
235 
236 void ui_menu_disk_update( void );
237 
238 /* Functions to update the statusbar */
239 
240 typedef enum ui_statusbar_item {
241 
242   UI_STATUSBAR_ITEM_DISK,
243   UI_STATUSBAR_ITEM_MICRODRIVE,
244   UI_STATUSBAR_ITEM_MOUSE,
245   UI_STATUSBAR_ITEM_PAUSED,
246   UI_STATUSBAR_ITEM_TAPE,
247 
248 } ui_statusbar_item;
249 
250 typedef enum ui_statusbar_state {
251 
252   UI_STATUSBAR_STATE_NOT_AVAILABLE,
253   UI_STATUSBAR_STATE_INACTIVE,
254   UI_STATUSBAR_STATE_ACTIVE,
255 
256 } ui_statusbar_state;
257 
258 int ui_statusbar_update( ui_statusbar_item item, ui_statusbar_state state );
259 int ui_statusbar_update_speed( float speed );
260 
261 typedef enum ui_tape_browser_update_type {
262 
263   UI_TAPE_BROWSER_NEW_TAPE,             /* Whole tape image has changed
264                                            implies modified reset */
265   UI_TAPE_BROWSER_SELECT_BLOCK,         /* Tape block selected has changed */
266   UI_TAPE_BROWSER_NEW_BLOCK,            /* A new block has been appended,
267                                            implies modified set */
268   UI_TAPE_BROWSER_MODIFIED,             /* Tape modified status has changed */
269 
270 } ui_tape_browser_update_type;
271 
272 /* Cause the tape browser to be updated */
273 int ui_tape_browser_update( ui_tape_browser_update_type change,
274                             libspectrum_tape_block *block );
275 
276 char *ui_get_open_filename( const char *title );
277 char *ui_get_save_filename( const char *title );
278 int ui_query( const char *message );
279 
280 #ifdef USE_WIDGET
281 #include "ui/widget/widget.h"
282 #define ui_widget_finish() widget_finish()
283 #else				/* #ifdef USE_WIDGET */
284 #define ui_widget_finish()
285 #endif				/* #ifdef USE_WIDGET */
286 
287 /* Code called at start and end of emulation if widget system is used */
288 int ui_widget_init( void );
289 int ui_widget_end( void );
290 
291 /* How many levels deep have we recursed through widgets; -1 => none */
292 extern int ui_widget_level;
293 
294 /* widget system popup the apropriate menu */
295 void ui_popup_menu( int native_key );
296 
297 void ui_widget_keyhandler( int native_key );
298 
299 void ui_pokemem_selector( const char *filename );
300 
301 #endif			/* #ifndef FUSE_UI_H */
302