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.7 by gbeauche, 2004-06-26T15:22:01Z vs.
Revision 1.13 by gbeauche, 2004-11-28T19:31:11Z

# Line 37 | Line 37
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 *  - Move generic Native QuickDraw acceleration routines to gfxaccel.cpp
40   */
41  
42   #include "sysdeps.h"
# Line 57 | Line 56
56   #include "video.h"
57   #include "video_defs.h"
58   #include "video_blit.h"
59 + #include "vm_alloc.h"
60  
61   #define DEBUG 0
62   #include "debug.h"
# Line 97 | Line 97 | static uint32 the_buffer_size;                                         // S
97   static bool redraw_thread_active = false;                       // Flag: Redraw thread installed
98   static volatile bool redraw_thread_cancel;                      // Flag: Cancel Redraw thread
99   static SDL_Thread *redraw_thread = NULL;                        // Redraw thread
100 + static volatile bool thread_stop_req = false;
101 + static volatile bool thread_stop_ack = false;           // Acknowledge for thread_stop_req
102  
103   #ifdef ENABLE_VOSF
104   static bool use_vosf = false;                                           // Flag: VOSF enabled
# Line 146 | Line 148 | extern void SysMountFirstFloppy(void);
148  
149  
150   /*
151 + *  Framebuffer allocation routines
152 + */
153 +
154 + static void *vm_acquire_framebuffer(uint32 size)
155 + {
156 + #ifdef SHEEPSHAVER
157 + #ifdef DIRECT_ADDRESSING_HACK
158 +        const uint32 FRAME_BUFFER_BASE = 0x61000000;
159 +        uint8 *fb = Mac2HostAddr(FRAME_BUFFER_BASE);
160 +        if (vm_acquire_fixed(fb, size) < 0)
161 +                fb = VM_MAP_FAILED;
162 +        return fb;
163 + #endif
164 + #endif
165 +        return vm_acquire(size);
166 + }
167 +
168 + static inline void vm_release_framebuffer(void *fb, uint32 size)
169 + {
170 +        vm_release(fb, size);
171 + }
172 +
173 +
174 + /*
175   *  SheepShaver glue
176   */
177  
# Line 325 | Line 351 | static inline int bytes_per_pixel(int de
351   }
352  
353   // Map video_mode depth ID to numerical depth value
354 < static int sdl_depth_of_video_depth(int video_depth)
354 > static int mac_depth_of_video_depth(int video_depth)
355   {
356          int depth = -1;
357          switch (video_depth) {
# Line 353 | Line 379 | static int sdl_depth_of_video_depth(int
379          return depth;
380   }
381  
382 + // Map video_mode depth ID to SDL screen depth
383 + static int sdl_depth_of_video_depth(int video_depth)
384 + {
385 +        return (video_depth <= VIDEO_DEPTH_8BIT) ? 8 : mac_depth_of_video_depth(video_depth);
386 + }
387 +
388   // Check wether specified mode is available
389   static bool has_mode(int type, int width, int height)
390   {
# Line 413 | Line 445 | static void add_mode(int type, int width
445          VIDEO_MODE_Y = height;
446          VIDEO_MODE_RESOLUTION = resolution_id;
447          VIDEO_MODE_ROW_BYTES = bytes_per_row;
448 <        VIDEO_MODE_DEPTH = depth;
448 >        VIDEO_MODE_DEPTH = (video_depth)depth;
449          VideoModes.push_back(mode);
450   }
451  
# Line 549 | Line 581 | driver_base::~driver_base()
581          if (s)
582                  SDL_FreeSurface(s);
583  
584 +        // the_buffer shall always be mapped through vm_acquire_framebuffer()
585 +        if (the_buffer != VM_MAP_FAILED) {
586 +                D(bug(" releasing the_buffer at %p (%d bytes)\n", the_buffer, the_buffer_size));
587 +                vm_release_framebuffer(the_buffer, the_buffer_size);
588 +                the_buffer = NULL;
589 +        }
590 +
591          // Free frame buffer(s)
592          if (!use_vosf) {
554                if (the_buffer) {
555                        free(the_buffer);
556                        the_buffer = NULL;
557                }
593                  if (the_buffer_copy) {
594                          free(the_buffer_copy);
595                          the_buffer_copy = NULL;
# Line 562 | Line 597 | driver_base::~driver_base()
597          }
598   #ifdef ENABLE_VOSF
599          else {
565                // the_buffer shall always be mapped through vm_acquire() so that we can vm_protect() it at will
566                if (the_buffer != VM_MAP_FAILED) {
567                        D(bug(" releasing the_buffer at %p (%d bytes)\n", the_buffer, the_buffer_size));
568                        vm_release(the_buffer, the_buffer_size);
569                        the_buffer = NULL;
570                }
600                  if (the_host_buffer) {
601                          D(bug(" freeing the_host_buffer at %p\n", the_host_buffer));
602                          free(the_host_buffer);
# Line 578 | Line 607 | driver_base::~driver_base()
607                          free(the_buffer_copy);
608                          the_buffer_copy = NULL;
609                  }
610 +
611 +                // Deinitialize VOSF
612 +                video_vosf_exit();
613          }
614   #endif
615   }
# Line 587 | Line 619 | void driver_base::update_palette(void)
619   {
620          const VIDEO_MODE &mode = monitor.get_current_mode();
621  
622 <        if (VIDEO_MODE_DEPTH <= VIDEO_DEPTH_8BIT)
622 >        if ((int)VIDEO_MODE_DEPTH <= VIDEO_DEPTH_8BIT)
623                  SDL_SetPalette(s, SDL_PHYSPAL, sdl_palette, 0, 256);
624   }
625  
# Line 618 | Line 650 | driver_window::driver_window(SDL_monitor
650          ADBSetRelMouseMode(mouse_grabbed);
651  
652          // Create surface
653 <        int depth = (VIDEO_MODE_DEPTH <= VIDEO_DEPTH_8BIT ? 8 : screen_depth);
653 >        int depth = sdl_depth_of_video_depth(VIDEO_MODE_DEPTH);
654          if ((s = SDL_SetVideoMode(width, height, depth, SDL_HWSURFACE)) == NULL)
655                  return;
656  
# Line 627 | Line 659 | driver_window::driver_window(SDL_monitor
659          // Allocate memory for frame buffer (SIZE is extended to page-boundary)
660          the_host_buffer = (uint8 *)s->pixels;
661          the_buffer_size = page_extend((aligned_height + 2) * s->pitch);
662 <        the_buffer = (uint8 *)vm_acquire(the_buffer_size);
662 >        the_buffer = (uint8 *)vm_acquire_framebuffer(the_buffer_size);
663          the_buffer_copy = (uint8 *)malloc(the_buffer_size);
664          D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer));
665  
# Line 638 | Line 670 | driver_window::driver_window(SDL_monitor
670          }
671          else if (!video_vosf_profitable()) {
672                  video_vosf_exit();
673 <                // WarningAlert(STR_VOSF_NOT_PROFITABLE_WARN);
642 <                printf("VOSF acceleration is not profitable on this platform\n");
673 >                printf("VOSF acceleration is not profitable on this platform, disabling it\n");
674                  use_vosf = false;
675          }
676          if (!use_vosf) {
# Line 652 | Line 683 | driver_window::driver_window(SDL_monitor
683                  // Allocate memory for frame buffer
684                  the_buffer_size = (aligned_height + 2) * s->pitch;
685                  the_buffer_copy = (uint8 *)calloc(1, the_buffer_size);
686 <                the_buffer = (uint8 *)calloc(1, the_buffer_size);
686 >                the_buffer = (uint8 *)vm_acquire_framebuffer(the_buffer_size);
687                  D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy));
688          }
689          
# Line 677 | Line 708 | driver_window::driver_window(SDL_monitor
708          visualFormat.Rmask = f->Rmask;
709          visualFormat.Gmask = f->Gmask;
710          visualFormat.Bmask = f->Bmask;
711 <        Screen_blitter_init(visualFormat, true, sdl_depth_of_video_depth(VIDEO_MODE_DEPTH));
711 >        Screen_blitter_init(visualFormat, true, mac_depth_of_video_depth(VIDEO_MODE_DEPTH));
712  
713          // Load gray ramp to 8->16/32 expand map
714          if (!IsDirectMode(mode))
# Line 788 | Line 819 | static void keycode_init(void)
819  
820                          if (video_driver_found) {
821                                  // Skip aliases
822 <                                static const char alias_str[] = "alias";
823 <                                if (strncmp(line, alias_str, sizeof(alias_str) - 1) == 0)
822 >                                static const char sdl_str[] = "sdl";
823 >                                if (strncmp(line, sdl_str, sizeof(sdl_str) - 1) == 0)
824                                          continue;
825  
826                                  // Read keycode
# Line 800 | Line 831 | static void keycode_init(void)
831                                          break;
832                          } else {
833                                  // Search for SDL video driver string
834 <                                static const char alias_sdl_str[] = "alias SDL";
835 <                                if (strncmp(line, alias_sdl_str, sizeof(alias_sdl_str) - 1) == 0) {
836 <                                        char *p = line + sizeof(alias_sdl_str);
834 >                                static const char sdl_str[] = "sdl";
835 >                                if (strncmp(line, sdl_str, sizeof(sdl_str) - 1) == 0) {
836 >                                        char *p = line + sizeof(sdl_str);
837                                          if (strstr(video_driver, p) == video_driver)
838                                                  video_driver_found = true;
839                                  }
# Line 956 | Line 987 | bool VideoInit(bool classic)
987                          add_mode(display_type, 512, 342, 0x80, 64, VIDEO_DEPTH_1BIT);
988                  else {
989                          for (int d = VIDEO_DEPTH_1BIT; d <= default_depth; d++) {
990 <                                int bpp = (d <= VIDEO_DEPTH_8BIT ? 8 : sdl_depth_of_video_depth(d));
990 >                                int bpp = sdl_depth_of_video_depth(d);
991                                  if (SDL_VideoModeOK(max_width, max_height, bpp, SDL_HWSURFACE))
992                                          add_window_modes(video_depth(d));
993                          }
# Line 1044 | Line 1075 | void SDL_monitor_desc::video_close(void)
1075          UNLOCK_FRAME_BUFFER;
1076          D(bug(" frame buffer unlocked\n"));
1077  
1047 #ifdef ENABLE_VOSF
1048        if (use_vosf) {
1049                // Deinitialize VOSF
1050                video_vosf_exit();
1051        }
1052 #endif
1053
1078          // Close display
1079          delete drv;
1080          drv = NULL;
# Line 1148 | Line 1172 | void SDL_monitor_desc::set_palette(uint8
1172          const VIDEO_MODE &mode = get_current_mode();
1173  
1174          // FIXME: how can we handle the gamma ramp?
1175 <        if (VIDEO_MODE_DEPTH > VIDEO_DEPTH_8BIT)
1175 >        if ((int)VIDEO_MODE_DEPTH > VIDEO_DEPTH_8BIT)
1176                  return;
1177  
1178          LOCK_PALETTE;
# Line 1209 | Line 1233 | int16 video_mode_change(VidLocals *csSav
1233                          csSave->saveData = ReadMacInt32(ParamPtr + csData);
1234                          csSave->savePage = ReadMacInt16(ParamPtr + csPage);
1235  
1236 <                        // Disable interrupts
1236 >                        // Disable interrupts and pause redraw thread
1237                          DisableInterrupt();
1238 +                        thread_stop_ack = false;
1239 +                        thread_stop_req = true;
1240 +                        while (!thread_stop_ack) ;
1241  
1242                          cur_mode = i;
1243                          monitor_desc *monitor = VideoMonitors[0];
# Line 1221 | Line 1248 | int16 video_mode_change(VidLocals *csSav
1248                          csSave->saveData=VModes[cur_mode].viAppleID;/* First mode ... */
1249                          csSave->saveMode=VModes[cur_mode].viAppleMode;
1250  
1251 <                        // Enable interrupts
1251 >                        // Enable interrupts and resume redraw thread
1252 >                        thread_stop_req = false;
1253                          EnableInterrupt();
1254                          return noErr;
1255                  }
# Line 1268 | Line 1296 | void video_set_cursor(void)
1296  
1297  
1298   /*
1299 < *  Install graphics acceleration
1299 > *  Keyboard-related utilify functions
1300   */
1301  
1302 < #ifdef SHEEPSHAVER
1275 < // Rectangle inversion
1276 < template< int bpp >
1277 < static inline void do_invrect(uint8 *dest, uint32 length)
1278 < {
1279 < #define INVERT_1(PTR, OFS) ((uint8  *)(PTR))[OFS] = ~((uint8  *)(PTR))[OFS]
1280 < #define INVERT_2(PTR, OFS) ((uint16 *)(PTR))[OFS] = ~((uint16 *)(PTR))[OFS]
1281 < #define INVERT_4(PTR, OFS) ((uint32 *)(PTR))[OFS] = ~((uint32 *)(PTR))[OFS]
1282 < #define INVERT_8(PTR, OFS) ((uint64 *)(PTR))[OFS] = ~((uint64 *)(PTR))[OFS]
1283 <
1284 < #ifndef UNALIGNED_PROFITABLE
1285 <        // Align on 16-bit boundaries
1286 <        if (bpp < 16 && (((uintptr)dest) & 1)) {
1287 <                INVERT_1(dest, 0);
1288 <                dest += 1; length -= 1;
1289 <        }
1290 <
1291 <        // Align on 32-bit boundaries
1292 <        if (bpp < 32 && (((uintptr)dest) & 2)) {
1293 <                INVERT_2(dest, 0);
1294 <                dest += 2; length -= 2;
1295 <        }
1296 < #endif
1297 <
1298 <        // Invert 8-byte words
1299 <        if (length >= 8) {
1300 <                const int r = (length / 8) % 8;
1301 <                dest += r * 8;
1302 <
1303 <                int n = ((length / 8) + 7) / 8;
1304 <                switch (r) {
1305 <                case 0: do {
1306 <                                dest += 64;
1307 <                                INVERT_8(dest, -8);
1308 <                case 7: INVERT_8(dest, -7);
1309 <                case 6: INVERT_8(dest, -6);
1310 <                case 5: INVERT_8(dest, -5);
1311 <                case 4: INVERT_8(dest, -4);
1312 <                case 3: INVERT_8(dest, -3);
1313 <                case 2: INVERT_8(dest, -2);
1314 <                case 1: INVERT_8(dest, -1);
1315 <                                } while (--n > 0);
1316 <                }
1317 <        }
1318 <
1319 <        // 32-bit cell to invert?
1320 <        if (length & 4) {
1321 <                INVERT_4(dest, 0);
1322 <                if (bpp <= 16)
1323 <                        dest += 4;
1324 <        }
1325 <
1326 <        // 16-bit cell to invert?
1327 <        if (bpp <= 16 && (length & 2)) {
1328 <                INVERT_2(dest, 0);
1329 <                if (bpp <= 8)
1330 <                        dest += 2;
1331 <        }
1332 <
1333 <        // 8-bit cell to invert?
1334 <        if (bpp <= 8 && (length & 1))
1335 <                INVERT_1(dest, 0);
1336 <
1337 < #undef INVERT_1
1338 < #undef INVERT_2
1339 < #undef INVERT_4
1340 < #undef INVERT_8
1341 < }
1342 <
1343 < void NQD_invrect(uint32 p)
1302 > static bool is_modifier_key(SDL_KeyboardEvent const & e)
1303   {
1304 <        D(bug("accl_invrect %08x\n", p));
1305 <
1306 <        // Get inversion parameters
1307 <        int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2);
1308 <        int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0);
1309 <        int16 width  = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2);
1310 <        int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0);
1311 <        D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y));
1312 <        D(bug(" width %d, height %d, bytes_per_row %d\n", width, height, (int32)ReadMacInt32(p + acclDestRowBytes)));
1313 <
1314 <        //!!?? pen_mode == 14
1315 <
1316 <        // And perform the inversion
1317 <        const int bpp = bytes_per_pixel(ReadMacInt32(p + acclDestPixelSize));
1318 <        const int dest_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes);
1319 <        uint8 *dest = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dest_row_bytes) + (dest_X * bpp));
1361 <        width *= bpp;
1362 <        switch (bpp) {
1363 <        case 1:
1364 <                for (int i = 0; i < height; i++) {
1365 <                        do_invrect<8>(dest, width);
1366 <                        dest += dest_row_bytes;
1367 <                }
1368 <                break;
1369 <        case 2:
1370 <                for (int i = 0; i < height; i++) {
1371 <                        do_invrect<16>(dest, width);
1372 <                        dest += dest_row_bytes;
1373 <                }
1374 <                break;
1375 <        case 4:
1376 <                for (int i = 0; i < height; i++) {
1377 <                        do_invrect<32>(dest, width);
1378 <                        dest += dest_row_bytes;
1379 <                }
1380 <                break;
1381 <        }
1382 < }
1383 <
1384 < // Rectangle filling
1385 < template< int bpp >
1386 < static inline void do_fillrect(uint8 *dest, uint32 color, uint32 length)
1387 < {
1388 < #define FILL_1(PTR, OFS, VAL) ((uint8  *)(PTR))[OFS] = (VAL)
1389 < #define FILL_2(PTR, OFS, VAL) ((uint16 *)(PTR))[OFS] = (VAL)
1390 < #define FILL_4(PTR, OFS, VAL) ((uint32 *)(PTR))[OFS] = (VAL)
1391 < #define FILL_8(PTR, OFS, VAL) ((uint64 *)(PTR))[OFS] = (VAL)
1392 <
1393 < #ifndef UNALIGNED_PROFITABLE
1394 <        // Align on 16-bit boundaries
1395 <        if (bpp < 16 && (((uintptr)dest) & 1)) {
1396 <                FILL_1(dest, 0, color);
1397 <                dest += 1; length -= 1;
1398 <        }
1399 <
1400 <        // Align on 32-bit boundaries
1401 <        if (bpp < 32 && (((uintptr)dest) & 2)) {
1402 <                FILL_2(dest, 0, color);
1403 <                dest += 2; length -= 2;
1404 <        }
1405 < #endif
1406 <
1407 <        // Fill 8-byte words
1408 <        if (length >= 8) {
1409 <                const uint64 c = (((uint64)color) << 32) | color;
1410 <                const int r = (length / 8) % 8;
1411 <                dest += r * 8;
1412 <
1413 <                int n = ((length / 8) + 7) / 8;
1414 <                switch (r) {
1415 <                case 0: do {
1416 <                                dest += 64;
1417 <                                FILL_8(dest, -8, c);
1418 <                case 7: FILL_8(dest, -7, c);
1419 <                case 6: FILL_8(dest, -6, c);
1420 <                case 5: FILL_8(dest, -5, c);
1421 <                case 4: FILL_8(dest, -4, c);
1422 <                case 3: FILL_8(dest, -3, c);
1423 <                case 2: FILL_8(dest, -2, c);
1424 <                case 1: FILL_8(dest, -1, c);
1425 <                                } while (--n > 0);
1426 <                }
1427 <        }
1428 <
1429 <        // 32-bit cell to fill?
1430 <        if (length & 4) {
1431 <                FILL_4(dest, 0, color);
1432 <                if (bpp <= 16)
1433 <                        dest += 4;
1434 <        }
1435 <
1436 <        // 16-bit cell to fill?
1437 <        if (bpp <= 16 && (length & 2)) {
1438 <                FILL_2(dest, 0, color);
1439 <                if (bpp <= 8)
1440 <                        dest += 2;
1441 <        }
1442 <
1443 <        // 8-bit cell to fill?
1444 <        if (bpp <= 8 && (length & 1))
1445 <                FILL_1(dest, 0, color);
1446 <
1447 < #undef FILL_1
1448 < #undef FILL_2
1449 < #undef FILL_4
1450 < #undef FILL_8
1451 < }
1452 <
1453 < void NQD_fillrect(uint32 p)
1454 < {
1455 <        D(bug("accl_fillrect %08x\n", p));
1456 <
1457 <        // Get filling parameters
1458 <        int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2);
1459 <        int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0);
1460 <        int16 width  = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2);
1461 <        int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0);
1462 <        uint32 color = htonl(ReadMacInt32(p + acclPenMode) == 8 ? ReadMacInt32(p + acclForePen) : ReadMacInt32(p + acclBackPen));
1463 <        D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y));
1464 <        D(bug(" width %d, height %d\n", width, height));
1465 <        D(bug(" bytes_per_row %d color %08x\n", (int32)ReadMacInt32(p + acclDestRowBytes), color));
1466 <
1467 <        // And perform the fill
1468 <        const int bpp = bytes_per_pixel(ReadMacInt32(p + acclDestPixelSize));
1469 <        const int dest_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes);
1470 <        uint8 *dest = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dest_row_bytes) + (dest_X * bpp));
1471 <        width *= bpp;
1472 <        switch (bpp) {
1473 <        case 1:
1474 <                for (int i = 0; i < height; i++) {
1475 <                        memset(dest, color, width);
1476 <                        dest += dest_row_bytes;
1477 <                }
1478 <                break;
1479 <        case 2:
1480 <                for (int i = 0; i < height; i++) {
1481 <                        do_fillrect<16>(dest, color, width);
1482 <                        dest += dest_row_bytes;
1483 <                }
1484 <                break;
1485 <        case 4:
1486 <                for (int i = 0; i < height; i++) {
1487 <                        do_fillrect<32>(dest, color, width);
1488 <                        dest += dest_row_bytes;
1489 <                }
1490 <                break;
1491 <        }
1492 < }
1493 <
1494 < bool NQD_fillrect_hook(uint32 p)
1495 < {
1496 <        D(bug("accl_fillrect_hook %08x\n", p));
1497 <
1498 <        // Check if we can accelerate this fillrect
1499 <        if (ReadMacInt32(p + 0x284) != 0 && ReadMacInt32(p + acclDestPixelSize) >= 8) {
1500 <                const int transfer_mode = ReadMacInt32(p + acclTransferMode);
1501 <                if (transfer_mode == 8) {
1502 <                        // Fill
1503 <                        WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_FILLRECT));
1504 <                        return true;
1505 <                }
1506 <                else if (transfer_mode == 10) {
1507 <                        // Invert
1508 <                        WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_INVRECT));
1509 <                        return true;
1510 <                }
1511 <        }
1512 <        return false;
1513 < }
1514 <
1515 < // Rectangle blitting
1516 < // TODO: optimize for VOSF and target pixmap == screen
1517 < void NQD_bitblt(uint32 p)
1518 < {
1519 <        D(bug("accl_bitblt %08x\n", p));
1520 <
1521 <        // Get blitting parameters
1522 <        int16 src_X  = (int16)ReadMacInt16(p + acclSrcRect + 2) - (int16)ReadMacInt16(p + acclSrcBoundsRect + 2);
1523 <        int16 src_Y  = (int16)ReadMacInt16(p + acclSrcRect + 0) - (int16)ReadMacInt16(p + acclSrcBoundsRect + 0);
1524 <        int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2);
1525 <        int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0);
1526 <        int16 width  = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2);
1527 <        int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0);
1528 <        D(bug(" src addr %08x, dest addr %08x\n", ReadMacInt32(p + acclSrcBaseAddr), ReadMacInt32(p + acclDestBaseAddr)));
1529 <        D(bug(" src X %d, src Y %d, dest X %d, dest Y %d\n", src_X, src_Y, dest_X, dest_Y));
1530 <        D(bug(" width %d, height %d\n", width, height));
1531 <
1532 <        // And perform the blit
1533 <        const int bpp = bytes_per_pixel(ReadMacInt32(p + acclSrcPixelSize));
1534 <        width *= bpp;
1535 <        if ((int32)ReadMacInt32(p + acclSrcRowBytes) > 0) {
1536 <                const int src_row_bytes = (int32)ReadMacInt32(p + acclSrcRowBytes);
1537 <                const int dst_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes);
1538 <                uint8 *src = Mac2HostAddr(ReadMacInt32(p + acclSrcBaseAddr) + (src_Y * src_row_bytes) + (src_X * bpp));
1539 <                uint8 *dst = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dst_row_bytes) + (dest_X * bpp));
1540 <                for (int i = 0; i < height; i++) {
1541 <                        memmove(dst, src, width);
1542 <                        src += src_row_bytes;
1543 <                        dst += dst_row_bytes;
1544 <                }
1545 <        }
1546 <        else {
1547 <                const int src_row_bytes = -(int32)ReadMacInt32(p + acclSrcRowBytes);
1548 <                const int dst_row_bytes = -(int32)ReadMacInt32(p + acclDestRowBytes);
1549 <                uint8 *src = Mac2HostAddr(ReadMacInt32(p + acclSrcBaseAddr) + ((src_Y + height - 1) * src_row_bytes) + (src_X * bpp));
1550 <                uint8 *dst = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + ((dest_Y + height - 1) * dst_row_bytes) + (dest_X * bpp));
1551 <                for (int i = height - 1; i >= 0; i--) {
1552 <                        memmove(dst, src, width);
1553 <                        src -= src_row_bytes;
1554 <                        dst -= dst_row_bytes;
1555 <                }
1556 <        }
1557 < }
1558 <
1559 < /*
1560 <  BitBlt transfer modes:
1561 <  0 : srcCopy
1562 <  1 : srcOr
1563 <  2 : srcXor
1564 <  3 : srcBic
1565 <  4 : notSrcCopy
1566 <  5 : notSrcOr
1567 <  6 : notSrcXor
1568 <  7 : notSrcBic
1569 <  32 : blend
1570 <  33 : addPin
1571 <  34 : addOver
1572 <  35 : subPin
1573 <  36 : transparent
1574 <  37 : adMax
1575 <  38 : subOver
1576 <  39 : adMin
1577 <  50 : hilite
1578 < */
1579 <
1580 < bool NQD_bitblt_hook(uint32 p)
1581 < {
1582 <        D(bug("accl_draw_hook %08x\n", p));
1583 <
1584 <        // Check if we can accelerate this bitblt
1585 <        if (ReadMacInt32(p + 0x018) + ReadMacInt32(p + 0x128) == 0 &&
1586 <                ReadMacInt32(p + 0x130) == 0 &&
1587 <                ReadMacInt32(p + acclSrcPixelSize) >= 8 &&
1588 <                ReadMacInt32(p + acclSrcPixelSize) == ReadMacInt32(p + acclDestPixelSize) &&
1589 <                (ReadMacInt32(p + acclSrcRowBytes) ^ ReadMacInt32(p + acclDestRowBytes)) >= 0 && // same sign?
1590 <                ReadMacInt32(p + acclTransferMode) == 0 &&                                                                               // srcCopy?
1591 <                ReadMacInt32(p + 0x15c) > 0) {
1592 <
1593 <                // Yes, set function pointer
1594 <                WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_BITBLT));
1304 >        switch (e.keysym.sym) {
1305 >        case SDLK_NUMLOCK:
1306 >        case SDLK_CAPSLOCK:
1307 >        case SDLK_SCROLLOCK:
1308 >        case SDLK_RSHIFT:
1309 >        case SDLK_LSHIFT:
1310 >        case SDLK_RCTRL:
1311 >        case SDLK_LCTRL:
1312 >        case SDLK_RALT:
1313 >        case SDLK_LALT:
1314 >        case SDLK_RMETA:
1315 >        case SDLK_LMETA:
1316 >        case SDLK_LSUPER:
1317 >        case SDLK_RSUPER:
1318 >        case SDLK_MODE:
1319 >        case SDLK_COMPOSE:
1320                  return true;
1321          }
1322          return false;
1323   }
1324  
1325 < // Wait for graphics operation to finish
1601 < bool NQD_sync_hook(uint32 arg)
1602 < {
1603 <        D(bug("accl_sync_hook %08x\n", arg));
1604 <        return true;
1605 < }
1606 <
1607 < void VideoInstallAccel(void)
1325 > static bool is_ctrl_down(SDL_keysym const & ks)
1326   {
1327 <        // Install acceleration hooks
1610 <        if (PrefsFindBool("gfxaccel")) {
1611 <                D(bug("Video: Installing acceleration hooks\n"));
1612 <                uint32 base;
1613 <
1614 <                SheepVar bitblt_hook_info(sizeof(accl_hook_info));
1615 <                base = bitblt_hook_info.addr();
1616 <                WriteMacInt32(base + 0, NativeTVECT(NATIVE_BITBLT_HOOK));
1617 <                WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK));
1618 <                WriteMacInt32(base + 8, ACCL_BITBLT);
1619 <                NQDMisc(6, bitblt_hook_info.ptr());
1620 <
1621 <                SheepVar fillrect_hook_info(sizeof(accl_hook_info));
1622 <                base = fillrect_hook_info.addr();
1623 <                WriteMacInt32(base + 0, NativeTVECT(NATIVE_FILLRECT_HOOK));
1624 <                WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK));
1625 <                WriteMacInt32(base + 8, ACCL_FILLRECT);
1626 <                NQDMisc(6, fillrect_hook_info.ptr());
1627 <        }
1327 >        return ctrl_down || (ks.mod & KMOD_CTRL);
1328   }
1629 #endif
1329  
1330  
1331   /*
# Line 1634 | Line 1333 | void VideoInstallAccel(void)
1333   *  and -2 if the key was recognized as a hotkey
1334   */
1335  
1637 static bool is_ctrl_down(SDL_keysym const & ks)
1638 {
1639        return ctrl_down || (ks.mod & KMOD_CTRL);
1640 }
1641
1336   static int kc_decode(SDL_keysym const & ks, bool key_down)
1337   {
1338          switch (ks.sym) {
# Line 1708 | Line 1402 | static int kc_decode(SDL_keysym const &
1402          case SDLK_RCTRL: return 0x36;
1403          case SDLK_LSHIFT: return 0x38;
1404          case SDLK_RSHIFT: return 0x38;
1405 + #if (defined(__APPLE__) && defined(__MACH__))
1406 +        case SDLK_LALT: return 0x3a;
1407 +        case SDLK_RALT: return 0x3a;
1408 +        case SDLK_LMETA: return 0x37;
1409 +        case SDLK_RMETA: return 0x37;
1410 + #else
1411          case SDLK_LALT: return 0x37;
1412          case SDLK_RALT: return 0x37;
1413          case SDLK_LMETA: return 0x3a;
1414          case SDLK_RMETA: return 0x3a;
1415 + #endif
1416          case SDLK_MENU: return 0x32;
1417          case SDLK_CAPSLOCK: return 0x39;
1418          case SDLK_NUMLOCK: return 0x47;
# Line 1818 | Line 1519 | static void handle_events(void)
1519                          // Keyboard
1520                          case SDL_KEYDOWN: {
1521                                  int code = -1;
1522 <                                if (use_keycodes) {
1522 >                                if (use_keycodes && !is_modifier_key(event.key)) {
1523                                          if (event2keycode(event.key, true) != -2)       // This is called to process the hotkeys
1524                                                  code = keycode_table[event.key.keysym.scancode & 0xff];
1525                                  } else
# Line 1846 | Line 1547 | static void handle_events(void)
1547                          }
1548                          case SDL_KEYUP: {
1549                                  int code = -1;
1550 <                                if (use_keycodes) {
1550 >                                if (use_keycodes && !is_modifier_key(event.key)) {
1551                                          if (event2keycode(event.key, false) != -2)      // This is called to process the hotkeys
1552                                                  code = keycode_table[event.key.keysym.scancode & 0xff];
1553                                  } else
1554                                          code = event2keycode(event.key, false);
1555 <                                if (code >= 0 && code != 0x39) {        // Don't propagate Caps Lock releases
1556 <                                        ADBKeyUp(code);
1555 >                                if (code >= 0) {
1556 >                                        if (code == 0x39) {     // Caps Lock released
1557 >                                                if (caps_on) {
1558 >                                                        ADBKeyUp(code);
1559 >                                                        caps_on = false;
1560 >                                                } else {
1561 >                                                        ADBKeyDown(code);
1562 >                                                        caps_on = true;
1563 >                                                }
1564 >                                        } else
1565 >                                                ADBKeyUp(code);
1566                                          if (code == 0x36)
1567                                                  ctrl_down = false;
1568                                  }
# Line 1919 | Line 1629 | static void update_display_static(driver
1629  
1630          // Check for first column from left and first column from right that have changed
1631          if (high) {
1632 <                if (VIDEO_MODE_DEPTH < VIDEO_DEPTH_8BIT) {
1632 >                if ((int)VIDEO_MODE_DEPTH < VIDEO_DEPTH_8BIT) {
1633                          const int src_bytes_per_row = bytes_per_row;
1634                          const int dst_bytes_per_row = drv->s->pitch;
1635                          const int pixels_per_byte = VIDEO_MODE_X / src_bytes_per_row;
# Line 2180 | Line 1890 | static int redraw_func(void *arg)
1890                          next = GetTicks_usec();
1891                  ticks++;
1892  
1893 + #ifdef SHEEPSHAVER
1894 +                // Pause if requested (during video mode switches)
1895 +                if (thread_stop_req) {
1896 +                        thread_stop_ack = true;
1897 +                        continue;
1898 +                }
1899 + #endif
1900 +
1901                  // Handle SDL events
1902                  handle_events();
1903  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines