/[gxemul]/trunk/src/devices/dev_vga.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_vga.c

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

revision 20 by dpavlin, Mon Oct 8 16:19:23 2007 UTC revision 22 by dpavlin, Mon Oct 8 16:19:37 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2004-2005  Anders Gavare.  All rights reserved.   *  Copyright (C) 2004-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_vga.c,v 1.90 2005/11/13 00:14:10 debug Exp $   *  $Id: dev_vga.c,v 1.95 2006/01/01 13:17:18 debug Exp $
29   *   *
30   *  VGA charcell and graphics device.   *  VGA charcell and graphics device.
31   *   *
# Line 73  struct vga_data { Line 73  struct vga_data {
73          uint64_t        control_base;          uint64_t        control_base;
74    
75          struct vfb_data *fb;          struct vfb_data *fb;
76          size_t          fb_size;          uint32_t        fb_size;
77    
78          int             fb_max_x;               /*  pixels  */          int             fb_max_x;               /*  pixels  */
79          int             fb_max_y;               /*  pixels  */          int             fb_max_y;               /*  pixels  */
# Line 99  struct vga_data { Line 99  struct vga_data {
99          int             graphics_mode;          int             graphics_mode;
100          int             bits_per_pixel;          int             bits_per_pixel;
101          unsigned char   *gfx_mem;          unsigned char   *gfx_mem;
102          size_t          gfx_mem_size;          uint32_t        gfx_mem_size;
103    
104          /*  Registers:  */          /*  Registers:  */
105          int             attribute_state;        /*  0 or 1  */          int             attribute_state;        /*  0 or 1  */
# Line 137  struct vga_data { Line 137  struct vga_data {
137          int             cursor_y;          int             cursor_y;
138    
139          int             modified;          int             modified;
140            int             palette_modified;
141          int             update_x1;          int             update_x1;
142          int             update_y1;          int             update_y1;
143          int             update_x2;          int             update_x2;
# Line 207  static void reset_palette(struct vga_dat Line 208  static void reset_palette(struct vga_dat
208          for (i=16; i<256; i++)          for (i=16; i<256; i++)
209                  d->fb->rgb_palette[i*3 + 0] = d->fb->rgb_palette[i*3 + 1] =                  d->fb->rgb_palette[i*3 + 0] = d->fb->rgb_palette[i*3 + 1] =
210                      d->fb->rgb_palette[i*3 + 2] = (i & 15) * 4;                      d->fb->rgb_palette[i*3 + 2] = (i & 15) * 4;
211            d->palette_modified = 1;
212          i = 0;          i = 0;
213    
214          if (grayscale) {          if (grayscale) {
# Line 360  static void vga_update_graphics(struct m Line 361  static void vga_update_graphics(struct m
361                          }                          }
362                          for (iy=y*ry; iy<(y+1)*ry; iy++)                          for (iy=y*ry; iy<(y+1)*ry; iy++)
363                                  for (ix=x*rx; ix<(x+1)*rx; ix++) {                                  for (ix=x*rx; ix<(x+1)*rx; ix++) {
364                                          int addr2 = (d->fb_max_x * iy + ix) * 3;                                          uint32_t addr2 = (d->fb_max_x * iy
365                                                + ix) * 3;
366                                          if (addr2 < d->fb_size)                                          if (addr2 < d->fb_size)
367                                                  dev_fb_access(machine->cpus[0],                                                  dev_fb_access(machine->cpus[0],
368                                                      machine->memory, addr2,                                                      machine->memory, addr2,
# Line 381  static void vga_update_graphics(struct m Line 383  static void vga_update_graphics(struct m
383  static void vga_update_text(struct machine *machine, struct vga_data *d,  static void vga_update_text(struct machine *machine, struct vga_data *d,
384          int x1, int y1, int x2, int y2)          int x1, int y1, int x2, int y2)
385  {  {
386          int fg, bg, i, x,y, subx, line, start, end, base;          int fg, bg, x,y, subx, line;
387            size_t i, start, end, base;
388          int font_size = d->font_height;          int font_size = d->font_height;
389          int font_width = d->font_width;          int font_width = d->font_width;
390          unsigned char *pal = d->fb->rgb_palette;          unsigned char *pal = d->fb->rgb_palette;
391    
392            if (d->pixel_repx * font_width > 8*8) {
393                    fatal("[ too large font ]\n");
394                    return;
395            }
396    
397          /*  Hm... I'm still using the old start..end code:  */          /*  Hm... I'm still using the old start..end code:  */
398          start = (d->max_x * y1 + x1) * 2;          start = (d->max_x * y1 + x1) * 2;
399          end   = (d->max_x * y2 + x2) * 2;          end   = (d->max_x * y2 + x2) * 2;
# Line 405  static void vga_update_text(struct machi Line 413  static void vga_update_text(struct machi
413          for (i=start; i<=end; i+=2) {          for (i=start; i<=end; i+=2) {
414                  unsigned char ch = d->charcells[i + base];                  unsigned char ch = d->charcells[i + base];
415    
416                  if (d->charcells_drawn[i] == ch &&                  if (!d->palette_modified && d->charcells_drawn[i] == ch &&
417                      d->charcells_drawn[i+1] == d->charcells[i+base+1])                      d->charcells_drawn[i+1] == d->charcells[i+base+1])
418                          continue;                          continue;
419    
# Line 425  static void vga_update_text(struct machi Line 433  static void vga_update_text(struct machi
433    
434                  /*  Draw the character:  */                  /*  Draw the character:  */
435                  for (line = 0; line < font_size; line++) {                  for (line = 0; line < font_size; line++) {
436                            /*  hardcoded for max 8 scaleup... :-)  */
437                            unsigned char rgb_line[3 * 8 * 8];
438                            int iy;
439    
440                          for (subx = 0; subx < font_width; subx++) {                          for (subx = 0; subx < font_width; subx++) {
441                                  int ix, iy, color_index;                                  int ix, color_index;
442    
443                                  if (d->use_palette_per_line) {                                  if (d->use_palette_per_line) {
444                                          int sline = d->pixel_repy * (line+y);                                          int sline = d->pixel_repy * (line+y);
# Line 443  static void vga_update_text(struct machi Line 455  static void vga_update_text(struct machi
455                                  else                                  else
456                                          color_index = bg;                                          color_index = bg;
457    
458                                  for (iy=0; iy<d->pixel_repy; iy++)                                  for (ix=0; ix<d->pixel_repx; ix++)
459                                      for (ix=0; ix<d->pixel_repx; ix++) {                                          memcpy(rgb_line + (subx*d->pixel_repx +
460                                          int addr = (d->fb_max_x* (d->pixel_repy                                              ix) * 3, &pal[color_index * 3], 3);
461                                              * (line+y) + iy) + (x+subx) *                          }
                                             d->pixel_repx + ix) * 3;  
462    
463                                          if (addr >= d->fb_size)                          for (iy=0; iy<d->pixel_repy; iy++) {
464                                                  continue;                                  uint32_t addr = (d->fb_max_x * (d->pixel_repy *
465                                          dev_fb_access(machine->cpus[0],                                      (line+y) + iy) + x * d->pixel_repx) * 3;
466                                              machine->memory, addr,                                  if (addr >= d->fb_size)
467                                              &pal[color_index * 3], 3,                                          continue;
468                                              MEM_WRITE, d->fb);                                  dev_fb_access(machine->cpus[0],
469                                      }                                      machine->memory, addr, rgb_line,
470                                        3 * font_width, MEM_WRITE, d->fb);
471                          }                          }
472                  }                  }
473          }          }
# Line 560  void dev_vga_tick(struct cpu *cpu, void Line 572  void dev_vga_tick(struct cpu *cpu, void
572                          vga_update_graphics(cpu->machine, d, d->update_x1,                          vga_update_graphics(cpu->machine, d, d->update_x1,
573                              d->update_y1, d->update_x2, d->update_y2);                              d->update_y1, d->update_x2, d->update_y2);
574    
575                    d->palette_modified = 0;
576                  d->modified = 0;                  d->modified = 0;
577                  d->update_x1 = 999999;                  d->update_x1 = 999999;
578                  d->update_x2 = -1;                  d->update_x2 = -1;
# Line 577  void dev_vga_tick(struct cpu *cpu, void Line 590  void dev_vga_tick(struct cpu *cpu, void
590   *   *
591   *  Reads and writes to the VGA video memory (pixels).   *  Reads and writes to the VGA video memory (pixels).
592   */   */
593  int dev_vga_graphics_access(struct cpu *cpu, struct memory *mem,  DEVICE_ACCESS(vga_graphics)
         uint64_t relative_addr, unsigned char *data, size_t len,  
         int writeflag, void *extra)  
594  {  {
595          struct vga_data *d = extra;          struct vga_data *d = extra;
596          int i,j, x=0, y=0, x2=0, y2=0, modified = 0;          int j, x=0, y=0, x2=0, y2=0, modified = 0;
597            size_t i;
598    
599          if (relative_addr + len >= GFX_ADDR_WINDOW)          if (relative_addr + len >= GFX_ADDR_WINDOW)
600                  return 0;                  return 0;
# Line 619  int dev_vga_graphics_access(struct cpu * Line 631  int dev_vga_graphics_access(struct cpu *
631                                          int b = data[i] & pixelmask;                                          int b = data[i] & pixelmask;
632                                          int m = d->sequencer_reg[                                          int m = d->sequencer_reg[
633                                              VGA_SEQ_MAP_MASK] & 0x0f;                                              VGA_SEQ_MAP_MASK] & 0x0f;
634                                          int addr = (y * d->max_x + x + i*8 + j)                                          uint32_t addr = (y * d->max_x + x +
635                                              * d->bits_per_pixel / 8;                                              i*8 + j) * d->bits_per_pixel / 8;
636                                          unsigned char byte;                                          unsigned char byte;
637                                          if (!(d->graphcontr_reg[                                          if (!(d->graphcontr_reg[
638                                              VGA_GRAPHCONTR_MASK] & pixelmask))                                              VGA_GRAPHCONTR_MASK] & pixelmask))
# Line 675  int dev_vga_graphics_access(struct cpu * Line 687  int dev_vga_graphics_access(struct cpu *
687   *   *
688   *  Reads and writes to the VGA video memory (charcells).   *  Reads and writes to the VGA video memory (charcells).
689   */   */
690  int dev_vga_access(struct cpu *cpu, struct memory *mem, uint64_t relative_addr,  DEVICE_ACCESS(vga)
         unsigned char *data, size_t len, int writeflag, void *extra)  
691  {  {
692          struct vga_data *d = extra;          struct vga_data *d = extra;
693          uint64_t idata = 0, odata = 0;          uint64_t idata = 0, odata = 0;
694          int i, x, y, x2, y2, r, base;          int x, y, x2, y2, r, base;
695            size_t i;
696    
697          if (writeflag == MEM_WRITE)          if (writeflag == MEM_WRITE)
698                  idata = memory_readmax64(cpu, data, len);                  idata = memory_readmax64(cpu, data, len);
# Line 950  static void vga_attribute_reg_write(stru Line 962  static void vga_attribute_reg_write(stru
962   *   *
963   *  Reads and writes of the VGA control registers.   *  Reads and writes of the VGA control registers.
964   */   */
965  int dev_vga_ctrl_access(struct cpu *cpu, struct memory *mem,  DEVICE_ACCESS(vga_ctrl)
         uint64_t relative_addr, unsigned char *data, size_t len,  
         int writeflag, void *extra)  
966  {  {
967          struct vga_data *d = extra;          struct vga_data *d = extra;
968          int i;          size_t i;
969          uint64_t idata = 0, odata = 0;          uint64_t idata = 0, odata = 0;
970    
971          for (i=0; i<len; i++) {          for (i=0; i<len; i++) {
# Line 1060  int dev_vga_ctrl_access(struct cpu *cpu, Line 1070  int dev_vga_ctrl_access(struct cpu *cpu,
1070                                      palette changed:  */                                      palette changed:  */
1071                                  if (new != old) {                                  if (new != old) {
1072                                          d->modified = 1;                                          d->modified = 1;
1073                                            d->palette_modified = 1;
1074                                          d->update_x1 = d->update_y1 = 0;                                          d->update_x1 = d->update_y1 = 0;
1075                                          d->update_x2 = d->max_x - 1;                                          d->update_x2 = d->max_x - 1;
1076                                          d->update_y2 = d->max_y - 1;                                          d->update_y2 = d->max_y - 1;
# Line 1183  void dev_vga_init(struct machine *machin Line 1194  void dev_vga_init(struct machine *machin
1194          uint64_t videomem_base, uint64_t control_base, char *name)          uint64_t videomem_base, uint64_t control_base, char *name)
1195  {  {
1196          struct vga_data *d;          struct vga_data *d;
1197          int i;          size_t i;
1198          size_t allocsize;          size_t allocsize;
1199    
1200          d = malloc(sizeof(struct vga_data));          d = malloc(sizeof(struct vga_data));
# Line 1193  void dev_vga_init(struct machine *machin Line 1204  void dev_vga_init(struct machine *machin
1204          }          }
1205          memset(d, 0, sizeof(struct vga_data));          memset(d, 0, sizeof(struct vga_data));
1206    
1207          d->console_handle = console_start_slave(machine, name);          d->console_handle = console_start_slave(machine, "vga",
1208                CONSOLE_OUTPUT_ONLY);
1209    
1210          d->videomem_base  = videomem_base;          d->videomem_base  = videomem_base;
1211          d->control_base   = control_base;          d->control_base   = control_base;

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

  ViewVC Help
Powered by ViewVC 1.1.26