/[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 20 by dpavlin, Mon Oct 8 16:19:23 2007 UTC revision 28 by dpavlin, Mon Oct 8 16:20:26 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2003-2005  Anders Gavare.  All rights reserved.   *  Copyright (C) 2003-2006  Anders Gavare.  All rights reserved.
3   *   *
4   *  Redistribution and use in source and binary forms, with or without   *  Redistribution and use in source and binary forms, with or without
5   *  modification, are permitted provided that the following conditions are met:   *  modification, are permitted provided that the following conditions are met:
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *     *  
27   *   *
28   *  $Id: dev_fb.c,v 1.110 2005/11/13 00:14:08 debug Exp $   *  $Id: dev_fb.c,v 1.121 2006/07/08 12:30:02 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:  There is still a bug when redrawing the cursor. The underlying   *  TODO:  This should actually be independent of X11, but that
  *         image is moved 1 pixel (?), or something like that.  
  *  
  *  TODO:  This should actually be independant of X11, but that  
42   *         might be too hard to do right now.   *         might be too hard to do right now.
43   *   *
44   *  TODO:  playstation 2 pixels are stored in another format, actually   *  TODO:  playstation 2 pixels are stored in another format, actually
# Line 65  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 107  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 124  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 153  void dev_fb_resize(struct vfb_data *d, i Line 168  void dev_fb_resize(struct vfb_data *d, i
168          d->framebuffer = new_framebuffer;          d->framebuffer = new_framebuffer;
169          d->framebuffer_size = size;          d->framebuffer_size = size;
170    
171          if (new_xsize > d->x11_xsize || new_ysize > d->x11_ysize) {          if (new_xsize > d->xsize || new_ysize > d->ysize) {
172                  d->update_x1 = d->update_y1 = 0;                  d->update_x1 = d->update_y1 = 0;
173                  d->update_x2 = new_xsize - 1;                  d->update_x2 = new_xsize - 1;
174                  d->update_y2 = new_ysize - 1;                  d->update_y2 = new_ysize - 1;
175          }          }
176    
177          d->bytes_per_line = new_bytes_per_line;          d->bytes_per_line = new_bytes_per_line;
178          d->x11_xsize = d->visible_xsize = new_xsize;          d->xsize = d->visible_xsize = new_xsize;
179          d->x11_ysize = d->visible_ysize = new_ysize;          d->ysize = d->visible_ysize = new_ysize;
180    
181            d->x11_xsize = d->xsize / d->vfb_scaledown;
182            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 248  void framebuffer_blockcopyfill(struct vf Line 272  void framebuffer_blockcopyfill(struct vf
272                                  int x;                                  int x;
273                                  char buf[8192 * 3];                                  char buf[8192 * 3];
274                                  if (d->bit_depth == 24)                                  if (d->bit_depth == 24)
275                                          for (x=0; x<linelen; x+=3) {                                          for (x=0; x<linelen && x<sizeof(buf);
276                                                x += 3) {
277                                                  buf[x] = fill_r;                                                  buf[x] = fill_r;
278                                                  buf[x+1] = fill_g;                                                  buf[x+1] = fill_g;
279                                                  buf[x+2] = fill_b;                                                  buf[x+2] = fill_b;
280                                          }                                          }
281                                  else                                  else {
282                                          printf("TODO: fill for non-24-bit"                                          fatal("[ fb: TODO: fill for non-24-bit"
283                                              " modes\n");                                              " modes ]\n");
284                                    }
285    
286                                  memmove(d->framebuffer + dest_ofs, buf,                                  memmove(d->framebuffer + dest_ofs, buf,
287                                      linelen);                                      linelen);
# Line 290  void framebuffer_blockcopyfill(struct vf Line 316  void framebuffer_blockcopyfill(struct vf
316    
317    
318  #ifdef WITH_X11  #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 && x<d->x11_xsize && y>=0 && y<d->x11_ysize)           \  
                 XPutPixel(d->fb_window->fb_ximage, x, y, color);        \  
     }  
 #else  
 /*  If not WITH_X11:  */  
 #define macro_put_pixel() { }  
 #endif  
   
   
 /*  
  *  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; pixel<npixels; pixel++) {  
                                 int fb_addr, c, r, g, b;  
                                 color_r = color_g = color_b = 0;  
   
                                 fb_addr = (y * d->xsize + x) * d->bit_depth;  
                                 /*  fb_addr is now which _bit_ in  
                                     the framebuffer  */  
   
                                 c = d->framebuffer[fb_addr >> 3];  
                                 fb_addr &= 7;  
   
                                 /*  HPC is reverse:  */  
                                 if (d->vfb_type == VFB_HPC)  
                                         fb_addr = 8 - d->bit_depth - fb_addr;  
   
                                 c = (c >> fb_addr) & ((1<<d->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];  
319    
320                                  macro_put_pixel();  #define REDRAW  redraw_fallback
321                                  x++;  #include "fb_include.c"
322                          }  #undef REDRAW
323                  } else if (d->bit_depth == 8) {  
324                          for (pixel=0; pixel<npixels; pixel++) {  #define FB_24
325                                  int fb_addr, c, r, g, b;  #define REDRAW  redraw_24
326                                  color_r = color_g = color_b = 0;  #include "fb_include.c"
327    #undef REDRAW
328                                  fb_addr = y * d->xsize + x;  #undef FB_24
329                                  /*  fb_addr is now which byte in framebuffer  */  #define FB_16
330                                  c = d->framebuffer[fb_addr];  #define REDRAW  redraw_16
331                                  r = d->rgb_palette[c*3 + 0];  #include "fb_include.c"
332                                  g = d->rgb_palette[c*3 + 1];  #undef FB_16
333                                  b = d->rgb_palette[c*3 + 2];  #undef REDRAW
334    #define FB_15
335    #define REDRAW  redraw_15
336    #include "fb_include.c"
337    #undef REDRAW
338    #undef FB_15
339    
340    #define FB_BO
341    #define FB_24
342    #define REDRAW  redraw_24_bo
343    #include "fb_include.c"
344    #undef REDRAW
345    #undef FB_24
346    #define FB_16
347    #define REDRAW  redraw_16_bo
348    #include "fb_include.c"
349    #undef FB_16
350    #undef REDRAW
351    #define FB_15
352    #define REDRAW  redraw_15_bo
353    #include "fb_include.c"
354    #undef REDRAW
355    #undef FB_15
356    #undef FB_BO
357    
358    #define FB_SCALEDOWN
359    
360    #define REDRAW  redraw_fallback_sd
361    #include "fb_include.c"
362    #undef REDRAW
363    
364    #define FB_24
365    #define REDRAW  redraw_24_sd
366    #include "fb_include.c"
367    #undef REDRAW
368    #undef FB_24
369    #define FB_16
370    #define REDRAW  redraw_16_sd
371    #include "fb_include.c"
372    #undef FB_16
373    #undef REDRAW
374    #define FB_15
375    #define REDRAW  redraw_15_sd
376    #include "fb_include.c"
377    #undef REDRAW
378    #undef FB_15
379    
380    #define FB_BO
381    #define FB_24
382    #define REDRAW  redraw_24_bo_sd
383    #include "fb_include.c"
384    #undef REDRAW
385    #undef FB_24
386    #define FB_16
387    #define REDRAW  redraw_16_bo_sd
388    #include "fb_include.c"
389    #undef FB_16
390    #undef REDRAW
391    #define FB_15
392    #define REDRAW  redraw_15_bo_sd
393    #include "fb_include.c"
394    #undef REDRAW
395    #undef FB_15
396    #undef FB_BO
397    
398    void (*redraw[2 * 4 * 2])(struct vfb_data *, int, int) = {
399            redraw_fallback, redraw_fallback,
400            redraw_15, redraw_15_bo,
401            redraw_16, redraw_16_bo,
402            redraw_24, redraw_24_bo,
403            redraw_fallback_sd, redraw_fallback_sd,
404            redraw_15_sd, redraw_15_bo_sd,
405            redraw_16_sd, redraw_16_bo_sd,
406            redraw_24_sd, redraw_24_bo_sd  };
407    
408                                  macro_put_pixel();  #endif  /*  WITH_X11  */
                                 x++;  
                         }  
                 } else {        /*  d->bit_depth > 8  */  
                         for (pixel=0; pixel<npixels; pixel++) {  
                                 int fb_addr, r, g, b;  
                                 color_r = color_g = color_b = 0;  
   
                                 fb_addr = (y * d->xsize + 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_HPC) {  
                                                 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 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]&31;  
                                         }  
   
                                         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; pixel<npixels; pixel++) {  
                         int subx, suby, r, g, b;  
                         color_r = color_g = color_b = 0;  
                         for (suby=0; suby<scaledown; suby++)  
                             for (subx=0; subx<scaledown; subx++) {  
                                 int fb_x, fb_y, fb_addr, c;  
   
                                 fb_x = x * scaledown + subx;  
                                 fb_y = y * scaledown + suby;  
                                 fb_addr = fb_y * d->xsize + 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;  
   
                                 /*  HPC is reverse:  */  
                                 if (d->vfb_type == VFB_HPC)  
                                         fb_addr = 8 - d->bit_depth - fb_addr;  
   
                                 c = (c >> fb_addr) & ((1<<d->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; pixel<npixels; pixel++) {  
                         int subx, suby, r, g, b;  
                         color_r = color_g = color_b = 0;  
                         for (suby=0; suby<scaledown; suby++)  
                             for (subx=0; subx<scaledown; subx++) {  
                                 int fb_x, fb_y, fb_addr, c;  
   
                                 fb_x = x * scaledown + subx;  
                                 fb_y = y * scaledown + suby;  
                                 fb_addr = fb_y * d->xsize + 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; pixel<npixels; pixel++) {  
                         int subx, suby, r, g, b;  
                         color_r = color_g = color_b = 0;  
                         for (suby=0; suby<scaledown; suby++)  
                             for (subx=0; subx<scaledown; subx++) {  
                                 int fb_x, fb_y, fb_addr;  
   
                                 fb_x = x * scaledown + subx;  
                                 fb_y = y * scaledown + suby;  
                                 fb_addr = fb_y * d->xsize + 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++;  
                 }  
         }  
 }  
409    
410    
411  /*  /*
# Line 738  void dev_fb_tick(struct cpu *cpu, void * Line 537  void dev_fb_tick(struct cpu *cpu, void *
537  #endif  #endif
538    
539          if (d->update_x2 != -1) {          if (d->update_x2 != -1) {
540                  int y, addr, addr2, q = d->vfb_scaledown;  #ifdef WITH_X11
541                    int y;
542    #endif
543                    int addr, addr2, q = d->vfb_scaledown;
544    
545                  if (d->update_x1 >= d->visible_xsize)                  if (d->update_x1 >= d->visible_xsize)
546                          d->update_x1 = d->visible_xsize - 1;                          d->update_x1 = d->visible_xsize - 1;
# Line 763  void dev_fb_tick(struct cpu *cpu, void * Line 565  void dev_fb_tick(struct cpu *cpu, void *
565                  addr2 = d->update_y1 * d->bytes_per_line +                  addr2 = d->update_y1 * d->bytes_per_line +
566                      d->update_x2 * d->bit_depth / 8;                      d->update_x2 * d->bit_depth / 8;
567    
568    #ifdef WITH_X11
569                  for (y=d->update_y1; y<=d->update_y2; y+=q) {                  for (y=d->update_y1; y<=d->update_y2; y+=q) {
570                          update_framebuffer(d, addr, addr2 - addr);                          d->redraw_func(d, addr, addr2 - addr);
571                          addr  += d->bytes_per_line * q;                          addr  += d->bytes_per_line * q;
572                          addr2 += d->bytes_per_line * q;                          addr2 += d->bytes_per_line * q;
573                  }                  }
574    
 #ifdef WITH_X11  
575                  XPutImage(d->fb_window->x11_display, d->fb_window->                  XPutImage(d->fb_window->x11_display, d->fb_window->
576                      x11_fb_window, d->fb_window->x11_fb_gc, d->fb_window->                      x11_fb_window, d->fb_window->x11_fb_gc, d->fb_window->
577                      fb_ximage, d->update_x1/d->vfb_scaledown, d->update_y1/                      fb_ximage, d->update_x1/d->vfb_scaledown, d->update_y1/
# Line 798  void dev_fb_tick(struct cpu *cpu, void * Line 600  void dev_fb_tick(struct cpu *cpu, void *
600                              cursor_xsize;                              cursor_xsize;
601                          d->fb_window->OLD_cursor_ysize = d->fb_window->                          d->fb_window->OLD_cursor_ysize = d->fb_window->
602                              cursor_ysize;                              cursor_ysize;
603                            need_to_flush_x11 = 1;
604                  }                  }
605          }          }
606  #endif  #endif
# Line 812  void dev_fb_tick(struct cpu *cpu, void * Line 615  void dev_fb_tick(struct cpu *cpu, void *
615  /*  /*
616   *  dev_fb_access():   *  dev_fb_access():
617   */   */
618  int dev_fb_access(struct cpu *cpu, struct memory *mem,  DEVICE_ACCESS(fb)
         uint64_t relative_addr, unsigned char *data, size_t len,  
         int writeflag, void *extra)  
619  {  {
620          struct vfb_data *d = extra;          struct vfb_data *d = extra;
621          int i;          size_t i;
622    
623  #ifdef FB_DEBUG  #ifdef FB_DEBUG
624          if (writeflag == MEM_WRITE) { if (data[0]) {          if (writeflag == MEM_WRITE) { if (data[0]) {
# Line 846  int dev_fb_access(struct cpu *cpu, struc Line 647  int dev_fb_access(struct cpu *cpu, struc
647    
648                          /*  If all bytes are equal to what is already stored                          /*  If all bytes are equal to what is already stored
649                              in the framebuffer, then simply return:  */                              in the framebuffer, then simply return:  */
650                          if (i==len-1)                          if (i == len-1)
651                                  return 1;                                  return 1;
652                  }                  }
653          }          }
# Line 905  int dev_fb_access(struct cpu *cpu, struc Line 706  int dev_fb_access(struct cpu *cpu, struc
706          if (writeflag == MEM_WRITE) {          if (writeflag == MEM_WRITE) {
707                  if (len > 8)                  if (len > 8)
708                          memcpy(d->framebuffer + relative_addr, data, len);                          memcpy(d->framebuffer + relative_addr, data, len);
709                  else                  else {
710                          for (i=0; i<len; i++)                          for (i=0; i<len; i++)
711                                  d->framebuffer[relative_addr + i] = data[i];                                  d->framebuffer[relative_addr + i] = data[i];
712                    }
713          } else {          } else {
714                  if (len > 8)                  if (len > 8)
715                          memcpy(data, d->framebuffer + relative_addr, len);                          memcpy(data, d->framebuffer + relative_addr, len);
716                  else                  else {
717                          for (i=0; i<len; i++)                          for (i=0; i<len; i++)
718                                  data[i] = d->framebuffer[relative_addr + i];                                  data[i] = d->framebuffer[relative_addr + i];
719                    }
720          }          }
721    
722          return 1;          return 1;
# Line 948  struct vfb_data *dev_fb_init(struct mach Line 751  struct vfb_data *dev_fb_init(struct mach
751          struct vfb_data *d;          struct vfb_data *d;
752          size_t size, nlen;          size_t size, nlen;
753          int flags;          int flags;
754          char title[400];          int reverse_start = 0;
755          char *name2;          char *name2;
756    
757          d = malloc(sizeof(struct vfb_data));          d = malloc(sizeof(struct vfb_data));
# Line 958  struct vfb_data *dev_fb_init(struct mach Line 761  struct vfb_data *dev_fb_init(struct mach
761          }          }
762          memset(d, 0, sizeof(struct vfb_data));          memset(d, 0, sizeof(struct vfb_data));
763    
764            if (vfb_type & VFB_REVERSE_START) {
765                    vfb_type &= ~VFB_REVERSE_START;
766                    reverse_start = 1;
767            }
768    
769            d->memory = mem;
770          d->vfb_type = vfb_type;          d->vfb_type = vfb_type;
771    
772          /*  Defaults:  */          /*  Defaults:  */
# Line 1000  struct vfb_data *dev_fb_init(struct mach Line 809  struct vfb_data *dev_fb_init(struct mach
809                  d->ysize = ysize;  d->visible_ysize = d->ysize;                  d->ysize = ysize;  d->visible_ysize = d->ysize;
810                  d->bit_depth = 24;                  d->bit_depth = 24;
811                  break;                  break;
         default:  
                 ;  
812          }          }
813    
814          if (d->bit_depth == 2 || d->bit_depth == 4)          if (d->bit_depth == 2 || d->bit_depth == 4)
# Line 1022  struct vfb_data *dev_fb_init(struct mach Line 829  struct vfb_data *dev_fb_init(struct mach
829    
830          /*  Clear the framebuffer (all black pixels):  */          /*  Clear the framebuffer (all black pixels):  */
831          d->framebuffer_size = size;          d->framebuffer_size = size;
832          memset(d->framebuffer, 0, size);          memset(d->framebuffer, reverse_start? 255 : 0, size);
833    
834          d->x11_xsize = d->visible_xsize / d->vfb_scaledown;          d->x11_xsize = d->visible_xsize / d->vfb_scaledown;
835          d->x11_ysize = d->visible_ysize / d->vfb_scaledown;          d->x11_ysize = d->visible_ysize / d->vfb_scaledown;
836    
837          d->update_x1 = d->update_y1 = 99999;          /*  Only "update" from the start if we need to fill with white.  */
838          d->update_x2 = d->update_y2 = -1;          /*  (The Ximage will be black from the start anyway.)  */
839            if (reverse_start) {
840                    d->update_x1 = d->update_y1 = 0;
841                    d->update_x2 = d->xsize - 1;
842                    d->update_y2 = d->ysize - 1;
843            } else {
844                    d->update_x1 = d->update_y1 = 99999;
845                    d->update_x2 = d->update_y2 = -1;
846            }
847    
848          /*  Don't set the title to include the size of the framebuffer for          d->name = strdup(name);
849              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';  
850    
851  #ifdef WITH_X11  #ifdef WITH_X11
852          if (machine->use_x11)          if (machine->use_x11) {
853                    int i = 0;
854                  d->fb_window = x11_fb_init(d->x11_xsize, d->x11_ysize,                  d->fb_window = x11_fb_init(d->x11_xsize, d->x11_ysize,
855                      title, machine->x11_scaledown, machine);                      d->title, machine->x11_scaledown, machine);
856          else                  switch (d->fb_window->x11_screen_depth) {
857                    case 15: i = 2; break;
858                    case 16: i = 4; break;
859                    case 24: i = 6; break;
860                    }
861                    if (d->fb_window->fb_ximage->byte_order)
862                            i ++;
863                    if (d->vfb_scaledown > 1)
864                            i += 8;
865                    d->redraw_func = redraw[i];
866            } else
867  #endif  #endif
868                  d->fb_window = NULL;                  d->fb_window = NULL;
869    
# Line 1065  struct vfb_data *dev_fb_init(struct mach Line 884  struct vfb_data *dev_fb_init(struct mach
884          memory_device_register(mem, name2, baseaddr, size, dev_fb_access,          memory_device_register(mem, name2, baseaddr, size, dev_fb_access,
885              d, flags, d->framebuffer);              d, flags, d->framebuffer);
886    
887          machine_add_tickfunction(machine, dev_fb_tick, d, FB_TICK_SHIFT);          machine_add_tickfunction(machine, dev_fb_tick, d, FB_TICK_SHIFT, 0.0);
888          return d;          return d;
889  }  }
890    

Legend:
Removed from v.20  
changed lines
  Added in v.28

  ViewVC Help
Powered by ViewVC 1.1.26