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" |
197 |
|
|
198 |
|
static void *vm_acquire_framebuffer(uint32 size) |
199 |
|
{ |
200 |
< |
return vm_acquire(size); |
200 |
> |
// always try to reallocate framebuffer at the same address |
201 |
> |
static void *fb = VM_MAP_FAILED; |
202 |
> |
if (fb != VM_MAP_FAILED) { |
203 |
> |
if (vm_acquire_fixed(fb, size) < 0) { |
204 |
> |
#ifndef SHEEPSHAVER |
205 |
> |
printf("FATAL: Could not reallocate framebuffer at previous address\n"); |
206 |
> |
#endif |
207 |
> |
fb = VM_MAP_FAILED; |
208 |
> |
} |
209 |
> |
} |
210 |
> |
if (fb == VM_MAP_FAILED) |
211 |
> |
fb = vm_acquire(size, VM_MAP_DEFAULT | VM_MAP_32BIT); |
212 |
> |
return fb; |
213 |
|
} |
214 |
|
|
215 |
|
static inline void vm_release_framebuffer(void *fb, uint32 size) |
731 |
|
* Windowed display driver |
732 |
|
*/ |
733 |
|
|
734 |
+ |
static bool SDL_display_opened = false; |
735 |
+ |
|
736 |
|
// Open display |
737 |
|
driver_window::driver_window(SDL_monitor_desc &m) |
738 |
|
: driver_base(m), mouse_grabbed(false) |
744 |
|
// Set absolute mouse mode |
745 |
|
ADBSetRelMouseMode(mouse_grabbed); |
746 |
|
|
747 |
+ |
// This is ugly: |
748 |
+ |
// If we're switching resolutions (ie, not setting it for the first time), |
749 |
+ |
// there's a bug in SDL where the SDL_Surface created will not be properly |
750 |
+ |
// setup. The solution is to SDL_QuitSubSystem(SDL_INIT_VIDEO) before calling |
751 |
+ |
// SDL_SetVideoMode for the second time (SDL_SetVideoMode will call SDL_Init() |
752 |
+ |
// and all will be well). Without this, the video becomes corrupted (at least |
753 |
+ |
// on Mac OS X), after the resolution switch. |
754 |
+ |
if (SDL_display_opened) |
755 |
+ |
SDL_QuitSubSystem(SDL_INIT_VIDEO); |
756 |
+ |
|
757 |
|
// Create surface |
758 |
|
int depth = sdl_depth_of_video_depth(VIDEO_MODE_DEPTH); |
759 |
|
if ((s = SDL_SetVideoMode(width, height, depth, SDL_HWSURFACE)) == NULL) |
760 |
|
return; |
761 |
|
|
762 |
+ |
SDL_display_opened = true; |
763 |
+ |
|
764 |
|
#ifdef ENABLE_VOSF |
765 |
|
use_vosf = true; |
766 |
|
// Allocate memory for frame buffer (SIZE is extended to page-boundary) |
2013 |
|
} |
2014 |
|
} |
2015 |
|
|
2016 |
+ |
// Static display update (fixed frame rate, bounding boxes based) |
2017 |
+ |
// XXX use NQD bounding boxes to help detect dirty areas? |
2018 |
+ |
static void update_display_static_bbox(driver_window *drv) |
2019 |
+ |
{ |
2020 |
+ |
const VIDEO_MODE &mode = drv->mode; |
2021 |
+ |
|
2022 |
+ |
// Allocate bounding boxes for SDL_UpdateRects() |
2023 |
+ |
const int N_PIXELS = 64; |
2024 |
+ |
const int n_x_boxes = (VIDEO_MODE_X + N_PIXELS - 1) / N_PIXELS; |
2025 |
+ |
const int n_y_boxes = (VIDEO_MODE_Y + N_PIXELS - 1) / N_PIXELS; |
2026 |
+ |
SDL_Rect *boxes = (SDL_Rect *)alloca(sizeof(SDL_Rect) * n_x_boxes * n_y_boxes); |
2027 |
+ |
int nr_boxes = 0; |
2028 |
+ |
|
2029 |
+ |
// Lock surface, if required |
2030 |
+ |
if (SDL_MUSTLOCK(drv->s)) |
2031 |
+ |
SDL_LockSurface(drv->s); |
2032 |
+ |
|
2033 |
+ |
// Update the surface from Mac screen |
2034 |
+ |
const int bytes_per_row = VIDEO_MODE_ROW_BYTES; |
2035 |
+ |
const int bytes_per_pixel = bytes_per_row / VIDEO_MODE_X; |
2036 |
+ |
int x, y; |
2037 |
+ |
for (y = 0; y < VIDEO_MODE_Y; y += N_PIXELS) { |
2038 |
+ |
int h = N_PIXELS; |
2039 |
+ |
if (h > VIDEO_MODE_Y - y) |
2040 |
+ |
h = VIDEO_MODE_Y - y; |
2041 |
+ |
for (x = 0; x < VIDEO_MODE_X; x += N_PIXELS) { |
2042 |
+ |
int w = N_PIXELS; |
2043 |
+ |
if (w > VIDEO_MODE_X - x) |
2044 |
+ |
w = VIDEO_MODE_X - x; |
2045 |
+ |
const int xs = w * bytes_per_pixel; |
2046 |
+ |
const int xb = x * bytes_per_pixel; |
2047 |
+ |
bool dirty = false; |
2048 |
+ |
for (int j = y; j < (y + h); j++) { |
2049 |
+ |
const int yb = j * bytes_per_row; |
2050 |
+ |
if (memcmp(&the_buffer[yb + xb], &the_buffer_copy[yb + xb], xs) != 0) { |
2051 |
+ |
memcpy(&the_buffer_copy[yb + xb], &the_buffer[yb + xb], xs); |
2052 |
+ |
Screen_blit((uint8 *)drv->s->pixels + yb + xb, the_buffer + yb + xb, xs); |
2053 |
+ |
dirty = true; |
2054 |
+ |
} |
2055 |
+ |
} |
2056 |
+ |
if (dirty) { |
2057 |
+ |
boxes[nr_boxes].x = x; |
2058 |
+ |
boxes[nr_boxes].y = y; |
2059 |
+ |
boxes[nr_boxes].w = w; |
2060 |
+ |
boxes[nr_boxes].h = h; |
2061 |
+ |
nr_boxes++; |
2062 |
+ |
} |
2063 |
+ |
} |
2064 |
+ |
} |
2065 |
+ |
|
2066 |
+ |
// Unlock surface, if required |
2067 |
+ |
if (SDL_MUSTLOCK(drv->s)) |
2068 |
+ |
SDL_UnlockSurface(drv->s); |
2069 |
+ |
|
2070 |
+ |
// Refresh display |
2071 |
+ |
if (nr_boxes) |
2072 |
+ |
SDL_UpdateRects(drv->s, nr_boxes, boxes); |
2073 |
+ |
} |
2074 |
+ |
|
2075 |
|
|
2076 |
|
// We suggest the compiler to inline the next two functions so that it |
2077 |
|
// may specialise the code according to the current screen depth and |
2166 |
|
static int tick_counter = 0; |
2167 |
|
if (++tick_counter >= frame_skip) { |
2168 |
|
tick_counter = 0; |
2169 |
< |
update_display_static(static_cast<driver_window *>(drv)); |
2169 |
> |
const VIDEO_MODE &mode = drv->mode; |
2170 |
> |
if ((int)VIDEO_MODE_DEPTH >= VIDEO_DEPTH_8BIT) |
2171 |
> |
update_display_static_bbox(static_cast<driver_window *>(drv)); |
2172 |
> |
else |
2173 |
> |
update_display_static(static_cast<driver_window *>(drv)); |
2174 |
|
} |
2175 |
|
} |
2176 |
|
|
2215 |
|
LOCK_EVENTS; |
2216 |
|
SDL_FreeCursor(sdl_cursor); |
2217 |
|
sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, MacCursor[2], MacCursor[3]); |
2218 |
< |
if (sdl_cursor) |
2218 |
> |
if (sdl_cursor) { |
2219 |
|
SDL_SetCursor(sdl_cursor); |
2220 |
+ |
#ifdef WIN32 |
2221 |
+ |
// XXX Windows apparently needs an extra mouse event to |
2222 |
+ |
// make the new cursor image visible |
2223 |
+ |
int visible = SDL_ShowCursor(-1); |
2224 |
+ |
if (visible) { |
2225 |
+ |
int x, y; |
2226 |
+ |
SDL_GetMouseState(&x, &y); |
2227 |
+ |
SDL_WarpMouse(x, y); |
2228 |
+ |
} |
2229 |
+ |
#endif |
2230 |
+ |
} |
2231 |
|
UNLOCK_EVENTS; |
2232 |
|
} |
2233 |
|
#endif |
2286 |
|
return 0; |
2287 |
|
} |
2288 |
|
#endif |
2289 |
+ |
|
2290 |
+ |
|
2291 |
+ |
/* |
2292 |
+ |
* Record dirty area from NQD |
2293 |
+ |
*/ |
2294 |
+ |
|
2295 |
+ |
#ifdef SHEEPSHAVER |
2296 |
+ |
void video_set_dirty_area(int x, int y, int w, int h) |
2297 |
+ |
{ |
2298 |
+ |
const VIDEO_MODE &mode = drv->mode; |
2299 |
+ |
const int screen_width = VIDEO_MODE_X; |
2300 |
+ |
const int screen_height = VIDEO_MODE_Y; |
2301 |
+ |
const int bytes_per_row = VIDEO_MODE_ROW_BYTES; |
2302 |
+ |
|
2303 |
+ |
#ifdef ENABLE_VOSF |
2304 |
+ |
if (use_vosf) { |
2305 |
+ |
vosf_set_dirty_area(x, y, w, h, screen_width, screen_height, bytes_per_row); |
2306 |
+ |
return; |
2307 |
+ |
} |
2308 |
+ |
#endif |
2309 |
+ |
|
2310 |
+ |
// XXX handle dirty bounding boxes for non-VOSF modes |
2311 |
+ |
} |
2312 |
+ |
#endif |