1 /////////////////////////////////////////////////////////////////////////
2 // $Id: gui.h,v 1.59 2008/10/06 22:00:11 sshwarts Exp $
3 /////////////////////////////////////////////////////////////////////////
5 // Copyright (C) 2002 MandrakeSoft S.A.
9 // 75002 Paris - France
10 // http://www.linux-mandrake.com/
11 // http://www.mandrakesoft.com/
13 // This library is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU Lesser General Public
15 // License as published by the Free Software Foundation; either
16 // version 2 of the License, or (at your option) any later version.
18 // This library is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 // Lesser General Public License for more details.
23 // You should have received a copy of the GNU Lesser General Public
24 // License along with this library; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #define BX_MAX_STATUSITEMS 10
29 #define BX_GUI_DLG_FLOPPY 0x01
30 #define BX_GUI_DLG_CDROM 0x02
31 #define BX_GUI_DLG_SNAPSHOT 0x04
32 #define BX_GUI_DLG_RUNTIME 0x08
33 #define BX_GUI_DLG_USER 0x10
34 #define BX_GUI_DLG_SAVE_RESTORE 0x20
35 #define BX_GUI_DLG_ALL 0x3F
37 #define BX_TEXT_BLINK_MODE 0x01
38 #define BX_TEXT_BLINK_TOGGLE 0x02
39 #define BX_TEXT_BLINK_STATE 0x04
49 bx_bool line_graphics
;
50 bx_bool split_hpanning
;
56 Bit8u red_shift
, green_shift
, blue_shift
;
57 Bit8u is_indexed
, is_little_endian
;
58 unsigned long red_mask
, green_mask
, blue_mask
;
62 BOCHSAPI
extern class bx_gui_c
*bx_gui
;
65 #define BOCHS_WINDOW_NAME "Bochs x86-64 emulator, http://bochs.sourceforge.net/"
67 #define BOCHS_WINDOW_NAME "Bochs x86 emulator, http://bochs.sourceforge.net/"
70 // The bx_gui_c class provides data and behavior that is common to
71 // all guis. Each gui implementation will override the abstract methods.
72 class BOCHSAPI bx_gui_c
: public logfunctions
{
76 // Define the following functions in the module for your particular GUI
77 // (x.cc, beos.cc, ...)
78 virtual void specific_init(int argc
, char **argv
,
79 unsigned x_tilesize
, unsigned y_tilesize
, unsigned header_bar_y
) = 0;
80 virtual void text_update(Bit8u
*old_text
, Bit8u
*new_text
,
81 unsigned long cursor_x
, unsigned long cursor_y
,
82 bx_vga_tminfo_t tm_info
) = 0;
83 virtual void graphics_tile_update(Bit8u
*snapshot
, unsigned x
, unsigned y
) = 0;
84 virtual bx_svga_tileinfo_t
*graphics_tile_info(bx_svga_tileinfo_t
*info
);
85 virtual Bit8u
*graphics_tile_get(unsigned x
, unsigned y
, unsigned *w
, unsigned *h
);
86 virtual void graphics_tile_update_in_place(unsigned x
, unsigned y
, unsigned w
, unsigned h
);
87 virtual void handle_events(void) = 0;
88 virtual void flush(void) = 0;
89 virtual void clear_screen(void) = 0;
90 virtual bx_bool
palette_change(unsigned index
, unsigned red
, unsigned green
, unsigned blue
) = 0;
91 virtual void dimension_update(unsigned x
, unsigned y
, unsigned fheight
=0, unsigned fwidth
=0, unsigned bpp
=8) = 0;
92 virtual unsigned create_bitmap(const unsigned char *bmap
, unsigned xdim
, unsigned ydim
) = 0;
93 virtual unsigned headerbar_bitmap(unsigned bmap_id
, unsigned alignment
, void (*f
)(void)) = 0;
94 virtual void replace_bitmap(unsigned hbar_id
, unsigned bmap_id
) = 0;
95 virtual void show_headerbar(void) = 0;
96 virtual int get_clipboard_text(Bit8u
**bytes
, Bit32s
*nbytes
) = 0;
97 virtual int set_clipboard_text(char *snapshot
, Bit32u len
) = 0;
98 virtual void mouse_enabled_changed_specific (bx_bool val
) = 0;
99 virtual void statusbar_setitem(int element
, bx_bool active
, bx_bool w
=0) {}
100 virtual void set_tooltip(unsigned hbar_id
, const char *tip
) {}
101 virtual void exit(void) = 0;
102 // set_display_mode() changes the mode between the configuration interface
103 // and the simulation. This is primarily intended for display libraries
104 // which have a full-screen mode such as SDL, term, and svgalib. The display
105 // mode is set to DISP_MODE_CONFIG before displaying any configuration menus,
106 // for panics that requires user input, when entering the debugger, etc. It
107 // is set to DISP_MODE_SIM when the Bochs simulation resumes. The
108 // enum is defined in gui/siminterface.h.
109 virtual void set_display_mode (disp_mode_t newmode
) { /* default=no action*/ }
110 // These are only needed for the term gui. For all other guis they will
112 // returns 32-bit bitmask in which 1 means the GUI should handle that signal
113 virtual Bit32u
get_sighandler_mask () {return 0;}
114 // called when registered signal arrives
115 virtual void sighandler (int sig
) {}
117 // this is called from the CPU model when the HLT instruction is executed.
118 virtual void sim_is_idle(void) {}
120 virtual void show_ips(Bit32u ips_count
);
121 virtual void beep_on(float frequency
);
122 virtual void beep_off();
123 virtual void get_capabilities(Bit16u
*xres
, Bit16u
*yres
, Bit16u
*bpp
);
125 // The following function(s) are defined already, and your
126 // GUI code calls them
127 static void key_event(Bit32u key
);
128 static void set_text_charmap(Bit8u
*fbuffer
);
129 static void set_text_charbyte(Bit16u address
, Bit8u data
);
130 static Bit8u
get_mouse_headerbar_id();
132 void init(int argc
, char **argv
,
133 unsigned x_tilesize
, unsigned y_tilesize
);
135 void update_drive_status_buttons(void);
136 static void mouse_enabled_changed(bx_bool val
);
137 int register_statusitem(const char *text
);
138 static void init_signal_handlers();
139 static void toggle_mouse_enable(void);
143 // And these are defined and used privately in gui.cc
144 static Bit32s
make_text_snapshot (char **snapshot
, Bit32u
*length
);
145 static void floppyA_handler(void);
146 static void floppyB_handler(void);
147 static void cdromD_handler(void);
148 static void reset_handler(void);
149 static void power_handler(void);
150 static void copy_handler(void);
151 static void paste_handler(void);
152 static void snapshot_handler(void);
153 static void snapshot_checker(void *);
154 static void config_handler(void);
155 static void userbutton_handler(void);
156 static void save_restore_handler(void);
158 bx_bool floppyA_status
;
159 bx_bool floppyB_status
;
160 bx_bool cdromD_status
;
161 unsigned floppyA_bmap_id
, floppyA_eject_bmap_id
, floppyA_hbar_id
;
162 unsigned floppyB_bmap_id
, floppyB_eject_bmap_id
, floppyB_hbar_id
;
163 unsigned cdromD_bmap_id
, cdromD_eject_bmap_id
, cdromD_hbar_id
;
164 unsigned power_bmap_id
, power_hbar_id
;
165 unsigned reset_bmap_id
, reset_hbar_id
;
166 unsigned copy_bmap_id
, copy_hbar_id
;
167 unsigned paste_bmap_id
, paste_hbar_id
;
168 unsigned snapshot_bmap_id
, snapshot_hbar_id
;
169 unsigned config_bmap_id
, config_hbar_id
;
170 unsigned mouse_bmap_id
, nomouse_bmap_id
, mouse_hbar_id
;
171 unsigned user_bmap_id
, user_hbar_id
;
172 unsigned save_restore_bmap_id
, save_restore_hbar_id
;
174 unsigned char vga_charmap
[0x2000];
175 bx_bool charmap_updated
;
176 bx_bool char_changed
[256];
177 unsigned statusitem_count
;
178 char statusitem_text
[BX_MAX_STATUSITEMS
][8];
179 disp_mode_t disp_mode
;
190 // Add this macro in the class declaration of each GUI, to define all the
191 // required virtual methods. Example:
193 // class bx_rfb_gui_c : public bx_gui_c {
195 // bx_rfb_gui_c (void) {}
196 // DECLARE_GUI_VIRTUAL_METHODS()
198 // Then, each method must be defined later in the file.
199 #define DECLARE_GUI_VIRTUAL_METHODS() \
200 virtual void specific_init(int argc, char **argv, \
201 unsigned x_tilesize, unsigned y_tilesize, \
202 unsigned header_bar_y); \
203 virtual void text_update(Bit8u *old_text, Bit8u *new_text, \
204 unsigned long cursor_x, unsigned long cursor_y, \
205 bx_vga_tminfo_t tm_info); \
206 virtual void graphics_tile_update(Bit8u *snapshot, unsigned x, unsigned y); \
207 virtual void handle_events(void); \
208 virtual void flush(void); \
209 virtual void clear_screen(void); \
210 virtual bx_bool palette_change(unsigned index, \
211 unsigned red, unsigned green, unsigned blue); \
212 virtual void dimension_update(unsigned x, unsigned y, unsigned fheight=0, \
213 unsigned fwidth=0, unsigned bpp=8); \
214 virtual unsigned create_bitmap(const unsigned char *bmap, \
215 unsigned xdim, unsigned ydim); \
216 virtual unsigned headerbar_bitmap(unsigned bmap_id, unsigned alignment, \
218 virtual void replace_bitmap(unsigned hbar_id, unsigned bmap_id); \
219 virtual void show_headerbar(void); \
220 virtual int get_clipboard_text(Bit8u **bytes, Bit32s *nbytes); \
221 virtual int set_clipboard_text(char *snapshot, Bit32u len); \
222 virtual void mouse_enabled_changed_specific (bx_bool val); \
223 virtual void exit(void); \
224 /* end of DECLARE_GUI_VIRTUAL_METHODS */
226 #define DECLARE_GUI_NEW_VIRTUAL_METHODS() \
227 virtual bx_svga_tileinfo_t *graphics_tile_info(bx_svga_tileinfo_t *info); \
228 virtual Bit8u *graphics_tile_get(unsigned x, unsigned y, \
229 unsigned *w, unsigned *h); \
230 virtual void graphics_tile_update_in_place(unsigned x, unsigned y, \
231 unsigned w, unsigned h);
232 /* end of DECLARE_GUI_NEW_VIRTUAL_METHODS */
234 #define BX_HEADER_BAR_Y 32
236 #define BX_MAX_PIXMAPS 17
237 #define BX_MAX_HEADERBAR_ENTRIES 12
239 // align pixmaps towards left or right side of header bar
240 #define BX_GRAVITY_LEFT 10
241 #define BX_GRAVITY_RIGHT 11
243 #define BX_KEY_PRESSED 0x00000000
244 #define BX_KEY_RELEASED 0x80000000
246 #define BX_KEY_UNHANDLED 0x10000000
248 #define BX_KEY_CTRL_L 0
249 #define BX_KEY_SHIFT_L 1
260 #define BX_KEY_F10 11
261 #define BX_KEY_F11 12
262 #define BX_KEY_F12 13
264 #define BX_KEY_CTRL_R 14
265 #define BX_KEY_SHIFT_R 15
266 #define BX_KEY_CAPS_LOCK 16
267 #define BX_KEY_NUM_LOCK 17
268 #define BX_KEY_ALT_L 18
269 #define BX_KEY_ALT_R 19
309 #define BX_KEY_ESC 56
311 #define BX_KEY_SPACE 57
312 #define BX_KEY_SINGLE_QUOTE 58
313 #define BX_KEY_COMMA 59
314 #define BX_KEY_PERIOD 60
315 #define BX_KEY_SLASH 61
317 #define BX_KEY_SEMICOLON 62
318 #define BX_KEY_EQUALS 63
320 #define BX_KEY_LEFT_BRACKET 64
321 #define BX_KEY_BACKSLASH 65
322 #define BX_KEY_RIGHT_BRACKET 66
323 #define BX_KEY_MINUS 67
324 #define BX_KEY_GRAVE 68
326 #define BX_KEY_BACKSPACE 69
327 #define BX_KEY_ENTER 70
328 #define BX_KEY_TAB 71
330 #define BX_KEY_LEFT_BACKSLASH 72
331 #define BX_KEY_PRINT 73
332 #define BX_KEY_SCRL_LOCK 74
333 #define BX_KEY_PAUSE 75
335 #define BX_KEY_INSERT 76
336 #define BX_KEY_DELETE 77
337 #define BX_KEY_HOME 78
338 #define BX_KEY_END 79
339 #define BX_KEY_PAGE_UP 80
340 #define BX_KEY_PAGE_DOWN 81
342 #define BX_KEY_KP_ADD 82
343 #define BX_KEY_KP_SUBTRACT 83
344 #define BX_KEY_KP_END 84
345 #define BX_KEY_KP_DOWN 85
346 #define BX_KEY_KP_PAGE_DOWN 86
347 #define BX_KEY_KP_LEFT 87
348 #define BX_KEY_KP_RIGHT 88
349 #define BX_KEY_KP_HOME 89
350 #define BX_KEY_KP_UP 90
351 #define BX_KEY_KP_PAGE_UP 91
352 #define BX_KEY_KP_INSERT 92
353 #define BX_KEY_KP_DELETE 93
354 #define BX_KEY_KP_5 94
357 #define BX_KEY_DOWN 96
358 #define BX_KEY_LEFT 97
359 #define BX_KEY_RIGHT 98
361 #define BX_KEY_KP_ENTER 99
362 #define BX_KEY_KP_MULTIPLY 100
363 #define BX_KEY_KP_DIVIDE 101
365 #define BX_KEY_WIN_L 102
366 #define BX_KEY_WIN_R 103
367 #define BX_KEY_MENU 104
369 #define BX_KEY_ALT_SYSREQ 105
370 #define BX_KEY_CTRL_BREAK 106
372 #define BX_KEY_INT_BACK 107
373 #define BX_KEY_INT_FORWARD 108
374 #define BX_KEY_INT_STOP 109
375 #define BX_KEY_INT_MAIL 110
376 #define BX_KEY_INT_SEARCH 111
377 #define BX_KEY_INT_FAV 112
378 #define BX_KEY_INT_HOME 113
380 #define BX_KEY_POWER_MYCOMP 114
381 #define BX_KEY_POWER_CALC 115
382 #define BX_KEY_POWER_SLEEP 116
383 #define BX_KEY_POWER_POWER 117
384 #define BX_KEY_POWER_WAKE 118
386 #define BX_KEY_NBKEYS 119
387 // If you add BX_KEYs Please update
389 // - the scancodes table in the file iodev/scancodes.cc
390 // - the bx_key_symbol table in the file gui/keymap.cc
393 /////////////// GUI plugin support
395 // Define macro to supply gui plugin code. This macro is called once in GUI to
396 // supply the plugin initialization methods. Since it is nearly identical for
397 // each gui module, the macro is easier to maintain than pasting the same code
400 // Each gui should declare a class pointer called "theGui" which is derived
401 // from bx_gui_c, before calling this macro. For example, the SDL port
403 // static bx_sdl_gui_c *theGui;
405 #define IMPLEMENT_GUI_PLUGIN_CODE(gui_name) \
406 int lib##gui_name##_LTX_plugin_init(plugin_t *plugin, \
407 plugintype_t type, int argc, char *argv[]) { \
408 genlog->info("installing %s module as the Bochs GUI", #gui_name); \
409 theGui = new bx_##gui_name##_gui_c (); \
411 return(0); /* Success */ \
413 void lib##gui_name##_LTX_plugin_fini(void) { }