--- trunk/src/devices/dev_fb.c 2007/10/08 16:18:00 4 +++ trunk/src/devices/dev_fb.c 2007/10/08 16:19:37 22 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2005 Anders Gavare. All rights reserved. + * Copyright (C) 2003-2006 Anders Gavare. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -25,22 +25,19 @@ * SUCH DAMAGE. * * - * $Id: dev_fb.c,v 1.90 2005/03/29 09:46:06 debug Exp $ + * $Id: dev_fb.c,v 1.116 2006/02/05 10:26:36 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) * * - * TODO: There is still a bug when redrawing the cursor. The underlying - * image is moved 1 pixel (?), or something like that. - * - * TODO: This should actually be independant of X11, but that + * TODO: This should actually be independent of X11, but that * might be too hard to do right now. * * TODO: playstation 2 pixels are stored in another format, actually @@ -67,13 +64,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 +105,72 @@ /* + * 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->xsize || new_ysize > d->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->xsize = d->visible_xsize = new_xsize; + d->ysize = d->visible_ysize = new_ysize; + + d->x11_xsize = d->xsize / d->vfb_scaledown; + d->x11_ysize = d->ysize / d->vfb_scaledown; + +#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, @@ -192,14 +248,16 @@ int x; char buf[8192 * 3]; if (d->bit_depth == 24) - for (x=0; xframebuffer + dest_ofs, buf, linelen); @@ -234,308 +292,96 @@ #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); \ - } -#else -/* If not WITH_X11: */ -#define macro_put_pixel() { } -#endif +#define REDRAW redraw_fallback +#include "fb_include.c" +#undef REDRAW + +#define FB_24 +#define REDRAW redraw_24 +#include "fb_include.c" +#undef REDRAW +#undef FB_24 +#define FB_16 +#define REDRAW redraw_16 +#include "fb_include.c" +#undef FB_16 +#undef REDRAW +#define FB_15 +#define REDRAW redraw_15 +#include "fb_include.c" +#undef REDRAW +#undef FB_15 + +#define FB_BO +#define FB_24 +#define REDRAW redraw_24_bo +#include "fb_include.c" +#undef REDRAW +#undef FB_24 +#define FB_16 +#define REDRAW redraw_16_bo +#include "fb_include.c" +#undef FB_16 +#undef REDRAW +#define FB_15 +#define REDRAW redraw_15_bo +#include "fb_include.c" +#undef REDRAW +#undef FB_15 +#undef FB_BO + +#define FB_SCALEDOWN + +#define REDRAW redraw_fallback_sd +#include "fb_include.c" +#undef REDRAW + +#define FB_24 +#define REDRAW redraw_24_sd +#include "fb_include.c" +#undef REDRAW +#undef FB_24 +#define FB_16 +#define REDRAW redraw_16_sd +#include "fb_include.c" +#undef FB_16 +#undef REDRAW +#define FB_15 +#define REDRAW redraw_15_sd +#include "fb_include.c" +#undef REDRAW +#undef FB_15 + +#define FB_BO +#define FB_24 +#define REDRAW redraw_24_bo_sd +#include "fb_include.c" +#undef REDRAW +#undef FB_24 +#define FB_16 +#define REDRAW redraw_16_bo_sd +#include "fb_include.c" +#undef FB_16 +#undef REDRAW +#define FB_15 +#define REDRAW redraw_15_bo_sd +#include "fb_include.c" +#undef REDRAW +#undef FB_15 +#undef FB_BO + +void (*redraw[2 * 4 * 2])(struct vfb_data *, int, int) = { + redraw_fallback, redraw_fallback, + redraw_15, redraw_15_bo, + redraw_16, redraw_16_bo, + redraw_24, redraw_24_bo, + redraw_fallback_sd, redraw_fallback_sd, + redraw_15_sd, redraw_15_bo_sd, + redraw_16_sd, redraw_16_bo_sd, + redraw_24_sd, redraw_24_bo_sd }; -/* - * update_framebuffer(): - * - * The framebuffer memory has been updated. This function tries to make - * sure that the XImage is also updated (1 or more pixels). - */ -void update_framebuffer(struct vfb_data *d, int addr, int len) -{ - int x, y, pixel, npixels; - long color_r, color_g, color_b; -#ifdef WITH_X11 - long color; -#endif - int scaledown = d->vfb_scaledown; - int scaledownXscaledown = 1; - - if (scaledown == 1) { - /* Which framebuffer pixel does addr correspond to? */ - pixel = addr * 8 / d->bit_depth; - y = pixel / d->xsize; - x = pixel % d->xsize; - - /* How many framebuffer pixels? */ - npixels = len * 8 / d->bit_depth; - if (npixels == 0) - npixels = 1; - - if (d->bit_depth < 8) { - for (pixel=0; pixelxsize + x) * d->bit_depth; - /* fb_addr is now which _bit_ in - the framebuffer */ - - c = d->framebuffer[fb_addr >> 3]; - fb_addr &= 7; - - /* HPCmips is reverse: */ - if (d->vfb_type == VFB_HPCMIPS) - fb_addr = 8 - d->bit_depth - fb_addr; - - c = (c >> fb_addr) & ((1<bit_depth) - 1); - /* c <<= (8 - d->bit_depth); */ - - r = d->rgb_palette[c*3 + 0]; - g = d->rgb_palette[c*3 + 1]; - b = d->rgb_palette[c*3 + 2]; - - macro_put_pixel(); - x++; - } - } else if (d->bit_depth == 8) { - for (pixel=0; pixelxsize + x; - /* fb_addr is now which byte in framebuffer */ - c = d->framebuffer[fb_addr]; - r = d->rgb_palette[c*3 + 0]; - g = d->rgb_palette[c*3 + 1]; - b = d->rgb_palette[c*3 + 2]; - - macro_put_pixel(); - x++; - } - } else { /* d->bit_depth > 8 */ - for (pixel=0; pixelxsize + x) * d->bit_depth; - /* fb_addr is now which byte in framebuffer */ - - /* > 8 bits color. */ - fb_addr >>= 3; - switch (d->bit_depth) { - case 24: - r = d->framebuffer[fb_addr]; - g = d->framebuffer[fb_addr + 1]; - b = d->framebuffer[fb_addr + 2]; - break; - /* TODO: copy to the scaledown code below */ - case 16: - if (d->vfb_type == VFB_HPCMIPS) { - b = d->framebuffer[fb_addr] + - (d->framebuffer[fb_addr+1] << 8); - - if (d->color32k) { - r = b >> 11; - g = b >> 5; - r = r & 31; - g = (g & 31) * 2; - b = b & 31; - } 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 *= 8; - g *= 4; - b *= 8; - break; - default: - r = g = b = random() & 255; - } - - macro_put_pixel(); - x++; - } - } - - return; - } - - /* scaledown != 1: */ - - scaledown = d->vfb_scaledown; - scaledownXscaledown = scaledown * scaledown; - - /* Which framebuffer pixel does addr correspond to? */ - pixel = addr * 8 / d->bit_depth; - y = pixel / d->xsize; - x = pixel % d->xsize; - - /* How many framebuffer pixels? */ - npixels = len * 8 / d->bit_depth; - - /* Which x11 pixel? */ - x /= scaledown; - y /= scaledown; - - /* How many x11 pixels: */ - npixels /= scaledown; - if (npixels == 0) - npixels = 1; - - if (d->bit_depth < 8) { - for (pixel=0; pixelxsize + fb_x; - fb_addr = fb_addr * d->bit_depth; - /* fb_addr is now which _bit_ in - the framebuffer */ - - c = d->framebuffer[fb_addr >> 3]; - fb_addr &= 7; - - /* HPCmips is reverse: */ - if (d->vfb_type == VFB_HPCMIPS) - fb_addr = 8 - d->bit_depth - fb_addr; - - c = (c >> fb_addr) & ((1<bit_depth) - 1); - /* c <<= (8 - d->bit_depth); */ - - r = d->rgb_palette[c*3 + 0]; - g = d->rgb_palette[c*3 + 1]; - b = d->rgb_palette[c*3 + 2]; - - color_r += r; - color_g += g; - color_b += b; - } - - r = color_r / scaledownXscaledown; - g = color_g / scaledownXscaledown; - b = color_b / scaledownXscaledown; - macro_put_pixel(); - x++; - } - } else if (d->bit_depth == 8) { - for (pixel=0; pixelxsize + fb_x; - /* fb_addr is which _byte_ in framebuffer */ - c = d->framebuffer[fb_addr] * 3; - r = d->rgb_palette[c + 0]; - g = d->rgb_palette[c + 1]; - b = d->rgb_palette[c + 2]; - color_r += r; - color_g += g; - color_b += b; - } - - r = color_r / scaledownXscaledown; - g = color_g / scaledownXscaledown; - b = color_b / scaledownXscaledown; - macro_put_pixel(); - x++; - } - } else { - /* Generic > 8 bit bit-depth: */ - for (pixel=0; pixelxsize + fb_x; - fb_addr = (fb_addr * d->bit_depth) >> 3; - /* fb_addr is which _byte_ in framebuffer */ - - /* > 8 bits color. */ - switch (d->bit_depth) { - case 24: - r = d->framebuffer[fb_addr]; - g = d->framebuffer[fb_addr + 1]; - b = d->framebuffer[fb_addr + 2]; - break; - default: - r = g = b = random() & 255; - } - color_r += r; - color_g += g; - color_b += b; - } - r = color_r / scaledownXscaledown; - g = color_g / scaledownXscaledown; - b = color_b / scaledownXscaledown; - macro_put_pixel(); - x++; - } - } -} +#endif /* WITH_X11 */ /* @@ -553,12 +399,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 +464,6 @@ d->update_x2 = d->xsize-1; } } while (0); -#endif #ifdef WITH_X11 /* Do we need to redraw the cursor? */ @@ -631,20 +475,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 +507,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 +515,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,19 +533,23 @@ 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; +#ifdef WITH_X11 for (y=d->update_y1; y<=d->update_y2; y+=q) { - update_framebuffer(d, addr, addr2 - addr); + d->redraw_func(d, addr, addr2 - addr); addr += d->bytes_per_line * q; addr2 += d->bytes_per_line * q; } -#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 +564,16 @@ 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; + need_to_flush_x11 = 1; } } #endif @@ -727,12 +588,10 @@ /* * dev_fb_access(): */ -int dev_fb_access(struct cpu *cpu, struct memory *mem, - uint64_t relative_addr, unsigned char *data, size_t len, - int writeflag, void *extra) +DEVICE_ACCESS(fb) { struct vfb_data *d = extra; - int i; + size_t i; #ifdef FB_DEBUG if (writeflag == MEM_WRITE) { if (data[0]) { @@ -750,6 +609,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; i 8) memcpy(d->framebuffer + relative_addr, data, len); - else + else { for (i=0; iframebuffer[relative_addr + i] = data[i]; + } } else { if (len > 8) memcpy(data, d->framebuffer + relative_addr, len); - else + else { for (i=0; iframebuffer[relative_addr + i]; + } } return 1; @@ -835,18 +699,34 @@ /* * dev_fb_init(): * - * xsize and ysize are ignored if vfb_type is VFB_DEC_VFB01 or 02. + * This function is big and ugly, but the point is to initialize a framebuffer + * device. :-) + * + * visible_xsize and visible_ysize are the sizes of the visible display area. + * xsize and ysize tell how much memory is actually allocated (for example + * visible_xsize could be 640, but xsize could be 1024, for better alignment). + * + * vfb_type is useful for selecting special features. + * + * type = VFB_GENERIC is the most useful type, especially when bit_depth = 24. + * + * VFB_DEC_VFB01, _VFB02, and VFB_DEC_MAXINE are DECstation specific. + * + * If type is VFB_HPC, then color encoding differs from the generic case. + * + * If bit_depth = -15 (note the minus sign), then a special hack is used for + * the Playstation Portable's 5-bit R, 5-bit G, 5-bit B. */ struct vfb_data *dev_fb_init(struct machine *machine, struct memory *mem, uint64_t baseaddr, int vfb_type, int visible_xsize, int visible_ysize, - int xsize, int ysize, int bit_depth, char *name, int logo) + int xsize, int ysize, int bit_depth, char *name) { struct vfb_data *d; - size_t size; - int x, y; + size_t size, nlen; + int flags; + int reverse_start = 0; char title[400]; char *name2; - int flags; d = malloc(sizeof(struct vfb_data)); if (d == NULL) { @@ -855,6 +735,11 @@ } memset(d, 0, sizeof(struct vfb_data)); + if (vfb_type & VFB_REVERSE_START) { + vfb_type &= ~VFB_REVERSE_START; + reverse_start = 1; + } + d->vfb_type = vfb_type; /* Defaults: */ @@ -866,6 +751,9 @@ if (bit_depth == 15) { d->color32k = 1; bit_depth = d->bit_depth = 16; + } else if (bit_depth == -15) { + d->psp_15bit = 1; + bit_depth = d->bit_depth = 16; } /* Specific types: */ @@ -894,8 +782,6 @@ d->ysize = ysize; d->visible_ysize = d->ysize; d->bit_depth = 24; break; - default: - ; } if (d->bit_depth == 2 || d->bit_depth == 4) @@ -916,57 +802,63 @@ /* Clear the framebuffer (all black pixels): */ d->framebuffer_size = size; - memset(d->framebuffer, 0, size); + memset(d->framebuffer, reverse_start? 255 : 0, size); d->x11_xsize = d->visible_xsize / d->vfb_scaledown; d->x11_ysize = d->visible_ysize / d->vfb_scaledown; - d->update_x1 = d->update_y1 = 99999; - 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; - } + /* Only "update" from the start if we need to fill with white. */ + /* (The Ximage will be black from the start anyway.) */ + if (reverse_start) { + d->update_x1 = d->update_y1 = 0; + d->update_x2 = d->xsize - 1; + d->update_y2 = d->ysize - 1; + } else { + d->update_x1 = d->update_y1 = 99999; + d->update_x2 = d->update_y2 = -1; } - 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 - if (machine->use_x11) + if (machine->use_x11) { + int i = 0; d->fb_window = x11_fb_init(d->x11_xsize, d->x11_ysize, title, machine->x11_scaledown, machine); - else + switch (d->fb_window->x11_screen_depth) { + case 15: i = 2; break; + case 16: i = 4; break; + case 24: i = 6; break; + } + if (d->fb_window->fb_ximage->byte_order) + i ++; + if (d->vfb_scaledown > 1) + i += 8; + d->redraw_func = redraw[i]; + } else #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);