/[gxemul]/trunk/src/devices/dev_fb.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/src/devices/dev_fb.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 24 by dpavlin, Mon Oct 8 16:19:56 2007 UTC revision 30 by dpavlin, Mon Oct 8 16:20:40 2007 UTC
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *     *  
27   *   *
28   *  $Id: dev_fb.c,v 1.118 2006/03/04 12:38:47 debug Exp $   *  $Id: dev_fb.c,v 1.123 2006/07/24 08:08:39 debug Exp $
29   *     *  
30   *  Generic framebuffer device.   *  Generic framebuffer device.
31   *   *
# Line 34  Line 34 
34   *      DECstation Maxine, 1024x768 8-bit color   *      DECstation Maxine, 1024x768 8-bit color
35   *      HPC (mips, arm, ..) 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, useful for
38     *              testmachines)
39   *   *
40   *   *
41   *  TODO:  This should actually be independent of X11, but that   *  TODO:  This should actually be independent of X11, but that
# Line 62  Line 63 
63  #endif  #endif
64    
65    
66  #define FB_TICK_SHIFT           18  #define FB_TICK_SHIFT           19
67    
68    
69  /*  #define FB_DEBUG  */  /*  #define FB_DEBUG  */
# Line 104  void set_blackwhite_palette(struct vfb_d Line 105  void set_blackwhite_palette(struct vfb_d
105  }  }
106    
107    
108    static void set_title(struct vfb_data *d)
109    {
110            snprintf(d->title, sizeof(d->title),"GXemul: %ix%ix%i %s framebuffer",
111                d->visible_xsize, d->visible_ysize, d->bit_depth, d->name);
112            d->title[sizeof(d->title)-1] = '\0';
113    }
114    
115    
116  /*  /*
117   *  dev_fb_resize():   *  dev_fb_resize():
118   *   *
119   *  Resize a framebuffer window. (This functionality is probably a bit buggy,   *  Resize a framebuffer window. (This functionality is probably a bit buggy,
120   *  because I didn't think of including it from the start.)   *  because I didn't think of including it from the start.)
121     *
122     *  SUPER-IMPORTANT: Anyone who resizes a framebuffer by calling this function
123     *  must also clear all dyntrans address translations manually, in all cpus
124     *  which might have access to the framebuffer!
125   */   */
126  void dev_fb_resize(struct vfb_data *d, int new_xsize, int new_ysize)  void dev_fb_resize(struct vfb_data *d, int new_xsize, int new_ysize)
127  {  {
# Line 121  void dev_fb_resize(struct vfb_data *d, i Line 134  void dev_fb_resize(struct vfb_data *d, i
134                  return;                  return;
135          }          }
136    
137            if (new_xsize < 10 || new_ysize < 10) {
138                    fatal("dev_fb_resize(): size too small.\n");
139                    exit(1);
140            }
141    
142          new_bytes_per_line = new_xsize * d->bit_depth / 8;          new_bytes_per_line = new_xsize * d->bit_depth / 8;
143          size = new_ysize * new_bytes_per_line;          size = new_ysize * new_bytes_per_line;
144    
# Line 163  void dev_fb_resize(struct vfb_data *d, i Line 181  void dev_fb_resize(struct vfb_data *d, i
181          d->x11_xsize = d->xsize / d->vfb_scaledown;          d->x11_xsize = d->xsize / d->vfb_scaledown;
182          d->x11_ysize = d->ysize / d->vfb_scaledown;          d->x11_ysize = d->ysize / d->vfb_scaledown;
183    
184            memory_device_update_data(d->memory, d, d->framebuffer);
185    
186            set_title(d);
187    
188  #ifdef WITH_X11  #ifdef WITH_X11
189          if (d->fb_window != NULL)          if (d->fb_window != NULL) {
190                  x11_fb_resize(d->fb_window, new_xsize, new_ysize);                  x11_fb_resize(d->fb_window, new_xsize, new_ysize);
191                    x11_set_standard_properties(d->fb_window, d->title);
192            }
193  #endif  #endif
194  }  }
195    
# Line 211  void dev_fb_setcursor(struct vfb_data *d Line 235  void dev_fb_setcursor(struct vfb_data *d
235   *  block copy/fill.   *  block copy/fill.
236   *   *
237   *  If fillflag is non-zero, then fill_[rgb] should contain the color   *  If fillflag is non-zero, then fill_[rgb] should contain the color
238   *  with which to fill.   *  with which to fill. (In 8-bit mode, only fill_r is used.)
239   *   *
240   *  If fillflag is zero, copy mode is used, and from_[xy] should contain   *  If fillflag is zero, copy mode is used, and from_[xy] should contain
241   *  the offset on the framebuffer where we should copy from.   *  the offset on the framebuffer where we should copy from.
# Line 222  void framebuffer_blockcopyfill(struct vf Line 246  void framebuffer_blockcopyfill(struct vf
246          int fill_g, int fill_b, int x1, int y1, int x2, int y2,          int fill_g, int fill_b, int x1, int y1, int x2, int y2,
247          int from_x, int from_y)          int from_x, int from_y)
248  {  {
249          int y;          int x, y;
250          long from_ofs, dest_ofs, linelen;          long from_ofs, dest_ofs, linelen;
251    
252          if (fillflag)          if (fillflag)
# Line 245  void framebuffer_blockcopyfill(struct vf Line 269  void framebuffer_blockcopyfill(struct vf
269          if (fillflag) {          if (fillflag) {
270                  for (y=y1; y<=y2; y++) {                  for (y=y1; y<=y2; y++) {
271                          if (y>=0 && y<d->ysize) {                          if (y>=0 && y<d->ysize) {
272                                  int x;                                  unsigned char *buf =
273                                  char buf[8192 * 3];                                      d->framebuffer + dest_ofs;
274                                  if (d->bit_depth == 24)  
275                                    if (d->bit_depth == 24) {
276                                          for (x=0; x<linelen && x<sizeof(buf);                                          for (x=0; x<linelen && x<sizeof(buf);
277                                              x += 3) {                                              x += 3) {
278                                                  buf[x] = fill_r;                                                  buf[x] = fill_r;
279                                                  buf[x+1] = fill_g;                                                  buf[x+1] = fill_g;
280                                                  buf[x+2] = fill_b;                                                  buf[x+2] = fill_b;
281                                          }                                          }
282                                  else {                                  } else if (d->bit_depth == 8) {
283                                          fatal("[ fb: TODO: fill for non-24-bit"                                          memset(buf, fill_r, linelen);
284                                              " modes ]\n");                                  } else {
285                                            fatal("Unimplemented bit-depth (%i)"
286                                                " for fb fill\n", d->bit_depth);
287                                            exit(1);
288                                  }                                  }
   
                                 memmove(d->framebuffer + dest_ofs, buf,  
                                     linelen);  
289                          }                          }
290    
291                          dest_ofs += d->bytes_per_line;                          dest_ofs += d->bytes_per_line;
# Line 268  void framebuffer_blockcopyfill(struct vf Line 293  void framebuffer_blockcopyfill(struct vf
293          } else {          } else {
294                  from_ofs = d->bytes_per_line * from_y +                  from_ofs = d->bytes_per_line * from_y +
295                      (d->bit_depth/8) * from_x;                      (d->bit_depth/8) * from_x;
   
296                  for (y=y1; y<=y2; y++) {                  for (y=y1; y<=y2; y++) {
297                          if (y>=0 && y<d->ysize)                          if (y >= 0 && y < d->ysize) {
298                                  memmove(d->framebuffer + dest_ofs,                                  if (from_y >= 0 && from_y < d->ysize)
299                                      d->framebuffer + from_ofs, linelen);                                          memmove(d->framebuffer + dest_ofs,
300                                                d->framebuffer + from_ofs, linelen);
301                                    else
302                                            memset(d->framebuffer + dest_ofs,
303                                                0, linelen);
304                            }
305                            from_y ++;
306                          from_ofs += d->bytes_per_line;                          from_ofs += d->bytes_per_line;
307                          dest_ofs += d->bytes_per_line;                          dest_ofs += d->bytes_per_line;
308                  }                  }
# Line 728  struct vfb_data *dev_fb_init(struct mach Line 757  struct vfb_data *dev_fb_init(struct mach
757          size_t size, nlen;          size_t size, nlen;
758          int flags;          int flags;
759          int reverse_start = 0;          int reverse_start = 0;
         char title[400];  
760          char *name2;          char *name2;
761    
762          d = malloc(sizeof(struct vfb_data));          d = malloc(sizeof(struct vfb_data));
# Line 743  struct vfb_data *dev_fb_init(struct mach Line 771  struct vfb_data *dev_fb_init(struct mach
771                  reverse_start = 1;                  reverse_start = 1;
772          }          }
773    
774            d->memory = mem;
775          d->vfb_type = vfb_type;          d->vfb_type = vfb_type;
776    
777          /*  Defaults:  */          /*  Defaults:  */
# Line 821  struct vfb_data *dev_fb_init(struct mach Line 850  struct vfb_data *dev_fb_init(struct mach
850                  d->update_x2 = d->update_y2 = -1;                  d->update_x2 = d->update_y2 = -1;
851          }          }
852    
853          /*  Don't set the title to include the size of the framebuffer for          d->name = strdup(name);
854              VGA, since then the resolution might change during runtime.  */          set_title(d);
         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';  
855    
856  #ifdef WITH_X11  #ifdef WITH_X11
857          if (machine->use_x11) {          if (machine->use_x11) {
858                  int i = 0;                  int i = 0;
859                  d->fb_window = x11_fb_init(d->x11_xsize, d->x11_ysize,                  d->fb_window = x11_fb_init(d->x11_xsize, d->x11_ysize,
860                      title, machine->x11_scaledown, machine);                      d->title, machine->x11_scaledown, machine);
861                  switch (d->fb_window->x11_screen_depth) {                  switch (d->fb_window->x11_screen_depth) {
862                  case 15: i = 2; break;                  case 15: i = 2; break;
863                  case 16: i = 4; break;                  case 16: i = 4; break;

Legend:
Removed from v.24  
changed lines
  Added in v.30

  ViewVC Help
Powered by ViewVC 1.1.26