change PANIC to ERROR
[bochs-mirror.git] / gui / gui.h
blob475f26d0efb68f7e2d215b5c8d911971791edcea
1 /////////////////////////////////////////////////////////////////////////
2 // $Id: gui.h,v 1.59 2008/10/06 22:00:11 sshwarts Exp $
3 /////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (C) 2002 MandrakeSoft S.A.
6 //
7 // MandrakeSoft S.A.
8 // 43, rue d'Aboukir
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
41 typedef struct {
42 Bit16u start_address;
43 Bit8u cs_start;
44 Bit8u cs_end;
45 Bit16u line_offset;
46 Bit16u line_compare;
47 Bit8u h_panning;
48 Bit8u v_panning;
49 bx_bool line_graphics;
50 bx_bool split_hpanning;
51 Bit8u blink_flags;
52 } bx_vga_tminfo_t;
54 typedef struct {
55 Bit16u bpp, pitch;
56 Bit8u red_shift, green_shift, blue_shift;
57 Bit8u is_indexed, is_little_endian;
58 unsigned long red_mask, green_mask, blue_mask;
59 } bx_svga_tileinfo_t;
62 BOCHSAPI extern class bx_gui_c *bx_gui;
64 #if BX_SUPPORT_X86_64
65 #define BOCHS_WINDOW_NAME "Bochs x86-64 emulator, http://bochs.sourceforge.net/"
66 #else
67 #define BOCHS_WINDOW_NAME "Bochs x86 emulator, http://bochs.sourceforge.net/"
68 #endif
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 {
73 public:
74 bx_gui_c (void);
75 virtual ~bx_gui_c ();
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
111 // have no effect.
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) {}
116 #if BX_USE_IDLE_HACK
117 // this is called from the CPU model when the HLT instruction is executed.
118 virtual void sim_is_idle(void) {}
119 #endif
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);
134 void cleanup(void);
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);
142 protected:
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;
180 bx_bool new_gfx_api;
181 Bit16u host_xres;
182 Bit16u host_yres;
183 Bit16u host_pitch;
184 Bit8u host_bpp;
185 Bit8u *framebuffer;
186 Bit32u dialog_caps;
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 {
194 // public:
195 // bx_rfb_gui_c (void) {}
196 // DECLARE_GUI_VIRTUAL_METHODS()
197 // };
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, \
217 void (*f)(void)); \
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
251 #define BX_KEY_F1 2
252 #define BX_KEY_F2 3
253 #define BX_KEY_F3 4
254 #define BX_KEY_F4 5
255 #define BX_KEY_F5 6
256 #define BX_KEY_F6 7
257 #define BX_KEY_F7 8
258 #define BX_KEY_F8 9
259 #define BX_KEY_F9 10
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
271 #define BX_KEY_A 20
272 #define BX_KEY_B 21
273 #define BX_KEY_C 22
274 #define BX_KEY_D 23
275 #define BX_KEY_E 24
276 #define BX_KEY_F 25
277 #define BX_KEY_G 26
278 #define BX_KEY_H 27
279 #define BX_KEY_I 28
280 #define BX_KEY_J 29
281 #define BX_KEY_K 30
282 #define BX_KEY_L 31
283 #define BX_KEY_M 32
284 #define BX_KEY_N 33
285 #define BX_KEY_O 34
286 #define BX_KEY_P 35
287 #define BX_KEY_Q 36
288 #define BX_KEY_R 37
289 #define BX_KEY_S 38
290 #define BX_KEY_T 39
291 #define BX_KEY_U 40
292 #define BX_KEY_V 41
293 #define BX_KEY_W 42
294 #define BX_KEY_X 43
295 #define BX_KEY_Y 44
296 #define BX_KEY_Z 45
298 #define BX_KEY_0 46
299 #define BX_KEY_1 47
300 #define BX_KEY_2 48
301 #define BX_KEY_3 49
302 #define BX_KEY_4 50
303 #define BX_KEY_5 51
304 #define BX_KEY_6 52
305 #define BX_KEY_7 53
306 #define BX_KEY_8 54
307 #define BX_KEY_9 55
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
356 #define BX_KEY_UP 95
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
388 // - BX_KEY_NBKEYS
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
398 // in each one.
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
402 // says:
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 (); \
410 bx_gui = theGui; \
411 return(0); /* Success */ \
413 void lib##gui_name##_LTX_plugin_fini(void) { }