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.12 by gbeauche, 2004-07-27T21:40:52Z

# 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 314 | Line 324 | static inline int bytes_per_pixel(int de
324   }
325  
326   // Map video_mode depth ID to numerical depth value
327 < static int sdl_depth_of_video_depth(int video_depth)
327 > static int mac_depth_of_video_depth(int video_depth)
328   {
329          int depth = -1;
330          switch (video_depth) {
# Line 342 | Line 352 | static int sdl_depth_of_video_depth(int
352          return depth;
353   }
354  
355 + // Map video_mode depth ID to SDL screen depth
356 + static int sdl_depth_of_video_depth(int video_depth)
357 + {
358 +        return (video_depth <= VIDEO_DEPTH_8BIT) ? 8 : mac_depth_of_video_depth(video_depth);
359 + }
360 +
361   // Check wether specified mode is available
362   static bool has_mode(int type, int width, int height)
363   {
# Line 402 | Line 418 | static void add_mode(int type, int width
418          VIDEO_MODE_Y = height;
419          VIDEO_MODE_RESOLUTION = resolution_id;
420          VIDEO_MODE_ROW_BYTES = bytes_per_row;
421 <        VIDEO_MODE_DEPTH = depth;
421 >        VIDEO_MODE_DEPTH = (video_depth)depth;
422          VideoModes.push_back(mode);
423   }
424  
# Line 576 | Line 592 | void driver_base::update_palette(void)
592   {
593          const VIDEO_MODE &mode = monitor.get_current_mode();
594  
595 <        if (VIDEO_MODE_DEPTH <= VIDEO_DEPTH_8BIT)
595 >        if ((int)VIDEO_MODE_DEPTH <= VIDEO_DEPTH_8BIT)
596                  SDL_SetPalette(s, SDL_PHYSPAL, sdl_palette, 0, 256);
597   }
598  
# Line 607 | Line 623 | driver_window::driver_window(SDL_monitor
623          ADBSetRelMouseMode(mouse_grabbed);
624  
625          // Create surface
626 <        int depth = (VIDEO_MODE_DEPTH <= VIDEO_DEPTH_8BIT ? 8 : screen_depth);
626 >        int depth = sdl_depth_of_video_depth(VIDEO_MODE_DEPTH);
627          if ((s = SDL_SetVideoMode(width, height, depth, SDL_HWSURFACE)) == NULL)
628                  return;
629  
# Line 619 | Line 635 | driver_window::driver_window(SDL_monitor
635          the_buffer = (uint8 *)vm_acquire(the_buffer_size);
636          the_buffer_copy = (uint8 *)malloc(the_buffer_size);
637          D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer));
638 +
639 +        // Check whether we can initialize the VOSF subsystem and it's profitable
640 +        if (!video_vosf_init(m)) {
641 +                WarningAlert(STR_VOSF_INIT_ERR);
642 +                use_vosf = false;
643 +        }
644 +        else if (!video_vosf_profitable()) {
645 +                video_vosf_exit();
646 +                printf("VOSF acceleration is not profitable on this platform, disabling it\n");
647 +                use_vosf = false;
648 +        }
649 +        if (!use_vosf) {
650 +                free(the_buffer_copy);
651 +                vm_release(the_buffer, the_buffer_size);
652 +                the_host_buffer = NULL;
653 +        }
654 + #endif
655 +        if (!use_vosf) {
656 +                // Allocate memory for frame buffer
657 +                the_buffer_size = (aligned_height + 2) * s->pitch;
658 +                the_buffer_copy = (uint8 *)calloc(1, the_buffer_size);
659 +                the_buffer = (uint8 *)calloc(1, the_buffer_size);
660 +                D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy));
661 +        }
662 +        
663 + #ifdef SHEEPSHAVER
664 +        // Create cursor
665 +        if ((sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, 0, 0)) != NULL) {
666 +                SDL_SetCursor(sdl_cursor);
667 +                cursor_changed = false;
668 +        }
669   #else
670 <        // Allocate memory for frame buffer
671 <        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));
670 >        // Hide cursor
671 >        SDL_ShowCursor(0);
672   #endif
673  
674          // Set window name/class
675          set_window_name(STR_WINDOW_TITLE);
676  
633        // Hide cursor
634        SDL_ShowCursor(0);
635
677          // Init blitting routines
678          SDL_PixelFormat *f = s->format;
679          VisualFormat visualFormat;
# Line 640 | Line 681 | driver_window::driver_window(SDL_monitor
681          visualFormat.Rmask = f->Rmask;
682          visualFormat.Gmask = f->Gmask;
683          visualFormat.Bmask = f->Bmask;
684 <        Screen_blitter_init(visualFormat, true, sdl_depth_of_video_depth(VIDEO_MODE_DEPTH));
684 >        Screen_blitter_init(visualFormat, true, mac_depth_of_video_depth(VIDEO_MODE_DEPTH));
685  
686          // Load gray ramp to 8->16/32 expand map
687          if (!IsDirectMode(mode))
# Line 751 | Line 792 | static void keycode_init(void)
792  
793                          if (video_driver_found) {
794                                  // Skip aliases
795 <                                static const char alias_str[] = "alias";
796 <                                if (strncmp(line, alias_str, sizeof(alias_str) - 1) == 0)
795 >                                static const char sdl_str[] = "sdl";
796 >                                if (strncmp(line, sdl_str, sizeof(sdl_str) - 1) == 0)
797                                          continue;
798  
799                                  // Read keycode
# Line 763 | Line 804 | static void keycode_init(void)
804                                          break;
805                          } else {
806                                  // Search for SDL video driver string
807 <                                static const char alias_sdl_str[] = "alias SDL";
808 <                                if (strncmp(line, alias_sdl_str, sizeof(alias_sdl_str) - 1) == 0) {
809 <                                        char *p = line + sizeof(alias_sdl_str);
807 >                                static const char sdl_str[] = "sdl";
808 >                                if (strncmp(line, sdl_str, sizeof(sdl_str) - 1) == 0) {
809 >                                        char *p = line + sizeof(sdl_str);
810                                          if (strstr(video_driver, p) == video_driver)
811                                                  video_driver_found = true;
812                                  }
# Line 810 | Line 851 | bool SDL_monitor_desc::video_open(void)
851                  return false;
852          }
853  
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        
854          // Initialize VideoRefresh function
855          VideoRefreshInit();
856  
# Line 929 | Line 960 | bool VideoInit(bool classic)
960                          add_mode(display_type, 512, 342, 0x80, 64, VIDEO_DEPTH_1BIT);
961                  else {
962                          for (int d = VIDEO_DEPTH_1BIT; d <= default_depth; d++) {
963 <                                int bpp = (d <= VIDEO_DEPTH_8BIT ? 8 : sdl_depth_of_video_depth(d));
963 >                                int bpp = sdl_depth_of_video_depth(d);
964                                  if (SDL_VideoModeOK(max_width, max_height, bpp, SDL_HWSURFACE))
965                                          add_window_modes(video_depth(d));
966                          }
# Line 1121 | Line 1152 | void SDL_monitor_desc::set_palette(uint8
1152          const VIDEO_MODE &mode = get_current_mode();
1153  
1154          // FIXME: how can we handle the gamma ramp?
1155 <        if (VIDEO_MODE_DEPTH > VIDEO_DEPTH_8BIT)
1155 >        if ((int)VIDEO_MODE_DEPTH > VIDEO_DEPTH_8BIT)
1156                  return;
1157  
1158          LOCK_PALETTE;
# Line 1146 | Line 1177 | void SDL_monitor_desc::set_palette(uint8
1177                  }
1178  
1179   #ifdef ENABLE_VOSF
1180 <                // We have to redraw everything because the interpretation of pixel values changed
1181 <                LOCK_VOSF;
1182 <                PFLAG_SET_ALL;
1183 <                UNLOCK_VOSF;
1184 <                memset(the_buffer_copy, 0, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y);
1180 >                if (use_vosf) {
1181 >                        // We have to redraw everything because the interpretation of pixel values changed
1182 >                        LOCK_VOSF;
1183 >                        PFLAG_SET_ALL;
1184 >                        UNLOCK_VOSF;
1185 >                        memset(the_buffer_copy, 0, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y);
1186 >                }
1187   #endif
1188          }
1189  
# Line 1221 | Line 1254 | void SDL_monitor_desc::switch_to_current
1254   #ifdef SHEEPSHAVER
1255   bool video_can_change_cursor(void)
1256   {
1257 < //      return hw_mac_cursor_accl && (display_type != DISPLAY_SCREEN);
1225 <        return false;
1257 >        return (display_type == DISPLAY_WINDOW);
1258   }
1259   #endif
1260  
# Line 1234 | Line 1266 | bool video_can_change_cursor(void)
1266   #ifdef SHEEPSHAVER
1267   void video_set_cursor(void)
1268   {
1269 < //      cursor_changed = true;
1269 >        cursor_changed = true;
1270   }
1271   #endif
1272  
1273  
1274   /*
1275 < *  Install graphics acceleration
1275 > *  Keyboard-related utilify functions
1276   */
1277  
1278 < #ifdef SHEEPSHAVER
1247 < // Rectangle inversion
1248 < template< int bpp >
1249 < static inline void do_invrect(uint8 *dest, uint32 length)
1250 < {
1251 < #define INVERT_1(PTR, OFS) ((uint8  *)(PTR))[OFS] = ~((uint8  *)(PTR))[OFS]
1252 < #define INVERT_2(PTR, OFS) ((uint16 *)(PTR))[OFS] = ~((uint16 *)(PTR))[OFS]
1253 < #define INVERT_4(PTR, OFS) ((uint32 *)(PTR))[OFS] = ~((uint32 *)(PTR))[OFS]
1254 < #define INVERT_8(PTR, OFS) ((uint64 *)(PTR))[OFS] = ~((uint64 *)(PTR))[OFS]
1255 <
1256 < #ifndef UNALIGNED_PROFITABLE
1257 <        // Align on 16-bit boundaries
1258 <        if (bpp < 16 && (((uintptr)dest) & 1)) {
1259 <                INVERT_1(dest, 0);
1260 <                dest += 1; length -= 1;
1261 <        }
1262 <
1263 <        // Align on 32-bit boundaries
1264 <        if (bpp < 32 && (((uintptr)dest) & 2)) {
1265 <                INVERT_2(dest, 0);
1266 <                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)
1278 > static bool is_modifier_key(SDL_KeyboardEvent const & e)
1279   {
1280 <        D(bug("accl_invrect %08x\n", p));
1281 <
1282 <        // Get inversion parameters
1283 <        int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2);
1284 <        int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0);
1285 <        int16 width  = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2);
1286 <        int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0);
1287 <        D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y));
1288 <        D(bug(" width %d, height %d, bytes_per_row %d\n", width, height, (int32)ReadMacInt32(p + acclDestRowBytes)));
1289 <
1290 <        //!!?? pen_mode == 14
1291 <
1292 <        // And perform the inversion
1293 <        const int bpp = bytes_per_pixel(ReadMacInt32(p + acclDestPixelSize));
1294 <        const int dest_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes);
1295 <        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));
1280 >        switch (e.keysym.sym) {
1281 >        case SDLK_NUMLOCK:
1282 >        case SDLK_CAPSLOCK:
1283 >        case SDLK_SCROLLOCK:
1284 >        case SDLK_RSHIFT:
1285 >        case SDLK_LSHIFT:
1286 >        case SDLK_RCTRL:
1287 >        case SDLK_LCTRL:
1288 >        case SDLK_RALT:
1289 >        case SDLK_LALT:
1290 >        case SDLK_RMETA:
1291 >        case SDLK_LMETA:
1292 >        case SDLK_LSUPER:
1293 >        case SDLK_RSUPER:
1294 >        case SDLK_MODE:
1295 >        case SDLK_COMPOSE:
1296                  return true;
1297          }
1298          return false;
1299   }
1300  
1301 < // 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)
1301 > static bool is_ctrl_down(SDL_keysym const & ks)
1302   {
1303 <        // 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 <        }
1303 >        return ctrl_down || (ks.mod & KMOD_CTRL);
1304   }
1601 #endif
1305  
1306  
1307   /*
# Line 1606 | Line 1309 | void VideoInstallAccel(void)
1309   *  and -2 if the key was recognized as a hotkey
1310   */
1311  
1609 static bool is_ctrl_down(SDL_keysym const & ks)
1610 {
1611        return ctrl_down || (ks.mod & KMOD_CTRL);
1612 }
1613
1312   static int kc_decode(SDL_keysym const & ks, bool key_down)
1313   {
1314          switch (ks.sym) {
# Line 1680 | Line 1378 | static int kc_decode(SDL_keysym const &
1378          case SDLK_RCTRL: return 0x36;
1379          case SDLK_LSHIFT: return 0x38;
1380          case SDLK_RSHIFT: return 0x38;
1381 + #if (defined(__APPLE__) && defined(__MACH__))
1382 +        case SDLK_LALT: return 0x3a;
1383 +        case SDLK_RALT: return 0x3a;
1384 +        case SDLK_LMETA: return 0x37;
1385 +        case SDLK_RMETA: return 0x37;
1386 + #else
1387          case SDLK_LALT: return 0x37;
1388          case SDLK_RALT: return 0x37;
1389          case SDLK_LMETA: return 0x3a;
1390          case SDLK_RMETA: return 0x3a;
1391 + #endif
1392          case SDLK_MENU: return 0x32;
1393          case SDLK_CAPSLOCK: return 0x39;
1394          case SDLK_NUMLOCK: return 0x47;
# Line 1790 | Line 1495 | static void handle_events(void)
1495                          // Keyboard
1496                          case SDL_KEYDOWN: {
1497                                  int code = -1;
1498 <                                if (use_keycodes) {
1498 >                                if (use_keycodes && !is_modifier_key(event.key)) {
1499                                          if (event2keycode(event.key, true) != -2)       // This is called to process the hotkeys
1500                                                  code = keycode_table[event.key.keysym.scancode & 0xff];
1501                                  } else
# Line 1818 | Line 1523 | static void handle_events(void)
1523                          }
1524                          case SDL_KEYUP: {
1525                                  int code = -1;
1526 <                                if (use_keycodes) {
1526 >                                if (use_keycodes && !is_modifier_key(event.key)) {
1527                                          if (event2keycode(event.key, false) != -2)      // This is called to process the hotkeys
1528                                                  code = keycode_table[event.key.keysym.scancode & 0xff];
1529                                  } else
1530                                          code = event2keycode(event.key, false);
1531 <                                if (code >= 0 && code != 0x39) {        // Don't propagate Caps Lock releases
1532 <                                        ADBKeyUp(code);
1531 >                                if (code >= 0) {
1532 >                                        if (code == 0x39) {     // Caps Lock released
1533 >                                                if (caps_on) {
1534 >                                                        ADBKeyUp(code);
1535 >                                                        caps_on = false;
1536 >                                                } else {
1537 >                                                        ADBKeyDown(code);
1538 >                                                        caps_on = true;
1539 >                                                }
1540 >                                        } else
1541 >                                                ADBKeyUp(code);
1542                                          if (code == 0x36)
1543                                                  ctrl_down = false;
1544                                  }
# Line 1891 | Line 1605 | static void update_display_static(driver
1605  
1606          // Check for first column from left and first column from right that have changed
1607          if (high) {
1608 <                if (VIDEO_MODE_DEPTH < VIDEO_DEPTH_8BIT) {
1608 >                if ((int)VIDEO_MODE_DEPTH < VIDEO_DEPTH_8BIT) {
1609                          const int src_bytes_per_row = bytes_per_row;
1610                          const int dst_bytes_per_row = drv->s->pitch;
1611                          const int pixels_per_byte = VIDEO_MODE_X / src_bytes_per_row;
# Line 2158 | Line 1872 | static int redraw_func(void *arg)
1872                  // Refresh display
1873                  video_refresh();
1874  
1875 + #ifdef SHEEPSHAVER
1876 +                // Set new cursor image if it was changed
1877 +                if (cursor_changed && sdl_cursor) {
1878 +                        cursor_changed = false;
1879 +                        SDL_FreeCursor(sdl_cursor);
1880 +                        sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, MacCursor[2], MacCursor[3]);
1881 +                        if (sdl_cursor)
1882 +                                SDL_SetCursor(sdl_cursor);
1883 +                }
1884 + #endif
1885 +
1886                  // Set new palette if it was changed
1887                  handle_palette_changes();
1888          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines