2002-03-06 23:39:23 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2011-02-25 01:05:47 +03:00
|
|
|
// $Id$
|
2002-03-06 23:39:23 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2017-01-03 23:59:59 +03:00
|
|
|
// Copyright (C) 2002-2017 The Bochs Project
|
2002-03-06 23:39:23 +03: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
|
2008-02-16 01:05:43 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2002-03-06 23:39:23 +03:00
|
|
|
|
2002-02-05 08:51:38 +03:00
|
|
|
#define _MULTI_THREAD
|
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
// Define BX_PLUGGABLE in files that can be compiled into plugins. For
|
2008-02-06 01:57:43 +03:00
|
|
|
// platforms that require a special tag on exported symbols, BX_PLUGGABLE
|
2002-10-25 01:07:56 +04:00
|
|
|
// is used to know when we are exporting symbols and when we are importing.
|
|
|
|
#define BX_PLUGGABLE
|
|
|
|
|
2002-11-19 08:47:45 +03:00
|
|
|
#include "bochs.h"
|
2010-02-26 17:18:19 +03:00
|
|
|
#include "param_names.h"
|
2009-02-23 14:06:53 +03:00
|
|
|
#include "keymap.h"
|
2004-06-19 19:20:15 +04:00
|
|
|
#include "iodev.h"
|
2002-11-19 08:47:45 +03:00
|
|
|
#if BX_WITH_SDL
|
|
|
|
|
2002-02-05 08:51:38 +03:00
|
|
|
#include <stdlib.h>
|
2004-08-06 19:49:55 +04:00
|
|
|
#include <SDL.h>
|
|
|
|
#include <SDL_endian.h>
|
2002-02-05 08:51:38 +03:00
|
|
|
|
|
|
|
#include "icon_bochs.h"
|
|
|
|
#include "sdl.h"
|
2005-10-22 15:00:00 +04:00
|
|
|
#ifdef WIN32
|
|
|
|
#include "win32dialog.h"
|
|
|
|
#endif
|
2002-02-05 08:51:38 +03:00
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
class bx_sdl_gui_c : public bx_gui_c {
|
|
|
|
public:
|
2014-07-10 14:31:51 +04:00
|
|
|
bx_sdl_gui_c();
|
2002-10-25 01:07:56 +04:00
|
|
|
DECLARE_GUI_VIRTUAL_METHODS()
|
2004-08-15 23:27:15 +04:00
|
|
|
DECLARE_GUI_NEW_VIRTUAL_METHODS()
|
2008-03-07 00:15:40 +03:00
|
|
|
virtual void set_display_mode(disp_mode_t newmode);
|
2012-01-04 00:11:12 +04:00
|
|
|
virtual void statusbar_setitem_specific(int element, bx_bool active, bx_bool w);
|
2014-07-10 14:31:51 +04:00
|
|
|
virtual void get_capabilities(Bit16u *xres, Bit16u *yres, Bit16u *bpp);
|
2012-06-24 14:38:46 +04:00
|
|
|
virtual void set_mouse_mode_absxy(bx_bool mode);
|
2006-01-22 21:15:48 +03:00
|
|
|
#if BX_SHOW_IPS
|
2006-01-22 19:30:48 +03:00
|
|
|
virtual void show_ips(Bit32u ips_count);
|
2006-01-22 21:15:48 +03:00
|
|
|
#endif
|
2002-10-25 01:07:56 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// declare one instance of the gui object and call macro to insert the
|
|
|
|
// plugin code
|
|
|
|
static bx_sdl_gui_c *theGui = NULL;
|
|
|
|
IMPLEMENT_GUI_PLUGIN_CODE(sdl)
|
|
|
|
|
|
|
|
#define LOG_THIS theGui->
|
2002-02-05 08:51:38 +03:00
|
|
|
|
2004-02-14 00:45:28 +03:00
|
|
|
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
|
|
|
const Uint32 status_led_green = 0x00ff0000;
|
2004-03-01 00:16:18 +03:00
|
|
|
const Uint32 status_gray_text = 0x80808000;
|
2008-10-07 02:00:11 +04:00
|
|
|
const Uint32 status_led_red = 0x0040ff00;
|
2004-02-14 00:45:28 +03:00
|
|
|
#else
|
|
|
|
const Uint32 status_led_green = 0x0000ff00;
|
2004-03-01 00:16:18 +03:00
|
|
|
const Uint32 status_gray_text = 0x00808080;
|
2008-10-07 02:00:11 +04:00
|
|
|
const Uint32 status_led_red = 0x00ff4000;
|
2004-02-14 00:45:28 +03:00
|
|
|
#endif
|
|
|
|
|
2002-02-16 23:31:35 +03:00
|
|
|
static unsigned prev_cursor_x=0;
|
|
|
|
static unsigned prev_cursor_y=0;
|
2014-07-05 12:00:01 +04:00
|
|
|
static Bit32u convertStringToSDLKey(const char *string);
|
2002-02-16 23:31:35 +03:00
|
|
|
|
2002-03-06 23:38:31 +03:00
|
|
|
#define MAX_SDL_BITMAPS 32
|
2002-02-07 05:12:51 +03:00
|
|
|
struct bitmaps {
|
|
|
|
SDL_Surface *surface;
|
2017-01-03 23:59:59 +03:00
|
|
|
SDL_Rect src, dst;
|
2002-02-07 05:12:51 +03:00
|
|
|
};
|
2002-02-06 05:12:45 +03:00
|
|
|
|
|
|
|
SDL_Surface *sdl_screen, *sdl_fullscreen;
|
2014-07-10 14:31:51 +04:00
|
|
|
SDL_Rect sdl_maxres;
|
2002-02-06 05:12:45 +03:00
|
|
|
int sdl_fullscreen_toggle;
|
2002-02-06 00:39:15 +03:00
|
|
|
int sdl_grab;
|
2002-04-20 11:19:35 +04:00
|
|
|
unsigned res_x, res_y;
|
2002-10-06 21:17:14 +04:00
|
|
|
unsigned half_res_x, half_res_y;
|
2002-02-06 00:39:15 +03:00
|
|
|
int headerbar_height;
|
2002-03-17 15:34:03 +03:00
|
|
|
static unsigned bx_bitmap_left_xorigin = 0; // pixels from left
|
|
|
|
static unsigned bx_bitmap_right_xorigin = 0; // pixels from right
|
2008-01-26 03:00:31 +03:00
|
|
|
static unsigned int text_rows = 25, text_cols = 80;
|
2003-05-10 21:03:36 +04:00
|
|
|
Bit8u h_panning = 0, v_panning = 0;
|
2004-04-09 19:04:54 +04:00
|
|
|
Bit16u line_compare = 1023;
|
2002-02-05 08:51:38 +03:00
|
|
|
int fontwidth = 8, fontheight = 16;
|
2012-10-14 22:29:44 +04:00
|
|
|
static unsigned disp_bpp=8;
|
2002-02-05 08:51:38 +03:00
|
|
|
unsigned char menufont[256][8];
|
2012-10-14 22:29:44 +04:00
|
|
|
Uint32 sdl_palette[256];
|
2002-02-06 05:12:45 +03:00
|
|
|
Uint32 headerbar_fg, headerbar_bg;
|
2002-02-06 00:39:15 +03:00
|
|
|
Bit8u old_mousebuttons=0, new_mousebuttons=0;
|
|
|
|
int old_mousex=0, new_mousex=0;
|
|
|
|
int old_mousey=0, new_mousey=0;
|
2012-06-24 14:38:46 +04:00
|
|
|
bx_bool just_warped = 0;
|
|
|
|
bx_bool sdl_mouse_mode_absxy = 0;
|
2002-03-06 23:36:35 +03:00
|
|
|
bitmaps *sdl_bitmaps[MAX_SDL_BITMAPS];
|
|
|
|
int n_sdl_bitmaps = 0;
|
2004-02-14 00:45:28 +03:00
|
|
|
int statusbar_height = 18;
|
|
|
|
static unsigned statusitem_pos[12] = {
|
2015-10-23 21:39:38 +03:00
|
|
|
0, 170, 220, 270, 320, 370, 420, 470, 520, 570, 620, 670
|
2004-02-14 00:45:28 +03:00
|
|
|
};
|
|
|
|
static bx_bool statusitem_active[12];
|
2006-01-23 21:34:47 +03:00
|
|
|
#if BX_SHOW_IPS
|
2012-05-11 20:17:59 +04:00
|
|
|
static bx_bool sdl_hide_ips = 0;
|
2006-01-23 21:34:47 +03:00
|
|
|
static bx_bool sdl_ips_update = 0;
|
|
|
|
static char sdl_ips_text[20];
|
|
|
|
#endif
|
2002-02-05 08:51:38 +03:00
|
|
|
|
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
static void sdl_set_status_text(int element, const char *text, bx_bool active, bx_bool w = 0)
|
|
|
|
{
|
|
|
|
Uint32 *buf, *buf_row;
|
|
|
|
Uint32 disp, fgcolor, bgcolor;
|
|
|
|
unsigned char *pfont_row, font_row;
|
|
|
|
int rowsleft = statusbar_height - 2;
|
|
|
|
int colsleft, textlen;
|
|
|
|
int x, xleft, xsize;
|
|
|
|
|
|
|
|
statusitem_active[element] = active;
|
2014-07-05 12:00:01 +04:00
|
|
|
if (!sdl_screen) return;
|
2014-06-28 00:26:03 +04:00
|
|
|
disp = sdl_screen->pitch/4;
|
|
|
|
xleft = statusitem_pos[element] + 2;
|
|
|
|
xsize = statusitem_pos[element+1] - xleft - 1;
|
|
|
|
buf = (Uint32 *)sdl_screen->pixels + (res_y + headerbar_height + 1) * disp + xleft;
|
|
|
|
rowsleft = statusbar_height - 2;
|
|
|
|
fgcolor = active?headerbar_fg:status_gray_text;
|
|
|
|
if (element > 0) {
|
|
|
|
bgcolor = active?(w?status_led_red:status_led_green):headerbar_bg;
|
|
|
|
} else {
|
|
|
|
bgcolor = headerbar_bg;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
colsleft = xsize;
|
|
|
|
buf_row = buf;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
*buf++ = bgcolor;
|
|
|
|
} while(--colsleft);
|
|
|
|
buf = buf_row + disp;
|
|
|
|
} while(--rowsleft);
|
2015-10-23 21:39:38 +03:00
|
|
|
if ((element > 0) && (strlen(text) > 6)) {
|
|
|
|
textlen = 6;
|
2014-06-28 00:26:03 +04:00
|
|
|
} else {
|
|
|
|
textlen = strlen(text);
|
|
|
|
}
|
|
|
|
buf = (Uint32 *)sdl_screen->pixels + (res_y + headerbar_height + 5) * disp + xleft;
|
|
|
|
x = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
pfont_row = &menufont[(unsigned)text[x]][0];
|
|
|
|
buf_row = buf;
|
|
|
|
rowsleft = 8;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
font_row = *pfont_row++;
|
|
|
|
colsleft = 8;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if((font_row & 0x80) != 0x00)
|
|
|
|
*buf++ = fgcolor;
|
|
|
|
else
|
|
|
|
buf++;
|
|
|
|
font_row <<= 1;
|
|
|
|
} while(--colsleft);
|
|
|
|
buf += (disp - 8);
|
|
|
|
} while(--rowsleft);
|
|
|
|
buf = buf_row + 8;
|
|
|
|
x++;
|
|
|
|
} while (--textlen);
|
|
|
|
SDL_UpdateRect(sdl_screen, xleft,res_y+headerbar_height+1,xsize,statusbar_height-2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Bit32u sdl_sym_to_bx_key(SDLKey sym)
|
|
|
|
{
|
|
|
|
switch (sym) {
|
|
|
|
case SDLK_BACKSPACE: return BX_KEY_BACKSPACE;
|
|
|
|
case SDLK_TAB: return BX_KEY_TAB;
|
|
|
|
case SDLK_RETURN: return BX_KEY_ENTER;
|
|
|
|
case SDLK_PAUSE: return BX_KEY_PAUSE;
|
|
|
|
case SDLK_ESCAPE: return BX_KEY_ESC;
|
|
|
|
case SDLK_SPACE: return BX_KEY_SPACE;
|
|
|
|
case SDLK_QUOTE: return BX_KEY_SINGLE_QUOTE;
|
|
|
|
case SDLK_COMMA: return BX_KEY_COMMA;
|
|
|
|
case SDLK_MINUS: return BX_KEY_MINUS;
|
|
|
|
case SDLK_PERIOD: return BX_KEY_PERIOD;
|
|
|
|
case SDLK_SLASH: return BX_KEY_SLASH;
|
|
|
|
case SDLK_0: return BX_KEY_0;
|
|
|
|
case SDLK_1: return BX_KEY_1;
|
|
|
|
case SDLK_2: return BX_KEY_2;
|
|
|
|
case SDLK_3: return BX_KEY_3;
|
|
|
|
case SDLK_4: return BX_KEY_4;
|
|
|
|
case SDLK_5: return BX_KEY_5;
|
|
|
|
case SDLK_6: return BX_KEY_6;
|
|
|
|
case SDLK_7: return BX_KEY_7;
|
|
|
|
case SDLK_8: return BX_KEY_8;
|
|
|
|
case SDLK_9: return BX_KEY_9;
|
|
|
|
case SDLK_SEMICOLON: return BX_KEY_SEMICOLON;
|
|
|
|
case SDLK_EQUALS: return BX_KEY_EQUALS;
|
|
|
|
/*
|
|
|
|
Skip uppercase letters
|
|
|
|
*/
|
|
|
|
case SDLK_LEFTBRACKET: return BX_KEY_LEFT_BRACKET;
|
|
|
|
case SDLK_BACKSLASH: return BX_KEY_BACKSLASH;
|
|
|
|
case SDLK_RIGHTBRACKET: return BX_KEY_RIGHT_BRACKET;
|
|
|
|
case SDLK_BACKQUOTE: return BX_KEY_GRAVE;
|
|
|
|
case SDLK_a: return BX_KEY_A;
|
|
|
|
case SDLK_b: return BX_KEY_B;
|
|
|
|
case SDLK_c: return BX_KEY_C;
|
|
|
|
case SDLK_d: return BX_KEY_D;
|
|
|
|
case SDLK_e: return BX_KEY_E;
|
|
|
|
case SDLK_f: return BX_KEY_F;
|
|
|
|
case SDLK_g: return BX_KEY_G;
|
|
|
|
case SDLK_h: return BX_KEY_H;
|
|
|
|
case SDLK_i: return BX_KEY_I;
|
|
|
|
case SDLK_j: return BX_KEY_J;
|
|
|
|
case SDLK_k: return BX_KEY_K;
|
|
|
|
case SDLK_l: return BX_KEY_L;
|
|
|
|
case SDLK_m: return BX_KEY_M;
|
|
|
|
case SDLK_n: return BX_KEY_N;
|
|
|
|
case SDLK_o: return BX_KEY_O;
|
|
|
|
case SDLK_p: return BX_KEY_P;
|
|
|
|
case SDLK_q: return BX_KEY_Q;
|
|
|
|
case SDLK_r: return BX_KEY_R;
|
|
|
|
case SDLK_s: return BX_KEY_S;
|
|
|
|
case SDLK_t: return BX_KEY_T;
|
|
|
|
case SDLK_u: return BX_KEY_U;
|
|
|
|
case SDLK_v: return BX_KEY_V;
|
|
|
|
case SDLK_w: return BX_KEY_W;
|
|
|
|
case SDLK_x: return BX_KEY_X;
|
|
|
|
case SDLK_y: return BX_KEY_Y;
|
|
|
|
case SDLK_z: return BX_KEY_Z;
|
|
|
|
case SDLK_DELETE: return BX_KEY_DELETE;
|
|
|
|
/* End of ASCII mapped keysyms */
|
|
|
|
|
|
|
|
/* Numeric keypad */
|
|
|
|
case SDLK_KP0: return BX_KEY_KP_INSERT;
|
|
|
|
case SDLK_KP1: return BX_KEY_KP_END;
|
|
|
|
case SDLK_KP2: return BX_KEY_KP_DOWN;
|
|
|
|
case SDLK_KP3: return BX_KEY_KP_PAGE_DOWN;
|
|
|
|
case SDLK_KP4: return BX_KEY_KP_LEFT;
|
|
|
|
case SDLK_KP5: return BX_KEY_KP_5;
|
|
|
|
case SDLK_KP6: return BX_KEY_KP_RIGHT;
|
|
|
|
case SDLK_KP7: return BX_KEY_KP_HOME;
|
|
|
|
case SDLK_KP8: return BX_KEY_KP_UP;
|
|
|
|
case SDLK_KP9: return BX_KEY_KP_PAGE_UP;
|
|
|
|
case SDLK_KP_PERIOD: return BX_KEY_KP_DELETE;
|
|
|
|
case SDLK_KP_DIVIDE: return BX_KEY_KP_DIVIDE;
|
|
|
|
case SDLK_KP_MULTIPLY: return BX_KEY_KP_MULTIPLY;
|
|
|
|
case SDLK_KP_MINUS: return BX_KEY_KP_SUBTRACT;
|
|
|
|
case SDLK_KP_PLUS: return BX_KEY_KP_ADD;
|
|
|
|
case SDLK_KP_ENTER: return BX_KEY_KP_ENTER;
|
|
|
|
|
|
|
|
/* Arrows + Home/End pad */
|
|
|
|
case SDLK_UP: return BX_KEY_UP;
|
|
|
|
case SDLK_DOWN: return BX_KEY_DOWN;
|
|
|
|
case SDLK_RIGHT: return BX_KEY_RIGHT;
|
|
|
|
case SDLK_LEFT: return BX_KEY_LEFT;
|
|
|
|
case SDLK_INSERT: return BX_KEY_INSERT;
|
|
|
|
case SDLK_HOME: return BX_KEY_HOME;
|
|
|
|
case SDLK_END: return BX_KEY_END;
|
|
|
|
case SDLK_PAGEUP: return BX_KEY_PAGE_UP;
|
|
|
|
case SDLK_PAGEDOWN: return BX_KEY_PAGE_DOWN;
|
|
|
|
|
|
|
|
/* Function keys */
|
|
|
|
case SDLK_F1: return BX_KEY_F1;
|
|
|
|
case SDLK_F2: return BX_KEY_F2;
|
|
|
|
case SDLK_F3: return BX_KEY_F3;
|
|
|
|
case SDLK_F4: return BX_KEY_F4;
|
|
|
|
case SDLK_F5: return BX_KEY_F5;
|
|
|
|
case SDLK_F6: return BX_KEY_F6;
|
|
|
|
case SDLK_F7: return BX_KEY_F7;
|
|
|
|
case SDLK_F8: return BX_KEY_F8;
|
|
|
|
case SDLK_F9: return BX_KEY_F9;
|
|
|
|
case SDLK_F10: return BX_KEY_F10;
|
|
|
|
case SDLK_F11: return BX_KEY_F11;
|
|
|
|
case SDLK_F12: return BX_KEY_F12;
|
|
|
|
|
|
|
|
/* Key state modifier keys */
|
|
|
|
case SDLK_NUMLOCK: return BX_KEY_NUM_LOCK;
|
|
|
|
case SDLK_CAPSLOCK: return BX_KEY_CAPS_LOCK;
|
|
|
|
case SDLK_SCROLLOCK: return BX_KEY_SCRL_LOCK;
|
|
|
|
case SDLK_RSHIFT: return BX_KEY_SHIFT_R;
|
|
|
|
case SDLK_LSHIFT: return BX_KEY_SHIFT_L;
|
|
|
|
case SDLK_RCTRL: return BX_KEY_CTRL_R;
|
|
|
|
case SDLK_LCTRL: return BX_KEY_CTRL_L;
|
|
|
|
case SDLK_RALT: return BX_KEY_ALT_R;
|
|
|
|
case SDLK_LALT: return BX_KEY_ALT_L;
|
|
|
|
case SDLK_RMETA: return BX_KEY_ALT_R;
|
|
|
|
case SDLK_LMETA: return BX_KEY_WIN_L;
|
|
|
|
case SDLK_LSUPER: return BX_KEY_WIN_L;
|
|
|
|
case SDLK_RSUPER: return BX_KEY_WIN_R;
|
|
|
|
|
|
|
|
/* Miscellaneous function keys */
|
|
|
|
case SDLK_PRINT: return BX_KEY_PRINT;
|
|
|
|
case SDLK_BREAK: return BX_KEY_PAUSE;
|
|
|
|
case SDLK_MENU: return BX_KEY_MENU;
|
|
|
|
|
|
|
|
default:
|
|
|
|
BX_ERROR(("sdl keysym %d not mapped", (int)sym));
|
|
|
|
return BX_KEY_UNHANDLED;
|
|
|
|
}
|
|
|
|
}
|
2002-02-05 08:51:38 +03:00
|
|
|
|
2002-02-06 05:12:45 +03:00
|
|
|
|
|
|
|
void switch_to_windowed(void)
|
|
|
|
{
|
|
|
|
SDL_Surface *tmp;
|
|
|
|
SDL_Rect src, dst;
|
|
|
|
src.x = 0; src.y = 0;
|
|
|
|
src.w = res_x; src.h = res_y;
|
|
|
|
dst.x = 0; dst.y = 0;
|
|
|
|
|
|
|
|
tmp = SDL_CreateRGBSurface(
|
|
|
|
SDL_SWSURFACE,
|
|
|
|
res_x,
|
|
|
|
res_y,
|
|
|
|
32,
|
|
|
|
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
|
|
|
0xff000000,
|
|
|
|
0x00ff0000,
|
|
|
|
0x0000ff00,
|
|
|
|
0x000000ff
|
|
|
|
#else
|
|
|
|
0x000000ff,
|
|
|
|
0x0000ff00,
|
|
|
|
0x00ff0000,
|
|
|
|
0xff000000
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
|
|
|
|
SDL_BlitSurface(sdl_fullscreen,&src,tmp,&dst);
|
|
|
|
SDL_UpdateRect(tmp,0,0,res_x,res_y);
|
|
|
|
SDL_FreeSurface(sdl_fullscreen);
|
|
|
|
sdl_fullscreen = NULL;
|
|
|
|
|
2004-02-14 00:45:28 +03:00
|
|
|
sdl_screen = SDL_SetVideoMode(res_x,res_y+headerbar_height+statusbar_height,32, SDL_SWSURFACE);
|
2002-02-06 05:12:45 +03:00
|
|
|
dst.y = headerbar_height;
|
|
|
|
SDL_BlitSurface(tmp,&src,sdl_screen,&dst);
|
2004-02-14 00:45:28 +03:00
|
|
|
SDL_UpdateRect(tmp,0,0,res_x,res_y+headerbar_height+statusbar_height);
|
2002-02-06 05:12:45 +03:00
|
|
|
SDL_FreeSurface(tmp);
|
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
bx_gui->show_headerbar();
|
2008-09-26 15:05:07 +04:00
|
|
|
SDL_ShowCursor(1);
|
|
|
|
if (sdl_grab==1) {
|
|
|
|
SDL_WM_GrabInput(SDL_GRAB_OFF);
|
|
|
|
|
|
|
|
sdl_grab = 0;
|
|
|
|
bx_gui->toggle_mouse_enable();
|
|
|
|
}
|
|
|
|
bx_gui->flush();
|
2002-02-06 05:12:45 +03:00
|
|
|
}
|
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
|
2002-02-06 05:12:45 +03:00
|
|
|
void switch_to_fullscreen(void)
|
|
|
|
{
|
|
|
|
SDL_Surface *tmp;
|
|
|
|
SDL_Rect src, dst;
|
|
|
|
src.x = 0; src.y = headerbar_height;
|
|
|
|
src.w = res_x; src.h = res_y;
|
|
|
|
dst.x = 0; dst.y = 0;
|
|
|
|
|
|
|
|
tmp = SDL_CreateRGBSurface(
|
|
|
|
SDL_SWSURFACE,
|
|
|
|
res_x,
|
|
|
|
res_y,
|
|
|
|
32,
|
|
|
|
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
|
|
|
0xff000000,
|
|
|
|
0x00ff0000,
|
|
|
|
0x0000ff00,
|
|
|
|
0x000000ff
|
|
|
|
#else
|
|
|
|
0x000000ff,
|
|
|
|
0x0000ff00,
|
|
|
|
0x00ff0000,
|
|
|
|
0xff000000
|
|
|
|
#endif
|
|
|
|
);
|
2008-02-16 01:05:43 +03:00
|
|
|
|
2002-02-06 05:12:45 +03:00
|
|
|
SDL_BlitSurface(sdl_screen,&src,tmp,&dst);
|
|
|
|
SDL_UpdateRect(tmp,0,0,res_x,res_y);
|
|
|
|
SDL_FreeSurface(sdl_screen);
|
|
|
|
sdl_screen = NULL;
|
|
|
|
|
2016-08-14 19:55:05 +03:00
|
|
|
#ifdef ANDROID
|
|
|
|
sdl_fullscreen = SDL_SetVideoMode(res_x,res_y,32, SDL_SWSURFACE|SDL_FULLSCREEN);
|
|
|
|
#else
|
2002-02-06 05:12:45 +03:00
|
|
|
sdl_fullscreen = SDL_SetVideoMode(res_x,res_y,32, SDL_HWSURFACE|SDL_FULLSCREEN);
|
2016-08-14 19:55:05 +03:00
|
|
|
#endif
|
2002-02-06 05:12:45 +03:00
|
|
|
src.y = 0;
|
|
|
|
SDL_BlitSurface(tmp,&src,sdl_fullscreen,&dst);
|
|
|
|
SDL_FreeSurface(tmp);
|
|
|
|
|
|
|
|
SDL_ShowCursor(0);
|
2016-08-16 19:15:12 +03:00
|
|
|
#ifndef ANDROID
|
2008-09-26 15:05:07 +04:00
|
|
|
if (sdl_grab==0) {
|
2016-08-16 19:15:12 +03:00
|
|
|
SDL_WM_GrabInput(SDL_GRAB_ON);
|
|
|
|
sdl_grab = 1;
|
|
|
|
bx_gui->toggle_mouse_enable();
|
2008-09-26 15:05:07 +04:00
|
|
|
}
|
2016-08-16 19:15:12 +03:00
|
|
|
#endif
|
2008-09-26 15:05:07 +04:00
|
|
|
bx_gui->flush();
|
2002-02-06 05:12:45 +03:00
|
|
|
}
|
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
|
2006-01-27 01:13:20 +03:00
|
|
|
#if BX_SHOW_IPS
|
|
|
|
#if defined(__MINGW32__) || defined(_MSC_VER)
|
|
|
|
Uint32 SDLCALL sdlTimer(Uint32 interval)
|
|
|
|
{
|
2012-08-26 16:32:10 +04:00
|
|
|
bx_show_ips_handler();
|
2006-01-27 01:13:20 +03:00
|
|
|
return interval;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
|
2005-06-23 22:40:35 +04:00
|
|
|
#ifdef __MORPHOS__
|
|
|
|
void bx_sdl_morphos_exit(void)
|
|
|
|
{
|
2008-09-26 15:05:07 +04:00
|
|
|
SDL_Quit();
|
|
|
|
if (PowerSDLBase) CloseLibrary(PowerSDLBase);
|
2005-06-23 22:40:35 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
|
2012-07-01 18:37:13 +04:00
|
|
|
#if defined(WIN32) && BX_DEBUGGER && BX_DEBUGGER_GUI
|
|
|
|
DWORD WINAPI DebugGuiThread(LPVOID)
|
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
|
|
|
|
bx_gui->init_debug_dialog();
|
|
|
|
while (GetMessage(&msg, NULL, 0, 0)) {
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
|
2014-07-10 14:31:51 +04:00
|
|
|
bx_sdl_gui_c::bx_sdl_gui_c()
|
2002-02-05 08:51:38 +03:00
|
|
|
{
|
2006-01-27 01:13:20 +03:00
|
|
|
Uint32 flags;
|
2014-07-10 14:31:51 +04:00
|
|
|
SDL_Rect **modes;
|
2002-02-05 08:51:38 +03:00
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
put("SDL");
|
2002-03-19 00:21:19 +03:00
|
|
|
|
2014-07-10 14:31:51 +04:00
|
|
|
#ifdef __MORPHOS__
|
2005-06-23 22:40:35 +04:00
|
|
|
if (!(PowerSDLBase=OpenLibrary("powersdl.library",0)))
|
|
|
|
{
|
2017-01-25 00:52:19 +03:00
|
|
|
BX_FATAL(("Unable to open SDL libraries"));
|
2005-06-23 22:40:35 +04:00
|
|
|
return;
|
|
|
|
}
|
2014-07-10 14:31:51 +04:00
|
|
|
#endif
|
2008-02-06 01:57:43 +03:00
|
|
|
|
2006-01-27 01:13:20 +03:00
|
|
|
flags = SDL_INIT_VIDEO;
|
|
|
|
#if BX_SHOW_IPS
|
|
|
|
#if defined(__MINGW32__) || defined(_MSC_VER)
|
|
|
|
flags |= SDL_INIT_TIMER;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
if (SDL_Init(flags) < 0) {
|
2017-01-25 00:52:19 +03:00
|
|
|
BX_FATAL(("Unable to initialize SDL libraries"));
|
2002-02-05 08:51:38 +03:00
|
|
|
return;
|
|
|
|
}
|
2014-07-10 14:31:51 +04:00
|
|
|
#ifdef __MORPHOS__
|
2005-06-23 22:40:35 +04:00
|
|
|
atexit(bx_sdl_morphos_exit);
|
2014-07-10 14:31:51 +04:00
|
|
|
#else
|
2002-02-05 08:51:38 +03:00
|
|
|
atexit(SDL_Quit);
|
2014-07-10 14:31:51 +04:00
|
|
|
#endif
|
|
|
|
|
2016-08-14 19:55:05 +03:00
|
|
|
#ifdef ANDROID
|
|
|
|
modes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_SWSURFACE);
|
|
|
|
#else
|
2014-07-10 14:31:51 +04:00
|
|
|
modes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE);
|
2016-08-14 19:55:05 +03:00
|
|
|
#endif
|
2014-07-10 14:31:51 +04:00
|
|
|
if (modes == NULL) {
|
|
|
|
panic("No video modes available");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sdl_maxres.w = modes[0]->w;
|
|
|
|
sdl_maxres.h = modes[0]->h;
|
|
|
|
info("maximum host resolution: x=%d y=%d\n", sdl_maxres.w, sdl_maxres.h);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-15 14:44:43 +03:00
|
|
|
// SDL implementation of the bx_gui_c methods (see nogui.cc for details)
|
|
|
|
|
2014-07-10 14:31:51 +04:00
|
|
|
void bx_sdl_gui_c::specific_init(int argc, char **argv, unsigned headerbar_y)
|
|
|
|
{
|
|
|
|
int i, j;
|
2017-01-03 23:59:59 +03:00
|
|
|
bx_bool gui_ci = 0;
|
2014-07-10 14:31:51 +04:00
|
|
|
|
2017-01-03 23:59:59 +03:00
|
|
|
#ifdef WIN32
|
2014-07-10 14:31:51 +04:00
|
|
|
gui_ci = !strcmp(SIM->get_param_enum(BXPN_SEL_CONFIG_INTERFACE)->get_selected(), "win32config");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
UNUSED(bochs_icon_bits);
|
|
|
|
|
|
|
|
headerbar_height = headerbar_y;
|
|
|
|
|
|
|
|
for(i=0;i<256;i++)
|
|
|
|
for(j=0;j<16;j++)
|
|
|
|
vga_charmap[i*32+j] = sdl_font8x16[i][j];
|
|
|
|
|
|
|
|
for(i=0;i<256;i++)
|
|
|
|
for(j=0;j<8;j++)
|
|
|
|
menufont[i][j] = sdl_font8x8[i][j];
|
2002-02-05 08:51:38 +03:00
|
|
|
|
|
|
|
sdl_screen = NULL;
|
2002-02-06 05:12:45 +03:00
|
|
|
sdl_fullscreen_toggle = 0;
|
2014-07-05 12:00:01 +04:00
|
|
|
dimension_update(640, 480);
|
2002-03-15 04:11:10 +03:00
|
|
|
|
2011-12-04 13:04:16 +04:00
|
|
|
SDL_EnableKeyRepeat(250, 50);
|
2017-01-07 13:11:57 +03:00
|
|
|
SDL_EnableUNICODE(SDL_TRUE);
|
2008-02-16 01:05:43 +03:00
|
|
|
SDL_WM_SetCaption(BOCHS_WINDOW_NAME, "Bochs");
|
2002-10-06 21:17:14 +04:00
|
|
|
SDL_WarpMouse(half_res_x, half_res_y);
|
2002-10-08 10:14:53 +04:00
|
|
|
|
|
|
|
// load keymap for sdl
|
2006-02-22 22:18:29 +03:00
|
|
|
if (SIM->get_param_bool(BXPN_KBD_USEMAPPING)->get()) {
|
2002-10-08 10:14:53 +04:00
|
|
|
bx_keymap.loadKeymap(convertStringToSDLKey);
|
|
|
|
}
|
2004-02-24 22:21:48 +03:00
|
|
|
|
|
|
|
// parse sdl specific options
|
|
|
|
if (argc > 1) {
|
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
if (!strcmp(argv[i], "fullscreen")) {
|
|
|
|
sdl_fullscreen_toggle = 1;
|
|
|
|
switch_to_fullscreen();
|
2011-12-04 13:04:16 +04:00
|
|
|
} else if (!strcmp(argv[i], "nokeyrepeat")) {
|
|
|
|
BX_INFO(("disabled host keyboard repeat"));
|
|
|
|
SDL_EnableKeyRepeat(0, 0);
|
2012-07-01 18:37:13 +04:00
|
|
|
#if BX_DEBUGGER && BX_DEBUGGER_GUI
|
2009-01-31 21:11:13 +03:00
|
|
|
} else if (!strcmp(argv[i], "gui_debug")) {
|
|
|
|
SIM->set_debug_gui(1);
|
2012-07-01 18:37:13 +04:00
|
|
|
#ifdef WIN32
|
|
|
|
if (gui_ci) {
|
|
|
|
// on Windows the debugger gui must run in a separate thread
|
|
|
|
DWORD threadID;
|
|
|
|
CreateThread(NULL, 0, DebugGuiThread, NULL, 0, &threadID);
|
|
|
|
} else {
|
|
|
|
BX_PANIC(("Config interface 'win32config' is required for gui debugger"));
|
|
|
|
}
|
|
|
|
#else
|
2012-06-24 13:14:43 +04:00
|
|
|
init_debug_dialog();
|
2017-01-03 23:59:59 +03:00
|
|
|
#endif
|
2012-05-11 20:17:59 +04:00
|
|
|
#endif
|
|
|
|
#if BX_SHOW_IPS
|
|
|
|
} else if (!strcmp(argv[i], "hideIPS")) {
|
|
|
|
BX_INFO(("hide IPS display in status bar"));
|
|
|
|
sdl_hide_ips = 1;
|
2009-01-31 21:11:13 +03:00
|
|
|
#endif
|
2004-02-24 22:21:48 +03:00
|
|
|
} else {
|
|
|
|
BX_PANIC(("Unknown sdl option '%s'", argv[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-08-15 23:27:15 +04:00
|
|
|
|
|
|
|
new_gfx_api = 1;
|
2017-01-03 23:59:59 +03:00
|
|
|
#if defined(WIN32) && BX_SHOW_IPS
|
|
|
|
SDL_SetTimer(1000, sdlTimer);
|
|
|
|
#endif
|
2009-03-24 19:28:03 +03:00
|
|
|
if (gui_ci) {
|
|
|
|
dialog_caps = BX_GUI_DLG_ALL;
|
2017-01-03 23:59:59 +03:00
|
|
|
} else {
|
2017-01-07 13:11:57 +03:00
|
|
|
console.present = 1;
|
2009-03-24 19:28:03 +03:00
|
|
|
}
|
2002-02-05 08:51:38 +03:00
|
|
|
}
|
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
|
|
|
|
void bx_sdl_gui_c::text_update(Bit8u *old_text, Bit8u *new_text,
|
|
|
|
unsigned long cursor_x,
|
|
|
|
unsigned long cursor_y,
|
|
|
|
bx_vga_tminfo_t *tm_info)
|
2004-02-14 00:45:28 +03:00
|
|
|
{
|
2014-06-28 00:26:03 +04:00
|
|
|
Bit8u *pfont_row, *old_line, *new_line, *text_base;
|
|
|
|
unsigned int cs_y, i, x, y;
|
|
|
|
unsigned int curs, hchars, offset;
|
|
|
|
Bit8u fontline, fontpixels, fontrows;
|
|
|
|
int rows;
|
|
|
|
Uint32 fgcolor, bgcolor;
|
|
|
|
Uint32 *buf, *buf_row, *buf_char;
|
|
|
|
Uint32 disp;
|
|
|
|
Bit16u font_row, mask;
|
|
|
|
Bit8u cfstart, cfwidth, cfheight, split_fontrows, split_textrow;
|
|
|
|
bx_bool cursor_visible, gfxcharw9, invert, forceUpdate, split_screen;
|
2015-10-25 01:03:51 +03:00
|
|
|
bx_bool blink_mode, blink_state, dwidth;
|
2014-06-28 00:26:03 +04:00
|
|
|
Uint32 text_palette[16];
|
2002-02-16 23:31:35 +03:00
|
|
|
|
2002-10-04 14:52:44 +04:00
|
|
|
forceUpdate = 0;
|
2012-01-22 16:22:03 +04:00
|
|
|
blink_mode = (tm_info->blink_flags & BX_TEXT_BLINK_MODE) > 0;
|
|
|
|
blink_state = (tm_info->blink_flags & BX_TEXT_BLINK_STATE) > 0;
|
2008-01-29 00:52:09 +03:00
|
|
|
if (blink_mode) {
|
2012-01-22 16:22:03 +04:00
|
|
|
if (tm_info->blink_flags & BX_TEXT_BLINK_TOGGLE)
|
2008-01-29 00:52:09 +03:00
|
|
|
forceUpdate = 1;
|
|
|
|
}
|
2015-10-25 01:03:51 +03:00
|
|
|
dwidth = (fontwidth > 9);
|
2008-01-29 00:52:09 +03:00
|
|
|
if (charmap_updated) {
|
2002-10-04 14:52:44 +04:00
|
|
|
forceUpdate = 1;
|
2002-10-25 01:07:56 +04:00
|
|
|
charmap_updated = 0;
|
2002-10-04 14:52:44 +04:00
|
|
|
}
|
2008-01-29 00:52:09 +03:00
|
|
|
for (i=0; i<16; i++) {
|
2012-10-14 22:29:44 +04:00
|
|
|
text_palette[i] = sdl_palette[tm_info->actl_palette[i]];
|
2006-10-13 21:55:53 +04:00
|
|
|
}
|
2012-01-22 16:22:03 +04:00
|
|
|
if ((tm_info->h_panning != h_panning) || (tm_info->v_panning != v_panning)) {
|
2003-05-10 21:03:36 +04:00
|
|
|
forceUpdate = 1;
|
2012-01-22 16:22:03 +04:00
|
|
|
h_panning = tm_info->h_panning;
|
|
|
|
v_panning = tm_info->v_panning;
|
2003-05-10 21:03:36 +04:00
|
|
|
}
|
2012-01-22 16:22:03 +04:00
|
|
|
if (tm_info->line_compare != line_compare) {
|
2004-04-09 19:04:54 +04:00
|
|
|
forceUpdate = 1;
|
2012-01-22 16:22:03 +04:00
|
|
|
line_compare = tm_info->line_compare;
|
2004-04-09 19:04:54 +04:00
|
|
|
}
|
2008-01-29 00:52:09 +03:00
|
|
|
if (sdl_screen) {
|
2002-02-06 05:12:45 +03:00
|
|
|
disp = sdl_screen->pitch/4;
|
2014-07-05 12:00:01 +04:00
|
|
|
buf_row = (Uint32 *)sdl_screen->pixels + headerbar_height * disp;
|
2008-01-29 00:52:09 +03:00
|
|
|
} else {
|
2002-02-06 05:12:45 +03:00
|
|
|
disp = sdl_fullscreen->pitch/4;
|
2012-02-28 22:38:32 +04:00
|
|
|
buf_row = (Uint32 *)sdl_fullscreen->pixels + sdl_fullscreen->offset/4;
|
2002-02-06 05:12:45 +03:00
|
|
|
}
|
2003-06-15 19:10:45 +04:00
|
|
|
// first invalidate character at previous and new cursor location
|
2008-02-16 01:05:43 +03:00
|
|
|
if ((prev_cursor_y < text_rows) && (prev_cursor_x < text_cols)) {
|
2012-01-22 16:22:03 +04:00
|
|
|
curs = prev_cursor_y * tm_info->line_offset + prev_cursor_x * 2;
|
2003-06-11 00:22:37 +04:00
|
|
|
old_text[curs] = ~new_text[curs];
|
|
|
|
}
|
2012-01-22 16:22:03 +04:00
|
|
|
cursor_visible = ((tm_info->cs_start <= tm_info->cs_end) && (tm_info->cs_start < fontheight));
|
2003-06-15 19:10:45 +04:00
|
|
|
if((cursor_visible) && (cursor_y < text_rows) && (cursor_x < text_cols)) {
|
2012-01-22 16:22:03 +04:00
|
|
|
curs = cursor_y * tm_info->line_offset + cursor_x * 2;
|
2003-06-15 19:10:45 +04:00
|
|
|
old_text[curs] = ~new_text[curs];
|
|
|
|
} else {
|
|
|
|
curs = 0xffff;
|
|
|
|
}
|
2003-06-11 00:22:37 +04:00
|
|
|
|
2003-05-18 19:38:58 +04:00
|
|
|
rows = text_rows;
|
2003-05-10 21:03:36 +04:00
|
|
|
if (v_panning) rows++;
|
|
|
|
y = 0;
|
2004-04-10 20:35:47 +04:00
|
|
|
cs_y = 0;
|
2012-01-22 16:22:03 +04:00
|
|
|
text_base = new_text - tm_info->start_address;
|
2008-12-29 11:51:34 +03:00
|
|
|
if (line_compare < res_y) {
|
|
|
|
split_textrow = (line_compare + v_panning) / fontheight;
|
|
|
|
split_fontrows = ((line_compare + v_panning) % fontheight) + 1;
|
|
|
|
} else {
|
|
|
|
split_textrow = rows + 1;
|
|
|
|
split_fontrows = 0;
|
|
|
|
}
|
2004-04-09 19:04:54 +04:00
|
|
|
split_screen = 0;
|
2003-06-15 11:33:06 +04:00
|
|
|
|
2008-12-29 11:51:34 +03:00
|
|
|
do {
|
2002-02-05 08:51:38 +03:00
|
|
|
buf = buf_row;
|
2003-05-18 19:38:58 +04:00
|
|
|
hchars = text_cols;
|
2003-05-10 21:03:36 +04:00
|
|
|
if (h_panning) hchars++;
|
|
|
|
cfheight = fontheight;
|
2004-04-10 20:35:47 +04:00
|
|
|
cfstart = 0;
|
2014-06-28 00:26:03 +04:00
|
|
|
if (split_screen) {
|
|
|
|
if (rows == 1) {
|
2004-04-10 20:35:47 +04:00
|
|
|
cfheight = (res_y - line_compare - 1) % fontheight;
|
|
|
|
if (cfheight == 0) cfheight = fontheight;
|
|
|
|
}
|
2014-06-28 00:26:03 +04:00
|
|
|
} else if (v_panning) {
|
|
|
|
if (y == 0) {
|
2003-05-10 21:03:36 +04:00
|
|
|
cfheight -= v_panning;
|
2004-04-10 20:35:47 +04:00
|
|
|
cfstart = v_panning;
|
2014-06-28 00:26:03 +04:00
|
|
|
} else if (rows == 1) {
|
2004-04-10 20:35:47 +04:00
|
|
|
cfheight = v_panning;
|
2003-05-10 21:03:36 +04:00
|
|
|
}
|
|
|
|
}
|
2014-06-28 00:26:03 +04:00
|
|
|
if (!split_screen && (y == split_textrow)) {
|
|
|
|
if ((split_fontrows - cfstart) < cfheight) {
|
2004-04-10 20:35:47 +04:00
|
|
|
cfheight = split_fontrows - cfstart;
|
|
|
|
}
|
2004-04-09 19:04:54 +04:00
|
|
|
}
|
2003-05-10 21:03:36 +04:00
|
|
|
new_line = new_text;
|
|
|
|
old_line = old_text;
|
2002-02-16 23:31:35 +03:00
|
|
|
x = 0;
|
2012-01-22 16:22:03 +04:00
|
|
|
offset = cs_y * tm_info->line_offset;
|
2014-06-28 00:26:03 +04:00
|
|
|
do {
|
2003-05-10 21:03:36 +04:00
|
|
|
cfwidth = fontwidth;
|
2014-06-28 00:26:03 +04:00
|
|
|
if (h_panning) {
|
|
|
|
if (hchars > text_cols) {
|
2003-05-10 21:03:36 +04:00
|
|
|
cfwidth -= h_panning;
|
2014-06-28 00:26:03 +04:00
|
|
|
} else if (hchars == 1) {
|
2003-05-10 21:03:36 +04:00
|
|
|
cfwidth = h_panning;
|
|
|
|
}
|
|
|
|
}
|
2002-02-05 08:51:38 +03:00
|
|
|
// check if char needs to be updated
|
2002-10-04 14:52:44 +04:00
|
|
|
if(forceUpdate || (old_text[0] != new_text[0])
|
2012-10-14 22:29:44 +04:00
|
|
|
|| (old_text[1] != new_text[1])) {
|
|
|
|
// Get Foreground/Background pixel colors
|
|
|
|
fgcolor = text_palette[new_text[1] & 0x0F];
|
2008-01-29 00:52:09 +03:00
|
|
|
if (blink_mode) {
|
|
|
|
bgcolor = text_palette[(new_text[1] >> 4) & 0x07];
|
|
|
|
if (!blink_state && (new_text[1] & 0x80))
|
|
|
|
fgcolor = bgcolor;
|
|
|
|
} else {
|
|
|
|
bgcolor = text_palette[(new_text[1] >> 4) & 0x0F];
|
|
|
|
}
|
2014-06-28 00:26:03 +04:00
|
|
|
invert = ((offset == curs) && (cursor_visible));
|
|
|
|
gfxcharw9 = ((tm_info->line_graphics) && ((new_text[0] & 0xE0) == 0xC0));
|
|
|
|
|
|
|
|
// Display this one char
|
|
|
|
fontrows = cfheight;
|
|
|
|
fontline = cfstart;
|
|
|
|
if (y > 0) {
|
|
|
|
pfont_row = &vga_charmap[(new_text[0] << 5)];
|
|
|
|
} else {
|
|
|
|
pfont_row = &vga_charmap[(new_text[0] << 5) + cfstart];
|
|
|
|
}
|
|
|
|
buf_char = buf;
|
|
|
|
do {
|
|
|
|
font_row = *pfont_row++;
|
|
|
|
if (gfxcharw9) {
|
|
|
|
font_row = (font_row << 1) | (font_row & 0x01);
|
|
|
|
} else {
|
|
|
|
font_row <<= 1;
|
|
|
|
}
|
|
|
|
if (hchars > text_cols) {
|
|
|
|
font_row <<= h_panning;
|
|
|
|
}
|
|
|
|
fontpixels = cfwidth;
|
|
|
|
if ((invert) && (fontline >= tm_info->cs_start) && (fontline <= tm_info->cs_end))
|
|
|
|
mask = 0x100;
|
|
|
|
else
|
|
|
|
mask = 0x00;
|
|
|
|
do {
|
|
|
|
if ((font_row & 0x100) == mask)
|
|
|
|
*buf = bgcolor;
|
|
|
|
else
|
|
|
|
*buf = fgcolor;
|
|
|
|
buf++;
|
2015-10-25 01:03:51 +03:00
|
|
|
if (!dwidth || (fontpixels & 1)) font_row <<= 1;
|
2014-06-28 00:26:03 +04:00
|
|
|
} while (--fontpixels);
|
|
|
|
buf -= cfwidth;
|
|
|
|
buf += disp;
|
|
|
|
fontline++;
|
|
|
|
} while (--fontrows);
|
|
|
|
|
|
|
|
// restore output buffer ptr to start of this char
|
|
|
|
buf = buf_char;
|
2002-02-05 08:51:38 +03:00
|
|
|
}
|
|
|
|
// move to next char location on screen
|
2003-05-10 21:03:36 +04:00
|
|
|
buf += cfwidth;
|
2003-06-15 11:33:06 +04:00
|
|
|
|
2002-02-05 08:51:38 +03:00
|
|
|
// select next char in old/new text
|
|
|
|
new_text+=2;
|
|
|
|
old_text+=2;
|
2003-06-15 11:33:06 +04:00
|
|
|
offset+=2;
|
2002-02-16 23:31:35 +03:00
|
|
|
x++;
|
2003-06-15 11:33:06 +04:00
|
|
|
|
2002-02-05 08:51:38 +03:00
|
|
|
// process one entire horizontal row
|
2014-06-28 00:26:03 +04:00
|
|
|
} while (--hchars);
|
2002-02-05 08:51:38 +03:00
|
|
|
|
|
|
|
// go to next character row location
|
2003-05-10 21:03:36 +04:00
|
|
|
buf_row += disp * cfheight;
|
2014-06-28 00:26:03 +04:00
|
|
|
if (!split_screen && (y == split_textrow)) {
|
2004-04-09 19:04:54 +04:00
|
|
|
new_text = text_base;
|
|
|
|
forceUpdate = 1;
|
2004-04-10 20:35:47 +04:00
|
|
|
cs_y = 0;
|
2012-01-22 16:22:03 +04:00
|
|
|
if (tm_info->split_hpanning) h_panning = 0;
|
2004-04-10 20:35:47 +04:00
|
|
|
rows = ((res_y - line_compare + fontheight - 2) / fontheight) + 1;
|
2004-04-09 21:54:20 +04:00
|
|
|
split_screen = 1;
|
2014-06-28 00:26:03 +04:00
|
|
|
} else {
|
2012-01-22 16:22:03 +04:00
|
|
|
new_text = new_line + tm_info->line_offset;
|
|
|
|
old_text = old_line + tm_info->line_offset;
|
2004-04-10 20:35:47 +04:00
|
|
|
cs_y++;
|
2004-04-09 19:04:54 +04:00
|
|
|
y++;
|
|
|
|
}
|
2014-06-28 00:26:03 +04:00
|
|
|
} while (--rows);
|
2012-01-22 16:22:03 +04:00
|
|
|
h_panning = tm_info->h_panning;
|
2002-02-16 23:31:35 +03:00
|
|
|
prev_cursor_x = cursor_x;
|
|
|
|
prev_cursor_y = cursor_y;
|
2002-02-05 08:51:38 +03:00
|
|
|
}
|
|
|
|
|
2002-03-15 19:45:10 +03:00
|
|
|
|
2008-09-26 15:05:07 +04:00
|
|
|
void bx_sdl_gui_c::graphics_tile_update(Bit8u *snapshot, unsigned x, unsigned y)
|
2002-02-05 08:51:38 +03:00
|
|
|
{
|
2002-02-06 05:12:45 +03:00
|
|
|
Uint32 *buf, disp;
|
|
|
|
Uint32 *buf_row;
|
2014-07-05 12:00:01 +04:00
|
|
|
int i, j;
|
2008-02-06 01:57:43 +03:00
|
|
|
|
2014-07-05 12:00:01 +04:00
|
|
|
if (sdl_screen) {
|
2002-02-06 05:12:45 +03:00
|
|
|
disp = sdl_screen->pitch/4;
|
2014-07-05 12:00:01 +04:00
|
|
|
buf = (Uint32 *)sdl_screen->pixels + (headerbar_height + y) * disp + x;
|
|
|
|
} else {
|
2014-06-28 00:26:03 +04:00
|
|
|
disp = sdl_fullscreen->pitch/4;
|
2014-07-05 12:00:01 +04:00
|
|
|
buf = (Uint32 *)sdl_fullscreen->pixels + y * disp + x + sdl_fullscreen->offset/4;
|
2014-06-28 00:26:03 +04:00
|
|
|
}
|
2002-09-24 12:50:51 +04:00
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
i = y_tilesize;
|
|
|
|
if(i + y > res_y) i = res_y - y;
|
|
|
|
|
|
|
|
// FIXME
|
|
|
|
if (i<=0) return;
|
|
|
|
|
|
|
|
switch (disp_bpp) {
|
|
|
|
case 8: /* 8 bpp */
|
|
|
|
do {
|
|
|
|
buf_row = buf;
|
|
|
|
j = x_tilesize;
|
|
|
|
do {
|
|
|
|
*buf++ = sdl_palette[*snapshot++];
|
|
|
|
} while(--j);
|
|
|
|
buf = buf_row + disp;
|
|
|
|
} while(--i);
|
|
|
|
break;
|
2002-09-24 12:50:51 +04:00
|
|
|
default:
|
2014-06-28 00:26:03 +04:00
|
|
|
BX_PANIC(("%u bpp modes handled by new graphics API", disp_bpp));
|
|
|
|
return;
|
2002-09-24 12:50:51 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
void bx_sdl_gui_c::handle_events(void)
|
2002-02-05 08:51:38 +03:00
|
|
|
{
|
2014-06-28 00:26:03 +04:00
|
|
|
SDL_Event sdl_event;
|
2002-02-05 08:51:38 +03:00
|
|
|
Bit32u key_event;
|
2002-03-19 22:59:44 +03:00
|
|
|
Bit8u mouse_state;
|
2012-06-24 14:38:46 +04:00
|
|
|
int dx, dy, wheel_status;
|
2010-05-16 13:01:36 +04:00
|
|
|
bx_bool mouse_toggle = 0;
|
2002-02-05 08:51:38 +03:00
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
while (SDL_PollEvent(&sdl_event)) {
|
2004-12-10 18:57:46 +03:00
|
|
|
wheel_status = 0;
|
2014-06-28 00:26:03 +04:00
|
|
|
switch (sdl_event.type) {
|
2002-02-05 08:51:38 +03:00
|
|
|
case SDL_VIDEOEXPOSE:
|
2012-06-24 14:38:46 +04:00
|
|
|
if (sdl_fullscreen_toggle == 0)
|
|
|
|
SDL_UpdateRect(sdl_screen, 0,0, res_x, res_y+headerbar_height+statusbar_height);
|
|
|
|
else
|
|
|
|
SDL_UpdateRect(sdl_fullscreen, 0, headerbar_height, res_x, res_y);
|
|
|
|
break;
|
2002-02-06 00:39:15 +03:00
|
|
|
|
|
|
|
case SDL_MOUSEMOTION:
|
2017-01-05 21:20:47 +03:00
|
|
|
if (!sdl_grab || console_running()) {
|
2012-06-24 14:38:46 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (just_warped
|
|
|
|
&& sdl_event.motion.x == half_res_x
|
|
|
|
&& sdl_event.motion.y == half_res_y) {
|
|
|
|
// This event was generated as a side effect of the WarpMouse,
|
|
|
|
// and it must be ignored.
|
|
|
|
just_warped = 0;
|
|
|
|
break;
|
|
|
|
}
|
2004-02-15 20:12:55 +03:00
|
|
|
new_mousebuttons = ((sdl_event.motion.state & 0x01)|((sdl_event.motion.state>>1)&0x02)
|
|
|
|
|((sdl_event.motion.state<<1)&0x04));
|
2012-06-24 14:38:46 +04:00
|
|
|
if (sdl_mouse_mode_absxy) {
|
2014-07-05 12:00:01 +04:00
|
|
|
dx = sdl_event.motion.x * 0x7fff / res_x;
|
|
|
|
if (sdl_fullscreen_toggle) {
|
|
|
|
dy = sdl_event.motion.y * 0x7fff / res_y;
|
|
|
|
DEV_mouse_motion(dx, dy, 0, new_mousebuttons, 1);
|
|
|
|
} else if ((sdl_event.motion.y >= headerbar_height) && (sdl_event.motion.y < (res_y + headerbar_height))) {
|
2012-06-25 21:26:36 +04:00
|
|
|
dy = (sdl_event.motion.y - headerbar_height) * 0x7fff / res_y;
|
2014-07-05 12:00:01 +04:00
|
|
|
DEV_mouse_motion(dx, dy, 0, new_mousebuttons, 1);
|
2012-06-24 14:38:46 +04:00
|
|
|
}
|
|
|
|
} else {
|
2014-07-05 12:00:01 +04:00
|
|
|
DEV_mouse_motion(sdl_event.motion.xrel, -sdl_event.motion.yrel, 0,
|
|
|
|
new_mousebuttons, 0);
|
2012-06-24 14:38:46 +04:00
|
|
|
}
|
|
|
|
old_mousebuttons = new_mousebuttons;
|
|
|
|
old_mousex = (int)(sdl_event.motion.x);
|
|
|
|
old_mousey = (int)(sdl_event.motion.y);
|
|
|
|
if (!sdl_mouse_mode_absxy) {
|
|
|
|
SDL_WarpMouse(half_res_x, half_res_y);
|
|
|
|
just_warped = 1;
|
|
|
|
}
|
|
|
|
break;
|
2002-02-06 00:39:15 +03:00
|
|
|
|
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
2010-05-16 13:01:36 +04:00
|
|
|
// mouse capture toggle-check
|
|
|
|
if ((sdl_event.button.button == SDL_BUTTON_MIDDLE)
|
|
|
|
&& (sdl_fullscreen_toggle == 0)) {
|
|
|
|
if (mouse_toggle_check(BX_MT_MBUTTON, 1)) {
|
|
|
|
if (sdl_grab == 0) {
|
|
|
|
SDL_ShowCursor(0);
|
|
|
|
SDL_WM_GrabInput(SDL_GRAB_ON);
|
|
|
|
} else {
|
|
|
|
SDL_ShowCursor(1);
|
|
|
|
SDL_WM_GrabInput(SDL_GRAB_OFF);
|
|
|
|
}
|
|
|
|
sdl_grab = ~sdl_grab;
|
|
|
|
toggle_mouse_enable();
|
|
|
|
}
|
|
|
|
break;
|
2014-07-05 12:00:01 +04:00
|
|
|
} else if (!sdl_fullscreen_toggle && (sdl_event.button.y < headerbar_height)) {
|
2010-05-16 13:01:36 +04:00
|
|
|
headerbar_click(sdl_event.button.x);
|
|
|
|
break;
|
|
|
|
}
|
2005-07-30 22:57:02 +04:00
|
|
|
#ifdef SDL_BUTTON_WHEELUP
|
2004-12-10 18:57:46 +03:00
|
|
|
// get the wheel status
|
|
|
|
if (sdl_event.button.button == SDL_BUTTON_WHEELUP) {
|
|
|
|
wheel_status = 1;
|
|
|
|
}
|
|
|
|
if (sdl_event.button.button == SDL_BUTTON_WHEELDOWN) {
|
|
|
|
wheel_status = -1;
|
|
|
|
}
|
2005-07-30 22:57:02 +04:00
|
|
|
#endif
|
2002-02-06 00:39:15 +03:00
|
|
|
case SDL_MOUSEBUTTONUP:
|
2010-05-16 13:01:36 +04:00
|
|
|
if ((sdl_event.button.button == SDL_BUTTON_MIDDLE)
|
|
|
|
&& (sdl_fullscreen_toggle == 0)) {
|
|
|
|
mouse_toggle_check(BX_MT_MBUTTON, 0);
|
|
|
|
}
|
2017-01-05 21:20:47 +03:00
|
|
|
if (console_running()) {
|
|
|
|
break;
|
|
|
|
}
|
2010-05-16 13:01:36 +04:00
|
|
|
// figure out mouse state
|
|
|
|
new_mousex = (int)(sdl_event.button.x);
|
|
|
|
new_mousey = (int)(sdl_event.button.y);
|
|
|
|
// SDL_GetMouseState() returns the state of all buttons
|
|
|
|
mouse_state = SDL_GetMouseState(NULL, NULL);
|
|
|
|
new_mousebuttons =
|
|
|
|
(mouse_state & 0x01) |
|
|
|
|
((mouse_state>>1)&0x02) |
|
|
|
|
((mouse_state<<1)&0x04);
|
2004-12-10 18:57:46 +03:00
|
|
|
// send motion information
|
2012-06-24 14:38:46 +04:00
|
|
|
if (sdl_mouse_mode_absxy) {
|
2014-07-05 12:00:01 +04:00
|
|
|
dx = new_mousex * 0x7fff / res_x;
|
|
|
|
if (sdl_fullscreen_toggle) {
|
|
|
|
dy = new_mousey * 0x7fff / res_y;
|
|
|
|
DEV_mouse_motion(dx, dy, wheel_status, new_mousebuttons, 1);
|
|
|
|
} else if ((new_mousey >= headerbar_height) && (new_mousey < (int)(res_y + headerbar_height))) {
|
2012-06-25 21:26:36 +04:00
|
|
|
dy = (new_mousey - headerbar_height) * 0x7fff / res_y;
|
2012-06-24 14:38:46 +04:00
|
|
|
DEV_mouse_motion(dx, dy, wheel_status, new_mousebuttons, 1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
DEV_mouse_motion(new_mousex - old_mousex, -(new_mousey - old_mousey),
|
|
|
|
wheel_status, new_mousebuttons, 0);
|
|
|
|
}
|
2010-05-16 13:01:36 +04:00
|
|
|
// mark current state to diff with next packet
|
|
|
|
old_mousebuttons = new_mousebuttons;
|
|
|
|
old_mousex = new_mousex;
|
|
|
|
old_mousey = new_mousey;
|
|
|
|
break;
|
2002-02-06 00:39:15 +03:00
|
|
|
|
2002-02-05 08:51:38 +03:00
|
|
|
case SDL_KEYDOWN:
|
2017-01-05 21:20:47 +03:00
|
|
|
if (console_running()) {
|
|
|
|
SDLKey keysym = sdl_event.key.keysym.sym;
|
2017-01-07 13:11:57 +03:00
|
|
|
Bit8u ascii = (Bit8u)sdl_event.key.keysym.unicode;
|
2017-01-05 21:20:47 +03:00
|
|
|
if (((keysym >= SDLK_SPACE) && (keysym < SDLK_DELETE)) ||
|
|
|
|
(keysym == SDLK_RETURN) || (keysym == SDLK_BACKSPACE)) {
|
2017-01-07 13:11:57 +03:00
|
|
|
if (ascii < 0x80) {
|
|
|
|
console_key_enq(ascii);
|
|
|
|
}
|
2017-01-05 21:20:47 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2010-05-16 13:01:36 +04:00
|
|
|
// mouse capture toggle-check
|
|
|
|
if (sdl_fullscreen_toggle == 0) {
|
|
|
|
if ((sdl_event.key.keysym.sym == SDLK_LCTRL) ||
|
|
|
|
(sdl_event.key.keysym.sym == SDLK_RCTRL)) {
|
|
|
|
mouse_toggle = mouse_toggle_check(BX_MT_KEY_CTRL, 1);
|
|
|
|
} else if (sdl_event.key.keysym.sym == SDLK_LALT) {
|
|
|
|
mouse_toggle = mouse_toggle_check(BX_MT_KEY_ALT, 1);
|
|
|
|
} else if (sdl_event.key.keysym.sym == SDLK_F10) {
|
|
|
|
mouse_toggle = mouse_toggle_check(BX_MT_KEY_F10, 1);
|
2010-05-18 19:33:41 +04:00
|
|
|
} else if (sdl_event.key.keysym.sym == SDLK_F12) {
|
|
|
|
mouse_toggle = mouse_toggle_check(BX_MT_KEY_F12, 1);
|
2010-05-16 13:01:36 +04:00
|
|
|
}
|
|
|
|
if (mouse_toggle) {
|
|
|
|
toggle_mouse_enable();
|
|
|
|
}
|
|
|
|
}
|
2002-02-06 00:39:15 +03:00
|
|
|
|
2012-02-28 22:38:32 +04:00
|
|
|
// Window/Fullscreen toggle-check
|
2010-05-16 13:01:36 +04:00
|
|
|
if (sdl_event.key.keysym.sym == SDLK_SCROLLOCK) {
|
|
|
|
sdl_fullscreen_toggle = ~sdl_fullscreen_toggle;
|
2014-07-05 12:00:01 +04:00
|
|
|
if (sdl_fullscreen_toggle == 0) {
|
2010-05-16 13:01:36 +04:00
|
|
|
switch_to_windowed();
|
2014-07-05 12:00:01 +04:00
|
|
|
} else {
|
2010-05-16 13:01:36 +04:00
|
|
|
switch_to_fullscreen();
|
2014-07-05 12:00:01 +04:00
|
|
|
}
|
2010-05-16 13:01:36 +04:00
|
|
|
bx_gui->show_headerbar();
|
|
|
|
bx_gui->flush();
|
|
|
|
break;
|
|
|
|
}
|
2002-02-06 00:39:15 +03:00
|
|
|
|
2010-05-16 13:01:36 +04:00
|
|
|
// convert sym->bochs code
|
|
|
|
if (sdl_event.key.keysym.sym > SDLK_LAST) break;
|
2006-02-22 22:18:29 +03:00
|
|
|
if (!SIM->get_param_bool(BXPN_KBD_USEMAPPING)->get()) {
|
2014-07-05 12:00:01 +04:00
|
|
|
key_event = sdl_sym_to_bx_key(sdl_event.key.keysym.sym);
|
2010-05-16 13:01:36 +04:00
|
|
|
BX_DEBUG(("keypress scancode=%d, sym=%d, bx_key = %d", sdl_event.key.keysym.scancode, sdl_event.key.keysym.sym, key_event));
|
|
|
|
} else {
|
|
|
|
/* use mapping */
|
2014-07-05 12:00:01 +04:00
|
|
|
BXKeyEntry *entry = bx_keymap.findHostKey(sdl_event.key.keysym.sym);
|
2010-05-16 13:01:36 +04:00
|
|
|
if (!entry) {
|
|
|
|
BX_ERROR(("host key %d (0x%x) not mapped!",
|
|
|
|
(unsigned) sdl_event.key.keysym.sym,
|
|
|
|
(unsigned) sdl_event.key.keysym.sym));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
key_event = entry->baseKey;
|
|
|
|
}
|
|
|
|
if (key_event == BX_KEY_UNHANDLED) break;
|
|
|
|
DEV_kbd_gen_scancode( key_event);
|
2004-06-05 16:16:33 +04:00
|
|
|
if ((key_event == BX_KEY_NUM_LOCK) || (key_event == BX_KEY_CAPS_LOCK)) {
|
2010-05-16 13:01:36 +04:00
|
|
|
DEV_kbd_gen_scancode(key_event | BX_KEY_RELEASED);
|
2004-06-05 16:16:33 +04:00
|
|
|
}
|
2010-05-16 13:01:36 +04:00
|
|
|
break;
|
2002-02-06 00:39:15 +03:00
|
|
|
|
2002-02-05 08:51:38 +03:00
|
|
|
case SDL_KEYUP:
|
2010-05-16 13:01:36 +04:00
|
|
|
// mouse capture toggle-check
|
|
|
|
if ((sdl_event.key.keysym.sym == SDLK_LCTRL) ||
|
|
|
|
(sdl_event.key.keysym.sym == SDLK_RCTRL)) {
|
|
|
|
mouse_toggle_check(BX_MT_KEY_CTRL, 0);
|
|
|
|
} else if (sdl_event.key.keysym.sym == SDLK_LALT) {
|
|
|
|
mouse_toggle_check(BX_MT_KEY_ALT, 0);
|
|
|
|
} else if (sdl_event.key.keysym.sym == SDLK_F10) {
|
|
|
|
mouse_toggle_check(BX_MT_KEY_F10, 0);
|
2010-05-18 19:33:41 +04:00
|
|
|
} else if (sdl_event.key.keysym.sym == SDLK_F12) {
|
|
|
|
mouse_toggle_check(BX_MT_KEY_F12, 0);
|
2010-05-16 13:01:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// filter out release of Windows/Fullscreen toggle and unsupported keys
|
|
|
|
if ((sdl_event.key.keysym.sym != SDLK_SCROLLOCK)
|
|
|
|
&& (sdl_event.key.keysym.sym < SDLK_LAST))
|
|
|
|
{
|
|
|
|
// convert sym->bochs code
|
2006-02-22 22:18:29 +03:00
|
|
|
if (!SIM->get_param_bool(BXPN_KBD_USEMAPPING)->get()) {
|
2014-07-05 12:00:01 +04:00
|
|
|
key_event = sdl_sym_to_bx_key(sdl_event.key.keysym.sym);
|
2002-10-10 22:02:08 +04:00
|
|
|
} else {
|
|
|
|
/* use mapping */
|
2014-07-05 12:00:01 +04:00
|
|
|
BXKeyEntry *entry = bx_keymap.findHostKey(sdl_event.key.keysym.sym);
|
2002-10-10 22:02:08 +04:00
|
|
|
if (!entry) {
|
2008-09-26 15:05:07 +04:00
|
|
|
BX_ERROR(("host key %d (0x%x) not mapped!",
|
2014-07-05 12:00:01 +04:00
|
|
|
(unsigned) sdl_event.key.keysym.sym,
|
|
|
|
(unsigned) sdl_event.key.keysym.sym));
|
2002-10-10 22:02:08 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
key_event = entry->baseKey;
|
|
|
|
}
|
2010-05-16 13:01:36 +04:00
|
|
|
if (key_event == BX_KEY_UNHANDLED) break;
|
2004-06-05 16:16:33 +04:00
|
|
|
if ((key_event == BX_KEY_NUM_LOCK) || (key_event == BX_KEY_CAPS_LOCK)) {
|
2008-02-16 01:05:43 +03:00
|
|
|
DEV_kbd_gen_scancode(key_event);
|
2004-06-05 16:16:33 +04:00
|
|
|
}
|
2010-05-16 13:01:36 +04:00
|
|
|
DEV_kbd_gen_scancode(key_event | BX_KEY_RELEASED);
|
|
|
|
}
|
|
|
|
break;
|
2002-02-06 00:39:15 +03:00
|
|
|
|
2002-02-05 08:51:38 +03:00
|
|
|
case SDL_QUIT:
|
2017-01-25 00:52:19 +03:00
|
|
|
BX_FATAL(("User requested shutdown."));
|
2002-02-05 08:51:38 +03:00
|
|
|
}
|
|
|
|
}
|
2006-01-23 21:34:47 +03:00
|
|
|
#if BX_SHOW_IPS
|
|
|
|
if (sdl_ips_update) {
|
|
|
|
sdl_ips_update = 0;
|
|
|
|
sdl_set_status_text(0, sdl_ips_text, 1);
|
|
|
|
}
|
|
|
|
#endif
|
2002-02-05 08:51:38 +03:00
|
|
|
}
|
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
void bx_sdl_gui_c::flush(void)
|
2002-02-05 08:51:38 +03:00
|
|
|
{
|
2008-02-16 01:05:43 +03:00
|
|
|
if(sdl_screen)
|
|
|
|
SDL_UpdateRect(sdl_screen,0,0,res_x,res_y+headerbar_height);
|
2002-02-06 05:12:45 +03:00
|
|
|
else
|
2008-02-16 01:05:43 +03:00
|
|
|
SDL_UpdateRect(sdl_fullscreen,0,0,res_x,res_y);
|
2002-02-05 08:51:38 +03:00
|
|
|
}
|
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
void bx_sdl_gui_c::clear_screen(void)
|
2002-02-05 08:51:38 +03:00
|
|
|
{
|
|
|
|
int i = res_y, j;
|
|
|
|
Uint32 color;
|
2002-02-06 05:12:45 +03:00
|
|
|
Uint32 *buf, *buf_row;
|
|
|
|
Uint32 disp;
|
2002-02-05 08:51:38 +03:00
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
if (sdl_screen) {
|
2014-07-05 12:00:01 +04:00
|
|
|
color = SDL_MapRGB(sdl_screen->format, 0, 0, 0);
|
2002-02-06 05:12:45 +03:00
|
|
|
disp = sdl_screen->pitch/4;
|
2014-07-05 12:00:01 +04:00
|
|
|
buf = (Uint32 *)sdl_screen->pixels + headerbar_height * disp;
|
2014-06-28 00:26:03 +04:00
|
|
|
} else if (sdl_fullscreen) {
|
2014-07-05 12:00:01 +04:00
|
|
|
color = SDL_MapRGB(sdl_fullscreen->format, 0, 0, 0);
|
2002-02-06 05:12:45 +03:00
|
|
|
disp = sdl_fullscreen->pitch/4;
|
2012-02-28 22:38:32 +04:00
|
|
|
buf = (Uint32 *)sdl_fullscreen->pixels + sdl_fullscreen->offset/4;
|
2002-02-05 08:51:38 +03:00
|
|
|
}
|
2002-02-06 05:12:45 +03:00
|
|
|
else return;
|
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
do {
|
2002-02-06 05:12:45 +03:00
|
|
|
buf_row = buf;
|
|
|
|
j = res_x;
|
2014-06-28 00:26:03 +04:00
|
|
|
while (j--) *buf++ = color;
|
2002-02-06 05:12:45 +03:00
|
|
|
buf = buf_row + disp;
|
2014-06-28 00:26:03 +04:00
|
|
|
} while (--i);
|
2002-02-06 05:12:45 +03:00
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
if (sdl_screen)
|
2002-02-06 05:12:45 +03:00
|
|
|
SDL_UpdateRect(sdl_screen,0,0,res_x,res_y+headerbar_height);
|
|
|
|
else
|
|
|
|
SDL_UpdateRect(sdl_fullscreen,0,0,res_x,res_y);
|
2002-02-05 08:51:38 +03:00
|
|
|
}
|
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
|
2012-10-14 22:29:44 +04:00
|
|
|
bx_bool bx_sdl_gui_c::palette_change(Bit8u index, Bit8u red, Bit8u green, Bit8u blue)
|
2002-02-05 08:51:38 +03:00
|
|
|
{
|
2012-10-14 22:29:44 +04:00
|
|
|
if (sdl_screen)
|
|
|
|
sdl_palette[index] = SDL_MapRGB(sdl_screen->format, red, green, blue);
|
|
|
|
else if (sdl_fullscreen)
|
|
|
|
sdl_palette[index] = SDL_MapRGB(sdl_fullscreen->format, red, green, blue);
|
2002-02-06 05:12:45 +03:00
|
|
|
|
2002-02-05 08:51:38 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
|
2009-10-24 17:17:33 +04:00
|
|
|
void bx_sdl_gui_c::dimension_update(unsigned x, unsigned y,
|
|
|
|
unsigned fheight, unsigned fwidth, unsigned bpp)
|
2002-02-05 08:51:38 +03:00
|
|
|
{
|
2009-10-24 17:17:33 +04:00
|
|
|
if (bpp == 8 || bpp == 15 || bpp == 16 || bpp == 24 || bpp == 32) {
|
2012-10-14 22:29:44 +04:00
|
|
|
disp_bpp = guest_bpp = bpp;
|
|
|
|
} else {
|
2003-07-02 21:25:50 +04:00
|
|
|
BX_PANIC(("%d bpp graphics mode not supported", bpp));
|
2003-06-28 12:04:31 +04:00
|
|
|
}
|
2012-10-14 22:29:44 +04:00
|
|
|
guest_textmode = (fheight > 0);
|
2017-01-03 23:59:59 +03:00
|
|
|
guest_fsize = (fheight << 4) | fwidth;
|
2012-10-14 22:29:44 +04:00
|
|
|
guest_xres = x;
|
|
|
|
guest_yres = y;
|
|
|
|
if (guest_textmode) {
|
2002-09-08 11:56:10 +04:00
|
|
|
fontheight = fheight;
|
2003-05-11 19:07:54 +04:00
|
|
|
fontwidth = fwidth;
|
2003-05-18 19:38:58 +04:00
|
|
|
text_cols = x / fontwidth;
|
|
|
|
text_rows = y / fontheight;
|
2002-02-06 05:12:45 +03:00
|
|
|
}
|
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
if ((x == res_x) && (y == res_y)) return;
|
2016-08-12 20:06:14 +03:00
|
|
|
#ifndef ANDROID
|
|
|
|
// This is not needed on Android
|
2014-07-10 14:31:51 +04:00
|
|
|
if (((int)x > sdl_maxres.w) || ((int)y > sdl_maxres.h)) {
|
|
|
|
BX_PANIC(("dimension_update(): resolution of out of display bounds"));
|
|
|
|
return;
|
|
|
|
}
|
2016-08-12 20:06:14 +03:00
|
|
|
#endif
|
2002-02-05 08:51:38 +03:00
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
if (sdl_screen) {
|
2008-02-16 01:05:43 +03:00
|
|
|
SDL_FreeSurface(sdl_screen);
|
2002-02-06 05:12:45 +03:00
|
|
|
sdl_screen = NULL;
|
|
|
|
}
|
2014-06-28 00:26:03 +04:00
|
|
|
if(sdl_fullscreen) {
|
2008-02-16 01:05:43 +03:00
|
|
|
SDL_FreeSurface(sdl_fullscreen);
|
2002-02-06 05:12:45 +03:00
|
|
|
sdl_fullscreen = NULL;
|
|
|
|
}
|
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
if (sdl_fullscreen_toggle == 0) {
|
2008-02-16 01:05:43 +03:00
|
|
|
sdl_screen = SDL_SetVideoMode(x, y+headerbar_height+statusbar_height, 32, SDL_SWSURFACE);
|
|
|
|
if(!sdl_screen)
|
2002-02-06 05:12:45 +03:00
|
|
|
{
|
2017-01-25 00:52:19 +03:00
|
|
|
BX_FATAL(("Unable to set requested videomode: %ix%i: %s",x,y,SDL_GetError()));
|
2002-02-06 05:12:45 +03:00
|
|
|
}
|
|
|
|
headerbar_fg = SDL_MapRGB(
|
2014-06-28 00:26:03 +04:00
|
|
|
sdl_screen->format,
|
|
|
|
BX_HEADERBAR_FG_RED,
|
|
|
|
BX_HEADERBAR_FG_GREEN,
|
|
|
|
BX_HEADERBAR_FG_BLUE);
|
2002-02-06 05:12:45 +03:00
|
|
|
headerbar_bg = SDL_MapRGB(
|
2014-06-28 00:26:03 +04:00
|
|
|
sdl_screen->format,
|
|
|
|
BX_HEADERBAR_BG_RED,
|
|
|
|
BX_HEADERBAR_BG_GREEN,
|
|
|
|
BX_HEADERBAR_BG_BLUE);
|
|
|
|
} else {
|
2016-08-14 19:55:05 +03:00
|
|
|
#ifdef ANDROID
|
|
|
|
sdl_fullscreen = SDL_SetVideoMode(x, y, 32, SDL_SWSURFACE|SDL_FULLSCREEN);
|
|
|
|
#else
|
2008-02-16 01:05:43 +03:00
|
|
|
sdl_fullscreen = SDL_SetVideoMode(x, y, 32, SDL_HWSURFACE|SDL_FULLSCREEN);
|
2016-08-14 19:55:05 +03:00
|
|
|
#endif
|
2014-06-28 00:26:03 +04:00
|
|
|
if(!sdl_fullscreen) {
|
2017-01-25 00:52:19 +03:00
|
|
|
BX_FATAL(("Unable to set requested videomode: %ix%i: %s",x,y,SDL_GetError()));
|
2002-02-06 05:12:45 +03:00
|
|
|
}
|
2002-02-05 08:51:38 +03:00
|
|
|
}
|
|
|
|
res_x = x;
|
|
|
|
res_y = y;
|
2002-10-06 21:17:14 +04:00
|
|
|
half_res_x = x/2;
|
|
|
|
half_res_y = y/2;
|
2002-10-25 01:07:56 +04:00
|
|
|
bx_gui->show_headerbar();
|
2014-07-05 12:00:01 +04:00
|
|
|
host_xres = x;
|
|
|
|
host_yres = y;
|
|
|
|
host_bpp = 32;
|
2002-02-05 08:51:38 +03:00
|
|
|
}
|
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
|
2009-10-24 17:17:33 +04:00
|
|
|
unsigned bx_sdl_gui_c::create_bitmap(const unsigned char *bmap, unsigned xdim, unsigned ydim)
|
2002-02-05 08:51:38 +03:00
|
|
|
{
|
2002-02-07 05:12:51 +03:00
|
|
|
Uint32 *buf, *buf_row;
|
|
|
|
Uint32 disp;
|
|
|
|
unsigned char pixels;
|
|
|
|
|
2002-03-06 23:36:35 +03:00
|
|
|
if (n_sdl_bitmaps >= MAX_SDL_BITMAPS) {
|
2008-09-26 15:05:07 +04:00
|
|
|
BX_PANIC(("too many SDL bitmaps. To fix, increase MAX_SDL_BITMAPS"));
|
2002-03-06 23:36:35 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-24 17:17:33 +04:00
|
|
|
bitmaps *tmp = new bitmaps;
|
|
|
|
|
2002-02-07 05:12:51 +03:00
|
|
|
tmp->surface = SDL_CreateRGBSurface(
|
|
|
|
SDL_SWSURFACE,
|
|
|
|
xdim,
|
|
|
|
ydim,
|
|
|
|
32,
|
|
|
|
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
|
|
|
0xff000000,
|
|
|
|
0x00ff0000,
|
|
|
|
0x0000ff00,
|
2002-03-17 19:57:07 +03:00
|
|
|
0x00000000
|
2002-02-07 05:12:51 +03:00
|
|
|
#else
|
|
|
|
0x000000ff,
|
|
|
|
0x0000ff00,
|
|
|
|
0x00ff0000,
|
2002-03-17 19:57:07 +03:00
|
|
|
0x00000000
|
2002-02-07 05:12:51 +03:00
|
|
|
#endif
|
|
|
|
);
|
2009-10-24 17:17:33 +04:00
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
if (!tmp->surface) {
|
2002-02-07 05:12:51 +03:00
|
|
|
delete tmp;
|
2002-10-25 01:07:56 +04:00
|
|
|
bx_gui->exit();
|
2017-01-25 00:52:19 +03:00
|
|
|
BX_FATAL(("Unable to create requested bitmap"));
|
2002-02-07 05:12:51 +03:00
|
|
|
}
|
2009-10-24 17:17:33 +04:00
|
|
|
|
2002-02-07 05:12:51 +03:00
|
|
|
tmp->src.w = xdim;
|
|
|
|
tmp->src.h = ydim;
|
|
|
|
tmp->src.x = 0;
|
|
|
|
tmp->src.y = 0;
|
|
|
|
tmp->dst.x = -1;
|
|
|
|
tmp->dst.y = 0;
|
|
|
|
tmp->dst.w = xdim;
|
|
|
|
tmp->dst.h = ydim;
|
|
|
|
buf = (Uint32 *)tmp->surface->pixels;
|
|
|
|
disp = tmp->surface->pitch/4;
|
2009-10-24 17:17:33 +04:00
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
do {
|
2002-02-07 05:12:51 +03:00
|
|
|
buf_row = buf;
|
|
|
|
xdim = tmp->src.w / 8;
|
2014-06-28 00:26:03 +04:00
|
|
|
do {
|
2002-02-07 05:12:51 +03:00
|
|
|
pixels = *bmap++;
|
2014-06-28 00:26:03 +04:00
|
|
|
for (unsigned i=0; i<8; i++) {
|
|
|
|
if ((pixels & 0x01) == 0)
|
|
|
|
*buf++ = headerbar_bg;
|
|
|
|
else
|
|
|
|
*buf++ = headerbar_fg;
|
|
|
|
pixels = pixels >> 1;
|
2002-02-07 05:12:51 +03:00
|
|
|
}
|
2014-06-28 00:26:03 +04:00
|
|
|
} while (--xdim);
|
2002-02-07 05:12:51 +03:00
|
|
|
buf = buf_row + disp;
|
2014-06-28 00:26:03 +04:00
|
|
|
} while (--ydim);
|
2009-10-24 17:17:33 +04:00
|
|
|
|
|
|
|
SDL_UpdateRect(tmp->surface, 0, 0, tmp->src.w, tmp->src.h);
|
2002-03-06 23:36:35 +03:00
|
|
|
sdl_bitmaps[n_sdl_bitmaps] = tmp;
|
2009-10-24 17:17:33 +04:00
|
|
|
|
2002-03-06 23:36:35 +03:00
|
|
|
return n_sdl_bitmaps++;
|
2002-02-05 08:51:38 +03:00
|
|
|
}
|
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
|
2009-10-24 17:17:33 +04:00
|
|
|
unsigned bx_sdl_gui_c::headerbar_bitmap(unsigned bmap_id, unsigned alignment,
|
2002-02-05 08:51:38 +03:00
|
|
|
void (*f)(void))
|
|
|
|
{
|
2002-03-17 15:34:03 +03:00
|
|
|
unsigned hb_index;
|
2002-02-07 05:12:51 +03:00
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
if (bmap_id >= (unsigned)n_sdl_bitmaps) return 0;
|
2002-03-17 15:34:03 +03:00
|
|
|
|
2008-02-16 01:05:43 +03:00
|
|
|
if ((bx_headerbar_entries+1) > BX_MAX_HEADERBAR_ENTRIES)
|
2002-03-17 15:34:03 +03:00
|
|
|
BX_PANIC(("too many headerbar entries, increase BX_MAX_HEADERBAR_ENTRIES"));
|
|
|
|
|
|
|
|
bx_headerbar_entries++;
|
|
|
|
hb_index = bx_headerbar_entries - 1;
|
|
|
|
|
2017-01-14 16:10:20 +03:00
|
|
|
bx_headerbar_entry[hb_index].bmap_id = bmap_id;
|
|
|
|
bx_headerbar_entry[hb_index].xdim = sdl_bitmaps[bmap_id]->src.w;
|
|
|
|
bx_headerbar_entry[hb_index].ydim = sdl_bitmaps[bmap_id]->src.h;
|
|
|
|
bx_headerbar_entry[hb_index].alignment = alignment;
|
|
|
|
bx_headerbar_entry[hb_index].f = f;
|
2009-10-24 17:17:33 +04:00
|
|
|
|
2002-03-17 15:34:03 +03:00
|
|
|
if (alignment == BX_GRAVITY_LEFT) {
|
|
|
|
sdl_bitmaps[bmap_id]->dst.x = bx_bitmap_left_xorigin;
|
|
|
|
bx_bitmap_left_xorigin += sdl_bitmaps[bmap_id]->src.w;
|
|
|
|
} else {
|
|
|
|
bx_bitmap_right_xorigin += sdl_bitmaps[bmap_id]->src.w;
|
|
|
|
sdl_bitmaps[bmap_id]->dst.x = bx_bitmap_right_xorigin;
|
2002-02-07 05:12:51 +03:00
|
|
|
}
|
2017-01-14 16:10:20 +03:00
|
|
|
bx_headerbar_entry[hb_index].xorigin = sdl_bitmaps[bmap_id]->dst.x;
|
2009-10-24 17:17:33 +04:00
|
|
|
|
2002-03-17 15:34:03 +03:00
|
|
|
return hb_index;
|
2002-02-05 08:51:38 +03:00
|
|
|
}
|
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
|
2009-10-24 17:17:33 +04:00
|
|
|
void bx_sdl_gui_c::replace_bitmap(unsigned hbar_id, unsigned bmap_id)
|
2002-02-05 08:51:38 +03:00
|
|
|
{
|
2002-03-17 15:34:03 +03:00
|
|
|
SDL_Rect hb_dst;
|
2002-03-17 23:56:15 +03:00
|
|
|
unsigned old_id;
|
2002-03-17 15:34:03 +03:00
|
|
|
|
2014-07-05 12:00:01 +04:00
|
|
|
if (!sdl_screen) return;
|
2017-01-14 16:10:20 +03:00
|
|
|
old_id = bx_headerbar_entry[hbar_id].bmap_id;
|
2002-03-17 23:56:15 +03:00
|
|
|
hb_dst = sdl_bitmaps[old_id]->dst;
|
|
|
|
sdl_bitmaps[old_id]->dst.x = -1;
|
2017-01-14 16:10:20 +03:00
|
|
|
bx_headerbar_entry[hbar_id].bmap_id = bmap_id;
|
2002-03-17 23:56:15 +03:00
|
|
|
sdl_bitmaps[bmap_id]->dst.x = hb_dst.x;
|
2014-06-28 00:26:03 +04:00
|
|
|
if (sdl_bitmaps[bmap_id]->dst.x != -1) {
|
2017-01-14 16:10:20 +03:00
|
|
|
if (bx_headerbar_entry[hbar_id].alignment == BX_GRAVITY_RIGHT) {
|
2002-03-17 15:34:03 +03:00
|
|
|
hb_dst.x = res_x - hb_dst.x;
|
|
|
|
}
|
|
|
|
SDL_BlitSurface(
|
|
|
|
sdl_bitmaps[bmap_id]->surface,
|
|
|
|
&sdl_bitmaps[bmap_id]->src,
|
|
|
|
sdl_screen,
|
|
|
|
&hb_dst);
|
|
|
|
SDL_UpdateRect(
|
|
|
|
sdl_screen,
|
|
|
|
hb_dst.x,
|
|
|
|
sdl_bitmaps[bmap_id]->dst.y,
|
|
|
|
sdl_bitmaps[bmap_id]->src.w,
|
2008-02-16 01:05:43 +03:00
|
|
|
sdl_bitmaps[bmap_id]->src.h);
|
2002-03-17 15:34:03 +03:00
|
|
|
}
|
2002-02-05 08:51:38 +03:00
|
|
|
}
|
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
void bx_sdl_gui_c::show_headerbar(void)
|
2002-02-05 08:51:38 +03:00
|
|
|
{
|
2002-02-06 05:12:45 +03:00
|
|
|
Uint32 *buf;
|
|
|
|
Uint32 *buf_row;
|
2002-02-07 05:12:51 +03:00
|
|
|
Uint32 disp;
|
2002-02-06 05:12:45 +03:00
|
|
|
int rowsleft = headerbar_height;
|
2004-02-14 00:45:28 +03:00
|
|
|
int colsleft, sb_item;
|
2002-03-17 15:34:03 +03:00
|
|
|
int bitmapscount = bx_headerbar_entries;
|
2004-02-14 00:45:28 +03:00
|
|
|
unsigned current_bmp, pos_x;
|
2002-03-17 15:34:03 +03:00
|
|
|
SDL_Rect hb_dst;
|
2002-02-06 05:12:45 +03:00
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
if (!sdl_screen) return;
|
2002-02-07 05:12:51 +03:00
|
|
|
disp = sdl_screen->pitch/4;
|
2002-02-06 05:12:45 +03:00
|
|
|
buf = (Uint32 *)sdl_screen->pixels;
|
|
|
|
|
2002-02-07 05:12:51 +03:00
|
|
|
// draw headerbar background
|
2014-06-28 00:26:03 +04:00
|
|
|
do {
|
2002-02-06 05:12:45 +03:00
|
|
|
colsleft = res_x;
|
|
|
|
buf_row = buf;
|
2014-06-28 00:26:03 +04:00
|
|
|
do {
|
2002-02-06 05:12:45 +03:00
|
|
|
*buf++ = headerbar_bg;
|
2014-06-28 00:26:03 +04:00
|
|
|
} while (--colsleft);
|
2002-02-07 05:12:51 +03:00
|
|
|
buf = buf_row + disp;
|
2014-06-28 00:26:03 +04:00
|
|
|
} while (--rowsleft);
|
2002-02-07 05:12:51 +03:00
|
|
|
SDL_UpdateRect( sdl_screen, 0,0,res_x,headerbar_height);
|
2002-02-05 08:51:38 +03:00
|
|
|
|
2002-02-07 05:12:51 +03:00
|
|
|
// go thru the bitmaps and display the active ones
|
2014-06-28 00:26:03 +04:00
|
|
|
while (bitmapscount--) {
|
2017-01-14 16:10:20 +03:00
|
|
|
current_bmp = bx_headerbar_entry[bitmapscount].bmap_id;
|
2014-06-28 00:26:03 +04:00
|
|
|
if(sdl_bitmaps[current_bmp]->dst.x != -1) {
|
2002-03-17 15:34:03 +03:00
|
|
|
hb_dst = sdl_bitmaps[current_bmp]->dst;
|
2017-01-14 16:10:20 +03:00
|
|
|
if (bx_headerbar_entry[bitmapscount].alignment == BX_GRAVITY_RIGHT) {
|
2002-03-17 15:34:03 +03:00
|
|
|
hb_dst.x = res_x - hb_dst.x;
|
|
|
|
}
|
2002-02-07 05:12:51 +03:00
|
|
|
SDL_BlitSurface(
|
2014-06-28 00:26:03 +04:00
|
|
|
sdl_bitmaps[current_bmp]->surface,
|
|
|
|
&sdl_bitmaps[current_bmp]->src,
|
|
|
|
sdl_screen,
|
|
|
|
&hb_dst);
|
2002-02-07 05:12:51 +03:00
|
|
|
SDL_UpdateRect(
|
2014-06-28 00:26:03 +04:00
|
|
|
sdl_screen,
|
|
|
|
hb_dst.x,
|
|
|
|
sdl_bitmaps[current_bmp]->dst.y,
|
|
|
|
sdl_bitmaps[current_bmp]->src.w,
|
|
|
|
sdl_bitmaps[current_bmp]->src.h);
|
2002-02-07 05:12:51 +03:00
|
|
|
}
|
|
|
|
}
|
2004-02-14 00:45:28 +03:00
|
|
|
// draw statusbar background
|
|
|
|
rowsleft = statusbar_height;
|
|
|
|
buf = (Uint32 *)sdl_screen->pixels + (res_y + headerbar_height) * disp;
|
2014-06-28 00:26:03 +04:00
|
|
|
do {
|
2004-02-14 00:45:28 +03:00
|
|
|
colsleft = res_x;
|
|
|
|
buf_row = buf;
|
|
|
|
sb_item = 1;
|
|
|
|
pos_x = 0;
|
2014-06-28 00:26:03 +04:00
|
|
|
do {
|
|
|
|
if (pos_x == statusitem_pos[sb_item]) {
|
2004-02-14 00:45:28 +03:00
|
|
|
*buf++ = headerbar_fg;
|
|
|
|
if (sb_item < 11) sb_item++;
|
2014-06-28 00:26:03 +04:00
|
|
|
} else {
|
2004-02-14 00:45:28 +03:00
|
|
|
*buf++ = headerbar_bg;
|
|
|
|
}
|
|
|
|
pos_x++;
|
2014-06-28 00:26:03 +04:00
|
|
|
} while (--colsleft);
|
2004-02-14 00:45:28 +03:00
|
|
|
buf = buf_row + disp;
|
2014-06-28 00:26:03 +04:00
|
|
|
} while (--rowsleft);
|
2004-02-14 00:45:28 +03:00
|
|
|
SDL_UpdateRect( sdl_screen, 0,res_y+headerbar_height,res_x,statusbar_height);
|
2004-03-01 00:16:18 +03:00
|
|
|
for (unsigned i=0; i<statusitem_count; i++) {
|
2011-12-28 15:51:42 +04:00
|
|
|
sdl_set_status_text(i+1, statusitem[i].text, statusitem_active[i+1]);
|
2004-02-14 00:45:28 +03:00
|
|
|
}
|
2002-02-05 08:51:38 +03:00
|
|
|
}
|
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
|
|
|
|
int bx_sdl_gui_c::get_clipboard_text(Bit8u **bytes, Bit32s *nbytes)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int bx_sdl_gui_c::set_clipboard_text(char *text_snapshot, Bit32u len)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-25 15:44:41 +04:00
|
|
|
void bx_sdl_gui_c::mouse_enabled_changed_specific (bx_bool val)
|
2002-02-05 08:51:38 +03:00
|
|
|
{
|
2014-06-28 00:26:03 +04:00
|
|
|
if (val == 1) {
|
2002-03-19 00:21:19 +03:00
|
|
|
SDL_ShowCursor(0);
|
|
|
|
SDL_WM_GrabInput(SDL_GRAB_ON);
|
2014-06-28 00:26:03 +04:00
|
|
|
} else {
|
2002-03-19 00:21:19 +03:00
|
|
|
SDL_ShowCursor(1);
|
|
|
|
SDL_WM_GrabInput(SDL_GRAB_OFF);
|
|
|
|
}
|
|
|
|
sdl_grab = val;
|
2002-02-05 08:51:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
void bx_sdl_gui_c::exit(void)
|
2002-02-05 08:51:38 +03:00
|
|
|
{
|
2014-08-17 16:48:05 +04:00
|
|
|
if (sdl_screen)
|
2002-02-05 08:51:38 +03:00
|
|
|
SDL_FreeSurface(sdl_screen);
|
2014-08-17 16:48:05 +04:00
|
|
|
if (sdl_fullscreen)
|
2002-02-07 05:12:51 +03:00
|
|
|
SDL_FreeSurface(sdl_fullscreen);
|
2014-08-17 16:48:05 +04:00
|
|
|
while (n_sdl_bitmaps) {
|
2008-02-16 01:05:43 +03:00
|
|
|
SDL_FreeSurface(sdl_bitmaps[n_sdl_bitmaps-1]->surface);
|
2002-03-06 23:36:35 +03:00
|
|
|
n_sdl_bitmaps--;
|
2002-02-07 05:12:51 +03:00
|
|
|
}
|
2014-08-17 16:48:05 +04:00
|
|
|
|
|
|
|
#if BX_DEBUGGER && BX_DEBUGGER_GUI
|
|
|
|
if (SIM->has_debug_gui()) {
|
|
|
|
close_debug_dialog();
|
|
|
|
}
|
|
|
|
#endif
|
2002-02-05 08:51:38 +03:00
|
|
|
}
|
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
// New graphics API methods
|
2002-10-08 10:14:53 +04:00
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
bx_svga_tileinfo_t *bx_sdl_gui_c::graphics_tile_info(bx_svga_tileinfo_t *info)
|
|
|
|
{
|
|
|
|
if (sdl_screen) {
|
|
|
|
info->bpp = sdl_screen->format->BitsPerPixel;
|
|
|
|
info->pitch = sdl_screen->pitch;
|
|
|
|
info->red_shift = sdl_screen->format->Rshift + 8 - sdl_screen->format->Rloss;
|
|
|
|
info->green_shift = sdl_screen->format->Gshift + 8 - sdl_screen->format->Gloss;
|
|
|
|
info->blue_shift = sdl_screen->format->Bshift + 8 - sdl_screen->format->Bloss;
|
|
|
|
info->red_mask = sdl_screen->format->Rmask;
|
|
|
|
info->green_mask = sdl_screen->format->Gmask;
|
|
|
|
info->blue_mask = sdl_screen->format->Bmask;
|
|
|
|
info->is_indexed = (sdl_screen->format->palette != NULL);
|
|
|
|
} else {
|
|
|
|
info->bpp = sdl_fullscreen->format->BitsPerPixel;
|
|
|
|
info->pitch = sdl_fullscreen->pitch;
|
|
|
|
info->red_shift = sdl_fullscreen->format->Rshift + 8 - sdl_fullscreen->format->Rloss;
|
|
|
|
info->green_shift = sdl_fullscreen->format->Gshift + 8 - sdl_fullscreen->format->Gloss;
|
|
|
|
info->blue_shift = sdl_fullscreen->format->Bshift + 8 - sdl_fullscreen->format->Bloss;
|
|
|
|
info->red_mask = sdl_fullscreen->format->Rmask;
|
|
|
|
info->green_mask = sdl_fullscreen->format->Gmask;
|
|
|
|
info->blue_mask = sdl_fullscreen->format->Bmask;
|
|
|
|
info->is_indexed = (sdl_fullscreen->format->palette != NULL);
|
|
|
|
}
|
2017-04-04 20:57:44 +03:00
|
|
|
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
2014-06-28 00:26:03 +04:00
|
|
|
info->is_little_endian = 0;
|
2017-04-04 20:57:44 +03:00
|
|
|
#else
|
|
|
|
info->is_little_endian = 1;
|
2014-06-28 00:26:03 +04:00
|
|
|
#endif
|
|
|
|
return info;
|
|
|
|
}
|
2002-10-08 10:14:53 +04:00
|
|
|
|
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
Bit8u *bx_sdl_gui_c::graphics_tile_get(unsigned x0, unsigned y0, unsigned *w, unsigned *h)
|
2002-10-08 10:14:53 +04:00
|
|
|
{
|
2014-06-28 00:26:03 +04:00
|
|
|
if (x0+x_tilesize > res_x) {
|
|
|
|
*w = res_x - x0;
|
|
|
|
} else {
|
|
|
|
*w = x_tilesize;
|
2002-10-08 10:14:53 +04:00
|
|
|
}
|
2014-06-28 00:26:03 +04:00
|
|
|
|
|
|
|
if (y0+y_tilesize > res_y) {
|
|
|
|
*h = res_y - y0;
|
|
|
|
} else {
|
|
|
|
*h = y_tilesize;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sdl_screen) {
|
|
|
|
return (Bit8u *)sdl_screen->pixels +
|
2014-07-05 12:00:01 +04:00
|
|
|
sdl_screen->pitch * (headerbar_height + y0) +
|
|
|
|
sdl_screen->format->BytesPerPixel * x0;
|
2014-06-28 00:26:03 +04:00
|
|
|
} else {
|
|
|
|
return (Bit8u *)sdl_fullscreen->pixels + sdl_fullscreen->offset +
|
2014-07-05 12:00:01 +04:00
|
|
|
sdl_fullscreen->pitch * y0 +
|
|
|
|
sdl_fullscreen->format->BytesPerPixel * x0;
|
2014-06-28 00:26:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void bx_sdl_gui_c::graphics_tile_update_in_place(unsigned x0, unsigned y0,
|
|
|
|
unsigned w, unsigned h)
|
|
|
|
{
|
|
|
|
// Nothing to do here
|
2002-10-08 10:14:53 +04:00
|
|
|
}
|
2002-11-19 08:47:45 +03:00
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
// Optional bx_gui_c methods
|
|
|
|
|
2008-03-07 00:15:40 +03:00
|
|
|
void bx_sdl_gui_c::set_display_mode(disp_mode_t newmode)
|
2002-12-06 22:34:32 +03:00
|
|
|
{
|
|
|
|
// if no mode change, do nothing.
|
|
|
|
if (disp_mode == newmode) return;
|
|
|
|
// remember the display mode for next time
|
|
|
|
disp_mode = newmode;
|
2017-01-05 21:20:47 +03:00
|
|
|
if ((newmode == DISP_MODE_SIM) && console_running()) {
|
|
|
|
console_cleanup();
|
|
|
|
return;
|
|
|
|
}
|
2002-12-06 22:34:32 +03:00
|
|
|
// If fullscreen mode is on, we must switch back to windowed mode if
|
|
|
|
// the user needs to see the text console.
|
|
|
|
if (sdl_fullscreen_toggle) {
|
|
|
|
switch (newmode) {
|
|
|
|
case DISP_MODE_CONFIG:
|
2012-05-11 20:17:59 +04:00
|
|
|
BX_DEBUG(("switch to configuration mode (windowed)"));
|
|
|
|
switch_to_windowed();
|
|
|
|
break;
|
2002-12-06 22:34:32 +03:00
|
|
|
case DISP_MODE_SIM:
|
2012-05-11 20:17:59 +04:00
|
|
|
BX_DEBUG(("switch to simulation mode (fullscreen)"));
|
|
|
|
switch_to_fullscreen();
|
|
|
|
break;
|
2002-12-06 22:34:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
|
|
|
|
void bx_sdl_gui_c::statusbar_setitem_specific(int element, bx_bool active, bx_bool w)
|
|
|
|
{
|
|
|
|
sdl_set_status_text(element+1, statusitem[element].text, active, w);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-10 14:31:51 +04:00
|
|
|
void bx_sdl_gui_c::get_capabilities(Bit16u *xres, Bit16u *yres, Bit16u *bpp)
|
|
|
|
{
|
|
|
|
*xres = sdl_maxres.w;
|
|
|
|
*yres = sdl_maxres.h;
|
|
|
|
*bpp = 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-24 14:38:46 +04:00
|
|
|
void bx_sdl_gui_c::set_mouse_mode_absxy(bx_bool mode)
|
|
|
|
{
|
|
|
|
sdl_mouse_mode_absxy = mode;
|
|
|
|
}
|
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
|
2006-01-22 21:15:48 +03:00
|
|
|
#if BX_SHOW_IPS
|
2006-01-22 19:30:48 +03:00
|
|
|
void bx_sdl_gui_c::show_ips(Bit32u ips_count)
|
|
|
|
{
|
2012-05-11 20:17:59 +04:00
|
|
|
if (!sdl_hide_ips && !sdl_ips_update) {
|
|
|
|
ips_count /= 1000;
|
|
|
|
sprintf(sdl_ips_text, "IPS: %u.%3.3uM", ips_count / 1000, ips_count % 1000);
|
2006-01-23 21:34:47 +03:00
|
|
|
sdl_ips_update = 1;
|
|
|
|
}
|
2006-01-22 19:30:48 +03:00
|
|
|
}
|
2006-01-22 21:15:48 +03:00
|
|
|
#endif
|
2006-01-22 19:30:48 +03:00
|
|
|
|
2014-07-05 12:00:01 +04:00
|
|
|
/// key mapping code for SDL
|
|
|
|
|
2014-06-28 00:26:03 +04:00
|
|
|
typedef struct {
|
|
|
|
const char *name;
|
|
|
|
Bit32u value;
|
|
|
|
} keyTableEntry;
|
|
|
|
|
|
|
|
#define DEF_SDL_KEY(key) \
|
|
|
|
{ #key, key },
|
|
|
|
|
|
|
|
keyTableEntry keytable[] = {
|
|
|
|
// this include provides all the entries.
|
|
|
|
#include "sdlkeys.h"
|
|
|
|
// one final entry to mark the end
|
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
// function to convert key names into SDLKey values.
|
|
|
|
// This first try will be horribly inefficient, but it only has
|
|
|
|
// to be done while loading a keymap. Once the simulation starts,
|
|
|
|
// this function won't be called.
|
|
|
|
static Bit32u convertStringToSDLKey (const char *string)
|
|
|
|
{
|
|
|
|
keyTableEntry *ptr;
|
|
|
|
for (ptr = &keytable[0]; ptr->name != NULL; ptr++) {
|
|
|
|
//BX_DEBUG (("comparing string '%s' to SDL key '%s'", string, ptr->name));
|
|
|
|
if (!strcmp(string, ptr->name))
|
|
|
|
return ptr->value;
|
|
|
|
}
|
|
|
|
return BX_KEYMAP_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2002-11-19 08:47:45 +03:00
|
|
|
#endif /* if BX_WITH_SDL */
|