66 |
|
#define DEBUG 0 |
67 |
|
#include "debug.h" |
68 |
|
|
69 |
+ |
#if (defined(__APPLE__) && defined(__MACH__)) |
70 |
+ |
extern "C" { |
71 |
+ |
void NSAutoReleasePool_wrap(void (*fn)(void)); |
72 |
+ |
} |
73 |
+ |
#endif |
74 |
|
|
75 |
|
// Supported video modes |
76 |
|
using std::vector; |
141 |
|
static volatile bool cursor_changed = false; // Flag: cursor changed, redraw_func must update the cursor |
142 |
|
static SDL_Color sdl_palette[256]; // Color palette to be used as CLUT and gamma table |
143 |
|
static bool sdl_palette_changed = false; // Flag: Palette changed, redraw thread must set new colors |
144 |
< |
static const int sdl_eventmask = SDL_MOUSEBUTTONDOWNMASK | SDL_MOUSEBUTTONUPMASK | SDL_MOUSEMOTIONMASK | SDL_KEYUPMASK | SDL_KEYDOWNMASK | SDL_VIDEOEXPOSEMASK | SDL_QUITMASK; |
144 |
> |
static const int sdl_eventmask = SDL_MOUSEEVENTMASK | SDL_KEYEVENTMASK | SDL_VIDEOEXPOSEMASK | SDL_QUITMASK | SDL_ACTIVEEVENTMASK; |
145 |
|
|
146 |
|
// Mutex to protect SDL events |
147 |
|
static SDL_mutex *sdl_events_lock = NULL; |
630 |
|
class driver_window; |
631 |
|
static void update_display_window_vosf(driver_window *drv); |
632 |
|
static void update_display_dynamic(int ticker, driver_window *drv); |
633 |
< |
static void update_display_static(driver_window *drv); |
633 |
> |
static void update_display_static(driver_base *drv); |
634 |
|
|
635 |
|
class driver_window : public driver_base { |
636 |
|
friend void update_display_window_vosf(driver_window *drv); |
637 |
|
friend void update_display_dynamic(int ticker, driver_window *drv); |
638 |
< |
friend void update_display_static(driver_window *drv); |
638 |
> |
friend void update_display_static(driver_base *drv); |
639 |
|
|
640 |
|
public: |
641 |
|
driver_window(SDL_monitor_desc &monitor); |
1243 |
|
continue; |
1244 |
|
if (w == 512 && h == 384) |
1245 |
|
continue; |
1241 |
– |
#ifdef ENABLE_VOSF |
1246 |
|
for (int d = VIDEO_DEPTH_1BIT; d <= default_depth; d++) |
1247 |
|
add_mode(display_type, w, h, video_modes[i].resolution_id, TrivialBytesPerRow(w, (video_depth)d), d); |
1244 |
– |
#else |
1245 |
– |
add_mode(display_type, w, h, video_modes[i].resolution_id, TrivialBytesPerRow(w, (video_depth)default_depth), default_depth); |
1246 |
– |
#endif |
1248 |
|
} |
1249 |
|
} |
1250 |
|
|
1544 |
|
#ifdef SHEEPSHAVER |
1545 |
|
bool video_can_change_cursor(void) |
1546 |
|
{ |
1547 |
< |
return (display_type == DISPLAY_WINDOW); |
1547 |
> |
static char driver[] = "Quartz?"; |
1548 |
> |
static int quartzok = -1; |
1549 |
> |
|
1550 |
> |
if (display_type != DISPLAY_WINDOW) |
1551 |
> |
return false; |
1552 |
> |
|
1553 |
> |
if (quartzok < 0) { |
1554 |
> |
if (SDL_VideoDriverName(driver, sizeof driver) == NULL || strncmp(driver, "Quartz", sizeof driver)) |
1555 |
> |
quartzok = true; |
1556 |
> |
else { |
1557 |
> |
// Quartz driver bug prevents cursor changing in SDL 1.2.11 and later |
1558 |
> |
const SDL_version *vp = SDL_Linked_Version(); |
1559 |
> |
quartzok = SDL_VERSIONNUM(vp->major, vp->minor, vp->patch) <= SDL_VERSIONNUM(1, 2, 10); |
1560 |
> |
} |
1561 |
> |
} |
1562 |
> |
|
1563 |
> |
return quartzok; |
1564 |
|
} |
1565 |
|
#endif |
1566 |
|
|
1771 |
|
// Mouse button |
1772 |
|
case SDL_MOUSEBUTTONDOWN: { |
1773 |
|
unsigned int button = event.button.button; |
1774 |
< |
if (button < 4) |
1775 |
< |
ADBMouseDown(button - 1); |
1774 |
> |
if (button == SDL_BUTTON_LEFT) |
1775 |
> |
ADBMouseDown(0); |
1776 |
> |
else if (button == SDL_BUTTON_RIGHT) |
1777 |
> |
ADBMouseDown(1); |
1778 |
> |
else if (button == SDL_BUTTON_MIDDLE) |
1779 |
> |
ADBMouseDown(2); |
1780 |
|
else if (button < 6) { // Wheel mouse |
1781 |
|
if (mouse_wheel_mode == 0) { |
1782 |
|
int key = (button == 5) ? 0x79 : 0x74; // Page up/down |
1794 |
|
} |
1795 |
|
case SDL_MOUSEBUTTONUP: { |
1796 |
|
unsigned int button = event.button.button; |
1797 |
< |
if (button < 4) |
1798 |
< |
ADBMouseUp(button - 1); |
1797 |
> |
if (button == SDL_BUTTON_LEFT) |
1798 |
> |
ADBMouseUp(0); |
1799 |
> |
else if (button == SDL_BUTTON_RIGHT) |
1800 |
> |
ADBMouseUp(1); |
1801 |
> |
else if (button == SDL_BUTTON_MIDDLE) |
1802 |
> |
ADBMouseUp(2); |
1803 |
|
break; |
1804 |
|
} |
1805 |
|
|
1883 |
|
ADBKeyDown(0x7f); // Power key |
1884 |
|
ADBKeyUp(0x7f); |
1885 |
|
break; |
1886 |
+ |
|
1887 |
+ |
// Application activate/deactivate; consume the event but otherwise ignore it |
1888 |
+ |
case SDL_ACTIVEEVENT: |
1889 |
+ |
break; |
1890 |
|
} |
1891 |
|
} |
1892 |
|
} |
1898 |
|
*/ |
1899 |
|
|
1900 |
|
// Static display update (fixed frame rate, but incremental) |
1901 |
< |
static void update_display_static(driver_window *drv) |
1901 |
> |
static void update_display_static(driver_base *drv) |
1902 |
|
{ |
1903 |
|
// Incremental update code |
1904 |
|
int wide = 0, high = 0, x1, x2, y1, y2, i, j; |
1987 |
|
|
1988 |
|
} else { |
1989 |
|
const int bytes_per_pixel = VIDEO_MODE_ROW_BYTES / VIDEO_MODE_X; |
1990 |
+ |
const int dst_bytes_per_row = drv->s->pitch; |
1991 |
|
|
1992 |
|
x1 = VIDEO_MODE_X; |
1993 |
|
for (j=y1; j<=y2; j++) { |
2028 |
|
// Blit to screen surface |
2029 |
|
for (j=y1; j<=y2; j++) { |
2030 |
|
i = j * bytes_per_row + x1 * bytes_per_pixel; |
2031 |
+ |
int dst_i = j * dst_bytes_per_row + x1 * bytes_per_pixel; |
2032 |
|
memcpy(the_buffer_copy + i, the_buffer + i, bytes_per_pixel * wide); |
2033 |
< |
Screen_blit((uint8 *)drv->s->pixels + i, the_buffer + i, bytes_per_pixel * wide); |
2033 |
> |
Screen_blit((uint8 *)drv->s->pixels + dst_i, the_buffer + i, bytes_per_pixel * wide); |
2034 |
|
} |
2035 |
|
|
2036 |
|
// Unlock surface, if required |
2046 |
|
|
2047 |
|
// Static display update (fixed frame rate, bounding boxes based) |
2048 |
|
// XXX use NQD bounding boxes to help detect dirty areas? |
2049 |
< |
static void update_display_static_bbox(driver_window *drv) |
2049 |
> |
static void update_display_static_bbox(driver_base *drv) |
2050 |
|
{ |
2051 |
|
const VIDEO_MODE &mode = drv->mode; |
2052 |
|
|
2064 |
|
// Update the surface from Mac screen |
2065 |
|
const int bytes_per_row = VIDEO_MODE_ROW_BYTES; |
2066 |
|
const int bytes_per_pixel = bytes_per_row / VIDEO_MODE_X; |
2067 |
+ |
const int dst_bytes_per_row = drv->s->pitch; |
2068 |
|
int x, y; |
2069 |
|
for (y = 0; y < VIDEO_MODE_Y; y += N_PIXELS) { |
2070 |
|
int h = N_PIXELS; |
2079 |
|
bool dirty = false; |
2080 |
|
for (int j = y; j < (y + h); j++) { |
2081 |
|
const int yb = j * bytes_per_row; |
2082 |
+ |
const int dst_yb = j * dst_bytes_per_row; |
2083 |
|
if (memcmp(&the_buffer[yb + xb], &the_buffer_copy[yb + xb], xs) != 0) { |
2084 |
|
memcpy(&the_buffer_copy[yb + xb], &the_buffer[yb + xb], xs); |
2085 |
< |
Screen_blit((uint8 *)drv->s->pixels + yb + xb, the_buffer + yb + xb, xs); |
2085 |
> |
Screen_blit((uint8 *)drv->s->pixels + dst_yb + xb, the_buffer + yb + xb, xs); |
2086 |
|
dirty = true; |
2087 |
|
} |
2088 |
|
} |
2146 |
|
UNLOCK_PALETTE; |
2147 |
|
} |
2148 |
|
|
2149 |
+ |
static void video_refresh_window_static(void); |
2150 |
+ |
|
2151 |
|
static void video_refresh_dga(void) |
2152 |
|
{ |
2153 |
|
// Quit DGA mode if requested |
2154 |
|
possibly_quit_dga_mode(); |
2155 |
+ |
video_refresh_window_static(); |
2156 |
|
} |
2157 |
|
|
2158 |
|
#ifdef ENABLE_VOSF |
2204 |
|
tick_counter = 0; |
2205 |
|
const VIDEO_MODE &mode = drv->mode; |
2206 |
|
if ((int)VIDEO_MODE_DEPTH >= VIDEO_DEPTH_8BIT) |
2207 |
< |
update_display_static_bbox(static_cast<driver_window *>(drv)); |
2207 |
> |
update_display_static_bbox(drv); |
2208 |
|
else |
2209 |
< |
update_display_static(static_cast<driver_window *>(drv)); |
2209 |
> |
update_display_static(drv); |
2210 |
|
} |
2211 |
|
} |
2212 |
|
|
2242 |
|
handle_events(); |
2243 |
|
|
2244 |
|
// Update display |
2245 |
+ |
#if (defined(__APPLE__) && defined(__MACH__)) |
2246 |
+ |
// SDL expects an auto-release pool to be present. |
2247 |
+ |
NSAutoReleasePool_wrap(video_refresh); |
2248 |
+ |
#else |
2249 |
|
video_refresh(); |
2250 |
+ |
#endif |
2251 |
|
|
2252 |
|
#ifdef SHEEPSHAVER |
2253 |
|
// Set new cursor image if it was changed |
2257 |
|
SDL_FreeCursor(sdl_cursor); |
2258 |
|
sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, MacCursor[2], MacCursor[3]); |
2259 |
|
if (sdl_cursor) { |
2260 |
+ |
SDL_ShowCursor(private_data == NULL || private_data->cursorVisible); |
2261 |
|
SDL_SetCursor(sdl_cursor); |
2262 |
|
#ifdef WIN32 |
2263 |
|
// XXX Windows apparently needs an extra mouse event to |
2337 |
|
#ifdef SHEEPSHAVER |
2338 |
|
void video_set_dirty_area(int x, int y, int w, int h) |
2339 |
|
{ |
2340 |
+ |
#ifdef ENABLE_VOSF |
2341 |
|
const VIDEO_MODE &mode = drv->mode; |
2342 |
|
const int screen_width = VIDEO_MODE_X; |
2343 |
|
const int screen_height = VIDEO_MODE_Y; |
2344 |
|
const int bytes_per_row = VIDEO_MODE_ROW_BYTES; |
2345 |
|
|
2303 |
– |
#ifdef ENABLE_VOSF |
2346 |
|
if (use_vosf) { |
2347 |
|
vosf_set_dirty_area(x, y, w, h, screen_width, screen_height, bytes_per_row); |
2348 |
|
return; |