53 |
|
#endif |
54 |
|
|
55 |
|
#ifdef ENABLE_VOSF |
56 |
– |
# include <math.h> // log() |
56 |
|
# include <unistd.h> |
57 |
|
# include <signal.h> |
58 |
|
# include <fcntl.h> |
122 |
|
static XColor black, white; |
123 |
|
static unsigned long black_pixel, white_pixel; |
124 |
|
static int eventmask; |
125 |
< |
static const int win_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | ExposureMask; |
125 |
> |
static const int win_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | FocusChangeMask | ExposureMask; |
126 |
|
static const int dga_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask; |
127 |
|
|
128 |
|
static XColor palette[256]; // Color palette for 8-bit mode |
218 |
|
static pthread_mutex_t Screen_draw_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect frame buffer (dirtyPages in fact) |
219 |
|
#endif |
220 |
|
|
221 |
+ |
static int log_base_2(uint32 x) |
222 |
+ |
{ |
223 |
+ |
uint32 mask = 0x80000000; |
224 |
+ |
int l = 31; |
225 |
+ |
while (l >= 0 && (x & mask) == 0) { |
226 |
+ |
mask >>= 1; |
227 |
+ |
l--; |
228 |
+ |
} |
229 |
+ |
return l; |
230 |
+ |
} |
231 |
+ |
|
232 |
|
#endif |
233 |
|
|
234 |
|
// VideoRefresh function |
345 |
|
the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, |
346 |
|
InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel | |
347 |
|
CWBackingStore | CWBackingPlanes, &wattr); |
338 |
– |
XSync(x_display, false); |
339 |
– |
XStoreName(x_display, the_win, GetString(STR_WINDOW_TITLE)); |
340 |
– |
XMapRaised(x_display, the_win); |
341 |
– |
XSync(x_display, false); |
348 |
|
|
349 |
< |
// Set colormap |
350 |
< |
if (depth == 8) { |
351 |
< |
XSetWindowColormap(x_display, the_win, cmap[0]); |
352 |
< |
XSetWMColormapWindows(x_display, the_win, &the_win, 1); |
349 |
> |
// Indicate that we want keyboard input |
350 |
> |
{ |
351 |
> |
XWMHints *hints = XAllocWMHints(); |
352 |
> |
if (hints) { |
353 |
> |
hints->input = True; |
354 |
> |
hints->flags = InputHint; |
355 |
> |
XSetWMHints(x_display, the_win, hints); |
356 |
> |
XFree((char *)hints); |
357 |
> |
} |
358 |
|
} |
359 |
|
|
360 |
|
// Make window unresizable |
361 |
< |
XSizeHints *hints; |
362 |
< |
if ((hints = XAllocSizeHints()) != NULL) { |
363 |
< |
hints->min_width = width; |
364 |
< |
hints->max_width = width; |
365 |
< |
hints->min_height = height; |
366 |
< |
hints->max_height = height; |
367 |
< |
hints->flags = PMinSize | PMaxSize; |
368 |
< |
XSetWMNormalHints(x_display, the_win, hints); |
369 |
< |
XFree((char *)hints); |
361 |
> |
{ |
362 |
> |
XSizeHints *hints = XAllocSizeHints(); |
363 |
> |
if (hints) { |
364 |
> |
hints->min_width = width; |
365 |
> |
hints->max_width = width; |
366 |
> |
hints->min_height = height; |
367 |
> |
hints->max_height = height; |
368 |
> |
hints->flags = PMinSize | PMaxSize; |
369 |
> |
XSetWMNormalHints(x_display, the_win, hints); |
370 |
> |
XFree((char *)hints); |
371 |
> |
} |
372 |
|
} |
373 |
|
|
374 |
+ |
// Set window title |
375 |
+ |
{ |
376 |
+ |
XTextProperty title_prop; |
377 |
+ |
const char *title = GetString(STR_WINDOW_TITLE); |
378 |
+ |
XStringListToTextProperty((char **)&title, 1, &title_prop); |
379 |
+ |
XSetWMName(x_display, the_win, &title_prop); |
380 |
+ |
XFree(title_prop.value); |
381 |
+ |
} |
382 |
+ |
|
383 |
+ |
// Set window class |
384 |
+ |
{ |
385 |
+ |
XClassHint *hints; |
386 |
+ |
hints = XAllocClassHint(); |
387 |
+ |
if (hints) { |
388 |
+ |
hints->res_name = "BasiliskII"; |
389 |
+ |
hints->res_class = "BasiliskII"; |
390 |
+ |
XSetClassHint(x_display, the_win, hints); |
391 |
+ |
XFree((char *)hints); |
392 |
+ |
} |
393 |
+ |
} |
394 |
+ |
|
395 |
+ |
// Show window |
396 |
+ |
XSync(x_display, false); |
397 |
+ |
XMapRaised(x_display, the_win); |
398 |
+ |
XFlush(x_display); |
399 |
+ |
|
400 |
+ |
// Set colormap |
401 |
+ |
if (depth == 8) |
402 |
+ |
XSetWindowColormap(x_display, the_win, cmap[0]); |
403 |
+ |
|
404 |
|
// Try to create and attach SHM image |
405 |
|
have_shm = false; |
406 |
|
if (depth != 1 && local_X11 && XShmQueryExtension(x_display)) { |
596 |
|
GrabModeAsync, GrabModeAsync, the_win, None, CurrentTime); |
597 |
|
|
598 |
|
// Set colormap |
599 |
< |
if (depth == 8) { |
599 |
> |
if (depth == 8) |
600 |
|
XSetWindowColormap(x_display, the_win, cmap[0]); |
558 |
– |
XSetWMColormapWindows(x_display, the_win, &the_win, 1); |
559 |
– |
} |
601 |
|
|
602 |
|
// Set VideoMonitor |
603 |
|
int bytes_per_row = width; |
624 |
|
} |
625 |
|
} |
626 |
|
|
627 |
+ |
#if ENABLE_VOSF |
628 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
629 |
|
// If the blit function is null, i.e. just a copy of the buffer, |
630 |
|
// we first try to avoid the allocation of a temporary frame buffer |
641 |
|
the_buffer = (uint8 *)allocate_framebuffer(the_buffer_size); |
642 |
|
memset(the_buffer, 0, the_buffer_size); |
643 |
|
} |
644 |
< |
#elif ENABLE_VOSF |
644 |
> |
#else |
645 |
|
use_vosf = false; |
646 |
|
#endif |
647 |
+ |
#endif |
648 |
|
|
649 |
|
set_video_monitor(width, height, bytes_per_row, true); |
650 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
710 |
|
// Set colormap |
711 |
|
if (depth == 8) { |
712 |
|
XSetWindowColormap(x_display, the_win, cmap[current_dga_cmap = 0]); |
670 |
– |
XSetWMColormapWindows(x_display, the_win, &the_win, 1); |
713 |
|
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
714 |
|
} |
715 |
|
|
745 |
|
the_buffer = (uint8 *)allocate_framebuffer(the_buffer_size); |
746 |
|
memset(the_buffer, 0, the_buffer_size); |
747 |
|
} |
748 |
< |
#elif ENABLE_VOSF |
748 |
> |
#elif defined(ENABLE_VOSF) |
749 |
|
// The UAE memory handlers will already handle color conversion, if needed. |
750 |
|
use_vosf = false; |
751 |
|
#endif |
844 |
|
|
845 |
|
mainBuffer.pageSize = page_size; |
846 |
|
mainBuffer.pageCount = (mainBuffer.memLength + page_mask)/mainBuffer.pageSize; |
847 |
< |
mainBuffer.pageBits = int( log(mainBuffer.pageSize) / log(2.0) ); |
847 |
> |
mainBuffer.pageBits = log_base_2(mainBuffer.pageSize); |
848 |
|
|
849 |
|
if (mainBuffer.dirtyPages != 0) |
850 |
|
free(mainBuffer.dirtyPages); |
1239 |
|
|
1240 |
|
void video_set_palette(uint8 *pal) |
1241 |
|
{ |
1242 |
< |
#ifdef HAVE_PTHREDS |
1242 |
> |
#ifdef HAVE_PTHREADS |
1243 |
|
pthread_mutex_lock(&palette_lock); |
1244 |
|
#endif |
1245 |
|
|
1330 |
|
XF86DGASetViewPort(x_display, screen, 0, 0); |
1331 |
|
#endif |
1332 |
|
XSync(x_display, false); |
1333 |
< |
|
1334 |
< |
// Restore frame buffer |
1335 |
< |
if (fb_save) { |
1336 |
< |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
1337 |
< |
if (use_vosf) |
1338 |
< |
mprotect((caddr_t)mainBuffer.memStart, mainBuffer.memLength, PROT_READ|PROT_WRITE); |
1297 |
< |
#endif |
1298 |
< |
memcpy(the_buffer, fb_save, VideoMonitor.y * VideoMonitor.bytes_per_row); |
1299 |
< |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
1300 |
< |
if (use_vosf) { |
1301 |
< |
mprotect((caddr_t)mainBuffer.memStart, mainBuffer.memLength, PROT_READ); |
1302 |
< |
do_update_framebuffer(the_host_buffer, the_buffer, VideoMonitor.x * VideoMonitor.bytes_per_row); |
1333 |
> |
|
1334 |
> |
// the_buffer already contains the data to restore. i.e. since a temporary |
1335 |
> |
// frame buffer is used when VOSF is actually used, fb_save is therefore |
1336 |
> |
// not necessary. |
1337 |
> |
#ifdef ENABLE_VOSF |
1338 |
> |
if (use_vosf) { |
1339 |
|
#ifdef HAVE_PTHREADS |
1340 |
< |
pthread_mutex_lock(&Screen_draw_lock); |
1340 |
> |
pthread_mutex_lock(&Screen_draw_lock); |
1341 |
|
#endif |
1342 |
< |
PFLAG_CLEAR_ALL; |
1342 |
> |
PFLAG_SET_ALL; |
1343 |
|
#ifdef HAVE_PTHREADS |
1344 |
< |
pthread_mutex_unlock(&Screen_draw_lock); |
1344 |
> |
pthread_mutex_unlock(&Screen_draw_lock); |
1345 |
|
#endif |
1346 |
< |
} |
1346 |
> |
memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y); |
1347 |
> |
} |
1348 |
|
#endif |
1349 |
+ |
|
1350 |
+ |
// Restore frame buffer |
1351 |
+ |
if (fb_save) { |
1352 |
+ |
#ifdef ENABLE_VOSF |
1353 |
+ |
// Don't copy fb_save to the temporary frame buffer in VOSF mode |
1354 |
+ |
if (!use_vosf) |
1355 |
+ |
#endif |
1356 |
+ |
memcpy(the_buffer, fb_save, VideoMonitor.y * VideoMonitor.bytes_per_row); |
1357 |
|
free(fb_save); |
1358 |
|
fb_save = NULL; |
1359 |
|
} |
1634 |
|
// Hidden parts exposed, force complete refresh of window |
1635 |
|
case Expose: |
1636 |
|
if (display_type == DISPLAY_WINDOW) { |
1592 |
– |
if (frame_skip == 0) { // Dynamic refresh |
1593 |
– |
int x1, y1; |
1594 |
– |
for (y1=0; y1<16; y1++) |
1595 |
– |
for (x1=0; x1<16; x1++) |
1596 |
– |
updt_box[x1][y1] = true; |
1597 |
– |
nr_boxes = 16 * 16; |
1598 |
– |
} else { |
1637 |
|
#ifdef ENABLE_VOSF |
1638 |
+ |
if (use_vosf) { // VOSF refresh |
1639 |
|
#ifdef HAVE_PTHREADS |
1640 |
|
pthread_mutex_lock(&Screen_draw_lock); |
1641 |
|
#endif |
1643 |
|
#ifdef HAVE_PTHREADS |
1644 |
|
pthread_mutex_unlock(&Screen_draw_lock); |
1645 |
|
#endif |
1607 |
– |
#endif |
1646 |
|
memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y); |
1647 |
|
} |
1648 |
+ |
else |
1649 |
+ |
#endif |
1650 |
+ |
if (frame_skip == 0) { // Dynamic refresh |
1651 |
+ |
int x1, y1; |
1652 |
+ |
for (y1=0; y1<16; y1++) |
1653 |
+ |
for (x1=0; x1<16; x1++) |
1654 |
+ |
updt_box[x1][y1] = true; |
1655 |
+ |
nr_boxes = 16 * 16; |
1656 |
+ |
} else // Static refresh |
1657 |
+ |
memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y); |
1658 |
|
} |
1659 |
|
break; |
1660 |
+ |
|
1661 |
+ |
case FocusIn: |
1662 |
+ |
case FocusOut: |
1663 |
+ |
break; |
1664 |
|
} |
1665 |
|
} |
1666 |
|
} |
1789 |
|
// Check for first column from left and first column from right that have changed |
1790 |
|
if (high) { |
1791 |
|
if (depth == 1) { |
1792 |
< |
x1 = VideoMonitor.x; |
1792 |
> |
x1 = VideoMonitor.x - 1; |
1793 |
|
for (j=y1; j<=y2; j++) { |
1794 |
|
p = &the_buffer[j * bytes_per_row]; |
1795 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1810 |
|
for (i=(VideoMonitor.x>>3); i>(x2>>3); i--) { |
1811 |
|
p--; p2--; |
1812 |
|
if (*p != *p2) { |
1813 |
< |
x2 = i << 3; |
1813 |
> |
x2 = (i << 3) + 7; |
1814 |
|
break; |
1815 |
|
} |
1816 |
|
} |
1817 |
|
} |
1818 |
< |
wide = x2 - x1; |
1818 |
> |
wide = x2 - x1 + 1; |
1819 |
|
|
1820 |
|
// Update copy of the_buffer |
1821 |
|
if (high && wide) { |
1951 |
|
handle_palette_changes(depth, DISPLAY_DGA); |
1952 |
|
} |
1953 |
|
|
1954 |
+ |
#ifdef ENABLE_VOSF |
1955 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
1956 |
|
static void video_refresh_dga_vosf(void) |
1957 |
|
{ |
1979 |
|
} |
1980 |
|
#endif |
1981 |
|
|
1929 |
– |
#ifdef ENABLE_VOSF |
1982 |
|
static void video_refresh_window_vosf(void) |
1983 |
|
{ |
1984 |
|
// Quit DGA mode if requested |
2003 |
|
#endif |
2004 |
|
} |
2005 |
|
} |
2006 |
< |
#endif |
2006 |
> |
#endif // def ENABLE_VOSF |
2007 |
|
|
2008 |
|
static void video_refresh_window_static(void) |
2009 |
|
{ |
2044 |
|
{ |
2045 |
|
// TODO: set up specialised 8bpp VideoRefresh handlers ? |
2046 |
|
if (display_type == DISPLAY_DGA) { |
2047 |
< |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
2047 |
> |
#if ENABLE_VOSF && (REAL_ADDRESSING || DIRECT_ADDRESSING) |
2048 |
|
if (use_vosf) |
2049 |
|
video_refresh = video_refresh_dga_vosf; |
2050 |
|
else |