/[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 10 by dpavlin, Mon Oct 8 16:18:27 2007 UTC revision 24 by dpavlin, Mon Oct 8 16:19:56 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.99 2005/06/26 13:49:06 debug Exp $   *  $Id: dev_fb.c,v 1.118 2006/03/04 12:38:47 debug Exp $
29   *     *  
30   *  Generic framebuffer device.   *  Generic framebuffer device.
31   *   *
32   *      DECstation VFB01 monochrome framebuffer, 1024x864   *      DECstation VFB01 monochrome framebuffer, 1024x864
33   *      DECstation VFB02 8-bit color framebuffer, 1024x864   *      DECstation VFB02 8-bit color framebuffer, 1024x864
34   *      DECstation Maxine, 1024x768 8-bit color   *      DECstation Maxine, 1024x768 8-bit color
35   *      HPCmips 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)
38   *   *
39   *   *
40   *  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  
41   *         might be too hard to do right now.   *         might be too hard to do right now.
42   *   *
43   *  TODO:  playstation 2 pixels are stored in another format, actually   *  TODO:  playstation 2 pixels are stored in another format, actually
# Line 67  Line 64 
64    
65  #define FB_TICK_SHIFT           18  #define FB_TICK_SHIFT           18
66    
 #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;  
   
67    
68  /*  #define FB_DEBUG  */  /*  #define FB_DEBUG  */
69    
# Line 160  void dev_fb_resize(struct vfb_data *d, i Line 150  void dev_fb_resize(struct vfb_data *d, i
150          d->framebuffer = new_framebuffer;          d->framebuffer = new_framebuffer;
151          d->framebuffer_size = size;          d->framebuffer_size = size;
152    
153          if (new_xsize > d->x11_xsize || new_ysize > d->x11_ysize) {          if (new_xsize > d->xsize || new_ysize > d->ysize) {
154                  d->update_x1 = d->update_y1 = 0;                  d->update_x1 = d->update_y1 = 0;
155                  d->update_x2 = new_xsize - 1;                  d->update_x2 = new_xsize - 1;
156                  d->update_y2 = new_ysize - 1;                  d->update_y2 = new_ysize - 1;
157          }          }
158    
159          d->bytes_per_line = new_bytes_per_line;          d->bytes_per_line = new_bytes_per_line;
160          d->x11_xsize = d->visible_xsize = new_xsize;          d->xsize = d->visible_xsize = new_xsize;
161          d->x11_ysize = d->visible_ysize = new_ysize;          d->ysize = d->visible_ysize = new_ysize;
162    
163            d->x11_xsize = d->xsize / d->vfb_scaledown;
164            d->x11_ysize = d->ysize / d->vfb_scaledown;
165    
166  #ifdef WITH_X11  #ifdef WITH_X11
167          if (d->fb_window != NULL)          if (d->fb_window != NULL)
# Line 255  void framebuffer_blockcopyfill(struct vf Line 248  void framebuffer_blockcopyfill(struct vf
248                                  int x;                                  int x;
249                                  char buf[8192 * 3];                                  char buf[8192 * 3];
250                                  if (d->bit_depth == 24)                                  if (d->bit_depth == 24)
251                                          for (x=0; x<linelen; x+=3) {                                          for (x=0; x<linelen && x<sizeof(buf);
252                                                x += 3) {
253                                                  buf[x] = fill_r;                                                  buf[x] = fill_r;
254                                                  buf[x+1] = fill_g;                                                  buf[x+1] = fill_g;
255                                                  buf[x+2] = fill_b;                                                  buf[x+2] = fill_b;
256                                          }                                          }
257                                  else                                  else {
258                                          printf("TODO: fill for non-24-bit"                                          fatal("[ fb: TODO: fill for non-24-bit"
259                                              " modes\n");                                              " modes ]\n");
260                                    }
261    
262                                  memmove(d->framebuffer + dest_ofs, buf,                                  memmove(d->framebuffer + dest_ofs, buf,
263                                      linelen);                                      linelen);
# Line 297  void framebuffer_blockcopyfill(struct vf Line 292  void framebuffer_blockcopyfill(struct vf
292    
293    
294  #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;  
   
                                 /*  HPCmips is reverse:  */  
                                 if (d->vfb_type == VFB_HPCMIPS)  
                                         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];  
   
                                 macro_put_pixel();  
                                 x++;  
                         }  
                 } else 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;  
                                 /*  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; 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_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 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 *= 8;  
                                         g *= 4;  
                                         b *= 8;  
                                         break;  
                                 default:  
                                         r = g = b = random() & 255;  
                                 }  
   
                                 macro_put_pixel();  
                                 x++;  
                         }  
                 }  
   
                 return;  
         }  
   
         /*  scaledown != 1:  */  
295    
296          scaledown = d->vfb_scaledown;  #define REDRAW  redraw_fallback
297          scaledownXscaledown = scaledown * scaledown;  #include "fb_include.c"
298    #undef REDRAW
299    
300    #define FB_24
301    #define REDRAW  redraw_24
302    #include "fb_include.c"
303    #undef REDRAW
304    #undef FB_24
305    #define FB_16
306    #define REDRAW  redraw_16
307    #include "fb_include.c"
308    #undef FB_16
309    #undef REDRAW
310    #define FB_15
311    #define REDRAW  redraw_15
312    #include "fb_include.c"
313    #undef REDRAW
314    #undef FB_15
315    
316    #define FB_BO
317    #define FB_24
318    #define REDRAW  redraw_24_bo
319    #include "fb_include.c"
320    #undef REDRAW
321    #undef FB_24
322    #define FB_16
323    #define REDRAW  redraw_16_bo
324    #include "fb_include.c"
325    #undef FB_16
326    #undef REDRAW
327    #define FB_15
328    #define REDRAW  redraw_15_bo
329    #include "fb_include.c"
330    #undef REDRAW
331    #undef FB_15
332    #undef FB_BO
333    
334    #define FB_SCALEDOWN
335    
336    #define REDRAW  redraw_fallback_sd
337    #include "fb_include.c"
338    #undef REDRAW
339    
340    #define FB_24
341    #define REDRAW  redraw_24_sd
342    #include "fb_include.c"
343    #undef REDRAW
344    #undef FB_24
345    #define FB_16
346    #define REDRAW  redraw_16_sd
347    #include "fb_include.c"
348    #undef FB_16
349    #undef REDRAW
350    #define FB_15
351    #define REDRAW  redraw_15_sd
352    #include "fb_include.c"
353    #undef REDRAW
354    #undef FB_15
355    
356    #define FB_BO
357    #define FB_24
358    #define REDRAW  redraw_24_bo_sd
359    #include "fb_include.c"
360    #undef REDRAW
361    #undef FB_24
362    #define FB_16
363    #define REDRAW  redraw_16_bo_sd
364    #include "fb_include.c"
365    #undef FB_16
366    #undef REDRAW
367    #define FB_15
368    #define REDRAW  redraw_15_bo_sd
369    #include "fb_include.c"
370    #undef REDRAW
371    #undef FB_15
372    #undef FB_BO
373    
374    void (*redraw[2 * 4 * 2])(struct vfb_data *, int, int) = {
375            redraw_fallback, redraw_fallback,
376            redraw_15, redraw_15_bo,
377            redraw_16, redraw_16_bo,
378            redraw_24, redraw_24_bo,
379            redraw_fallback_sd, redraw_fallback_sd,
380            redraw_15_sd, redraw_15_bo_sd,
381            redraw_16_sd, redraw_16_bo_sd,
382            redraw_24_sd, redraw_24_bo_sd  };
383    
384          /*  Which framebuffer pixel does addr correspond to?  */  #endif  /*  WITH_X11  */
         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;  
   
                                 /*  HPCmips is reverse:  */  
                                 if (d->vfb_type == VFB_HPCMIPS)  
                                         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++;  
                 }  
         }  
 }  
385    
386    
387  /*  /*
# Line 623  void dev_fb_tick(struct cpu *cpu, void * Line 399  void dev_fb_tick(struct cpu *cpu, void *
399          if (!cpu->machine->use_x11)          if (!cpu->machine->use_x11)
400                  return;                  return;
401    
 #ifdef BINTRANS  
402          do {          do {
403                  uint64_t low = -1, high;                  uint64_t high, low = (uint64_t)(int64_t) -1;
404                  int x, y;                  int x, y;
405    
406                  memory_device_bintrans_access(cpu, cpu->mem,                  memory_device_dyntrans_access(cpu, cpu->mem,
407                      extra, &low, &high);                      extra, &low, &high);
408                  if ((int64_t)low == -1)                  if ((int64_t)low == -1)
409                          break;                          break;
# Line 689  void dev_fb_tick(struct cpu *cpu, void * Line 464  void dev_fb_tick(struct cpu *cpu, void *
464                          d->update_x2 = d->xsize-1;                          d->update_x2 = d->xsize-1;
465                  }                  }
466          } while (0);          } while (0);
 #endif  
467    
468  #ifdef WITH_X11  #ifdef WITH_X11
469          /*  Do we need to redraw the cursor?  */          /*  Do we need to redraw the cursor?  */
# Line 701  void dev_fb_tick(struct cpu *cpu, void * Line 475  void dev_fb_tick(struct cpu *cpu, void *
475                  need_to_redraw_cursor = 1;                  need_to_redraw_cursor = 1;
476    
477          if (d->update_x2 != -1) {          if (d->update_x2 != -1) {
478                  if ( (d->update_x1 >= d->fb_window->OLD_cursor_x &&                  if (((d->update_x1 >= d->fb_window->OLD_cursor_x &&
479                        d->update_x1 < (d->fb_window->OLD_cursor_x + d->fb_window->OLD_cursor_xsize)) ||                        d->update_x1 < (d->fb_window->OLD_cursor_x +
480                          d->fb_window->OLD_cursor_xsize)) ||
481                       (d->update_x2 >= d->fb_window->OLD_cursor_x &&                       (d->update_x2 >= d->fb_window->OLD_cursor_x &&
482                        d->update_x2 < (d->fb_window->OLD_cursor_x + d->fb_window->OLD_cursor_xsize)) ||                        d->update_x2 < (d->fb_window->OLD_cursor_x +
483                          d->fb_window->OLD_cursor_xsize)) ||
484                       (d->update_x1 <  d->fb_window->OLD_cursor_x &&                       (d->update_x1 <  d->fb_window->OLD_cursor_x &&
485                        d->update_x2 >= (d->fb_window->OLD_cursor_x + d->fb_window->OLD_cursor_xsize)) ) {                        d->update_x2 >= (d->fb_window->OLD_cursor_x +
486                          if ( (d->update_y1 >= d->fb_window->OLD_cursor_y &&                        d->fb_window->OLD_cursor_xsize)) ) &&
487                                d->update_y1 < (d->fb_window->OLD_cursor_y + d->fb_window->OLD_cursor_ysize)) ||                     ( (d->update_y1 >= d->fb_window->OLD_cursor_y &&
488                               (d->update_y2 >= d->fb_window->OLD_cursor_y &&                        d->update_y1 < (d->fb_window->OLD_cursor_y +
489                                d->update_y2 < (d->fb_window->OLD_cursor_y + d->fb_window->OLD_cursor_ysize)) ||                        d->fb_window->OLD_cursor_ysize)) ||
490                               (d->update_y1 <  d->fb_window->OLD_cursor_y &&                       (d->update_y2 >= d->fb_window->OLD_cursor_y &&
491                                d->update_y2 >= (d->fb_window->OLD_cursor_y + d->fb_window->OLD_cursor_ysize)) )                        d->update_y2 < (d->fb_window->OLD_cursor_y +
492                                  need_to_redraw_cursor = 1;                        d->fb_window->OLD_cursor_ysize)) ||
493                  }                       (d->update_y1 <  d->fb_window->OLD_cursor_y &&
494                          d->update_y2 >= (d->fb_window->OLD_cursor_y +
495                         d->fb_window->OLD_cursor_ysize)) ) )
496                            need_to_redraw_cursor = 1;
497          }          }
498    
499          if (need_to_redraw_cursor) {          if (need_to_redraw_cursor) {
# Line 728  void dev_fb_tick(struct cpu *cpu, void * Line 507  void dev_fb_tick(struct cpu *cpu, void *
507                              d->fb_window->OLD_cursor_x/d->vfb_scaledown,                              d->fb_window->OLD_cursor_x/d->vfb_scaledown,
508                              d->fb_window->OLD_cursor_y/d->vfb_scaledown,                              d->fb_window->OLD_cursor_y/d->vfb_scaledown,
509                              d->fb_window->OLD_cursor_xsize/d->vfb_scaledown + 1,                              d->fb_window->OLD_cursor_xsize/d->vfb_scaledown + 1,
510                              d->fb_window->OLD_cursor_ysize/d->vfb_scaledown + 1);                              d->fb_window->OLD_cursor_ysize/d->vfb_scaledown +1);
511                  }                  }
512          }          }
513  #endif  #endif
514    
515          if (d->update_x2 != -1) {          if (d->update_x2 != -1) {
516                  int y, addr, addr2, q = d->vfb_scaledown;  #ifdef WITH_X11
517                    int y;
518    #endif
519                    int addr, addr2, q = d->vfb_scaledown;
520    
521                  if (d->update_x1 >= d->visible_xsize)   d->update_x1 = d->visible_xsize - 1;                  if (d->update_x1 >= d->visible_xsize)
522                  if (d->update_x2 >= d->visible_xsize)   d->update_x2 = d->visible_xsize - 1;                          d->update_x1 = d->visible_xsize - 1;
523                  if (d->update_y1 >= d->visible_ysize)   d->update_y1 = d->visible_ysize - 1;                  if (d->update_x2 >= d->visible_xsize)
524                  if (d->update_y2 >= d->visible_ysize)   d->update_y2 = d->visible_ysize - 1;                          d->update_x2 = d->visible_xsize - 1;
525                    if (d->update_y1 >= d->visible_ysize)
526                            d->update_y1 = d->visible_ysize - 1;
527                    if (d->update_y2 >= d->visible_ysize)
528                            d->update_y2 = d->visible_ysize - 1;
529    
530                  /*  Without these, we might miss the right most / bottom pixel:  */                  /*  Without these, we might miss the rightmost/bottom pixel:  */
531                  d->update_x2 += (q - 1);                  d->update_x2 += (q - 1);
532                  d->update_y2 += (q - 1);                  d->update_y2 += (q - 1);
533    
# Line 750  void dev_fb_tick(struct cpu *cpu, void * Line 536  void dev_fb_tick(struct cpu *cpu, void *
536                  d->update_y1 = d->update_y1 / q * q;                  d->update_y1 = d->update_y1 / q * q;
537                  d->update_y2 = d->update_y2 / q * q;                  d->update_y2 = d->update_y2 / q * q;
538    
539                  addr  = d->update_y1 * d->bytes_per_line + d->update_x1 * d->bit_depth / 8;                  addr  = d->update_y1 * d->bytes_per_line +
540                  addr2 = d->update_y1 * d->bytes_per_line + d->update_x2 * d->bit_depth / 8;                      d->update_x1 * d->bit_depth / 8;
541                    addr2 = d->update_y1 * d->bytes_per_line +
542                        d->update_x2 * d->bit_depth / 8;
543    
544    #ifdef WITH_X11
545                  for (y=d->update_y1; y<=d->update_y2; y+=q) {                  for (y=d->update_y1; y<=d->update_y2; y+=q) {
546                          update_framebuffer(d, addr, addr2 - addr);                          d->redraw_func(d, addr, addr2 - addr);
547                          addr  += d->bytes_per_line * q;                          addr  += d->bytes_per_line * q;
548                          addr2 += d->bytes_per_line * q;                          addr2 += d->bytes_per_line * q;
549                  }                  }
550    
551  #ifdef WITH_X11                  XPutImage(d->fb_window->x11_display, d->fb_window->
552                  XPutImage(d->fb_window->x11_display, d->fb_window->x11_fb_window, d->fb_window->x11_fb_gc, d->fb_window->fb_ximage,                      x11_fb_window, d->fb_window->x11_fb_gc, d->fb_window->
553                      d->update_x1/d->vfb_scaledown, d->update_y1/d->vfb_scaledown,                      fb_ximage, d->update_x1/d->vfb_scaledown, d->update_y1/
554                      d->update_x1/d->vfb_scaledown, d->update_y1/d->vfb_scaledown,                      d->vfb_scaledown, d->update_x1/d->vfb_scaledown,
555                        d->update_y1/d->vfb_scaledown,
556                      (d->update_x2 - d->update_x1)/d->vfb_scaledown + 1,                      (d->update_x2 - d->update_x1)/d->vfb_scaledown + 1,
557                      (d->update_y2 - d->update_y1)/d->vfb_scaledown + 1);                      (d->update_y2 - d->update_y1)/d->vfb_scaledown + 1);
558    
# Line 777  void dev_fb_tick(struct cpu *cpu, void * Line 567  void dev_fb_tick(struct cpu *cpu, void *
567          if (need_to_redraw_cursor) {          if (need_to_redraw_cursor) {
568                  /*  Paint new cursor:  */                  /*  Paint new cursor:  */
569                  if (d->fb_window->cursor_on) {                  if (d->fb_window->cursor_on) {
570                          x11_redraw_cursor(cpu->machine, d->fb_window->fb_number);                          x11_redraw_cursor(cpu->machine,
571                                d->fb_window->fb_number);
572                          d->fb_window->OLD_cursor_on = d->fb_window->cursor_on;                          d->fb_window->OLD_cursor_on = d->fb_window->cursor_on;
573                          d->fb_window->OLD_cursor_x = d->fb_window->cursor_x;                          d->fb_window->OLD_cursor_x = d->fb_window->cursor_x;
574                          d->fb_window->OLD_cursor_y = d->fb_window->cursor_y;                          d->fb_window->OLD_cursor_y = d->fb_window->cursor_y;
575                          d->fb_window->OLD_cursor_xsize = d->fb_window->cursor_xsize;                          d->fb_window->OLD_cursor_xsize = d->fb_window->
576                          d->fb_window->OLD_cursor_ysize = d->fb_window->cursor_ysize;                              cursor_xsize;
577                            d->fb_window->OLD_cursor_ysize = d->fb_window->
578                                cursor_ysize;
579                            need_to_flush_x11 = 1;
580                  }                  }
581          }          }
582  #endif  #endif
# Line 797  void dev_fb_tick(struct cpu *cpu, void * Line 591  void dev_fb_tick(struct cpu *cpu, void *
591  /*  /*
592   *  dev_fb_access():   *  dev_fb_access():
593   */   */
594  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)  
595  {  {
596          struct vfb_data *d = extra;          struct vfb_data *d = extra;
597          int i;          size_t i;
598    
599  #ifdef FB_DEBUG  #ifdef FB_DEBUG
600          if (writeflag == MEM_WRITE) { if (data[0]) {          if (writeflag == MEM_WRITE) { if (data[0]) {
# Line 831  int dev_fb_access(struct cpu *cpu, struc Line 623  int dev_fb_access(struct cpu *cpu, struc
623    
624                          /*  If all bytes are equal to what is already stored                          /*  If all bytes are equal to what is already stored
625                              in the framebuffer, then simply return:  */                              in the framebuffer, then simply return:  */
626                          if (i==len-1)                          if (i == len-1)
627                                  return 1;                                  return 1;
628                  }                  }
629          }          }
# Line 890  int dev_fb_access(struct cpu *cpu, struc Line 682  int dev_fb_access(struct cpu *cpu, struc
682          if (writeflag == MEM_WRITE) {          if (writeflag == MEM_WRITE) {
683                  if (len > 8)                  if (len > 8)
684                          memcpy(d->framebuffer + relative_addr, data, len);                          memcpy(d->framebuffer + relative_addr, data, len);
685                  else                  else {
686                          for (i=0; i<len; i++)                          for (i=0; i<len; i++)
687                                  d->framebuffer[relative_addr + i] = data[i];                                  d->framebuffer[relative_addr + i] = data[i];
688                    }
689          } else {          } else {
690                  if (len > 8)                  if (len > 8)
691                          memcpy(data, d->framebuffer + relative_addr, len);                          memcpy(data, d->framebuffer + relative_addr, len);
692                  else                  else {
693                          for (i=0; i<len; i++)                          for (i=0; i<len; i++)
694                                  data[i] = d->framebuffer[relative_addr + i];                                  data[i] = d->framebuffer[relative_addr + i];
695                    }
696          }          }
697    
698          return 1;          return 1;
# Line 921  int dev_fb_access(struct cpu *cpu, struc Line 715  int dev_fb_access(struct cpu *cpu, struc
715   *   *
716   *  VFB_DEC_VFB01, _VFB02, and VFB_DEC_MAXINE are DECstation specific.   *  VFB_DEC_VFB01, _VFB02, and VFB_DEC_MAXINE are DECstation specific.
717   *   *
718   *  If type is VFB_HPCMIPS, then color encoding differs from the generic case.   *  If type is VFB_HPC, then color encoding differs from the generic case.
719   *   *
720   *  If bit_depth = -15 (note the minus sign), then a special hack is used for   *  If bit_depth = -15 (note the minus sign), then a special hack is used for
721   *  the Playstation Portable's 5-bit R, 5-bit G, 5-bit B.   *  the Playstation Portable's 5-bit R, 5-bit G, 5-bit B.
722   */   */
723  struct vfb_data *dev_fb_init(struct machine *machine, struct memory *mem,  struct vfb_data *dev_fb_init(struct machine *machine, struct memory *mem,
724          uint64_t baseaddr, int vfb_type, int visible_xsize, int visible_ysize,          uint64_t baseaddr, int vfb_type, int visible_xsize, int visible_ysize,
725          int xsize, int ysize, int bit_depth, char *name, int logo)          int xsize, int ysize, int bit_depth, char *name)
726  {  {
727          struct vfb_data *d;          struct vfb_data *d;
728          size_t size, nlen;          size_t size, nlen;
729          int x, y, flags;          int flags;
730            int reverse_start = 0;
731          char title[400];          char title[400];
732          char *name2;          char *name2;
733    
# Line 943  struct vfb_data *dev_fb_init(struct mach Line 738  struct vfb_data *dev_fb_init(struct mach
738          }          }
739          memset(d, 0, sizeof(struct vfb_data));          memset(d, 0, sizeof(struct vfb_data));
740    
741            if (vfb_type & VFB_REVERSE_START) {
742                    vfb_type &= ~VFB_REVERSE_START;
743                    reverse_start = 1;
744            }
745    
746          d->vfb_type = vfb_type;          d->vfb_type = vfb_type;
747    
748          /*  Defaults:  */          /*  Defaults:  */
# Line 985  struct vfb_data *dev_fb_init(struct mach Line 785  struct vfb_data *dev_fb_init(struct mach
785                  d->ysize = ysize;  d->visible_ysize = d->ysize;                  d->ysize = ysize;  d->visible_ysize = d->ysize;
786                  d->bit_depth = 24;                  d->bit_depth = 24;
787                  break;                  break;
         default:  
                 ;  
788          }          }
789    
790          if (d->bit_depth == 2 || d->bit_depth == 4)          if (d->bit_depth == 2 || d->bit_depth == 4)
# Line 1007  struct vfb_data *dev_fb_init(struct mach Line 805  struct vfb_data *dev_fb_init(struct mach
805    
806          /*  Clear the framebuffer (all black pixels):  */          /*  Clear the framebuffer (all black pixels):  */
807          d->framebuffer_size = size;          d->framebuffer_size = size;
808          memset(d->framebuffer, 0, size);          memset(d->framebuffer, reverse_start? 255 : 0, size);
809    
810          d->x11_xsize = d->visible_xsize / d->vfb_scaledown;          d->x11_xsize = d->visible_xsize / d->vfb_scaledown;
811          d->x11_ysize = d->visible_ysize / d->vfb_scaledown;          d->x11_ysize = d->visible_ysize / d->vfb_scaledown;
812    
813          d->update_x1 = d->update_y1 = 99999;          /*  Only "update" from the start if we need to fill with white.  */
814          d->update_x2 = d->update_y2 = -1;          /*  (The Ximage will be black from the start anyway.)  */
815            if (reverse_start) {
816                    d->update_x1 = d->update_y1 = 0;
817          /*  A nice bootup logo:  */                  d->update_x2 = d->xsize - 1;
818          if (logo) {                  d->update_y2 = d->ysize - 1;
819                  int logo_bottom_margin = LOGO_BOTTOM_MARGIN;          } else {
820                    d->update_x1 = d->update_y1 = 99999;
821                  d->update_x1 = 0;                  d->update_x2 = d->update_y2 = -1;
                 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; y<LOGO_YSIZE; y++)  
                         for (x=0; x<LOGO_XSIZE; x++) {  
                                 int s, a = ((y + d->visible_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; s<d->bit_depth / 8; s++)  
                                         if (a+s >= 0 && a+s < size)  
                                                 d->framebuffer[a+s] = b? 0:255;  
                         }  
822          }          }
823    
824          /*  Don't set the title to include the size of the framebuffer for          /*  Don't set the title to include the size of the framebuffer for
# Line 1047  struct vfb_data *dev_fb_init(struct mach Line 831  struct vfb_data *dev_fb_init(struct mach
831          title[sizeof(title)-1] = '\0';          title[sizeof(title)-1] = '\0';
832    
833  #ifdef WITH_X11  #ifdef WITH_X11
834          if (machine->use_x11)          if (machine->use_x11) {
835                    int i = 0;
836                  d->fb_window = x11_fb_init(d->x11_xsize, d->x11_ysize,                  d->fb_window = x11_fb_init(d->x11_xsize, d->x11_ysize,
837                      title, machine->x11_scaledown, machine);                      title, machine->x11_scaledown, machine);
838          else                  switch (d->fb_window->x11_screen_depth) {
839                    case 15: i = 2; break;
840                    case 16: i = 4; break;
841                    case 24: i = 6; break;
842                    }
843                    if (d->fb_window->fb_ximage->byte_order)
844                            i ++;
845                    if (d->vfb_scaledown > 1)
846                            i += 8;
847                    d->redraw_func = redraw[i];
848            } else
849  #endif  #endif
850                  d->fb_window = NULL;                  d->fb_window = NULL;
851    
# Line 1062  struct vfb_data *dev_fb_init(struct mach Line 857  struct vfb_data *dev_fb_init(struct mach
857          }          }
858          snprintf(name2, nlen, "fb [%s]", name);          snprintf(name2, nlen, "fb [%s]", name);
859    
860          flags = MEM_DEFAULT;          flags = DM_DEFAULT;
861          if ((baseaddr & 0xfff) == 0)          if ((baseaddr & 0xfff) == 0)
862                  flags = MEM_BINTRANS_OK | MEM_BINTRANS_WRITE_OK;                  flags = DM_DYNTRANS_OK | DM_DYNTRANS_WRITE_OK;
863    
864          flags |= MEM_READING_HAS_NO_SIDE_EFFECTS;          flags |= DM_READS_HAVE_NO_SIDE_EFFECTS;
865    
866          memory_device_register(mem, name2, baseaddr, size, dev_fb_access,          memory_device_register(mem, name2, baseaddr, size, dev_fb_access,
867              d, flags, d->framebuffer);              d, flags, d->framebuffer);
868    
869          machine_add_tickfunction(machine, dev_fb_tick, d, FB_TICK_SHIFT);          machine_add_tickfunction(machine, dev_fb_tick, d, FB_TICK_SHIFT, 0.0);
870          return d;          return d;
871  }  }
872    

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

  ViewVC Help
Powered by ViewVC 1.1.26