src/emu/video/pc_vga.c
| r14096 | r14097 | |
| 19 | 19 | TODO: |
| 20 | 20 | - modernize |
| 21 | 21 | - convert to an ISA device. |
| 22 | | - fix pixel clock |
| 23 | 22 | - add emulated mc6845 hook-up |
| 24 | 23 | - fix resolution change |
| 25 | 24 | - fix video update. |
| r14096 | r14097 | |
| 29 | 28 | - (and many more ...) |
| 30 | 29 | |
| 31 | 30 | 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?). |
| 33 | 33 | |
| 34 | 34 | ROM declarations: |
| 35 | 35 | |
| r14096 | r14097 | |
| 76 | 76 | { |
| 77 | 77 | UINT8 index; |
| 78 | 78 | UINT8 *data; |
| 79 | | /**/ UINT16 horz_total; |
| 80 | | /**/ UINT16 horz_disp_end; |
| 79 | UINT16 horz_total; |
| 80 | UINT16 horz_disp_end; |
| 81 | 81 | /**/ UINT8 horz_blank_start; |
| 82 | 82 | /**/ UINT8 horz_blank_end; |
| 83 | 83 | /**/ UINT8 horz_retrace_start; |
| r14096 | r14097 | |
| 85 | 85 | /**/ UINT8 horz_retrace_end; |
| 86 | 86 | /**/ UINT8 disp_enable_skew; |
| 87 | 87 | /**/ UINT8 evra; |
| 88 | | /**/ UINT16 vert_total; |
| 88 | UINT16 vert_total; |
| 89 | 89 | /**/ UINT16 vert_retrace_start; |
| 90 | 90 | /**/ UINT8 vert_retrace_end; |
| 91 | | /**/ UINT16 vert_disp_end; |
| 91 | UINT16 vert_disp_end; |
| 92 | 92 | /**/ UINT16 vert_blank_start; |
| 93 | 93 | UINT16 line_compare; |
| 94 | 94 | /**/ UINT16 cursor_addr; |
| r14096 | r14097 | |
| 139 | 139 | int visible; |
| 140 | 140 | } cursor; |
| 141 | 141 | |
| 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 | | |
| 155 | 142 | /* oak vga */ |
| 156 | 143 | struct { UINT8 reg; } oak; |
| 157 | 144 | |
| r14096 | r14097 | |
| 406 | 393 | } |
| 407 | 394 | } |
| 408 | 395 | |
| 409 | | static UINT8 pc_vga_choosevideomode(running_machine &machine, int *width, int *height) |
| 396 | static UINT8 pc_vga_choosevideomode(running_machine &machine) |
| 410 | 397 | { |
| 411 | 398 | int i; |
| 412 | 399 | |
| r14096 | r14097 | |
| 447 | 434 | else if (!GRAPHIC_MODE) |
| 448 | 435 | { |
| 449 | 436 | //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 | |
| 452 | 442 | return 1; |
| 453 | 443 | } |
| 454 | 444 | else if (vga.gc.data[5]&0x40) |
| 455 | 445 | { |
| 456 | 446 | //proc = vga_vh_vga; |
| 457 | | *height = LINES; |
| 458 | | *width = VGA_COLUMNS * 8; |
| 447 | //*height = LINES; |
| 448 | //*width = VGA_COLUMNS * 8; |
| 459 | 449 | return 2; |
| 460 | 450 | } |
| 461 | 451 | else |
| 462 | 452 | { |
| 463 | 453 | //proc = vga_vh_ega; |
| 464 | | *height = LINES; |
| 465 | | *width = EGA_COLUMNS * 8; |
| 454 | //*height = LINES; |
| 455 | //*width = EGA_COLUMNS * 8; |
| 466 | 456 | return 3; |
| 467 | 457 | } |
| 468 | 458 | } |
| r14096 | r14097 | |
| 475 | 465 | UINT8 cur_mode = 0; |
| 476 | 466 | int w = 0, h = 0; |
| 477 | 467 | |
| 478 | | cur_mode = pc_vga_choosevideomode(screen.machine(), &w, &h); |
| 468 | cur_mode = pc_vga_choosevideomode(screen.machine()); |
| 479 | 469 | |
| 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 | | |
| 499 | 470 | //popmessage("%02x",cur_mode); |
| 500 | 471 | |
| 501 | 472 | switch(cur_mode) |
| r14096 | r14097 | |
| 524 | 495 | } |
| 525 | 496 | |
| 526 | 497 | |
| 527 | | |
| 528 | | static 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 | | |
| 541 | | static 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 | | |
| 555 | | static 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 | | |
| 564 | | static int vga_get_crtc_sync_lines(void) |
| 565 | | { |
| 566 | | return 10; |
| 567 | | } |
| 568 | | |
| 569 | | static int vga_get_crtc_sync_columns(void) |
| 570 | | { |
| 571 | | return 40; |
| 572 | | } |
| 573 | | |
| 574 | 498 | INLINE WRITE8_HANDLER(vga_dirty_w) |
| 575 | 499 | { |
| 576 | 500 | vga.memory[offset] = data; |
| r14096 | r14097 | |
| 796 | 720 | } |
| 797 | 721 | #endif |
| 798 | 722 | |
| 799 | | static void crtc_reg_write(UINT8 index, UINT8 data) |
| 723 | static void recompute_params(running_machine &machine) |
| 800 | 724 | { |
| 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 | |
| 753 | static void crtc_reg_write(running_machine &machine, UINT8 index, UINT8 data) |
| 754 | { |
| 801 | 755 | switch(index) |
| 802 | 756 | { |
| 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; |
| 805 | 765 | case 0x02: vga.crtc.horz_blank_start = (data & 0xff); break; |
| 806 | 766 | case 0x03: |
| 807 | 767 | vga.crtc.horz_blank_end &= ~0x1f; |
| r14096 | r14097 | |
| 821 | 781 | case 0x06: |
| 822 | 782 | vga.crtc.vert_total &= ~0xff; |
| 823 | 783 | vga.crtc.vert_total |= data & 0xff; |
| 784 | recompute_params(machine); |
| 824 | 785 | break; |
| 825 | 786 | case 0x07: // Overflow Register |
| 826 | 787 | vga.crtc.vert_total &= ~0x300; |
| r14096 | r14097 | |
| 836 | 797 | vga.crtc.vert_retrace_start |= ((data & 0x04) << (8-2)); |
| 837 | 798 | vga.crtc.vert_disp_end |= ((data & 0x02) << (8-1)); |
| 838 | 799 | vga.crtc.vert_total |= ((data & 0x01) << (8-0)); |
| 800 | recompute_params(machine); |
| 839 | 801 | break; |
| 840 | 802 | case 0x08: // Preset Row Scan Register |
| 841 | 803 | vga.crtc.byte_panning = (data & 0x60) >> 5; |
| r14096 | r14097 | |
| 879 | 841 | case 0x12: |
| 880 | 842 | vga.crtc.vert_disp_end &= ~0xff; |
| 881 | 843 | vga.crtc.vert_disp_end |= data & 0xff; |
| 844 | recompute_params(machine); |
| 882 | 845 | break; |
| 883 | 846 | case 0x13: |
| 884 | 847 | vga.crtc.offset = data & 0xff; |
| r14096 | r14097 | |
| 989 | 952 | if (vga.crtc.index < vga.svga_intf.crtc_regcount) |
| 990 | 953 | vga.crtc.data[vga.crtc.index] = data; |
| 991 | 954 | |
| 992 | | crtc_reg_write(vga.crtc.index,data); |
| 955 | crtc_reg_write(space->machine(),vga.crtc.index,data); |
| 993 | 956 | //space->machine().primary_screen->update_partial(space->machine().primary_screen->vpos()); |
| 994 | 957 | //printf("%02x %02x %d\n",vga.crtc.index,data,space->machine().primary_screen->vpos()); |
| 995 | 958 | break; |
| r14096 | r14097 | |
| 1161 | 1124 | break; |
| 1162 | 1125 | case 2: |
| 1163 | 1126 | vga.miscellaneous_output=data; |
| 1127 | recompute_params(space->machine()); |
| 1164 | 1128 | break; |
| 1165 | 1129 | case 3: |
| 1166 | 1130 | vga.oak.reg = data; |
| r14096 | r14097 | |
| 1181 | 1145 | vga.sequencer.data[vga.sequencer.index] = data; |
| 1182 | 1146 | vga_cpu_interface(space->machine()); |
| 1183 | 1147 | |
| 1184 | | if (vga.sequencer.index == 0) |
| 1185 | | vga.monitor.start_time = space->machine().time(); |
| 1148 | recompute_params(space->machine()); |
| 1186 | 1149 | } |
| 1187 | 1150 | break; |
| 1188 | 1151 | case 6: |
| r14096 | r14097 | |
| 1277 | 1240 | memset(&vga.attribute, 0, sizeof(vga.attribute)); |
| 1278 | 1241 | memset(&vga.dac, 0, sizeof(vga.dac)); |
| 1279 | 1242 | memset(&vga.cursor, 0, sizeof(vga.cursor)); |
| 1280 | | memset(&vga.monitor, 0, sizeof(vga.monitor)); |
| 1281 | 1243 | memset(&vga.oak, 0, sizeof(vga.oak)); |
| 1282 | 1244 | vga.log = 0; |
| 1283 | 1245 | |
| r14096 | r14097 | |
| 1288 | 1250 | vga.sequencer.data[4] = 0; |
| 1289 | 1251 | vga_cpu_interface(machine); |
| 1290 | 1252 | |
| 1253 | /* TODO: real defaults */ |
| 1291 | 1254 | 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; |
| 1292 | 1259 | } |
| 1293 | 1260 | |
| 1294 | 1261 | void pc_vga_init(running_machine &machine, const struct pc_vga_interface *vga_intf, const struct pc_svga_interface *svga_intf) |
| r14096 | r14097 | |
| 1377 | 1344 | |
| 1378 | 1345 | static VIDEO_START( vga ) |
| 1379 | 1346 | { |
| 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; |
| 1385 | 1347 | pc_video_start(machine); |
| 1386 | 1348 | } |
| 1387 | 1349 | |
| r14096 | r14097 | |
| 1406 | 1368 | |
| 1407 | 1369 | MACHINE_CONFIG_FRAGMENT( pcvideo_vga ) |
| 1408 | 1370 | 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) |
| 1410 | 1372 | MCFG_SCREEN_UPDATE_STATIC(pc_video) |
| 1411 | 1373 | |
| 1412 | 1374 | MCFG_PALETTE_LENGTH(0x100) |