52 |
|
# include <sys/mman.h> |
53 |
|
#endif |
54 |
|
|
55 |
+ |
#ifdef ENABLE_VOSF |
56 |
+ |
# include <unistd.h> |
57 |
+ |
# include <signal.h> |
58 |
+ |
# include <fcntl.h> |
59 |
+ |
# include <sys/mman.h> |
60 |
+ |
#endif |
61 |
+ |
|
62 |
|
#include "cpu_emulation.h" |
63 |
|
#include "main.h" |
64 |
|
#include "adb.h" |
67 |
|
#include "user_strings.h" |
68 |
|
#include "video.h" |
69 |
|
|
70 |
< |
#define DEBUG 1 |
70 |
> |
#define DEBUG 0 |
71 |
|
#include "debug.h" |
72 |
|
|
73 |
|
|
88 |
|
static int16 mouse_wheel_lines = 3; |
89 |
|
|
90 |
|
static int display_type = DISPLAY_WINDOW; // See enum above |
91 |
+ |
static bool local_X11; // Flag: X server running on local machine? |
92 |
|
static uint8 *the_buffer; // Mac frame buffer |
93 |
|
|
94 |
|
#ifdef HAVE_PTHREADS |
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; |
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 |
141 |
|
static GC the_gc; |
142 |
|
static XImage *img = NULL; |
143 |
|
static XShmSegmentInfo shminfo; |
130 |
– |
static XImage *cursor_image, *cursor_mask_image; |
131 |
– |
static Pixmap cursor_map, cursor_mask_map; |
144 |
|
static Cursor mac_cursor; |
133 |
– |
static GC cursor_gc, cursor_mask_gc; |
145 |
|
static uint8 *the_buffer_copy = NULL; // Copy of Mac frame buffer |
135 |
– |
static uint8 the_cursor[64]; // Cursor image data |
146 |
|
static bool have_shm = false; // Flag: SHM extensions available |
147 |
|
static bool updt_box[17][17]; // Flag for Update |
148 |
|
static int nr_boxes; |
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 |
172 |
|
static int num_x_video_modes; |
173 |
|
#endif |
174 |
|
|
175 |
+ |
#ifdef ENABLE_VOSF |
176 |
+ |
static bool use_vosf = true; // Flag: VOSF enabled |
177 |
+ |
#else |
178 |
+ |
static const bool use_vosf = false; // Flag: VOSF enabled |
179 |
+ |
#endif |
180 |
+ |
|
181 |
+ |
#ifdef ENABLE_VOSF |
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 |
185 |
+ |
|
186 |
+ |
struct ScreenPageInfo { |
187 |
+ |
int top, bottom; // Mapping between this virtual page and Mac scanlines |
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 |
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 |
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) |
210 |
+ |
#ifdef UNALIGNED_PROFITABLE |
211 |
+ |
# define PFLAG_ISCLEAR_4(page) (*((uint32 *)(mainBuffer.dirtyPages + page)) == 0) |
212 |
+ |
#else |
213 |
+ |
# define PFLAG_ISCLEAR_4(page) \ |
214 |
+ |
(mainBuffer.dirtyPages[page ] == 0) \ |
215 |
+ |
&& (mainBuffer.dirtyPages[page+1] == 0) \ |
216 |
+ |
&& (mainBuffer.dirtyPages[page+2] == 0) \ |
217 |
+ |
&& (mainBuffer.dirtyPages[page+3] == 0) |
218 |
+ |
#endif |
219 |
+ |
#define PFLAG_CLEAR_ALL memset(mainBuffer.dirtyPages, 0, mainBuffer.pageCount) |
220 |
+ |
#define PFLAG_SET_ALL memset(mainBuffer.dirtyPages, 1, mainBuffer.pageCount) |
221 |
+ |
|
222 |
+ |
static int zero_fd = -1; |
223 |
+ |
static bool Screen_fault_handler_init(); |
224 |
+ |
static struct sigaction vosf_sa; |
225 |
+ |
|
226 |
+ |
#ifdef HAVE_PTHREADS |
227 |
+ |
static pthread_mutex_t vosf_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect frame buffer (dirtyPages in fact) |
228 |
+ |
#define LOCK_VOSF pthread_mutex_lock(&vosf_lock); |
229 |
+ |
#define UNLOCK_VOSF pthread_mutex_unlock(&vosf_lock); |
230 |
+ |
#else |
231 |
+ |
#define LOCK_VOSF |
232 |
+ |
#define UNLOCK_VOSF |
233 |
+ |
#endif |
234 |
+ |
|
235 |
+ |
static int log_base_2(uint32 x) |
236 |
+ |
{ |
237 |
+ |
uint32 mask = 0x80000000; |
238 |
+ |
int l = 31; |
239 |
+ |
while (l >= 0 && (x & mask) == 0) { |
240 |
+ |
mask >>= 1; |
241 |
+ |
l--; |
242 |
+ |
} |
243 |
+ |
return l; |
244 |
+ |
} |
245 |
+ |
|
246 |
+ |
#endif |
247 |
+ |
|
248 |
+ |
// VideoRefresh function |
249 |
+ |
void VideoRefreshInit(void); |
250 |
+ |
static void (*video_refresh)(void); |
251 |
|
|
252 |
|
// Prototypes |
253 |
|
static void *redraw_func(void *arg); |
254 |
< |
static int event2keycode(XKeyEvent *ev); |
254 |
> |
static int event2keycode(XKeyEvent &ev); |
255 |
|
|
256 |
|
|
257 |
|
// From main_unix.cpp |
258 |
+ |
extern char *x_display_name; |
259 |
|
extern Display *x_display; |
260 |
|
|
261 |
|
// From sys_unix.cpp |
262 |
|
extern void SysMountFirstFloppy(void); |
263 |
|
|
264 |
+ |
#ifdef ENABLE_VOSF |
265 |
+ |
# include "video_vosf.h" |
266 |
+ |
#endif |
267 |
+ |
|
268 |
|
|
269 |
|
/* |
270 |
|
* Initialization |
273 |
|
// Set VideoMonitor according to video mode |
274 |
|
void set_video_monitor(int width, int height, int bytes_per_row, bool native_byte_order) |
275 |
|
{ |
276 |
< |
#if !REAL_ADDRESSING |
276 |
> |
#if !REAL_ADDRESSING && !DIRECT_ADDRESSING |
277 |
|
int layout = FLAYOUT_DIRECT; |
278 |
|
switch (depth) { |
279 |
|
case 1: |
321 |
|
VideoMonitor.bytes_per_row = bytes_per_row; |
322 |
|
} |
323 |
|
|
324 |
+ |
// Set window name and class |
325 |
+ |
static void set_window_name(Window w, int name) |
326 |
+ |
{ |
327 |
+ |
const char *str = GetString(name); |
328 |
+ |
XStoreName(x_display, w, str); |
329 |
+ |
XSetIconName(x_display, w, str); |
330 |
+ |
|
331 |
+ |
XClassHint *hints; |
332 |
+ |
hints = XAllocClassHint(); |
333 |
+ |
if (hints) { |
334 |
+ |
hints->res_name = "BasiliskII"; |
335 |
+ |
hints->res_class = "BasiliskII"; |
336 |
+ |
XSetClassHint(x_display, w, hints); |
337 |
+ |
XFree((char *)hints); |
338 |
+ |
} |
339 |
+ |
} |
340 |
+ |
|
341 |
+ |
// Set window input focus flag |
342 |
+ |
static void set_window_focus(Window w) |
343 |
+ |
{ |
344 |
+ |
XWMHints *hints = XAllocWMHints(); |
345 |
+ |
if (hints) { |
346 |
+ |
hints->input = True; |
347 |
+ |
hints->initial_state = NormalState; |
348 |
+ |
hints->flags = InputHint | StateHint; |
349 |
+ |
XSetWMHints(x_display, w, hints); |
350 |
+ |
XFree((char *)hints); |
351 |
+ |
} |
352 |
+ |
} |
353 |
+ |
|
354 |
+ |
// Set WM_DELETE_WINDOW protocol on window (preventing it from being destroyed by the WM when clicking on the "close" widget) |
355 |
+ |
static void set_window_delete_protocol(Window w) |
356 |
+ |
{ |
357 |
+ |
WM_DELETE_WINDOW = XInternAtom(x_display, "WM_DELETE_WINDOW", false); |
358 |
+ |
XSetWMProtocols(x_display, w, &WM_DELETE_WINDOW, 1); |
359 |
+ |
} |
360 |
+ |
|
361 |
+ |
// Wait until window is mapped/unmapped |
362 |
+ |
void wait_mapped(Window w) |
363 |
+ |
{ |
364 |
+ |
XEvent e; |
365 |
+ |
do { |
366 |
+ |
XMaskEvent(x_display, StructureNotifyMask, &e); |
367 |
+ |
} while ((e.type != MapNotify) || (e.xmap.event != w)); |
368 |
+ |
} |
369 |
+ |
|
370 |
+ |
void wait_unmapped(Window w) |
371 |
+ |
{ |
372 |
+ |
XEvent e; |
373 |
+ |
do { |
374 |
+ |
XMaskEvent(x_display, StructureNotifyMask, &e); |
375 |
+ |
} while ((e.type != UnmapNotify) || (e.xmap.event != w)); |
376 |
+ |
} |
377 |
+ |
|
378 |
|
// Trap SHM errors |
379 |
|
static bool shm_error = false; |
380 |
|
static int (*old_error_handler)(Display *, XErrorEvent *); |
399 |
|
|
400 |
|
// Read frame skip prefs |
401 |
|
frame_skip = PrefsFindInt32("frameskip"); |
252 |
– |
if (frame_skip == 0) |
253 |
– |
frame_skip = 1; |
402 |
|
|
403 |
|
// Create window |
404 |
|
XSetWindowAttributes wattr; |
405 |
|
wattr.event_mask = eventmask = win_eventmask; |
406 |
|
wattr.background_pixel = black_pixel; |
407 |
< |
wattr.border_pixel = black_pixel; |
260 |
< |
wattr.backing_store = NotUseful; |
261 |
< |
wattr.save_under = false; |
262 |
< |
wattr.backing_planes = xdepth; |
407 |
> |
wattr.colormap = cmap[0]; |
408 |
|
|
264 |
– |
XSync(x_display, false); |
409 |
|
the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, |
410 |
< |
InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel | |
267 |
< |
CWBackingStore | CWBackingPlanes, &wattr); |
268 |
< |
XSync(x_display, false); |
269 |
< |
XStoreName(x_display, the_win, GetString(STR_WINDOW_TITLE)); |
270 |
< |
XMapRaised(x_display, the_win); |
271 |
< |
XSync(x_display, false); |
410 |
> |
InputOutput, vis, CWEventMask | CWBackPixel | (depth == 8 ? CWColormap : 0), &wattr); |
411 |
|
|
412 |
< |
// Set colormap |
413 |
< |
if (depth == 8) { |
414 |
< |
XSetWindowColormap(x_display, the_win, cmap[0]); |
415 |
< |
XSetWMColormapWindows(x_display, the_win, &the_win, 1); |
416 |
< |
} |
412 |
> |
// Set window name/class |
413 |
> |
set_window_name(the_win, STR_WINDOW_TITLE); |
414 |
> |
|
415 |
> |
// Indicate that we want keyboard input |
416 |
> |
set_window_focus(the_win); |
417 |
> |
|
418 |
> |
// Set delete protocol property |
419 |
> |
set_window_delete_protocol(the_win); |
420 |
|
|
421 |
|
// Make window unresizable |
422 |
< |
XSizeHints *hints; |
423 |
< |
if ((hints = XAllocSizeHints()) != NULL) { |
424 |
< |
hints->min_width = width; |
425 |
< |
hints->max_width = width; |
426 |
< |
hints->min_height = height; |
427 |
< |
hints->max_height = height; |
428 |
< |
hints->flags = PMinSize | PMaxSize; |
429 |
< |
XSetWMNormalHints(x_display, the_win, hints); |
430 |
< |
XFree((char *)hints); |
422 |
> |
{ |
423 |
> |
XSizeHints *hints = XAllocSizeHints(); |
424 |
> |
if (hints) { |
425 |
> |
hints->min_width = width; |
426 |
> |
hints->max_width = width; |
427 |
> |
hints->min_height = height; |
428 |
> |
hints->max_height = height; |
429 |
> |
hints->flags = PMinSize | PMaxSize; |
430 |
> |
XSetWMNormalHints(x_display, the_win, hints); |
431 |
> |
XFree((char *)hints); |
432 |
> |
} |
433 |
|
} |
434 |
|
|
435 |
+ |
// Show window |
436 |
+ |
XMapWindow(x_display, the_win); |
437 |
+ |
wait_mapped(the_win); |
438 |
+ |
|
439 |
|
// Try to create and attach SHM image |
440 |
|
have_shm = false; |
441 |
< |
if (depth != 1 && XShmQueryExtension(x_display)) { |
441 |
> |
if (depth != 1 && local_X11 && XShmQueryExtension(x_display)) { |
442 |
|
|
443 |
|
// Create SHM image ("height + 2" for safety) |
444 |
|
img = XShmCreateImage(x_display, vis, depth, depth == 1 ? XYBitmap : ZPixmap, 0, &shminfo, width, height); |
489 |
|
img->bitmap_bit_order = MSBFirst; |
490 |
|
} |
491 |
|
|
492 |
< |
// Allocate memory for frame buffer copy |
492 |
> |
#ifdef ENABLE_VOSF |
493 |
> |
// 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); |
495 |
> |
the_host_buffer = the_buffer_copy; |
496 |
> |
|
497 |
> |
the_buffer_copy = (uint8 *)allocate_framebuffer(the_buffer_size); |
498 |
> |
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); |
502 |
> |
#else |
503 |
> |
// Allocate memory for frame buffer |
504 |
|
the_buffer = (uint8 *)malloc((aligned_height + 2) * img->bytes_per_line); |
505 |
+ |
#endif |
506 |
|
|
507 |
|
// Create GC |
508 |
|
the_gc = XCreateGC(x_display, the_win, 0, 0); |
509 |
|
XSetState(x_display, the_gc, black_pixel, white_pixel, GXcopy, AllPlanes); |
510 |
|
|
511 |
|
// Create no_cursor |
512 |
< |
mac_cursor = XCreatePixmapCursor (x_display, |
513 |
< |
XCreatePixmap (x_display, the_win, 1, 1, 1), |
514 |
< |
XCreatePixmap (x_display, the_win, 1, 1, 1), |
515 |
< |
&black, &white, 0, 0); |
516 |
< |
XDefineCursor (x_display, the_win, mac_cursor); |
512 |
> |
mac_cursor = XCreatePixmapCursor(x_display, |
513 |
> |
XCreatePixmap(x_display, the_win, 1, 1, 1), |
514 |
> |
XCreatePixmap(x_display, the_win, 1, 1, 1), |
515 |
> |
&black, &white, 0, 0); |
516 |
> |
XDefineCursor(x_display, the_win, mac_cursor); |
517 |
|
|
518 |
|
// Set VideoMonitor |
519 |
+ |
bool native_byte_order; |
520 |
|
#ifdef WORDS_BIGENDIAN |
521 |
< |
set_video_monitor(width, height, img->bytes_per_line, img->bitmap_bit_order == MSBFirst); |
521 |
> |
native_byte_order = (img->bitmap_bit_order == MSBFirst); |
522 |
|
#else |
523 |
< |
set_video_monitor(width, height, img->bytes_per_line, img->bitmap_bit_order == LSBFirst); |
523 |
> |
native_byte_order = (img->bitmap_bit_order == LSBFirst); |
524 |
|
#endif |
525 |
+ |
#ifdef ENABLE_VOSF |
526 |
+ |
do_update_framebuffer = GET_FBCOPY_FUNC(depth, native_byte_order, DISPLAY_WINDOW); |
527 |
+ |
#endif |
528 |
+ |
set_video_monitor(width, height, img->bytes_per_line, native_byte_order); |
529 |
|
|
530 |
< |
#if REAL_ADDRESSING |
531 |
< |
VideoMonitor.mac_frame_base = (uint32)the_buffer; |
530 |
> |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
531 |
> |
VideoMonitor.mac_frame_base = Host2MacAddr(the_buffer); |
532 |
|
#else |
533 |
|
VideoMonitor.mac_frame_base = MacFrameBaseMac; |
534 |
|
#endif |
607 |
|
|
608 |
|
// Create window |
609 |
|
XSetWindowAttributes wattr; |
610 |
< |
wattr.override_redirect = True; |
611 |
< |
wattr.backing_store = NotUseful; |
612 |
< |
wattr.background_pixel = white_pixel; |
613 |
< |
wattr.border_pixel = black_pixel; |
449 |
< |
wattr.event_mask = eventmask = dga_eventmask; |
610 |
> |
wattr.event_mask = eventmask = dga_eventmask; |
611 |
> |
wattr.background_pixel = white_pixel; |
612 |
> |
wattr.override_redirect = True; |
613 |
> |
wattr.colormap = cmap[0]; |
614 |
|
|
451 |
– |
XSync(x_display, false); |
615 |
|
the_win = XCreateWindow(x_display, rootwin, |
616 |
|
0, 0, width, height, |
617 |
|
0, xdepth, InputOutput, vis, |
618 |
< |
CWEventMask|CWBackPixel|CWBorderPixel|CWOverrideRedirect|CWBackingStore, |
618 |
> |
CWEventMask | CWBackPixel | CWOverrideRedirect | (depth == 8 ? CWColormap : 0), |
619 |
|
&wattr); |
620 |
< |
XSync(x_display, false); |
620 |
> |
|
621 |
> |
// Set window name/class |
622 |
> |
set_window_name(the_win, STR_WINDOW_TITLE); |
623 |
> |
|
624 |
> |
// Indicate that we want keyboard input |
625 |
> |
set_window_focus(the_win); |
626 |
> |
|
627 |
> |
// Show window |
628 |
|
XMapRaised(x_display, the_win); |
629 |
< |
XSync(x_display, false); |
629 |
> |
wait_mapped(the_win); |
630 |
|
|
631 |
|
// Grab mouse and keyboard |
632 |
|
XGrabKeyboard(x_display, the_win, True, |
635 |
|
PointerMotionMask | ButtonPressMask | ButtonReleaseMask, |
636 |
|
GrabModeAsync, GrabModeAsync, the_win, None, CurrentTime); |
637 |
|
|
468 |
– |
// Set colormap |
469 |
– |
if (depth == 8) { |
470 |
– |
XSetWindowColormap(x_display, the_win, cmap[0]); |
471 |
– |
XSetWMColormapWindows(x_display, the_win, &the_win, 1); |
472 |
– |
} |
473 |
– |
|
638 |
|
// Set VideoMonitor |
639 |
|
int bytes_per_row = width; |
640 |
|
switch (depth) { |
660 |
|
} |
661 |
|
} |
662 |
|
|
663 |
+ |
#if ENABLE_VOSF |
664 |
+ |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
665 |
+ |
// If the blit function is null, i.e. just a copy of the buffer, |
666 |
+ |
// we first try to avoid the allocation of a temporary frame buffer |
667 |
+ |
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; |
671 |
+ |
|
672 |
+ |
if (use_vosf) { |
673 |
+ |
the_host_buffer = the_buffer; |
674 |
+ |
the_buffer_size = align_on_page_boundary((height + 2) * bytes_per_row); |
675 |
+ |
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
676 |
+ |
memset(the_buffer_copy, 0, the_buffer_size); |
677 |
+ |
the_buffer = (uint8 *)allocate_framebuffer(the_buffer_size); |
678 |
+ |
memset(the_buffer, 0, the_buffer_size); |
679 |
+ |
} |
680 |
+ |
#else |
681 |
+ |
use_vosf = false; |
682 |
+ |
#endif |
683 |
+ |
#endif |
684 |
+ |
|
685 |
|
set_video_monitor(width, height, bytes_per_row, true); |
686 |
< |
#if REAL_ADDRESSING |
687 |
< |
VideoMonitor.mac_frame_base = (uint32)the_buffer; |
686 |
> |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
687 |
> |
VideoMonitor.mac_frame_base = Host2MacAddr(the_buffer); |
688 |
|
#else |
689 |
|
VideoMonitor.mac_frame_base = MacFrameBaseMac; |
690 |
|
#endif |
714 |
|
} |
715 |
|
XF86VidModeSwitchToMode(x_display, screen, x_video_modes[best]); |
716 |
|
XF86VidModeSetViewPort(x_display, screen, 0, 0); |
717 |
+ |
XSync(x_display, false); |
718 |
|
} |
719 |
|
#endif |
720 |
|
|
721 |
|
// Create window |
722 |
|
XSetWindowAttributes wattr; |
723 |
|
wattr.event_mask = eventmask = dga_eventmask; |
537 |
– |
wattr.border_pixel = black_pixel; |
724 |
|
wattr.override_redirect = True; |
725 |
|
|
540 |
– |
XSync(x_display, false); |
726 |
|
the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, |
727 |
< |
InputOutput, vis, CWEventMask | CWBorderPixel | CWOverrideRedirect, &wattr); |
728 |
< |
XSync(x_display, false); |
729 |
< |
XStoreName(x_display, the_win, GetString(STR_WINDOW_TITLE)); |
727 |
> |
InputOutput, vis, CWEventMask | CWOverrideRedirect, &wattr); |
728 |
> |
|
729 |
> |
// Set window name/class |
730 |
> |
set_window_name(the_win, STR_WINDOW_TITLE); |
731 |
> |
|
732 |
> |
// Indicate that we want keyboard input |
733 |
> |
set_window_focus(the_win); |
734 |
> |
|
735 |
> |
// Show window |
736 |
|
XMapRaised(x_display, the_win); |
737 |
< |
XSync(x_display, false); |
737 |
> |
wait_mapped(the_win); |
738 |
|
|
739 |
|
// Establish direct screen connection |
740 |
|
XMoveResizeWindow(x_display, the_win, 0, 0, width, height); |
751 |
|
// Set colormap |
752 |
|
if (depth == 8) { |
753 |
|
XSetWindowColormap(x_display, the_win, cmap[current_dga_cmap = 0]); |
563 |
– |
XSetWMColormapWindows(x_display, the_win, &the_win, 1); |
754 |
|
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
755 |
|
} |
756 |
+ |
XSync(x_display, false); |
757 |
|
|
758 |
|
// Set VideoMonitor |
759 |
|
int bytes_per_row = (v_width + 7) & ~7; |
770 |
|
bytes_per_row *= 4; |
771 |
|
break; |
772 |
|
} |
773 |
+ |
|
774 |
+ |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
775 |
+ |
// If the blit function is null, i.e. just a copy of the buffer, |
776 |
+ |
// we first try to avoid the allocation of a temporary frame buffer |
777 |
+ |
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; |
781 |
+ |
|
782 |
+ |
if (use_vosf) { |
783 |
+ |
the_host_buffer = the_buffer; |
784 |
+ |
the_buffer_size = align_on_page_boundary((height + 2) * bytes_per_row); |
785 |
+ |
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
786 |
+ |
memset(the_buffer_copy, 0, the_buffer_size); |
787 |
+ |
the_buffer = (uint8 *)allocate_framebuffer(the_buffer_size); |
788 |
+ |
memset(the_buffer, 0, the_buffer_size); |
789 |
+ |
} |
790 |
+ |
#elif defined(ENABLE_VOSF) |
791 |
+ |
// The UAE memory handlers will already handle color conversion, if needed. |
792 |
+ |
use_vosf = false; |
793 |
+ |
#endif |
794 |
+ |
|
795 |
|
set_video_monitor(width, height, bytes_per_row, true); |
796 |
< |
#if REAL_ADDRESSING |
797 |
< |
VideoMonitor.mac_frame_base = (uint32)the_buffer; |
798 |
< |
MacFrameLayout = FLAYOUT_DIRECT; |
796 |
> |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
797 |
> |
VideoMonitor.mac_frame_base = Host2MacAddr(the_buffer); |
798 |
> |
// MacFrameLayout = FLAYOUT_DIRECT; |
799 |
|
#else |
800 |
|
VideoMonitor.mac_frame_base = MacFrameBaseMac; |
801 |
|
#endif |
871 |
|
} |
872 |
|
} |
873 |
|
|
874 |
+ |
bool VideoInitBuffer() |
875 |
+ |
{ |
876 |
+ |
#ifdef ENABLE_VOSF |
877 |
+ |
if (use_vosf) { |
878 |
+ |
const uint32 page_size = getpagesize(); |
879 |
+ |
const uint32 page_mask = page_size - 1; |
880 |
+ |
|
881 |
+ |
mainBuffer.memBase = (uint32) the_buffer; |
882 |
+ |
// Align the frame buffer on page boundary |
883 |
+ |
mainBuffer.memStart = (uint32)((((unsigned long) the_buffer) + page_mask) & ~page_mask); |
884 |
+ |
mainBuffer.memLength = the_buffer_size; |
885 |
+ |
mainBuffer.memEnd = mainBuffer.memStart + mainBuffer.memLength; |
886 |
+ |
|
887 |
+ |
mainBuffer.pageSize = page_size; |
888 |
+ |
mainBuffer.pageCount = (mainBuffer.memLength + page_mask)/mainBuffer.pageSize; |
889 |
+ |
mainBuffer.pageBits = log_base_2(mainBuffer.pageSize); |
890 |
+ |
|
891 |
+ |
if (mainBuffer.dirtyPages != 0) |
892 |
+ |
free(mainBuffer.dirtyPages); |
893 |
+ |
|
894 |
+ |
mainBuffer.dirtyPages = (uint8 *) malloc(mainBuffer.pageCount); |
895 |
+ |
|
896 |
+ |
if (mainBuffer.pageInfo != 0) |
897 |
+ |
free(mainBuffer.pageInfo); |
898 |
+ |
|
899 |
+ |
mainBuffer.pageInfo = (ScreenPageInfo *) malloc(mainBuffer.pageCount * sizeof(ScreenPageInfo)); |
900 |
+ |
|
901 |
+ |
if ((mainBuffer.dirtyPages == 0) || (mainBuffer.pageInfo == 0)) |
902 |
+ |
return false; |
903 |
+ |
|
904 |
+ |
PFLAG_CLEAR_ALL; |
905 |
+ |
|
906 |
+ |
uint32 a = 0; |
907 |
+ |
for (int i = 0; i < mainBuffer.pageCount; i++) { |
908 |
+ |
int y1 = a / VideoMonitor.bytes_per_row; |
909 |
+ |
if (y1 >= VideoMonitor.y) |
910 |
+ |
y1 = VideoMonitor.y - 1; |
911 |
+ |
|
912 |
+ |
int y2 = (a + mainBuffer.pageSize) / VideoMonitor.bytes_per_row; |
913 |
+ |
if (y2 >= VideoMonitor.y) |
914 |
+ |
y2 = VideoMonitor.y - 1; |
915 |
+ |
|
916 |
+ |
mainBuffer.pageInfo[i].top = y1; |
917 |
+ |
mainBuffer.pageInfo[i].bottom = y2; |
918 |
+ |
|
919 |
+ |
a += mainBuffer.pageSize; |
920 |
+ |
if (a > mainBuffer.memLength) |
921 |
+ |
a = mainBuffer.memLength; |
922 |
+ |
} |
923 |
+ |
|
924 |
+ |
// We can now write-protect the frame buffer |
925 |
+ |
if (mprotect((caddr_t)mainBuffer.memStart, mainBuffer.memLength, PROT_READ) != 0) |
926 |
+ |
return false; |
927 |
+ |
} |
928 |
+ |
#endif |
929 |
+ |
return true; |
930 |
+ |
} |
931 |
+ |
|
932 |
|
bool VideoInit(bool classic) |
933 |
|
{ |
934 |
+ |
#ifdef ENABLE_VOSF |
935 |
+ |
// Open /dev/zero |
936 |
+ |
zero_fd = open("/dev/zero", O_RDWR); |
937 |
+ |
if (zero_fd < 0) { |
938 |
+ |
char str[256]; |
939 |
+ |
sprintf(str, GetString(STR_NO_DEV_ZERO_ERR), strerror(errno)); |
940 |
+ |
ErrorAlert(str); |
941 |
+ |
return false; |
942 |
+ |
} |
943 |
+ |
|
944 |
+ |
// Zero the mainBuffer structure |
945 |
+ |
mainBuffer.dirtyPages = 0; |
946 |
+ |
mainBuffer.pageInfo = 0; |
947 |
+ |
#endif |
948 |
+ |
|
949 |
+ |
// Check if X server runs on local machine |
950 |
+ |
local_X11 = (strncmp(XDisplayName(x_display_name), ":", 1) == 0) |
951 |
+ |
|| (strncmp(XDisplayName(x_display_name), "unix:", 5) == 0); |
952 |
+ |
|
953 |
|
// Init keycode translation |
954 |
|
keycode_init(); |
955 |
|
|
978 |
|
#ifdef ENABLE_XF86_DGA |
979 |
|
// DGA available? |
980 |
|
int dga_event_base, dga_error_base; |
981 |
< |
if (XF86DGAQueryExtension(x_display, &dga_event_base, &dga_error_base)) { |
981 |
> |
if (local_X11 && XF86DGAQueryExtension(x_display, &dga_event_base, &dga_error_base)) { |
982 |
|
int dga_flags = 0; |
983 |
|
XF86DGAQueryDirectVideo(x_display, screen, &dga_flags); |
984 |
|
has_dga = dga_flags & XF86DGADirectPresent; |
1092 |
|
break; |
1093 |
|
} |
1094 |
|
|
805 |
– |
#ifdef HAVE_PTHREADS |
1095 |
|
// Lock down frame buffer |
1096 |
< |
pthread_mutex_lock(&frame_buffer_lock); |
808 |
< |
#endif |
1096 |
> |
LOCK_FRAME_BUFFER; |
1097 |
|
|
1098 |
< |
#if !REAL_ADDRESSING |
1098 |
> |
#if !REAL_ADDRESSING && !DIRECT_ADDRESSING |
1099 |
|
// Set variables for UAE memory mapping |
1100 |
|
MacFrameBaseHost = the_buffer; |
1101 |
|
MacFrameSize = VideoMonitor.bytes_per_row * VideoMonitor.y; |
1105 |
|
MacFrameLayout = FLAYOUT_NONE; |
1106 |
|
#endif |
1107 |
|
|
1108 |
+ |
#ifdef ENABLE_VOSF |
1109 |
+ |
if (use_vosf) { |
1110 |
+ |
// Initialize the mainBuffer structure |
1111 |
+ |
if (!VideoInitBuffer()) { |
1112 |
+ |
// TODO: STR_VOSF_INIT_ERR ? |
1113 |
+ |
ErrorAlert("Could not initialize Video on SEGV signals"); |
1114 |
+ |
return false; |
1115 |
+ |
} |
1116 |
+ |
|
1117 |
+ |
// Initialize the handler for SIGSEGV |
1118 |
+ |
if (!Screen_fault_handler_init()) { |
1119 |
+ |
// TODO: STR_VOSF_INIT_ERR ? |
1120 |
+ |
ErrorAlert("Could not initialize Video on SEGV signals"); |
1121 |
+ |
return false; |
1122 |
+ |
} |
1123 |
+ |
} |
1124 |
+ |
#endif |
1125 |
+ |
|
1126 |
+ |
// Initialize VideoRefresh function |
1127 |
+ |
VideoRefreshInit(); |
1128 |
+ |
|
1129 |
|
XSync(x_display, false); |
1130 |
|
|
1131 |
|
#ifdef HAVE_PTHREADS |
1158 |
|
} |
1159 |
|
#endif |
1160 |
|
|
852 |
– |
#ifdef HAVE_PTHREADS |
1161 |
|
// Unlock frame buffer |
1162 |
< |
pthread_mutex_unlock(&frame_buffer_lock); |
855 |
< |
#endif |
1162 |
> |
UNLOCK_FRAME_BUFFER; |
1163 |
|
|
1164 |
|
// Close window and server connection |
1165 |
|
if (x_display != NULL) { |
1192 |
|
XFreeColormap(x_display, cmap[0]); |
1193 |
|
XFreeColormap(x_display, cmap[1]); |
1194 |
|
} |
1195 |
+ |
|
1196 |
+ |
if (!use_vosf) { |
1197 |
+ |
if (the_buffer) { |
1198 |
+ |
free(the_buffer); |
1199 |
+ |
the_buffer = NULL; |
1200 |
+ |
} |
1201 |
|
|
1202 |
< |
if (the_buffer) { |
1203 |
< |
free(the_buffer); |
1204 |
< |
the_buffer = NULL; |
1202 |
> |
if (!have_shm && the_buffer_copy) { |
1203 |
> |
free(the_buffer_copy); |
1204 |
> |
the_buffer_copy = NULL; |
1205 |
> |
} |
1206 |
> |
} |
1207 |
> |
#ifdef ENABLE_VOSF |
1208 |
> |
else { |
1209 |
> |
if (the_buffer != (uint8 *)MAP_FAILED) { |
1210 |
> |
munmap((caddr_t)the_buffer, the_buffer_size); |
1211 |
> |
the_buffer = 0; |
1212 |
> |
} |
1213 |
> |
|
1214 |
> |
if (the_buffer_copy != (uint8 *)MAP_FAILED) { |
1215 |
> |
munmap((caddr_t)the_buffer_copy, the_buffer_size); |
1216 |
> |
the_buffer_copy = 0; |
1217 |
> |
} |
1218 |
> |
} |
1219 |
> |
#endif |
1220 |
> |
} |
1221 |
> |
|
1222 |
> |
#ifdef ENABLE_VOSF |
1223 |
> |
if (use_vosf) { |
1224 |
> |
// Clear mainBuffer data |
1225 |
> |
if (mainBuffer.pageInfo) { |
1226 |
> |
free(mainBuffer.pageInfo); |
1227 |
> |
mainBuffer.pageInfo = 0; |
1228 |
|
} |
1229 |
|
|
1230 |
< |
if (!have_shm && the_buffer_copy) { |
1231 |
< |
free(the_buffer_copy); |
1232 |
< |
the_buffer_copy = NULL; |
1230 |
> |
if (mainBuffer.dirtyPages) { |
1231 |
> |
free(mainBuffer.dirtyPages); |
1232 |
> |
mainBuffer.dirtyPages = 0; |
1233 |
|
} |
1234 |
|
} |
1235 |
+ |
|
1236 |
+ |
// Close /dev/zero |
1237 |
+ |
if (zero_fd > 0) |
1238 |
+ |
close(zero_fd); |
1239 |
+ |
#endif |
1240 |
|
} |
1241 |
|
|
1242 |
|
|
1262 |
|
if (emerg_quit) |
1263 |
|
QuitEmulator(); |
1264 |
|
|
924 |
– |
#ifdef HAVE_PTHREADS |
1265 |
|
// Temporarily give up frame buffer lock (this is the point where |
1266 |
|
// we are suspended when the user presses Ctrl-Tab) |
1267 |
< |
pthread_mutex_unlock(&frame_buffer_lock); |
1268 |
< |
pthread_mutex_lock(&frame_buffer_lock); |
929 |
< |
#endif |
1267 |
> |
UNLOCK_FRAME_BUFFER; |
1268 |
> |
LOCK_FRAME_BUFFER; |
1269 |
|
} |
1270 |
|
|
1271 |
|
|
1275 |
|
|
1276 |
|
void video_set_palette(uint8 *pal) |
1277 |
|
{ |
1278 |
< |
#ifdef HAVE_PTHREDS |
940 |
< |
pthread_mutex_lock(&palette_lock); |
941 |
< |
#endif |
1278 |
> |
LOCK_PALETTE; |
1279 |
|
|
1280 |
|
// Convert colors to XColor array |
1281 |
|
for (int i=0; i<256; i++) { |
1289 |
|
// Tell redraw thread to change palette |
1290 |
|
palette_changed = true; |
1291 |
|
|
1292 |
< |
#ifdef HAVE_PTHREADS |
956 |
< |
pthread_mutex_unlock(&palette_lock); |
957 |
< |
#endif |
1292 |
> |
UNLOCK_PALETTE; |
1293 |
|
} |
1294 |
|
|
1295 |
|
|
1305 |
|
ADBKeyUp(0x36); |
1306 |
|
ctrl_down = false; |
1307 |
|
|
973 |
– |
#ifdef HAVE_PTHREADS |
1308 |
|
// Lock frame buffer (this will stop the MacOS thread) |
1309 |
< |
pthread_mutex_lock(&frame_buffer_lock); |
976 |
< |
#endif |
1309 |
> |
LOCK_FRAME_BUFFER; |
1310 |
|
|
1311 |
|
// Save frame buffer |
1312 |
|
fb_save = malloc(VideoMonitor.y * VideoMonitor.bytes_per_row); |
1320 |
|
XUngrabPointer(x_display, CurrentTime); |
1321 |
|
XUngrabKeyboard(x_display, CurrentTime); |
1322 |
|
XUnmapWindow(x_display, the_win); |
1323 |
< |
XSync(x_display, false); |
1323 |
> |
wait_unmapped(the_win); |
1324 |
|
|
1325 |
|
// Open "suspend" window |
1326 |
|
XSetWindowAttributes wattr; |
1327 |
|
wattr.event_mask = KeyPressMask; |
1328 |
|
wattr.background_pixel = black_pixel; |
996 |
– |
wattr.border_pixel = black_pixel; |
997 |
– |
wattr.backing_store = Always; |
998 |
– |
wattr.backing_planes = xdepth; |
999 |
– |
wattr.colormap = DefaultColormap(x_display, screen); |
1329 |
|
|
1001 |
– |
XSync(x_display, false); |
1330 |
|
suspend_win = XCreateWindow(x_display, rootwin, 0, 0, 512, 1, 0, xdepth, |
1331 |
< |
InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel | |
1332 |
< |
CWBackingStore | CWBackingPlanes | (xdepth == 8 ? CWColormap : 0), &wattr); |
1333 |
< |
XSync(x_display, false); |
1334 |
< |
XStoreName(x_display, suspend_win, GetString(STR_SUSPEND_WINDOW_TITLE)); |
1007 |
< |
XMapRaised(x_display, suspend_win); |
1008 |
< |
XSync(x_display, false); |
1331 |
> |
InputOutput, vis, CWEventMask | CWBackPixel, &wattr); |
1332 |
> |
set_window_name(suspend_win, STR_SUSPEND_WINDOW_TITLE); |
1333 |
> |
set_window_focus(suspend_win); |
1334 |
> |
XMapWindow(x_display, suspend_win); |
1335 |
|
emul_suspended = true; |
1336 |
|
} |
1337 |
|
} |
1344 |
|
|
1345 |
|
// Reopen full screen display |
1346 |
|
XMapRaised(x_display, the_win); |
1347 |
+ |
wait_mapped(the_win); |
1348 |
|
XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0); |
1022 |
– |
XSync(x_display, false); |
1349 |
|
XGrabKeyboard(x_display, rootwin, 1, GrabModeAsync, GrabModeAsync, CurrentTime); |
1350 |
|
XGrabPointer(x_display, rootwin, 1, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); |
1351 |
|
#ifdef ENABLE_XF86_DGA |
1353 |
|
XF86DGASetViewPort(x_display, screen, 0, 0); |
1354 |
|
#endif |
1355 |
|
XSync(x_display, false); |
1356 |
< |
|
1356 |
> |
|
1357 |
> |
// the_buffer already contains the data to restore. i.e. since a temporary |
1358 |
> |
// frame buffer is used when VOSF is actually used, fb_save is therefore |
1359 |
> |
// not necessary. |
1360 |
> |
#ifdef ENABLE_VOSF |
1361 |
> |
if (use_vosf) { |
1362 |
> |
LOCK_VOSF; |
1363 |
> |
PFLAG_SET_ALL; |
1364 |
> |
UNLOCK_VOSF; |
1365 |
> |
memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y); |
1366 |
> |
} |
1367 |
> |
#endif |
1368 |
> |
|
1369 |
|
// Restore frame buffer |
1370 |
|
if (fb_save) { |
1371 |
+ |
#ifdef ENABLE_VOSF |
1372 |
+ |
// Don't copy fb_save to the temporary frame buffer in VOSF mode |
1373 |
+ |
if (!use_vosf) |
1374 |
+ |
#endif |
1375 |
|
memcpy(the_buffer, fb_save, VideoMonitor.y * VideoMonitor.bytes_per_row); |
1376 |
|
free(fb_save); |
1377 |
|
fb_save = NULL; |
1382 |
|
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
1383 |
|
#endif |
1384 |
|
|
1043 |
– |
#ifdef HAVE_PTHREADS |
1385 |
|
// Unlock frame buffer (and continue MacOS thread) |
1386 |
< |
pthread_mutex_unlock(&frame_buffer_lock); |
1386 |
> |
UNLOCK_FRAME_BUFFER; |
1387 |
|
emul_suspended = false; |
1047 |
– |
#endif |
1388 |
|
} |
1389 |
|
#endif |
1390 |
|
|
1538 |
|
return -1; |
1539 |
|
} |
1540 |
|
|
1541 |
< |
static int event2keycode(XKeyEvent *ev) |
1541 |
> |
static int event2keycode(XKeyEvent &ev) |
1542 |
|
{ |
1543 |
|
KeySym ks; |
1544 |
|
int as; |
1545 |
|
int i = 0; |
1546 |
|
|
1547 |
|
do { |
1548 |
< |
ks = XLookupKeysym(ev, i++); |
1548 |
> |
ks = XLookupKeysym(&ev, i++); |
1549 |
|
as = kc_decode(ks); |
1550 |
|
if (as != -1) |
1551 |
|
return as; |
1561 |
|
|
1562 |
|
static void handle_events(void) |
1563 |
|
{ |
1564 |
< |
XEvent event; |
1565 |
< |
for (;;) { |
1566 |
< |
if (!XCheckMaskEvent(x_display, eventmask, &event)) |
1227 |
< |
break; |
1564 |
> |
while (XPending(x_display)) { |
1565 |
> |
XEvent event; |
1566 |
> |
XNextEvent(x_display, &event); |
1567 |
|
|
1568 |
|
switch (event.type) { |
1569 |
|
// Mouse button |
1570 |
|
case ButtonPress: { |
1571 |
< |
unsigned int button = ((XButtonEvent *)&event)->button; |
1571 |
> |
unsigned int button = event.xbutton.button; |
1572 |
|
if (button < 4) |
1573 |
|
ADBMouseDown(button - 1); |
1574 |
|
else if (button < 6) { // Wheel mouse |
1587 |
|
break; |
1588 |
|
} |
1589 |
|
case ButtonRelease: { |
1590 |
< |
unsigned int button = ((XButtonEvent *)&event)->button; |
1590 |
> |
unsigned int button = event.xbutton.button; |
1591 |
|
if (button < 4) |
1592 |
|
ADBMouseUp(button - 1); |
1593 |
|
break; |
1595 |
|
|
1596 |
|
// Mouse moved |
1597 |
|
case EnterNotify: |
1259 |
– |
ADBMouseMoved(((XMotionEvent *)&event)->x, ((XMotionEvent *)&event)->y); |
1260 |
– |
break; |
1598 |
|
case MotionNotify: |
1599 |
< |
ADBMouseMoved(((XMotionEvent *)&event)->x, ((XMotionEvent *)&event)->y); |
1599 |
> |
ADBMouseMoved(event.xmotion.x, event.xmotion.y); |
1600 |
|
break; |
1601 |
|
|
1602 |
|
// Keyboard |
1603 |
|
case KeyPress: { |
1604 |
|
int code; |
1605 |
|
if (use_keycodes) { |
1606 |
< |
event2keycode((XKeyEvent *)&event); // This is called to process the hotkeys |
1607 |
< |
code = keycode_table[((XKeyEvent *)&event)->keycode & 0xff]; |
1606 |
> |
event2keycode(event.xkey); // This is called to process the hotkeys |
1607 |
> |
code = keycode_table[event.xkey.keycode & 0xff]; |
1608 |
|
} else |
1609 |
< |
code = event2keycode((XKeyEvent *)&event); |
1609 |
> |
code = event2keycode(event.xkey); |
1610 |
|
if (code != -1) { |
1611 |
|
if (!emul_suspended) { |
1612 |
|
if (code == 0x39) { // Caps Lock pressed |
1633 |
|
case KeyRelease: { |
1634 |
|
int code; |
1635 |
|
if (use_keycodes) { |
1636 |
< |
event2keycode((XKeyEvent *)&event); // This is called to process the hotkeys |
1637 |
< |
code = keycode_table[((XKeyEvent *)&event)->keycode & 0xff]; |
1636 |
> |
event2keycode(event.xkey); // This is called to process the hotkeys |
1637 |
> |
code = keycode_table[event.xkey.keycode & 0xff]; |
1638 |
|
} else |
1639 |
< |
code = event2keycode((XKeyEvent *)&event); |
1639 |
> |
code = event2keycode(event.xkey); |
1640 |
|
if (code != -1 && code != 0x39) { // Don't propagate Caps Lock releases |
1641 |
|
ADBKeyUp(code); |
1642 |
|
if (code == 0x36) |
1648 |
|
// Hidden parts exposed, force complete refresh of window |
1649 |
|
case Expose: |
1650 |
|
if (display_type == DISPLAY_WINDOW) { |
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; |
1651 |
> |
#ifdef ENABLE_VOSF |
1652 |
> |
if (use_vosf) { // VOSF refresh |
1653 |
> |
LOCK_VOSF; |
1654 |
> |
PFLAG_SET_ALL; |
1655 |
> |
UNLOCK_VOSF; |
1656 |
> |
memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y); |
1657 |
> |
} |
1658 |
> |
else |
1659 |
> |
#endif |
1660 |
> |
if (frame_skip == 0) { // Dynamic refresh |
1661 |
> |
int x1, y1; |
1662 |
> |
for (y1=0; y1<16; y1++) |
1663 |
> |
for (x1=0; x1<16; x1++) |
1664 |
> |
updt_box[x1][y1] = true; |
1665 |
> |
nr_boxes = 16 * 16; |
1666 |
> |
} else // Static refresh |
1667 |
> |
memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y); |
1668 |
|
} |
1669 |
|
break; |
1670 |
+ |
|
1671 |
+ |
// Window "close" widget clicked |
1672 |
+ |
case ClientMessage: |
1673 |
+ |
if (event.xclient.format == 32 && event.xclient.data.l[0] == WM_DELETE_WINDOW) |
1674 |
+ |
XBell(x_display, 0); |
1675 |
+ |
break; |
1676 |
|
} |
1677 |
|
} |
1678 |
|
} |
1682 |
|
* Window display update |
1683 |
|
*/ |
1684 |
|
|
1685 |
< |
static void update_display(int ticker) |
1685 |
> |
// Dynamic display update (variable frame rate for each box) |
1686 |
> |
static void update_display_dynamic(int ticker) |
1687 |
|
{ |
1688 |
< |
int y1, y2, y2s, y2a, i, x1, xm, xmo, ymo, yo, yi, yil, xic, xicl, xi; |
1688 |
> |
int y1, y2, y2s, y2a, i, x1, xm, xmo, ymo, yo, yi, yil, xi; |
1689 |
|
int xil = 0; |
1690 |
|
int rxm = 0, rxmo = 0; |
1691 |
|
int bytes_per_row = VideoMonitor.bytes_per_row; |
1772 |
|
} |
1773 |
|
} |
1774 |
|
|
1775 |
+ |
// Static display update (fixed frame rate, but incremental) |
1776 |
+ |
static void update_display_static(void) |
1777 |
+ |
{ |
1778 |
+ |
// Incremental update code |
1779 |
+ |
int wide = 0, high = 0, x1, x2, y1, y2, i, j; |
1780 |
+ |
int bytes_per_row = VideoMonitor.bytes_per_row; |
1781 |
+ |
int bytes_per_pixel = VideoMonitor.bytes_per_row / VideoMonitor.x; |
1782 |
+ |
uint8 *p, *p2; |
1783 |
+ |
|
1784 |
+ |
// Check for first line from top and first line from bottom that have changed |
1785 |
+ |
y1 = 0; |
1786 |
+ |
for (j=0; j<VideoMonitor.y; j++) { |
1787 |
+ |
if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) { |
1788 |
+ |
y1 = j; |
1789 |
+ |
break; |
1790 |
+ |
} |
1791 |
+ |
} |
1792 |
+ |
y2 = y1 - 1; |
1793 |
+ |
for (j=VideoMonitor.y-1; j>=y1; j--) { |
1794 |
+ |
if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) { |
1795 |
+ |
y2 = j; |
1796 |
+ |
break; |
1797 |
+ |
} |
1798 |
+ |
} |
1799 |
+ |
high = y2 - y1 + 1; |
1800 |
+ |
|
1801 |
+ |
// Check for first column from left and first column from right that have changed |
1802 |
+ |
if (high) { |
1803 |
+ |
if (depth == 1) { |
1804 |
+ |
x1 = VideoMonitor.x - 1; |
1805 |
+ |
for (j=y1; j<=y2; j++) { |
1806 |
+ |
p = &the_buffer[j * bytes_per_row]; |
1807 |
+ |
p2 = &the_buffer_copy[j * bytes_per_row]; |
1808 |
+ |
for (i=0; i<(x1>>3); i++) { |
1809 |
+ |
if (*p != *p2) { |
1810 |
+ |
x1 = i << 3; |
1811 |
+ |
break; |
1812 |
+ |
} |
1813 |
+ |
p++; p2++; |
1814 |
+ |
} |
1815 |
+ |
} |
1816 |
+ |
x2 = x1; |
1817 |
+ |
for (j=y1; j<=y2; j++) { |
1818 |
+ |
p = &the_buffer[j * bytes_per_row]; |
1819 |
+ |
p2 = &the_buffer_copy[j * bytes_per_row]; |
1820 |
+ |
p += bytes_per_row; |
1821 |
+ |
p2 += bytes_per_row; |
1822 |
+ |
for (i=(VideoMonitor.x>>3); i>(x2>>3); i--) { |
1823 |
+ |
p--; p2--; |
1824 |
+ |
if (*p != *p2) { |
1825 |
+ |
x2 = (i << 3) + 7; |
1826 |
+ |
break; |
1827 |
+ |
} |
1828 |
+ |
} |
1829 |
+ |
} |
1830 |
+ |
wide = x2 - x1 + 1; |
1831 |
+ |
|
1832 |
+ |
// Update copy of the_buffer |
1833 |
+ |
if (high && wide) { |
1834 |
+ |
for (j=y1; j<=y2; j++) { |
1835 |
+ |
i = j * bytes_per_row + (x1 >> 3); |
1836 |
+ |
memcpy(the_buffer_copy + i, the_buffer + i, wide >> 3); |
1837 |
+ |
} |
1838 |
+ |
} |
1839 |
+ |
|
1840 |
+ |
} else { |
1841 |
+ |
x1 = VideoMonitor.x; |
1842 |
+ |
for (j=y1; j<=y2; j++) { |
1843 |
+ |
p = &the_buffer[j * bytes_per_row]; |
1844 |
+ |
p2 = &the_buffer_copy[j * bytes_per_row]; |
1845 |
+ |
for (i=0; i<x1*bytes_per_pixel; i++) { |
1846 |
+ |
if (*p != *p2) { |
1847 |
+ |
x1 = i / bytes_per_pixel; |
1848 |
+ |
break; |
1849 |
+ |
} |
1850 |
+ |
p++; p2++; |
1851 |
+ |
} |
1852 |
+ |
} |
1853 |
+ |
x2 = x1; |
1854 |
+ |
for (j=y1; j<=y2; j++) { |
1855 |
+ |
p = &the_buffer[j * bytes_per_row]; |
1856 |
+ |
p2 = &the_buffer_copy[j * bytes_per_row]; |
1857 |
+ |
p += bytes_per_row; |
1858 |
+ |
p2 += bytes_per_row; |
1859 |
+ |
for (i=VideoMonitor.x*bytes_per_pixel; i>x2*bytes_per_pixel; i--) { |
1860 |
+ |
p--; |
1861 |
+ |
p2--; |
1862 |
+ |
if (*p != *p2) { |
1863 |
+ |
x2 = i / bytes_per_pixel; |
1864 |
+ |
break; |
1865 |
+ |
} |
1866 |
+ |
} |
1867 |
+ |
} |
1868 |
+ |
wide = x2 - x1; |
1869 |
+ |
|
1870 |
+ |
// Update copy of the_buffer |
1871 |
+ |
if (high && wide) { |
1872 |
+ |
for (j=y1; j<=y2; j++) { |
1873 |
+ |
i = j * bytes_per_row + x1 * bytes_per_pixel; |
1874 |
+ |
memcpy(the_buffer_copy + i, the_buffer + i, bytes_per_pixel * wide); |
1875 |
+ |
} |
1876 |
+ |
} |
1877 |
+ |
} |
1878 |
+ |
} |
1879 |
+ |
|
1880 |
+ |
// Refresh display |
1881 |
+ |
if (high && wide) { |
1882 |
+ |
if (have_shm) |
1883 |
+ |
XShmPutImage(x_display, the_win, the_gc, img, x1, y1, x1, y1, wide, high, 0); |
1884 |
+ |
else |
1885 |
+ |
XPutImage(x_display, the_win, the_gc, img, x1, y1, x1, y1, wide, high); |
1886 |
+ |
} |
1887 |
+ |
} |
1888 |
+ |
|
1889 |
|
|
1890 |
|
/* |
1891 |
< |
* Thread for screen refresh, input handling etc. |
1891 |
> |
* Screen refresh functions |
1892 |
|
*/ |
1893 |
|
|
1894 |
< |
void VideoRefresh(void) |
1894 |
> |
// The specialisations hereunder are meant to enable VOSF with DGA in direct |
1895 |
> |
// addressing mode in case the address spaces (RAM, ROM, FrameBuffer) could |
1896 |
> |
// not get mapped correctly with respect to the predetermined host frame |
1897 |
> |
// buffer base address. |
1898 |
> |
// |
1899 |
> |
// Hmm, in other words, when in direct addressing mode and DGA is requested, |
1900 |
> |
// we first try to "triple allocate" the address spaces according to the real |
1901 |
> |
// host frame buffer address. Then, if it fails, we will use a temporary |
1902 |
> |
// frame buffer thus making the real host frame buffer updated when pages |
1903 |
> |
// of the temp frame buffer are altered. |
1904 |
> |
// |
1905 |
> |
// As a side effect, a little speed gain in screen updates could be noticed |
1906 |
> |
// for other modes than DGA. |
1907 |
> |
// |
1908 |
> |
// The following two functions below are inline so that a clever compiler |
1909 |
> |
// could specialise the code according to the current screen depth and |
1910 |
> |
// display type. A more clever compiler would the job by itself though... |
1911 |
> |
// (update_display_vosf is inlined as well) |
1912 |
> |
|
1913 |
> |
static inline void possibly_quit_dga_mode() |
1914 |
|
{ |
1915 |
|
#if defined(ENABLE_XF86_DGA) || defined(ENABLE_FBDEV_DGA) |
1916 |
|
// Quit DGA mode if requested |
1917 |
|
if (quit_full_screen) { |
1918 |
|
quit_full_screen = false; |
1430 |
– |
if (display_type == DISPLAY_DGA) { |
1919 |
|
#ifdef ENABLE_XF86_DGA |
1920 |
< |
XF86DGADirectVideo(x_display, screen, 0); |
1920 |
> |
XF86DGADirectVideo(x_display, screen, 0); |
1921 |
|
#endif |
1922 |
< |
XUngrabPointer(x_display, CurrentTime); |
1923 |
< |
XUngrabKeyboard(x_display, CurrentTime); |
1924 |
< |
XUnmapWindow(x_display, the_win); |
1925 |
< |
XSync(x_display, false); |
1438 |
< |
} |
1922 |
> |
XUngrabPointer(x_display, CurrentTime); |
1923 |
> |
XUngrabKeyboard(x_display, CurrentTime); |
1924 |
> |
XUnmapWindow(x_display, the_win); |
1925 |
> |
XSync(x_display, false); |
1926 |
|
} |
1927 |
|
#endif |
1928 |
+ |
} |
1929 |
|
|
1930 |
< |
// Handle X events |
1931 |
< |
handle_events(); |
1930 |
> |
static inline void handle_palette_changes(int depth, int display_type) |
1931 |
> |
{ |
1932 |
> |
LOCK_PALETTE; |
1933 |
|
|
1445 |
– |
// Handle palette changes |
1446 |
– |
#ifdef HAVE_PTHREADS |
1447 |
– |
pthread_mutex_lock(&palette_lock); |
1448 |
– |
#endif |
1934 |
|
if (palette_changed) { |
1935 |
|
palette_changed = false; |
1936 |
|
if (depth == 8) { |
1937 |
|
XStoreColors(x_display, cmap[0], palette, 256); |
1938 |
|
XStoreColors(x_display, cmap[1], palette, 256); |
1939 |
+ |
XSync(x_display, false); |
1940 |
|
|
1941 |
|
#ifdef ENABLE_XF86_DGA |
1942 |
|
if (display_type == DISPLAY_DGA) { |
1946 |
|
#endif |
1947 |
|
} |
1948 |
|
} |
1949 |
< |
#ifdef HAVE_PTHREADS |
1950 |
< |
pthread_mutex_unlock(&palette_lock); |
1949 |
> |
|
1950 |
> |
UNLOCK_PALETTE; |
1951 |
> |
} |
1952 |
> |
|
1953 |
> |
static void video_refresh_dga(void) |
1954 |
> |
{ |
1955 |
> |
// Quit DGA mode if requested |
1956 |
> |
possibly_quit_dga_mode(); |
1957 |
> |
|
1958 |
> |
// Handle X events |
1959 |
> |
handle_events(); |
1960 |
> |
|
1961 |
> |
// Handle palette changes |
1962 |
> |
handle_palette_changes(depth, DISPLAY_DGA); |
1963 |
> |
} |
1964 |
> |
|
1965 |
> |
#ifdef ENABLE_VOSF |
1966 |
> |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
1967 |
> |
static void video_refresh_dga_vosf(void) |
1968 |
> |
{ |
1969 |
> |
// Quit DGA mode if requested |
1970 |
> |
possibly_quit_dga_mode(); |
1971 |
> |
|
1972 |
> |
// Handle X events |
1973 |
> |
handle_events(); |
1974 |
> |
|
1975 |
> |
// Handle palette changes |
1976 |
> |
handle_palette_changes(depth, DISPLAY_DGA); |
1977 |
> |
|
1978 |
> |
// Update display (VOSF variant) |
1979 |
> |
static int tick_counter = 0; |
1980 |
> |
if (++tick_counter >= frame_skip) { |
1981 |
> |
tick_counter = 0; |
1982 |
> |
LOCK_VOSF; |
1983 |
> |
update_display_dga_vosf(); |
1984 |
> |
UNLOCK_VOSF; |
1985 |
> |
} |
1986 |
> |
} |
1987 |
|
#endif |
1988 |
|
|
1989 |
< |
// In window mode, update display |
1989 |
> |
static void video_refresh_window_vosf(void) |
1990 |
> |
{ |
1991 |
> |
// Quit DGA mode if requested |
1992 |
> |
possibly_quit_dga_mode(); |
1993 |
> |
|
1994 |
> |
// Handle X events |
1995 |
> |
handle_events(); |
1996 |
> |
|
1997 |
> |
// Handle palette changes |
1998 |
> |
handle_palette_changes(depth, DISPLAY_WINDOW); |
1999 |
> |
|
2000 |
> |
// Update display (VOSF variant) |
2001 |
> |
static int tick_counter = 0; |
2002 |
> |
if (++tick_counter >= frame_skip) { |
2003 |
> |
tick_counter = 0; |
2004 |
> |
LOCK_VOSF; |
2005 |
> |
update_display_window_vosf(); |
2006 |
> |
UNLOCK_VOSF; |
2007 |
> |
} |
2008 |
> |
} |
2009 |
> |
#endif // def ENABLE_VOSF |
2010 |
> |
|
2011 |
> |
static void video_refresh_window_static(void) |
2012 |
> |
{ |
2013 |
> |
// Handle X events |
2014 |
> |
handle_events(); |
2015 |
> |
|
2016 |
> |
// Handle_palette changes |
2017 |
> |
handle_palette_changes(depth, DISPLAY_WINDOW); |
2018 |
> |
|
2019 |
> |
// Update display (static variant) |
2020 |
> |
static int tick_counter = 0; |
2021 |
> |
if (++tick_counter >= frame_skip) { |
2022 |
> |
tick_counter = 0; |
2023 |
> |
update_display_static(); |
2024 |
> |
} |
2025 |
> |
} |
2026 |
> |
|
2027 |
> |
static void video_refresh_window_dynamic(void) |
2028 |
> |
{ |
2029 |
> |
// Handle X events |
2030 |
> |
handle_events(); |
2031 |
> |
|
2032 |
> |
// Handle_palette changes |
2033 |
> |
handle_palette_changes(depth, DISPLAY_WINDOW); |
2034 |
> |
|
2035 |
> |
// Update display (dynamic variant) |
2036 |
|
static int tick_counter = 0; |
2037 |
< |
if (display_type == DISPLAY_WINDOW) { |
2038 |
< |
tick_counter++; |
2039 |
< |
update_display(tick_counter); |
2037 |
> |
tick_counter++; |
2038 |
> |
update_display_dynamic(tick_counter); |
2039 |
> |
} |
2040 |
> |
|
2041 |
> |
|
2042 |
> |
/* |
2043 |
> |
* Thread for screen refresh, input handling etc. |
2044 |
> |
*/ |
2045 |
> |
|
2046 |
> |
void VideoRefreshInit(void) |
2047 |
> |
{ |
2048 |
> |
// TODO: set up specialised 8bpp VideoRefresh handlers ? |
2049 |
> |
if (display_type == DISPLAY_DGA) { |
2050 |
> |
#if ENABLE_VOSF && (REAL_ADDRESSING || DIRECT_ADDRESSING) |
2051 |
> |
if (use_vosf) |
2052 |
> |
video_refresh = video_refresh_dga_vosf; |
2053 |
> |
else |
2054 |
> |
#endif |
2055 |
> |
video_refresh = video_refresh_dga; |
2056 |
> |
} |
2057 |
> |
else { |
2058 |
> |
#ifdef ENABLE_VOSF |
2059 |
> |
if (use_vosf) |
2060 |
> |
video_refresh = video_refresh_window_vosf; |
2061 |
> |
else |
2062 |
> |
#endif |
2063 |
> |
if (frame_skip == 0) |
2064 |
> |
video_refresh = video_refresh_window_dynamic; |
2065 |
> |
else |
2066 |
> |
video_refresh = video_refresh_window_static; |
2067 |
|
} |
2068 |
|
} |
2069 |
|
|
2070 |
+ |
void VideoRefresh(void) |
2071 |
+ |
{ |
2072 |
+ |
// TODO: make main_unix/VideoRefresh call directly video_refresh() ? |
2073 |
+ |
video_refresh(); |
2074 |
+ |
} |
2075 |
+ |
|
2076 |
|
#ifdef HAVE_PTHREADS |
2077 |
|
static void *redraw_func(void *arg) |
2078 |
|
{ |
2079 |
+ |
uint64 start = GetTicks_usec(); |
2080 |
+ |
int64 ticks = 0; |
2081 |
+ |
uint64 next = GetTicks_usec(); |
2082 |
|
while (!redraw_thread_cancel) { |
2083 |
< |
#ifdef HAVE_NANOSLEEP |
2084 |
< |
struct timespec req = {0, 16666667}; |
2085 |
< |
nanosleep(&req, NULL); |
2086 |
< |
#else |
2087 |
< |
usleep(16667); |
2088 |
< |
#endif |
2089 |
< |
VideoRefresh(); |
2083 |
> |
video_refresh(); |
2084 |
> |
next += 16667; |
2085 |
> |
int64 delay = next - GetTicks_usec(); |
2086 |
> |
if (delay > 0) |
2087 |
> |
Delay_usec(delay); |
2088 |
> |
else if (delay < -16667) |
2089 |
> |
next = GetTicks_usec(); |
2090 |
> |
ticks++; |
2091 |
|
} |
2092 |
+ |
uint64 end = GetTicks_usec(); |
2093 |
+ |
printf("%Ld ticks in %Ld usec = %Ld ticks/sec\n", ticks, end - start, (end - start) / ticks); |
2094 |
|
return NULL; |
2095 |
|
} |
2096 |
|
#endif |