--- BasiliskII/src/SDL/video_sdl.cpp 2007/01/22 00:32:25 1.31 +++ BasiliskII/src/SDL/video_sdl.cpp 2008/07/20 07:33:09 1.37 @@ -1,7 +1,7 @@ /* * video_sdl.cpp - Video/graphics emulation, SDL specific stuff * - * Basilisk II (C) 1997-2005 Christian Bauer + * Basilisk II (C) 1997-2008 Christian Bauer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -136,7 +136,7 @@ static SDL_Cursor *sdl_cursor; // C static volatile bool cursor_changed = false; // Flag: cursor changed, redraw_func must update the cursor static SDL_Color sdl_palette[256]; // Color palette to be used as CLUT and gamma table static bool sdl_palette_changed = false; // Flag: Palette changed, redraw thread must set new colors -static const int sdl_eventmask = SDL_MOUSEBUTTONDOWNMASK | SDL_MOUSEBUTTONUPMASK | SDL_MOUSEMOTIONMASK | SDL_KEYUPMASK | SDL_KEYDOWNMASK | SDL_VIDEOEXPOSEMASK | SDL_QUITMASK; +static const int sdl_eventmask = SDL_MOUSEEVENTMASK | SDL_KEYEVENTMASK | SDL_VIDEOEXPOSEMASK | SDL_QUITMASK | SDL_ACTIVEEVENTMASK; // Mutex to protect SDL events static SDL_mutex *sdl_events_lock = NULL; @@ -197,7 +197,19 @@ extern void SysMountFirstFloppy(void); static void *vm_acquire_framebuffer(uint32 size) { - return vm_acquire(size); + // always try to reallocate framebuffer at the same address + static void *fb = VM_MAP_FAILED; + if (fb != VM_MAP_FAILED) { + if (vm_acquire_fixed(fb, size) < 0) { +#ifndef SHEEPSHAVER + printf("FATAL: Could not reallocate framebuffer at previous address\n"); +#endif + fb = VM_MAP_FAILED; + } + } + if (fb == VM_MAP_FAILED) + fb = vm_acquire(size, VM_MAP_DEFAULT | VM_MAP_32BIT); + return fb; } static inline void vm_release_framebuffer(void *fb, uint32 size) @@ -719,7 +731,7 @@ void driver_base::restore_mouse_accel(vo * Windowed display driver */ -static int SDL_display_opened = FALSE; +static bool SDL_display_opened = false; // Open display driver_window::driver_window(SDL_monitor_desc &m) @@ -735,20 +747,19 @@ driver_window::driver_window(SDL_monitor // This is ugly: // If we're switching resolutions (ie, not setting it for the first time), // there's a bug in SDL where the SDL_Surface created will not be properly - // setup. The solution is to SDL_Quit() before calling SDL_SetVideoMode for - // the second time (SDL_SetVideoMode will call SDL_Init() and all will be - // well). Without this, the video becomes corrupted (at least on Mac OS X), - // after the resolution switch (for the second and subsequent times). -// EDIT: Ack, this breaks audio! -// if (SDL_display_opened) -// SDL_Quit(); + // setup. The solution is to SDL_QuitSubSystem(SDL_INIT_VIDEO) before calling + // SDL_SetVideoMode for the second time (SDL_SetVideoMode will call SDL_Init() + // and all will be well). Without this, the video becomes corrupted (at least + // on Mac OS X), after the resolution switch. + if (SDL_display_opened) + SDL_QuitSubSystem(SDL_INIT_VIDEO); // Create surface int depth = sdl_depth_of_video_depth(VIDEO_MODE_DEPTH); if ((s = SDL_SetVideoMode(width, height, depth, SDL_HWSURFACE)) == NULL) return; - SDL_display_opened = TRUE; + SDL_display_opened = true; #ifdef ENABLE_VOSF use_vosf = true; @@ -1532,7 +1543,23 @@ void SDL_monitor_desc::switch_to_current #ifdef SHEEPSHAVER bool video_can_change_cursor(void) { - return (display_type == DISPLAY_WINDOW); + static char driver[] = "Quartz?"; + static int quartzok = -1; + + if (display_type != DISPLAY_WINDOW) + return false; + + if (quartzok < 0) { + if (SDL_VideoDriverName(driver, sizeof driver) == NULL || strncmp(driver, "Quartz", sizeof driver)) + quartzok = true; + else { + // Quartz driver bug prevents cursor changing in SDL 1.2.11 and later + const SDL_version *vp = SDL_Linked_Version(); + quartzok = SDL_VERSIONNUM(vp->major, vp->minor, vp->patch) <= SDL_VERSIONNUM(1, 2, 10); + } + } + + return quartzok; } #endif @@ -1743,8 +1770,12 @@ static void handle_events(void) // Mouse button case SDL_MOUSEBUTTONDOWN: { unsigned int button = event.button.button; - if (button < 4) - ADBMouseDown(button - 1); + if (button == SDL_BUTTON_LEFT) + ADBMouseDown(0); + else if (button == SDL_BUTTON_RIGHT) + ADBMouseDown(1); + else if (button == SDL_BUTTON_MIDDLE) + ADBMouseDown(2); else if (button < 6) { // Wheel mouse if (mouse_wheel_mode == 0) { int key = (button == 5) ? 0x79 : 0x74; // Page up/down @@ -1762,8 +1793,12 @@ static void handle_events(void) } case SDL_MOUSEBUTTONUP: { unsigned int button = event.button.button; - if (button < 4) - ADBMouseUp(button - 1); + if (button == SDL_BUTTON_LEFT) + ADBMouseUp(0); + else if (button == SDL_BUTTON_RIGHT) + ADBMouseUp(1); + else if (button == SDL_BUTTON_MIDDLE) + ADBMouseUp(2); break; } @@ -1847,6 +1882,10 @@ static void handle_events(void) ADBKeyDown(0x7f); // Power key ADBKeyUp(0x7f); break; + + // Application activate/deactivate; consume the event but otherwise ignore it + case SDL_ACTIVEEVENT: + break; } } } @@ -2205,6 +2244,7 @@ static inline void do_video_refresh(void SDL_FreeCursor(sdl_cursor); sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, MacCursor[2], MacCursor[3]); if (sdl_cursor) { + SDL_ShowCursor(private_data == NULL || private_data->cursorVisible); SDL_SetCursor(sdl_cursor); #ifdef WIN32 // XXX Windows apparently needs an extra mouse event to