/[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 6 by dpavlin, Mon Oct 8 16:18:11 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.74 2005/05/29 16:04:28 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 52  Line 52 
52  #include "fonts/font8x16.c"  #include "fonts/font8x16.c"
53    
54    
55  /*  For bintranslated videomem -> framebuffer updates:  */  /*  For videomem -> framebuffer updates:  */
56  #define VGA_TICK_SHIFT          16  #define VGA_TICK_SHIFT          18
57    
58  #define MAX_RETRACE_SCANLINES   420  #define MAX_RETRACE_SCANLINES   420
59  #define N_IS1_READ_THRESHOLD    50  #define N_IS1_READ_THRESHOLD    50
60    
 #define VGA_MEM_MAXY            60  
 #define VGA_MEM_ALLOCY          60  
61  #define GFX_ADDR_WINDOW         0x18000  #define GFX_ADDR_WINDOW         0x18000
62    
63  #define VGA_FB_ADDR     0x1c00000000ULL  #define VGA_FB_ADDR     0x1c00000000ULL
# Line 75  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 94  struct vga_data { Line 92  struct vga_data {
92          unsigned char   *font;          unsigned char   *font;
93          size_t          charcells_size;          size_t          charcells_size;
94          unsigned char   *charcells;             /*  2 bytes per char  */          unsigned char   *charcells;             /*  2 bytes per char  */
95          unsigned char   *charcells_outputed;          unsigned char   *charcells_outputed;    /*  text  */
96            unsigned char   *charcells_drawn;       /*  framebuffer  */
97    
98          /*  Graphics:  */          /*  Graphics:  */
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 138  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 146  struct vga_data { Line 146  struct vga_data {
146    
147    
148  /*  /*
149     *  recalc_cursor_position():
150     *
151     *  Should be called whenever the cursor location _or_ the display
152     *  base has been changed.
153     */
154    static void recalc_cursor_position(struct vga_data *d)
155    {
156            int base = (d->crtc_reg[VGA_CRTC_START_ADDR_HIGH] << 8)
157                + d->crtc_reg[VGA_CRTC_START_ADDR_LOW];
158            int ofs = d->crtc_reg[VGA_CRTC_CURSOR_LOCATION_HIGH] * 256 +
159                d->crtc_reg[VGA_CRTC_CURSOR_LOCATION_LOW];
160            ofs -= base;
161            d->cursor_x = ofs % d->max_x;
162            d->cursor_y = ofs / d->max_x;
163    }
164    
165    
166    /*
167   *  register_reset():   *  register_reset():
168   *   *
169   *  Resets many registers to sane values.   *  Resets many registers to sane values.
170   */   */
171  static void register_reset(struct vga_data *d)  static void register_reset(struct vga_data *d)
172  {  {
173          /*  Home cursor:  */          /*  Home cursor and start at the top:  */
         d->cursor_x = d->cursor_y = 0;  
174          d->crtc_reg[VGA_CRTC_CURSOR_LOCATION_HIGH] =          d->crtc_reg[VGA_CRTC_CURSOR_LOCATION_HIGH] =
175              d->crtc_reg[VGA_CRTC_CURSOR_LOCATION_LOW] = 0;              d->crtc_reg[VGA_CRTC_CURSOR_LOCATION_LOW] = 0;
   
176          d->crtc_reg[VGA_CRTC_START_ADDR_HIGH] =          d->crtc_reg[VGA_CRTC_START_ADDR_HIGH] =
177              d->crtc_reg[VGA_CRTC_START_ADDR_LOW] = 0;              d->crtc_reg[VGA_CRTC_START_ADDR_LOW] = 0;
178    
179            recalc_cursor_position(d);
180    
181          /*  Reset cursor scanline stuff:  */          /*  Reset cursor scanline stuff:  */
182          d->crtc_reg[VGA_CRTC_CURSOR_SCANLINE_START] = d->font_height - 4;          d->crtc_reg[VGA_CRTC_CURSOR_SCANLINE_START] = d->font_height - 2;
183          d->crtc_reg[VGA_CRTC_CURSOR_SCANLINE_END] = d->font_height - 2;          d->crtc_reg[VGA_CRTC_CURSOR_SCANLINE_END] = d->font_height - 1;
184    
185          d->sequencer_reg[VGA_SEQ_MAP_MASK] = 0x0f;          d->sequencer_reg[VGA_SEQ_MAP_MASK] = 0x0f;
186          d->graphcontr_reg[VGA_GRAPHCONTR_MASK] = 0xff;          d->graphcontr_reg[VGA_GRAPHCONTR_MASK] = 0xff;
# Line 190  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 260  static void vga_update_textmode(struct m Line 278  static void vga_update_textmode(struct m
278                  d->charcells_outputed[i+1] = d->charcells[base+i+1];                  d->charcells_outputed[i+1] = d->charcells[base+i+1];
279    
280                  if (!printed_last || x == 0) {                  if (!printed_last || x == 0) {
281                          sprintf(s, "\033[%i;%iH", y + 1, x + 1);                          snprintf(s, sizeof(s), "\033[%i;%iH", y + 1, x + 1);
282                          c_putstr(d, s);                          c_putstr(d, s);
283                  }                  }
284                  if (oldcolor < 0 || (bg<<4)+fg != oldcolor || !printed_last) {                  if (oldcolor < 0 || (bg<<4)+fg != oldcolor || !printed_last) {
285                          sprintf(s, "\033[0;"); c_putstr(d, s);                          snprintf(s, sizeof(s), "\033[0;"); c_putstr(d, s);
286    
287                          switch (fg & 7) {                          switch (fg & 7) {
288                          case 0: c_putstr(d, "30"); break;                          case 0: c_putstr(d, "30"); break;
# Line 301  static void vga_update_textmode(struct m Line 319  static void vga_update_textmode(struct m
319          }          }
320    
321          /*  Restore the terminal's cursor position:  */          /*  Restore the terminal's cursor position:  */
322          sprintf(s, "\033[%i;%iH", d->cursor_y + 1, d->cursor_x + 1);          snprintf(s, sizeof(s), "\033[%i;%iH", d->cursor_y + 1, d->cursor_x + 1);
323          c_putstr(d, s);          c_putstr(d, s);
324  }  }
325    
# Line 343  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 364  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 387  static void vga_update_text(struct machi Line 412  static void vga_update_text(struct machi
412    
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->palette_modified && d->charcells_drawn[i] == ch &&
417                        d->charcells_drawn[i+1] == d->charcells[i+base+1])
418                            continue;
419    
420                    d->charcells_drawn[i] = ch;
421                    d->charcells_drawn[i+1] = d->charcells[i + base + 1];
422    
423                  fg = d->charcells[i+base + 1] & 15;                  fg = d->charcells[i+base + 1] & 15;
424                  bg = (d->charcells[i+base + 1] >> 4) & 7;                  bg = (d->charcells[i+base + 1] >> 4) & 7;
425    
# Line 400  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 418  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 471  static void vga_update_cursor(struct mac Line 508  static void vga_update_cursor(struct mac
508  void dev_vga_tick(struct cpu *cpu, void *extra)  void dev_vga_tick(struct cpu *cpu, void *extra)
509  {  {
510          struct vga_data *d = extra;          struct vga_data *d = extra;
511          uint64_t low = (uint64_t)-1, high;          int64_t low = -1, high;
512    
513          vga_update_cursor(cpu->machine, d);          vga_update_cursor(cpu->machine, d);
514    
515          /*  TODO: text vs graphics tick?  */          /*  TODO: text vs graphics tick?  */
516          memory_device_bintrans_access(cpu, cpu->mem, extra, &low, &high);          memory_device_dyntrans_access(cpu, cpu->mem, extra,
517                (uint64_t *) &low, (uint64_t *) &high);
518    
519          if ((int64_t)low != -1) {          if (low != -1) {
520                  debug("[ dev_vga_tick: bintrans access, %llx .. %llx ]\n",                  int base = ((d->crtc_reg[VGA_CRTC_START_ADDR_HIGH] << 8)
521                        + d->crtc_reg[VGA_CRTC_START_ADDR_LOW]) * 2;
522                    int new_u_y1, new_u_y2;
523                    debug("[ dev_vga_tick: dyntrans access, %llx .. %llx ]\n",
524                      (long long)low, (long long)high);                      (long long)low, (long long)high);
525                    low -= base;
526                    high -= base;
527                  d->update_x1 = 0;                  d->update_x1 = 0;
528                  d->update_x2 = d->max_x - 1;                  d->update_x2 = d->max_x - 1;
529                  d->update_y1 = (low/2) / d->max_x;                  new_u_y1 = (low/2) / d->max_x;
530                  d->update_y2 = ((high/2) / d->max_x) + 1;                  new_u_y2 = ((high/2) / d->max_x) + 1;
531                    if (new_u_y1 < d->update_y1)
532                            d->update_y1 = new_u_y1;
533                    if (new_u_y2 > d->update_y2)
534                            d->update_y2 = new_u_y2;
535                    if (d->update_y1 < 0)
536                            d->update_y1 = 0;
537                  if (d->update_y2 >= d->max_y)                  if (d->update_y2 >= d->max_y)
538                          d->update_y2 = d->max_y - 1;                          d->update_y2 = d->max_y - 1;
539                  d->modified = 1;                  d->modified = 1;
# Line 523  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 540  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 582  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 638  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          idata = memory_readmax64(cpu, data, len);          if (writeflag == MEM_WRITE)
698                    idata = memory_readmax64(cpu, data, len);
699    
700          base = ((d->crtc_reg[VGA_CRTC_START_ADDR_HIGH] << 8)          base = ((d->crtc_reg[VGA_CRTC_START_ADDR_HIGH] << 8)
701              + d->crtc_reg[VGA_CRTC_START_ADDR_LOW]) * 2;              + d->crtc_reg[VGA_CRTC_START_ADDR_LOW]) * 2;
# Line 655  int dev_vga_access(struct cpu *cpu, stru Line 705  int dev_vga_access(struct cpu *cpu, stru
705          y2 = (r+len-1) / (d->max_x * 2);          y2 = (r+len-1) / (d->max_x * 2);
706          x2 = ((r+len-1)/2) % d->max_x;          x2 = ((r+len-1)/2) % d->max_x;
707    
708          if (relative_addr < d->charcells_size) {          if (relative_addr + len - 1 < d->charcells_size) {
709                  if (writeflag == MEM_WRITE) {                  if (writeflag == MEM_WRITE) {
710                          for (i=0; i<len; i++) {                          for (i=0; i<len; i++) {
711                                  int old = d->charcells[relative_addr + i];                                  int old = d->charcells[relative_addr + i];
# Line 712  int dev_vga_access(struct cpu *cpu, stru Line 762  int dev_vga_access(struct cpu *cpu, stru
762  static void vga_crtc_reg_write(struct machine *machine, struct vga_data *d,  static void vga_crtc_reg_write(struct machine *machine, struct vga_data *d,
763          int regnr, int idata)          int regnr, int idata)
764  {  {
765          int ofs, grayscale;          int grayscale;
766    
767          switch (regnr) {          switch (regnr) {
768          case VGA_CRTC_CURSOR_SCANLINE_START:            /*  0x0a  */          case VGA_CRTC_CURSOR_SCANLINE_START:            /*  0x0a  */
# Line 725  static void vga_crtc_reg_write(struct ma Line 775  static void vga_crtc_reg_write(struct ma
775                  d->update_y1 = 0;                  d->update_y1 = 0;
776                  d->update_y2 = d->max_y - 1;                  d->update_y2 = d->max_y - 1;
777                  d->modified = 1;                  d->modified = 1;
778                    recalc_cursor_position(d);
779                  break;                  break;
780          case VGA_CRTC_CURSOR_LOCATION_HIGH:             /*  0x0e  */          case VGA_CRTC_CURSOR_LOCATION_HIGH:             /*  0x0e  */
781          case VGA_CRTC_CURSOR_LOCATION_LOW:              /*  0x0f  */          case VGA_CRTC_CURSOR_LOCATION_LOW:              /*  0x0f  */
782                  ofs = d->crtc_reg[VGA_CRTC_CURSOR_LOCATION_HIGH] * 256 +                  recalc_cursor_position(d);
                     d->crtc_reg[VGA_CRTC_CURSOR_LOCATION_LOW];  
                 d->cursor_x = ofs % d->max_x;  
                 d->cursor_y = ofs / d->max_x;  
783                  break;                  break;
784          case 0xff:          case 0xff:
785                  grayscale = 0;                  grayscale = 0;
# Line 741  static void vga_crtc_reg_write(struct ma Line 789  static void vga_crtc_reg_write(struct ma
789                  case 0x01:                  case 0x01:
790                          d->cur_mode = MODE_CHARCELL;                          d->cur_mode = MODE_CHARCELL;
791                          d->max_x = 40; d->max_y = 25;                          d->max_x = 40; d->max_y = 25;
792                          d->pixel_repx = 2; d->pixel_repy = 1;                          d->pixel_repx = machine->x11_scaleup * 2;
793                            d->pixel_repy = machine->x11_scaleup;
794                          d->font_width = 8;                          d->font_width = 8;
795                          d->font_height = 16;                          d->font_height = 16;
796                          d->font = font8x16;                          d->font = font8x16;
# Line 751  static void vga_crtc_reg_write(struct ma Line 800  static void vga_crtc_reg_write(struct ma
800                  case 0x03:                  case 0x03:
801                          d->cur_mode = MODE_CHARCELL;                          d->cur_mode = MODE_CHARCELL;
802                          d->max_x = 80; d->max_y = 25;                          d->max_x = 80; d->max_y = 25;
803                          d->pixel_repx = d->pixel_repy = 1;                          d->pixel_repx = d->pixel_repy = machine->x11_scaleup;
804                          d->font_width = 8;                          d->font_width = 8;
805                          d->font_height = 16;                          d->font_height = 16;
806                          d->font = font8x16;                          d->font = font8x16;
# Line 761  static void vga_crtc_reg_write(struct ma Line 810  static void vga_crtc_reg_write(struct ma
810                          d->max_x = 160; d->max_y = 200;                          d->max_x = 160; d->max_y = 200;
811                          d->graphics_mode = GRAPHICS_MODE_4BIT;                          d->graphics_mode = GRAPHICS_MODE_4BIT;
812                          d->bits_per_pixel = 4;                          d->bits_per_pixel = 4;
813                          d->pixel_repx = 4;                          d->pixel_repx = 4 * machine->x11_scaleup;
814                          d->pixel_repy = 2;                          d->pixel_repy = 2 * machine->x11_scaleup;
815                          break;                          break;
816                  case 0x09:                  case 0x09:
817                  case 0x0d:                  case 0x0d:
# Line 770  static void vga_crtc_reg_write(struct ma Line 819  static void vga_crtc_reg_write(struct ma
819                          d->max_x = 320; d->max_y = 200;                          d->max_x = 320; d->max_y = 200;
820                          d->graphics_mode = GRAPHICS_MODE_4BIT;                          d->graphics_mode = GRAPHICS_MODE_4BIT;
821                          d->bits_per_pixel = 4;                          d->bits_per_pixel = 4;
822                          d->pixel_repx = d->pixel_repy = 2;                          d->pixel_repx = d->pixel_repy =
823                                2 * machine->x11_scaleup;
824                          break;                          break;
825                  case 0x0e:                  case 0x0e:
826                          d->cur_mode = MODE_GRAPHICS;                          d->cur_mode = MODE_GRAPHICS;
827                          d->max_x = 640; d->max_y = 200;                          d->max_x = 640; d->max_y = 200;
828                          d->graphics_mode = GRAPHICS_MODE_4BIT;                          d->graphics_mode = GRAPHICS_MODE_4BIT;
829                          d->bits_per_pixel = 4;                          d->bits_per_pixel = 4;
830                          d->pixel_repx = 1;                          d->pixel_repx = machine->x11_scaleup;
831                          d->pixel_repy = 2;                          d->pixel_repy = machine->x11_scaleup * 2;
832                          break;                          break;
833                  case 0x10:                  case 0x10:
834                          d->cur_mode = MODE_GRAPHICS;                          d->cur_mode = MODE_GRAPHICS;
835                          d->max_x = 640; d->max_y = 350;                          d->max_x = 640; d->max_y = 350;
836                          d->graphics_mode = GRAPHICS_MODE_4BIT;                          d->graphics_mode = GRAPHICS_MODE_4BIT;
837                          d->bits_per_pixel = 4;                          d->bits_per_pixel = 4;
838                          d->pixel_repx = d->pixel_repy = 1;                          d->pixel_repx = d->pixel_repy = machine->x11_scaleup;
839                          break;                          break;
840                  case 0x12:                  case 0x12:
841                          d->cur_mode = MODE_GRAPHICS;                          d->cur_mode = MODE_GRAPHICS;
842                          d->max_x = 640; d->max_y = 480;                          d->max_x = 640; d->max_y = 480;
843                          d->graphics_mode = GRAPHICS_MODE_4BIT;                          d->graphics_mode = GRAPHICS_MODE_4BIT;
844                          d->bits_per_pixel = 4;                          d->bits_per_pixel = 4;
845                          d->pixel_repx = d->pixel_repy = 1;                          d->pixel_repx = d->pixel_repy = machine->x11_scaleup;
846                          break;                          break;
847                  case 0x13:                  case 0x13:
848                          d->cur_mode = MODE_GRAPHICS;                          d->cur_mode = MODE_GRAPHICS;
849                          d->max_x = 320; d->max_y = 200;                          d->max_x = 320; d->max_y = 200;
850                          d->graphics_mode = GRAPHICS_MODE_8BIT;                          d->graphics_mode = GRAPHICS_MODE_8BIT;
851                          d->bits_per_pixel = 8;                          d->bits_per_pixel = 8;
852                          d->pixel_repx = d->pixel_repy = 2;                          d->pixel_repx = d->pixel_repy =
853                                2 * machine->x11_scaleup;
854                          break;                          break;
855                  default:                  default:
856                          fatal("TODO! video mode change hack (mode 0x%02x)\n",                          fatal("TODO! video mode change hack (mode 0x%02x)\n",
# Line 830  static void vga_crtc_reg_write(struct ma Line 881  static void vga_crtc_reg_write(struct ma
881    
882                  /*  Clear screen and reset the palette:  */                  /*  Clear screen and reset the palette:  */
883                  memset(d->charcells_outputed, 0, d->charcells_size);                  memset(d->charcells_outputed, 0, d->charcells_size);
884                    memset(d->charcells_drawn, 0, d->charcells_size);
885                  memset(d->gfx_mem, 0, d->gfx_mem_size);                  memset(d->gfx_mem, 0, d->gfx_mem_size);
886                  d->update_x1 = 0;                  d->update_x1 = 0;
887                  d->update_x2 = d->max_x - 1;                  d->update_x2 = d->max_x - 1;
# Line 854  static void vga_sequencer_reg_write(stru Line 906  static void vga_sequencer_reg_write(stru
906          int regnr, int idata)          int regnr, int idata)
907  {  {
908          switch (regnr) {          switch (regnr) {
909          case VGA_SEQ_MAP_MASK:          /*  0x02  */          case VGA_SEQ_RESET:
910            case VGA_SEQ_MAP_MASK:
911            case VGA_SEQ_SEQUENCER_MEMORY_MODE:
912                    debug("[ vga_sequencer_reg_write: select %i: TODO ]\n", regnr);
913                  break;                  break;
914          default:fatal("[ vga_sequencer_reg_write: select %i ]\n", regnr);          default:fatal("[ vga_sequencer_reg_write: select %i ]\n", regnr);
915                  /*  cpu->running = 0;  */                  /*  cpu->running = 0;  */
# Line 871  static void vga_graphcontr_reg_write(str Line 926  static void vga_graphcontr_reg_write(str
926          struct vga_data *d, int regnr, int idata)          struct vga_data *d, int regnr, int idata)
927  {  {
928          switch (regnr) {          switch (regnr) {
929          case VGA_GRAPHCONTR_MASK:               /*  0x08  */          case VGA_GRAPHCONTR_READMAPSELECT:
930            case VGA_GRAPHCONTR_GRAPHICSMODE:
931            case VGA_GRAPHCONTR_MISC:
932            case VGA_GRAPHCONTR_MASK:
933                    debug("[ vga_graphcontr_reg_write: select %i: TODO ]\n", regnr);
934                  break;                  break;
935          default:fatal("[ vga_graphcontr_reg_write: select %i ]\n", regnr);          default:fatal("[ vga_graphcontr_reg_write: select %i ]\n", regnr);
936                  /*  cpu->running = 0;  */                  /*  cpu->running = 0;  */
# Line 887  static void vga_graphcontr_reg_write(str Line 946  static void vga_graphcontr_reg_write(str
946  static void vga_attribute_reg_write(struct machine *machine, struct vga_data *d,  static void vga_attribute_reg_write(struct machine *machine, struct vga_data *d,
947          int regnr, int idata)          int regnr, int idata)
948  {  {
949            /*  0-15 are palette registers: TODO  */
950            if (regnr >= 0 && regnr <= 0xf)
951                    return;
952    
953          switch (regnr) {          switch (regnr) {
954          default:fatal("[ vga_attribute_reg_write: select %i ]\n", regnr);          default:fatal("[ vga_attribute_reg_write: select %i ]\n", regnr);
955                  /*  cpu->running = 0;  */                  /*  cpu->running = 0;  */
# Line 899  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 978  int dev_vga_ctrl_access(struct cpu *cpu, Line 1039  int dev_vga_ctrl_access(struct cpu *cpu,
1039                                  d->palette_read_index = idata;                                  d->palette_read_index = idata;
1040                                  d->palette_read_subindex = 0;                                  d->palette_read_subindex = 0;
1041                          } else {                          } else {
1042                                  fatal("[ dev_vga: WARNING: Read from "                                  debug("[ dev_vga: WARNING: Read from "
1043                                      "VGA_DAC_ADDR_READ? TODO ]\n");                                      "VGA_DAC_ADDR_READ? TODO ]\n");
1044                                  /*  TODO  */                                  /*  TODO  */
1045                          }                          }
# Line 1009  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 1103  int dev_vga_ctrl_access(struct cpu *cpu, Line 1165  int dev_vga_ctrl_access(struct cpu *cpu,
1165    
1166                  default:                  default:
1167                          if (writeflag==MEM_READ) {                          if (writeflag==MEM_READ) {
1168                                  fatal("[ vga_ctrl: read from 0x%08lx ]\n",                                  debug("[ vga_ctrl: read from 0x%08lx ]\n",
1169                                      (long)relative_addr);                                      (long)relative_addr);
1170                          } else {                          } else {
1171                                  fatal("[ vga_ctrl: write to  0x%08lx: 0x%08x"                                  debug("[ vga_ctrl: write to  0x%08lx: 0x%08x"
1172                                      " ]\n", (long)relative_addr, (int)idata);                                      " ]\n", (long)relative_addr, (int)idata);
1173                          }                          }
1174                  }                  }
# Line 1132  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, x,y, tmpi;          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 1142  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;
1212          d->max_x          = 80;          d->max_x          = 80;
1213          d->max_y          = 25;          d->max_y          = 25;
         d->pixel_repx     = 1;  
         d->pixel_repy     = 1;  
1214          d->cur_mode       = MODE_CHARCELL;          d->cur_mode       = MODE_CHARCELL;
1215          d->crtc_reg[0xff] = 0x03;          d->crtc_reg[0xff] = 0x03;
1216          d->charcells_size = d->max_x * VGA_MEM_MAXY * 2;          d->charcells_size = 0x8000;
1217          d->gfx_mem_size   = 1;  /*  Nothing, as we start in text mode  */          d->gfx_mem_size   = 1;  /*  Nothing, as we start in text mode  */
1218            d->pixel_repx = d->pixel_repy = machine->x11_scaleup;
1219    
1220          /*  Allocate in 4KB pages, to make it possible to use bintrans:  */          /*  Allocate in full pages, to make it possible to use bintrans:  */
1221          allocsize = ((d->charcells_size - 1) | 0xfff) + 1;          allocsize = ((d->charcells_size-1) | (machine->arch_pagesize-1)) + 1;
1222          d->charcells = malloc(d->charcells_size);          d->charcells = malloc(d->charcells_size);
1223          d->charcells_outputed = malloc(d->charcells_size);          d->charcells_outputed = malloc(d->charcells_size);
1224            d->charcells_drawn = malloc(d->charcells_size);
1225          d->gfx_mem = malloc(d->gfx_mem_size);          d->gfx_mem = malloc(d->gfx_mem_size);
1226          if (d->charcells == NULL || d->charcells_outputed == NULL ||          if (d->charcells == NULL || d->charcells_outputed == NULL ||
1227              d->gfx_mem == NULL) {              d->charcells_drawn == NULL || d->gfx_mem == NULL) {
1228                  fprintf(stderr, "out of memory in dev_vga_init()\n");                  fprintf(stderr, "out of memory in dev_vga_init()\n");
1229                  exit(1);                  exit(1);
1230          }          }
1231    
1232          for (y=0; y<VGA_MEM_MAXY; y++) {          memset(d->charcells_drawn, 0, d->charcells_size);
1233                  for (x=0; x<d->max_x; x++) {  
1234                          char ch = ' ';          for (i=0; i<d->charcells_size; i+=2) {
1235                          i = (x + d->max_x * y) * 2;                  d->charcells[i] = ' ';
1236                          d->charcells[i] = ch;                  d->charcells[i+1] = 0x07;  /*  Default color  */
1237                          d->charcells[i+1] = 0x07;  /*  Default color  */                  d->charcells_drawn[i] = ' ';
1238                  }                  d->charcells_drawn[i+1] = 0x07;
1239          }          }
1240    
1241          memset(d->charcells_outputed, 0, d->charcells_size);          memset(d->charcells_outputed, 0, d->charcells_size);
# Line 1189  void dev_vga_init(struct machine *machin Line 1252  void dev_vga_init(struct machine *machin
1252                  d->fb_max_y *= d->font_height;                  d->fb_max_y *= d->font_height;
1253          }          }
1254    
1255            memory_device_register(mem, "vga_charcells", videomem_base + 0x18000,
1256                allocsize, dev_vga_access, d, DM_DYNTRANS_OK |
1257                DM_DYNTRANS_WRITE_OK | DM_READS_HAVE_NO_SIDE_EFFECTS,
1258                d->charcells);
1259            memory_device_register(mem, "vga_gfx", videomem_base, GFX_ADDR_WINDOW,
1260                dev_vga_graphics_access, d, DM_DEFAULT |
1261                DM_READS_HAVE_NO_SIDE_EFFECTS, d->gfx_mem);
1262            memory_device_register(mem, "vga_ctrl", control_base,
1263                32, dev_vga_ctrl_access, d, DM_DEFAULT, NULL);
1264    
1265          d->fb = dev_fb_init(machine, mem, VGA_FB_ADDR, VFB_GENERIC,          d->fb = dev_fb_init(machine, mem, VGA_FB_ADDR, VFB_GENERIC,
1266              d->fb_max_x, d->fb_max_y, d->fb_max_x, d->fb_max_y, 24, "VGA", 0);              d->fb_max_x, d->fb_max_y, d->fb_max_x, d->fb_max_y, 24, "VGA");
1267          d->fb_size = d->fb_max_x * d->fb_max_y * 3;          d->fb_size = d->fb_max_x * d->fb_max_y * 3;
1268    
1269          reset_palette(d, 0);          reset_palette(d, 0);
1270    
         /*  MEM_BINTRANS_WRITE_OK  <-- This works with OpenBSD/arc, but not  
             with Windows NT yet. Why? */  
         memory_device_register(mem, "vga_charcells", videomem_base + 0x18000,  
             allocsize, dev_vga_access, d, MEM_BINTRANS_OK |  
             MEM_READING_HAS_NO_SIDE_EFFECTS, d->charcells);  
         memory_device_register(mem, "vga_gfx", videomem_base, GFX_ADDR_WINDOW,  
             dev_vga_graphics_access, d, MEM_DEFAULT |  
             MEM_READING_HAS_NO_SIDE_EFFECTS, d->gfx_mem);  
         memory_device_register(mem, "vga_ctrl", control_base,  
             32, dev_vga_ctrl_access, d, MEM_DEFAULT, NULL);  
   
1271          /*  This will force an initial redraw/resynch:  */          /*  This will force an initial redraw/resynch:  */
1272          d->update_x1 = 0;          d->update_x1 = 0;
1273          d->update_x2 = d->max_x - 1;          d->update_x2 = d->max_x - 1;
# Line 1215  void dev_vga_init(struct machine *machin Line 1277  void dev_vga_init(struct machine *machin
1277    
1278          machine_add_tickfunction(machine, dev_vga_tick, d, VGA_TICK_SHIFT);          machine_add_tickfunction(machine, dev_vga_tick, d, VGA_TICK_SHIFT);
1279    
         vga_update_cursor(machine, d);  
   
         tmpi = d->cursor_y * d->max_x + d->cursor_x;  
   
1280          register_reset(d);          register_reset(d);
1281    
1282            vga_update_cursor(machine, d);
1283  }  }
1284    

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

  ViewVC Help
Powered by ViewVC 1.1.26