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

Comparing BasiliskII/src/Unix/video_x.cpp (file contents):
Revision 1.31 by cebix, 2000-11-30T16:09:03Z vs.
Revision 1.40 by cebix, 2001-06-27T19:03:37Z

# Line 1 | Line 1
1   /*
2   *  video_x.cpp - Video/graphics emulation, X11 specific stuff
3   *
4 < *  Basilisk II (C) 1997-2000 Christian Bauer
4 > *  Basilisk II (C) 1997-2001 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 53 | Line 53
53   #endif
54  
55   #ifdef ENABLE_VOSF
56 # include <unistd.h>
57 # include <signal.h>
56   # include <fcntl.h>
57   # include <sys/mman.h>
58 + # include "sigsegv.h"
59 + # include "vm_alloc.h"
60   #endif
61  
62   #include "cpu_emulation.h"
# Line 188 | Line 188 | struct ScreenPageInfo {
188   };
189  
190   struct ScreenInfo {
191 <    uint32 memBase;                             // Real start address
192 <    uint32 memStart;                    // Start address aligned to page boundary
193 <    uint32 memEnd;                              // Address of one-past-the-end of the screen
191 >    uintptr memBase;                    // Real start address
192 >    uintptr memStart;                   // Start address aligned to page boundary
193 >    uintptr memEnd;                             // Address of one-past-the-end of the screen
194      uint32 memLength;                   // Length of the memory addressed by the screen pages
195      
196      uint32 pageSize;                    // Size of a page
197      int pageBits;                               // Shift count to get the page number
198      uint32 pageCount;                   // Number of pages allocated to the screen
199      
200 <    uint8 * dirtyPages;                 // Table of flags set if page was altered
200 >        bool dirty;                                     // Flag: set if the frame buffer was touched
201 >    char * dirtyPages;                  // Table of flags set if page was altered
202      ScreenPageInfo * pageInfo;  // Table of mappings page -> Mac scanlines
203   };
204  
205   static ScreenInfo mainBuffer;
206  
207 < #define PFLAG_SET(page)                 mainBuffer.dirtyPages[page] = 1
208 < #define PFLAG_CLEAR(page)               mainBuffer.dirtyPages[page] = 0
209 < #define PFLAG_ISSET(page)               mainBuffer.dirtyPages[page]
210 < #define PFLAG_ISCLEAR(page)             (mainBuffer.dirtyPages[page] == 0)
207 > #define PFLAG_SET_VALUE                 0x00
208 > #define PFLAG_CLEAR_VALUE               0x01
209 > #define PFLAG_SET_VALUE_4               0x00000000
210 > #define PFLAG_CLEAR_VALUE_4             0x01010101
211 > #define PFLAG_SET(page)                 mainBuffer.dirtyPages[page] = PFLAG_SET_VALUE
212 > #define PFLAG_CLEAR(page)               mainBuffer.dirtyPages[page] = PFLAG_CLEAR_VALUE
213 > #define PFLAG_ISSET(page)               (mainBuffer.dirtyPages[page] == PFLAG_SET_VALUE)
214 > #define PFLAG_ISCLEAR(page)             (mainBuffer.dirtyPages[page] != PFLAG_SET_VALUE)
215 >
216   #ifdef UNALIGNED_PROFITABLE
217 < # define PFLAG_ISCLEAR_4(page)  (*((uint32 *)(mainBuffer.dirtyPages + page)) == 0)
217 > # define PFLAG_ISSET_4(page)    (*((uint32 *)(mainBuffer.dirtyPages + (page))) == PFLAG_SET_VALUE_4)
218 > # define PFLAG_ISCLEAR_4(page)  (*((uint32 *)(mainBuffer.dirtyPages + (page))) == PFLAG_CLEAR_VALUE_4)
219 > #else
220 > # define PFLAG_ISSET_4(page) \
221 >                PFLAG_ISSET(page  ) && PFLAG_ISSET(page+1) \
222 >        &&      PFLAG_ISSET(page+2) && PFLAG_ISSET(page+3)
223 > # define PFLAG_ISCLEAR_4(page) \
224 >                PFLAG_ISCLEAR(page  ) && PFLAG_ISCLEAR(page+1) \
225 >        &&      PFLAG_ISCLEAR(page+2) && PFLAG_ISCLEAR(page+3)
226 > #endif
227 >
228 > // Set the selected page range [ first_page, last_page [ into the SET state
229 > #define PFLAG_SET_RANGE(first_page, last_page) \
230 >        memset(mainBuffer.dirtyPages + (first_page), PFLAG_SET_VALUE, \
231 >                (last_page) - (first_page))
232 >
233 > // Set the selected page range [ first_page, last_page [ into the CLEAR state
234 > #define PFLAG_CLEAR_RANGE(first_page, last_page) \
235 >        memset(mainBuffer.dirtyPages + (first_page), PFLAG_CLEAR_VALUE, \
236 >                (last_page) - (first_page))
237 >
238 > #define PFLAG_SET_ALL do { \
239 >        PFLAG_SET_RANGE(0, mainBuffer.pageCount); \
240 >        mainBuffer.dirty = true; \
241 > } while (0)
242 >
243 > #define PFLAG_CLEAR_ALL do { \
244 >        PFLAG_CLEAR_RANGE(0, mainBuffer.pageCount); \
245 >        mainBuffer.dirty = false; \
246 > } while (0)
247 >
248 > // Set the following macro definition to 1 if your system
249 > // provides a really fast strchr() implementation
250 > //#define HAVE_FAST_STRCHR 0
251 >
252 > static inline int find_next_page_set(int page)
253 > {
254 > #if HAVE_FAST_STRCHR
255 >        char *match = strchr(mainBuffer.dirtyPages + page, PFLAG_SET_VALUE);
256 >        return match ? match - mainBuffer.dirtyPages : mainBuffer.pageCount;
257 > #else
258 >        while (PFLAG_ISCLEAR_4(page))
259 >                page += 4;
260 >        while (PFLAG_ISCLEAR(page))
261 >                page++;
262 >        return page;
263 > #endif
264 > }
265 >
266 > static inline int find_next_page_clear(int page)
267 > {
268 > #if HAVE_FAST_STRCHR
269 >        char *match = strchr(mainBuffer.dirtyPages + page, PFLAG_CLEAR_VALUE);
270 >        return match ? match - mainBuffer.dirtyPages : mainBuffer.pageCount;
271   #else
272 < # define PFLAG_ISCLEAR_4(page)  \
273 <                (mainBuffer.dirtyPages[page  ] == 0) \
274 <        &&      (mainBuffer.dirtyPages[page+1] == 0) \
275 <        &&      (mainBuffer.dirtyPages[page+2] == 0) \
276 <        &&      (mainBuffer.dirtyPages[page+3] == 0)
272 >        while (PFLAG_ISSET_4(page))
273 >                page += 4;
274 >        while (PFLAG_ISSET(page))
275 >                page++;
276 >        return page;
277   #endif
278 < #define PFLAG_CLEAR_ALL                 memset(mainBuffer.dirtyPages, 0, mainBuffer.pageCount)
220 < #define PFLAG_SET_ALL                   memset(mainBuffer.dirtyPages, 1, mainBuffer.pageCount)
278 > }
279  
280   static int zero_fd = -1;
223 static bool Screen_fault_handler_init();
224 static struct sigaction vosf_sa;
281  
282   #ifdef HAVE_PTHREADS
283   static pthread_mutex_t vosf_lock = PTHREAD_MUTEX_INITIALIZER;   // Mutex to protect frame buffer (dirtyPages in fact)
# Line 242 | Line 298 | static int log_base_2(uint32 x)
298          }
299          return l;
300   }
301 <
246 < #endif
301 > #endif /* ENABLE_VOSF */
302  
303   // VideoRefresh function
304   void VideoRefreshInit(void);
# Line 270 | Line 325 | extern void SysMountFirstFloppy(void);
325   *  Initialization
326   */
327  
328 < // Set VideoMonitor according to video mode
329 < void set_video_monitor(int width, int height, int bytes_per_row, bool native_byte_order)
328 > // Add resolution to list of supported modes and set VideoMonitor
329 > static void set_video_monitor(uint32 width, uint32 height, uint32 bytes_per_row, bool native_byte_order)
330   {
331 +        video_mode mode;
332   #if !REAL_ADDRESSING && !DIRECT_ADDRESSING
333          int layout = FLAYOUT_DIRECT;
334          switch (depth) {
# Line 298 | Line 354 | void set_video_monitor(int width, int he
354          else
355                  MacFrameLayout = FLAYOUT_DIRECT;
356   #endif
357 +
358 +        mode.x = width;
359 +        mode.y = height;
360 +        mode.resolution_id = 0x80;
361 +        mode.bytes_per_row = bytes_per_row;
362 +
363          switch (depth) {
364                  case 1:
365 <                        VideoMonitor.mode = VMODE_1BIT;
365 >                        mode.depth = VDEPTH_1BIT;
366 >                        break;
367 >                case 2:
368 >                        mode.depth = VDEPTH_2BIT;
369 >                        break;
370 >                case 4:
371 >                        mode.depth = VDEPTH_4BIT;
372                          break;
373                  case 8:
374 <                        VideoMonitor.mode = VMODE_8BIT;
374 >                        mode.depth = VDEPTH_8BIT;
375                          break;
376                  case 15:
377 <                        VideoMonitor.mode = VMODE_16BIT;
377 >                        mode.depth = VDEPTH_16BIT;
378                          break;
379                  case 16:
380 <                        VideoMonitor.mode = VMODE_16BIT;
380 >                        mode.depth = VDEPTH_16BIT;
381                          break;
382                  case 24:
383                  case 32:
384 <                        VideoMonitor.mode = VMODE_32BIT;
384 >                        mode.depth = VDEPTH_32BIT;
385                          break;
386          }
387 <        VideoMonitor.x = width;
388 <        VideoMonitor.y = height;
389 <        VideoMonitor.bytes_per_row = bytes_per_row;
387 >
388 >        VideoModes.push_back(mode);
389 >        VideoMonitor.mode = mode;
390   }
391  
392   // Set window name and class
# Line 334 | Line 402 | static void set_window_name(Window w, in
402                  hints->res_name = "BasiliskII";
403                  hints->res_class = "BasiliskII";
404                  XSetClassHint(x_display, w, hints);
405 <                XFree((char *)hints);
405 >                XFree(hints);
406          }
407   }
408  
# Line 347 | Line 415 | static void set_window_focus(Window w)
415                  hints->initial_state = NormalState;
416                  hints->flags = InputHint | StateHint;
417                  XSetWMHints(x_display, w, hints);
418 <                XFree((char *)hints);
418 >                XFree(hints);
419          }
420   }
421  
# Line 428 | Line 496 | static bool init_window(int width, int h
496                          hints->max_height = height;
497                          hints->flags = PMinSize | PMaxSize;
498                          XSetWMNormalHints(x_display, the_win, hints);
499 <                        XFree((char *)hints);
499 >                        XFree(hints);
500                  }
501          }
502          
# Line 490 | Line 558 | static bool init_window(int width, int h
558          }
559  
560   #ifdef ENABLE_VOSF
561 <        // Allocate a page-aligned chunk of memory for frame buffer
494 <        the_buffer_size = align_on_page_boundary((aligned_height + 2) * img->bytes_per_line);
561 >        // Allocate memory for frame buffer (SIZE is extended to page-boundary)
562          the_host_buffer = the_buffer_copy;
563 <        
564 <        the_buffer_copy = (uint8 *)allocate_framebuffer(the_buffer_size);
565 <        memset(the_buffer_copy, 0, the_buffer_size);
499 <        
500 <        the_buffer = (uint8 *)allocate_framebuffer(the_buffer_size);
501 <        memset(the_buffer, 0, the_buffer_size);
563 >        the_buffer_size = page_extend((aligned_height + 2) * img->bytes_per_line);
564 >        the_buffer_copy = (uint8 *)vm_acquire(the_buffer_size);
565 >        the_buffer = (uint8 *)vm_acquire(the_buffer_size);
566   #else
567          // Allocate memory for frame buffer
568          the_buffer = (uint8 *)malloc((aligned_height + 2) * img->bytes_per_line);
# Line 515 | Line 579 | static bool init_window(int width, int h
579             &black, &white, 0, 0);
580          XDefineCursor(x_display, the_win, mac_cursor);
581  
582 <        // Set VideoMonitor
582 >        // Add resolution and set VideoMonitor
583          bool native_byte_order;
584   #ifdef WORDS_BIGENDIAN
585          native_byte_order = (XImageByteOrder(x_display) == MSBFirst);
# Line 523 | Line 587 | static bool init_window(int width, int h
587          native_byte_order = (XImageByteOrder(x_display) == LSBFirst);
588   #endif
589   #ifdef ENABLE_VOSF
590 <        do_update_framebuffer = GET_FBCOPY_FUNC(depth, native_byte_order, DISPLAY_WINDOW);
590 >        Screen_blitter_init(&visualInfo, native_byte_order);
591   #endif
592          set_video_monitor(width, height, img->bytes_per_line, native_byte_order);
593          
# Line 662 | Line 726 | static bool init_fbdev_dga(char *in_fb_n
726          
727   #if ENABLE_VOSF
728   #if REAL_ADDRESSING || DIRECT_ADDRESSING
729 <        // If the blit function is null, i.e. just a copy of the buffer,
730 <        // we first try to avoid the allocation of a temporary frame buffer
731 <        use_vosf = true;
668 <        do_update_framebuffer = GET_FBCOPY_FUNC(depth, true, DISPLAY_DGA);
669 <        if (do_update_framebuffer == FBCOPY_FUNC(fbcopy_raw))
670 <                use_vosf = false;
729 >        // Screen_blitter_init() returns TRUE if VOSF is mandatory
730 >        // i.e. the framebuffer update function is not Blit_Copy_Raw
731 >        use_vosf = Screen_blitter_init(&visualInfo, true);
732          
733          if (use_vosf) {
734 <                the_host_buffer = the_buffer;
735 <                the_buffer_size = align_on_page_boundary((height + 2) * bytes_per_row);
736 <                the_buffer_copy = (uint8 *)malloc(the_buffer_size);
737 <                memset(the_buffer_copy, 0, the_buffer_size);
738 <                the_buffer = (uint8 *)allocate_framebuffer(the_buffer_size);
678 <                memset(the_buffer, 0, the_buffer_size);
734 >          // Allocate memory for frame buffer (SIZE is extended to page-boundary)
735 >          the_host_buffer = the_buffer;
736 >          the_buffer_size = page_extend((height + 2) * bytes_per_row);
737 >          the_buffer_copy = (uint8 *)vm_acquire(the_buffer_size);
738 >          the_buffer = (uint8 *)vm_acquire(the_buffer_size);
739          }
740   #else
741          use_vosf = false;
# Line 770 | Line 830 | static bool init_xf86_dga(int width, int
830                          bytes_per_row *= 4;
831                          break;
832          }
833 <        
833 >
834 > #ifdef VIDEO_VOSF
835   #if REAL_ADDRESSING || DIRECT_ADDRESSING
836 <        // If the blit function is null, i.e. just a copy of the buffer,
837 <        // we first try to avoid the allocation of a temporary frame buffer
838 <        use_vosf = true;
778 <        do_update_framebuffer = GET_FBCOPY_FUNC(depth, true, DISPLAY_DGA);
779 <        if (do_update_framebuffer == FBCOPY_FUNC(fbcopy_raw))
780 <                use_vosf = false;
836 >        // Screen_blitter_init() returns TRUE if VOSF is mandatory
837 >        // i.e. the framebuffer update function is not Blit_Copy_Raw
838 >        use_vosf = Screen_blitter_init(&visualInfo, true);
839          
840          if (use_vosf) {
841 <                the_host_buffer = the_buffer;
842 <                the_buffer_size = align_on_page_boundary((height + 2) * bytes_per_row);
843 <                the_buffer_copy = (uint8 *)malloc(the_buffer_size);
844 <                memset(the_buffer_copy, 0, the_buffer_size);
845 <                the_buffer = (uint8 *)allocate_framebuffer(the_buffer_size);
788 <                memset(the_buffer, 0, the_buffer_size);
841 >          // Allocate memory for frame buffer (SIZE is extended to page-boundary)
842 >          the_host_buffer = the_buffer;
843 >          the_buffer_size = page_extend((height + 2) * bytes_per_row);
844 >          the_buffer_copy = (uint8 *)vm_acquire(the_buffer_size);
845 >          the_buffer = (uint8 *)vm_acquire(the_buffer_size);
846          }
847 < #elif defined(ENABLE_VOSF)
791 <        // The UAE memory handlers will already handle color conversion, if needed.
847 > #else
848          use_vosf = false;
849   #endif
850 + #endif
851          
852          set_video_monitor(width, height, bytes_per_row, true);
853   #if REAL_ADDRESSING || DIRECT_ADDRESSING
# Line 878 | Line 935 | bool VideoInitBuffer()
935                  const uint32 page_size  = getpagesize();
936                  const uint32 page_mask  = page_size - 1;
937                  
938 <                mainBuffer.memBase      = (uint32) the_buffer;
938 >                mainBuffer.memBase      = (uintptr) the_buffer;
939                  // Align the frame buffer on page boundary
940 <                mainBuffer.memStart             = (uint32)((((unsigned long) the_buffer) + page_mask) & ~page_mask);
940 >                mainBuffer.memStart             = (uintptr)((((unsigned long) the_buffer) + page_mask) & ~page_mask);
941                  mainBuffer.memLength    = the_buffer_size;
942                  mainBuffer.memEnd       = mainBuffer.memStart + mainBuffer.memLength;
943  
# Line 891 | Line 948 | bool VideoInitBuffer()
948                  if (mainBuffer.dirtyPages != 0)
949                          free(mainBuffer.dirtyPages);
950  
951 <                mainBuffer.dirtyPages = (uint8 *) malloc(mainBuffer.pageCount);
951 >                mainBuffer.dirtyPages = (char *) malloc(mainBuffer.pageCount + 2);
952  
953                  if (mainBuffer.pageInfo != 0)
954                          free(mainBuffer.pageInfo);
# Line 900 | Line 957 | bool VideoInitBuffer()
957  
958                  if ((mainBuffer.dirtyPages == 0) || (mainBuffer.pageInfo == 0))
959                          return false;
960 +                
961 +                mainBuffer.dirty = false;
962  
963                  PFLAG_CLEAR_ALL;
964 +                // Safety net to insure the loops in the update routines will terminate
965 +                // See a discussion in <video_vosf.h> for further details
966 +                PFLAG_CLEAR(mainBuffer.pageCount);
967 +                PFLAG_SET(mainBuffer.pageCount+1);
968  
969                  uint32 a = 0;
970                  for (int i = 0; i < mainBuffer.pageCount; i++) {
971 <                        int y1 = a / VideoMonitor.bytes_per_row;
972 <                        if (y1 >= VideoMonitor.y)
973 <                                y1 = VideoMonitor.y - 1;
974 <
975 <                        int y2 = (a + mainBuffer.pageSize) / VideoMonitor.bytes_per_row;
976 <                        if (y2 >= VideoMonitor.y)
977 <                                y2 = VideoMonitor.y - 1;
971 >                        int y1 = a / VideoMonitor.mode.bytes_per_row;
972 >                        if (y1 >= VideoMonitor.mode.y)
973 >                                y1 = VideoMonitor.mode.y - 1;
974 >
975 >                        int y2 = (a + mainBuffer.pageSize) / VideoMonitor.mode.bytes_per_row;
976 >                        if (y2 >= VideoMonitor.mode.y)
977 >                                y2 = VideoMonitor.mode.y - 1;
978  
979                          mainBuffer.pageInfo[i].top = y1;
980                          mainBuffer.pageInfo[i].bottom = y2;
# Line 922 | Line 985 | bool VideoInitBuffer()
985                  }
986                  
987                  // We can now write-protect the frame buffer
988 <                if (mprotect((caddr_t)mainBuffer.memStart, mainBuffer.memLength, PROT_READ) != 0)
988 >                if (vm_protect((char *)mainBuffer.memStart, mainBuffer.memLength, VM_PAGE_READ) != 0)
989                          return false;
990          }
991   #endif
# Line 954 | Line 1017 | bool VideoInit(bool classic)
1017          keycode_init();
1018  
1019          // Read prefs
1020 <        mouse_wheel_mode = PrefsFindInt16("mousewheelmode");
1021 <        mouse_wheel_lines = PrefsFindInt16("mousewheellines");
1020 >        mouse_wheel_mode = PrefsFindInt32("mousewheelmode");
1021 >        mouse_wheel_lines = PrefsFindInt32("mousewheellines");
1022  
1023          // Find screen and root window
1024          screen = XDefaultScreen(x_display);
# Line 1098 | Line 1161 | bool VideoInit(bool classic)
1161   #if !REAL_ADDRESSING && !DIRECT_ADDRESSING
1162          // Set variables for UAE memory mapping
1163          MacFrameBaseHost = the_buffer;
1164 <        MacFrameSize = VideoMonitor.bytes_per_row * VideoMonitor.y;
1164 >        MacFrameSize = VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y;
1165  
1166          // No special frame buffer in Classic mode (frame buffer is in Mac RAM)
1167          if (classic)
# Line 1115 | Line 1178 | bool VideoInit(bool classic)
1178                  }
1179  
1180                  // Initialize the handler for SIGSEGV
1181 <                if (!Screen_fault_handler_init()) {
1181 >                if (!sigsegv_install_handler(screen_fault_handler)) {
1182                          // TODO: STR_VOSF_INIT_ERR ?
1183                          ErrorAlert("Could not initialize Video on SEGV signals");
1184                          return false;
# Line 1206 | Line 1269 | void VideoExit(void)
1269                  }
1270   #ifdef ENABLE_VOSF
1271                  else {
1272 <                        if (the_buffer != (uint8 *)MAP_FAILED) {
1273 <                                munmap((caddr_t)the_buffer, the_buffer_size);
1272 >                        if (the_buffer != (uint8 *)VM_MAP_FAILED) {
1273 >                                vm_release(the_buffer, the_buffer_size);
1274                                  the_buffer = 0;
1275                          }
1276                          
1277 <                        if (the_buffer_copy != (uint8 *)MAP_FAILED) {
1278 <                                munmap((caddr_t)the_buffer_copy, the_buffer_size);
1277 >                        if (the_buffer_copy != (uint8 *)VM_MAP_FAILED) {
1278 >                                vm_release(the_buffer_copy, the_buffer_size);
1279                                  the_buffer_copy = 0;
1280                          }
1281                  }
# Line 1309 | Line 1372 | static void suspend_emul(void)
1372                  LOCK_FRAME_BUFFER;
1373  
1374                  // Save frame buffer
1375 <                fb_save = malloc(VideoMonitor.y * VideoMonitor.bytes_per_row);
1375 >                fb_save = malloc(VideoMonitor.mode.y * VideoMonitor.mode.bytes_per_row);
1376                  if (fb_save)
1377 <                        memcpy(fb_save, the_buffer, VideoMonitor.y * VideoMonitor.bytes_per_row);
1377 >                        memcpy(fb_save, the_buffer, VideoMonitor.mode.y * VideoMonitor.mode.bytes_per_row);
1378  
1379                  // Close full screen display
1380   #ifdef ENABLE_XF86_DGA
# Line 1362 | Line 1425 | static void resume_emul(void)
1425                  LOCK_VOSF;
1426                  PFLAG_SET_ALL;
1427                  UNLOCK_VOSF;
1428 <                memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y);
1428 >                memset(the_buffer_copy, 0, VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y);
1429          }
1430   #endif
1431          
# Line 1372 | Line 1435 | static void resume_emul(void)
1435                  // Don't copy fb_save to the temporary frame buffer in VOSF mode
1436                  if (!use_vosf)
1437   #endif
1438 <                memcpy(the_buffer, fb_save, VideoMonitor.y * VideoMonitor.bytes_per_row);
1438 >                memcpy(the_buffer, fb_save, VideoMonitor.mode.y * VideoMonitor.mode.bytes_per_row);
1439                  free(fb_save);
1440                  fb_save = NULL;
1441          }
# Line 1653 | Line 1716 | static void handle_events(void)
1716                                                  LOCK_VOSF;
1717                                                  PFLAG_SET_ALL;
1718                                                  UNLOCK_VOSF;
1719 <                                                memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y);
1719 >                                                memset(the_buffer_copy, 0, VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y);
1720                                          }
1721                                          else
1722   #endif
# Line 1664 | Line 1727 | static void handle_events(void)
1727                                                          updt_box[x1][y1] = true;
1728                                                  nr_boxes = 16 * 16;
1729                                          } else                                  // Static refresh
1730 <                                                memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y);
1730 >                                                memset(the_buffer_copy, 0, VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y);
1731                                  }
1732                                  break;
1733  
# Line 1690 | Line 1753 | static void update_display_dynamic(int t
1753          int y1, y2, y2s, y2a, i, x1, xm, xmo, ymo, yo, yi, yil, xi;
1754          int xil = 0;
1755          int rxm = 0, rxmo = 0;
1756 <        int bytes_per_row = VideoMonitor.bytes_per_row;
1757 <        int bytes_per_pixel = VideoMonitor.bytes_per_row / VideoMonitor.x;
1758 <        int rx = VideoMonitor.bytes_per_row / 16;
1759 <        int ry = VideoMonitor.y / 16;
1756 >        int bytes_per_row = VideoMonitor.mode.bytes_per_row;
1757 >        int bytes_per_pixel = VideoMonitor.mode.bytes_per_row / VideoMonitor.mode.x;
1758 >        int rx = VideoMonitor.mode.bytes_per_row / 16;
1759 >        int ry = VideoMonitor.mode.y / 16;
1760          int max_box;
1761  
1762          y2s = sm_uptd[ticker % 8];
# Line 1779 | Line 1842 | static void update_display_static(void)
1842   {
1843          // Incremental update code
1844          int wide = 0, high = 0, x1, x2, y1, y2, i, j;
1845 <        int bytes_per_row = VideoMonitor.bytes_per_row;
1846 <        int bytes_per_pixel = VideoMonitor.bytes_per_row / VideoMonitor.x;
1845 >        int bytes_per_row = VideoMonitor.mode.bytes_per_row;
1846 >        int bytes_per_pixel = VideoMonitor.mode.bytes_per_row / VideoMonitor.mode.x;
1847          uint8 *p, *p2;
1848  
1849          // Check for first line from top and first line from bottom that have changed
1850          y1 = 0;
1851 <        for (j=0; j<VideoMonitor.y; j++) {
1851 >        for (j=0; j<VideoMonitor.mode.y; j++) {
1852                  if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) {
1853                          y1 = j;
1854                          break;
1855                  }
1856          }
1857          y2 = y1 - 1;
1858 <        for (j=VideoMonitor.y-1; j>=y1; j--) {
1858 >        for (j=VideoMonitor.mode.y-1; j>=y1; j--) {
1859                  if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) {
1860                          y2 = j;
1861                          break;
# Line 1803 | Line 1866 | static void update_display_static(void)
1866          // Check for first column from left and first column from right that have changed
1867          if (high) {
1868                  if (depth == 1) {
1869 <                        x1 = VideoMonitor.x - 1;
1869 >                        x1 = VideoMonitor.mode.x - 1;
1870                          for (j=y1; j<=y2; j++) {
1871                                  p = &the_buffer[j * bytes_per_row];
1872                                  p2 = &the_buffer_copy[j * bytes_per_row];
# Line 1821 | Line 1884 | static void update_display_static(void)
1884                                  p2 = &the_buffer_copy[j * bytes_per_row];
1885                                  p += bytes_per_row;
1886                                  p2 += bytes_per_row;
1887 <                                for (i=(VideoMonitor.x>>3); i>(x2>>3); i--) {
1887 >                                for (i=(VideoMonitor.mode.x>>3); i>(x2>>3); i--) {
1888                                          p--; p2--;
1889                                          if (*p != *p2) {
1890                                                  x2 = (i << 3) + 7;
# Line 1840 | Line 1903 | static void update_display_static(void)
1903                          }
1904  
1905                  } else {
1906 <                        x1 = VideoMonitor.x;
1906 >                        x1 = VideoMonitor.mode.x;
1907                          for (j=y1; j<=y2; j++) {
1908                                  p = &the_buffer[j * bytes_per_row];
1909                                  p2 = &the_buffer_copy[j * bytes_per_row];
# Line 1858 | Line 1921 | static void update_display_static(void)
1921                                  p2 = &the_buffer_copy[j * bytes_per_row];
1922                                  p += bytes_per_row;
1923                                  p2 += bytes_per_row;
1924 <                                for (i=VideoMonitor.x*bytes_per_pixel; i>x2*bytes_per_pixel; i--) {
1924 >                                for (i=VideoMonitor.mode.x*bytes_per_pixel; i>x2*bytes_per_pixel; i--) {
1925                                          p--;
1926                                          p2--;
1927                                          if (*p != *p2) {
# Line 1893 | Line 1956 | static void update_display_static(void)
1956   *      Screen refresh functions
1957   */
1958  
1959 < // The specialisations hereunder are meant to enable VOSF with DGA in direct
1960 < // addressing mode in case the address spaces (RAM, ROM, FrameBuffer) could
1961 < // not get mapped correctly with respect to the predetermined host frame
1962 < // buffer base address.
1963 < //
1901 < // Hmm, in other words, when in direct addressing mode and DGA is requested,
1902 < // we first try to "triple allocate" the address spaces according to the real
1903 < // host frame buffer address. Then, if it fails, we will use a temporary
1904 < // frame buffer thus making the real host frame buffer updated when pages
1905 < // of the temp frame buffer are altered.
1906 < //
1907 < // As a side effect, a little speed gain in screen updates could be noticed
1908 < // for other modes than DGA.
1909 < //
1910 < // The following two functions below are inline so that a clever compiler
1911 < // could specialise the code according to the current screen depth and
1912 < // display type. A more clever compiler would the job by itself though...
1913 < // (update_display_vosf is inlined as well)
1959 > // We suggest the compiler to inline the next two functions so that it
1960 > // may specialise the code according to the current screen depth and
1961 > // display type. A clever compiler would do that job by itself though...
1962 >
1963 > // NOTE: update_display_vosf is inlined too
1964  
1965   static inline void possibly_quit_dga_mode()
1966   {
# Line 1981 | Line 2031 | static void video_refresh_dga_vosf(void)
2031          static int tick_counter = 0;
2032          if (++tick_counter >= frame_skip) {
2033                  tick_counter = 0;
2034 <                LOCK_VOSF;
2035 <                update_display_dga_vosf();
2036 <                UNLOCK_VOSF;
2034 >                if (mainBuffer.dirty) {
2035 >                        LOCK_VOSF;
2036 >                        update_display_dga_vosf();
2037 >                        UNLOCK_VOSF;
2038 >                }
2039          }
2040   }
2041   #endif
# Line 2003 | Line 2055 | static void video_refresh_window_vosf(vo
2055          static int tick_counter = 0;
2056          if (++tick_counter >= frame_skip) {
2057                  tick_counter = 0;
2058 <                LOCK_VOSF;
2059 <                update_display_window_vosf();
2060 <                UNLOCK_VOSF;
2058 >                if (mainBuffer.dirty) {
2059 >                        LOCK_VOSF;
2060 >                        update_display_window_vosf();
2061 >                        UNLOCK_VOSF;
2062 >                        XSync(x_display, false); // Let the server catch up
2063 >                }
2064          }
2065   }
2066   #endif // def ENABLE_VOSF
# Line 2092 | Line 2147 | static void *redraw_func(void *arg)
2147                  ticks++;
2148          }
2149          uint64 end = GetTicks_usec();
2150 <        printf("%Ld ticks in %Ld usec = %Ld ticks/sec\n", ticks, end - start, (end - start) / ticks);
2150 >        // printf("%Ld ticks in %Ld usec = %Ld ticks/sec\n", ticks, end - start, ticks * 1000000 / (end - start));
2151          return NULL;
2152   }
2153   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines