25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: dev_fb.c,v 1.99 2005/06/26 13:49:06 debug Exp $ |
* $Id: dev_fb.c,v 1.110 2005/11/13 00:14:08 debug Exp $ |
29 |
* |
* |
30 |
* Generic framebuffer device. |
* Generic framebuffer device. |
31 |
* |
* |
32 |
* DECstation VFB01 monochrome framebuffer, 1024x864 |
* DECstation VFB01 monochrome framebuffer, 1024x864 |
33 |
* DECstation VFB02 8-bit color framebuffer, 1024x864 |
* DECstation VFB02 8-bit color framebuffer, 1024x864 |
34 |
* DECstation Maxine, 1024x768 8-bit color |
* DECstation Maxine, 1024x768 8-bit color |
35 |
* HPCmips framebuffer |
* HPC (mips, arm, ..) framebuffer |
36 |
* Playstation 2 (24-bit color) |
* Playstation 2 (24-bit color) |
37 |
* generic (any resolution, several bit depths possible) |
* generic (any resolution, several bit depths possible) |
38 |
* |
* |
67 |
|
|
68 |
#define FB_TICK_SHIFT 18 |
#define FB_TICK_SHIFT 18 |
69 |
|
|
|
#define LOGO_XSIZE 256 |
|
|
#define LOGO_YSIZE 256 |
|
|
#define LOGO_BOTTOM_MARGIN 60 |
|
|
/* This must be a 256*256 pixels P4 ppm: */ |
|
|
#include "fb_logo.c" |
|
|
unsigned char *fb_logo = fb_logo_ppm + 11; |
|
|
|
|
70 |
|
|
71 |
/* #define FB_DEBUG */ |
/* #define FB_DEBUG */ |
72 |
|
|
291 |
|
|
292 |
#ifdef WITH_X11 |
#ifdef WITH_X11 |
293 |
#define macro_put_pixel() { \ |
#define macro_put_pixel() { \ |
294 |
/* Combine the color into an X11 long and display it: */ \ |
/* Combine the color into an X11 long and display it: */ \ |
295 |
/* TODO: construct color in a more portable way: */ \ |
/* TODO: construct color in a more portable way: */ \ |
296 |
switch (d->fb_window->x11_screen_depth) { \ |
switch (d->fb_window->x11_screen_depth) { \ |
297 |
case 24: \ |
case 24: \ |
298 |
if (d->fb_window->fb_ximage->byte_order) \ |
if (d->fb_window->fb_ximage->byte_order) \ |
299 |
color = (b << 16) + (g << 8) + r; \ |
color = (b << 16) + (g << 8) + r; \ |
300 |
else \ |
else \ |
301 |
color = (r << 16) + (g << 8) + b; \ |
color = (r << 16) + (g << 8) + b; \ |
302 |
break; \ |
break; \ |
303 |
case 16: \ |
case 16: \ |
304 |
r >>= 3; g >>= 2; b >>= 3; \ |
r >>= 3; g >>= 2; b >>= 3; \ |
305 |
if (d->fb_window->fb_ximage->byte_order) { \ |
if (d->fb_window->fb_ximage->byte_order) { \ |
306 |
/* Big endian 16-bit X server: */ \ |
/* Big endian 16-bit X server: */ \ |
307 |
static int first = 1; \ |
static int first = 1; \ |
308 |
if (first) { \ |
if (first) { \ |
309 |
fprintf(stderr, "\n*** Please report to the author whether 16-bit X11 colors are rendered correctly or not!\n\n"); \ |
fprintf(stderr, "\n*** Please report " \ |
310 |
first = 0; \ |
"to the author whether 16-bit X11 " \ |
311 |
} \ |
"colors are rendered correctly or " \ |
312 |
color = (b << 11) + (g << 5) + r; \ |
"not!\n\n"); \ |
313 |
} else { \ |
first = 0; \ |
314 |
/* Little endian (eg PC) X servers: */ \ |
} \ |
315 |
color = (r << 11) + (g << 5) + b; \ |
color = (b << 11) + (g << 5) + r; \ |
316 |
} \ |
} else { \ |
317 |
break; \ |
/* Little endian (eg PC) X servers: */ \ |
318 |
case 15: \ |
color = (r << 11) + (g << 5) + b; \ |
319 |
r >>= 3; g >>= 3; b >>= 3; \ |
} \ |
320 |
if (d->fb_window->fb_ximage->byte_order) { \ |
break; \ |
321 |
/* Big endian 15-bit X server: */ \ |
case 15: \ |
322 |
static int first = 1; \ |
r >>= 3; g >>= 3; b >>= 3; \ |
323 |
if (first) { \ |
if (d->fb_window->fb_ximage->byte_order) { \ |
324 |
fprintf(stderr, "\n*** Please report to the author whether 15-bit X11 colors are rendered correctly or not!\n\n"); \ |
/* Big endian 15-bit X server: */ \ |
325 |
first = 0; \ |
static int first = 1; \ |
326 |
} \ |
if (first) { \ |
327 |
color = (b << 10) + (g << 5) + r; \ |
fprintf(stderr, "\n*** Please report " \ |
328 |
} else { \ |
"to the author whether 15-bit X11 " \ |
329 |
/* Little endian (eg PC) X servers: */ \ |
"colors are rendered correctly or " \ |
330 |
color = (r << 10) + (g << 5) + b; \ |
"not!\n\n"); \ |
331 |
} \ |
first = 0; \ |
332 |
break; \ |
} \ |
333 |
default: \ |
color = (b << 10) + (g << 5) + r; \ |
334 |
color = d->fb_window->x11_graycolor[15 * (r + g + b) / (255 * 3)].pixel; \ |
} else { \ |
335 |
} \ |
/* Little endian (eg PC) X servers: */ \ |
336 |
if (x>=0 && x<d->x11_xsize && y>=0 && y<d->x11_ysize) \ |
color = (r << 10) + (g << 5) + b; \ |
337 |
XPutPixel(d->fb_window->fb_ximage, x, y, color); \ |
} \ |
338 |
} |
break; \ |
339 |
|
default: \ |
340 |
|
color = d->fb_window->x11_graycolor[15 * (r + g + b) \ |
341 |
|
/ (255 * 3)].pixel; \ |
342 |
|
} \ |
343 |
|
if (x>=0 && x<d->x11_xsize && y>=0 && y<d->x11_ysize) \ |
344 |
|
XPutPixel(d->fb_window->fb_ximage, x, y, color); \ |
345 |
|
} |
346 |
#else |
#else |
347 |
/* If not WITH_X11: */ |
/* If not WITH_X11: */ |
348 |
#define macro_put_pixel() { } |
#define macro_put_pixel() { } |
388 |
c = d->framebuffer[fb_addr >> 3]; |
c = d->framebuffer[fb_addr >> 3]; |
389 |
fb_addr &= 7; |
fb_addr &= 7; |
390 |
|
|
391 |
/* HPCmips is reverse: */ |
/* HPC is reverse: */ |
392 |
if (d->vfb_type == VFB_HPCMIPS) |
if (d->vfb_type == VFB_HPC) |
393 |
fb_addr = 8 - d->bit_depth - fb_addr; |
fb_addr = 8 - d->bit_depth - fb_addr; |
394 |
|
|
395 |
c = (c >> fb_addr) & ((1<<d->bit_depth) - 1); |
c = (c >> fb_addr) & ((1<<d->bit_depth) - 1); |
435 |
break; |
break; |
436 |
/* TODO: copy to the scaledown code below */ |
/* TODO: copy to the scaledown code below */ |
437 |
case 16: |
case 16: |
438 |
if (d->vfb_type == VFB_HPCMIPS) { |
if (d->vfb_type == VFB_HPC) { |
439 |
b = d->framebuffer[fb_addr] + |
b = d->framebuffer[fb_addr] + |
440 |
(d->framebuffer[fb_addr+1] << 8); |
(d->framebuffer[fb_addr+1] |
441 |
|
<< 8); |
442 |
|
|
443 |
if (d->color32k) { |
if (d->color32k) { |
444 |
r = b >> 11; |
r = b >> 11; |
459 |
b = b & 0x1f; |
b = b & 0x1f; |
460 |
} |
} |
461 |
} else { |
} else { |
462 |
r = d->framebuffer[fb_addr] >> 3; |
r = d->framebuffer[fb_addr] >> 3; |
463 |
g = (d->framebuffer[fb_addr] << 5) + |
g = (d->framebuffer[fb_addr] << 5) + |
464 |
(d->framebuffer[fb_addr + 1] >> 5); |
(d->framebuffer[fb_addr + 1] >>5); |
465 |
b = d->framebuffer[fb_addr + 1] & 0x1f; |
b = d->framebuffer[fb_addr + 1]&31; |
466 |
} |
} |
467 |
|
|
468 |
r *= 8; |
r *= 8; |
481 |
return; |
return; |
482 |
} |
} |
483 |
|
|
484 |
/* scaledown != 1: */ |
/* scaledown > 1: */ |
485 |
|
|
486 |
scaledown = d->vfb_scaledown; |
scaledown = d->vfb_scaledown; |
487 |
scaledownXscaledown = scaledown * scaledown; |
scaledownXscaledown = scaledown * scaledown; |
521 |
c = d->framebuffer[fb_addr >> 3]; |
c = d->framebuffer[fb_addr >> 3]; |
522 |
fb_addr &= 7; |
fb_addr &= 7; |
523 |
|
|
524 |
/* HPCmips is reverse: */ |
/* HPC is reverse: */ |
525 |
if (d->vfb_type == VFB_HPCMIPS) |
if (d->vfb_type == VFB_HPC) |
526 |
fb_addr = 8 - d->bit_depth - fb_addr; |
fb_addr = 8 - d->bit_depth - fb_addr; |
527 |
|
|
528 |
c = (c >> fb_addr) & ((1<<d->bit_depth) - 1); |
c = (c >> fb_addr) & ((1<<d->bit_depth) - 1); |
624 |
if (!cpu->machine->use_x11) |
if (!cpu->machine->use_x11) |
625 |
return; |
return; |
626 |
|
|
|
#ifdef BINTRANS |
|
627 |
do { |
do { |
628 |
uint64_t low = -1, high; |
uint64_t high, low = (uint64_t)(int64_t) -1; |
629 |
int x, y; |
int x, y; |
630 |
|
|
631 |
memory_device_bintrans_access(cpu, cpu->mem, |
memory_device_dyntrans_access(cpu, cpu->mem, |
632 |
extra, &low, &high); |
extra, &low, &high); |
633 |
if ((int64_t)low == -1) |
if ((int64_t)low == -1) |
634 |
break; |
break; |
689 |
d->update_x2 = d->xsize-1; |
d->update_x2 = d->xsize-1; |
690 |
} |
} |
691 |
} while (0); |
} while (0); |
|
#endif |
|
692 |
|
|
693 |
#ifdef WITH_X11 |
#ifdef WITH_X11 |
694 |
/* Do we need to redraw the cursor? */ |
/* Do we need to redraw the cursor? */ |
700 |
need_to_redraw_cursor = 1; |
need_to_redraw_cursor = 1; |
701 |
|
|
702 |
if (d->update_x2 != -1) { |
if (d->update_x2 != -1) { |
703 |
if ( (d->update_x1 >= d->fb_window->OLD_cursor_x && |
if (((d->update_x1 >= d->fb_window->OLD_cursor_x && |
704 |
d->update_x1 < (d->fb_window->OLD_cursor_x + d->fb_window->OLD_cursor_xsize)) || |
d->update_x1 < (d->fb_window->OLD_cursor_x + |
705 |
|
d->fb_window->OLD_cursor_xsize)) || |
706 |
(d->update_x2 >= d->fb_window->OLD_cursor_x && |
(d->update_x2 >= d->fb_window->OLD_cursor_x && |
707 |
d->update_x2 < (d->fb_window->OLD_cursor_x + d->fb_window->OLD_cursor_xsize)) || |
d->update_x2 < (d->fb_window->OLD_cursor_x + |
708 |
|
d->fb_window->OLD_cursor_xsize)) || |
709 |
(d->update_x1 < d->fb_window->OLD_cursor_x && |
(d->update_x1 < d->fb_window->OLD_cursor_x && |
710 |
d->update_x2 >= (d->fb_window->OLD_cursor_x + d->fb_window->OLD_cursor_xsize)) ) { |
d->update_x2 >= (d->fb_window->OLD_cursor_x + |
711 |
if ( (d->update_y1 >= d->fb_window->OLD_cursor_y && |
d->fb_window->OLD_cursor_xsize)) ) && |
712 |
d->update_y1 < (d->fb_window->OLD_cursor_y + d->fb_window->OLD_cursor_ysize)) || |
( (d->update_y1 >= d->fb_window->OLD_cursor_y && |
713 |
(d->update_y2 >= d->fb_window->OLD_cursor_y && |
d->update_y1 < (d->fb_window->OLD_cursor_y + |
714 |
d->update_y2 < (d->fb_window->OLD_cursor_y + d->fb_window->OLD_cursor_ysize)) || |
d->fb_window->OLD_cursor_ysize)) || |
715 |
(d->update_y1 < d->fb_window->OLD_cursor_y && |
(d->update_y2 >= d->fb_window->OLD_cursor_y && |
716 |
d->update_y2 >= (d->fb_window->OLD_cursor_y + d->fb_window->OLD_cursor_ysize)) ) |
d->update_y2 < (d->fb_window->OLD_cursor_y + |
717 |
need_to_redraw_cursor = 1; |
d->fb_window->OLD_cursor_ysize)) || |
718 |
} |
(d->update_y1 < d->fb_window->OLD_cursor_y && |
719 |
|
d->update_y2 >= (d->fb_window->OLD_cursor_y + |
720 |
|
d->fb_window->OLD_cursor_ysize)) ) ) |
721 |
|
need_to_redraw_cursor = 1; |
722 |
} |
} |
723 |
|
|
724 |
if (need_to_redraw_cursor) { |
if (need_to_redraw_cursor) { |
732 |
d->fb_window->OLD_cursor_x/d->vfb_scaledown, |
d->fb_window->OLD_cursor_x/d->vfb_scaledown, |
733 |
d->fb_window->OLD_cursor_y/d->vfb_scaledown, |
d->fb_window->OLD_cursor_y/d->vfb_scaledown, |
734 |
d->fb_window->OLD_cursor_xsize/d->vfb_scaledown + 1, |
d->fb_window->OLD_cursor_xsize/d->vfb_scaledown + 1, |
735 |
d->fb_window->OLD_cursor_ysize/d->vfb_scaledown + 1); |
d->fb_window->OLD_cursor_ysize/d->vfb_scaledown +1); |
736 |
} |
} |
737 |
} |
} |
738 |
#endif |
#endif |
740 |
if (d->update_x2 != -1) { |
if (d->update_x2 != -1) { |
741 |
int y, addr, addr2, q = d->vfb_scaledown; |
int y, addr, addr2, q = d->vfb_scaledown; |
742 |
|
|
743 |
if (d->update_x1 >= d->visible_xsize) d->update_x1 = d->visible_xsize - 1; |
if (d->update_x1 >= d->visible_xsize) |
744 |
if (d->update_x2 >= d->visible_xsize) d->update_x2 = d->visible_xsize - 1; |
d->update_x1 = d->visible_xsize - 1; |
745 |
if (d->update_y1 >= d->visible_ysize) d->update_y1 = d->visible_ysize - 1; |
if (d->update_x2 >= d->visible_xsize) |
746 |
if (d->update_y2 >= d->visible_ysize) d->update_y2 = d->visible_ysize - 1; |
d->update_x2 = d->visible_xsize - 1; |
747 |
|
if (d->update_y1 >= d->visible_ysize) |
748 |
|
d->update_y1 = d->visible_ysize - 1; |
749 |
|
if (d->update_y2 >= d->visible_ysize) |
750 |
|
d->update_y2 = d->visible_ysize - 1; |
751 |
|
|
752 |
/* Without these, we might miss the right most / bottom pixel: */ |
/* Without these, we might miss the rightmost/bottom pixel: */ |
753 |
d->update_x2 += (q - 1); |
d->update_x2 += (q - 1); |
754 |
d->update_y2 += (q - 1); |
d->update_y2 += (q - 1); |
755 |
|
|
758 |
d->update_y1 = d->update_y1 / q * q; |
d->update_y1 = d->update_y1 / q * q; |
759 |
d->update_y2 = d->update_y2 / q * q; |
d->update_y2 = d->update_y2 / q * q; |
760 |
|
|
761 |
addr = d->update_y1 * d->bytes_per_line + d->update_x1 * d->bit_depth / 8; |
addr = d->update_y1 * d->bytes_per_line + |
762 |
addr2 = d->update_y1 * d->bytes_per_line + d->update_x2 * d->bit_depth / 8; |
d->update_x1 * d->bit_depth / 8; |
763 |
|
addr2 = d->update_y1 * d->bytes_per_line + |
764 |
|
d->update_x2 * d->bit_depth / 8; |
765 |
|
|
766 |
for (y=d->update_y1; y<=d->update_y2; y+=q) { |
for (y=d->update_y1; y<=d->update_y2; y+=q) { |
767 |
update_framebuffer(d, addr, addr2 - addr); |
update_framebuffer(d, addr, addr2 - addr); |
770 |
} |
} |
771 |
|
|
772 |
#ifdef WITH_X11 |
#ifdef WITH_X11 |
773 |
XPutImage(d->fb_window->x11_display, d->fb_window->x11_fb_window, d->fb_window->x11_fb_gc, d->fb_window->fb_ximage, |
XPutImage(d->fb_window->x11_display, d->fb_window-> |
774 |
d->update_x1/d->vfb_scaledown, d->update_y1/d->vfb_scaledown, |
x11_fb_window, d->fb_window->x11_fb_gc, d->fb_window-> |
775 |
d->update_x1/d->vfb_scaledown, d->update_y1/d->vfb_scaledown, |
fb_ximage, d->update_x1/d->vfb_scaledown, d->update_y1/ |
776 |
|
d->vfb_scaledown, d->update_x1/d->vfb_scaledown, |
777 |
|
d->update_y1/d->vfb_scaledown, |
778 |
(d->update_x2 - d->update_x1)/d->vfb_scaledown + 1, |
(d->update_x2 - d->update_x1)/d->vfb_scaledown + 1, |
779 |
(d->update_y2 - d->update_y1)/d->vfb_scaledown + 1); |
(d->update_y2 - d->update_y1)/d->vfb_scaledown + 1); |
780 |
|
|
789 |
if (need_to_redraw_cursor) { |
if (need_to_redraw_cursor) { |
790 |
/* Paint new cursor: */ |
/* Paint new cursor: */ |
791 |
if (d->fb_window->cursor_on) { |
if (d->fb_window->cursor_on) { |
792 |
x11_redraw_cursor(cpu->machine, d->fb_window->fb_number); |
x11_redraw_cursor(cpu->machine, |
793 |
|
d->fb_window->fb_number); |
794 |
d->fb_window->OLD_cursor_on = d->fb_window->cursor_on; |
d->fb_window->OLD_cursor_on = d->fb_window->cursor_on; |
795 |
d->fb_window->OLD_cursor_x = d->fb_window->cursor_x; |
d->fb_window->OLD_cursor_x = d->fb_window->cursor_x; |
796 |
d->fb_window->OLD_cursor_y = d->fb_window->cursor_y; |
d->fb_window->OLD_cursor_y = d->fb_window->cursor_y; |
797 |
d->fb_window->OLD_cursor_xsize = d->fb_window->cursor_xsize; |
d->fb_window->OLD_cursor_xsize = d->fb_window-> |
798 |
d->fb_window->OLD_cursor_ysize = d->fb_window->cursor_ysize; |
cursor_xsize; |
799 |
|
d->fb_window->OLD_cursor_ysize = d->fb_window-> |
800 |
|
cursor_ysize; |
801 |
} |
} |
802 |
} |
} |
803 |
#endif |
#endif |
936 |
* |
* |
937 |
* VFB_DEC_VFB01, _VFB02, and VFB_DEC_MAXINE are DECstation specific. |
* VFB_DEC_VFB01, _VFB02, and VFB_DEC_MAXINE are DECstation specific. |
938 |
* |
* |
939 |
* If type is VFB_HPCMIPS, then color encoding differs from the generic case. |
* If type is VFB_HPC, then color encoding differs from the generic case. |
940 |
* |
* |
941 |
* If bit_depth = -15 (note the minus sign), then a special hack is used for |
* If bit_depth = -15 (note the minus sign), then a special hack is used for |
942 |
* the Playstation Portable's 5-bit R, 5-bit G, 5-bit B. |
* the Playstation Portable's 5-bit R, 5-bit G, 5-bit B. |
943 |
*/ |
*/ |
944 |
struct vfb_data *dev_fb_init(struct machine *machine, struct memory *mem, |
struct vfb_data *dev_fb_init(struct machine *machine, struct memory *mem, |
945 |
uint64_t baseaddr, int vfb_type, int visible_xsize, int visible_ysize, |
uint64_t baseaddr, int vfb_type, int visible_xsize, int visible_ysize, |
946 |
int xsize, int ysize, int bit_depth, char *name, int logo) |
int xsize, int ysize, int bit_depth, char *name) |
947 |
{ |
{ |
948 |
struct vfb_data *d; |
struct vfb_data *d; |
949 |
size_t size, nlen; |
size_t size, nlen; |
950 |
int x, y, flags; |
int flags; |
951 |
char title[400]; |
char title[400]; |
952 |
char *name2; |
char *name2; |
953 |
|
|
1031 |
d->update_x2 = d->update_y2 = -1; |
d->update_x2 = d->update_y2 = -1; |
1032 |
|
|
1033 |
|
|
|
/* A nice bootup logo: */ |
|
|
if (logo) { |
|
|
int logo_bottom_margin = LOGO_BOTTOM_MARGIN; |
|
|
|
|
|
d->update_x1 = 0; |
|
|
d->update_x2 = LOGO_XSIZE-1; |
|
|
d->update_y1 = d->visible_ysize-LOGO_YSIZE-logo_bottom_margin; |
|
|
d->update_y2 = d->visible_ysize-logo_bottom_margin; |
|
|
for (y=0; y<LOGO_YSIZE; y++) |
|
|
for (x=0; x<LOGO_XSIZE; x++) { |
|
|
int s, a = ((y + d->visible_ysize - LOGO_YSIZE |
|
|
- logo_bottom_margin)*d->xsize + x) |
|
|
* d->bit_depth / 8; |
|
|
int b = fb_logo[(y*LOGO_XSIZE+x) / 8] & |
|
|
(128 >> (x&7)); |
|
|
for (s=0; s<d->bit_depth / 8; s++) |
|
|
if (a+s >= 0 && a+s < size) |
|
|
d->framebuffer[a+s] = b? 0:255; |
|
|
} |
|
|
} |
|
|
|
|
1034 |
/* Don't set the title to include the size of the framebuffer for |
/* Don't set the title to include the size of the framebuffer for |
1035 |
VGA, since then the resolution might change during runtime. */ |
VGA, since then the resolution might change during runtime. */ |
1036 |
if (strcmp(name, "VGA") == 0) |
if (strcmp(name, "VGA") == 0) |
1056 |
} |
} |
1057 |
snprintf(name2, nlen, "fb [%s]", name); |
snprintf(name2, nlen, "fb [%s]", name); |
1058 |
|
|
1059 |
flags = MEM_DEFAULT; |
flags = DM_DEFAULT; |
1060 |
if ((baseaddr & 0xfff) == 0) |
if ((baseaddr & 0xfff) == 0) |
1061 |
flags = MEM_BINTRANS_OK | MEM_BINTRANS_WRITE_OK; |
flags = DM_DYNTRANS_OK | DM_DYNTRANS_WRITE_OK; |
1062 |
|
|
1063 |
flags |= MEM_READING_HAS_NO_SIDE_EFFECTS; |
flags |= DM_READS_HAVE_NO_SIDE_EFFECTS; |
1064 |
|
|
1065 |
memory_device_register(mem, name2, baseaddr, size, dev_fb_access, |
memory_device_register(mem, name2, baseaddr, size, dev_fb_access, |
1066 |
d, flags, d->framebuffer); |
d, flags, d->framebuffer); |