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.6 by gbeauche, 2004-06-24T22:38:42Z vs.
Revision 1.17 by gbeauche, 2005-03-19T05:34:15Z

# Line 1 | Line 1
1   /*
2   *  video_sdl.cpp - Video/graphics emulation, SDL specific stuff
3   *
4 < *  Basilisk II (C) 1997-2004 Christian Bauer
4 > *  Basilisk II (C) 1997-2005 Christian Bauer
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 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 82 | Line 82 | static int display_type = DISPLAY_WINDOW
82   #endif
83  
84   // Constants
85 + #ifdef WIN32
86 + const char KEYCODE_FILE_NAME[] = "BasiliskII_keycodes";
87 + #else
88   const char KEYCODE_FILE_NAME[] = DATADIR "/keycodes";
89 + #endif
90  
91  
92   // Global variables
# Line 97 | Line 101 | static uint32 the_buffer_size;                                         // S
101   static bool redraw_thread_active = false;                       // Flag: Redraw thread installed
102   static volatile bool redraw_thread_cancel;                      // Flag: Cancel Redraw thread
103   static SDL_Thread *redraw_thread = NULL;                        // Redraw thread
104 + static volatile bool thread_stop_req = false;
105 + static volatile bool thread_stop_ack = false;           // Acknowledge for thread_stop_req
106  
107   #ifdef ENABLE_VOSF
108 < static bool use_vosf = true;                                            // Flag: VOSF enabled
108 > static bool use_vosf = false;                                           // Flag: VOSF enabled
109   #else
110   static const bool use_vosf = false;                                     // VOSF not possible
111   #endif
# Line 146 | Line 152 | extern void SysMountFirstFloppy(void);
152  
153  
154   /*
155 + *  Framebuffer allocation routines
156 + */
157 +
158 + static void *vm_acquire_framebuffer(uint32 size)
159 + {
160 + #ifdef SHEEPSHAVER
161 + #ifdef DIRECT_ADDRESSING_HACK
162 +        const uint32 FRAME_BUFFER_BASE = 0x61000000;
163 +        uint8 *fb = Mac2HostAddr(FRAME_BUFFER_BASE);
164 +        if (vm_acquire_fixed(fb, size) < 0)
165 +                fb = VM_MAP_FAILED;
166 +        return fb;
167 + #endif
168 + #endif
169 +        return vm_acquire(size);
170 + }
171 +
172 + static inline void vm_release_framebuffer(void *fb, uint32 size)
173 + {
174 +        vm_release(fb, size);
175 + }
176 +
177 +
178 + /*
179   *  SheepShaver glue
180   */
181  
# Line 260 | Line 290 | static void ErrorAlert(int error)
290   {
291          ErrorAlert(GetString(error));
292   }
293 +
294 + // Display warning alert
295 + static void WarningAlert(int warning)
296 + {
297 +        WarningAlert(GetString(warning));
298 + }
299   #endif
300  
301  
# Line 319 | Line 355 | static inline int bytes_per_pixel(int de
355   }
356  
357   // Map video_mode depth ID to numerical depth value
358 < static int sdl_depth_of_video_depth(int video_depth)
358 > static int mac_depth_of_video_depth(int video_depth)
359   {
360          int depth = -1;
361          switch (video_depth) {
# Line 347 | Line 383 | static int sdl_depth_of_video_depth(int
383          return depth;
384   }
385  
386 + // Map video_mode depth ID to SDL screen depth
387 + static int sdl_depth_of_video_depth(int video_depth)
388 + {
389 +        return (video_depth <= VIDEO_DEPTH_8BIT) ? 8 : mac_depth_of_video_depth(video_depth);
390 + }
391 +
392   // Check wether specified mode is available
393   static bool has_mode(int type, int width, int height)
394   {
# Line 407 | Line 449 | static void add_mode(int type, int width
449          VIDEO_MODE_Y = height;
450          VIDEO_MODE_RESOLUTION = resolution_id;
451          VIDEO_MODE_ROW_BYTES = bytes_per_row;
452 <        VIDEO_MODE_DEPTH = depth;
452 >        VIDEO_MODE_DEPTH = (video_depth)depth;
453          VideoModes.push_back(mode);
454   }
455  
# Line 543 | Line 585 | driver_base::~driver_base()
585          if (s)
586                  SDL_FreeSurface(s);
587  
588 +        // the_buffer shall always be mapped through vm_acquire_framebuffer()
589 +        if (the_buffer != VM_MAP_FAILED) {
590 +                D(bug(" releasing the_buffer at %p (%d bytes)\n", the_buffer, the_buffer_size));
591 +                vm_release_framebuffer(the_buffer, the_buffer_size);
592 +                the_buffer = NULL;
593 +        }
594 +
595          // Free frame buffer(s)
596          if (!use_vosf) {
548                if (the_buffer) {
549                        free(the_buffer);
550                        the_buffer = NULL;
551                }
597                  if (the_buffer_copy) {
598                          free(the_buffer_copy);
599                          the_buffer_copy = NULL;
# Line 556 | Line 601 | driver_base::~driver_base()
601          }
602   #ifdef ENABLE_VOSF
603          else {
559                // the_buffer shall always be mapped through vm_acquire() so that we can vm_protect() it at will
560                if (the_buffer != VM_MAP_FAILED) {
561                        D(bug(" releasing the_buffer at %p (%d bytes)\n", the_buffer, the_buffer_size));
562                        vm_release(the_buffer, the_buffer_size);
563                        the_buffer = NULL;
564                }
604                  if (the_host_buffer) {
605                          D(bug(" freeing the_host_buffer at %p\n", the_host_buffer));
606                          free(the_host_buffer);
# Line 572 | Line 611 | driver_base::~driver_base()
611                          free(the_buffer_copy);
612                          the_buffer_copy = NULL;
613                  }
614 +
615 +                // Deinitialize VOSF
616 +                video_vosf_exit();
617          }
618   #endif
619   }
# Line 581 | Line 623 | void driver_base::update_palette(void)
623   {
624          const VIDEO_MODE &mode = monitor.get_current_mode();
625  
626 <        if (VIDEO_MODE_DEPTH <= VIDEO_DEPTH_8BIT)
626 >        if ((int)VIDEO_MODE_DEPTH <= VIDEO_DEPTH_8BIT)
627                  SDL_SetPalette(s, SDL_PHYSPAL, sdl_palette, 0, 256);
628   }
629  
# Line 612 | Line 654 | driver_window::driver_window(SDL_monitor
654          ADBSetRelMouseMode(mouse_grabbed);
655  
656          // Create surface
657 <        int depth = (VIDEO_MODE_DEPTH <= VIDEO_DEPTH_8BIT ? 8 : screen_depth);
657 >        int depth = sdl_depth_of_video_depth(VIDEO_MODE_DEPTH);
658          if ((s = SDL_SetVideoMode(width, height, depth, SDL_HWSURFACE)) == NULL)
659                  return;
660  
# Line 621 | Line 663 | driver_window::driver_window(SDL_monitor
663          // Allocate memory for frame buffer (SIZE is extended to page-boundary)
664          the_host_buffer = (uint8 *)s->pixels;
665          the_buffer_size = page_extend((aligned_height + 2) * s->pitch);
666 <        the_buffer = (uint8 *)vm_acquire(the_buffer_size);
666 >        the_buffer = (uint8 *)vm_acquire_framebuffer(the_buffer_size);
667          the_buffer_copy = (uint8 *)malloc(the_buffer_size);
668          D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer));
627 #else
628        // Allocate memory for frame buffer
629        the_buffer_size = (aligned_height + 2) * s->pitch;
630        the_buffer_copy = (uint8 *)calloc(1, the_buffer_size);
631        the_buffer = (uint8 *)calloc(1, the_buffer_size);
632        D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy));
633 #endif
669  
670 +        // Check whether we can initialize the VOSF subsystem and it's profitable
671 +        if (!video_vosf_init(m)) {
672 +                WarningAlert(STR_VOSF_INIT_ERR);
673 +                use_vosf = false;
674 +        }
675 +        else if (!video_vosf_profitable()) {
676 +                video_vosf_exit();
677 +                printf("VOSF acceleration is not profitable on this platform, disabling it\n");
678 +                use_vosf = false;
679 +        }
680 +        if (!use_vosf) {
681 +                free(the_buffer_copy);
682 +                vm_release(the_buffer, the_buffer_size);
683 +                the_host_buffer = NULL;
684 +        }
685 + #endif
686 +        if (!use_vosf) {
687 +                // Allocate memory for frame buffer
688 +                the_buffer_size = (aligned_height + 2) * s->pitch;
689 +                the_buffer_copy = (uint8 *)calloc(1, the_buffer_size);
690 +                the_buffer = (uint8 *)vm_acquire_framebuffer(the_buffer_size);
691 +                D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy));
692 +        }
693 +        
694   #ifdef SHEEPSHAVER
695          // Create cursor
696          if ((sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, 0, 0)) != NULL) {
# Line 653 | Line 712 | driver_window::driver_window(SDL_monitor
712          visualFormat.Rmask = f->Rmask;
713          visualFormat.Gmask = f->Gmask;
714          visualFormat.Bmask = f->Bmask;
715 <        Screen_blitter_init(visualFormat, true, sdl_depth_of_video_depth(VIDEO_MODE_DEPTH));
715 >        Screen_blitter_init(visualFormat, true, mac_depth_of_video_depth(VIDEO_MODE_DEPTH));
716  
717          // Load gray ramp to 8->16/32 expand map
718          if (!IsDirectMode(mode))
# Line 751 | Line 810 | static void keycode_init(void)
810                  SDL_VideoDriverName(video_driver, sizeof(video_driver));
811                  bool video_driver_found = false;
812                  char line[256];
813 +                int n_keys = 0;
814                  while (fgets(line, sizeof(line) - 1, f)) {
815                          // Read line
816                          int len = strlen(line);
# Line 763 | Line 823 | static void keycode_init(void)
823                                  continue;
824  
825                          if (video_driver_found) {
826 <                                // Skip aliases
827 <                                static const char alias_str[] = "alias";
828 <                                if (strncmp(line, alias_str, sizeof(alias_str) - 1) == 0)
826 >                                // Skip aliases as long as we have read keycodes yet
827 >                                // Otherwise, it's another mapping and we have to stop
828 >                                static const char sdl_str[] = "sdl";
829 >                                if (strncmp(line, sdl_str, sizeof(sdl_str) - 1) == 0 && n_keys == 0)
830                                          continue;
831  
832                                  // Read keycode
833                                  int x_code, mac_code;
834                                  if (sscanf(line, "%d %d", &x_code, &mac_code) == 2)
835 <                                        keycode_table[x_code & 0xff] = mac_code;
835 >                                        keycode_table[x_code & 0xff] = mac_code, n_keys++;
836                                  else
837                                          break;
838                          } else {
839                                  // Search for SDL video driver string
840 <                                static const char alias_sdl_str[] = "alias SDL";
841 <                                if (strncmp(line, alias_sdl_str, sizeof(alias_sdl_str) - 1) == 0) {
842 <                                        char *p = line + sizeof(alias_sdl_str);
840 >                                static const char sdl_str[] = "sdl";
841 >                                if (strncmp(line, sdl_str, sizeof(sdl_str) - 1) == 0) {
842 >                                        char *p = line + sizeof(sdl_str);
843                                          if (strstr(video_driver, p) == video_driver)
844                                                  video_driver_found = true;
845                                  }
# Line 796 | Line 857 | static void keycode_init(void)
857                          WarningAlert(str);
858                          return;
859                  }
860 +
861 +                D(bug("Using SDL/%s keycodes table, %d key mappings\n", video_driver, n_keys));
862          }
863   }
864  
# Line 823 | Line 886 | bool SDL_monitor_desc::video_open(void)
886                  return false;
887          }
888  
826 #ifdef ENABLE_VOSF
827        if (use_vosf) {
828                // Initialize the VOSF system
829                if (!video_vosf_init(*this)) {
830                        ErrorAlert(STR_VOSF_INIT_ERR);
831                return false;
832                }
833        }
834 #endif
835        
889          // Initialize VideoRefresh function
890          VideoRefreshInit();
891  
# Line 906 | Line 959 | bool VideoInit(bool classic)
959          int max_width = 640, max_height = 480;
960          SDL_Rect **modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE);
961          if (modes && modes != (SDL_Rect **)-1) {
962 <                max_width = modes[0]->w;
963 <                max_height = modes[0]->h;
962 >                // It turns out that on some implementations, and contrary to the documentation,
963 >                // the returned list is not sorted from largest to smallest (e.g. Windows)
964 >                for (int i = 0; modes[i] != NULL; i++) {
965 >                        const int w = modes[i]->w;
966 >                        const int h = modes[i]->h;
967 >                        if (w > max_width && h > max_height) {
968 >                                max_width = w;
969 >                                max_height = h;
970 >                        }
971 >                }
972                  if (default_width > max_width)
973                          default_width = max_width;
974                  if (default_height > max_height)
# Line 942 | Line 1003 | bool VideoInit(bool classic)
1003                          add_mode(display_type, 512, 342, 0x80, 64, VIDEO_DEPTH_1BIT);
1004                  else {
1005                          for (int d = VIDEO_DEPTH_1BIT; d <= default_depth; d++) {
1006 <                                int bpp = (d <= VIDEO_DEPTH_8BIT ? 8 : sdl_depth_of_video_depth(d));
1006 >                                int bpp = sdl_depth_of_video_depth(d);
1007                                  if (SDL_VideoModeOK(max_width, max_height, bpp, SDL_HWSURFACE))
1008                                          add_window_modes(video_depth(d));
1009                          }
# Line 1030 | Line 1091 | void SDL_monitor_desc::video_close(void)
1091          UNLOCK_FRAME_BUFFER;
1092          D(bug(" frame buffer unlocked\n"));
1093  
1033 #ifdef ENABLE_VOSF
1034        if (use_vosf) {
1035                // Deinitialize VOSF
1036                video_vosf_exit();
1037        }
1038 #endif
1039
1094          // Close display
1095          delete drv;
1096          drv = NULL;
# Line 1134 | Line 1188 | void SDL_monitor_desc::set_palette(uint8
1188          const VIDEO_MODE &mode = get_current_mode();
1189  
1190          // FIXME: how can we handle the gamma ramp?
1191 <        if (VIDEO_MODE_DEPTH > VIDEO_DEPTH_8BIT)
1191 >        if ((int)VIDEO_MODE_DEPTH > VIDEO_DEPTH_8BIT)
1192                  return;
1193  
1194          LOCK_PALETTE;
# Line 1159 | Line 1213 | void SDL_monitor_desc::set_palette(uint8
1213                  }
1214  
1215   #ifdef ENABLE_VOSF
1216 <                // We have to redraw everything because the interpretation of pixel values changed
1217 <                LOCK_VOSF;
1218 <                PFLAG_SET_ALL;
1219 <                UNLOCK_VOSF;
1220 <                memset(the_buffer_copy, 0, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y);
1216 >                if (use_vosf) {
1217 >                        // We have to redraw everything because the interpretation of pixel values changed
1218 >                        LOCK_VOSF;
1219 >                        PFLAG_SET_ALL;
1220 >                        UNLOCK_VOSF;
1221 >                        memset(the_buffer_copy, 0, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y);
1222 >                }
1223   #endif
1224          }
1225  
# Line 1193 | Line 1249 | int16 video_mode_change(VidLocals *csSav
1249                          csSave->saveData = ReadMacInt32(ParamPtr + csData);
1250                          csSave->savePage = ReadMacInt16(ParamPtr + csPage);
1251  
1252 <                        // Disable interrupts
1252 >                        // Disable interrupts and pause redraw thread
1253                          DisableInterrupt();
1254 +                        thread_stop_ack = false;
1255 +                        thread_stop_req = true;
1256 +                        while (!thread_stop_ack) ;
1257  
1258                          cur_mode = i;
1259                          monitor_desc *monitor = VideoMonitors[0];
# Line 1205 | Line 1264 | int16 video_mode_change(VidLocals *csSav
1264                          csSave->saveData=VModes[cur_mode].viAppleID;/* First mode ... */
1265                          csSave->saveMode=VModes[cur_mode].viAppleMode;
1266  
1267 <                        // Enable interrupts
1267 >                        // Enable interrupts and resume redraw thread
1268 >                        thread_stop_req = false;
1269                          EnableInterrupt();
1270                          return noErr;
1271                  }
# Line 1252 | Line 1312 | void video_set_cursor(void)
1312  
1313  
1314   /*
1315 < *  Install graphics acceleration
1315 > *  Keyboard-related utilify functions
1316   */
1317  
1318 < #ifdef SHEEPSHAVER
1259 < // Rectangle inversion
1260 < template< int bpp >
1261 < static inline void do_invrect(uint8 *dest, uint32 length)
1262 < {
1263 < #define INVERT_1(PTR, OFS) ((uint8  *)(PTR))[OFS] = ~((uint8  *)(PTR))[OFS]
1264 < #define INVERT_2(PTR, OFS) ((uint16 *)(PTR))[OFS] = ~((uint16 *)(PTR))[OFS]
1265 < #define INVERT_4(PTR, OFS) ((uint32 *)(PTR))[OFS] = ~((uint32 *)(PTR))[OFS]
1266 < #define INVERT_8(PTR, OFS) ((uint64 *)(PTR))[OFS] = ~((uint64 *)(PTR))[OFS]
1267 <
1268 < #ifndef UNALIGNED_PROFITABLE
1269 <        // Align on 16-bit boundaries
1270 <        if (bpp < 16 && (((uintptr)dest) & 1)) {
1271 <                INVERT_1(dest, 0);
1272 <                dest += 1; length -= 1;
1273 <        }
1274 <
1275 <        // Align on 32-bit boundaries
1276 <        if (bpp < 32 && (((uintptr)dest) & 2)) {
1277 <                INVERT_2(dest, 0);
1278 <                dest += 2; length -= 2;
1279 <        }
1280 < #endif
1281 <
1282 <        // Invert 8-byte words
1283 <        if (length >= 8) {
1284 <                const int r = (length / 8) % 8;
1285 <                dest += r * 8;
1286 <
1287 <                int n = ((length / 8) + 7) / 8;
1288 <                switch (r) {
1289 <                case 0: do {
1290 <                                dest += 64;
1291 <                                INVERT_8(dest, -8);
1292 <                case 7: INVERT_8(dest, -7);
1293 <                case 6: INVERT_8(dest, -6);
1294 <                case 5: INVERT_8(dest, -5);
1295 <                case 4: INVERT_8(dest, -4);
1296 <                case 3: INVERT_8(dest, -3);
1297 <                case 2: INVERT_8(dest, -2);
1298 <                case 1: INVERT_8(dest, -1);
1299 <                                } while (--n > 0);
1300 <                }
1301 <        }
1302 <
1303 <        // 32-bit cell to invert?
1304 <        if (length & 4) {
1305 <                INVERT_4(dest, 0);
1306 <                if (bpp <= 16)
1307 <                        dest += 4;
1308 <        }
1309 <
1310 <        // 16-bit cell to invert?
1311 <        if (bpp <= 16 && (length & 2)) {
1312 <                INVERT_2(dest, 0);
1313 <                if (bpp <= 8)
1314 <                        dest += 2;
1315 <        }
1316 <
1317 <        // 8-bit cell to invert?
1318 <        if (bpp <= 8 && (length & 1))
1319 <                INVERT_1(dest, 0);
1320 <
1321 < #undef INVERT_1
1322 < #undef INVERT_2
1323 < #undef INVERT_4
1324 < #undef INVERT_8
1325 < }
1326 <
1327 < void NQD_invrect(uint32 p)
1328 < {
1329 <        D(bug("accl_invrect %08x\n", p));
1330 <
1331 <        // Get inversion parameters
1332 <        int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2);
1333 <        int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0);
1334 <        int16 width  = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2);
1335 <        int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0);
1336 <        D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y));
1337 <        D(bug(" width %d, height %d, bytes_per_row %d\n", width, height, (int32)ReadMacInt32(p + acclDestRowBytes)));
1338 <
1339 <        //!!?? pen_mode == 14
1340 <
1341 <        // And perform the inversion
1342 <        const int bpp = bytes_per_pixel(ReadMacInt32(p + acclDestPixelSize));
1343 <        const int dest_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes);
1344 <        uint8 *dest = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dest_row_bytes) + (dest_X * bpp));
1345 <        width *= bpp;
1346 <        switch (bpp) {
1347 <        case 1:
1348 <                for (int i = 0; i < height; i++) {
1349 <                        do_invrect<8>(dest, width);
1350 <                        dest += dest_row_bytes;
1351 <                }
1352 <                break;
1353 <        case 2:
1354 <                for (int i = 0; i < height; i++) {
1355 <                        do_invrect<16>(dest, width);
1356 <                        dest += dest_row_bytes;
1357 <                }
1358 <                break;
1359 <        case 4:
1360 <                for (int i = 0; i < height; i++) {
1361 <                        do_invrect<32>(dest, width);
1362 <                        dest += dest_row_bytes;
1363 <                }
1364 <                break;
1365 <        }
1366 < }
1367 <
1368 < // Rectangle filling
1369 < template< int bpp >
1370 < static inline void do_fillrect(uint8 *dest, uint32 color, uint32 length)
1371 < {
1372 < #define FILL_1(PTR, OFS, VAL) ((uint8  *)(PTR))[OFS] = (VAL)
1373 < #define FILL_2(PTR, OFS, VAL) ((uint16 *)(PTR))[OFS] = (VAL)
1374 < #define FILL_4(PTR, OFS, VAL) ((uint32 *)(PTR))[OFS] = (VAL)
1375 < #define FILL_8(PTR, OFS, VAL) ((uint64 *)(PTR))[OFS] = (VAL)
1376 <
1377 < #ifndef UNALIGNED_PROFITABLE
1378 <        // Align on 16-bit boundaries
1379 <        if (bpp < 16 && (((uintptr)dest) & 1)) {
1380 <                FILL_1(dest, 0, color);
1381 <                dest += 1; length -= 1;
1382 <        }
1383 <
1384 <        // Align on 32-bit boundaries
1385 <        if (bpp < 32 && (((uintptr)dest) & 2)) {
1386 <                FILL_2(dest, 0, color);
1387 <                dest += 2; length -= 2;
1388 <        }
1389 < #endif
1390 <
1391 <        // Fill 8-byte words
1392 <        if (length >= 8) {
1393 <                const uint64 c = (((uint64)color) << 32) | color;
1394 <                const int r = (length / 8) % 8;
1395 <                dest += r * 8;
1396 <
1397 <                int n = ((length / 8) + 7) / 8;
1398 <                switch (r) {
1399 <                case 0: do {
1400 <                                dest += 64;
1401 <                                FILL_8(dest, -8, c);
1402 <                case 7: FILL_8(dest, -7, c);
1403 <                case 6: FILL_8(dest, -6, c);
1404 <                case 5: FILL_8(dest, -5, c);
1405 <                case 4: FILL_8(dest, -4, c);
1406 <                case 3: FILL_8(dest, -3, c);
1407 <                case 2: FILL_8(dest, -2, c);
1408 <                case 1: FILL_8(dest, -1, c);
1409 <                                } while (--n > 0);
1410 <                }
1411 <        }
1412 <
1413 <        // 32-bit cell to fill?
1414 <        if (length & 4) {
1415 <                FILL_4(dest, 0, color);
1416 <                if (bpp <= 16)
1417 <                        dest += 4;
1418 <        }
1419 <
1420 <        // 16-bit cell to fill?
1421 <        if (bpp <= 16 && (length & 2)) {
1422 <                FILL_2(dest, 0, color);
1423 <                if (bpp <= 8)
1424 <                        dest += 2;
1425 <        }
1426 <
1427 <        // 8-bit cell to fill?
1428 <        if (bpp <= 8 && (length & 1))
1429 <                FILL_1(dest, 0, color);
1430 <
1431 < #undef FILL_1
1432 < #undef FILL_2
1433 < #undef FILL_4
1434 < #undef FILL_8
1435 < }
1436 <
1437 < void NQD_fillrect(uint32 p)
1318 > static bool is_modifier_key(SDL_KeyboardEvent const & e)
1319   {
1320 <        D(bug("accl_fillrect %08x\n", p));
1321 <
1322 <        // Get filling parameters
1323 <        int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2);
1324 <        int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0);
1325 <        int16 width  = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2);
1326 <        int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0);
1327 <        uint32 color = htonl(ReadMacInt32(p + acclPenMode) == 8 ? ReadMacInt32(p + acclForePen) : ReadMacInt32(p + acclBackPen));
1328 <        D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y));
1329 <        D(bug(" width %d, height %d\n", width, height));
1330 <        D(bug(" bytes_per_row %d color %08x\n", (int32)ReadMacInt32(p + acclDestRowBytes), color));
1331 <
1332 <        // And perform the fill
1333 <        const int bpp = bytes_per_pixel(ReadMacInt32(p + acclDestPixelSize));
1334 <        const int dest_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes);
1335 <        uint8 *dest = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dest_row_bytes) + (dest_X * bpp));
1455 <        width *= bpp;
1456 <        switch (bpp) {
1457 <        case 1:
1458 <                for (int i = 0; i < height; i++) {
1459 <                        memset(dest, color, width);
1460 <                        dest += dest_row_bytes;
1461 <                }
1462 <                break;
1463 <        case 2:
1464 <                for (int i = 0; i < height; i++) {
1465 <                        do_fillrect<16>(dest, color, width);
1466 <                        dest += dest_row_bytes;
1467 <                }
1468 <                break;
1469 <        case 4:
1470 <                for (int i = 0; i < height; i++) {
1471 <                        do_fillrect<32>(dest, color, width);
1472 <                        dest += dest_row_bytes;
1473 <                }
1474 <                break;
1475 <        }
1476 < }
1477 <
1478 < bool NQD_fillrect_hook(uint32 p)
1479 < {
1480 <        D(bug("accl_fillrect_hook %08x\n", p));
1481 <
1482 <        // Check if we can accelerate this fillrect
1483 <        if (ReadMacInt32(p + 0x284) != 0 && ReadMacInt32(p + acclDestPixelSize) >= 8) {
1484 <                const int transfer_mode = ReadMacInt32(p + acclTransferMode);
1485 <                if (transfer_mode == 8) {
1486 <                        // Fill
1487 <                        WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_FILLRECT));
1488 <                        return true;
1489 <                }
1490 <                else if (transfer_mode == 10) {
1491 <                        // Invert
1492 <                        WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_INVRECT));
1493 <                        return true;
1494 <                }
1495 <        }
1496 <        return false;
1497 < }
1498 <
1499 < // Rectangle blitting
1500 < // TODO: optimize for VOSF and target pixmap == screen
1501 < void NQD_bitblt(uint32 p)
1502 < {
1503 <        D(bug("accl_bitblt %08x\n", p));
1504 <
1505 <        // Get blitting parameters
1506 <        int16 src_X  = (int16)ReadMacInt16(p + acclSrcRect + 2) - (int16)ReadMacInt16(p + acclSrcBoundsRect + 2);
1507 <        int16 src_Y  = (int16)ReadMacInt16(p + acclSrcRect + 0) - (int16)ReadMacInt16(p + acclSrcBoundsRect + 0);
1508 <        int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2);
1509 <        int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0);
1510 <        int16 width  = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2);
1511 <        int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0);
1512 <        D(bug(" src addr %08x, dest addr %08x\n", ReadMacInt32(p + acclSrcBaseAddr), ReadMacInt32(p + acclDestBaseAddr)));
1513 <        D(bug(" src X %d, src Y %d, dest X %d, dest Y %d\n", src_X, src_Y, dest_X, dest_Y));
1514 <        D(bug(" width %d, height %d\n", width, height));
1515 <
1516 <        // And perform the blit
1517 <        const int bpp = bytes_per_pixel(ReadMacInt32(p + acclSrcPixelSize));
1518 <        width *= bpp;
1519 <        if ((int32)ReadMacInt32(p + acclSrcRowBytes) > 0) {
1520 <                const int src_row_bytes = (int32)ReadMacInt32(p + acclSrcRowBytes);
1521 <                const int dst_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes);
1522 <                uint8 *src = Mac2HostAddr(ReadMacInt32(p + acclSrcBaseAddr) + (src_Y * src_row_bytes) + (src_X * bpp));
1523 <                uint8 *dst = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dst_row_bytes) + (dest_X * bpp));
1524 <                for (int i = 0; i < height; i++) {
1525 <                        memmove(dst, src, width);
1526 <                        src += src_row_bytes;
1527 <                        dst += dst_row_bytes;
1528 <                }
1529 <        }
1530 <        else {
1531 <                const int src_row_bytes = -(int32)ReadMacInt32(p + acclSrcRowBytes);
1532 <                const int dst_row_bytes = -(int32)ReadMacInt32(p + acclDestRowBytes);
1533 <                uint8 *src = Mac2HostAddr(ReadMacInt32(p + acclSrcBaseAddr) + ((src_Y + height - 1) * src_row_bytes) + (src_X * bpp));
1534 <                uint8 *dst = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + ((dest_Y + height - 1) * dst_row_bytes) + (dest_X * bpp));
1535 <                for (int i = height - 1; i >= 0; i--) {
1536 <                        memmove(dst, src, width);
1537 <                        src -= src_row_bytes;
1538 <                        dst -= dst_row_bytes;
1539 <                }
1540 <        }
1541 < }
1542 <
1543 < /*
1544 <  BitBlt transfer modes:
1545 <  0 : srcCopy
1546 <  1 : srcOr
1547 <  2 : srcXor
1548 <  3 : srcBic
1549 <  4 : notSrcCopy
1550 <  5 : notSrcOr
1551 <  6 : notSrcXor
1552 <  7 : notSrcBic
1553 <  32 : blend
1554 <  33 : addPin
1555 <  34 : addOver
1556 <  35 : subPin
1557 <  36 : transparent
1558 <  37 : adMax
1559 <  38 : subOver
1560 <  39 : adMin
1561 <  50 : hilite
1562 < */
1563 <
1564 < bool NQD_bitblt_hook(uint32 p)
1565 < {
1566 <        D(bug("accl_draw_hook %08x\n", p));
1567 <
1568 <        // Check if we can accelerate this bitblt
1569 <        if (ReadMacInt32(p + 0x018) + ReadMacInt32(p + 0x128) == 0 &&
1570 <                ReadMacInt32(p + 0x130) == 0 &&
1571 <                ReadMacInt32(p + acclSrcPixelSize) >= 8 &&
1572 <                ReadMacInt32(p + acclSrcPixelSize) == ReadMacInt32(p + acclDestPixelSize) &&
1573 <                (ReadMacInt32(p + acclSrcRowBytes) ^ ReadMacInt32(p + acclDestRowBytes)) >= 0 && // same sign?
1574 <                ReadMacInt32(p + acclTransferMode) == 0 &&                                                                               // srcCopy?
1575 <                ReadMacInt32(p + 0x15c) > 0) {
1576 <
1577 <                // Yes, set function pointer
1578 <                WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_BITBLT));
1320 >        switch (e.keysym.sym) {
1321 >        case SDLK_NUMLOCK:
1322 >        case SDLK_CAPSLOCK:
1323 >        case SDLK_SCROLLOCK:
1324 >        case SDLK_RSHIFT:
1325 >        case SDLK_LSHIFT:
1326 >        case SDLK_RCTRL:
1327 >        case SDLK_LCTRL:
1328 >        case SDLK_RALT:
1329 >        case SDLK_LALT:
1330 >        case SDLK_RMETA:
1331 >        case SDLK_LMETA:
1332 >        case SDLK_LSUPER:
1333 >        case SDLK_RSUPER:
1334 >        case SDLK_MODE:
1335 >        case SDLK_COMPOSE:
1336                  return true;
1337          }
1338          return false;
1339   }
1340  
1341 < // Wait for graphics operation to finish
1585 < bool NQD_sync_hook(uint32 arg)
1586 < {
1587 <        D(bug("accl_sync_hook %08x\n", arg));
1588 <        return true;
1589 < }
1590 <
1591 < void VideoInstallAccel(void)
1341 > static bool is_ctrl_down(SDL_keysym const & ks)
1342   {
1343 <        // Install acceleration hooks
1594 <        if (PrefsFindBool("gfxaccel")) {
1595 <                D(bug("Video: Installing acceleration hooks\n"));
1596 <                uint32 base;
1597 <
1598 <                SheepVar bitblt_hook_info(sizeof(accl_hook_info));
1599 <                base = bitblt_hook_info.addr();
1600 <                WriteMacInt32(base + 0, NativeTVECT(NATIVE_BITBLT_HOOK));
1601 <                WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK));
1602 <                WriteMacInt32(base + 8, ACCL_BITBLT);
1603 <                NQDMisc(6, bitblt_hook_info.ptr());
1604 <
1605 <                SheepVar fillrect_hook_info(sizeof(accl_hook_info));
1606 <                base = fillrect_hook_info.addr();
1607 <                WriteMacInt32(base + 0, NativeTVECT(NATIVE_FILLRECT_HOOK));
1608 <                WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK));
1609 <                WriteMacInt32(base + 8, ACCL_FILLRECT);
1610 <                NQDMisc(6, fillrect_hook_info.ptr());
1611 <        }
1343 >        return ctrl_down || (ks.mod & KMOD_CTRL);
1344   }
1613 #endif
1345  
1346  
1347   /*
# Line 1618 | Line 1349 | void VideoInstallAccel(void)
1349   *  and -2 if the key was recognized as a hotkey
1350   */
1351  
1621 static bool is_ctrl_down(SDL_keysym const & ks)
1622 {
1623        return ctrl_down || (ks.mod & KMOD_CTRL);
1624 }
1625
1352   static int kc_decode(SDL_keysym const & ks, bool key_down)
1353   {
1354          switch (ks.sym) {
# Line 1692 | Line 1418 | static int kc_decode(SDL_keysym const &
1418          case SDLK_RCTRL: return 0x36;
1419          case SDLK_LSHIFT: return 0x38;
1420          case SDLK_RSHIFT: return 0x38;
1421 + #if (defined(__APPLE__) && defined(__MACH__))
1422 +        case SDLK_LALT: return 0x3a;
1423 +        case SDLK_RALT: return 0x3a;
1424 +        case SDLK_LMETA: return 0x37;
1425 +        case SDLK_RMETA: return 0x37;
1426 + #else
1427          case SDLK_LALT: return 0x37;
1428          case SDLK_RALT: return 0x37;
1429          case SDLK_LMETA: return 0x3a;
1430          case SDLK_RMETA: return 0x3a;
1431 + #endif
1432          case SDLK_MENU: return 0x32;
1433          case SDLK_CAPSLOCK: return 0x39;
1434          case SDLK_NUMLOCK: return 0x47;
# Line 1802 | Line 1535 | static void handle_events(void)
1535                          // Keyboard
1536                          case SDL_KEYDOWN: {
1537                                  int code = -1;
1538 <                                if (use_keycodes) {
1538 >                                if (use_keycodes && !is_modifier_key(event.key)) {
1539                                          if (event2keycode(event.key, true) != -2)       // This is called to process the hotkeys
1540                                                  code = keycode_table[event.key.keysym.scancode & 0xff];
1541                                  } else
# Line 1830 | Line 1563 | static void handle_events(void)
1563                          }
1564                          case SDL_KEYUP: {
1565                                  int code = -1;
1566 <                                if (use_keycodes) {
1566 >                                if (use_keycodes && !is_modifier_key(event.key)) {
1567                                          if (event2keycode(event.key, false) != -2)      // This is called to process the hotkeys
1568                                                  code = keycode_table[event.key.keysym.scancode & 0xff];
1569                                  } else
1570                                          code = event2keycode(event.key, false);
1571 <                                if (code >= 0 && code != 0x39) {        // Don't propagate Caps Lock releases
1572 <                                        ADBKeyUp(code);
1571 >                                if (code >= 0) {
1572 >                                        if (code == 0x39) {     // Caps Lock released
1573 >                                                if (caps_on) {
1574 >                                                        ADBKeyUp(code);
1575 >                                                        caps_on = false;
1576 >                                                } else {
1577 >                                                        ADBKeyDown(code);
1578 >                                                        caps_on = true;
1579 >                                                }
1580 >                                        } else
1581 >                                                ADBKeyUp(code);
1582                                          if (code == 0x36)
1583                                                  ctrl_down = false;
1584                                  }
# Line 1903 | Line 1645 | static void update_display_static(driver
1645  
1646          // Check for first column from left and first column from right that have changed
1647          if (high) {
1648 <                if (VIDEO_MODE_DEPTH < VIDEO_DEPTH_8BIT) {
1648 >                if ((int)VIDEO_MODE_DEPTH < VIDEO_DEPTH_8BIT) {
1649                          const int src_bytes_per_row = bytes_per_row;
1650                          const int dst_bytes_per_row = drv->s->pitch;
1651                          const int pixels_per_byte = VIDEO_MODE_X / src_bytes_per_row;
# Line 2164 | Line 1906 | static int redraw_func(void *arg)
1906                          next = GetTicks_usec();
1907                  ticks++;
1908  
1909 + #ifdef SHEEPSHAVER
1910 +                // Pause if requested (during video mode switches)
1911 +                if (thread_stop_req) {
1912 +                        thread_stop_ack = true;
1913 +                        continue;
1914 +                }
1915 + #endif
1916 +
1917                  // Handle SDL events
1918                  handle_events();
1919  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines