/[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 14 by dpavlin, Mon Oct 8 16:18:51 2007 UTC
# 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.107 2005/09/18 19:54:15 debug Exp $
29   *     *  
30   *  Generic framebuffer device.   *  Generic framebuffer device.
31   *   *
# Line 65  Line 65 
65  #endif  #endif
66    
67    
68  #define FB_TICK_SHIFT           18  #define FB_TICK_SHIFT           19
   
 #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;  
69    
70    
71  /*  #define FB_DEBUG  */  /*  #define FB_DEBUG  */
# Line 298  void framebuffer_blockcopyfill(struct vf Line 291  void framebuffer_blockcopyfill(struct vf
291    
292  #ifdef WITH_X11  #ifdef WITH_X11
293  #define macro_put_pixel() {     \  #define macro_put_pixel() {     \
294                          /*  Combine the color into an X11 long and display it:  */      \          /*  Combine the color into an X11 long and display it:  */      \
295                          /*  TODO:  construct color in a more portable way:  */          \          /*  TODO:  construct color in a more portable way:  */          \
296                          switch (d->fb_window->x11_screen_depth) {                                       \          switch (d->fb_window->x11_screen_depth) {                       \
297                          case 24:                                                        \          case 24:                                                        \
298                                  if (d->fb_window->fb_ximage->byte_order)                \                  if (d->fb_window->fb_ximage->byte_order)                \
299                                          color = (b << 16) + (g << 8) + r;               \                          color = (b << 16) + (g << 8) + r;               \
300                                  else                                                    \                  else                                                    \
301                                          color = (r << 16) + (g << 8) + b;               \                          color = (r << 16) + (g << 8) + b;               \
302                                  break;                                                  \                  break;                                                  \
303                          case 16:                                                        \          case 16:                                                        \
304                                  r >>= 3; g >>= 2; b >>= 3;                              \                  r >>= 3; g >>= 2; b >>= 3;                              \
305                                  if (d->fb_window->fb_ximage->byte_order) {              \                  if (d->fb_window->fb_ximage->byte_order) {              \
306                                          /*  Big endian 16-bit X server:  */             \                          /*  Big endian 16-bit X server:  */             \
307                                          static int first = 1;                           \                          static int first = 1;                           \
308                                          if (first) {                                    \                          if (first) {                                    \
309                                                  fprintf(stderr, "\n*** Please report to the author whether 16-bit X11 colors are rendered correctly or not!\n\n"); \                                  fprintf(stderr, "\n*** Please report "  \
310                                                  first = 0;                              \                                      "to the author whether 16-bit X11 " \
311                                          }                                               \                                      "colors are rendered correctly or " \
312                                          color = (b << 11) + (g << 5) + r;               \                                      "not!\n\n");                        \
313                                  } else {                                                \                                  first = 0;                              \
314                                          /*  Little endian (eg PC) X servers:  */        \                          }                                               \
315                                          color = (r << 11) + (g << 5) + b;               \                          color = (b << 11) + (g << 5) + r;               \
316                                  }                                                       \                  } else {                                                \
317                                  break;                                                  \                          /*  Little endian (eg PC) X servers:  */        \
318                          case 15:                                                        \                          color = (r << 11) + (g << 5) + b;               \
319                                  r >>= 3; g >>= 3; b >>= 3;                              \                  }                                                       \
320                                  if (d->fb_window->fb_ximage->byte_order) {              \                  break;                                                  \
321                                          /*  Big endian 15-bit X server:  */             \          case 15:                                                        \
322                                          static int first = 1;                           \                  r >>= 3; g >>= 3; b >>= 3;                              \
323                                          if (first) {                                    \                  if (d->fb_window->fb_ximage->byte_order) {              \
324                                                  fprintf(stderr, "\n*** Please report to the author whether 15-bit X11 colors are rendered correctly or not!\n\n"); \                          /*  Big endian 15-bit X server:  */             \
325                                                  first = 0;                              \                          static int first = 1;                           \
326                                          }                                               \                          if (first) {                                    \
327                                          color = (b << 10) + (g << 5) + r;               \                                  fprintf(stderr, "\n*** Please report "  \
328                                  } else {                                                \                                      "to the author whether 15-bit X11 " \
329                                          /*  Little endian (eg PC) X servers:  */        \                                      "colors are rendered correctly or " \
330                                          color = (r << 10) + (g << 5) + b;               \                                      "not!\n\n");                        \
331                                  }                                                       \                                  first = 0;                              \
332                                  break;                                                  \                          }                                               \
333                          default:                                                        \                          color = (b << 10) + (g << 5) + r;               \
334                                  color = d->fb_window->x11_graycolor[15 * (r + g + b) / (255 * 3)].pixel; \                  } else {                                                \
335                          }                                                               \                          /*  Little endian (eg PC) X servers:  */        \
336                          if (x>=0 && x<d->x11_xsize && y>=0 && y<d->x11_ysize)           \                          color = (r << 10) + (g << 5) + b;               \
337                                  XPutPixel(d->fb_window->fb_ximage, x, y, color);        \                  }                                                       \
338                  }                  break;                                                  \
339            default:                                                        \
340                    color = d->fb_window->x11_graycolor[15 * (r + g + b)    \
341                        / (255 * 3)].pixel;                                 \
342            }                                                               \
343            if (x>=0 && x<d->x11_xsize && y>=0 && y<d->x11_ysize)           \
344                    XPutPixel(d->fb_window->fb_ximage, x, y, color);        \
345        }
346  #else  #else
347  /*  If not WITH_X11:  */  /*  If not WITH_X11:  */
348  #define macro_put_pixel() { }  #define macro_put_pixel() { }
# Line 437  void update_framebuffer(struct vfb_data Line 437  void update_framebuffer(struct vfb_data
437                                  case 16:                                  case 16:
438                                          if (d->vfb_type == VFB_HPCMIPS) {                                          if (d->vfb_type == VFB_HPCMIPS) {
439                                                  b = d->framebuffer[fb_addr] +                                                  b = d->framebuffer[fb_addr] +
440                                                      (d->framebuffer[fb_addr+1] << 8);                                                      (d->framebuffer[fb_addr+1]
441                                                        << 8);
442    
443                                                  if (d->color32k) {                                                  if (d->color32k) {
444                                                          r = b >> 11;                                                          r = b >> 11;
# Line 458  void update_framebuffer(struct vfb_data Line 459  void update_framebuffer(struct vfb_data
459                                                          b = b & 0x1f;                                                          b = b & 0x1f;
460                                                  }                                                  }
461                                          } else {                                          } else {
462                                                  r = d->framebuffer[fb_addr] >> 3;                                              r = d->framebuffer[fb_addr] >> 3;
463                                                  g = (d->framebuffer[fb_addr] << 5) +                                              g = (d->framebuffer[fb_addr] << 5) +
464                                                      (d->framebuffer[fb_addr + 1] >> 5);                                                (d->framebuffer[fb_addr + 1] >>5);
465                                                  b = d->framebuffer[fb_addr + 1] & 0x1f;                                              b = d->framebuffer[fb_addr + 1]&31;
466                                          }                                          }
467    
468                                          r *= 8;                                          r *= 8;
# Line 480  void update_framebuffer(struct vfb_data Line 481  void update_framebuffer(struct vfb_data
481                  return;                  return;
482          }          }
483    
484          /*  scaledown != 1:  */          /*  scaledown > 1:  */
485    
486          scaledown = d->vfb_scaledown;          scaledown = d->vfb_scaledown;
487          scaledownXscaledown = scaledown * scaledown;          scaledownXscaledown = scaledown * scaledown;
# Line 623  void dev_fb_tick(struct cpu *cpu, void * Line 624  void dev_fb_tick(struct cpu *cpu, void *
624          if (!cpu->machine->use_x11)          if (!cpu->machine->use_x11)
625                  return;                  return;
626    
 #ifdef BINTRANS  
627          do {          do {
628                  uint64_t low = -1, high;                  uint64_t high, low = (uint64_t)(int64_t) -1;
629                  int x, y;                  int x, y;
630    
631                  memory_device_bintrans_access(cpu, cpu->mem,                  memory_device_dyntrans_access(cpu, cpu->mem,
632                      extra, &low, &high);                      extra, &low, &high);
633                  if ((int64_t)low == -1)                  if ((int64_t)low == -1)
634                          break;                          break;
# Line 689  void dev_fb_tick(struct cpu *cpu, void * Line 689  void dev_fb_tick(struct cpu *cpu, void *
689                          d->update_x2 = d->xsize-1;                          d->update_x2 = d->xsize-1;
690                  }                  }
691          } while (0);          } while (0);
 #endif  
692    
693  #ifdef WITH_X11  #ifdef WITH_X11
694          /*  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 700  void dev_fb_tick(struct cpu *cpu, void *
700                  need_to_redraw_cursor = 1;                  need_to_redraw_cursor = 1;
701    
702          if (d->update_x2 != -1) {          if (d->update_x2 != -1) {
703                  if ( (d->update_x1 >= d->fb_window->OLD_cursor_x &&                  if (((d->update_x1 >= d->fb_window->OLD_cursor_x &&
704                        d->update_x1 < (d->fb_window->OLD_cursor_x + d->fb_window->OLD_cursor_xsize)) ||                        d->update_x1 < (d->fb_window->OLD_cursor_x +
705                          d->fb_window->OLD_cursor_xsize)) ||
706                       (d->update_x2 >= d->fb_window->OLD_cursor_x &&                       (d->update_x2 >= d->fb_window->OLD_cursor_x &&
707                        d->update_x2 < (d->fb_window->OLD_cursor_x + d->fb_window->OLD_cursor_xsize)) ||                        d->update_x2 < (d->fb_window->OLD_cursor_x +
708                          d->fb_window->OLD_cursor_xsize)) ||
709                       (d->update_x1 <  d->fb_window->OLD_cursor_x &&                       (d->update_x1 <  d->fb_window->OLD_cursor_x &&
710                        d->update_x2 >= (d->fb_window->OLD_cursor_x + d->fb_window->OLD_cursor_xsize)) ) {                        d->update_x2 >= (d->fb_window->OLD_cursor_x +
711                          if ( (d->update_y1 >= d->fb_window->OLD_cursor_y &&                        d->fb_window->OLD_cursor_xsize)) ) &&
712                                d->update_y1 < (d->fb_window->OLD_cursor_y + d->fb_window->OLD_cursor_ysize)) ||                     ( (d->update_y1 >= d->fb_window->OLD_cursor_y &&
713                               (d->update_y2 >= d->fb_window->OLD_cursor_y &&                        d->update_y1 < (d->fb_window->OLD_cursor_y +
714                                d->update_y2 < (d->fb_window->OLD_cursor_y + d->fb_window->OLD_cursor_ysize)) ||                        d->fb_window->OLD_cursor_ysize)) ||
715                               (d->update_y1 <  d->fb_window->OLD_cursor_y &&                       (d->update_y2 >= d->fb_window->OLD_cursor_y &&
716                                d->update_y2 >= (d->fb_window->OLD_cursor_y + d->fb_window->OLD_cursor_ysize)) )                        d->update_y2 < (d->fb_window->OLD_cursor_y +
717                                  need_to_redraw_cursor = 1;                        d->fb_window->OLD_cursor_ysize)) ||
718                  }                       (d->update_y1 <  d->fb_window->OLD_cursor_y &&
719                          d->update_y2 >= (d->fb_window->OLD_cursor_y +
720                         d->fb_window->OLD_cursor_ysize)) ) )
721                            need_to_redraw_cursor = 1;
722          }          }
723    
724          if (need_to_redraw_cursor) {          if (need_to_redraw_cursor) {
# Line 728  void dev_fb_tick(struct cpu *cpu, void * Line 732  void dev_fb_tick(struct cpu *cpu, void *
732                              d->fb_window->OLD_cursor_x/d->vfb_scaledown,                              d->fb_window->OLD_cursor_x/d->vfb_scaledown,
733                              d->fb_window->OLD_cursor_y/d->vfb_scaledown,                              d->fb_window->OLD_cursor_y/d->vfb_scaledown,
734                              d->fb_window->OLD_cursor_xsize/d->vfb_scaledown + 1,                              d->fb_window->OLD_cursor_xsize/d->vfb_scaledown + 1,
735                              d->fb_window->OLD_cursor_ysize/d->vfb_scaledown + 1);                              d->fb_window->OLD_cursor_ysize/d->vfb_scaledown +1);
736                  }                  }
737          }          }
738  #endif  #endif
# Line 736  void dev_fb_tick(struct cpu *cpu, void * Line 740  void dev_fb_tick(struct cpu *cpu, void *
740          if (d->update_x2 != -1) {          if (d->update_x2 != -1) {
741                  int y, addr, addr2, q = d->vfb_scaledown;                  int y, addr, addr2, q = d->vfb_scaledown;
742    
743                  if (d->update_x1 >= d->visible_xsize)   d->update_x1 = d->visible_xsize - 1;                  if (d->update_x1 >= d->visible_xsize)
744                  if (d->update_x2 >= d->visible_xsize)   d->update_x2 = d->visible_xsize - 1;                          d->update_x1 = d->visible_xsize - 1;
745                  if (d->update_y1 >= d->visible_ysize)   d->update_y1 = d->visible_ysize - 1;                  if (d->update_x2 >= d->visible_xsize)
746                  if (d->update_y2 >= d->visible_ysize)   d->update_y2 = d->visible_ysize - 1;                          d->update_x2 = d->visible_xsize - 1;
747                    if (d->update_y1 >= d->visible_ysize)
748                            d->update_y1 = d->visible_ysize - 1;
749                    if (d->update_y2 >= d->visible_ysize)
750                            d->update_y2 = d->visible_ysize - 1;
751    
752                  /*  Without these, we might miss the right most / bottom pixel:  */                  /*  Without these, we might miss the rightmost/bottom pixel:  */
753                  d->update_x2 += (q - 1);                  d->update_x2 += (q - 1);
754                  d->update_y2 += (q - 1);                  d->update_y2 += (q - 1);
755    
# Line 750  void dev_fb_tick(struct cpu *cpu, void * Line 758  void dev_fb_tick(struct cpu *cpu, void *
758                  d->update_y1 = d->update_y1 / q * q;                  d->update_y1 = d->update_y1 / q * q;
759                  d->update_y2 = d->update_y2 / q * q;                  d->update_y2 = d->update_y2 / q * q;
760    
761                  addr  = d->update_y1 * d->bytes_per_line + d->update_x1 * d->bit_depth / 8;                  addr  = d->update_y1 * d->bytes_per_line +
762                  addr2 = d->update_y1 * d->bytes_per_line + d->update_x2 * d->bit_depth / 8;                      d->update_x1 * d->bit_depth / 8;
763                    addr2 = d->update_y1 * d->bytes_per_line +
764                        d->update_x2 * d->bit_depth / 8;
765    
766                  for (y=d->update_y1; y<=d->update_y2; y+=q) {                  for (y=d->update_y1; y<=d->update_y2; y+=q) {
767                          update_framebuffer(d, addr, addr2 - addr);                          update_framebuffer(d, addr, addr2 - addr);
# Line 760  void dev_fb_tick(struct cpu *cpu, void * Line 770  void dev_fb_tick(struct cpu *cpu, void *
770                  }                  }
771    
772  #ifdef WITH_X11  #ifdef WITH_X11
773                  XPutImage(d->fb_window->x11_display, d->fb_window->x11_fb_window, d->fb_window->x11_fb_gc, d->fb_window->fb_ximage,                  XPutImage(d->fb_window->x11_display, d->fb_window->
774                      d->update_x1/d->vfb_scaledown, d->update_y1/d->vfb_scaledown,                      x11_fb_window, d->fb_window->x11_fb_gc, d->fb_window->
775                      d->update_x1/d->vfb_scaledown, d->update_y1/d->vfb_scaledown,                      fb_ximage, d->update_x1/d->vfb_scaledown, d->update_y1/
776                        d->vfb_scaledown, d->update_x1/d->vfb_scaledown,
777                        d->update_y1/d->vfb_scaledown,
778                      (d->update_x2 - d->update_x1)/d->vfb_scaledown + 1,                      (d->update_x2 - d->update_x1)/d->vfb_scaledown + 1,
779                      (d->update_y2 - d->update_y1)/d->vfb_scaledown + 1);                      (d->update_y2 - d->update_y1)/d->vfb_scaledown + 1);
780    
# Line 777  void dev_fb_tick(struct cpu *cpu, void * Line 789  void dev_fb_tick(struct cpu *cpu, void *
789          if (need_to_redraw_cursor) {          if (need_to_redraw_cursor) {
790                  /*  Paint new cursor:  */                  /*  Paint new cursor:  */
791                  if (d->fb_window->cursor_on) {                  if (d->fb_window->cursor_on) {
792                          x11_redraw_cursor(cpu->machine, d->fb_window->fb_number);                          x11_redraw_cursor(cpu->machine,
793                                d->fb_window->fb_number);
794                          d->fb_window->OLD_cursor_on = d->fb_window->cursor_on;                          d->fb_window->OLD_cursor_on = d->fb_window->cursor_on;
795                          d->fb_window->OLD_cursor_x = d->fb_window->cursor_x;                          d->fb_window->OLD_cursor_x = d->fb_window->cursor_x;
796                          d->fb_window->OLD_cursor_y = d->fb_window->cursor_y;                          d->fb_window->OLD_cursor_y = d->fb_window->cursor_y;
797                          d->fb_window->OLD_cursor_xsize = d->fb_window->cursor_xsize;                          d->fb_window->OLD_cursor_xsize = d->fb_window->
798                          d->fb_window->OLD_cursor_ysize = d->fb_window->cursor_ysize;                              cursor_xsize;
799                            d->fb_window->OLD_cursor_ysize = d->fb_window->
800                                cursor_ysize;
801                  }                  }
802          }          }
803  #endif  #endif
# Line 928  int dev_fb_access(struct cpu *cpu, struc Line 943  int dev_fb_access(struct cpu *cpu, struc
943   */   */
944  struct vfb_data *dev_fb_init(struct machine *machine, struct memory *mem,  struct vfb_data *dev_fb_init(struct machine *machine, struct memory *mem,
945          uint64_t baseaddr, int vfb_type, int visible_xsize, int visible_ysize,          uint64_t baseaddr, int vfb_type, int visible_xsize, int visible_ysize,
946          int xsize, int ysize, int bit_depth, char *name, int logo)          int xsize, int ysize, int bit_depth, char *name)
947  {  {
948          struct vfb_data *d;          struct vfb_data *d;
949          size_t size, nlen;          size_t size, nlen;
950          int x, y, flags;          int flags;
951          char title[400];          char title[400];
952          char *name2;          char *name2;
953    
# Line 1016  struct vfb_data *dev_fb_init(struct mach Line 1031  struct vfb_data *dev_fb_init(struct mach
1031          d->update_x2 = d->update_y2 = -1;          d->update_x2 = d->update_y2 = -1;
1032    
1033    
         /*  A nice bootup logo:  */  
         if (logo) {  
                 int logo_bottom_margin = LOGO_BOTTOM_MARGIN;  
   
                 d->update_x1 = 0;  
                 d->update_x2 = LOGO_XSIZE-1;  
                 d->update_y1 = d->visible_ysize-LOGO_YSIZE-logo_bottom_margin;  
                 d->update_y2 = d->visible_ysize-logo_bottom_margin;  
                 for (y=0; 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;  
                         }  
         }  
   
1034          /*  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
1035              VGA, since then the resolution might change during runtime.  */              VGA, since then the resolution might change during runtime.  */
1036          if (strcmp(name, "VGA") == 0)          if (strcmp(name, "VGA") == 0)
# Line 1064  struct vfb_data *dev_fb_init(struct mach Line 1058  struct vfb_data *dev_fb_init(struct mach
1058    
1059          flags = MEM_DEFAULT;          flags = MEM_DEFAULT;
1060          if ((baseaddr & 0xfff) == 0)          if ((baseaddr & 0xfff) == 0)
1061                  flags = MEM_BINTRANS_OK | MEM_BINTRANS_WRITE_OK;                  flags = MEM_DYNTRANS_OK | MEM_DYNTRANS_WRITE_OK;
1062    
1063          flags |= MEM_READING_HAS_NO_SIDE_EFFECTS;          flags |= MEM_READING_HAS_NO_SIDE_EFFECTS;
1064    

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

  ViewVC Help
Powered by ViewVC 1.1.26