--- trunk/src/devices/dev_fb.c 2007/10/08 16:18:00 4 +++ trunk/src/devices/dev_fb.c 2007/10/08 16:18:11 6 @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * - * $Id: dev_fb.c,v 1.90 2005/03/29 09:46:06 debug Exp $ + * $Id: dev_fb.c,v 1.94 2005/05/23 14:22:02 debug Exp $ * * Generic framebuffer device. * @@ -65,7 +65,7 @@ #endif -#define FB_TICK_SHIFT 18 +#define FB_TICK_SHIFT 17 #define LOGO_XSIZE 256 #define LOGO_YSIZE 256 @@ -115,6 +115,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, @@ -750,6 +813,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; ivisible_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 @@ -968,6 +1039,8 @@ if ((baseaddr & 0xfff) == 0) flags = MEM_BINTRANS_OK | MEM_BINTRANS_WRITE_OK; + flags |= MEM_READING_HAS_NO_SIDE_EFFECTS; + memory_device_register(mem, name2, baseaddr, size, dev_fb_access, d, flags, d->framebuffer);