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 |
+ |
* - Move generic Native QuickDraw acceleration routines to gfxaccel.cpp |
41 |
|
*/ |
42 |
|
|
43 |
|
#include "sysdeps.h" |
46 |
|
#include <SDL_mutex.h> |
47 |
|
#include <SDL_thread.h> |
48 |
|
#include <errno.h> |
49 |
+ |
#include <vector> |
50 |
|
|
51 |
|
#include "cpu_emulation.h" |
52 |
|
#include "main.h" |
55 |
|
#include "prefs.h" |
56 |
|
#include "user_strings.h" |
57 |
|
#include "video.h" |
58 |
+ |
#include "video_defs.h" |
59 |
|
#include "video_blit.h" |
60 |
|
|
61 |
|
#define DEBUG 0 |
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 |
|
const char KEYCODE_FILE_NAME[] = DATADIR "/keycodes"; |
90 |
|
static int16 mouse_wheel_mode; |
91 |
|
static int16 mouse_wheel_lines; |
92 |
|
|
78 |
– |
static int display_type = DISPLAY_WINDOW; // See enum above |
93 |
|
static uint8 *the_buffer = NULL; // Mac frame buffer (where MacOS draws into) |
94 |
|
static uint8 *the_buffer_copy = NULL; // Copy of Mac frame buffer (for refreshed modes) |
95 |
|
static uint32 the_buffer_size; // Size of allocated the_buffer |
99 |
|
static SDL_Thread *redraw_thread = NULL; // Redraw thread |
100 |
|
|
101 |
|
#ifdef ENABLE_VOSF |
102 |
< |
static bool use_vosf = true; // Flag: VOSF enabled |
102 |
> |
static bool use_vosf = false; // Flag: VOSF enabled |
103 |
|
#else |
104 |
|
static const bool use_vosf = false; // VOSF not possible |
105 |
|
#endif |
117 |
|
|
118 |
|
// SDL variables |
119 |
|
static int screen_depth; // Depth of current screen |
120 |
+ |
static SDL_Cursor *sdl_cursor; // Copy of Mac cursor |
121 |
+ |
static volatile bool cursor_changed = false; // Flag: cursor changed, redraw_func must update the cursor |
122 |
|
static SDL_Color sdl_palette[256]; // Color palette to be used as CLUT and gamma table |
123 |
|
static bool sdl_palette_changed = false; // Flag: Palette changed, redraw thread must set new colors |
124 |
|
static const int sdl_eventmask = SDL_MOUSEBUTTONDOWNMASK | SDL_MOUSEBUTTONUPMASK | SDL_MOUSEMOTIONMASK | SDL_KEYUPMASK | SDL_KEYDOWNMASK | SDL_VIDEOEXPOSEMASK | SDL_QUITMASK; |
146 |
|
|
147 |
|
|
148 |
|
/* |
149 |
+ |
* SheepShaver glue |
150 |
+ |
*/ |
151 |
+ |
|
152 |
+ |
#ifdef SHEEPSHAVER |
153 |
+ |
// Color depth modes type |
154 |
+ |
typedef int video_depth; |
155 |
+ |
|
156 |
+ |
// 1, 2, 4 and 8 bit depths use a color palette |
157 |
+ |
static inline bool IsDirectMode(VIDEO_MODE const & mode) |
158 |
+ |
{ |
159 |
+ |
return IsDirectMode(mode.viAppleMode); |
160 |
+ |
} |
161 |
+ |
|
162 |
+ |
// Abstract base class representing one (possibly virtual) monitor |
163 |
+ |
// ("monitor" = rectangular display with a contiguous frame buffer) |
164 |
+ |
class monitor_desc { |
165 |
+ |
public: |
166 |
+ |
monitor_desc(const vector<VIDEO_MODE> &available_modes, video_depth default_depth, uint32 default_id) {} |
167 |
+ |
virtual ~monitor_desc() {} |
168 |
+ |
|
169 |
+ |
// Get current Mac frame buffer base address |
170 |
+ |
uint32 get_mac_frame_base(void) const {return screen_base;} |
171 |
+ |
|
172 |
+ |
// Set Mac frame buffer base address (called from switch_to_mode()) |
173 |
+ |
void set_mac_frame_base(uint32 base) {screen_base = base;} |
174 |
+ |
|
175 |
+ |
// Get current video mode |
176 |
+ |
const VIDEO_MODE &get_current_mode(void) const {return VModes[cur_mode];} |
177 |
+ |
|
178 |
+ |
// Called by the video driver to switch the video mode on this display |
179 |
+ |
// (must call set_mac_frame_base()) |
180 |
+ |
virtual void switch_to_current_mode(void) = 0; |
181 |
+ |
|
182 |
+ |
// Called by the video driver to set the color palette (in indexed modes) |
183 |
+ |
// or the gamma table (in direct modes) |
184 |
+ |
virtual void set_palette(uint8 *pal, int num) = 0; |
185 |
+ |
}; |
186 |
+ |
|
187 |
+ |
// Vector of pointers to available monitor descriptions, filled by VideoInit() |
188 |
+ |
static vector<monitor_desc *> VideoMonitors; |
189 |
+ |
|
190 |
+ |
// Find Apple mode matching best specified dimensions |
191 |
+ |
static int find_apple_resolution(int xsize, int ysize) |
192 |
+ |
{ |
193 |
+ |
int apple_id; |
194 |
+ |
if (xsize < 800) |
195 |
+ |
apple_id = APPLE_640x480; |
196 |
+ |
else if (xsize < 1024) |
197 |
+ |
apple_id = APPLE_800x600; |
198 |
+ |
else if (xsize < 1152) |
199 |
+ |
apple_id = APPLE_1024x768; |
200 |
+ |
else if (xsize < 1280) { |
201 |
+ |
if (ysize < 900) |
202 |
+ |
apple_id = APPLE_1152x768; |
203 |
+ |
else |
204 |
+ |
apple_id = APPLE_1152x900; |
205 |
+ |
} |
206 |
+ |
else if (xsize < 1600) |
207 |
+ |
apple_id = APPLE_1280x1024; |
208 |
+ |
else |
209 |
+ |
apple_id = APPLE_1600x1200; |
210 |
+ |
return apple_id; |
211 |
+ |
} |
212 |
+ |
|
213 |
+ |
// Set parameters to specified Apple mode |
214 |
+ |
static void set_apple_resolution(int apple_id, int &xsize, int &ysize) |
215 |
+ |
{ |
216 |
+ |
switch (apple_id) { |
217 |
+ |
case APPLE_640x480: |
218 |
+ |
xsize = 640; |
219 |
+ |
ysize = 480; |
220 |
+ |
break; |
221 |
+ |
case APPLE_800x600: |
222 |
+ |
xsize = 800; |
223 |
+ |
ysize = 600; |
224 |
+ |
break; |
225 |
+ |
case APPLE_1024x768: |
226 |
+ |
xsize = 1024; |
227 |
+ |
ysize = 768; |
228 |
+ |
break; |
229 |
+ |
case APPLE_1152x768: |
230 |
+ |
xsize = 1152; |
231 |
+ |
ysize = 768; |
232 |
+ |
break; |
233 |
+ |
case APPLE_1152x900: |
234 |
+ |
xsize = 1152; |
235 |
+ |
ysize = 900; |
236 |
+ |
break; |
237 |
+ |
case APPLE_1280x1024: |
238 |
+ |
xsize = 1280; |
239 |
+ |
ysize = 1024; |
240 |
+ |
break; |
241 |
+ |
case APPLE_1600x1200: |
242 |
+ |
xsize = 1600; |
243 |
+ |
ysize = 1200; |
244 |
+ |
break; |
245 |
+ |
default: |
246 |
+ |
abort(); |
247 |
+ |
} |
248 |
+ |
} |
249 |
+ |
|
250 |
+ |
// Match Apple mode matching best specified dimensions |
251 |
+ |
static int match_apple_resolution(int &xsize, int &ysize) |
252 |
+ |
{ |
253 |
+ |
int apple_id = find_apple_resolution(xsize, ysize); |
254 |
+ |
set_apple_resolution(apple_id, xsize, ysize); |
255 |
+ |
return apple_id; |
256 |
+ |
} |
257 |
+ |
|
258 |
+ |
// Display error alert |
259 |
+ |
static void ErrorAlert(int error) |
260 |
+ |
{ |
261 |
+ |
ErrorAlert(GetString(error)); |
262 |
+ |
} |
263 |
+ |
|
264 |
+ |
// Display warning alert |
265 |
+ |
static void WarningAlert(int warning) |
266 |
+ |
{ |
267 |
+ |
WarningAlert(GetString(warning)); |
268 |
+ |
} |
269 |
+ |
#endif |
270 |
+ |
|
271 |
+ |
|
272 |
+ |
/* |
273 |
|
* monitor_desc subclass for SDL display |
274 |
|
*/ |
275 |
|
|
276 |
|
class SDL_monitor_desc : public monitor_desc { |
277 |
|
public: |
278 |
< |
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(const vector<VIDEO_MODE> &available_modes, video_depth default_depth, uint32 default_id) : monitor_desc(available_modes, default_depth, default_id) {} |
279 |
|
~SDL_monitor_desc() {} |
280 |
|
|
281 |
|
virtual void switch_to_current_mode(void); |
290 |
|
* Utility functions |
291 |
|
*/ |
292 |
|
|
293 |
+ |
// Find palette size for given color depth |
294 |
+ |
static int palette_size(int mode) |
295 |
+ |
{ |
296 |
+ |
switch (mode) { |
297 |
+ |
case VIDEO_DEPTH_1BIT: return 2; |
298 |
+ |
case VIDEO_DEPTH_2BIT: return 4; |
299 |
+ |
case VIDEO_DEPTH_4BIT: return 16; |
300 |
+ |
case VIDEO_DEPTH_8BIT: return 256; |
301 |
+ |
case VIDEO_DEPTH_16BIT: return 32; |
302 |
+ |
case VIDEO_DEPTH_32BIT: return 256; |
303 |
+ |
default: return 0; |
304 |
+ |
} |
305 |
+ |
} |
306 |
+ |
|
307 |
+ |
// Return bytes per pixel for requested depth |
308 |
+ |
static inline int bytes_per_pixel(int depth) |
309 |
+ |
{ |
310 |
+ |
int bpp; |
311 |
+ |
switch (depth) { |
312 |
+ |
case 8: |
313 |
+ |
bpp = 1; |
314 |
+ |
break; |
315 |
+ |
case 15: case 16: |
316 |
+ |
bpp = 2; |
317 |
+ |
break; |
318 |
+ |
case 24: case 32: |
319 |
+ |
bpp = 4; |
320 |
+ |
break; |
321 |
+ |
default: |
322 |
+ |
abort(); |
323 |
+ |
} |
324 |
+ |
return bpp; |
325 |
+ |
} |
326 |
+ |
|
327 |
|
// Map video_mode depth ID to numerical depth value |
328 |
|
static int sdl_depth_of_video_depth(int video_depth) |
329 |
|
{ |
330 |
|
int depth = -1; |
331 |
|
switch (video_depth) { |
332 |
< |
case VDEPTH_1BIT: |
332 |
> |
case VIDEO_DEPTH_1BIT: |
333 |
|
depth = 1; |
334 |
|
break; |
335 |
< |
case VDEPTH_2BIT: |
335 |
> |
case VIDEO_DEPTH_2BIT: |
336 |
|
depth = 2; |
337 |
|
break; |
338 |
< |
case VDEPTH_4BIT: |
338 |
> |
case VIDEO_DEPTH_4BIT: |
339 |
|
depth = 4; |
340 |
|
break; |
341 |
< |
case VDEPTH_8BIT: |
341 |
> |
case VIDEO_DEPTH_8BIT: |
342 |
|
depth = 8; |
343 |
|
break; |
344 |
< |
case VDEPTH_16BIT: |
344 |
> |
case VIDEO_DEPTH_16BIT: |
345 |
|
depth = 16; |
346 |
|
break; |
347 |
< |
case VDEPTH_32BIT: |
347 |
> |
case VIDEO_DEPTH_32BIT: |
348 |
|
depth = 32; |
349 |
|
break; |
350 |
|
default: |
353 |
|
return depth; |
354 |
|
} |
355 |
|
|
356 |
+ |
// Check wether specified mode is available |
357 |
+ |
static bool has_mode(int type, int width, int height) |
358 |
+ |
{ |
359 |
+ |
// FIXME: no fullscreen support yet |
360 |
+ |
if (type == DISPLAY_SCREEN) |
361 |
+ |
return false; |
362 |
+ |
|
363 |
+ |
#ifdef SHEEPSHAVER |
364 |
+ |
// Filter out Classic resolutiosn |
365 |
+ |
if (width == 512 && height == 384) |
366 |
+ |
return false; |
367 |
+ |
|
368 |
+ |
// Read window modes prefs |
369 |
+ |
static uint32 window_modes = 0; |
370 |
+ |
static uint32 screen_modes = 0; |
371 |
+ |
if (window_modes == 0 || screen_modes == 0) { |
372 |
+ |
window_modes = PrefsFindInt32("windowmodes"); |
373 |
+ |
screen_modes = PrefsFindInt32("screenmodes"); |
374 |
+ |
if (window_modes == 0 || screen_modes == 0) |
375 |
+ |
window_modes |= 3; // Allow at least 640x480 and 800x600 window modes |
376 |
+ |
} |
377 |
+ |
|
378 |
+ |
if (type == DISPLAY_WINDOW) { |
379 |
+ |
int apple_mask, apple_id = find_apple_resolution(width, height); |
380 |
+ |
switch (apple_id) { |
381 |
+ |
case APPLE_640x480: apple_mask = 0x01; break; |
382 |
+ |
case APPLE_800x600: apple_mask = 0x02; break; |
383 |
+ |
case APPLE_1024x768: apple_mask = 0x04; break; |
384 |
+ |
case APPLE_1152x768: apple_mask = 0x40; break; |
385 |
+ |
case APPLE_1152x900: apple_mask = 0x08; break; |
386 |
+ |
case APPLE_1280x1024: apple_mask = 0x10; break; |
387 |
+ |
case APPLE_1600x1200: apple_mask = 0x20; break; |
388 |
+ |
default: apple_mask = 0x00; break; |
389 |
+ |
} |
390 |
+ |
return (window_modes & apple_mask); |
391 |
+ |
} |
392 |
+ |
#else |
393 |
+ |
return true; |
394 |
+ |
#endif |
395 |
+ |
return false; |
396 |
+ |
} |
397 |
+ |
|
398 |
|
// Add mode to list of supported modes |
399 |
< |
static void add_mode(uint32 width, uint32 height, uint32 resolution_id, uint32 bytes_per_row, video_depth depth) |
399 |
> |
static void add_mode(int type, int width, int height, int resolution_id, int bytes_per_row, int depth) |
400 |
|
{ |
401 |
< |
video_mode mode; |
402 |
< |
mode.x = width; |
403 |
< |
mode.y = height; |
404 |
< |
mode.resolution_id = resolution_id; |
405 |
< |
mode.bytes_per_row = bytes_per_row; |
406 |
< |
mode.depth = depth; |
401 |
> |
// Filter out unsupported modes |
402 |
> |
if (!has_mode(type, width, height)) |
403 |
> |
return; |
404 |
> |
|
405 |
> |
// Fill in VideoMode entry |
406 |
> |
VIDEO_MODE mode; |
407 |
> |
#ifdef SHEEPSHAVER |
408 |
> |
// Recalculate dimensions to fit Apple modes |
409 |
> |
resolution_id = match_apple_resolution(width, height); |
410 |
> |
mode.viType = type; |
411 |
> |
#endif |
412 |
> |
VIDEO_MODE_X = width; |
413 |
> |
VIDEO_MODE_Y = height; |
414 |
> |
VIDEO_MODE_RESOLUTION = resolution_id; |
415 |
> |
VIDEO_MODE_ROW_BYTES = bytes_per_row; |
416 |
> |
VIDEO_MODE_DEPTH = depth; |
417 |
|
VideoModes.push_back(mode); |
418 |
|
} |
419 |
|
|
420 |
|
// Add standard list of windowed modes for given color depth |
421 |
< |
static void add_window_modes(video_depth depth) |
421 |
> |
static void add_window_modes(int depth) |
422 |
|
{ |
423 |
< |
add_mode(512, 384, 0x80, TrivialBytesPerRow(512, depth), depth); |
424 |
< |
add_mode(640, 480, 0x81, TrivialBytesPerRow(640, depth), depth); |
425 |
< |
add_mode(800, 600, 0x82, TrivialBytesPerRow(800, depth), depth); |
426 |
< |
add_mode(1024, 768, 0x83, TrivialBytesPerRow(1024, depth), depth); |
427 |
< |
add_mode(1152, 870, 0x84, TrivialBytesPerRow(1152, depth), depth); |
428 |
< |
add_mode(1280, 1024, 0x85, TrivialBytesPerRow(1280, depth), depth); |
429 |
< |
add_mode(1600, 1200, 0x86, TrivialBytesPerRow(1600, depth), depth); |
423 |
> |
video_depth vdepth = (video_depth)depth; |
424 |
> |
add_mode(DISPLAY_WINDOW, 512, 384, 0x80, TrivialBytesPerRow(512, vdepth), depth); |
425 |
> |
add_mode(DISPLAY_WINDOW, 640, 480, 0x81, TrivialBytesPerRow(640, vdepth), depth); |
426 |
> |
add_mode(DISPLAY_WINDOW, 800, 600, 0x82, TrivialBytesPerRow(800, vdepth), depth); |
427 |
> |
add_mode(DISPLAY_WINDOW, 1024, 768, 0x83, TrivialBytesPerRow(1024, vdepth), depth); |
428 |
> |
add_mode(DISPLAY_WINDOW, 1152, 870, 0x84, TrivialBytesPerRow(1152, vdepth), depth); |
429 |
> |
add_mode(DISPLAY_WINDOW, 1280, 1024, 0x85, TrivialBytesPerRow(1280, vdepth), depth); |
430 |
> |
add_mode(DISPLAY_WINDOW, 1600, 1200, 0x86, TrivialBytesPerRow(1600, vdepth), depth); |
431 |
|
} |
432 |
|
|
433 |
|
// Set Mac frame layout and base address (uses the_buffer/MacFrameBaseMac) |
434 |
< |
static void set_mac_frame_buffer(SDL_monitor_desc &monitor, video_depth depth, bool native_byte_order) |
434 |
> |
static void set_mac_frame_buffer(SDL_monitor_desc &monitor, int depth, bool native_byte_order) |
435 |
|
{ |
436 |
|
#if !REAL_ADDRESSING && !DIRECT_ADDRESSING |
437 |
|
int layout = FLAYOUT_DIRECT; |
438 |
< |
if (depth == VDEPTH_16BIT) |
438 |
> |
if (depth == VIDEO_DEPTH_16BIT) |
439 |
|
layout = (screen_depth == 15) ? FLAYOUT_HOST_555 : FLAYOUT_HOST_565; |
440 |
< |
else if (depth == VDEPTH_32BIT) |
440 |
> |
else if (depth == VIDEO_DEPTH_32BIT) |
441 |
|
layout = (screen_depth == 24) ? FLAYOUT_HOST_888 : FLAYOUT_DIRECT; |
442 |
|
if (native_byte_order) |
443 |
|
MacFrameLayout = layout; |
446 |
|
monitor.set_mac_frame_base(MacFrameBaseMac); |
447 |
|
|
448 |
|
// Set variables used by UAE memory banking |
449 |
< |
const video_mode &mode = monitor.get_current_mode(); |
449 |
> |
const VIDEO_MODE &mode = monitor.get_current_mode(); |
450 |
|
MacFrameBaseHost = the_buffer; |
451 |
< |
MacFrameSize = mode.bytes_per_row * mode.y; |
451 |
> |
MacFrameSize = VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y; |
452 |
|
InitFrameBufferMapping(); |
453 |
|
#else |
454 |
|
monitor.set_mac_frame_base(Host2MacAddr(the_buffer)); |
497 |
|
|
498 |
|
public: |
499 |
|
SDL_monitor_desc &monitor; // Associated video monitor |
500 |
< |
const video_mode &mode; // Video mode handled by the driver |
500 |
> |
const VIDEO_MODE &mode; // Video mode handled by the driver |
501 |
|
|
502 |
|
bool init_ok; // Initialization succeeded (we can't use exceptions because of -fomit-frame-pointer) |
503 |
|
SDL_Surface *s; // The surface we draw into |
585 |
|
// Palette has changed |
586 |
|
void driver_base::update_palette(void) |
587 |
|
{ |
588 |
< |
const video_mode &mode = monitor.get_current_mode(); |
588 |
> |
const VIDEO_MODE &mode = monitor.get_current_mode(); |
589 |
|
|
590 |
< |
if (mode.depth <= VDEPTH_8BIT) |
590 |
> |
if (VIDEO_MODE_DEPTH <= VIDEO_DEPTH_8BIT) |
591 |
|
SDL_SetPalette(s, SDL_PHYSPAL, sdl_palette, 0, 256); |
592 |
|
} |
593 |
|
|
610 |
|
driver_window::driver_window(SDL_monitor_desc &m) |
611 |
|
: driver_base(m), mouse_grabbed(false) |
612 |
|
{ |
613 |
< |
int width = mode.x, height = mode.y; |
613 |
> |
int width = VIDEO_MODE_X, height = VIDEO_MODE_Y; |
614 |
|
int aligned_width = (width + 15) & ~15; |
615 |
|
int aligned_height = (height + 15) & ~15; |
616 |
|
|
618 |
|
ADBSetRelMouseMode(mouse_grabbed); |
619 |
|
|
620 |
|
// Create surface |
621 |
< |
int depth = (mode.depth <= VDEPTH_8BIT ? 8 : screen_depth); |
621 |
> |
int depth = (VIDEO_MODE_DEPTH <= VIDEO_DEPTH_8BIT ? 8 : screen_depth); |
622 |
|
if ((s = SDL_SetVideoMode(width, height, depth, SDL_HWSURFACE)) == NULL) |
623 |
|
return; |
624 |
|
|
630 |
|
the_buffer = (uint8 *)vm_acquire(the_buffer_size); |
631 |
|
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
632 |
|
D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer)); |
633 |
+ |
|
634 |
+ |
// Check whether we can initialize the VOSF subsystem and it's profitable |
635 |
+ |
if (!video_vosf_init(m)) { |
636 |
+ |
WarningAlert(STR_VOSF_INIT_ERR); |
637 |
+ |
use_vosf = false; |
638 |
+ |
} |
639 |
+ |
else if (!video_vosf_profitable()) { |
640 |
+ |
video_vosf_exit(); |
641 |
+ |
// WarningAlert(STR_VOSF_NOT_PROFITABLE_WARN); |
642 |
+ |
printf("VOSF acceleration is not profitable on this platform\n"); |
643 |
+ |
use_vosf = false; |
644 |
+ |
} |
645 |
+ |
if (!use_vosf) { |
646 |
+ |
free(the_buffer_copy); |
647 |
+ |
vm_release(the_buffer, the_buffer_size); |
648 |
+ |
the_host_buffer = NULL; |
649 |
+ |
} |
650 |
+ |
#endif |
651 |
+ |
if (!use_vosf) { |
652 |
+ |
// Allocate memory for frame buffer |
653 |
+ |
the_buffer_size = (aligned_height + 2) * s->pitch; |
654 |
+ |
the_buffer_copy = (uint8 *)calloc(1, the_buffer_size); |
655 |
+ |
the_buffer = (uint8 *)calloc(1, the_buffer_size); |
656 |
+ |
D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy)); |
657 |
+ |
} |
658 |
+ |
|
659 |
+ |
#ifdef SHEEPSHAVER |
660 |
+ |
// Create cursor |
661 |
+ |
if ((sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, 0, 0)) != NULL) { |
662 |
+ |
SDL_SetCursor(sdl_cursor); |
663 |
+ |
cursor_changed = false; |
664 |
+ |
} |
665 |
|
#else |
666 |
< |
// Allocate memory for frame buffer |
667 |
< |
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)); |
666 |
> |
// Hide cursor |
667 |
> |
SDL_ShowCursor(0); |
668 |
|
#endif |
669 |
|
|
670 |
|
// Set window name/class |
671 |
|
set_window_name(STR_WINDOW_TITLE); |
672 |
|
|
417 |
– |
// Hide cursor |
418 |
– |
SDL_ShowCursor(0); |
419 |
– |
|
673 |
|
// Init blitting routines |
674 |
|
SDL_PixelFormat *f = s->format; |
675 |
|
VisualFormat visualFormat; |
677 |
|
visualFormat.Rmask = f->Rmask; |
678 |
|
visualFormat.Gmask = f->Gmask; |
679 |
|
visualFormat.Bmask = f->Bmask; |
680 |
< |
Screen_blitter_init(visualFormat, true, sdl_depth_of_video_depth(mode.depth)); |
680 |
> |
Screen_blitter_init(visualFormat, true, sdl_depth_of_video_depth(VIDEO_MODE_DEPTH)); |
681 |
|
|
682 |
|
// Load gray ramp to 8->16/32 expand map |
683 |
|
if (!IsDirectMode(mode)) |
685 |
|
ExpandMap[i] = SDL_MapRGB(f, i, i, i); |
686 |
|
|
687 |
|
// Set frame buffer base |
688 |
< |
set_mac_frame_buffer(monitor, mode.depth, true); |
688 |
> |
set_mac_frame_buffer(monitor, VIDEO_MODE_DEPTH, true); |
689 |
|
|
690 |
|
// Everything went well |
691 |
|
init_ok = true; |
827 |
|
bool SDL_monitor_desc::video_open(void) |
828 |
|
{ |
829 |
|
D(bug("video_open()\n")); |
830 |
< |
const video_mode &mode = get_current_mode(); |
830 |
> |
const VIDEO_MODE &mode = get_current_mode(); |
831 |
> |
#if DEBUG |
832 |
> |
D(bug("Current video mode:\n")); |
833 |
> |
D(bug(" %dx%d (ID %02x), %d bpp\n", VIDEO_MODE_X, VIDEO_MODE_Y, VIDEO_MODE_RESOLUTION, 1 << (VIDEO_MODE_DEPTH & 0x0f))); |
834 |
> |
#endif |
835 |
|
|
836 |
|
// Create display driver object of requested type |
837 |
|
switch (display_type) { |
847 |
|
return false; |
848 |
|
} |
849 |
|
|
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 |
– |
|
850 |
|
// Initialize VideoRefresh function |
851 |
|
VideoRefreshInit(); |
852 |
|
|
855 |
|
|
856 |
|
// Start redraw/input thread |
857 |
|
redraw_thread_cancel = false; |
858 |
< |
redraw_thread_active = (SDL_CreateThread(redraw_func, NULL) != NULL); |
858 |
> |
redraw_thread_active = ((redraw_thread = SDL_CreateThread(redraw_func, NULL)) != NULL); |
859 |
|
if (!redraw_thread_active) { |
860 |
|
printf("FATAL: cannot create redraw thread\n"); |
861 |
|
return false; |
863 |
|
return true; |
864 |
|
} |
865 |
|
|
866 |
+ |
#ifdef SHEEPSHAVER |
867 |
+ |
bool VideoInit(void) |
868 |
+ |
{ |
869 |
+ |
const bool classic = false; |
870 |
+ |
#else |
871 |
|
bool VideoInit(bool classic) |
872 |
|
{ |
873 |
+ |
#endif |
874 |
|
classic_mode = classic; |
875 |
|
|
876 |
|
#ifdef ENABLE_VOSF |
894 |
|
mouse_wheel_lines = PrefsFindInt32("mousewheellines"); |
895 |
|
|
896 |
|
// Get screen mode from preferences |
897 |
< |
const char *mode_str; |
897 |
> |
const char *mode_str = NULL; |
898 |
> |
#ifndef SHEEPSHAVER |
899 |
|
if (classic_mode) |
900 |
|
mode_str = "win/512/342"; |
901 |
|
else |
902 |
|
mode_str = PrefsFindString("screen"); |
903 |
+ |
#endif |
904 |
|
|
905 |
|
// Determine display type and default dimensions |
906 |
< |
int default_width = 512, default_height = 384; |
906 |
> |
int default_width, default_height; |
907 |
> |
if (classic) { |
908 |
> |
default_width = 512; |
909 |
> |
default_height = 384; |
910 |
> |
} |
911 |
> |
else { |
912 |
> |
default_width = 640; |
913 |
> |
default_height = 480; |
914 |
> |
} |
915 |
|
display_type = DISPLAY_WINDOW; |
916 |
|
if (mode_str) { |
917 |
|
if (sscanf(mode_str, "win/%d/%d", &default_width, &default_height) == 2) |
918 |
|
display_type = DISPLAY_WINDOW; |
919 |
|
} |
920 |
|
int max_width = 640, max_height = 480; |
921 |
< |
if (display_type == DISPLAY_SCREEN) { |
922 |
< |
SDL_Rect **modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE); |
923 |
< |
if (modes && modes != (SDL_Rect **)-1) { |
924 |
< |
max_width = modes[0]->w; |
925 |
< |
max_height = modes[0]->h; |
926 |
< |
} |
921 |
> |
SDL_Rect **modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE); |
922 |
> |
if (modes && modes != (SDL_Rect **)-1) { |
923 |
> |
max_width = modes[0]->w; |
924 |
> |
max_height = modes[0]->h; |
925 |
> |
if (default_width > max_width) |
926 |
> |
default_width = max_width; |
927 |
> |
if (default_height > max_height) |
928 |
> |
default_height = max_height; |
929 |
|
} |
930 |
|
if (default_width <= 0) |
931 |
|
default_width = max_width; |
934 |
|
|
935 |
|
// Mac screen depth follows X depth |
936 |
|
screen_depth = SDL_GetVideoInfo()->vfmt->BitsPerPixel; |
937 |
< |
video_depth default_depth; |
937 |
> |
int default_depth; |
938 |
|
switch (screen_depth) { |
939 |
|
case 8: |
940 |
< |
default_depth = VDEPTH_8BIT; |
940 |
> |
default_depth = VIDEO_DEPTH_8BIT; |
941 |
|
break; |
942 |
|
case 15: case 16: |
943 |
< |
default_depth = VDEPTH_16BIT; |
943 |
> |
default_depth = VIDEO_DEPTH_16BIT; |
944 |
|
break; |
945 |
|
case 24: case 32: |
946 |
< |
default_depth = VDEPTH_32BIT; |
946 |
> |
default_depth = VIDEO_DEPTH_32BIT; |
947 |
|
break; |
948 |
|
default: |
949 |
< |
default_depth = VDEPTH_1BIT; |
949 |
> |
default_depth = VIDEO_DEPTH_1BIT; |
950 |
|
break; |
951 |
|
} |
952 |
|
|
953 |
|
// Construct list of supported modes |
954 |
|
if (display_type == DISPLAY_WINDOW) { |
955 |
|
if (classic) |
956 |
< |
add_mode(512, 342, 0x80, 64, VDEPTH_1BIT); |
956 |
> |
add_mode(display_type, 512, 342, 0x80, 64, VIDEO_DEPTH_1BIT); |
957 |
|
else { |
958 |
< |
for (int d = VDEPTH_1BIT; d <= default_depth; d++) { |
959 |
< |
int bpp = (d <= VDEPTH_8BIT ? 8 : sdl_depth_of_video_depth(d)); |
958 |
> |
for (int d = VIDEO_DEPTH_1BIT; d <= default_depth; d++) { |
959 |
> |
int bpp = (d <= VIDEO_DEPTH_8BIT ? 8 : sdl_depth_of_video_depth(d)); |
960 |
|
if (SDL_VideoModeOK(max_width, max_height, bpp, SDL_HWSURFACE)) |
961 |
|
add_window_modes(video_depth(d)); |
962 |
|
} |
963 |
|
} |
964 |
|
} else |
965 |
< |
add_mode(default_width, default_height, 0x80, TrivialBytesPerRow(default_width, default_depth), default_depth); |
965 |
> |
add_mode(display_type, default_width, default_height, 0x80, TrivialBytesPerRow(default_width, (video_depth)default_depth), default_depth); |
966 |
|
if (VideoModes.empty()) { |
967 |
|
ErrorAlert(STR_NO_XVISUAL_ERR); |
968 |
|
return false; |
970 |
|
|
971 |
|
// Find requested default mode with specified dimensions |
972 |
|
uint32 default_id; |
973 |
< |
std::vector<video_mode>::const_iterator i, end = VideoModes.end(); |
973 |
> |
std::vector<VIDEO_MODE>::const_iterator i, end = VideoModes.end(); |
974 |
|
for (i = VideoModes.begin(); i != end; ++i) { |
975 |
< |
if (i->x == default_width && i->y == default_height && i->depth == default_depth) { |
976 |
< |
default_id = i->resolution_id; |
975 |
> |
const VIDEO_MODE & mode = (*i); |
976 |
> |
if (VIDEO_MODE_X == default_width && VIDEO_MODE_Y == default_height && VIDEO_MODE_DEPTH == default_depth) { |
977 |
> |
default_id = VIDEO_MODE_RESOLUTION; |
978 |
> |
#ifdef SHEEPSHAVER |
979 |
> |
std::vector<VIDEO_MODE>::const_iterator begin = VideoModes.begin(); |
980 |
> |
cur_mode = distance(begin, i); |
981 |
> |
#endif |
982 |
|
break; |
983 |
|
} |
984 |
|
} |
985 |
|
if (i == end) { // not found, use first available mode |
986 |
< |
default_depth = VideoModes[0].depth; |
987 |
< |
default_id = VideoModes[0].resolution_id; |
986 |
> |
const VIDEO_MODE & mode = VideoModes[0]; |
987 |
> |
default_depth = VIDEO_MODE_DEPTH; |
988 |
> |
default_id = VIDEO_MODE_RESOLUTION; |
989 |
> |
#ifdef SHEEPSHAVER |
990 |
> |
cur_mode = 0; |
991 |
> |
#endif |
992 |
|
} |
993 |
|
|
994 |
+ |
#ifdef SHEEPSHAVER |
995 |
+ |
for (int i = 0; i < VideoModes.size(); i++) |
996 |
+ |
VModes[i] = VideoModes[i]; |
997 |
+ |
VideoInfo *p = &VModes[VideoModes.size()]; |
998 |
+ |
p->viType = DIS_INVALID; // End marker |
999 |
+ |
p->viRowBytes = 0; |
1000 |
+ |
p->viXsize = p->viYsize = 0; |
1001 |
+ |
p->viAppleMode = 0; |
1002 |
+ |
p->viAppleID = 0; |
1003 |
+ |
#endif |
1004 |
+ |
|
1005 |
|
#if DEBUG |
1006 |
|
D(bug("Available video modes:\n")); |
1007 |
|
for (i = VideoModes.begin(); i != end; ++i) { |
1008 |
< |
int bits = 1 << i->depth; |
1008 |
> |
const VIDEO_MODE & mode = (*i); |
1009 |
> |
int bits = 1 << VIDEO_MODE_DEPTH; |
1010 |
|
if (bits == 16) |
1011 |
|
bits = 15; |
1012 |
|
else if (bits == 32) |
1013 |
|
bits = 24; |
1014 |
< |
D(bug(" %dx%d (ID %02x), %d colors\n", i->x, i->y, i->resolution_id, 1 << bits)); |
1014 |
> |
D(bug(" %dx%d (ID %02x), %d colors\n", VIDEO_MODE_X, VIDEO_MODE_Y, VIDEO_MODE_RESOLUTION, 1 << bits)); |
1015 |
|
} |
1016 |
|
#endif |
1017 |
|
|
1018 |
|
// Create SDL_monitor_desc for this (the only) display |
1019 |
< |
SDL_monitor_desc *monitor = new SDL_monitor_desc(VideoModes, default_depth, default_id); |
1019 |
> |
SDL_monitor_desc *monitor = new SDL_monitor_desc(VideoModes, (video_depth)default_depth, default_id); |
1020 |
|
VideoMonitors.push_back(monitor); |
1021 |
|
|
1022 |
|
// Open display |
1036 |
|
// Stop redraw thread |
1037 |
|
if (redraw_thread_active) { |
1038 |
|
redraw_thread_cancel = true; |
1039 |
< |
// SDL_WaitThread(redraw_thread, NULL); doesn't work |
754 |
< |
while (redraw_thread_cancel); |
1039 |
> |
SDL_WaitThread(redraw_thread, NULL); |
1040 |
|
} |
1041 |
|
redraw_thread_active = false; |
1042 |
|
|
1086 |
|
* Mac VBL interrupt |
1087 |
|
*/ |
1088 |
|
|
1089 |
+ |
/* |
1090 |
+ |
* Execute video VBL routine |
1091 |
+ |
*/ |
1092 |
+ |
|
1093 |
+ |
#ifdef SHEEPSHAVER |
1094 |
+ |
void VideoVBL(void) |
1095 |
+ |
{ |
1096 |
+ |
// Emergency quit requested? Then quit |
1097 |
+ |
if (emerg_quit) |
1098 |
+ |
QuitEmulator(); |
1099 |
+ |
|
1100 |
+ |
// Temporarily give up frame buffer lock (this is the point where |
1101 |
+ |
// we are suspended when the user presses Ctrl-Tab) |
1102 |
+ |
UNLOCK_FRAME_BUFFER; |
1103 |
+ |
LOCK_FRAME_BUFFER; |
1104 |
+ |
|
1105 |
+ |
// Execute video VBL |
1106 |
+ |
if (private_data != NULL && private_data->interruptsEnabled) |
1107 |
+ |
VSLDoInterruptService(private_data->vslServiceID); |
1108 |
+ |
} |
1109 |
+ |
#else |
1110 |
|
void VideoInterrupt(void) |
1111 |
|
{ |
1112 |
|
// We must fill in the events queue in the same thread that did call SDL_SetVideoMode() |
1121 |
|
UNLOCK_FRAME_BUFFER; |
1122 |
|
LOCK_FRAME_BUFFER; |
1123 |
|
} |
1124 |
+ |
#endif |
1125 |
|
|
1126 |
|
|
1127 |
|
/* |
1128 |
|
* Set palette |
1129 |
|
*/ |
1130 |
|
|
1131 |
+ |
#ifdef SHEEPSHAVER |
1132 |
+ |
void video_set_palette(void) |
1133 |
+ |
{ |
1134 |
+ |
monitor_desc * monitor = VideoMonitors[0]; |
1135 |
+ |
int n_colors = palette_size(monitor->get_current_mode().viAppleMode); |
1136 |
+ |
uint8 pal[256 * 3]; |
1137 |
+ |
for (int c = 0; c < n_colors; c++) { |
1138 |
+ |
pal[c*3 + 0] = mac_pal[c].red; |
1139 |
+ |
pal[c*3 + 1] = mac_pal[c].green; |
1140 |
+ |
pal[c*3 + 2] = mac_pal[c].blue; |
1141 |
+ |
} |
1142 |
+ |
monitor->set_palette(pal, n_colors); |
1143 |
+ |
} |
1144 |
+ |
#endif |
1145 |
+ |
|
1146 |
|
void SDL_monitor_desc::set_palette(uint8 *pal, int num_in) |
1147 |
|
{ |
1148 |
< |
const video_mode &mode = get_current_mode(); |
1148 |
> |
const VIDEO_MODE &mode = get_current_mode(); |
1149 |
|
|
1150 |
|
// FIXME: how can we handle the gamma ramp? |
1151 |
< |
if (mode.depth > VDEPTH_8BIT) |
1151 |
> |
if (VIDEO_MODE_DEPTH > VIDEO_DEPTH_8BIT) |
1152 |
|
return; |
1153 |
|
|
1154 |
|
LOCK_PALETTE; |
1173 |
|
} |
1174 |
|
|
1175 |
|
#ifdef ENABLE_VOSF |
1176 |
< |
// We have to redraw everything because the interpretation of pixel values changed |
1177 |
< |
LOCK_VOSF; |
1178 |
< |
PFLAG_SET_ALL; |
1179 |
< |
UNLOCK_VOSF; |
1180 |
< |
memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y); |
1176 |
> |
if (use_vosf) { |
1177 |
> |
// We have to redraw everything because the interpretation of pixel values changed |
1178 |
> |
LOCK_VOSF; |
1179 |
> |
PFLAG_SET_ALL; |
1180 |
> |
UNLOCK_VOSF; |
1181 |
> |
memset(the_buffer_copy, 0, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y); |
1182 |
> |
} |
1183 |
|
#endif |
1184 |
|
} |
1185 |
|
|
1194 |
|
* Switch video mode |
1195 |
|
*/ |
1196 |
|
|
1197 |
+ |
#ifdef SHEEPSHAVER |
1198 |
+ |
int16 video_mode_change(VidLocals *csSave, uint32 ParamPtr) |
1199 |
+ |
{ |
1200 |
+ |
/* return if no mode change */ |
1201 |
+ |
if ((csSave->saveData == ReadMacInt32(ParamPtr + csData)) && |
1202 |
+ |
(csSave->saveMode == ReadMacInt16(ParamPtr + csMode))) return noErr; |
1203 |
+ |
|
1204 |
+ |
/* first find video mode in table */ |
1205 |
+ |
for (int i=0; VModes[i].viType != DIS_INVALID; i++) { |
1206 |
+ |
if ((ReadMacInt16(ParamPtr + csMode) == VModes[i].viAppleMode) && |
1207 |
+ |
(ReadMacInt32(ParamPtr + csData) == VModes[i].viAppleID)) { |
1208 |
+ |
csSave->saveMode = ReadMacInt16(ParamPtr + csMode); |
1209 |
+ |
csSave->saveData = ReadMacInt32(ParamPtr + csData); |
1210 |
+ |
csSave->savePage = ReadMacInt16(ParamPtr + csPage); |
1211 |
+ |
|
1212 |
+ |
// Disable interrupts |
1213 |
+ |
DisableInterrupt(); |
1214 |
+ |
|
1215 |
+ |
cur_mode = i; |
1216 |
+ |
monitor_desc *monitor = VideoMonitors[0]; |
1217 |
+ |
monitor->switch_to_current_mode(); |
1218 |
+ |
|
1219 |
+ |
WriteMacInt32(ParamPtr + csBaseAddr, screen_base); |
1220 |
+ |
csSave->saveBaseAddr=screen_base; |
1221 |
+ |
csSave->saveData=VModes[cur_mode].viAppleID;/* First mode ... */ |
1222 |
+ |
csSave->saveMode=VModes[cur_mode].viAppleMode; |
1223 |
+ |
|
1224 |
+ |
// Enable interrupts |
1225 |
+ |
EnableInterrupt(); |
1226 |
+ |
return noErr; |
1227 |
+ |
} |
1228 |
+ |
} |
1229 |
+ |
return paramErr; |
1230 |
+ |
} |
1231 |
+ |
#endif |
1232 |
+ |
|
1233 |
|
void SDL_monitor_desc::switch_to_current_mode(void) |
1234 |
|
{ |
1235 |
|
// Close and reopen display |
1244 |
|
|
1245 |
|
|
1246 |
|
/* |
1247 |
+ |
* Can we set the MacOS cursor image into the window? |
1248 |
+ |
*/ |
1249 |
+ |
|
1250 |
+ |
#ifdef SHEEPSHAVER |
1251 |
+ |
bool video_can_change_cursor(void) |
1252 |
+ |
{ |
1253 |
+ |
return (display_type == DISPLAY_WINDOW); |
1254 |
+ |
} |
1255 |
+ |
#endif |
1256 |
+ |
|
1257 |
+ |
|
1258 |
+ |
/* |
1259 |
+ |
* Set cursor image for window |
1260 |
+ |
*/ |
1261 |
+ |
|
1262 |
+ |
#ifdef SHEEPSHAVER |
1263 |
+ |
void video_set_cursor(void) |
1264 |
+ |
{ |
1265 |
+ |
cursor_changed = true; |
1266 |
+ |
} |
1267 |
+ |
#endif |
1268 |
+ |
|
1269 |
+ |
|
1270 |
+ |
/* |
1271 |
+ |
* Install graphics acceleration |
1272 |
+ |
*/ |
1273 |
+ |
|
1274 |
+ |
#ifdef SHEEPSHAVER |
1275 |
+ |
// Rectangle inversion |
1276 |
+ |
template< int bpp > |
1277 |
+ |
static inline void do_invrect(uint8 *dest, uint32 length) |
1278 |
+ |
{ |
1279 |
+ |
#define INVERT_1(PTR, OFS) ((uint8 *)(PTR))[OFS] = ~((uint8 *)(PTR))[OFS] |
1280 |
+ |
#define INVERT_2(PTR, OFS) ((uint16 *)(PTR))[OFS] = ~((uint16 *)(PTR))[OFS] |
1281 |
+ |
#define INVERT_4(PTR, OFS) ((uint32 *)(PTR))[OFS] = ~((uint32 *)(PTR))[OFS] |
1282 |
+ |
#define INVERT_8(PTR, OFS) ((uint64 *)(PTR))[OFS] = ~((uint64 *)(PTR))[OFS] |
1283 |
+ |
|
1284 |
+ |
#ifndef UNALIGNED_PROFITABLE |
1285 |
+ |
// Align on 16-bit boundaries |
1286 |
+ |
if (bpp < 16 && (((uintptr)dest) & 1)) { |
1287 |
+ |
INVERT_1(dest, 0); |
1288 |
+ |
dest += 1; length -= 1; |
1289 |
+ |
} |
1290 |
+ |
|
1291 |
+ |
// Align on 32-bit boundaries |
1292 |
+ |
if (bpp < 32 && (((uintptr)dest) & 2)) { |
1293 |
+ |
INVERT_2(dest, 0); |
1294 |
+ |
dest += 2; length -= 2; |
1295 |
+ |
} |
1296 |
+ |
#endif |
1297 |
+ |
|
1298 |
+ |
// Invert 8-byte words |
1299 |
+ |
if (length >= 8) { |
1300 |
+ |
const int r = (length / 8) % 8; |
1301 |
+ |
dest += r * 8; |
1302 |
+ |
|
1303 |
+ |
int n = ((length / 8) + 7) / 8; |
1304 |
+ |
switch (r) { |
1305 |
+ |
case 0: do { |
1306 |
+ |
dest += 64; |
1307 |
+ |
INVERT_8(dest, -8); |
1308 |
+ |
case 7: INVERT_8(dest, -7); |
1309 |
+ |
case 6: INVERT_8(dest, -6); |
1310 |
+ |
case 5: INVERT_8(dest, -5); |
1311 |
+ |
case 4: INVERT_8(dest, -4); |
1312 |
+ |
case 3: INVERT_8(dest, -3); |
1313 |
+ |
case 2: INVERT_8(dest, -2); |
1314 |
+ |
case 1: INVERT_8(dest, -1); |
1315 |
+ |
} while (--n > 0); |
1316 |
+ |
} |
1317 |
+ |
} |
1318 |
+ |
|
1319 |
+ |
// 32-bit cell to invert? |
1320 |
+ |
if (length & 4) { |
1321 |
+ |
INVERT_4(dest, 0); |
1322 |
+ |
if (bpp <= 16) |
1323 |
+ |
dest += 4; |
1324 |
+ |
} |
1325 |
+ |
|
1326 |
+ |
// 16-bit cell to invert? |
1327 |
+ |
if (bpp <= 16 && (length & 2)) { |
1328 |
+ |
INVERT_2(dest, 0); |
1329 |
+ |
if (bpp <= 8) |
1330 |
+ |
dest += 2; |
1331 |
+ |
} |
1332 |
+ |
|
1333 |
+ |
// 8-bit cell to invert? |
1334 |
+ |
if (bpp <= 8 && (length & 1)) |
1335 |
+ |
INVERT_1(dest, 0); |
1336 |
+ |
|
1337 |
+ |
#undef INVERT_1 |
1338 |
+ |
#undef INVERT_2 |
1339 |
+ |
#undef INVERT_4 |
1340 |
+ |
#undef INVERT_8 |
1341 |
+ |
} |
1342 |
+ |
|
1343 |
+ |
void NQD_invrect(uint32 p) |
1344 |
+ |
{ |
1345 |
+ |
D(bug("accl_invrect %08x\n", p)); |
1346 |
+ |
|
1347 |
+ |
// Get inversion parameters |
1348 |
+ |
int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2); |
1349 |
+ |
int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0); |
1350 |
+ |
int16 width = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2); |
1351 |
+ |
int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0); |
1352 |
+ |
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1353 |
+ |
D(bug(" width %d, height %d, bytes_per_row %d\n", width, height, (int32)ReadMacInt32(p + acclDestRowBytes))); |
1354 |
+ |
|
1355 |
+ |
//!!?? pen_mode == 14 |
1356 |
+ |
|
1357 |
+ |
// And perform the inversion |
1358 |
+ |
const int bpp = bytes_per_pixel(ReadMacInt32(p + acclDestPixelSize)); |
1359 |
+ |
const int dest_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes); |
1360 |
+ |
uint8 *dest = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dest_row_bytes) + (dest_X * bpp)); |
1361 |
+ |
width *= bpp; |
1362 |
+ |
switch (bpp) { |
1363 |
+ |
case 1: |
1364 |
+ |
for (int i = 0; i < height; i++) { |
1365 |
+ |
do_invrect<8>(dest, width); |
1366 |
+ |
dest += dest_row_bytes; |
1367 |
+ |
} |
1368 |
+ |
break; |
1369 |
+ |
case 2: |
1370 |
+ |
for (int i = 0; i < height; i++) { |
1371 |
+ |
do_invrect<16>(dest, width); |
1372 |
+ |
dest += dest_row_bytes; |
1373 |
+ |
} |
1374 |
+ |
break; |
1375 |
+ |
case 4: |
1376 |
+ |
for (int i = 0; i < height; i++) { |
1377 |
+ |
do_invrect<32>(dest, width); |
1378 |
+ |
dest += dest_row_bytes; |
1379 |
+ |
} |
1380 |
+ |
break; |
1381 |
+ |
} |
1382 |
+ |
} |
1383 |
+ |
|
1384 |
+ |
// Rectangle filling |
1385 |
+ |
template< int bpp > |
1386 |
+ |
static inline void do_fillrect(uint8 *dest, uint32 color, uint32 length) |
1387 |
+ |
{ |
1388 |
+ |
#define FILL_1(PTR, OFS, VAL) ((uint8 *)(PTR))[OFS] = (VAL) |
1389 |
+ |
#define FILL_2(PTR, OFS, VAL) ((uint16 *)(PTR))[OFS] = (VAL) |
1390 |
+ |
#define FILL_4(PTR, OFS, VAL) ((uint32 *)(PTR))[OFS] = (VAL) |
1391 |
+ |
#define FILL_8(PTR, OFS, VAL) ((uint64 *)(PTR))[OFS] = (VAL) |
1392 |
+ |
|
1393 |
+ |
#ifndef UNALIGNED_PROFITABLE |
1394 |
+ |
// Align on 16-bit boundaries |
1395 |
+ |
if (bpp < 16 && (((uintptr)dest) & 1)) { |
1396 |
+ |
FILL_1(dest, 0, color); |
1397 |
+ |
dest += 1; length -= 1; |
1398 |
+ |
} |
1399 |
+ |
|
1400 |
+ |
// Align on 32-bit boundaries |
1401 |
+ |
if (bpp < 32 && (((uintptr)dest) & 2)) { |
1402 |
+ |
FILL_2(dest, 0, color); |
1403 |
+ |
dest += 2; length -= 2; |
1404 |
+ |
} |
1405 |
+ |
#endif |
1406 |
+ |
|
1407 |
+ |
// Fill 8-byte words |
1408 |
+ |
if (length >= 8) { |
1409 |
+ |
const uint64 c = (((uint64)color) << 32) | color; |
1410 |
+ |
const int r = (length / 8) % 8; |
1411 |
+ |
dest += r * 8; |
1412 |
+ |
|
1413 |
+ |
int n = ((length / 8) + 7) / 8; |
1414 |
+ |
switch (r) { |
1415 |
+ |
case 0: do { |
1416 |
+ |
dest += 64; |
1417 |
+ |
FILL_8(dest, -8, c); |
1418 |
+ |
case 7: FILL_8(dest, -7, c); |
1419 |
+ |
case 6: FILL_8(dest, -6, c); |
1420 |
+ |
case 5: FILL_8(dest, -5, c); |
1421 |
+ |
case 4: FILL_8(dest, -4, c); |
1422 |
+ |
case 3: FILL_8(dest, -3, c); |
1423 |
+ |
case 2: FILL_8(dest, -2, c); |
1424 |
+ |
case 1: FILL_8(dest, -1, c); |
1425 |
+ |
} while (--n > 0); |
1426 |
+ |
} |
1427 |
+ |
} |
1428 |
+ |
|
1429 |
+ |
// 32-bit cell to fill? |
1430 |
+ |
if (length & 4) { |
1431 |
+ |
FILL_4(dest, 0, color); |
1432 |
+ |
if (bpp <= 16) |
1433 |
+ |
dest += 4; |
1434 |
+ |
} |
1435 |
+ |
|
1436 |
+ |
// 16-bit cell to fill? |
1437 |
+ |
if (bpp <= 16 && (length & 2)) { |
1438 |
+ |
FILL_2(dest, 0, color); |
1439 |
+ |
if (bpp <= 8) |
1440 |
+ |
dest += 2; |
1441 |
+ |
} |
1442 |
+ |
|
1443 |
+ |
// 8-bit cell to fill? |
1444 |
+ |
if (bpp <= 8 && (length & 1)) |
1445 |
+ |
FILL_1(dest, 0, color); |
1446 |
+ |
|
1447 |
+ |
#undef FILL_1 |
1448 |
+ |
#undef FILL_2 |
1449 |
+ |
#undef FILL_4 |
1450 |
+ |
#undef FILL_8 |
1451 |
+ |
} |
1452 |
+ |
|
1453 |
+ |
void NQD_fillrect(uint32 p) |
1454 |
+ |
{ |
1455 |
+ |
D(bug("accl_fillrect %08x\n", p)); |
1456 |
+ |
|
1457 |
+ |
// Get filling parameters |
1458 |
+ |
int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2); |
1459 |
+ |
int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0); |
1460 |
+ |
int16 width = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2); |
1461 |
+ |
int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0); |
1462 |
+ |
uint32 color = htonl(ReadMacInt32(p + acclPenMode) == 8 ? ReadMacInt32(p + acclForePen) : ReadMacInt32(p + acclBackPen)); |
1463 |
+ |
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1464 |
+ |
D(bug(" width %d, height %d\n", width, height)); |
1465 |
+ |
D(bug(" bytes_per_row %d color %08x\n", (int32)ReadMacInt32(p + acclDestRowBytes), color)); |
1466 |
+ |
|
1467 |
+ |
// And perform the fill |
1468 |
+ |
const int bpp = bytes_per_pixel(ReadMacInt32(p + acclDestPixelSize)); |
1469 |
+ |
const int dest_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes); |
1470 |
+ |
uint8 *dest = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dest_row_bytes) + (dest_X * bpp)); |
1471 |
+ |
width *= bpp; |
1472 |
+ |
switch (bpp) { |
1473 |
+ |
case 1: |
1474 |
+ |
for (int i = 0; i < height; i++) { |
1475 |
+ |
memset(dest, color, width); |
1476 |
+ |
dest += dest_row_bytes; |
1477 |
+ |
} |
1478 |
+ |
break; |
1479 |
+ |
case 2: |
1480 |
+ |
for (int i = 0; i < height; i++) { |
1481 |
+ |
do_fillrect<16>(dest, color, width); |
1482 |
+ |
dest += dest_row_bytes; |
1483 |
+ |
} |
1484 |
+ |
break; |
1485 |
+ |
case 4: |
1486 |
+ |
for (int i = 0; i < height; i++) { |
1487 |
+ |
do_fillrect<32>(dest, color, width); |
1488 |
+ |
dest += dest_row_bytes; |
1489 |
+ |
} |
1490 |
+ |
break; |
1491 |
+ |
} |
1492 |
+ |
} |
1493 |
+ |
|
1494 |
+ |
bool NQD_fillrect_hook(uint32 p) |
1495 |
+ |
{ |
1496 |
+ |
D(bug("accl_fillrect_hook %08x\n", p)); |
1497 |
+ |
|
1498 |
+ |
// Check if we can accelerate this fillrect |
1499 |
+ |
if (ReadMacInt32(p + 0x284) != 0 && ReadMacInt32(p + acclDestPixelSize) >= 8) { |
1500 |
+ |
const int transfer_mode = ReadMacInt32(p + acclTransferMode); |
1501 |
+ |
if (transfer_mode == 8) { |
1502 |
+ |
// Fill |
1503 |
+ |
WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_FILLRECT)); |
1504 |
+ |
return true; |
1505 |
+ |
} |
1506 |
+ |
else if (transfer_mode == 10) { |
1507 |
+ |
// Invert |
1508 |
+ |
WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_INVRECT)); |
1509 |
+ |
return true; |
1510 |
+ |
} |
1511 |
+ |
} |
1512 |
+ |
return false; |
1513 |
+ |
} |
1514 |
+ |
|
1515 |
+ |
// Rectangle blitting |
1516 |
+ |
// TODO: optimize for VOSF and target pixmap == screen |
1517 |
+ |
void NQD_bitblt(uint32 p) |
1518 |
+ |
{ |
1519 |
+ |
D(bug("accl_bitblt %08x\n", p)); |
1520 |
+ |
|
1521 |
+ |
// Get blitting parameters |
1522 |
+ |
int16 src_X = (int16)ReadMacInt16(p + acclSrcRect + 2) - (int16)ReadMacInt16(p + acclSrcBoundsRect + 2); |
1523 |
+ |
int16 src_Y = (int16)ReadMacInt16(p + acclSrcRect + 0) - (int16)ReadMacInt16(p + acclSrcBoundsRect + 0); |
1524 |
+ |
int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2); |
1525 |
+ |
int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0); |
1526 |
+ |
int16 width = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2); |
1527 |
+ |
int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0); |
1528 |
+ |
D(bug(" src addr %08x, dest addr %08x\n", ReadMacInt32(p + acclSrcBaseAddr), ReadMacInt32(p + acclDestBaseAddr))); |
1529 |
+ |
D(bug(" src X %d, src Y %d, dest X %d, dest Y %d\n", src_X, src_Y, dest_X, dest_Y)); |
1530 |
+ |
D(bug(" width %d, height %d\n", width, height)); |
1531 |
+ |
|
1532 |
+ |
// And perform the blit |
1533 |
+ |
const int bpp = bytes_per_pixel(ReadMacInt32(p + acclSrcPixelSize)); |
1534 |
+ |
width *= bpp; |
1535 |
+ |
if ((int32)ReadMacInt32(p + acclSrcRowBytes) > 0) { |
1536 |
+ |
const int src_row_bytes = (int32)ReadMacInt32(p + acclSrcRowBytes); |
1537 |
+ |
const int dst_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes); |
1538 |
+ |
uint8 *src = Mac2HostAddr(ReadMacInt32(p + acclSrcBaseAddr) + (src_Y * src_row_bytes) + (src_X * bpp)); |
1539 |
+ |
uint8 *dst = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dst_row_bytes) + (dest_X * bpp)); |
1540 |
+ |
for (int i = 0; i < height; i++) { |
1541 |
+ |
memmove(dst, src, width); |
1542 |
+ |
src += src_row_bytes; |
1543 |
+ |
dst += dst_row_bytes; |
1544 |
+ |
} |
1545 |
+ |
} |
1546 |
+ |
else { |
1547 |
+ |
const int src_row_bytes = -(int32)ReadMacInt32(p + acclSrcRowBytes); |
1548 |
+ |
const int dst_row_bytes = -(int32)ReadMacInt32(p + acclDestRowBytes); |
1549 |
+ |
uint8 *src = Mac2HostAddr(ReadMacInt32(p + acclSrcBaseAddr) + ((src_Y + height - 1) * src_row_bytes) + (src_X * bpp)); |
1550 |
+ |
uint8 *dst = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + ((dest_Y + height - 1) * dst_row_bytes) + (dest_X * bpp)); |
1551 |
+ |
for (int i = height - 1; i >= 0; i--) { |
1552 |
+ |
memmove(dst, src, width); |
1553 |
+ |
src -= src_row_bytes; |
1554 |
+ |
dst -= dst_row_bytes; |
1555 |
+ |
} |
1556 |
+ |
} |
1557 |
+ |
} |
1558 |
+ |
|
1559 |
+ |
/* |
1560 |
+ |
BitBlt transfer modes: |
1561 |
+ |
0 : srcCopy |
1562 |
+ |
1 : srcOr |
1563 |
+ |
2 : srcXor |
1564 |
+ |
3 : srcBic |
1565 |
+ |
4 : notSrcCopy |
1566 |
+ |
5 : notSrcOr |
1567 |
+ |
6 : notSrcXor |
1568 |
+ |
7 : notSrcBic |
1569 |
+ |
32 : blend |
1570 |
+ |
33 : addPin |
1571 |
+ |
34 : addOver |
1572 |
+ |
35 : subPin |
1573 |
+ |
36 : transparent |
1574 |
+ |
37 : adMax |
1575 |
+ |
38 : subOver |
1576 |
+ |
39 : adMin |
1577 |
+ |
50 : hilite |
1578 |
+ |
*/ |
1579 |
+ |
|
1580 |
+ |
bool NQD_bitblt_hook(uint32 p) |
1581 |
+ |
{ |
1582 |
+ |
D(bug("accl_draw_hook %08x\n", p)); |
1583 |
+ |
|
1584 |
+ |
// Check if we can accelerate this bitblt |
1585 |
+ |
if (ReadMacInt32(p + 0x018) + ReadMacInt32(p + 0x128) == 0 && |
1586 |
+ |
ReadMacInt32(p + 0x130) == 0 && |
1587 |
+ |
ReadMacInt32(p + acclSrcPixelSize) >= 8 && |
1588 |
+ |
ReadMacInt32(p + acclSrcPixelSize) == ReadMacInt32(p + acclDestPixelSize) && |
1589 |
+ |
(ReadMacInt32(p + acclSrcRowBytes) ^ ReadMacInt32(p + acclDestRowBytes)) >= 0 && // same sign? |
1590 |
+ |
ReadMacInt32(p + acclTransferMode) == 0 && // srcCopy? |
1591 |
+ |
ReadMacInt32(p + 0x15c) > 0) { |
1592 |
+ |
|
1593 |
+ |
// Yes, set function pointer |
1594 |
+ |
WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_BITBLT)); |
1595 |
+ |
return true; |
1596 |
+ |
} |
1597 |
+ |
return false; |
1598 |
+ |
} |
1599 |
+ |
|
1600 |
+ |
// Wait for graphics operation to finish |
1601 |
+ |
bool NQD_sync_hook(uint32 arg) |
1602 |
+ |
{ |
1603 |
+ |
D(bug("accl_sync_hook %08x\n", arg)); |
1604 |
+ |
return true; |
1605 |
+ |
} |
1606 |
+ |
|
1607 |
+ |
void VideoInstallAccel(void) |
1608 |
+ |
{ |
1609 |
+ |
// Install acceleration hooks |
1610 |
+ |
if (PrefsFindBool("gfxaccel")) { |
1611 |
+ |
D(bug("Video: Installing acceleration hooks\n")); |
1612 |
+ |
uint32 base; |
1613 |
+ |
|
1614 |
+ |
SheepVar bitblt_hook_info(sizeof(accl_hook_info)); |
1615 |
+ |
base = bitblt_hook_info.addr(); |
1616 |
+ |
WriteMacInt32(base + 0, NativeTVECT(NATIVE_BITBLT_HOOK)); |
1617 |
+ |
WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK)); |
1618 |
+ |
WriteMacInt32(base + 8, ACCL_BITBLT); |
1619 |
+ |
NQDMisc(6, bitblt_hook_info.ptr()); |
1620 |
+ |
|
1621 |
+ |
SheepVar fillrect_hook_info(sizeof(accl_hook_info)); |
1622 |
+ |
base = fillrect_hook_info.addr(); |
1623 |
+ |
WriteMacInt32(base + 0, NativeTVECT(NATIVE_FILLRECT_HOOK)); |
1624 |
+ |
WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK)); |
1625 |
+ |
WriteMacInt32(base + 8, ACCL_FILLRECT); |
1626 |
+ |
NQDMisc(6, fillrect_hook_info.ptr()); |
1627 |
+ |
} |
1628 |
+ |
} |
1629 |
+ |
#endif |
1630 |
+ |
|
1631 |
+ |
|
1632 |
+ |
/* |
1633 |
|
* Translate key event to Mac keycode, returns -1 if no keycode was found |
1634 |
|
* and -2 if the key was recognized as a hotkey |
1635 |
|
*/ |
1862 |
|
// Hidden parts exposed, force complete refresh of window |
1863 |
|
case SDL_VIDEOEXPOSE: |
1864 |
|
if (display_type == DISPLAY_WINDOW) { |
1865 |
< |
const video_mode &mode = VideoMonitors[0]->get_current_mode(); |
1865 |
> |
const VIDEO_MODE &mode = VideoMonitors[0]->get_current_mode(); |
1866 |
|
#ifdef ENABLE_VOSF |
1867 |
|
if (use_vosf) { // VOSF refresh |
1868 |
|
LOCK_VOSF; |
1869 |
|
PFLAG_SET_ALL; |
1870 |
|
UNLOCK_VOSF; |
1871 |
< |
memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y); |
1871 |
> |
memset(the_buffer_copy, 0, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y); |
1872 |
|
} |
1873 |
|
else |
1874 |
|
#endif |
1875 |
< |
memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y); |
1875 |
> |
memset(the_buffer_copy, 0, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y); |
1876 |
|
} |
1877 |
|
break; |
1878 |
|
|
1896 |
|
{ |
1897 |
|
// Incremental update code |
1898 |
|
int wide = 0, high = 0, x1, x2, y1, y2, i, j; |
1899 |
< |
const video_mode &mode = drv->mode; |
1900 |
< |
int bytes_per_row = mode.bytes_per_row; |
1899 |
> |
const VIDEO_MODE &mode = drv->mode; |
1900 |
> |
int bytes_per_row = VIDEO_MODE_ROW_BYTES; |
1901 |
|
uint8 *p, *p2; |
1902 |
|
|
1903 |
|
// Check for first line from top and first line from bottom that have changed |
1904 |
|
y1 = 0; |
1905 |
< |
for (j=0; j<mode.y; j++) { |
1905 |
> |
for (j=0; j<VIDEO_MODE_Y; j++) { |
1906 |
|
if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) { |
1907 |
|
y1 = j; |
1908 |
|
break; |
1909 |
|
} |
1910 |
|
} |
1911 |
|
y2 = y1 - 1; |
1912 |
< |
for (j=mode.y-1; j>=y1; j--) { |
1912 |
> |
for (j=VIDEO_MODE_Y-1; j>=y1; j--) { |
1913 |
|
if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) { |
1914 |
|
y2 = j; |
1915 |
|
break; |
1919 |
|
|
1920 |
|
// Check for first column from left and first column from right that have changed |
1921 |
|
if (high) { |
1922 |
< |
if (mode.depth < VDEPTH_8BIT) { |
1922 |
> |
if (VIDEO_MODE_DEPTH < VIDEO_DEPTH_8BIT) { |
1923 |
|
const int src_bytes_per_row = bytes_per_row; |
1924 |
|
const int dst_bytes_per_row = drv->s->pitch; |
1925 |
< |
const int pixels_per_byte = mode.x / src_bytes_per_row; |
1925 |
> |
const int pixels_per_byte = VIDEO_MODE_X / src_bytes_per_row; |
1926 |
|
|
1927 |
< |
x1 = mode.x / pixels_per_byte; |
1927 |
> |
x1 = VIDEO_MODE_X / pixels_per_byte; |
1928 |
|
for (j = y1; j <= y2; j++) { |
1929 |
|
p = &the_buffer[j * bytes_per_row]; |
1930 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1942 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1943 |
|
p += bytes_per_row; |
1944 |
|
p2 += bytes_per_row; |
1945 |
< |
for (i = (mode.x / pixels_per_byte); i > x2; i--) { |
1945 |
> |
for (i = (VIDEO_MODE_X / pixels_per_byte); i > x2; i--) { |
1946 |
|
p--; p2--; |
1947 |
|
if (*p != *p2) { |
1948 |
|
x2 = i; |
1980 |
|
} |
1981 |
|
|
1982 |
|
} else { |
1983 |
< |
const int bytes_per_pixel = mode.bytes_per_row / mode.x; |
1983 |
> |
const int bytes_per_pixel = VIDEO_MODE_ROW_BYTES / VIDEO_MODE_X; |
1984 |
|
|
1985 |
< |
x1 = mode.x; |
1985 |
> |
x1 = VIDEO_MODE_X; |
1986 |
|
for (j=y1; j<=y2; j++) { |
1987 |
|
p = &the_buffer[j * bytes_per_row]; |
1988 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
2000 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
2001 |
|
p += bytes_per_row; |
2002 |
|
p2 += bytes_per_row; |
2003 |
< |
for (i=mode.x*bytes_per_pixel; i>x2*bytes_per_pixel; i--) { |
2003 |
> |
for (i=VIDEO_MODE_X*bytes_per_pixel; i>x2*bytes_per_pixel; i--) { |
2004 |
|
p--; |
2005 |
|
p2--; |
2006 |
|
if (*p != *p2) { |
2160 |
|
} |
2161 |
|
} |
2162 |
|
|
2163 |
+ |
const int VIDEO_REFRESH_HZ = 60; |
2164 |
+ |
const int VIDEO_REFRESH_DELAY = 1000000 / VIDEO_REFRESH_HZ; |
2165 |
+ |
|
2166 |
|
static int redraw_func(void *arg) |
2167 |
|
{ |
2168 |
|
uint64 start = GetTicks_usec(); |
2169 |
|
int64 ticks = 0; |
2170 |
+ |
uint64 next = GetTicks_usec() + VIDEO_REFRESH_DELAY; |
2171 |
|
|
2172 |
|
while (!redraw_thread_cancel) { |
2173 |
|
|
2174 |
|
// Wait |
2175 |
< |
Delay_usec(16667); |
2175 |
> |
next += VIDEO_REFRESH_DELAY; |
2176 |
> |
int64 delay = next - GetTicks_usec(); |
2177 |
> |
if (delay > 0) |
2178 |
> |
Delay_usec(delay); |
2179 |
> |
else if (delay < -VIDEO_REFRESH_DELAY) |
2180 |
> |
next = GetTicks_usec(); |
2181 |
> |
ticks++; |
2182 |
|
|
2183 |
|
// Handle SDL events |
2184 |
|
handle_events(); |
2185 |
|
|
2186 |
|
// Refresh display |
2187 |
|
video_refresh(); |
2188 |
< |
ticks++; |
2188 |
> |
|
2189 |
> |
#ifdef SHEEPSHAVER |
2190 |
> |
// Set new cursor image if it was changed |
2191 |
> |
if (cursor_changed && sdl_cursor) { |
2192 |
> |
cursor_changed = false; |
2193 |
> |
SDL_FreeCursor(sdl_cursor); |
2194 |
> |
sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, MacCursor[2], MacCursor[3]); |
2195 |
> |
if (sdl_cursor) |
2196 |
> |
SDL_SetCursor(sdl_cursor); |
2197 |
> |
} |
2198 |
> |
#endif |
2199 |
|
|
2200 |
|
// Set new palette if it was changed |
2201 |
|
handle_palette_changes(); |
2203 |
|
|
2204 |
|
uint64 end = GetTicks_usec(); |
2205 |
|
D(bug("%lld refreshes in %lld usec = %f refreshes/sec\n", ticks, end - start, ticks * 1000000.0 / (end - start))); |
1440 |
– |
redraw_thread_cancel = false; |
2206 |
|
return 0; |
2207 |
|
} |