260 |
|
} |
261 |
|
|
262 |
|
#if defined(HAVE_SIGINFO_T) |
263 |
+ |
|
264 |
|
static void Screen_fault_handler(int, siginfo_t * sip, void *) |
265 |
|
{ |
266 |
|
D(bug("Screen_fault_handler: ADDR=0x%08X\n", sip->si_addr)); |
267 |
|
do_handle_screen_fault((uintptr)sip->si_addr); |
268 |
|
} |
269 |
+ |
|
270 |
|
#elif defined(HAVE_SIGCONTEXT_SUBTERFUGE) |
271 |
+ |
|
272 |
|
# if defined(__i386__) && defined(__linux__) |
273 |
|
static void Screen_fault_handler(int, struct sigcontext scs) |
274 |
|
{ |
275 |
|
D(bug("Screen_fault_handler: ADDR=0x%08X from IP=0x%08X\n", scs.cr2, scs.eip)); |
276 |
|
do_handle_screen_fault((uintptr)scs.cr2); |
277 |
|
} |
278 |
+ |
|
279 |
+ |
# elif defined(__m68k__) && defined(__NetBSD__) |
280 |
+ |
|
281 |
+ |
# include <m68k/frame.h> |
282 |
+ |
static void Screen_fault_handler(int, int code, struct sigcontext *scp) |
283 |
+ |
{ |
284 |
+ |
D(bug("Screen_fault_handler: ADDR=0x%08X\n", code)); |
285 |
+ |
struct sigstate { |
286 |
+ |
int ss_flags; |
287 |
+ |
struct frame ss_frame; |
288 |
+ |
}; |
289 |
+ |
struct sigstate *state = (struct sigstate *)scp->sc_ap; |
290 |
+ |
uintptr fault_addr; |
291 |
+ |
switch (state->ss_frame.f_format) { |
292 |
+ |
case 7: // 68040 access error |
293 |
+ |
// "code" is sometimes unreliable (i.e. contains NULL or a bogus address), reason unknown |
294 |
+ |
fault_addr = state->ss_frame.f_fmt7.f_fa; |
295 |
+ |
break; |
296 |
+ |
default: |
297 |
+ |
fault_addr = (uintptr)code; |
298 |
+ |
break; |
299 |
+ |
} |
300 |
+ |
do_handle_screen_fault(fault_addr); |
301 |
+ |
} |
302 |
+ |
|
303 |
|
# else |
304 |
|
# error "No suitable subterfuge for Video on SEGV signals" |
305 |
|
# endif |
318 |
|
// Setup SIGSEGV handler to process writes to frame buffer |
319 |
|
sigemptyset(&vosf_sa.sa_mask); |
320 |
|
vosf_sa.sa_sigaction = Screen_fault_handler; |
321 |
< |
vosf_sa.sa_flags = 0; |
321 |
> |
vosf_sa.sa_flags = SA_SIGINFO; |
322 |
|
return (sigaction(SIGSEGV, &vosf_sa, NULL) == 0); |
323 |
|
} |
324 |
|
#elif defined(HAVE_SIGCONTEXT_SUBTERFUGE) |
327 |
|
// Setup SIGSEGV handler to process writes to frame buffer |
328 |
|
sigemptyset(&vosf_sa.sa_mask); |
329 |
|
vosf_sa.sa_handler = (void (*)(int)) Screen_fault_handler; |
330 |
+ |
#if !EMULATED_68K && defined(__NetBSD__) |
331 |
+ |
sigaddset(&vosf_sa.sa_mask, SIGALRM); |
332 |
+ |
vosf_sa.sa_flags = SA_ONSTACK; |
333 |
+ |
#else |
334 |
|
vosf_sa.sa_flags = 0; |
335 |
+ |
#endif |
336 |
|
return (sigaction(SIGSEGV, &vosf_sa, NULL) == 0); |
337 |
|
} |
338 |
|
#endif |
360 |
|
PFLAG_CLEAR(page); |
361 |
|
++page; |
362 |
|
} |
363 |
< |
|
363 |
> |
|
364 |
|
// Make the dirty pages read-only again |
365 |
|
const int32 offset = first_page << mainBuffer.pageBits; |
366 |
|
const uint32 length = (page - first_page) << mainBuffer.pageBits; |
377 |
|
|
378 |
|
// Check for first column from left and first column |
379 |
|
// from right that have changed |
380 |
< |
int x1 = VideoMonitor.x * bytes_per_pixel - 1; |
381 |
< |
for (j = y1; j <= y2; j++) { |
382 |
< |
uint8 * const p1 = &the_buffer[j * bytes_per_row]; |
383 |
< |
uint8 * const p2 = &the_buffer_copy[j * bytes_per_row]; |
384 |
< |
for (i = 0; i < x1; i++) { |
385 |
< |
if (p1[i] != p2[i]) { |
386 |
< |
x1 = i; |
387 |
< |
break; |
380 |
> |
int x1, x2, width; |
381 |
> |
if (depth == 1) { |
382 |
> |
|
383 |
> |
x1 = VideoMonitor.x - 1; |
384 |
> |
for (j = y1; j <= y2; j++) { |
385 |
> |
uint8 * const p1 = &the_buffer[j * bytes_per_row]; |
386 |
> |
uint8 * const p2 = &the_buffer_copy[j * bytes_per_row]; |
387 |
> |
for (i = 0; i < (x1>>3); i++) { |
388 |
> |
if (p1[i] != p2[i]) { |
389 |
> |
x1 = i << 3; |
390 |
> |
break; |
391 |
> |
} |
392 |
|
} |
393 |
|
} |
394 |
< |
} |
395 |
< |
x1 /= bytes_per_pixel; |
396 |
< |
|
397 |
< |
int x2 = x1 * bytes_per_pixel; |
398 |
< |
for (j = y2; j >= y1; j--) { |
399 |
< |
uint8 * const p1 = &the_buffer[j * bytes_per_row]; |
400 |
< |
uint8 * const p2 = &the_buffer_copy[j * bytes_per_row]; |
401 |
< |
for (i = VideoMonitor.x * bytes_per_pixel - 1; i > x2; i--) { |
402 |
< |
if (p1[i] != p2[i]) { |
403 |
< |
x2 = i; |
367 |
< |
break; |
394 |
> |
|
395 |
> |
x2 = x1; |
396 |
> |
for (j = y2; j >= y1; j--) { |
397 |
> |
uint8 * const p1 = &the_buffer[j * bytes_per_row]; |
398 |
> |
uint8 * const p2 = &the_buffer_copy[j * bytes_per_row]; |
399 |
> |
for (i = (VideoMonitor.x>>3) - 1; i > (x2>>3); i--) { |
400 |
> |
if (p1[i] != p2[i]) { |
401 |
> |
x2 = (i << 3) + 7; |
402 |
> |
break; |
403 |
> |
} |
404 |
|
} |
405 |
|
} |
406 |
< |
} |
407 |
< |
x2 /= bytes_per_pixel; |
406 |
> |
width = x2 - x1 + 1; |
407 |
> |
|
408 |
> |
// Update the_host_buffer and copy of the_buffer |
409 |
> |
i = y1 * bytes_per_row + (x1 >> 3); |
410 |
> |
for (j = y1; j <= y2; j++) { |
411 |
> |
do_update_framebuffer(the_host_buffer + i, the_buffer + i, width >> 3); |
412 |
> |
memcpy(the_buffer_copy + i, the_buffer + i, width >> 3); |
413 |
> |
i += bytes_per_row; |
414 |
> |
} |
415 |
> |
|
416 |
> |
} else { |
417 |
> |
|
418 |
> |
x1 = VideoMonitor.x * bytes_per_pixel - 1; |
419 |
> |
for (j = y1; j <= y2; j++) { |
420 |
> |
uint8 * const p1 = &the_buffer[j * bytes_per_row]; |
421 |
> |
uint8 * const p2 = &the_buffer_copy[j * bytes_per_row]; |
422 |
> |
for (i = 0; i < x1; i++) { |
423 |
> |
if (p1[i] != p2[i]) { |
424 |
> |
x1 = i; |
425 |
> |
break; |
426 |
> |
} |
427 |
> |
} |
428 |
> |
} |
429 |
> |
x1 /= bytes_per_pixel; |
430 |
|
|
431 |
< |
// Update the_host_buffer and copy of the_buffer |
432 |
< |
// There is at least one pixel to copy |
433 |
< |
const int width = x2 - x1 + 1; |
434 |
< |
i = y1 * bytes_per_row + x1 * bytes_per_pixel; |
435 |
< |
for (j = y1; j <= y2; j++) { |
436 |
< |
do_update_framebuffer(the_host_buffer + i, the_buffer + i, bytes_per_pixel * width); |
437 |
< |
memcpy(the_buffer_copy + i, the_buffer + i, bytes_per_pixel * width); |
438 |
< |
i += bytes_per_row; |
431 |
> |
x2 = x1 * bytes_per_pixel; |
432 |
> |
for (j = y2; j >= y1; j--) { |
433 |
> |
uint8 * const p1 = &the_buffer[j * bytes_per_row]; |
434 |
> |
uint8 * const p2 = &the_buffer_copy[j * bytes_per_row]; |
435 |
> |
for (i = VideoMonitor.x * bytes_per_pixel - 1; i > x2; i--) { |
436 |
> |
if (p1[i] != p2[i]) { |
437 |
> |
x2 = i; |
438 |
> |
break; |
439 |
> |
} |
440 |
> |
} |
441 |
> |
} |
442 |
> |
x2 /= bytes_per_pixel; |
443 |
> |
width = x2 - x1 + 1; |
444 |
> |
|
445 |
> |
// Update the_host_buffer and copy of the_buffer |
446 |
> |
i = y1 * bytes_per_row + x1 * bytes_per_pixel; |
447 |
> |
for (j = y1; j <= y2; j++) { |
448 |
> |
do_update_framebuffer(the_host_buffer + i, the_buffer + i, bytes_per_pixel * width); |
449 |
> |
memcpy(the_buffer_copy + i, the_buffer + i, bytes_per_pixel * width); |
450 |
> |
i += bytes_per_row; |
451 |
> |
} |
452 |
|
} |
453 |
|
|
454 |
|
if (have_shm) |