/[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 12 by dpavlin, Mon Oct 8 16:18:38 2007 UTC revision 20 by dpavlin, Mon Oct 8 16:19:23 2007 UTC
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *     *  
27   *   *
28   *  $Id: dev_fb.c,v 1.106 2005/08/14 11:14:38 debug Exp $   *  $Id: dev_fb.c,v 1.110 2005/11/13 00:14:08 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   *   *
# Line 65  Line 65 
65  #endif  #endif
66    
67    
68  #define FB_TICK_SHIFT           19  #define FB_TICK_SHIFT           18
69    
70    
71  /*  #define FB_DEBUG  */  /*  #define FB_DEBUG  */
# Line 291  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 381  void update_framebuffer(struct vfb_data Line 388  void update_framebuffer(struct vfb_data
388                                  c = d->framebuffer[fb_addr >> 3];                                  c = d->framebuffer[fb_addr >> 3];
389                                  fb_addr &= 7;                                  fb_addr &= 7;
390    
391                                  /*  HPCmips is reverse:  */                                  /*  HPC is reverse:  */
392                                  if (d->vfb_type == VFB_HPCMIPS)                                  if (d->vfb_type == VFB_HPC)
393                                          fb_addr = 8 - d->bit_depth - fb_addr;                                          fb_addr = 8 - d->bit_depth - fb_addr;
394    
395                                  c = (c >> fb_addr) & ((1<<d->bit_depth) - 1);                                  c = (c >> fb_addr) & ((1<<d->bit_depth) - 1);
# Line 428  void update_framebuffer(struct vfb_data Line 435  void update_framebuffer(struct vfb_data
435                                          break;                                          break;
436                                  /*  TODO: copy to the scaledown code below  */                                  /*  TODO: copy to the scaledown code below  */
437                                  case 16:                                  case 16:
438                                          if (d->vfb_type == VFB_HPCMIPS) {                                          if (d->vfb_type == VFB_HPC) {
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 451  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 513  void update_framebuffer(struct vfb_data Line 521  void update_framebuffer(struct vfb_data
521                                  c = d->framebuffer[fb_addr >> 3];                                  c = d->framebuffer[fb_addr >> 3];
522                                  fb_addr &= 7;                                  fb_addr &= 7;
523    
524                                  /*  HPCmips is reverse:  */                                  /*  HPC is reverse:  */
525                                  if (d->vfb_type == VFB_HPCMIPS)                                  if (d->vfb_type == VFB_HPC)
526                                          fb_addr = 8 - d->bit_depth - fb_addr;                                          fb_addr = 8 - d->bit_depth - fb_addr;
527    
528                                  c = (c >> fb_addr) & ((1<<d->bit_depth) - 1);                                  c = (c >> fb_addr) & ((1<<d->bit_depth) - 1);
# Line 692  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 719  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 727  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 741  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 751  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 768  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 912  int dev_fb_access(struct cpu *cpu, struc Line 936  int dev_fb_access(struct cpu *cpu, struc
936   *   *
937   *  VFB_DEC_VFB01, _VFB02, and VFB_DEC_MAXINE are DECstation specific.   *  VFB_DEC_VFB01, _VFB02, and VFB_DEC_MAXINE are DECstation specific.
938   *   *
939   *  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.
940   *   *
941   *  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
942   *  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.
# Line 1032  struct vfb_data *dev_fb_init(struct mach Line 1056  struct vfb_data *dev_fb_init(struct mach
1056          }          }
1057          snprintf(name2, nlen, "fb [%s]", name);          snprintf(name2, nlen, "fb [%s]", name);
1058    
1059          flags = MEM_DEFAULT;          flags = DM_DEFAULT;
1060          if ((baseaddr & 0xfff) == 0)          if ((baseaddr & 0xfff) == 0)
1061                  flags = MEM_DYNTRANS_OK | MEM_DYNTRANS_WRITE_OK;                  flags = DM_DYNTRANS_OK | DM_DYNTRANS_WRITE_OK;
1062    
1063          flags |= MEM_READING_HAS_NO_SIDE_EFFECTS;          flags |= DM_READS_HAVE_NO_SIDE_EFFECTS;
1064    
1065          memory_device_register(mem, name2, baseaddr, size, dev_fb_access,          memory_device_register(mem, name2, baseaddr, size, dev_fb_access,
1066              d, flags, d->framebuffer);              d, flags, d->framebuffer);

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

  ViewVC Help
Powered by ViewVC 1.1.26