OpenCores
URL https://opencores.org/ocsvn/zet86/zet86/trunk

Subversion Repositories zet86

[/] [zet86/] [trunk/] [src/] [bochs-diff-2.3.7/] [gui/] [gui.cc] - Blame information for rev 52

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 39 zeus
/////////////////////////////////////////////////////////////////////////
2 52 zeus
// $Id: gui.cc,v 1.105 2008/05/04 09:29:45 vruppert Exp $
3 39 zeus
/////////////////////////////////////////////////////////////////////////
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/
12
//
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.
17
//
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.
22
//
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
26
 
27
 
28
#include <signal.h>
29
#include "bochs.h"
30
#include "iodev.h"
31
#include "gui/bitmaps/floppya.h"
32
#include "gui/bitmaps/floppyb.h"
33
#include "gui/bitmaps/mouse.h"
34
#include "gui/bitmaps/reset.h"
35
#include "gui/bitmaps/power.h"
36
#include "gui/bitmaps/snapshot.h"
37
#include "gui/bitmaps/copy.h"
38
#include "gui/bitmaps/paste.h"
39
#include "gui/bitmaps/configbutton.h"
40
#include "gui/bitmaps/cdromd.h"
41
#include "gui/bitmaps/userbutton.h"
42
#include "gui/bitmaps/saverestore.h"
43
 
44
#if BX_WITH_MACOS
45
#  include <Disks.h>
46
#endif
47
 
48
bx_gui_c *bx_gui = NULL;
49
 
50
#define BX_GUI_THIS bx_gui->
51
#define LOG_THIS BX_GUI_THIS
52
 
53
#define BX_KEY_UNKNOWN 0x7fffffff
54
#define N_USER_KEYS 37
55
 
56
typedef struct {
57
  const char *key;
58
  Bit32u symbol;
59
} user_key_t;
60
 
61
static user_key_t user_keys[N_USER_KEYS] =
62
{
63
  { "f1",    BX_KEY_F1 },
64
  { "f2",    BX_KEY_F2 },
65
  { "f3",    BX_KEY_F3 },
66
  { "f4",    BX_KEY_F4 },
67
  { "f5",    BX_KEY_F5 },
68
  { "f6",    BX_KEY_F6 },
69
  { "f7",    BX_KEY_F7 },
70
  { "f8",    BX_KEY_F8 },
71
  { "f9",    BX_KEY_F9 },
72
  { "f10",   BX_KEY_F10 },
73
  { "f11",   BX_KEY_F11 },
74
  { "f12",   BX_KEY_F12 },
75
  { "alt",   BX_KEY_ALT_L },
76
  { "bksl",  BX_KEY_BACKSLASH },
77
  { "bksp",  BX_KEY_BACKSPACE },
78
  { "ctrl",  BX_KEY_CTRL_L },
79
  { "del",   BX_KEY_DELETE },
80
  { "down",  BX_KEY_DOWN },
81
  { "end",   BX_KEY_END },
82
  { "enter", BX_KEY_ENTER },
83
  { "esc",   BX_KEY_ESC },
84
  { "home",  BX_KEY_HOME },
85
  { "ins",   BX_KEY_INSERT },
86
  { "left",  BX_KEY_LEFT },
87
  { "menu",  BX_KEY_MENU },
88
  { "minus", BX_KEY_MINUS },
89
  { "pgdwn", BX_KEY_PAGE_DOWN },
90
  { "pgup",  BX_KEY_PAGE_UP },
91
  { "plus",  BX_KEY_KP_ADD },
92
  { "right", BX_KEY_RIGHT },
93
  { "shift", BX_KEY_SHIFT_L },
94
  { "space", BX_KEY_SPACE },
95
  { "tab",   BX_KEY_TAB },
96
  { "up",    BX_KEY_UP },
97
  { "win",   BX_KEY_WIN_L },
98
  { "print", BX_KEY_PRINT },
99
  { "power", BX_KEY_POWER_POWER }
100
};
101
 
102
bx_gui_c::bx_gui_c(void)
103
{
104
  put("GUI"); // Init in specific_init
105
  settype(GUILOG);
106
  statusitem_count = 0;
107
  framebuffer = NULL;
108
}
109
 
110
bx_gui_c::~bx_gui_c()
111
{
112
  if (framebuffer != NULL) {
113
    delete [] framebuffer;
114
  }
115
}
116
 
117
void bx_gui_c::init(int argc, char **argv, unsigned tilewidth, unsigned tileheight)
118
{
119
  BX_GUI_THIS new_gfx_api = 0;
120
  BX_GUI_THIS host_xres = 640;
121
  BX_GUI_THIS host_yres = 480;
122
  BX_GUI_THIS host_bpp = 8;
123
  BX_GUI_THIS dialog_caps = BX_GUI_DLG_RUNTIME | BX_GUI_DLG_SAVE_RESTORE;
124
 
125
  specific_init(argc, argv, tilewidth, tileheight, BX_HEADER_BAR_Y);
126
 
127
  // Define some bitmaps to use in the headerbar
128
  BX_GUI_THIS floppyA_bmap_id = create_bitmap(bx_floppya_bmap,
129
                          BX_FLOPPYA_BMAP_X, BX_FLOPPYA_BMAP_Y);
130
  BX_GUI_THIS floppyA_eject_bmap_id = create_bitmap(bx_floppya_eject_bmap,
131
                          BX_FLOPPYA_BMAP_X, BX_FLOPPYA_BMAP_Y);
132
  BX_GUI_THIS floppyB_bmap_id = create_bitmap(bx_floppyb_bmap,
133
                          BX_FLOPPYB_BMAP_X, BX_FLOPPYB_BMAP_Y);
134
  BX_GUI_THIS floppyB_eject_bmap_id = create_bitmap(bx_floppyb_eject_bmap,
135
                          BX_FLOPPYB_BMAP_X, BX_FLOPPYB_BMAP_Y);
136
  BX_GUI_THIS cdromD_bmap_id = create_bitmap(bx_cdromd_bmap,
137
                          BX_CDROMD_BMAP_X, BX_CDROMD_BMAP_Y);
138
  BX_GUI_THIS cdromD_eject_bmap_id = create_bitmap(bx_cdromd_eject_bmap,
139
                          BX_CDROMD_BMAP_X, BX_CDROMD_BMAP_Y);
140
  BX_GUI_THIS mouse_bmap_id = create_bitmap(bx_mouse_bmap,
141
                          BX_MOUSE_BMAP_X, BX_MOUSE_BMAP_Y);
142
  BX_GUI_THIS nomouse_bmap_id = create_bitmap(bx_nomouse_bmap,
143
                          BX_MOUSE_BMAP_X, BX_MOUSE_BMAP_Y);
144
 
145
  BX_GUI_THIS power_bmap_id = create_bitmap(bx_power_bmap, BX_POWER_BMAP_X, BX_POWER_BMAP_Y);
146
  BX_GUI_THIS reset_bmap_id = create_bitmap(bx_reset_bmap, BX_RESET_BMAP_X, BX_RESET_BMAP_Y);
147
  BX_GUI_THIS snapshot_bmap_id = create_bitmap(bx_snapshot_bmap, BX_SNAPSHOT_BMAP_X, BX_SNAPSHOT_BMAP_Y);
148
  BX_GUI_THIS copy_bmap_id = create_bitmap(bx_copy_bmap, BX_COPY_BMAP_X, BX_COPY_BMAP_Y);
149
  BX_GUI_THIS paste_bmap_id = create_bitmap(bx_paste_bmap, BX_PASTE_BMAP_X, BX_PASTE_BMAP_Y);
150
  BX_GUI_THIS config_bmap_id = create_bitmap(bx_config_bmap, BX_CONFIG_BMAP_X, BX_CONFIG_BMAP_Y);
151
  BX_GUI_THIS user_bmap_id = create_bitmap(bx_user_bmap, BX_USER_BMAP_X, BX_USER_BMAP_Y);
152
  BX_GUI_THIS save_restore_bmap_id = create_bitmap(bx_save_restore_bmap,
153
                          BX_SAVE_RESTORE_BMAP_X, BX_SAVE_RESTORE_BMAP_Y);
154
 
155
  // Add the initial bitmaps to the headerbar, and enable callback routine, for use
156
  // when that bitmap is clicked on
157
 
158
  // Floppy A:
159
//  BX_GUI_THIS floppyA_status = DEV_floppy_get_media_status(0);
160
BX_GUI_THIS floppyA_status = true;
161
  if (BX_GUI_THIS floppyA_status)
162
    BX_GUI_THIS floppyA_hbar_id = headerbar_bitmap(BX_GUI_THIS floppyA_bmap_id,
163
                          BX_GRAVITY_LEFT, floppyA_handler);
164
  else
165
    BX_GUI_THIS floppyA_hbar_id = headerbar_bitmap(BX_GUI_THIS floppyA_eject_bmap_id,
166
                          BX_GRAVITY_LEFT, floppyA_handler);
167
  BX_GUI_THIS set_tooltip(BX_GUI_THIS floppyA_hbar_id, "Change floppy A: media");
168
 
169
  // Floppy B:
170
//  BX_GUI_THIS floppyB_status = DEV_floppy_get_media_status(1);
171
BX_GUI_THIS floppyB_status = false;
172
  if (BX_GUI_THIS floppyB_status)
173
    BX_GUI_THIS floppyB_hbar_id = headerbar_bitmap(BX_GUI_THIS floppyB_bmap_id,
174
                          BX_GRAVITY_LEFT, floppyB_handler);
175
  else
176
    BX_GUI_THIS floppyB_hbar_id = headerbar_bitmap(BX_GUI_THIS floppyB_eject_bmap_id,
177
                          BX_GRAVITY_LEFT, floppyB_handler);
178
  BX_GUI_THIS set_tooltip(BX_GUI_THIS floppyB_hbar_id, "Change floppy B: media");
179
 
180
  // CDROM,
181
  // the harddrive object is not initialised yet,
182
  // so we just set the bitmap to ejected for now
183
  BX_GUI_THIS cdromD_hbar_id = headerbar_bitmap(BX_GUI_THIS cdromD_eject_bmap_id,
184
                          BX_GRAVITY_LEFT, cdromD_handler);
185
  BX_GUI_THIS set_tooltip(BX_GUI_THIS cdromD_hbar_id, "Change first CDROM media");
186
 
187
  // Mouse button
188
  if (SIM->get_param_bool(BXPN_MOUSE_ENABLED)->get())
189
    BX_GUI_THIS mouse_hbar_id = headerbar_bitmap(BX_GUI_THIS mouse_bmap_id,
190
                          BX_GRAVITY_LEFT, toggle_mouse_enable);
191
  else
192
    BX_GUI_THIS mouse_hbar_id = headerbar_bitmap(BX_GUI_THIS nomouse_bmap_id,
193
                          BX_GRAVITY_LEFT, toggle_mouse_enable);
194
  BX_GUI_THIS set_tooltip(BX_GUI_THIS mouse_hbar_id, "Enable mouse capture");
195
 
196
  // These are the buttons on the right side.  They are created in order
197
  // of right to left.
198
 
199
  // Power button
200
  BX_GUI_THIS power_hbar_id = headerbar_bitmap(BX_GUI_THIS power_bmap_id,
201
                          BX_GRAVITY_RIGHT, power_handler);
202
  BX_GUI_THIS set_tooltip(BX_GUI_THIS power_hbar_id, "Turn power off");
203
  // Save/Restore Button
204
  BX_GUI_THIS save_restore_hbar_id = headerbar_bitmap(BX_GUI_THIS save_restore_bmap_id,
205
                          BX_GRAVITY_RIGHT, save_restore_handler);
206
  BX_GUI_THIS set_tooltip(BX_GUI_THIS save_restore_hbar_id, "Save simulation state");
207
  // Reset button
208
  BX_GUI_THIS reset_hbar_id = headerbar_bitmap(BX_GUI_THIS reset_bmap_id,
209
                          BX_GRAVITY_RIGHT, reset_handler);
210
  BX_GUI_THIS set_tooltip(BX_GUI_THIS reset_hbar_id, "Reset the system");
211
  // Configure button
212
  BX_GUI_THIS config_hbar_id = headerbar_bitmap(BX_GUI_THIS config_bmap_id,
213
                          BX_GRAVITY_RIGHT, config_handler);
214
  BX_GUI_THIS set_tooltip(BX_GUI_THIS config_hbar_id, "Runtime config dialog");
215
  // Snapshot button
216
  BX_GUI_THIS snapshot_hbar_id = headerbar_bitmap(BX_GUI_THIS snapshot_bmap_id,
217
                          BX_GRAVITY_RIGHT, snapshot_handler);
218
  BX_GUI_THIS set_tooltip(BX_GUI_THIS snapshot_hbar_id, "Save snapshot of the text mode screen");
219
  // Paste button
220
  BX_GUI_THIS paste_hbar_id = headerbar_bitmap(BX_GUI_THIS paste_bmap_id,
221
                          BX_GRAVITY_RIGHT, paste_handler);
222
  BX_GUI_THIS set_tooltip(BX_GUI_THIS paste_hbar_id, "Paste clipboard text as emulated keystrokes");
223
  // Copy button
224
  BX_GUI_THIS copy_hbar_id = headerbar_bitmap(BX_GUI_THIS copy_bmap_id,
225
                          BX_GRAVITY_RIGHT, copy_handler);
226
  BX_GUI_THIS set_tooltip(BX_GUI_THIS copy_hbar_id, "Copy text mode screen to the clipboard");
227
  // User button
228
  BX_GUI_THIS user_hbar_id = headerbar_bitmap(BX_GUI_THIS user_bmap_id,
229
                          BX_GRAVITY_RIGHT, userbutton_handler);
230
  BX_GUI_THIS set_tooltip(BX_GUI_THIS user_hbar_id, "Send keyboard shortcut");
231
 
232
  if (SIM->get_param_bool(BXPN_TEXT_SNAPSHOT_CHECK)->get()) {
233
    bx_pc_system.register_timer(this, bx_gui_c::snapshot_checker, (unsigned) 1000000, 1, 1, "snap_chk");
234
  }
235
 
236
  BX_GUI_THIS charmap_updated = 0;
237
 
238
  if (!BX_GUI_THIS new_gfx_api && (BX_GUI_THIS framebuffer == NULL)) {
239
    BX_GUI_THIS framebuffer = new Bit8u[BX_MAX_XRES * BX_MAX_YRES * 4];
240
  }
241
  show_headerbar();
242
}
243
 
244
void bx_gui_c::cleanup(void)
245
{
246
  statusitem_count = 0;
247
}
248
 
249
void bx_gui_c::update_drive_status_buttons(void)
250
{
251
  BX_GUI_THIS floppyA_status = /* DEV_floppy_get_media_status(0)
252
    && */ (SIM->get_param_enum(BXPN_FLOPPYA_STATUS)->get() == BX_INSERTED);
253
  BX_GUI_THIS floppyB_status = false /*DEV_floppy_get_media_status(1)
254
    && (SIM->get_param_enum(BXPN_FLOPPYB_STATUS)->get() == BX_INSERTED) */;
255
  //Bit32u handle = DEV_hd_get_first_cd_handle();
256
  //BX_GUI_THIS cdromD_status = DEV_hd_get_cd_media_status(handle);
257
  BX_GUI_THIS cdromD_status = false;
258
  if (BX_GUI_THIS floppyA_status)
259
    replace_bitmap(BX_GUI_THIS floppyA_hbar_id, BX_GUI_THIS floppyA_bmap_id);
260
  else {
261
#if BX_WITH_MACOS
262
    // If we are using the Mac floppy driver, eject the disk
263
    // from the floppy drive.  This doesn't work in MacOS X.
264
    if (!strcmp(SIM->get_param_string(BXPN_FLOPPYA_PATH)->getptr(), SuperDrive))
265
      DiskEject(1);
266
#endif
267
    replace_bitmap(BX_GUI_THIS floppyA_hbar_id, BX_GUI_THIS floppyA_eject_bmap_id);
268
  }
269
  if (BX_GUI_THIS floppyB_status)
270
    replace_bitmap(BX_GUI_THIS floppyB_hbar_id, BX_GUI_THIS floppyB_bmap_id);
271
  else {
272
#if BX_WITH_MACOS
273
    // If we are using the Mac floppy driver, eject the disk
274
    // from the floppy drive.  This doesn't work in MacOS X.
275
    if (!strcmp(SIM->get_param_string(BXPN_FLOPPYB_PATH)->getptr(), SuperDrive))
276
      DiskEject(1);
277
#endif
278
    replace_bitmap(BX_GUI_THIS floppyB_hbar_id, BX_GUI_THIS floppyB_eject_bmap_id);
279
  }
280
  if (BX_GUI_THIS cdromD_status)
281
    replace_bitmap(BX_GUI_THIS cdromD_hbar_id, BX_GUI_THIS cdromD_bmap_id);
282
  else {
283
    replace_bitmap(BX_GUI_THIS cdromD_hbar_id, BX_GUI_THIS cdromD_eject_bmap_id);
284
  }
285
}
286
 
287
void bx_gui_c::floppyA_handler(void)
288
{
289
  if (SIM->get_param_enum(BXPN_FLOPPYA_DEVTYPE)->get() == BX_FLOPPY_NONE)
290
    return; // no primary floppy device present
291
  if (BX_GUI_THIS dialog_caps & BX_GUI_DLG_FLOPPY) {
292
    // instead of just toggling the status, call win32dialog to bring up
293
    // a dialog asking what disk image you want to switch to.
294
    int ret = SIM->ask_param(BXPN_FLOPPYA_PATH);
295
    if (ret > 0) {
296
      BX_GUI_THIS update_drive_status_buttons();
297
    }
298
    return;
299
  }
300
  BX_GUI_THIS floppyA_status = !BX_GUI_THIS floppyA_status;
301
  DEV_floppy_set_media_status(0, BX_GUI_THIS floppyA_status);
302
  BX_GUI_THIS update_drive_status_buttons();
303
}
304
 
305
void bx_gui_c::floppyB_handler(void)
306
{
307
  if (SIM->get_param_enum(BXPN_FLOPPYB_DEVTYPE)->get() == BX_FLOPPY_NONE)
308
    return; // no secondary floppy device present
309
  if (BX_GUI_THIS dialog_caps & BX_GUI_DLG_FLOPPY) {
310
    // instead of just toggling the status, call win32dialog to bring up
311
    // a dialog asking what disk image you want to switch to.
312
    int ret = SIM->ask_param(BXPN_FLOPPYB_PATH);
313
    if (ret > 0) {
314
      BX_GUI_THIS update_drive_status_buttons();
315
    }
316
    return;
317
  }
318
  BX_GUI_THIS floppyB_status = !BX_GUI_THIS floppyB_status;
319
  DEV_floppy_set_media_status(1, BX_GUI_THIS floppyB_status);
320
  BX_GUI_THIS update_drive_status_buttons();
321
}
322
 
323
void bx_gui_c::cdromD_handler(void)
324
{
325
  Bit32u handle = DEV_hd_get_first_cd_handle();
326
  if (BX_GUI_THIS dialog_caps & BX_GUI_DLG_CDROM) {
327
    // instead of just toggling the status, call win32dialog to bring up
328
    // a dialog asking what disk image you want to switch to.
329
    // This code handles the first cdrom only. The cdrom drives #2, #3 and
330
    // #4 are handled in the win32 runtime dialog.
331
    bx_param_c *cdrom = SIM->get_first_cdrom();
332
    if (cdrom == NULL)
333
      return;  // no cdrom found
334
    int ret = SIM->ask_param(cdrom);
335
    if (ret > 0) {
336
      BX_GUI_THIS update_drive_status_buttons();
337
    }
338
    return;
339
  }
340
  BX_GUI_THIS cdromD_status =
341
    DEV_hd_set_cd_media_status(handle, !BX_GUI_THIS cdromD_status);
342
  BX_GUI_THIS update_drive_status_buttons();
343
}
344
 
345
void bx_gui_c::reset_handler(void)
346
{
347
  BX_INFO(("system RESET callback"));
348
  bx_pc_system.Reset(BX_RESET_HARDWARE);
349
}
350
 
351
void bx_gui_c::power_handler(void)
352
{
353
  // test case for yes/no dialog: confirm power off
354
  //if (!SIM->ask_yes_no("Quit Bochs", "Are you sure ?", 0))
355
  //  return;
356
  // the user pressed power button, so there's no doubt they want bochs
357
  // to quit.  Change panics to fatal for the GUI and then do a panic.
358
  bx_user_quit = 1;
359
  LOG_THIS setonoff(LOGLEV_PANIC, ACT_FATAL);
360
  BX_PANIC (("POWER button turned off."));
361
  // shouldn't reach this point, but if you do, QUIT!!!
362
  fprintf (stderr, "Bochs is exiting because you pressed the power button.\n");
363
  BX_EXIT (1);
364
}
365
 
366
Bit32s bx_gui_c::make_text_snapshot(char **snapshot, Bit32u *length)
367
{
368
  Bit8u* raw_snap = NULL;
369
  char *clean_snap;
370
  unsigned line_addr, txt_addr, txHeight, txWidth;
371
 
372
  DEV_vga_get_text_snapshot(&raw_snap, &txHeight, &txWidth);
373
  if (txHeight <= 0) return -1;
374
  clean_snap = (char*) malloc(txHeight*(txWidth+2)+1);
375
  txt_addr = 0;
376
  for (unsigned i=0; i<txHeight; i++) {
377
    line_addr = i * txWidth * 2;
378
    for (unsigned j=0; j<(txWidth*2); j+=2) {
379
      clean_snap[txt_addr++] = raw_snap[line_addr+j];
380
    }
381
    while ((txt_addr > 0) && (clean_snap[txt_addr-1] == ' ')) txt_addr--;
382
#ifdef WIN32
383
    if(!(SIM->get_param_bool(BXPN_TEXT_SNAPSHOT_CHECK)->get())) {
384
      clean_snap[txt_addr++] = 13;
385
    }
386
#endif
387
    clean_snap[txt_addr++] = 10;
388
  }
389
  clean_snap[txt_addr] = 0;
390
  *snapshot = clean_snap;
391
  *length = txt_addr;
392
  return 0;
393
}
394
 
395
// create a text snapshot and copy to the system clipboard.  On guis that
396
// we haven't figured out how to support yet, dump to a file instead.
397
void bx_gui_c::copy_handler(void)
398
{
399
  Bit32u len;
400
  char *text_snapshot;
401
  if (make_text_snapshot (&text_snapshot, &len) < 0) {
402
    BX_INFO(("copy button failed, mode not implemented"));
403
    return;
404
  }
405
  if (!BX_GUI_THIS set_clipboard_text(text_snapshot, len)) {
406
    // platform specific code failed, use portable code instead
407
    FILE *fp = fopen("copy.txt", "w");
408
    fwrite(text_snapshot, 1, len, fp);
409
    fclose(fp);
410
  }
411
  free(text_snapshot);
412
}
413
 
414
// Check the current text snapshot against file snapchk.txt.
415
void bx_gui_c::snapshot_checker(void *this_ptr)
416
{
417
  char filename[BX_PATHNAME_LEN];
418
  strcpy(filename,"snapchk.txt");
419
  FILE *fp = fopen(filename, "rb");
420
  if(fp) {
421
    char *text_snapshot;
422
    Bit32u len;
423
    if (make_text_snapshot (&text_snapshot, &len) < 0) {
424
      return;
425
    }
426
    char *compare_snapshot = (char *) malloc((len+1) * sizeof(char));
427
    fread(compare_snapshot, 1, len, fp);
428
    fclose(fp);
429
    strcpy(filename,"snapmask.txt");
430
    fp=fopen(filename, "rb");
431
    if(fp) {
432
      char *mask_snapshot = (char *) malloc((len+1) * sizeof(char));
433
      unsigned i;
434
      bx_bool flag = 1;
435
      fread(mask_snapshot, 1, len, fp);
436
      fclose(fp);
437
      for(i=0;i<len;i++) {
438
        if((text_snapshot[i] != compare_snapshot[i]) &&
439
           (compare_snapshot[i] == mask_snapshot[i])) {
440
          flag = 0;
441
          break;
442
        }
443
      }
444
      if(flag) {
445
        if(!memcmp(text_snapshot,compare_snapshot,len)) {
446
          BX_PASS(("Test Passed."));
447
        } else {
448
          BX_PASS(("Test Passed with Mask."));
449
        }
450
      }
451
    } else {
452
      if(!memcmp(text_snapshot,compare_snapshot,len)) {
453
        BX_PASS(("Test Passed."));
454
      }
455
    }
456
    free(compare_snapshot);
457
    free(text_snapshot);
458
  }
459
}
460
 
461
// create a text snapshot and dump it to a file
462
void bx_gui_c::snapshot_handler(void)
463
{
464
  char *text_snapshot;
465
  Bit32u len;
466
  if (make_text_snapshot (&text_snapshot, &len) < 0) {
467
    BX_ERROR(("snapshot button failed, mode not implemented"));
468
    return;
469
  }
470
  //FIXME
471
  char filename[BX_PATHNAME_LEN];
472
  if (BX_GUI_THIS dialog_caps & BX_GUI_DLG_SNAPSHOT) {
473
    int ret = SIM->ask_filename (filename, sizeof(filename),
474
                                 "Save snapshot as...", "snapshot.txt",
475
                                 bx_param_string_c::SAVE_FILE_DIALOG);
476
    if (ret < 0) { // cancelled
477
      free(text_snapshot);
478
      return;
479
    }
480
  } else {
481
    strcpy (filename, "snapshot.txt");
482
  }
483
  FILE *fp = fopen(filename, "wb");
484
  fwrite(text_snapshot, 1, len, fp);
485
  fclose(fp);
486
  free(text_snapshot);
487
}
488
 
489
// Read ASCII chars from the system clipboard and paste them into bochs.
490
// Note that paste cannot work with the key mapping tables loaded.
491
void bx_gui_c::paste_handler(void)
492
{
493
  Bit32s nbytes;
494
  Bit8u *bytes;
495
  if (!bx_keymap.isKeymapLoaded ()) {
496
    BX_ERROR (("keyboard_mapping disabled, so paste cannot work"));
497
    return;
498
  }
499
  if (!BX_GUI_THIS get_clipboard_text(&bytes, &nbytes)) {
500
    BX_ERROR (("paste not implemented on this platform"));
501
    return;
502
  }
503
  BX_INFO (("pasting %d bytes", nbytes));
504
  DEV_kbd_paste_bytes (bytes, nbytes);
505
}
506
 
507
void bx_gui_c::config_handler(void)
508
{
509
  if (BX_GUI_THIS dialog_caps & BX_GUI_DLG_RUNTIME) {
510
    SIM->configuration_interface(NULL, CI_RUNTIME_CONFIG);
511
  }
512
}
513
 
514
void bx_gui_c::toggle_mouse_enable(void)
515
{
516
  int old = SIM->get_param_bool(BXPN_MOUSE_ENABLED)->get();
517
  BX_DEBUG (("toggle mouse_enabled, now %d", !old));
518
  SIM->get_param_bool(BXPN_MOUSE_ENABLED)->set(!old);
519
}
520
 
521
Bit32u get_user_key(char *key)
522
{
523
  int i = 0;
524
 
525
  while (i < N_USER_KEYS) {
526
    if (!strcmp(key, user_keys[i].key))
527
      return user_keys[i].symbol;
528
    i++;
529
  }
530
  return BX_KEY_UNKNOWN;
531
}
532
 
533
void bx_gui_c::userbutton_handler(void)
534
{
535
  Bit32u shortcut[4];
536
  Bit32u symbol;
537
  char user_shortcut[512];
538
  char *ptr;
539
  int i, len = 0, ret = 1;
540
 
541
  if (BX_GUI_THIS dialog_caps & BX_GUI_DLG_USER) {
542
    ret = SIM->ask_param(BXPN_USER_SHORTCUT);
543
  }
544
  strcpy(user_shortcut, SIM->get_param_string(BXPN_USER_SHORTCUT)->getptr());
545
  if ((ret > 0) && user_shortcut[0] && (strcmp(user_shortcut, "none"))) {
546
    ptr = strtok(user_shortcut, "-");
547
    if ((strcmp(ptr, SIM->get_param_string(BXPN_USER_SHORTCUT)->getptr())) ||
548
        (strlen(SIM->get_param_string(BXPN_USER_SHORTCUT)->getptr()) < 6)) {
549
      while (ptr) {
550
        symbol = get_user_key(ptr);
551
        if (symbol == BX_KEY_UNKNOWN) {
552
          BX_ERROR(("Unknown shortcut %s ignored", ptr));
553
          return;
554
        }
555
        shortcut[len++] = symbol;
556
        ptr = strtok(NULL, "-");
557
      }
558
    } else {
559
      BX_ERROR(("Unknown shortcut %s ignored", user_shortcut));
560
      return;
561
    }
562
    i = 0;
563
    while (i < len) {
564
      DEV_kbd_gen_scancode(shortcut[i++]);
565
    }
566
    i--;
567
    while (i >= 0) {
568
      DEV_kbd_gen_scancode(shortcut[i--] | BX_KEY_RELEASED);
569
    }
570
  }
571
}
572
 
573
void bx_gui_c::save_restore_handler(void)
574
{
575
  int ret;
576
  char sr_path[BX_PATHNAME_LEN];
577
 
578
  if (BX_GUI_THIS dialog_caps & BX_GUI_DLG_SAVE_RESTORE) {
579
    sr_path[0] = 0;
580
    ret = SIM->ask_filename(sr_path, sizeof(sr_path),
581
                            "Save Bochs state to folder...", "none",
582
                            bx_param_string_c::SELECT_FOLDER_DLG);
583
    if ((ret >= 0) && (strcmp(sr_path, "none"))) {
584
      if (SIM->save_state(sr_path)) {
585
        if (!SIM->ask_yes_no("WARNING",
586
              "The save function currently doesn't handle the state of hard drive images,\n"
587
              "so we don't recommend to continue, unless you are running a read-only\n"
588
              "guest system (e.g. Live-CD).\n\n"
589
              "Do you want to continue?", 0)) {
590
          power_handler();
591
        }
592
      }
593
    }
594
  }
595
}
596
 
597
void bx_gui_c::mouse_enabled_changed(bx_bool val)
598
{
599
  // This is only called when SIM->get_init_done is 1.  Note that VAL
600
  // is the new value of mouse_enabled, which may not match the old
601
  // value which is still in SIM->get_param_bool(BXPN_MOUSE_ENABLED)->get().
602
  BX_DEBUG (("replacing the mouse bitmaps"));
603
  if (val)
604
    BX_GUI_THIS replace_bitmap(BX_GUI_THIS mouse_hbar_id, BX_GUI_THIS mouse_bmap_id);
605
  else
606
    BX_GUI_THIS replace_bitmap(BX_GUI_THIS mouse_hbar_id, BX_GUI_THIS nomouse_bmap_id);
607
  // give the GUI a chance to respond to the event.  Most guis will hide
608
  // the native mouse cursor and do something to trap the mouse inside the
609
  // bochs VGA display window.
610
  BX_GUI_THIS mouse_enabled_changed_specific (val);
611
}
612
 
613
void bx_gui_c::init_signal_handlers()
614
{
615
#if BX_GUI_SIGHANDLER
616
  if (bx_gui_sighandler)
617
  {
618
    Bit32u mask = bx_gui->get_sighandler_mask ();
619
    for (Bit32u sig=0; sig<32; sig++)
620
    {
621
      if (mask & (1<<sig))
622
        signal (sig, bx_signal_handler);
623
    }
624
  }
625
#endif
626
}
627
 
628
void bx_gui_c::set_text_charmap(Bit8u *fbuffer)
629
{
630
  memcpy(& BX_GUI_THIS vga_charmap, fbuffer, 0x2000);
631
  for (unsigned i=0; i<256; i++) BX_GUI_THIS char_changed[i] = 1;
632
  BX_GUI_THIS charmap_updated = 1;
633
}
634
 
635
void bx_gui_c::set_text_charbyte(Bit16u address, Bit8u data)
636
{
637
  BX_GUI_THIS vga_charmap[address] = data;
638
  BX_GUI_THIS char_changed[address >> 5] = 1;
639
  BX_GUI_THIS charmap_updated = 1;
640
}
641
 
642
void bx_gui_c::beep_on(float frequency)
643
{
644
  BX_INFO(("GUI Beep ON (frequency=%.2f)", frequency));
645
}
646
 
647
void bx_gui_c::beep_off()
648
{
649
  BX_INFO(("GUI Beep OFF"));
650
}
651
 
652
int bx_gui_c::register_statusitem(const char *text)
653
{
654
  if (statusitem_count < BX_MAX_STATUSITEMS) {
655
    strncpy(statusitem_text[statusitem_count], text, 8);
656
    statusitem_text[statusitem_count][7] = 0;
657
    return statusitem_count++;
658
  } else {
659
   return -1;
660
  }
661
}
662
 
663
void bx_gui_c::get_capabilities(Bit16u *xres, Bit16u *yres, Bit16u *bpp)
664
{
665
  *xres = 1024;
666
  *yres = 768;
667
  *bpp = 32;
668
}
669
 
670
bx_svga_tileinfo_t *bx_gui_c::graphics_tile_info(bx_svga_tileinfo_t *info)
671
{
672
  if (!info) {
673
    info = (bx_svga_tileinfo_t *)malloc(sizeof(bx_svga_tileinfo_t));
674
    if (!info) {
675
      return NULL;
676
    }
677
  }
678
 
679
  BX_GUI_THIS host_pitch = BX_GUI_THIS host_xres * ((BX_GUI_THIS host_bpp + 1) >> 3);
680
 
681
  info->bpp = BX_GUI_THIS host_bpp;
682
  info->pitch = BX_GUI_THIS host_pitch;
683
  switch (info->bpp) {
684
    case 15:
685
      info->red_shift = 15;
686
      info->green_shift = 10;
687
      info->blue_shift = 5;
688
      info->red_mask = 0x7c00;
689
      info->green_mask = 0x03e0;
690
      info->blue_mask = 0x001f;
691
      break;
692
    case 16:
693
      info->red_shift = 16;
694
      info->green_shift = 11;
695
      info->blue_shift = 5;
696
      info->red_mask = 0xf800;
697
      info->green_mask = 0x07e0;
698
      info->blue_mask = 0x001f;
699
      break;
700
    case 24:
701
    case 32:
702
      info->red_shift = 24;
703
      info->green_shift = 16;
704
      info->blue_shift = 8;
705
      info->red_mask = 0xff0000;
706
      info->green_mask = 0x00ff00;
707
      info->blue_mask = 0x0000ff;
708
      break;
709
  }
710
  info->is_indexed = (BX_GUI_THIS host_bpp == 8);
711
#ifdef BX_LITTLE_ENDIAN
712
  info->is_little_endian = 1;
713
#else
714
  info->is_little_endian = 0;
715
#endif
716
 
717
  return info;
718
}
719
 
720
Bit8u *bx_gui_c::graphics_tile_get(unsigned x0, unsigned y0,
721
                            unsigned *w, unsigned *h)
722
{
723
  if (x0+X_TILESIZE > BX_GUI_THIS host_xres) {
724
    *w = BX_GUI_THIS host_xres - x0;
725
  }
726
  else {
727
    *w = X_TILESIZE;
728
  }
729
 
730
  if (y0+Y_TILESIZE > BX_GUI_THIS host_yres) {
731
    *h = BX_GUI_THIS host_yres - y0;
732
  }
733
  else {
734
    *h = Y_TILESIZE;
735
  }
736
 
737
  return (Bit8u *)framebuffer + y0 * BX_GUI_THIS host_pitch +
738
                  x0 * ((BX_GUI_THIS host_bpp + 1) >> 3);
739
}
740
 
741
void bx_gui_c::graphics_tile_update_in_place(unsigned x0, unsigned y0,
742
                                        unsigned w, unsigned h)
743
{
744
  Bit8u tile[X_TILESIZE * Y_TILESIZE * 4];
745
  Bit8u *tile_ptr, *fb_ptr;
746
  Bit16u xc, yc, fb_pitch, tile_pitch;
747
  Bit8u r, diffx, diffy;
748
 
749
  diffx = (x0 % X_TILESIZE);
750
  diffy = (y0 % Y_TILESIZE);
751
  if (diffx > 0) {
752
    x0 -= diffx;
753
    w += diffx;
754
  }
755
  if (diffy > 0) {
756
    y0 -= diffy;
757
    h += diffy;
758
  }
759
  fb_pitch = BX_GUI_THIS host_pitch;
760
  tile_pitch = X_TILESIZE * ((BX_GUI_THIS host_bpp + 1) >> 3);
761
  for (yc=y0; yc<(y0+h); yc+=Y_TILESIZE) {
762
    for (xc=x0; xc<(x0+w); xc+=X_TILESIZE) {
763
      fb_ptr = BX_GUI_THIS framebuffer + (yc * fb_pitch + xc * ((BX_GUI_THIS host_bpp + 1) >> 3));
764
      tile_ptr = &tile[0];
765
      for (r=0; r<h; r++) {
766
        memcpy(tile_ptr, fb_ptr, tile_pitch);
767
        fb_ptr += fb_pitch;
768
        tile_ptr += tile_pitch;
769
      }
770
      BX_GUI_THIS graphics_tile_update(tile, xc, yc);
771
    }
772
  }
773
}
774
 
775
void bx_gui_c::show_ips(Bit32u ips_count)
776
{
777
#if BX_SHOW_IPS
778
  BX_INFO(("ips = %u", ips_count));
779
#endif
780
}
781
 
782
Bit8u bx_gui_c::get_mouse_headerbar_id()
783
{
784
  return BX_GUI_THIS mouse_hbar_id;
785
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.