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.4 by gbeauche, 2004-06-24T15:25:57Z vs.
Revision 1.11 by gbeauche, 2004-07-02T06:08:01Z

# Line 35 | Line 35
35   *  - Events processing is bound to the general emulation thread as SDL requires
36   *    to PumpEvents() within the same thread as the one that called SetVideoMode().
37   *    Besides, there can't seem to be a way to call SetVideoMode() from a child thread.
38 + *  - Refresh performance is still slow. Use SDL_CreateRGBSurface()?
39 + *  - Backport hw cursor acceleration to Basilisk II?
40   */
41  
42   #include "sysdeps.h"
# Line 96 | Line 98 | static volatile bool redraw_thread_cance
98   static SDL_Thread *redraw_thread = NULL;                        // Redraw thread
99  
100   #ifdef ENABLE_VOSF
101 < static bool use_vosf = true;                                            // Flag: VOSF enabled
101 > static bool use_vosf = false;                                           // Flag: VOSF enabled
102   #else
103   static const bool use_vosf = false;                                     // VOSF not possible
104   #endif
# Line 114 | Line 116 | static int keycode_table[256];                                         // X
116  
117   // SDL variables
118   static int screen_depth;                                                        // Depth of current screen
119 + static SDL_Cursor *sdl_cursor;                                          // Copy of Mac cursor
120 + static volatile bool cursor_changed = false;            // Flag: cursor changed, redraw_func must update the cursor
121   static SDL_Color sdl_palette[256];                                      // Color palette to be used as CLUT and gamma table
122   static bool sdl_palette_changed = false;                        // Flag: Palette changed, redraw thread must set new colors
123   static const int sdl_eventmask = SDL_MOUSEBUTTONDOWNMASK | SDL_MOUSEBUTTONUPMASK | SDL_MOUSEMOTIONMASK | SDL_KEYUPMASK | SDL_KEYDOWNMASK | SDL_VIDEOEXPOSEMASK | SDL_QUITMASK;
# Line 255 | Line 259 | static void ErrorAlert(int error)
259   {
260          ErrorAlert(GetString(error));
261   }
262 +
263 + // Display warning alert
264 + static void WarningAlert(int warning)
265 + {
266 +        WarningAlert(GetString(warning));
267 + }
268   #endif
269  
270  
# Line 342 | Line 352 | static int sdl_depth_of_video_depth(int
352          return depth;
353   }
354  
355 < // Add mode to list of supported modes
356 < static void add_mode(int type, int width, int height, int resolution_id, int bytes_per_row, int depth)
355 > // Check wether specified mode is available
356 > static bool has_mode(int type, int width, int height)
357   {
358 <        VIDEO_MODE mode;
358 >        // FIXME: no fullscreen support yet
359 >        if (type == DISPLAY_SCREEN)
360 >                return false;
361 >
362   #ifdef SHEEPSHAVER
363 <        // Don't add 512x384 modes
363 >        // Filter out Classic resolutiosn
364          if (width == 512 && height == 384)
365 +                return false;
366 +
367 +        // Read window modes prefs
368 +        static uint32 window_modes = 0;
369 +        static uint32 screen_modes = 0;
370 +        if (window_modes == 0 || screen_modes == 0) {
371 +                window_modes = PrefsFindInt32("windowmodes");
372 +                screen_modes = PrefsFindInt32("screenmodes");
373 +                if (window_modes == 0 || screen_modes == 0)
374 +                        window_modes |= 3;                      // Allow at least 640x480 and 800x600 window modes
375 +        }
376 +
377 +        if (type == DISPLAY_WINDOW) {
378 +                int apple_mask, apple_id = find_apple_resolution(width, height);
379 +                switch (apple_id) {
380 +                case APPLE_640x480:             apple_mask = 0x01; break;
381 +                case APPLE_800x600:             apple_mask = 0x02; break;
382 +                case APPLE_1024x768:    apple_mask = 0x04; break;
383 +                case APPLE_1152x768:    apple_mask = 0x40; break;
384 +                case APPLE_1152x900:    apple_mask = 0x08; break;
385 +                case APPLE_1280x1024:   apple_mask = 0x10; break;
386 +                case APPLE_1600x1200:   apple_mask = 0x20; break;
387 +                default:                                apple_mask = 0x00; break;
388 +                }
389 +                return (window_modes & apple_mask);
390 +        }
391 + #else
392 +        return true;
393 + #endif
394 +        return false;
395 + }
396 +
397 + // Add mode to list of supported modes
398 + static void add_mode(int type, int width, int height, int resolution_id, int bytes_per_row, int depth)
399 + {
400 +        // Filter out unsupported modes
401 +        if (!has_mode(type, width, height))
402                  return;
403  
404 +        // Fill in VideoMode entry
405 +        VIDEO_MODE mode;
406 + #ifdef SHEEPSHAVER
407          // Recalculate dimensions to fit Apple modes
408          resolution_id = match_apple_resolution(width, height);
409          mode.viType = type;
# Line 359 | Line 412 | static void add_mode(int type, int width
412          VIDEO_MODE_Y = height;
413          VIDEO_MODE_RESOLUTION = resolution_id;
414          VIDEO_MODE_ROW_BYTES = bytes_per_row;
415 <        VIDEO_MODE_DEPTH = depth;
415 >        VIDEO_MODE_DEPTH = (video_depth)depth;
416          VideoModes.push_back(mode);
417   }
418  
# Line 533 | Line 586 | void driver_base::update_palette(void)
586   {
587          const VIDEO_MODE &mode = monitor.get_current_mode();
588  
589 <        if (VIDEO_MODE_DEPTH <= VIDEO_DEPTH_8BIT)
589 >        if ((int)VIDEO_MODE_DEPTH <= VIDEO_DEPTH_8BIT)
590                  SDL_SetPalette(s, SDL_PHYSPAL, sdl_palette, 0, 256);
591   }
592  
# Line 564 | Line 617 | driver_window::driver_window(SDL_monitor
617          ADBSetRelMouseMode(mouse_grabbed);
618  
619          // Create surface
620 <        int depth = (VIDEO_MODE_DEPTH <= VIDEO_DEPTH_8BIT ? 8 : screen_depth);
620 >        int depth = ((int)VIDEO_MODE_DEPTH <= VIDEO_DEPTH_8BIT ? 8 : screen_depth);
621          if ((s = SDL_SetVideoMode(width, height, depth, SDL_HWSURFACE)) == NULL)
622                  return;
623  
# Line 576 | Line 629 | driver_window::driver_window(SDL_monitor
629          the_buffer = (uint8 *)vm_acquire(the_buffer_size);
630          the_buffer_copy = (uint8 *)malloc(the_buffer_size);
631          D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer));
632 +
633 +        // Check whether we can initialize the VOSF subsystem and it's profitable
634 +        if (!video_vosf_init(m)) {
635 +                WarningAlert(STR_VOSF_INIT_ERR);
636 +                use_vosf = false;
637 +        }
638 +        else if (!video_vosf_profitable()) {
639 +                video_vosf_exit();
640 +                printf("VOSF acceleration is not profitable on this platform, disabling it\n");
641 +                use_vosf = false;
642 +        }
643 +        if (!use_vosf) {
644 +                free(the_buffer_copy);
645 +                vm_release(the_buffer, the_buffer_size);
646 +                the_host_buffer = NULL;
647 +        }
648 + #endif
649 +        if (!use_vosf) {
650 +                // Allocate memory for frame buffer
651 +                the_buffer_size = (aligned_height + 2) * s->pitch;
652 +                the_buffer_copy = (uint8 *)calloc(1, the_buffer_size);
653 +                the_buffer = (uint8 *)calloc(1, the_buffer_size);
654 +                D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy));
655 +        }
656 +        
657 + #ifdef SHEEPSHAVER
658 +        // Create cursor
659 +        if ((sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, 0, 0)) != NULL) {
660 +                SDL_SetCursor(sdl_cursor);
661 +                cursor_changed = false;
662 +        }
663   #else
664 <        // Allocate memory for frame buffer
665 <        the_buffer_size = (aligned_height + 2) * s->pitch;
582 <        the_buffer_copy = (uint8 *)calloc(1, the_buffer_size);
583 <        the_buffer = (uint8 *)calloc(1, the_buffer_size);
584 <        D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy));
664 >        // Hide cursor
665 >        SDL_ShowCursor(0);
666   #endif
667  
668          // Set window name/class
669          set_window_name(STR_WINDOW_TITLE);
670  
590        // Hide cursor
591        SDL_ShowCursor(0);
592
671          // Init blitting routines
672          SDL_PixelFormat *f = s->format;
673          VisualFormat visualFormat;
# Line 708 | Line 786 | static void keycode_init(void)
786  
787                          if (video_driver_found) {
788                                  // Skip aliases
789 <                                static const char alias_str[] = "alias";
790 <                                if (strncmp(line, alias_str, sizeof(alias_str) - 1) == 0)
789 >                                static const char sdl_str[] = "sdl";
790 >                                if (strncmp(line, sdl_str, sizeof(sdl_str) - 1) == 0)
791                                          continue;
792  
793                                  // Read keycode
# Line 720 | Line 798 | static void keycode_init(void)
798                                          break;
799                          } else {
800                                  // Search for SDL video driver string
801 <                                static const char alias_sdl_str[] = "alias SDL";
802 <                                if (strncmp(line, alias_sdl_str, sizeof(alias_sdl_str) - 1) == 0) {
803 <                                        char *p = line + sizeof(alias_sdl_str);
801 >                                static const char sdl_str[] = "sdl";
802 >                                if (strncmp(line, sdl_str, sizeof(sdl_str) - 1) == 0) {
803 >                                        char *p = line + sizeof(sdl_str);
804                                          if (strstr(video_driver, p) == video_driver)
805                                                  video_driver_found = true;
806                                  }
# Line 748 | Line 826 | bool SDL_monitor_desc::video_open(void)
826   {
827          D(bug("video_open()\n"));
828          const VIDEO_MODE &mode = get_current_mode();
829 + #if DEBUG
830 +        D(bug("Current video mode:\n"));
831 +        D(bug(" %dx%d (ID %02x), %d bpp\n", VIDEO_MODE_X, VIDEO_MODE_Y, VIDEO_MODE_RESOLUTION, 1 << (VIDEO_MODE_DEPTH & 0x0f)));
832 + #endif
833  
834          // Create display driver object of requested type
835          switch (display_type) {
# Line 763 | Line 845 | bool SDL_monitor_desc::video_open(void)
845                  return false;
846          }
847  
766 #ifdef ENABLE_VOSF
767        if (use_vosf) {
768                // Initialize the VOSF system
769                if (!video_vosf_init(*this)) {
770                        ErrorAlert(STR_VOSF_INIT_ERR);
771                return false;
772                }
773        }
774 #endif
775        
848          // Initialize VideoRefresh function
849          VideoRefreshInit();
850  
# Line 820 | Line 892 | bool VideoInit(bool classic)
892          mouse_wheel_lines = PrefsFindInt32("mousewheellines");
893  
894          // Get screen mode from preferences
895 <        const char *mode_str;
895 >        const char *mode_str = NULL;
896 > #ifndef SHEEPSHAVER
897          if (classic_mode)
898                  mode_str = "win/512/342";
899          else
900                  mode_str = PrefsFindString("screen");
901 + #endif
902  
903          // Determine display type and default dimensions
904          int default_width, default_height;
# Line 842 | Line 916 | bool VideoInit(bool classic)
916                          display_type = DISPLAY_WINDOW;
917          }
918          int max_width = 640, max_height = 480;
919 <        if (display_type == DISPLAY_SCREEN) {
920 <                SDL_Rect **modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE);
921 <                if (modes && modes != (SDL_Rect **)-1) {
922 <                        max_width = modes[0]->w;
923 <                        max_height = modes[0]->h;
924 <                }
919 >        SDL_Rect **modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE);
920 >        if (modes && modes != (SDL_Rect **)-1) {
921 >                max_width = modes[0]->w;
922 >                max_height = modes[0]->h;
923 >                if (default_width > max_width)
924 >                        default_width = max_width;
925 >                if (default_height > max_height)
926 >                        default_height = max_height;
927          }
928          if (default_width <= 0)
929                  default_width = max_width;
# Line 914 | Line 990 | bool VideoInit(bool classic)
990          }
991  
992   #ifdef SHEEPSHAVER
993 <        for (int i = 0; i < VideoModes.size(); ++i)
993 >        for (int i = 0; i < VideoModes.size(); i++)
994                  VModes[i] = VideoModes[i];
995 <
996 <        const VIDEO_MODE & mode = VideoModes[cur_mode];
997 <        D(bug("Current video mode\n"));
998 <        D(bug(" %dx%d (ID %02x), %d bpp\n", VIDEO_MODE_X, VIDEO_MODE_Y, VIDEO_MODE_RESOLUTION, 1 << (VIDEO_MODE_DEPTH - 0x80)));
995 >        VideoInfo *p = &VModes[VideoModes.size()];
996 >        p->viType = DIS_INVALID;        // End marker
997 >        p->viRowBytes = 0;
998 >        p->viXsize = p->viYsize = 0;
999 >        p->viAppleMode = 0;
1000 >        p->viAppleID = 0;
1001   #endif
1002  
1003   #if DEBUG
# Line 1068 | Line 1146 | void SDL_monitor_desc::set_palette(uint8
1146          const VIDEO_MODE &mode = get_current_mode();
1147  
1148          // FIXME: how can we handle the gamma ramp?
1149 <        if (VIDEO_MODE_DEPTH > VIDEO_DEPTH_8BIT)
1149 >        if ((int)VIDEO_MODE_DEPTH > VIDEO_DEPTH_8BIT)
1150                  return;
1151  
1152          LOCK_PALETTE;
# Line 1093 | Line 1171 | void SDL_monitor_desc::set_palette(uint8
1171                  }
1172  
1173   #ifdef ENABLE_VOSF
1174 <                // We have to redraw everything because the interpretation of pixel values changed
1175 <                LOCK_VOSF;
1176 <                PFLAG_SET_ALL;
1177 <                UNLOCK_VOSF;
1178 <                memset(the_buffer_copy, 0, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y);
1174 >                if (use_vosf) {
1175 >                        // We have to redraw everything because the interpretation of pixel values changed
1176 >                        LOCK_VOSF;
1177 >                        PFLAG_SET_ALL;
1178 >                        UNLOCK_VOSF;
1179 >                        memset(the_buffer_copy, 0, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y);
1180 >                }
1181   #endif
1182          }
1183  
# Line 1168 | Line 1248 | void SDL_monitor_desc::switch_to_current
1248   #ifdef SHEEPSHAVER
1249   bool video_can_change_cursor(void)
1250   {
1251 < //      return hw_mac_cursor_accl && (display_type != DISPLAY_SCREEN);
1172 <        return false;
1251 >        return (display_type == DISPLAY_WINDOW);
1252   }
1253   #endif
1254  
# Line 1181 | Line 1260 | bool video_can_change_cursor(void)
1260   #ifdef SHEEPSHAVER
1261   void video_set_cursor(void)
1262   {
1263 < //      cursor_changed = true;
1263 >        cursor_changed = true;
1264   }
1265   #endif
1266  
1267  
1268   /*
1269 < *  Install graphics acceleration
1269 > *  Keyboard-related utilify functions
1270   */
1271  
1272 < #ifdef SHEEPSHAVER
1194 < // Rectangle inversion
1195 < template< int bpp >
1196 < static inline void do_invrect(uint8 *dest, uint32 length)
1197 < {
1198 < #define INVERT_1(PTR, OFS) ((uint8  *)(PTR))[OFS] = ~((uint8  *)(PTR))[OFS]
1199 < #define INVERT_2(PTR, OFS) ((uint16 *)(PTR))[OFS] = ~((uint16 *)(PTR))[OFS]
1200 < #define INVERT_4(PTR, OFS) ((uint32 *)(PTR))[OFS] = ~((uint32 *)(PTR))[OFS]
1201 < #define INVERT_8(PTR, OFS) ((uint64 *)(PTR))[OFS] = ~((uint64 *)(PTR))[OFS]
1202 <
1203 < #ifndef UNALIGNED_PROFITABLE
1204 <        // Align on 16-bit boundaries
1205 <        if (bpp < 16 && (((uintptr)dest) & 1)) {
1206 <                INVERT_1(dest, 0);
1207 <                dest += 1; length -= 1;
1208 <        }
1209 <
1210 <        // Align on 32-bit boundaries
1211 <        if (bpp < 32 && (((uintptr)dest) & 2)) {
1212 <                INVERT_2(dest, 0);
1213 <                dest += 2; length -= 2;
1214 <        }
1215 < #endif
1216 <
1217 <        // Invert 8-byte words
1218 <        if (length >= 8) {
1219 <                const int r = (length / 8) % 8;
1220 <                dest += r * 8;
1221 <
1222 <                int n = ((length / 8) + 7) / 8;
1223 <                switch (r) {
1224 <                case 0: do {
1225 <                                dest += 64;
1226 <                                INVERT_8(dest, -8);
1227 <                case 7: INVERT_8(dest, -7);
1228 <                case 6: INVERT_8(dest, -6);
1229 <                case 5: INVERT_8(dest, -5);
1230 <                case 4: INVERT_8(dest, -4);
1231 <                case 3: INVERT_8(dest, -3);
1232 <                case 2: INVERT_8(dest, -2);
1233 <                case 1: INVERT_8(dest, -1);
1234 <                                } while (--n > 0);
1235 <                }
1236 <        }
1237 <
1238 <        // 32-bit cell to invert?
1239 <        if (length & 4) {
1240 <                INVERT_4(dest, 0);
1241 <                if (bpp <= 16)
1242 <                        dest += 4;
1243 <        }
1244 <
1245 <        // 16-bit cell to invert?
1246 <        if (bpp <= 16 && (length & 2)) {
1247 <                INVERT_2(dest, 0);
1248 <                if (bpp <= 8)
1249 <                        dest += 2;
1250 <        }
1251 <
1252 <        // 8-bit cell to invert?
1253 <        if (bpp <= 8 && (length & 1))
1254 <                INVERT_1(dest, 0);
1255 <
1256 < #undef INVERT_1
1257 < #undef INVERT_2
1258 < #undef INVERT_4
1259 < #undef INVERT_8
1260 < }
1261 <
1262 < void NQD_invrect(uint32 p)
1263 < {
1264 <        D(bug("accl_invrect %08x\n", p));
1265 <
1266 <        // Get inversion parameters
1267 <        int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2);
1268 <        int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0);
1269 <        int16 width  = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2);
1270 <        int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0);
1271 <        D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y));
1272 <        D(bug(" width %d, height %d, bytes_per_row %d\n", width, height, (int32)ReadMacInt32(p + acclDestRowBytes)));
1273 <
1274 <        //!!?? pen_mode == 14
1275 <
1276 <        // And perform the inversion
1277 <        const int bpp = bytes_per_pixel(ReadMacInt32(p + acclDestPixelSize));
1278 <        const int dest_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes);
1279 <        uint8 *dest = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dest_row_bytes) + (dest_X * bpp));
1280 <        width *= bpp;
1281 <        switch (bpp) {
1282 <        case 1:
1283 <                for (int i = 0; i < height; i++) {
1284 <                        do_invrect<8>(dest, width);
1285 <                        dest += dest_row_bytes;
1286 <                }
1287 <                break;
1288 <        case 2:
1289 <                for (int i = 0; i < height; i++) {
1290 <                        do_invrect<16>(dest, width);
1291 <                        dest += dest_row_bytes;
1292 <                }
1293 <                break;
1294 <        case 4:
1295 <                for (int i = 0; i < height; i++) {
1296 <                        do_invrect<32>(dest, width);
1297 <                        dest += dest_row_bytes;
1298 <                }
1299 <                break;
1300 <        }
1301 < }
1302 <
1303 < // Rectangle filling
1304 < template< int bpp >
1305 < static inline void do_fillrect(uint8 *dest, uint32 color, uint32 length)
1306 < {
1307 < #define FILL_1(PTR, OFS, VAL) ((uint8  *)(PTR))[OFS] = (VAL)
1308 < #define FILL_2(PTR, OFS, VAL) ((uint16 *)(PTR))[OFS] = (VAL)
1309 < #define FILL_4(PTR, OFS, VAL) ((uint32 *)(PTR))[OFS] = (VAL)
1310 < #define FILL_8(PTR, OFS, VAL) ((uint64 *)(PTR))[OFS] = (VAL)
1311 <
1312 < #ifndef UNALIGNED_PROFITABLE
1313 <        // Align on 16-bit boundaries
1314 <        if (bpp < 16 && (((uintptr)dest) & 1)) {
1315 <                FILL_1(dest, 0, color);
1316 <                dest += 1; length -= 1;
1317 <        }
1318 <
1319 <        // Align on 32-bit boundaries
1320 <        if (bpp < 32 && (((uintptr)dest) & 2)) {
1321 <                FILL_2(dest, 0, color);
1322 <                dest += 2; length -= 2;
1323 <        }
1324 < #endif
1325 <
1326 <        // Fill 8-byte words
1327 <        if (length >= 8) {
1328 <                const uint64 c = (((uint64)color) << 32) | color;
1329 <                const int r = (length / 8) % 8;
1330 <                dest += r * 8;
1331 <
1332 <                int n = ((length / 8) + 7) / 8;
1333 <                switch (r) {
1334 <                case 0: do {
1335 <                                dest += 64;
1336 <                                FILL_8(dest, -8, c);
1337 <                case 7: FILL_8(dest, -7, c);
1338 <                case 6: FILL_8(dest, -6, c);
1339 <                case 5: FILL_8(dest, -5, c);
1340 <                case 4: FILL_8(dest, -4, c);
1341 <                case 3: FILL_8(dest, -3, c);
1342 <                case 2: FILL_8(dest, -2, c);
1343 <                case 1: FILL_8(dest, -1, c);
1344 <                                } while (--n > 0);
1345 <                }
1346 <        }
1347 <
1348 <        // 32-bit cell to fill?
1349 <        if (length & 4) {
1350 <                FILL_4(dest, 0, color);
1351 <                if (bpp <= 16)
1352 <                        dest += 4;
1353 <        }
1354 <
1355 <        // 16-bit cell to fill?
1356 <        if (bpp <= 16 && (length & 2)) {
1357 <                FILL_2(dest, 0, color);
1358 <                if (bpp <= 8)
1359 <                        dest += 2;
1360 <        }
1361 <
1362 <        // 8-bit cell to fill?
1363 <        if (bpp <= 8 && (length & 1))
1364 <                FILL_1(dest, 0, color);
1365 <
1366 < #undef FILL_1
1367 < #undef FILL_2
1368 < #undef FILL_4
1369 < #undef FILL_8
1370 < }
1371 <
1372 < void NQD_fillrect(uint32 p)
1373 < {
1374 <        D(bug("accl_fillrect %08x\n", p));
1375 <
1376 <        // Get filling parameters
1377 <        int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2);
1378 <        int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0);
1379 <        int16 width  = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2);
1380 <        int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0);
1381 <        uint32 color = htonl(ReadMacInt32(p + acclPenMode) == 8 ? ReadMacInt32(p + acclForePen) : ReadMacInt32(p + acclBackPen));
1382 <        D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y));
1383 <        D(bug(" width %d, height %d\n", width, height));
1384 <        D(bug(" bytes_per_row %d color %08x\n", (int32)ReadMacInt32(p + acclDestRowBytes), color));
1385 <
1386 <        // And perform the fill
1387 <        const int bpp = bytes_per_pixel(ReadMacInt32(p + acclDestPixelSize));
1388 <        const int dest_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes);
1389 <        uint8 *dest = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dest_row_bytes) + (dest_X * bpp));
1390 <        width *= bpp;
1391 <        switch (bpp) {
1392 <        case 1:
1393 <                for (int i = 0; i < height; i++) {
1394 <                        memset(dest, color, width);
1395 <                        dest += dest_row_bytes;
1396 <                }
1397 <                break;
1398 <        case 2:
1399 <                for (int i = 0; i < height; i++) {
1400 <                        do_fillrect<16>(dest, color, width);
1401 <                        dest += dest_row_bytes;
1402 <                }
1403 <                break;
1404 <        case 4:
1405 <                for (int i = 0; i < height; i++) {
1406 <                        do_fillrect<32>(dest, color, width);
1407 <                        dest += dest_row_bytes;
1408 <                }
1409 <                break;
1410 <        }
1411 < }
1412 <
1413 < bool NQD_fillrect_hook(uint32 p)
1272 > static bool is_modifier_key(SDL_KeyboardEvent const & e)
1273   {
1274 <        D(bug("accl_fillrect_hook %08x\n", p));
1275 <
1276 <        // Check if we can accelerate this fillrect
1277 <        if (ReadMacInt32(p + 0x284) != 0 && ReadMacInt32(p + acclDestPixelSize) >= 8) {
1278 <                const int transfer_mode = ReadMacInt32(p + acclTransferMode);
1279 <                if (transfer_mode == 8) {
1280 <                        // Fill
1281 <                        WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_FILLRECT));
1282 <                        return true;
1283 <                }
1284 <                else if (transfer_mode == 10) {
1285 <                        // Invert
1286 <                        WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_INVRECT));
1287 <                        return true;
1288 <                }
1289 <        }
1431 <        return false;
1432 < }
1433 <
1434 < // Rectangle blitting
1435 < // TODO: optimize for VOSF and target pixmap == screen
1436 < void NQD_bitblt(uint32 p)
1437 < {
1438 <        D(bug("accl_bitblt %08x\n", p));
1439 <
1440 <        // Get blitting parameters
1441 <        int16 src_X  = (int16)ReadMacInt16(p + acclSrcRect + 2) - (int16)ReadMacInt16(p + acclSrcBoundsRect + 2);
1442 <        int16 src_Y  = (int16)ReadMacInt16(p + acclSrcRect + 0) - (int16)ReadMacInt16(p + acclSrcBoundsRect + 0);
1443 <        int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2);
1444 <        int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0);
1445 <        int16 width  = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2);
1446 <        int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0);
1447 <        D(bug(" src addr %08x, dest addr %08x\n", ReadMacInt32(p + acclSrcBaseAddr), ReadMacInt32(p + acclDestBaseAddr)));
1448 <        D(bug(" src X %d, src Y %d, dest X %d, dest Y %d\n", src_X, src_Y, dest_X, dest_Y));
1449 <        D(bug(" width %d, height %d\n", width, height));
1450 <
1451 <        // And perform the blit
1452 <        const int bpp = bytes_per_pixel(ReadMacInt32(p + acclSrcPixelSize));
1453 <        width *= bpp;
1454 <        if ((int32)ReadMacInt32(p + acclSrcRowBytes) > 0) {
1455 <                const int src_row_bytes = (int32)ReadMacInt32(p + acclSrcRowBytes);
1456 <                const int dst_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes);
1457 <                uint8 *src = Mac2HostAddr(ReadMacInt32(p + acclSrcBaseAddr) + (src_Y * src_row_bytes) + (src_X * bpp));
1458 <                uint8 *dst = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dst_row_bytes) + (dest_X * bpp));
1459 <                for (int i = 0; i < height; i++) {
1460 <                        memmove(dst, src, width);
1461 <                        src += src_row_bytes;
1462 <                        dst += dst_row_bytes;
1463 <                }
1464 <        }
1465 <        else {
1466 <                const int src_row_bytes = -(int32)ReadMacInt32(p + acclSrcRowBytes);
1467 <                const int dst_row_bytes = -(int32)ReadMacInt32(p + acclDestRowBytes);
1468 <                uint8 *src = Mac2HostAddr(ReadMacInt32(p + acclSrcBaseAddr) + ((src_Y + height - 1) * src_row_bytes) + (src_X * bpp));
1469 <                uint8 *dst = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + ((dest_Y + height - 1) * dst_row_bytes) + (dest_X * bpp));
1470 <                for (int i = height - 1; i >= 0; i--) {
1471 <                        memmove(dst, src, width);
1472 <                        src -= src_row_bytes;
1473 <                        dst -= dst_row_bytes;
1474 <                }
1475 <        }
1476 < }
1477 <
1478 < /*
1479 <  BitBlt transfer modes:
1480 <  0 : srcCopy
1481 <  1 : srcOr
1482 <  2 : srcXor
1483 <  3 : srcBic
1484 <  4 : notSrcCopy
1485 <  5 : notSrcOr
1486 <  6 : notSrcXor
1487 <  7 : notSrcBic
1488 <  32 : blend
1489 <  33 : addPin
1490 <  34 : addOver
1491 <  35 : subPin
1492 <  36 : transparent
1493 <  37 : adMax
1494 <  38 : subOver
1495 <  39 : adMin
1496 <  50 : hilite
1497 < */
1498 <
1499 < bool NQD_bitblt_hook(uint32 p)
1500 < {
1501 <        D(bug("accl_draw_hook %08x\n", p));
1502 <
1503 <        // Check if we can accelerate this bitblt
1504 <        if (ReadMacInt32(p + 0x018) + ReadMacInt32(p + 0x128) == 0 &&
1505 <                ReadMacInt32(p + 0x130) == 0 &&
1506 <                ReadMacInt32(p + acclSrcPixelSize) >= 8 &&
1507 <                ReadMacInt32(p + acclSrcPixelSize) == ReadMacInt32(p + acclDestPixelSize) &&
1508 <                (ReadMacInt32(p + acclSrcRowBytes) ^ ReadMacInt32(p + acclDestRowBytes)) >= 0 && // same sign?
1509 <                ReadMacInt32(p + acclTransferMode) == 0 &&                                                                               // srcCopy?
1510 <                ReadMacInt32(p + 0x15c) > 0) {
1511 <
1512 <                // Yes, set function pointer
1513 <                WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_BITBLT));
1274 >        switch (e.keysym.sym) {
1275 >        case SDLK_NUMLOCK:
1276 >        case SDLK_CAPSLOCK:
1277 >        case SDLK_SCROLLOCK:
1278 >        case SDLK_RSHIFT:
1279 >        case SDLK_LSHIFT:
1280 >        case SDLK_RCTRL:
1281 >        case SDLK_LCTRL:
1282 >        case SDLK_RALT:
1283 >        case SDLK_LALT:
1284 >        case SDLK_RMETA:
1285 >        case SDLK_LMETA:
1286 >        case SDLK_LSUPER:
1287 >        case SDLK_RSUPER:
1288 >        case SDLK_MODE:
1289 >        case SDLK_COMPOSE:
1290                  return true;
1291          }
1292          return false;
1293   }
1294  
1295 < // Wait for graphics operation to finish
1520 < bool NQD_sync_hook(uint32 arg)
1521 < {
1522 <        D(bug("accl_sync_hook %08x\n", arg));
1523 <        return true;
1524 < }
1525 <
1526 < void VideoInstallAccel(void)
1295 > static bool is_ctrl_down(SDL_keysym const & ks)
1296   {
1297 <        // Install acceleration hooks
1529 <        if (PrefsFindBool("gfxaccel")) {
1530 <                D(bug("Video: Installing acceleration hooks\n"));
1531 <                uint32 base;
1532 <
1533 <                SheepVar bitblt_hook_info(sizeof(accl_hook_info));
1534 <                base = bitblt_hook_info.addr();
1535 <                WriteMacInt32(base + 0, NativeTVECT(NATIVE_BITBLT_HOOK));
1536 <                WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK));
1537 <                WriteMacInt32(base + 8, ACCL_BITBLT);
1538 <                NQDMisc(6, bitblt_hook_info.ptr());
1539 <
1540 <                SheepVar fillrect_hook_info(sizeof(accl_hook_info));
1541 <                base = fillrect_hook_info.addr();
1542 <                WriteMacInt32(base + 0, NativeTVECT(NATIVE_FILLRECT_HOOK));
1543 <                WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK));
1544 <                WriteMacInt32(base + 8, ACCL_FILLRECT);
1545 <                NQDMisc(6, fillrect_hook_info.ptr());
1546 <        }
1297 >        return ctrl_down || (ks.mod & KMOD_CTRL);
1298   }
1548 #endif
1299  
1300  
1301   /*
# Line 1553 | Line 1303 | void VideoInstallAccel(void)
1303   *  and -2 if the key was recognized as a hotkey
1304   */
1305  
1556 static bool is_ctrl_down(SDL_keysym const & ks)
1557 {
1558        return ctrl_down || (ks.mod & KMOD_CTRL);
1559 }
1560
1306   static int kc_decode(SDL_keysym const & ks, bool key_down)
1307   {
1308          switch (ks.sym) {
# Line 1627 | Line 1372 | static int kc_decode(SDL_keysym const &
1372          case SDLK_RCTRL: return 0x36;
1373          case SDLK_LSHIFT: return 0x38;
1374          case SDLK_RSHIFT: return 0x38;
1375 + #if (defined(__APPLE__) && defined(__MACH__))
1376 +        case SDLK_LALT: return 0x3a;
1377 +        case SDLK_RALT: return 0x3a;
1378 +        case SDLK_LMETA: return 0x37;
1379 +        case SDLK_RMETA: return 0x37;
1380 + #else
1381          case SDLK_LALT: return 0x37;
1382          case SDLK_RALT: return 0x37;
1383          case SDLK_LMETA: return 0x3a;
1384          case SDLK_RMETA: return 0x3a;
1385 + #endif
1386          case SDLK_MENU: return 0x32;
1387          case SDLK_CAPSLOCK: return 0x39;
1388          case SDLK_NUMLOCK: return 0x47;
# Line 1737 | Line 1489 | static void handle_events(void)
1489                          // Keyboard
1490                          case SDL_KEYDOWN: {
1491                                  int code = -1;
1492 <                                if (use_keycodes) {
1492 >                                if (use_keycodes && !is_modifier_key(event.key)) {
1493                                          if (event2keycode(event.key, true) != -2)       // This is called to process the hotkeys
1494                                                  code = keycode_table[event.key.keysym.scancode & 0xff];
1495                                  } else
# Line 1765 | Line 1517 | static void handle_events(void)
1517                          }
1518                          case SDL_KEYUP: {
1519                                  int code = -1;
1520 <                                if (use_keycodes) {
1520 >                                if (use_keycodes && !is_modifier_key(event.key)) {
1521                                          if (event2keycode(event.key, false) != -2)      // This is called to process the hotkeys
1522                                                  code = keycode_table[event.key.keysym.scancode & 0xff];
1523                                  } else
1524                                          code = event2keycode(event.key, false);
1525 <                                if (code >= 0 && code != 0x39) {        // Don't propagate Caps Lock releases
1526 <                                        ADBKeyUp(code);
1525 >                                if (code >= 0) {
1526 >                                        if (code == 0x39) {     // Caps Lock released
1527 >                                                if (caps_on) {
1528 >                                                        ADBKeyUp(code);
1529 >                                                        caps_on = false;
1530 >                                                } else {
1531 >                                                        ADBKeyDown(code);
1532 >                                                        caps_on = true;
1533 >                                                }
1534 >                                        } else
1535 >                                                ADBKeyUp(code);
1536                                          if (code == 0x36)
1537                                                  ctrl_down = false;
1538                                  }
# Line 1838 | Line 1599 | static void update_display_static(driver
1599  
1600          // Check for first column from left and first column from right that have changed
1601          if (high) {
1602 <                if (VIDEO_MODE_DEPTH < VIDEO_DEPTH_8BIT) {
1602 >                if ((int)VIDEO_MODE_DEPTH < VIDEO_DEPTH_8BIT) {
1603                          const int src_bytes_per_row = bytes_per_row;
1604                          const int dst_bytes_per_row = drv->s->pitch;
1605                          const int pixels_per_byte = VIDEO_MODE_X / src_bytes_per_row;
# Line 2105 | Line 1866 | static int redraw_func(void *arg)
1866                  // Refresh display
1867                  video_refresh();
1868  
1869 + #ifdef SHEEPSHAVER
1870 +                // Set new cursor image if it was changed
1871 +                if (cursor_changed && sdl_cursor) {
1872 +                        cursor_changed = false;
1873 +                        SDL_FreeCursor(sdl_cursor);
1874 +                        sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, MacCursor[2], MacCursor[3]);
1875 +                        if (sdl_cursor)
1876 +                                SDL_SetCursor(sdl_cursor);
1877 +                }
1878 + #endif
1879 +
1880                  // Set new palette if it was changed
1881                  handle_palette_changes();
1882          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines