34 |
|
#endif |
35 |
|
|
36 |
|
// Variables for Video on SEGV support |
37 |
< |
static uint8 *the_host_buffer; // Host frame buffer in VOSF mode |
38 |
< |
static uint32 the_buffer_size; // Size of allocated the_buffer |
37 |
> |
static uint8 *the_host_buffer; // Host frame buffer in VOSF mode |
38 |
> |
static uint32 the_buffer_size; // Size of allocated the_buffer |
39 |
|
|
40 |
|
struct ScreenPageInfo { |
41 |
|
int top, bottom; // Mapping between this virtual page and Mac scanlines |
131 |
|
#endif |
132 |
|
} |
133 |
|
|
134 |
– |
static int zero_fd = -1; |
135 |
– |
|
134 |
|
#ifdef HAVE_PTHREADS |
135 |
|
static pthread_mutex_t vosf_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect frame buffer (dirtyPages in fact) |
136 |
|
#define LOCK_VOSF pthread_mutex_lock(&vosf_lock); |
151 |
|
return l; |
152 |
|
} |
153 |
|
|
154 |
+ |
// Extend size to page boundary |
155 |
+ |
static uint32 page_extend(uint32 size) |
156 |
+ |
{ |
157 |
+ |
const uint32 page_size = getpagesize(); |
158 |
+ |
const uint32 page_mask = page_size - 1; |
159 |
+ |
return (size + page_mask) & ~page_mask; |
160 |
+ |
} |
161 |
+ |
|
162 |
|
|
163 |
|
/* |
164 |
|
* Initialize mainBuffer structure |
171 |
|
const uint32 page_mask = page_size - 1; |
172 |
|
|
173 |
|
mainBuffer.memBase = (uintptr) the_buffer; |
174 |
< |
// Align the frame buffer on page boundary |
174 |
> |
// Round up frame buffer base to page boundary |
175 |
|
mainBuffer.memStart = (uintptr)((((unsigned long) the_buffer) + page_mask) & ~page_mask); |
176 |
|
mainBuffer.memLength = the_buffer_size; |
177 |
|
mainBuffer.memEnd = mainBuffer.memStart + mainBuffer.memLength; |
194 |
|
|
195 |
|
mainBuffer.pageInfo = (ScreenPageInfo *) malloc(mainBuffer.pageCount * sizeof(ScreenPageInfo)); |
196 |
|
|
197 |
< |
if ((mainBuffer.dirtyPages == 0) || (mainBuffer.pageInfo == 0)) |
197 |
> |
if ((mainBuffer.dirtyPages == NULL) || (mainBuffer.pageInfo == NULL)) |
198 |
|
return false; |
199 |
|
|
200 |
|
mainBuffer.dirty = false; |
201 |
|
|
202 |
|
PFLAG_CLEAR_ALL; |
203 |
|
// Safety net to insure the loops in the update routines will terminate |
204 |
< |
// See a discussion in <video_vosf.h> for further details |
204 |
> |
// See "How can we deal with array overrun conditions ?" hereunder for further details |
205 |
|
PFLAG_CLEAR(mainBuffer.pageCount); |
206 |
|
PFLAG_SET(mainBuffer.pageCount+1); |
207 |
|
|
232 |
|
|
233 |
|
|
234 |
|
/* |
235 |
< |
* Page-aligned memory allocation |
235 |
> |
* Screen fault handler |
236 |
|
*/ |
237 |
|
|
232 |
– |
// Extend size to page boundary |
233 |
– |
static uint32 page_extend(uint32 size) |
234 |
– |
{ |
235 |
– |
const uint32 page_size = getpagesize(); |
236 |
– |
const uint32 page_mask = page_size - 1; |
237 |
– |
return (size + page_mask) & ~page_mask; |
238 |
– |
} |
239 |
– |
|
240 |
– |
// Screen fault handler |
238 |
|
static bool screen_fault_handler(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction) |
239 |
|
{ |
240 |
< |
D(bug("screen_fault_handler: ADDR=0x%08X from IP=0x%08X\n", fault_address, fault_instruction)); |
240 |
> |
// D(bug("screen_fault_handler: ADDR=0x%08X from IP=0x%08X\n", fault_address, fault_instruction)); |
241 |
|
const uintptr addr = (uintptr)fault_address; |
242 |
|
|
243 |
|
/* Someone attempted to write to the frame buffer. Make it writeable |
244 |
< |
* now so that the data could actually be written. It will be made |
244 |
> |
* now so that the data could actually be written to. It will be made |
245 |
|
* read-only back in one of the screen update_*() functions. |
246 |
|
*/ |
247 |
|
if ((addr >= mainBuffer.memStart) && (addr < mainBuffer.memEnd)) { |
265 |
|
extern void m68k_dumpstate(uaecptr *nextpc); |
266 |
|
m68k_dumpstate(&nextpc); |
267 |
|
#endif |
268 |
+ |
VideoQuitFullScreen(); |
269 |
|
#ifdef ENABLE_MON |
270 |
|
char *arg[4] = {"mon", "-m", "-r", NULL}; |
271 |
|
mon(3, arg); |
274 |
|
return false; |
275 |
|
} |
276 |
|
|
277 |
+ |
|
278 |
|
/* |
279 |
|
* Update display for Windowed mode and VOSF |
280 |
|
*/ |
281 |
|
|
282 |
|
// From video_blit.cpp |
283 |
|
extern void (*Screen_blit)(uint8 * dest, const uint8 * source, uint32 length); |
284 |
< |
extern bool Screen_blitter_init(XVisualInfo * visual_info, bool native_byte_order); |
284 |
> |
extern bool Screen_blitter_init(XVisualInfo * visual_info, bool native_byte_order, video_depth mac_depth); |
285 |
> |
extern uint32 ExpandMap[256]; |
286 |
|
|
287 |
|
/* How can we deal with array overrun conditions ? |
288 |
|
|
317 |
|
than pageCount. |
318 |
|
*/ |
319 |
|
|
320 |
< |
static inline void update_display_window_vosf(void) |
320 |
> |
static inline void update_display_window_vosf(driver_window *drv) |
321 |
|
{ |
322 |
|
int page = 0; |
323 |
|
for (;;) { |
338 |
|
const int y2 = mainBuffer.pageInfo[page - 1].bottom; |
339 |
|
const int height = y2 - y1 + 1; |
340 |
|
|
341 |
< |
const int bytes_per_row = VideoMonitor.mode.bytes_per_row; |
342 |
< |
const int bytes_per_pixel = VideoMonitor.mode.bytes_per_row / VideoMonitor.mode.x; |
343 |
< |
int i = y1 * bytes_per_row, j; |
344 |
< |
|
345 |
< |
if (VideoMonitor.mode.depth == VDEPTH_1BIT) { |
341 |
> |
if (VideoMonitor.mode.depth < VDEPTH_8BIT) { |
342 |
|
|
343 |
|
// Update the_host_buffer and copy of the_buffer |
344 |
+ |
const int src_bytes_per_row = VideoMonitor.mode.bytes_per_row; |
345 |
+ |
const int dst_bytes_per_row = drv->img->bytes_per_line; |
346 |
+ |
const int pixels_per_byte = VideoMonitor.mode.x / src_bytes_per_row; |
347 |
+ |
int i1 = y1 * src_bytes_per_row, i2 = y1 * dst_bytes_per_row, j; |
348 |
|
for (j = y1; j <= y2; j++) { |
349 |
< |
Screen_blit(the_host_buffer + i, the_buffer + i, VideoMonitor.mode.x >> 3); |
350 |
< |
i += bytes_per_row; |
349 |
> |
Screen_blit(the_host_buffer + i2, the_buffer + i1, VideoMonitor.mode.x / pixels_per_byte); |
350 |
> |
i1 += src_bytes_per_row; |
351 |
> |
i2 += dst_bytes_per_row; |
352 |
|
} |
353 |
|
|
354 |
|
} else { |
355 |
|
|
356 |
|
// Update the_host_buffer and copy of the_buffer |
357 |
+ |
const int src_bytes_per_row = VideoMonitor.mode.bytes_per_row; |
358 |
+ |
const int dst_bytes_per_row = drv->img->bytes_per_line; |
359 |
+ |
const int bytes_per_pixel = src_bytes_per_row / VideoMonitor.mode.x; |
360 |
+ |
int i1 = y1 * src_bytes_per_row, i2 = y1 * dst_bytes_per_row, j; |
361 |
|
for (j = y1; j <= y2; j++) { |
362 |
< |
Screen_blit(the_host_buffer + i, the_buffer + i, bytes_per_pixel * VideoMonitor.mode.x); |
363 |
< |
i += bytes_per_row; |
362 |
> |
Screen_blit(the_host_buffer + i2, the_buffer + i1, bytes_per_pixel * VideoMonitor.mode.x); |
363 |
> |
i1 += src_bytes_per_row; |
364 |
> |
i2 += dst_bytes_per_row; |
365 |
|
} |
366 |
|
} |
367 |
|
|
368 |
< |
if (have_shm) |
369 |
< |
XShmPutImage(x_display, the_win, the_gc, img, 0, y1, 0, y1, VideoMonitor.mode.x, height, 0); |
368 |
> |
if (drv->have_shm) |
369 |
> |
XShmPutImage(x_display, drv->w, drv->gc, drv->img, 0, y1, 0, y1, VideoMonitor.mode.x, height, 0); |
370 |
|
else |
371 |
< |
XPutImage(x_display, the_win, the_gc, img, 0, y1, 0, y1, VideoMonitor.mode.x, height); |
371 |
> |
XPutImage(x_display, drv->w, drv->gc, drv->img, 0, y1, 0, y1, VideoMonitor.mode.x, height); |
372 |
|
} |
367 |
– |
|
373 |
|
mainBuffer.dirty = false; |
374 |
|
} |
375 |
|
|
376 |
|
|
377 |
|
/* |
378 |
|
* Update display for DGA mode and VOSF |
379 |
< |
* (only in Direct Addressing mode) |
379 |
> |
* (only in Real or Direct Addressing mode) |
380 |
|
*/ |
381 |
|
|
382 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |