ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/SDL/video_sdl.cpp
(Generate patch)

Comparing BasiliskII/src/SDL/video_sdl.cpp (file contents):
Revision 1.5 by gbeauche, 2004-06-24T21:46:55Z vs.
Revision 1.19 by gbeauche, 2005-06-06T21:20:28Z

# Line 1 | Line 1
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
# Line 21 | Line 21
21   /*
22   *  NOTES:
23   *    The Ctrl key works like a qualifier for special actions:
24 < *      Ctrl-Tab = suspend DGA mode
24 > *      Ctrl-Tab = suspend DGA mode (TODO)
25   *      Ctrl-Esc = emergency quit
26   *      Ctrl-F1 = mount floppy
27   *      Ctrl-F5 = grab mouse (in windowed mode)
28   *
29   *  FIXMEs and TODOs:
30 + *  - Ctr-Tab for suspend/resume but how? SDL does not support that for non-Linux
31   *  - Ctrl-Fn doesn't generate SDL_KEYDOWN events (SDL bug?)
32   *  - Mouse acceleration, there is no API in SDL yet for that
33   *  - Force relative mode in Grab mode even if SDL provides absolute coordinates?
# Line 35 | Line 36
36   *  - Events processing is bound to the general emulation thread as SDL requires
37   *    to PumpEvents() within the same thread as the one that called SetVideoMode().
38   *    Besides, there can't seem to be a way to call SetVideoMode() from a child thread.
39 + *  - Refresh performance is still slow. Use SDL_CreateRGBSurface()?
40 + *  - Backport hw cursor acceleration to Basilisk II?
41 + *  - Factor out code
42   */
43  
44   #include "sysdeps.h"
# Line 54 | Line 58
58   #include "video.h"
59   #include "video_defs.h"
60   #include "video_blit.h"
61 + #include "vm_alloc.h"
62  
63   #define DEBUG 0
64   #include "debug.h"
# Line 79 | Line 84 | static int display_type = DISPLAY_WINDOW
84   #endif
85  
86   // Constants
87 + #ifdef WIN32
88 + const char KEYCODE_FILE_NAME[] = "BasiliskII_keycodes";
89 + #else
90   const char KEYCODE_FILE_NAME[] = DATADIR "/keycodes";
91 + #endif
92  
93  
94   // Global variables
# Line 94 | Line 103 | static uint32 the_buffer_size;                                         // S
103   static bool redraw_thread_active = false;                       // Flag: Redraw thread installed
104   static volatile bool redraw_thread_cancel;                      // Flag: Cancel Redraw thread
105   static SDL_Thread *redraw_thread = NULL;                        // Redraw thread
106 + static volatile bool thread_stop_req = false;
107 + static volatile bool thread_stop_ack = false;           // Acknowledge for thread_stop_req
108  
109   #ifdef ENABLE_VOSF
110 < static bool use_vosf = true;                                            // Flag: VOSF enabled
110 > static bool use_vosf = false;                                           // Flag: VOSF enabled
111   #else
112   static const bool use_vosf = false;                                     // VOSF not possible
113   #endif
# Line 114 | Line 125 | static int keycode_table[256];                                         // X
125  
126   // SDL variables
127   static int screen_depth;                                                        // Depth of current screen
128 + static SDL_Cursor *sdl_cursor;                                          // Copy of Mac cursor
129 + static volatile bool cursor_changed = false;            // Flag: cursor changed, redraw_func must update the cursor
130   static SDL_Color sdl_palette[256];                                      // Color palette to be used as CLUT and gamma table
131   static bool sdl_palette_changed = false;                        // Flag: Palette changed, redraw thread must set new colors
132   static const int sdl_eventmask = SDL_MOUSEBUTTONDOWNMASK | SDL_MOUSEBUTTONUPMASK | SDL_MOUSEMOTIONMASK | SDL_KEYUPMASK | SDL_KEYDOWNMASK | SDL_VIDEOEXPOSEMASK | SDL_QUITMASK;
# Line 141 | Line 154 | extern void SysMountFirstFloppy(void);
154  
155  
156   /*
157 + *  Framebuffer allocation routines
158 + */
159 +
160 + static void *vm_acquire_framebuffer(uint32 size)
161 + {
162 + #ifdef SHEEPSHAVER
163 + #ifdef DIRECT_ADDRESSING_HACK
164 +        const uint32 FRAME_BUFFER_BASE = 0x61000000;
165 +        uint8 *fb = Mac2HostAddr(FRAME_BUFFER_BASE);
166 +        if (vm_acquire_fixed(fb, size) < 0)
167 +                fb = VM_MAP_FAILED;
168 +        return fb;
169 + #endif
170 + #endif
171 +        return vm_acquire(size);
172 + }
173 +
174 + static inline void vm_release_framebuffer(void *fb, uint32 size)
175 + {
176 +        vm_release(fb, size);
177 + }
178 +
179 +
180 + /*
181   *  SheepShaver glue
182   */
183  
# Line 255 | Line 292 | static void ErrorAlert(int error)
292   {
293          ErrorAlert(GetString(error));
294   }
295 +
296 + // Display warning alert
297 + static void WarningAlert(int warning)
298 + {
299 +        WarningAlert(GetString(warning));
300 + }
301   #endif
302  
303  
# Line 314 | Line 357 | static inline int bytes_per_pixel(int de
357   }
358  
359   // Map video_mode depth ID to numerical depth value
360 < static int sdl_depth_of_video_depth(int video_depth)
360 > static int mac_depth_of_video_depth(int video_depth)
361   {
362          int depth = -1;
363          switch (video_depth) {
# Line 342 | Line 385 | static int sdl_depth_of_video_depth(int
385          return depth;
386   }
387  
388 + // Map video_mode depth ID to SDL screen depth
389 + static int sdl_depth_of_video_depth(int video_depth)
390 + {
391 +        return (video_depth <= VIDEO_DEPTH_8BIT) ? 8 : mac_depth_of_video_depth(video_depth);
392 + }
393 +
394   // Check wether specified mode is available
395   static bool has_mode(int type, int width, int height)
396   {
348        // FIXME: no fullscreen support yet
349        if (type == DISPLAY_SCREEN)
350                return false;
351
397   #ifdef SHEEPSHAVER
398          // Filter out Classic resolutiosn
399          if (width == 512 && height == 384)
400                  return false;
401  
402 <        // Read window modes prefs
402 >        // "screen" prefs items always succeeds
403 >        if (PrefsFindString("screen"))
404 >                return true;
405 >
406 >        // Read window & screen modes prefs
407          static uint32 window_modes = 0;
408          static uint32 screen_modes = 0;
409          if (window_modes == 0 || screen_modes == 0) {
# Line 364 | Line 413 | static bool has_mode(int type, int width
413                          window_modes |= 3;                      // Allow at least 640x480 and 800x600 window modes
414          }
415  
416 <        if (type == DISPLAY_WINDOW) {
417 <                int apple_mask, apple_id = find_apple_resolution(width, height);
418 <                switch (apple_id) {
419 <                case APPLE_640x480:             apple_mask = 0x01; break;
420 <                case APPLE_800x600:             apple_mask = 0x02; break;
421 <                case APPLE_1024x768:    apple_mask = 0x04; break;
422 <                case APPLE_1152x768:    apple_mask = 0x40; break;
423 <                case APPLE_1152x900:    apple_mask = 0x08; break;
424 <                case APPLE_1280x1024:   apple_mask = 0x10; break;
425 <                case APPLE_1600x1200:   apple_mask = 0x20; break;
426 <                default:                                apple_mask = 0x00; break;
378 <                }
379 <                return (window_modes & apple_mask);
416 >        int test_modes;
417 >        switch (type) {
418 >        case DISPLAY_WINDOW:
419 >                test_modes = window_modes;
420 >                break;
421 >        case DISPLAY_SCREEN:
422 >                test_modes = screen_modes;
423 >                break;
424 >        default:
425 >                test_modes = 0;
426 >                break;
427          }
428 < #else
429 <        return true;
428 >
429 >        int apple_mask;
430 >        switch (find_apple_resolution(width, height)) {
431 >        case APPLE_640x480:             apple_mask = 0x01; break;
432 >        case APPLE_800x600:             apple_mask = 0x02; break;
433 >        case APPLE_1024x768:    apple_mask = 0x04; break;
434 >        case APPLE_1152x768:    apple_mask = 0x40; break;
435 >        case APPLE_1152x900:    apple_mask = 0x08; break;
436 >        case APPLE_1280x1024:   apple_mask = 0x10; break;
437 >        case APPLE_1600x1200:   apple_mask = 0x20; break;
438 >        default:                                apple_mask = 0x00; break;
439 >        }
440 >        return (test_modes & apple_mask);
441   #endif
442 <        return false;
442 >        return true;
443   }
444  
445   // Add mode to list of supported modes
# Line 402 | Line 460 | static void add_mode(int type, int width
460          VIDEO_MODE_Y = height;
461          VIDEO_MODE_RESOLUTION = resolution_id;
462          VIDEO_MODE_ROW_BYTES = bytes_per_row;
463 <        VIDEO_MODE_DEPTH = depth;
463 >        VIDEO_MODE_DEPTH = (video_depth)depth;
464          VideoModes.push_back(mode);
465   }
466  
# Line 458 | Line 516 | static void set_window_name(int name)
516   // Set mouse grab mode
517   static SDL_GrabMode set_grab_mode(SDL_GrabMode mode)
518   {
519 <        const SDL_VideoInfo *vi =SDL_GetVideoInfo();
519 >        const SDL_VideoInfo *vi = SDL_GetVideoInfo();
520          return (vi && vi->wm_available ? SDL_WM_GrabInput(mode) : SDL_GRAB_OFF);
521   }
522  
# Line 517 | Line 575 | private:
575          int mouse_last_x, mouse_last_y; // Last mouse position (for relative mode)
576   };
577  
578 + class driver_fullscreen : public driver_base {
579 + public:
580 +        driver_fullscreen(SDL_monitor_desc &monitor);
581 +        ~driver_fullscreen();
582 + };
583 +
584   static driver_base *drv = NULL; // Pointer to currently used driver object
585  
586   #ifdef ENABLE_VOSF
# Line 538 | Line 602 | driver_base::~driver_base()
602          if (s)
603                  SDL_FreeSurface(s);
604  
605 +        // the_buffer shall always be mapped through vm_acquire_framebuffer()
606 +        if (the_buffer != VM_MAP_FAILED) {
607 +                D(bug(" releasing the_buffer at %p (%d bytes)\n", the_buffer, the_buffer_size));
608 +                vm_release_framebuffer(the_buffer, the_buffer_size);
609 +                the_buffer = NULL;
610 +        }
611 +
612          // Free frame buffer(s)
613          if (!use_vosf) {
543                if (the_buffer) {
544                        free(the_buffer);
545                        the_buffer = NULL;
546                }
614                  if (the_buffer_copy) {
615                          free(the_buffer_copy);
616                          the_buffer_copy = NULL;
# Line 551 | Line 618 | driver_base::~driver_base()
618          }
619   #ifdef ENABLE_VOSF
620          else {
554                // the_buffer shall always be mapped through vm_acquire() so that we can vm_protect() it at will
555                if (the_buffer != VM_MAP_FAILED) {
556                        D(bug(" releasing the_buffer at %p (%d bytes)\n", the_buffer, the_buffer_size));
557                        vm_release(the_buffer, the_buffer_size);
558                        the_buffer = NULL;
559                }
621                  if (the_host_buffer) {
622                          D(bug(" freeing the_host_buffer at %p\n", the_host_buffer));
623                          free(the_host_buffer);
# Line 567 | Line 628 | driver_base::~driver_base()
628                          free(the_buffer_copy);
629                          the_buffer_copy = NULL;
630                  }
631 +
632 +                // Deinitialize VOSF
633 +                video_vosf_exit();
634          }
635   #endif
636   }
# Line 576 | Line 640 | void driver_base::update_palette(void)
640   {
641          const VIDEO_MODE &mode = monitor.get_current_mode();
642  
643 <        if (VIDEO_MODE_DEPTH <= VIDEO_DEPTH_8BIT)
643 >        if ((int)VIDEO_MODE_DEPTH <= VIDEO_DEPTH_8BIT)
644                  SDL_SetPalette(s, SDL_PHYSPAL, sdl_palette, 0, 256);
645   }
646  
# Line 607 | Line 671 | driver_window::driver_window(SDL_monitor
671          ADBSetRelMouseMode(mouse_grabbed);
672  
673          // Create surface
674 <        int depth = (VIDEO_MODE_DEPTH <= VIDEO_DEPTH_8BIT ? 8 : screen_depth);
674 >        int depth = sdl_depth_of_video_depth(VIDEO_MODE_DEPTH);
675          if ((s = SDL_SetVideoMode(width, height, depth, SDL_HWSURFACE)) == NULL)
676                  return;
677  
# Line 616 | Line 680 | driver_window::driver_window(SDL_monitor
680          // Allocate memory for frame buffer (SIZE is extended to page-boundary)
681          the_host_buffer = (uint8 *)s->pixels;
682          the_buffer_size = page_extend((aligned_height + 2) * s->pitch);
683 <        the_buffer = (uint8 *)vm_acquire(the_buffer_size);
683 >        the_buffer = (uint8 *)vm_acquire_framebuffer(the_buffer_size);
684          the_buffer_copy = (uint8 *)malloc(the_buffer_size);
685          D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer));
686 +
687 +        // Check whether we can initialize the VOSF subsystem and it's profitable
688 +        if (!video_vosf_init(m)) {
689 +                WarningAlert(STR_VOSF_INIT_ERR);
690 +                use_vosf = false;
691 +        }
692 +        else if (!video_vosf_profitable()) {
693 +                video_vosf_exit();
694 +                printf("VOSF acceleration is not profitable on this platform, disabling it\n");
695 +                use_vosf = false;
696 +        }
697 +        if (!use_vosf) {
698 +                free(the_buffer_copy);
699 +                vm_release(the_buffer, the_buffer_size);
700 +                the_host_buffer = NULL;
701 +        }
702 + #endif
703 +        if (!use_vosf) {
704 +                // Allocate memory for frame buffer
705 +                the_buffer_size = (aligned_height + 2) * s->pitch;
706 +                the_buffer_copy = (uint8 *)calloc(1, the_buffer_size);
707 +                the_buffer = (uint8 *)vm_acquire_framebuffer(the_buffer_size);
708 +                D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy));
709 +        }
710 +        
711 + #ifdef SHEEPSHAVER
712 +        // Create cursor
713 +        if ((sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, 0, 0)) != NULL) {
714 +                SDL_SetCursor(sdl_cursor);
715 +                cursor_changed = false;
716 +        }
717   #else
718 <        // Allocate memory for frame buffer
719 <        the_buffer_size = (aligned_height + 2) * s->pitch;
625 <        the_buffer_copy = (uint8 *)calloc(1, the_buffer_size);
626 <        the_buffer = (uint8 *)calloc(1, the_buffer_size);
627 <        D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy));
718 >        // Hide cursor
719 >        SDL_ShowCursor(0);
720   #endif
721  
722          // Set window name/class
723          set_window_name(STR_WINDOW_TITLE);
724  
633        // Hide cursor
634        SDL_ShowCursor(0);
635
725          // Init blitting routines
726          SDL_PixelFormat *f = s->format;
727          VisualFormat visualFormat;
# Line 640 | Line 729 | driver_window::driver_window(SDL_monitor
729          visualFormat.Rmask = f->Rmask;
730          visualFormat.Gmask = f->Gmask;
731          visualFormat.Bmask = f->Bmask;
732 <        Screen_blitter_init(visualFormat, true, sdl_depth_of_video_depth(VIDEO_MODE_DEPTH));
732 >        Screen_blitter_init(visualFormat, true, mac_depth_of_video_depth(VIDEO_MODE_DEPTH));
733  
734          // Load gray ramp to 8->16/32 expand map
735          if (!IsDirectMode(mode))
# Line 707 | Line 796 | void driver_window::mouse_moved(int x, i
796          ADBMouseMoved(x, y);
797   }
798  
799 +
800 + /*
801 + *  Full-screen display driver
802 + */
803 +
804 + // Open display
805 + driver_fullscreen::driver_fullscreen(SDL_monitor_desc &m)
806 +        : driver_base(m)
807 + {
808 +        int width = VIDEO_MODE_X, height = VIDEO_MODE_Y;
809 +        int aligned_width = (width + 15) & ~15;
810 +        int aligned_height = (height + 15) & ~15;
811 +
812 +        // Set absolute mouse mode
813 +        ADBSetRelMouseMode(false);
814 +
815 +        // Create surface
816 +        int depth = sdl_depth_of_video_depth(VIDEO_MODE_DEPTH);
817 +        if ((s = SDL_SetVideoMode(width, height, depth, SDL_HWSURFACE | SDL_FULLSCREEN)) == NULL)
818 +                return;
819 +
820 + #ifdef ENABLE_VOSF
821 +        use_vosf = true;
822 +        // Allocate memory for frame buffer (SIZE is extended to page-boundary)
823 +        the_host_buffer = (uint8 *)s->pixels;
824 +        the_buffer_size = page_extend((aligned_height + 2) * s->pitch);
825 +        the_buffer = (uint8 *)vm_acquire_framebuffer(the_buffer_size);
826 +        the_buffer_copy = (uint8 *)malloc(the_buffer_size);
827 +        D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer));
828 +
829 +        // Check whether we can initialize the VOSF subsystem and it's profitable
830 +        if (!video_vosf_init(m)) {
831 +                WarningAlert(STR_VOSF_INIT_ERR);
832 +                use_vosf = false;
833 +        }
834 +        else if (!video_vosf_profitable()) {
835 +                video_vosf_exit();
836 +                printf("VOSF acceleration is not profitable on this platform, disabling it\n");
837 +                use_vosf = false;
838 +        }
839 +        if (!use_vosf) {
840 +                free(the_buffer_copy);
841 +                vm_release(the_buffer, the_buffer_size);
842 +                the_host_buffer = NULL;
843 +        }
844 + #endif
845 +        if (!use_vosf) {
846 +                // Allocate memory for frame buffer
847 +                the_buffer_size = (aligned_height + 2) * s->pitch;
848 +                the_buffer_copy = (uint8 *)calloc(1, the_buffer_size);
849 +                the_buffer = (uint8 *)vm_acquire_framebuffer(the_buffer_size);
850 +                D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy));
851 +        }
852 +        
853 +        // Hide cursor
854 +        SDL_ShowCursor(0);
855 +
856 +        // Init blitting routines
857 +        SDL_PixelFormat *f = s->format;
858 +        VisualFormat visualFormat;
859 +        visualFormat.depth = depth;
860 +        visualFormat.Rmask = f->Rmask;
861 +        visualFormat.Gmask = f->Gmask;
862 +        visualFormat.Bmask = f->Bmask;
863 +        Screen_blitter_init(visualFormat, true, mac_depth_of_video_depth(VIDEO_MODE_DEPTH));
864 +
865 +        // Load gray ramp to 8->16/32 expand map
866 +        if (!IsDirectMode(mode))
867 +                for (int i=0; i<256; i++)
868 +                        ExpandMap[i] = SDL_MapRGB(f, i, i, i);
869 +
870 +        // Set frame buffer base
871 +        set_mac_frame_buffer(monitor, VIDEO_MODE_DEPTH, true);
872 +
873 +        // Everything went well
874 +        init_ok = true;
875 + }
876 +
877 + // Close display
878 + driver_fullscreen::~driver_fullscreen()
879 + {
880 + #ifdef ENABLE_VOSF
881 +        if (use_vosf)
882 +                the_host_buffer = NULL; // don't free() in driver_base dtor
883 + #endif
884 +        if (s)
885 +                SDL_FreeSurface(s);
886 +
887 +        // Show cursor
888 +        SDL_ShowCursor(1);
889 + }
890 +
891 +
892   /*
893   *  Initialization
894   */
# Line 738 | Line 920 | static void keycode_init(void)
920                  SDL_VideoDriverName(video_driver, sizeof(video_driver));
921                  bool video_driver_found = false;
922                  char line[256];
923 +                int n_keys = 0;
924                  while (fgets(line, sizeof(line) - 1, f)) {
925                          // Read line
926                          int len = strlen(line);
# Line 750 | Line 933 | static void keycode_init(void)
933                                  continue;
934  
935                          if (video_driver_found) {
936 <                                // Skip aliases
937 <                                static const char alias_str[] = "alias";
938 <                                if (strncmp(line, alias_str, sizeof(alias_str) - 1) == 0)
936 >                                // Skip aliases as long as we have read keycodes yet
937 >                                // Otherwise, it's another mapping and we have to stop
938 >                                static const char sdl_str[] = "sdl";
939 >                                if (strncmp(line, sdl_str, sizeof(sdl_str) - 1) == 0 && n_keys == 0)
940                                          continue;
941  
942                                  // Read keycode
943                                  int x_code, mac_code;
944                                  if (sscanf(line, "%d %d", &x_code, &mac_code) == 2)
945 <                                        keycode_table[x_code & 0xff] = mac_code;
945 >                                        keycode_table[x_code & 0xff] = mac_code, n_keys++;
946                                  else
947                                          break;
948                          } else {
949                                  // Search for SDL video driver string
950 <                                static const char alias_sdl_str[] = "alias SDL";
951 <                                if (strncmp(line, alias_sdl_str, sizeof(alias_sdl_str) - 1) == 0) {
952 <                                        char *p = line + sizeof(alias_sdl_str);
950 >                                static const char sdl_str[] = "sdl";
951 >                                if (strncmp(line, sdl_str, sizeof(sdl_str) - 1) == 0) {
952 >                                        char *p = line + sizeof(sdl_str);
953                                          if (strstr(video_driver, p) == video_driver)
954                                                  video_driver_found = true;
955                                  }
# Line 783 | Line 967 | static void keycode_init(void)
967                          WarningAlert(str);
968                          return;
969                  }
970 +
971 +                D(bug("Using SDL/%s keycodes table, %d key mappings\n", video_driver, n_keys));
972          }
973   }
974  
# Line 801 | Line 987 | bool SDL_monitor_desc::video_open(void)
987          case DISPLAY_WINDOW:
988                  drv = new(std::nothrow) driver_window(*this);
989                  break;
990 +        case DISPLAY_SCREEN:
991 +                drv = new(std::nothrow) driver_fullscreen(*this);
992 +                break;
993          }
994          if (drv == NULL)
995                  return false;
# Line 810 | Line 999 | bool SDL_monitor_desc::video_open(void)
999                  return false;
1000          }
1001  
813 #ifdef ENABLE_VOSF
814        if (use_vosf) {
815                // Initialize the VOSF system
816                if (!video_vosf_init(*this)) {
817                        ErrorAlert(STR_VOSF_INIT_ERR);
818                return false;
819                }
820        }
821 #endif
822        
1002          // Initialize VideoRefresh function
1003          VideoRefreshInit();
1004  
# Line 868 | Line 1047 | bool VideoInit(bool classic)
1047  
1048          // Get screen mode from preferences
1049          const char *mode_str = NULL;
871 #ifndef SHEEPSHAVER
1050          if (classic_mode)
1051                  mode_str = "win/512/342";
1052          else
1053                  mode_str = PrefsFindString("screen");
876 #endif
1054  
1055          // Determine display type and default dimensions
1056          int default_width, default_height;
# Line 889 | Line 1066 | bool VideoInit(bool classic)
1066          if (mode_str) {
1067                  if (sscanf(mode_str, "win/%d/%d", &default_width, &default_height) == 2)
1068                          display_type = DISPLAY_WINDOW;
1069 +                else if (sscanf(mode_str, "dga/%d/%d", &default_width, &default_height) == 2)
1070 +                        display_type = DISPLAY_SCREEN;
1071          }
1072          int max_width = 640, max_height = 480;
1073          SDL_Rect **modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE);
1074          if (modes && modes != (SDL_Rect **)-1) {
1075 <                max_width = modes[0]->w;
1076 <                max_height = modes[0]->h;
1075 >                // It turns out that on some implementations, and contrary to the documentation,
1076 >                // the returned list is not sorted from largest to smallest (e.g. Windows)
1077 >                for (int i = 0; modes[i] != NULL; i++) {
1078 >                        const int w = modes[i]->w;
1079 >                        const int h = modes[i]->h;
1080 >                        if (w > max_width && h > max_height) {
1081 >                                max_width = w;
1082 >                                max_height = h;
1083 >                        }
1084 >                }
1085                  if (default_width > max_width)
1086                          default_width = max_width;
1087                  if (default_height > max_height)
# Line 929 | Line 1116 | bool VideoInit(bool classic)
1116                          add_mode(display_type, 512, 342, 0x80, 64, VIDEO_DEPTH_1BIT);
1117                  else {
1118                          for (int d = VIDEO_DEPTH_1BIT; d <= default_depth; d++) {
1119 <                                int bpp = (d <= VIDEO_DEPTH_8BIT ? 8 : sdl_depth_of_video_depth(d));
1119 >                                int bpp = sdl_depth_of_video_depth(d);
1120                                  if (SDL_VideoModeOK(max_width, max_height, bpp, SDL_HWSURFACE))
1121                                          add_window_modes(video_depth(d));
1122                          }
1123                  }
1124 <        } else
1125 <                add_mode(display_type, default_width, default_height, 0x80, TrivialBytesPerRow(default_width, (video_depth)default_depth), default_depth);
1124 >        } else if (display_type == DISPLAY_SCREEN) {
1125 >                struct {
1126 >                        int w;
1127 >                        int h;
1128 >                        int resolution_id;
1129 >                }
1130 >                video_modes[] = {
1131 >                        {   -1,   -1, 0x80 },
1132 >                        {  640,  480, 0x81 },
1133 >                        {  800,  600, 0x82 },
1134 >                        { 1024,  768, 0x83 },
1135 >                        { 1152,  870, 0x84 },
1136 >                        { 1280, 1024, 0x85 },
1137 >                        { 1600, 1200, 0x86 },
1138 >                        { 0, }
1139 >                };
1140 >                video_modes[0].w = default_width;
1141 >                video_modes[0].h = default_height;
1142 >
1143 >                for (int i = 0; video_modes[i].w != 0; i++) {
1144 >                        const int w = video_modes[i].w;
1145 >                        const int h = video_modes[i].h;
1146 >                        if (i > 0 && (w >= default_width || h >= default_height))
1147 >                                continue;
1148 > #ifdef ENABLE_VOSF
1149 >                        for (int d = VIDEO_DEPTH_1BIT; d <= default_depth; d++) {
1150 >                                int bpp = sdl_depth_of_video_depth(d);
1151 >                                if (SDL_VideoModeOK(w, h, bpp, SDL_HWSURFACE | SDL_FULLSCREEN))
1152 >                                        add_mode(display_type, w, h, video_modes[i].resolution_id, TrivialBytesPerRow(w, (video_depth)d), d);
1153 >                        }
1154 > #else
1155 >                        add_mode(display_type, w, h, video_modes[i].resolution_id, TrivialBytesPerRow(w, (video_depth)default_depth), default_depth);
1156 > #endif
1157 >                }
1158 >        }
1159 >
1160          if (VideoModes.empty()) {
1161                  ErrorAlert(STR_NO_XVISUAL_ERR);
1162                  return false;
# Line 1017 | Line 1238 | void SDL_monitor_desc::video_close(void)
1238          UNLOCK_FRAME_BUFFER;
1239          D(bug(" frame buffer unlocked\n"));
1240  
1020 #ifdef ENABLE_VOSF
1021        if (use_vosf) {
1022                // Deinitialize VOSF
1023                video_vosf_exit();
1024        }
1025 #endif
1026
1241          // Close display
1242          delete drv;
1243          drv = NULL;
# Line 1121 | Line 1335 | void SDL_monitor_desc::set_palette(uint8
1335          const VIDEO_MODE &mode = get_current_mode();
1336  
1337          // FIXME: how can we handle the gamma ramp?
1338 <        if (VIDEO_MODE_DEPTH > VIDEO_DEPTH_8BIT)
1338 >        if ((int)VIDEO_MODE_DEPTH > VIDEO_DEPTH_8BIT)
1339                  return;
1340  
1341          LOCK_PALETTE;
# Line 1146 | Line 1360 | void SDL_monitor_desc::set_palette(uint8
1360                  }
1361  
1362   #ifdef ENABLE_VOSF
1363 <                // We have to redraw everything because the interpretation of pixel values changed
1364 <                LOCK_VOSF;
1365 <                PFLAG_SET_ALL;
1366 <                UNLOCK_VOSF;
1367 <                memset(the_buffer_copy, 0, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y);
1363 >                if (use_vosf) {
1364 >                        // We have to redraw everything because the interpretation of pixel values changed
1365 >                        LOCK_VOSF;
1366 >                        PFLAG_SET_ALL;
1367 >                        UNLOCK_VOSF;
1368 >                        memset(the_buffer_copy, 0, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y);
1369 >                }
1370   #endif
1371          }
1372  
# Line 1180 | Line 1396 | int16 video_mode_change(VidLocals *csSav
1396                          csSave->saveData = ReadMacInt32(ParamPtr + csData);
1397                          csSave->savePage = ReadMacInt16(ParamPtr + csPage);
1398  
1399 <                        // Disable interrupts
1399 >                        // Disable interrupts and pause redraw thread
1400                          DisableInterrupt();
1401 +                        thread_stop_ack = false;
1402 +                        thread_stop_req = true;
1403 +                        while (!thread_stop_ack) ;
1404  
1405                          cur_mode = i;
1406                          monitor_desc *monitor = VideoMonitors[0];
# Line 1192 | Line 1411 | int16 video_mode_change(VidLocals *csSav
1411                          csSave->saveData=VModes[cur_mode].viAppleID;/* First mode ... */
1412                          csSave->saveMode=VModes[cur_mode].viAppleMode;
1413  
1414 <                        // Enable interrupts
1414 >                        // Enable interrupts and resume redraw thread
1415 >                        thread_stop_req = false;
1416                          EnableInterrupt();
1417                          return noErr;
1418                  }
# Line 1221 | Line 1441 | void SDL_monitor_desc::switch_to_current
1441   #ifdef SHEEPSHAVER
1442   bool video_can_change_cursor(void)
1443   {
1444 < //      return hw_mac_cursor_accl && (display_type != DISPLAY_SCREEN);
1225 <        return false;
1444 >        return (display_type == DISPLAY_WINDOW);
1445   }
1446   #endif
1447  
# Line 1234 | Line 1453 | bool video_can_change_cursor(void)
1453   #ifdef SHEEPSHAVER
1454   void video_set_cursor(void)
1455   {
1456 < //      cursor_changed = true;
1456 >        cursor_changed = true;
1457   }
1458   #endif
1459  
1460  
1461   /*
1462 < *  Install graphics acceleration
1462 > *  Keyboard-related utilify functions
1463   */
1464  
1465 < #ifdef SHEEPSHAVER
1247 < // Rectangle inversion
1248 < template< int bpp >
1249 < static inline void do_invrect(uint8 *dest, uint32 length)
1465 > static bool is_modifier_key(SDL_KeyboardEvent const & e)
1466   {
1467 < #define INVERT_1(PTR, OFS) ((uint8  *)(PTR))[OFS] = ~((uint8  *)(PTR))[OFS]
1468 < #define INVERT_2(PTR, OFS) ((uint16 *)(PTR))[OFS] = ~((uint16 *)(PTR))[OFS]
1469 < #define INVERT_4(PTR, OFS) ((uint32 *)(PTR))[OFS] = ~((uint32 *)(PTR))[OFS]
1470 < #define INVERT_8(PTR, OFS) ((uint64 *)(PTR))[OFS] = ~((uint64 *)(PTR))[OFS]
1471 <
1472 < #ifndef UNALIGNED_PROFITABLE
1473 <        // Align on 16-bit boundaries
1474 <        if (bpp < 16 && (((uintptr)dest) & 1)) {
1475 <                INVERT_1(dest, 0);
1476 <                dest += 1; length -= 1;
1477 <        }
1478 <
1479 <        // Align on 32-bit boundaries
1480 <        if (bpp < 32 && (((uintptr)dest) & 2)) {
1481 <                INVERT_2(dest, 0);
1482 <                dest += 2; length -= 2;
1267 <        }
1268 < #endif
1269 <
1270 <        // Invert 8-byte words
1271 <        if (length >= 8) {
1272 <                const int r = (length / 8) % 8;
1273 <                dest += r * 8;
1274 <
1275 <                int n = ((length / 8) + 7) / 8;
1276 <                switch (r) {
1277 <                case 0: do {
1278 <                                dest += 64;
1279 <                                INVERT_8(dest, -8);
1280 <                case 7: INVERT_8(dest, -7);
1281 <                case 6: INVERT_8(dest, -6);
1282 <                case 5: INVERT_8(dest, -5);
1283 <                case 4: INVERT_8(dest, -4);
1284 <                case 3: INVERT_8(dest, -3);
1285 <                case 2: INVERT_8(dest, -2);
1286 <                case 1: INVERT_8(dest, -1);
1287 <                                } while (--n > 0);
1288 <                }
1289 <        }
1290 <
1291 <        // 32-bit cell to invert?
1292 <        if (length & 4) {
1293 <                INVERT_4(dest, 0);
1294 <                if (bpp <= 16)
1295 <                        dest += 4;
1296 <        }
1297 <
1298 <        // 16-bit cell to invert?
1299 <        if (bpp <= 16 && (length & 2)) {
1300 <                INVERT_2(dest, 0);
1301 <                if (bpp <= 8)
1302 <                        dest += 2;
1303 <        }
1304 <
1305 <        // 8-bit cell to invert?
1306 <        if (bpp <= 8 && (length & 1))
1307 <                INVERT_1(dest, 0);
1308 <
1309 < #undef INVERT_1
1310 < #undef INVERT_2
1311 < #undef INVERT_4
1312 < #undef INVERT_8
1313 < }
1314 <
1315 < void NQD_invrect(uint32 p)
1316 < {
1317 <        D(bug("accl_invrect %08x\n", p));
1318 <
1319 <        // Get inversion parameters
1320 <        int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2);
1321 <        int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0);
1322 <        int16 width  = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2);
1323 <        int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0);
1324 <        D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y));
1325 <        D(bug(" width %d, height %d, bytes_per_row %d\n", width, height, (int32)ReadMacInt32(p + acclDestRowBytes)));
1326 <
1327 <        //!!?? pen_mode == 14
1328 <
1329 <        // And perform the inversion
1330 <        const int bpp = bytes_per_pixel(ReadMacInt32(p + acclDestPixelSize));
1331 <        const int dest_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes);
1332 <        uint8 *dest = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dest_row_bytes) + (dest_X * bpp));
1333 <        width *= bpp;
1334 <        switch (bpp) {
1335 <        case 1:
1336 <                for (int i = 0; i < height; i++) {
1337 <                        do_invrect<8>(dest, width);
1338 <                        dest += dest_row_bytes;
1339 <                }
1340 <                break;
1341 <        case 2:
1342 <                for (int i = 0; i < height; i++) {
1343 <                        do_invrect<16>(dest, width);
1344 <                        dest += dest_row_bytes;
1345 <                }
1346 <                break;
1347 <        case 4:
1348 <                for (int i = 0; i < height; i++) {
1349 <                        do_invrect<32>(dest, width);
1350 <                        dest += dest_row_bytes;
1351 <                }
1352 <                break;
1353 <        }
1354 < }
1355 <
1356 < // Rectangle filling
1357 < template< int bpp >
1358 < static inline void do_fillrect(uint8 *dest, uint32 color, uint32 length)
1359 < {
1360 < #define FILL_1(PTR, OFS, VAL) ((uint8  *)(PTR))[OFS] = (VAL)
1361 < #define FILL_2(PTR, OFS, VAL) ((uint16 *)(PTR))[OFS] = (VAL)
1362 < #define FILL_4(PTR, OFS, VAL) ((uint32 *)(PTR))[OFS] = (VAL)
1363 < #define FILL_8(PTR, OFS, VAL) ((uint64 *)(PTR))[OFS] = (VAL)
1364 <
1365 < #ifndef UNALIGNED_PROFITABLE
1366 <        // Align on 16-bit boundaries
1367 <        if (bpp < 16 && (((uintptr)dest) & 1)) {
1368 <                FILL_1(dest, 0, color);
1369 <                dest += 1; length -= 1;
1370 <        }
1371 <
1372 <        // Align on 32-bit boundaries
1373 <        if (bpp < 32 && (((uintptr)dest) & 2)) {
1374 <                FILL_2(dest, 0, color);
1375 <                dest += 2; length -= 2;
1376 <        }
1377 < #endif
1378 <
1379 <        // Fill 8-byte words
1380 <        if (length >= 8) {
1381 <                const uint64 c = (((uint64)color) << 32) | color;
1382 <                const int r = (length / 8) % 8;
1383 <                dest += r * 8;
1384 <
1385 <                int n = ((length / 8) + 7) / 8;
1386 <                switch (r) {
1387 <                case 0: do {
1388 <                                dest += 64;
1389 <                                FILL_8(dest, -8, c);
1390 <                case 7: FILL_8(dest, -7, c);
1391 <                case 6: FILL_8(dest, -6, c);
1392 <                case 5: FILL_8(dest, -5, c);
1393 <                case 4: FILL_8(dest, -4, c);
1394 <                case 3: FILL_8(dest, -3, c);
1395 <                case 2: FILL_8(dest, -2, c);
1396 <                case 1: FILL_8(dest, -1, c);
1397 <                                } while (--n > 0);
1398 <                }
1399 <        }
1400 <
1401 <        // 32-bit cell to fill?
1402 <        if (length & 4) {
1403 <                FILL_4(dest, 0, color);
1404 <                if (bpp <= 16)
1405 <                        dest += 4;
1406 <        }
1407 <
1408 <        // 16-bit cell to fill?
1409 <        if (bpp <= 16 && (length & 2)) {
1410 <                FILL_2(dest, 0, color);
1411 <                if (bpp <= 8)
1412 <                        dest += 2;
1413 <        }
1414 <
1415 <        // 8-bit cell to fill?
1416 <        if (bpp <= 8 && (length & 1))
1417 <                FILL_1(dest, 0, color);
1418 <
1419 < #undef FILL_1
1420 < #undef FILL_2
1421 < #undef FILL_4
1422 < #undef FILL_8
1423 < }
1424 <
1425 < void NQD_fillrect(uint32 p)
1426 < {
1427 <        D(bug("accl_fillrect %08x\n", p));
1428 <
1429 <        // Get filling parameters
1430 <        int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2);
1431 <        int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0);
1432 <        int16 width  = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2);
1433 <        int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0);
1434 <        uint32 color = htonl(ReadMacInt32(p + acclPenMode) == 8 ? ReadMacInt32(p + acclForePen) : ReadMacInt32(p + acclBackPen));
1435 <        D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y));
1436 <        D(bug(" width %d, height %d\n", width, height));
1437 <        D(bug(" bytes_per_row %d color %08x\n", (int32)ReadMacInt32(p + acclDestRowBytes), color));
1438 <
1439 <        // And perform the fill
1440 <        const int bpp = bytes_per_pixel(ReadMacInt32(p + acclDestPixelSize));
1441 <        const int dest_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes);
1442 <        uint8 *dest = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dest_row_bytes) + (dest_X * bpp));
1443 <        width *= bpp;
1444 <        switch (bpp) {
1445 <        case 1:
1446 <                for (int i = 0; i < height; i++) {
1447 <                        memset(dest, color, width);
1448 <                        dest += dest_row_bytes;
1449 <                }
1450 <                break;
1451 <        case 2:
1452 <                for (int i = 0; i < height; i++) {
1453 <                        do_fillrect<16>(dest, color, width);
1454 <                        dest += dest_row_bytes;
1455 <                }
1456 <                break;
1457 <        case 4:
1458 <                for (int i = 0; i < height; i++) {
1459 <                        do_fillrect<32>(dest, color, width);
1460 <                        dest += dest_row_bytes;
1461 <                }
1462 <                break;
1463 <        }
1464 < }
1465 <
1466 < bool NQD_fillrect_hook(uint32 p)
1467 < {
1468 <        D(bug("accl_fillrect_hook %08x\n", p));
1469 <
1470 <        // Check if we can accelerate this fillrect
1471 <        if (ReadMacInt32(p + 0x284) != 0 && ReadMacInt32(p + acclDestPixelSize) >= 8) {
1472 <                const int transfer_mode = ReadMacInt32(p + acclTransferMode);
1473 <                if (transfer_mode == 8) {
1474 <                        // Fill
1475 <                        WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_FILLRECT));
1476 <                        return true;
1477 <                }
1478 <                else if (transfer_mode == 10) {
1479 <                        // Invert
1480 <                        WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_INVRECT));
1481 <                        return true;
1482 <                }
1483 <        }
1484 <        return false;
1485 < }
1486 <
1487 < // Rectangle blitting
1488 < // TODO: optimize for VOSF and target pixmap == screen
1489 < void NQD_bitblt(uint32 p)
1490 < {
1491 <        D(bug("accl_bitblt %08x\n", p));
1492 <
1493 <        // Get blitting parameters
1494 <        int16 src_X  = (int16)ReadMacInt16(p + acclSrcRect + 2) - (int16)ReadMacInt16(p + acclSrcBoundsRect + 2);
1495 <        int16 src_Y  = (int16)ReadMacInt16(p + acclSrcRect + 0) - (int16)ReadMacInt16(p + acclSrcBoundsRect + 0);
1496 <        int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2);
1497 <        int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0);
1498 <        int16 width  = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2);
1499 <        int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0);
1500 <        D(bug(" src addr %08x, dest addr %08x\n", ReadMacInt32(p + acclSrcBaseAddr), ReadMacInt32(p + acclDestBaseAddr)));
1501 <        D(bug(" src X %d, src Y %d, dest X %d, dest Y %d\n", src_X, src_Y, dest_X, dest_Y));
1502 <        D(bug(" width %d, height %d\n", width, height));
1503 <
1504 <        // And perform the blit
1505 <        const int bpp = bytes_per_pixel(ReadMacInt32(p + acclSrcPixelSize));
1506 <        width *= bpp;
1507 <        if ((int32)ReadMacInt32(p + acclSrcRowBytes) > 0) {
1508 <                const int src_row_bytes = (int32)ReadMacInt32(p + acclSrcRowBytes);
1509 <                const int dst_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes);
1510 <                uint8 *src = Mac2HostAddr(ReadMacInt32(p + acclSrcBaseAddr) + (src_Y * src_row_bytes) + (src_X * bpp));
1511 <                uint8 *dst = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dst_row_bytes) + (dest_X * bpp));
1512 <                for (int i = 0; i < height; i++) {
1513 <                        memmove(dst, src, width);
1514 <                        src += src_row_bytes;
1515 <                        dst += dst_row_bytes;
1516 <                }
1517 <        }
1518 <        else {
1519 <                const int src_row_bytes = -(int32)ReadMacInt32(p + acclSrcRowBytes);
1520 <                const int dst_row_bytes = -(int32)ReadMacInt32(p + acclDestRowBytes);
1521 <                uint8 *src = Mac2HostAddr(ReadMacInt32(p + acclSrcBaseAddr) + ((src_Y + height - 1) * src_row_bytes) + (src_X * bpp));
1522 <                uint8 *dst = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + ((dest_Y + height - 1) * dst_row_bytes) + (dest_X * bpp));
1523 <                for (int i = height - 1; i >= 0; i--) {
1524 <                        memmove(dst, src, width);
1525 <                        src -= src_row_bytes;
1526 <                        dst -= dst_row_bytes;
1527 <                }
1528 <        }
1529 < }
1530 <
1531 < /*
1532 <  BitBlt transfer modes:
1533 <  0 : srcCopy
1534 <  1 : srcOr
1535 <  2 : srcXor
1536 <  3 : srcBic
1537 <  4 : notSrcCopy
1538 <  5 : notSrcOr
1539 <  6 : notSrcXor
1540 <  7 : notSrcBic
1541 <  32 : blend
1542 <  33 : addPin
1543 <  34 : addOver
1544 <  35 : subPin
1545 <  36 : transparent
1546 <  37 : adMax
1547 <  38 : subOver
1548 <  39 : adMin
1549 <  50 : hilite
1550 < */
1551 <
1552 < bool NQD_bitblt_hook(uint32 p)
1553 < {
1554 <        D(bug("accl_draw_hook %08x\n", p));
1555 <
1556 <        // Check if we can accelerate this bitblt
1557 <        if (ReadMacInt32(p + 0x018) + ReadMacInt32(p + 0x128) == 0 &&
1558 <                ReadMacInt32(p + 0x130) == 0 &&
1559 <                ReadMacInt32(p + acclSrcPixelSize) >= 8 &&
1560 <                ReadMacInt32(p + acclSrcPixelSize) == ReadMacInt32(p + acclDestPixelSize) &&
1561 <                (ReadMacInt32(p + acclSrcRowBytes) ^ ReadMacInt32(p + acclDestRowBytes)) >= 0 && // same sign?
1562 <                ReadMacInt32(p + acclTransferMode) == 0 &&                                                                               // srcCopy?
1563 <                ReadMacInt32(p + 0x15c) > 0) {
1564 <
1565 <                // Yes, set function pointer
1566 <                WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_BITBLT));
1467 >        switch (e.keysym.sym) {
1468 >        case SDLK_NUMLOCK:
1469 >        case SDLK_CAPSLOCK:
1470 >        case SDLK_SCROLLOCK:
1471 >        case SDLK_RSHIFT:
1472 >        case SDLK_LSHIFT:
1473 >        case SDLK_RCTRL:
1474 >        case SDLK_LCTRL:
1475 >        case SDLK_RALT:
1476 >        case SDLK_LALT:
1477 >        case SDLK_RMETA:
1478 >        case SDLK_LMETA:
1479 >        case SDLK_LSUPER:
1480 >        case SDLK_RSUPER:
1481 >        case SDLK_MODE:
1482 >        case SDLK_COMPOSE:
1483                  return true;
1484          }
1485          return false;
1486   }
1487  
1488 < // Wait for graphics operation to finish
1573 < bool NQD_sync_hook(uint32 arg)
1574 < {
1575 <        D(bug("accl_sync_hook %08x\n", arg));
1576 <        return true;
1577 < }
1578 <
1579 < void VideoInstallAccel(void)
1488 > static bool is_ctrl_down(SDL_keysym const & ks)
1489   {
1490 <        // Install acceleration hooks
1582 <        if (PrefsFindBool("gfxaccel")) {
1583 <                D(bug("Video: Installing acceleration hooks\n"));
1584 <                uint32 base;
1585 <
1586 <                SheepVar bitblt_hook_info(sizeof(accl_hook_info));
1587 <                base = bitblt_hook_info.addr();
1588 <                WriteMacInt32(base + 0, NativeTVECT(NATIVE_BITBLT_HOOK));
1589 <                WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK));
1590 <                WriteMacInt32(base + 8, ACCL_BITBLT);
1591 <                NQDMisc(6, bitblt_hook_info.ptr());
1592 <
1593 <                SheepVar fillrect_hook_info(sizeof(accl_hook_info));
1594 <                base = fillrect_hook_info.addr();
1595 <                WriteMacInt32(base + 0, NativeTVECT(NATIVE_FILLRECT_HOOK));
1596 <                WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK));
1597 <                WriteMacInt32(base + 8, ACCL_FILLRECT);
1598 <                NQDMisc(6, fillrect_hook_info.ptr());
1599 <        }
1490 >        return ctrl_down || (ks.mod & KMOD_CTRL);
1491   }
1601 #endif
1492  
1493  
1494   /*
# Line 1606 | Line 1496 | void VideoInstallAccel(void)
1496   *  and -2 if the key was recognized as a hotkey
1497   */
1498  
1609 static bool is_ctrl_down(SDL_keysym const & ks)
1610 {
1611        return ctrl_down || (ks.mod & KMOD_CTRL);
1612 }
1613
1499   static int kc_decode(SDL_keysym const & ks, bool key_down)
1500   {
1501          switch (ks.sym) {
# Line 1643 | Line 1528 | static int kc_decode(SDL_keysym const &
1528  
1529          case SDLK_1: case SDLK_EXCLAIM: return 0x12;
1530          case SDLK_2: case SDLK_AT: return 0x13;
1531 < //      case SDLK_3: case SDLK_numbersign: return 0x14;
1531 >        case SDLK_3: case SDLK_HASH: return 0x14;
1532          case SDLK_4: case SDLK_DOLLAR: return 0x15;
1533 < //      case SDLK_5: case SDLK_percent: return 0x17;
1533 >        case SDLK_5: return 0x17;
1534          case SDLK_6: return 0x16;
1535          case SDLK_7: return 0x1a;
1536          case SDLK_8: return 0x1c;
1537          case SDLK_9: return 0x19;
1538          case SDLK_0: return 0x1d;
1539  
1540 < //      case SDLK_BACKQUOTE: case SDLK_asciitilde: return 0x0a;
1540 >        case SDLK_BACKQUOTE: return 0x0a;
1541          case SDLK_MINUS: case SDLK_UNDERSCORE: return 0x1b;
1542          case SDLK_EQUALS: case SDLK_PLUS: return 0x18;
1543 < //      case SDLK_bracketleft: case SDLK_braceleft: return 0x21;
1544 < //      case SDLK_bracketright: case SDLK_braceright: return 0x1e;
1545 < //      case SDLK_BACKSLASH: case SDLK_bar: return 0x2a;
1543 >        case SDLK_LEFTBRACKET: return 0x21;
1544 >        case SDLK_RIGHTBRACKET: return 0x1e;
1545 >        case SDLK_BACKSLASH: return 0x2a;
1546          case SDLK_SEMICOLON: case SDLK_COLON: return 0x29;
1547 < //      case SDLK_apostrophe: case SDLK_QUOTEDBL: return 0x27;
1547 >        case SDLK_QUOTE: case SDLK_QUOTEDBL: return 0x27;
1548          case SDLK_COMMA: case SDLK_LESS: return 0x2b;
1549          case SDLK_PERIOD: case SDLK_GREATER: return 0x2f;
1550          case SDLK_SLASH: case SDLK_QUESTION: return 0x2c;
# Line 1680 | Line 1565 | static int kc_decode(SDL_keysym const &
1565          case SDLK_RCTRL: return 0x36;
1566          case SDLK_LSHIFT: return 0x38;
1567          case SDLK_RSHIFT: return 0x38;
1568 + #if (defined(__APPLE__) && defined(__MACH__))
1569 +        case SDLK_LALT: return 0x3a;
1570 +        case SDLK_RALT: return 0x3a;
1571 +        case SDLK_LMETA: return 0x37;
1572 +        case SDLK_RMETA: return 0x37;
1573 + #else
1574          case SDLK_LALT: return 0x37;
1575          case SDLK_RALT: return 0x37;
1576          case SDLK_LMETA: return 0x3a;
1577          case SDLK_RMETA: return 0x3a;
1578 + #endif
1579 +        case SDLK_LSUPER: return 0x3a; // "Windows" key
1580 +        case SDLK_RSUPER: return 0x3a;
1581          case SDLK_MENU: return 0x32;
1582          case SDLK_CAPSLOCK: return 0x39;
1583          case SDLK_NUMLOCK: return 0x47;
# Line 1790 | Line 1684 | static void handle_events(void)
1684                          // Keyboard
1685                          case SDL_KEYDOWN: {
1686                                  int code = -1;
1687 <                                if (use_keycodes) {
1687 >                                if (use_keycodes && !is_modifier_key(event.key)) {
1688                                          if (event2keycode(event.key, true) != -2)       // This is called to process the hotkeys
1689                                                  code = keycode_table[event.key.keysym.scancode & 0xff];
1690                                  } else
# Line 1818 | Line 1712 | static void handle_events(void)
1712                          }
1713                          case SDL_KEYUP: {
1714                                  int code = -1;
1715 <                                if (use_keycodes) {
1715 >                                if (use_keycodes && !is_modifier_key(event.key)) {
1716                                          if (event2keycode(event.key, false) != -2)      // This is called to process the hotkeys
1717                                                  code = keycode_table[event.key.keysym.scancode & 0xff];
1718                                  } else
1719                                          code = event2keycode(event.key, false);
1720 <                                if (code >= 0 && code != 0x39) {        // Don't propagate Caps Lock releases
1721 <                                        ADBKeyUp(code);
1720 >                                if (code >= 0) {
1721 >                                        if (code == 0x39) {     // Caps Lock released
1722 >                                                if (caps_on) {
1723 >                                                        ADBKeyUp(code);
1724 >                                                        caps_on = false;
1725 >                                                } else {
1726 >                                                        ADBKeyDown(code);
1727 >                                                        caps_on = true;
1728 >                                                }
1729 >                                        } else
1730 >                                                ADBKeyUp(code);
1731                                          if (code == 0x36)
1732                                                  ctrl_down = false;
1733                                  }
# Line 1891 | Line 1794 | static void update_display_static(driver
1794  
1795          // Check for first column from left and first column from right that have changed
1796          if (high) {
1797 <                if (VIDEO_MODE_DEPTH < VIDEO_DEPTH_8BIT) {
1797 >                if ((int)VIDEO_MODE_DEPTH < VIDEO_DEPTH_8BIT) {
1798                          const int src_bytes_per_row = bytes_per_row;
1799                          const int dst_bytes_per_row = drv->s->pitch;
1800                          const int pixels_per_byte = VIDEO_MODE_X / src_bytes_per_row;
# Line 2068 | Line 1971 | static void video_refresh_dga_vosf(void)
1971                  tick_counter = 0;
1972                  if (mainBuffer.dirty) {
1973                          LOCK_VOSF;
1974 <                        update_display_dga_vosf();
1974 >                        update_display_dga_vosf(static_cast<driver_fullscreen *>(drv));
1975                          UNLOCK_VOSF;
1976                  }
1977          }
# Line 2152 | Line 2055 | static int redraw_func(void *arg)
2055                          next = GetTicks_usec();
2056                  ticks++;
2057  
2058 + #ifdef SHEEPSHAVER
2059 +                // Pause if requested (during video mode switches)
2060 +                if (thread_stop_req) {
2061 +                        thread_stop_ack = true;
2062 +                        continue;
2063 +                }
2064 + #endif
2065 +
2066                  // Handle SDL events
2067                  handle_events();
2068  
2069                  // Refresh display
2070                  video_refresh();
2071  
2072 + #ifdef SHEEPSHAVER
2073 +                // Set new cursor image if it was changed
2074 +                if (cursor_changed && sdl_cursor) {
2075 +                        cursor_changed = false;
2076 +                        SDL_FreeCursor(sdl_cursor);
2077 +                        sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, MacCursor[2], MacCursor[3]);
2078 +                        if (sdl_cursor)
2079 +                                SDL_SetCursor(sdl_cursor);
2080 +                }
2081 + #endif
2082 +
2083                  // Set new palette if it was changed
2084                  handle_palette_changes();
2085          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines