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 | FocusChangeMask | ExposureMask; |
126 |
< |
static const int dga_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask; |
125 |
> |
static const int win_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | ExposureMask | StructureNotifyMask; |
126 |
> |
static const int dga_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask; |
127 |
> |
static Atom WM_DELETE_WINDOW = (Atom)0; |
128 |
|
|
129 |
|
static XColor palette[256]; // Color palette for 8-bit mode |
130 |
|
static bool palette_changed = false; // Flag: Palette changed, redraw thread must set new colors |
131 |
|
#ifdef HAVE_PTHREADS |
132 |
|
static pthread_mutex_t palette_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect palette |
133 |
+ |
#define LOCK_PALETTE pthread_mutex_lock(&palette_lock) |
134 |
+ |
#define UNLOCK_PALETTE pthread_mutex_unlock(&palette_lock) |
135 |
+ |
#else |
136 |
+ |
#define LOCK_PALETTE |
137 |
+ |
#define UNLOCK_PALETTE |
138 |
|
#endif |
139 |
|
|
140 |
|
// Variables for window mode |
155 |
|
static void *fb_save = NULL; // Saved frame buffer for suspend |
156 |
|
#ifdef HAVE_PTHREADS |
157 |
|
static pthread_mutex_t frame_buffer_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect frame buffer |
158 |
+ |
#define LOCK_FRAME_BUFFER pthread_mutex_lock(&frame_buffer_lock); |
159 |
+ |
#define UNLOCK_FRAME_BUFFER pthread_mutex_unlock(&frame_buffer_lock); |
160 |
+ |
#else |
161 |
+ |
#define LOCK_FRAME_BUFFER |
162 |
+ |
#define UNLOCK_FRAME_BUFFER |
163 |
|
#endif |
164 |
|
|
165 |
|
// Variables for fbdev DGA mode |
179 |
|
#endif |
180 |
|
|
181 |
|
#ifdef ENABLE_VOSF |
182 |
< |
static uint8 * the_host_buffer; // Host frame buffer in VOSF mode |
182 |
> |
// Variables for Video on SEGV support (taken from the Win32 port) |
183 |
> |
static uint8 *the_host_buffer; // Host frame buffer in VOSF mode |
184 |
|
static uint32 the_buffer_size; // Size of allocated the_buffer |
173 |
– |
#endif |
185 |
|
|
175 |
– |
#ifdef ENABLE_VOSF |
176 |
– |
// Variables for Video on SEGV support (taken from the Win32 port) |
186 |
|
struct ScreenPageInfo { |
187 |
|
int top, bottom; // Mapping between this virtual page and Mac scanlines |
188 |
|
}; |
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 |
> |
char * dirtyPages; // Table of flags set if page was altered |
201 |
|
ScreenPageInfo * pageInfo; // Table of mappings page -> Mac scanlines |
202 |
|
}; |
203 |
|
|
204 |
|
static ScreenInfo mainBuffer; |
205 |
|
|
206 |
< |
#define PFLAG_SET(page) mainBuffer.dirtyPages[page] = 1 |
207 |
< |
#define PFLAG_CLEAR(page) mainBuffer.dirtyPages[page] = 0 |
208 |
< |
#define PFLAG_ISSET(page) mainBuffer.dirtyPages[page] |
209 |
< |
#define PFLAG_ISCLEAR(page) (mainBuffer.dirtyPages[page] == 0) |
206 |
> |
#define PFLAG_SET_VALUE 0x00 |
207 |
> |
#define PFLAG_CLEAR_VALUE 0x01 |
208 |
> |
#define PFLAG_SET_VALUE_4 0x00000000 |
209 |
> |
#define PFLAG_CLEAR_VALUE_4 0x01010101 |
210 |
> |
#define PFLAG_SET(page) mainBuffer.dirtyPages[page] = PFLAG_SET_VALUE |
211 |
> |
#define PFLAG_CLEAR(page) mainBuffer.dirtyPages[page] = PFLAG_CLEAR_VALUE |
212 |
> |
#define PFLAG_ISSET(page) (mainBuffer.dirtyPages[page] == PFLAG_SET_VALUE) |
213 |
> |
#define PFLAG_ISCLEAR(page) (mainBuffer.dirtyPages[page] != PFLAG_SET_VALUE) |
214 |
> |
|
215 |
|
#ifdef UNALIGNED_PROFITABLE |
216 |
< |
# define PFLAG_ISCLEAR_4(page) (*((uint32 *)(mainBuffer.dirtyPages + page)) == 0) |
216 |
> |
# define PFLAG_ISSET_4(page) (*((uint32 *)(mainBuffer.dirtyPages + (page))) == PFLAG_SET_VALUE_4) |
217 |
> |
# define PFLAG_ISCLEAR_4(page) (*((uint32 *)(mainBuffer.dirtyPages + (page))) == PFLAG_CLEAR_VALUE_4) |
218 |
> |
#else |
219 |
> |
# define PFLAG_ISSET_4(page) \ |
220 |
> |
PFLAG_ISSET(page ) && PFLAG_ISSET(page+1) \ |
221 |
> |
&& PFLAG_ISSET(page+2) && PFLAG_ISSET(page+3) |
222 |
> |
# define PFLAG_ISCLEAR_4(page) \ |
223 |
> |
PFLAG_ISCLEAR(page ) && PFLAG_ISCLEAR(page+1) \ |
224 |
> |
&& PFLAG_ISCLEAR(page+2) && PFLAG_ISCLEAR(page+3) |
225 |
> |
#endif |
226 |
> |
|
227 |
> |
// Set the selected page range [ first_page, last_page [ into the SET state |
228 |
> |
#define PFLAG_SET_RANGE(first_page, last_page) \ |
229 |
> |
memset(mainBuffer.dirtyPages + (first_page), PFLAG_SET_VALUE, \ |
230 |
> |
(last_page) - (first_page)) |
231 |
> |
|
232 |
> |
// Set the selected page range [ first_page, last_page [ into the CLEAR state |
233 |
> |
#define PFLAG_CLEAR_RANGE(first_page, last_page) \ |
234 |
> |
memset(mainBuffer.dirtyPages + (first_page), PFLAG_CLEAR_VALUE, \ |
235 |
> |
(last_page) - (first_page)) |
236 |
> |
|
237 |
> |
#define PFLAG_SET_ALL \ |
238 |
> |
PFLAG_SET_RANGE(0, mainBuffer.pageCount) |
239 |
> |
|
240 |
> |
#define PFLAG_CLEAR_ALL \ |
241 |
> |
PFLAG_CLEAR_RANGE(0, mainBuffer.pageCount) |
242 |
> |
|
243 |
> |
// Set the following macro definition to 1 if your system |
244 |
> |
// provides a really fast strchr() implementation |
245 |
> |
//#define HAVE_FAST_STRCHR 0 |
246 |
> |
|
247 |
> |
static inline int find_next_page_set(int page) |
248 |
> |
{ |
249 |
> |
#if HAVE_FAST_STRCHR |
250 |
> |
char *match = strchr(mainBuffer.dirtyPages + page, PFLAG_SET_VALUE); |
251 |
> |
return match ? match - mainBuffer.dirtyPages : mainBuffer.pageCount; |
252 |
> |
#else |
253 |
> |
while (PFLAG_ISCLEAR_4(page)) |
254 |
> |
page += 4; |
255 |
> |
while (PFLAG_ISCLEAR(page)) |
256 |
> |
page++; |
257 |
> |
return page; |
258 |
> |
#endif |
259 |
> |
} |
260 |
> |
|
261 |
> |
static inline int find_next_page_clear(int page) |
262 |
> |
{ |
263 |
> |
#if HAVE_FAST_STRCHR |
264 |
> |
char *match = strchr(mainBuffer.dirtyPages + page, PFLAG_CLEAR_VALUE); |
265 |
> |
return match ? match - mainBuffer.dirtyPages : mainBuffer.pageCount; |
266 |
|
#else |
267 |
< |
# define PFLAG_ISCLEAR_4(page) \ |
268 |
< |
(mainBuffer.dirtyPages[page ] == 0) \ |
269 |
< |
&& (mainBuffer.dirtyPages[page+1] == 0) \ |
270 |
< |
&& (mainBuffer.dirtyPages[page+2] == 0) \ |
271 |
< |
&& (mainBuffer.dirtyPages[page+3] == 0) |
267 |
> |
while (PFLAG_ISSET_4(page)) |
268 |
> |
page += 4; |
269 |
> |
while (PFLAG_ISSET(page)) |
270 |
> |
page++; |
271 |
> |
return page; |
272 |
|
#endif |
273 |
< |
#define PFLAG_CLEAR_ALL memset(mainBuffer.dirtyPages, 0, mainBuffer.pageCount) |
211 |
< |
#define PFLAG_SET_ALL memset(mainBuffer.dirtyPages, 1, mainBuffer.pageCount) |
273 |
> |
} |
274 |
|
|
275 |
|
static int zero_fd = -1; |
276 |
|
static bool Screen_fault_handler_init(); |
277 |
|
static struct sigaction vosf_sa; |
278 |
|
|
279 |
|
#ifdef HAVE_PTHREADS |
280 |
< |
static pthread_mutex_t Screen_draw_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect frame buffer (dirtyPages in fact) |
280 |
> |
static pthread_mutex_t vosf_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect frame buffer (dirtyPages in fact) |
281 |
> |
#define LOCK_VOSF pthread_mutex_lock(&vosf_lock); |
282 |
> |
#define UNLOCK_VOSF pthread_mutex_unlock(&vosf_lock); |
283 |
> |
#else |
284 |
> |
#define LOCK_VOSF |
285 |
> |
#define UNLOCK_VOSF |
286 |
|
#endif |
287 |
|
|
288 |
|
static int log_base_2(uint32 x) |
295 |
|
} |
296 |
|
return l; |
297 |
|
} |
298 |
< |
|
232 |
< |
#endif |
298 |
> |
#endif /* ENABLE_VOSF */ |
299 |
|
|
300 |
|
// VideoRefresh function |
301 |
|
void VideoRefreshInit(void); |
303 |
|
|
304 |
|
// Prototypes |
305 |
|
static void *redraw_func(void *arg); |
306 |
< |
static int event2keycode(XKeyEvent *ev); |
306 |
> |
static int event2keycode(XKeyEvent &ev); |
307 |
|
|
308 |
|
|
309 |
|
// From main_unix.cpp |
373 |
|
VideoMonitor.bytes_per_row = bytes_per_row; |
374 |
|
} |
375 |
|
|
376 |
+ |
// Set window name and class |
377 |
+ |
static void set_window_name(Window w, int name) |
378 |
+ |
{ |
379 |
+ |
const char *str = GetString(name); |
380 |
+ |
XStoreName(x_display, w, str); |
381 |
+ |
XSetIconName(x_display, w, str); |
382 |
+ |
|
383 |
+ |
XClassHint *hints; |
384 |
+ |
hints = XAllocClassHint(); |
385 |
+ |
if (hints) { |
386 |
+ |
hints->res_name = "BasiliskII"; |
387 |
+ |
hints->res_class = "BasiliskII"; |
388 |
+ |
XSetClassHint(x_display, w, hints); |
389 |
+ |
XFree(hints); |
390 |
+ |
} |
391 |
+ |
} |
392 |
+ |
|
393 |
+ |
// Set window input focus flag |
394 |
+ |
static void set_window_focus(Window w) |
395 |
+ |
{ |
396 |
+ |
XWMHints *hints = XAllocWMHints(); |
397 |
+ |
if (hints) { |
398 |
+ |
hints->input = True; |
399 |
+ |
hints->initial_state = NormalState; |
400 |
+ |
hints->flags = InputHint | StateHint; |
401 |
+ |
XSetWMHints(x_display, w, hints); |
402 |
+ |
XFree(hints); |
403 |
+ |
} |
404 |
+ |
} |
405 |
+ |
|
406 |
+ |
// Set WM_DELETE_WINDOW protocol on window (preventing it from being destroyed by the WM when clicking on the "close" widget) |
407 |
+ |
static void set_window_delete_protocol(Window w) |
408 |
+ |
{ |
409 |
+ |
WM_DELETE_WINDOW = XInternAtom(x_display, "WM_DELETE_WINDOW", false); |
410 |
+ |
XSetWMProtocols(x_display, w, &WM_DELETE_WINDOW, 1); |
411 |
+ |
} |
412 |
+ |
|
413 |
+ |
// Wait until window is mapped/unmapped |
414 |
+ |
void wait_mapped(Window w) |
415 |
+ |
{ |
416 |
+ |
XEvent e; |
417 |
+ |
do { |
418 |
+ |
XMaskEvent(x_display, StructureNotifyMask, &e); |
419 |
+ |
} while ((e.type != MapNotify) || (e.xmap.event != w)); |
420 |
+ |
} |
421 |
+ |
|
422 |
+ |
void wait_unmapped(Window w) |
423 |
+ |
{ |
424 |
+ |
XEvent e; |
425 |
+ |
do { |
426 |
+ |
XMaskEvent(x_display, StructureNotifyMask, &e); |
427 |
+ |
} while ((e.type != UnmapNotify) || (e.xmap.event != w)); |
428 |
+ |
} |
429 |
+ |
|
430 |
|
// Trap SHM errors |
431 |
|
static bool shm_error = false; |
432 |
|
static int (*old_error_handler)(Display *, XErrorEvent *); |
456 |
|
XSetWindowAttributes wattr; |
457 |
|
wattr.event_mask = eventmask = win_eventmask; |
458 |
|
wattr.background_pixel = black_pixel; |
459 |
+ |
wattr.colormap = cmap[0]; |
460 |
|
|
340 |
– |
XSync(x_display, false); |
461 |
|
the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, |
462 |
< |
InputOutput, vis, CWEventMask | CWBackPixel, &wattr); |
462 |
> |
InputOutput, vis, CWEventMask | CWBackPixel | (depth == 8 ? CWColormap : 0), &wattr); |
463 |
> |
|
464 |
> |
// Set window name/class |
465 |
> |
set_window_name(the_win, STR_WINDOW_TITLE); |
466 |
|
|
467 |
|
// Indicate that we want keyboard input |
468 |
< |
{ |
469 |
< |
XWMHints *hints = XAllocWMHints(); |
470 |
< |
if (hints) { |
471 |
< |
hints->input = True; |
349 |
< |
hints->flags = InputHint; |
350 |
< |
XSetWMHints(x_display, the_win, hints); |
351 |
< |
XFree((char *)hints); |
352 |
< |
} |
353 |
< |
} |
468 |
> |
set_window_focus(the_win); |
469 |
> |
|
470 |
> |
// Set delete protocol property |
471 |
> |
set_window_delete_protocol(the_win); |
472 |
|
|
473 |
|
// Make window unresizable |
474 |
|
{ |
480 |
|
hints->max_height = height; |
481 |
|
hints->flags = PMinSize | PMaxSize; |
482 |
|
XSetWMNormalHints(x_display, the_win, hints); |
483 |
< |
XFree((char *)hints); |
483 |
> |
XFree(hints); |
484 |
|
} |
485 |
|
} |
486 |
|
|
369 |
– |
// Set window title |
370 |
– |
XStoreName(x_display, the_win, GetString(STR_WINDOW_TITLE)); |
371 |
– |
|
372 |
– |
// Set window class |
373 |
– |
{ |
374 |
– |
XClassHint *hints; |
375 |
– |
hints = XAllocClassHint(); |
376 |
– |
if (hints) { |
377 |
– |
hints->res_name = "BasiliskII"; |
378 |
– |
hints->res_class = "BasiliskII"; |
379 |
– |
XSetClassHint(x_display, the_win, hints); |
380 |
– |
XFree((char *)hints); |
381 |
– |
} |
382 |
– |
} |
383 |
– |
|
487 |
|
// Show window |
488 |
< |
XSync(x_display, false); |
489 |
< |
XMapRaised(x_display, the_win); |
387 |
< |
XFlush(x_display); |
388 |
< |
|
389 |
< |
// Set colormap |
390 |
< |
if (depth == 8) |
391 |
< |
XSetWindowColormap(x_display, the_win, cmap[0]); |
488 |
> |
XMapWindow(x_display, the_win); |
489 |
> |
wait_mapped(the_win); |
490 |
|
|
491 |
|
// Try to create and attach SHM image |
492 |
|
have_shm = false; |
570 |
|
// Set VideoMonitor |
571 |
|
bool native_byte_order; |
572 |
|
#ifdef WORDS_BIGENDIAN |
573 |
< |
native_byte_order = (img->bitmap_bit_order == MSBFirst); |
573 |
> |
native_byte_order = (XImageByteOrder(x_display) == MSBFirst); |
574 |
|
#else |
575 |
< |
native_byte_order = (img->bitmap_bit_order == LSBFirst); |
575 |
> |
native_byte_order = (XImageByteOrder(x_display) == LSBFirst); |
576 |
|
#endif |
577 |
|
#ifdef ENABLE_VOSF |
578 |
|
do_update_framebuffer = GET_FBCOPY_FUNC(depth, native_byte_order, DISPLAY_WINDOW); |
659 |
|
|
660 |
|
// Create window |
661 |
|
XSetWindowAttributes wattr; |
662 |
< |
wattr.event_mask = eventmask = dga_eventmask; |
663 |
< |
wattr.background_pixel = white_pixel; |
664 |
< |
wattr.override_redirect = True; |
662 |
> |
wattr.event_mask = eventmask = dga_eventmask; |
663 |
> |
wattr.background_pixel = white_pixel; |
664 |
> |
wattr.override_redirect = True; |
665 |
> |
wattr.colormap = cmap[0]; |
666 |
|
|
568 |
– |
XSync(x_display, false); |
667 |
|
the_win = XCreateWindow(x_display, rootwin, |
668 |
|
0, 0, width, height, |
669 |
|
0, xdepth, InputOutput, vis, |
670 |
< |
CWEventMask | CWBackPixel | CWOverrideRedirect, |
670 |
> |
CWEventMask | CWBackPixel | CWOverrideRedirect | (depth == 8 ? CWColormap : 0), |
671 |
|
&wattr); |
672 |
< |
XSync(x_display, false); |
672 |
> |
|
673 |
> |
// Set window name/class |
674 |
> |
set_window_name(the_win, STR_WINDOW_TITLE); |
675 |
> |
|
676 |
> |
// Indicate that we want keyboard input |
677 |
> |
set_window_focus(the_win); |
678 |
> |
|
679 |
> |
// Show window |
680 |
|
XMapRaised(x_display, the_win); |
681 |
< |
XSync(x_display, false); |
681 |
> |
wait_mapped(the_win); |
682 |
|
|
683 |
|
// Grab mouse and keyboard |
684 |
|
XGrabKeyboard(x_display, the_win, True, |
687 |
|
PointerMotionMask | ButtonPressMask | ButtonReleaseMask, |
688 |
|
GrabModeAsync, GrabModeAsync, the_win, None, CurrentTime); |
689 |
|
|
585 |
– |
// Set colormap |
586 |
– |
if (depth == 8) |
587 |
– |
XSetWindowColormap(x_display, the_win, cmap[0]); |
588 |
– |
|
690 |
|
// Set VideoMonitor |
691 |
|
int bytes_per_row = width; |
692 |
|
switch (depth) { |
766 |
|
} |
767 |
|
XF86VidModeSwitchToMode(x_display, screen, x_video_modes[best]); |
768 |
|
XF86VidModeSetViewPort(x_display, screen, 0, 0); |
769 |
+ |
XSync(x_display, false); |
770 |
|
} |
771 |
|
#endif |
772 |
|
|
775 |
|
wattr.event_mask = eventmask = dga_eventmask; |
776 |
|
wattr.override_redirect = True; |
777 |
|
|
676 |
– |
XSync(x_display, false); |
778 |
|
the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, |
779 |
|
InputOutput, vis, CWEventMask | CWOverrideRedirect, &wattr); |
780 |
< |
XSync(x_display, false); |
781 |
< |
XStoreName(x_display, the_win, GetString(STR_WINDOW_TITLE)); |
780 |
> |
|
781 |
> |
// Set window name/class |
782 |
> |
set_window_name(the_win, STR_WINDOW_TITLE); |
783 |
> |
|
784 |
> |
// Indicate that we want keyboard input |
785 |
> |
set_window_focus(the_win); |
786 |
> |
|
787 |
> |
// Show window |
788 |
|
XMapRaised(x_display, the_win); |
789 |
< |
XSync(x_display, false); |
789 |
> |
wait_mapped(the_win); |
790 |
|
|
791 |
|
// Establish direct screen connection |
792 |
|
XMoveResizeWindow(x_display, the_win, 0, 0, width, height); |
805 |
|
XSetWindowColormap(x_display, the_win, cmap[current_dga_cmap = 0]); |
806 |
|
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
807 |
|
} |
808 |
+ |
XSync(x_display, false); |
809 |
|
|
810 |
|
// Set VideoMonitor |
811 |
|
int bytes_per_row = (v_width + 7) & ~7; |
943 |
|
if (mainBuffer.dirtyPages != 0) |
944 |
|
free(mainBuffer.dirtyPages); |
945 |
|
|
946 |
< |
mainBuffer.dirtyPages = (uint8 *) malloc(mainBuffer.pageCount); |
946 |
> |
mainBuffer.dirtyPages = (char *) malloc(mainBuffer.pageCount + 2); |
947 |
|
|
948 |
|
if (mainBuffer.pageInfo != 0) |
949 |
|
free(mainBuffer.pageInfo); |
954 |
|
return false; |
955 |
|
|
956 |
|
PFLAG_CLEAR_ALL; |
957 |
+ |
// Safety net to insure the loops in the update routines will terminate |
958 |
+ |
// See a discussion in <video_vosf.h> for further details |
959 |
+ |
PFLAG_CLEAR(mainBuffer.pageCount); |
960 |
+ |
PFLAG_SET(mainBuffer.pageCount+1); |
961 |
|
|
962 |
|
uint32 a = 0; |
963 |
|
for (int i = 0; i < mainBuffer.pageCount; i++) { |
1010 |
|
keycode_init(); |
1011 |
|
|
1012 |
|
// Read prefs |
1013 |
< |
mouse_wheel_mode = PrefsFindInt16("mousewheelmode"); |
1014 |
< |
mouse_wheel_lines = PrefsFindInt16("mousewheellines"); |
1013 |
> |
mouse_wheel_mode = PrefsFindInt32("mousewheelmode"); |
1014 |
> |
mouse_wheel_lines = PrefsFindInt32("mousewheellines"); |
1015 |
|
|
1016 |
|
// Find screen and root window |
1017 |
|
screen = XDefaultScreen(x_display); |
1148 |
|
break; |
1149 |
|
} |
1150 |
|
|
1039 |
– |
#ifdef HAVE_PTHREADS |
1151 |
|
// Lock down frame buffer |
1152 |
< |
pthread_mutex_lock(&frame_buffer_lock); |
1042 |
< |
#endif |
1152 |
> |
LOCK_FRAME_BUFFER; |
1153 |
|
|
1154 |
|
#if !REAL_ADDRESSING && !DIRECT_ADDRESSING |
1155 |
|
// Set variables for UAE memory mapping |
1214 |
|
} |
1215 |
|
#endif |
1216 |
|
|
1107 |
– |
#ifdef HAVE_PTHREADS |
1217 |
|
// Unlock frame buffer |
1218 |
< |
pthread_mutex_unlock(&frame_buffer_lock); |
1110 |
< |
#endif |
1218 |
> |
UNLOCK_FRAME_BUFFER; |
1219 |
|
|
1220 |
|
// Close window and server connection |
1221 |
|
if (x_display != NULL) { |
1318 |
|
if (emerg_quit) |
1319 |
|
QuitEmulator(); |
1320 |
|
|
1213 |
– |
#ifdef HAVE_PTHREADS |
1321 |
|
// Temporarily give up frame buffer lock (this is the point where |
1322 |
|
// we are suspended when the user presses Ctrl-Tab) |
1323 |
< |
pthread_mutex_unlock(&frame_buffer_lock); |
1324 |
< |
pthread_mutex_lock(&frame_buffer_lock); |
1218 |
< |
#endif |
1323 |
> |
UNLOCK_FRAME_BUFFER; |
1324 |
> |
LOCK_FRAME_BUFFER; |
1325 |
|
} |
1326 |
|
|
1327 |
|
|
1331 |
|
|
1332 |
|
void video_set_palette(uint8 *pal) |
1333 |
|
{ |
1334 |
< |
#ifdef HAVE_PTHREADS |
1229 |
< |
pthread_mutex_lock(&palette_lock); |
1230 |
< |
#endif |
1334 |
> |
LOCK_PALETTE; |
1335 |
|
|
1336 |
|
// Convert colors to XColor array |
1337 |
|
for (int i=0; i<256; i++) { |
1345 |
|
// Tell redraw thread to change palette |
1346 |
|
palette_changed = true; |
1347 |
|
|
1348 |
< |
#ifdef HAVE_PTHREADS |
1245 |
< |
pthread_mutex_unlock(&palette_lock); |
1246 |
< |
#endif |
1348 |
> |
UNLOCK_PALETTE; |
1349 |
|
} |
1350 |
|
|
1351 |
|
|
1361 |
|
ADBKeyUp(0x36); |
1362 |
|
ctrl_down = false; |
1363 |
|
|
1262 |
– |
#ifdef HAVE_PTHREADS |
1364 |
|
// Lock frame buffer (this will stop the MacOS thread) |
1365 |
< |
pthread_mutex_lock(&frame_buffer_lock); |
1265 |
< |
#endif |
1365 |
> |
LOCK_FRAME_BUFFER; |
1366 |
|
|
1367 |
|
// Save frame buffer |
1368 |
|
fb_save = malloc(VideoMonitor.y * VideoMonitor.bytes_per_row); |
1376 |
|
XUngrabPointer(x_display, CurrentTime); |
1377 |
|
XUngrabKeyboard(x_display, CurrentTime); |
1378 |
|
XUnmapWindow(x_display, the_win); |
1379 |
< |
XSync(x_display, false); |
1379 |
> |
wait_unmapped(the_win); |
1380 |
|
|
1381 |
|
// Open "suspend" window |
1382 |
|
XSetWindowAttributes wattr; |
1383 |
|
wattr.event_mask = KeyPressMask; |
1384 |
|
wattr.background_pixel = black_pixel; |
1285 |
– |
wattr.backing_store = WhenMapped; |
1286 |
– |
wattr.backing_planes = xdepth; |
1287 |
– |
wattr.colormap = DefaultColormap(x_display, screen); |
1385 |
|
|
1289 |
– |
XSync(x_display, false); |
1386 |
|
suspend_win = XCreateWindow(x_display, rootwin, 0, 0, 512, 1, 0, xdepth, |
1387 |
< |
InputOutput, vis, CWEventMask | CWBackPixel | CWBackingStore | |
1388 |
< |
CWBackingPlanes | (xdepth == 8 ? CWColormap : 0), &wattr); |
1389 |
< |
XSync(x_display, false); |
1390 |
< |
XStoreName(x_display, suspend_win, GetString(STR_SUSPEND_WINDOW_TITLE)); |
1295 |
< |
XMapRaised(x_display, suspend_win); |
1296 |
< |
XSync(x_display, false); |
1387 |
> |
InputOutput, vis, CWEventMask | CWBackPixel, &wattr); |
1388 |
> |
set_window_name(suspend_win, STR_SUSPEND_WINDOW_TITLE); |
1389 |
> |
set_window_focus(suspend_win); |
1390 |
> |
XMapWindow(x_display, suspend_win); |
1391 |
|
emul_suspended = true; |
1392 |
|
} |
1393 |
|
} |
1400 |
|
|
1401 |
|
// Reopen full screen display |
1402 |
|
XMapRaised(x_display, the_win); |
1403 |
+ |
wait_mapped(the_win); |
1404 |
|
XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0); |
1310 |
– |
XSync(x_display, false); |
1405 |
|
XGrabKeyboard(x_display, rootwin, 1, GrabModeAsync, GrabModeAsync, CurrentTime); |
1406 |
|
XGrabPointer(x_display, rootwin, 1, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); |
1407 |
|
#ifdef ENABLE_XF86_DGA |
1415 |
|
// not necessary. |
1416 |
|
#ifdef ENABLE_VOSF |
1417 |
|
if (use_vosf) { |
1418 |
< |
#ifdef HAVE_PTHREADS |
1325 |
< |
pthread_mutex_lock(&Screen_draw_lock); |
1326 |
< |
#endif |
1418 |
> |
LOCK_VOSF; |
1419 |
|
PFLAG_SET_ALL; |
1420 |
< |
#ifdef HAVE_PTHREADS |
1329 |
< |
pthread_mutex_unlock(&Screen_draw_lock); |
1330 |
< |
#endif |
1420 |
> |
UNLOCK_VOSF; |
1421 |
|
memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y); |
1422 |
|
} |
1423 |
|
#endif |
1438 |
|
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
1439 |
|
#endif |
1440 |
|
|
1351 |
– |
#ifdef HAVE_PTHREADS |
1441 |
|
// Unlock frame buffer (and continue MacOS thread) |
1442 |
< |
pthread_mutex_unlock(&frame_buffer_lock); |
1442 |
> |
UNLOCK_FRAME_BUFFER; |
1443 |
|
emul_suspended = false; |
1355 |
– |
#endif |
1444 |
|
} |
1445 |
|
#endif |
1446 |
|
|
1594 |
|
return -1; |
1595 |
|
} |
1596 |
|
|
1597 |
< |
static int event2keycode(XKeyEvent *ev) |
1597 |
> |
static int event2keycode(XKeyEvent &ev) |
1598 |
|
{ |
1599 |
|
KeySym ks; |
1600 |
|
int as; |
1601 |
|
int i = 0; |
1602 |
|
|
1603 |
|
do { |
1604 |
< |
ks = XLookupKeysym(ev, i++); |
1604 |
> |
ks = XLookupKeysym(&ev, i++); |
1605 |
|
as = kc_decode(ks); |
1606 |
|
if (as != -1) |
1607 |
|
return as; |
1617 |
|
|
1618 |
|
static void handle_events(void) |
1619 |
|
{ |
1620 |
< |
XEvent event; |
1621 |
< |
for (;;) { |
1622 |
< |
if (!XCheckMaskEvent(x_display, eventmask, &event)) |
1535 |
< |
break; |
1620 |
> |
while (XPending(x_display)) { |
1621 |
> |
XEvent event; |
1622 |
> |
XNextEvent(x_display, &event); |
1623 |
|
|
1624 |
|
switch (event.type) { |
1625 |
|
// Mouse button |
1626 |
|
case ButtonPress: { |
1627 |
< |
unsigned int button = ((XButtonEvent *)&event)->button; |
1627 |
> |
unsigned int button = event.xbutton.button; |
1628 |
|
if (button < 4) |
1629 |
|
ADBMouseDown(button - 1); |
1630 |
|
else if (button < 6) { // Wheel mouse |
1643 |
|
break; |
1644 |
|
} |
1645 |
|
case ButtonRelease: { |
1646 |
< |
unsigned int button = ((XButtonEvent *)&event)->button; |
1646 |
> |
unsigned int button = event.xbutton.button; |
1647 |
|
if (button < 4) |
1648 |
|
ADBMouseUp(button - 1); |
1649 |
|
break; |
1651 |
|
|
1652 |
|
// Mouse moved |
1653 |
|
case EnterNotify: |
1567 |
– |
ADBMouseMoved(((XMotionEvent *)&event)->x, ((XMotionEvent *)&event)->y); |
1568 |
– |
break; |
1654 |
|
case MotionNotify: |
1655 |
< |
ADBMouseMoved(((XMotionEvent *)&event)->x, ((XMotionEvent *)&event)->y); |
1655 |
> |
ADBMouseMoved(event.xmotion.x, event.xmotion.y); |
1656 |
|
break; |
1657 |
|
|
1658 |
|
// Keyboard |
1659 |
|
case KeyPress: { |
1660 |
|
int code; |
1661 |
|
if (use_keycodes) { |
1662 |
< |
event2keycode((XKeyEvent *)&event); // This is called to process the hotkeys |
1663 |
< |
code = keycode_table[((XKeyEvent *)&event)->keycode & 0xff]; |
1662 |
> |
event2keycode(event.xkey); // This is called to process the hotkeys |
1663 |
> |
code = keycode_table[event.xkey.keycode & 0xff]; |
1664 |
|
} else |
1665 |
< |
code = event2keycode((XKeyEvent *)&event); |
1665 |
> |
code = event2keycode(event.xkey); |
1666 |
|
if (code != -1) { |
1667 |
|
if (!emul_suspended) { |
1668 |
|
if (code == 0x39) { // Caps Lock pressed |
1689 |
|
case KeyRelease: { |
1690 |
|
int code; |
1691 |
|
if (use_keycodes) { |
1692 |
< |
event2keycode((XKeyEvent *)&event); // This is called to process the hotkeys |
1693 |
< |
code = keycode_table[((XKeyEvent *)&event)->keycode & 0xff]; |
1692 |
> |
event2keycode(event.xkey); // This is called to process the hotkeys |
1693 |
> |
code = keycode_table[event.xkey.keycode & 0xff]; |
1694 |
|
} else |
1695 |
< |
code = event2keycode((XKeyEvent *)&event); |
1695 |
> |
code = event2keycode(event.xkey); |
1696 |
|
if (code != -1 && code != 0x39) { // Don't propagate Caps Lock releases |
1697 |
|
ADBKeyUp(code); |
1698 |
|
if (code == 0x36) |
1706 |
|
if (display_type == DISPLAY_WINDOW) { |
1707 |
|
#ifdef ENABLE_VOSF |
1708 |
|
if (use_vosf) { // VOSF refresh |
1709 |
< |
#ifdef HAVE_PTHREADS |
1625 |
< |
pthread_mutex_lock(&Screen_draw_lock); |
1626 |
< |
#endif |
1709 |
> |
LOCK_VOSF; |
1710 |
|
PFLAG_SET_ALL; |
1711 |
< |
#ifdef HAVE_PTHREADS |
1629 |
< |
pthread_mutex_unlock(&Screen_draw_lock); |
1630 |
< |
#endif |
1711 |
> |
UNLOCK_VOSF; |
1712 |
|
memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y); |
1713 |
|
} |
1714 |
|
else |
1724 |
|
} |
1725 |
|
break; |
1726 |
|
|
1727 |
< |
case FocusIn: |
1728 |
< |
case FocusOut: |
1727 |
> |
// Window "close" widget clicked |
1728 |
> |
case ClientMessage: |
1729 |
> |
if (event.xclient.format == 32 && event.xclient.data.l[0] == WM_DELETE_WINDOW) { |
1730 |
> |
ADBKeyDown(0x7f); // Power key |
1731 |
> |
ADBKeyUp(0x7f); |
1732 |
> |
} |
1733 |
|
break; |
1734 |
|
} |
1735 |
|
} |
1949 |
|
* Screen refresh functions |
1950 |
|
*/ |
1951 |
|
|
1952 |
< |
// The specialisations hereunder are meant to enable VOSF with DGA in direct |
1953 |
< |
// addressing mode in case the address spaces (RAM, ROM, FrameBuffer) could |
1954 |
< |
// not get mapped correctly with respect to the predetermined host frame |
1955 |
< |
// buffer base address. |
1956 |
< |
// |
1872 |
< |
// Hmm, in other words, when in direct addressing mode and DGA is requested, |
1873 |
< |
// we first try to "triple allocate" the address spaces according to the real |
1874 |
< |
// host frame buffer address. Then, if it fails, we will use a temporary |
1875 |
< |
// frame buffer thus making the real host frame buffer updated when pages |
1876 |
< |
// of the temp frame buffer are altered. |
1877 |
< |
// |
1878 |
< |
// As a side effect, a little speed gain in screen updates could be noticed |
1879 |
< |
// for other modes than DGA. |
1880 |
< |
// |
1881 |
< |
// The following two functions below are inline so that a clever compiler |
1882 |
< |
// could specialise the code according to the current screen depth and |
1883 |
< |
// display type. A more clever compiler would the job by itself though... |
1884 |
< |
// (update_display_vosf is inlined as well) |
1952 |
> |
// We suggest the compiler to inline the next two functions so that it |
1953 |
> |
// may specialise the code according to the current screen depth and |
1954 |
> |
// display type. A clever compiler would do that job by itself though... |
1955 |
> |
|
1956 |
> |
// NOTE: update_display_vosf is inlined too |
1957 |
|
|
1958 |
|
static inline void possibly_quit_dga_mode() |
1959 |
|
{ |
1974 |
|
|
1975 |
|
static inline void handle_palette_changes(int depth, int display_type) |
1976 |
|
{ |
1977 |
< |
#ifdef HAVE_PTHREADS |
1978 |
< |
pthread_mutex_lock(&palette_lock); |
1907 |
< |
#endif |
1977 |
> |
LOCK_PALETTE; |
1978 |
> |
|
1979 |
|
if (palette_changed) { |
1980 |
|
palette_changed = false; |
1981 |
|
if (depth == 8) { |
1982 |
|
XStoreColors(x_display, cmap[0], palette, 256); |
1983 |
|
XStoreColors(x_display, cmap[1], palette, 256); |
1984 |
+ |
XSync(x_display, false); |
1985 |
|
|
1986 |
|
#ifdef ENABLE_XF86_DGA |
1987 |
|
if (display_type == DISPLAY_DGA) { |
1991 |
|
#endif |
1992 |
|
} |
1993 |
|
} |
1994 |
< |
#ifdef HAVE_PTHREADS |
1995 |
< |
pthread_mutex_unlock(&palette_lock); |
1924 |
< |
#endif |
1994 |
> |
|
1995 |
> |
UNLOCK_PALETTE; |
1996 |
|
} |
1997 |
|
|
1998 |
|
static void video_refresh_dga(void) |
2024 |
|
static int tick_counter = 0; |
2025 |
|
if (++tick_counter >= frame_skip) { |
2026 |
|
tick_counter = 0; |
2027 |
< |
#ifdef HAVE_PTHREADS |
1957 |
< |
pthread_mutex_lock(&Screen_draw_lock); |
1958 |
< |
#endif |
2027 |
> |
LOCK_VOSF; |
2028 |
|
update_display_dga_vosf(); |
2029 |
< |
#ifdef HAVE_PTHREADS |
1961 |
< |
pthread_mutex_unlock(&Screen_draw_lock); |
1962 |
< |
#endif |
2029 |
> |
UNLOCK_VOSF; |
2030 |
|
} |
2031 |
|
} |
2032 |
|
#endif |
2046 |
|
static int tick_counter = 0; |
2047 |
|
if (++tick_counter >= frame_skip) { |
2048 |
|
tick_counter = 0; |
2049 |
< |
#ifdef HAVE_PTHREADS |
1983 |
< |
pthread_mutex_lock(&Screen_draw_lock); |
1984 |
< |
#endif |
2049 |
> |
LOCK_VOSF; |
2050 |
|
update_display_window_vosf(); |
2051 |
< |
#ifdef HAVE_PTHREADS |
1987 |
< |
pthread_mutex_unlock(&Screen_draw_lock); |
1988 |
< |
#endif |
2051 |
> |
UNLOCK_VOSF; |
2052 |
|
} |
2053 |
|
} |
2054 |
|
#endif // def ENABLE_VOSF |
2118 |
|
video_refresh(); |
2119 |
|
} |
2120 |
|
|
2058 |
– |
#if 0 |
2059 |
– |
void VideoRefresh(void) |
2060 |
– |
{ |
2061 |
– |
#if defined(ENABLE_XF86_DGA) || defined(ENABLE_FBDEV_DGA) |
2062 |
– |
// Quit DGA mode if requested |
2063 |
– |
if (quit_full_screen) { |
2064 |
– |
quit_full_screen = false; |
2065 |
– |
if (display_type == DISPLAY_DGA) { |
2066 |
– |
#ifdef ENABLE_XF86_DGA |
2067 |
– |
XF86DGADirectVideo(x_display, screen, 0); |
2068 |
– |
#endif |
2069 |
– |
XUngrabPointer(x_display, CurrentTime); |
2070 |
– |
XUngrabKeyboard(x_display, CurrentTime); |
2071 |
– |
XUnmapWindow(x_display, the_win); |
2072 |
– |
XSync(x_display, false); |
2073 |
– |
} |
2074 |
– |
} |
2075 |
– |
#endif |
2076 |
– |
|
2077 |
– |
// Handle X events |
2078 |
– |
handle_events(); |
2079 |
– |
|
2080 |
– |
// Handle palette changes |
2081 |
– |
#ifdef HAVE_PTHREADS |
2082 |
– |
pthread_mutex_lock(&palette_lock); |
2083 |
– |
#endif |
2084 |
– |
if (palette_changed) { |
2085 |
– |
palette_changed = false; |
2086 |
– |
if (depth == 8) { |
2087 |
– |
XStoreColors(x_display, cmap[0], palette, 256); |
2088 |
– |
XStoreColors(x_display, cmap[1], palette, 256); |
2089 |
– |
|
2090 |
– |
#ifdef ENABLE_XF86_DGA |
2091 |
– |
if (display_type == DISPLAY_DGA) { |
2092 |
– |
current_dga_cmap ^= 1; |
2093 |
– |
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
2094 |
– |
} |
2095 |
– |
#endif |
2096 |
– |
} |
2097 |
– |
} |
2098 |
– |
#ifdef HAVE_PTHREADS |
2099 |
– |
pthread_mutex_unlock(&palette_lock); |
2100 |
– |
#endif |
2101 |
– |
|
2102 |
– |
// In window mode, update display |
2103 |
– |
static int tick_counter = 0; |
2104 |
– |
if (display_type == DISPLAY_WINDOW) { |
2105 |
– |
tick_counter++; |
2106 |
– |
if (frame_skip == 0) |
2107 |
– |
update_display_dynamic(tick_counter); |
2108 |
– |
else if (tick_counter >= frame_skip) { |
2109 |
– |
tick_counter = 0; |
2110 |
– |
update_display_static(); |
2111 |
– |
} |
2112 |
– |
} |
2113 |
– |
} |
2114 |
– |
#endif |
2115 |
– |
|
2121 |
|
#ifdef HAVE_PTHREADS |
2122 |
|
static void *redraw_func(void *arg) |
2123 |
|
{ |
2125 |
|
int64 ticks = 0; |
2126 |
|
uint64 next = GetTicks_usec(); |
2127 |
|
while (!redraw_thread_cancel) { |
2123 |
– |
// VideoRefresh(); |
2128 |
|
video_refresh(); |
2129 |
|
next += 16667; |
2130 |
|
int64 delay = next - GetTicks_usec(); |
2135 |
|
ticks++; |
2136 |
|
} |
2137 |
|
uint64 end = GetTicks_usec(); |
2138 |
< |
printf("%Ld ticks in %Ld usec = %Ld ticks/sec\n", ticks, end - start, (end - start) / ticks); |
2138 |
> |
printf("%Ld ticks in %Ld usec = %Ld ticks/sec\n", ticks, end - start, ticks * 1000000 / (end - start)); |
2139 |
|
return NULL; |
2140 |
|
} |
2141 |
|
#endif |