27 |
|
* Ctrl-F5 = grab mouse (in windowed mode) |
28 |
|
* |
29 |
|
* FIXMEs and TODOs: |
30 |
+ |
* - Windows requires an extra mouse event to update the actual cursor image? |
31 |
|
* - Ctr-Tab for suspend/resume but how? SDL does not support that for non-Linux |
32 |
|
* - Ctrl-Fn doesn't generate SDL_KEYDOWN events (SDL bug?) |
33 |
|
* - Mouse acceleration, there is no API in SDL yet for that |
34 |
|
* - Force relative mode in Grab mode even if SDL provides absolute coordinates? |
34 |
– |
* - Fullscreen mode |
35 |
|
* - Gamma tables support is likely to be broken here |
36 |
|
* - Events processing is bound to the general emulation thread as SDL requires |
37 |
|
* to PumpEvents() within the same thread as the one that called SetVideoMode(). |
38 |
|
* Besides, there can't seem to be a way to call SetVideoMode() from a child thread. |
39 |
– |
* - Refresh performance is still slow. Use SDL_CreateRGBSurface()? |
39 |
|
* - Backport hw cursor acceleration to Basilisk II? |
40 |
|
* - Factor out code |
41 |
|
*/ |
48 |
|
#include <errno.h> |
49 |
|
#include <vector> |
50 |
|
|
51 |
+ |
#ifdef WIN32 |
52 |
+ |
#include <malloc.h> /* alloca() */ |
53 |
+ |
#endif |
54 |
+ |
|
55 |
|
#include "cpu_emulation.h" |
56 |
|
#include "main.h" |
57 |
|
#include "adb.h" |
1987 |
|
} |
1988 |
|
} |
1989 |
|
|
1990 |
+ |
// Static display update (fixed frame rate, bounding boxes based) |
1991 |
+ |
// XXX use NQD bounding boxes to help detect dirty areas? |
1992 |
+ |
static void update_display_static_bbox(driver_window *drv) |
1993 |
+ |
{ |
1994 |
+ |
const VIDEO_MODE &mode = drv->mode; |
1995 |
+ |
|
1996 |
+ |
// Allocate bounding boxes for SDL_UpdateRects() |
1997 |
+ |
const int N_PIXELS = 64; |
1998 |
+ |
const int n_x_boxes = (VIDEO_MODE_X + N_PIXELS - 1) / N_PIXELS; |
1999 |
+ |
const int n_y_boxes = (VIDEO_MODE_Y + N_PIXELS - 1) / N_PIXELS; |
2000 |
+ |
SDL_Rect *boxes = (SDL_Rect *)alloca(sizeof(SDL_Rect) * n_x_boxes * n_y_boxes); |
2001 |
+ |
int nr_boxes = 0; |
2002 |
+ |
|
2003 |
+ |
// Lock surface, if required |
2004 |
+ |
if (SDL_MUSTLOCK(drv->s)) |
2005 |
+ |
SDL_LockSurface(drv->s); |
2006 |
+ |
|
2007 |
+ |
// Update the surface from Mac screen |
2008 |
+ |
const int bytes_per_row = VIDEO_MODE_ROW_BYTES; |
2009 |
+ |
const int bytes_per_pixel = bytes_per_row / VIDEO_MODE_X; |
2010 |
+ |
int x, y; |
2011 |
+ |
for (y = 0; y < VIDEO_MODE_Y; y += N_PIXELS) { |
2012 |
+ |
int h = N_PIXELS; |
2013 |
+ |
if (h > VIDEO_MODE_Y - y) |
2014 |
+ |
h = VIDEO_MODE_Y - y; |
2015 |
+ |
for (x = 0; x < VIDEO_MODE_X; x += N_PIXELS) { |
2016 |
+ |
int w = N_PIXELS; |
2017 |
+ |
if (w > VIDEO_MODE_X - x) |
2018 |
+ |
w = VIDEO_MODE_X - x; |
2019 |
+ |
const int xs = w * bytes_per_pixel; |
2020 |
+ |
const int xb = x * bytes_per_pixel; |
2021 |
+ |
bool dirty = false; |
2022 |
+ |
for (int j = y; j < (y + h); j++) { |
2023 |
+ |
const int yb = j * bytes_per_row; |
2024 |
+ |
if (memcmp(&the_buffer[yb + xb], &the_buffer_copy[yb + xb], xs) != 0) { |
2025 |
+ |
memcpy(&the_buffer_copy[yb + xb], &the_buffer[yb + xb], xs); |
2026 |
+ |
Screen_blit((uint8 *)drv->s->pixels + yb + xb, the_buffer + yb + xb, xs); |
2027 |
+ |
dirty = true; |
2028 |
+ |
} |
2029 |
+ |
} |
2030 |
+ |
if (dirty) { |
2031 |
+ |
boxes[nr_boxes].x = x; |
2032 |
+ |
boxes[nr_boxes].y = y; |
2033 |
+ |
boxes[nr_boxes].w = w; |
2034 |
+ |
boxes[nr_boxes].h = h; |
2035 |
+ |
nr_boxes++; |
2036 |
+ |
} |
2037 |
+ |
} |
2038 |
+ |
} |
2039 |
+ |
|
2040 |
+ |
// Unlock surface, if required |
2041 |
+ |
if (SDL_MUSTLOCK(drv->s)) |
2042 |
+ |
SDL_UnlockSurface(drv->s); |
2043 |
+ |
|
2044 |
+ |
// Refresh display |
2045 |
+ |
if (nr_boxes) |
2046 |
+ |
SDL_UpdateRects(drv->s, nr_boxes, boxes); |
2047 |
+ |
} |
2048 |
+ |
|
2049 |
|
|
2050 |
|
// We suggest the compiler to inline the next two functions so that it |
2051 |
|
// may specialise the code according to the current screen depth and |
2140 |
|
static int tick_counter = 0; |
2141 |
|
if (++tick_counter >= frame_skip) { |
2142 |
|
tick_counter = 0; |
2143 |
< |
update_display_static(static_cast<driver_window *>(drv)); |
2143 |
> |
const VIDEO_MODE &mode = drv->mode; |
2144 |
> |
if ((int)VIDEO_MODE_DEPTH >= VIDEO_DEPTH_8BIT) |
2145 |
> |
update_display_static_bbox(static_cast<driver_window *>(drv)); |
2146 |
> |
else |
2147 |
> |
update_display_static(static_cast<driver_window *>(drv)); |
2148 |
|
} |
2149 |
|
} |
2150 |
|
|
2189 |
|
LOCK_EVENTS; |
2190 |
|
SDL_FreeCursor(sdl_cursor); |
2191 |
|
sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, MacCursor[2], MacCursor[3]); |
2192 |
< |
if (sdl_cursor) |
2192 |
> |
if (sdl_cursor) { |
2193 |
|
SDL_SetCursor(sdl_cursor); |
2194 |
+ |
#ifdef WIN32 |
2195 |
+ |
// XXX Windows apparently needs an extra mouse event to |
2196 |
+ |
// make the new cursor image visible |
2197 |
+ |
int visible = SDL_ShowCursor(-1); |
2198 |
+ |
if (visible) { |
2199 |
+ |
int x, y; |
2200 |
+ |
SDL_GetMouseState(&x, &y); |
2201 |
+ |
SDL_WarpMouse(x, y); |
2202 |
+ |
} |
2203 |
+ |
#endif |
2204 |
+ |
} |
2205 |
|
UNLOCK_EVENTS; |
2206 |
|
} |
2207 |
|
#endif |
2260 |
|
return 0; |
2261 |
|
} |
2262 |
|
#endif |
2263 |
+ |
|
2264 |
+ |
|
2265 |
+ |
/* |
2266 |
+ |
* Record dirty area from NQD |
2267 |
+ |
*/ |
2268 |
+ |
|
2269 |
+ |
#ifdef SHEEPSHAVER |
2270 |
+ |
void video_set_dirty_area(int x, int y, int w, int h) |
2271 |
+ |
{ |
2272 |
+ |
const VIDEO_MODE &mode = drv->mode; |
2273 |
+ |
const int screen_width = VIDEO_MODE_X; |
2274 |
+ |
const int screen_height = VIDEO_MODE_Y; |
2275 |
+ |
const int bytes_per_row = VIDEO_MODE_ROW_BYTES; |
2276 |
+ |
|
2277 |
+ |
#ifdef ENABLE_VOSF |
2278 |
+ |
if (use_vosf) { |
2279 |
+ |
vosf_set_dirty_area(x, y, w, h, screen_width, screen_height, bytes_per_row); |
2280 |
+ |
return; |
2281 |
+ |
} |
2282 |
+ |
#endif |
2283 |
+ |
|
2284 |
+ |
// XXX handle dirty bounding boxes for non-VOSF modes |
2285 |
+ |
} |
2286 |
+ |
#endif |