52 |
|
# include <sys/mman.h> |
53 |
|
#endif |
54 |
|
|
55 |
– |
#ifdef ENABLE_VOSF |
56 |
– |
# include <fcntl.h> |
57 |
– |
# include <sys/mman.h> |
58 |
– |
# include "sigsegv.h" |
59 |
– |
#endif |
60 |
– |
|
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 |
116 |
– |
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; |
171 |
|
static const bool use_vosf = false; // Flag: VOSF enabled |
172 |
|
#endif |
173 |
|
|
180 |
– |
#ifdef ENABLE_VOSF |
181 |
– |
// Variables for Video on SEGV support (taken from the Win32 port) |
182 |
– |
static uint8 *the_host_buffer; // Host frame buffer in VOSF mode |
183 |
– |
static uint32 the_buffer_size; // Size of allocated the_buffer |
184 |
– |
|
185 |
– |
struct ScreenPageInfo { |
186 |
– |
int top, bottom; // Mapping between this virtual page and Mac scanlines |
187 |
– |
}; |
188 |
– |
|
189 |
– |
struct ScreenInfo { |
190 |
– |
uint32 memBase; // Real start address |
191 |
– |
uint32 memStart; // Start address aligned to page boundary |
192 |
– |
uint32 memEnd; // Address of one-past-the-end of the screen |
193 |
– |
uint32 memLength; // Length of the memory addressed by the screen pages |
194 |
– |
|
195 |
– |
uint32 pageSize; // Size of a page |
196 |
– |
int pageBits; // Shift count to get the page number |
197 |
– |
uint32 pageCount; // Number of pages allocated to the screen |
198 |
– |
|
199 |
– |
bool dirty; // Flag: set if the frame buffer was touched |
200 |
– |
char * dirtyPages; // Table of flags set if page was altered |
201 |
– |
ScreenPageInfo * pageInfo; // Table of mappings page -> Mac scanlines |
202 |
– |
}; |
203 |
– |
|
204 |
– |
static ScreenInfo mainBuffer; |
205 |
– |
|
206 |
– |
#define PFLAG_SET_VALUE 0x00 |
207 |
– |
#define PFLAG_CLEAR_VALUE 0x01 |
208 |
– |
#define PFLAG_SET_VALUE_4 0x00000000 |
209 |
– |
#define PFLAG_CLEAR_VALUE_4 0x01010101 |
210 |
– |
#define PFLAG_SET(page) mainBuffer.dirtyPages[page] = PFLAG_SET_VALUE |
211 |
– |
#define PFLAG_CLEAR(page) mainBuffer.dirtyPages[page] = PFLAG_CLEAR_VALUE |
212 |
– |
#define PFLAG_ISSET(page) (mainBuffer.dirtyPages[page] == PFLAG_SET_VALUE) |
213 |
– |
#define PFLAG_ISCLEAR(page) (mainBuffer.dirtyPages[page] != PFLAG_SET_VALUE) |
214 |
– |
|
215 |
– |
#ifdef UNALIGNED_PROFITABLE |
216 |
– |
# define PFLAG_ISSET_4(page) (*((uint32 *)(mainBuffer.dirtyPages + (page))) == PFLAG_SET_VALUE_4) |
217 |
– |
# define PFLAG_ISCLEAR_4(page) (*((uint32 *)(mainBuffer.dirtyPages + (page))) == PFLAG_CLEAR_VALUE_4) |
218 |
– |
#else |
219 |
– |
# define PFLAG_ISSET_4(page) \ |
220 |
– |
PFLAG_ISSET(page ) && PFLAG_ISSET(page+1) \ |
221 |
– |
&& PFLAG_ISSET(page+2) && PFLAG_ISSET(page+3) |
222 |
– |
# define PFLAG_ISCLEAR_4(page) \ |
223 |
– |
PFLAG_ISCLEAR(page ) && PFLAG_ISCLEAR(page+1) \ |
224 |
– |
&& PFLAG_ISCLEAR(page+2) && PFLAG_ISCLEAR(page+3) |
225 |
– |
#endif |
226 |
– |
|
227 |
– |
// Set the selected page range [ first_page, last_page [ into the SET state |
228 |
– |
#define PFLAG_SET_RANGE(first_page, last_page) \ |
229 |
– |
memset(mainBuffer.dirtyPages + (first_page), PFLAG_SET_VALUE, \ |
230 |
– |
(last_page) - (first_page)) |
231 |
– |
|
232 |
– |
// Set the selected page range [ first_page, last_page [ into the CLEAR state |
233 |
– |
#define PFLAG_CLEAR_RANGE(first_page, last_page) \ |
234 |
– |
memset(mainBuffer.dirtyPages + (first_page), PFLAG_CLEAR_VALUE, \ |
235 |
– |
(last_page) - (first_page)) |
236 |
– |
|
237 |
– |
#define PFLAG_SET_ALL do { \ |
238 |
– |
PFLAG_SET_RANGE(0, mainBuffer.pageCount); \ |
239 |
– |
mainBuffer.dirty = true; \ |
240 |
– |
} while (0) |
241 |
– |
|
242 |
– |
#define PFLAG_CLEAR_ALL do { \ |
243 |
– |
PFLAG_CLEAR_RANGE(0, mainBuffer.pageCount); \ |
244 |
– |
mainBuffer.dirty = false; \ |
245 |
– |
} while (0) |
246 |
– |
|
247 |
– |
// Set the following macro definition to 1 if your system |
248 |
– |
// provides a really fast strchr() implementation |
249 |
– |
//#define HAVE_FAST_STRCHR 0 |
250 |
– |
|
251 |
– |
static inline int find_next_page_set(int page) |
252 |
– |
{ |
253 |
– |
#if HAVE_FAST_STRCHR |
254 |
– |
char *match = strchr(mainBuffer.dirtyPages + page, PFLAG_SET_VALUE); |
255 |
– |
return match ? match - mainBuffer.dirtyPages : mainBuffer.pageCount; |
256 |
– |
#else |
257 |
– |
while (PFLAG_ISCLEAR_4(page)) |
258 |
– |
page += 4; |
259 |
– |
while (PFLAG_ISCLEAR(page)) |
260 |
– |
page++; |
261 |
– |
return page; |
262 |
– |
#endif |
263 |
– |
} |
264 |
– |
|
265 |
– |
static inline int find_next_page_clear(int page) |
266 |
– |
{ |
267 |
– |
#if HAVE_FAST_STRCHR |
268 |
– |
char *match = strchr(mainBuffer.dirtyPages + page, PFLAG_CLEAR_VALUE); |
269 |
– |
return match ? match - mainBuffer.dirtyPages : mainBuffer.pageCount; |
270 |
– |
#else |
271 |
– |
while (PFLAG_ISSET_4(page)) |
272 |
– |
page += 4; |
273 |
– |
while (PFLAG_ISSET(page)) |
274 |
– |
page++; |
275 |
– |
return page; |
276 |
– |
#endif |
277 |
– |
} |
278 |
– |
|
279 |
– |
static int zero_fd = -1; |
280 |
– |
|
281 |
– |
#ifdef HAVE_PTHREADS |
282 |
– |
static pthread_mutex_t vosf_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect frame buffer (dirtyPages in fact) |
283 |
– |
#define LOCK_VOSF pthread_mutex_lock(&vosf_lock); |
284 |
– |
#define UNLOCK_VOSF pthread_mutex_unlock(&vosf_lock); |
285 |
– |
#else |
286 |
– |
#define LOCK_VOSF |
287 |
– |
#define UNLOCK_VOSF |
288 |
– |
#endif |
289 |
– |
|
290 |
– |
static int log_base_2(uint32 x) |
291 |
– |
{ |
292 |
– |
uint32 mask = 0x80000000; |
293 |
– |
int l = 31; |
294 |
– |
while (l >= 0 && (x & mask) == 0) { |
295 |
– |
mask >>= 1; |
296 |
– |
l--; |
297 |
– |
} |
298 |
– |
return l; |
299 |
– |
} |
300 |
– |
#endif /* ENABLE_VOSF */ |
301 |
– |
|
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); |
181 |
|
|
310 |
– |
|
182 |
|
// From main_unix.cpp |
183 |
|
extern char *x_display_name; |
184 |
|
extern Display *x_display; |
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; |
336 |
< |
case 8: |
337 |
< |
layout = FLAYOUT_DIRECT; |
338 |
< |
break; |
339 |
< |
case 15: |
340 |
< |
layout = FLAYOUT_HOST_555; |
341 |
< |
break; |
342 |
< |
case 16: |
343 |
< |
layout = FLAYOUT_HOST_565; |
344 |
< |
break; |
345 |
< |
case 24: |
346 |
< |
case 32: |
347 |
< |
layout = FLAYOUT_HOST_888; |
348 |
< |
break; |
349 |
< |
} |
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) { |
356 |
< |
case 1: |
357 |
< |
VideoMonitor.mode = VMODE_1BIT; |
358 |
< |
break; |
359 |
< |
case 8: |
360 |
< |
VideoMonitor.mode = VMODE_8BIT; |
361 |
< |
break; |
362 |
< |
case 15: |
363 |
< |
VideoMonitor.mode = VMODE_16BIT; |
364 |
< |
break; |
365 |
< |
case 16: |
366 |
< |
VideoMonitor.mode = VMODE_16BIT; |
367 |
< |
break; |
368 |
< |
case 24: |
369 |
< |
case 32: |
370 |
< |
VideoMonitor.mode = VMODE_32BIT; |
371 |
< |
break; |
372 |
< |
} |
373 |
< |
VideoMonitor.x = width; |
374 |
< |
VideoMonitor.y = height; |
375 |
< |
VideoMonitor.bytes_per_row = bytes_per_row; |
229 |
> |
D(bug("VideoMonitor.mac_frame_base = %08x\n", VideoMonitor.mac_frame_base)); |
230 |
|
} |
231 |
|
|
232 |
|
// Set window name and class |
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 |
|
|
316 |
|
wattr.colormap = cmap[0]; |
317 |
|
|
318 |
|
the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, |
319 |
< |
InputOutput, vis, CWEventMask | CWBackPixel | (depth == 8 ? CWColormap : 0), &wattr); |
319 |
> |
InputOutput, vis, CWEventMask | CWBackPixel | ((IsDirectMode(mode) || mode.depth == VDEPTH_1BIT) ? 0 : CWColormap), &wattr); |
320 |
|
|
321 |
|
// Set window name/class |
322 |
|
set_window_name(the_win, STR_WINDOW_TITLE); |
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; |
523 |
< |
switch (depth) { |
524 |
< |
case 1: |
525 |
< |
bytes_per_row /= 8; |
526 |
< |
break; |
527 |
< |
case 15: |
528 |
< |
case 16: |
529 |
< |
bytes_per_row *= 2; |
530 |
< |
break; |
531 |
< |
case 24: |
532 |
< |
case 32: |
533 |
< |
bytes_per_row *= 4; |
534 |
< |
break; |
535 |
< |
} |
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 |
548 |
< |
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); |
553 |
< |
|
554 |
< |
the_buffer = (uint8 *)allocate_framebuffer(the_buffer_size); |
555 |
< |
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 = (XImageByteOrder(x_display) == MSBFirst); |
417 |
|
#ifdef ENABLE_VOSF |
418 |
|
Screen_blitter_init(&visualInfo, native_byte_order); |
419 |
|
#endif |
420 |
< |
set_video_monitor(width, height, img->bytes_per_line, native_byte_order); |
421 |
< |
|
584 |
< |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
585 |
< |
VideoMonitor.mac_frame_base = Host2MacAddr(the_buffer); |
586 |
< |
#else |
587 |
< |
VideoMonitor.mac_frame_base = MacFrameBaseMac; |
588 |
< |
#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); |
656 |
< |
int height = DisplayHeight(x_display, screen); |
657 |
< |
depth = fb_depth; // max_depth |
490 |
> |
depth = fb_depth; |
491 |
|
|
492 |
|
// Set relative mouse mode |
493 |
|
ADBSetRelMouseMode(false); |
522 |
|
PointerMotionMask | ButtonPressMask | ButtonReleaseMask, |
523 |
|
GrabModeAsync, GrabModeAsync, the_win, None, CurrentTime); |
524 |
|
|
525 |
< |
// Set VideoMonitor |
526 |
< |
int bytes_per_row = width; |
694 |
< |
switch (depth) { |
695 |
< |
case 1: |
696 |
< |
bytes_per_row = ((width | 7) & ~7) >> 3; |
697 |
< |
break; |
698 |
< |
case 15: |
699 |
< |
case 16: |
700 |
< |
bytes_per_row *= 2; |
701 |
< |
break; |
702 |
< |
case 24: |
703 |
< |
case 32: |
704 |
< |
bytes_per_row *= 4; |
705 |
< |
break; |
706 |
< |
} |
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]; |
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); |
729 |
< |
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 |
|
#else |
552 |
|
use_vosf = false; |
553 |
|
#endif |
554 |
|
#endif |
555 |
|
|
556 |
< |
set_video_monitor(width, height, bytes_per_row, true); |
557 |
< |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
558 |
< |
VideoMonitor.mac_frame_base = Host2MacAddr(the_buffer); |
739 |
< |
#else |
740 |
< |
VideoMonitor.mac_frame_base = MacFrameBaseMac; |
741 |
< |
#endif |
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); |
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]); |
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: |
813 |
< |
bytes_per_row /= 8; |
814 |
< |
break; |
815 |
< |
case 15: |
816 |
< |
case 16: |
817 |
< |
bytes_per_row *= 2; |
818 |
< |
break; |
819 |
< |
case 24: |
820 |
< |
case 32: |
821 |
< |
bytes_per_row *= 4; |
822 |
< |
break; |
823 |
< |
} |
824 |
< |
|
629 |
> |
int bytes_per_row = TrivialBytesPerRow((v_width + 7) & ~7, mode.depth); |
630 |
> |
|
631 |
> |
#ifdef VIDEO_VOSF |
632 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
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); |
836 |
< |
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) |
839 |
< |
// The UAE memory handlers will already handle color conversion, if needed. |
644 |
> |
#else |
645 |
|
use_vosf = false; |
646 |
|
#endif |
842 |
– |
|
843 |
– |
set_video_monitor(width, height, bytes_per_row, true); |
844 |
– |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
845 |
– |
VideoMonitor.mac_frame_base = Host2MacAddr(the_buffer); |
846 |
– |
// MacFrameLayout = FLAYOUT_DIRECT; |
847 |
– |
#else |
848 |
– |
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); |
932 |
< |
mainBuffer.memLength = the_buffer_size; |
933 |
< |
mainBuffer.memEnd = mainBuffer.memStart + mainBuffer.memLength; |
934 |
< |
|
935 |
< |
mainBuffer.pageSize = page_size; |
936 |
< |
mainBuffer.pageCount = (mainBuffer.memLength + page_mask)/mainBuffer.pageSize; |
937 |
< |
mainBuffer.pageBits = log_base_2(mainBuffer.pageSize); |
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 |
< |
if (mainBuffer.dirtyPages != 0) |
737 |
< |
free(mainBuffer.dirtyPages); |
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 |
< |
mainBuffer.dirtyPages = (char *) malloc(mainBuffer.pageCount + 2); |
752 |
> |
// Lock down frame buffer |
753 |
> |
LOCK_FRAME_BUFFER; |
754 |
|
|
755 |
< |
if (mainBuffer.pageInfo != 0) |
756 |
< |
free(mainBuffer.pageInfo); |
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 |
< |
mainBuffer.pageInfo = (ScreenPageInfo *) malloc(mainBuffer.pageCount * sizeof(ScreenPageInfo)); |
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 |
< |
if ((mainBuffer.dirtyPages == 0) || (mainBuffer.pageInfo == 0)) |
950 |
< |
return false; |
951 |
< |
|
952 |
< |
mainBuffer.dirty = false; |
765 |
> |
InitFrameBufferMapping(); |
766 |
|
|
767 |
< |
PFLAG_CLEAR_ALL; |
768 |
< |
// Safety net to insure the loops in the update routines will terminate |
769 |
< |
// See a discussion in <video_vosf.h> for further details |
770 |
< |
PFLAG_CLEAR(mainBuffer.pageCount); |
771 |
< |
PFLAG_SET(mainBuffer.pageCount+1); |
772 |
< |
|
960 |
< |
uint32 a = 0; |
961 |
< |
for (int i = 0; i < mainBuffer.pageCount; i++) { |
962 |
< |
int y1 = a / VideoMonitor.bytes_per_row; |
963 |
< |
if (y1 >= VideoMonitor.y) |
964 |
< |
y1 = VideoMonitor.y - 1; |
965 |
< |
|
966 |
< |
int y2 = (a + mainBuffer.pageSize) / VideoMonitor.bytes_per_row; |
967 |
< |
if (y2 >= VideoMonitor.y) |
968 |
< |
y2 = VideoMonitor.y - 1; |
969 |
< |
|
970 |
< |
mainBuffer.pageInfo[i].top = y1; |
971 |
< |
mainBuffer.pageInfo[i].bottom = y2; |
972 |
< |
|
973 |
< |
a += mainBuffer.pageSize; |
974 |
< |
if (a > mainBuffer.memLength) |
975 |
< |
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 |
806 |
|
// Open /dev/zero |
807 |
|
zero_fd = open("/dev/zero", O_RDWR); |
902 |
|
} |
903 |
|
vis = visualInfo.visual; |
904 |
|
|
1088 |
– |
// Mac screen depth is always 1 bit in Classic mode, but follows X depth otherwise |
1089 |
– |
classic_mode = classic; |
1090 |
– |
if (classic) |
1091 |
– |
depth = 1; |
1092 |
– |
else |
1093 |
– |
depth = xdepth; |
1094 |
– |
|
1095 |
– |
// Create color maps for 8 bit mode |
1096 |
– |
if (depth == 8) { |
1097 |
– |
cmap[0] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
1098 |
– |
cmap[1] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
1099 |
– |
XInstallColormap(x_display, cmap[0]); |
1100 |
– |
XInstallColormap(x_display, cmap[1]); |
1101 |
– |
} |
1102 |
– |
|
905 |
|
// Get screen mode from preferences |
906 |
|
const char *mode_str; |
907 |
< |
if (classic) |
907 |
> |
if (classic_mode) |
908 |
|
mode_str = "win/512/342"; |
909 |
|
else |
910 |
|
mode_str = PrefsFindString("screen"); |
911 |
|
|
912 |
< |
// Determine type and mode |
913 |
< |
int width = 512, height = 384; |
912 |
> |
// Determine display type and default dimensions |
913 |
> |
int default_width = 512, default_height = 384; |
914 |
|
display_type = DISPLAY_WINDOW; |
915 |
|
if (mode_str) { |
916 |
< |
if (sscanf(mode_str, "win/%d/%d", &width, &height) == 2) |
916 |
> |
if (sscanf(mode_str, "win/%d/%d", &default_width, &default_height) == 2) { |
917 |
|
display_type = DISPLAY_WINDOW; |
918 |
|
#ifdef ENABLE_FBDEV_DGA |
919 |
< |
else if (has_dga && sscanf(mode_str, "dga/%19s", fb_name) == 1) { |
1118 |
< |
#else |
1119 |
< |
else if (has_dga && sscanf(mode_str, "dga/%d/%d", &width, &height) == 2) { |
1120 |
< |
#endif |
919 |
> |
} else if (has_dga && sscanf(mode_str, "dga/%19s", fb_name) == 1) { |
920 |
|
display_type = DISPLAY_DGA; |
921 |
< |
if (width > DisplayWidth(x_display, screen)) |
1123 |
< |
width = DisplayWidth(x_display, screen); |
1124 |
< |
if (height > DisplayHeight(x_display, screen)) |
1125 |
< |
height = DisplayHeight(x_display, screen); |
1126 |
< |
} |
1127 |
< |
if (width <= 0) |
1128 |
< |
width = DisplayWidth(x_display, screen); |
1129 |
< |
if (height <= 0) |
1130 |
< |
height = DisplayHeight(x_display, screen); |
1131 |
< |
} |
1132 |
< |
|
1133 |
< |
// Initialize according to display type |
1134 |
< |
switch (display_type) { |
1135 |
< |
case DISPLAY_WINDOW: |
1136 |
< |
if (!init_window(width, height)) |
1137 |
< |
return false; |
1138 |
< |
break; |
1139 |
< |
case DISPLAY_DGA: |
1140 |
< |
#ifdef ENABLE_FBDEV_DGA |
1141 |
< |
if (!init_fbdev_dga(fb_name)) |
921 |
> |
default_width = -1; default_height = -1; |
922 |
|
#else |
923 |
< |
if (!init_xf86_dga(width, height)) |
923 |
> |
} else if (has_dga && sscanf(mode_str, "dga/%d/%d", &default_width, &default_height) == 2) { |
924 |
> |
display_type = DISPLAY_DGA; |
925 |
|
#endif |
926 |
< |
return false; |
1146 |
< |
break; |
926 |
> |
} |
927 |
|
} |
928 |
+ |
if (default_width <= 0) |
929 |
+ |
default_width = DisplayWidth(x_display, screen); |
930 |
+ |
else if (default_width > DisplayWidth(x_display, screen)) |
931 |
+ |
default_width = DisplayWidth(x_display, screen); |
932 |
+ |
if (default_height <= 0) |
933 |
+ |
default_height = DisplayHeight(x_display, screen); |
934 |
+ |
else if (default_height > DisplayHeight(x_display, screen)) |
935 |
+ |
default_height = DisplayHeight(x_display, screen); |
936 |
|
|
937 |
< |
// Lock down frame buffer |
938 |
< |
LOCK_FRAME_BUFFER; |
939 |
< |
|
1152 |
< |
#if !REAL_ADDRESSING && !DIRECT_ADDRESSING |
1153 |
< |
// Set variables for UAE memory mapping |
1154 |
< |
MacFrameBaseHost = the_buffer; |
1155 |
< |
MacFrameSize = VideoMonitor.bytes_per_row * VideoMonitor.y; |
1156 |
< |
|
1157 |
< |
// No special frame buffer in Classic mode (frame buffer is in Mac RAM) |
1158 |
< |
if (classic) |
1159 |
< |
MacFrameLayout = FLAYOUT_NONE; |
1160 |
< |
#endif |
937 |
> |
// Mac screen depth is always 1 bit in Classic mode, but follows X depth otherwise |
938 |
> |
int depth = (classic_mode ? 1 : xdepth); |
939 |
> |
video_depth depth_mode = DepthModeForPixelDepth(depth); |
940 |
|
|
941 |
< |
#ifdef ENABLE_VOSF |
942 |
< |
if (use_vosf) { |
943 |
< |
// Initialize the mainBuffer structure |
944 |
< |
if (!VideoInitBuffer()) { |
945 |
< |
// TODO: STR_VOSF_INIT_ERR ? |
946 |
< |
ErrorAlert("Could not initialize Video on SEGV signals"); |
947 |
< |
return false; |
941 |
> |
// Construct list of supported modes |
942 |
> |
if (display_type == DISPLAY_WINDOW) { |
943 |
> |
if (classic) |
944 |
> |
add_mode(512, 342, 0x80, 64, depth_mode); |
945 |
> |
else { |
946 |
> |
add_mode(512, 384, 0x80, TrivialBytesPerRow(512, depth_mode), depth_mode); |
947 |
> |
add_mode(640, 480, 0x81, TrivialBytesPerRow(640, depth_mode), depth_mode); |
948 |
> |
add_mode(800, 600, 0x82, TrivialBytesPerRow(800, depth_mode), depth_mode); |
949 |
> |
add_mode(1024, 768, 0x83, TrivialBytesPerRow(1024, depth_mode), depth_mode); |
950 |
> |
add_mode(1280, 1024, 0x84, TrivialBytesPerRow(1280, depth_mode), depth_mode); |
951 |
|
} |
952 |
+ |
} else |
953 |
+ |
add_mode(default_width, default_height, 0x80, TrivialBytesPerRow(default_width, depth_mode), depth_mode); |
954 |
|
|
955 |
< |
// Initialize the handler for SIGSEGV |
956 |
< |
if (!sigsegv_install_handler(screen_fault_handler)) { |
957 |
< |
// TODO: STR_VOSF_INIT_ERR ? |
958 |
< |
ErrorAlert("Could not initialize Video on SEGV signals"); |
959 |
< |
return false; |
955 |
> |
// Find requested default mode and open display |
956 |
> |
if (VideoModes.size() == 1) |
957 |
> |
return video_open(VideoModes[0]); |
958 |
> |
else { |
959 |
> |
// Find mode with specified dimensions |
960 |
> |
std::vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end(); |
961 |
> |
while (i != end) { |
962 |
> |
if (i->x == default_width && i->y == default_height) |
963 |
> |
return video_open(*i); |
964 |
> |
++i; |
965 |
|
} |
966 |
+ |
return video_open(VideoModes[0]); |
967 |
|
} |
1178 |
– |
#endif |
1179 |
– |
|
1180 |
– |
// Initialize VideoRefresh function |
1181 |
– |
VideoRefreshInit(); |
1182 |
– |
|
1183 |
– |
XSync(x_display, false); |
1184 |
– |
|
1185 |
– |
#ifdef HAVE_PTHREADS |
1186 |
– |
// Start redraw/input thread |
1187 |
– |
redraw_thread_active = (pthread_create(&redraw_thread, NULL, redraw_func, NULL) == 0); |
1188 |
– |
if (!redraw_thread_active) { |
1189 |
– |
printf("FATAL: cannot create redraw thread\n"); |
1190 |
– |
return false; |
1191 |
– |
} |
1192 |
– |
#endif |
1193 |
– |
return true; |
968 |
|
} |
969 |
|
|
970 |
|
|
972 |
|
* Deinitialization |
973 |
|
*/ |
974 |
|
|
975 |
< |
void VideoExit(void) |
975 |
> |
// Close display |
976 |
> |
static void video_close(void) |
977 |
|
{ |
978 |
|
#ifdef HAVE_PTHREADS |
979 |
|
// Stop redraw thread |
1017 |
|
|
1018 |
|
XFlush(x_display); |
1019 |
|
XSync(x_display, false); |
1020 |
< |
if (depth == 8) { |
1020 |
> |
XUnmapWindow(x_display, the_win); |
1021 |
> |
wait_unmapped(the_win); |
1022 |
> |
XDestroyWindow(x_display, the_win); |
1023 |
> |
|
1024 |
> |
if (have_shm) { |
1025 |
> |
XDestroyImage(img); |
1026 |
> |
XShmDetach(x_display, &shminfo); |
1027 |
> |
have_shm = false; |
1028 |
> |
} else { |
1029 |
> |
//!! free img |
1030 |
> |
} |
1031 |
> |
//!! free the_gc |
1032 |
> |
|
1033 |
> |
if (cmap_allocated) { |
1034 |
|
XFreeColormap(x_display, cmap[0]); |
1035 |
|
XFreeColormap(x_display, cmap[1]); |
1036 |
+ |
cmap_allocated = false; |
1037 |
|
} |
1038 |
|
|
1039 |
|
if (!use_vosf) { |
1049 |
|
} |
1050 |
|
#ifdef ENABLE_VOSF |
1051 |
|
else { |
1052 |
< |
if (the_buffer != (uint8 *)MAP_FAILED) { |
1053 |
< |
munmap((caddr_t)the_buffer, the_buffer_size); |
1052 |
> |
//!! uninstall SEGV handler? |
1053 |
> |
|
1054 |
> |
if (the_buffer != (uint8 *)VM_MAP_FAILED) { |
1055 |
> |
vm_release(the_buffer, the_buffer_size); |
1056 |
|
the_buffer = 0; |
1057 |
|
} |
1058 |
|
|
1059 |
< |
if (the_buffer_copy != (uint8 *)MAP_FAILED) { |
1060 |
< |
munmap((caddr_t)the_buffer_copy, the_buffer_size); |
1059 |
> |
if (the_buffer_copy != (uint8 *)VM_MAP_FAILED) { |
1060 |
> |
vm_release(the_buffer_copy, the_buffer_size); |
1061 |
|
the_buffer_copy = 0; |
1062 |
|
} |
1063 |
|
} |
1077 |
|
mainBuffer.dirtyPages = 0; |
1078 |
|
} |
1079 |
|
} |
1080 |
+ |
#endif |
1081 |
+ |
} |
1082 |
+ |
|
1083 |
+ |
void VideoExit(void) |
1084 |
+ |
{ |
1085 |
+ |
video_close(); |
1086 |
|
|
1087 |
+ |
#ifdef ENABLE_VOSF |
1088 |
|
// Close /dev/zero |
1089 |
|
if (zero_fd > 0) |
1090 |
|
close(zero_fd); |
1146 |
|
|
1147 |
|
|
1148 |
|
/* |
1149 |
+ |
* Switch video mode |
1150 |
+ |
*/ |
1151 |
+ |
|
1152 |
+ |
void video_switch_to_mode(const video_mode &mode) |
1153 |
+ |
{ |
1154 |
+ |
video_close(); |
1155 |
+ |
video_open(mode); |
1156 |
+ |
} |
1157 |
+ |
|
1158 |
+ |
|
1159 |
+ |
/* |
1160 |
|
* Suspend/resume emulator |
1161 |
|
*/ |
1162 |
|
|
1172 |
|
LOCK_FRAME_BUFFER; |
1173 |
|
|
1174 |
|
// Save frame buffer |
1175 |
< |
fb_save = malloc(VideoMonitor.y * VideoMonitor.bytes_per_row); |
1175 |
> |
fb_save = malloc(VideoMonitor.mode.y * VideoMonitor.mode.bytes_per_row); |
1176 |
|
if (fb_save) |
1177 |
< |
memcpy(fb_save, the_buffer, VideoMonitor.y * VideoMonitor.bytes_per_row); |
1177 |
> |
memcpy(fb_save, the_buffer, VideoMonitor.mode.y * VideoMonitor.mode.bytes_per_row); |
1178 |
|
|
1179 |
|
// Close full screen display |
1180 |
|
#ifdef ENABLE_XF86_DGA |
1225 |
|
LOCK_VOSF; |
1226 |
|
PFLAG_SET_ALL; |
1227 |
|
UNLOCK_VOSF; |
1228 |
< |
memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y); |
1228 |
> |
memset(the_buffer_copy, 0, VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y); |
1229 |
|
} |
1230 |
|
#endif |
1231 |
|
|
1235 |
|
// Don't copy fb_save to the temporary frame buffer in VOSF mode |
1236 |
|
if (!use_vosf) |
1237 |
|
#endif |
1238 |
< |
memcpy(the_buffer, fb_save, VideoMonitor.y * VideoMonitor.bytes_per_row); |
1238 |
> |
memcpy(the_buffer, fb_save, VideoMonitor.mode.y * VideoMonitor.mode.bytes_per_row); |
1239 |
|
free(fb_save); |
1240 |
|
fb_save = NULL; |
1241 |
|
} |
1242 |
|
|
1243 |
|
#ifdef ENABLE_XF86_DGA |
1244 |
< |
if (depth == 8) |
1244 |
> |
if (!IsDirectMode(VideoMonitor.mode)) |
1245 |
|
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
1246 |
|
#endif |
1247 |
|
|
1516 |
|
LOCK_VOSF; |
1517 |
|
PFLAG_SET_ALL; |
1518 |
|
UNLOCK_VOSF; |
1519 |
< |
memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y); |
1519 |
> |
memset(the_buffer_copy, 0, VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y); |
1520 |
|
} |
1521 |
|
else |
1522 |
|
#endif |
1527 |
|
updt_box[x1][y1] = true; |
1528 |
|
nr_boxes = 16 * 16; |
1529 |
|
} else // Static refresh |
1530 |
< |
memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y); |
1530 |
> |
memset(the_buffer_copy, 0, VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y); |
1531 |
|
} |
1532 |
|
break; |
1533 |
|
|
1553 |
|
int y1, y2, y2s, y2a, i, x1, xm, xmo, ymo, yo, yi, yil, xi; |
1554 |
|
int xil = 0; |
1555 |
|
int rxm = 0, rxmo = 0; |
1556 |
< |
int bytes_per_row = VideoMonitor.bytes_per_row; |
1557 |
< |
int bytes_per_pixel = VideoMonitor.bytes_per_row / VideoMonitor.x; |
1558 |
< |
int rx = VideoMonitor.bytes_per_row / 16; |
1559 |
< |
int ry = VideoMonitor.y / 16; |
1556 |
> |
int bytes_per_row = VideoMonitor.mode.bytes_per_row; |
1557 |
> |
int bytes_per_pixel = VideoMonitor.mode.bytes_per_row / VideoMonitor.mode.x; |
1558 |
> |
int rx = VideoMonitor.mode.bytes_per_row / 16; |
1559 |
> |
int ry = VideoMonitor.mode.y / 16; |
1560 |
|
int max_box; |
1561 |
|
|
1562 |
|
y2s = sm_uptd[ticker % 8]; |
1610 |
|
i = (yi * bytes_per_row) + xi; |
1611 |
|
for (y2=0; y2 < yil; y2++, i += bytes_per_row) |
1612 |
|
memcpy(&the_buffer_copy[i], &the_buffer[i], xil); |
1613 |
< |
if (depth == 1) { |
1613 |
> |
if (VideoMonitor.mode.depth == VDEPTH_1BIT) { |
1614 |
|
if (have_shm) |
1615 |
|
XShmPutImage(x_display, the_win, the_gc, img, xi * 8, yi, xi * 8, yi, xil * 8, yil, 0); |
1616 |
|
else |
1642 |
|
{ |
1643 |
|
// Incremental update code |
1644 |
|
int wide = 0, high = 0, x1, x2, y1, y2, i, j; |
1645 |
< |
int bytes_per_row = VideoMonitor.bytes_per_row; |
1646 |
< |
int bytes_per_pixel = VideoMonitor.bytes_per_row / VideoMonitor.x; |
1645 |
> |
int bytes_per_row = VideoMonitor.mode.bytes_per_row; |
1646 |
> |
int bytes_per_pixel = VideoMonitor.mode.bytes_per_row / VideoMonitor.mode.x; |
1647 |
|
uint8 *p, *p2; |
1648 |
|
|
1649 |
|
// Check for first line from top and first line from bottom that have changed |
1650 |
|
y1 = 0; |
1651 |
< |
for (j=0; j<VideoMonitor.y; j++) { |
1651 |
> |
for (j=0; j<VideoMonitor.mode.y; j++) { |
1652 |
|
if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) { |
1653 |
|
y1 = j; |
1654 |
|
break; |
1655 |
|
} |
1656 |
|
} |
1657 |
|
y2 = y1 - 1; |
1658 |
< |
for (j=VideoMonitor.y-1; j>=y1; j--) { |
1658 |
> |
for (j=VideoMonitor.mode.y-1; j>=y1; j--) { |
1659 |
|
if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) { |
1660 |
|
y2 = j; |
1661 |
|
break; |
1665 |
|
|
1666 |
|
// Check for first column from left and first column from right that have changed |
1667 |
|
if (high) { |
1668 |
< |
if (depth == 1) { |
1669 |
< |
x1 = VideoMonitor.x - 1; |
1668 |
> |
if (VideoMonitor.mode.depth == VDEPTH_1BIT) { |
1669 |
> |
x1 = VideoMonitor.mode.x - 1; |
1670 |
|
for (j=y1; j<=y2; j++) { |
1671 |
|
p = &the_buffer[j * bytes_per_row]; |
1672 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1684 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1685 |
|
p += bytes_per_row; |
1686 |
|
p2 += bytes_per_row; |
1687 |
< |
for (i=(VideoMonitor.x>>3); i>(x2>>3); i--) { |
1687 |
> |
for (i=(VideoMonitor.mode.x>>3); i>(x2>>3); i--) { |
1688 |
|
p--; p2--; |
1689 |
|
if (*p != *p2) { |
1690 |
|
x2 = (i << 3) + 7; |
1703 |
|
} |
1704 |
|
|
1705 |
|
} else { |
1706 |
< |
x1 = VideoMonitor.x; |
1706 |
> |
x1 = VideoMonitor.mode.x; |
1707 |
|
for (j=y1; j<=y2; j++) { |
1708 |
|
p = &the_buffer[j * bytes_per_row]; |
1709 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1721 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1722 |
|
p += bytes_per_row; |
1723 |
|
p2 += bytes_per_row; |
1724 |
< |
for (i=VideoMonitor.x*bytes_per_pixel; i>x2*bytes_per_pixel; i--) { |
1724 |
> |
for (i=VideoMonitor.mode.x*bytes_per_pixel; i>x2*bytes_per_pixel; i--) { |
1725 |
|
p--; |
1726 |
|
p2--; |
1727 |
|
if (*p != *p2) { |
1774 |
|
XUngrabPointer(x_display, CurrentTime); |
1775 |
|
XUngrabKeyboard(x_display, CurrentTime); |
1776 |
|
XUnmapWindow(x_display, the_win); |
1777 |
< |
XSync(x_display, false); |
1777 |
> |
wait_unmapped(the_win); |
1778 |
|
} |
1779 |
|
#endif |
1780 |
|
} |
1781 |
|
|
1782 |
< |
static inline void handle_palette_changes(int depth, int display_type) |
1782 |
> |
static inline void handle_palette_changes(int display_type) |
1783 |
|
{ |
1784 |
|
LOCK_PALETTE; |
1785 |
|
|
1786 |
|
if (palette_changed) { |
1787 |
|
palette_changed = false; |
1788 |
< |
if (depth == 8) { |
1788 |
> |
if (!IsDirectMode(VideoMonitor.mode)) { |
1789 |
|
XStoreColors(x_display, cmap[0], palette, 256); |
1790 |
|
XStoreColors(x_display, cmap[1], palette, 256); |
1791 |
|
XSync(x_display, false); |
1811 |
|
handle_events(); |
1812 |
|
|
1813 |
|
// Handle palette changes |
1814 |
< |
handle_palette_changes(depth, DISPLAY_DGA); |
1814 |
> |
handle_palette_changes(DISPLAY_DGA); |
1815 |
|
} |
1816 |
|
|
1817 |
|
#ifdef ENABLE_VOSF |
1825 |
|
handle_events(); |
1826 |
|
|
1827 |
|
// Handle palette changes |
1828 |
< |
handle_palette_changes(depth, DISPLAY_DGA); |
1828 |
> |
handle_palette_changes(DISPLAY_DGA); |
1829 |
|
|
1830 |
|
// Update display (VOSF variant) |
1831 |
|
static int tick_counter = 0; |
1849 |
|
handle_events(); |
1850 |
|
|
1851 |
|
// Handle palette changes |
1852 |
< |
handle_palette_changes(depth, DISPLAY_WINDOW); |
1852 |
> |
handle_palette_changes(DISPLAY_WINDOW); |
1853 |
|
|
1854 |
|
// Update display (VOSF variant) |
1855 |
|
static int tick_counter = 0; |
1871 |
|
handle_events(); |
1872 |
|
|
1873 |
|
// Handle_palette changes |
1874 |
< |
handle_palette_changes(depth, DISPLAY_WINDOW); |
1874 |
> |
handle_palette_changes(DISPLAY_WINDOW); |
1875 |
|
|
1876 |
|
// Update display (static variant) |
1877 |
|
static int tick_counter = 0; |
1887 |
|
handle_events(); |
1888 |
|
|
1889 |
|
// Handle_palette changes |
1890 |
< |
handle_palette_changes(depth, DISPLAY_WINDOW); |
1890 |
> |
handle_palette_changes(DISPLAY_WINDOW); |
1891 |
|
|
1892 |
|
// Update display (dynamic variant) |
1893 |
|
static int tick_counter = 0; |
1900 |
|
* Thread for screen refresh, input handling etc. |
1901 |
|
*/ |
1902 |
|
|
1903 |
< |
void VideoRefreshInit(void) |
1903 |
> |
static void VideoRefreshInit(void) |
1904 |
|
{ |
1905 |
|
// TODO: set up specialised 8bpp VideoRefresh handlers ? |
1906 |
|
if (display_type == DISPLAY_DGA) { |