2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2011-02-25 01:05:47 +03:00
|
|
|
// $Id$
|
2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2017-01-01 20:45:06 +03:00
|
|
|
// Copyright (C) 2002-2017 The Bochs Project
|
2001-04-10 05:04:59 +04:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
2009-02-08 12:05:52 +03:00
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
|
2001-05-09 00:18:04 +04:00
|
|
|
#include <signal.h>
|
2004-06-19 19:20:15 +04:00
|
|
|
#include "iodev.h"
|
2014-04-07 21:37:07 +04:00
|
|
|
#include "virt_timer.h"
|
2011-01-24 23:35:51 +03:00
|
|
|
#include "keymap.h"
|
2001-04-10 05:04:59 +04:00
|
|
|
#include "gui/bitmaps/floppya.h"
|
|
|
|
#include "gui/bitmaps/floppyb.h"
|
|
|
|
#include "gui/bitmaps/mouse.h"
|
|
|
|
#include "gui/bitmaps/reset.h"
|
|
|
|
#include "gui/bitmaps/power.h"
|
|
|
|
#include "gui/bitmaps/snapshot.h"
|
2002-03-11 18:04:58 +03:00
|
|
|
#include "gui/bitmaps/copy.h"
|
|
|
|
#include "gui/bitmaps/paste.h"
|
2001-11-10 01:17:33 +03:00
|
|
|
#include "gui/bitmaps/configbutton.h"
|
2002-02-01 19:46:27 +03:00
|
|
|
#include "gui/bitmaps/cdromd.h"
|
2002-08-09 10:16:43 +04:00
|
|
|
#include "gui/bitmaps/userbutton.h"
|
2006-06-07 02:11:09 +04:00
|
|
|
#include "gui/bitmaps/saverestore.h"
|
|
|
|
|
2017-01-13 18:57:36 +03:00
|
|
|
#if BX_USE_GUI_CONSOLE
|
2017-01-01 20:45:06 +03:00
|
|
|
#include "sdl.h"
|
2017-01-01 22:37:26 +03:00
|
|
|
#endif
|
2017-01-01 20:45:06 +03:00
|
|
|
|
2001-09-26 04:15:30 +04:00
|
|
|
#if BX_WITH_MACOS
|
2001-04-10 05:04:59 +04:00
|
|
|
# include <Disks.h>
|
|
|
|
#endif
|
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
bx_gui_c *bx_gui = NULL;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
#define BX_GUI_THIS bx_gui->
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
#define LOG_THIS BX_GUI_THIS
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2017-04-02 19:16:53 +03:00
|
|
|
// Enable this if you want confirm quit after pressing power button.
|
|
|
|
//#define BX_GUI_CONFIRM_QUIT
|
|
|
|
|
2017-01-15 14:44:43 +03:00
|
|
|
// user button shortcut stuff
|
|
|
|
|
2005-10-08 15:41:18 +04:00
|
|
|
#define BX_KEY_UNKNOWN 0x7fffffff
|
2014-07-07 11:29:08 +04:00
|
|
|
#define N_USER_KEYS 38
|
2005-10-08 15:41:18 +04:00
|
|
|
|
|
|
|
typedef struct {
|
2007-10-25 03:09:59 +04:00
|
|
|
const char *key;
|
2005-10-08 15:41:18 +04:00
|
|
|
Bit32u symbol;
|
|
|
|
} user_key_t;
|
|
|
|
|
|
|
|
static user_key_t user_keys[N_USER_KEYS] =
|
|
|
|
{
|
2005-10-20 21:34:22 +04:00
|
|
|
{ "f1", BX_KEY_F1 },
|
|
|
|
{ "f2", BX_KEY_F2 },
|
|
|
|
{ "f3", BX_KEY_F3 },
|
|
|
|
{ "f4", BX_KEY_F4 },
|
|
|
|
{ "f5", BX_KEY_F5 },
|
|
|
|
{ "f6", BX_KEY_F6 },
|
|
|
|
{ "f7", BX_KEY_F7 },
|
|
|
|
{ "f8", BX_KEY_F8 },
|
|
|
|
{ "f9", BX_KEY_F9 },
|
|
|
|
{ "f10", BX_KEY_F10 },
|
|
|
|
{ "f11", BX_KEY_F11 },
|
|
|
|
{ "f12", BX_KEY_F12 },
|
|
|
|
{ "alt", BX_KEY_ALT_L },
|
2006-01-09 21:37:29 +03:00
|
|
|
{ "bksl", BX_KEY_BACKSLASH },
|
2005-10-20 21:34:22 +04:00
|
|
|
{ "bksp", BX_KEY_BACKSPACE },
|
|
|
|
{ "ctrl", BX_KEY_CTRL_L },
|
|
|
|
{ "del", BX_KEY_DELETE },
|
|
|
|
{ "down", BX_KEY_DOWN },
|
|
|
|
{ "end", BX_KEY_END },
|
|
|
|
{ "enter", BX_KEY_ENTER },
|
|
|
|
{ "esc", BX_KEY_ESC },
|
|
|
|
{ "home", BX_KEY_HOME },
|
|
|
|
{ "ins", BX_KEY_INSERT },
|
|
|
|
{ "left", BX_KEY_LEFT },
|
|
|
|
{ "menu", BX_KEY_MENU },
|
|
|
|
{ "minus", BX_KEY_MINUS },
|
|
|
|
{ "pgdwn", BX_KEY_PAGE_DOWN },
|
|
|
|
{ "pgup", BX_KEY_PAGE_UP },
|
|
|
|
{ "plus", BX_KEY_KP_ADD },
|
|
|
|
{ "right", BX_KEY_RIGHT },
|
|
|
|
{ "shift", BX_KEY_SHIFT_L },
|
|
|
|
{ "space", BX_KEY_SPACE },
|
|
|
|
{ "tab", BX_KEY_TAB },
|
|
|
|
{ "up", BX_KEY_UP },
|
2007-08-18 12:05:33 +04:00
|
|
|
{ "win", BX_KEY_WIN_L },
|
2008-05-04 13:29:45 +04:00
|
|
|
{ "print", BX_KEY_PRINT },
|
2014-07-07 11:29:08 +04:00
|
|
|
{ "power", BX_KEY_POWER_POWER },
|
|
|
|
{ "scrlck", BX_KEY_SCRL_LOCK }
|
2005-10-08 15:41:18 +04:00
|
|
|
};
|
|
|
|
|
2017-01-15 14:44:43 +03:00
|
|
|
Bit32u get_user_key(char *key)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
while (i < N_USER_KEYS) {
|
|
|
|
if (!strcmp(key, user_keys[i].key))
|
|
|
|
return user_keys[i].symbol;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return BX_KEY_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
// font bitmap helper function
|
|
|
|
|
2017-01-03 23:59:59 +03:00
|
|
|
Bit8u reverse_bitorder(Bit8u b)
|
|
|
|
{
|
|
|
|
Bit8u ret = 0;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < 8; i++) {
|
|
|
|
ret |= (b & 0x01) << (7 - i);
|
|
|
|
b >>= 1;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-01-15 14:44:43 +03:00
|
|
|
// common gui implementation
|
|
|
|
|
2012-06-24 21:52:45 +04:00
|
|
|
bx_gui_c::bx_gui_c(void): disp_mode(DISP_MODE_SIM)
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
{
|
2001-06-27 23:16:01 +04:00
|
|
|
put("GUI"); // Init in specific_init
|
2017-01-14 16:10:20 +03:00
|
|
|
bx_headerbar_entries = 0;
|
2004-02-07 17:34:35 +03:00
|
|
|
statusitem_count = 0;
|
2011-12-28 15:51:42 +04:00
|
|
|
led_timer_index = BX_NULL_TIMER_HANDLE;
|
2004-08-15 23:27:15 +04:00
|
|
|
framebuffer = NULL;
|
2012-10-14 22:29:44 +04:00
|
|
|
guest_textmode = 1;
|
2017-01-01 20:45:06 +03:00
|
|
|
guest_fsize = (16 << 4) | 8;
|
2012-10-14 22:29:44 +04:00
|
|
|
guest_xres = 640;
|
|
|
|
guest_yres = 480;
|
|
|
|
guest_bpp = 8;
|
2012-10-15 23:43:06 +04:00
|
|
|
snapshot_mode = 0;
|
|
|
|
snapshot_buffer = NULL;
|
2012-10-14 22:29:44 +04:00
|
|
|
memset(palette, 0, sizeof(palette));
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
bx_gui_c::~bx_gui_c()
|
|
|
|
{
|
2004-08-15 23:27:15 +04:00
|
|
|
if (framebuffer != NULL) {
|
|
|
|
delete [] framebuffer;
|
|
|
|
}
|
2017-01-13 18:57:36 +03:00
|
|
|
#if BX_USE_GUI_CONSOLE
|
2017-01-01 20:45:06 +03:00
|
|
|
if (console.running) {
|
|
|
|
console_cleanup();
|
|
|
|
}
|
|
|
|
#endif
|
2002-10-25 01:07:56 +04:00
|
|
|
}
|
|
|
|
|
2012-01-21 16:15:10 +04:00
|
|
|
void bx_gui_c::init(int argc, char **argv, unsigned max_xres, unsigned max_yres,
|
|
|
|
unsigned tilewidth, unsigned tileheight)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2004-08-15 23:27:15 +04:00
|
|
|
BX_GUI_THIS new_gfx_api = 0;
|
|
|
|
BX_GUI_THIS host_xres = 640;
|
|
|
|
BX_GUI_THIS host_yres = 480;
|
|
|
|
BX_GUI_THIS host_bpp = 8;
|
2012-01-22 13:08:59 +04:00
|
|
|
BX_GUI_THIS max_xres = max_xres;
|
|
|
|
BX_GUI_THIS max_yres = max_yres;
|
2012-01-21 16:15:10 +04:00
|
|
|
BX_GUI_THIS x_tilesize = tilewidth;
|
|
|
|
BX_GUI_THIS y_tilesize = tileheight;
|
2006-06-07 23:40:15 +04:00
|
|
|
BX_GUI_THIS dialog_caps = BX_GUI_DLG_RUNTIME | BX_GUI_DLG_SAVE_RESTORE;
|
2017-01-13 18:57:36 +03:00
|
|
|
#if BX_USE_GUI_CONSOLE
|
2017-01-01 20:45:06 +03:00
|
|
|
BX_GUI_THIS console.present = 0;
|
|
|
|
BX_GUI_THIS console.running = 0;
|
|
|
|
#endif
|
2010-05-16 13:01:36 +04:00
|
|
|
BX_GUI_THIS toggle_method = SIM->get_param_enum(BXPN_MOUSE_TOGGLE)->get();
|
|
|
|
BX_GUI_THIS toggle_keystate = 0;
|
|
|
|
switch (toggle_method) {
|
|
|
|
case BX_MOUSE_TOGGLE_CTRL_MB:
|
|
|
|
strcpy(mouse_toggle_text, "CTRL + 3rd button");
|
|
|
|
break;
|
|
|
|
case BX_MOUSE_TOGGLE_CTRL_F10:
|
|
|
|
strcpy(mouse_toggle_text, "CTRL + F10");
|
|
|
|
break;
|
|
|
|
case BX_MOUSE_TOGGLE_CTRL_ALT:
|
|
|
|
strcpy(mouse_toggle_text, "CTRL + ALT");
|
2010-08-02 23:26:13 +04:00
|
|
|
break;
|
2010-05-18 19:33:41 +04:00
|
|
|
case BX_MOUSE_TOGGLE_F12:
|
|
|
|
strcpy(mouse_toggle_text, "F12");
|
2010-05-16 13:01:36 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-03 16:41:24 +04:00
|
|
|
specific_init(argc, argv, BX_HEADER_BAR_Y);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
// Define some bitmaps to use in the headerbar
|
|
|
|
BX_GUI_THIS floppyA_bmap_id = create_bitmap(bx_floppya_bmap,
|
|
|
|
BX_FLOPPYA_BMAP_X, BX_FLOPPYA_BMAP_Y);
|
|
|
|
BX_GUI_THIS floppyA_eject_bmap_id = create_bitmap(bx_floppya_eject_bmap,
|
|
|
|
BX_FLOPPYA_BMAP_X, BX_FLOPPYA_BMAP_Y);
|
|
|
|
BX_GUI_THIS floppyB_bmap_id = create_bitmap(bx_floppyb_bmap,
|
|
|
|
BX_FLOPPYB_BMAP_X, BX_FLOPPYB_BMAP_Y);
|
|
|
|
BX_GUI_THIS floppyB_eject_bmap_id = create_bitmap(bx_floppyb_eject_bmap,
|
|
|
|
BX_FLOPPYB_BMAP_X, BX_FLOPPYB_BMAP_Y);
|
2011-06-13 13:32:39 +04:00
|
|
|
BX_GUI_THIS cdrom1_bmap_id = create_bitmap(bx_cdromd_bmap,
|
2002-02-01 19:46:27 +03:00
|
|
|
BX_CDROMD_BMAP_X, BX_CDROMD_BMAP_Y);
|
2011-06-13 13:32:39 +04:00
|
|
|
BX_GUI_THIS cdrom1_eject_bmap_id = create_bitmap(bx_cdromd_eject_bmap,
|
2002-02-01 19:46:27 +03:00
|
|
|
BX_CDROMD_BMAP_X, BX_CDROMD_BMAP_Y);
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_GUI_THIS mouse_bmap_id = create_bitmap(bx_mouse_bmap,
|
|
|
|
BX_MOUSE_BMAP_X, BX_MOUSE_BMAP_Y);
|
|
|
|
BX_GUI_THIS nomouse_bmap_id = create_bitmap(bx_nomouse_bmap,
|
|
|
|
BX_MOUSE_BMAP_X, BX_MOUSE_BMAP_Y);
|
|
|
|
|
|
|
|
BX_GUI_THIS power_bmap_id = create_bitmap(bx_power_bmap, BX_POWER_BMAP_X, BX_POWER_BMAP_Y);
|
|
|
|
BX_GUI_THIS reset_bmap_id = create_bitmap(bx_reset_bmap, BX_RESET_BMAP_X, BX_RESET_BMAP_Y);
|
|
|
|
BX_GUI_THIS snapshot_bmap_id = create_bitmap(bx_snapshot_bmap, BX_SNAPSHOT_BMAP_X, BX_SNAPSHOT_BMAP_Y);
|
2002-03-11 18:04:58 +03:00
|
|
|
BX_GUI_THIS copy_bmap_id = create_bitmap(bx_copy_bmap, BX_COPY_BMAP_X, BX_COPY_BMAP_Y);
|
|
|
|
BX_GUI_THIS paste_bmap_id = create_bitmap(bx_paste_bmap, BX_PASTE_BMAP_X, BX_PASTE_BMAP_Y);
|
|
|
|
BX_GUI_THIS config_bmap_id = create_bitmap(bx_config_bmap, BX_CONFIG_BMAP_X, BX_CONFIG_BMAP_Y);
|
2002-08-09 10:16:43 +04:00
|
|
|
BX_GUI_THIS user_bmap_id = create_bitmap(bx_user_bmap, BX_USER_BMAP_X, BX_USER_BMAP_Y);
|
2006-06-07 02:11:09 +04:00
|
|
|
BX_GUI_THIS save_restore_bmap_id = create_bitmap(bx_save_restore_bmap,
|
|
|
|
BX_SAVE_RESTORE_BMAP_X, BX_SAVE_RESTORE_BMAP_Y);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
// Add the initial bitmaps to the headerbar, and enable callback routine, for use
|
2014-05-26 21:04:02 +04:00
|
|
|
// when that bitmap is clicked on. The floppy and cdrom devices are not
|
|
|
|
// initialized yet. so we just set the bitmaps to ejected for now.
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
// Floppy A:
|
2014-05-26 21:04:02 +04:00
|
|
|
BX_GUI_THIS floppyA_hbar_id = headerbar_bitmap(BX_GUI_THIS floppyA_eject_bmap_id,
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_GRAVITY_LEFT, floppyA_handler);
|
2006-01-25 20:37:22 +03:00
|
|
|
BX_GUI_THIS set_tooltip(BX_GUI_THIS floppyA_hbar_id, "Change floppy A: media");
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
// Floppy B:
|
2014-05-26 21:04:02 +04:00
|
|
|
BX_GUI_THIS floppyB_hbar_id = headerbar_bitmap(BX_GUI_THIS floppyB_eject_bmap_id,
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_GRAVITY_LEFT, floppyB_handler);
|
2006-01-25 20:37:22 +03:00
|
|
|
BX_GUI_THIS set_tooltip(BX_GUI_THIS floppyB_hbar_id, "Change floppy B: media");
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2014-05-26 21:04:02 +04:00
|
|
|
// First CD-ROM
|
2011-06-13 13:32:39 +04:00
|
|
|
BX_GUI_THIS cdrom1_hbar_id = headerbar_bitmap(BX_GUI_THIS cdrom1_eject_bmap_id,
|
|
|
|
BX_GRAVITY_LEFT, cdrom1_handler);
|
|
|
|
BX_GUI_THIS set_tooltip(BX_GUI_THIS cdrom1_hbar_id, "Change first CDROM media");
|
2002-02-01 19:46:27 +03:00
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
// Mouse button
|
2006-02-22 22:18:29 +03:00
|
|
|
if (SIM->get_param_bool(BXPN_MOUSE_ENABLED)->get())
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_GUI_THIS mouse_hbar_id = headerbar_bitmap(BX_GUI_THIS mouse_bmap_id,
|
2001-06-23 07:18:14 +04:00
|
|
|
BX_GRAVITY_LEFT, toggle_mouse_enable);
|
2001-04-10 05:04:59 +04:00
|
|
|
else
|
|
|
|
BX_GUI_THIS mouse_hbar_id = headerbar_bitmap(BX_GUI_THIS nomouse_bmap_id,
|
2001-06-23 07:18:14 +04:00
|
|
|
BX_GRAVITY_LEFT, toggle_mouse_enable);
|
2006-01-25 20:37:22 +03:00
|
|
|
BX_GUI_THIS set_tooltip(BX_GUI_THIS mouse_hbar_id, "Enable mouse capture");
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-03-11 18:04:58 +03:00
|
|
|
// These are the buttons on the right side. They are created in order
|
|
|
|
// of right to left.
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
// Power button
|
|
|
|
BX_GUI_THIS power_hbar_id = headerbar_bitmap(BX_GUI_THIS power_bmap_id,
|
|
|
|
BX_GRAVITY_RIGHT, power_handler);
|
2006-01-25 20:37:22 +03:00
|
|
|
BX_GUI_THIS set_tooltip(BX_GUI_THIS power_hbar_id, "Turn power off");
|
2006-06-07 02:11:09 +04:00
|
|
|
// Save/Restore Button
|
|
|
|
BX_GUI_THIS save_restore_hbar_id = headerbar_bitmap(BX_GUI_THIS save_restore_bmap_id,
|
|
|
|
BX_GRAVITY_RIGHT, save_restore_handler);
|
|
|
|
BX_GUI_THIS set_tooltip(BX_GUI_THIS save_restore_hbar_id, "Save simulation state");
|
2001-04-10 05:04:59 +04:00
|
|
|
// Reset button
|
|
|
|
BX_GUI_THIS reset_hbar_id = headerbar_bitmap(BX_GUI_THIS reset_bmap_id,
|
|
|
|
BX_GRAVITY_RIGHT, reset_handler);
|
2006-01-25 20:37:22 +03:00
|
|
|
BX_GUI_THIS set_tooltip(BX_GUI_THIS reset_hbar_id, "Reset the system");
|
2001-11-10 01:17:33 +03:00
|
|
|
// Configure button
|
|
|
|
BX_GUI_THIS config_hbar_id = headerbar_bitmap(BX_GUI_THIS config_bmap_id,
|
|
|
|
BX_GRAVITY_RIGHT, config_handler);
|
2006-01-25 20:37:22 +03:00
|
|
|
BX_GUI_THIS set_tooltip(BX_GUI_THIS config_hbar_id, "Runtime config dialog");
|
2002-03-11 18:04:58 +03:00
|
|
|
// Snapshot button
|
|
|
|
BX_GUI_THIS snapshot_hbar_id = headerbar_bitmap(BX_GUI_THIS snapshot_bmap_id,
|
|
|
|
BX_GRAVITY_RIGHT, snapshot_handler);
|
2013-11-07 23:38:23 +04:00
|
|
|
BX_GUI_THIS set_tooltip(BX_GUI_THIS snapshot_hbar_id, "Save snapshot of the Bochs screen");
|
2002-03-11 18:04:58 +03:00
|
|
|
// Paste button
|
|
|
|
BX_GUI_THIS paste_hbar_id = headerbar_bitmap(BX_GUI_THIS paste_bmap_id,
|
|
|
|
BX_GRAVITY_RIGHT, paste_handler);
|
2006-01-25 20:37:22 +03:00
|
|
|
BX_GUI_THIS set_tooltip(BX_GUI_THIS paste_hbar_id, "Paste clipboard text as emulated keystrokes");
|
2002-03-11 18:04:58 +03:00
|
|
|
// Copy button
|
|
|
|
BX_GUI_THIS copy_hbar_id = headerbar_bitmap(BX_GUI_THIS copy_bmap_id,
|
|
|
|
BX_GRAVITY_RIGHT, copy_handler);
|
2006-01-25 20:37:22 +03:00
|
|
|
BX_GUI_THIS set_tooltip(BX_GUI_THIS copy_hbar_id, "Copy text mode screen to the clipboard");
|
2002-08-09 10:16:43 +04:00
|
|
|
// User button
|
|
|
|
BX_GUI_THIS user_hbar_id = headerbar_bitmap(BX_GUI_THIS user_bmap_id,
|
|
|
|
BX_GRAVITY_RIGHT, userbutton_handler);
|
2006-01-25 20:37:22 +03:00
|
|
|
BX_GUI_THIS set_tooltip(BX_GUI_THIS user_hbar_id, "Send keyboard shortcut");
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2014-07-08 18:30:27 +04:00
|
|
|
if (!parse_user_shortcut(SIM->get_param_string(BXPN_USER_SHORTCUT)->getptr())) {
|
|
|
|
SIM->get_param_string(BXPN_USER_SHORTCUT)->set("none");
|
|
|
|
}
|
|
|
|
|
2003-05-24 14:51:00 +04:00
|
|
|
BX_GUI_THIS charmap_updated = 0;
|
|
|
|
|
2006-09-18 00:37:28 +04:00
|
|
|
if (!BX_GUI_THIS new_gfx_api && (BX_GUI_THIS framebuffer == NULL)) {
|
2012-01-21 16:15:10 +04:00
|
|
|
BX_GUI_THIS framebuffer = new Bit8u[max_xres * max_yres * 4];
|
2004-08-15 23:27:15 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
show_headerbar();
|
2011-12-28 15:51:42 +04:00
|
|
|
|
|
|
|
// register timer for status bar LEDs
|
|
|
|
if (BX_GUI_THIS led_timer_index == BX_NULL_TIMER_HANDLE) {
|
|
|
|
BX_GUI_THIS led_timer_index =
|
2014-10-19 12:54:16 +04:00
|
|
|
bx_virt_timer.register_timer(this, led_timer_handler, 100000, 1, 1, 1,
|
2014-04-07 21:37:07 +04:00
|
|
|
"status bar LEDs");
|
2011-12-28 15:51:42 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2006-09-18 00:37:28 +04:00
|
|
|
void bx_gui_c::cleanup(void)
|
|
|
|
{
|
|
|
|
statusitem_count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bx_gui_c::update_drive_status_buttons(void)
|
2006-04-10 23:02:30 +04:00
|
|
|
{
|
2013-01-23 21:56:57 +04:00
|
|
|
BX_GUI_THIS floppyA_status = (SIM->get_param_enum(BXPN_FLOPPYA_STATUS)->get() == BX_INSERTED);
|
|
|
|
BX_GUI_THIS floppyB_status = (SIM->get_param_enum(BXPN_FLOPPYB_STATUS)->get() == BX_INSERTED);
|
2002-10-25 01:07:56 +04:00
|
|
|
Bit32u handle = DEV_hd_get_first_cd_handle();
|
2011-06-13 13:32:39 +04:00
|
|
|
BX_GUI_THIS cdrom1_status = DEV_hd_get_cd_media_status(handle);
|
2001-04-10 05:04:59 +04:00
|
|
|
if (BX_GUI_THIS floppyA_status)
|
|
|
|
replace_bitmap(BX_GUI_THIS floppyA_hbar_id, BX_GUI_THIS floppyA_bmap_id);
|
|
|
|
else {
|
2001-09-26 04:15:30 +04:00
|
|
|
#if BX_WITH_MACOS
|
2001-04-10 05:04:59 +04:00
|
|
|
// If we are using the Mac floppy driver, eject the disk
|
2001-09-26 04:15:30 +04:00
|
|
|
// from the floppy drive. This doesn't work in MacOS X.
|
2006-02-25 01:35:46 +03:00
|
|
|
if (!strcmp(SIM->get_param_string(BXPN_FLOPPYA_PATH)->getptr(), SuperDrive))
|
2001-04-10 05:04:59 +04:00
|
|
|
DiskEject(1);
|
|
|
|
#endif
|
|
|
|
replace_bitmap(BX_GUI_THIS floppyA_hbar_id, BX_GUI_THIS floppyA_eject_bmap_id);
|
2006-04-10 23:02:30 +04:00
|
|
|
}
|
2001-09-28 10:03:40 +04:00
|
|
|
if (BX_GUI_THIS floppyB_status)
|
|
|
|
replace_bitmap(BX_GUI_THIS floppyB_hbar_id, BX_GUI_THIS floppyB_bmap_id);
|
|
|
|
else {
|
|
|
|
#if BX_WITH_MACOS
|
|
|
|
// If we are using the Mac floppy driver, eject the disk
|
|
|
|
// from the floppy drive. This doesn't work in MacOS X.
|
2006-02-25 01:35:46 +03:00
|
|
|
if (!strcmp(SIM->get_param_string(BXPN_FLOPPYB_PATH)->getptr(), SuperDrive))
|
2001-09-28 10:03:40 +04:00
|
|
|
DiskEject(1);
|
|
|
|
#endif
|
|
|
|
replace_bitmap(BX_GUI_THIS floppyB_hbar_id, BX_GUI_THIS floppyB_eject_bmap_id);
|
2006-04-10 23:02:30 +04:00
|
|
|
}
|
2011-06-13 13:32:39 +04:00
|
|
|
if (BX_GUI_THIS cdrom1_status)
|
|
|
|
replace_bitmap(BX_GUI_THIS cdrom1_hbar_id, BX_GUI_THIS cdrom1_bmap_id);
|
2002-02-01 19:46:27 +03:00
|
|
|
else {
|
2011-06-13 13:32:39 +04:00
|
|
|
replace_bitmap(BX_GUI_THIS cdrom1_hbar_id, BX_GUI_THIS cdrom1_eject_bmap_id);
|
2006-04-10 23:02:30 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2006-04-10 23:02:30 +04:00
|
|
|
void bx_gui_c::floppyA_handler(void)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2009-03-23 22:05:16 +03:00
|
|
|
if (SIM->get_param_enum(BXPN_FLOPPYA_DEVTYPE)->get() == BX_FDD_NONE)
|
2003-07-17 19:49:23 +04:00
|
|
|
return; // no primary floppy device present
|
2005-11-12 19:09:55 +03:00
|
|
|
if (BX_GUI_THIS dialog_caps & BX_GUI_DLG_FLOPPY) {
|
2011-06-13 13:32:39 +04:00
|
|
|
// instead of just toggling the status, bring up a dialog asking what disk
|
|
|
|
// image you want to switch to.
|
2013-12-08 02:58:41 +04:00
|
|
|
int ret = SIM->ask_param(BXPN_FLOPPYA);
|
2003-07-18 19:51:02 +04:00
|
|
|
if (ret > 0) {
|
2011-07-24 18:11:10 +04:00
|
|
|
SIM->update_runtime_options();
|
2003-07-18 19:51:02 +04:00
|
|
|
}
|
|
|
|
return;
|
2003-07-16 01:02:05 +04:00
|
|
|
}
|
2003-07-18 19:51:02 +04:00
|
|
|
BX_GUI_THIS floppyA_status = !BX_GUI_THIS floppyA_status;
|
|
|
|
DEV_floppy_set_media_status(0, BX_GUI_THIS floppyA_status);
|
2006-02-25 01:35:46 +03:00
|
|
|
BX_GUI_THIS update_drive_status_buttons();
|
2001-09-28 10:03:40 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2006-04-10 23:02:30 +04:00
|
|
|
void bx_gui_c::floppyB_handler(void)
|
2001-09-28 10:03:40 +04:00
|
|
|
{
|
2009-03-23 22:05:16 +03:00
|
|
|
if (SIM->get_param_enum(BXPN_FLOPPYB_DEVTYPE)->get() == BX_FDD_NONE)
|
2003-07-17 19:49:23 +04:00
|
|
|
return; // no secondary floppy device present
|
2005-11-12 19:09:55 +03:00
|
|
|
if (BX_GUI_THIS dialog_caps & BX_GUI_DLG_FLOPPY) {
|
2011-06-13 13:32:39 +04:00
|
|
|
// instead of just toggling the status, bring up a dialog asking what disk
|
|
|
|
// image you want to switch to.
|
2013-12-08 02:58:41 +04:00
|
|
|
int ret = SIM->ask_param(BXPN_FLOPPYB);
|
2003-07-18 19:51:02 +04:00
|
|
|
if (ret > 0) {
|
2011-07-24 18:11:10 +04:00
|
|
|
SIM->update_runtime_options();
|
2003-07-18 19:51:02 +04:00
|
|
|
}
|
|
|
|
return;
|
2003-07-16 01:02:05 +04:00
|
|
|
}
|
2003-07-18 19:51:02 +04:00
|
|
|
BX_GUI_THIS floppyB_status = !BX_GUI_THIS floppyB_status;
|
|
|
|
DEV_floppy_set_media_status(1, BX_GUI_THIS floppyB_status);
|
2006-02-25 01:35:46 +03:00
|
|
|
BX_GUI_THIS update_drive_status_buttons();
|
2002-02-01 19:46:27 +03:00
|
|
|
}
|
|
|
|
|
2011-06-13 13:32:39 +04:00
|
|
|
void bx_gui_c::cdrom1_handler(void)
|
2002-02-01 19:46:27 +03:00
|
|
|
{
|
2002-10-25 01:07:56 +04:00
|
|
|
Bit32u handle = DEV_hd_get_first_cd_handle();
|
2005-11-12 19:09:55 +03:00
|
|
|
if (BX_GUI_THIS dialog_caps & BX_GUI_DLG_CDROM) {
|
2011-06-13 13:32:39 +04:00
|
|
|
// instead of just toggling the status, bring up a dialog asking what disk
|
|
|
|
// image you want to switch to.
|
2004-02-01 04:40:14 +03:00
|
|
|
// This code handles the first cdrom only. The cdrom drives #2, #3 and
|
2011-06-13 13:32:39 +04:00
|
|
|
// #4 are handled in the runtime configuaration.
|
2006-02-27 12:37:58 +03:00
|
|
|
bx_param_c *cdrom = SIM->get_first_cdrom();
|
2002-11-09 09:41:34 +03:00
|
|
|
if (cdrom == NULL)
|
|
|
|
return; // no cdrom found
|
2006-02-27 12:37:58 +03:00
|
|
|
int ret = SIM->ask_param(cdrom);
|
2004-02-01 04:40:14 +03:00
|
|
|
if (ret > 0) {
|
2011-07-24 18:11:10 +04:00
|
|
|
SIM->update_runtime_options();
|
2004-02-01 04:40:14 +03:00
|
|
|
}
|
|
|
|
return;
|
2002-11-09 09:41:34 +03:00
|
|
|
}
|
2011-06-13 13:32:39 +04:00
|
|
|
BX_GUI_THIS cdrom1_status =
|
|
|
|
DEV_hd_set_cd_media_status(handle, !BX_GUI_THIS cdrom1_status);
|
2006-02-27 12:37:58 +03:00
|
|
|
BX_GUI_THIS update_drive_status_buttons();
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2006-04-10 23:02:30 +04:00
|
|
|
void bx_gui_c::reset_handler(void)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2006-04-10 23:02:30 +04:00
|
|
|
BX_INFO(("system RESET callback"));
|
|
|
|
bx_pc_system.Reset(BX_RESET_HARDWARE);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2006-04-10 23:02:30 +04:00
|
|
|
void bx_gui_c::power_handler(void)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2017-04-02 19:16:53 +03:00
|
|
|
#ifdef BX_GUI_CONFIRM_QUIT
|
|
|
|
if (!SIM->ask_yes_no("Quit Bochs", "Are you sure ?", 0))
|
|
|
|
return;
|
|
|
|
#endif
|
2001-06-15 22:01:52 +04:00
|
|
|
// the user pressed power button, so there's no doubt they want bochs
|
|
|
|
// to quit. Change panics to fatal for the GUI and then do a panic.
|
2003-05-27 22:19:13 +04:00
|
|
|
bx_user_quit = 1;
|
2017-01-25 00:52:19 +03:00
|
|
|
BX_FATAL(("POWER button turned off."));
|
2001-06-15 22:01:52 +04:00
|
|
|
// shouldn't reach this point, but if you do, QUIT!!!
|
|
|
|
fprintf (stderr, "Bochs is exiting because you pressed the power button.\n");
|
2017-01-25 00:52:19 +03:00
|
|
|
BX_EXIT(1);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2011-08-01 22:21:25 +04:00
|
|
|
void bx_gui_c::make_text_snapshot(char **snapshot, Bit32u *length)
|
2001-11-10 01:17:33 +03:00
|
|
|
{
|
2002-03-11 18:04:58 +03:00
|
|
|
Bit8u* raw_snap = NULL;
|
|
|
|
char *clean_snap;
|
2002-02-12 20:09:51 +03:00
|
|
|
unsigned line_addr, txt_addr, txHeight, txWidth;
|
2002-02-04 23:31:35 +03:00
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
DEV_vga_get_text_snapshot(&raw_snap, &txHeight, &txWidth);
|
2017-02-18 14:13:56 +03:00
|
|
|
clean_snap = new char[txHeight*(txWidth+2)+1];
|
2002-03-11 18:04:58 +03:00
|
|
|
txt_addr = 0;
|
|
|
|
for (unsigned i=0; i<txHeight; i++) {
|
|
|
|
line_addr = i * txWidth * 2;
|
|
|
|
for (unsigned j=0; j<(txWidth*2); j+=2) {
|
2009-04-20 22:11:13 +04:00
|
|
|
if (!raw_snap[line_addr+j])
|
|
|
|
raw_snap[line_addr+j] = 0x20;
|
2002-10-22 21:30:54 +04:00
|
|
|
clean_snap[txt_addr++] = raw_snap[line_addr+j];
|
2002-02-04 23:31:35 +03:00
|
|
|
}
|
2002-11-09 09:41:34 +03:00
|
|
|
while ((txt_addr > 0) && (clean_snap[txt_addr-1] == ' ')) txt_addr--;
|
2002-03-10 08:49:26 +03:00
|
|
|
#ifdef WIN32
|
2011-07-31 18:38:03 +04:00
|
|
|
clean_snap[txt_addr++] = 13;
|
2002-03-11 18:04:58 +03:00
|
|
|
#endif
|
2002-10-22 21:30:54 +04:00
|
|
|
clean_snap[txt_addr++] = 10;
|
2002-03-11 18:04:58 +03:00
|
|
|
}
|
|
|
|
clean_snap[txt_addr] = 0;
|
|
|
|
*snapshot = clean_snap;
|
|
|
|
*length = txt_addr;
|
|
|
|
}
|
|
|
|
|
2012-10-25 19:53:04 +04:00
|
|
|
Bit32u bx_gui_c::set_snapshot_mode(bx_bool mode)
|
2012-10-15 23:43:06 +04:00
|
|
|
{
|
|
|
|
unsigned pixel_bytes, bufsize;
|
|
|
|
|
|
|
|
BX_GUI_THIS snapshot_mode = mode;
|
|
|
|
if (mode) {
|
|
|
|
pixel_bytes = ((BX_GUI_THIS guest_bpp + 1) >> 3);
|
|
|
|
bufsize = BX_GUI_THIS guest_xres * BX_GUI_THIS guest_yres * pixel_bytes;
|
2017-02-18 14:13:56 +03:00
|
|
|
BX_GUI_THIS snapshot_buffer = new Bit8u[bufsize];
|
2012-10-15 23:43:06 +04:00
|
|
|
if (BX_GUI_THIS snapshot_buffer != NULL) {
|
|
|
|
memset(BX_GUI_THIS snapshot_buffer, 0, bufsize);
|
2012-10-28 12:23:39 +04:00
|
|
|
DEV_vga_refresh(1);
|
2012-10-25 19:53:04 +04:00
|
|
|
return bufsize;
|
2012-10-15 23:43:06 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (BX_GUI_THIS snapshot_buffer != NULL) {
|
2017-02-18 14:13:56 +03:00
|
|
|
delete [] BX_GUI_THIS snapshot_buffer;
|
2012-10-15 23:43:06 +04:00
|
|
|
BX_GUI_THIS snapshot_buffer = NULL;
|
|
|
|
DEV_vga_redraw_area(0, 0, BX_GUI_THIS guest_xres, BX_GUI_THIS guest_yres);
|
|
|
|
}
|
|
|
|
}
|
2012-10-25 19:53:04 +04:00
|
|
|
return 0;
|
2012-10-15 23:43:06 +04:00
|
|
|
}
|
|
|
|
|
2002-03-11 18:04:58 +03:00
|
|
|
// create a text snapshot and copy to the system clipboard. On guis that
|
|
|
|
// we haven't figured out how to support yet, dump to a file instead.
|
2006-04-10 23:02:30 +04:00
|
|
|
void bx_gui_c::copy_handler(void)
|
2002-03-11 18:04:58 +03:00
|
|
|
{
|
|
|
|
Bit32u len;
|
|
|
|
char *text_snapshot;
|
2011-08-01 22:21:25 +04:00
|
|
|
|
2012-10-14 22:29:44 +04:00
|
|
|
if (BX_GUI_THIS guest_textmode) {
|
|
|
|
make_text_snapshot(&text_snapshot, &len);
|
2011-08-01 22:21:25 +04:00
|
|
|
if (!BX_GUI_THIS set_clipboard_text(text_snapshot, len)) {
|
|
|
|
// platform specific code failed, use portable code instead
|
|
|
|
FILE *fp = fopen("copy.txt", "w");
|
2016-12-05 21:17:22 +03:00
|
|
|
if (fp != NULL) {
|
|
|
|
fwrite(text_snapshot, 1, len, fp);
|
|
|
|
fclose(fp);
|
|
|
|
}
|
2011-08-01 22:21:25 +04:00
|
|
|
}
|
2017-02-18 14:13:56 +03:00
|
|
|
delete [] text_snapshot;
|
2011-08-01 22:21:25 +04:00
|
|
|
} else {
|
2012-10-14 22:29:44 +04:00
|
|
|
BX_ERROR(("copy button failed, graphics mode not implemented"));
|
2002-03-16 14:30:06 +03:00
|
|
|
}
|
2002-03-11 18:04:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// create a text snapshot and dump it to a file
|
2006-04-10 23:02:30 +04:00
|
|
|
void bx_gui_c::snapshot_handler(void)
|
2002-03-11 18:04:58 +03:00
|
|
|
{
|
2012-10-15 23:43:06 +04:00
|
|
|
int fd, i, j, pitch;
|
2012-10-14 22:29:44 +04:00
|
|
|
Bit8u *snapshot_ptr = NULL;
|
2011-08-05 19:47:33 +04:00
|
|
|
Bit8u *row_buffer, *pixel_ptr, *row_ptr;
|
2011-08-06 17:08:31 +04:00
|
|
|
Bit8u bmp_header[54], iBits, b1, b2;
|
2011-08-03 00:08:34 +04:00
|
|
|
Bit32u ilen, len, rlen;
|
2002-04-18 04:22:20 +04:00
|
|
|
char filename[BX_PATHNAME_LEN];
|
2011-08-01 22:21:25 +04:00
|
|
|
|
2012-10-14 22:29:44 +04:00
|
|
|
if (BX_GUI_THIS guest_textmode) {
|
|
|
|
make_text_snapshot((char**)&snapshot_ptr, &len);
|
2011-08-01 22:21:25 +04:00
|
|
|
if (BX_GUI_THIS dialog_caps & BX_GUI_DLG_SNAPSHOT) {
|
|
|
|
int ret = SIM->ask_filename (filename, sizeof(filename),
|
|
|
|
"Save snapshot as...", "snapshot.txt",
|
|
|
|
bx_param_string_c::SAVE_FILE_DIALOG);
|
|
|
|
if (ret < 0) { // cancelled
|
2017-02-18 14:13:56 +03:00
|
|
|
delete [] snapshot_ptr;
|
2011-08-01 22:21:25 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
strcpy (filename, "snapshot.txt");
|
2002-11-09 09:41:34 +03:00
|
|
|
}
|
2011-08-01 22:21:25 +04:00
|
|
|
FILE *fp = fopen(filename, "wb");
|
2016-12-05 21:17:22 +03:00
|
|
|
if (fp == NULL) {
|
2012-07-28 12:17:08 +04:00
|
|
|
BX_ERROR(("snapshot button failed: cannot create text file"));
|
2017-02-18 14:13:56 +03:00
|
|
|
delete [] snapshot_ptr;
|
2012-07-28 12:17:08 +04:00
|
|
|
return;
|
|
|
|
}
|
2011-08-01 22:21:25 +04:00
|
|
|
fwrite(snapshot_ptr, 1, len, fp);
|
|
|
|
fclose(fp);
|
2017-02-18 14:13:56 +03:00
|
|
|
delete [] snapshot_ptr;
|
2012-10-14 22:29:44 +04:00
|
|
|
} else {
|
2011-08-03 00:08:34 +04:00
|
|
|
if (BX_GUI_THIS dialog_caps & BX_GUI_DLG_SNAPSHOT) {
|
|
|
|
int ret = SIM->ask_filename (filename, sizeof(filename),
|
|
|
|
"Save snapshot as...", "snapshot.bmp",
|
|
|
|
bx_param_string_c::SAVE_FILE_DIALOG);
|
|
|
|
if (ret < 0) { // cancelled
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
strcpy (filename, "snapshot.bmp");
|
|
|
|
}
|
|
|
|
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC
|
|
|
|
#ifdef O_BINARY
|
|
|
|
| O_BINARY
|
|
|
|
#endif
|
|
|
|
, S_IRUSR | S_IWUSR
|
|
|
|
);
|
|
|
|
if (fd < 0) {
|
|
|
|
BX_ERROR(("snapshot button failed: cannot create BMP file"));
|
|
|
|
return;
|
|
|
|
}
|
2012-10-25 19:53:04 +04:00
|
|
|
ilen = BX_GUI_THIS set_snapshot_mode(1);
|
|
|
|
if (ilen > 0) {
|
|
|
|
BX_INFO(("GFX snapshot: %u x %u x %u bpp (%u bytes)", BX_GUI_THIS guest_xres,
|
|
|
|
BX_GUI_THIS guest_yres, BX_GUI_THIS guest_bpp, ilen));
|
|
|
|
} else {
|
2015-01-07 19:17:40 +03:00
|
|
|
close(fd);
|
2012-10-25 19:53:04 +04:00
|
|
|
BX_ERROR(("snapshot button failed: cannot allocate memory"));
|
|
|
|
return;
|
2012-10-15 23:43:06 +04:00
|
|
|
}
|
2012-10-14 22:29:44 +04:00
|
|
|
iBits = (BX_GUI_THIS guest_bpp == 8) ? 8 : 24;
|
|
|
|
rlen = (BX_GUI_THIS guest_xres * (iBits >> 3) + 3) & ~3;
|
|
|
|
len = rlen * BX_GUI_THIS guest_yres + 54;
|
|
|
|
if (BX_GUI_THIS guest_bpp == 8) {
|
2011-08-09 13:56:00 +04:00
|
|
|
len += (256 * 4);
|
|
|
|
}
|
2011-08-05 19:47:33 +04:00
|
|
|
memset(bmp_header, 0, 54);
|
|
|
|
bmp_header[0] = 0x42;
|
|
|
|
bmp_header[1] = 0x4d;
|
|
|
|
bmp_header[2] = len & 0xff;
|
|
|
|
bmp_header[3] = (len >> 8) & 0xff;
|
|
|
|
bmp_header[4] = (len >> 16) & 0xff;
|
|
|
|
bmp_header[5] = (len >> 24) & 0xff;
|
|
|
|
bmp_header[10] = 54;
|
2012-10-14 22:29:44 +04:00
|
|
|
if (BX_GUI_THIS guest_bpp == 8) {
|
2011-08-09 13:56:00 +04:00
|
|
|
bmp_header[11] = 4;
|
|
|
|
}
|
2011-08-05 19:47:33 +04:00
|
|
|
bmp_header[14] = 40;
|
2012-10-14 22:29:44 +04:00
|
|
|
bmp_header[18] = BX_GUI_THIS guest_xres & 0xff;
|
|
|
|
bmp_header[19] = (BX_GUI_THIS guest_xres >> 8) & 0xff;
|
|
|
|
bmp_header[22] = BX_GUI_THIS guest_yres & 0xff;
|
|
|
|
bmp_header[23] = (BX_GUI_THIS guest_yres >> 8) & 0xff;
|
2011-08-05 19:47:33 +04:00
|
|
|
bmp_header[26] = 1;
|
|
|
|
bmp_header[28] = iBits;
|
|
|
|
write(fd, bmp_header, 54);
|
2012-10-14 22:29:44 +04:00
|
|
|
if (BX_GUI_THIS guest_bpp == 8) {
|
2012-10-15 23:43:06 +04:00
|
|
|
write(fd, BX_GUI_THIS palette, 256 * 4);
|
2011-08-05 19:47:33 +04:00
|
|
|
}
|
2012-10-14 22:29:44 +04:00
|
|
|
pitch = BX_GUI_THIS guest_xres * ((BX_GUI_THIS guest_bpp + 1) >> 3);
|
2017-02-18 14:13:56 +03:00
|
|
|
row_buffer = new Bit8u[rlen];
|
2012-10-25 19:53:04 +04:00
|
|
|
row_ptr = BX_GUI_THIS snapshot_buffer + ((BX_GUI_THIS guest_yres - 1) * pitch);
|
2012-10-14 22:29:44 +04:00
|
|
|
for (i = BX_GUI_THIS guest_yres; i > 0; i--) {
|
2011-08-05 19:47:33 +04:00
|
|
|
memset(row_buffer, 0, rlen);
|
2012-10-14 22:29:44 +04:00
|
|
|
if ((BX_GUI_THIS guest_bpp == 8) || (BX_GUI_THIS guest_bpp == 24)) {
|
2011-08-05 19:47:33 +04:00
|
|
|
memcpy(row_buffer, row_ptr, pitch);
|
2012-10-14 22:29:44 +04:00
|
|
|
} else if ((BX_GUI_THIS guest_bpp == 15) || (BX_GUI_THIS guest_bpp == 16)) {
|
2011-08-05 19:47:33 +04:00
|
|
|
pixel_ptr = row_ptr;
|
2012-10-14 22:29:44 +04:00
|
|
|
for (j = 0; j < (int)(BX_GUI_THIS guest_xres * 3); j+=3) {
|
2011-08-05 19:47:33 +04:00
|
|
|
b1 = *(pixel_ptr++);
|
|
|
|
b2 = *(pixel_ptr++);
|
|
|
|
*(row_buffer+j) = (b1 << 3);
|
2012-10-14 22:29:44 +04:00
|
|
|
if (BX_GUI_THIS guest_bpp == 15) {
|
2011-08-05 19:47:33 +04:00
|
|
|
*(row_buffer+j+1) = ((b1 & 0xe0) >> 2) | (b2 << 6);
|
|
|
|
*(row_buffer+j+2) = (b2 & 0x7c) << 1;
|
|
|
|
} else {
|
|
|
|
*(row_buffer+j+1) = ((b1 & 0xe0) >> 3) | (b2 << 5);
|
|
|
|
*(row_buffer+j+2) = (b2 & 0xf8);
|
2011-08-03 20:35:04 +04:00
|
|
|
}
|
|
|
|
}
|
2012-10-14 22:29:44 +04:00
|
|
|
} else if (BX_GUI_THIS guest_bpp == 32) {
|
2011-08-05 19:47:33 +04:00
|
|
|
pixel_ptr = row_ptr;
|
2012-10-14 22:29:44 +04:00
|
|
|
for (j = 0; j < (int)(BX_GUI_THIS guest_xres * 3); j+=3) {
|
2011-08-05 19:47:33 +04:00
|
|
|
*(row_buffer+j) = *(pixel_ptr++);
|
|
|
|
*(row_buffer+j+1) = *(pixel_ptr++);
|
|
|
|
*(row_buffer+j+2) = *(pixel_ptr++);
|
|
|
|
pixel_ptr++;
|
|
|
|
}
|
2011-08-03 00:08:34 +04:00
|
|
|
}
|
2011-08-05 19:47:33 +04:00
|
|
|
write(fd, row_buffer, rlen);
|
|
|
|
row_ptr -= pitch;
|
2011-08-03 00:08:34 +04:00
|
|
|
}
|
2017-02-18 14:13:56 +03:00
|
|
|
delete [] row_buffer;
|
2011-08-03 00:08:34 +04:00
|
|
|
close(fd);
|
2012-10-25 19:53:04 +04:00
|
|
|
BX_GUI_THIS set_snapshot_mode(0);
|
2002-09-21 23:38:47 +04:00
|
|
|
}
|
2001-11-10 01:17:33 +03:00
|
|
|
}
|
|
|
|
|
2002-03-11 18:04:58 +03:00
|
|
|
// Read ASCII chars from the system clipboard and paste them into bochs.
|
|
|
|
// Note that paste cannot work with the key mapping tables loaded.
|
2006-04-10 23:02:30 +04:00
|
|
|
void bx_gui_c::paste_handler(void)
|
2002-03-11 18:04:58 +03:00
|
|
|
{
|
|
|
|
Bit32s nbytes;
|
|
|
|
Bit8u *bytes;
|
|
|
|
if (!bx_keymap.isKeymapLoaded ()) {
|
|
|
|
BX_ERROR (("keyboard_mapping disabled, so paste cannot work"));
|
|
|
|
return;
|
|
|
|
}
|
2002-10-25 01:07:56 +04:00
|
|
|
if (!BX_GUI_THIS get_clipboard_text(&bytes, &nbytes)) {
|
2002-03-16 14:30:06 +03:00
|
|
|
BX_ERROR (("paste not implemented on this platform"));
|
|
|
|
return;
|
|
|
|
}
|
2002-03-11 18:04:58 +03:00
|
|
|
BX_INFO (("pasting %d bytes", nbytes));
|
2002-10-25 01:07:56 +04:00
|
|
|
DEV_kbd_paste_bytes (bytes, nbytes);
|
2002-03-11 18:04:58 +03:00
|
|
|
}
|
|
|
|
|
2006-04-10 23:02:30 +04:00
|
|
|
void bx_gui_c::config_handler(void)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2005-11-12 19:09:55 +03:00
|
|
|
if (BX_GUI_THIS dialog_caps & BX_GUI_DLG_RUNTIME) {
|
2006-06-07 23:40:15 +04:00
|
|
|
SIM->configuration_interface(NULL, CI_RUNTIME_CONFIG);
|
2003-07-18 19:51:02 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2006-04-10 23:02:30 +04:00
|
|
|
void bx_gui_c::toggle_mouse_enable(void)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2006-02-22 22:18:29 +03:00
|
|
|
int old = SIM->get_param_bool(BXPN_MOUSE_ENABLED)->get();
|
2001-08-31 20:06:32 +04:00
|
|
|
BX_DEBUG (("toggle mouse_enabled, now %d", !old));
|
2006-02-22 22:18:29 +03:00
|
|
|
SIM->get_param_bool(BXPN_MOUSE_ENABLED)->set(!old);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2010-05-16 13:01:36 +04:00
|
|
|
bx_bool bx_gui_c::mouse_toggle_check(Bit32u key, bx_bool pressed)
|
|
|
|
{
|
|
|
|
Bit32u newstate;
|
|
|
|
bx_bool toggle = 0;
|
|
|
|
|
2017-01-02 22:11:23 +03:00
|
|
|
if (console_running())
|
|
|
|
return 0;
|
2010-05-16 13:01:36 +04:00
|
|
|
newstate = toggle_keystate;
|
|
|
|
if (pressed) {
|
|
|
|
newstate |= key;
|
|
|
|
if (newstate == toggle_keystate) return 0;
|
|
|
|
switch (toggle_method) {
|
|
|
|
case BX_MOUSE_TOGGLE_CTRL_MB:
|
|
|
|
toggle = (newstate & BX_GUI_MT_CTRL_MB) == BX_GUI_MT_CTRL_MB;
|
2010-05-18 19:33:41 +04:00
|
|
|
if (!toggle) {
|
|
|
|
toggle = (newstate & BX_GUI_MT_CTRL_LRB) == BX_GUI_MT_CTRL_LRB;
|
|
|
|
}
|
2010-05-16 13:01:36 +04:00
|
|
|
break;
|
|
|
|
case BX_MOUSE_TOGGLE_CTRL_F10:
|
|
|
|
toggle = (newstate & BX_GUI_MT_CTRL_F10) == BX_GUI_MT_CTRL_F10;
|
|
|
|
break;
|
|
|
|
case BX_MOUSE_TOGGLE_CTRL_ALT:
|
|
|
|
toggle = (newstate & BX_GUI_MT_CTRL_ALT) == BX_GUI_MT_CTRL_ALT;
|
|
|
|
break;
|
2010-05-18 19:33:41 +04:00
|
|
|
case BX_MOUSE_TOGGLE_F12:
|
|
|
|
toggle = (newstate == BX_GUI_MT_F12);
|
|
|
|
break;
|
2010-05-16 13:01:36 +04:00
|
|
|
}
|
|
|
|
toggle_keystate = newstate;
|
|
|
|
} else {
|
|
|
|
toggle_keystate &= ~key;
|
|
|
|
}
|
|
|
|
return toggle;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* bx_gui_c::get_toggle_info(void)
|
|
|
|
{
|
|
|
|
return mouse_toggle_text;
|
|
|
|
}
|
|
|
|
|
2014-07-08 18:30:27 +04:00
|
|
|
bx_bool bx_gui_c::parse_user_shortcut(const char *val)
|
2002-08-09 10:16:43 +04:00
|
|
|
{
|
2014-07-08 18:30:27 +04:00
|
|
|
char *ptr, shortcut_tmp[512];
|
2005-10-08 15:41:18 +04:00
|
|
|
Bit32u symbol;
|
2014-07-08 18:30:27 +04:00
|
|
|
|
|
|
|
user_shortcut_len = 0;
|
|
|
|
if ((strlen(val) == 0) || !strcmp(val, "none")) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
strcpy(shortcut_tmp, val);
|
|
|
|
ptr = strtok(shortcut_tmp, "-");
|
|
|
|
while (ptr) {
|
|
|
|
symbol = get_user_key(ptr);
|
|
|
|
if (symbol == BX_KEY_UNKNOWN) {
|
|
|
|
BX_ERROR(("Unknown key symbol '%s' ignored", ptr));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (user_shortcut_len < 3) {
|
|
|
|
user_shortcut[user_shortcut_len++] = symbol;
|
|
|
|
ptr = strtok(NULL, "-");
|
|
|
|
} else {
|
|
|
|
BX_ERROR(("Ignoring extra key symbol '%s'", ptr));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void bx_gui_c::userbutton_handler(void)
|
|
|
|
{
|
|
|
|
int i, ret = 1;
|
2002-08-09 10:16:43 +04:00
|
|
|
|
2005-11-12 19:09:55 +03:00
|
|
|
if (BX_GUI_THIS dialog_caps & BX_GUI_DLG_USER) {
|
2006-02-22 22:18:29 +03:00
|
|
|
ret = SIM->ask_param(BXPN_USER_SHORTCUT);
|
2002-11-09 09:41:34 +03:00
|
|
|
}
|
2014-07-08 18:30:27 +04:00
|
|
|
if ((ret > 0) && (BX_GUI_THIS user_shortcut_len > 0)) {
|
2002-08-25 16:32:54 +04:00
|
|
|
i = 0;
|
2014-07-08 18:30:27 +04:00
|
|
|
while (i < BX_GUI_THIS user_shortcut_len) {
|
|
|
|
DEV_kbd_gen_scancode(BX_GUI_THIS user_shortcut[i++]);
|
2002-08-09 10:16:43 +04:00
|
|
|
}
|
|
|
|
i--;
|
|
|
|
while (i >= 0) {
|
2014-07-08 18:30:27 +04:00
|
|
|
DEV_kbd_gen_scancode(BX_GUI_THIS user_shortcut[i--] | BX_KEY_RELEASED);
|
2002-08-09 10:16:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-07 02:11:09 +04:00
|
|
|
void bx_gui_c::save_restore_handler(void)
|
|
|
|
{
|
2006-08-30 00:10:27 +04:00
|
|
|
int ret;
|
|
|
|
char sr_path[BX_PATHNAME_LEN];
|
|
|
|
|
2006-06-07 23:40:15 +04:00
|
|
|
if (BX_GUI_THIS dialog_caps & BX_GUI_DLG_SAVE_RESTORE) {
|
2017-01-12 21:11:38 +03:00
|
|
|
BX_GUI_THIS set_display_mode(DISP_MODE_CONFIG);
|
2006-08-30 00:10:27 +04:00
|
|
|
sr_path[0] = 0;
|
|
|
|
ret = SIM->ask_filename(sr_path, sizeof(sr_path),
|
|
|
|
"Save Bochs state to folder...", "none",
|
|
|
|
bx_param_string_c::SELECT_FOLDER_DLG);
|
|
|
|
if ((ret >= 0) && (strcmp(sr_path, "none"))) {
|
|
|
|
if (SIM->save_state(sr_path)) {
|
|
|
|
if (!SIM->ask_yes_no("WARNING",
|
2012-09-27 22:38:30 +04:00
|
|
|
"The state of cpu, memory, devices and hard drive images is saved now.\n"
|
|
|
|
"It is possible to continue, but when using the restore function in a\n"
|
|
|
|
"new Bochs session, all changes after this checkpoint will be lost.\n\n"
|
2006-08-30 00:10:27 +04:00
|
|
|
"Do you want to continue?", 0)) {
|
|
|
|
power_handler();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-01-12 21:11:38 +03:00
|
|
|
BX_GUI_THIS set_display_mode(DISP_MODE_SIM);
|
2006-06-07 23:40:15 +04:00
|
|
|
}
|
2006-06-07 02:11:09 +04:00
|
|
|
}
|
|
|
|
|
2017-01-14 16:10:20 +03:00
|
|
|
void bx_gui_c::headerbar_click(int x)
|
|
|
|
{
|
|
|
|
int xorigin;
|
|
|
|
|
|
|
|
for (unsigned i=0; i<bx_headerbar_entries; i++) {
|
|
|
|
if (bx_headerbar_entry[i].alignment == BX_GRAVITY_LEFT)
|
|
|
|
xorigin = bx_headerbar_entry[i].xorigin;
|
|
|
|
else
|
|
|
|
xorigin = guest_xres - bx_headerbar_entry[i].xorigin;
|
|
|
|
if ((x>=xorigin) && (x<(xorigin+int(bx_headerbar_entry[i].xdim)))) {
|
|
|
|
if (console_running() && (i != power_hbar_id))
|
|
|
|
return;
|
|
|
|
bx_headerbar_entry[i].f();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-28 23:52:08 +04:00
|
|
|
void bx_gui_c::mouse_enabled_changed(bx_bool val)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2001-06-23 07:18:14 +04:00
|
|
|
// This is only called when SIM->get_init_done is 1. Note that VAL
|
|
|
|
// is the new value of mouse_enabled, which may not match the old
|
2006-02-22 22:18:29 +03:00
|
|
|
// value which is still in SIM->get_param_bool(BXPN_MOUSE_ENABLED)->get().
|
2001-08-31 20:06:32 +04:00
|
|
|
BX_DEBUG (("replacing the mouse bitmaps"));
|
2001-06-17 03:08:32 +04:00
|
|
|
if (val)
|
2002-10-25 01:07:56 +04:00
|
|
|
BX_GUI_THIS replace_bitmap(BX_GUI_THIS mouse_hbar_id, BX_GUI_THIS mouse_bmap_id);
|
2001-06-10 00:01:12 +04:00
|
|
|
else
|
2002-10-25 01:07:56 +04:00
|
|
|
BX_GUI_THIS replace_bitmap(BX_GUI_THIS mouse_hbar_id, BX_GUI_THIS nomouse_bmap_id);
|
2001-06-23 07:18:14 +04:00
|
|
|
// give the GUI a chance to respond to the event. Most guis will hide
|
|
|
|
// the native mouse cursor and do something to trap the mouse inside the
|
|
|
|
// bochs VGA display window.
|
2002-10-25 01:07:56 +04:00
|
|
|
BX_GUI_THIS mouse_enabled_changed_specific (val);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2001-05-09 00:18:04 +04:00
|
|
|
|
2006-04-10 23:02:30 +04:00
|
|
|
void bx_gui_c::init_signal_handlers()
|
2001-05-09 00:18:04 +04:00
|
|
|
{
|
|
|
|
#if BX_GUI_SIGHANDLER
|
2008-02-06 01:57:43 +03:00
|
|
|
if (bx_gui_sighandler)
|
2001-05-09 00:18:04 +04:00
|
|
|
{
|
2002-11-11 20:09:57 +03:00
|
|
|
Bit32u mask = bx_gui->get_sighandler_mask ();
|
|
|
|
for (Bit32u sig=0; sig<32; sig++)
|
|
|
|
{
|
|
|
|
if (mask & (1<<sig))
|
|
|
|
signal (sig, bx_signal_handler);
|
|
|
|
}
|
2001-05-09 00:18:04 +04:00
|
|
|
}
|
|
|
|
#endif
|
2002-09-08 11:56:10 +04:00
|
|
|
}
|
|
|
|
|
2006-04-10 23:02:30 +04:00
|
|
|
void bx_gui_c::set_text_charmap(Bit8u *fbuffer)
|
2002-09-08 11:56:10 +04:00
|
|
|
{
|
|
|
|
memcpy(& BX_GUI_THIS vga_charmap, fbuffer, 0x2000);
|
2002-09-21 23:38:47 +04:00
|
|
|
for (unsigned i=0; i<256; i++) BX_GUI_THIS char_changed[i] = 1;
|
|
|
|
BX_GUI_THIS charmap_updated = 1;
|
2002-09-19 22:59:50 +04:00
|
|
|
}
|
|
|
|
|
2006-04-10 23:02:30 +04:00
|
|
|
void bx_gui_c::set_text_charbyte(Bit16u address, Bit8u data)
|
2002-09-19 22:59:50 +04:00
|
|
|
{
|
|
|
|
BX_GUI_THIS vga_charmap[address] = data;
|
2002-09-21 23:38:47 +04:00
|
|
|
BX_GUI_THIS char_changed[address >> 5] = 1;
|
|
|
|
BX_GUI_THIS charmap_updated = 1;
|
2001-05-09 00:18:04 +04:00
|
|
|
}
|
2008-02-06 01:57:43 +03:00
|
|
|
|
2006-04-10 23:02:30 +04:00
|
|
|
void bx_gui_c::beep_on(float frequency)
|
2004-02-02 02:48:57 +03:00
|
|
|
{
|
2011-10-09 12:20:32 +04:00
|
|
|
BX_DEBUG(("GUI Beep ON (frequency=%.2f)", frequency));
|
2004-02-02 02:48:57 +03:00
|
|
|
}
|
|
|
|
|
2006-04-10 23:02:30 +04:00
|
|
|
void bx_gui_c::beep_off()
|
2004-02-02 02:48:57 +03:00
|
|
|
{
|
2011-10-09 12:20:32 +04:00
|
|
|
BX_DEBUG(("GUI Beep OFF"));
|
2004-02-02 02:48:57 +03:00
|
|
|
}
|
2004-02-07 17:34:35 +03:00
|
|
|
|
2011-12-28 15:51:42 +04:00
|
|
|
int bx_gui_c::register_statusitem(const char *text, bx_bool auto_off)
|
2004-02-07 17:34:35 +03:00
|
|
|
{
|
2015-07-13 19:56:06 +03:00
|
|
|
unsigned id = statusitem_count;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < statusitem_count; i++) {
|
|
|
|
if (!statusitem[i].in_use) {
|
|
|
|
id = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (id == statusitem_count) {
|
|
|
|
if (++statusitem_count > BX_MAX_STATUSITEMS) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
statusitem[id].in_use = 1;
|
|
|
|
strncpy(statusitem[id].text, text, 8);
|
|
|
|
statusitem[id].text[7] = 0;
|
|
|
|
statusitem[id].auto_off = auto_off;
|
|
|
|
statusitem[id].counter = 0;
|
|
|
|
statusitem[id].active = 0;
|
|
|
|
statusitem[id].mode = 0;
|
2015-08-11 20:48:18 +03:00
|
|
|
statusbar_setitem_specific(id, 0, 0);
|
2015-07-13 19:56:06 +03:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bx_gui_c::unregister_statusitem(int id)
|
|
|
|
{
|
2015-07-28 21:44:08 +03:00
|
|
|
if ((id >= 0) && (id < (int)statusitem_count)) {
|
2015-07-13 19:56:06 +03:00
|
|
|
strcpy(statusitem[id].text, " ");
|
2015-08-11 20:48:18 +03:00
|
|
|
statusbar_setitem_specific(id, 0, 0);
|
2015-07-13 19:56:06 +03:00
|
|
|
if (id == (int)(statusitem_count - 1)) {
|
|
|
|
statusitem_count--;
|
|
|
|
} else {
|
|
|
|
statusitem[id].in_use = 0;
|
|
|
|
}
|
2004-02-07 17:34:35 +03:00
|
|
|
}
|
|
|
|
}
|
2004-02-22 16:03:02 +03:00
|
|
|
|
2012-01-04 00:11:12 +04:00
|
|
|
void bx_gui_c::statusbar_setitem(int element, bx_bool active, bx_bool w)
|
|
|
|
{
|
|
|
|
if (element < 0) {
|
|
|
|
for (unsigned i = 0; i < statusitem_count; i++) {
|
2012-01-06 02:31:19 +04:00
|
|
|
statusbar_setitem_specific(i, 0, 0);
|
2012-01-04 00:11:12 +04:00
|
|
|
}
|
|
|
|
} else if ((unsigned)element < statusitem_count) {
|
|
|
|
if ((active != statusitem[element].active) ||
|
|
|
|
(w != statusitem[element].mode)) {
|
|
|
|
statusbar_setitem_specific(element, active, w);
|
|
|
|
statusitem[element].active = active;
|
|
|
|
statusitem[element].mode = w;
|
|
|
|
}
|
|
|
|
if (active && statusitem[element].auto_off) {
|
|
|
|
statusitem[element].counter = 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-28 15:51:42 +04:00
|
|
|
void bx_gui_c::led_timer_handler(void *this_ptr)
|
|
|
|
{
|
|
|
|
bx_gui_c *class_ptr = (bx_gui_c *) this_ptr;
|
|
|
|
class_ptr->led_timer();
|
|
|
|
}
|
|
|
|
|
|
|
|
void bx_gui_c::led_timer()
|
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < statusitem_count; i++) {
|
|
|
|
if (statusitem[i].auto_off) {
|
|
|
|
if (statusitem[i].counter > 0) {
|
|
|
|
if (!(--statusitem[i].counter)) {
|
|
|
|
statusbar_setitem(i, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-10 23:02:30 +04:00
|
|
|
void bx_gui_c::get_capabilities(Bit16u *xres, Bit16u *yres, Bit16u *bpp)
|
2004-02-22 16:03:02 +03:00
|
|
|
{
|
|
|
|
*xres = 1024;
|
|
|
|
*yres = 768;
|
|
|
|
*bpp = 32;
|
|
|
|
}
|
2004-08-15 23:27:15 +04:00
|
|
|
|
2017-01-15 14:44:43 +03:00
|
|
|
bx_bool bx_gui_c::palette_change_common(Bit8u index, Bit8u red, Bit8u green, Bit8u blue)
|
|
|
|
{
|
|
|
|
BX_GUI_THIS palette[index].red = red;
|
|
|
|
BX_GUI_THIS palette[index].green = green;
|
|
|
|
BX_GUI_THIS palette[index].blue = blue;
|
|
|
|
return palette_change(index, red, green, blue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void bx_gui_c::show_ips(Bit32u ips_count)
|
|
|
|
{
|
|
|
|
#if BX_SHOW_IPS
|
|
|
|
BX_INFO(("ips = %3.3fM", ips_count / 1000000.0));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
Bit8u bx_gui_c::get_mouse_headerbar_id()
|
|
|
|
{
|
|
|
|
return BX_GUI_THIS mouse_hbar_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if BX_DEBUGGER && BX_DEBUGGER_GUI
|
|
|
|
void bx_gui_c::init_debug_dialog()
|
|
|
|
{
|
|
|
|
extern void InitDebugDialog();
|
|
|
|
InitDebugDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
void bx_gui_c::close_debug_dialog()
|
|
|
|
{
|
|
|
|
extern void CloseDebugDialog();
|
|
|
|
CloseDebugDialog();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// new graphics API (compatibility code)
|
|
|
|
|
2006-04-10 23:02:30 +04:00
|
|
|
bx_svga_tileinfo_t *bx_gui_c::graphics_tile_info(bx_svga_tileinfo_t *info)
|
2004-08-15 23:27:15 +04:00
|
|
|
{
|
|
|
|
BX_GUI_THIS host_pitch = BX_GUI_THIS host_xres * ((BX_GUI_THIS host_bpp + 1) >> 3);
|
|
|
|
|
|
|
|
info->bpp = BX_GUI_THIS host_bpp;
|
|
|
|
info->pitch = BX_GUI_THIS host_pitch;
|
|
|
|
switch (info->bpp) {
|
|
|
|
case 15:
|
|
|
|
info->red_shift = 15;
|
|
|
|
info->green_shift = 10;
|
|
|
|
info->blue_shift = 5;
|
|
|
|
info->red_mask = 0x7c00;
|
|
|
|
info->green_mask = 0x03e0;
|
|
|
|
info->blue_mask = 0x001f;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
info->red_shift = 16;
|
|
|
|
info->green_shift = 11;
|
|
|
|
info->blue_shift = 5;
|
|
|
|
info->red_mask = 0xf800;
|
|
|
|
info->green_mask = 0x07e0;
|
|
|
|
info->blue_mask = 0x001f;
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
case 32:
|
|
|
|
info->red_shift = 24;
|
|
|
|
info->green_shift = 16;
|
|
|
|
info->blue_shift = 8;
|
|
|
|
info->red_mask = 0xff0000;
|
|
|
|
info->green_mask = 0x00ff00;
|
|
|
|
info->blue_mask = 0x0000ff;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
info->is_indexed = (BX_GUI_THIS host_bpp == 8);
|
|
|
|
#ifdef BX_LITTLE_ENDIAN
|
|
|
|
info->is_little_endian = 1;
|
|
|
|
#else
|
|
|
|
info->is_little_endian = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2006-04-10 23:02:30 +04:00
|
|
|
Bit8u *bx_gui_c::graphics_tile_get(unsigned x0, unsigned y0,
|
2004-08-15 23:27:15 +04:00
|
|
|
unsigned *w, unsigned *h)
|
|
|
|
{
|
2012-01-21 16:15:10 +04:00
|
|
|
if (x0+BX_GUI_THIS x_tilesize > BX_GUI_THIS host_xres) {
|
2004-08-15 23:27:15 +04:00
|
|
|
*w = BX_GUI_THIS host_xres - x0;
|
2012-01-21 16:15:10 +04:00
|
|
|
} else {
|
|
|
|
*w = BX_GUI_THIS x_tilesize;
|
2004-08-15 23:27:15 +04:00
|
|
|
}
|
|
|
|
|
2012-01-21 16:15:10 +04:00
|
|
|
if (y0+BX_GUI_THIS y_tilesize > BX_GUI_THIS host_yres) {
|
2004-08-15 23:27:15 +04:00
|
|
|
*h = BX_GUI_THIS host_yres - y0;
|
2012-01-21 16:15:10 +04:00
|
|
|
} else {
|
|
|
|
*h = BX_GUI_THIS y_tilesize;
|
2004-08-15 23:27:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return (Bit8u *)framebuffer + y0 * BX_GUI_THIS host_pitch +
|
|
|
|
x0 * ((BX_GUI_THIS host_bpp + 1) >> 3);
|
|
|
|
}
|
|
|
|
|
2006-04-10 23:02:30 +04:00
|
|
|
void bx_gui_c::graphics_tile_update_in_place(unsigned x0, unsigned y0,
|
2004-08-15 23:27:15 +04:00
|
|
|
unsigned w, unsigned h)
|
|
|
|
{
|
2012-01-21 16:15:10 +04:00
|
|
|
Bit8u *tile;
|
2004-08-15 23:27:15 +04:00
|
|
|
Bit8u *tile_ptr, *fb_ptr;
|
|
|
|
Bit16u xc, yc, fb_pitch, tile_pitch;
|
|
|
|
Bit8u r, diffx, diffy;
|
|
|
|
|
2012-01-21 16:15:10 +04:00
|
|
|
tile = new Bit8u[BX_GUI_THIS x_tilesize * BX_GUI_THIS y_tilesize * 4];
|
|
|
|
diffx = (x0 % BX_GUI_THIS x_tilesize);
|
|
|
|
diffy = (y0 % BX_GUI_THIS y_tilesize);
|
2004-08-15 23:27:15 +04:00
|
|
|
if (diffx > 0) {
|
|
|
|
x0 -= diffx;
|
|
|
|
w += diffx;
|
|
|
|
}
|
|
|
|
if (diffy > 0) {
|
|
|
|
y0 -= diffy;
|
|
|
|
h += diffy;
|
|
|
|
}
|
|
|
|
fb_pitch = BX_GUI_THIS host_pitch;
|
2012-01-21 16:15:10 +04:00
|
|
|
tile_pitch = BX_GUI_THIS x_tilesize * ((BX_GUI_THIS host_bpp + 1) >> 3);
|
|
|
|
for (yc=y0; yc<(y0+h); yc+=BX_GUI_THIS y_tilesize) {
|
|
|
|
for (xc=x0; xc<(x0+w); xc+=BX_GUI_THIS x_tilesize) {
|
2004-08-15 23:27:15 +04:00
|
|
|
fb_ptr = BX_GUI_THIS framebuffer + (yc * fb_pitch + xc * ((BX_GUI_THIS host_bpp + 1) >> 3));
|
|
|
|
tile_ptr = &tile[0];
|
|
|
|
for (r=0; r<h; r++) {
|
|
|
|
memcpy(tile_ptr, fb_ptr, tile_pitch);
|
|
|
|
fb_ptr += fb_pitch;
|
|
|
|
tile_ptr += tile_pitch;
|
|
|
|
}
|
|
|
|
BX_GUI_THIS graphics_tile_update(tile, xc, yc);
|
|
|
|
}
|
|
|
|
}
|
2012-01-21 16:15:10 +04:00
|
|
|
delete [] tile;
|
2005-10-13 20:22:21 +04:00
|
|
|
}
|
|
|
|
|
2012-10-15 23:43:06 +04:00
|
|
|
void bx_gui_c::graphics_tile_update_common(Bit8u *tile, unsigned x, unsigned y)
|
|
|
|
{
|
|
|
|
unsigned i, pitch, pixel_bytes, nbytes, tilebytes;
|
|
|
|
Bit8u *src, *dst;
|
|
|
|
|
|
|
|
if (BX_GUI_THIS snapshot_mode) {
|
|
|
|
if (BX_GUI_THIS snapshot_buffer != NULL) {
|
|
|
|
pixel_bytes = ((BX_GUI_THIS guest_bpp + 1) >> 3);
|
|
|
|
tilebytes = BX_GUI_THIS x_tilesize * pixel_bytes;
|
|
|
|
if ((x + BX_GUI_THIS x_tilesize) <= BX_GUI_THIS guest_xres) {
|
|
|
|
nbytes = tilebytes;
|
|
|
|
} else {
|
|
|
|
nbytes = (BX_GUI_THIS guest_xres - x) * pixel_bytes;
|
|
|
|
}
|
|
|
|
pitch = BX_GUI_THIS guest_xres * pixel_bytes;
|
|
|
|
src = tile;
|
|
|
|
dst = BX_GUI_THIS snapshot_buffer + (y * pitch) + x;
|
|
|
|
for (i = 0; i < y_tilesize; i++) {
|
|
|
|
memcpy(dst, src, nbytes);
|
|
|
|
src += tilebytes;
|
|
|
|
dst += pitch;
|
|
|
|
if (++y >= BX_GUI_THIS guest_yres) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
graphics_tile_update(tile, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-25 19:53:04 +04:00
|
|
|
bx_svga_tileinfo_t * bx_gui_c::graphics_tile_info_common(bx_svga_tileinfo_t *info)
|
|
|
|
{
|
|
|
|
if (!info) {
|
2017-02-18 14:13:56 +03:00
|
|
|
info = new bx_svga_tileinfo_t;
|
2012-10-25 19:53:04 +04:00
|
|
|
if (!info) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
info->snapshot_mode = BX_GUI_THIS snapshot_mode;
|
|
|
|
if (BX_GUI_THIS snapshot_mode) {
|
|
|
|
info->pitch = BX_GUI_THIS guest_xres * ((BX_GUI_THIS guest_bpp + 1) >> 3);
|
|
|
|
} else {
|
|
|
|
return graphics_tile_info(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2017-01-13 18:57:36 +03:00
|
|
|
#if BX_USE_GUI_CONSOLE
|
2017-01-01 20:45:06 +03:00
|
|
|
|
|
|
|
#define BX_CONSOLE_BUFSIZE 4000
|
|
|
|
|
|
|
|
void bx_gui_c::console_init(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
console.screen = new Bit8u[BX_CONSOLE_BUFSIZE];
|
|
|
|
console.oldscreen = new Bit8u[BX_CONSOLE_BUFSIZE];
|
|
|
|
for (i = 0; i < BX_CONSOLE_BUFSIZE; i+=2) {
|
|
|
|
console.screen[i] = 0x20;
|
|
|
|
console.screen[i+1] = 0x07;
|
|
|
|
}
|
|
|
|
memset(console.oldscreen, 0xff, BX_CONSOLE_BUFSIZE);
|
|
|
|
console.saved_xres = guest_xres;
|
|
|
|
console.saved_yres = guest_yres;
|
|
|
|
console.saved_bpp = guest_bpp;
|
|
|
|
console.saved_fsize = guest_fsize;
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
memcpy(&BX_GUI_THIS vga_charmap[0]+i*32, &sdl_font8x16[i], 16);
|
|
|
|
BX_GUI_THIS char_changed[i] = 1;
|
|
|
|
}
|
|
|
|
BX_GUI_THIS charmap_updated = 1;
|
|
|
|
console.cursor_x = 0;
|
|
|
|
console.cursor_y = 0;
|
|
|
|
memset(&console.tminfo, 0, sizeof(bx_vga_tminfo_t));
|
|
|
|
console.tminfo.line_offset = 160;
|
|
|
|
console.tminfo.line_compare = 1023;
|
2017-01-02 22:11:23 +03:00
|
|
|
console.tminfo.cs_start = 0x2e;
|
|
|
|
console.tminfo.cs_end = 0x0f;
|
2017-01-01 20:45:06 +03:00
|
|
|
console.tminfo.actl_palette[7] = 0x07;
|
2017-03-03 15:43:20 +03:00
|
|
|
memcpy(console.saved_palette, palette, 32);
|
|
|
|
palette_change_common(0x00, 0x00, 0x00, 0x00);
|
|
|
|
palette_change_common(0x07, 0xa8, 0xa8, 0xa8);
|
2017-01-01 20:45:06 +03:00
|
|
|
dimension_update(720, 400, 16, 9, 8);
|
|
|
|
console.n_keys = 0;
|
|
|
|
console.running = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bx_gui_c::console_cleanup(void)
|
|
|
|
{
|
|
|
|
delete [] console.screen;
|
|
|
|
delete [] console.oldscreen;
|
2017-03-03 15:43:20 +03:00
|
|
|
palette_change_common(0x00, console.saved_palette[2], console.saved_palette[1],
|
|
|
|
console.saved_palette[0]);
|
|
|
|
palette_change_common(0x07, console.saved_palette[30], console.saved_palette[29],
|
|
|
|
console.saved_palette[28]);
|
2017-01-01 20:45:06 +03:00
|
|
|
unsigned fheight = (console.saved_fsize >> 4);
|
|
|
|
unsigned fwidth = (console.saved_fsize & 0x0f);
|
|
|
|
dimension_update(console.saved_xres, console.saved_yres, fheight, fwidth,
|
|
|
|
console.saved_bpp);
|
|
|
|
console.running = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bx_gui_c::console_refresh(bx_bool force)
|
|
|
|
{
|
|
|
|
if (force) memset(console.oldscreen, 0xff, BX_CONSOLE_BUFSIZE);
|
|
|
|
text_update(console.oldscreen, console.screen, console.cursor_x,
|
|
|
|
console.cursor_y, &console.tminfo);
|
2017-01-03 23:59:59 +03:00
|
|
|
flush();
|
2017-01-01 20:45:06 +03:00
|
|
|
memcpy(console.oldscreen, console.screen, BX_CONSOLE_BUFSIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void bx_gui_c::console_key_enq(Bit8u key)
|
|
|
|
{
|
|
|
|
if (console.n_keys < 16) {
|
|
|
|
console.keys[console.n_keys++] = key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int bx_gui_c::bx_printf(const char *s)
|
|
|
|
{
|
|
|
|
unsigned offset;
|
|
|
|
|
|
|
|
if (!console.running) {
|
|
|
|
console_init();
|
|
|
|
}
|
|
|
|
for (unsigned i = 0; i < strlen(s); i++) {
|
|
|
|
offset = console.cursor_y * 160 + console.cursor_x * 2;
|
|
|
|
if ((s[i] != 0x08) && (s[i] != 0x0a)) {
|
|
|
|
console.screen[offset] = s[i];
|
|
|
|
console.screen[offset+1] = 0x07;
|
|
|
|
console.cursor_x++;
|
|
|
|
}
|
|
|
|
if ((s[i] == 0x0a) || (console.cursor_x == 80)) {
|
|
|
|
console.cursor_x = 0;
|
|
|
|
console.cursor_y++;
|
|
|
|
}
|
|
|
|
if (s[i] == 0x08) {
|
|
|
|
if (offset > 0) {
|
|
|
|
console.screen[offset-2] = 0x20;
|
|
|
|
console.screen[offset-1] = 0x07;
|
|
|
|
if (console.cursor_x > 0) {
|
|
|
|
console.cursor_x--;
|
|
|
|
} else {
|
|
|
|
console.cursor_x = 79;
|
|
|
|
console.cursor_y--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (console.cursor_y == 25) {
|
|
|
|
memcpy(console.screen, console.screen+160, BX_CONSOLE_BUFSIZE-160);
|
|
|
|
console.cursor_y--;
|
|
|
|
offset = console.cursor_y * 160 + console.cursor_x * 2;
|
|
|
|
for (int j = 0; j < 160; j+=2) {
|
|
|
|
console.screen[offset+j] = 0x20;
|
|
|
|
console.screen[offset+j+1] = 0x07;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console_refresh(0);
|
|
|
|
return strlen(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
char* bx_gui_c::bx_gets(char *s, int size)
|
|
|
|
{
|
|
|
|
char keystr[2];
|
|
|
|
int pos = 0, done = 0;
|
2017-01-02 22:11:23 +03:00
|
|
|
int cs_counter = 1, cs_visible = 0;
|
2017-01-01 20:45:06 +03:00
|
|
|
|
2017-01-14 00:37:06 +03:00
|
|
|
set_console_edit_mode(1);
|
2017-01-01 20:45:06 +03:00
|
|
|
keystr[1] = 0;
|
|
|
|
do {
|
|
|
|
handle_events();
|
2017-01-02 22:11:23 +03:00
|
|
|
while (console.n_keys > 0) {
|
2017-01-01 20:45:06 +03:00
|
|
|
if ((console.keys[0] >= 0x20) && (pos < (size-1))) {
|
|
|
|
s[pos++] = console.keys[0];
|
|
|
|
keystr[0] = console.keys[0];
|
|
|
|
bx_printf(keystr);
|
|
|
|
} else if (console.keys[0] == 0x0d) {
|
|
|
|
s[pos] = 0x00;
|
|
|
|
keystr[0] = 0x0a;
|
|
|
|
bx_printf(keystr);
|
|
|
|
done = 1;
|
|
|
|
} else if ((console.keys[0] == 0x08) && (pos > 0)) {
|
|
|
|
pos--;
|
|
|
|
keystr[0] = 0x08;
|
|
|
|
bx_printf(keystr);
|
|
|
|
}
|
|
|
|
memcpy(&console.keys[0], &console.keys[1], 15);
|
|
|
|
console.n_keys--;
|
|
|
|
}
|
|
|
|
#if BX_HAVE_USLEEP
|
|
|
|
usleep(25000);
|
|
|
|
#else
|
|
|
|
msleep(25);
|
|
|
|
#endif
|
2017-01-02 22:11:23 +03:00
|
|
|
if (--cs_counter == 0) {
|
|
|
|
cs_counter = 10;
|
|
|
|
cs_visible ^= 1;
|
|
|
|
if (cs_visible) {
|
|
|
|
console.tminfo.cs_start &= ~0x20;
|
|
|
|
} else {
|
|
|
|
console.tminfo.cs_start |= 0x20;
|
|
|
|
}
|
|
|
|
console_refresh(0);
|
|
|
|
}
|
2017-01-01 20:45:06 +03:00
|
|
|
} while (!done);
|
2017-01-02 22:11:23 +03:00
|
|
|
console.tminfo.cs_start |= 0x20;
|
2017-01-14 00:37:06 +03:00
|
|
|
set_console_edit_mode(0);
|
2017-01-01 20:45:06 +03:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
#endif
|