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 |
|
|
78 |
– |
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; |
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) |
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 |
+ |
// Check wether specified mode is available |
356 |
+ |
static bool has_mode(int type, int width, int height) |
357 |
+ |
{ |
358 |
+ |
// FIXME: no fullscreen support yet |
359 |
+ |
if (type == DISPLAY_SCREEN) |
360 |
+ |
return false; |
361 |
+ |
|
362 |
+ |
#ifdef SHEEPSHAVER |
363 |
+ |
// Filter out Classic resolutiosn |
364 |
+ |
if (width == 512 && height == 384) |
365 |
+ |
return false; |
366 |
+ |
|
367 |
+ |
// Read window modes prefs |
368 |
+ |
static uint32 window_modes = 0; |
369 |
+ |
static uint32 screen_modes = 0; |
370 |
+ |
if (window_modes == 0 || screen_modes == 0) { |
371 |
+ |
window_modes = PrefsFindInt32("windowmodes"); |
372 |
+ |
screen_modes = PrefsFindInt32("screenmodes"); |
373 |
+ |
if (window_modes == 0 || screen_modes == 0) |
374 |
+ |
window_modes |= 3; // Allow at least 640x480 and 800x600 window modes |
375 |
+ |
} |
376 |
+ |
|
377 |
+ |
if (type == DISPLAY_WINDOW) { |
378 |
+ |
int apple_mask, apple_id = find_apple_resolution(width, height); |
379 |
+ |
switch (apple_id) { |
380 |
+ |
case APPLE_640x480: apple_mask = 0x01; break; |
381 |
+ |
case APPLE_800x600: apple_mask = 0x02; break; |
382 |
+ |
case APPLE_1024x768: apple_mask = 0x04; break; |
383 |
+ |
case APPLE_1152x768: apple_mask = 0x40; break; |
384 |
+ |
case APPLE_1152x900: apple_mask = 0x08; break; |
385 |
+ |
case APPLE_1280x1024: apple_mask = 0x10; break; |
386 |
+ |
case APPLE_1600x1200: apple_mask = 0x20; break; |
387 |
+ |
default: apple_mask = 0x00; break; |
388 |
+ |
} |
389 |
+ |
return (window_modes & apple_mask); |
390 |
+ |
} |
391 |
+ |
#else |
392 |
+ |
return true; |
393 |
+ |
#endif |
394 |
+ |
return false; |
395 |
+ |
} |
396 |
+ |
|
397 |
|
// Add mode to list of supported modes |
398 |
< |
static void add_mode(uint32 width, uint32 height, uint32 resolution_id, uint32 bytes_per_row, video_depth depth) |
398 |
> |
static void add_mode(int type, int width, int height, int resolution_id, int bytes_per_row, int depth) |
399 |
|
{ |
400 |
< |
video_mode mode; |
401 |
< |
mode.x = width; |
402 |
< |
mode.y = height; |
403 |
< |
mode.resolution_id = resolution_id; |
404 |
< |
mode.bytes_per_row = bytes_per_row; |
405 |
< |
mode.depth = depth; |
400 |
> |
// Filter out unsupported modes |
401 |
> |
if (!has_mode(type, width, height)) |
402 |
> |
return; |
403 |
> |
|
404 |
> |
// Fill in VideoMode entry |
405 |
> |
VIDEO_MODE mode; |
406 |
> |
#ifdef SHEEPSHAVER |
407 |
> |
// Recalculate dimensions to fit Apple modes |
408 |
> |
resolution_id = match_apple_resolution(width, height); |
409 |
> |
mode.viType = type; |
410 |
> |
#endif |
411 |
> |
VIDEO_MODE_X = width; |
412 |
> |
VIDEO_MODE_Y = height; |
413 |
> |
VIDEO_MODE_RESOLUTION = resolution_id; |
414 |
> |
VIDEO_MODE_ROW_BYTES = bytes_per_row; |
415 |
> |
VIDEO_MODE_DEPTH = (video_depth)depth; |
416 |
|
VideoModes.push_back(mode); |
417 |
|
} |
418 |
|
|
419 |
|
// Add standard list of windowed modes for given color depth |
420 |
< |
static void add_window_modes(video_depth depth) |
420 |
> |
static void add_window_modes(int depth) |
421 |
|
{ |
422 |
< |
add_mode(512, 384, 0x80, TrivialBytesPerRow(512, depth), depth); |
423 |
< |
add_mode(640, 480, 0x81, TrivialBytesPerRow(640, depth), depth); |
424 |
< |
add_mode(800, 600, 0x82, TrivialBytesPerRow(800, depth), depth); |
425 |
< |
add_mode(1024, 768, 0x83, TrivialBytesPerRow(1024, depth), depth); |
426 |
< |
add_mode(1152, 870, 0x84, TrivialBytesPerRow(1152, depth), depth); |
427 |
< |
add_mode(1280, 1024, 0x85, TrivialBytesPerRow(1280, depth), depth); |
428 |
< |
add_mode(1600, 1200, 0x86, TrivialBytesPerRow(1600, depth), depth); |
422 |
> |
video_depth vdepth = (video_depth)depth; |
423 |
> |
add_mode(DISPLAY_WINDOW, 512, 384, 0x80, TrivialBytesPerRow(512, vdepth), depth); |
424 |
> |
add_mode(DISPLAY_WINDOW, 640, 480, 0x81, TrivialBytesPerRow(640, vdepth), depth); |
425 |
> |
add_mode(DISPLAY_WINDOW, 800, 600, 0x82, TrivialBytesPerRow(800, vdepth), depth); |
426 |
> |
add_mode(DISPLAY_WINDOW, 1024, 768, 0x83, TrivialBytesPerRow(1024, vdepth), depth); |
427 |
> |
add_mode(DISPLAY_WINDOW, 1152, 870, 0x84, TrivialBytesPerRow(1152, vdepth), depth); |
428 |
> |
add_mode(DISPLAY_WINDOW, 1280, 1024, 0x85, TrivialBytesPerRow(1280, vdepth), depth); |
429 |
> |
add_mode(DISPLAY_WINDOW, 1600, 1200, 0x86, TrivialBytesPerRow(1600, vdepth), depth); |
430 |
|
} |
431 |
|
|
432 |
|
// Set Mac frame layout and base address (uses the_buffer/MacFrameBaseMac) |
433 |
< |
static void set_mac_frame_buffer(SDL_monitor_desc &monitor, video_depth depth, bool native_byte_order) |
433 |
> |
static void set_mac_frame_buffer(SDL_monitor_desc &monitor, int depth, bool native_byte_order) |
434 |
|
{ |
435 |
|
#if !REAL_ADDRESSING && !DIRECT_ADDRESSING |
436 |
|
int layout = FLAYOUT_DIRECT; |
437 |
< |
if (depth == VDEPTH_16BIT) |
437 |
> |
if (depth == VIDEO_DEPTH_16BIT) |
438 |
|
layout = (screen_depth == 15) ? FLAYOUT_HOST_555 : FLAYOUT_HOST_565; |
439 |
< |
else if (depth == VDEPTH_32BIT) |
439 |
> |
else if (depth == VIDEO_DEPTH_32BIT) |
440 |
|
layout = (screen_depth == 24) ? FLAYOUT_HOST_888 : FLAYOUT_DIRECT; |
441 |
|
if (native_byte_order) |
442 |
|
MacFrameLayout = layout; |
445 |
|
monitor.set_mac_frame_base(MacFrameBaseMac); |
446 |
|
|
447 |
|
// Set variables used by UAE memory banking |
448 |
< |
const video_mode &mode = monitor.get_current_mode(); |
448 |
> |
const VIDEO_MODE &mode = monitor.get_current_mode(); |
449 |
|
MacFrameBaseHost = the_buffer; |
450 |
< |
MacFrameSize = mode.bytes_per_row * mode.y; |
450 |
> |
MacFrameSize = VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y; |
451 |
|
InitFrameBufferMapping(); |
452 |
|
#else |
453 |
|
monitor.set_mac_frame_base(Host2MacAddr(the_buffer)); |
496 |
|
|
497 |
|
public: |
498 |
|
SDL_monitor_desc &monitor; // Associated video monitor |
499 |
< |
const video_mode &mode; // Video mode handled by the driver |
499 |
> |
const VIDEO_MODE &mode; // Video mode handled by the driver |
500 |
|
|
501 |
|
bool init_ok; // Initialization succeeded (we can't use exceptions because of -fomit-frame-pointer) |
502 |
|
SDL_Surface *s; // The surface we draw into |
584 |
|
// Palette has changed |
585 |
|
void driver_base::update_palette(void) |
586 |
|
{ |
587 |
< |
const video_mode &mode = monitor.get_current_mode(); |
587 |
> |
const VIDEO_MODE &mode = monitor.get_current_mode(); |
588 |
|
|
589 |
< |
if (mode.depth <= VDEPTH_8BIT) |
589 |
> |
if ((int)VIDEO_MODE_DEPTH <= VIDEO_DEPTH_8BIT) |
590 |
|
SDL_SetPalette(s, SDL_PHYSPAL, sdl_palette, 0, 256); |
591 |
|
} |
592 |
|
|
609 |
|
driver_window::driver_window(SDL_monitor_desc &m) |
610 |
|
: driver_base(m), mouse_grabbed(false) |
611 |
|
{ |
612 |
< |
int width = mode.x, height = mode.y; |
612 |
> |
int width = VIDEO_MODE_X, height = VIDEO_MODE_Y; |
613 |
|
int aligned_width = (width + 15) & ~15; |
614 |
|
int aligned_height = (height + 15) & ~15; |
615 |
|
|
617 |
|
ADBSetRelMouseMode(mouse_grabbed); |
618 |
|
|
619 |
|
// Create surface |
620 |
< |
int depth = (mode.depth <= VDEPTH_8BIT ? 8 : screen_depth); |
620 |
> |
int depth = ((int)VIDEO_MODE_DEPTH <= VIDEO_DEPTH_8BIT ? 8 : screen_depth); |
621 |
|
if ((s = SDL_SetVideoMode(width, height, depth, SDL_HWSURFACE)) == NULL) |
622 |
|
return; |
623 |
|
|
629 |
|
the_buffer = (uint8 *)vm_acquire(the_buffer_size); |
630 |
|
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
631 |
|
D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer)); |
632 |
+ |
|
633 |
+ |
// Check whether we can initialize the VOSF subsystem and it's profitable |
634 |
+ |
if (!video_vosf_init(m)) { |
635 |
+ |
WarningAlert(STR_VOSF_INIT_ERR); |
636 |
+ |
use_vosf = false; |
637 |
+ |
} |
638 |
+ |
else if (!video_vosf_profitable()) { |
639 |
+ |
video_vosf_exit(); |
640 |
+ |
printf("VOSF acceleration is not profitable on this platform, disabling it\n"); |
641 |
+ |
use_vosf = false; |
642 |
+ |
} |
643 |
+ |
if (!use_vosf) { |
644 |
+ |
free(the_buffer_copy); |
645 |
+ |
vm_release(the_buffer, the_buffer_size); |
646 |
+ |
the_host_buffer = NULL; |
647 |
+ |
} |
648 |
+ |
#endif |
649 |
+ |
if (!use_vosf) { |
650 |
+ |
// Allocate memory for frame buffer |
651 |
+ |
the_buffer_size = (aligned_height + 2) * s->pitch; |
652 |
+ |
the_buffer_copy = (uint8 *)calloc(1, the_buffer_size); |
653 |
+ |
the_buffer = (uint8 *)calloc(1, the_buffer_size); |
654 |
+ |
D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy)); |
655 |
+ |
} |
656 |
+ |
|
657 |
+ |
#ifdef SHEEPSHAVER |
658 |
+ |
// Create cursor |
659 |
+ |
if ((sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, 0, 0)) != NULL) { |
660 |
+ |
SDL_SetCursor(sdl_cursor); |
661 |
+ |
cursor_changed = false; |
662 |
+ |
} |
663 |
|
#else |
664 |
< |
// Allocate memory for frame buffer |
665 |
< |
the_buffer_size = (aligned_height + 2) * s->pitch; |
409 |
< |
the_buffer_copy = (uint8 *)calloc(1, the_buffer_size); |
410 |
< |
the_buffer = (uint8 *)calloc(1, the_buffer_size); |
411 |
< |
D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy)); |
664 |
> |
// Hide cursor |
665 |
> |
SDL_ShowCursor(0); |
666 |
|
#endif |
667 |
|
|
668 |
|
// Set window name/class |
669 |
|
set_window_name(STR_WINDOW_TITLE); |
670 |
|
|
417 |
– |
// Hide cursor |
418 |
– |
SDL_ShowCursor(0); |
419 |
– |
|
671 |
|
// Init blitting routines |
672 |
|
SDL_PixelFormat *f = s->format; |
673 |
|
VisualFormat visualFormat; |
675 |
|
visualFormat.Rmask = f->Rmask; |
676 |
|
visualFormat.Gmask = f->Gmask; |
677 |
|
visualFormat.Bmask = f->Bmask; |
678 |
< |
Screen_blitter_init(visualFormat, true, sdl_depth_of_video_depth(mode.depth)); |
678 |
> |
Screen_blitter_init(visualFormat, true, sdl_depth_of_video_depth(VIDEO_MODE_DEPTH)); |
679 |
|
|
680 |
|
// Load gray ramp to 8->16/32 expand map |
681 |
|
if (!IsDirectMode(mode)) |
683 |
|
ExpandMap[i] = SDL_MapRGB(f, i, i, i); |
684 |
|
|
685 |
|
// Set frame buffer base |
686 |
< |
set_mac_frame_buffer(monitor, mode.depth, true); |
686 |
> |
set_mac_frame_buffer(monitor, VIDEO_MODE_DEPTH, true); |
687 |
|
|
688 |
|
// Everything went well |
689 |
|
init_ok = true; |
786 |
|
|
787 |
|
if (video_driver_found) { |
788 |
|
// Skip aliases |
789 |
< |
static const char alias_str[] = "alias"; |
790 |
< |
if (strncmp(line, alias_str, sizeof(alias_str) - 1) == 0) |
789 |
> |
static const char sdl_str[] = "sdl"; |
790 |
> |
if (strncmp(line, sdl_str, sizeof(sdl_str) - 1) == 0) |
791 |
|
continue; |
792 |
|
|
793 |
|
// Read keycode |
798 |
|
break; |
799 |
|
} else { |
800 |
|
// Search for SDL video driver string |
801 |
< |
static const char alias_sdl_str[] = "alias SDL"; |
802 |
< |
if (strncmp(line, alias_sdl_str, sizeof(alias_sdl_str) - 1) == 0) { |
803 |
< |
char *p = line + sizeof(alias_sdl_str); |
801 |
> |
static const char sdl_str[] = "sdl"; |
802 |
> |
if (strncmp(line, sdl_str, sizeof(sdl_str) - 1) == 0) { |
803 |
> |
char *p = line + sizeof(sdl_str); |
804 |
|
if (strstr(video_driver, p) == video_driver) |
805 |
|
video_driver_found = true; |
806 |
|
} |
825 |
|
bool SDL_monitor_desc::video_open(void) |
826 |
|
{ |
827 |
|
D(bug("video_open()\n")); |
828 |
< |
const video_mode &mode = get_current_mode(); |
828 |
> |
const VIDEO_MODE &mode = get_current_mode(); |
829 |
> |
#if DEBUG |
830 |
> |
D(bug("Current video mode:\n")); |
831 |
> |
D(bug(" %dx%d (ID %02x), %d bpp\n", VIDEO_MODE_X, VIDEO_MODE_Y, VIDEO_MODE_RESOLUTION, 1 << (VIDEO_MODE_DEPTH & 0x0f))); |
832 |
> |
#endif |
833 |
|
|
834 |
|
// Create display driver object of requested type |
835 |
|
switch (display_type) { |
845 |
|
return false; |
846 |
|
} |
847 |
|
|
593 |
– |
#ifdef ENABLE_VOSF |
594 |
– |
if (use_vosf) { |
595 |
– |
// Initialize the VOSF system |
596 |
– |
if (!video_vosf_init(*this)) { |
597 |
– |
ErrorAlert(STR_VOSF_INIT_ERR); |
598 |
– |
return false; |
599 |
– |
} |
600 |
– |
} |
601 |
– |
#endif |
602 |
– |
|
848 |
|
// Initialize VideoRefresh function |
849 |
|
VideoRefreshInit(); |
850 |
|
|
853 |
|
|
854 |
|
// Start redraw/input thread |
855 |
|
redraw_thread_cancel = false; |
856 |
< |
redraw_thread_active = (SDL_CreateThread(redraw_func, NULL) != NULL); |
856 |
> |
redraw_thread_active = ((redraw_thread = SDL_CreateThread(redraw_func, NULL)) != NULL); |
857 |
|
if (!redraw_thread_active) { |
858 |
|
printf("FATAL: cannot create redraw thread\n"); |
859 |
|
return false; |
861 |
|
return true; |
862 |
|
} |
863 |
|
|
864 |
+ |
#ifdef SHEEPSHAVER |
865 |
+ |
bool VideoInit(void) |
866 |
+ |
{ |
867 |
+ |
const bool classic = false; |
868 |
+ |
#else |
869 |
|
bool VideoInit(bool classic) |
870 |
|
{ |
871 |
+ |
#endif |
872 |
|
classic_mode = classic; |
873 |
|
|
874 |
|
#ifdef ENABLE_VOSF |
892 |
|
mouse_wheel_lines = PrefsFindInt32("mousewheellines"); |
893 |
|
|
894 |
|
// Get screen mode from preferences |
895 |
< |
const char *mode_str; |
895 |
> |
const char *mode_str = NULL; |
896 |
> |
#ifndef SHEEPSHAVER |
897 |
|
if (classic_mode) |
898 |
|
mode_str = "win/512/342"; |
899 |
|
else |
900 |
|
mode_str = PrefsFindString("screen"); |
901 |
+ |
#endif |
902 |
|
|
903 |
|
// Determine display type and default dimensions |
904 |
< |
int default_width = 512, default_height = 384; |
904 |
> |
int default_width, default_height; |
905 |
> |
if (classic) { |
906 |
> |
default_width = 512; |
907 |
> |
default_height = 384; |
908 |
> |
} |
909 |
> |
else { |
910 |
> |
default_width = 640; |
911 |
> |
default_height = 480; |
912 |
> |
} |
913 |
|
display_type = DISPLAY_WINDOW; |
914 |
|
if (mode_str) { |
915 |
|
if (sscanf(mode_str, "win/%d/%d", &default_width, &default_height) == 2) |
916 |
|
display_type = DISPLAY_WINDOW; |
917 |
|
} |
918 |
|
int max_width = 640, max_height = 480; |
919 |
< |
if (display_type == DISPLAY_SCREEN) { |
920 |
< |
SDL_Rect **modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE); |
921 |
< |
if (modes && modes != (SDL_Rect **)-1) { |
922 |
< |
max_width = modes[0]->w; |
923 |
< |
max_height = modes[0]->h; |
924 |
< |
} |
919 |
> |
SDL_Rect **modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE); |
920 |
> |
if (modes && modes != (SDL_Rect **)-1) { |
921 |
> |
max_width = modes[0]->w; |
922 |
> |
max_height = modes[0]->h; |
923 |
> |
if (default_width > max_width) |
924 |
> |
default_width = max_width; |
925 |
> |
if (default_height > max_height) |
926 |
> |
default_height = max_height; |
927 |
|
} |
928 |
|
if (default_width <= 0) |
929 |
|
default_width = max_width; |
932 |
|
|
933 |
|
// Mac screen depth follows X depth |
934 |
|
screen_depth = SDL_GetVideoInfo()->vfmt->BitsPerPixel; |
935 |
< |
video_depth default_depth; |
935 |
> |
int default_depth; |
936 |
|
switch (screen_depth) { |
937 |
|
case 8: |
938 |
< |
default_depth = VDEPTH_8BIT; |
938 |
> |
default_depth = VIDEO_DEPTH_8BIT; |
939 |
|
break; |
940 |
|
case 15: case 16: |
941 |
< |
default_depth = VDEPTH_16BIT; |
941 |
> |
default_depth = VIDEO_DEPTH_16BIT; |
942 |
|
break; |
943 |
|
case 24: case 32: |
944 |
< |
default_depth = VDEPTH_32BIT; |
944 |
> |
default_depth = VIDEO_DEPTH_32BIT; |
945 |
|
break; |
946 |
|
default: |
947 |
< |
default_depth = VDEPTH_1BIT; |
947 |
> |
default_depth = VIDEO_DEPTH_1BIT; |
948 |
|
break; |
949 |
|
} |
950 |
|
|
951 |
|
// Construct list of supported modes |
952 |
|
if (display_type == DISPLAY_WINDOW) { |
953 |
|
if (classic) |
954 |
< |
add_mode(512, 342, 0x80, 64, VDEPTH_1BIT); |
954 |
> |
add_mode(display_type, 512, 342, 0x80, 64, VIDEO_DEPTH_1BIT); |
955 |
|
else { |
956 |
< |
for (int d = VDEPTH_1BIT; d <= default_depth; d++) { |
957 |
< |
int bpp = (d <= VDEPTH_8BIT ? 8 : sdl_depth_of_video_depth(d)); |
956 |
> |
for (int d = VIDEO_DEPTH_1BIT; d <= default_depth; d++) { |
957 |
> |
int bpp = (d <= VIDEO_DEPTH_8BIT ? 8 : sdl_depth_of_video_depth(d)); |
958 |
|
if (SDL_VideoModeOK(max_width, max_height, bpp, SDL_HWSURFACE)) |
959 |
|
add_window_modes(video_depth(d)); |
960 |
|
} |
961 |
|
} |
962 |
|
} else |
963 |
< |
add_mode(default_width, default_height, 0x80, TrivialBytesPerRow(default_width, default_depth), default_depth); |
963 |
> |
add_mode(display_type, default_width, default_height, 0x80, TrivialBytesPerRow(default_width, (video_depth)default_depth), default_depth); |
964 |
|
if (VideoModes.empty()) { |
965 |
|
ErrorAlert(STR_NO_XVISUAL_ERR); |
966 |
|
return false; |
968 |
|
|
969 |
|
// Find requested default mode with specified dimensions |
970 |
|
uint32 default_id; |
971 |
< |
std::vector<video_mode>::const_iterator i, end = VideoModes.end(); |
971 |
> |
std::vector<VIDEO_MODE>::const_iterator i, end = VideoModes.end(); |
972 |
|
for (i = VideoModes.begin(); i != end; ++i) { |
973 |
< |
if (i->x == default_width && i->y == default_height && i->depth == default_depth) { |
974 |
< |
default_id = i->resolution_id; |
973 |
> |
const VIDEO_MODE & mode = (*i); |
974 |
> |
if (VIDEO_MODE_X == default_width && VIDEO_MODE_Y == default_height && VIDEO_MODE_DEPTH == default_depth) { |
975 |
> |
default_id = VIDEO_MODE_RESOLUTION; |
976 |
> |
#ifdef SHEEPSHAVER |
977 |
> |
std::vector<VIDEO_MODE>::const_iterator begin = VideoModes.begin(); |
978 |
> |
cur_mode = distance(begin, i); |
979 |
> |
#endif |
980 |
|
break; |
981 |
|
} |
982 |
|
} |
983 |
|
if (i == end) { // not found, use first available mode |
984 |
< |
default_depth = VideoModes[0].depth; |
985 |
< |
default_id = VideoModes[0].resolution_id; |
984 |
> |
const VIDEO_MODE & mode = VideoModes[0]; |
985 |
> |
default_depth = VIDEO_MODE_DEPTH; |
986 |
> |
default_id = VIDEO_MODE_RESOLUTION; |
987 |
> |
#ifdef SHEEPSHAVER |
988 |
> |
cur_mode = 0; |
989 |
> |
#endif |
990 |
|
} |
991 |
|
|
992 |
+ |
#ifdef SHEEPSHAVER |
993 |
+ |
for (int i = 0; i < VideoModes.size(); i++) |
994 |
+ |
VModes[i] = VideoModes[i]; |
995 |
+ |
VideoInfo *p = &VModes[VideoModes.size()]; |
996 |
+ |
p->viType = DIS_INVALID; // End marker |
997 |
+ |
p->viRowBytes = 0; |
998 |
+ |
p->viXsize = p->viYsize = 0; |
999 |
+ |
p->viAppleMode = 0; |
1000 |
+ |
p->viAppleID = 0; |
1001 |
+ |
#endif |
1002 |
+ |
|
1003 |
|
#if DEBUG |
1004 |
|
D(bug("Available video modes:\n")); |
1005 |
|
for (i = VideoModes.begin(); i != end; ++i) { |
1006 |
< |
int bits = 1 << i->depth; |
1006 |
> |
const VIDEO_MODE & mode = (*i); |
1007 |
> |
int bits = 1 << VIDEO_MODE_DEPTH; |
1008 |
|
if (bits == 16) |
1009 |
|
bits = 15; |
1010 |
|
else if (bits == 32) |
1011 |
|
bits = 24; |
1012 |
< |
D(bug(" %dx%d (ID %02x), %d colors\n", i->x, i->y, i->resolution_id, 1 << bits)); |
1012 |
> |
D(bug(" %dx%d (ID %02x), %d colors\n", VIDEO_MODE_X, VIDEO_MODE_Y, VIDEO_MODE_RESOLUTION, 1 << bits)); |
1013 |
|
} |
1014 |
|
#endif |
1015 |
|
|
1016 |
|
// Create SDL_monitor_desc for this (the only) display |
1017 |
< |
SDL_monitor_desc *monitor = new SDL_monitor_desc(VideoModes, default_depth, default_id); |
1017 |
> |
SDL_monitor_desc *monitor = new SDL_monitor_desc(VideoModes, (video_depth)default_depth, default_id); |
1018 |
|
VideoMonitors.push_back(monitor); |
1019 |
|
|
1020 |
|
// Open display |
1034 |
|
// Stop redraw thread |
1035 |
|
if (redraw_thread_active) { |
1036 |
|
redraw_thread_cancel = true; |
1037 |
< |
// SDL_WaitThread(redraw_thread, NULL); doesn't work |
754 |
< |
while (redraw_thread_cancel); |
1037 |
> |
SDL_WaitThread(redraw_thread, NULL); |
1038 |
|
} |
1039 |
|
redraw_thread_active = false; |
1040 |
|
|
1084 |
|
* Mac VBL interrupt |
1085 |
|
*/ |
1086 |
|
|
1087 |
+ |
/* |
1088 |
+ |
* Execute video VBL routine |
1089 |
+ |
*/ |
1090 |
+ |
|
1091 |
+ |
#ifdef SHEEPSHAVER |
1092 |
+ |
void VideoVBL(void) |
1093 |
+ |
{ |
1094 |
+ |
// Emergency quit requested? Then quit |
1095 |
+ |
if (emerg_quit) |
1096 |
+ |
QuitEmulator(); |
1097 |
+ |
|
1098 |
+ |
// Temporarily give up frame buffer lock (this is the point where |
1099 |
+ |
// we are suspended when the user presses Ctrl-Tab) |
1100 |
+ |
UNLOCK_FRAME_BUFFER; |
1101 |
+ |
LOCK_FRAME_BUFFER; |
1102 |
+ |
|
1103 |
+ |
// Execute video VBL |
1104 |
+ |
if (private_data != NULL && private_data->interruptsEnabled) |
1105 |
+ |
VSLDoInterruptService(private_data->vslServiceID); |
1106 |
+ |
} |
1107 |
+ |
#else |
1108 |
|
void VideoInterrupt(void) |
1109 |
|
{ |
1110 |
|
// We must fill in the events queue in the same thread that did call SDL_SetVideoMode() |
1119 |
|
UNLOCK_FRAME_BUFFER; |
1120 |
|
LOCK_FRAME_BUFFER; |
1121 |
|
} |
1122 |
+ |
#endif |
1123 |
|
|
1124 |
|
|
1125 |
|
/* |
1126 |
|
* Set palette |
1127 |
|
*/ |
1128 |
|
|
1129 |
+ |
#ifdef SHEEPSHAVER |
1130 |
+ |
void video_set_palette(void) |
1131 |
+ |
{ |
1132 |
+ |
monitor_desc * monitor = VideoMonitors[0]; |
1133 |
+ |
int n_colors = palette_size(monitor->get_current_mode().viAppleMode); |
1134 |
+ |
uint8 pal[256 * 3]; |
1135 |
+ |
for (int c = 0; c < n_colors; c++) { |
1136 |
+ |
pal[c*3 + 0] = mac_pal[c].red; |
1137 |
+ |
pal[c*3 + 1] = mac_pal[c].green; |
1138 |
+ |
pal[c*3 + 2] = mac_pal[c].blue; |
1139 |
+ |
} |
1140 |
+ |
monitor->set_palette(pal, n_colors); |
1141 |
+ |
} |
1142 |
+ |
#endif |
1143 |
+ |
|
1144 |
|
void SDL_monitor_desc::set_palette(uint8 *pal, int num_in) |
1145 |
|
{ |
1146 |
< |
const video_mode &mode = get_current_mode(); |
1146 |
> |
const VIDEO_MODE &mode = get_current_mode(); |
1147 |
|
|
1148 |
|
// FIXME: how can we handle the gamma ramp? |
1149 |
< |
if (mode.depth > VDEPTH_8BIT) |
1149 |
> |
if ((int)VIDEO_MODE_DEPTH > VIDEO_DEPTH_8BIT) |
1150 |
|
return; |
1151 |
|
|
1152 |
|
LOCK_PALETTE; |
1171 |
|
} |
1172 |
|
|
1173 |
|
#ifdef ENABLE_VOSF |
1174 |
< |
// We have to redraw everything because the interpretation of pixel values changed |
1175 |
< |
LOCK_VOSF; |
1176 |
< |
PFLAG_SET_ALL; |
1177 |
< |
UNLOCK_VOSF; |
1178 |
< |
memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y); |
1174 |
> |
if (use_vosf) { |
1175 |
> |
// We have to redraw everything because the interpretation of pixel values changed |
1176 |
> |
LOCK_VOSF; |
1177 |
> |
PFLAG_SET_ALL; |
1178 |
> |
UNLOCK_VOSF; |
1179 |
> |
memset(the_buffer_copy, 0, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y); |
1180 |
> |
} |
1181 |
|
#endif |
1182 |
|
} |
1183 |
|
|
1192 |
|
* Switch video mode |
1193 |
|
*/ |
1194 |
|
|
1195 |
+ |
#ifdef SHEEPSHAVER |
1196 |
+ |
int16 video_mode_change(VidLocals *csSave, uint32 ParamPtr) |
1197 |
+ |
{ |
1198 |
+ |
/* return if no mode change */ |
1199 |
+ |
if ((csSave->saveData == ReadMacInt32(ParamPtr + csData)) && |
1200 |
+ |
(csSave->saveMode == ReadMacInt16(ParamPtr + csMode))) return noErr; |
1201 |
+ |
|
1202 |
+ |
/* first find video mode in table */ |
1203 |
+ |
for (int i=0; VModes[i].viType != DIS_INVALID; i++) { |
1204 |
+ |
if ((ReadMacInt16(ParamPtr + csMode) == VModes[i].viAppleMode) && |
1205 |
+ |
(ReadMacInt32(ParamPtr + csData) == VModes[i].viAppleID)) { |
1206 |
+ |
csSave->saveMode = ReadMacInt16(ParamPtr + csMode); |
1207 |
+ |
csSave->saveData = ReadMacInt32(ParamPtr + csData); |
1208 |
+ |
csSave->savePage = ReadMacInt16(ParamPtr + csPage); |
1209 |
+ |
|
1210 |
+ |
// Disable interrupts |
1211 |
+ |
DisableInterrupt(); |
1212 |
+ |
|
1213 |
+ |
cur_mode = i; |
1214 |
+ |
monitor_desc *monitor = VideoMonitors[0]; |
1215 |
+ |
monitor->switch_to_current_mode(); |
1216 |
+ |
|
1217 |
+ |
WriteMacInt32(ParamPtr + csBaseAddr, screen_base); |
1218 |
+ |
csSave->saveBaseAddr=screen_base; |
1219 |
+ |
csSave->saveData=VModes[cur_mode].viAppleID;/* First mode ... */ |
1220 |
+ |
csSave->saveMode=VModes[cur_mode].viAppleMode; |
1221 |
+ |
|
1222 |
+ |
// Enable interrupts |
1223 |
+ |
EnableInterrupt(); |
1224 |
+ |
return noErr; |
1225 |
+ |
} |
1226 |
+ |
} |
1227 |
+ |
return paramErr; |
1228 |
+ |
} |
1229 |
+ |
#endif |
1230 |
+ |
|
1231 |
|
void SDL_monitor_desc::switch_to_current_mode(void) |
1232 |
|
{ |
1233 |
|
// Close and reopen display |
1242 |
|
|
1243 |
|
|
1244 |
|
/* |
1245 |
< |
* Translate key event to Mac keycode, returns -1 if no keycode was found |
1246 |
< |
* and -2 if the key was recognized as a hotkey |
1245 |
> |
* Can we set the MacOS cursor image into the window? |
1246 |
> |
*/ |
1247 |
> |
|
1248 |
> |
#ifdef SHEEPSHAVER |
1249 |
> |
bool video_can_change_cursor(void) |
1250 |
> |
{ |
1251 |
> |
return (display_type == DISPLAY_WINDOW); |
1252 |
> |
} |
1253 |
> |
#endif |
1254 |
> |
|
1255 |
> |
|
1256 |
> |
/* |
1257 |
> |
* Set cursor image for window |
1258 |
|
*/ |
1259 |
|
|
1260 |
+ |
#ifdef SHEEPSHAVER |
1261 |
+ |
void video_set_cursor(void) |
1262 |
+ |
{ |
1263 |
+ |
cursor_changed = true; |
1264 |
+ |
} |
1265 |
+ |
#endif |
1266 |
+ |
|
1267 |
+ |
|
1268 |
+ |
/* |
1269 |
+ |
* Keyboard-related utilify functions |
1270 |
+ |
*/ |
1271 |
+ |
|
1272 |
+ |
static bool is_modifier_key(SDL_KeyboardEvent const & e) |
1273 |
+ |
{ |
1274 |
+ |
switch (e.keysym.sym) { |
1275 |
+ |
case SDLK_NUMLOCK: |
1276 |
+ |
case SDLK_CAPSLOCK: |
1277 |
+ |
case SDLK_SCROLLOCK: |
1278 |
+ |
case SDLK_RSHIFT: |
1279 |
+ |
case SDLK_LSHIFT: |
1280 |
+ |
case SDLK_RCTRL: |
1281 |
+ |
case SDLK_LCTRL: |
1282 |
+ |
case SDLK_RALT: |
1283 |
+ |
case SDLK_LALT: |
1284 |
+ |
case SDLK_RMETA: |
1285 |
+ |
case SDLK_LMETA: |
1286 |
+ |
case SDLK_LSUPER: |
1287 |
+ |
case SDLK_RSUPER: |
1288 |
+ |
case SDLK_MODE: |
1289 |
+ |
case SDLK_COMPOSE: |
1290 |
+ |
return true; |
1291 |
+ |
} |
1292 |
+ |
return false; |
1293 |
+ |
} |
1294 |
+ |
|
1295 |
|
static bool is_ctrl_down(SDL_keysym const & ks) |
1296 |
|
{ |
1297 |
|
return ctrl_down || (ks.mod & KMOD_CTRL); |
1298 |
|
} |
1299 |
|
|
1300 |
+ |
|
1301 |
+ |
/* |
1302 |
+ |
* Translate key event to Mac keycode, returns -1 if no keycode was found |
1303 |
+ |
* and -2 if the key was recognized as a hotkey |
1304 |
+ |
*/ |
1305 |
+ |
|
1306 |
|
static int kc_decode(SDL_keysym const & ks, bool key_down) |
1307 |
|
{ |
1308 |
|
switch (ks.sym) { |
1372 |
|
case SDLK_RCTRL: return 0x36; |
1373 |
|
case SDLK_LSHIFT: return 0x38; |
1374 |
|
case SDLK_RSHIFT: return 0x38; |
1375 |
+ |
#if (defined(__APPLE__) && defined(__MACH__)) |
1376 |
+ |
case SDLK_LALT: return 0x3a; |
1377 |
+ |
case SDLK_RALT: return 0x3a; |
1378 |
+ |
case SDLK_LMETA: return 0x37; |
1379 |
+ |
case SDLK_RMETA: return 0x37; |
1380 |
+ |
#else |
1381 |
|
case SDLK_LALT: return 0x37; |
1382 |
|
case SDLK_RALT: return 0x37; |
1383 |
|
case SDLK_LMETA: return 0x3a; |
1384 |
|
case SDLK_RMETA: return 0x3a; |
1385 |
+ |
#endif |
1386 |
|
case SDLK_MENU: return 0x32; |
1387 |
|
case SDLK_CAPSLOCK: return 0x39; |
1388 |
|
case SDLK_NUMLOCK: return 0x47; |
1489 |
|
// Keyboard |
1490 |
|
case SDL_KEYDOWN: { |
1491 |
|
int code = -1; |
1492 |
< |
if (use_keycodes) { |
1492 |
> |
if (use_keycodes && !is_modifier_key(event.key)) { |
1493 |
|
if (event2keycode(event.key, true) != -2) // This is called to process the hotkeys |
1494 |
|
code = keycode_table[event.key.keysym.scancode & 0xff]; |
1495 |
|
} else |
1517 |
|
} |
1518 |
|
case SDL_KEYUP: { |
1519 |
|
int code = -1; |
1520 |
< |
if (use_keycodes) { |
1520 |
> |
if (use_keycodes && !is_modifier_key(event.key)) { |
1521 |
|
if (event2keycode(event.key, false) != -2) // This is called to process the hotkeys |
1522 |
|
code = keycode_table[event.key.keysym.scancode & 0xff]; |
1523 |
|
} else |
1524 |
|
code = event2keycode(event.key, false); |
1525 |
< |
if (code >= 0 && code != 0x39) { // Don't propagate Caps Lock releases |
1526 |
< |
ADBKeyUp(code); |
1525 |
> |
if (code >= 0) { |
1526 |
> |
if (code == 0x39) { // Caps Lock released |
1527 |
> |
if (caps_on) { |
1528 |
> |
ADBKeyUp(code); |
1529 |
> |
caps_on = false; |
1530 |
> |
} else { |
1531 |
> |
ADBKeyDown(code); |
1532 |
> |
caps_on = true; |
1533 |
> |
} |
1534 |
> |
} else |
1535 |
> |
ADBKeyUp(code); |
1536 |
|
if (code == 0x36) |
1537 |
|
ctrl_down = false; |
1538 |
|
} |
1542 |
|
// Hidden parts exposed, force complete refresh of window |
1543 |
|
case SDL_VIDEOEXPOSE: |
1544 |
|
if (display_type == DISPLAY_WINDOW) { |
1545 |
< |
const video_mode &mode = VideoMonitors[0]->get_current_mode(); |
1545 |
> |
const VIDEO_MODE &mode = VideoMonitors[0]->get_current_mode(); |
1546 |
|
#ifdef ENABLE_VOSF |
1547 |
|
if (use_vosf) { // VOSF refresh |
1548 |
|
LOCK_VOSF; |
1549 |
|
PFLAG_SET_ALL; |
1550 |
|
UNLOCK_VOSF; |
1551 |
< |
memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y); |
1551 |
> |
memset(the_buffer_copy, 0, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y); |
1552 |
|
} |
1553 |
|
else |
1554 |
|
#endif |
1555 |
< |
memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y); |
1555 |
> |
memset(the_buffer_copy, 0, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y); |
1556 |
|
} |
1557 |
|
break; |
1558 |
|
|
1576 |
|
{ |
1577 |
|
// Incremental update code |
1578 |
|
int wide = 0, high = 0, x1, x2, y1, y2, i, j; |
1579 |
< |
const video_mode &mode = drv->mode; |
1580 |
< |
int bytes_per_row = mode.bytes_per_row; |
1579 |
> |
const VIDEO_MODE &mode = drv->mode; |
1580 |
> |
int bytes_per_row = VIDEO_MODE_ROW_BYTES; |
1581 |
|
uint8 *p, *p2; |
1582 |
|
|
1583 |
|
// Check for first line from top and first line from bottom that have changed |
1584 |
|
y1 = 0; |
1585 |
< |
for (j=0; j<mode.y; j++) { |
1585 |
> |
for (j=0; j<VIDEO_MODE_Y; j++) { |
1586 |
|
if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) { |
1587 |
|
y1 = j; |
1588 |
|
break; |
1589 |
|
} |
1590 |
|
} |
1591 |
|
y2 = y1 - 1; |
1592 |
< |
for (j=mode.y-1; j>=y1; j--) { |
1592 |
> |
for (j=VIDEO_MODE_Y-1; j>=y1; j--) { |
1593 |
|
if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) { |
1594 |
|
y2 = j; |
1595 |
|
break; |
1599 |
|
|
1600 |
|
// Check for first column from left and first column from right that have changed |
1601 |
|
if (high) { |
1602 |
< |
if (mode.depth < VDEPTH_8BIT) { |
1602 |
> |
if ((int)VIDEO_MODE_DEPTH < VIDEO_DEPTH_8BIT) { |
1603 |
|
const int src_bytes_per_row = bytes_per_row; |
1604 |
|
const int dst_bytes_per_row = drv->s->pitch; |
1605 |
< |
const int pixels_per_byte = mode.x / src_bytes_per_row; |
1605 |
> |
const int pixels_per_byte = VIDEO_MODE_X / src_bytes_per_row; |
1606 |
|
|
1607 |
< |
x1 = mode.x / pixels_per_byte; |
1607 |
> |
x1 = VIDEO_MODE_X / pixels_per_byte; |
1608 |
|
for (j = y1; j <= y2; j++) { |
1609 |
|
p = &the_buffer[j * bytes_per_row]; |
1610 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1622 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1623 |
|
p += bytes_per_row; |
1624 |
|
p2 += bytes_per_row; |
1625 |
< |
for (i = (mode.x / pixels_per_byte); i > x2; i--) { |
1625 |
> |
for (i = (VIDEO_MODE_X / pixels_per_byte); i > x2; i--) { |
1626 |
|
p--; p2--; |
1627 |
|
if (*p != *p2) { |
1628 |
|
x2 = i; |
1660 |
|
} |
1661 |
|
|
1662 |
|
} else { |
1663 |
< |
const int bytes_per_pixel = mode.bytes_per_row / mode.x; |
1663 |
> |
const int bytes_per_pixel = VIDEO_MODE_ROW_BYTES / VIDEO_MODE_X; |
1664 |
|
|
1665 |
< |
x1 = mode.x; |
1665 |
> |
x1 = VIDEO_MODE_X; |
1666 |
|
for (j=y1; j<=y2; j++) { |
1667 |
|
p = &the_buffer[j * bytes_per_row]; |
1668 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1680 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1681 |
|
p += bytes_per_row; |
1682 |
|
p2 += bytes_per_row; |
1683 |
< |
for (i=mode.x*bytes_per_pixel; i>x2*bytes_per_pixel; i--) { |
1683 |
> |
for (i=VIDEO_MODE_X*bytes_per_pixel; i>x2*bytes_per_pixel; i--) { |
1684 |
|
p--; |
1685 |
|
p2--; |
1686 |
|
if (*p != *p2) { |
1840 |
|
} |
1841 |
|
} |
1842 |
|
|
1843 |
+ |
const int VIDEO_REFRESH_HZ = 60; |
1844 |
+ |
const int VIDEO_REFRESH_DELAY = 1000000 / VIDEO_REFRESH_HZ; |
1845 |
+ |
|
1846 |
|
static int redraw_func(void *arg) |
1847 |
|
{ |
1848 |
|
uint64 start = GetTicks_usec(); |
1849 |
|
int64 ticks = 0; |
1850 |
+ |
uint64 next = GetTicks_usec() + VIDEO_REFRESH_DELAY; |
1851 |
|
|
1852 |
|
while (!redraw_thread_cancel) { |
1853 |
|
|
1854 |
|
// Wait |
1855 |
< |
Delay_usec(16667); |
1855 |
> |
next += VIDEO_REFRESH_DELAY; |
1856 |
> |
int64 delay = next - GetTicks_usec(); |
1857 |
> |
if (delay > 0) |
1858 |
> |
Delay_usec(delay); |
1859 |
> |
else if (delay < -VIDEO_REFRESH_DELAY) |
1860 |
> |
next = GetTicks_usec(); |
1861 |
> |
ticks++; |
1862 |
|
|
1863 |
|
// Handle SDL events |
1864 |
|
handle_events(); |
1865 |
|
|
1866 |
|
// Refresh display |
1867 |
|
video_refresh(); |
1868 |
< |
ticks++; |
1868 |
> |
|
1869 |
> |
#ifdef SHEEPSHAVER |
1870 |
> |
// Set new cursor image if it was changed |
1871 |
> |
if (cursor_changed && sdl_cursor) { |
1872 |
> |
cursor_changed = false; |
1873 |
> |
SDL_FreeCursor(sdl_cursor); |
1874 |
> |
sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, MacCursor[2], MacCursor[3]); |
1875 |
> |
if (sdl_cursor) |
1876 |
> |
SDL_SetCursor(sdl_cursor); |
1877 |
> |
} |
1878 |
> |
#endif |
1879 |
|
|
1880 |
|
// Set new palette if it was changed |
1881 |
|
handle_palette_changes(); |
1883 |
|
|
1884 |
|
uint64 end = GetTicks_usec(); |
1885 |
|
D(bug("%lld refreshes in %lld usec = %f refreshes/sec\n", ticks, end - start, ticks * 1000000.0 / (end - start))); |
1440 |
– |
redraw_thread_cancel = false; |
1886 |
|
return 0; |
1887 |
|
} |