1 |
|
/* |
2 |
|
* video_vosf.h - Video/graphics emulation, video on SEGV signals support |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-2004 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2005 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 |
33 |
|
// Glue for SDL and X11 support |
34 |
|
#ifdef USE_SDL_VIDEO |
35 |
|
#define MONITOR_INIT SDL_monitor_desc &monitor |
36 |
< |
#define VIDEO_DRV_INIT driver_window *drv |
37 |
< |
#define VIDEO_DRV_ROW_BYTES drv->s->pitch |
36 |
> |
#define VIDEO_DRV_WIN_INIT driver_window *drv |
37 |
> |
#define VIDEO_DRV_DGA_INIT driver_fullscreen *drv |
38 |
|
#define VIDEO_DRV_LOCK_PIXELS if (SDL_MUSTLOCK(drv->s)) SDL_LockSurface(drv->s) |
39 |
|
#define VIDEO_DRV_UNLOCK_PIXELS if (SDL_MUSTLOCK(drv->s)) SDL_UnlockSurface(drv->s) |
40 |
+ |
#define VIDEO_DRV_DEPTH drv->s->format->BitsPerPixel |
41 |
+ |
#define VIDEO_DRV_WIDTH drv->s->w |
42 |
+ |
#define VIDEO_DRV_HEIGHT drv->s->h |
43 |
+ |
#define VIDEO_DRV_ROW_BYTES drv->s->pitch |
44 |
|
#else |
45 |
|
#ifdef SHEEPSHAVER |
46 |
|
#define MONITOR_INIT /* nothing */ |
47 |
< |
#define VIDEO_DRV_INIT /* nothing */ |
47 |
> |
#define VIDEO_DRV_WIN_INIT /* nothing */ |
48 |
> |
#define VIDEO_DRV_DGA_INIT /* nothing */ |
49 |
|
#define VIDEO_DRV_WINDOW the_win |
50 |
|
#define VIDEO_DRV_GC the_gc |
51 |
|
#define VIDEO_DRV_IMAGE img |
52 |
|
#define VIDEO_DRV_HAVE_SHM have_shm |
53 |
|
#else |
54 |
|
#define MONITOR_INIT X11_monitor_desc &monitor |
55 |
< |
#define VIDEO_DRV_INIT driver_window *drv |
55 |
> |
#define VIDEO_DRV_WIN_INIT driver_window *drv |
56 |
> |
#define VIDEO_DRV_DGA_INIT driver_dga *drv |
57 |
|
#define VIDEO_DRV_WINDOW drv->w |
58 |
|
#define VIDEO_DRV_GC drv->gc |
59 |
|
#define VIDEO_DRV_IMAGE drv->img |
61 |
|
#endif |
62 |
|
#define VIDEO_DRV_LOCK_PIXELS /* nothing */ |
63 |
|
#define VIDEO_DRV_UNLOCK_PIXELS /* nothing */ |
64 |
+ |
#define VIDEO_DRV_DEPTH VIDEO_DRV_IMAGE->depth |
65 |
+ |
#define VIDEO_DRV_WIDTH VIDEO_DRV_IMAGE->width |
66 |
+ |
#define VIDEO_DRV_HEIGHT VIDEO_DRV_IMAGE->height |
67 |
|
#define VIDEO_DRV_ROW_BYTES VIDEO_DRV_IMAGE->bytes_per_line |
68 |
|
#endif |
69 |
|
|
83 |
|
uint32 pageCount; // Number of pages allocated to the screen |
84 |
|
|
85 |
|
bool dirty; // Flag: set if the frame buffer was touched |
86 |
+ |
bool very_dirty; // Flag: set if the frame buffer was completely modified (e.g. colormap changes) |
87 |
|
char * dirtyPages; // Table of flags set if page was altered |
88 |
|
ScreenPageInfo * pageInfo; // Table of mappings page -> Mac scanlines |
89 |
|
}; |
129 |
|
#define PFLAG_CLEAR_ALL do { \ |
130 |
|
PFLAG_CLEAR_RANGE(0, mainBuffer.pageCount); \ |
131 |
|
mainBuffer.dirty = false; \ |
132 |
+ |
mainBuffer.very_dirty = false; \ |
133 |
+ |
} while (0) |
134 |
+ |
|
135 |
+ |
#define PFLAG_SET_VERY_DIRTY do { \ |
136 |
+ |
mainBuffer.very_dirty = true; \ |
137 |
|
} while (0) |
138 |
|
|
139 |
|
// Set the following macro definition to 1 if your system |
199 |
|
// Extend size to page boundary |
200 |
|
static uint32 page_extend(uint32 size) |
201 |
|
{ |
202 |
< |
const uint32 page_size = vm_page_size(); |
202 |
> |
const uint32 page_size = vm_get_page_size(); |
203 |
|
const uint32 page_mask = page_size - 1; |
204 |
|
return (size + page_mask) & ~page_mask; |
205 |
|
} |
247 |
|
{ |
248 |
|
VIDEO_MODE_INIT_MONITOR; |
249 |
|
|
250 |
< |
const uintptr page_size = vm_page_size(); |
250 |
> |
const uintptr page_size = vm_get_page_size(); |
251 |
|
const uintptr page_mask = page_size - 1; |
252 |
|
|
253 |
|
// Round up frame buffer base to page boundary |
385 |
|
than pageCount. |
386 |
|
*/ |
387 |
|
|
388 |
< |
static inline void update_display_window_vosf(VIDEO_DRV_INIT) |
388 |
> |
static void update_display_window_vosf(VIDEO_DRV_WIN_INIT) |
389 |
|
{ |
390 |
|
VIDEO_MODE_INIT; |
391 |
|
|
408 |
|
const int y2 = mainBuffer.pageInfo[page - 1].bottom; |
409 |
|
const int height = y2 - y1 + 1; |
410 |
|
|
411 |
+ |
// Update the_host_buffer |
412 |
|
VIDEO_DRV_LOCK_PIXELS; |
413 |
< |
|
414 |
< |
if ((int)VIDEO_MODE_DEPTH < VIDEO_DEPTH_8BIT) { |
415 |
< |
|
416 |
< |
// Update the_host_buffer and copy of the_buffer |
417 |
< |
const int src_bytes_per_row = VIDEO_MODE_ROW_BYTES; |
418 |
< |
const int dst_bytes_per_row = VIDEO_DRV_ROW_BYTES; |
419 |
< |
const int pixels_per_byte = VIDEO_MODE_X / src_bytes_per_row; |
404 |
< |
int i1 = y1 * src_bytes_per_row, i2 = y1 * dst_bytes_per_row, j; |
405 |
< |
for (j = y1; j <= y2; j++) { |
406 |
< |
Screen_blit(the_host_buffer + i2, the_buffer + i1, VIDEO_MODE_X / pixels_per_byte); |
407 |
< |
i1 += src_bytes_per_row; |
408 |
< |
i2 += dst_bytes_per_row; |
409 |
< |
} |
410 |
< |
|
411 |
< |
} else { |
412 |
< |
|
413 |
< |
// Update the_host_buffer and copy of the_buffer |
414 |
< |
const int src_bytes_per_row = VIDEO_MODE_ROW_BYTES; |
415 |
< |
const int dst_bytes_per_row = VIDEO_DRV_ROW_BYTES; |
416 |
< |
const int bytes_per_pixel = src_bytes_per_row / VIDEO_MODE_X; |
417 |
< |
int i1 = y1 * src_bytes_per_row, i2 = y1 * dst_bytes_per_row, j; |
418 |
< |
for (j = y1; j <= y2; j++) { |
419 |
< |
Screen_blit(the_host_buffer + i2, the_buffer + i1, bytes_per_pixel * VIDEO_MODE_X); |
420 |
< |
i1 += src_bytes_per_row; |
421 |
< |
i2 += dst_bytes_per_row; |
422 |
< |
} |
413 |
> |
const int src_bytes_per_row = VIDEO_MODE_ROW_BYTES; |
414 |
> |
const int dst_bytes_per_row = VIDEO_DRV_ROW_BYTES; |
415 |
> |
int i1 = y1 * src_bytes_per_row, i2 = y1 * dst_bytes_per_row, j; |
416 |
> |
for (j = y1; j <= y2; j++) { |
417 |
> |
Screen_blit(the_host_buffer + i2, the_buffer + i1, src_bytes_per_row); |
418 |
> |
i1 += src_bytes_per_row; |
419 |
> |
i2 += dst_bytes_per_row; |
420 |
|
} |
424 |
– |
|
421 |
|
VIDEO_DRV_UNLOCK_PIXELS; |
422 |
|
|
423 |
|
#ifdef USE_SDL_VIDEO |
439 |
|
*/ |
440 |
|
|
441 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
442 |
< |
static inline void update_display_dga_vosf(void) |
442 |
> |
static void update_display_dga_vosf(VIDEO_DRV_DGA_INIT) |
443 |
|
{ |
444 |
|
VIDEO_MODE_INIT; |
445 |
|
|
446 |
< |
int page = 0; |
446 |
> |
// Compute number of bytes per row, take care to virtual screens |
447 |
> |
const int src_bytes_per_row = VIDEO_MODE_ROW_BYTES; |
448 |
> |
const int dst_bytes_per_row = TrivialBytesPerRow(VIDEO_MODE_X, DepthModeForPixelDepth(VIDEO_DRV_DEPTH)); |
449 |
> |
const int scr_bytes_per_row = VIDEO_DRV_ROW_BYTES; |
450 |
> |
assert(dst_bytes_per_row <= scr_bytes_per_row); |
451 |
> |
const int scr_bytes_left = scr_bytes_per_row - dst_bytes_per_row; |
452 |
> |
|
453 |
> |
// Full screen update requested? |
454 |
> |
if (mainBuffer.very_dirty) { |
455 |
> |
PFLAG_CLEAR_ALL; |
456 |
> |
vm_protect((char *)mainBuffer.memStart, mainBuffer.memLength, VM_PAGE_READ); |
457 |
> |
memcpy(the_buffer_copy, the_buffer, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y); |
458 |
> |
VIDEO_DRV_LOCK_PIXELS; |
459 |
> |
int i1 = 0, i2 = 0; |
460 |
> |
for (int j = 0; j < VIDEO_MODE_Y; j++) { |
461 |
> |
Screen_blit(the_host_buffer + i2, the_buffer + i1, src_bytes_per_row); |
462 |
> |
i1 += src_bytes_per_row; |
463 |
> |
i2 += scr_bytes_per_row; |
464 |
> |
} |
465 |
> |
#ifdef USE_SDL_VIDEO |
466 |
> |
SDL_UpdateRect(drv->s, 0, 0, VIDEO_MODE_X, VIDEO_MODE_Y); |
467 |
> |
#endif |
468 |
> |
VIDEO_DRV_UNLOCK_PIXELS; |
469 |
> |
return; |
470 |
> |
} |
471 |
> |
|
472 |
> |
// Setup partial blitter (use 64-pixel wide chunks) |
473 |
> |
const int n_pixels = 64; |
474 |
> |
const int n_chunks = VIDEO_MODE_X / n_pixels; |
475 |
> |
const int n_pixels_left = VIDEO_MODE_X - (n_chunks * n_pixels); |
476 |
> |
const int src_chunk_size = src_bytes_per_row / n_chunks; |
477 |
> |
const int dst_chunk_size = dst_bytes_per_row / n_chunks; |
478 |
> |
const int src_chunk_size_left = src_bytes_per_row - (n_chunks * src_chunk_size); |
479 |
> |
const int dst_chunk_size_left = dst_bytes_per_row - (n_chunks * dst_chunk_size); |
480 |
> |
|
481 |
> |
int page = 0, last_scanline = -1; |
482 |
|
for (;;) { |
483 |
|
const unsigned first_page = find_next_page_set(page); |
484 |
|
if (first_page >= mainBuffer.pageCount) |
491 |
|
const int32 offset = first_page << mainBuffer.pageBits; |
492 |
|
const uint32 length = (page - first_page) << mainBuffer.pageBits; |
493 |
|
vm_protect((char *)mainBuffer.memStart + offset, length, VM_PAGE_READ); |
494 |
< |
|
495 |
< |
// I am sure that y2 >= y1 and depth != 1 |
496 |
< |
const int y1 = mainBuffer.pageInfo[first_page].top; |
497 |
< |
const int y2 = mainBuffer.pageInfo[page - 1].bottom; |
498 |
< |
|
499 |
< |
const int bytes_per_row = VIDEO_MODE_ROW_BYTES; |
500 |
< |
const int bytes_per_pixel = VIDEO_MODE_ROW_BYTES / VIDEO_MODE_X; |
501 |
< |
int i, j; |
502 |
< |
|
503 |
< |
// Check for first column from left and first column |
504 |
< |
// from right that have changed |
505 |
< |
int x1 = VIDEO_MODE_X * bytes_per_pixel - 1; |
506 |
< |
for (j = y1; j <= y2; j++) { |
507 |
< |
uint8 * const p1 = &the_buffer[j * bytes_per_row]; |
508 |
< |
uint8 * const p2 = &the_buffer_copy[j * bytes_per_row]; |
509 |
< |
for (i = 0; i < x1; i++) { |
510 |
< |
if (p1[i] != p2[i]) { |
511 |
< |
x1 = i; |
512 |
< |
break; |
494 |
> |
|
495 |
> |
// Optimized for scanlines, don't process overlapping lines again |
496 |
> |
int y1 = mainBuffer.pageInfo[first_page].top; |
497 |
> |
int y2 = mainBuffer.pageInfo[page - 1].bottom; |
498 |
> |
if (y1 <= last_scanline && ++y1 >= VIDEO_MODE_Y) |
499 |
> |
continue; |
500 |
> |
if (y2 <= last_scanline && ++y2 >= VIDEO_MODE_Y) |
501 |
> |
continue; |
502 |
> |
last_scanline = y2; |
503 |
> |
|
504 |
> |
// Update the_host_buffer and copy of the_buffer, one line at a time |
505 |
> |
int i1 = y1 * src_bytes_per_row; |
506 |
> |
int i2 = y1 * scr_bytes_per_row; |
507 |
> |
#ifdef USE_SDL_VIDEO |
508 |
> |
int bbi = 0; |
509 |
> |
SDL_Rect bb[3] = { |
510 |
> |
{ VIDEO_MODE_X, y1, 0, 0 }, |
511 |
> |
{ VIDEO_MODE_X, -1, 0, 0 }, |
512 |
> |
{ VIDEO_MODE_X, -1, 0, 0 } |
513 |
> |
}; |
514 |
> |
#endif |
515 |
> |
VIDEO_DRV_LOCK_PIXELS; |
516 |
> |
for (int j = y1; j <= y2; j++) { |
517 |
> |
for (int i = 0; i < n_chunks; i++) { |
518 |
> |
if (memcmp(the_buffer_copy + i1, the_buffer + i1, src_chunk_size) != 0) { |
519 |
> |
memcpy(the_buffer_copy + i1, the_buffer + i1, src_chunk_size); |
520 |
> |
Screen_blit(the_host_buffer + i2, the_buffer + i1, src_chunk_size); |
521 |
> |
#ifdef USE_SDL_VIDEO |
522 |
> |
const int x = i * n_pixels; |
523 |
> |
if (x < bb[bbi].x) { |
524 |
> |
if (bb[bbi].w) |
525 |
> |
bb[bbi].w += bb[bbi].x - x; |
526 |
> |
else |
527 |
> |
bb[bbi].w = n_pixels; |
528 |
> |
bb[bbi].x = x; |
529 |
> |
} |
530 |
> |
else if (x >= bb[bbi].x + bb[bbi].w) |
531 |
> |
bb[bbi].w = x + n_pixels - bb[bbi].x; |
532 |
> |
#endif |
533 |
|
} |
534 |
+ |
i1 += src_chunk_size; |
535 |
+ |
i2 += dst_chunk_size; |
536 |
|
} |
537 |
< |
} |
538 |
< |
x1 /= bytes_per_pixel; |
539 |
< |
|
540 |
< |
int x2 = x1 * bytes_per_pixel; |
488 |
< |
for (j = y2; j >= y1; j--) { |
489 |
< |
uint8 * const p1 = &the_buffer[j * bytes_per_row]; |
490 |
< |
uint8 * const p2 = &the_buffer_copy[j * bytes_per_row]; |
491 |
< |
for (i = VIDEO_MODE_X * bytes_per_pixel - 1; i > x2; i--) { |
492 |
< |
if (p1[i] != p2[i]) { |
493 |
< |
x2 = i; |
494 |
< |
break; |
537 |
> |
if (src_chunk_size_left && dst_chunk_size_left) { |
538 |
> |
if (memcmp(the_buffer_copy + i1, the_buffer + i1, src_chunk_size_left) != 0) { |
539 |
> |
memcpy(the_buffer_copy + i1, the_buffer + i1, src_chunk_size_left); |
540 |
> |
Screen_blit(the_host_buffer + i2, the_buffer + i1, src_chunk_size_left); |
541 |
|
} |
542 |
+ |
i1 += src_chunk_size_left; |
543 |
+ |
i2 += dst_chunk_size_left; |
544 |
+ |
#ifdef USE_SDL_VIDEO |
545 |
+ |
const int x = n_chunks * n_pixels; |
546 |
+ |
if (x < bb[bbi].x) { |
547 |
+ |
if (bb[bbi].w) |
548 |
+ |
bb[bbi].w += bb[bbi].x - x; |
549 |
+ |
else |
550 |
+ |
bb[bbi].w = n_pixels_left; |
551 |
+ |
bb[bbi].x = x; |
552 |
+ |
} |
553 |
+ |
else if (x >= bb[bbi].x + bb[bbi].w) |
554 |
+ |
bb[bbi].w = x + n_pixels_left - bb[bbi].x; |
555 |
+ |
#endif |
556 |
|
} |
557 |
+ |
i2 += scr_bytes_left; |
558 |
+ |
#ifdef USE_SDL_VIDEO |
559 |
+ |
bb[bbi].h++; |
560 |
+ |
if (bb[bbi].w && (j == y1 || j == y2 - 1 || j == y2)) { |
561 |
+ |
bbi++; |
562 |
+ |
assert(bbi <= 3); |
563 |
+ |
if (j != y2) |
564 |
+ |
bb[bbi].y = j + 1; |
565 |
+ |
} |
566 |
+ |
#endif |
567 |
|
} |
568 |
< |
x2 /= bytes_per_pixel; |
569 |
< |
|
570 |
< |
// Update the_host_buffer and copy of the_buffer |
501 |
< |
// There should be at least one pixel to copy |
502 |
< |
VIDEO_DRV_LOCK_PIXELS; |
503 |
< |
const int width = x2 - x1 + 1; |
504 |
< |
i = y1 * bytes_per_row + x1 * bytes_per_pixel; |
505 |
< |
for (j = y1; j <= y2; j++) { |
506 |
< |
Screen_blit(the_host_buffer + i, the_buffer + i, bytes_per_pixel * width); |
507 |
< |
memcpy(the_buffer_copy + i, the_buffer + i, bytes_per_pixel * width); |
508 |
< |
i += bytes_per_row; |
509 |
< |
} |
568 |
> |
#ifdef USE_SDL_VIDEO |
569 |
> |
SDL_UpdateRects(drv->s, bbi, bb); |
570 |
> |
#endif |
571 |
|
VIDEO_DRV_UNLOCK_PIXELS; |
572 |
|
} |
573 |
|
mainBuffer.dirty = false; |