--- trunk/src/devices/dev_fb.c 2007/10/08 16:18:00 4 +++ trunk/src/devices/dev_fb.c 2007/10/08 16:19:23 20 @@ -25,14 +25,14 @@ * SUCH DAMAGE. * * - * $Id: dev_fb.c,v 1.90 2005/03/29 09:46:06 debug Exp $ + * $Id: dev_fb.c,v 1.110 2005/11/13 00:14:08 debug Exp $ * * Generic framebuffer device. * * DECstation VFB01 monochrome framebuffer, 1024x864 * DECstation VFB02 8-bit color framebuffer, 1024x864 * DECstation Maxine, 1024x768 8-bit color - * HPCmips framebuffer + * HPC (mips, arm, ..) framebuffer * Playstation 2 (24-bit color) * generic (any resolution, several bit depths possible) * @@ -67,13 +67,6 @@ #define FB_TICK_SHIFT 18 -#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; - /* #define FB_DEBUG */ @@ -115,6 +108,69 @@ /* + * dev_fb_resize(): + * + * Resize a framebuffer window. (This functionality is probably a bit buggy, + * because I didn't think of including it from the start.) + */ +void dev_fb_resize(struct vfb_data *d, int new_xsize, int new_ysize) +{ + unsigned char *new_framebuffer; + int y, new_bytes_per_line; + size_t size; + + if (d == NULL) { + fatal("dev_fb_resize(): d == NULL\n"); + return; + } + + new_bytes_per_line = new_xsize * d->bit_depth / 8; + size = new_ysize * new_bytes_per_line; + + new_framebuffer = malloc(size); + if (new_framebuffer == NULL) { + fprintf(stderr, "dev_fb_resize(): out of memory\n"); + exit(1); + } + + /* Copy the old framebuffer to the new: */ + if (d->framebuffer != NULL) { + for (y=0; ybytes_per_line * y; + size_t toofs = new_bytes_per_line * y; + size_t len_to_copy = d->bytes_per_line < + new_bytes_per_line? d->bytes_per_line + : new_bytes_per_line; + memset(new_framebuffer + toofs, 0, new_bytes_per_line); + if (y < d->x11_ysize) + memmove(new_framebuffer + toofs, + d->framebuffer + fromofs, len_to_copy); + } + + free(d->framebuffer); + } + + d->framebuffer = new_framebuffer; + d->framebuffer_size = size; + + if (new_xsize > d->x11_xsize || new_ysize > d->x11_ysize) { + d->update_x1 = d->update_y1 = 0; + d->update_x2 = new_xsize - 1; + d->update_y2 = new_ysize - 1; + } + + d->bytes_per_line = new_bytes_per_line; + d->x11_xsize = d->visible_xsize = new_xsize; + d->x11_ysize = d->visible_ysize = new_ysize; + +#ifdef WITH_X11 + if (d->fb_window != NULL) + x11_fb_resize(d->fb_window, new_xsize, new_ysize); +#endif +} + + +/* * dev_fb_setcursor(): */ void dev_fb_setcursor(struct vfb_data *d, int cursor_x, int cursor_y, int on, @@ -235,51 +291,58 @@ #ifdef WITH_X11 #define macro_put_pixel() { \ - /* Combine the color into an X11 long and display it: */ \ - /* TODO: construct color in a more portable way: */ \ - switch (d->fb_window->x11_screen_depth) { \ - case 24: \ - if (d->fb_window->fb_ximage->byte_order) \ - color = (b << 16) + (g << 8) + r; \ - else \ - color = (r << 16) + (g << 8) + b; \ - break; \ - case 16: \ - r >>= 3; g >>= 2; b >>= 3; \ - if (d->fb_window->fb_ximage->byte_order) { \ - /* Big endian 16-bit X server: */ \ - static int first = 1; \ - if (first) { \ - fprintf(stderr, "\n*** Please report to the author whether 16-bit X11 colors are rendered correctly or not!\n\n"); \ - first = 0; \ - } \ - color = (b << 11) + (g << 5) + r; \ - } else { \ - /* Little endian (eg PC) X servers: */ \ - color = (r << 11) + (g << 5) + b; \ - } \ - break; \ - case 15: \ - r >>= 3; g >>= 3; b >>= 3; \ - if (d->fb_window->fb_ximage->byte_order) { \ - /* Big endian 15-bit X server: */ \ - static int first = 1; \ - if (first) { \ - fprintf(stderr, "\n*** Please report to the author whether 15-bit X11 colors are rendered correctly or not!\n\n"); \ - first = 0; \ - } \ - color = (b << 10) + (g << 5) + r; \ - } else { \ - /* Little endian (eg PC) X servers: */ \ - color = (r << 10) + (g << 5) + b; \ - } \ - break; \ - default: \ - color = d->fb_window->x11_graycolor[15 * (r + g + b) / (255 * 3)].pixel; \ - } \ - if (x>=0 && xx11_xsize && y>=0 && yx11_ysize) \ - XPutPixel(d->fb_window->fb_ximage, x, y, color); \ - } + /* Combine the color into an X11 long and display it: */ \ + /* TODO: construct color in a more portable way: */ \ + switch (d->fb_window->x11_screen_depth) { \ + case 24: \ + if (d->fb_window->fb_ximage->byte_order) \ + color = (b << 16) + (g << 8) + r; \ + else \ + color = (r << 16) + (g << 8) + b; \ + break; \ + case 16: \ + r >>= 3; g >>= 2; b >>= 3; \ + if (d->fb_window->fb_ximage->byte_order) { \ + /* Big endian 16-bit X server: */ \ + static int first = 1; \ + if (first) { \ + fprintf(stderr, "\n*** Please report " \ + "to the author whether 16-bit X11 " \ + "colors are rendered correctly or " \ + "not!\n\n"); \ + first = 0; \ + } \ + color = (b << 11) + (g << 5) + r; \ + } else { \ + /* Little endian (eg PC) X servers: */ \ + color = (r << 11) + (g << 5) + b; \ + } \ + break; \ + case 15: \ + r >>= 3; g >>= 3; b >>= 3; \ + if (d->fb_window->fb_ximage->byte_order) { \ + /* Big endian 15-bit X server: */ \ + static int first = 1; \ + if (first) { \ + fprintf(stderr, "\n*** Please report " \ + "to the author whether 15-bit X11 " \ + "colors are rendered correctly or " \ + "not!\n\n"); \ + first = 0; \ + } \ + color = (b << 10) + (g << 5) + r; \ + } else { \ + /* Little endian (eg PC) X servers: */ \ + color = (r << 10) + (g << 5) + b; \ + } \ + break; \ + default: \ + color = d->fb_window->x11_graycolor[15 * (r + g + b) \ + / (255 * 3)].pixel; \ + } \ + if (x>=0 && xx11_xsize && y>=0 && yx11_ysize) \ + XPutPixel(d->fb_window->fb_ximage, x, y, color); \ + } #else /* If not WITH_X11: */ #define macro_put_pixel() { } @@ -325,8 +388,8 @@ c = d->framebuffer[fb_addr >> 3]; fb_addr &= 7; - /* HPCmips is reverse: */ - if (d->vfb_type == VFB_HPCMIPS) + /* HPC is reverse: */ + if (d->vfb_type == VFB_HPC) fb_addr = 8 - d->bit_depth - fb_addr; c = (c >> fb_addr) & ((1<bit_depth) - 1); @@ -372,9 +435,10 @@ break; /* TODO: copy to the scaledown code below */ case 16: - if (d->vfb_type == VFB_HPCMIPS) { + if (d->vfb_type == VFB_HPC) { b = d->framebuffer[fb_addr] + - (d->framebuffer[fb_addr+1] << 8); + (d->framebuffer[fb_addr+1] + << 8); if (d->color32k) { r = b >> 11; @@ -382,16 +446,23 @@ r = r & 31; g = (g & 31) * 2; b = b & 31; + } else if (d->psp_15bit) { + int tmp; + r = (b >> 10) & 0x1f; + g = (b >> 5) & 0x1f; + b = b & 0x1f; + g <<= 1; + tmp = r; r = b; b = tmp; } else { r = (b >> 11) & 0x1f; g = (b >> 5) & 0x3f; b = b & 0x1f; } } else { - r = d->framebuffer[fb_addr] >> 3; - g = (d->framebuffer[fb_addr] << 5) + - (d->framebuffer[fb_addr + 1] >> 5); - b = d->framebuffer[fb_addr + 1] & 0x1f; + r = d->framebuffer[fb_addr] >> 3; + g = (d->framebuffer[fb_addr] << 5) + + (d->framebuffer[fb_addr + 1] >>5); + b = d->framebuffer[fb_addr + 1]&31; } r *= 8; @@ -410,7 +481,7 @@ return; } - /* scaledown != 1: */ + /* scaledown > 1: */ scaledown = d->vfb_scaledown; scaledownXscaledown = scaledown * scaledown; @@ -450,8 +521,8 @@ c = d->framebuffer[fb_addr >> 3]; fb_addr &= 7; - /* HPCmips is reverse: */ - if (d->vfb_type == VFB_HPCMIPS) + /* HPC is reverse: */ + if (d->vfb_type == VFB_HPC) fb_addr = 8 - d->bit_depth - fb_addr; c = (c >> fb_addr) & ((1<bit_depth) - 1); @@ -553,12 +624,11 @@ if (!cpu->machine->use_x11) return; -#ifdef BINTRANS do { - uint64_t low = -1, high; + uint64_t high, low = (uint64_t)(int64_t) -1; int x, y; - memory_device_bintrans_access(cpu, cpu->mem, + memory_device_dyntrans_access(cpu, cpu->mem, extra, &low, &high); if ((int64_t)low == -1) break; @@ -619,7 +689,6 @@ d->update_x2 = d->xsize-1; } } while (0); -#endif #ifdef WITH_X11 /* Do we need to redraw the cursor? */ @@ -631,20 +700,25 @@ need_to_redraw_cursor = 1; if (d->update_x2 != -1) { - if ( (d->update_x1 >= d->fb_window->OLD_cursor_x && - d->update_x1 < (d->fb_window->OLD_cursor_x + d->fb_window->OLD_cursor_xsize)) || + if (((d->update_x1 >= d->fb_window->OLD_cursor_x && + d->update_x1 < (d->fb_window->OLD_cursor_x + + d->fb_window->OLD_cursor_xsize)) || (d->update_x2 >= d->fb_window->OLD_cursor_x && - d->update_x2 < (d->fb_window->OLD_cursor_x + d->fb_window->OLD_cursor_xsize)) || + d->update_x2 < (d->fb_window->OLD_cursor_x + + d->fb_window->OLD_cursor_xsize)) || (d->update_x1 < d->fb_window->OLD_cursor_x && - d->update_x2 >= (d->fb_window->OLD_cursor_x + d->fb_window->OLD_cursor_xsize)) ) { - if ( (d->update_y1 >= d->fb_window->OLD_cursor_y && - d->update_y1 < (d->fb_window->OLD_cursor_y + d->fb_window->OLD_cursor_ysize)) || - (d->update_y2 >= d->fb_window->OLD_cursor_y && - d->update_y2 < (d->fb_window->OLD_cursor_y + d->fb_window->OLD_cursor_ysize)) || - (d->update_y1 < d->fb_window->OLD_cursor_y && - d->update_y2 >= (d->fb_window->OLD_cursor_y + d->fb_window->OLD_cursor_ysize)) ) - need_to_redraw_cursor = 1; - } + d->update_x2 >= (d->fb_window->OLD_cursor_x + + d->fb_window->OLD_cursor_xsize)) ) && + ( (d->update_y1 >= d->fb_window->OLD_cursor_y && + d->update_y1 < (d->fb_window->OLD_cursor_y + + d->fb_window->OLD_cursor_ysize)) || + (d->update_y2 >= d->fb_window->OLD_cursor_y && + d->update_y2 < (d->fb_window->OLD_cursor_y + + d->fb_window->OLD_cursor_ysize)) || + (d->update_y1 < d->fb_window->OLD_cursor_y && + d->update_y2 >= (d->fb_window->OLD_cursor_y + + d->fb_window->OLD_cursor_ysize)) ) ) + need_to_redraw_cursor = 1; } if (need_to_redraw_cursor) { @@ -658,7 +732,7 @@ d->fb_window->OLD_cursor_x/d->vfb_scaledown, d->fb_window->OLD_cursor_y/d->vfb_scaledown, d->fb_window->OLD_cursor_xsize/d->vfb_scaledown + 1, - d->fb_window->OLD_cursor_ysize/d->vfb_scaledown + 1); + d->fb_window->OLD_cursor_ysize/d->vfb_scaledown +1); } } #endif @@ -666,12 +740,16 @@ if (d->update_x2 != -1) { int y, addr, addr2, q = d->vfb_scaledown; - if (d->update_x1 >= d->visible_xsize) d->update_x1 = d->visible_xsize - 1; - if (d->update_x2 >= d->visible_xsize) d->update_x2 = d->visible_xsize - 1; - if (d->update_y1 >= d->visible_ysize) d->update_y1 = d->visible_ysize - 1; - if (d->update_y2 >= d->visible_ysize) d->update_y2 = d->visible_ysize - 1; + if (d->update_x1 >= d->visible_xsize) + d->update_x1 = d->visible_xsize - 1; + if (d->update_x2 >= d->visible_xsize) + d->update_x2 = d->visible_xsize - 1; + if (d->update_y1 >= d->visible_ysize) + d->update_y1 = d->visible_ysize - 1; + if (d->update_y2 >= d->visible_ysize) + d->update_y2 = d->visible_ysize - 1; - /* Without these, we might miss the right most / bottom pixel: */ + /* Without these, we might miss the rightmost/bottom pixel: */ d->update_x2 += (q - 1); d->update_y2 += (q - 1); @@ -680,8 +758,10 @@ d->update_y1 = d->update_y1 / q * q; d->update_y2 = d->update_y2 / q * q; - addr = d->update_y1 * d->bytes_per_line + d->update_x1 * d->bit_depth / 8; - addr2 = d->update_y1 * d->bytes_per_line + d->update_x2 * d->bit_depth / 8; + addr = d->update_y1 * d->bytes_per_line + + d->update_x1 * d->bit_depth / 8; + addr2 = d->update_y1 * d->bytes_per_line + + d->update_x2 * d->bit_depth / 8; for (y=d->update_y1; y<=d->update_y2; y+=q) { update_framebuffer(d, addr, addr2 - addr); @@ -690,9 +770,11 @@ } #ifdef WITH_X11 - XPutImage(d->fb_window->x11_display, d->fb_window->x11_fb_window, d->fb_window->x11_fb_gc, d->fb_window->fb_ximage, - d->update_x1/d->vfb_scaledown, d->update_y1/d->vfb_scaledown, - d->update_x1/d->vfb_scaledown, d->update_y1/d->vfb_scaledown, + XPutImage(d->fb_window->x11_display, d->fb_window-> + x11_fb_window, d->fb_window->x11_fb_gc, d->fb_window-> + fb_ximage, d->update_x1/d->vfb_scaledown, d->update_y1/ + d->vfb_scaledown, d->update_x1/d->vfb_scaledown, + d->update_y1/d->vfb_scaledown, (d->update_x2 - d->update_x1)/d->vfb_scaledown + 1, (d->update_y2 - d->update_y1)/d->vfb_scaledown + 1); @@ -707,12 +789,15 @@ if (need_to_redraw_cursor) { /* Paint new cursor: */ if (d->fb_window->cursor_on) { - x11_redraw_cursor(cpu->machine, d->fb_window->fb_number); + x11_redraw_cursor(cpu->machine, + d->fb_window->fb_number); d->fb_window->OLD_cursor_on = d->fb_window->cursor_on; d->fb_window->OLD_cursor_x = d->fb_window->cursor_x; d->fb_window->OLD_cursor_y = d->fb_window->cursor_y; - d->fb_window->OLD_cursor_xsize = d->fb_window->cursor_xsize; - d->fb_window->OLD_cursor_ysize = d->fb_window->cursor_ysize; + d->fb_window->OLD_cursor_xsize = d->fb_window-> + cursor_xsize; + d->fb_window->OLD_cursor_ysize = d->fb_window-> + cursor_ysize; } } #endif @@ -750,6 +835,9 @@ } #endif + if (relative_addr >= d->framebuffer_size) + return 0; + /* See if a write actually modifies the framebuffer contents: */ if (writeflag == MEM_WRITE) { for (i=0; icolor32k = 1; bit_depth = d->bit_depth = 16; + } else if (bit_depth == -15) { + d->psp_15bit = 1; + bit_depth = d->bit_depth = 16; } /* Specific types: */ @@ -925,28 +1031,13 @@ d->update_x2 = d->update_y2 = -1; - /* 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; yvisible_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; sbit_depth / 8; s++) - d->framebuffer[a+s] = b? 0 : 255; - } - } - - snprintf(title, sizeof(title), "GXemul: %ix%ix%i %s framebuffer", - d->visible_xsize, d->visible_ysize, d->bit_depth, name); + /* Don't set the title to include the size of the framebuffer for + VGA, since then the resolution might change during runtime. */ + if (strcmp(name, "VGA") == 0) + snprintf(title, sizeof(title),"GXemul: %s framebuffer", name); + else + snprintf(title, sizeof(title),"GXemul: %ix%ix%i %s framebuffer", + d->visible_xsize, d->visible_ysize, d->bit_depth, name); title[sizeof(title)-1] = '\0'; #ifdef WITH_X11 @@ -957,16 +1048,19 @@ #endif d->fb_window = NULL; - name2 = malloc(strlen(name) + 10); + nlen = strlen(name) + 10; + name2 = malloc(nlen); if (name2 == NULL) { fprintf(stderr, "out of memory in dev_fb_init()\n"); exit(1); } - sprintf(name2, "fb [%s]", name); + snprintf(name2, nlen, "fb [%s]", name); - flags = MEM_DEFAULT; + flags = DM_DEFAULT; if ((baseaddr & 0xfff) == 0) - flags = MEM_BINTRANS_OK | MEM_BINTRANS_WRITE_OK; + flags = DM_DYNTRANS_OK | DM_DYNTRANS_WRITE_OK; + + flags |= DM_READS_HAVE_NO_SIDE_EFFECTS; memory_device_register(mem, name2, baseaddr, size, dev_fb_access, d, flags, d->framebuffer);