1 |
|
/* |
2 |
|
* video_x.cpp - Video/graphics emulation, X11 specific stuff |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-2000 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2001 Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
52 |
|
# include <sys/mman.h> |
53 |
|
#endif |
54 |
|
|
55 |
– |
#ifdef ENABLE_VOSF |
56 |
– |
# include <math.h> // log() |
57 |
– |
# include <unistd.h> |
58 |
– |
# include <signal.h> |
59 |
– |
# include <fcntl.h> |
60 |
– |
# include <sys/mman.h> |
61 |
– |
#endif |
62 |
– |
|
55 |
|
#include "cpu_emulation.h" |
56 |
|
#include "main.h" |
57 |
|
#include "adb.h" |
86 |
|
|
87 |
|
#ifdef HAVE_PTHREADS |
88 |
|
static bool redraw_thread_active = false; // Flag: Redraw thread installed |
89 |
< |
static volatile bool redraw_thread_cancel = false; // Flag: Cancel Redraw thread |
89 |
> |
static volatile bool redraw_thread_cancel; // Flag: Cancel Redraw thread |
90 |
|
static pthread_t redraw_thread; // Redraw thread |
91 |
|
#endif |
92 |
|
|
107 |
|
// X11 variables |
108 |
|
static int screen; // Screen number |
109 |
|
static int xdepth; // Depth of X screen |
118 |
– |
static int depth; // Depth of Mac frame buffer |
110 |
|
static Window rootwin, the_win; // Root window and our window |
111 |
|
static XVisualInfo visualInfo; |
112 |
|
static Visual *vis; |
113 |
|
static Colormap cmap[2]; // Two colormaps (DGA) for 8-bit mode |
114 |
+ |
static bool cmap_allocated = false; |
115 |
|
static XColor black, white; |
116 |
|
static unsigned long black_pixel, white_pixel; |
117 |
|
static int eventmask; |
118 |
< |
static const int win_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | ExposureMask; |
119 |
< |
static const int dga_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask; |
118 |
> |
static const int win_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | ExposureMask | StructureNotifyMask; |
119 |
> |
static const int dga_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask; |
120 |
> |
static Atom WM_DELETE_WINDOW = (Atom)0; |
121 |
|
|
122 |
|
static XColor palette[256]; // Color palette for 8-bit mode |
123 |
|
static bool palette_changed = false; // Flag: Palette changed, redraw thread must set new colors |
124 |
|
#ifdef HAVE_PTHREADS |
125 |
|
static pthread_mutex_t palette_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect palette |
126 |
+ |
#define LOCK_PALETTE pthread_mutex_lock(&palette_lock) |
127 |
+ |
#define UNLOCK_PALETTE pthread_mutex_unlock(&palette_lock) |
128 |
+ |
#else |
129 |
+ |
#define LOCK_PALETTE |
130 |
+ |
#define UNLOCK_PALETTE |
131 |
|
#endif |
132 |
|
|
133 |
|
// Variables for window mode |
148 |
|
static void *fb_save = NULL; // Saved frame buffer for suspend |
149 |
|
#ifdef HAVE_PTHREADS |
150 |
|
static pthread_mutex_t frame_buffer_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect frame buffer |
151 |
+ |
#define LOCK_FRAME_BUFFER pthread_mutex_lock(&frame_buffer_lock); |
152 |
+ |
#define UNLOCK_FRAME_BUFFER pthread_mutex_unlock(&frame_buffer_lock); |
153 |
+ |
#else |
154 |
+ |
#define LOCK_FRAME_BUFFER |
155 |
+ |
#define UNLOCK_FRAME_BUFFER |
156 |
|
#endif |
157 |
|
|
158 |
|
// Variables for fbdev DGA mode |
171 |
|
static const bool use_vosf = false; // Flag: VOSF enabled |
172 |
|
#endif |
173 |
|
|
171 |
– |
#ifdef ENABLE_VOSF |
172 |
– |
static uint8 * the_host_buffer; // Host frame buffer in VOSF mode |
173 |
– |
static uint32 the_buffer_size; // Size of allocated the_buffer |
174 |
– |
#endif |
175 |
– |
|
176 |
– |
#ifdef ENABLE_VOSF |
177 |
– |
// Variables for Video on SEGV support (taken from the Win32 port) |
178 |
– |
struct ScreenPageInfo { |
179 |
– |
int top, bottom; // Mapping between this virtual page and Mac scanlines |
180 |
– |
}; |
181 |
– |
|
182 |
– |
struct ScreenInfo { |
183 |
– |
uint32 memBase; // Real start address |
184 |
– |
uint32 memStart; // Start address aligned to page boundary |
185 |
– |
uint32 memEnd; // Address of one-past-the-end of the screen |
186 |
– |
uint32 memLength; // Length of the memory addressed by the screen pages |
187 |
– |
|
188 |
– |
uint32 pageSize; // Size of a page |
189 |
– |
int pageBits; // Shift count to get the page number |
190 |
– |
uint32 pageCount; // Number of pages allocated to the screen |
191 |
– |
|
192 |
– |
uint8 * dirtyPages; // Table of flags set if page was altered |
193 |
– |
ScreenPageInfo * pageInfo; // Table of mappings page -> Mac scanlines |
194 |
– |
}; |
195 |
– |
|
196 |
– |
static ScreenInfo mainBuffer; |
197 |
– |
|
198 |
– |
#define PFLAG_SET(page) mainBuffer.dirtyPages[page] = 1 |
199 |
– |
#define PFLAG_CLEAR(page) mainBuffer.dirtyPages[page] = 0 |
200 |
– |
#define PFLAG_ISSET(page) mainBuffer.dirtyPages[page] |
201 |
– |
#define PFLAG_ISCLEAR(page) (mainBuffer.dirtyPages[page] == 0) |
202 |
– |
#ifdef UNALIGNED_PROFITABLE |
203 |
– |
# define PFLAG_ISCLEAR_4(page) (*((uint32 *)(mainBuffer.dirtyPages + page)) == 0) |
204 |
– |
#else |
205 |
– |
# define PFLAG_ISCLEAR_4(page) \ |
206 |
– |
(mainBuffer.dirtyPages[page ] == 0) \ |
207 |
– |
&& (mainBuffer.dirtyPages[page+1] == 0) \ |
208 |
– |
&& (mainBuffer.dirtyPages[page+2] == 0) \ |
209 |
– |
&& (mainBuffer.dirtyPages[page+3] == 0) |
210 |
– |
#endif |
211 |
– |
#define PFLAG_CLEAR_ALL memset(mainBuffer.dirtyPages, 0, mainBuffer.pageCount) |
212 |
– |
#define PFLAG_SET_ALL memset(mainBuffer.dirtyPages, 1, mainBuffer.pageCount) |
213 |
– |
|
214 |
– |
static int zero_fd = -1; |
215 |
– |
static bool Screen_fault_handler_init(); |
216 |
– |
static struct sigaction vosf_sa; |
217 |
– |
|
218 |
– |
#ifdef HAVE_PTHREADS |
219 |
– |
static pthread_mutex_t Screen_draw_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect frame buffer (dirtyPages in fact) |
220 |
– |
#endif |
221 |
– |
|
222 |
– |
#endif |
223 |
– |
|
174 |
|
// VideoRefresh function |
175 |
< |
void VideoRefreshInit(void); |
175 |
> |
static void VideoRefreshInit(void); |
176 |
|
static void (*video_refresh)(void); |
177 |
|
|
178 |
|
// Prototypes |
179 |
|
static void *redraw_func(void *arg); |
180 |
< |
static int event2keycode(XKeyEvent *ev); |
231 |
< |
|
180 |
> |
static int event2keycode(XKeyEvent &ev); |
181 |
|
|
182 |
|
// From main_unix.cpp |
183 |
|
extern char *x_display_name; |
186 |
|
// From sys_unix.cpp |
187 |
|
extern void SysMountFirstFloppy(void); |
188 |
|
|
189 |
+ |
|
190 |
|
#ifdef ENABLE_VOSF |
191 |
|
# include "video_vosf.h" |
192 |
|
#endif |
196 |
|
* Initialization |
197 |
|
*/ |
198 |
|
|
199 |
< |
// Set VideoMonitor according to video mode |
200 |
< |
void set_video_monitor(int width, int height, int bytes_per_row, bool native_byte_order) |
199 |
> |
// Add mode to list of supported modes |
200 |
> |
static void add_mode(uint32 width, uint32 height, uint32 resolution_id, uint32 bytes_per_row, video_depth depth) |
201 |
> |
{ |
202 |
> |
video_mode mode; |
203 |
> |
mode.x = width; |
204 |
> |
mode.y = height; |
205 |
> |
mode.resolution_id = resolution_id; |
206 |
> |
mode.bytes_per_row = bytes_per_row; |
207 |
> |
mode.depth = depth; |
208 |
> |
VideoModes.push_back(mode); |
209 |
> |
} |
210 |
> |
|
211 |
> |
// Set Mac frame layout and base address (uses the_buffer/MacFrameBaseMac) |
212 |
> |
static void set_mac_frame_buffer(video_depth depth, bool native_byte_order) |
213 |
|
{ |
214 |
|
#if !REAL_ADDRESSING && !DIRECT_ADDRESSING |
215 |
|
int layout = FLAYOUT_DIRECT; |
216 |
< |
switch (depth) { |
217 |
< |
case 1: |
218 |
< |
layout = FLAYOUT_DIRECT; |
219 |
< |
break; |
258 |
< |
case 8: |
259 |
< |
layout = FLAYOUT_DIRECT; |
260 |
< |
break; |
261 |
< |
case 15: |
262 |
< |
layout = FLAYOUT_HOST_555; |
263 |
< |
break; |
264 |
< |
case 16: |
265 |
< |
layout = FLAYOUT_HOST_565; |
266 |
< |
break; |
267 |
< |
case 24: |
268 |
< |
case 32: |
269 |
< |
layout = FLAYOUT_HOST_888; |
270 |
< |
break; |
271 |
< |
} |
216 |
> |
if (depth == VDEPTH_16BIT) |
217 |
> |
layout = (xdepth == 15) ? FLAYOUT_HOST_555 : FLAYOUT_HOST_565; |
218 |
> |
else if (depth == VDEPTH_32BIT) |
219 |
> |
layour = (xdepth == 24) ? FLAYOUT_HOST_888 : FLAYOUT_DIRECT; |
220 |
|
if (native_byte_order) |
221 |
|
MacFrameLayout = layout; |
222 |
|
else |
223 |
|
MacFrameLayout = FLAYOUT_DIRECT; |
224 |
+ |
VideoMonitor.mac_frame_base = MacFrameBaseMac; |
225 |
+ |
#else |
226 |
+ |
VideoMonitor.mac_frame_base = Host2MacAddr(the_buffer); |
227 |
+ |
D(bug("Host frame buffer = %p, ", the_buffer)); |
228 |
|
#endif |
229 |
< |
switch (depth) { |
230 |
< |
case 1: |
231 |
< |
VideoMonitor.mode = VMODE_1BIT; |
232 |
< |
break; |
233 |
< |
case 8: |
234 |
< |
VideoMonitor.mode = VMODE_8BIT; |
235 |
< |
break; |
236 |
< |
case 15: |
237 |
< |
VideoMonitor.mode = VMODE_16BIT; |
238 |
< |
break; |
239 |
< |
case 16: |
240 |
< |
VideoMonitor.mode = VMODE_16BIT; |
241 |
< |
break; |
242 |
< |
case 24: |
243 |
< |
case 32: |
244 |
< |
VideoMonitor.mode = VMODE_32BIT; |
245 |
< |
break; |
229 |
> |
D(bug("VideoMonitor.mac_frame_base = %08x\n", VideoMonitor.mac_frame_base)); |
230 |
> |
} |
231 |
> |
|
232 |
> |
// Set window name and class |
233 |
> |
static void set_window_name(Window w, int name) |
234 |
> |
{ |
235 |
> |
const char *str = GetString(name); |
236 |
> |
XStoreName(x_display, w, str); |
237 |
> |
XSetIconName(x_display, w, str); |
238 |
> |
|
239 |
> |
XClassHint *hints; |
240 |
> |
hints = XAllocClassHint(); |
241 |
> |
if (hints) { |
242 |
> |
hints->res_name = "BasiliskII"; |
243 |
> |
hints->res_class = "BasiliskII"; |
244 |
> |
XSetClassHint(x_display, w, hints); |
245 |
> |
XFree(hints); |
246 |
> |
} |
247 |
> |
} |
248 |
> |
|
249 |
> |
// Set window input focus flag |
250 |
> |
static void set_window_focus(Window w) |
251 |
> |
{ |
252 |
> |
XWMHints *hints = XAllocWMHints(); |
253 |
> |
if (hints) { |
254 |
> |
hints->input = True; |
255 |
> |
hints->initial_state = NormalState; |
256 |
> |
hints->flags = InputHint | StateHint; |
257 |
> |
XSetWMHints(x_display, w, hints); |
258 |
> |
XFree(hints); |
259 |
|
} |
260 |
< |
VideoMonitor.x = width; |
261 |
< |
VideoMonitor.y = height; |
262 |
< |
VideoMonitor.bytes_per_row = bytes_per_row; |
260 |
> |
} |
261 |
> |
|
262 |
> |
// Set WM_DELETE_WINDOW protocol on window (preventing it from being destroyed by the WM when clicking on the "close" widget) |
263 |
> |
static void set_window_delete_protocol(Window w) |
264 |
> |
{ |
265 |
> |
WM_DELETE_WINDOW = XInternAtom(x_display, "WM_DELETE_WINDOW", false); |
266 |
> |
XSetWMProtocols(x_display, w, &WM_DELETE_WINDOW, 1); |
267 |
> |
} |
268 |
> |
|
269 |
> |
// Wait until window is mapped/unmapped |
270 |
> |
void wait_mapped(Window w) |
271 |
> |
{ |
272 |
> |
XEvent e; |
273 |
> |
do { |
274 |
> |
XMaskEvent(x_display, StructureNotifyMask, &e); |
275 |
> |
} while ((e.type != MapNotify) || (e.xmap.event != w)); |
276 |
> |
} |
277 |
> |
|
278 |
> |
void wait_unmapped(Window w) |
279 |
> |
{ |
280 |
> |
XEvent e; |
281 |
> |
do { |
282 |
> |
XMaskEvent(x_display, StructureNotifyMask, &e); |
283 |
> |
} while ((e.type != UnmapNotify) || (e.xmap.event != w)); |
284 |
|
} |
285 |
|
|
286 |
|
// Trap SHM errors |
297 |
|
} |
298 |
|
|
299 |
|
// Init window mode |
300 |
< |
static bool init_window(int width, int height) |
300 |
> |
static bool init_window(const video_mode &mode) |
301 |
|
{ |
302 |
+ |
int width = mode.x, height = mode.y; |
303 |
|
int aligned_width = (width + 15) & ~15; |
304 |
|
int aligned_height = (height + 15) & ~15; |
305 |
|
|
313 |
|
XSetWindowAttributes wattr; |
314 |
|
wattr.event_mask = eventmask = win_eventmask; |
315 |
|
wattr.background_pixel = black_pixel; |
316 |
< |
wattr.border_pixel = black_pixel; |
330 |
< |
wattr.backing_store = NotUseful; |
331 |
< |
wattr.save_under = false; |
332 |
< |
wattr.backing_planes = xdepth; |
316 |
> |
wattr.colormap = cmap[0]; |
317 |
|
|
334 |
– |
XSync(x_display, false); |
318 |
|
the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, |
319 |
< |
InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel | |
337 |
< |
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); |
319 |
> |
InputOutput, vis, CWEventMask | CWBackPixel | ((IsDirectMode(mode) || mode.depth == VDEPTH_1BIT) ? 0 : CWColormap), &wattr); |
320 |
|
|
321 |
< |
// Set colormap |
322 |
< |
if (depth == 8) { |
323 |
< |
XSetWindowColormap(x_display, the_win, cmap[0]); |
324 |
< |
XSetWMColormapWindows(x_display, the_win, &the_win, 1); |
325 |
< |
} |
321 |
> |
// Set window name/class |
322 |
> |
set_window_name(the_win, STR_WINDOW_TITLE); |
323 |
> |
|
324 |
> |
// Indicate that we want keyboard input |
325 |
> |
set_window_focus(the_win); |
326 |
> |
|
327 |
> |
// Set delete protocol property |
328 |
> |
set_window_delete_protocol(the_win); |
329 |
|
|
330 |
|
// Make window unresizable |
331 |
< |
XSizeHints *hints; |
332 |
< |
if ((hints = XAllocSizeHints()) != NULL) { |
333 |
< |
hints->min_width = width; |
334 |
< |
hints->max_width = width; |
335 |
< |
hints->min_height = height; |
336 |
< |
hints->max_height = height; |
337 |
< |
hints->flags = PMinSize | PMaxSize; |
338 |
< |
XSetWMNormalHints(x_display, the_win, hints); |
339 |
< |
XFree((char *)hints); |
331 |
> |
{ |
332 |
> |
XSizeHints *hints = XAllocSizeHints(); |
333 |
> |
if (hints) { |
334 |
> |
hints->min_width = width; |
335 |
> |
hints->max_width = width; |
336 |
> |
hints->min_height = height; |
337 |
> |
hints->max_height = height; |
338 |
> |
hints->flags = PMinSize | PMaxSize; |
339 |
> |
XSetWMNormalHints(x_display, the_win, hints); |
340 |
> |
XFree(hints); |
341 |
> |
} |
342 |
|
} |
343 |
|
|
344 |
+ |
// Show window |
345 |
+ |
XMapWindow(x_display, the_win); |
346 |
+ |
wait_mapped(the_win); |
347 |
+ |
|
348 |
|
// Try to create and attach SHM image |
349 |
|
have_shm = false; |
350 |
< |
if (depth != 1 && local_X11 && XShmQueryExtension(x_display)) { |
350 |
> |
if (mode.depth != VDEPTH_1BIT && local_X11 && XShmQueryExtension(x_display)) { |
351 |
|
|
352 |
|
// Create SHM image ("height + 2" for safety) |
353 |
< |
img = XShmCreateImage(x_display, vis, depth, depth == 1 ? XYBitmap : ZPixmap, 0, &shminfo, width, height); |
353 |
> |
img = XShmCreateImage(x_display, vis, mode.depth == VDEPTH_1BIT ? 1 : xdepth, mode.depth == VDEPTH_1BIT ? XYBitmap : ZPixmap, 0, &shminfo, width, height); |
354 |
|
shminfo.shmid = shmget(IPC_PRIVATE, (aligned_height + 2) * img->bytes_per_line, IPC_CREAT | 0777); |
355 |
|
the_buffer_copy = (uint8 *)shmat(shminfo.shmid, 0, 0); |
356 |
|
shminfo.shmaddr = img->data = (char *)the_buffer_copy; |
374 |
|
|
375 |
|
// Create normal X image if SHM doesn't work ("height + 2" for safety) |
376 |
|
if (!have_shm) { |
377 |
< |
int bytes_per_row = aligned_width; |
391 |
< |
switch (depth) { |
392 |
< |
case 1: |
393 |
< |
bytes_per_row /= 8; |
394 |
< |
break; |
395 |
< |
case 15: |
396 |
< |
case 16: |
397 |
< |
bytes_per_row *= 2; |
398 |
< |
break; |
399 |
< |
case 24: |
400 |
< |
case 32: |
401 |
< |
bytes_per_row *= 4; |
402 |
< |
break; |
403 |
< |
} |
377 |
> |
int bytes_per_row = TrivialBytesPerRow(aligned_width, mode.depth); |
378 |
|
the_buffer_copy = (uint8 *)malloc((aligned_height + 2) * bytes_per_row); |
379 |
< |
img = XCreateImage(x_display, vis, depth, depth == 1 ? XYBitmap : ZPixmap, 0, (char *)the_buffer_copy, aligned_width, aligned_height, 32, bytes_per_row); |
379 |
> |
img = XCreateImage(x_display, vis, mode.depth == VDEPTH_1BIT ? 1 : xdepth, mode.depth == VDEPTH_1BIT ? XYBitmap : ZPixmap, 0, (char *)the_buffer_copy, aligned_width, aligned_height, 32, bytes_per_row); |
380 |
|
} |
381 |
|
|
382 |
|
// 1-Bit mode is big-endian |
383 |
< |
if (depth == 1) { |
383 |
> |
if (mode.depth == VDEPTH_1BIT) { |
384 |
|
img->byte_order = MSBFirst; |
385 |
|
img->bitmap_bit_order = MSBFirst; |
386 |
|
} |
387 |
|
|
388 |
|
#ifdef ENABLE_VOSF |
389 |
< |
// Allocate a page-aligned chunk of memory for frame buffer |
416 |
< |
the_buffer_size = align_on_page_boundary((aligned_height + 2) * img->bytes_per_line); |
389 |
> |
// Allocate memory for frame buffer (SIZE is extended to page-boundary) |
390 |
|
the_host_buffer = the_buffer_copy; |
391 |
< |
|
392 |
< |
the_buffer_copy = (uint8 *)allocate_framebuffer(the_buffer_size); |
393 |
< |
memset(the_buffer_copy, 0, the_buffer_size); |
421 |
< |
|
422 |
< |
the_buffer = (uint8 *)allocate_framebuffer(the_buffer_size); |
423 |
< |
memset(the_buffer, 0, the_buffer_size); |
391 |
> |
the_buffer_size = page_extend((aligned_height + 2) * img->bytes_per_line); |
392 |
> |
the_buffer_copy = (uint8 *)vm_acquire(the_buffer_size); |
393 |
> |
the_buffer = (uint8 *)vm_acquire(the_buffer_size); |
394 |
|
#else |
395 |
|
// Allocate memory for frame buffer |
396 |
|
the_buffer = (uint8 *)malloc((aligned_height + 2) * img->bytes_per_line); |
407 |
|
&black, &white, 0, 0); |
408 |
|
XDefineCursor(x_display, the_win, mac_cursor); |
409 |
|
|
410 |
< |
// Set VideoMonitor |
410 |
> |
// Add resolution and set VideoMonitor |
411 |
|
bool native_byte_order; |
412 |
|
#ifdef WORDS_BIGENDIAN |
413 |
< |
native_byte_order = (img->bitmap_bit_order == MSBFirst); |
413 |
> |
native_byte_order = (XImageByteOrder(x_display) == MSBFirst); |
414 |
|
#else |
415 |
< |
native_byte_order = (img->bitmap_bit_order == LSBFirst); |
415 |
> |
native_byte_order = (XImageByteOrder(x_display) == LSBFirst); |
416 |
|
#endif |
417 |
|
#ifdef ENABLE_VOSF |
418 |
< |
do_update_framebuffer = GET_FBCOPY_FUNC(depth, native_byte_order, DISPLAY_WINDOW); |
449 |
< |
#endif |
450 |
< |
set_video_monitor(width, height, img->bytes_per_line, native_byte_order); |
451 |
< |
|
452 |
< |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
453 |
< |
VideoMonitor.mac_frame_base = Host2MacAddr(the_buffer); |
454 |
< |
#else |
455 |
< |
VideoMonitor.mac_frame_base = MacFrameBaseMac; |
418 |
> |
Screen_blitter_init(&visualInfo, native_byte_order); |
419 |
|
#endif |
420 |
+ |
VideoMonitor.mode = mode; |
421 |
+ |
set_mac_frame_buffer(mode.depth, native_byte_order); |
422 |
|
return true; |
423 |
|
} |
424 |
|
|
425 |
|
// Init fbdev DGA display |
426 |
< |
static bool init_fbdev_dga(char *in_fb_name) |
426 |
> |
static bool init_fbdev_dga(const video_mode &mode) |
427 |
|
{ |
428 |
|
#ifdef ENABLE_FBDEV_DGA |
429 |
+ |
int width = mode.x, height = mode.y; |
430 |
+ |
|
431 |
|
// Find the maximum depth available |
432 |
|
int ndepths, max_depth(0); |
433 |
|
int *depths = XListDepths(x_display, screen, &ndepths); |
470 |
|
continue; |
471 |
|
|
472 |
|
if ((sscanf(line, "%19s %d %x", &fb_name, &fb_depth, &fb_offset) == 3) |
473 |
< |
&& (strcmp(fb_name, in_fb_name) == 0) && (fb_depth == max_depth)) { |
473 |
> |
&& (strcmp(fb_name, fb_name) == 0) && (fb_depth == max_depth)) { |
474 |
|
device_found = true; |
475 |
|
break; |
476 |
|
} |
482 |
|
// Frame buffer name not found ? Then, display warning |
483 |
|
if (!device_found) { |
484 |
|
char str[256]; |
485 |
< |
sprintf(str, GetString(STR_FBDEV_NAME_ERR), in_fb_name, max_depth); |
485 |
> |
sprintf(str, GetString(STR_FBDEV_NAME_ERR), fb_name, max_depth); |
486 |
|
ErrorAlert(str); |
487 |
|
return false; |
488 |
|
} |
489 |
|
|
490 |
< |
int width = DisplayWidth(x_display, screen); |
524 |
< |
int height = DisplayHeight(x_display, screen); |
525 |
< |
depth = fb_depth; // max_depth |
490 |
> |
depth = fb_depth; |
491 |
|
|
492 |
|
// Set relative mouse mode |
493 |
|
ADBSetRelMouseMode(false); |
494 |
|
|
495 |
|
// Create window |
496 |
|
XSetWindowAttributes wattr; |
497 |
< |
wattr.override_redirect = True; |
498 |
< |
wattr.backing_store = NotUseful; |
499 |
< |
wattr.background_pixel = white_pixel; |
500 |
< |
wattr.border_pixel = black_pixel; |
536 |
< |
wattr.event_mask = eventmask = dga_eventmask; |
497 |
> |
wattr.event_mask = eventmask = dga_eventmask; |
498 |
> |
wattr.background_pixel = white_pixel; |
499 |
> |
wattr.override_redirect = True; |
500 |
> |
wattr.colormap = cmap[0]; |
501 |
|
|
538 |
– |
XSync(x_display, false); |
502 |
|
the_win = XCreateWindow(x_display, rootwin, |
503 |
|
0, 0, width, height, |
504 |
|
0, xdepth, InputOutput, vis, |
505 |
< |
CWEventMask|CWBackPixel|CWBorderPixel|CWOverrideRedirect|CWBackingStore, |
505 |
> |
CWEventMask | CWBackPixel | CWOverrideRedirect | (depth == 8 ? CWColormap : 0), |
506 |
|
&wattr); |
507 |
< |
XSync(x_display, false); |
507 |
> |
|
508 |
> |
// Set window name/class |
509 |
> |
set_window_name(the_win, STR_WINDOW_TITLE); |
510 |
> |
|
511 |
> |
// Indicate that we want keyboard input |
512 |
> |
set_window_focus(the_win); |
513 |
> |
|
514 |
> |
// Show window |
515 |
|
XMapRaised(x_display, the_win); |
516 |
< |
XSync(x_display, false); |
516 |
> |
wait_mapped(the_win); |
517 |
|
|
518 |
|
// Grab mouse and keyboard |
519 |
|
XGrabKeyboard(x_display, the_win, True, |
522 |
|
PointerMotionMask | ButtonPressMask | ButtonReleaseMask, |
523 |
|
GrabModeAsync, GrabModeAsync, the_win, None, CurrentTime); |
524 |
|
|
525 |
< |
// Set colormap |
526 |
< |
if (depth == 8) { |
557 |
< |
XSetWindowColormap(x_display, the_win, cmap[0]); |
558 |
< |
XSetWMColormapWindows(x_display, the_win, &the_win, 1); |
559 |
< |
} |
560 |
< |
|
561 |
< |
// Set VideoMonitor |
562 |
< |
int bytes_per_row = width; |
563 |
< |
switch (depth) { |
564 |
< |
case 1: |
565 |
< |
bytes_per_row = ((width | 7) & ~7) >> 3; |
566 |
< |
break; |
567 |
< |
case 15: |
568 |
< |
case 16: |
569 |
< |
bytes_per_row *= 2; |
570 |
< |
break; |
571 |
< |
case 24: |
572 |
< |
case 32: |
573 |
< |
bytes_per_row *= 4; |
574 |
< |
break; |
575 |
< |
} |
525 |
> |
// Calculate bytes per row |
526 |
> |
int bytes_per_row = TrivialBytesPerRow(mode.x, mode.depth); |
527 |
|
|
528 |
+ |
// Map frame buffer |
529 |
|
if ((the_buffer = (uint8 *) mmap(NULL, height * bytes_per_row, PROT_READ | PROT_WRITE, MAP_PRIVATE, fbdev_fd, fb_offset)) == MAP_FAILED) { |
530 |
|
if ((the_buffer = (uint8 *) mmap(NULL, height * bytes_per_row, PROT_READ | PROT_WRITE, MAP_SHARED, fbdev_fd, fb_offset)) == MAP_FAILED) { |
531 |
|
char str[256]; |
535 |
|
} |
536 |
|
} |
537 |
|
|
538 |
+ |
#if ENABLE_VOSF |
539 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
540 |
< |
// If the blit function is null, i.e. just a copy of the buffer, |
541 |
< |
// we first try to avoid the allocation of a temporary frame buffer |
542 |
< |
use_vosf = true; |
590 |
< |
do_update_framebuffer = GET_FBCOPY_FUNC(depth, true, DISPLAY_DGA); |
591 |
< |
if (do_update_framebuffer == FBCOPY_FUNC(fbcopy_raw)) |
592 |
< |
use_vosf = false; |
540 |
> |
// Screen_blitter_init() returns TRUE if VOSF is mandatory |
541 |
> |
// i.e. the framebuffer update function is not Blit_Copy_Raw |
542 |
> |
use_vosf = Screen_blitter_init(&visualInfo, true); |
543 |
|
|
544 |
|
if (use_vosf) { |
545 |
< |
the_host_buffer = the_buffer; |
546 |
< |
the_buffer_size = align_on_page_boundary((height + 2) * bytes_per_row); |
547 |
< |
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
548 |
< |
memset(the_buffer_copy, 0, the_buffer_size); |
549 |
< |
the_buffer = (uint8 *)allocate_framebuffer(the_buffer_size); |
600 |
< |
memset(the_buffer, 0, the_buffer_size); |
545 |
> |
// Allocate memory for frame buffer (SIZE is extended to page-boundary) |
546 |
> |
the_host_buffer = the_buffer; |
547 |
> |
the_buffer_size = page_extend((height + 2) * bytes_per_row); |
548 |
> |
the_buffer_copy = (uint8 *)vm_acquire(the_buffer_size); |
549 |
> |
the_buffer = (uint8 *)vm_acquire(the_buffer_size); |
550 |
|
} |
551 |
< |
#elif ENABLE_VOSF |
551 |
> |
#else |
552 |
|
use_vosf = false; |
553 |
|
#endif |
605 |
– |
|
606 |
– |
set_video_monitor(width, height, bytes_per_row, true); |
607 |
– |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
608 |
– |
VideoMonitor.mac_frame_base = Host2MacAddr(the_buffer); |
609 |
– |
#else |
610 |
– |
VideoMonitor.mac_frame_base = MacFrameBaseMac; |
554 |
|
#endif |
555 |
+ |
|
556 |
+ |
// Set VideoMonitor |
557 |
+ |
VideoMonitor.mode = mode; |
558 |
+ |
set_mac_frame_buffer(mode.depth, true); |
559 |
|
return true; |
560 |
|
#else |
561 |
|
ErrorAlert("Basilisk II has been compiled with fbdev DGA support disabled."); |
564 |
|
} |
565 |
|
|
566 |
|
// Init XF86 DGA display |
567 |
< |
static bool init_xf86_dga(int width, int height) |
567 |
> |
static bool init_xf86_dga(const video_mode &mode) |
568 |
|
{ |
569 |
+ |
int width = mode.x, height = mode.y; |
570 |
+ |
|
571 |
|
#ifdef ENABLE_XF86_DGA |
572 |
|
// Set relative mouse mode |
573 |
|
ADBSetRelMouseMode(true); |
584 |
|
} |
585 |
|
XF86VidModeSwitchToMode(x_display, screen, x_video_modes[best]); |
586 |
|
XF86VidModeSetViewPort(x_display, screen, 0, 0); |
587 |
+ |
XSync(x_display, false); |
588 |
|
} |
589 |
|
#endif |
590 |
|
|
591 |
|
// Create window |
592 |
|
XSetWindowAttributes wattr; |
593 |
|
wattr.event_mask = eventmask = dga_eventmask; |
644 |
– |
wattr.border_pixel = black_pixel; |
594 |
|
wattr.override_redirect = True; |
595 |
|
|
647 |
– |
XSync(x_display, false); |
596 |
|
the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, |
597 |
< |
InputOutput, vis, CWEventMask | CWBorderPixel | CWOverrideRedirect, &wattr); |
598 |
< |
XSync(x_display, false); |
599 |
< |
XStoreName(x_display, the_win, GetString(STR_WINDOW_TITLE)); |
597 |
> |
InputOutput, vis, CWEventMask | CWOverrideRedirect, &wattr); |
598 |
> |
|
599 |
> |
// Set window name/class |
600 |
> |
set_window_name(the_win, STR_WINDOW_TITLE); |
601 |
> |
|
602 |
> |
// Indicate that we want keyboard input |
603 |
> |
set_window_focus(the_win); |
604 |
> |
|
605 |
> |
// Show window |
606 |
|
XMapRaised(x_display, the_win); |
607 |
< |
XSync(x_display, false); |
607 |
> |
wait_mapped(the_win); |
608 |
|
|
609 |
|
// Establish direct screen connection |
610 |
|
XMoveResizeWindow(x_display, the_win, 0, 0, width, height); |
619 |
|
XF86DGASetVidPage(x_display, screen, 0); |
620 |
|
|
621 |
|
// Set colormap |
622 |
< |
if (depth == 8) { |
622 |
> |
if (!IsDirectMode(mode)) { |
623 |
|
XSetWindowColormap(x_display, the_win, cmap[current_dga_cmap = 0]); |
670 |
– |
XSetWMColormapWindows(x_display, the_win, &the_win, 1); |
624 |
|
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
625 |
|
} |
626 |
+ |
XSync(x_display, false); |
627 |
|
|
628 |
|
// Set VideoMonitor |
629 |
< |
int bytes_per_row = (v_width + 7) & ~7; |
630 |
< |
switch (depth) { |
631 |
< |
case 1: |
678 |
< |
bytes_per_row /= 8; |
679 |
< |
break; |
680 |
< |
case 15: |
681 |
< |
case 16: |
682 |
< |
bytes_per_row *= 2; |
683 |
< |
break; |
684 |
< |
case 24: |
685 |
< |
case 32: |
686 |
< |
bytes_per_row *= 4; |
687 |
< |
break; |
688 |
< |
} |
689 |
< |
|
629 |
> |
int bytes_per_row = TrivialBytesPerRow((v_width + 7) & ~7, mode.depth); |
630 |
> |
|
631 |
> |
#ifdef VIDEO_VOSF |
632 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
633 |
< |
// If the blit function is null, i.e. just a copy of the buffer, |
634 |
< |
// we first try to avoid the allocation of a temporary frame buffer |
635 |
< |
use_vosf = true; |
694 |
< |
do_update_framebuffer = GET_FBCOPY_FUNC(depth, true, DISPLAY_DGA); |
695 |
< |
if (do_update_framebuffer == FBCOPY_FUNC(fbcopy_raw)) |
696 |
< |
use_vosf = false; |
633 |
> |
// Screen_blitter_init() returns TRUE if VOSF is mandatory |
634 |
> |
// i.e. the framebuffer update function is not Blit_Copy_Raw |
635 |
> |
use_vosf = Screen_blitter_init(&visualInfo, true); |
636 |
|
|
637 |
|
if (use_vosf) { |
638 |
< |
the_host_buffer = the_buffer; |
639 |
< |
the_buffer_size = align_on_page_boundary((height + 2) * bytes_per_row); |
640 |
< |
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
641 |
< |
memset(the_buffer_copy, 0, the_buffer_size); |
642 |
< |
the_buffer = (uint8 *)allocate_framebuffer(the_buffer_size); |
704 |
< |
memset(the_buffer, 0, the_buffer_size); |
638 |
> |
// Allocate memory for frame buffer (SIZE is extended to page-boundary) |
639 |
> |
the_host_buffer = the_buffer; |
640 |
> |
the_buffer_size = page_extend((height + 2) * bytes_per_row); |
641 |
> |
the_buffer_copy = (uint8 *)vm_acquire(the_buffer_size); |
642 |
> |
the_buffer = (uint8 *)vm_acquire(the_buffer_size); |
643 |
|
} |
644 |
< |
#elif defined(ENABLE_VOSF) |
707 |
< |
// The UAE memory handlers will already handle color conversion, if needed. |
644 |
> |
#else |
645 |
|
use_vosf = false; |
646 |
|
#endif |
710 |
– |
|
711 |
– |
set_video_monitor(width, height, bytes_per_row, true); |
712 |
– |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
713 |
– |
VideoMonitor.mac_frame_base = Host2MacAddr(the_buffer); |
714 |
– |
// MacFrameLayout = FLAYOUT_DIRECT; |
715 |
– |
#else |
716 |
– |
VideoMonitor.mac_frame_base = MacFrameBaseMac; |
647 |
|
#endif |
648 |
+ |
|
649 |
+ |
const_cast<video_mode *>(&mode)->bytes_per_row = bytes_per_row; |
650 |
+ |
VideoMonitor.mode = mode; |
651 |
+ |
set_mac_frame_buffer(mode.depth, true); |
652 |
|
return true; |
653 |
|
#else |
654 |
|
ErrorAlert("Basilisk II has been compiled with XF86 DGA support disabled."); |
721 |
|
} |
722 |
|
} |
723 |
|
|
724 |
< |
bool VideoInitBuffer() |
724 |
> |
// Open display for specified mode |
725 |
> |
static bool video_open(const video_mode &mode) |
726 |
|
{ |
727 |
< |
#ifdef ENABLE_VOSF |
728 |
< |
if (use_vosf) { |
729 |
< |
const uint32 page_size = getpagesize(); |
730 |
< |
const uint32 page_mask = page_size - 1; |
731 |
< |
|
732 |
< |
mainBuffer.memBase = (uint32) the_buffer; |
733 |
< |
// Align the frame buffer on page boundary |
734 |
< |
mainBuffer.memStart = (uint32)((((unsigned long) the_buffer) + page_mask) & ~page_mask); |
800 |
< |
mainBuffer.memLength = the_buffer_size; |
801 |
< |
mainBuffer.memEnd = mainBuffer.memStart + mainBuffer.memLength; |
802 |
< |
|
803 |
< |
mainBuffer.pageSize = page_size; |
804 |
< |
mainBuffer.pageCount = (mainBuffer.memLength + page_mask)/mainBuffer.pageSize; |
805 |
< |
mainBuffer.pageBits = int( log(mainBuffer.pageSize) / log(2.0) ); |
806 |
< |
|
807 |
< |
if (mainBuffer.dirtyPages != 0) |
808 |
< |
free(mainBuffer.dirtyPages); |
727 |
> |
// Create color maps for 8 bit mode |
728 |
> |
if (!IsDirectMode(mode)) { |
729 |
> |
cmap[0] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
730 |
> |
cmap[1] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
731 |
> |
cmap_allocated = true; |
732 |
> |
XInstallColormap(x_display, cmap[0]); |
733 |
> |
XInstallColormap(x_display, cmap[1]); |
734 |
> |
} |
735 |
|
|
736 |
< |
mainBuffer.dirtyPages = (uint8 *) malloc(mainBuffer.pageCount); |
736 |
> |
// Initialize according to display type |
737 |
> |
switch (display_type) { |
738 |
> |
case DISPLAY_WINDOW: |
739 |
> |
if (!init_window(mode)) |
740 |
> |
return false; |
741 |
> |
break; |
742 |
> |
case DISPLAY_DGA: |
743 |
> |
#ifdef ENABLE_FBDEV_DGA |
744 |
> |
if (!init_fbdev_dga(mode)) |
745 |
> |
#else |
746 |
> |
if (!init_xf86_dga(mode)) |
747 |
> |
#endif |
748 |
> |
return false; |
749 |
> |
break; |
750 |
> |
} |
751 |
|
|
752 |
< |
if (mainBuffer.pageInfo != 0) |
753 |
< |
free(mainBuffer.pageInfo); |
752 |
> |
// Lock down frame buffer |
753 |
> |
LOCK_FRAME_BUFFER; |
754 |
|
|
755 |
< |
mainBuffer.pageInfo = (ScreenPageInfo *) malloc(mainBuffer.pageCount * sizeof(ScreenPageInfo)); |
755 |
> |
#if !REAL_ADDRESSING && !DIRECT_ADDRESSING |
756 |
> |
// Set variables for UAE memory mapping |
757 |
> |
MacFrameBaseHost = the_buffer; |
758 |
> |
MacFrameSize = VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y; |
759 |
|
|
760 |
< |
if ((mainBuffer.dirtyPages == 0) || (mainBuffer.pageInfo == 0)) |
761 |
< |
return false; |
760 |
> |
// No special frame buffer in Classic mode (frame buffer is in Mac RAM) |
761 |
> |
if (classic) |
762 |
> |
MacFrameLayout = FLAYOUT_NONE; |
763 |
> |
#endif |
764 |
|
|
765 |
< |
PFLAG_CLEAR_ALL; |
765 |
> |
InitFrameBufferMapping(); |
766 |
|
|
767 |
< |
uint32 a = 0; |
768 |
< |
for (int i = 0; i < mainBuffer.pageCount; i++) { |
769 |
< |
int y1 = a / VideoMonitor.bytes_per_row; |
770 |
< |
if (y1 >= VideoMonitor.y) |
771 |
< |
y1 = VideoMonitor.y - 1; |
772 |
< |
|
828 |
< |
int y2 = (a + mainBuffer.pageSize) / VideoMonitor.bytes_per_row; |
829 |
< |
if (y2 >= VideoMonitor.y) |
830 |
< |
y2 = VideoMonitor.y - 1; |
831 |
< |
|
832 |
< |
mainBuffer.pageInfo[i].top = y1; |
833 |
< |
mainBuffer.pageInfo[i].bottom = y2; |
834 |
< |
|
835 |
< |
a += mainBuffer.pageSize; |
836 |
< |
if (a > mainBuffer.memLength) |
837 |
< |
a = mainBuffer.memLength; |
767 |
> |
#ifdef ENABLE_VOSF |
768 |
> |
if (use_vosf) { |
769 |
> |
// Initialize the mainBuffer structure |
770 |
> |
if (!video_init_buffer()) { |
771 |
> |
ErrorAlert(GetString(STR_VOSF_INIT_ERR)); |
772 |
> |
return false; |
773 |
|
} |
774 |
< |
|
775 |
< |
// We can now write-protect the frame buffer |
776 |
< |
if (mprotect((caddr_t)mainBuffer.memStart, mainBuffer.memLength, PROT_READ) != 0) |
774 |
> |
|
775 |
> |
// Initialize the handler for SIGSEGV |
776 |
> |
if (!sigsegv_install_handler(screen_fault_handler)) { |
777 |
> |
ErrorAlert("Could not initialize Video on SEGV signals"); |
778 |
|
return false; |
779 |
+ |
} |
780 |
|
} |
781 |
|
#endif |
782 |
+ |
|
783 |
+ |
// Initialize VideoRefresh function |
784 |
+ |
VideoRefreshInit(); |
785 |
+ |
|
786 |
+ |
XSync(x_display, false); |
787 |
+ |
|
788 |
+ |
#ifdef HAVE_PTHREADS |
789 |
+ |
// Start redraw/input thread |
790 |
+ |
redraw_thread_cancel = false; |
791 |
+ |
redraw_thread_active = (pthread_create(&redraw_thread, NULL, redraw_func, NULL) == 0); |
792 |
+ |
if (!redraw_thread_active) { |
793 |
+ |
printf("FATAL: cannot create redraw thread\n"); |
794 |
+ |
return false; |
795 |
+ |
} |
796 |
+ |
#endif |
797 |
+ |
|
798 |
|
return true; |
799 |
|
} |
800 |
|
|
801 |
|
bool VideoInit(bool classic) |
802 |
|
{ |
803 |
+ |
classic_mode = classic; |
804 |
+ |
|
805 |
|
#ifdef ENABLE_VOSF |
851 |
– |
// Open /dev/zero |
852 |
– |
zero_fd = open("/dev/zero", O_RDWR); |
853 |
– |
if (zero_fd < 0) { |
854 |
– |
char str[256]; |
855 |
– |
sprintf(str, GetString(STR_NO_DEV_ZERO_ERR), strerror(errno)); |
856 |
– |
ErrorAlert(str); |
857 |
– |
return false; |
858 |
– |
} |
859 |
– |
|
806 |
|
// Zero the mainBuffer structure |
807 |
|
mainBuffer.dirtyPages = 0; |
808 |
|
mainBuffer.pageInfo = 0; |
816 |
|
keycode_init(); |
817 |
|
|
818 |
|
// Read prefs |
819 |
< |
mouse_wheel_mode = PrefsFindInt16("mousewheelmode"); |
820 |
< |
mouse_wheel_lines = PrefsFindInt16("mousewheellines"); |
819 |
> |
mouse_wheel_mode = PrefsFindInt32("mousewheelmode"); |
820 |
> |
mouse_wheel_lines = PrefsFindInt32("mousewheellines"); |
821 |
|
|
822 |
|
// Find screen and root window |
823 |
|
screen = XDefaultScreen(x_display); |
893 |
|
} |
894 |
|
vis = visualInfo.visual; |
895 |
|
|
950 |
– |
// Mac screen depth is always 1 bit in Classic mode, but follows X depth otherwise |
951 |
– |
classic_mode = classic; |
952 |
– |
if (classic) |
953 |
– |
depth = 1; |
954 |
– |
else |
955 |
– |
depth = xdepth; |
956 |
– |
|
957 |
– |
// Create color maps for 8 bit mode |
958 |
– |
if (depth == 8) { |
959 |
– |
cmap[0] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
960 |
– |
cmap[1] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
961 |
– |
XInstallColormap(x_display, cmap[0]); |
962 |
– |
XInstallColormap(x_display, cmap[1]); |
963 |
– |
} |
964 |
– |
|
896 |
|
// Get screen mode from preferences |
897 |
|
const char *mode_str; |
898 |
< |
if (classic) |
898 |
> |
if (classic_mode) |
899 |
|
mode_str = "win/512/342"; |
900 |
|
else |
901 |
|
mode_str = PrefsFindString("screen"); |
902 |
|
|
903 |
< |
// Determine type and mode |
904 |
< |
int width = 512, height = 384; |
903 |
> |
// Determine display type and default dimensions |
904 |
> |
int default_width = 512, default_height = 384; |
905 |
|
display_type = DISPLAY_WINDOW; |
906 |
|
if (mode_str) { |
907 |
< |
if (sscanf(mode_str, "win/%d/%d", &width, &height) == 2) |
907 |
> |
if (sscanf(mode_str, "win/%d/%d", &default_width, &default_height) == 2) { |
908 |
|
display_type = DISPLAY_WINDOW; |
909 |
|
#ifdef ENABLE_FBDEV_DGA |
910 |
< |
else if (has_dga && sscanf(mode_str, "dga/%19s", fb_name) == 1) { |
980 |
< |
#else |
981 |
< |
else if (has_dga && sscanf(mode_str, "dga/%d/%d", &width, &height) == 2) { |
982 |
< |
#endif |
910 |
> |
} else if (has_dga && sscanf(mode_str, "dga/%19s", fb_name) == 1) { |
911 |
|
display_type = DISPLAY_DGA; |
912 |
< |
if (width > DisplayWidth(x_display, screen)) |
985 |
< |
width = DisplayWidth(x_display, screen); |
986 |
< |
if (height > DisplayHeight(x_display, screen)) |
987 |
< |
height = DisplayHeight(x_display, screen); |
988 |
< |
} |
989 |
< |
if (width <= 0) |
990 |
< |
width = DisplayWidth(x_display, screen); |
991 |
< |
if (height <= 0) |
992 |
< |
height = DisplayHeight(x_display, screen); |
993 |
< |
} |
994 |
< |
|
995 |
< |
// Initialize according to display type |
996 |
< |
switch (display_type) { |
997 |
< |
case DISPLAY_WINDOW: |
998 |
< |
if (!init_window(width, height)) |
999 |
< |
return false; |
1000 |
< |
break; |
1001 |
< |
case DISPLAY_DGA: |
1002 |
< |
#ifdef ENABLE_FBDEV_DGA |
1003 |
< |
if (!init_fbdev_dga(fb_name)) |
912 |
> |
default_width = -1; default_height = -1; |
913 |
|
#else |
914 |
< |
if (!init_xf86_dga(width, height)) |
914 |
> |
} else if (has_dga && sscanf(mode_str, "dga/%d/%d", &default_width, &default_height) == 2) { |
915 |
> |
display_type = DISPLAY_DGA; |
916 |
|
#endif |
917 |
< |
return false; |
1008 |
< |
break; |
917 |
> |
} |
918 |
|
} |
919 |
+ |
if (default_width <= 0) |
920 |
+ |
default_width = DisplayWidth(x_display, screen); |
921 |
+ |
else if (default_width > DisplayWidth(x_display, screen)) |
922 |
+ |
default_width = DisplayWidth(x_display, screen); |
923 |
+ |
if (default_height <= 0) |
924 |
+ |
default_height = DisplayHeight(x_display, screen); |
925 |
+ |
else if (default_height > DisplayHeight(x_display, screen)) |
926 |
+ |
default_height = DisplayHeight(x_display, screen); |
927 |
|
|
928 |
< |
#ifdef HAVE_PTHREADS |
929 |
< |
// Lock down frame buffer |
930 |
< |
pthread_mutex_lock(&frame_buffer_lock); |
1014 |
< |
#endif |
1015 |
< |
|
1016 |
< |
#if !REAL_ADDRESSING && !DIRECT_ADDRESSING |
1017 |
< |
// Set variables for UAE memory mapping |
1018 |
< |
MacFrameBaseHost = the_buffer; |
1019 |
< |
MacFrameSize = VideoMonitor.bytes_per_row * VideoMonitor.y; |
1020 |
< |
|
1021 |
< |
// No special frame buffer in Classic mode (frame buffer is in Mac RAM) |
1022 |
< |
if (classic) |
1023 |
< |
MacFrameLayout = FLAYOUT_NONE; |
1024 |
< |
#endif |
928 |
> |
// Mac screen depth is always 1 bit in Classic mode, but follows X depth otherwise |
929 |
> |
int depth = (classic_mode ? 1 : xdepth); |
930 |
> |
video_depth depth_mode = DepthModeForPixelDepth(depth); |
931 |
|
|
932 |
< |
#ifdef ENABLE_VOSF |
933 |
< |
if (use_vosf) { |
934 |
< |
// Initialize the mainBuffer structure |
935 |
< |
if (!VideoInitBuffer()) { |
936 |
< |
// TODO: STR_VOSF_INIT_ERR ? |
937 |
< |
ErrorAlert("Could not initialize Video on SEGV signals"); |
938 |
< |
return false; |
932 |
> |
// Construct list of supported modes |
933 |
> |
if (display_type == DISPLAY_WINDOW) { |
934 |
> |
if (classic) |
935 |
> |
add_mode(512, 342, 0x80, 64, depth_mode); |
936 |
> |
else { |
937 |
> |
add_mode(512, 384, 0x80, TrivialBytesPerRow(512, depth_mode), depth_mode); |
938 |
> |
add_mode(640, 480, 0x81, TrivialBytesPerRow(640, depth_mode), depth_mode); |
939 |
> |
add_mode(800, 600, 0x82, TrivialBytesPerRow(800, depth_mode), depth_mode); |
940 |
> |
add_mode(1024, 768, 0x83, TrivialBytesPerRow(1024, depth_mode), depth_mode); |
941 |
> |
add_mode(1280, 1024, 0x84, TrivialBytesPerRow(1280, depth_mode), depth_mode); |
942 |
|
} |
943 |
+ |
} else |
944 |
+ |
add_mode(default_width, default_height, 0x80, TrivialBytesPerRow(default_width, depth_mode), depth_mode); |
945 |
|
|
946 |
< |
// Initialize the handler for SIGSEGV |
947 |
< |
if (!Screen_fault_handler_init()) { |
948 |
< |
// TODO: STR_VOSF_INIT_ERR ? |
949 |
< |
ErrorAlert("Could not initialize Video on SEGV signals"); |
950 |
< |
return false; |
946 |
> |
// Find requested default mode and open display |
947 |
> |
if (VideoModes.size() == 1) |
948 |
> |
return video_open(VideoModes[0]); |
949 |
> |
else { |
950 |
> |
// Find mode with specified dimensions |
951 |
> |
std::vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end(); |
952 |
> |
while (i != end) { |
953 |
> |
if (i->x == default_width && i->y == default_height) |
954 |
> |
return video_open(*i); |
955 |
> |
++i; |
956 |
|
} |
957 |
+ |
return video_open(VideoModes[0]); |
958 |
|
} |
1042 |
– |
#endif |
1043 |
– |
|
1044 |
– |
// Initialize VideoRefresh function |
1045 |
– |
VideoRefreshInit(); |
1046 |
– |
|
1047 |
– |
XSync(x_display, false); |
1048 |
– |
|
1049 |
– |
#ifdef HAVE_PTHREADS |
1050 |
– |
// Start redraw/input thread |
1051 |
– |
redraw_thread_active = (pthread_create(&redraw_thread, NULL, redraw_func, NULL) == 0); |
1052 |
– |
if (!redraw_thread_active) { |
1053 |
– |
printf("FATAL: cannot create redraw thread\n"); |
1054 |
– |
return false; |
1055 |
– |
} |
1056 |
– |
#endif |
1057 |
– |
return true; |
959 |
|
} |
960 |
|
|
961 |
|
|
963 |
|
* Deinitialization |
964 |
|
*/ |
965 |
|
|
966 |
< |
void VideoExit(void) |
966 |
> |
// Close display |
967 |
> |
static void video_close(void) |
968 |
|
{ |
969 |
|
#ifdef HAVE_PTHREADS |
970 |
|
// Stop redraw thread |
978 |
|
} |
979 |
|
#endif |
980 |
|
|
1079 |
– |
#ifdef HAVE_PTHREADS |
981 |
|
// Unlock frame buffer |
982 |
< |
pthread_mutex_unlock(&frame_buffer_lock); |
1082 |
< |
#endif |
982 |
> |
UNLOCK_FRAME_BUFFER; |
983 |
|
|
984 |
|
// Close window and server connection |
985 |
|
if (x_display != NULL) { |
1008 |
|
|
1009 |
|
XFlush(x_display); |
1010 |
|
XSync(x_display, false); |
1011 |
< |
if (depth == 8) { |
1011 |
> |
XUnmapWindow(x_display, the_win); |
1012 |
> |
wait_unmapped(the_win); |
1013 |
> |
XDestroyWindow(x_display, the_win); |
1014 |
> |
|
1015 |
> |
if (have_shm) { |
1016 |
> |
XDestroyImage(img); |
1017 |
> |
XShmDetach(x_display, &shminfo); |
1018 |
> |
have_shm = false; |
1019 |
> |
} else { |
1020 |
> |
//!! free img |
1021 |
> |
} |
1022 |
> |
//!! free the_gc |
1023 |
> |
|
1024 |
> |
if (cmap_allocated) { |
1025 |
|
XFreeColormap(x_display, cmap[0]); |
1026 |
|
XFreeColormap(x_display, cmap[1]); |
1027 |
+ |
cmap_allocated = false; |
1028 |
|
} |
1029 |
|
|
1030 |
|
if (!use_vosf) { |
1040 |
|
} |
1041 |
|
#ifdef ENABLE_VOSF |
1042 |
|
else { |
1043 |
< |
if (the_buffer != (uint8 *)MAP_FAILED) { |
1044 |
< |
munmap((caddr_t)the_buffer, the_buffer_size); |
1043 |
> |
//!! uninstall SEGV handler? |
1044 |
> |
|
1045 |
> |
if (the_buffer != (uint8 *)VM_MAP_FAILED) { |
1046 |
> |
vm_release(the_buffer, the_buffer_size); |
1047 |
|
the_buffer = 0; |
1048 |
|
} |
1049 |
|
|
1050 |
< |
if (the_buffer_copy != (uint8 *)MAP_FAILED) { |
1051 |
< |
munmap((caddr_t)the_buffer_copy, the_buffer_size); |
1050 |
> |
if (the_buffer_copy != (uint8 *)VM_MAP_FAILED) { |
1051 |
> |
vm_release(the_buffer_copy, the_buffer_size); |
1052 |
|
the_buffer_copy = 0; |
1053 |
|
} |
1054 |
|
} |
1068 |
|
mainBuffer.dirtyPages = 0; |
1069 |
|
} |
1070 |
|
} |
1155 |
– |
|
1156 |
– |
// Close /dev/zero |
1157 |
– |
if (zero_fd > 0) |
1158 |
– |
close(zero_fd); |
1071 |
|
#endif |
1072 |
|
} |
1073 |
|
|
1074 |
+ |
void VideoExit(void) |
1075 |
+ |
{ |
1076 |
+ |
video_close(); |
1077 |
+ |
} |
1078 |
+ |
|
1079 |
|
|
1080 |
|
/* |
1081 |
|
* Close down full-screen mode (if bringing up error alerts is unsafe while in full-screen mode) |
1099 |
|
if (emerg_quit) |
1100 |
|
QuitEmulator(); |
1101 |
|
|
1185 |
– |
#ifdef HAVE_PTHREADS |
1102 |
|
// Temporarily give up frame buffer lock (this is the point where |
1103 |
|
// we are suspended when the user presses Ctrl-Tab) |
1104 |
< |
pthread_mutex_unlock(&frame_buffer_lock); |
1105 |
< |
pthread_mutex_lock(&frame_buffer_lock); |
1190 |
< |
#endif |
1104 |
> |
UNLOCK_FRAME_BUFFER; |
1105 |
> |
LOCK_FRAME_BUFFER; |
1106 |
|
} |
1107 |
|
|
1108 |
|
|
1112 |
|
|
1113 |
|
void video_set_palette(uint8 *pal) |
1114 |
|
{ |
1115 |
< |
#ifdef HAVE_PTHREDS |
1201 |
< |
pthread_mutex_lock(&palette_lock); |
1202 |
< |
#endif |
1115 |
> |
LOCK_PALETTE; |
1116 |
|
|
1117 |
|
// Convert colors to XColor array |
1118 |
|
for (int i=0; i<256; i++) { |
1126 |
|
// Tell redraw thread to change palette |
1127 |
|
palette_changed = true; |
1128 |
|
|
1129 |
< |
#ifdef HAVE_PTHREADS |
1130 |
< |
pthread_mutex_unlock(&palette_lock); |
1131 |
< |
#endif |
1129 |
> |
UNLOCK_PALETTE; |
1130 |
> |
} |
1131 |
> |
|
1132 |
> |
|
1133 |
> |
/* |
1134 |
> |
* Switch video mode |
1135 |
> |
*/ |
1136 |
> |
|
1137 |
> |
void video_switch_to_mode(const video_mode &mode) |
1138 |
> |
{ |
1139 |
> |
video_close(); |
1140 |
> |
video_open(mode); |
1141 |
|
} |
1142 |
|
|
1143 |
|
|
1153 |
|
ADBKeyUp(0x36); |
1154 |
|
ctrl_down = false; |
1155 |
|
|
1234 |
– |
#ifdef HAVE_PTHREADS |
1156 |
|
// Lock frame buffer (this will stop the MacOS thread) |
1157 |
< |
pthread_mutex_lock(&frame_buffer_lock); |
1237 |
< |
#endif |
1157 |
> |
LOCK_FRAME_BUFFER; |
1158 |
|
|
1159 |
|
// Save frame buffer |
1160 |
< |
fb_save = malloc(VideoMonitor.y * VideoMonitor.bytes_per_row); |
1160 |
> |
fb_save = malloc(VideoMonitor.mode.y * VideoMonitor.mode.bytes_per_row); |
1161 |
|
if (fb_save) |
1162 |
< |
memcpy(fb_save, the_buffer, VideoMonitor.y * VideoMonitor.bytes_per_row); |
1162 |
> |
memcpy(fb_save, the_buffer, VideoMonitor.mode.y * VideoMonitor.mode.bytes_per_row); |
1163 |
|
|
1164 |
|
// Close full screen display |
1165 |
|
#ifdef ENABLE_XF86_DGA |
1168 |
|
XUngrabPointer(x_display, CurrentTime); |
1169 |
|
XUngrabKeyboard(x_display, CurrentTime); |
1170 |
|
XUnmapWindow(x_display, the_win); |
1171 |
< |
XSync(x_display, false); |
1171 |
> |
wait_unmapped(the_win); |
1172 |
|
|
1173 |
|
// Open "suspend" window |
1174 |
|
XSetWindowAttributes wattr; |
1175 |
|
wattr.event_mask = KeyPressMask; |
1176 |
|
wattr.background_pixel = black_pixel; |
1257 |
– |
wattr.border_pixel = black_pixel; |
1258 |
– |
wattr.backing_store = Always; |
1259 |
– |
wattr.backing_planes = xdepth; |
1260 |
– |
wattr.colormap = DefaultColormap(x_display, screen); |
1177 |
|
|
1262 |
– |
XSync(x_display, false); |
1178 |
|
suspend_win = XCreateWindow(x_display, rootwin, 0, 0, 512, 1, 0, xdepth, |
1179 |
< |
InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel | |
1180 |
< |
CWBackingStore | CWBackingPlanes | (xdepth == 8 ? CWColormap : 0), &wattr); |
1181 |
< |
XSync(x_display, false); |
1182 |
< |
XStoreName(x_display, suspend_win, GetString(STR_SUSPEND_WINDOW_TITLE)); |
1268 |
< |
XMapRaised(x_display, suspend_win); |
1269 |
< |
XSync(x_display, false); |
1179 |
> |
InputOutput, vis, CWEventMask | CWBackPixel, &wattr); |
1180 |
> |
set_window_name(suspend_win, STR_SUSPEND_WINDOW_TITLE); |
1181 |
> |
set_window_focus(suspend_win); |
1182 |
> |
XMapWindow(x_display, suspend_win); |
1183 |
|
emul_suspended = true; |
1184 |
|
} |
1185 |
|
} |
1192 |
|
|
1193 |
|
// Reopen full screen display |
1194 |
|
XMapRaised(x_display, the_win); |
1195 |
+ |
wait_mapped(the_win); |
1196 |
|
XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0); |
1283 |
– |
XSync(x_display, false); |
1197 |
|
XGrabKeyboard(x_display, rootwin, 1, GrabModeAsync, GrabModeAsync, CurrentTime); |
1198 |
|
XGrabPointer(x_display, rootwin, 1, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); |
1199 |
|
#ifdef ENABLE_XF86_DGA |
1207 |
|
// not necessary. |
1208 |
|
#ifdef ENABLE_VOSF |
1209 |
|
if (use_vosf) { |
1210 |
< |
#ifdef HAVE_PTHREADS |
1298 |
< |
pthread_mutex_lock(&Screen_draw_lock); |
1299 |
< |
#endif |
1210 |
> |
LOCK_VOSF; |
1211 |
|
PFLAG_SET_ALL; |
1212 |
< |
#ifdef HAVE_PTHREADS |
1213 |
< |
pthread_mutex_unlock(&Screen_draw_lock); |
1303 |
< |
#endif |
1304 |
< |
memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y); |
1212 |
> |
UNLOCK_VOSF; |
1213 |
> |
memset(the_buffer_copy, 0, VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y); |
1214 |
|
} |
1215 |
|
#endif |
1216 |
|
|
1220 |
|
// Don't copy fb_save to the temporary frame buffer in VOSF mode |
1221 |
|
if (!use_vosf) |
1222 |
|
#endif |
1223 |
< |
memcpy(the_buffer, fb_save, VideoMonitor.y * VideoMonitor.bytes_per_row); |
1223 |
> |
memcpy(the_buffer, fb_save, VideoMonitor.mode.y * VideoMonitor.mode.bytes_per_row); |
1224 |
|
free(fb_save); |
1225 |
|
fb_save = NULL; |
1226 |
|
} |
1227 |
|
|
1228 |
|
#ifdef ENABLE_XF86_DGA |
1229 |
< |
if (depth == 8) |
1229 |
> |
if (!IsDirectMode(VideoMonitor.mode)) |
1230 |
|
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
1231 |
|
#endif |
1232 |
|
|
1324 |
– |
#ifdef HAVE_PTHREADS |
1233 |
|
// Unlock frame buffer (and continue MacOS thread) |
1234 |
< |
pthread_mutex_unlock(&frame_buffer_lock); |
1234 |
> |
UNLOCK_FRAME_BUFFER; |
1235 |
|
emul_suspended = false; |
1328 |
– |
#endif |
1236 |
|
} |
1237 |
|
#endif |
1238 |
|
|
1386 |
|
return -1; |
1387 |
|
} |
1388 |
|
|
1389 |
< |
static int event2keycode(XKeyEvent *ev) |
1389 |
> |
static int event2keycode(XKeyEvent &ev) |
1390 |
|
{ |
1391 |
|
KeySym ks; |
1392 |
|
int as; |
1393 |
|
int i = 0; |
1394 |
|
|
1395 |
|
do { |
1396 |
< |
ks = XLookupKeysym(ev, i++); |
1396 |
> |
ks = XLookupKeysym(&ev, i++); |
1397 |
|
as = kc_decode(ks); |
1398 |
|
if (as != -1) |
1399 |
|
return as; |
1409 |
|
|
1410 |
|
static void handle_events(void) |
1411 |
|
{ |
1412 |
< |
XEvent event; |
1413 |
< |
for (;;) { |
1414 |
< |
if (!XCheckMaskEvent(x_display, eventmask, &event)) |
1508 |
< |
break; |
1412 |
> |
while (XPending(x_display)) { |
1413 |
> |
XEvent event; |
1414 |
> |
XNextEvent(x_display, &event); |
1415 |
|
|
1416 |
|
switch (event.type) { |
1417 |
|
// Mouse button |
1418 |
|
case ButtonPress: { |
1419 |
< |
unsigned int button = ((XButtonEvent *)&event)->button; |
1419 |
> |
unsigned int button = event.xbutton.button; |
1420 |
|
if (button < 4) |
1421 |
|
ADBMouseDown(button - 1); |
1422 |
|
else if (button < 6) { // Wheel mouse |
1435 |
|
break; |
1436 |
|
} |
1437 |
|
case ButtonRelease: { |
1438 |
< |
unsigned int button = ((XButtonEvent *)&event)->button; |
1438 |
> |
unsigned int button = event.xbutton.button; |
1439 |
|
if (button < 4) |
1440 |
|
ADBMouseUp(button - 1); |
1441 |
|
break; |
1443 |
|
|
1444 |
|
// Mouse moved |
1445 |
|
case EnterNotify: |
1540 |
– |
ADBMouseMoved(((XMotionEvent *)&event)->x, ((XMotionEvent *)&event)->y); |
1541 |
– |
break; |
1446 |
|
case MotionNotify: |
1447 |
< |
ADBMouseMoved(((XMotionEvent *)&event)->x, ((XMotionEvent *)&event)->y); |
1447 |
> |
ADBMouseMoved(event.xmotion.x, event.xmotion.y); |
1448 |
|
break; |
1449 |
|
|
1450 |
|
// Keyboard |
1451 |
|
case KeyPress: { |
1452 |
|
int code; |
1453 |
|
if (use_keycodes) { |
1454 |
< |
event2keycode((XKeyEvent *)&event); // This is called to process the hotkeys |
1455 |
< |
code = keycode_table[((XKeyEvent *)&event)->keycode & 0xff]; |
1454 |
> |
event2keycode(event.xkey); // This is called to process the hotkeys |
1455 |
> |
code = keycode_table[event.xkey.keycode & 0xff]; |
1456 |
|
} else |
1457 |
< |
code = event2keycode((XKeyEvent *)&event); |
1457 |
> |
code = event2keycode(event.xkey); |
1458 |
|
if (code != -1) { |
1459 |
|
if (!emul_suspended) { |
1460 |
|
if (code == 0x39) { // Caps Lock pressed |
1481 |
|
case KeyRelease: { |
1482 |
|
int code; |
1483 |
|
if (use_keycodes) { |
1484 |
< |
event2keycode((XKeyEvent *)&event); // This is called to process the hotkeys |
1485 |
< |
code = keycode_table[((XKeyEvent *)&event)->keycode & 0xff]; |
1484 |
> |
event2keycode(event.xkey); // This is called to process the hotkeys |
1485 |
> |
code = keycode_table[event.xkey.keycode & 0xff]; |
1486 |
|
} else |
1487 |
< |
code = event2keycode((XKeyEvent *)&event); |
1487 |
> |
code = event2keycode(event.xkey); |
1488 |
|
if (code != -1 && code != 0x39) { // Don't propagate Caps Lock releases |
1489 |
|
ADBKeyUp(code); |
1490 |
|
if (code == 0x36) |
1498 |
|
if (display_type == DISPLAY_WINDOW) { |
1499 |
|
#ifdef ENABLE_VOSF |
1500 |
|
if (use_vosf) { // VOSF refresh |
1501 |
< |
#ifdef HAVE_PTHREADS |
1598 |
< |
pthread_mutex_lock(&Screen_draw_lock); |
1599 |
< |
#endif |
1501 |
> |
LOCK_VOSF; |
1502 |
|
PFLAG_SET_ALL; |
1503 |
< |
#ifdef HAVE_PTHREADS |
1504 |
< |
pthread_mutex_unlock(&Screen_draw_lock); |
1603 |
< |
#endif |
1604 |
< |
memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y); |
1503 |
> |
UNLOCK_VOSF; |
1504 |
> |
memset(the_buffer_copy, 0, VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y); |
1505 |
|
} |
1506 |
|
else |
1507 |
|
#endif |
1512 |
|
updt_box[x1][y1] = true; |
1513 |
|
nr_boxes = 16 * 16; |
1514 |
|
} else // Static refresh |
1515 |
< |
memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y); |
1515 |
> |
memset(the_buffer_copy, 0, VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y); |
1516 |
> |
} |
1517 |
> |
break; |
1518 |
> |
|
1519 |
> |
// Window "close" widget clicked |
1520 |
> |
case ClientMessage: |
1521 |
> |
if (event.xclient.format == 32 && event.xclient.data.l[0] == WM_DELETE_WINDOW) { |
1522 |
> |
ADBKeyDown(0x7f); // Power key |
1523 |
> |
ADBKeyUp(0x7f); |
1524 |
|
} |
1525 |
|
break; |
1526 |
|
} |
1538 |
|
int y1, y2, y2s, y2a, i, x1, xm, xmo, ymo, yo, yi, yil, xi; |
1539 |
|
int xil = 0; |
1540 |
|
int rxm = 0, rxmo = 0; |
1541 |
< |
int bytes_per_row = VideoMonitor.bytes_per_row; |
1542 |
< |
int bytes_per_pixel = VideoMonitor.bytes_per_row / VideoMonitor.x; |
1543 |
< |
int rx = VideoMonitor.bytes_per_row / 16; |
1544 |
< |
int ry = VideoMonitor.y / 16; |
1541 |
> |
int bytes_per_row = VideoMonitor.mode.bytes_per_row; |
1542 |
> |
int bytes_per_pixel = VideoMonitor.mode.bytes_per_row / VideoMonitor.mode.x; |
1543 |
> |
int rx = VideoMonitor.mode.bytes_per_row / 16; |
1544 |
> |
int ry = VideoMonitor.mode.y / 16; |
1545 |
|
int max_box; |
1546 |
|
|
1547 |
|
y2s = sm_uptd[ticker % 8]; |
1595 |
|
i = (yi * bytes_per_row) + xi; |
1596 |
|
for (y2=0; y2 < yil; y2++, i += bytes_per_row) |
1597 |
|
memcpy(&the_buffer_copy[i], &the_buffer[i], xil); |
1598 |
< |
if (depth == 1) { |
1598 |
> |
if (VideoMonitor.mode.depth == VDEPTH_1BIT) { |
1599 |
|
if (have_shm) |
1600 |
|
XShmPutImage(x_display, the_win, the_gc, img, xi * 8, yi, xi * 8, yi, xil * 8, yil, 0); |
1601 |
|
else |
1627 |
|
{ |
1628 |
|
// Incremental update code |
1629 |
|
int wide = 0, high = 0, x1, x2, y1, y2, i, j; |
1630 |
< |
int bytes_per_row = VideoMonitor.bytes_per_row; |
1631 |
< |
int bytes_per_pixel = VideoMonitor.bytes_per_row / VideoMonitor.x; |
1630 |
> |
int bytes_per_row = VideoMonitor.mode.bytes_per_row; |
1631 |
> |
int bytes_per_pixel = VideoMonitor.mode.bytes_per_row / VideoMonitor.mode.x; |
1632 |
|
uint8 *p, *p2; |
1633 |
|
|
1634 |
|
// Check for first line from top and first line from bottom that have changed |
1635 |
|
y1 = 0; |
1636 |
< |
for (j=0; j<VideoMonitor.y; j++) { |
1636 |
> |
for (j=0; j<VideoMonitor.mode.y; j++) { |
1637 |
|
if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) { |
1638 |
|
y1 = j; |
1639 |
|
break; |
1640 |
|
} |
1641 |
|
} |
1642 |
|
y2 = y1 - 1; |
1643 |
< |
for (j=VideoMonitor.y-1; j>=y1; j--) { |
1643 |
> |
for (j=VideoMonitor.mode.y-1; j>=y1; j--) { |
1644 |
|
if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) { |
1645 |
|
y2 = j; |
1646 |
|
break; |
1650 |
|
|
1651 |
|
// Check for first column from left and first column from right that have changed |
1652 |
|
if (high) { |
1653 |
< |
if (depth == 1) { |
1654 |
< |
x1 = VideoMonitor.x; |
1653 |
> |
if (VideoMonitor.mode.depth == VDEPTH_1BIT) { |
1654 |
> |
x1 = VideoMonitor.mode.x - 1; |
1655 |
|
for (j=y1; j<=y2; j++) { |
1656 |
|
p = &the_buffer[j * bytes_per_row]; |
1657 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1669 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1670 |
|
p += bytes_per_row; |
1671 |
|
p2 += bytes_per_row; |
1672 |
< |
for (i=(VideoMonitor.x>>3); i>(x2>>3); i--) { |
1672 |
> |
for (i=(VideoMonitor.mode.x>>3); i>(x2>>3); i--) { |
1673 |
|
p--; p2--; |
1674 |
|
if (*p != *p2) { |
1675 |
< |
x2 = i << 3; |
1675 |
> |
x2 = (i << 3) + 7; |
1676 |
|
break; |
1677 |
|
} |
1678 |
|
} |
1679 |
|
} |
1680 |
< |
wide = x2 - x1; |
1680 |
> |
wide = x2 - x1 + 1; |
1681 |
|
|
1682 |
|
// Update copy of the_buffer |
1683 |
|
if (high && wide) { |
1688 |
|
} |
1689 |
|
|
1690 |
|
} else { |
1691 |
< |
x1 = VideoMonitor.x; |
1691 |
> |
x1 = VideoMonitor.mode.x; |
1692 |
|
for (j=y1; j<=y2; j++) { |
1693 |
|
p = &the_buffer[j * bytes_per_row]; |
1694 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1706 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1707 |
|
p += bytes_per_row; |
1708 |
|
p2 += bytes_per_row; |
1709 |
< |
for (i=VideoMonitor.x*bytes_per_pixel; i>x2*bytes_per_pixel; i--) { |
1709 |
> |
for (i=VideoMonitor.mode.x*bytes_per_pixel; i>x2*bytes_per_pixel; i--) { |
1710 |
|
p--; |
1711 |
|
p2--; |
1712 |
|
if (*p != *p2) { |
1741 |
|
* Screen refresh functions |
1742 |
|
*/ |
1743 |
|
|
1744 |
< |
// The specialisations hereunder are meant to enable VOSF with DGA in direct |
1745 |
< |
// addressing mode in case the address spaces (RAM, ROM, FrameBuffer) could |
1746 |
< |
// not get mapped correctly with respect to the predetermined host frame |
1747 |
< |
// buffer base address. |
1748 |
< |
// |
1841 |
< |
// Hmm, in other words, when in direct addressing mode and DGA is requested, |
1842 |
< |
// we first try to "triple allocate" the address spaces according to the real |
1843 |
< |
// host frame buffer address. Then, if it fails, we will use a temporary |
1844 |
< |
// frame buffer thus making the real host frame buffer updated when pages |
1845 |
< |
// of the temp frame buffer are altered. |
1846 |
< |
// |
1847 |
< |
// As a side effect, a little speed gain in screen updates could be noticed |
1848 |
< |
// for other modes than DGA. |
1849 |
< |
// |
1850 |
< |
// The following two functions below are inline so that a clever compiler |
1851 |
< |
// could specialise the code according to the current screen depth and |
1852 |
< |
// display type. A more clever compiler would the job by itself though... |
1853 |
< |
// (update_display_vosf is inlined as well) |
1744 |
> |
// We suggest the compiler to inline the next two functions so that it |
1745 |
> |
// may specialise the code according to the current screen depth and |
1746 |
> |
// display type. A clever compiler would do that job by itself though... |
1747 |
> |
|
1748 |
> |
// NOTE: update_display_vosf is inlined too |
1749 |
|
|
1750 |
|
static inline void possibly_quit_dga_mode() |
1751 |
|
{ |
1759 |
|
XUngrabPointer(x_display, CurrentTime); |
1760 |
|
XUngrabKeyboard(x_display, CurrentTime); |
1761 |
|
XUnmapWindow(x_display, the_win); |
1762 |
< |
XSync(x_display, false); |
1762 |
> |
wait_unmapped(the_win); |
1763 |
|
} |
1764 |
|
#endif |
1765 |
|
} |
1766 |
|
|
1767 |
< |
static inline void handle_palette_changes(int depth, int display_type) |
1767 |
> |
static inline void handle_palette_changes(int display_type) |
1768 |
|
{ |
1769 |
< |
#ifdef HAVE_PTHREADS |
1770 |
< |
pthread_mutex_lock(&palette_lock); |
1876 |
< |
#endif |
1769 |
> |
LOCK_PALETTE; |
1770 |
> |
|
1771 |
|
if (palette_changed) { |
1772 |
|
palette_changed = false; |
1773 |
< |
if (depth == 8) { |
1773 |
> |
if (!IsDirectMode(VideoMonitor.mode)) { |
1774 |
|
XStoreColors(x_display, cmap[0], palette, 256); |
1775 |
|
XStoreColors(x_display, cmap[1], palette, 256); |
1776 |
+ |
XSync(x_display, false); |
1777 |
|
|
1778 |
|
#ifdef ENABLE_XF86_DGA |
1779 |
|
if (display_type == DISPLAY_DGA) { |
1783 |
|
#endif |
1784 |
|
} |
1785 |
|
} |
1786 |
< |
#ifdef HAVE_PTHREADS |
1787 |
< |
pthread_mutex_unlock(&palette_lock); |
1893 |
< |
#endif |
1786 |
> |
|
1787 |
> |
UNLOCK_PALETTE; |
1788 |
|
} |
1789 |
|
|
1790 |
|
static void video_refresh_dga(void) |
1796 |
|
handle_events(); |
1797 |
|
|
1798 |
|
// Handle palette changes |
1799 |
< |
handle_palette_changes(depth, DISPLAY_DGA); |
1799 |
> |
handle_palette_changes(DISPLAY_DGA); |
1800 |
|
} |
1801 |
|
|
1802 |
+ |
#ifdef ENABLE_VOSF |
1803 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
1804 |
|
static void video_refresh_dga_vosf(void) |
1805 |
|
{ |
1810 |
|
handle_events(); |
1811 |
|
|
1812 |
|
// Handle palette changes |
1813 |
< |
handle_palette_changes(depth, DISPLAY_DGA); |
1813 |
> |
handle_palette_changes(DISPLAY_DGA); |
1814 |
|
|
1815 |
|
// Update display (VOSF variant) |
1816 |
|
static int tick_counter = 0; |
1817 |
|
if (++tick_counter >= frame_skip) { |
1818 |
|
tick_counter = 0; |
1819 |
< |
#ifdef HAVE_PTHREADS |
1820 |
< |
pthread_mutex_lock(&Screen_draw_lock); |
1821 |
< |
#endif |
1822 |
< |
update_display_dga_vosf(); |
1823 |
< |
#ifdef HAVE_PTHREADS |
1929 |
< |
pthread_mutex_unlock(&Screen_draw_lock); |
1930 |
< |
#endif |
1819 |
> |
if (mainBuffer.dirty) { |
1820 |
> |
LOCK_VOSF; |
1821 |
> |
update_display_dga_vosf(); |
1822 |
> |
UNLOCK_VOSF; |
1823 |
> |
} |
1824 |
|
} |
1825 |
|
} |
1826 |
|
#endif |
1827 |
|
|
1935 |
– |
#ifdef ENABLE_VOSF |
1828 |
|
static void video_refresh_window_vosf(void) |
1829 |
|
{ |
1830 |
|
// Quit DGA mode if requested |
1834 |
|
handle_events(); |
1835 |
|
|
1836 |
|
// Handle palette changes |
1837 |
< |
handle_palette_changes(depth, DISPLAY_WINDOW); |
1837 |
> |
handle_palette_changes(DISPLAY_WINDOW); |
1838 |
|
|
1839 |
|
// Update display (VOSF variant) |
1840 |
|
static int tick_counter = 0; |
1841 |
|
if (++tick_counter >= frame_skip) { |
1842 |
|
tick_counter = 0; |
1843 |
< |
#ifdef HAVE_PTHREADS |
1844 |
< |
pthread_mutex_lock(&Screen_draw_lock); |
1845 |
< |
#endif |
1846 |
< |
update_display_window_vosf(); |
1847 |
< |
#ifdef HAVE_PTHREADS |
1848 |
< |
pthread_mutex_unlock(&Screen_draw_lock); |
1957 |
< |
#endif |
1843 |
> |
if (mainBuffer.dirty) { |
1844 |
> |
LOCK_VOSF; |
1845 |
> |
update_display_window_vosf(); |
1846 |
> |
UNLOCK_VOSF; |
1847 |
> |
XSync(x_display, false); // Let the server catch up |
1848 |
> |
} |
1849 |
|
} |
1850 |
|
} |
1851 |
< |
#endif |
1851 |
> |
#endif // def ENABLE_VOSF |
1852 |
|
|
1853 |
|
static void video_refresh_window_static(void) |
1854 |
|
{ |
1856 |
|
handle_events(); |
1857 |
|
|
1858 |
|
// Handle_palette changes |
1859 |
< |
handle_palette_changes(depth, DISPLAY_WINDOW); |
1859 |
> |
handle_palette_changes(DISPLAY_WINDOW); |
1860 |
|
|
1861 |
|
// Update display (static variant) |
1862 |
|
static int tick_counter = 0; |
1872 |
|
handle_events(); |
1873 |
|
|
1874 |
|
// Handle_palette changes |
1875 |
< |
handle_palette_changes(depth, DISPLAY_WINDOW); |
1875 |
> |
handle_palette_changes(DISPLAY_WINDOW); |
1876 |
|
|
1877 |
|
// Update display (dynamic variant) |
1878 |
|
static int tick_counter = 0; |
1885 |
|
* Thread for screen refresh, input handling etc. |
1886 |
|
*/ |
1887 |
|
|
1888 |
< |
void VideoRefreshInit(void) |
1888 |
> |
static void VideoRefreshInit(void) |
1889 |
|
{ |
1890 |
|
// TODO: set up specialised 8bpp VideoRefresh handlers ? |
1891 |
|
if (display_type == DISPLAY_DGA) { |
1892 |
< |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
1892 |
> |
#if ENABLE_VOSF && (REAL_ADDRESSING || DIRECT_ADDRESSING) |
1893 |
|
if (use_vosf) |
1894 |
|
video_refresh = video_refresh_dga_vosf; |
1895 |
|
else |
1915 |
|
video_refresh(); |
1916 |
|
} |
1917 |
|
|
2027 |
– |
#if 0 |
2028 |
– |
void VideoRefresh(void) |
2029 |
– |
{ |
2030 |
– |
#if defined(ENABLE_XF86_DGA) || defined(ENABLE_FBDEV_DGA) |
2031 |
– |
// Quit DGA mode if requested |
2032 |
– |
if (quit_full_screen) { |
2033 |
– |
quit_full_screen = false; |
2034 |
– |
if (display_type == DISPLAY_DGA) { |
2035 |
– |
#ifdef ENABLE_XF86_DGA |
2036 |
– |
XF86DGADirectVideo(x_display, screen, 0); |
2037 |
– |
#endif |
2038 |
– |
XUngrabPointer(x_display, CurrentTime); |
2039 |
– |
XUngrabKeyboard(x_display, CurrentTime); |
2040 |
– |
XUnmapWindow(x_display, the_win); |
2041 |
– |
XSync(x_display, false); |
2042 |
– |
} |
2043 |
– |
} |
2044 |
– |
#endif |
2045 |
– |
|
2046 |
– |
// Handle X events |
2047 |
– |
handle_events(); |
2048 |
– |
|
2049 |
– |
// Handle palette changes |
2050 |
– |
#ifdef HAVE_PTHREADS |
2051 |
– |
pthread_mutex_lock(&palette_lock); |
2052 |
– |
#endif |
2053 |
– |
if (palette_changed) { |
2054 |
– |
palette_changed = false; |
2055 |
– |
if (depth == 8) { |
2056 |
– |
XStoreColors(x_display, cmap[0], palette, 256); |
2057 |
– |
XStoreColors(x_display, cmap[1], palette, 256); |
2058 |
– |
|
2059 |
– |
#ifdef ENABLE_XF86_DGA |
2060 |
– |
if (display_type == DISPLAY_DGA) { |
2061 |
– |
current_dga_cmap ^= 1; |
2062 |
– |
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
2063 |
– |
} |
2064 |
– |
#endif |
2065 |
– |
} |
2066 |
– |
} |
2067 |
– |
#ifdef HAVE_PTHREADS |
2068 |
– |
pthread_mutex_unlock(&palette_lock); |
2069 |
– |
#endif |
2070 |
– |
|
2071 |
– |
// In window mode, update display |
2072 |
– |
static int tick_counter = 0; |
2073 |
– |
if (display_type == DISPLAY_WINDOW) { |
2074 |
– |
tick_counter++; |
2075 |
– |
if (frame_skip == 0) |
2076 |
– |
update_display_dynamic(tick_counter); |
2077 |
– |
else if (tick_counter >= frame_skip) { |
2078 |
– |
tick_counter = 0; |
2079 |
– |
update_display_static(); |
2080 |
– |
} |
2081 |
– |
} |
2082 |
– |
} |
2083 |
– |
#endif |
2084 |
– |
|
1918 |
|
#ifdef HAVE_PTHREADS |
1919 |
|
static void *redraw_func(void *arg) |
1920 |
|
{ |
1922 |
|
int64 ticks = 0; |
1923 |
|
uint64 next = GetTicks_usec(); |
1924 |
|
while (!redraw_thread_cancel) { |
2092 |
– |
// VideoRefresh(); |
1925 |
|
video_refresh(); |
1926 |
|
next += 16667; |
1927 |
|
int64 delay = next - GetTicks_usec(); |
1932 |
|
ticks++; |
1933 |
|
} |
1934 |
|
uint64 end = GetTicks_usec(); |
1935 |
< |
printf("%Ld ticks in %Ld usec = %Ld ticks/sec\n", ticks, end - start, (end - start) / ticks); |
1935 |
> |
// printf("%Ld ticks in %Ld usec = %Ld ticks/sec\n", ticks, end - start, ticks * 1000000 / (end - start)); |
1936 |
|
return NULL; |
1937 |
|
} |
1938 |
|
#endif |