Previous 15994 Revisions Next

r14097 Thursday 19th January, 2012 at 22:27:16 UTC by Angelo Salese
First attempt in adding proper VGA timings
[src/emu/video]pc_vga.c

src/emu/video/pc_vga.c
r14096r14097
1919    TODO:
2020    - modernize
2121    - convert to an ISA device.
22    - fix pixel clock
2322    - add emulated mc6845 hook-up
2423    - fix resolution change
2524    - fix video update.
r14096r14097
2928    - (and many more ...)
3029
3130   per-game issues:
32   - fix partial updates (The Incredible Machine)
31   - The Incredible Machine: fix partial updates
32   - MAME 0.01: fix 92 Hz refresh rate bug (uses VESA register?).
3333
3434    ROM declarations:
3535
r14096r14097
7676   {
7777      UINT8 index;
7878      UINT8 *data;
79/**/   UINT16 horz_total;
80/**/   UINT16 horz_disp_end;
79      UINT16 horz_total;
80      UINT16 horz_disp_end;
8181/**/   UINT8 horz_blank_start;
8282/**/   UINT8 horz_blank_end;
8383/**/   UINT8 horz_retrace_start;
r14096r14097
8585/**/   UINT8 horz_retrace_end;
8686/**/   UINT8 disp_enable_skew;
8787/**/   UINT8 evra;
88/**/   UINT16 vert_total;
88      UINT16 vert_total;
8989/**/   UINT16 vert_retrace_start;
9090/**/   UINT8 vert_retrace_end;
91/**/   UINT16 vert_disp_end;
91      UINT16 vert_disp_end;
9292/**/   UINT16 vert_blank_start;
9393      UINT16 line_compare;
9494/**/   UINT16 cursor_addr;
r14096r14097
139139      int visible;
140140   } cursor;
141141
142   struct {
143      int (*get_clock)(void);
144
145      int (*get_lines)(void);
146      int (*get_sync_lines)(void);
147
148      int (*get_columns)(void);
149      int (*get_sync_columns)(void);
150
151      attotime start_time;
152      int retrace;
153   } monitor;
154
155142   /* oak vga */
156143   struct { UINT8 reg; } oak;
157144
r14096r14097
406393   }
407394}
408395
409static UINT8 pc_vga_choosevideomode(running_machine &machine, int *width, int *height)
396static UINT8 pc_vga_choosevideomode(running_machine &machine)
410397{
411398   int i;
412399
r14096r14097
447434      else if (!GRAPHIC_MODE)
448435      {
449436         //proc = vga_vh_text;
450         *height = TEXT_LINES;
451         *width = TEXT_COLUMNS * CHAR_WIDTH;
437         //*height = TEXT_LINES;
438         //*width = TEXT_COLUMNS * CHAR_WIDTH;
439         if(vga.crtc.scan_doubling)
440            popmessage("Text mode with double scan enabled, contact MAMEdev");
441
452442         return 1;
453443      }
454444      else if (vga.gc.data[5]&0x40)
455445      {
456446         //proc = vga_vh_vga;
457         *height = LINES;
458         *width = VGA_COLUMNS * 8;
447         //*height = LINES;
448         //*width = VGA_COLUMNS * 8;
459449         return 2;
460450      }
461451      else
462452      {
463453         //proc = vga_vh_ega;
464         *height = LINES;
465         *width = EGA_COLUMNS * 8;
454         //*height = LINES;
455         //*width = EGA_COLUMNS * 8;
466456         return 3;
467457      }
468458   }
r14096r14097
475465   UINT8 cur_mode = 0;
476466   int w = 0, h = 0;
477467
478   cur_mode = pc_vga_choosevideomode(screen.machine(), &w, &h);
468   cur_mode = pc_vga_choosevideomode(screen.machine());
479469
480   if ((pc_current_width != w) || (pc_current_height != h))
481   {
482      int width = screen.width();
483      int height = screen.height();
484
485      pc_current_width = w;
486      pc_current_height = h;
487
488      if (pc_current_width > width)
489         pc_current_width = width;
490      if (pc_current_height > height)
491         pc_current_height = height;
492
493      if ((pc_current_width > 100) && (pc_current_height > 100))
494         screen.set_visible_area(0, pc_current_width-1, 0, pc_current_height-1);
495
496      bitmap.fill(0, cliprect);
497   }
498
499470   //popmessage("%02x",cur_mode);
500471
501472   switch(cur_mode)
r14096r14097
524495}
525496
526497
527
528static int vga_get_clock(void)
529{
530   int clck=0;
531   switch(vga.miscellaneous_output&0xc) {
532   case 0: clck=25000000;break;
533   case 4: clck=28000000;break;
534   /* case 8: external */
535   /* case 0xc: reserved */
536   }
537   if (vga.sequencer.data[1]&8) clck/=2;
538   return clck;
539}
540
541static int vga_get_crtc_columns(void) /* in clocks! */
542{
543   int columns=vga.crtc.data[0]+5; // htotal
544
545   if (!GRAPHIC_MODE)
546      columns *= CHAR_WIDTH;
547   else if (vga.gc.data[5]&0x40)
548      columns *= 4;
549   else
550      columns *= 8;
551
552   return columns;
553}
554
555static int vga_get_crtc_lines(void)
556{
557   int lines=(vga.crtc.data[6]
558            |((vga.crtc.data[7]&1)<<8)
559            |((vga.crtc.data[7]&0x20)<<(8-4)))+2;
560
561   return lines;
562}
563
564static int vga_get_crtc_sync_lines(void)
565{
566   return 10;
567}
568
569static int vga_get_crtc_sync_columns(void)
570{
571   return 40;
572}
573
574498INLINE WRITE8_HANDLER(vga_dirty_w)
575499{
576500   vga.memory[offset] = data;
r14096r14097
796720}
797721#endif
798722
799static void crtc_reg_write(UINT8 index, UINT8 data)
723static void recompute_params(running_machine &machine)
800724{
725   int vblank_period,hblank_period;
726   attoseconds_t refresh;
727   UINT8 hclock_m,hclock_d;
728   int pixel_clock;
729
730   hclock_m = (!GRAPHIC_MODE) ? CHAR_WIDTH : 8;
731
732   /* TODO: actually display is 640 x 400 in "VGA" mode */
733   if(!GRAPHIC_MODE)
734      hclock_d = CHAR_WIDTH;
735   else
736      hclock_d = vga.gc.data[5]&0x40 ? 4 : 8;
737
738   rectangle visarea(0, ((vga.crtc.horz_disp_end + 1) * hclock_d)-1, 0, vga.crtc.vert_disp_end);
739
740   vblank_period = (vga.crtc.vert_total + 2);
741   hblank_period = ((vga.crtc.horz_total + 5) * hclock_m);
742
743   /* TODO: 10b and 11b settings aren't known */
744   pixel_clock  = (vga.miscellaneous_output & 0xc) ? XTAL_28_63636MHz : XTAL_25_1748MHz;
745   pixel_clock /=    (((vga.sequencer.data[1]&8) >> 3) + 1);
746
747   refresh  = HZ_TO_ATTOSECONDS(pixel_clock) * (hblank_period) * vblank_period;
748
749   machine.primary_screen->configure((hblank_period), (vblank_period), visarea, refresh );
750//   popmessage("%d %d\n",vga.crtc.horz_total * 8,vga.crtc.vert_total);
751}
752
753static void crtc_reg_write(running_machine &machine, UINT8 index, UINT8 data)
754{
801755   switch(index)
802756   {
803      case 0x00: vga.crtc.horz_total = (data & 0xff) + 5; break;
804      case 0x01: vga.crtc.horz_disp_end = (data & 0xff) + 1; break;
757      case 0x00:
758         vga.crtc.horz_total = (data & 0xff);
759         recompute_params(machine);
760         break;
761      case 0x01:
762         vga.crtc.horz_disp_end = (data & 0xff);
763         recompute_params(machine);
764         break;
805765      case 0x02: vga.crtc.horz_blank_start = (data & 0xff); break;
806766      case 0x03:
807767         vga.crtc.horz_blank_end &= ~0x1f;
r14096r14097
821781      case 0x06:
822782         vga.crtc.vert_total &= ~0xff;
823783         vga.crtc.vert_total |= data & 0xff;
784         recompute_params(machine);
824785         break;
825786      case 0x07: // Overflow Register
826787         vga.crtc.vert_total         &= ~0x300;
r14096r14097
836797         vga.crtc.vert_retrace_start |= ((data & 0x04) << (8-2));
837798         vga.crtc.vert_disp_end      |= ((data & 0x02) << (8-1));
838799         vga.crtc.vert_total         |= ((data & 0x01) << (8-0));
800         recompute_params(machine);
839801         break;
840802      case 0x08: // Preset Row Scan Register
841803         vga.crtc.byte_panning = (data & 0x60) >> 5;
r14096r14097
879841      case 0x12:
880842         vga.crtc.vert_disp_end &= ~0xff;
881843         vga.crtc.vert_disp_end |= data & 0xff;
844         recompute_params(machine);
882845         break;
883846      case 0x13:
884847         vga.crtc.offset = data & 0xff;
r14096r14097
989952         if (vga.crtc.index < vga.svga_intf.crtc_regcount)
990953            vga.crtc.data[vga.crtc.index] = data;
991954
992         crtc_reg_write(vga.crtc.index,data);
955         crtc_reg_write(space->machine(),vga.crtc.index,data);
993956         //space->machine().primary_screen->update_partial(space->machine().primary_screen->vpos());
994957         //printf("%02x %02x %d\n",vga.crtc.index,data,space->machine().primary_screen->vpos());
995958         break;
r14096r14097
11611124      break;
11621125   case 2:
11631126      vga.miscellaneous_output=data;
1127      recompute_params(space->machine());
11641128      break;
11651129   case 3:
11661130      vga.oak.reg = data;
r14096r14097
11811145         vga.sequencer.data[vga.sequencer.index] = data;
11821146         vga_cpu_interface(space->machine());
11831147
1184         if (vga.sequencer.index == 0)
1185            vga.monitor.start_time = space->machine().time();
1148         recompute_params(space->machine());
11861149      }
11871150      break;
11881151   case 6:
r14096r14097
12771240   memset(&vga.attribute, 0, sizeof(vga.attribute));
12781241   memset(&vga.dac, 0, sizeof(vga.dac));
12791242   memset(&vga.cursor, 0, sizeof(vga.cursor));
1280   memset(&vga.monitor, 0, sizeof(vga.monitor));
12811243   memset(&vga.oak, 0, sizeof(vga.oak));
12821244   vga.log = 0;
12831245
r14096r14097
12881250   vga.sequencer.data[4] = 0;
12891251   vga_cpu_interface(machine);
12901252
1253   /* TODO: real defaults */
12911254   vga.crtc.line_compare = 0x3ff;
1255   vga.crtc.horz_total = 0xff;
1256   vga.crtc.vert_total = 0xff;
1257   vga.crtc.horz_disp_end = 0xff;
1258   vga.crtc.vert_disp_end = 0x3ff;
12921259}
12931260
12941261void pc_vga_init(running_machine &machine, const struct pc_vga_interface *vga_intf, const struct pc_svga_interface *svga_intf)
r14096r14097
13771344
13781345static VIDEO_START( vga )
13791346{
1380   vga.monitor.get_clock=vga_get_clock;
1381   vga.monitor.get_lines=vga_get_crtc_lines;
1382   vga.monitor.get_columns=vga_get_crtc_columns;
1383   vga.monitor.get_sync_lines=vga_get_crtc_sync_lines;
1384   vga.monitor.get_sync_columns=vga_get_crtc_sync_columns;
13851347   pc_video_start(machine);
13861348}
13871349
r14096r14097
14061368
14071369MACHINE_CONFIG_FRAGMENT( pcvideo_vga )
14081370   MCFG_SCREEN_ADD("screen", RASTER)
1409   MCFG_SCREEN_RAW_PARAMS(XTAL_25_1748MHz,800,0,640,525,0,480)
1371   MCFG_SCREEN_RAW_PARAMS(XTAL_25_1748MHz,900,0,640,526,0,480)
14101372   MCFG_SCREEN_UPDATE_STATIC(pc_video)
14111373
14121374   MCFG_PALETTE_LENGTH(0x100)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team