32 |
|
* - Force relative mode in Grab mode even if SDL provides absolute coordinates? |
33 |
|
* - Fullscreen mode |
34 |
|
* - Gamma tables support is likely to be broken here |
35 |
+ |
* - Events processing is bound to the general emulation thread as SDL requires |
36 |
+ |
* to PumpEvents() within the same thread as the one that called SetVideoMode(). |
37 |
+ |
* Besides, there can't seem to be a way to call SetVideoMode() from a child thread. |
38 |
+ |
* - Refresh performance is still slow. Use SDL_CreateRGBSurface()? |
39 |
+ |
* - Backport hw cursor acceleration to Basilisk II? |
40 |
|
*/ |
41 |
|
|
42 |
|
#include "sysdeps.h" |
45 |
|
#include <SDL_mutex.h> |
46 |
|
#include <SDL_thread.h> |
47 |
|
#include <errno.h> |
48 |
+ |
#include <vector> |
49 |
|
|
50 |
|
#include "cpu_emulation.h" |
51 |
|
#include "main.h" |
54 |
|
#include "prefs.h" |
55 |
|
#include "user_strings.h" |
56 |
|
#include "video.h" |
57 |
+ |
#include "video_defs.h" |
58 |
|
#include "video_blit.h" |
59 |
|
|
60 |
|
#define DEBUG 0 |
62 |
|
|
63 |
|
|
64 |
|
// Supported video modes |
65 |
< |
static vector<video_mode> VideoModes; |
65 |
> |
using std::vector; |
66 |
> |
static vector<VIDEO_MODE> VideoModes; |
67 |
|
|
68 |
|
// Display types |
69 |
+ |
#ifdef SHEEPSHAVER |
70 |
|
enum { |
71 |
< |
DISPLAY_WINDOW, // windowed display |
72 |
< |
DISPLAY_SCREEN // fullscreen display |
71 |
> |
DISPLAY_WINDOW = DIS_WINDOW, // windowed display |
72 |
> |
DISPLAY_SCREEN = DIS_SCREEN // fullscreen display |
73 |
|
}; |
74 |
+ |
extern int display_type; // See enum above |
75 |
+ |
#else |
76 |
+ |
enum { |
77 |
+ |
DISPLAY_WINDOW, // windowed display |
78 |
+ |
DISPLAY_SCREEN // fullscreen display |
79 |
+ |
}; |
80 |
+ |
static int display_type = DISPLAY_WINDOW; // See enum above |
81 |
+ |
#endif |
82 |
|
|
83 |
|
// Constants |
84 |
|
const char KEYCODE_FILE_NAME[] = DATADIR "/keycodes"; |
89 |
|
static int16 mouse_wheel_mode; |
90 |
|
static int16 mouse_wheel_lines; |
91 |
|
|
75 |
– |
static int display_type = DISPLAY_WINDOW; // See enum above |
92 |
|
static uint8 *the_buffer = NULL; // Mac frame buffer (where MacOS draws into) |
93 |
|
static uint8 *the_buffer_copy = NULL; // Copy of Mac frame buffer (for refreshed modes) |
94 |
|
static uint32 the_buffer_size; // Size of allocated the_buffer |
98 |
|
static SDL_Thread *redraw_thread = NULL; // Redraw thread |
99 |
|
|
100 |
|
#ifdef ENABLE_VOSF |
101 |
< |
static bool use_vosf = true; // Flag: VOSF enabled |
101 |
> |
static bool use_vosf = false; // Flag: VOSF enabled |
102 |
|
#else |
103 |
|
static const bool use_vosf = false; // VOSF not possible |
104 |
|
#endif |
116 |
|
|
117 |
|
// SDL variables |
118 |
|
static int screen_depth; // Depth of current screen |
119 |
+ |
static SDL_Cursor *sdl_cursor; // Copy of Mac cursor |
120 |
+ |
static volatile bool cursor_changed = false; // Flag: cursor changed, redraw_func must update the cursor |
121 |
|
static SDL_Color sdl_palette[256]; // Color palette to be used as CLUT and gamma table |
122 |
|
static bool sdl_palette_changed = false; // Flag: Palette changed, redraw thread must set new colors |
123 |
+ |
static const int sdl_eventmask = SDL_MOUSEBUTTONDOWNMASK | SDL_MOUSEBUTTONUPMASK | SDL_MOUSEMOTIONMASK | SDL_KEYUPMASK | SDL_KEYDOWNMASK | SDL_VIDEOEXPOSEMASK | SDL_QUITMASK; |
124 |
|
|
125 |
|
// Mutex to protect palette |
126 |
|
static SDL_mutex *sdl_palette_lock = NULL; |
145 |
|
|
146 |
|
|
147 |
|
/* |
148 |
+ |
* SheepShaver glue |
149 |
+ |
*/ |
150 |
+ |
|
151 |
+ |
#ifdef SHEEPSHAVER |
152 |
+ |
// Color depth modes type |
153 |
+ |
typedef int video_depth; |
154 |
+ |
|
155 |
+ |
// 1, 2, 4 and 8 bit depths use a color palette |
156 |
+ |
static inline bool IsDirectMode(VIDEO_MODE const & mode) |
157 |
+ |
{ |
158 |
+ |
return IsDirectMode(mode.viAppleMode); |
159 |
+ |
} |
160 |
+ |
|
161 |
+ |
// Abstract base class representing one (possibly virtual) monitor |
162 |
+ |
// ("monitor" = rectangular display with a contiguous frame buffer) |
163 |
+ |
class monitor_desc { |
164 |
+ |
public: |
165 |
+ |
monitor_desc(const vector<VIDEO_MODE> &available_modes, video_depth default_depth, uint32 default_id) {} |
166 |
+ |
virtual ~monitor_desc() {} |
167 |
+ |
|
168 |
+ |
// Get current Mac frame buffer base address |
169 |
+ |
uint32 get_mac_frame_base(void) const {return screen_base;} |
170 |
+ |
|
171 |
+ |
// Set Mac frame buffer base address (called from switch_to_mode()) |
172 |
+ |
void set_mac_frame_base(uint32 base) {screen_base = base;} |
173 |
+ |
|
174 |
+ |
// Get current video mode |
175 |
+ |
const VIDEO_MODE &get_current_mode(void) const {return VModes[cur_mode];} |
176 |
+ |
|
177 |
+ |
// Called by the video driver to switch the video mode on this display |
178 |
+ |
// (must call set_mac_frame_base()) |
179 |
+ |
virtual void switch_to_current_mode(void) = 0; |
180 |
+ |
|
181 |
+ |
// Called by the video driver to set the color palette (in indexed modes) |
182 |
+ |
// or the gamma table (in direct modes) |
183 |
+ |
virtual void set_palette(uint8 *pal, int num) = 0; |
184 |
+ |
}; |
185 |
+ |
|
186 |
+ |
// Vector of pointers to available monitor descriptions, filled by VideoInit() |
187 |
+ |
static vector<monitor_desc *> VideoMonitors; |
188 |
+ |
|
189 |
+ |
// Find Apple mode matching best specified dimensions |
190 |
+ |
static int find_apple_resolution(int xsize, int ysize) |
191 |
+ |
{ |
192 |
+ |
int apple_id; |
193 |
+ |
if (xsize < 800) |
194 |
+ |
apple_id = APPLE_640x480; |
195 |
+ |
else if (xsize < 1024) |
196 |
+ |
apple_id = APPLE_800x600; |
197 |
+ |
else if (xsize < 1152) |
198 |
+ |
apple_id = APPLE_1024x768; |
199 |
+ |
else if (xsize < 1280) { |
200 |
+ |
if (ysize < 900) |
201 |
+ |
apple_id = APPLE_1152x768; |
202 |
+ |
else |
203 |
+ |
apple_id = APPLE_1152x900; |
204 |
+ |
} |
205 |
+ |
else if (xsize < 1600) |
206 |
+ |
apple_id = APPLE_1280x1024; |
207 |
+ |
else |
208 |
+ |
apple_id = APPLE_1600x1200; |
209 |
+ |
return apple_id; |
210 |
+ |
} |
211 |
+ |
|
212 |
+ |
// Set parameters to specified Apple mode |
213 |
+ |
static void set_apple_resolution(int apple_id, int &xsize, int &ysize) |
214 |
+ |
{ |
215 |
+ |
switch (apple_id) { |
216 |
+ |
case APPLE_640x480: |
217 |
+ |
xsize = 640; |
218 |
+ |
ysize = 480; |
219 |
+ |
break; |
220 |
+ |
case APPLE_800x600: |
221 |
+ |
xsize = 800; |
222 |
+ |
ysize = 600; |
223 |
+ |
break; |
224 |
+ |
case APPLE_1024x768: |
225 |
+ |
xsize = 1024; |
226 |
+ |
ysize = 768; |
227 |
+ |
break; |
228 |
+ |
case APPLE_1152x768: |
229 |
+ |
xsize = 1152; |
230 |
+ |
ysize = 768; |
231 |
+ |
break; |
232 |
+ |
case APPLE_1152x900: |
233 |
+ |
xsize = 1152; |
234 |
+ |
ysize = 900; |
235 |
+ |
break; |
236 |
+ |
case APPLE_1280x1024: |
237 |
+ |
xsize = 1280; |
238 |
+ |
ysize = 1024; |
239 |
+ |
break; |
240 |
+ |
case APPLE_1600x1200: |
241 |
+ |
xsize = 1600; |
242 |
+ |
ysize = 1200; |
243 |
+ |
break; |
244 |
+ |
default: |
245 |
+ |
abort(); |
246 |
+ |
} |
247 |
+ |
} |
248 |
+ |
|
249 |
+ |
// Match Apple mode matching best specified dimensions |
250 |
+ |
static int match_apple_resolution(int &xsize, int &ysize) |
251 |
+ |
{ |
252 |
+ |
int apple_id = find_apple_resolution(xsize, ysize); |
253 |
+ |
set_apple_resolution(apple_id, xsize, ysize); |
254 |
+ |
return apple_id; |
255 |
+ |
} |
256 |
+ |
|
257 |
+ |
// Display error alert |
258 |
+ |
static void ErrorAlert(int error) |
259 |
+ |
{ |
260 |
+ |
ErrorAlert(GetString(error)); |
261 |
+ |
} |
262 |
+ |
|
263 |
+ |
// Display warning alert |
264 |
+ |
static void WarningAlert(int warning) |
265 |
+ |
{ |
266 |
+ |
WarningAlert(GetString(warning)); |
267 |
+ |
} |
268 |
+ |
#endif |
269 |
+ |
|
270 |
+ |
|
271 |
+ |
/* |
272 |
|
* monitor_desc subclass for SDL display |
273 |
|
*/ |
274 |
|
|
275 |
|
class SDL_monitor_desc : public monitor_desc { |
276 |
|
public: |
277 |
< |
SDL_monitor_desc(const vector<video_mode> &available_modes, video_depth default_depth, uint32 default_id) : monitor_desc(available_modes, default_depth, default_id) {} |
277 |
> |
SDL_monitor_desc(const vector<VIDEO_MODE> &available_modes, video_depth default_depth, uint32 default_id) : monitor_desc(available_modes, default_depth, default_id) {} |
278 |
|
~SDL_monitor_desc() {} |
279 |
|
|
280 |
|
virtual void switch_to_current_mode(void); |
289 |
|
* Utility functions |
290 |
|
*/ |
291 |
|
|
292 |
+ |
// Find palette size for given color depth |
293 |
+ |
static int palette_size(int mode) |
294 |
+ |
{ |
295 |
+ |
switch (mode) { |
296 |
+ |
case VIDEO_DEPTH_1BIT: return 2; |
297 |
+ |
case VIDEO_DEPTH_2BIT: return 4; |
298 |
+ |
case VIDEO_DEPTH_4BIT: return 16; |
299 |
+ |
case VIDEO_DEPTH_8BIT: return 256; |
300 |
+ |
case VIDEO_DEPTH_16BIT: return 32; |
301 |
+ |
case VIDEO_DEPTH_32BIT: return 256; |
302 |
+ |
default: return 0; |
303 |
+ |
} |
304 |
+ |
} |
305 |
+ |
|
306 |
+ |
// Return bytes per pixel for requested depth |
307 |
+ |
static inline int bytes_per_pixel(int depth) |
308 |
+ |
{ |
309 |
+ |
int bpp; |
310 |
+ |
switch (depth) { |
311 |
+ |
case 8: |
312 |
+ |
bpp = 1; |
313 |
+ |
break; |
314 |
+ |
case 15: case 16: |
315 |
+ |
bpp = 2; |
316 |
+ |
break; |
317 |
+ |
case 24: case 32: |
318 |
+ |
bpp = 4; |
319 |
+ |
break; |
320 |
+ |
default: |
321 |
+ |
abort(); |
322 |
+ |
} |
323 |
+ |
return bpp; |
324 |
+ |
} |
325 |
+ |
|
326 |
|
// Map video_mode depth ID to numerical depth value |
327 |
< |
static int sdl_depth_of_video_depth(int video_depth) |
327 |
> |
static int mac_depth_of_video_depth(int video_depth) |
328 |
|
{ |
329 |
|
int depth = -1; |
330 |
|
switch (video_depth) { |
331 |
< |
case VDEPTH_1BIT: |
331 |
> |
case VIDEO_DEPTH_1BIT: |
332 |
|
depth = 1; |
333 |
|
break; |
334 |
< |
case VDEPTH_2BIT: |
334 |
> |
case VIDEO_DEPTH_2BIT: |
335 |
|
depth = 2; |
336 |
|
break; |
337 |
< |
case VDEPTH_4BIT: |
337 |
> |
case VIDEO_DEPTH_4BIT: |
338 |
|
depth = 4; |
339 |
|
break; |
340 |
< |
case VDEPTH_8BIT: |
340 |
> |
case VIDEO_DEPTH_8BIT: |
341 |
|
depth = 8; |
342 |
|
break; |
343 |
< |
case VDEPTH_16BIT: |
343 |
> |
case VIDEO_DEPTH_16BIT: |
344 |
|
depth = 16; |
345 |
|
break; |
346 |
< |
case VDEPTH_32BIT: |
346 |
> |
case VIDEO_DEPTH_32BIT: |
347 |
|
depth = 32; |
348 |
|
break; |
349 |
|
default: |
352 |
|
return depth; |
353 |
|
} |
354 |
|
|
355 |
+ |
// Map video_mode depth ID to SDL screen depth |
356 |
+ |
static int sdl_depth_of_video_depth(int video_depth) |
357 |
+ |
{ |
358 |
+ |
return (video_depth <= VIDEO_DEPTH_8BIT) ? 8 : mac_depth_of_video_depth(video_depth); |
359 |
+ |
} |
360 |
+ |
|
361 |
+ |
// Check wether specified mode is available |
362 |
+ |
static bool has_mode(int type, int width, int height) |
363 |
+ |
{ |
364 |
+ |
// FIXME: no fullscreen support yet |
365 |
+ |
if (type == DISPLAY_SCREEN) |
366 |
+ |
return false; |
367 |
+ |
|
368 |
+ |
#ifdef SHEEPSHAVER |
369 |
+ |
// Filter out Classic resolutiosn |
370 |
+ |
if (width == 512 && height == 384) |
371 |
+ |
return false; |
372 |
+ |
|
373 |
+ |
// Read window modes prefs |
374 |
+ |
static uint32 window_modes = 0; |
375 |
+ |
static uint32 screen_modes = 0; |
376 |
+ |
if (window_modes == 0 || screen_modes == 0) { |
377 |
+ |
window_modes = PrefsFindInt32("windowmodes"); |
378 |
+ |
screen_modes = PrefsFindInt32("screenmodes"); |
379 |
+ |
if (window_modes == 0 || screen_modes == 0) |
380 |
+ |
window_modes |= 3; // Allow at least 640x480 and 800x600 window modes |
381 |
+ |
} |
382 |
+ |
|
383 |
+ |
if (type == DISPLAY_WINDOW) { |
384 |
+ |
int apple_mask, apple_id = find_apple_resolution(width, height); |
385 |
+ |
switch (apple_id) { |
386 |
+ |
case APPLE_640x480: apple_mask = 0x01; break; |
387 |
+ |
case APPLE_800x600: apple_mask = 0x02; break; |
388 |
+ |
case APPLE_1024x768: apple_mask = 0x04; break; |
389 |
+ |
case APPLE_1152x768: apple_mask = 0x40; break; |
390 |
+ |
case APPLE_1152x900: apple_mask = 0x08; break; |
391 |
+ |
case APPLE_1280x1024: apple_mask = 0x10; break; |
392 |
+ |
case APPLE_1600x1200: apple_mask = 0x20; break; |
393 |
+ |
default: apple_mask = 0x00; break; |
394 |
+ |
} |
395 |
+ |
return (window_modes & apple_mask); |
396 |
+ |
} |
397 |
+ |
#else |
398 |
+ |
return true; |
399 |
+ |
#endif |
400 |
+ |
return false; |
401 |
+ |
} |
402 |
+ |
|
403 |
|
// Add mode to list of supported modes |
404 |
< |
static void add_mode(uint32 width, uint32 height, uint32 resolution_id, uint32 bytes_per_row, video_depth depth) |
404 |
> |
static void add_mode(int type, int width, int height, int resolution_id, int bytes_per_row, int depth) |
405 |
|
{ |
406 |
< |
video_mode mode; |
407 |
< |
mode.x = width; |
408 |
< |
mode.y = height; |
409 |
< |
mode.resolution_id = resolution_id; |
410 |
< |
mode.bytes_per_row = bytes_per_row; |
411 |
< |
mode.depth = depth; |
406 |
> |
// Filter out unsupported modes |
407 |
> |
if (!has_mode(type, width, height)) |
408 |
> |
return; |
409 |
> |
|
410 |
> |
// Fill in VideoMode entry |
411 |
> |
VIDEO_MODE mode; |
412 |
> |
#ifdef SHEEPSHAVER |
413 |
> |
// Recalculate dimensions to fit Apple modes |
414 |
> |
resolution_id = match_apple_resolution(width, height); |
415 |
> |
mode.viType = type; |
416 |
> |
#endif |
417 |
> |
VIDEO_MODE_X = width; |
418 |
> |
VIDEO_MODE_Y = height; |
419 |
> |
VIDEO_MODE_RESOLUTION = resolution_id; |
420 |
> |
VIDEO_MODE_ROW_BYTES = bytes_per_row; |
421 |
> |
VIDEO_MODE_DEPTH = (video_depth)depth; |
422 |
|
VideoModes.push_back(mode); |
423 |
|
} |
424 |
|
|
425 |
|
// Add standard list of windowed modes for given color depth |
426 |
< |
static void add_window_modes(video_depth depth) |
426 |
> |
static void add_window_modes(int depth) |
427 |
|
{ |
428 |
< |
add_mode(512, 384, 0x80, TrivialBytesPerRow(512, depth), depth); |
429 |
< |
add_mode(640, 480, 0x81, TrivialBytesPerRow(640, depth), depth); |
430 |
< |
add_mode(800, 600, 0x82, TrivialBytesPerRow(800, depth), depth); |
431 |
< |
add_mode(1024, 768, 0x83, TrivialBytesPerRow(1024, depth), depth); |
432 |
< |
add_mode(1152, 870, 0x84, TrivialBytesPerRow(1152, depth), depth); |
433 |
< |
add_mode(1280, 1024, 0x85, TrivialBytesPerRow(1280, depth), depth); |
434 |
< |
add_mode(1600, 1200, 0x86, TrivialBytesPerRow(1600, depth), depth); |
428 |
> |
video_depth vdepth = (video_depth)depth; |
429 |
> |
add_mode(DISPLAY_WINDOW, 512, 384, 0x80, TrivialBytesPerRow(512, vdepth), depth); |
430 |
> |
add_mode(DISPLAY_WINDOW, 640, 480, 0x81, TrivialBytesPerRow(640, vdepth), depth); |
431 |
> |
add_mode(DISPLAY_WINDOW, 800, 600, 0x82, TrivialBytesPerRow(800, vdepth), depth); |
432 |
> |
add_mode(DISPLAY_WINDOW, 1024, 768, 0x83, TrivialBytesPerRow(1024, vdepth), depth); |
433 |
> |
add_mode(DISPLAY_WINDOW, 1152, 870, 0x84, TrivialBytesPerRow(1152, vdepth), depth); |
434 |
> |
add_mode(DISPLAY_WINDOW, 1280, 1024, 0x85, TrivialBytesPerRow(1280, vdepth), depth); |
435 |
> |
add_mode(DISPLAY_WINDOW, 1600, 1200, 0x86, TrivialBytesPerRow(1600, vdepth), depth); |
436 |
|
} |
437 |
|
|
438 |
|
// Set Mac frame layout and base address (uses the_buffer/MacFrameBaseMac) |
439 |
< |
static void set_mac_frame_buffer(SDL_monitor_desc &monitor, video_depth depth, bool native_byte_order) |
439 |
> |
static void set_mac_frame_buffer(SDL_monitor_desc &monitor, int depth, bool native_byte_order) |
440 |
|
{ |
441 |
|
#if !REAL_ADDRESSING && !DIRECT_ADDRESSING |
442 |
|
int layout = FLAYOUT_DIRECT; |
443 |
< |
if (depth == VDEPTH_16BIT) |
443 |
> |
if (depth == VIDEO_DEPTH_16BIT) |
444 |
|
layout = (screen_depth == 15) ? FLAYOUT_HOST_555 : FLAYOUT_HOST_565; |
445 |
< |
else if (depth == VDEPTH_32BIT) |
445 |
> |
else if (depth == VIDEO_DEPTH_32BIT) |
446 |
|
layout = (screen_depth == 24) ? FLAYOUT_HOST_888 : FLAYOUT_DIRECT; |
447 |
|
if (native_byte_order) |
448 |
|
MacFrameLayout = layout; |
451 |
|
monitor.set_mac_frame_base(MacFrameBaseMac); |
452 |
|
|
453 |
|
// Set variables used by UAE memory banking |
454 |
< |
const video_mode &mode = monitor.get_current_mode(); |
454 |
> |
const VIDEO_MODE &mode = monitor.get_current_mode(); |
455 |
|
MacFrameBaseHost = the_buffer; |
456 |
< |
MacFrameSize = mode.bytes_per_row * mode.y; |
456 |
> |
MacFrameSize = VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y; |
457 |
|
InitFrameBufferMapping(); |
458 |
|
#else |
459 |
|
monitor.set_mac_frame_base(Host2MacAddr(the_buffer)); |
502 |
|
|
503 |
|
public: |
504 |
|
SDL_monitor_desc &monitor; // Associated video monitor |
505 |
< |
const video_mode &mode; // Video mode handled by the driver |
505 |
> |
const VIDEO_MODE &mode; // Video mode handled by the driver |
506 |
|
|
507 |
|
bool init_ok; // Initialization succeeded (we can't use exceptions because of -fomit-frame-pointer) |
508 |
|
SDL_Surface *s; // The surface we draw into |
590 |
|
// Palette has changed |
591 |
|
void driver_base::update_palette(void) |
592 |
|
{ |
593 |
< |
const video_mode &mode = monitor.get_current_mode(); |
593 |
> |
const VIDEO_MODE &mode = monitor.get_current_mode(); |
594 |
|
|
595 |
< |
if (mode.depth <= VDEPTH_8BIT) |
595 |
> |
if ((int)VIDEO_MODE_DEPTH <= VIDEO_DEPTH_8BIT) |
596 |
|
SDL_SetPalette(s, SDL_PHYSPAL, sdl_palette, 0, 256); |
597 |
|
} |
598 |
|
|
615 |
|
driver_window::driver_window(SDL_monitor_desc &m) |
616 |
|
: driver_base(m), mouse_grabbed(false) |
617 |
|
{ |
618 |
< |
int width = mode.x, height = mode.y; |
618 |
> |
int width = VIDEO_MODE_X, height = VIDEO_MODE_Y; |
619 |
|
int aligned_width = (width + 15) & ~15; |
620 |
|
int aligned_height = (height + 15) & ~15; |
621 |
|
|
623 |
|
ADBSetRelMouseMode(mouse_grabbed); |
624 |
|
|
625 |
|
// Create surface |
626 |
< |
int depth = (mode.depth <= VDEPTH_8BIT ? 8 : screen_depth); |
626 |
> |
int depth = sdl_depth_of_video_depth(VIDEO_MODE_DEPTH); |
627 |
|
if ((s = SDL_SetVideoMode(width, height, depth, SDL_HWSURFACE)) == NULL) |
628 |
|
return; |
629 |
|
|
635 |
|
the_buffer = (uint8 *)vm_acquire(the_buffer_size); |
636 |
|
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
637 |
|
D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer)); |
638 |
+ |
|
639 |
+ |
// Check whether we can initialize the VOSF subsystem and it's profitable |
640 |
+ |
if (!video_vosf_init(m)) { |
641 |
+ |
WarningAlert(STR_VOSF_INIT_ERR); |
642 |
+ |
use_vosf = false; |
643 |
+ |
} |
644 |
+ |
else if (!video_vosf_profitable()) { |
645 |
+ |
video_vosf_exit(); |
646 |
+ |
printf("VOSF acceleration is not profitable on this platform, disabling it\n"); |
647 |
+ |
use_vosf = false; |
648 |
+ |
} |
649 |
+ |
if (!use_vosf) { |
650 |
+ |
free(the_buffer_copy); |
651 |
+ |
vm_release(the_buffer, the_buffer_size); |
652 |
+ |
the_host_buffer = NULL; |
653 |
+ |
} |
654 |
+ |
#endif |
655 |
+ |
if (!use_vosf) { |
656 |
+ |
// Allocate memory for frame buffer |
657 |
+ |
the_buffer_size = (aligned_height + 2) * s->pitch; |
658 |
+ |
the_buffer_copy = (uint8 *)calloc(1, the_buffer_size); |
659 |
+ |
the_buffer = (uint8 *)calloc(1, the_buffer_size); |
660 |
+ |
D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy)); |
661 |
+ |
} |
662 |
+ |
|
663 |
+ |
#ifdef SHEEPSHAVER |
664 |
+ |
// Create cursor |
665 |
+ |
if ((sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, 0, 0)) != NULL) { |
666 |
+ |
SDL_SetCursor(sdl_cursor); |
667 |
+ |
cursor_changed = false; |
668 |
+ |
} |
669 |
|
#else |
670 |
< |
// Allocate memory for frame buffer |
671 |
< |
the_buffer_size = (aligned_height + 2) * s->pitch; |
405 |
< |
the_buffer_copy = (uint8 *)calloc(1, the_buffer_size); |
406 |
< |
the_buffer = (uint8 *)calloc(1, the_buffer_size); |
407 |
< |
D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy)); |
670 |
> |
// Hide cursor |
671 |
> |
SDL_ShowCursor(0); |
672 |
|
#endif |
673 |
|
|
674 |
|
// Set window name/class |
675 |
|
set_window_name(STR_WINDOW_TITLE); |
676 |
|
|
413 |
– |
// Hide cursor |
414 |
– |
SDL_ShowCursor(0); |
415 |
– |
|
677 |
|
// Init blitting routines |
678 |
|
SDL_PixelFormat *f = s->format; |
679 |
|
VisualFormat visualFormat; |
681 |
|
visualFormat.Rmask = f->Rmask; |
682 |
|
visualFormat.Gmask = f->Gmask; |
683 |
|
visualFormat.Bmask = f->Bmask; |
684 |
< |
Screen_blitter_init(visualFormat, true, sdl_depth_of_video_depth(mode.depth)); |
684 |
> |
Screen_blitter_init(visualFormat, true, mac_depth_of_video_depth(VIDEO_MODE_DEPTH)); |
685 |
|
|
686 |
|
// Load gray ramp to 8->16/32 expand map |
687 |
|
if (!IsDirectMode(mode)) |
689 |
|
ExpandMap[i] = SDL_MapRGB(f, i, i, i); |
690 |
|
|
691 |
|
// Set frame buffer base |
692 |
< |
set_mac_frame_buffer(monitor, mode.depth, true); |
692 |
> |
set_mac_frame_buffer(monitor, VIDEO_MODE_DEPTH, true); |
693 |
|
|
694 |
|
// Everything went well |
695 |
|
init_ok = true; |
792 |
|
|
793 |
|
if (video_driver_found) { |
794 |
|
// Skip aliases |
795 |
< |
static const char alias_str[] = "alias"; |
796 |
< |
if (strncmp(line, alias_str, sizeof(alias_str) - 1) == 0) |
795 |
> |
static const char sdl_str[] = "sdl"; |
796 |
> |
if (strncmp(line, sdl_str, sizeof(sdl_str) - 1) == 0) |
797 |
|
continue; |
798 |
|
|
799 |
|
// Read keycode |
804 |
|
break; |
805 |
|
} else { |
806 |
|
// Search for SDL video driver string |
807 |
< |
static const char alias_sdl_str[] = "alias SDL"; |
808 |
< |
if (strncmp(line, alias_sdl_str, sizeof(alias_sdl_str) - 1) == 0) { |
809 |
< |
char *p = line + sizeof(alias_sdl_str); |
807 |
> |
static const char sdl_str[] = "sdl"; |
808 |
> |
if (strncmp(line, sdl_str, sizeof(sdl_str) - 1) == 0) { |
809 |
> |
char *p = line + sizeof(sdl_str); |
810 |
|
if (strstr(video_driver, p) == video_driver) |
811 |
|
video_driver_found = true; |
812 |
|
} |
831 |
|
bool SDL_monitor_desc::video_open(void) |
832 |
|
{ |
833 |
|
D(bug("video_open()\n")); |
834 |
< |
const video_mode &mode = get_current_mode(); |
834 |
> |
const VIDEO_MODE &mode = get_current_mode(); |
835 |
> |
#if DEBUG |
836 |
> |
D(bug("Current video mode:\n")); |
837 |
> |
D(bug(" %dx%d (ID %02x), %d bpp\n", VIDEO_MODE_X, VIDEO_MODE_Y, VIDEO_MODE_RESOLUTION, 1 << (VIDEO_MODE_DEPTH & 0x0f))); |
838 |
> |
#endif |
839 |
|
|
840 |
|
// Create display driver object of requested type |
841 |
|
switch (display_type) { |
851 |
|
return false; |
852 |
|
} |
853 |
|
|
589 |
– |
#ifdef ENABLE_VOSF |
590 |
– |
if (use_vosf) { |
591 |
– |
// Initialize the VOSF system |
592 |
– |
if (!video_vosf_init(*this)) { |
593 |
– |
ErrorAlert(STR_VOSF_INIT_ERR); |
594 |
– |
return false; |
595 |
– |
} |
596 |
– |
} |
597 |
– |
#endif |
598 |
– |
|
854 |
|
// Initialize VideoRefresh function |
855 |
|
VideoRefreshInit(); |
856 |
|
|
859 |
|
|
860 |
|
// Start redraw/input thread |
861 |
|
redraw_thread_cancel = false; |
862 |
< |
redraw_thread_active = (SDL_CreateThread(redraw_func, NULL) != NULL); |
862 |
> |
redraw_thread_active = ((redraw_thread = SDL_CreateThread(redraw_func, NULL)) != NULL); |
863 |
|
if (!redraw_thread_active) { |
864 |
|
printf("FATAL: cannot create redraw thread\n"); |
865 |
|
return false; |
867 |
|
return true; |
868 |
|
} |
869 |
|
|
870 |
+ |
#ifdef SHEEPSHAVER |
871 |
+ |
bool VideoInit(void) |
872 |
+ |
{ |
873 |
+ |
const bool classic = false; |
874 |
+ |
#else |
875 |
|
bool VideoInit(bool classic) |
876 |
|
{ |
877 |
+ |
#endif |
878 |
|
classic_mode = classic; |
879 |
|
|
880 |
|
#ifdef ENABLE_VOSF |
898 |
|
mouse_wheel_lines = PrefsFindInt32("mousewheellines"); |
899 |
|
|
900 |
|
// Get screen mode from preferences |
901 |
< |
const char *mode_str; |
901 |
> |
const char *mode_str = NULL; |
902 |
> |
#ifndef SHEEPSHAVER |
903 |
|
if (classic_mode) |
904 |
|
mode_str = "win/512/342"; |
905 |
|
else |
906 |
|
mode_str = PrefsFindString("screen"); |
907 |
+ |
#endif |
908 |
|
|
909 |
|
// Determine display type and default dimensions |
910 |
< |
int default_width = 512, default_height = 384; |
910 |
> |
int default_width, default_height; |
911 |
> |
if (classic) { |
912 |
> |
default_width = 512; |
913 |
> |
default_height = 384; |
914 |
> |
} |
915 |
> |
else { |
916 |
> |
default_width = 640; |
917 |
> |
default_height = 480; |
918 |
> |
} |
919 |
|
display_type = DISPLAY_WINDOW; |
920 |
|
if (mode_str) { |
921 |
|
if (sscanf(mode_str, "win/%d/%d", &default_width, &default_height) == 2) |
922 |
|
display_type = DISPLAY_WINDOW; |
923 |
|
} |
924 |
|
int max_width = 640, max_height = 480; |
925 |
< |
if (display_type == DISPLAY_SCREEN) { |
926 |
< |
SDL_Rect **modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE); |
927 |
< |
if (modes && modes != (SDL_Rect **)-1) { |
928 |
< |
max_width = modes[0]->w; |
929 |
< |
max_height = modes[0]->h; |
930 |
< |
} |
925 |
> |
SDL_Rect **modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE); |
926 |
> |
if (modes && modes != (SDL_Rect **)-1) { |
927 |
> |
max_width = modes[0]->w; |
928 |
> |
max_height = modes[0]->h; |
929 |
> |
if (default_width > max_width) |
930 |
> |
default_width = max_width; |
931 |
> |
if (default_height > max_height) |
932 |
> |
default_height = max_height; |
933 |
|
} |
934 |
|
if (default_width <= 0) |
935 |
|
default_width = max_width; |
938 |
|
|
939 |
|
// Mac screen depth follows X depth |
940 |
|
screen_depth = SDL_GetVideoInfo()->vfmt->BitsPerPixel; |
941 |
< |
video_depth default_depth; |
941 |
> |
int default_depth; |
942 |
|
switch (screen_depth) { |
943 |
|
case 8: |
944 |
< |
default_depth = VDEPTH_8BIT; |
944 |
> |
default_depth = VIDEO_DEPTH_8BIT; |
945 |
|
break; |
946 |
|
case 15: case 16: |
947 |
< |
default_depth = VDEPTH_16BIT; |
947 |
> |
default_depth = VIDEO_DEPTH_16BIT; |
948 |
|
break; |
949 |
|
case 24: case 32: |
950 |
< |
default_depth = VDEPTH_32BIT; |
950 |
> |
default_depth = VIDEO_DEPTH_32BIT; |
951 |
|
break; |
952 |
|
default: |
953 |
< |
default_depth = VDEPTH_1BIT; |
953 |
> |
default_depth = VIDEO_DEPTH_1BIT; |
954 |
|
break; |
955 |
|
} |
956 |
|
|
957 |
|
// Construct list of supported modes |
958 |
|
if (display_type == DISPLAY_WINDOW) { |
959 |
|
if (classic) |
960 |
< |
add_mode(512, 342, 0x80, 64, VDEPTH_1BIT); |
960 |
> |
add_mode(display_type, 512, 342, 0x80, 64, VIDEO_DEPTH_1BIT); |
961 |
|
else { |
962 |
< |
for (int d = VDEPTH_1BIT; d <= default_depth; d++) { |
963 |
< |
int bpp = (d <= VDEPTH_8BIT ? 8 : sdl_depth_of_video_depth(d)); |
962 |
> |
for (int d = VIDEO_DEPTH_1BIT; d <= default_depth; d++) { |
963 |
> |
int bpp = sdl_depth_of_video_depth(d); |
964 |
|
if (SDL_VideoModeOK(max_width, max_height, bpp, SDL_HWSURFACE)) |
965 |
|
add_window_modes(video_depth(d)); |
966 |
|
} |
967 |
|
} |
968 |
|
} else |
969 |
< |
add_mode(default_width, default_height, 0x80, TrivialBytesPerRow(default_width, default_depth), default_depth); |
969 |
> |
add_mode(display_type, default_width, default_height, 0x80, TrivialBytesPerRow(default_width, (video_depth)default_depth), default_depth); |
970 |
|
if (VideoModes.empty()) { |
971 |
|
ErrorAlert(STR_NO_XVISUAL_ERR); |
972 |
|
return false; |
974 |
|
|
975 |
|
// Find requested default mode with specified dimensions |
976 |
|
uint32 default_id; |
977 |
< |
std::vector<video_mode>::const_iterator i, end = VideoModes.end(); |
977 |
> |
std::vector<VIDEO_MODE>::const_iterator i, end = VideoModes.end(); |
978 |
|
for (i = VideoModes.begin(); i != end; ++i) { |
979 |
< |
if (i->x == default_width && i->y == default_height && i->depth == default_depth) { |
980 |
< |
default_id = i->resolution_id; |
979 |
> |
const VIDEO_MODE & mode = (*i); |
980 |
> |
if (VIDEO_MODE_X == default_width && VIDEO_MODE_Y == default_height && VIDEO_MODE_DEPTH == default_depth) { |
981 |
> |
default_id = VIDEO_MODE_RESOLUTION; |
982 |
> |
#ifdef SHEEPSHAVER |
983 |
> |
std::vector<VIDEO_MODE>::const_iterator begin = VideoModes.begin(); |
984 |
> |
cur_mode = distance(begin, i); |
985 |
> |
#endif |
986 |
|
break; |
987 |
|
} |
988 |
|
} |
989 |
|
if (i == end) { // not found, use first available mode |
990 |
< |
default_depth = VideoModes[0].depth; |
991 |
< |
default_id = VideoModes[0].resolution_id; |
990 |
> |
const VIDEO_MODE & mode = VideoModes[0]; |
991 |
> |
default_depth = VIDEO_MODE_DEPTH; |
992 |
> |
default_id = VIDEO_MODE_RESOLUTION; |
993 |
> |
#ifdef SHEEPSHAVER |
994 |
> |
cur_mode = 0; |
995 |
> |
#endif |
996 |
|
} |
997 |
|
|
998 |
+ |
#ifdef SHEEPSHAVER |
999 |
+ |
for (int i = 0; i < VideoModes.size(); i++) |
1000 |
+ |
VModes[i] = VideoModes[i]; |
1001 |
+ |
VideoInfo *p = &VModes[VideoModes.size()]; |
1002 |
+ |
p->viType = DIS_INVALID; // End marker |
1003 |
+ |
p->viRowBytes = 0; |
1004 |
+ |
p->viXsize = p->viYsize = 0; |
1005 |
+ |
p->viAppleMode = 0; |
1006 |
+ |
p->viAppleID = 0; |
1007 |
+ |
#endif |
1008 |
+ |
|
1009 |
|
#if DEBUG |
1010 |
|
D(bug("Available video modes:\n")); |
1011 |
|
for (i = VideoModes.begin(); i != end; ++i) { |
1012 |
< |
int bits = 1 << i->depth; |
1012 |
> |
const VIDEO_MODE & mode = (*i); |
1013 |
> |
int bits = 1 << VIDEO_MODE_DEPTH; |
1014 |
|
if (bits == 16) |
1015 |
|
bits = 15; |
1016 |
|
else if (bits == 32) |
1017 |
|
bits = 24; |
1018 |
< |
D(bug(" %dx%d (ID %02x), %d colors\n", i->x, i->y, i->resolution_id, 1 << bits)); |
1018 |
> |
D(bug(" %dx%d (ID %02x), %d colors\n", VIDEO_MODE_X, VIDEO_MODE_Y, VIDEO_MODE_RESOLUTION, 1 << bits)); |
1019 |
|
} |
1020 |
|
#endif |
1021 |
|
|
1022 |
|
// Create SDL_monitor_desc for this (the only) display |
1023 |
< |
SDL_monitor_desc *monitor = new SDL_monitor_desc(VideoModes, default_depth, default_id); |
1023 |
> |
SDL_monitor_desc *monitor = new SDL_monitor_desc(VideoModes, (video_depth)default_depth, default_id); |
1024 |
|
VideoMonitors.push_back(monitor); |
1025 |
|
|
1026 |
|
// Open display |
1040 |
|
// Stop redraw thread |
1041 |
|
if (redraw_thread_active) { |
1042 |
|
redraw_thread_cancel = true; |
1043 |
< |
// SDL_WaitThread(redraw_thread, NULL); doesn't work |
750 |
< |
while (redraw_thread_cancel); |
1043 |
> |
SDL_WaitThread(redraw_thread, NULL); |
1044 |
|
} |
1045 |
|
redraw_thread_active = false; |
1046 |
|
|
1090 |
|
* Mac VBL interrupt |
1091 |
|
*/ |
1092 |
|
|
1093 |
+ |
/* |
1094 |
+ |
* Execute video VBL routine |
1095 |
+ |
*/ |
1096 |
+ |
|
1097 |
+ |
#ifdef SHEEPSHAVER |
1098 |
+ |
void VideoVBL(void) |
1099 |
+ |
{ |
1100 |
+ |
// Emergency quit requested? Then quit |
1101 |
+ |
if (emerg_quit) |
1102 |
+ |
QuitEmulator(); |
1103 |
+ |
|
1104 |
+ |
// Temporarily give up frame buffer lock (this is the point where |
1105 |
+ |
// we are suspended when the user presses Ctrl-Tab) |
1106 |
+ |
UNLOCK_FRAME_BUFFER; |
1107 |
+ |
LOCK_FRAME_BUFFER; |
1108 |
+ |
|
1109 |
+ |
// Execute video VBL |
1110 |
+ |
if (private_data != NULL && private_data->interruptsEnabled) |
1111 |
+ |
VSLDoInterruptService(private_data->vslServiceID); |
1112 |
+ |
} |
1113 |
+ |
#else |
1114 |
|
void VideoInterrupt(void) |
1115 |
|
{ |
1116 |
+ |
// We must fill in the events queue in the same thread that did call SDL_SetVideoMode() |
1117 |
+ |
SDL_PumpEvents(); |
1118 |
+ |
|
1119 |
|
// Emergency quit requested? Then quit |
1120 |
|
if (emerg_quit) |
1121 |
|
QuitEmulator(); |
1125 |
|
UNLOCK_FRAME_BUFFER; |
1126 |
|
LOCK_FRAME_BUFFER; |
1127 |
|
} |
1128 |
+ |
#endif |
1129 |
|
|
1130 |
|
|
1131 |
|
/* |
1132 |
|
* Set palette |
1133 |
|
*/ |
1134 |
|
|
1135 |
+ |
#ifdef SHEEPSHAVER |
1136 |
+ |
void video_set_palette(void) |
1137 |
+ |
{ |
1138 |
+ |
monitor_desc * monitor = VideoMonitors[0]; |
1139 |
+ |
int n_colors = palette_size(monitor->get_current_mode().viAppleMode); |
1140 |
+ |
uint8 pal[256 * 3]; |
1141 |
+ |
for (int c = 0; c < n_colors; c++) { |
1142 |
+ |
pal[c*3 + 0] = mac_pal[c].red; |
1143 |
+ |
pal[c*3 + 1] = mac_pal[c].green; |
1144 |
+ |
pal[c*3 + 2] = mac_pal[c].blue; |
1145 |
+ |
} |
1146 |
+ |
monitor->set_palette(pal, n_colors); |
1147 |
+ |
} |
1148 |
+ |
#endif |
1149 |
+ |
|
1150 |
|
void SDL_monitor_desc::set_palette(uint8 *pal, int num_in) |
1151 |
|
{ |
1152 |
< |
const video_mode &mode = get_current_mode(); |
1152 |
> |
const VIDEO_MODE &mode = get_current_mode(); |
1153 |
|
|
1154 |
|
// FIXME: how can we handle the gamma ramp? |
1155 |
< |
if (mode.depth > VDEPTH_8BIT) |
1155 |
> |
if ((int)VIDEO_MODE_DEPTH > VIDEO_DEPTH_8BIT) |
1156 |
|
return; |
1157 |
|
|
1158 |
|
LOCK_PALETTE; |
1177 |
|
} |
1178 |
|
|
1179 |
|
#ifdef ENABLE_VOSF |
1180 |
< |
// We have to redraw everything because the interpretation of pixel values changed |
1181 |
< |
LOCK_VOSF; |
1182 |
< |
PFLAG_SET_ALL; |
1183 |
< |
UNLOCK_VOSF; |
1184 |
< |
memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y); |
1180 |
> |
if (use_vosf) { |
1181 |
> |
// We have to redraw everything because the interpretation of pixel values changed |
1182 |
> |
LOCK_VOSF; |
1183 |
> |
PFLAG_SET_ALL; |
1184 |
> |
UNLOCK_VOSF; |
1185 |
> |
memset(the_buffer_copy, 0, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y); |
1186 |
> |
} |
1187 |
|
#endif |
1188 |
|
} |
1189 |
|
|
1198 |
|
* Switch video mode |
1199 |
|
*/ |
1200 |
|
|
1201 |
+ |
#ifdef SHEEPSHAVER |
1202 |
+ |
int16 video_mode_change(VidLocals *csSave, uint32 ParamPtr) |
1203 |
+ |
{ |
1204 |
+ |
/* return if no mode change */ |
1205 |
+ |
if ((csSave->saveData == ReadMacInt32(ParamPtr + csData)) && |
1206 |
+ |
(csSave->saveMode == ReadMacInt16(ParamPtr + csMode))) return noErr; |
1207 |
+ |
|
1208 |
+ |
/* first find video mode in table */ |
1209 |
+ |
for (int i=0; VModes[i].viType != DIS_INVALID; i++) { |
1210 |
+ |
if ((ReadMacInt16(ParamPtr + csMode) == VModes[i].viAppleMode) && |
1211 |
+ |
(ReadMacInt32(ParamPtr + csData) == VModes[i].viAppleID)) { |
1212 |
+ |
csSave->saveMode = ReadMacInt16(ParamPtr + csMode); |
1213 |
+ |
csSave->saveData = ReadMacInt32(ParamPtr + csData); |
1214 |
+ |
csSave->savePage = ReadMacInt16(ParamPtr + csPage); |
1215 |
+ |
|
1216 |
+ |
// Disable interrupts |
1217 |
+ |
DisableInterrupt(); |
1218 |
+ |
|
1219 |
+ |
cur_mode = i; |
1220 |
+ |
monitor_desc *monitor = VideoMonitors[0]; |
1221 |
+ |
monitor->switch_to_current_mode(); |
1222 |
+ |
|
1223 |
+ |
WriteMacInt32(ParamPtr + csBaseAddr, screen_base); |
1224 |
+ |
csSave->saveBaseAddr=screen_base; |
1225 |
+ |
csSave->saveData=VModes[cur_mode].viAppleID;/* First mode ... */ |
1226 |
+ |
csSave->saveMode=VModes[cur_mode].viAppleMode; |
1227 |
+ |
|
1228 |
+ |
// Enable interrupts |
1229 |
+ |
EnableInterrupt(); |
1230 |
+ |
return noErr; |
1231 |
+ |
} |
1232 |
+ |
} |
1233 |
+ |
return paramErr; |
1234 |
+ |
} |
1235 |
+ |
#endif |
1236 |
+ |
|
1237 |
|
void SDL_monitor_desc::switch_to_current_mode(void) |
1238 |
|
{ |
1239 |
|
// Close and reopen display |
1248 |
|
|
1249 |
|
|
1250 |
|
/* |
1251 |
< |
* Translate key event to Mac keycode, returns -1 if no keycode was found |
881 |
< |
* and -2 if the key was recognized as a hotkey |
1251 |
> |
* Can we set the MacOS cursor image into the window? |
1252 |
|
*/ |
1253 |
|
|
1254 |
+ |
#ifdef SHEEPSHAVER |
1255 |
+ |
bool video_can_change_cursor(void) |
1256 |
+ |
{ |
1257 |
+ |
return (display_type == DISPLAY_WINDOW); |
1258 |
+ |
} |
1259 |
+ |
#endif |
1260 |
+ |
|
1261 |
+ |
|
1262 |
+ |
/* |
1263 |
+ |
* Set cursor image for window |
1264 |
+ |
*/ |
1265 |
+ |
|
1266 |
+ |
#ifdef SHEEPSHAVER |
1267 |
+ |
void video_set_cursor(void) |
1268 |
+ |
{ |
1269 |
+ |
cursor_changed = true; |
1270 |
+ |
} |
1271 |
+ |
#endif |
1272 |
+ |
|
1273 |
+ |
|
1274 |
+ |
/* |
1275 |
+ |
* Keyboard-related utilify functions |
1276 |
+ |
*/ |
1277 |
+ |
|
1278 |
+ |
static bool is_modifier_key(SDL_KeyboardEvent const & e) |
1279 |
+ |
{ |
1280 |
+ |
switch (e.keysym.sym) { |
1281 |
+ |
case SDLK_NUMLOCK: |
1282 |
+ |
case SDLK_CAPSLOCK: |
1283 |
+ |
case SDLK_SCROLLOCK: |
1284 |
+ |
case SDLK_RSHIFT: |
1285 |
+ |
case SDLK_LSHIFT: |
1286 |
+ |
case SDLK_RCTRL: |
1287 |
+ |
case SDLK_LCTRL: |
1288 |
+ |
case SDLK_RALT: |
1289 |
+ |
case SDLK_LALT: |
1290 |
+ |
case SDLK_RMETA: |
1291 |
+ |
case SDLK_LMETA: |
1292 |
+ |
case SDLK_LSUPER: |
1293 |
+ |
case SDLK_RSUPER: |
1294 |
+ |
case SDLK_MODE: |
1295 |
+ |
case SDLK_COMPOSE: |
1296 |
+ |
return true; |
1297 |
+ |
} |
1298 |
+ |
return false; |
1299 |
+ |
} |
1300 |
+ |
|
1301 |
|
static bool is_ctrl_down(SDL_keysym const & ks) |
1302 |
|
{ |
1303 |
|
return ctrl_down || (ks.mod & KMOD_CTRL); |
1304 |
|
} |
1305 |
|
|
1306 |
+ |
|
1307 |
+ |
/* |
1308 |
+ |
* Translate key event to Mac keycode, returns -1 if no keycode was found |
1309 |
+ |
* and -2 if the key was recognized as a hotkey |
1310 |
+ |
*/ |
1311 |
+ |
|
1312 |
|
static int kc_decode(SDL_keysym const & ks, bool key_down) |
1313 |
|
{ |
1314 |
|
switch (ks.sym) { |
1378 |
|
case SDLK_RCTRL: return 0x36; |
1379 |
|
case SDLK_LSHIFT: return 0x38; |
1380 |
|
case SDLK_RSHIFT: return 0x38; |
1381 |
+ |
#if (defined(__APPLE__) && defined(__MACH__)) |
1382 |
+ |
case SDLK_LALT: return 0x3a; |
1383 |
+ |
case SDLK_RALT: return 0x3a; |
1384 |
+ |
case SDLK_LMETA: return 0x37; |
1385 |
+ |
case SDLK_RMETA: return 0x37; |
1386 |
+ |
#else |
1387 |
|
case SDLK_LALT: return 0x37; |
1388 |
|
case SDLK_RALT: return 0x37; |
1389 |
|
case SDLK_LMETA: return 0x3a; |
1390 |
|
case SDLK_RMETA: return 0x3a; |
1391 |
+ |
#endif |
1392 |
|
case SDLK_MENU: return 0x32; |
1393 |
|
case SDLK_CAPSLOCK: return 0x39; |
1394 |
|
case SDLK_NUMLOCK: return 0x47; |
1451 |
|
|
1452 |
|
static void handle_events(void) |
1453 |
|
{ |
1454 |
< |
SDL_Event event; |
1455 |
< |
while (SDL_PollEvent(&event)) { |
1456 |
< |
switch (event.type) { |
1454 |
> |
SDL_Event events[10]; |
1455 |
> |
const int n_max_events = sizeof(events) / sizeof(events[0]); |
1456 |
> |
int n_events; |
1457 |
> |
|
1458 |
> |
while ((n_events = SDL_PeepEvents(events, n_max_events, SDL_GETEVENT, sdl_eventmask)) > 0) { |
1459 |
> |
for (int i = 0; i < n_events; i++) { |
1460 |
> |
SDL_Event const & event = events[i]; |
1461 |
> |
switch (event.type) { |
1462 |
|
|
1463 |
|
// Mouse button |
1464 |
|
case SDL_MOUSEBUTTONDOWN: { |
1495 |
|
// Keyboard |
1496 |
|
case SDL_KEYDOWN: { |
1497 |
|
int code = -1; |
1498 |
< |
if (use_keycodes) { |
1498 |
> |
if (use_keycodes && !is_modifier_key(event.key)) { |
1499 |
|
if (event2keycode(event.key, true) != -2) // This is called to process the hotkeys |
1500 |
|
code = keycode_table[event.key.keysym.scancode & 0xff]; |
1501 |
|
} else |
1523 |
|
} |
1524 |
|
case SDL_KEYUP: { |
1525 |
|
int code = -1; |
1526 |
< |
if (use_keycodes) { |
1526 |
> |
if (use_keycodes && !is_modifier_key(event.key)) { |
1527 |
|
if (event2keycode(event.key, false) != -2) // This is called to process the hotkeys |
1528 |
|
code = keycode_table[event.key.keysym.scancode & 0xff]; |
1529 |
|
} else |
1530 |
|
code = event2keycode(event.key, false); |
1531 |
< |
if (code >= 0 && code != 0x39) { // Don't propagate Caps Lock releases |
1532 |
< |
ADBKeyUp(code); |
1531 |
> |
if (code >= 0) { |
1532 |
> |
if (code == 0x39) { // Caps Lock released |
1533 |
> |
if (caps_on) { |
1534 |
> |
ADBKeyUp(code); |
1535 |
> |
caps_on = false; |
1536 |
> |
} else { |
1537 |
> |
ADBKeyDown(code); |
1538 |
> |
caps_on = true; |
1539 |
> |
} |
1540 |
> |
} else |
1541 |
> |
ADBKeyUp(code); |
1542 |
|
if (code == 0x36) |
1543 |
|
ctrl_down = false; |
1544 |
|
} |
1548 |
|
// Hidden parts exposed, force complete refresh of window |
1549 |
|
case SDL_VIDEOEXPOSE: |
1550 |
|
if (display_type == DISPLAY_WINDOW) { |
1551 |
< |
const video_mode &mode = VideoMonitors[0]->get_current_mode(); |
1551 |
> |
const VIDEO_MODE &mode = VideoMonitors[0]->get_current_mode(); |
1552 |
|
#ifdef ENABLE_VOSF |
1553 |
|
if (use_vosf) { // VOSF refresh |
1554 |
|
LOCK_VOSF; |
1555 |
|
PFLAG_SET_ALL; |
1556 |
|
UNLOCK_VOSF; |
1557 |
< |
memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y); |
1557 |
> |
memset(the_buffer_copy, 0, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y); |
1558 |
|
} |
1559 |
|
else |
1560 |
|
#endif |
1561 |
< |
memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y); |
1561 |
> |
memset(the_buffer_copy, 0, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y); |
1562 |
|
} |
1563 |
|
break; |
1564 |
|
|
1567 |
|
ADBKeyDown(0x7f); // Power key |
1568 |
|
ADBKeyUp(0x7f); |
1569 |
|
break; |
1570 |
+ |
} |
1571 |
|
} |
1572 |
|
} |
1573 |
|
} |
1582 |
|
{ |
1583 |
|
// Incremental update code |
1584 |
|
int wide = 0, high = 0, x1, x2, y1, y2, i, j; |
1585 |
< |
const video_mode &mode = drv->mode; |
1586 |
< |
int bytes_per_row = mode.bytes_per_row; |
1585 |
> |
const VIDEO_MODE &mode = drv->mode; |
1586 |
> |
int bytes_per_row = VIDEO_MODE_ROW_BYTES; |
1587 |
|
uint8 *p, *p2; |
1588 |
|
|
1589 |
|
// Check for first line from top and first line from bottom that have changed |
1590 |
|
y1 = 0; |
1591 |
< |
for (j=0; j<mode.y; j++) { |
1591 |
> |
for (j=0; j<VIDEO_MODE_Y; j++) { |
1592 |
|
if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) { |
1593 |
|
y1 = j; |
1594 |
|
break; |
1595 |
|
} |
1596 |
|
} |
1597 |
|
y2 = y1 - 1; |
1598 |
< |
for (j=mode.y-1; j>=y1; j--) { |
1598 |
> |
for (j=VIDEO_MODE_Y-1; j>=y1; j--) { |
1599 |
|
if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) { |
1600 |
|
y2 = j; |
1601 |
|
break; |
1605 |
|
|
1606 |
|
// Check for first column from left and first column from right that have changed |
1607 |
|
if (high) { |
1608 |
< |
if (mode.depth < VDEPTH_8BIT) { |
1608 |
> |
if ((int)VIDEO_MODE_DEPTH < VIDEO_DEPTH_8BIT) { |
1609 |
|
const int src_bytes_per_row = bytes_per_row; |
1610 |
|
const int dst_bytes_per_row = drv->s->pitch; |
1611 |
< |
const int pixels_per_byte = mode.x / src_bytes_per_row; |
1611 |
> |
const int pixels_per_byte = VIDEO_MODE_X / src_bytes_per_row; |
1612 |
|
|
1613 |
< |
x1 = mode.x / pixels_per_byte; |
1613 |
> |
x1 = VIDEO_MODE_X / pixels_per_byte; |
1614 |
|
for (j = y1; j <= y2; j++) { |
1615 |
|
p = &the_buffer[j * bytes_per_row]; |
1616 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1628 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1629 |
|
p += bytes_per_row; |
1630 |
|
p2 += bytes_per_row; |
1631 |
< |
for (i = (mode.x / pixels_per_byte); i > x2; i--) { |
1631 |
> |
for (i = (VIDEO_MODE_X / pixels_per_byte); i > x2; i--) { |
1632 |
|
p--; p2--; |
1633 |
|
if (*p != *p2) { |
1634 |
|
x2 = i; |
1666 |
|
} |
1667 |
|
|
1668 |
|
} else { |
1669 |
< |
const int bytes_per_pixel = mode.bytes_per_row / mode.x; |
1669 |
> |
const int bytes_per_pixel = VIDEO_MODE_ROW_BYTES / VIDEO_MODE_X; |
1670 |
|
|
1671 |
< |
x1 = mode.x; |
1671 |
> |
x1 = VIDEO_MODE_X; |
1672 |
|
for (j=y1; j<=y2; j++) { |
1673 |
|
p = &the_buffer[j * bytes_per_row]; |
1674 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1686 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1687 |
|
p += bytes_per_row; |
1688 |
|
p2 += bytes_per_row; |
1689 |
< |
for (i=mode.x*bytes_per_pixel; i>x2*bytes_per_pixel; i--) { |
1689 |
> |
for (i=VIDEO_MODE_X*bytes_per_pixel; i>x2*bytes_per_pixel; i--) { |
1690 |
|
p--; |
1691 |
|
p2--; |
1692 |
|
if (*p != *p2) { |
1846 |
|
} |
1847 |
|
} |
1848 |
|
|
1849 |
+ |
const int VIDEO_REFRESH_HZ = 60; |
1850 |
+ |
const int VIDEO_REFRESH_DELAY = 1000000 / VIDEO_REFRESH_HZ; |
1851 |
+ |
|
1852 |
|
static int redraw_func(void *arg) |
1853 |
|
{ |
1854 |
|
uint64 start = GetTicks_usec(); |
1855 |
|
int64 ticks = 0; |
1856 |
+ |
uint64 next = GetTicks_usec() + VIDEO_REFRESH_DELAY; |
1857 |
|
|
1858 |
|
while (!redraw_thread_cancel) { |
1859 |
|
|
1860 |
|
// Wait |
1861 |
< |
Delay_usec(16667); |
1861 |
> |
next += VIDEO_REFRESH_DELAY; |
1862 |
> |
int64 delay = next - GetTicks_usec(); |
1863 |
> |
if (delay > 0) |
1864 |
> |
Delay_usec(delay); |
1865 |
> |
else if (delay < -VIDEO_REFRESH_DELAY) |
1866 |
> |
next = GetTicks_usec(); |
1867 |
> |
ticks++; |
1868 |
|
|
1869 |
|
// Handle SDL events |
1870 |
|
handle_events(); |
1871 |
|
|
1872 |
|
// Refresh display |
1873 |
|
video_refresh(); |
1874 |
< |
ticks++; |
1874 |
> |
|
1875 |
> |
#ifdef SHEEPSHAVER |
1876 |
> |
// Set new cursor image if it was changed |
1877 |
> |
if (cursor_changed && sdl_cursor) { |
1878 |
> |
cursor_changed = false; |
1879 |
> |
SDL_FreeCursor(sdl_cursor); |
1880 |
> |
sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, MacCursor[2], MacCursor[3]); |
1881 |
> |
if (sdl_cursor) |
1882 |
> |
SDL_SetCursor(sdl_cursor); |
1883 |
> |
} |
1884 |
> |
#endif |
1885 |
|
|
1886 |
|
// Set new palette if it was changed |
1887 |
|
handle_palette_changes(); |
1889 |
|
|
1890 |
|
uint64 end = GetTicks_usec(); |
1891 |
|
D(bug("%lld refreshes in %lld usec = %f refreshes/sec\n", ticks, end - start, ticks * 1000000.0 / (end - start))); |
1427 |
– |
redraw_thread_cancel = false; |
1892 |
|
return 0; |
1893 |
|
} |