52 |
|
#include <X11/extensions/xf86dga.h> |
53 |
|
#endif |
54 |
|
|
55 |
+ |
#if ENABLE_XF86_VIDMODE |
56 |
+ |
#include <X11/extensions/xf86vmode.h> |
57 |
+ |
#endif |
58 |
+ |
|
59 |
|
#if ENABLE_FBDEV_DGA |
60 |
|
#include <sys/mman.h> |
61 |
|
#endif |
75 |
|
|
76 |
|
|
77 |
|
// Global variables |
78 |
< |
static int32 frame_skip; |
78 |
> |
static int32 frame_skip; // Prefs items |
79 |
> |
static int16 mouse_wheel_mode = 1; |
80 |
> |
static int16 mouse_wheel_lines = 3; |
81 |
> |
|
82 |
|
static int display_type = DISPLAY_WINDOW; // See enum above |
83 |
|
static uint8 *the_buffer; // Mac frame buffer |
84 |
|
static bool redraw_thread_active = false; // Flag: Redraw thread installed |
86 |
|
static pthread_t redraw_thread; // Redraw thread |
87 |
|
|
88 |
|
static bool has_dga = false; // Flag: Video DGA capable |
89 |
+ |
static bool has_vidmode = false; // Flag: VidMode extension available |
90 |
|
|
91 |
|
static bool ctrl_down = false; // Flag: Ctrl key pressed |
92 |
|
static bool caps_on = false; // Flag: Caps Lock on |
139 |
|
const char FBDEVICE_FILE_NAME[] = "/dev/fb"; |
140 |
|
static int fbdev_fd; |
141 |
|
|
142 |
+ |
#if ENABLE_XF86_VIDMODE |
143 |
+ |
// Variables for XF86 VidMode support |
144 |
+ |
static XF86VidModeModeInfo **x_video_modes; // Array of all available modes |
145 |
+ |
static int num_x_video_modes; |
146 |
+ |
#endif |
147 |
+ |
|
148 |
|
|
149 |
|
// Prototypes |
150 |
|
static void *redraw_func(void *arg); |
354 |
|
int ndepths, max_depth(0); |
355 |
|
int *depths = XListDepths(x_display, screen, &ndepths); |
356 |
|
if (depths == NULL) { |
357 |
< |
fprintf(stderr, "Error: could not determine the maximal depth available\n"); |
357 |
> |
printf("FATAL: Could not determine the maximal depth available\n"); |
358 |
|
return false; |
359 |
|
} else { |
360 |
|
while (ndepths-- > 0) { |
443 |
|
|
444 |
|
// Set colormap |
445 |
|
if (depth == 8) { |
446 |
< |
XSetWindowColormap(x_display, the_win, cmap[current_dga_cmap = 0]); |
446 |
> |
XSetWindowColormap(x_display, the_win, cmap[0]); |
447 |
|
XSetWMColormapWindows(x_display, the_win, &the_win, 1); |
448 |
|
} |
449 |
|
|
479 |
|
#else |
480 |
|
VideoMonitor.mac_frame_base = MacFrameBaseMac; |
481 |
|
#endif |
468 |
– |
|
469 |
– |
printf("FbDev DGA with %s in %d-bit mode enabled\n", fb_name, fb_depth); |
482 |
|
return true; |
483 |
|
#else |
484 |
|
ErrorAlert("Basilisk II has been compiled with fbdev DGA support disabled."); |
493 |
|
// Set relative mouse mode |
494 |
|
ADBSetRelMouseMode(true); |
495 |
|
|
496 |
+ |
#if ENABLE_XF86_VIDMODE |
497 |
+ |
// Switch to best mode |
498 |
+ |
if (has_vidmode) { |
499 |
+ |
int best = 0; |
500 |
+ |
for (int i=1; i<num_x_video_modes; i++) { |
501 |
+ |
if (x_video_modes[i]->hdisplay >= width && x_video_modes[i]->vdisplay >= height && |
502 |
+ |
x_video_modes[i]->hdisplay <= x_video_modes[best]->hdisplay && x_video_modes[i]->vdisplay <= x_video_modes[best]->vdisplay) { |
503 |
+ |
best = i; |
504 |
+ |
} |
505 |
+ |
} |
506 |
+ |
XF86VidModeSwitchToMode(x_display, screen, x_video_modes[best]); |
507 |
+ |
XF86VidModeSetViewPort(x_display, screen, 0, 0); |
508 |
+ |
} |
509 |
+ |
#endif |
510 |
+ |
|
511 |
|
// Create window |
512 |
|
XSetWindowAttributes wattr; |
513 |
|
wattr.event_mask = eventmask = dga_eventmask; |
640 |
|
// Init keycode translation |
641 |
|
keycode_init(); |
642 |
|
|
643 |
+ |
// Read prefs |
644 |
+ |
mouse_wheel_mode = PrefsFindInt16("mousewheelmode"); |
645 |
+ |
mouse_wheel_lines = PrefsFindInt16("mousewheellines"); |
646 |
+ |
|
647 |
|
// Find screen and root window |
648 |
|
screen = XDefaultScreen(x_display); |
649 |
|
rootwin = XRootWindow(x_display, screen); |
661 |
|
else |
662 |
|
has_dga = false; |
663 |
|
#endif |
664 |
< |
|
664 |
> |
|
665 |
|
#if ENABLE_XF86_DGA |
666 |
|
// DGA available? |
667 |
< |
int event_base, error_base; |
668 |
< |
if (XF86DGAQueryExtension(x_display, &event_base, &error_base)) { |
667 |
> |
int dga_event_base, dga_error_base; |
668 |
> |
if (XF86DGAQueryExtension(x_display, &dga_event_base, &dga_error_base)) { |
669 |
|
int dga_flags = 0; |
670 |
|
XF86DGAQueryDirectVideo(x_display, screen, &dga_flags); |
671 |
|
has_dga = dga_flags & XF86DGADirectPresent; |
673 |
|
has_dga = false; |
674 |
|
#endif |
675 |
|
|
676 |
+ |
#if ENABLE_XF86_VIDMODE |
677 |
+ |
// VidMode available? |
678 |
+ |
int vm_event_base, vm_error_base; |
679 |
+ |
has_vidmode = XF86VidModeQueryExtension(x_display, &vm_event_base, &vm_error_base); |
680 |
+ |
if (has_vidmode) |
681 |
+ |
XF86VidModeGetAllModeLines(x_display, screen, &num_x_video_modes, &x_video_modes); |
682 |
+ |
#endif |
683 |
+ |
|
684 |
|
// Find black and white colors |
685 |
|
XParseColor(x_display, DefaultColormap(x_display, screen), "rgb:00/00/00", &black); |
686 |
|
XAllocColor(x_display, DefaultColormap(x_display, screen), &black); |
832 |
|
} |
833 |
|
#endif |
834 |
|
|
835 |
+ |
#if ENABLE_XF86_VIDMODE |
836 |
+ |
if (has_vidmode && display_type == DISPLAY_DGA) |
837 |
+ |
XF86VidModeSwitchToMode(x_display, screen, x_video_modes[0]); |
838 |
+ |
#endif |
839 |
+ |
|
840 |
|
#if ENABLE_FBDEV_DGA |
841 |
|
if (display_type == DISPLAY_DGA) { |
842 |
|
XUngrabPointer(x_display, CurrentTime); |
992 |
|
#if ENABLE_XF86_DGA |
993 |
|
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
994 |
|
#endif |
951 |
– |
#if ENABLE_FBDEV_DGA |
952 |
– |
XSetWindowColormap(x_display, the_win, cmap[current_dga_cmap]); |
953 |
– |
#endif |
995 |
|
|
996 |
|
// Unlock frame buffer (and continue MacOS thread) |
997 |
|
pthread_mutex_unlock(&frame_buffer_lock); |
1183 |
|
unsigned int button = ((XButtonEvent *)&event)->button; |
1184 |
|
if (button < 4) |
1185 |
|
ADBMouseDown(button - 1); |
1186 |
+ |
else if (button < 6) { // Wheel mouse |
1187 |
+ |
if (mouse_wheel_mode == 0) { |
1188 |
+ |
int key = (button == 5) ? 0x79 : 0x74; // Page up/down |
1189 |
+ |
ADBKeyDown(key); |
1190 |
+ |
ADBKeyUp(key); |
1191 |
+ |
} else { |
1192 |
+ |
int key = (button == 5) ? 0x3d : 0x3e; // Cursor up/down |
1193 |
+ |
for(int i=0; i<mouse_wheel_lines; i++) { |
1194 |
+ |
ADBKeyDown(key); |
1195 |
+ |
ADBKeyUp(key); |
1196 |
+ |
} |
1197 |
+ |
} |
1198 |
+ |
} |
1199 |
|
break; |
1200 |
|
} |
1201 |
|
case ButtonRelease: { |
1277 |
|
{ |
1278 |
|
// In classic mode, copy the frame buffer from Mac RAM |
1279 |
|
if (classic_mode) |
1280 |
< |
memcpy(the_buffer, Mac2HostAddr(0x3fa700), VideoMonitor.bytes_per_row * VideoMonitor.y); |
1280 |
> |
Mac2Host_memcpy(the_buffer, 0x3fa700, VideoMonitor.bytes_per_row * VideoMonitor.y); |
1281 |
|
|
1282 |
|
// Incremental update code |
1283 |
|
int wide = 0, high = 0, x1, x2, y1, y2, i, j; |
1397 |
|
|
1398 |
|
// Set new cursor image if it was changed |
1399 |
|
if (memcmp(the_cursor, Mac2HostAddr(0x844), 64)) { |
1400 |
< |
memcpy(the_cursor, Mac2HostAddr(0x844), 64); |
1400 |
> |
Mac2Host_memcpy(the_cursor, 0x844, 64); |
1401 |
|
memcpy(cursor_image->data, the_cursor, 32); |
1402 |
|
memcpy(cursor_mask_image->data, the_cursor+32, 32); |
1403 |
|
XFreeCursor(x_display, mac_cursor); |
1471 |
|
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
1472 |
|
} |
1473 |
|
#endif |
1420 |
– |
|
1421 |
– |
#if ENABLE_FBDEV_DGA |
1422 |
– |
if (display_type == DISPLAY_DGA) |
1423 |
– |
XSetWindowColormap(x_display, the_win, cmap[current_dga_cmap]); |
1424 |
– |
#endif |
1474 |
|
} |
1475 |
|
} |
1476 |
|
pthread_mutex_unlock(&palette_lock); |