1 |
|
/* |
2 |
|
* video_sdl.cpp - Video/graphics emulation, SDL specific stuff |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-2004 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2005 Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
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 |
+ |
#include "vm_alloc.h" |
60 |
|
|
61 |
|
#define DEBUG 0 |
62 |
|
#include "debug.h" |
63 |
|
|
64 |
|
|
65 |
|
// Supported video modes |
66 |
< |
static vector<video_mode> VideoModes; |
66 |
> |
using std::vector; |
67 |
> |
static vector<VIDEO_MODE> VideoModes; |
68 |
|
|
69 |
|
// Display types |
70 |
+ |
#ifdef SHEEPSHAVER |
71 |
|
enum { |
72 |
< |
DISPLAY_WINDOW, // windowed display |
73 |
< |
DISPLAY_SCREEN // fullscreen display |
72 |
> |
DISPLAY_WINDOW = DIS_WINDOW, // windowed display |
73 |
> |
DISPLAY_SCREEN = DIS_SCREEN // fullscreen display |
74 |
|
}; |
75 |
+ |
extern int display_type; // See enum above |
76 |
+ |
#else |
77 |
+ |
enum { |
78 |
+ |
DISPLAY_WINDOW, // windowed display |
79 |
+ |
DISPLAY_SCREEN // fullscreen display |
80 |
+ |
}; |
81 |
+ |
static int display_type = DISPLAY_WINDOW; // See enum above |
82 |
+ |
#endif |
83 |
|
|
84 |
|
// Constants |
85 |
+ |
#ifdef WIN32 |
86 |
+ |
const char KEYCODE_FILE_NAME[] = "BasiliskII_keycodes"; |
87 |
+ |
#else |
88 |
|
const char KEYCODE_FILE_NAME[] = DATADIR "/keycodes"; |
89 |
+ |
#endif |
90 |
|
|
91 |
|
|
92 |
|
// Global variables |
94 |
|
static int16 mouse_wheel_mode; |
95 |
|
static int16 mouse_wheel_lines; |
96 |
|
|
78 |
– |
static int display_type = DISPLAY_WINDOW; // See enum above |
97 |
|
static uint8 *the_buffer = NULL; // Mac frame buffer (where MacOS draws into) |
98 |
|
static uint8 *the_buffer_copy = NULL; // Copy of Mac frame buffer (for refreshed modes) |
99 |
|
static uint32 the_buffer_size; // Size of allocated the_buffer |
101 |
|
static bool redraw_thread_active = false; // Flag: Redraw thread installed |
102 |
|
static volatile bool redraw_thread_cancel; // Flag: Cancel Redraw thread |
103 |
|
static SDL_Thread *redraw_thread = NULL; // Redraw thread |
104 |
+ |
static volatile bool thread_stop_req = false; |
105 |
+ |
static volatile bool thread_stop_ack = false; // Acknowledge for thread_stop_req |
106 |
|
|
107 |
|
#ifdef ENABLE_VOSF |
108 |
< |
static bool use_vosf = true; // Flag: VOSF enabled |
108 |
> |
static bool use_vosf = false; // Flag: VOSF enabled |
109 |
|
#else |
110 |
|
static const bool use_vosf = false; // VOSF not possible |
111 |
|
#endif |
123 |
|
|
124 |
|
// SDL variables |
125 |
|
static int screen_depth; // Depth of current screen |
126 |
+ |
static SDL_Cursor *sdl_cursor; // Copy of Mac cursor |
127 |
+ |
static volatile bool cursor_changed = false; // Flag: cursor changed, redraw_func must update the cursor |
128 |
|
static SDL_Color sdl_palette[256]; // Color palette to be used as CLUT and gamma table |
129 |
|
static bool sdl_palette_changed = false; // Flag: Palette changed, redraw thread must set new colors |
130 |
|
static const int sdl_eventmask = SDL_MOUSEBUTTONDOWNMASK | SDL_MOUSEBUTTONUPMASK | SDL_MOUSEMOTIONMASK | SDL_KEYUPMASK | SDL_KEYDOWNMASK | SDL_VIDEOEXPOSEMASK | SDL_QUITMASK; |
152 |
|
|
153 |
|
|
154 |
|
/* |
155 |
+ |
* Framebuffer allocation routines |
156 |
+ |
*/ |
157 |
+ |
|
158 |
+ |
static void *vm_acquire_framebuffer(uint32 size) |
159 |
+ |
{ |
160 |
+ |
#ifdef SHEEPSHAVER |
161 |
+ |
#ifdef DIRECT_ADDRESSING_HACK |
162 |
+ |
const uint32 FRAME_BUFFER_BASE = 0x61000000; |
163 |
+ |
uint8 *fb = Mac2HostAddr(FRAME_BUFFER_BASE); |
164 |
+ |
if (vm_acquire_fixed(fb, size) < 0) |
165 |
+ |
fb = VM_MAP_FAILED; |
166 |
+ |
return fb; |
167 |
+ |
#endif |
168 |
+ |
#endif |
169 |
+ |
return vm_acquire(size); |
170 |
+ |
} |
171 |
+ |
|
172 |
+ |
static inline void vm_release_framebuffer(void *fb, uint32 size) |
173 |
+ |
{ |
174 |
+ |
vm_release(fb, size); |
175 |
+ |
} |
176 |
+ |
|
177 |
+ |
|
178 |
+ |
/* |
179 |
+ |
* SheepShaver glue |
180 |
+ |
*/ |
181 |
+ |
|
182 |
+ |
#ifdef SHEEPSHAVER |
183 |
+ |
// Color depth modes type |
184 |
+ |
typedef int video_depth; |
185 |
+ |
|
186 |
+ |
// 1, 2, 4 and 8 bit depths use a color palette |
187 |
+ |
static inline bool IsDirectMode(VIDEO_MODE const & mode) |
188 |
+ |
{ |
189 |
+ |
return IsDirectMode(mode.viAppleMode); |
190 |
+ |
} |
191 |
+ |
|
192 |
+ |
// Abstract base class representing one (possibly virtual) monitor |
193 |
+ |
// ("monitor" = rectangular display with a contiguous frame buffer) |
194 |
+ |
class monitor_desc { |
195 |
+ |
public: |
196 |
+ |
monitor_desc(const vector<VIDEO_MODE> &available_modes, video_depth default_depth, uint32 default_id) {} |
197 |
+ |
virtual ~monitor_desc() {} |
198 |
+ |
|
199 |
+ |
// Get current Mac frame buffer base address |
200 |
+ |
uint32 get_mac_frame_base(void) const {return screen_base;} |
201 |
+ |
|
202 |
+ |
// Set Mac frame buffer base address (called from switch_to_mode()) |
203 |
+ |
void set_mac_frame_base(uint32 base) {screen_base = base;} |
204 |
+ |
|
205 |
+ |
// Get current video mode |
206 |
+ |
const VIDEO_MODE &get_current_mode(void) const {return VModes[cur_mode];} |
207 |
+ |
|
208 |
+ |
// Called by the video driver to switch the video mode on this display |
209 |
+ |
// (must call set_mac_frame_base()) |
210 |
+ |
virtual void switch_to_current_mode(void) = 0; |
211 |
+ |
|
212 |
+ |
// Called by the video driver to set the color palette (in indexed modes) |
213 |
+ |
// or the gamma table (in direct modes) |
214 |
+ |
virtual void set_palette(uint8 *pal, int num) = 0; |
215 |
+ |
}; |
216 |
+ |
|
217 |
+ |
// Vector of pointers to available monitor descriptions, filled by VideoInit() |
218 |
+ |
static vector<monitor_desc *> VideoMonitors; |
219 |
+ |
|
220 |
+ |
// Find Apple mode matching best specified dimensions |
221 |
+ |
static int find_apple_resolution(int xsize, int ysize) |
222 |
+ |
{ |
223 |
+ |
int apple_id; |
224 |
+ |
if (xsize < 800) |
225 |
+ |
apple_id = APPLE_640x480; |
226 |
+ |
else if (xsize < 1024) |
227 |
+ |
apple_id = APPLE_800x600; |
228 |
+ |
else if (xsize < 1152) |
229 |
+ |
apple_id = APPLE_1024x768; |
230 |
+ |
else if (xsize < 1280) { |
231 |
+ |
if (ysize < 900) |
232 |
+ |
apple_id = APPLE_1152x768; |
233 |
+ |
else |
234 |
+ |
apple_id = APPLE_1152x900; |
235 |
+ |
} |
236 |
+ |
else if (xsize < 1600) |
237 |
+ |
apple_id = APPLE_1280x1024; |
238 |
+ |
else |
239 |
+ |
apple_id = APPLE_1600x1200; |
240 |
+ |
return apple_id; |
241 |
+ |
} |
242 |
+ |
|
243 |
+ |
// Set parameters to specified Apple mode |
244 |
+ |
static void set_apple_resolution(int apple_id, int &xsize, int &ysize) |
245 |
+ |
{ |
246 |
+ |
switch (apple_id) { |
247 |
+ |
case APPLE_640x480: |
248 |
+ |
xsize = 640; |
249 |
+ |
ysize = 480; |
250 |
+ |
break; |
251 |
+ |
case APPLE_800x600: |
252 |
+ |
xsize = 800; |
253 |
+ |
ysize = 600; |
254 |
+ |
break; |
255 |
+ |
case APPLE_1024x768: |
256 |
+ |
xsize = 1024; |
257 |
+ |
ysize = 768; |
258 |
+ |
break; |
259 |
+ |
case APPLE_1152x768: |
260 |
+ |
xsize = 1152; |
261 |
+ |
ysize = 768; |
262 |
+ |
break; |
263 |
+ |
case APPLE_1152x900: |
264 |
+ |
xsize = 1152; |
265 |
+ |
ysize = 900; |
266 |
+ |
break; |
267 |
+ |
case APPLE_1280x1024: |
268 |
+ |
xsize = 1280; |
269 |
+ |
ysize = 1024; |
270 |
+ |
break; |
271 |
+ |
case APPLE_1600x1200: |
272 |
+ |
xsize = 1600; |
273 |
+ |
ysize = 1200; |
274 |
+ |
break; |
275 |
+ |
default: |
276 |
+ |
abort(); |
277 |
+ |
} |
278 |
+ |
} |
279 |
+ |
|
280 |
+ |
// Match Apple mode matching best specified dimensions |
281 |
+ |
static int match_apple_resolution(int &xsize, int &ysize) |
282 |
+ |
{ |
283 |
+ |
int apple_id = find_apple_resolution(xsize, ysize); |
284 |
+ |
set_apple_resolution(apple_id, xsize, ysize); |
285 |
+ |
return apple_id; |
286 |
+ |
} |
287 |
+ |
|
288 |
+ |
// Display error alert |
289 |
+ |
static void ErrorAlert(int error) |
290 |
+ |
{ |
291 |
+ |
ErrorAlert(GetString(error)); |
292 |
+ |
} |
293 |
+ |
|
294 |
+ |
// Display warning alert |
295 |
+ |
static void WarningAlert(int warning) |
296 |
+ |
{ |
297 |
+ |
WarningAlert(GetString(warning)); |
298 |
+ |
} |
299 |
+ |
#endif |
300 |
+ |
|
301 |
+ |
|
302 |
+ |
/* |
303 |
|
* monitor_desc subclass for SDL display |
304 |
|
*/ |
305 |
|
|
306 |
|
class SDL_monitor_desc : public monitor_desc { |
307 |
|
public: |
308 |
< |
SDL_monitor_desc(const vector<video_mode> &available_modes, video_depth default_depth, uint32 default_id) : monitor_desc(available_modes, default_depth, default_id) {} |
308 |
> |
SDL_monitor_desc(const vector<VIDEO_MODE> &available_modes, video_depth default_depth, uint32 default_id) : monitor_desc(available_modes, default_depth, default_id) {} |
309 |
|
~SDL_monitor_desc() {} |
310 |
|
|
311 |
|
virtual void switch_to_current_mode(void); |
320 |
|
* Utility functions |
321 |
|
*/ |
322 |
|
|
323 |
+ |
// Find palette size for given color depth |
324 |
+ |
static int palette_size(int mode) |
325 |
+ |
{ |
326 |
+ |
switch (mode) { |
327 |
+ |
case VIDEO_DEPTH_1BIT: return 2; |
328 |
+ |
case VIDEO_DEPTH_2BIT: return 4; |
329 |
+ |
case VIDEO_DEPTH_4BIT: return 16; |
330 |
+ |
case VIDEO_DEPTH_8BIT: return 256; |
331 |
+ |
case VIDEO_DEPTH_16BIT: return 32; |
332 |
+ |
case VIDEO_DEPTH_32BIT: return 256; |
333 |
+ |
default: return 0; |
334 |
+ |
} |
335 |
+ |
} |
336 |
+ |
|
337 |
+ |
// Return bytes per pixel for requested depth |
338 |
+ |
static inline int bytes_per_pixel(int depth) |
339 |
+ |
{ |
340 |
+ |
int bpp; |
341 |
+ |
switch (depth) { |
342 |
+ |
case 8: |
343 |
+ |
bpp = 1; |
344 |
+ |
break; |
345 |
+ |
case 15: case 16: |
346 |
+ |
bpp = 2; |
347 |
+ |
break; |
348 |
+ |
case 24: case 32: |
349 |
+ |
bpp = 4; |
350 |
+ |
break; |
351 |
+ |
default: |
352 |
+ |
abort(); |
353 |
+ |
} |
354 |
+ |
return bpp; |
355 |
+ |
} |
356 |
+ |
|
357 |
|
// Map video_mode depth ID to numerical depth value |
358 |
< |
static int sdl_depth_of_video_depth(int video_depth) |
358 |
> |
static int mac_depth_of_video_depth(int video_depth) |
359 |
|
{ |
360 |
|
int depth = -1; |
361 |
|
switch (video_depth) { |
362 |
< |
case VDEPTH_1BIT: |
362 |
> |
case VIDEO_DEPTH_1BIT: |
363 |
|
depth = 1; |
364 |
|
break; |
365 |
< |
case VDEPTH_2BIT: |
365 |
> |
case VIDEO_DEPTH_2BIT: |
366 |
|
depth = 2; |
367 |
|
break; |
368 |
< |
case VDEPTH_4BIT: |
368 |
> |
case VIDEO_DEPTH_4BIT: |
369 |
|
depth = 4; |
370 |
|
break; |
371 |
< |
case VDEPTH_8BIT: |
371 |
> |
case VIDEO_DEPTH_8BIT: |
372 |
|
depth = 8; |
373 |
|
break; |
374 |
< |
case VDEPTH_16BIT: |
374 |
> |
case VIDEO_DEPTH_16BIT: |
375 |
|
depth = 16; |
376 |
|
break; |
377 |
< |
case VDEPTH_32BIT: |
377 |
> |
case VIDEO_DEPTH_32BIT: |
378 |
|
depth = 32; |
379 |
|
break; |
380 |
|
default: |
383 |
|
return depth; |
384 |
|
} |
385 |
|
|
386 |
+ |
// Map video_mode depth ID to SDL screen depth |
387 |
+ |
static int sdl_depth_of_video_depth(int video_depth) |
388 |
+ |
{ |
389 |
+ |
return (video_depth <= VIDEO_DEPTH_8BIT) ? 8 : mac_depth_of_video_depth(video_depth); |
390 |
+ |
} |
391 |
+ |
|
392 |
+ |
// Check wether specified mode is available |
393 |
+ |
static bool has_mode(int type, int width, int height) |
394 |
+ |
{ |
395 |
+ |
// FIXME: no fullscreen support yet |
396 |
+ |
if (type == DISPLAY_SCREEN) |
397 |
+ |
return false; |
398 |
+ |
|
399 |
+ |
#ifdef SHEEPSHAVER |
400 |
+ |
// Filter out Classic resolutiosn |
401 |
+ |
if (width == 512 && height == 384) |
402 |
+ |
return false; |
403 |
+ |
|
404 |
+ |
// Read window modes prefs |
405 |
+ |
static uint32 window_modes = 0; |
406 |
+ |
static uint32 screen_modes = 0; |
407 |
+ |
if (window_modes == 0 || screen_modes == 0) { |
408 |
+ |
window_modes = PrefsFindInt32("windowmodes"); |
409 |
+ |
screen_modes = PrefsFindInt32("screenmodes"); |
410 |
+ |
if (window_modes == 0 || screen_modes == 0) |
411 |
+ |
window_modes |= 3; // Allow at least 640x480 and 800x600 window modes |
412 |
+ |
} |
413 |
+ |
|
414 |
+ |
if (type == DISPLAY_WINDOW) { |
415 |
+ |
int apple_mask, apple_id = find_apple_resolution(width, height); |
416 |
+ |
switch (apple_id) { |
417 |
+ |
case APPLE_640x480: apple_mask = 0x01; break; |
418 |
+ |
case APPLE_800x600: apple_mask = 0x02; break; |
419 |
+ |
case APPLE_1024x768: apple_mask = 0x04; break; |
420 |
+ |
case APPLE_1152x768: apple_mask = 0x40; break; |
421 |
+ |
case APPLE_1152x900: apple_mask = 0x08; break; |
422 |
+ |
case APPLE_1280x1024: apple_mask = 0x10; break; |
423 |
+ |
case APPLE_1600x1200: apple_mask = 0x20; break; |
424 |
+ |
default: apple_mask = 0x00; break; |
425 |
+ |
} |
426 |
+ |
return (window_modes & apple_mask); |
427 |
+ |
} |
428 |
+ |
#else |
429 |
+ |
return true; |
430 |
+ |
#endif |
431 |
+ |
return false; |
432 |
+ |
} |
433 |
+ |
|
434 |
|
// Add mode to list of supported modes |
435 |
< |
static void add_mode(uint32 width, uint32 height, uint32 resolution_id, uint32 bytes_per_row, video_depth depth) |
435 |
> |
static void add_mode(int type, int width, int height, int resolution_id, int bytes_per_row, int depth) |
436 |
|
{ |
437 |
< |
video_mode mode; |
438 |
< |
mode.x = width; |
439 |
< |
mode.y = height; |
440 |
< |
mode.resolution_id = resolution_id; |
441 |
< |
mode.bytes_per_row = bytes_per_row; |
442 |
< |
mode.depth = depth; |
437 |
> |
// Filter out unsupported modes |
438 |
> |
if (!has_mode(type, width, height)) |
439 |
> |
return; |
440 |
> |
|
441 |
> |
// Fill in VideoMode entry |
442 |
> |
VIDEO_MODE mode; |
443 |
> |
#ifdef SHEEPSHAVER |
444 |
> |
// Recalculate dimensions to fit Apple modes |
445 |
> |
resolution_id = match_apple_resolution(width, height); |
446 |
> |
mode.viType = type; |
447 |
> |
#endif |
448 |
> |
VIDEO_MODE_X = width; |
449 |
> |
VIDEO_MODE_Y = height; |
450 |
> |
VIDEO_MODE_RESOLUTION = resolution_id; |
451 |
> |
VIDEO_MODE_ROW_BYTES = bytes_per_row; |
452 |
> |
VIDEO_MODE_DEPTH = (video_depth)depth; |
453 |
|
VideoModes.push_back(mode); |
454 |
|
} |
455 |
|
|
456 |
|
// Add standard list of windowed modes for given color depth |
457 |
< |
static void add_window_modes(video_depth depth) |
457 |
> |
static void add_window_modes(int depth) |
458 |
|
{ |
459 |
< |
add_mode(512, 384, 0x80, TrivialBytesPerRow(512, depth), depth); |
460 |
< |
add_mode(640, 480, 0x81, TrivialBytesPerRow(640, depth), depth); |
461 |
< |
add_mode(800, 600, 0x82, TrivialBytesPerRow(800, depth), depth); |
462 |
< |
add_mode(1024, 768, 0x83, TrivialBytesPerRow(1024, depth), depth); |
463 |
< |
add_mode(1152, 870, 0x84, TrivialBytesPerRow(1152, depth), depth); |
464 |
< |
add_mode(1280, 1024, 0x85, TrivialBytesPerRow(1280, depth), depth); |
465 |
< |
add_mode(1600, 1200, 0x86, TrivialBytesPerRow(1600, depth), depth); |
459 |
> |
video_depth vdepth = (video_depth)depth; |
460 |
> |
add_mode(DISPLAY_WINDOW, 512, 384, 0x80, TrivialBytesPerRow(512, vdepth), depth); |
461 |
> |
add_mode(DISPLAY_WINDOW, 640, 480, 0x81, TrivialBytesPerRow(640, vdepth), depth); |
462 |
> |
add_mode(DISPLAY_WINDOW, 800, 600, 0x82, TrivialBytesPerRow(800, vdepth), depth); |
463 |
> |
add_mode(DISPLAY_WINDOW, 1024, 768, 0x83, TrivialBytesPerRow(1024, vdepth), depth); |
464 |
> |
add_mode(DISPLAY_WINDOW, 1152, 870, 0x84, TrivialBytesPerRow(1152, vdepth), depth); |
465 |
> |
add_mode(DISPLAY_WINDOW, 1280, 1024, 0x85, TrivialBytesPerRow(1280, vdepth), depth); |
466 |
> |
add_mode(DISPLAY_WINDOW, 1600, 1200, 0x86, TrivialBytesPerRow(1600, vdepth), depth); |
467 |
|
} |
468 |
|
|
469 |
|
// Set Mac frame layout and base address (uses the_buffer/MacFrameBaseMac) |
470 |
< |
static void set_mac_frame_buffer(SDL_monitor_desc &monitor, video_depth depth, bool native_byte_order) |
470 |
> |
static void set_mac_frame_buffer(SDL_monitor_desc &monitor, int depth, bool native_byte_order) |
471 |
|
{ |
472 |
|
#if !REAL_ADDRESSING && !DIRECT_ADDRESSING |
473 |
|
int layout = FLAYOUT_DIRECT; |
474 |
< |
if (depth == VDEPTH_16BIT) |
474 |
> |
if (depth == VIDEO_DEPTH_16BIT) |
475 |
|
layout = (screen_depth == 15) ? FLAYOUT_HOST_555 : FLAYOUT_HOST_565; |
476 |
< |
else if (depth == VDEPTH_32BIT) |
476 |
> |
else if (depth == VIDEO_DEPTH_32BIT) |
477 |
|
layout = (screen_depth == 24) ? FLAYOUT_HOST_888 : FLAYOUT_DIRECT; |
478 |
|
if (native_byte_order) |
479 |
|
MacFrameLayout = layout; |
482 |
|
monitor.set_mac_frame_base(MacFrameBaseMac); |
483 |
|
|
484 |
|
// Set variables used by UAE memory banking |
485 |
< |
const video_mode &mode = monitor.get_current_mode(); |
485 |
> |
const VIDEO_MODE &mode = monitor.get_current_mode(); |
486 |
|
MacFrameBaseHost = the_buffer; |
487 |
< |
MacFrameSize = mode.bytes_per_row * mode.y; |
487 |
> |
MacFrameSize = VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y; |
488 |
|
InitFrameBufferMapping(); |
489 |
|
#else |
490 |
|
monitor.set_mac_frame_base(Host2MacAddr(the_buffer)); |
533 |
|
|
534 |
|
public: |
535 |
|
SDL_monitor_desc &monitor; // Associated video monitor |
536 |
< |
const video_mode &mode; // Video mode handled by the driver |
536 |
> |
const VIDEO_MODE &mode; // Video mode handled by the driver |
537 |
|
|
538 |
|
bool init_ok; // Initialization succeeded (we can't use exceptions because of -fomit-frame-pointer) |
539 |
|
SDL_Surface *s; // The surface we draw into |
585 |
|
if (s) |
586 |
|
SDL_FreeSurface(s); |
587 |
|
|
588 |
+ |
// the_buffer shall always be mapped through vm_acquire_framebuffer() |
589 |
+ |
if (the_buffer != VM_MAP_FAILED) { |
590 |
+ |
D(bug(" releasing the_buffer at %p (%d bytes)\n", the_buffer, the_buffer_size)); |
591 |
+ |
vm_release_framebuffer(the_buffer, the_buffer_size); |
592 |
+ |
the_buffer = NULL; |
593 |
+ |
} |
594 |
+ |
|
595 |
|
// Free frame buffer(s) |
596 |
|
if (!use_vosf) { |
327 |
– |
if (the_buffer) { |
328 |
– |
free(the_buffer); |
329 |
– |
the_buffer = NULL; |
330 |
– |
} |
597 |
|
if (the_buffer_copy) { |
598 |
|
free(the_buffer_copy); |
599 |
|
the_buffer_copy = NULL; |
601 |
|
} |
602 |
|
#ifdef ENABLE_VOSF |
603 |
|
else { |
338 |
– |
// the_buffer shall always be mapped through vm_acquire() so that we can vm_protect() it at will |
339 |
– |
if (the_buffer != VM_MAP_FAILED) { |
340 |
– |
D(bug(" releasing the_buffer at %p (%d bytes)\n", the_buffer, the_buffer_size)); |
341 |
– |
vm_release(the_buffer, the_buffer_size); |
342 |
– |
the_buffer = NULL; |
343 |
– |
} |
604 |
|
if (the_host_buffer) { |
605 |
|
D(bug(" freeing the_host_buffer at %p\n", the_host_buffer)); |
606 |
|
free(the_host_buffer); |
611 |
|
free(the_buffer_copy); |
612 |
|
the_buffer_copy = NULL; |
613 |
|
} |
614 |
+ |
|
615 |
+ |
// Deinitialize VOSF |
616 |
+ |
video_vosf_exit(); |
617 |
|
} |
618 |
|
#endif |
619 |
|
} |
621 |
|
// Palette has changed |
622 |
|
void driver_base::update_palette(void) |
623 |
|
{ |
624 |
< |
const video_mode &mode = monitor.get_current_mode(); |
624 |
> |
const VIDEO_MODE &mode = monitor.get_current_mode(); |
625 |
|
|
626 |
< |
if (mode.depth <= VDEPTH_8BIT) |
626 |
> |
if ((int)VIDEO_MODE_DEPTH <= VIDEO_DEPTH_8BIT) |
627 |
|
SDL_SetPalette(s, SDL_PHYSPAL, sdl_palette, 0, 256); |
628 |
|
} |
629 |
|
|
646 |
|
driver_window::driver_window(SDL_monitor_desc &m) |
647 |
|
: driver_base(m), mouse_grabbed(false) |
648 |
|
{ |
649 |
< |
int width = mode.x, height = mode.y; |
649 |
> |
int width = VIDEO_MODE_X, height = VIDEO_MODE_Y; |
650 |
|
int aligned_width = (width + 15) & ~15; |
651 |
|
int aligned_height = (height + 15) & ~15; |
652 |
|
|
654 |
|
ADBSetRelMouseMode(mouse_grabbed); |
655 |
|
|
656 |
|
// Create surface |
657 |
< |
int depth = (mode.depth <= VDEPTH_8BIT ? 8 : screen_depth); |
657 |
> |
int depth = sdl_depth_of_video_depth(VIDEO_MODE_DEPTH); |
658 |
|
if ((s = SDL_SetVideoMode(width, height, depth, SDL_HWSURFACE)) == NULL) |
659 |
|
return; |
660 |
|
|
663 |
|
// Allocate memory for frame buffer (SIZE is extended to page-boundary) |
664 |
|
the_host_buffer = (uint8 *)s->pixels; |
665 |
|
the_buffer_size = page_extend((aligned_height + 2) * s->pitch); |
666 |
< |
the_buffer = (uint8 *)vm_acquire(the_buffer_size); |
666 |
> |
the_buffer = (uint8 *)vm_acquire_framebuffer(the_buffer_size); |
667 |
|
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
668 |
|
D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer)); |
669 |
+ |
|
670 |
+ |
// Check whether we can initialize the VOSF subsystem and it's profitable |
671 |
+ |
if (!video_vosf_init(m)) { |
672 |
+ |
WarningAlert(STR_VOSF_INIT_ERR); |
673 |
+ |
use_vosf = false; |
674 |
+ |
} |
675 |
+ |
else if (!video_vosf_profitable()) { |
676 |
+ |
video_vosf_exit(); |
677 |
+ |
printf("VOSF acceleration is not profitable on this platform, disabling it\n"); |
678 |
+ |
use_vosf = false; |
679 |
+ |
} |
680 |
+ |
if (!use_vosf) { |
681 |
+ |
free(the_buffer_copy); |
682 |
+ |
vm_release(the_buffer, the_buffer_size); |
683 |
+ |
the_host_buffer = NULL; |
684 |
+ |
} |
685 |
+ |
#endif |
686 |
+ |
if (!use_vosf) { |
687 |
+ |
// Allocate memory for frame buffer |
688 |
+ |
the_buffer_size = (aligned_height + 2) * s->pitch; |
689 |
+ |
the_buffer_copy = (uint8 *)calloc(1, the_buffer_size); |
690 |
+ |
the_buffer = (uint8 *)vm_acquire_framebuffer(the_buffer_size); |
691 |
+ |
D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy)); |
692 |
+ |
} |
693 |
+ |
|
694 |
+ |
#ifdef SHEEPSHAVER |
695 |
+ |
// Create cursor |
696 |
+ |
if ((sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, 0, 0)) != NULL) { |
697 |
+ |
SDL_SetCursor(sdl_cursor); |
698 |
+ |
cursor_changed = false; |
699 |
+ |
} |
700 |
|
#else |
701 |
< |
// Allocate memory for frame buffer |
702 |
< |
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)); |
701 |
> |
// Hide cursor |
702 |
> |
SDL_ShowCursor(0); |
703 |
|
#endif |
704 |
|
|
705 |
|
// Set window name/class |
706 |
|
set_window_name(STR_WINDOW_TITLE); |
707 |
|
|
417 |
– |
// Hide cursor |
418 |
– |
SDL_ShowCursor(0); |
419 |
– |
|
708 |
|
// Init blitting routines |
709 |
|
SDL_PixelFormat *f = s->format; |
710 |
|
VisualFormat visualFormat; |
712 |
|
visualFormat.Rmask = f->Rmask; |
713 |
|
visualFormat.Gmask = f->Gmask; |
714 |
|
visualFormat.Bmask = f->Bmask; |
715 |
< |
Screen_blitter_init(visualFormat, true, sdl_depth_of_video_depth(mode.depth)); |
715 |
> |
Screen_blitter_init(visualFormat, true, mac_depth_of_video_depth(VIDEO_MODE_DEPTH)); |
716 |
|
|
717 |
|
// Load gray ramp to 8->16/32 expand map |
718 |
|
if (!IsDirectMode(mode)) |
720 |
|
ExpandMap[i] = SDL_MapRGB(f, i, i, i); |
721 |
|
|
722 |
|
// Set frame buffer base |
723 |
< |
set_mac_frame_buffer(monitor, mode.depth, true); |
723 |
> |
set_mac_frame_buffer(monitor, VIDEO_MODE_DEPTH, true); |
724 |
|
|
725 |
|
// Everything went well |
726 |
|
init_ok = true; |
810 |
|
SDL_VideoDriverName(video_driver, sizeof(video_driver)); |
811 |
|
bool video_driver_found = false; |
812 |
|
char line[256]; |
813 |
+ |
int n_keys = 0; |
814 |
|
while (fgets(line, sizeof(line) - 1, f)) { |
815 |
|
// Read line |
816 |
|
int len = strlen(line); |
823 |
|
continue; |
824 |
|
|
825 |
|
if (video_driver_found) { |
826 |
< |
// Skip aliases |
827 |
< |
static const char alias_str[] = "alias"; |
828 |
< |
if (strncmp(line, alias_str, sizeof(alias_str) - 1) == 0) |
826 |
> |
// Skip aliases as long as we have read keycodes yet |
827 |
> |
// Otherwise, it's another mapping and we have to stop |
828 |
> |
static const char sdl_str[] = "sdl"; |
829 |
> |
if (strncmp(line, sdl_str, sizeof(sdl_str) - 1) == 0 && n_keys == 0) |
830 |
|
continue; |
831 |
|
|
832 |
|
// Read keycode |
833 |
|
int x_code, mac_code; |
834 |
|
if (sscanf(line, "%d %d", &x_code, &mac_code) == 2) |
835 |
< |
keycode_table[x_code & 0xff] = mac_code; |
835 |
> |
keycode_table[x_code & 0xff] = mac_code, n_keys++; |
836 |
|
else |
837 |
|
break; |
838 |
|
} else { |
839 |
|
// Search for SDL video driver string |
840 |
< |
static const char alias_sdl_str[] = "alias SDL"; |
841 |
< |
if (strncmp(line, alias_sdl_str, sizeof(alias_sdl_str) - 1) == 0) { |
842 |
< |
char *p = line + sizeof(alias_sdl_str); |
840 |
> |
static const char sdl_str[] = "sdl"; |
841 |
> |
if (strncmp(line, sdl_str, sizeof(sdl_str) - 1) == 0) { |
842 |
> |
char *p = line + sizeof(sdl_str); |
843 |
|
if (strstr(video_driver, p) == video_driver) |
844 |
|
video_driver_found = true; |
845 |
|
} |
857 |
|
WarningAlert(str); |
858 |
|
return; |
859 |
|
} |
860 |
+ |
|
861 |
+ |
D(bug("Using SDL/%s keycodes table, %d key mappings\n", video_driver, n_keys)); |
862 |
|
} |
863 |
|
} |
864 |
|
|
866 |
|
bool SDL_monitor_desc::video_open(void) |
867 |
|
{ |
868 |
|
D(bug("video_open()\n")); |
869 |
< |
const video_mode &mode = get_current_mode(); |
869 |
> |
const VIDEO_MODE &mode = get_current_mode(); |
870 |
> |
#if DEBUG |
871 |
> |
D(bug("Current video mode:\n")); |
872 |
> |
D(bug(" %dx%d (ID %02x), %d bpp\n", VIDEO_MODE_X, VIDEO_MODE_Y, VIDEO_MODE_RESOLUTION, 1 << (VIDEO_MODE_DEPTH & 0x0f))); |
873 |
> |
#endif |
874 |
|
|
875 |
|
// Create display driver object of requested type |
876 |
|
switch (display_type) { |
886 |
|
return false; |
887 |
|
} |
888 |
|
|
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 |
– |
|
889 |
|
// Initialize VideoRefresh function |
890 |
|
VideoRefreshInit(); |
891 |
|
|
894 |
|
|
895 |
|
// Start redraw/input thread |
896 |
|
redraw_thread_cancel = false; |
897 |
< |
redraw_thread_active = (SDL_CreateThread(redraw_func, NULL) != NULL); |
897 |
> |
redraw_thread_active = ((redraw_thread = SDL_CreateThread(redraw_func, NULL)) != NULL); |
898 |
|
if (!redraw_thread_active) { |
899 |
|
printf("FATAL: cannot create redraw thread\n"); |
900 |
|
return false; |
902 |
|
return true; |
903 |
|
} |
904 |
|
|
905 |
+ |
#ifdef SHEEPSHAVER |
906 |
+ |
bool VideoInit(void) |
907 |
+ |
{ |
908 |
+ |
const bool classic = false; |
909 |
+ |
#else |
910 |
|
bool VideoInit(bool classic) |
911 |
|
{ |
912 |
+ |
#endif |
913 |
|
classic_mode = classic; |
914 |
|
|
915 |
|
#ifdef ENABLE_VOSF |
933 |
|
mouse_wheel_lines = PrefsFindInt32("mousewheellines"); |
934 |
|
|
935 |
|
// Get screen mode from preferences |
936 |
< |
const char *mode_str; |
936 |
> |
const char *mode_str = NULL; |
937 |
> |
#ifndef SHEEPSHAVER |
938 |
|
if (classic_mode) |
939 |
|
mode_str = "win/512/342"; |
940 |
|
else |
941 |
|
mode_str = PrefsFindString("screen"); |
942 |
+ |
#endif |
943 |
|
|
944 |
|
// Determine display type and default dimensions |
945 |
< |
int default_width = 512, default_height = 384; |
945 |
> |
int default_width, default_height; |
946 |
> |
if (classic) { |
947 |
> |
default_width = 512; |
948 |
> |
default_height = 384; |
949 |
> |
} |
950 |
> |
else { |
951 |
> |
default_width = 640; |
952 |
> |
default_height = 480; |
953 |
> |
} |
954 |
|
display_type = DISPLAY_WINDOW; |
955 |
|
if (mode_str) { |
956 |
|
if (sscanf(mode_str, "win/%d/%d", &default_width, &default_height) == 2) |
957 |
|
display_type = DISPLAY_WINDOW; |
958 |
|
} |
959 |
|
int max_width = 640, max_height = 480; |
960 |
< |
if (display_type == DISPLAY_SCREEN) { |
961 |
< |
SDL_Rect **modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE); |
962 |
< |
if (modes && modes != (SDL_Rect **)-1) { |
963 |
< |
max_width = modes[0]->w; |
964 |
< |
max_height = modes[0]->h; |
965 |
< |
} |
960 |
> |
SDL_Rect **modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE); |
961 |
> |
if (modes && modes != (SDL_Rect **)-1) { |
962 |
> |
max_width = modes[0]->w; |
963 |
> |
max_height = modes[0]->h; |
964 |
> |
if (default_width > max_width) |
965 |
> |
default_width = max_width; |
966 |
> |
if (default_height > max_height) |
967 |
> |
default_height = max_height; |
968 |
|
} |
969 |
|
if (default_width <= 0) |
970 |
|
default_width = max_width; |
973 |
|
|
974 |
|
// Mac screen depth follows X depth |
975 |
|
screen_depth = SDL_GetVideoInfo()->vfmt->BitsPerPixel; |
976 |
< |
video_depth default_depth; |
976 |
> |
int default_depth; |
977 |
|
switch (screen_depth) { |
978 |
|
case 8: |
979 |
< |
default_depth = VDEPTH_8BIT; |
979 |
> |
default_depth = VIDEO_DEPTH_8BIT; |
980 |
|
break; |
981 |
|
case 15: case 16: |
982 |
< |
default_depth = VDEPTH_16BIT; |
982 |
> |
default_depth = VIDEO_DEPTH_16BIT; |
983 |
|
break; |
984 |
|
case 24: case 32: |
985 |
< |
default_depth = VDEPTH_32BIT; |
985 |
> |
default_depth = VIDEO_DEPTH_32BIT; |
986 |
|
break; |
987 |
|
default: |
988 |
< |
default_depth = VDEPTH_1BIT; |
988 |
> |
default_depth = VIDEO_DEPTH_1BIT; |
989 |
|
break; |
990 |
|
} |
991 |
|
|
992 |
|
// Construct list of supported modes |
993 |
|
if (display_type == DISPLAY_WINDOW) { |
994 |
|
if (classic) |
995 |
< |
add_mode(512, 342, 0x80, 64, VDEPTH_1BIT); |
995 |
> |
add_mode(display_type, 512, 342, 0x80, 64, VIDEO_DEPTH_1BIT); |
996 |
|
else { |
997 |
< |
for (int d = VDEPTH_1BIT; d <= default_depth; d++) { |
998 |
< |
int bpp = (d <= VDEPTH_8BIT ? 8 : sdl_depth_of_video_depth(d)); |
997 |
> |
for (int d = VIDEO_DEPTH_1BIT; d <= default_depth; d++) { |
998 |
> |
int bpp = sdl_depth_of_video_depth(d); |
999 |
|
if (SDL_VideoModeOK(max_width, max_height, bpp, SDL_HWSURFACE)) |
1000 |
|
add_window_modes(video_depth(d)); |
1001 |
|
} |
1002 |
|
} |
1003 |
|
} else |
1004 |
< |
add_mode(default_width, default_height, 0x80, TrivialBytesPerRow(default_width, default_depth), default_depth); |
1004 |
> |
add_mode(display_type, default_width, default_height, 0x80, TrivialBytesPerRow(default_width, (video_depth)default_depth), default_depth); |
1005 |
|
if (VideoModes.empty()) { |
1006 |
|
ErrorAlert(STR_NO_XVISUAL_ERR); |
1007 |
|
return false; |
1009 |
|
|
1010 |
|
// Find requested default mode with specified dimensions |
1011 |
|
uint32 default_id; |
1012 |
< |
std::vector<video_mode>::const_iterator i, end = VideoModes.end(); |
1012 |
> |
std::vector<VIDEO_MODE>::const_iterator i, end = VideoModes.end(); |
1013 |
|
for (i = VideoModes.begin(); i != end; ++i) { |
1014 |
< |
if (i->x == default_width && i->y == default_height && i->depth == default_depth) { |
1015 |
< |
default_id = i->resolution_id; |
1014 |
> |
const VIDEO_MODE & mode = (*i); |
1015 |
> |
if (VIDEO_MODE_X == default_width && VIDEO_MODE_Y == default_height && VIDEO_MODE_DEPTH == default_depth) { |
1016 |
> |
default_id = VIDEO_MODE_RESOLUTION; |
1017 |
> |
#ifdef SHEEPSHAVER |
1018 |
> |
std::vector<VIDEO_MODE>::const_iterator begin = VideoModes.begin(); |
1019 |
> |
cur_mode = distance(begin, i); |
1020 |
> |
#endif |
1021 |
|
break; |
1022 |
|
} |
1023 |
|
} |
1024 |
|
if (i == end) { // not found, use first available mode |
1025 |
< |
default_depth = VideoModes[0].depth; |
1026 |
< |
default_id = VideoModes[0].resolution_id; |
1025 |
> |
const VIDEO_MODE & mode = VideoModes[0]; |
1026 |
> |
default_depth = VIDEO_MODE_DEPTH; |
1027 |
> |
default_id = VIDEO_MODE_RESOLUTION; |
1028 |
> |
#ifdef SHEEPSHAVER |
1029 |
> |
cur_mode = 0; |
1030 |
> |
#endif |
1031 |
|
} |
1032 |
|
|
1033 |
+ |
#ifdef SHEEPSHAVER |
1034 |
+ |
for (int i = 0; i < VideoModes.size(); i++) |
1035 |
+ |
VModes[i] = VideoModes[i]; |
1036 |
+ |
VideoInfo *p = &VModes[VideoModes.size()]; |
1037 |
+ |
p->viType = DIS_INVALID; // End marker |
1038 |
+ |
p->viRowBytes = 0; |
1039 |
+ |
p->viXsize = p->viYsize = 0; |
1040 |
+ |
p->viAppleMode = 0; |
1041 |
+ |
p->viAppleID = 0; |
1042 |
+ |
#endif |
1043 |
+ |
|
1044 |
|
#if DEBUG |
1045 |
|
D(bug("Available video modes:\n")); |
1046 |
|
for (i = VideoModes.begin(); i != end; ++i) { |
1047 |
< |
int bits = 1 << i->depth; |
1047 |
> |
const VIDEO_MODE & mode = (*i); |
1048 |
> |
int bits = 1 << VIDEO_MODE_DEPTH; |
1049 |
|
if (bits == 16) |
1050 |
|
bits = 15; |
1051 |
|
else if (bits == 32) |
1052 |
|
bits = 24; |
1053 |
< |
D(bug(" %dx%d (ID %02x), %d colors\n", i->x, i->y, i->resolution_id, 1 << bits)); |
1053 |
> |
D(bug(" %dx%d (ID %02x), %d colors\n", VIDEO_MODE_X, VIDEO_MODE_Y, VIDEO_MODE_RESOLUTION, 1 << bits)); |
1054 |
|
} |
1055 |
|
#endif |
1056 |
|
|
1057 |
|
// Create SDL_monitor_desc for this (the only) display |
1058 |
< |
SDL_monitor_desc *monitor = new SDL_monitor_desc(VideoModes, default_depth, default_id); |
1058 |
> |
SDL_monitor_desc *monitor = new SDL_monitor_desc(VideoModes, (video_depth)default_depth, default_id); |
1059 |
|
VideoMonitors.push_back(monitor); |
1060 |
|
|
1061 |
|
// Open display |
1075 |
|
// Stop redraw thread |
1076 |
|
if (redraw_thread_active) { |
1077 |
|
redraw_thread_cancel = true; |
1078 |
< |
// SDL_WaitThread(redraw_thread, NULL); doesn't work |
754 |
< |
while (redraw_thread_cancel); |
1078 |
> |
SDL_WaitThread(redraw_thread, NULL); |
1079 |
|
} |
1080 |
|
redraw_thread_active = false; |
1081 |
|
|
1083 |
|
UNLOCK_FRAME_BUFFER; |
1084 |
|
D(bug(" frame buffer unlocked\n")); |
1085 |
|
|
762 |
– |
#ifdef ENABLE_VOSF |
763 |
– |
if (use_vosf) { |
764 |
– |
// Deinitialize VOSF |
765 |
– |
video_vosf_exit(); |
766 |
– |
} |
767 |
– |
#endif |
768 |
– |
|
1086 |
|
// Close display |
1087 |
|
delete drv; |
1088 |
|
drv = NULL; |
1118 |
|
* Mac VBL interrupt |
1119 |
|
*/ |
1120 |
|
|
1121 |
+ |
/* |
1122 |
+ |
* Execute video VBL routine |
1123 |
+ |
*/ |
1124 |
+ |
|
1125 |
+ |
#ifdef SHEEPSHAVER |
1126 |
+ |
void VideoVBL(void) |
1127 |
+ |
{ |
1128 |
+ |
// Emergency quit requested? Then quit |
1129 |
+ |
if (emerg_quit) |
1130 |
+ |
QuitEmulator(); |
1131 |
+ |
|
1132 |
+ |
// Temporarily give up frame buffer lock (this is the point where |
1133 |
+ |
// we are suspended when the user presses Ctrl-Tab) |
1134 |
+ |
UNLOCK_FRAME_BUFFER; |
1135 |
+ |
LOCK_FRAME_BUFFER; |
1136 |
+ |
|
1137 |
+ |
// Execute video VBL |
1138 |
+ |
if (private_data != NULL && private_data->interruptsEnabled) |
1139 |
+ |
VSLDoInterruptService(private_data->vslServiceID); |
1140 |
+ |
} |
1141 |
+ |
#else |
1142 |
|
void VideoInterrupt(void) |
1143 |
|
{ |
1144 |
|
// We must fill in the events queue in the same thread that did call SDL_SetVideoMode() |
1153 |
|
UNLOCK_FRAME_BUFFER; |
1154 |
|
LOCK_FRAME_BUFFER; |
1155 |
|
} |
1156 |
+ |
#endif |
1157 |
|
|
1158 |
|
|
1159 |
|
/* |
1160 |
|
* Set palette |
1161 |
|
*/ |
1162 |
|
|
1163 |
+ |
#ifdef SHEEPSHAVER |
1164 |
+ |
void video_set_palette(void) |
1165 |
+ |
{ |
1166 |
+ |
monitor_desc * monitor = VideoMonitors[0]; |
1167 |
+ |
int n_colors = palette_size(monitor->get_current_mode().viAppleMode); |
1168 |
+ |
uint8 pal[256 * 3]; |
1169 |
+ |
for (int c = 0; c < n_colors; c++) { |
1170 |
+ |
pal[c*3 + 0] = mac_pal[c].red; |
1171 |
+ |
pal[c*3 + 1] = mac_pal[c].green; |
1172 |
+ |
pal[c*3 + 2] = mac_pal[c].blue; |
1173 |
+ |
} |
1174 |
+ |
monitor->set_palette(pal, n_colors); |
1175 |
+ |
} |
1176 |
+ |
#endif |
1177 |
+ |
|
1178 |
|
void SDL_monitor_desc::set_palette(uint8 *pal, int num_in) |
1179 |
|
{ |
1180 |
< |
const video_mode &mode = get_current_mode(); |
1180 |
> |
const VIDEO_MODE &mode = get_current_mode(); |
1181 |
|
|
1182 |
|
// FIXME: how can we handle the gamma ramp? |
1183 |
< |
if (mode.depth > VDEPTH_8BIT) |
1183 |
> |
if ((int)VIDEO_MODE_DEPTH > VIDEO_DEPTH_8BIT) |
1184 |
|
return; |
1185 |
|
|
1186 |
|
LOCK_PALETTE; |
1205 |
|
} |
1206 |
|
|
1207 |
|
#ifdef ENABLE_VOSF |
1208 |
< |
// We have to redraw everything because the interpretation of pixel values changed |
1209 |
< |
LOCK_VOSF; |
1210 |
< |
PFLAG_SET_ALL; |
1211 |
< |
UNLOCK_VOSF; |
1212 |
< |
memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y); |
1208 |
> |
if (use_vosf) { |
1209 |
> |
// We have to redraw everything because the interpretation of pixel values changed |
1210 |
> |
LOCK_VOSF; |
1211 |
> |
PFLAG_SET_ALL; |
1212 |
> |
UNLOCK_VOSF; |
1213 |
> |
memset(the_buffer_copy, 0, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y); |
1214 |
> |
} |
1215 |
|
#endif |
1216 |
|
} |
1217 |
|
|
1226 |
|
* Switch video mode |
1227 |
|
*/ |
1228 |
|
|
1229 |
+ |
#ifdef SHEEPSHAVER |
1230 |
+ |
int16 video_mode_change(VidLocals *csSave, uint32 ParamPtr) |
1231 |
+ |
{ |
1232 |
+ |
/* return if no mode change */ |
1233 |
+ |
if ((csSave->saveData == ReadMacInt32(ParamPtr + csData)) && |
1234 |
+ |
(csSave->saveMode == ReadMacInt16(ParamPtr + csMode))) return noErr; |
1235 |
+ |
|
1236 |
+ |
/* first find video mode in table */ |
1237 |
+ |
for (int i=0; VModes[i].viType != DIS_INVALID; i++) { |
1238 |
+ |
if ((ReadMacInt16(ParamPtr + csMode) == VModes[i].viAppleMode) && |
1239 |
+ |
(ReadMacInt32(ParamPtr + csData) == VModes[i].viAppleID)) { |
1240 |
+ |
csSave->saveMode = ReadMacInt16(ParamPtr + csMode); |
1241 |
+ |
csSave->saveData = ReadMacInt32(ParamPtr + csData); |
1242 |
+ |
csSave->savePage = ReadMacInt16(ParamPtr + csPage); |
1243 |
+ |
|
1244 |
+ |
// Disable interrupts and pause redraw thread |
1245 |
+ |
DisableInterrupt(); |
1246 |
+ |
thread_stop_ack = false; |
1247 |
+ |
thread_stop_req = true; |
1248 |
+ |
while (!thread_stop_ack) ; |
1249 |
+ |
|
1250 |
+ |
cur_mode = i; |
1251 |
+ |
monitor_desc *monitor = VideoMonitors[0]; |
1252 |
+ |
monitor->switch_to_current_mode(); |
1253 |
+ |
|
1254 |
+ |
WriteMacInt32(ParamPtr + csBaseAddr, screen_base); |
1255 |
+ |
csSave->saveBaseAddr=screen_base; |
1256 |
+ |
csSave->saveData=VModes[cur_mode].viAppleID;/* First mode ... */ |
1257 |
+ |
csSave->saveMode=VModes[cur_mode].viAppleMode; |
1258 |
+ |
|
1259 |
+ |
// Enable interrupts and resume redraw thread |
1260 |
+ |
thread_stop_req = false; |
1261 |
+ |
EnableInterrupt(); |
1262 |
+ |
return noErr; |
1263 |
+ |
} |
1264 |
+ |
} |
1265 |
+ |
return paramErr; |
1266 |
+ |
} |
1267 |
+ |
#endif |
1268 |
+ |
|
1269 |
|
void SDL_monitor_desc::switch_to_current_mode(void) |
1270 |
|
{ |
1271 |
|
// Close and reopen display |
1280 |
|
|
1281 |
|
|
1282 |
|
/* |
1283 |
< |
* Translate key event to Mac keycode, returns -1 if no keycode was found |
1284 |
< |
* and -2 if the key was recognized as a hotkey |
1283 |
> |
* Can we set the MacOS cursor image into the window? |
1284 |
> |
*/ |
1285 |
> |
|
1286 |
> |
#ifdef SHEEPSHAVER |
1287 |
> |
bool video_can_change_cursor(void) |
1288 |
> |
{ |
1289 |
> |
return (display_type == DISPLAY_WINDOW); |
1290 |
> |
} |
1291 |
> |
#endif |
1292 |
> |
|
1293 |
> |
|
1294 |
> |
/* |
1295 |
> |
* Set cursor image for window |
1296 |
> |
*/ |
1297 |
> |
|
1298 |
> |
#ifdef SHEEPSHAVER |
1299 |
> |
void video_set_cursor(void) |
1300 |
> |
{ |
1301 |
> |
cursor_changed = true; |
1302 |
> |
} |
1303 |
> |
#endif |
1304 |
> |
|
1305 |
> |
|
1306 |
> |
/* |
1307 |
> |
* Keyboard-related utilify functions |
1308 |
|
*/ |
1309 |
|
|
1310 |
+ |
static bool is_modifier_key(SDL_KeyboardEvent const & e) |
1311 |
+ |
{ |
1312 |
+ |
switch (e.keysym.sym) { |
1313 |
+ |
case SDLK_NUMLOCK: |
1314 |
+ |
case SDLK_CAPSLOCK: |
1315 |
+ |
case SDLK_SCROLLOCK: |
1316 |
+ |
case SDLK_RSHIFT: |
1317 |
+ |
case SDLK_LSHIFT: |
1318 |
+ |
case SDLK_RCTRL: |
1319 |
+ |
case SDLK_LCTRL: |
1320 |
+ |
case SDLK_RALT: |
1321 |
+ |
case SDLK_LALT: |
1322 |
+ |
case SDLK_RMETA: |
1323 |
+ |
case SDLK_LMETA: |
1324 |
+ |
case SDLK_LSUPER: |
1325 |
+ |
case SDLK_RSUPER: |
1326 |
+ |
case SDLK_MODE: |
1327 |
+ |
case SDLK_COMPOSE: |
1328 |
+ |
return true; |
1329 |
+ |
} |
1330 |
+ |
return false; |
1331 |
+ |
} |
1332 |
+ |
|
1333 |
|
static bool is_ctrl_down(SDL_keysym const & ks) |
1334 |
|
{ |
1335 |
|
return ctrl_down || (ks.mod & KMOD_CTRL); |
1336 |
|
} |
1337 |
|
|
1338 |
+ |
|
1339 |
+ |
/* |
1340 |
+ |
* Translate key event to Mac keycode, returns -1 if no keycode was found |
1341 |
+ |
* and -2 if the key was recognized as a hotkey |
1342 |
+ |
*/ |
1343 |
+ |
|
1344 |
|
static int kc_decode(SDL_keysym const & ks, bool key_down) |
1345 |
|
{ |
1346 |
|
switch (ks.sym) { |
1410 |
|
case SDLK_RCTRL: return 0x36; |
1411 |
|
case SDLK_LSHIFT: return 0x38; |
1412 |
|
case SDLK_RSHIFT: return 0x38; |
1413 |
+ |
#if (defined(__APPLE__) && defined(__MACH__)) |
1414 |
+ |
case SDLK_LALT: return 0x3a; |
1415 |
+ |
case SDLK_RALT: return 0x3a; |
1416 |
+ |
case SDLK_LMETA: return 0x37; |
1417 |
+ |
case SDLK_RMETA: return 0x37; |
1418 |
+ |
#else |
1419 |
|
case SDLK_LALT: return 0x37; |
1420 |
|
case SDLK_RALT: return 0x37; |
1421 |
|
case SDLK_LMETA: return 0x3a; |
1422 |
|
case SDLK_RMETA: return 0x3a; |
1423 |
+ |
#endif |
1424 |
|
case SDLK_MENU: return 0x32; |
1425 |
|
case SDLK_CAPSLOCK: return 0x39; |
1426 |
|
case SDLK_NUMLOCK: return 0x47; |
1527 |
|
// Keyboard |
1528 |
|
case SDL_KEYDOWN: { |
1529 |
|
int code = -1; |
1530 |
< |
if (use_keycodes) { |
1530 |
> |
if (use_keycodes && !is_modifier_key(event.key)) { |
1531 |
|
if (event2keycode(event.key, true) != -2) // This is called to process the hotkeys |
1532 |
|
code = keycode_table[event.key.keysym.scancode & 0xff]; |
1533 |
|
} else |
1555 |
|
} |
1556 |
|
case SDL_KEYUP: { |
1557 |
|
int code = -1; |
1558 |
< |
if (use_keycodes) { |
1558 |
> |
if (use_keycodes && !is_modifier_key(event.key)) { |
1559 |
|
if (event2keycode(event.key, false) != -2) // This is called to process the hotkeys |
1560 |
|
code = keycode_table[event.key.keysym.scancode & 0xff]; |
1561 |
|
} else |
1562 |
|
code = event2keycode(event.key, false); |
1563 |
< |
if (code >= 0 && code != 0x39) { // Don't propagate Caps Lock releases |
1564 |
< |
ADBKeyUp(code); |
1563 |
> |
if (code >= 0) { |
1564 |
> |
if (code == 0x39) { // Caps Lock released |
1565 |
> |
if (caps_on) { |
1566 |
> |
ADBKeyUp(code); |
1567 |
> |
caps_on = false; |
1568 |
> |
} else { |
1569 |
> |
ADBKeyDown(code); |
1570 |
> |
caps_on = true; |
1571 |
> |
} |
1572 |
> |
} else |
1573 |
> |
ADBKeyUp(code); |
1574 |
|
if (code == 0x36) |
1575 |
|
ctrl_down = false; |
1576 |
|
} |
1580 |
|
// Hidden parts exposed, force complete refresh of window |
1581 |
|
case SDL_VIDEOEXPOSE: |
1582 |
|
if (display_type == DISPLAY_WINDOW) { |
1583 |
< |
const video_mode &mode = VideoMonitors[0]->get_current_mode(); |
1583 |
> |
const VIDEO_MODE &mode = VideoMonitors[0]->get_current_mode(); |
1584 |
|
#ifdef ENABLE_VOSF |
1585 |
|
if (use_vosf) { // VOSF refresh |
1586 |
|
LOCK_VOSF; |
1587 |
|
PFLAG_SET_ALL; |
1588 |
|
UNLOCK_VOSF; |
1589 |
< |
memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y); |
1589 |
> |
memset(the_buffer_copy, 0, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y); |
1590 |
|
} |
1591 |
|
else |
1592 |
|
#endif |
1593 |
< |
memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y); |
1593 |
> |
memset(the_buffer_copy, 0, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y); |
1594 |
|
} |
1595 |
|
break; |
1596 |
|
|
1614 |
|
{ |
1615 |
|
// Incremental update code |
1616 |
|
int wide = 0, high = 0, x1, x2, y1, y2, i, j; |
1617 |
< |
const video_mode &mode = drv->mode; |
1618 |
< |
int bytes_per_row = mode.bytes_per_row; |
1617 |
> |
const VIDEO_MODE &mode = drv->mode; |
1618 |
> |
int bytes_per_row = VIDEO_MODE_ROW_BYTES; |
1619 |
|
uint8 *p, *p2; |
1620 |
|
|
1621 |
|
// Check for first line from top and first line from bottom that have changed |
1622 |
|
y1 = 0; |
1623 |
< |
for (j=0; j<mode.y; j++) { |
1623 |
> |
for (j=0; j<VIDEO_MODE_Y; j++) { |
1624 |
|
if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) { |
1625 |
|
y1 = j; |
1626 |
|
break; |
1627 |
|
} |
1628 |
|
} |
1629 |
|
y2 = y1 - 1; |
1630 |
< |
for (j=mode.y-1; j>=y1; j--) { |
1630 |
> |
for (j=VIDEO_MODE_Y-1; j>=y1; j--) { |
1631 |
|
if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) { |
1632 |
|
y2 = j; |
1633 |
|
break; |
1637 |
|
|
1638 |
|
// Check for first column from left and first column from right that have changed |
1639 |
|
if (high) { |
1640 |
< |
if (mode.depth < VDEPTH_8BIT) { |
1640 |
> |
if ((int)VIDEO_MODE_DEPTH < VIDEO_DEPTH_8BIT) { |
1641 |
|
const int src_bytes_per_row = bytes_per_row; |
1642 |
|
const int dst_bytes_per_row = drv->s->pitch; |
1643 |
< |
const int pixels_per_byte = mode.x / src_bytes_per_row; |
1643 |
> |
const int pixels_per_byte = VIDEO_MODE_X / src_bytes_per_row; |
1644 |
|
|
1645 |
< |
x1 = mode.x / pixels_per_byte; |
1645 |
> |
x1 = VIDEO_MODE_X / pixels_per_byte; |
1646 |
|
for (j = y1; j <= y2; j++) { |
1647 |
|
p = &the_buffer[j * bytes_per_row]; |
1648 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1660 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1661 |
|
p += bytes_per_row; |
1662 |
|
p2 += bytes_per_row; |
1663 |
< |
for (i = (mode.x / pixels_per_byte); i > x2; i--) { |
1663 |
> |
for (i = (VIDEO_MODE_X / pixels_per_byte); i > x2; i--) { |
1664 |
|
p--; p2--; |
1665 |
|
if (*p != *p2) { |
1666 |
|
x2 = i; |
1698 |
|
} |
1699 |
|
|
1700 |
|
} else { |
1701 |
< |
const int bytes_per_pixel = mode.bytes_per_row / mode.x; |
1701 |
> |
const int bytes_per_pixel = VIDEO_MODE_ROW_BYTES / VIDEO_MODE_X; |
1702 |
|
|
1703 |
< |
x1 = mode.x; |
1703 |
> |
x1 = VIDEO_MODE_X; |
1704 |
|
for (j=y1; j<=y2; j++) { |
1705 |
|
p = &the_buffer[j * bytes_per_row]; |
1706 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1718 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1719 |
|
p += bytes_per_row; |
1720 |
|
p2 += bytes_per_row; |
1721 |
< |
for (i=mode.x*bytes_per_pixel; i>x2*bytes_per_pixel; i--) { |
1721 |
> |
for (i=VIDEO_MODE_X*bytes_per_pixel; i>x2*bytes_per_pixel; i--) { |
1722 |
|
p--; |
1723 |
|
p2--; |
1724 |
|
if (*p != *p2) { |
1878 |
|
} |
1879 |
|
} |
1880 |
|
|
1881 |
+ |
const int VIDEO_REFRESH_HZ = 60; |
1882 |
+ |
const int VIDEO_REFRESH_DELAY = 1000000 / VIDEO_REFRESH_HZ; |
1883 |
+ |
|
1884 |
|
static int redraw_func(void *arg) |
1885 |
|
{ |
1886 |
|
uint64 start = GetTicks_usec(); |
1887 |
|
int64 ticks = 0; |
1888 |
+ |
uint64 next = GetTicks_usec() + VIDEO_REFRESH_DELAY; |
1889 |
|
|
1890 |
|
while (!redraw_thread_cancel) { |
1891 |
|
|
1892 |
|
// Wait |
1893 |
< |
Delay_usec(16667); |
1893 |
> |
next += VIDEO_REFRESH_DELAY; |
1894 |
> |
int64 delay = next - GetTicks_usec(); |
1895 |
> |
if (delay > 0) |
1896 |
> |
Delay_usec(delay); |
1897 |
> |
else if (delay < -VIDEO_REFRESH_DELAY) |
1898 |
> |
next = GetTicks_usec(); |
1899 |
> |
ticks++; |
1900 |
> |
|
1901 |
> |
#ifdef SHEEPSHAVER |
1902 |
> |
// Pause if requested (during video mode switches) |
1903 |
> |
if (thread_stop_req) { |
1904 |
> |
thread_stop_ack = true; |
1905 |
> |
continue; |
1906 |
> |
} |
1907 |
> |
#endif |
1908 |
|
|
1909 |
|
// Handle SDL events |
1910 |
|
handle_events(); |
1911 |
|
|
1912 |
|
// Refresh display |
1913 |
|
video_refresh(); |
1914 |
< |
ticks++; |
1914 |
> |
|
1915 |
> |
#ifdef SHEEPSHAVER |
1916 |
> |
// Set new cursor image if it was changed |
1917 |
> |
if (cursor_changed && sdl_cursor) { |
1918 |
> |
cursor_changed = false; |
1919 |
> |
SDL_FreeCursor(sdl_cursor); |
1920 |
> |
sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, MacCursor[2], MacCursor[3]); |
1921 |
> |
if (sdl_cursor) |
1922 |
> |
SDL_SetCursor(sdl_cursor); |
1923 |
> |
} |
1924 |
> |
#endif |
1925 |
|
|
1926 |
|
// Set new palette if it was changed |
1927 |
|
handle_palette_changes(); |
1929 |
|
|
1930 |
|
uint64 end = GetTicks_usec(); |
1931 |
|
D(bug("%lld refreshes in %lld usec = %f refreshes/sec\n", ticks, end - start, ticks * 1000000.0 / (end - start))); |
1440 |
– |
redraw_thread_cancel = false; |
1932 |
|
return 0; |
1933 |
|
} |