1999-10-03 14:16:26 +00:00
|
|
|
/*
|
|
|
|
* video_x.cpp - Video/graphics emulation, X11 specific stuff
|
|
|
|
*
|
2002-01-15 14:58:43 +00:00
|
|
|
* Basilisk II (C) 1997-2002 Christian Bauer
|
1999-10-03 14:16:26 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTES:
|
|
|
|
* The Ctrl key works like a qualifier for special actions:
|
|
|
|
* Ctrl-Tab = suspend DGA mode
|
|
|
|
* Ctrl-Esc = emergency quit
|
|
|
|
* Ctrl-F1 = mount floppy
|
2001-07-03 15:59:49 +00:00
|
|
|
* Ctrl-F5 = grab mouse (in windowed mode)
|
1999-10-03 14:16:26 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sysdeps.h"
|
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <X11/keysym.h>
|
|
|
|
#include <X11/extensions/XShm.h>
|
|
|
|
#include <sys/ipc.h>
|
|
|
|
#include <sys/shm.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2001-07-06 20:49:53 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2000-07-13 13:47:12 +00:00
|
|
|
#ifdef HAVE_PTHREADS
|
|
|
|
# include <pthread.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENABLE_XF86_DGA
|
|
|
|
# include <X11/extensions/xf86dga.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENABLE_XF86_VIDMODE
|
|
|
|
# include <X11/extensions/xf86vmode.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENABLE_FBDEV_DGA
|
|
|
|
# include <sys/mman.h>
|
|
|
|
#endif
|
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
#include "cpu_emulation.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "adb.h"
|
|
|
|
#include "macos_util.h"
|
|
|
|
#include "prefs.h"
|
|
|
|
#include "user_strings.h"
|
|
|
|
#include "video.h"
|
|
|
|
|
2001-07-06 22:37:23 +00:00
|
|
|
#define DEBUG 0
|
1999-10-03 14:16:26 +00:00
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
|
2002-04-25 11:00:31 +00:00
|
|
|
// Supported video modes
|
|
|
|
static vector<video_mode> VideoModes;
|
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
// Display types
|
|
|
|
enum {
|
|
|
|
DISPLAY_WINDOW, // X11 window, using MIT SHM extensions if possible
|
|
|
|
DISPLAY_DGA // DGA fullscreen display
|
|
|
|
};
|
|
|
|
|
|
|
|
// Constants
|
1999-10-04 21:07:18 +00:00
|
|
|
const char KEYCODE_FILE_NAME[] = DATADIR "/keycodes";
|
2001-06-30 17:21:56 +00:00
|
|
|
|
2001-07-09 11:22:01 +00:00
|
|
|
static const int win_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | ExposureMask | StructureNotifyMask;
|
2001-06-30 17:21:56 +00:00
|
|
|
static const int dga_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask;
|
1999-10-03 14:16:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Global variables
|
1999-10-25 20:22:35 +00:00
|
|
|
static int32 frame_skip; // Prefs items
|
2001-06-30 17:21:56 +00:00
|
|
|
static int16 mouse_wheel_mode;
|
|
|
|
static int16 mouse_wheel_lines;
|
1999-10-25 20:22:35 +00:00
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
static int display_type = DISPLAY_WINDOW; // See enum above
|
2000-07-13 16:12:33 +00:00
|
|
|
static bool local_X11; // Flag: X server running on local machine?
|
2001-06-30 17:21:56 +00:00
|
|
|
static uint8 *the_buffer = NULL; // Mac frame buffer (where MacOS draws into)
|
|
|
|
static uint8 *the_buffer_copy = NULL; // Copy of Mac frame buffer (for refreshed modes)
|
2001-07-07 09:14:47 +00:00
|
|
|
static uint32 the_buffer_size; // Size of allocated the_buffer
|
2000-07-13 13:47:12 +00:00
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
static bool redraw_thread_active = false; // Flag: Redraw thread installed
|
2001-06-30 20:18:36 +00:00
|
|
|
#ifdef HAVE_PTHREADS
|
2002-02-07 16:10:57 +00:00
|
|
|
static pthread_attr_t redraw_thread_attr; // Redraw thread attributes
|
2001-06-28 21:20:02 +00:00
|
|
|
static volatile bool redraw_thread_cancel; // Flag: Cancel Redraw thread
|
1999-10-03 14:16:26 +00:00
|
|
|
static pthread_t redraw_thread; // Redraw thread
|
2000-07-13 13:47:12 +00:00
|
|
|
#endif
|
1999-10-03 14:16:26 +00:00
|
|
|
|
|
|
|
static bool has_dga = false; // Flag: Video DGA capable
|
1999-11-03 21:04:23 +00:00
|
|
|
static bool has_vidmode = false; // Flag: VidMode extension available
|
1999-10-03 14:16:26 +00:00
|
|
|
|
2001-06-30 17:21:56 +00:00
|
|
|
#ifdef ENABLE_VOSF
|
|
|
|
static bool use_vosf = true; // Flag: VOSF enabled
|
|
|
|
#else
|
|
|
|
static const bool use_vosf = false; // VOSF not possible
|
|
|
|
#endif
|
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
static bool ctrl_down = false; // Flag: Ctrl key pressed
|
1999-10-03 19:43:28 +00:00
|
|
|
static bool caps_on = false; // Flag: Caps Lock on
|
1999-10-03 14:16:26 +00:00
|
|
|
static bool quit_full_screen = false; // Flag: DGA close requested from redraw thread
|
|
|
|
static bool emerg_quit = false; // Flag: Ctrl-Esc pressed, emergency quit requested from MacOS thread
|
|
|
|
static bool emul_suspended = false; // Flag: Emulator suspended
|
|
|
|
|
|
|
|
static bool classic_mode = false; // Flag: Classic Mac video mode
|
|
|
|
|
|
|
|
static bool use_keycodes = false; // Flag: Use keycodes rather than keysyms
|
|
|
|
static int keycode_table[256]; // X keycode -> Mac keycode translation table
|
|
|
|
|
|
|
|
// X11 variables
|
|
|
|
static int screen; // Screen number
|
2001-06-30 17:21:56 +00:00
|
|
|
static Window rootwin; // Root window and our window
|
2001-07-06 20:49:53 +00:00
|
|
|
static int num_depths = 0; // Number of available X depths
|
|
|
|
static int *avail_depths = NULL; // List of available X depths
|
1999-10-03 14:16:26 +00:00
|
|
|
static XColor black, white;
|
|
|
|
static unsigned long black_pixel, white_pixel;
|
|
|
|
static int eventmask;
|
|
|
|
|
2001-07-06 20:49:53 +00:00
|
|
|
static int xdepth; // Depth of X screen
|
|
|
|
static XVisualInfo visualInfo;
|
|
|
|
static Visual *vis;
|
|
|
|
static int color_class;
|
|
|
|
|
2001-07-01 14:38:03 +00:00
|
|
|
static int rshift, rloss, gshift, gloss, bshift, bloss; // Pixel format of DirectColor/TrueColor modes
|
|
|
|
|
2001-07-06 20:49:53 +00:00
|
|
|
static Colormap cmap[2] = {0, 0}; // Colormaps for indexed modes (DGA needs two of them)
|
|
|
|
|
2002-04-25 11:00:31 +00:00
|
|
|
static XColor x_palette[256]; // Color palette to be used as CLUT and gamma table
|
|
|
|
static bool x_palette_changed = false; // Flag: Palette changed, redraw thread must set new colors
|
2001-06-30 17:21:56 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_FBDEV_DGA
|
|
|
|
static int fbdev_fd = -1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENABLE_XF86_VIDMODE
|
|
|
|
static XF86VidModeModeInfo **x_video_modes = NULL; // Array of all available modes
|
|
|
|
static int num_x_video_modes;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Mutex to protect palette
|
2000-07-13 13:47:12 +00:00
|
|
|
#ifdef HAVE_PTHREADS
|
2002-04-25 11:00:31 +00:00
|
|
|
static pthread_mutex_t x_palette_lock = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
#define LOCK_PALETTE pthread_mutex_lock(&x_palette_lock)
|
|
|
|
#define UNLOCK_PALETTE pthread_mutex_unlock(&x_palette_lock)
|
2000-11-03 18:21:43 +00:00
|
|
|
#else
|
|
|
|
#define LOCK_PALETTE
|
|
|
|
#define UNLOCK_PALETTE
|
2000-07-13 13:47:12 +00:00
|
|
|
#endif
|
1999-10-03 14:16:26 +00:00
|
|
|
|
2001-06-30 17:21:56 +00:00
|
|
|
// Mutex to protect frame buffer
|
2000-07-13 13:47:12 +00:00
|
|
|
#ifdef HAVE_PTHREADS
|
2001-06-30 17:21:56 +00:00
|
|
|
static pthread_mutex_t frame_buffer_lock = PTHREAD_MUTEX_INITIALIZER;
|
2000-11-03 18:21:43 +00:00
|
|
|
#define LOCK_FRAME_BUFFER pthread_mutex_lock(&frame_buffer_lock);
|
|
|
|
#define UNLOCK_FRAME_BUFFER pthread_mutex_unlock(&frame_buffer_lock);
|
|
|
|
#else
|
|
|
|
#define LOCK_FRAME_BUFFER
|
|
|
|
#define UNLOCK_FRAME_BUFFER
|
2000-07-13 13:47:12 +00:00
|
|
|
#endif
|
1999-10-03 14:16:26 +00:00
|
|
|
|
2001-06-30 17:21:56 +00:00
|
|
|
// Variables for non-VOSF incremental refresh
|
|
|
|
static const int sm_uptd[] = {4,1,6,3,0,5,2,7};
|
|
|
|
static int sm_no_boxes[] = {1,8,32,64,128,300};
|
|
|
|
static bool updt_box[17][17];
|
|
|
|
static int nr_boxes;
|
2000-09-22 17:16:31 +00:00
|
|
|
|
2001-06-30 17:21:56 +00:00
|
|
|
// Video refresh function
|
2001-06-28 21:20:02 +00:00
|
|
|
static void VideoRefreshInit(void);
|
2000-09-22 17:16:31 +00:00
|
|
|
static void (*video_refresh)(void);
|
1999-10-03 14:16:26 +00:00
|
|
|
|
2001-06-30 17:21:56 +00:00
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
// Prototypes
|
|
|
|
static void *redraw_func(void *arg);
|
|
|
|
|
|
|
|
// From main_unix.cpp
|
2000-07-13 16:12:33 +00:00
|
|
|
extern char *x_display_name;
|
1999-10-03 14:16:26 +00:00
|
|
|
extern Display *x_display;
|
|
|
|
|
|
|
|
// From sys_unix.cpp
|
|
|
|
extern void SysMountFirstFloppy(void);
|
|
|
|
|
2001-06-28 21:20:02 +00:00
|
|
|
|
2002-04-25 11:00:31 +00:00
|
|
|
/*
|
|
|
|
* monitor_desc subclass for X11 display
|
|
|
|
*/
|
|
|
|
|
|
|
|
class X11_monitor_desc : public monitor_desc {
|
|
|
|
public:
|
|
|
|
X11_monitor_desc(const vector<video_mode> &available_modes, video_depth default_depth, uint32 default_id) : monitor_desc(available_modes, default_depth, default_id) {}
|
|
|
|
~X11_monitor_desc() {}
|
|
|
|
|
|
|
|
virtual void switch_to_current_mode(void);
|
|
|
|
virtual void set_palette(uint8 *pal, int num);
|
|
|
|
|
|
|
|
bool video_open(void);
|
|
|
|
void video_close(void);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
/*
|
2001-06-30 17:21:56 +00:00
|
|
|
* Utility functions
|
1999-10-03 14:16:26 +00:00
|
|
|
*/
|
|
|
|
|
2001-07-01 19:57:55 +00:00
|
|
|
// Map RGB color to pixel value (this only works in TrueColor/DirectColor visuals)
|
|
|
|
static inline uint32 map_rgb(uint8 red, uint8 green, uint8 blue)
|
|
|
|
{
|
|
|
|
return ((red >> rloss) << rshift) | ((green >> gloss) << gshift) | ((blue >> bloss) << bshift);
|
|
|
|
}
|
|
|
|
|
2001-07-06 20:49:53 +00:00
|
|
|
// Do we have a visual for handling the specified Mac depth? If so, set the
|
|
|
|
// global variables "xdepth", "visualInfo", "vis" and "color_class".
|
|
|
|
static bool find_visual_for_depth(video_depth depth)
|
|
|
|
{
|
|
|
|
D(bug("have_visual_for_depth(%d)\n", 1 << depth));
|
|
|
|
|
2001-07-14 15:02:49 +00:00
|
|
|
// 1-bit works always and uses default visual
|
|
|
|
if (depth == VDEPTH_1BIT) {
|
|
|
|
vis = DefaultVisual(x_display, screen);
|
|
|
|
visualInfo.visualid = XVisualIDFromVisual(vis);
|
|
|
|
int num = 0;
|
|
|
|
XVisualInfo *vi = XGetVisualInfo(x_display, VisualIDMask, &visualInfo, &num);
|
|
|
|
visualInfo = vi[0];
|
|
|
|
XFree(vi);
|
|
|
|
xdepth = visualInfo.depth;
|
|
|
|
color_class = visualInfo.c_class;
|
|
|
|
D(bug(" found visual ID 0x%02x, depth %d\n", visualInfo.visualid, xdepth));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2001-07-06 20:49:53 +00:00
|
|
|
// Calculate minimum and maximum supported X depth
|
|
|
|
int min_depth = 1, max_depth = 32;
|
|
|
|
switch (depth) {
|
|
|
|
#ifdef ENABLE_VOSF
|
|
|
|
case VDEPTH_2BIT:
|
2001-07-06 22:00:39 +00:00
|
|
|
case VDEPTH_4BIT: // VOSF blitters can convert 2/4/8-bit -> 8/16/32-bit
|
|
|
|
case VDEPTH_8BIT:
|
2001-07-06 20:49:53 +00:00
|
|
|
min_depth = 8;
|
|
|
|
max_depth = 32;
|
|
|
|
break;
|
|
|
|
#else
|
|
|
|
case VDEPTH_2BIT:
|
|
|
|
case VDEPTH_4BIT: // 2/4-bit requires VOSF blitters
|
|
|
|
return false;
|
|
|
|
case VDEPTH_8BIT: // 8-bit without VOSF requires an 8-bit visual
|
|
|
|
min_depth = 8;
|
|
|
|
max_depth = 8;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case VDEPTH_16BIT: // 16-bit requires a 15/16-bit visual
|
|
|
|
min_depth = 15;
|
|
|
|
max_depth = 16;
|
|
|
|
break;
|
|
|
|
case VDEPTH_32BIT: // 32-bit requires a 24/32-bit visual
|
|
|
|
min_depth = 24;
|
|
|
|
max_depth = 32;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
D(bug(" minimum required X depth is %d, maximum supported X depth is %d\n", min_depth, max_depth));
|
|
|
|
|
|
|
|
// Try to find a visual for one of the color depths
|
|
|
|
bool visual_found = false;
|
|
|
|
for (int i=0; i<num_depths && !visual_found; i++) {
|
|
|
|
|
|
|
|
xdepth = avail_depths[i];
|
|
|
|
D(bug(" trying to find visual for depth %d\n", xdepth));
|
|
|
|
if (xdepth < min_depth || xdepth > max_depth)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Determine best color class for this depth
|
|
|
|
switch (xdepth) {
|
|
|
|
case 1: // Try StaticGray or StaticColor
|
|
|
|
if (XMatchVisualInfo(x_display, screen, xdepth, StaticGray, &visualInfo)
|
|
|
|
|| XMatchVisualInfo(x_display, screen, xdepth, StaticColor, &visualInfo))
|
|
|
|
visual_found = true;
|
|
|
|
break;
|
|
|
|
case 8: // Need PseudoColor
|
|
|
|
if (XMatchVisualInfo(x_display, screen, xdepth, PseudoColor, &visualInfo))
|
|
|
|
visual_found = true;
|
|
|
|
break;
|
|
|
|
case 15:
|
|
|
|
case 16:
|
|
|
|
case 24:
|
|
|
|
case 32: // Try DirectColor first, as this will allow gamma correction
|
|
|
|
if (XMatchVisualInfo(x_display, screen, xdepth, DirectColor, &visualInfo)
|
|
|
|
|| XMatchVisualInfo(x_display, screen, xdepth, TrueColor, &visualInfo))
|
|
|
|
visual_found = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
D(bug(" not a supported depth\n"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!visual_found)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Visual was found
|
|
|
|
vis = visualInfo.visual;
|
|
|
|
color_class = visualInfo.c_class;
|
|
|
|
D(bug(" found visual ID 0x%02x, depth %d, class ", visualInfo.visualid, xdepth));
|
|
|
|
#if DEBUG
|
|
|
|
switch (color_class) {
|
|
|
|
case StaticGray: D(bug("StaticGray\n")); break;
|
|
|
|
case GrayScale: D(bug("GrayScale\n")); break;
|
|
|
|
case StaticColor: D(bug("StaticColor\n")); break;
|
|
|
|
case PseudoColor: D(bug("PseudoColor\n")); break;
|
|
|
|
case TrueColor: D(bug("TrueColor\n")); break;
|
|
|
|
case DirectColor: D(bug("DirectColor\n")); break;
|
|
|
|
}
|
|
|
|
#endif
|
2001-07-11 17:04:41 +00:00
|
|
|
return true;
|
2001-07-06 20:49:53 +00:00
|
|
|
}
|
|
|
|
|
2001-06-28 21:20:02 +00:00
|
|
|
// Add mode to list of supported modes
|
|
|
|
static void add_mode(uint32 width, uint32 height, uint32 resolution_id, uint32 bytes_per_row, video_depth depth)
|
1999-10-03 14:16:26 +00:00
|
|
|
{
|
2001-06-27 19:03:38 +00:00
|
|
|
video_mode mode;
|
2001-06-28 21:20:02 +00:00
|
|
|
mode.x = width;
|
|
|
|
mode.y = height;
|
|
|
|
mode.resolution_id = resolution_id;
|
|
|
|
mode.bytes_per_row = bytes_per_row;
|
|
|
|
mode.depth = depth;
|
|
|
|
VideoModes.push_back(mode);
|
|
|
|
}
|
|
|
|
|
2001-07-01 21:09:30 +00:00
|
|
|
// Add standard list of windowed modes for given color depth
|
|
|
|
static void add_window_modes(video_depth depth)
|
|
|
|
{
|
|
|
|
add_mode(512, 384, 0x80, TrivialBytesPerRow(512, depth), depth);
|
|
|
|
add_mode(640, 480, 0x81, TrivialBytesPerRow(640, depth), depth);
|
|
|
|
add_mode(800, 600, 0x82, TrivialBytesPerRow(800, depth), depth);
|
|
|
|
add_mode(1024, 768, 0x83, TrivialBytesPerRow(1024, depth), depth);
|
|
|
|
add_mode(1152, 870, 0x84, TrivialBytesPerRow(1152, depth), depth);
|
|
|
|
add_mode(1280, 1024, 0x85, TrivialBytesPerRow(1280, depth), depth);
|
|
|
|
add_mode(1600, 1200, 0x86, TrivialBytesPerRow(1600, depth), depth);
|
|
|
|
}
|
|
|
|
|
2001-06-28 21:20:02 +00:00
|
|
|
// Set Mac frame layout and base address (uses the_buffer/MacFrameBaseMac)
|
2002-04-25 11:00:31 +00:00
|
|
|
static void set_mac_frame_buffer(X11_monitor_desc &monitor, video_depth depth, bool native_byte_order)
|
2001-06-28 21:20:02 +00:00
|
|
|
{
|
2000-09-22 17:16:31 +00:00
|
|
|
#if !REAL_ADDRESSING && !DIRECT_ADDRESSING
|
1999-10-05 14:59:46 +00:00
|
|
|
int layout = FLAYOUT_DIRECT;
|
2001-06-28 21:20:02 +00:00
|
|
|
if (depth == VDEPTH_16BIT)
|
|
|
|
layout = (xdepth == 15) ? FLAYOUT_HOST_555 : FLAYOUT_HOST_565;
|
|
|
|
else if (depth == VDEPTH_32BIT)
|
2001-07-01 14:38:03 +00:00
|
|
|
layout = (xdepth == 24) ? FLAYOUT_HOST_888 : FLAYOUT_DIRECT;
|
1999-10-03 14:16:26 +00:00
|
|
|
if (native_byte_order)
|
|
|
|
MacFrameLayout = layout;
|
|
|
|
else
|
|
|
|
MacFrameLayout = FLAYOUT_DIRECT;
|
2002-04-25 11:00:31 +00:00
|
|
|
monitor.set_mac_frame_base(MacFrameBaseMac);
|
2001-06-30 17:21:56 +00:00
|
|
|
|
|
|
|
// Set variables used by UAE memory banking
|
2002-04-25 11:00:31 +00:00
|
|
|
const video_mode &mode = monitor.get_current_mode();
|
2001-06-30 17:21:56 +00:00
|
|
|
MacFrameBaseHost = the_buffer;
|
2002-04-25 11:00:31 +00:00
|
|
|
MacFrameSize = mode.bytes_per_row * mode.y;
|
2001-06-30 17:21:56 +00:00
|
|
|
InitFrameBufferMapping();
|
2001-06-28 21:20:02 +00:00
|
|
|
#else
|
2002-04-25 11:00:31 +00:00
|
|
|
monitor.set_mac_frame_base(Host2MacAddr(the_buffer));
|
2000-07-13 13:47:12 +00:00
|
|
|
#endif
|
2002-04-25 11:00:31 +00:00
|
|
|
D(bug("monitor.mac_frame_base = %08x\n", monitor.get_mac_frame_base()));
|
1999-10-03 14:16:26 +00:00
|
|
|
}
|
|
|
|
|
2000-11-03 18:21:43 +00:00
|
|
|
// Set window name and class
|
|
|
|
static void set_window_name(Window w, int name)
|
|
|
|
{
|
|
|
|
const char *str = GetString(name);
|
|
|
|
XStoreName(x_display, w, str);
|
|
|
|
XSetIconName(x_display, w, str);
|
|
|
|
|
|
|
|
XClassHint *hints;
|
|
|
|
hints = XAllocClassHint();
|
|
|
|
if (hints) {
|
|
|
|
hints->res_name = "BasiliskII";
|
|
|
|
hints->res_class = "BasiliskII";
|
|
|
|
XSetClassHint(x_display, w, hints);
|
2001-01-06 22:15:35 +00:00
|
|
|
XFree(hints);
|
2000-11-03 18:21:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set window input focus flag
|
|
|
|
static void set_window_focus(Window w)
|
|
|
|
{
|
|
|
|
XWMHints *hints = XAllocWMHints();
|
|
|
|
if (hints) {
|
|
|
|
hints->input = True;
|
|
|
|
hints->initial_state = NormalState;
|
|
|
|
hints->flags = InputHint | StateHint;
|
|
|
|
XSetWMHints(x_display, w, hints);
|
2001-01-06 22:15:35 +00:00
|
|
|
XFree(hints);
|
2000-11-03 18:21:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set WM_DELETE_WINDOW protocol on window (preventing it from being destroyed by the WM when clicking on the "close" widget)
|
2001-06-30 17:21:56 +00:00
|
|
|
static Atom WM_DELETE_WINDOW = (Atom)0;
|
2000-11-03 18:21:43 +00:00
|
|
|
static void set_window_delete_protocol(Window w)
|
|
|
|
{
|
|
|
|
WM_DELETE_WINDOW = XInternAtom(x_display, "WM_DELETE_WINDOW", false);
|
|
|
|
XSetWMProtocols(x_display, w, &WM_DELETE_WINDOW, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait until window is mapped/unmapped
|
|
|
|
void wait_mapped(Window w)
|
|
|
|
{
|
|
|
|
XEvent e;
|
|
|
|
do {
|
|
|
|
XMaskEvent(x_display, StructureNotifyMask, &e);
|
|
|
|
} while ((e.type != MapNotify) || (e.xmap.event != w));
|
|
|
|
}
|
|
|
|
|
|
|
|
void wait_unmapped(Window w)
|
|
|
|
{
|
|
|
|
XEvent e;
|
|
|
|
do {
|
|
|
|
XMaskEvent(x_display, StructureNotifyMask, &e);
|
|
|
|
} while ((e.type != UnmapNotify) || (e.xmap.event != w));
|
|
|
|
}
|
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
// Trap SHM errors
|
|
|
|
static bool shm_error = false;
|
|
|
|
static int (*old_error_handler)(Display *, XErrorEvent *);
|
|
|
|
|
|
|
|
static int error_handler(Display *d, XErrorEvent *e)
|
|
|
|
{
|
|
|
|
if (e->error_code == BadAccess) {
|
|
|
|
shm_error = true;
|
|
|
|
return 0;
|
|
|
|
} else
|
|
|
|
return old_error_handler(d, e);
|
|
|
|
}
|
|
|
|
|
2001-06-30 17:21:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Display "driver" classes
|
|
|
|
*/
|
|
|
|
|
|
|
|
class driver_base {
|
|
|
|
public:
|
2002-04-25 11:00:31 +00:00
|
|
|
driver_base(X11_monitor_desc &m);
|
2001-06-30 17:21:56 +00:00
|
|
|
virtual ~driver_base();
|
|
|
|
|
|
|
|
virtual void update_palette(void);
|
|
|
|
virtual void suspend(void) {}
|
|
|
|
virtual void resume(void) {}
|
2001-07-03 15:59:49 +00:00
|
|
|
virtual void toggle_mouse_grab(void) {}
|
|
|
|
virtual void mouse_moved(int x, int y) { ADBMouseMoved(x, y); }
|
|
|
|
|
2001-07-09 11:22:01 +00:00
|
|
|
void disable_mouse_accel(void);
|
|
|
|
void restore_mouse_accel(void);
|
|
|
|
|
2001-07-03 15:59:49 +00:00
|
|
|
virtual void grab_mouse(void) {}
|
|
|
|
virtual void ungrab_mouse(void) {}
|
2001-06-30 17:21:56 +00:00
|
|
|
|
|
|
|
public:
|
2002-04-25 11:00:31 +00:00
|
|
|
X11_monitor_desc &monitor; // Associated video monitor
|
|
|
|
const video_mode &mode; // Video mode handled by the driver
|
|
|
|
|
2001-06-30 17:21:56 +00:00
|
|
|
bool init_ok; // Initialization succeeded (we can't use exceptions because of -fomit-frame-pointer)
|
|
|
|
Window w; // The window we draw into
|
2001-07-09 11:22:01 +00:00
|
|
|
|
|
|
|
int orig_accel_numer, orig_accel_denom, orig_threshold; // Original mouse acceleration
|
2001-06-30 17:21:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class driver_window;
|
|
|
|
static void update_display_window_vosf(driver_window *drv);
|
|
|
|
static void update_display_dynamic(int ticker, driver_window *drv);
|
|
|
|
static void update_display_static(driver_window *drv);
|
|
|
|
|
|
|
|
class driver_window : public driver_base {
|
|
|
|
friend void update_display_window_vosf(driver_window *drv);
|
|
|
|
friend void update_display_dynamic(int ticker, driver_window *drv);
|
|
|
|
friend void update_display_static(driver_window *drv);
|
|
|
|
|
|
|
|
public:
|
2002-04-25 11:00:31 +00:00
|
|
|
driver_window(X11_monitor_desc &monitor);
|
2001-06-30 17:21:56 +00:00
|
|
|
~driver_window();
|
|
|
|
|
2001-07-03 15:59:49 +00:00
|
|
|
void toggle_mouse_grab(void);
|
|
|
|
void mouse_moved(int x, int y);
|
|
|
|
|
|
|
|
void grab_mouse(void);
|
|
|
|
void ungrab_mouse(void);
|
|
|
|
|
2001-06-30 17:21:56 +00:00
|
|
|
private:
|
|
|
|
GC gc;
|
|
|
|
XImage *img;
|
2001-07-03 15:59:49 +00:00
|
|
|
bool have_shm; // Flag: SHM extensions available
|
2001-06-30 17:21:56 +00:00
|
|
|
XShmSegmentInfo shminfo;
|
|
|
|
Cursor mac_cursor;
|
2001-07-03 15:59:49 +00:00
|
|
|
bool mouse_grabbed; // Flag: mouse pointer grabbed, using relative mouse mode
|
|
|
|
int mouse_last_x, mouse_last_y; // Last mouse position (for relative mode)
|
2001-06-30 17:21:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static driver_base *drv = NULL; // Pointer to currently used driver object
|
|
|
|
|
|
|
|
#ifdef ENABLE_VOSF
|
|
|
|
# include "video_vosf.h"
|
|
|
|
#endif
|
|
|
|
|
2002-04-25 11:00:31 +00:00
|
|
|
driver_base::driver_base(X11_monitor_desc &m)
|
|
|
|
: monitor(m), mode(m.get_current_mode()), init_ok(false), w(0)
|
2001-06-30 17:21:56 +00:00
|
|
|
{
|
|
|
|
the_buffer = NULL;
|
|
|
|
the_buffer_copy = NULL;
|
2001-07-09 11:22:01 +00:00
|
|
|
XGetPointerControl(x_display, &orig_accel_numer, &orig_accel_denom, &orig_threshold);
|
2001-06-30 17:21:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
driver_base::~driver_base()
|
|
|
|
{
|
2001-07-03 15:59:49 +00:00
|
|
|
ungrab_mouse();
|
2001-07-09 11:22:01 +00:00
|
|
|
restore_mouse_accel();
|
2001-07-03 15:59:49 +00:00
|
|
|
|
2001-06-30 17:21:56 +00:00
|
|
|
if (w) {
|
|
|
|
XUnmapWindow(x_display, w);
|
|
|
|
wait_unmapped(w);
|
|
|
|
XDestroyWindow(x_display, w);
|
|
|
|
}
|
|
|
|
|
2001-06-30 20:18:36 +00:00
|
|
|
XFlush(x_display);
|
|
|
|
XSync(x_display, false);
|
|
|
|
|
2001-06-30 17:21:56 +00:00
|
|
|
// Free frame buffer(s)
|
|
|
|
if (!use_vosf) {
|
|
|
|
if (the_buffer) {
|
|
|
|
free(the_buffer);
|
|
|
|
the_buffer = NULL;
|
|
|
|
}
|
|
|
|
if (the_buffer_copy) {
|
|
|
|
free(the_buffer_copy);
|
|
|
|
the_buffer_copy = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef ENABLE_VOSF
|
|
|
|
else {
|
2001-07-14 18:41:05 +00:00
|
|
|
// the_buffer shall always be mapped through vm_acquire() so that we can vm_protect() it at will
|
|
|
|
if (the_buffer != VM_MAP_FAILED) {
|
|
|
|
D(bug(" releasing the_buffer at %p (%d bytes)\n", the_buffer, the_buffer_size));
|
|
|
|
vm_release(the_buffer, the_buffer_size);
|
|
|
|
the_buffer = NULL;
|
|
|
|
}
|
2001-07-06 22:37:23 +00:00
|
|
|
if (the_host_buffer) {
|
2001-07-14 15:02:49 +00:00
|
|
|
D(bug(" freeing the_host_buffer at %p\n", the_host_buffer));
|
2001-07-06 22:37:23 +00:00
|
|
|
free(the_host_buffer);
|
|
|
|
the_host_buffer = NULL;
|
|
|
|
}
|
2001-07-07 09:14:47 +00:00
|
|
|
if (the_buffer_copy) {
|
2001-07-14 15:02:49 +00:00
|
|
|
D(bug(" freeing the_buffer_copy at %p\n", the_buffer_copy));
|
2001-07-07 09:14:47 +00:00
|
|
|
free(the_buffer_copy);
|
2001-06-30 17:21:56 +00:00
|
|
|
the_buffer_copy = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// Palette has changed
|
|
|
|
void driver_base::update_palette(void)
|
|
|
|
{
|
2001-07-10 15:50:57 +00:00
|
|
|
if (color_class == PseudoColor || color_class == DirectColor) {
|
2001-07-06 22:00:39 +00:00
|
|
|
int num = vis->map_entries;
|
2002-04-25 11:00:31 +00:00
|
|
|
if (!IsDirectMode(monitor.get_current_mode()) && color_class == DirectColor)
|
2001-07-01 00:46:38 +00:00
|
|
|
return; // Indexed mode on true color screen, don't set CLUT
|
2002-04-25 11:00:31 +00:00
|
|
|
XStoreColors(x_display, cmap[0], x_palette, num);
|
|
|
|
XStoreColors(x_display, cmap[1], x_palette, num);
|
2001-06-30 17:21:56 +00:00
|
|
|
}
|
|
|
|
XSync(x_display, false);
|
|
|
|
}
|
|
|
|
|
2001-07-09 11:22:01 +00:00
|
|
|
// Disable mouse acceleration
|
|
|
|
void driver_base::disable_mouse_accel(void)
|
|
|
|
{
|
|
|
|
XChangePointerControl(x_display, True, False, 1, 1, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restore mouse acceleration to original value
|
|
|
|
void driver_base::restore_mouse_accel(void)
|
|
|
|
{
|
|
|
|
XChangePointerControl(x_display, True, True, orig_accel_numer, orig_accel_denom, orig_threshold);
|
|
|
|
}
|
|
|
|
|
2001-06-30 17:21:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Windowed display driver
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Open display
|
2002-04-25 11:00:31 +00:00
|
|
|
driver_window::driver_window(X11_monitor_desc &m)
|
|
|
|
: driver_base(m), gc(0), img(NULL), have_shm(false), mac_cursor(0), mouse_grabbed(false)
|
1999-10-03 14:16:26 +00:00
|
|
|
{
|
2001-06-28 21:20:02 +00:00
|
|
|
int width = mode.x, height = mode.y;
|
2000-02-11 17:20:44 +00:00
|
|
|
int aligned_width = (width + 15) & ~15;
|
|
|
|
int aligned_height = (height + 15) & ~15;
|
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
// Set absolute mouse mode
|
2001-07-03 15:59:49 +00:00
|
|
|
ADBSetRelMouseMode(mouse_grabbed);
|
1999-10-03 14:16:26 +00:00
|
|
|
|
2001-07-14 18:41:05 +00:00
|
|
|
// Create window (setting background_pixel, border_pixel and colormap is
|
2001-07-10 15:50:57 +00:00
|
|
|
// mandatory when using a non-default visual; in 1-bit mode we use the
|
|
|
|
// default visual, so we can also use the default colormap)
|
1999-10-03 14:16:26 +00:00
|
|
|
XSetWindowAttributes wattr;
|
|
|
|
wattr.event_mask = eventmask = win_eventmask;
|
2001-07-10 15:50:57 +00:00
|
|
|
wattr.background_pixel = (vis == DefaultVisual(x_display, screen) ? black_pixel : 0);
|
|
|
|
wattr.border_pixel = 0;
|
|
|
|
wattr.colormap = (mode.depth == VDEPTH_1BIT ? DefaultColormap(x_display, screen) : cmap[0]);
|
2001-06-30 17:21:56 +00:00
|
|
|
w = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth,
|
2001-07-10 15:50:57 +00:00
|
|
|
InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel | CWColormap, &wattr);
|
2001-07-14 15:02:49 +00:00
|
|
|
D(bug(" window created\n"));
|
2000-11-03 18:21:43 +00:00
|
|
|
|
|
|
|
// Set window name/class
|
2001-06-30 17:21:56 +00:00
|
|
|
set_window_name(w, STR_WINDOW_TITLE);
|
1999-10-03 14:16:26 +00:00
|
|
|
|
2000-10-27 17:01:40 +00:00
|
|
|
// Indicate that we want keyboard input
|
2001-06-30 17:21:56 +00:00
|
|
|
set_window_focus(w);
|
2000-11-03 18:21:43 +00:00
|
|
|
|
|
|
|
// Set delete protocol property
|
2001-06-30 17:21:56 +00:00
|
|
|
set_window_delete_protocol(w);
|
1999-10-03 14:16:26 +00:00
|
|
|
|
|
|
|
// Make window unresizable
|
2000-10-27 17:01:40 +00:00
|
|
|
{
|
|
|
|
XSizeHints *hints = XAllocSizeHints();
|
|
|
|
if (hints) {
|
|
|
|
hints->min_width = width;
|
|
|
|
hints->max_width = width;
|
|
|
|
hints->min_height = height;
|
|
|
|
hints->max_height = height;
|
|
|
|
hints->flags = PMinSize | PMaxSize;
|
2001-06-30 17:21:56 +00:00
|
|
|
XSetWMNormalHints(x_display, w, hints);
|
2001-01-06 22:15:35 +00:00
|
|
|
XFree(hints);
|
2000-10-27 17:01:40 +00:00
|
|
|
}
|
1999-10-03 14:16:26 +00:00
|
|
|
}
|
2001-07-14 15:02:49 +00:00
|
|
|
D(bug(" window attributes set\n"));
|
1999-10-21 13:19:27 +00:00
|
|
|
|
2000-10-27 17:01:40 +00:00
|
|
|
// Show window
|
2001-06-30 17:21:56 +00:00
|
|
|
XMapWindow(x_display, w);
|
|
|
|
wait_mapped(w);
|
2001-07-14 15:02:49 +00:00
|
|
|
D(bug(" window mapped\n"));
|
2000-10-27 17:01:40 +00:00
|
|
|
|
2001-07-01 14:38:03 +00:00
|
|
|
// 1-bit mode is big-endian; if the X server is little-endian, we can't
|
|
|
|
// use SHM because that doesn't allow changing the image byte order
|
|
|
|
bool need_msb_image = (mode.depth == VDEPTH_1BIT && XImageByteOrder(x_display) == LSBFirst);
|
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
// Try to create and attach SHM image
|
2001-07-01 14:38:03 +00:00
|
|
|
if (local_X11 && !need_msb_image && XShmQueryExtension(x_display)) {
|
1999-10-03 14:16:26 +00:00
|
|
|
|
|
|
|
// Create SHM image ("height + 2" for safety)
|
2001-06-28 21:20:02 +00:00
|
|
|
img = XShmCreateImage(x_display, vis, mode.depth == VDEPTH_1BIT ? 1 : xdepth, mode.depth == VDEPTH_1BIT ? XYBitmap : ZPixmap, 0, &shminfo, width, height);
|
2001-07-14 15:02:49 +00:00
|
|
|
D(bug(" shm image created\n"));
|
2000-02-11 17:20:44 +00:00
|
|
|
shminfo.shmid = shmget(IPC_PRIVATE, (aligned_height + 2) * img->bytes_per_line, IPC_CREAT | 0777);
|
|
|
|
the_buffer_copy = (uint8 *)shmat(shminfo.shmid, 0, 0);
|
|
|
|
shminfo.shmaddr = img->data = (char *)the_buffer_copy;
|
1999-10-03 14:16:26 +00:00
|
|
|
shminfo.readOnly = False;
|
|
|
|
|
|
|
|
// Try to attach SHM image, catching errors
|
|
|
|
shm_error = false;
|
|
|
|
old_error_handler = XSetErrorHandler(error_handler);
|
|
|
|
XShmAttach(x_display, &shminfo);
|
|
|
|
XSync(x_display, false);
|
|
|
|
XSetErrorHandler(old_error_handler);
|
|
|
|
if (shm_error) {
|
|
|
|
shmdt(shminfo.shmaddr);
|
|
|
|
XDestroyImage(img);
|
2001-07-06 22:37:23 +00:00
|
|
|
img = NULL;
|
1999-10-03 14:16:26 +00:00
|
|
|
shminfo.shmid = -1;
|
|
|
|
} else {
|
|
|
|
have_shm = true;
|
|
|
|
shmctl(shminfo.shmid, IPC_RMID, 0);
|
|
|
|
}
|
2001-07-14 15:02:49 +00:00
|
|
|
D(bug(" shm image attached\n"));
|
1999-10-03 14:16:26 +00:00
|
|
|
}
|
1999-10-21 13:19:27 +00:00
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
// Create normal X image if SHM doesn't work ("height + 2" for safety)
|
|
|
|
if (!have_shm) {
|
2001-07-01 19:57:55 +00:00
|
|
|
int bytes_per_row = (mode.depth == VDEPTH_1BIT ? aligned_width/8 : TrivialBytesPerRow(aligned_width, DepthModeForPixelDepth(xdepth)));
|
2000-02-11 17:20:44 +00:00
|
|
|
the_buffer_copy = (uint8 *)malloc((aligned_height + 2) * bytes_per_row);
|
2001-06-28 21:20:02 +00:00
|
|
|
img = XCreateImage(x_display, vis, mode.depth == VDEPTH_1BIT ? 1 : xdepth, mode.depth == VDEPTH_1BIT ? XYBitmap : ZPixmap, 0, (char *)the_buffer_copy, aligned_width, aligned_height, 32, bytes_per_row);
|
2001-07-14 15:02:49 +00:00
|
|
|
D(bug(" X image created\n"));
|
1999-10-03 14:16:26 +00:00
|
|
|
}
|
|
|
|
|
2001-07-01 14:38:03 +00:00
|
|
|
if (need_msb_image) {
|
1999-10-03 14:16:26 +00:00
|
|
|
img->byte_order = MSBFirst;
|
|
|
|
img->bitmap_bit_order = MSBFirst;
|
|
|
|
}
|
|
|
|
|
2000-09-22 17:16:31 +00:00
|
|
|
#ifdef ENABLE_VOSF
|
2001-07-07 09:14:47 +00:00
|
|
|
use_vosf = true;
|
2001-06-26 22:35:42 +00:00
|
|
|
// Allocate memory for frame buffer (SIZE is extended to page-boundary)
|
2000-09-22 17:16:31 +00:00
|
|
|
the_host_buffer = the_buffer_copy;
|
2001-06-26 22:35:42 +00:00
|
|
|
the_buffer_size = page_extend((aligned_height + 2) * img->bytes_per_line);
|
|
|
|
the_buffer = (uint8 *)vm_acquire(the_buffer_size);
|
2001-07-14 18:41:05 +00:00
|
|
|
the_buffer_copy = (uint8 *)malloc(the_buffer_size);
|
2001-07-06 22:37:23 +00:00
|
|
|
D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer));
|
2000-09-22 17:16:31 +00:00
|
|
|
#else
|
2000-07-13 16:12:33 +00:00
|
|
|
// Allocate memory for frame buffer
|
2000-02-11 17:20:44 +00:00
|
|
|
the_buffer = (uint8 *)malloc((aligned_height + 2) * img->bytes_per_line);
|
2001-07-06 22:37:23 +00:00
|
|
|
D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy));
|
2000-09-22 17:16:31 +00:00
|
|
|
#endif
|
1999-10-03 14:16:26 +00:00
|
|
|
|
|
|
|
// Create GC
|
2001-06-30 17:21:56 +00:00
|
|
|
gc = XCreateGC(x_display, w, 0, 0);
|
|
|
|
XSetState(x_display, gc, black_pixel, white_pixel, GXcopy, AllPlanes);
|
1999-10-03 14:16:26 +00:00
|
|
|
|
2000-02-11 17:20:44 +00:00
|
|
|
// Create no_cursor
|
2000-07-13 16:12:33 +00:00
|
|
|
mac_cursor = XCreatePixmapCursor(x_display,
|
2001-06-30 17:21:56 +00:00
|
|
|
XCreatePixmap(x_display, w, 1, 1, 1),
|
|
|
|
XCreatePixmap(x_display, w, 1, 1, 1),
|
2000-07-13 16:12:33 +00:00
|
|
|
&black, &white, 0, 0);
|
2001-06-30 17:21:56 +00:00
|
|
|
XDefineCursor(x_display, w, mac_cursor);
|
1999-10-03 14:16:26 +00:00
|
|
|
|
2001-06-30 17:21:56 +00:00
|
|
|
// Init blitting routines
|
2000-09-22 17:16:31 +00:00
|
|
|
bool native_byte_order;
|
1999-10-03 14:16:26 +00:00
|
|
|
#ifdef WORDS_BIGENDIAN
|
2000-11-30 16:09:03 +00:00
|
|
|
native_byte_order = (XImageByteOrder(x_display) == MSBFirst);
|
1999-10-03 14:16:26 +00:00
|
|
|
#else
|
2000-11-30 16:09:03 +00:00
|
|
|
native_byte_order = (XImageByteOrder(x_display) == LSBFirst);
|
1999-10-03 14:16:26 +00:00
|
|
|
#endif
|
2000-09-22 17:16:31 +00:00
|
|
|
#ifdef ENABLE_VOSF
|
2001-07-01 14:38:03 +00:00
|
|
|
Screen_blitter_init(&visualInfo, native_byte_order, mode.depth);
|
2000-09-22 17:16:31 +00:00
|
|
|
#endif
|
2001-06-30 17:21:56 +00:00
|
|
|
|
2002-04-25 11:00:31 +00:00
|
|
|
// Set frame buffer base
|
|
|
|
set_mac_frame_buffer(monitor, mode.depth, native_byte_order);
|
2001-06-30 17:21:56 +00:00
|
|
|
|
|
|
|
// Everything went well
|
|
|
|
init_ok = true;
|
1999-10-21 13:19:27 +00:00
|
|
|
}
|
|
|
|
|
2001-06-30 17:21:56 +00:00
|
|
|
// Close display
|
|
|
|
driver_window::~driver_window()
|
1999-10-21 13:19:27 +00:00
|
|
|
{
|
2001-06-30 17:21:56 +00:00
|
|
|
if (have_shm) {
|
|
|
|
XShmDetach(x_display, &shminfo);
|
2001-07-06 22:37:23 +00:00
|
|
|
#ifdef ENABLE_VOSF
|
|
|
|
the_host_buffer = NULL; // don't free() in driver_base dtor
|
|
|
|
#else
|
2001-06-30 17:21:56 +00:00
|
|
|
the_buffer_copy = NULL; // don't free() in driver_base dtor
|
2001-07-06 22:37:23 +00:00
|
|
|
#endif
|
|
|
|
}
|
2001-07-14 15:02:49 +00:00
|
|
|
if (img) {
|
|
|
|
if (!have_shm)
|
|
|
|
img->data = NULL;
|
2001-07-06 22:37:23 +00:00
|
|
|
XDestroyImage(img);
|
2001-07-14 15:02:49 +00:00
|
|
|
}
|
2001-07-06 22:37:23 +00:00
|
|
|
if (have_shm) {
|
|
|
|
shmdt(shminfo.shmaddr);
|
|
|
|
shmctl(shminfo.shmid, IPC_RMID, 0);
|
2001-06-30 17:21:56 +00:00
|
|
|
}
|
|
|
|
if (gc)
|
|
|
|
XFreeGC(x_display, gc);
|
|
|
|
}
|
|
|
|
|
2001-07-03 15:59:49 +00:00
|
|
|
// Toggle mouse grab
|
|
|
|
void driver_window::toggle_mouse_grab(void)
|
|
|
|
{
|
|
|
|
if (mouse_grabbed)
|
|
|
|
ungrab_mouse();
|
|
|
|
else
|
|
|
|
grab_mouse();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Grab mouse, switch to relative mouse mode
|
|
|
|
void driver_window::grab_mouse(void)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
for (int i=0; i<10; i++) {
|
|
|
|
result = XGrabPointer(x_display, w, True, 0,
|
|
|
|
GrabModeAsync, GrabModeAsync, w, None, CurrentTime);
|
|
|
|
if (result != AlreadyGrabbed)
|
|
|
|
break;
|
|
|
|
Delay_usec(100000);
|
|
|
|
}
|
|
|
|
if (result == GrabSuccess) {
|
|
|
|
XStoreName(x_display, w, GetString(STR_WINDOW_TITLE_GRABBED));
|
2001-07-09 11:22:01 +00:00
|
|
|
ADBSetRelMouseMode(mouse_grabbed = true);
|
|
|
|
disable_mouse_accel();
|
2001-07-03 15:59:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ungrab mouse, switch to absolute mouse mode
|
|
|
|
void driver_window::ungrab_mouse(void)
|
|
|
|
{
|
|
|
|
if (mouse_grabbed) {
|
|
|
|
XUngrabPointer(x_display, CurrentTime);
|
|
|
|
XStoreName(x_display, w, GetString(STR_WINDOW_TITLE));
|
|
|
|
ADBSetRelMouseMode(mouse_grabbed = false);
|
2001-07-09 11:22:01 +00:00
|
|
|
restore_mouse_accel();
|
2001-07-03 15:59:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mouse moved
|
|
|
|
void driver_window::mouse_moved(int x, int y)
|
|
|
|
{
|
|
|
|
if (!mouse_grabbed) {
|
|
|
|
mouse_last_x = x; mouse_last_y = y;
|
|
|
|
ADBMouseMoved(x, y);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Warped mouse motion (this code is taken from SDL)
|
|
|
|
|
|
|
|
// Post first mouse event
|
2002-04-25 11:00:31 +00:00
|
|
|
int width = monitor.get_current_mode().x, height = monitor.get_current_mode().y;
|
2001-07-03 15:59:49 +00:00
|
|
|
int delta_x = x - mouse_last_x, delta_y = y - mouse_last_y;
|
|
|
|
mouse_last_x = x; mouse_last_y = y;
|
|
|
|
ADBMouseMoved(delta_x, delta_y);
|
|
|
|
|
|
|
|
// Only warp the pointer when it has reached the edge
|
|
|
|
const int MOUSE_FUDGE_FACTOR = 8;
|
|
|
|
if (x < MOUSE_FUDGE_FACTOR || x > (width - MOUSE_FUDGE_FACTOR)
|
|
|
|
|| y < MOUSE_FUDGE_FACTOR || y > (height - MOUSE_FUDGE_FACTOR)) {
|
|
|
|
XEvent event;
|
|
|
|
while (XCheckTypedEvent(x_display, MotionNotify, &event)) {
|
|
|
|
delta_x = x - mouse_last_x; delta_y = y - mouse_last_y;
|
|
|
|
mouse_last_x = x; mouse_last_y = y;
|
|
|
|
ADBMouseMoved(delta_x, delta_y);
|
|
|
|
}
|
|
|
|
mouse_last_x = width/2;
|
|
|
|
mouse_last_y = height/2;
|
|
|
|
XWarpPointer(x_display, None, w, 0, 0, 0, 0, mouse_last_x, mouse_last_y);
|
|
|
|
for (int i=0; i<10; i++) {
|
|
|
|
XMaskEvent(x_display, PointerMotionMask, &event);
|
|
|
|
if (event.xmotion.x > (mouse_last_x - MOUSE_FUDGE_FACTOR)
|
|
|
|
&& event.xmotion.x < (mouse_last_x + MOUSE_FUDGE_FACTOR)
|
|
|
|
&& event.xmotion.y > (mouse_last_y - MOUSE_FUDGE_FACTOR)
|
|
|
|
&& event.xmotion.y < (mouse_last_y + MOUSE_FUDGE_FACTOR))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-30 17:21:56 +00:00
|
|
|
|
|
|
|
#if defined(ENABLE_XF86_DGA) || defined(ENABLE_FBDEV_DGA)
|
|
|
|
/*
|
|
|
|
* DGA display driver base class
|
|
|
|
*/
|
|
|
|
|
|
|
|
class driver_dga : public driver_base {
|
|
|
|
public:
|
2002-04-25 11:00:31 +00:00
|
|
|
driver_dga(X11_monitor_desc &monitor);
|
2001-06-30 17:21:56 +00:00
|
|
|
~driver_dga();
|
|
|
|
|
|
|
|
void suspend(void);
|
|
|
|
void resume(void);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Window suspend_win; // "Suspend" information window
|
|
|
|
void *fb_save; // Saved frame buffer for suspend/resume
|
|
|
|
};
|
|
|
|
|
2002-04-25 11:00:31 +00:00
|
|
|
driver_dga::driver_dga(X11_monitor_desc &m)
|
|
|
|
: driver_base(m), suspend_win(0), fb_save(NULL)
|
2001-06-30 17:21:56 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
driver_dga::~driver_dga()
|
|
|
|
{
|
|
|
|
XUngrabPointer(x_display, CurrentTime);
|
|
|
|
XUngrabKeyboard(x_display, CurrentTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Suspend emulation
|
|
|
|
void driver_dga::suspend(void)
|
|
|
|
{
|
|
|
|
// Release ctrl key
|
|
|
|
ADBKeyUp(0x36);
|
|
|
|
ctrl_down = false;
|
|
|
|
|
|
|
|
// Lock frame buffer (this will stop the MacOS thread)
|
|
|
|
LOCK_FRAME_BUFFER;
|
|
|
|
|
|
|
|
// Save frame buffer
|
2002-04-25 11:00:31 +00:00
|
|
|
fb_save = malloc(mode.y * mode.bytes_per_row);
|
2001-06-30 17:21:56 +00:00
|
|
|
if (fb_save)
|
2002-04-25 11:00:31 +00:00
|
|
|
memcpy(fb_save, the_buffer, mode.y * mode.bytes_per_row);
|
2001-06-30 17:21:56 +00:00
|
|
|
|
|
|
|
// Close full screen display
|
|
|
|
#ifdef ENABLE_XF86_DGA
|
|
|
|
XF86DGADirectVideo(x_display, screen, 0);
|
|
|
|
#endif
|
|
|
|
XUngrabPointer(x_display, CurrentTime);
|
|
|
|
XUngrabKeyboard(x_display, CurrentTime);
|
2001-07-09 11:22:01 +00:00
|
|
|
restore_mouse_accel();
|
2001-06-30 17:21:56 +00:00
|
|
|
XUnmapWindow(x_display, w);
|
|
|
|
wait_unmapped(w);
|
|
|
|
|
|
|
|
// Open "suspend" window
|
|
|
|
XSetWindowAttributes wattr;
|
|
|
|
wattr.event_mask = KeyPressMask;
|
|
|
|
wattr.background_pixel = black_pixel;
|
|
|
|
|
|
|
|
suspend_win = XCreateWindow(x_display, rootwin, 0, 0, 512, 1, 0, xdepth,
|
|
|
|
InputOutput, vis, CWEventMask | CWBackPixel, &wattr);
|
|
|
|
set_window_name(suspend_win, STR_SUSPEND_WINDOW_TITLE);
|
|
|
|
set_window_focus(suspend_win);
|
|
|
|
XMapWindow(x_display, suspend_win);
|
|
|
|
emul_suspended = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resume emulation
|
|
|
|
void driver_dga::resume(void)
|
|
|
|
{
|
|
|
|
// Close "suspend" window
|
|
|
|
XDestroyWindow(x_display, suspend_win);
|
|
|
|
XSync(x_display, false);
|
|
|
|
|
|
|
|
// Reopen full screen display
|
|
|
|
XMapRaised(x_display, w);
|
|
|
|
wait_mapped(w);
|
|
|
|
XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0);
|
2001-07-03 15:59:49 +00:00
|
|
|
XGrabKeyboard(x_display, rootwin, True, GrabModeAsync, GrabModeAsync, CurrentTime);
|
|
|
|
XGrabPointer(x_display, rootwin, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
|
2001-07-09 11:22:01 +00:00
|
|
|
disable_mouse_accel();
|
2001-06-30 17:21:56 +00:00
|
|
|
#ifdef ENABLE_XF86_DGA
|
|
|
|
XF86DGADirectVideo(x_display, screen, XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse);
|
|
|
|
XF86DGASetViewPort(x_display, screen, 0, 0);
|
|
|
|
#endif
|
|
|
|
XSync(x_display, false);
|
|
|
|
|
|
|
|
// the_buffer already contains the data to restore. i.e. since a temporary
|
|
|
|
// frame buffer is used when VOSF is actually used, fb_save is therefore
|
|
|
|
// not necessary.
|
|
|
|
#ifdef ENABLE_VOSF
|
|
|
|
if (use_vosf) {
|
|
|
|
LOCK_VOSF;
|
|
|
|
PFLAG_SET_ALL;
|
|
|
|
UNLOCK_VOSF;
|
2002-04-25 11:00:31 +00:00
|
|
|
memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y);
|
2001-06-30 17:21:56 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Restore frame buffer
|
|
|
|
if (fb_save) {
|
|
|
|
#ifdef ENABLE_VOSF
|
|
|
|
// Don't copy fb_save to the temporary frame buffer in VOSF mode
|
|
|
|
if (!use_vosf)
|
|
|
|
#endif
|
2002-04-25 11:00:31 +00:00
|
|
|
memcpy(the_buffer, fb_save, mode.y * mode.bytes_per_row);
|
2001-06-30 17:21:56 +00:00
|
|
|
free(fb_save);
|
|
|
|
fb_save = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unlock frame buffer (and continue MacOS thread)
|
|
|
|
UNLOCK_FRAME_BUFFER;
|
|
|
|
emul_suspended = false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2000-07-13 13:47:12 +00:00
|
|
|
#ifdef ENABLE_FBDEV_DGA
|
2001-06-30 17:21:56 +00:00
|
|
|
/*
|
|
|
|
* fbdev DGA display driver
|
|
|
|
*/
|
|
|
|
|
2001-06-30 20:18:36 +00:00
|
|
|
const char FBDEVICES_FILE_NAME[] = DATADIR "/fbdevices";
|
|
|
|
const char FBDEVICE_FILE_NAME[] = "/dev/fb";
|
|
|
|
|
2001-06-30 17:21:56 +00:00
|
|
|
class driver_fbdev : public driver_dga {
|
|
|
|
public:
|
2002-04-25 11:00:31 +00:00
|
|
|
driver_fbdev(X11_monitor_desc &monitor);
|
2001-06-30 17:21:56 +00:00
|
|
|
~driver_fbdev();
|
|
|
|
};
|
|
|
|
|
|
|
|
// Open display
|
2002-04-25 11:00:31 +00:00
|
|
|
driver_fbdev::driver_fbdev(X11_monitor_desc &m) : driver_dga(m)
|
2001-06-30 17:21:56 +00:00
|
|
|
{
|
2001-06-28 21:20:02 +00:00
|
|
|
int width = mode.x, height = mode.y;
|
|
|
|
|
2001-06-30 17:21:56 +00:00
|
|
|
// Set absolute mouse mode
|
|
|
|
ADBSetRelMouseMode(false);
|
|
|
|
|
1999-10-21 13:19:27 +00:00
|
|
|
// Find the maximum depth available
|
|
|
|
int ndepths, max_depth(0);
|
|
|
|
int *depths = XListDepths(x_display, screen, &ndepths);
|
|
|
|
if (depths == NULL) {
|
1999-10-21 16:40:49 +00:00
|
|
|
printf("FATAL: Could not determine the maximal depth available\n");
|
2001-06-30 17:21:56 +00:00
|
|
|
return;
|
1999-10-21 13:19:27 +00:00
|
|
|
} else {
|
|
|
|
while (ndepths-- > 0) {
|
|
|
|
if (depths[ndepths] > max_depth)
|
|
|
|
max_depth = depths[ndepths];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get fbdevices file path from preferences
|
1999-10-21 16:07:36 +00:00
|
|
|
const char *fbd_path = PrefsFindString("fbdevicefile");
|
1999-10-21 13:19:27 +00:00
|
|
|
|
|
|
|
// Open fbdevices file
|
|
|
|
FILE *fp = fopen(fbd_path ? fbd_path : FBDEVICES_FILE_NAME, "r");
|
|
|
|
if (fp == NULL) {
|
|
|
|
char str[256];
|
|
|
|
sprintf(str, GetString(STR_NO_FBDEVICE_FILE_ERR), fbd_path ? fbd_path : FBDEVICES_FILE_NAME, strerror(errno));
|
|
|
|
ErrorAlert(str);
|
2001-06-30 17:21:56 +00:00
|
|
|
return;
|
1999-10-21 13:19:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int fb_depth; // supported depth
|
|
|
|
uint32 fb_offset; // offset used for mmap(2)
|
|
|
|
char fb_name[20];
|
|
|
|
char line[256];
|
|
|
|
bool device_found = false;
|
|
|
|
while (fgets(line, 255, fp)) {
|
|
|
|
// Read line
|
|
|
|
int len = strlen(line);
|
|
|
|
if (len == 0)
|
|
|
|
continue;
|
|
|
|
line[len - 1] = '\0';
|
|
|
|
|
|
|
|
// Comments begin with "#" or ";"
|
|
|
|
if ((line[0] == '#') || (line[0] == ';') || (line[0] == '\0'))
|
|
|
|
continue;
|
|
|
|
|
2002-03-20 19:03:41 +00:00
|
|
|
if ((sscanf(line, "%19s %d %x", fb_name, &fb_depth, &fb_offset) == 3)
|
2001-06-30 17:21:56 +00:00
|
|
|
&& (strcmp(fb_name, fb_name) == 0) && (fb_depth == max_depth)) {
|
1999-10-21 13:19:27 +00:00
|
|
|
device_found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// fbdevices file completely read
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
// Frame buffer name not found ? Then, display warning
|
|
|
|
if (!device_found) {
|
|
|
|
char str[256];
|
2001-06-28 21:20:02 +00:00
|
|
|
sprintf(str, GetString(STR_FBDEV_NAME_ERR), fb_name, max_depth);
|
1999-10-21 13:19:27 +00:00
|
|
|
ErrorAlert(str);
|
2001-06-30 17:21:56 +00:00
|
|
|
return;
|
1999-10-21 13:19:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create window
|
|
|
|
XSetWindowAttributes wattr;
|
2000-11-03 18:21:43 +00:00
|
|
|
wattr.event_mask = eventmask = dga_eventmask;
|
|
|
|
wattr.background_pixel = white_pixel;
|
|
|
|
wattr.override_redirect = True;
|
|
|
|
wattr.colormap = cmap[0];
|
1999-10-21 13:19:27 +00:00
|
|
|
|
2001-06-30 17:21:56 +00:00
|
|
|
w = XCreateWindow(x_display, rootwin,
|
1999-10-21 13:19:27 +00:00
|
|
|
0, 0, width, height,
|
|
|
|
0, xdepth, InputOutput, vis,
|
2001-06-30 17:21:56 +00:00
|
|
|
CWEventMask | CWBackPixel | CWOverrideRedirect | (fb_depth <= 8 ? CWColormap : 0),
|
1999-10-21 13:19:27 +00:00
|
|
|
&wattr);
|
2000-11-03 18:21:43 +00:00
|
|
|
|
|
|
|
// Set window name/class
|
2001-06-30 17:21:56 +00:00
|
|
|
set_window_name(w, STR_WINDOW_TITLE);
|
2000-11-03 18:21:43 +00:00
|
|
|
|
|
|
|
// Indicate that we want keyboard input
|
2001-06-30 17:21:56 +00:00
|
|
|
set_window_focus(w);
|
2000-11-03 18:21:43 +00:00
|
|
|
|
|
|
|
// Show window
|
2001-06-30 17:21:56 +00:00
|
|
|
XMapRaised(x_display, w);
|
|
|
|
wait_mapped(w);
|
1999-10-21 13:19:27 +00:00
|
|
|
|
|
|
|
// Grab mouse and keyboard
|
2001-06-30 17:21:56 +00:00
|
|
|
XGrabKeyboard(x_display, w, True,
|
1999-10-21 13:19:27 +00:00
|
|
|
GrabModeAsync, GrabModeAsync, CurrentTime);
|
2001-06-30 17:21:56 +00:00
|
|
|
XGrabPointer(x_display, w, True,
|
1999-10-21 13:19:27 +00:00
|
|
|
PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
|
2001-06-30 17:21:56 +00:00
|
|
|
GrabModeAsync, GrabModeAsync, w, None, CurrentTime);
|
2001-07-09 11:22:01 +00:00
|
|
|
disable_mouse_accel();
|
1999-10-21 13:19:27 +00:00
|
|
|
|
2001-06-28 21:20:02 +00:00
|
|
|
// Calculate bytes per row
|
|
|
|
int bytes_per_row = TrivialBytesPerRow(mode.x, mode.depth);
|
1999-10-21 13:19:27 +00:00
|
|
|
|
2001-06-28 21:20:02 +00:00
|
|
|
// Map frame buffer
|
2001-07-07 09:14:47 +00:00
|
|
|
the_buffer_size = height * bytes_per_row;
|
|
|
|
if ((the_buffer = (uint8 *) mmap(NULL, the_buffer_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fbdev_fd, fb_offset)) == MAP_FAILED) {
|
|
|
|
if ((the_buffer = (uint8 *) mmap(NULL, the_buffer_size, PROT_READ | PROT_WRITE, MAP_SHARED, fbdev_fd, fb_offset)) == MAP_FAILED) {
|
1999-10-21 13:19:27 +00:00
|
|
|
char str[256];
|
|
|
|
sprintf(str, GetString(STR_FBDEV_MMAP_ERR), strerror(errno));
|
|
|
|
ErrorAlert(str);
|
2001-06-30 17:21:56 +00:00
|
|
|
return;
|
1999-10-21 13:19:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-09 17:05:17 +00:00
|
|
|
#if ENABLE_VOSF
|
2000-09-22 17:16:31 +00:00
|
|
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING
|
2001-01-28 14:05:19 +00:00
|
|
|
// Screen_blitter_init() returns TRUE if VOSF is mandatory
|
|
|
|
// i.e. the framebuffer update function is not Blit_Copy_Raw
|
2001-07-01 14:38:03 +00:00
|
|
|
use_vosf = Screen_blitter_init(&visualInfo, true, mode.depth);
|
2000-09-22 17:16:31 +00:00
|
|
|
|
|
|
|
if (use_vosf) {
|
2001-06-26 22:35:42 +00:00
|
|
|
// Allocate memory for frame buffer (SIZE is extended to page-boundary)
|
|
|
|
the_host_buffer = the_buffer;
|
|
|
|
the_buffer_size = page_extend((height + 2) * bytes_per_row);
|
2001-07-14 18:41:05 +00:00
|
|
|
the_buffer_copy = (uint8 *)malloc(the_buffer_size);
|
2001-06-26 22:35:42 +00:00
|
|
|
the_buffer = (uint8 *)vm_acquire(the_buffer_size);
|
2000-09-22 17:16:31 +00:00
|
|
|
}
|
2000-10-09 17:05:17 +00:00
|
|
|
#else
|
2000-09-22 17:16:31 +00:00
|
|
|
use_vosf = false;
|
2000-10-09 17:05:17 +00:00
|
|
|
#endif
|
2000-09-22 17:16:31 +00:00
|
|
|
#endif
|
|
|
|
|
2002-04-25 11:00:31 +00:00
|
|
|
// Set frame buffer base
|
|
|
|
const_cast<video_mode *>(&mode)->bytes_per_row = bytes_per_row;
|
|
|
|
const_cast<video_mode *>(&mode)->depth = DepthModeForPixelDepth(fb_depth);
|
2002-04-28 12:09:23 +00:00
|
|
|
set_mac_frame_buffer(monitor, mode.depth, true);
|
2001-06-30 17:21:56 +00:00
|
|
|
|
|
|
|
// Everything went well
|
|
|
|
init_ok = true;
|
1999-10-03 14:16:26 +00:00
|
|
|
}
|
|
|
|
|
2001-06-30 17:21:56 +00:00
|
|
|
// Close display
|
|
|
|
driver_fbdev::~driver_fbdev()
|
1999-10-03 14:16:26 +00:00
|
|
|
{
|
2001-07-07 09:14:47 +00:00
|
|
|
if (!use_vosf) {
|
|
|
|
if (the_buffer != MAP_FAILED) {
|
|
|
|
// don't free() the screen buffer in driver_base dtor
|
|
|
|
munmap(the_buffer, the_buffer_size);
|
|
|
|
the_buffer = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef ENABLE_VOSF
|
|
|
|
else {
|
|
|
|
if (the_host_buffer != MAP_FAILED) {
|
|
|
|
// don't free() the screen buffer in driver_base dtor
|
|
|
|
munmap(the_host_buffer, the_buffer_size);
|
|
|
|
the_host_buffer = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2001-06-30 17:21:56 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-06-28 21:20:02 +00:00
|
|
|
|
2000-07-13 13:47:12 +00:00
|
|
|
#ifdef ENABLE_XF86_DGA
|
2001-06-30 17:21:56 +00:00
|
|
|
/*
|
|
|
|
* XFree86 DGA display driver
|
|
|
|
*/
|
|
|
|
|
|
|
|
class driver_xf86dga : public driver_dga {
|
|
|
|
public:
|
2002-04-25 11:00:31 +00:00
|
|
|
driver_xf86dga(X11_monitor_desc &monitor);
|
2001-06-30 17:21:56 +00:00
|
|
|
~driver_xf86dga();
|
|
|
|
|
|
|
|
void update_palette(void);
|
|
|
|
void resume(void);
|
|
|
|
|
|
|
|
private:
|
|
|
|
int current_dga_cmap; // Number (0 or 1) of currently installed DGA colormap
|
|
|
|
};
|
|
|
|
|
|
|
|
// Open display
|
2002-04-25 11:00:31 +00:00
|
|
|
driver_xf86dga::driver_xf86dga(X11_monitor_desc &m)
|
|
|
|
: driver_dga(m), current_dga_cmap(0)
|
2001-06-30 17:21:56 +00:00
|
|
|
{
|
|
|
|
int width = mode.x, height = mode.y;
|
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
// Set relative mouse mode
|
|
|
|
ADBSetRelMouseMode(true);
|
|
|
|
|
2000-07-13 13:47:12 +00:00
|
|
|
#ifdef ENABLE_XF86_VIDMODE
|
1999-11-03 21:04:23 +00:00
|
|
|
// Switch to best mode
|
|
|
|
if (has_vidmode) {
|
|
|
|
int best = 0;
|
|
|
|
for (int i=1; i<num_x_video_modes; i++) {
|
|
|
|
if (x_video_modes[i]->hdisplay >= width && x_video_modes[i]->vdisplay >= height &&
|
|
|
|
x_video_modes[i]->hdisplay <= x_video_modes[best]->hdisplay && x_video_modes[i]->vdisplay <= x_video_modes[best]->vdisplay) {
|
|
|
|
best = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
XF86VidModeSwitchToMode(x_display, screen, x_video_modes[best]);
|
|
|
|
XF86VidModeSetViewPort(x_display, screen, 0, 0);
|
2000-11-03 18:21:43 +00:00
|
|
|
XSync(x_display, false);
|
1999-11-03 21:04:23 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
// Create window
|
|
|
|
XSetWindowAttributes wattr;
|
|
|
|
wattr.event_mask = eventmask = dga_eventmask;
|
|
|
|
wattr.override_redirect = True;
|
|
|
|
|
2001-06-30 17:21:56 +00:00
|
|
|
w = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth,
|
2000-11-03 12:23:49 +00:00
|
|
|
InputOutput, vis, CWEventMask | CWOverrideRedirect, &wattr);
|
2000-11-03 18:21:43 +00:00
|
|
|
|
|
|
|
// Set window name/class
|
2001-06-30 17:21:56 +00:00
|
|
|
set_window_name(w, STR_WINDOW_TITLE);
|
2000-11-03 18:21:43 +00:00
|
|
|
|
|
|
|
// Indicate that we want keyboard input
|
2001-06-30 17:21:56 +00:00
|
|
|
set_window_focus(w);
|
2000-11-03 18:21:43 +00:00
|
|
|
|
|
|
|
// Show window
|
2001-06-30 17:21:56 +00:00
|
|
|
XMapRaised(x_display, w);
|
|
|
|
wait_mapped(w);
|
1999-10-03 14:16:26 +00:00
|
|
|
|
|
|
|
// Establish direct screen connection
|
2001-06-30 17:21:56 +00:00
|
|
|
XMoveResizeWindow(x_display, w, 0, 0, width, height);
|
1999-10-03 14:16:26 +00:00
|
|
|
XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0);
|
|
|
|
XGrabKeyboard(x_display, rootwin, True, GrabModeAsync, GrabModeAsync, CurrentTime);
|
|
|
|
XGrabPointer(x_display, rootwin, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
|
2001-07-09 11:22:01 +00:00
|
|
|
disable_mouse_accel();
|
1999-10-03 14:16:26 +00:00
|
|
|
|
|
|
|
int v_width, v_bank, v_size;
|
|
|
|
XF86DGAGetVideo(x_display, screen, (char **)&the_buffer, &v_width, &v_bank, &v_size);
|
|
|
|
XF86DGADirectVideo(x_display, screen, XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse);
|
|
|
|
XF86DGASetViewPort(x_display, screen, 0, 0);
|
|
|
|
XF86DGASetVidPage(x_display, screen, 0);
|
|
|
|
|
|
|
|
// Set colormap
|
2001-06-28 21:20:02 +00:00
|
|
|
if (!IsDirectMode(mode)) {
|
2001-06-30 17:21:56 +00:00
|
|
|
XSetWindowColormap(x_display, w, cmap[current_dga_cmap = 0]);
|
1999-10-03 14:16:26 +00:00
|
|
|
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]);
|
|
|
|
}
|
2000-11-03 18:21:43 +00:00
|
|
|
XSync(x_display, false);
|
1999-10-03 14:16:26 +00:00
|
|
|
|
2001-06-30 17:21:56 +00:00
|
|
|
// Init blitting routines
|
2001-06-28 21:20:02 +00:00
|
|
|
int bytes_per_row = TrivialBytesPerRow((v_width + 7) & ~7, mode.depth);
|
2001-07-07 09:14:47 +00:00
|
|
|
#if VIDEO_VOSF
|
2000-09-22 17:16:31 +00:00
|
|
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING
|
2001-01-28 14:05:19 +00:00
|
|
|
// Screen_blitter_init() returns TRUE if VOSF is mandatory
|
|
|
|
// i.e. the framebuffer update function is not Blit_Copy_Raw
|
2001-07-01 14:38:03 +00:00
|
|
|
use_vosf = Screen_blitter_init(&visualInfo, true, mode.depth);
|
2000-09-22 17:16:31 +00:00
|
|
|
|
|
|
|
if (use_vosf) {
|
2001-06-26 22:35:42 +00:00
|
|
|
// Allocate memory for frame buffer (SIZE is extended to page-boundary)
|
|
|
|
the_host_buffer = the_buffer;
|
|
|
|
the_buffer_size = page_extend((height + 2) * bytes_per_row);
|
2001-07-14 18:41:05 +00:00
|
|
|
the_buffer_copy = (uint8 *)malloc(the_buffer_size);
|
2001-06-26 22:35:42 +00:00
|
|
|
the_buffer = (uint8 *)vm_acquire(the_buffer_size);
|
2000-09-22 17:16:31 +00:00
|
|
|
}
|
2001-06-26 22:35:42 +00:00
|
|
|
#else
|
2000-09-22 17:16:31 +00:00
|
|
|
use_vosf = false;
|
2001-06-26 22:35:42 +00:00
|
|
|
#endif
|
2000-09-22 17:16:31 +00:00
|
|
|
#endif
|
|
|
|
|
2002-04-25 11:00:31 +00:00
|
|
|
// Set frame buffer base
|
2001-06-28 21:20:02 +00:00
|
|
|
const_cast<video_mode *>(&mode)->bytes_per_row = bytes_per_row;
|
2002-04-25 11:00:31 +00:00
|
|
|
set_mac_frame_buffer(monitor, mode.depth, true);
|
2001-06-30 17:21:56 +00:00
|
|
|
|
|
|
|
// Everything went well
|
|
|
|
init_ok = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close display
|
|
|
|
driver_xf86dga::~driver_xf86dga()
|
|
|
|
{
|
|
|
|
XF86DGADirectVideo(x_display, screen, 0);
|
2001-07-07 09:14:47 +00:00
|
|
|
if (!use_vosf) {
|
|
|
|
// don't free() the screen buffer in driver_base dtor
|
|
|
|
the_buffer = NULL;
|
|
|
|
}
|
|
|
|
#ifdef ENABLE_VOSF
|
|
|
|
else {
|
|
|
|
// don't free() the screen buffer in driver_base dtor
|
|
|
|
the_host_buffer = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
2001-06-30 17:21:56 +00:00
|
|
|
#ifdef ENABLE_XF86_VIDMODE
|
|
|
|
if (has_vidmode)
|
|
|
|
XF86VidModeSwitchToMode(x_display, screen, x_video_modes[0]);
|
1999-10-03 14:16:26 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-06-30 17:21:56 +00:00
|
|
|
// Palette has changed
|
|
|
|
void driver_xf86dga::update_palette(void)
|
|
|
|
{
|
|
|
|
driver_dga::update_palette();
|
|
|
|
current_dga_cmap ^= 1;
|
2002-04-25 11:00:31 +00:00
|
|
|
if (!IsDirectMode(monitor.get_current_mode()) && cmap[current_dga_cmap])
|
2001-06-30 17:21:56 +00:00
|
|
|
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resume emulation
|
|
|
|
void driver_xf86dga::resume(void)
|
|
|
|
{
|
|
|
|
driver_dga::resume();
|
2002-04-25 11:00:31 +00:00
|
|
|
if (!IsDirectMode(monitor.get_current_mode()))
|
2001-06-30 17:21:56 +00:00
|
|
|
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialization
|
|
|
|
*/
|
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
// Init keycode translation table
|
|
|
|
static void keycode_init(void)
|
|
|
|
{
|
|
|
|
bool use_kc = PrefsFindBool("keycodes");
|
|
|
|
if (use_kc) {
|
|
|
|
|
|
|
|
// Get keycode file path from preferences
|
|
|
|
const char *kc_path = PrefsFindString("keycodefile");
|
|
|
|
|
|
|
|
// Open keycode table
|
|
|
|
FILE *f = fopen(kc_path ? kc_path : KEYCODE_FILE_NAME, "r");
|
|
|
|
if (f == NULL) {
|
|
|
|
char str[256];
|
|
|
|
sprintf(str, GetString(STR_KEYCODE_FILE_WARN), kc_path ? kc_path : KEYCODE_FILE_NAME, strerror(errno));
|
|
|
|
WarningAlert(str);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default translation table
|
|
|
|
for (int i=0; i<256; i++)
|
|
|
|
keycode_table[i] = -1;
|
|
|
|
|
|
|
|
// Search for server vendor string, then read keycodes
|
|
|
|
const char *vendor = ServerVendor(x_display);
|
|
|
|
bool vendor_found = false;
|
|
|
|
char line[256];
|
|
|
|
while (fgets(line, 255, f)) {
|
|
|
|
// Read line
|
|
|
|
int len = strlen(line);
|
|
|
|
if (len == 0)
|
|
|
|
continue;
|
|
|
|
line[len-1] = 0;
|
|
|
|
|
|
|
|
// Comments begin with "#" or ";"
|
|
|
|
if (line[0] == '#' || line[0] == ';' || line[0] == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (vendor_found) {
|
|
|
|
// Read keycode
|
|
|
|
int x_code, mac_code;
|
|
|
|
if (sscanf(line, "%d %d", &x_code, &mac_code) == 2)
|
|
|
|
keycode_table[x_code & 0xff] = mac_code;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
// Search for vendor string
|
|
|
|
if (strstr(vendor, line) == vendor)
|
|
|
|
vendor_found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Keycode file completely read
|
|
|
|
fclose(f);
|
|
|
|
use_keycodes = vendor_found;
|
|
|
|
|
|
|
|
// Vendor not found? Then display warning
|
|
|
|
if (!vendor_found) {
|
|
|
|
char str[256];
|
|
|
|
sprintf(str, GetString(STR_KEYCODE_VENDOR_WARN), vendor, kc_path ? kc_path : KEYCODE_FILE_NAME);
|
|
|
|
WarningAlert(str);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-25 11:00:31 +00:00
|
|
|
// Open display for current mode
|
|
|
|
bool X11_monitor_desc::video_open(void)
|
2000-09-22 17:16:31 +00:00
|
|
|
{
|
2001-07-14 15:02:49 +00:00
|
|
|
D(bug("video_open()\n"));
|
2002-04-25 11:00:31 +00:00
|
|
|
const video_mode &mode = get_current_mode();
|
2001-07-14 15:02:49 +00:00
|
|
|
|
2001-07-06 20:49:53 +00:00
|
|
|
// Find best available X visual
|
|
|
|
if (!find_visual_for_depth(mode.depth)) {
|
|
|
|
ErrorAlert(STR_NO_XVISUAL_ERR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create color maps
|
|
|
|
if (color_class == PseudoColor || color_class == DirectColor) {
|
|
|
|
cmap[0] = XCreateColormap(x_display, rootwin, vis, AllocAll);
|
|
|
|
cmap[1] = XCreateColormap(x_display, rootwin, vis, AllocAll);
|
2001-07-10 15:50:57 +00:00
|
|
|
} else {
|
|
|
|
cmap[0] = XCreateColormap(x_display, rootwin, vis, AllocNone);
|
|
|
|
cmap[1] = XCreateColormap(x_display, rootwin, vis, AllocNone);
|
2001-07-06 20:49:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Find pixel format of direct modes
|
|
|
|
if (color_class == DirectColor || color_class == TrueColor) {
|
|
|
|
rshift = gshift = bshift = 0;
|
|
|
|
rloss = gloss = bloss = 8;
|
|
|
|
uint32 mask;
|
|
|
|
for (mask=vis->red_mask; !(mask&1); mask>>=1)
|
|
|
|
++rshift;
|
|
|
|
for (; mask&1; mask>>=1)
|
|
|
|
--rloss;
|
|
|
|
for (mask=vis->green_mask; !(mask&1); mask>>=1)
|
|
|
|
++gshift;
|
|
|
|
for (; mask&1; mask>>=1)
|
|
|
|
--gloss;
|
|
|
|
for (mask=vis->blue_mask; !(mask&1); mask>>=1)
|
|
|
|
++bshift;
|
|
|
|
for (; mask&1; mask>>=1)
|
|
|
|
--bloss;
|
|
|
|
}
|
|
|
|
|
2001-07-09 11:22:01 +00:00
|
|
|
// Preset palette pixel values for CLUT or gamma table
|
2001-07-06 20:49:53 +00:00
|
|
|
if (color_class == DirectColor) {
|
|
|
|
int num = vis->map_entries;
|
|
|
|
for (int i=0; i<num; i++) {
|
|
|
|
int c = (i * 256) / num;
|
2002-04-25 11:00:31 +00:00
|
|
|
x_palette[i].pixel = map_rgb(c, c, c);
|
|
|
|
x_palette[i].flags = DoRed | DoGreen | DoBlue;
|
2001-07-09 11:22:01 +00:00
|
|
|
}
|
|
|
|
} else if (color_class == PseudoColor) {
|
|
|
|
for (int i=0; i<256; i++) {
|
2002-04-25 11:00:31 +00:00
|
|
|
x_palette[i].pixel = i;
|
|
|
|
x_palette[i].flags = DoRed | DoGreen | DoBlue;
|
2001-07-06 20:49:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-01 14:38:03 +00:00
|
|
|
// Load gray ramp to color map
|
2001-07-06 20:49:53 +00:00
|
|
|
int num = (color_class == DirectColor ? vis->map_entries : 256);
|
2001-07-01 14:38:03 +00:00
|
|
|
for (int i=0; i<num; i++) {
|
|
|
|
int c = (i * 256) / num;
|
2002-04-25 11:00:31 +00:00
|
|
|
x_palette[i].red = c * 0x0101;
|
|
|
|
x_palette[i].green = c * 0x0101;
|
|
|
|
x_palette[i].blue = c * 0x0101;
|
2001-07-01 14:38:03 +00:00
|
|
|
}
|
2001-07-10 15:50:57 +00:00
|
|
|
if (color_class == PseudoColor || color_class == DirectColor) {
|
2002-04-25 11:00:31 +00:00
|
|
|
XStoreColors(x_display, cmap[0], x_palette, num);
|
|
|
|
XStoreColors(x_display, cmap[1], x_palette, num);
|
2001-07-01 14:38:03 +00:00
|
|
|
}
|
|
|
|
|
2001-07-01 19:57:55 +00:00
|
|
|
#ifdef ENABLE_VOSF
|
|
|
|
// Load gray ramp to 8->16/32 expand map
|
2001-07-09 11:22:01 +00:00
|
|
|
if (!IsDirectMode(mode) && xdepth > 8)
|
2001-07-01 19:57:55 +00:00
|
|
|
for (int i=0; i<256; i++)
|
|
|
|
ExpandMap[i] = map_rgb(i, i, i);
|
|
|
|
#endif
|
|
|
|
|
2001-06-30 17:21:56 +00:00
|
|
|
// Create display driver object of requested type
|
2001-06-28 21:20:02 +00:00
|
|
|
switch (display_type) {
|
|
|
|
case DISPLAY_WINDOW:
|
2002-04-25 11:00:31 +00:00
|
|
|
drv = new driver_window(*this);
|
2001-06-28 21:20:02 +00:00
|
|
|
break;
|
|
|
|
#ifdef ENABLE_FBDEV_DGA
|
2001-06-30 17:21:56 +00:00
|
|
|
case DISPLAY_DGA:
|
2002-04-25 11:00:31 +00:00
|
|
|
drv = new driver_fbdev(*this);
|
2001-06-30 17:21:56 +00:00
|
|
|
break;
|
2001-06-28 21:20:02 +00:00
|
|
|
#endif
|
2001-06-30 17:21:56 +00:00
|
|
|
#ifdef ENABLE_XF86_DGA
|
|
|
|
case DISPLAY_DGA:
|
2002-04-25 11:00:31 +00:00
|
|
|
drv = new driver_xf86dga(*this);
|
2001-06-28 21:20:02 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2001-06-30 17:21:56 +00:00
|
|
|
}
|
|
|
|
if (drv == NULL)
|
|
|
|
return false;
|
|
|
|
if (!drv->init_ok) {
|
|
|
|
delete drv;
|
|
|
|
drv = NULL;
|
|
|
|
return false;
|
|
|
|
}
|
2000-09-22 17:16:31 +00:00
|
|
|
|
2001-06-28 21:20:02 +00:00
|
|
|
#ifdef ENABLE_VOSF
|
|
|
|
if (use_vosf) {
|
2001-07-07 09:14:47 +00:00
|
|
|
// Initialize the VOSF system
|
2002-04-25 11:00:31 +00:00
|
|
|
if (!video_vosf_init(*this)) {
|
2001-06-30 17:21:56 +00:00
|
|
|
ErrorAlert(STR_VOSF_INIT_ERR);
|
2001-06-28 21:20:02 +00:00
|
|
|
return false;
|
2000-09-22 17:16:31 +00:00
|
|
|
}
|
2001-06-28 21:20:02 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Initialize VideoRefresh function
|
|
|
|
VideoRefreshInit();
|
2001-06-30 17:21:56 +00:00
|
|
|
|
|
|
|
// Lock down frame buffer
|
2001-06-28 21:20:02 +00:00
|
|
|
XSync(x_display, false);
|
2001-06-30 17:21:56 +00:00
|
|
|
LOCK_FRAME_BUFFER;
|
2001-06-28 21:20:02 +00:00
|
|
|
|
|
|
|
// Start redraw/input thread
|
2001-06-30 20:18:36 +00:00
|
|
|
#ifdef HAVE_PTHREADS
|
2001-06-28 21:20:02 +00:00
|
|
|
redraw_thread_cancel = false;
|
2002-02-07 16:10:57 +00:00
|
|
|
Set_pthread_attr(&redraw_thread_attr, 0);
|
|
|
|
redraw_thread_active = (pthread_create(&redraw_thread, &redraw_thread_attr, redraw_func, NULL) == 0);
|
2001-06-28 21:20:02 +00:00
|
|
|
if (!redraw_thread_active) {
|
|
|
|
printf("FATAL: cannot create redraw thread\n");
|
|
|
|
return false;
|
2000-09-22 17:16:31 +00:00
|
|
|
}
|
2001-06-30 20:18:36 +00:00
|
|
|
#else
|
|
|
|
redraw_thread_active = true;
|
2000-09-22 17:16:31 +00:00
|
|
|
#endif
|
2001-06-28 21:20:02 +00:00
|
|
|
|
2000-09-22 17:16:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
bool VideoInit(bool classic)
|
|
|
|
{
|
2001-06-28 21:20:02 +00:00
|
|
|
classic_mode = classic;
|
|
|
|
|
2000-09-22 17:16:31 +00:00
|
|
|
#ifdef ENABLE_VOSF
|
|
|
|
// Zero the mainBuffer structure
|
2001-06-30 17:21:56 +00:00
|
|
|
mainBuffer.dirtyPages = NULL;
|
|
|
|
mainBuffer.pageInfo = NULL;
|
2000-09-22 17:16:31 +00:00
|
|
|
#endif
|
|
|
|
|
2000-07-13 16:12:33 +00:00
|
|
|
// Check if X server runs on local machine
|
|
|
|
local_X11 = (strncmp(XDisplayName(x_display_name), ":", 1) == 0)
|
|
|
|
|| (strncmp(XDisplayName(x_display_name), "unix:", 5) == 0);
|
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
// Init keycode translation
|
|
|
|
keycode_init();
|
|
|
|
|
1999-10-25 20:22:35 +00:00
|
|
|
// Read prefs
|
2001-06-30 17:21:56 +00:00
|
|
|
frame_skip = PrefsFindInt32("frameskip");
|
2001-01-04 19:50:23 +00:00
|
|
|
mouse_wheel_mode = PrefsFindInt32("mousewheelmode");
|
|
|
|
mouse_wheel_lines = PrefsFindInt32("mousewheellines");
|
1999-10-25 20:22:35 +00:00
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
// Find screen and root window
|
|
|
|
screen = XDefaultScreen(x_display);
|
|
|
|
rootwin = XRootWindow(x_display, screen);
|
2001-07-06 20:49:53 +00:00
|
|
|
|
|
|
|
// Get sorted list of available depths
|
|
|
|
avail_depths = XListDepths(x_display, screen, &num_depths);
|
|
|
|
if (avail_depths == NULL) {
|
|
|
|
ErrorAlert(STR_UNSUPP_DEPTH_ERR);
|
|
|
|
return false;
|
|
|
|
}
|
2002-04-25 11:00:31 +00:00
|
|
|
std::sort(avail_depths, avail_depths + num_depths);
|
1999-10-21 13:19:27 +00:00
|
|
|
|
2000-07-13 13:47:12 +00:00
|
|
|
#ifdef ENABLE_FBDEV_DGA
|
1999-10-21 13:19:27 +00:00
|
|
|
// Frame buffer name
|
|
|
|
char fb_name[20];
|
|
|
|
|
2001-06-30 17:21:56 +00:00
|
|
|
// Could do fbdev DGA?
|
1999-10-21 13:19:27 +00:00
|
|
|
if ((fbdev_fd = open(FBDEVICE_FILE_NAME, O_RDWR)) != -1)
|
|
|
|
has_dga = true;
|
|
|
|
else
|
|
|
|
has_dga = false;
|
|
|
|
#endif
|
1999-11-03 21:04:23 +00:00
|
|
|
|
2000-07-13 13:47:12 +00:00
|
|
|
#ifdef ENABLE_XF86_DGA
|
1999-10-03 14:16:26 +00:00
|
|
|
// DGA available?
|
1999-11-03 21:04:23 +00:00
|
|
|
int dga_event_base, dga_error_base;
|
2000-07-13 16:12:33 +00:00
|
|
|
if (local_X11 && XF86DGAQueryExtension(x_display, &dga_event_base, &dga_error_base)) {
|
1999-10-05 14:59:46 +00:00
|
|
|
int dga_flags = 0;
|
|
|
|
XF86DGAQueryDirectVideo(x_display, screen, &dga_flags);
|
|
|
|
has_dga = dga_flags & XF86DGADirectPresent;
|
|
|
|
} else
|
|
|
|
has_dga = false;
|
1999-10-03 14:16:26 +00:00
|
|
|
#endif
|
|
|
|
|
2000-07-13 13:47:12 +00:00
|
|
|
#ifdef ENABLE_XF86_VIDMODE
|
1999-11-03 21:04:23 +00:00
|
|
|
// VidMode available?
|
|
|
|
int vm_event_base, vm_error_base;
|
|
|
|
has_vidmode = XF86VidModeQueryExtension(x_display, &vm_event_base, &vm_error_base);
|
|
|
|
if (has_vidmode)
|
|
|
|
XF86VidModeGetAllModeLines(x_display, screen, &num_x_video_modes, &x_video_modes);
|
|
|
|
#endif
|
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
// Find black and white colors
|
|
|
|
XParseColor(x_display, DefaultColormap(x_display, screen), "rgb:00/00/00", &black);
|
|
|
|
XAllocColor(x_display, DefaultColormap(x_display, screen), &black);
|
|
|
|
XParseColor(x_display, DefaultColormap(x_display, screen), "rgb:ff/ff/ff", &white);
|
|
|
|
XAllocColor(x_display, DefaultColormap(x_display, screen), &white);
|
|
|
|
black_pixel = BlackPixel(x_display, screen);
|
|
|
|
white_pixel = WhitePixel(x_display, screen);
|
|
|
|
|
|
|
|
// Get screen mode from preferences
|
|
|
|
const char *mode_str;
|
2001-06-28 21:20:02 +00:00
|
|
|
if (classic_mode)
|
1999-10-03 14:16:26 +00:00
|
|
|
mode_str = "win/512/342";
|
|
|
|
else
|
|
|
|
mode_str = PrefsFindString("screen");
|
|
|
|
|
2001-06-28 21:20:02 +00:00
|
|
|
// Determine display type and default dimensions
|
|
|
|
int default_width = 512, default_height = 384;
|
1999-10-03 14:16:26 +00:00
|
|
|
display_type = DISPLAY_WINDOW;
|
|
|
|
if (mode_str) {
|
2001-06-28 21:20:02 +00:00
|
|
|
if (sscanf(mode_str, "win/%d/%d", &default_width, &default_height) == 2) {
|
1999-10-03 14:16:26 +00:00
|
|
|
display_type = DISPLAY_WINDOW;
|
2000-07-13 13:47:12 +00:00
|
|
|
#ifdef ENABLE_FBDEV_DGA
|
2001-06-28 21:20:02 +00:00
|
|
|
} else if (has_dga && sscanf(mode_str, "dga/%19s", fb_name) == 1) {
|
1999-10-03 14:16:26 +00:00
|
|
|
display_type = DISPLAY_DGA;
|
2001-06-30 17:21:56 +00:00
|
|
|
default_width = -1; default_height = -1; // use entire screen
|
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_XF86_DGA
|
2001-06-28 21:20:02 +00:00
|
|
|
} else if (has_dga && sscanf(mode_str, "dga/%d/%d", &default_width, &default_height) == 2) {
|
|
|
|
display_type = DISPLAY_DGA;
|
1999-10-21 13:19:27 +00:00
|
|
|
#endif
|
2001-06-28 21:20:02 +00:00
|
|
|
}
|
1999-10-03 14:16:26 +00:00
|
|
|
}
|
2001-06-28 21:20:02 +00:00
|
|
|
if (default_width <= 0)
|
|
|
|
default_width = DisplayWidth(x_display, screen);
|
|
|
|
else if (default_width > DisplayWidth(x_display, screen))
|
|
|
|
default_width = DisplayWidth(x_display, screen);
|
|
|
|
if (default_height <= 0)
|
|
|
|
default_height = DisplayHeight(x_display, screen);
|
|
|
|
else if (default_height > DisplayHeight(x_display, screen))
|
|
|
|
default_height = DisplayHeight(x_display, screen);
|
1999-10-03 14:16:26 +00:00
|
|
|
|
2001-07-01 14:38:03 +00:00
|
|
|
// Mac screen depth follows X depth
|
2001-07-06 20:49:53 +00:00
|
|
|
video_depth default_depth = VDEPTH_1BIT;
|
|
|
|
switch (DefaultDepth(x_display, screen)) {
|
|
|
|
case 8:
|
|
|
|
default_depth = VDEPTH_8BIT;
|
|
|
|
break;
|
|
|
|
case 15: case 16:
|
|
|
|
default_depth = VDEPTH_16BIT;
|
|
|
|
break;
|
|
|
|
case 24: case 32:
|
|
|
|
default_depth = VDEPTH_32BIT;
|
|
|
|
break;
|
|
|
|
}
|
1999-10-03 14:16:26 +00:00
|
|
|
|
2001-06-28 21:20:02 +00:00
|
|
|
// Construct list of supported modes
|
|
|
|
if (display_type == DISPLAY_WINDOW) {
|
|
|
|
if (classic)
|
2001-07-01 14:38:03 +00:00
|
|
|
add_mode(512, 342, 0x80, 64, VDEPTH_1BIT);
|
2001-06-28 21:20:02 +00:00
|
|
|
else {
|
2001-07-06 20:49:53 +00:00
|
|
|
for (unsigned d=VDEPTH_1BIT; d<=VDEPTH_32BIT; d++) {
|
|
|
|
if (find_visual_for_depth(video_depth(d)))
|
|
|
|
add_window_modes(video_depth(d));
|
2001-07-01 19:57:55 +00:00
|
|
|
}
|
2000-09-22 17:16:31 +00:00
|
|
|
}
|
2001-06-28 21:20:02 +00:00
|
|
|
} else
|
2001-07-01 14:38:03 +00:00
|
|
|
add_mode(default_width, default_height, 0x80, TrivialBytesPerRow(default_width, default_depth), default_depth);
|
2001-07-06 20:49:53 +00:00
|
|
|
if (VideoModes.empty()) {
|
|
|
|
ErrorAlert(STR_NO_XVISUAL_ERR);
|
|
|
|
return false;
|
|
|
|
}
|
2002-04-25 11:00:31 +00:00
|
|
|
|
|
|
|
// Find requested default mode with specified dimensions
|
|
|
|
uint32 default_id;
|
|
|
|
std::vector<video_mode>::const_iterator i, end = VideoModes.end();
|
|
|
|
for (i = VideoModes.begin(); i != end; ++i) {
|
|
|
|
if (i->x == default_width && i->y == default_height && i->depth == default_depth) {
|
|
|
|
default_id = i->resolution_id;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == end) { // not found, use first available mode
|
|
|
|
default_depth = VideoModes[0].depth;
|
|
|
|
default_id = VideoModes[0].resolution_id;
|
|
|
|
}
|
2001-06-28 21:20:02 +00:00
|
|
|
|
2001-07-06 20:49:53 +00:00
|
|
|
#if DEBUG
|
|
|
|
D(bug("Available video modes:\n"));
|
2002-04-25 11:00:31 +00:00
|
|
|
for (i = VideoModes.begin(); i != end; ++i) {
|
2001-07-06 20:49:53 +00:00
|
|
|
int bits = 1 << i->depth;
|
|
|
|
if (bits == 16)
|
|
|
|
bits = 15;
|
|
|
|
else if (bits == 32)
|
|
|
|
bits = 24;
|
|
|
|
D(bug(" %dx%d (ID %02x), %d colors\n", i->x, i->y, i->resolution_id, 1 << bits));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-04-25 11:00:31 +00:00
|
|
|
// Create X11_monitor_desc for this (the only) display
|
|
|
|
X11_monitor_desc *monitor = new X11_monitor_desc(VideoModes, default_depth, default_id);
|
|
|
|
VideoMonitors.push_back(monitor);
|
|
|
|
|
|
|
|
// Open display
|
|
|
|
return monitor->video_open();
|
1999-10-03 14:16:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Deinitialization
|
|
|
|
*/
|
|
|
|
|
2001-06-28 21:20:02 +00:00
|
|
|
// Close display
|
2002-04-25 11:00:31 +00:00
|
|
|
void X11_monitor_desc::video_close(void)
|
1999-10-03 14:16:26 +00:00
|
|
|
{
|
2001-07-14 15:02:49 +00:00
|
|
|
D(bug("video_close()\n"));
|
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
// Stop redraw thread
|
2001-06-30 20:18:36 +00:00
|
|
|
#ifdef HAVE_PTHREADS
|
1999-10-03 14:16:26 +00:00
|
|
|
if (redraw_thread_active) {
|
|
|
|
redraw_thread_cancel = true;
|
|
|
|
#ifdef HAVE_PTHREAD_CANCEL
|
|
|
|
pthread_cancel(redraw_thread);
|
|
|
|
#endif
|
|
|
|
pthread_join(redraw_thread, NULL);
|
|
|
|
}
|
2000-07-13 13:47:12 +00:00
|
|
|
#endif
|
2001-06-30 20:18:36 +00:00
|
|
|
redraw_thread_active = false;
|
1999-10-03 14:16:26 +00:00
|
|
|
|
|
|
|
// Unlock frame buffer
|
2000-11-03 18:21:43 +00:00
|
|
|
UNLOCK_FRAME_BUFFER;
|
2001-06-30 17:21:56 +00:00
|
|
|
XSync(x_display, false);
|
2001-07-14 15:02:49 +00:00
|
|
|
D(bug(" frame buffer unlocked\n"));
|
1999-10-03 14:16:26 +00:00
|
|
|
|
2000-09-22 17:16:31 +00:00
|
|
|
#ifdef ENABLE_VOSF
|
|
|
|
if (use_vosf) {
|
2001-07-07 09:14:47 +00:00
|
|
|
// Deinitialize VOSF
|
|
|
|
video_vosf_exit();
|
1999-10-03 14:16:26 +00:00
|
|
|
}
|
2001-06-28 21:20:02 +00:00
|
|
|
#endif
|
2001-06-30 17:21:56 +00:00
|
|
|
|
|
|
|
// Close display
|
|
|
|
delete drv;
|
|
|
|
drv = NULL;
|
|
|
|
|
|
|
|
// Free colormaps
|
|
|
|
if (cmap[0]) {
|
|
|
|
XFreeColormap(x_display, cmap[0]);
|
|
|
|
cmap[0] = 0;
|
|
|
|
}
|
|
|
|
if (cmap[1]) {
|
|
|
|
XFreeColormap(x_display, cmap[1]);
|
|
|
|
cmap[1] = 0;
|
|
|
|
}
|
2001-07-06 20:49:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoExit(void)
|
|
|
|
{
|
2002-04-25 11:00:31 +00:00
|
|
|
// Close displays
|
|
|
|
vector<monitor_desc *>::iterator i, end = VideoMonitors.end();
|
|
|
|
for (i = VideoMonitors.begin(); i != end; ++i)
|
|
|
|
dynamic_cast<X11_monitor_desc *>(*i)->video_close();
|
2001-06-30 17:21:56 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_XF86_VIDMODE
|
|
|
|
// Free video mode list
|
|
|
|
if (x_video_modes) {
|
|
|
|
XFree(x_video_modes);
|
|
|
|
x_video_modes = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENABLE_FBDEV_DGA
|
|
|
|
// Close framebuffer device
|
|
|
|
if (fbdev_fd >= 0) {
|
|
|
|
close(fbdev_fd);
|
|
|
|
fbdev_fd = -1;
|
|
|
|
}
|
|
|
|
#endif
|
2001-07-06 20:49:53 +00:00
|
|
|
|
|
|
|
// Free depth list
|
|
|
|
if (avail_depths) {
|
|
|
|
XFree(avail_depths);
|
|
|
|
avail_depths = NULL;
|
|
|
|
}
|
1999-10-03 14:16:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Close down full-screen mode (if bringing up error alerts is unsafe while in full-screen mode)
|
|
|
|
*/
|
|
|
|
|
|
|
|
void VideoQuitFullScreen(void)
|
|
|
|
{
|
|
|
|
D(bug("VideoQuitFullScreen()\n"));
|
2001-06-30 17:21:56 +00:00
|
|
|
quit_full_screen = true;
|
1999-10-03 14:16:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mac VBL interrupt
|
|
|
|
*/
|
|
|
|
|
|
|
|
void VideoInterrupt(void)
|
|
|
|
{
|
|
|
|
// Emergency quit requested? Then quit
|
|
|
|
if (emerg_quit)
|
|
|
|
QuitEmulator();
|
|
|
|
|
|
|
|
// Temporarily give up frame buffer lock (this is the point where
|
|
|
|
// we are suspended when the user presses Ctrl-Tab)
|
2000-11-03 18:21:43 +00:00
|
|
|
UNLOCK_FRAME_BUFFER;
|
|
|
|
LOCK_FRAME_BUFFER;
|
1999-10-03 14:16:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set palette
|
|
|
|
*/
|
|
|
|
|
2002-04-25 11:00:31 +00:00
|
|
|
void X11_monitor_desc::set_palette(uint8 *pal, int num_in)
|
1999-10-03 14:16:26 +00:00
|
|
|
{
|
2002-04-25 11:00:31 +00:00
|
|
|
const video_mode &mode = get_current_mode();
|
|
|
|
|
2000-11-03 18:21:43 +00:00
|
|
|
LOCK_PALETTE;
|
1999-10-03 14:16:26 +00:00
|
|
|
|
|
|
|
// Convert colors to XColor array
|
2001-07-01 21:09:30 +00:00
|
|
|
int num_out = 256;
|
2001-07-06 22:00:39 +00:00
|
|
|
bool stretch = false;
|
2002-04-25 11:00:31 +00:00
|
|
|
if (IsDirectMode(mode)) {
|
2001-07-01 21:09:30 +00:00
|
|
|
// If X is in 565 mode we have to stretch the gamma table from 32 to 64 entries
|
2001-07-01 00:46:38 +00:00
|
|
|
num_out = vis->map_entries;
|
2001-07-06 22:00:39 +00:00
|
|
|
stretch = true;
|
2001-06-30 22:23:44 +00:00
|
|
|
}
|
2002-04-25 11:00:31 +00:00
|
|
|
XColor *p = x_palette;
|
2001-06-30 22:23:44 +00:00
|
|
|
for (int i=0; i<num_out; i++) {
|
2001-07-06 22:00:39 +00:00
|
|
|
int c = (stretch ? (i * num_in) / num_out : i);
|
2001-06-30 22:23:44 +00:00
|
|
|
p->red = pal[c*3 + 0] * 0x0101;
|
|
|
|
p->green = pal[c*3 + 1] * 0x0101;
|
|
|
|
p->blue = pal[c*3 + 2] * 0x0101;
|
|
|
|
p++;
|
1999-10-03 14:16:26 +00:00
|
|
|
}
|
|
|
|
|
2001-07-01 19:57:55 +00:00
|
|
|
#ifdef ENABLE_VOSF
|
|
|
|
// Recalculate pixel color expansion map
|
2002-04-25 11:00:31 +00:00
|
|
|
if (!IsDirectMode(mode) && xdepth > 8) {
|
2001-07-01 21:09:30 +00:00
|
|
|
for (int i=0; i<256; i++) {
|
2001-07-03 15:59:49 +00:00
|
|
|
int c = i & (num_in-1); // If there are less than 256 colors, we repeat the first entries (this makes color expansion easier)
|
2001-07-01 21:09:30 +00:00
|
|
|
ExpandMap[i] = map_rgb(pal[c*3+0], pal[c*3+1], pal[c*3+2]);
|
|
|
|
}
|
2001-07-01 19:57:55 +00:00
|
|
|
|
|
|
|
// We have to redraw everything because the interpretation of pixel values changed
|
|
|
|
LOCK_VOSF;
|
|
|
|
PFLAG_SET_ALL;
|
|
|
|
UNLOCK_VOSF;
|
2002-04-25 11:00:31 +00:00
|
|
|
memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y);
|
2001-07-01 19:57:55 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
// Tell redraw thread to change palette
|
2002-04-25 11:00:31 +00:00
|
|
|
x_palette_changed = true;
|
1999-10-03 14:16:26 +00:00
|
|
|
|
2000-11-03 18:21:43 +00:00
|
|
|
UNLOCK_PALETTE;
|
1999-10-03 14:16:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 20:05:31 +00:00
|
|
|
/*
|
|
|
|
* Switch video mode
|
|
|
|
*/
|
|
|
|
|
2002-04-25 11:00:31 +00:00
|
|
|
void X11_monitor_desc::switch_to_current_mode(void)
|
2001-06-27 20:05:31 +00:00
|
|
|
{
|
2001-06-30 17:21:56 +00:00
|
|
|
// Close and reopen display
|
2001-06-28 21:20:02 +00:00
|
|
|
video_close();
|
2002-04-25 11:00:31 +00:00
|
|
|
video_open();
|
2001-06-27 20:05:31 +00:00
|
|
|
|
2001-06-30 17:21:56 +00:00
|
|
|
if (drv == NULL) {
|
|
|
|
ErrorAlert(STR_OPEN_WINDOW_ERR);
|
|
|
|
QuitEmulator();
|
1999-10-03 14:16:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2001-07-03 15:59:49 +00:00
|
|
|
* Translate key event to Mac keycode, returns -1 if no keycode was found
|
|
|
|
* and -2 if the key was recognized as a hotkey
|
1999-10-03 14:16:26 +00:00
|
|
|
*/
|
|
|
|
|
2001-07-03 15:59:49 +00:00
|
|
|
static int kc_decode(KeySym ks, bool key_down)
|
1999-10-03 14:16:26 +00:00
|
|
|
{
|
|
|
|
switch (ks) {
|
|
|
|
case XK_A: case XK_a: return 0x00;
|
|
|
|
case XK_B: case XK_b: return 0x0b;
|
|
|
|
case XK_C: case XK_c: return 0x08;
|
|
|
|
case XK_D: case XK_d: return 0x02;
|
|
|
|
case XK_E: case XK_e: return 0x0e;
|
|
|
|
case XK_F: case XK_f: return 0x03;
|
|
|
|
case XK_G: case XK_g: return 0x05;
|
|
|
|
case XK_H: case XK_h: return 0x04;
|
|
|
|
case XK_I: case XK_i: return 0x22;
|
|
|
|
case XK_J: case XK_j: return 0x26;
|
|
|
|
case XK_K: case XK_k: return 0x28;
|
|
|
|
case XK_L: case XK_l: return 0x25;
|
|
|
|
case XK_M: case XK_m: return 0x2e;
|
|
|
|
case XK_N: case XK_n: return 0x2d;
|
|
|
|
case XK_O: case XK_o: return 0x1f;
|
|
|
|
case XK_P: case XK_p: return 0x23;
|
|
|
|
case XK_Q: case XK_q: return 0x0c;
|
|
|
|
case XK_R: case XK_r: return 0x0f;
|
|
|
|
case XK_S: case XK_s: return 0x01;
|
|
|
|
case XK_T: case XK_t: return 0x11;
|
|
|
|
case XK_U: case XK_u: return 0x20;
|
|
|
|
case XK_V: case XK_v: return 0x09;
|
|
|
|
case XK_W: case XK_w: return 0x0d;
|
|
|
|
case XK_X: case XK_x: return 0x07;
|
|
|
|
case XK_Y: case XK_y: return 0x10;
|
|
|
|
case XK_Z: case XK_z: return 0x06;
|
|
|
|
|
|
|
|
case XK_1: case XK_exclam: return 0x12;
|
|
|
|
case XK_2: case XK_at: return 0x13;
|
|
|
|
case XK_3: case XK_numbersign: return 0x14;
|
|
|
|
case XK_4: case XK_dollar: return 0x15;
|
|
|
|
case XK_5: case XK_percent: return 0x17;
|
|
|
|
case XK_6: return 0x16;
|
|
|
|
case XK_7: return 0x1a;
|
|
|
|
case XK_8: return 0x1c;
|
|
|
|
case XK_9: return 0x19;
|
|
|
|
case XK_0: return 0x1d;
|
|
|
|
|
|
|
|
case XK_grave: case XK_asciitilde: return 0x0a;
|
|
|
|
case XK_minus: case XK_underscore: return 0x1b;
|
|
|
|
case XK_equal: case XK_plus: return 0x18;
|
|
|
|
case XK_bracketleft: case XK_braceleft: return 0x21;
|
|
|
|
case XK_bracketright: case XK_braceright: return 0x1e;
|
|
|
|
case XK_backslash: case XK_bar: return 0x2a;
|
|
|
|
case XK_semicolon: case XK_colon: return 0x29;
|
|
|
|
case XK_apostrophe: case XK_quotedbl: return 0x27;
|
|
|
|
case XK_comma: case XK_less: return 0x2b;
|
|
|
|
case XK_period: case XK_greater: return 0x2f;
|
|
|
|
case XK_slash: case XK_question: return 0x2c;
|
|
|
|
|
2001-07-03 15:59:49 +00:00
|
|
|
case XK_Tab: if (ctrl_down) {if (key_down) drv->suspend(); return -2;} else return 0x30;
|
1999-10-03 14:16:26 +00:00
|
|
|
case XK_Return: return 0x24;
|
|
|
|
case XK_space: return 0x31;
|
|
|
|
case XK_BackSpace: return 0x33;
|
|
|
|
|
|
|
|
case XK_Delete: return 0x75;
|
|
|
|
case XK_Insert: return 0x72;
|
|
|
|
case XK_Home: case XK_Help: return 0x73;
|
|
|
|
case XK_End: return 0x77;
|
|
|
|
#ifdef __hpux
|
|
|
|
case XK_Prior: return 0x74;
|
|
|
|
case XK_Next: return 0x79;
|
|
|
|
#else
|
|
|
|
case XK_Page_Up: return 0x74;
|
|
|
|
case XK_Page_Down: return 0x79;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case XK_Control_L: return 0x36;
|
|
|
|
case XK_Control_R: return 0x36;
|
|
|
|
case XK_Shift_L: return 0x38;
|
|
|
|
case XK_Shift_R: return 0x38;
|
|
|
|
case XK_Alt_L: return 0x37;
|
|
|
|
case XK_Alt_R: return 0x37;
|
|
|
|
case XK_Meta_L: return 0x3a;
|
|
|
|
case XK_Meta_R: return 0x3a;
|
|
|
|
case XK_Menu: return 0x32;
|
|
|
|
case XK_Caps_Lock: return 0x39;
|
|
|
|
case XK_Num_Lock: return 0x47;
|
|
|
|
|
|
|
|
case XK_Up: return 0x3e;
|
|
|
|
case XK_Down: return 0x3d;
|
|
|
|
case XK_Left: return 0x3b;
|
|
|
|
case XK_Right: return 0x3c;
|
|
|
|
|
2001-07-03 15:59:49 +00:00
|
|
|
case XK_Escape: if (ctrl_down) {if (key_down) { quit_full_screen = true; emerg_quit = true; } return -2;} else return 0x35;
|
1999-10-03 14:16:26 +00:00
|
|
|
|
2001-07-03 15:59:49 +00:00
|
|
|
case XK_F1: if (ctrl_down) {if (key_down) SysMountFirstFloppy(); return -2;} else return 0x7a;
|
1999-10-03 14:16:26 +00:00
|
|
|
case XK_F2: return 0x78;
|
|
|
|
case XK_F3: return 0x63;
|
|
|
|
case XK_F4: return 0x76;
|
2001-07-03 15:59:49 +00:00
|
|
|
case XK_F5: if (ctrl_down) {if (key_down) drv->toggle_mouse_grab(); return -2;} else return 0x60;
|
1999-10-03 14:16:26 +00:00
|
|
|
case XK_F6: return 0x61;
|
|
|
|
case XK_F7: return 0x62;
|
|
|
|
case XK_F8: return 0x64;
|
|
|
|
case XK_F9: return 0x65;
|
|
|
|
case XK_F10: return 0x6d;
|
|
|
|
case XK_F11: return 0x67;
|
|
|
|
case XK_F12: return 0x6f;
|
|
|
|
|
|
|
|
case XK_Print: return 0x69;
|
|
|
|
case XK_Scroll_Lock: return 0x6b;
|
|
|
|
case XK_Pause: return 0x71;
|
|
|
|
|
|
|
|
#if defined(XK_KP_Prior) && defined(XK_KP_Left) && defined(XK_KP_Insert) && defined (XK_KP_End)
|
|
|
|
case XK_KP_0: case XK_KP_Insert: return 0x52;
|
|
|
|
case XK_KP_1: case XK_KP_End: return 0x53;
|
|
|
|
case XK_KP_2: case XK_KP_Down: return 0x54;
|
|
|
|
case XK_KP_3: case XK_KP_Next: return 0x55;
|
|
|
|
case XK_KP_4: case XK_KP_Left: return 0x56;
|
|
|
|
case XK_KP_5: case XK_KP_Begin: return 0x57;
|
|
|
|
case XK_KP_6: case XK_KP_Right: return 0x58;
|
|
|
|
case XK_KP_7: case XK_KP_Home: return 0x59;
|
|
|
|
case XK_KP_8: case XK_KP_Up: return 0x5b;
|
|
|
|
case XK_KP_9: case XK_KP_Prior: return 0x5c;
|
|
|
|
case XK_KP_Decimal: case XK_KP_Delete: return 0x41;
|
|
|
|
#else
|
|
|
|
case XK_KP_0: return 0x52;
|
|
|
|
case XK_KP_1: return 0x53;
|
|
|
|
case XK_KP_2: return 0x54;
|
|
|
|
case XK_KP_3: return 0x55;
|
|
|
|
case XK_KP_4: return 0x56;
|
|
|
|
case XK_KP_5: return 0x57;
|
|
|
|
case XK_KP_6: return 0x58;
|
|
|
|
case XK_KP_7: return 0x59;
|
|
|
|
case XK_KP_8: return 0x5b;
|
|
|
|
case XK_KP_9: return 0x5c;
|
|
|
|
case XK_KP_Decimal: return 0x41;
|
|
|
|
#endif
|
|
|
|
case XK_KP_Add: return 0x45;
|
|
|
|
case XK_KP_Subtract: return 0x4e;
|
|
|
|
case XK_KP_Multiply: return 0x43;
|
|
|
|
case XK_KP_Divide: return 0x4b;
|
|
|
|
case XK_KP_Enter: return 0x4c;
|
|
|
|
case XK_KP_Equal: return 0x51;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2001-07-03 15:59:49 +00:00
|
|
|
static int event2keycode(XKeyEvent &ev, bool key_down)
|
1999-10-03 14:16:26 +00:00
|
|
|
{
|
|
|
|
KeySym ks;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
do {
|
2000-11-03 18:21:43 +00:00
|
|
|
ks = XLookupKeysym(&ev, i++);
|
2001-07-03 15:59:49 +00:00
|
|
|
int as = kc_decode(ks, key_down);
|
|
|
|
if (as >= 0)
|
|
|
|
return as;
|
|
|
|
if (as == -2)
|
1999-10-03 14:16:26 +00:00
|
|
|
return as;
|
|
|
|
} while (ks != NoSymbol);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* X event handling
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void handle_events(void)
|
|
|
|
{
|
2000-11-03 18:21:43 +00:00
|
|
|
while (XPending(x_display)) {
|
|
|
|
XEvent event;
|
|
|
|
XNextEvent(x_display, &event);
|
1999-10-03 14:16:26 +00:00
|
|
|
|
|
|
|
switch (event.type) {
|
2001-07-09 11:22:01 +00:00
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
// Mouse button
|
|
|
|
case ButtonPress: {
|
2000-11-03 18:21:43 +00:00
|
|
|
unsigned int button = event.xbutton.button;
|
1999-10-03 14:16:26 +00:00
|
|
|
if (button < 4)
|
|
|
|
ADBMouseDown(button - 1);
|
1999-10-25 20:22:35 +00:00
|
|
|
else if (button < 6) { // Wheel mouse
|
|
|
|
if (mouse_wheel_mode == 0) {
|
|
|
|
int key = (button == 5) ? 0x79 : 0x74; // Page up/down
|
|
|
|
ADBKeyDown(key);
|
|
|
|
ADBKeyUp(key);
|
|
|
|
} else {
|
|
|
|
int key = (button == 5) ? 0x3d : 0x3e; // Cursor up/down
|
|
|
|
for(int i=0; i<mouse_wheel_lines; i++) {
|
|
|
|
ADBKeyDown(key);
|
|
|
|
ADBKeyUp(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-10-03 14:16:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ButtonRelease: {
|
2000-11-03 18:21:43 +00:00
|
|
|
unsigned int button = event.xbutton.button;
|
1999-10-03 14:16:26 +00:00
|
|
|
if (button < 4)
|
|
|
|
ADBMouseUp(button - 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mouse moved
|
|
|
|
case MotionNotify:
|
2001-07-03 15:59:49 +00:00
|
|
|
drv->mouse_moved(event.xmotion.x, event.xmotion.y);
|
1999-10-03 14:16:26 +00:00
|
|
|
break;
|
|
|
|
|
2001-07-09 11:22:01 +00:00
|
|
|
// Mouse entered window
|
|
|
|
case EnterNotify:
|
|
|
|
if (event.xcrossing.mode != NotifyGrab && event.xcrossing.mode != NotifyUngrab)
|
|
|
|
drv->mouse_moved(event.xmotion.x, event.xmotion.y);
|
|
|
|
break;
|
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
// Keyboard
|
|
|
|
case KeyPress: {
|
2001-07-03 15:59:49 +00:00
|
|
|
int code = -1;
|
1999-10-03 14:16:26 +00:00
|
|
|
if (use_keycodes) {
|
2001-07-03 15:59:49 +00:00
|
|
|
if (event2keycode(event.xkey, true) != -2) // This is called to process the hotkeys
|
|
|
|
code = keycode_table[event.xkey.keycode & 0xff];
|
1999-10-03 14:16:26 +00:00
|
|
|
} else
|
2001-07-03 15:59:49 +00:00
|
|
|
code = event2keycode(event.xkey, true);
|
|
|
|
if (code >= 0) {
|
1999-10-03 14:16:26 +00:00
|
|
|
if (!emul_suspended) {
|
1999-10-03 19:43:28 +00:00
|
|
|
if (code == 0x39) { // Caps Lock pressed
|
|
|
|
if (caps_on) {
|
|
|
|
ADBKeyUp(code);
|
|
|
|
caps_on = false;
|
|
|
|
} else {
|
|
|
|
ADBKeyDown(code);
|
|
|
|
caps_on = true;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
ADBKeyDown(code);
|
1999-10-03 14:16:26 +00:00
|
|
|
if (code == 0x36)
|
|
|
|
ctrl_down = true;
|
|
|
|
} else {
|
|
|
|
if (code == 0x31)
|
2001-06-30 17:21:56 +00:00
|
|
|
drv->resume(); // Space wakes us up
|
1999-10-03 14:16:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KeyRelease: {
|
2001-07-03 15:59:49 +00:00
|
|
|
int code = -1;
|
1999-10-03 14:16:26 +00:00
|
|
|
if (use_keycodes) {
|
2001-07-03 15:59:49 +00:00
|
|
|
if (event2keycode(event.xkey, false) != -2) // This is called to process the hotkeys
|
|
|
|
code = keycode_table[event.xkey.keycode & 0xff];
|
1999-10-03 14:16:26 +00:00
|
|
|
} else
|
2001-07-03 15:59:49 +00:00
|
|
|
code = event2keycode(event.xkey, false);
|
|
|
|
if (code >= 0 && code != 0x39) { // Don't propagate Caps Lock releases
|
1999-10-03 14:16:26 +00:00
|
|
|
ADBKeyUp(code);
|
|
|
|
if (code == 0x36)
|
|
|
|
ctrl_down = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hidden parts exposed, force complete refresh of window
|
|
|
|
case Expose:
|
2000-02-11 17:20:44 +00:00
|
|
|
if (display_type == DISPLAY_WINDOW) {
|
2002-04-25 11:00:31 +00:00
|
|
|
const video_mode &mode = VideoMonitors[0]->get_current_mode();
|
2000-09-22 17:16:31 +00:00
|
|
|
#ifdef ENABLE_VOSF
|
2000-09-25 22:33:49 +00:00
|
|
|
if (use_vosf) { // VOSF refresh
|
2000-11-03 18:21:43 +00:00
|
|
|
LOCK_VOSF;
|
2000-09-25 21:49:19 +00:00
|
|
|
PFLAG_SET_ALL;
|
2000-11-03 18:21:43 +00:00
|
|
|
UNLOCK_VOSF;
|
2002-04-25 11:00:31 +00:00
|
|
|
memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y);
|
2000-09-25 21:49:19 +00:00
|
|
|
}
|
2000-09-25 22:33:49 +00:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if (frame_skip == 0) { // Dynamic refresh
|
|
|
|
int x1, y1;
|
|
|
|
for (y1=0; y1<16; y1++)
|
|
|
|
for (x1=0; x1<16; x1++)
|
|
|
|
updt_box[x1][y1] = true;
|
|
|
|
nr_boxes = 16 * 16;
|
|
|
|
} else // Static refresh
|
2002-04-25 11:00:31 +00:00
|
|
|
memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y);
|
2000-02-11 17:20:44 +00:00
|
|
|
}
|
1999-10-03 14:16:26 +00:00
|
|
|
break;
|
2000-10-27 17:01:40 +00:00
|
|
|
|
2000-11-03 18:21:43 +00:00
|
|
|
// Window "close" widget clicked
|
|
|
|
case ClientMessage:
|
2000-11-03 18:27:55 +00:00
|
|
|
if (event.xclient.format == 32 && event.xclient.data.l[0] == WM_DELETE_WINDOW) {
|
|
|
|
ADBKeyDown(0x7f); // Power key
|
|
|
|
ADBKeyUp(0x7f);
|
|
|
|
}
|
2000-10-27 17:01:40 +00:00
|
|
|
break;
|
1999-10-03 14:16:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Window display update
|
|
|
|
*/
|
|
|
|
|
2000-07-13 16:12:33 +00:00
|
|
|
// Dynamic display update (variable frame rate for each box)
|
2001-06-30 17:21:56 +00:00
|
|
|
static void update_display_dynamic(int ticker, driver_window *drv)
|
1999-10-03 14:16:26 +00:00
|
|
|
{
|
2000-07-22 16:07:23 +00:00
|
|
|
int y1, y2, y2s, y2a, i, x1, xm, xmo, ymo, yo, yi, yil, xi;
|
2000-02-11 17:20:44 +00:00
|
|
|
int xil = 0;
|
|
|
|
int rxm = 0, rxmo = 0;
|
2002-04-25 11:00:31 +00:00
|
|
|
const video_mode &mode = drv->monitor.get_current_mode();
|
|
|
|
int bytes_per_row = mode.bytes_per_row;
|
|
|
|
int bytes_per_pixel = mode.bytes_per_row / mode.x;
|
|
|
|
int rx = mode.bytes_per_row / 16;
|
|
|
|
int ry = mode.y / 16;
|
2000-02-11 17:20:44 +00:00
|
|
|
int max_box;
|
|
|
|
|
|
|
|
y2s = sm_uptd[ticker % 8];
|
|
|
|
y2a = 8;
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
if (ticker % (2 << i))
|
1999-10-03 14:16:26 +00:00
|
|
|
break;
|
2000-02-11 17:20:44 +00:00
|
|
|
max_box = sm_no_boxes[i];
|
|
|
|
|
|
|
|
if (y2a) {
|
|
|
|
for (y1=0; y1<16; y1++) {
|
|
|
|
for (y2=y2s; y2 < ry; y2 += y2a) {
|
|
|
|
i = ((y1 * ry) + y2) * bytes_per_row;
|
|
|
|
for (x1=0; x1<16; x1++, i += rx) {
|
|
|
|
if (updt_box[x1][y1] == false) {
|
|
|
|
if (memcmp(&the_buffer_copy[i], &the_buffer[i], rx)) {
|
|
|
|
updt_box[x1][y1] = true;
|
|
|
|
nr_boxes++;
|
|
|
|
}
|
1999-10-03 14:16:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-02-11 17:20:44 +00:00
|
|
|
}
|
|
|
|
}
|
1999-10-03 14:16:26 +00:00
|
|
|
|
2000-02-11 17:20:44 +00:00
|
|
|
if ((nr_boxes <= max_box) && (nr_boxes)) {
|
|
|
|
for (y1=0; y1<16; y1++) {
|
|
|
|
for (x1=0; x1<16; x1++) {
|
|
|
|
if (updt_box[x1][y1] == true) {
|
|
|
|
if (rxm == 0)
|
|
|
|
xm = x1;
|
|
|
|
rxm += rx;
|
|
|
|
updt_box[x1][y1] = false;
|
1999-10-03 14:16:26 +00:00
|
|
|
}
|
2000-02-11 17:20:44 +00:00
|
|
|
if (((updt_box[x1+1][y1] == false) || (x1 == 15)) && (rxm)) {
|
|
|
|
if ((rxmo != rxm) || (xmo != xm) || (yo != y1 - 1)) {
|
|
|
|
if (rxmo) {
|
|
|
|
xi = xmo * rx;
|
|
|
|
yi = ymo * ry;
|
|
|
|
xil = rxmo;
|
|
|
|
yil = (yo - ymo +1) * ry;
|
|
|
|
}
|
|
|
|
rxmo = rxm;
|
|
|
|
xmo = xm;
|
|
|
|
ymo = y1;
|
1999-10-03 14:16:26 +00:00
|
|
|
}
|
2000-02-11 17:20:44 +00:00
|
|
|
rxm = 0;
|
|
|
|
yo = y1;
|
|
|
|
}
|
|
|
|
if (xil) {
|
|
|
|
i = (yi * bytes_per_row) + xi;
|
|
|
|
for (y2=0; y2 < yil; y2++, i += bytes_per_row)
|
|
|
|
memcpy(&the_buffer_copy[i], &the_buffer[i], xil);
|
2002-04-25 11:00:31 +00:00
|
|
|
if (mode.depth == VDEPTH_1BIT) {
|
2001-06-30 17:21:56 +00:00
|
|
|
if (drv->have_shm)
|
|
|
|
XShmPutImage(x_display, drv->w, drv->gc, drv->img, xi * 8, yi, xi * 8, yi, xil * 8, yil, 0);
|
2000-02-11 17:20:44 +00:00
|
|
|
else
|
2001-06-30 17:21:56 +00:00
|
|
|
XPutImage(x_display, drv->w, drv->gc, drv->img, xi * 8, yi, xi * 8, yi, xil * 8, yil);
|
2000-02-11 17:20:44 +00:00
|
|
|
} else {
|
2001-06-30 17:21:56 +00:00
|
|
|
if (drv->have_shm)
|
|
|
|
XShmPutImage(x_display, drv->w, drv->gc, drv->img, xi / bytes_per_pixel, yi, xi / bytes_per_pixel, yi, xil / bytes_per_pixel, yil, 0);
|
2000-02-11 17:20:44 +00:00
|
|
|
else
|
2001-06-30 17:21:56 +00:00
|
|
|
XPutImage(x_display, drv->w, drv->gc, drv->img, xi / bytes_per_pixel, yi, xi / bytes_per_pixel, yi, xil / bytes_per_pixel, yil);
|
1999-10-03 14:16:26 +00:00
|
|
|
}
|
2000-02-11 17:20:44 +00:00
|
|
|
xil = 0;
|
1999-10-03 14:16:26 +00:00
|
|
|
}
|
2000-02-11 17:20:44 +00:00
|
|
|
if ((x1 == 15) && (y1 == 15) && (rxmo)) {
|
|
|
|
x1--;
|
|
|
|
xi = xmo * rx;
|
|
|
|
yi = ymo * ry;
|
|
|
|
xil = rxmo;
|
|
|
|
yil = (yo - ymo +1) * ry;
|
|
|
|
rxmo = 0;
|
1999-10-03 14:16:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-02-11 17:20:44 +00:00
|
|
|
nr_boxes = 0;
|
1999-10-03 14:16:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-13 16:12:33 +00:00
|
|
|
// Static display update (fixed frame rate, but incremental)
|
2001-06-30 17:21:56 +00:00
|
|
|
static void update_display_static(driver_window *drv)
|
2000-07-13 16:12:33 +00:00
|
|
|
{
|
|
|
|
// Incremental update code
|
2001-07-11 19:26:14 +00:00
|
|
|
unsigned wide = 0, high = 0, x1, x2, y1, y2, i, j;
|
2002-04-25 11:00:31 +00:00
|
|
|
const video_mode &mode = drv->monitor.get_current_mode();
|
|
|
|
int bytes_per_row = mode.bytes_per_row;
|
|
|
|
int bytes_per_pixel = mode.bytes_per_row / mode.x;
|
2000-07-13 16:12:33 +00:00
|
|
|
uint8 *p, *p2;
|
|
|
|
|
|
|
|
// Check for first line from top and first line from bottom that have changed
|
|
|
|
y1 = 0;
|
2002-04-25 11:00:31 +00:00
|
|
|
for (j=0; j<mode.y; j++) {
|
2000-07-13 16:12:33 +00:00
|
|
|
if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) {
|
|
|
|
y1 = j;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
y2 = y1 - 1;
|
2002-04-25 11:00:31 +00:00
|
|
|
for (j=mode.y-1; j>=y1; j--) {
|
2000-07-13 16:12:33 +00:00
|
|
|
if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) {
|
|
|
|
y2 = j;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
high = y2 - y1 + 1;
|
|
|
|
|
|
|
|
// Check for first column from left and first column from right that have changed
|
|
|
|
if (high) {
|
2002-04-25 11:00:31 +00:00
|
|
|
if (mode.depth == VDEPTH_1BIT) {
|
|
|
|
x1 = mode.x - 1;
|
2000-07-13 16:12:33 +00:00
|
|
|
for (j=y1; j<=y2; j++) {
|
|
|
|
p = &the_buffer[j * bytes_per_row];
|
|
|
|
p2 = &the_buffer_copy[j * bytes_per_row];
|
|
|
|
for (i=0; i<(x1>>3); i++) {
|
|
|
|
if (*p != *p2) {
|
|
|
|
x1 = i << 3;
|
|
|
|
break;
|
|
|
|
}
|
2000-07-22 18:12:35 +00:00
|
|
|
p++; p2++;
|
2000-07-13 16:12:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
x2 = x1;
|
|
|
|
for (j=y1; j<=y2; j++) {
|
|
|
|
p = &the_buffer[j * bytes_per_row];
|
|
|
|
p2 = &the_buffer_copy[j * bytes_per_row];
|
|
|
|
p += bytes_per_row;
|
|
|
|
p2 += bytes_per_row;
|
2002-04-25 11:00:31 +00:00
|
|
|
for (i=(mode.x>>3); i>(x2>>3); i--) {
|
2000-07-22 18:12:35 +00:00
|
|
|
p--; p2--;
|
2000-07-13 16:12:33 +00:00
|
|
|
if (*p != *p2) {
|
2000-10-13 16:47:52 +00:00
|
|
|
x2 = (i << 3) + 7;
|
2000-07-13 16:12:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-10-13 16:47:52 +00:00
|
|
|
wide = x2 - x1 + 1;
|
2000-07-13 16:12:33 +00:00
|
|
|
|
|
|
|
// Update copy of the_buffer
|
|
|
|
if (high && wide) {
|
|
|
|
for (j=y1; j<=y2; j++) {
|
|
|
|
i = j * bytes_per_row + (x1 >> 3);
|
|
|
|
memcpy(the_buffer_copy + i, the_buffer + i, wide >> 3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2002-04-25 11:00:31 +00:00
|
|
|
x1 = mode.x;
|
2000-07-13 16:12:33 +00:00
|
|
|
for (j=y1; j<=y2; j++) {
|
|
|
|
p = &the_buffer[j * bytes_per_row];
|
|
|
|
p2 = &the_buffer_copy[j * bytes_per_row];
|
2000-07-22 18:12:35 +00:00
|
|
|
for (i=0; i<x1*bytes_per_pixel; i++) {
|
|
|
|
if (*p != *p2) {
|
|
|
|
x1 = i / bytes_per_pixel;
|
2000-07-13 16:12:33 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-07-22 18:12:35 +00:00
|
|
|
p++; p2++;
|
2000-07-13 16:12:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
x2 = x1;
|
|
|
|
for (j=y1; j<=y2; j++) {
|
|
|
|
p = &the_buffer[j * bytes_per_row];
|
|
|
|
p2 = &the_buffer_copy[j * bytes_per_row];
|
|
|
|
p += bytes_per_row;
|
|
|
|
p2 += bytes_per_row;
|
2002-04-25 11:00:31 +00:00
|
|
|
for (i=mode.x*bytes_per_pixel; i>x2*bytes_per_pixel; i--) {
|
2000-07-22 18:12:35 +00:00
|
|
|
p--;
|
|
|
|
p2--;
|
|
|
|
if (*p != *p2) {
|
|
|
|
x2 = i / bytes_per_pixel;
|
2000-07-13 16:12:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
wide = x2 - x1;
|
|
|
|
|
|
|
|
// Update copy of the_buffer
|
|
|
|
if (high && wide) {
|
|
|
|
for (j=y1; j<=y2; j++) {
|
|
|
|
i = j * bytes_per_row + x1 * bytes_per_pixel;
|
|
|
|
memcpy(the_buffer_copy + i, the_buffer + i, bytes_per_pixel * wide);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Refresh display
|
|
|
|
if (high && wide) {
|
2001-06-30 17:21:56 +00:00
|
|
|
if (drv->have_shm)
|
|
|
|
XShmPutImage(x_display, drv->w, drv->gc, drv->img, x1, y1, x1, y1, wide, high, 0);
|
2000-07-13 16:12:33 +00:00
|
|
|
else
|
2001-06-30 17:21:56 +00:00
|
|
|
XPutImage(x_display, drv->w, drv->gc, drv->img, x1, y1, x1, y1, wide, high);
|
2000-07-13 16:12:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
|
2000-09-22 17:16:31 +00:00
|
|
|
/*
|
|
|
|
* Screen refresh functions
|
|
|
|
*/
|
|
|
|
|
2001-01-11 16:38:48 +00:00
|
|
|
// We suggest the compiler to inline the next two functions so that it
|
|
|
|
// may specialise the code according to the current screen depth and
|
2001-01-11 18:00:40 +00:00
|
|
|
// display type. A clever compiler would do that job by itself though...
|
2001-01-11 16:38:48 +00:00
|
|
|
|
|
|
|
// NOTE: update_display_vosf is inlined too
|
2000-09-22 17:16:31 +00:00
|
|
|
|
|
|
|
static inline void possibly_quit_dga_mode()
|
|
|
|
{
|
2001-07-03 15:59:49 +00:00
|
|
|
// Quit DGA mode if requested (something terrible has happened and we
|
|
|
|
// want to give control back to the user)
|
2000-09-22 17:16:31 +00:00
|
|
|
if (quit_full_screen) {
|
|
|
|
quit_full_screen = false;
|
2001-06-30 17:21:56 +00:00
|
|
|
delete drv;
|
|
|
|
drv = NULL;
|
2000-09-22 17:16:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-03 15:59:49 +00:00
|
|
|
static inline void possibly_ungrab_mouse()
|
|
|
|
{
|
|
|
|
// Ungrab mouse if requested (something terrible has happened and we
|
|
|
|
// want to give control back to the user)
|
|
|
|
if (quit_full_screen) {
|
|
|
|
quit_full_screen = false;
|
|
|
|
if (drv)
|
|
|
|
drv->ungrab_mouse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-30 17:21:56 +00:00
|
|
|
static inline void handle_palette_changes(void)
|
2000-09-22 17:16:31 +00:00
|
|
|
{
|
2000-11-03 18:21:43 +00:00
|
|
|
LOCK_PALETTE;
|
|
|
|
|
2002-04-25 11:00:31 +00:00
|
|
|
if (x_palette_changed) {
|
|
|
|
x_palette_changed = false;
|
2001-06-30 17:21:56 +00:00
|
|
|
drv->update_palette();
|
2000-09-22 17:16:31 +00:00
|
|
|
}
|
2000-11-03 18:21:43 +00:00
|
|
|
|
|
|
|
UNLOCK_PALETTE;
|
2000-09-22 17:16:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void video_refresh_dga(void)
|
|
|
|
{
|
|
|
|
// Quit DGA mode if requested
|
|
|
|
possibly_quit_dga_mode();
|
|
|
|
}
|
|
|
|
|
2000-10-09 17:05:17 +00:00
|
|
|
#ifdef ENABLE_VOSF
|
2000-09-22 17:16:31 +00:00
|
|
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING
|
|
|
|
static void video_refresh_dga_vosf(void)
|
|
|
|
{
|
|
|
|
// Quit DGA mode if requested
|
|
|
|
possibly_quit_dga_mode();
|
|
|
|
|
|
|
|
// Update display (VOSF variant)
|
|
|
|
static int tick_counter = 0;
|
|
|
|
if (++tick_counter >= frame_skip) {
|
|
|
|
tick_counter = 0;
|
2001-01-28 14:05:19 +00:00
|
|
|
if (mainBuffer.dirty) {
|
|
|
|
LOCK_VOSF;
|
|
|
|
update_display_dga_vosf();
|
|
|
|
UNLOCK_VOSF;
|
|
|
|
}
|
2000-09-22 17:16:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void video_refresh_window_vosf(void)
|
|
|
|
{
|
2001-07-03 15:59:49 +00:00
|
|
|
// Ungrab mouse if requested
|
|
|
|
possibly_ungrab_mouse();
|
2000-09-22 17:16:31 +00:00
|
|
|
|
|
|
|
// Update display (VOSF variant)
|
|
|
|
static int tick_counter = 0;
|
|
|
|
if (++tick_counter >= frame_skip) {
|
|
|
|
tick_counter = 0;
|
2001-01-28 14:05:19 +00:00
|
|
|
if (mainBuffer.dirty) {
|
|
|
|
LOCK_VOSF;
|
2001-06-30 17:21:56 +00:00
|
|
|
update_display_window_vosf(static_cast<driver_window *>(drv));
|
2001-01-28 14:05:19 +00:00
|
|
|
UNLOCK_VOSF;
|
2001-03-06 18:41:12 +00:00
|
|
|
XSync(x_display, false); // Let the server catch up
|
2001-01-28 14:05:19 +00:00
|
|
|
}
|
2000-09-22 17:16:31 +00:00
|
|
|
}
|
|
|
|
}
|
2000-10-09 17:05:17 +00:00
|
|
|
#endif // def ENABLE_VOSF
|
2000-09-22 17:16:31 +00:00
|
|
|
|
|
|
|
static void video_refresh_window_static(void)
|
|
|
|
{
|
2001-07-03 15:59:49 +00:00
|
|
|
// Ungrab mouse if requested
|
|
|
|
possibly_ungrab_mouse();
|
|
|
|
|
2000-09-22 17:16:31 +00:00
|
|
|
// Update display (static variant)
|
|
|
|
static int tick_counter = 0;
|
|
|
|
if (++tick_counter >= frame_skip) {
|
|
|
|
tick_counter = 0;
|
2001-06-30 17:21:56 +00:00
|
|
|
update_display_static(static_cast<driver_window *>(drv));
|
2000-09-22 17:16:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void video_refresh_window_dynamic(void)
|
|
|
|
{
|
2001-07-03 15:59:49 +00:00
|
|
|
// Ungrab mouse if requested
|
|
|
|
possibly_ungrab_mouse();
|
|
|
|
|
2000-09-22 17:16:31 +00:00
|
|
|
// Update display (dynamic variant)
|
|
|
|
static int tick_counter = 0;
|
|
|
|
tick_counter++;
|
2001-06-30 17:21:56 +00:00
|
|
|
update_display_dynamic(tick_counter, static_cast<driver_window *>(drv));
|
2000-09-22 17:16:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
/*
|
|
|
|
* Thread for screen refresh, input handling etc.
|
|
|
|
*/
|
|
|
|
|
2001-06-28 21:20:02 +00:00
|
|
|
static void VideoRefreshInit(void)
|
2000-09-22 17:16:31 +00:00
|
|
|
{
|
|
|
|
// TODO: set up specialised 8bpp VideoRefresh handlers ?
|
|
|
|
if (display_type == DISPLAY_DGA) {
|
2000-10-09 17:05:17 +00:00
|
|
|
#if ENABLE_VOSF && (REAL_ADDRESSING || DIRECT_ADDRESSING)
|
2000-09-22 17:16:31 +00:00
|
|
|
if (use_vosf)
|
|
|
|
video_refresh = video_refresh_dga_vosf;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
video_refresh = video_refresh_dga;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
#ifdef ENABLE_VOSF
|
|
|
|
if (use_vosf)
|
|
|
|
video_refresh = video_refresh_window_vosf;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if (frame_skip == 0)
|
|
|
|
video_refresh = video_refresh_window_dynamic;
|
|
|
|
else
|
|
|
|
video_refresh = video_refresh_window_static;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-09 11:22:01 +00:00
|
|
|
// This function is called on non-threaded platforms from a timer interrupt
|
2000-09-22 17:16:31 +00:00
|
|
|
void VideoRefresh(void)
|
|
|
|
{
|
2001-06-30 20:18:36 +00:00
|
|
|
// We need to check redraw_thread_active to inhibit refreshed during
|
|
|
|
// mode changes on non-threaded platforms
|
2001-07-09 11:22:01 +00:00
|
|
|
if (!redraw_thread_active)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Handle X events
|
|
|
|
handle_events();
|
|
|
|
|
|
|
|
// Handle palette changes
|
|
|
|
handle_palette_changes();
|
|
|
|
|
|
|
|
// Update display
|
|
|
|
video_refresh();
|
2000-09-22 17:16:31 +00:00
|
|
|
}
|
|
|
|
|
2001-07-09 11:22:01 +00:00
|
|
|
const int VIDEO_REFRESH_HZ = 60;
|
|
|
|
const int VIDEO_REFRESH_DELAY = 1000000 / VIDEO_REFRESH_HZ;
|
|
|
|
|
2000-07-13 13:47:12 +00:00
|
|
|
#ifdef HAVE_PTHREADS
|
|
|
|
static void *redraw_func(void *arg)
|
|
|
|
{
|
2001-07-09 11:22:01 +00:00
|
|
|
int fd = ConnectionNumber(x_display);
|
|
|
|
|
2000-09-22 17:16:31 +00:00
|
|
|
uint64 start = GetTicks_usec();
|
|
|
|
int64 ticks = 0;
|
2001-07-09 11:22:01 +00:00
|
|
|
uint64 next = GetTicks_usec() + VIDEO_REFRESH_DELAY;
|
|
|
|
|
2000-07-13 13:47:12 +00:00
|
|
|
while (!redraw_thread_cancel) {
|
2001-07-09 11:22:01 +00:00
|
|
|
|
2000-07-22 18:12:35 +00:00
|
|
|
int64 delay = next - GetTicks_usec();
|
2001-07-09 11:22:01 +00:00
|
|
|
if (delay < -VIDEO_REFRESH_DELAY) {
|
|
|
|
|
|
|
|
// We are lagging far behind, so we reset the delay mechanism
|
2000-07-22 18:12:35 +00:00
|
|
|
next = GetTicks_usec();
|
2001-07-09 11:22:01 +00:00
|
|
|
|
|
|
|
} else if (delay <= 0) {
|
|
|
|
|
|
|
|
// Delay expired, refresh display
|
|
|
|
handle_events();
|
|
|
|
handle_palette_changes();
|
|
|
|
video_refresh();
|
|
|
|
next += VIDEO_REFRESH_DELAY;
|
|
|
|
ticks++;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// No display refresh pending, check for X events
|
|
|
|
fd_set readfds;
|
|
|
|
FD_ZERO(&readfds);
|
|
|
|
FD_SET(fd, &readfds);
|
|
|
|
struct timeval timeout;
|
|
|
|
timeout.tv_sec = 0;
|
|
|
|
timeout.tv_usec = delay;
|
|
|
|
if (select(fd+1, &readfds, NULL, NULL, &timeout) > 0)
|
|
|
|
handle_events();
|
|
|
|
}
|
1999-10-03 14:16:26 +00:00
|
|
|
}
|
2001-07-09 11:22:01 +00:00
|
|
|
|
2000-09-22 17:16:31 +00:00
|
|
|
uint64 end = GetTicks_usec();
|
2001-07-09 11:22:01 +00:00
|
|
|
D(bug("%Ld refreshes in %Ld usec = %f refreshes/sec\n", ticks, end - start, ticks * 1000000.0 / (end - start)));
|
1999-10-03 14:16:26 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2000-07-13 13:47:12 +00:00
|
|
|
#endif
|