src/mess/video/isa_ega.c
| r15502 | r15503 | |
| 454 | 454 | */ |
| 455 | 455 | static SCREEN_UPDATE_IND16( pc_ega ); |
| 456 | 456 | static CRTC_EGA_UPDATE_ROW( ega_update_row ); |
| 457 | | static CRTC_EGA_ON_DE_CHANGED( ega_de_changed ); |
| 458 | | static CRTC_EGA_ON_VSYNC_CHANGED( ega_vsync_changed ); |
| 459 | | static CRTC_EGA_ON_VBLANK_CHANGED( ega_vblank_changed ); |
| 460 | 457 | |
| 461 | | static const crtc_ega_interface crtc_ega_ega_intf = |
| 458 | static CRTC_EGA_INTERFACE( crtc_ega_ega_intf ) |
| 462 | 459 | { |
| 463 | 460 | EGA_SCREEN_NAME, /* screen number */ |
| 464 | 461 | 8, /* numbers of pixels per video memory address */ |
| 465 | 462 | NULL, /* begin_update */ |
| 466 | 463 | ega_update_row, /* update_row */ |
| 467 | 464 | NULL, /* end_update */ |
| 468 | | ega_de_changed, /* on_de_chaged */ |
| 469 | | NULL, /* on_hsync_changed */ |
| 470 | | ega_vsync_changed, /* on_vsync_changed */ |
| 471 | | ega_vblank_changed /* on_vblank_changed */ |
| 465 | DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, isa8_ega_device, de_changed), /* on_de_chaged */ |
| 466 | DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, isa8_ega_device, hsync_changed), /* on_hsync_changed */ |
| 467 | DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, isa8_ega_device, vsync_changed), /* on vsync_changed */ |
| 468 | DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, isa8_ega_device, vblank_changed) /* on_vblank_changed */ |
| 472 | 469 | }; |
| 473 | 470 | |
| 474 | 471 | |
| r15502 | r15503 | |
| 510 | 507 | |
| 511 | 508 | INPUT_PORTS_START( ega ) |
| 512 | 509 | PORT_START( "config" ) |
| 513 | | PORT_CONFNAME( 0x0f, 0x0e, "dipswitches" ) |
| 514 | | PORT_CONFSETTING( 0x00, "0000 - MDA PRIMARY, EGA COLOR, 40x25" ) |
| 515 | | PORT_CONFSETTING( 0x08, "0001 - MDA PRIMARY, EGA COLOR, 80x25" ) |
| 516 | | PORT_CONFSETTING( 0x04, "0010 - MDA PRIMARY, EGA HI RES EMULATE (SAME AS 0001)" ) |
| 517 | | PORT_CONFSETTING( 0x0c, "0011 - MDA PRIMARY, EGA HI RES ENHANCED" ) |
| 518 | | PORT_CONFSETTING( 0x02, "0100 - CGA 40 PRIMARY, EGA MONOCHROME" ) |
| 519 | | PORT_CONFSETTING( 0x0a, "0101 - CGA 80 PRIMARY, EGA MONOCHROME" ) |
| 520 | | PORT_CONFSETTING( 0x06, "0110 - MDA SECONDARY, EGA COLOR, 40x25" ) |
| 521 | | PORT_CONFSETTING( 0x0e, "0111 - MDA SECONDARY, EGA COLOR, 80x25" ) |
| 522 | | PORT_CONFSETTING( 0x01, "1000 - MDA SECONDARY, EGA HI RES EMULATE (SAME AS 0111)" ) |
| 523 | | PORT_CONFSETTING( 0x09, "1001 - MDA SECONDARY, EGA HI RES ENHANCED" ) |
| 524 | | PORT_CONFSETTING( 0x05, "1010 - COLOR 40 SECONDARY, EGA" ) |
| 525 | | PORT_CONFSETTING( 0x0d, "1011 - COLOR 80 SECONDARY, EGA" ) |
| 526 | | PORT_CONFSETTING( 0x03, "1100 - RESERVED" ) |
| 527 | | PORT_CONFSETTING( 0x0b, "1101 - RESERVED" ) |
| 528 | | PORT_CONFSETTING( 0x07, "1110 - RESERVED" ) |
| 529 | | PORT_CONFSETTING( 0x0f, "1111 - RESERVED" ) |
| 510 | PORT_CONFNAME( 0x0f, 0x09, "dipswitches" ) |
| 511 | PORT_CONFSETTING( 0x00, "0000 - MDA PRIMARY, EGA COLOR, 40x25" ) /* DIAG: ?? 40 cols, RGBI */ |
| 512 | PORT_CONFSETTING( 0x08, "0001 - MDA PRIMARY, EGA COLOR, 80x25" ) /* DIAG: ?? 80 cols, RGBI */ |
| 513 | PORT_CONFSETTING( 0x04, "0010 - MDA PRIMARY, EGA HI RES EMULATE (SAME AS 0001)" ) /* DIAG: ?? 80 cols, RGBI */ |
| 514 | PORT_CONFSETTING( 0x0c, "0011 - MDA PRIMARY, EGA HI RES ENHANCED" ) /* DIAG: Color Display 40 cols, RrGgBb */ |
| 515 | PORT_CONFSETTING( 0x02, "0100 - CGA 40 PRIMARY, EGA MONOCHROME" ) /* DIAG: ??, Mono RGBI */ |
| 516 | PORT_CONFSETTING( 0x0a, "0101 - CGA 80 PRIMARY, EGA MONOCHROME" ) /* DIAG: ??, Mono RGBI */ |
| 517 | PORT_CONFSETTING( 0x06, "0110 - MDA SECONDARY, EGA COLOR, 40x25" ) /* DIAG: Color Display 40 cols, RGBI */ |
| 518 | PORT_CONFSETTING( 0x0e, "0111 - MDA SECONDARY, EGA COLOR, 80x25" ) /* DIAG: Color Display 80 cols, RGBI */ |
| 519 | PORT_CONFSETTING( 0x01, "1000 - MDA SECONDARY, EGA HI RES EMULATE (SAME AS 0111)" ) /* DIAG: Color Display 80 cols, RGBI */ |
| 520 | PORT_CONFSETTING( 0x09, "1001 - MDA SECONDARY, EGA HI RES ENHANCED" ) /* DIAG: Color Display 40 cols, RrGgBb */ |
| 521 | PORT_CONFSETTING( 0x05, "1010 - COLOR 40 SECONDARY, EGA" ) /* DIAG: Monochrome display, Mono RGBI */ |
| 522 | PORT_CONFSETTING( 0x0d, "1011 - COLOR 80 SECONDARY, EGA" ) /* DIAG: Monochrome display, Mono RGBI */ |
| 523 | PORT_CONFSETTING( 0x03, "1100 - RESERVED" ) /* ??, RGBI */ |
| 524 | PORT_CONFSETTING( 0x0b, "1101 - RESERVED" ) /* ??, RGBI */ |
| 525 | PORT_CONFSETTING( 0x07, "1110 - RESERVED" ) /* ??, RGBI */ |
| 526 | PORT_CONFSETTING( 0x0f, "1111 - RESERVED" ) /* ??, RGBI */ |
| 530 | 527 | INPUT_PORTS_END |
| 531 | 528 | |
| 532 | 529 | //************************************************************************** |
| r15502 | r15503 | |
| 618 | 615 | m_plane[2] = m_videoram + 0x20000; |
| 619 | 616 | m_plane[3] = m_videoram + 0x30000; |
| 620 | 617 | |
| 621 | | m_crtc_ega = subdevice(EGA_CRTC_NAME); |
| 618 | m_crtc_ega = subdevice<crtc_ega_device>(EGA_CRTC_NAME); |
| 622 | 619 | |
| 623 | 620 | m_isa->install_rom(this, 0xc0000, 0xc3fff, 0, 0, "ega", "user2"); |
| 624 | 621 | m_isa->install_device(0x3b0, 0x3bf, 0, 0, read8_delegate(FUNC(isa8_ega_device::pc_ega8_3b0_r), this), write8_delegate(FUNC(isa8_ega_device::pc_ega8_3b0_w), this)); |
| r15502 | r15503 | |
| 639 | 636 | memset(&m_graphics_controller,0,sizeof(m_graphics_controller)); |
| 640 | 637 | |
| 641 | 638 | m_frame_cnt = 0; |
| 639 | m_hsync = 0; |
| 642 | 640 | m_vsync = 0; |
| 643 | 641 | m_vblank = 0; |
| 644 | 642 | m_display_enable = 0; |
| r15502 | r15503 | |
| 730 | 728 | static SCREEN_UPDATE_IND16( pc_ega ) |
| 731 | 729 | { |
| 732 | 730 | isa8_ega_device *ega = dynamic_cast<isa8_ega_device*>(screen.owner()); |
| 733 | | crtc_ega_update( ega->m_crtc_ega, bitmap, cliprect); |
| 731 | ega->m_crtc_ega->screen_update( screen, bitmap, cliprect); |
| 734 | 732 | return 0; |
| 735 | 733 | } |
| 736 | 734 | |
| r15502 | r15503 | |
| 745 | 743 | } |
| 746 | 744 | |
| 747 | 745 | |
| 748 | | static CRTC_EGA_ON_DE_CHANGED( ega_de_changed ) |
| 746 | WRITE_LINE_MEMBER( isa8_ega_device::de_changed ) |
| 749 | 747 | { |
| 750 | | isa8_ega_device *ega = dynamic_cast<isa8_ega_device*>(device->owner()); |
| 751 | | ega->m_display_enable = display_enabled ? 1 : 0; |
| 748 | m_display_enable = state ? 1 : 0; |
| 752 | 749 | } |
| 753 | 750 | |
| 754 | 751 | |
| 755 | | static CRTC_EGA_ON_VSYNC_CHANGED( ega_vsync_changed ) |
| 752 | WRITE_LINE_MEMBER( isa8_ega_device::hsync_changed ) |
| 756 | 753 | { |
| 757 | | isa8_ega_device *ega = dynamic_cast<isa8_ega_device*>(device->owner()); |
| 758 | | ega->m_vsync = vsync ? 8 : 0; |
| 759 | | if ( vsync ) |
| 754 | m_hsync = state ? 1 : 0; |
| 755 | } |
| 756 | |
| 757 | |
| 758 | WRITE_LINE_MEMBER( isa8_ega_device::vsync_changed ) |
| 759 | { |
| 760 | m_vsync = state ? 1 : 0; |
| 761 | if ( state ) |
| 760 | 762 | { |
| 761 | | ega->m_frame_cnt++; |
| 763 | m_frame_cnt++; |
| 762 | 764 | } |
| 763 | 765 | } |
| 764 | 766 | |
| 765 | 767 | |
| 766 | | static CRTC_EGA_ON_VBLANK_CHANGED( ega_vblank_changed ) |
| 768 | WRITE_LINE_MEMBER( isa8_ega_device::vblank_changed ) |
| 767 | 769 | { |
| 768 | | isa8_ega_device *ega = dynamic_cast<isa8_ega_device*>(device->owner()); |
| 769 | | ega->m_vblank = vblank ? 8 : 0; |
| 770 | m_vblank = state ? 8 : 0; |
| 770 | 771 | } |
| 771 | 772 | |
| 772 | 773 | |
| r15502 | r15503 | |
| 803 | 804 | { |
| 804 | 805 | // EGA mode |
| 805 | 806 | |
| 806 | | // UINT8 mask = ega->m_attribute.data[0x12] & 0x0f; |
| 807 | UINT8 mask = ega->m_attribute.data[0x12] & 0x0f; |
| 807 | 808 | |
| 808 | 809 | for ( int i = 0; i < x_count; i++ ) |
| 809 | 810 | { |
| r15502 | r15503 | |
| 817 | 818 | { |
| 818 | 819 | UINT16 col = ( data0 & 0x01 ) | ( data1 & 0x02 ) | ( data2 & 0x04 ) | ( data3 & 0x08 ); |
| 819 | 820 | |
| 820 | | // col &= mask; |
| 821 | col &= mask; |
| 821 | 822 | |
| 822 | 823 | p[j] = ega->m_attribute.data[col]; |
| 823 | 824 | |
| r15502 | r15503 | |
| 942 | 943 | { |
| 943 | 944 | clock >>= 1; |
| 944 | 945 | } |
| 945 | | crtc_ega_set_clock( m_crtc_ega, clock / pixels ); |
| 946 | | crtc_ega_set_hpixels_per_column( m_crtc_ega, pixels ); |
| 946 | m_crtc_ega->set_clock( clock / pixels ); |
| 947 | m_crtc_ega->set_hpixels_per_column( pixels ); |
| 947 | 948 | |
| 948 | 949 | if ( ! m_update_row ) |
| 949 | 950 | logerror("unknown video mode\n"); |
| r15502 | r15503 | |
| 954 | 955 | { |
| 955 | 956 | UINT8 data = 0xFF; |
| 956 | 957 | |
| 957 | | if ( !space.debugger_access() ) |
| 958 | if ( !space.debugger_access() && ! ( m_sequencer.data[4] & 0x04 ) ) |
| 958 | 959 | { |
| 959 | 960 | /* Fill read latches */ |
| 960 | 961 | m_read_latch[0] = m_plane[0][offset & 0xffff]; |
| r15502 | r15503 | |
| 967 | 968 | { |
| 968 | 969 | // Read mode #1 |
| 969 | 970 | popmessage("ega: Read mode 1 not supported yet!"); |
| 971 | printf("EGA: Read mode 1 not supported yet!\n"); |
| 970 | 972 | } |
| 971 | 973 | else |
| 972 | 974 | { |
| r15502 | r15503 | |
| 987 | 989 | } |
| 988 | 990 | |
| 989 | 991 | |
| 992 | UINT8 isa8_ega_device::alu_op( UINT8 data, UINT8 latch_data ) |
| 993 | { |
| 994 | UINT8 mask = m_graphics_controller.data[8]; |
| 995 | |
| 996 | switch( m_graphics_controller.data[3] & 0x18 ) |
| 997 | { |
| 998 | case 0x00: // Unmodified |
| 999 | return ( data & mask ) | ( latch_data & ~mask ); |
| 1000 | |
| 1001 | case 0x08: // AND |
| 1002 | return ( data | ~mask ) & latch_data; |
| 1003 | |
| 1004 | case 0x10: // OR |
| 1005 | return ( data & mask ) | latch_data; |
| 1006 | |
| 1007 | case 0x18: // XOR |
| 1008 | return ( data & mask ) ^ latch_data; |
| 1009 | } |
| 1010 | return 0; |
| 1011 | } |
| 1012 | |
| 1013 | |
| 990 | 1014 | WRITE8_MEMBER( isa8_ega_device::write ) |
| 991 | 1015 | { |
| 1016 | UINT8 d[4]; |
| 992 | 1017 | UINT8 alu[4]; |
| 993 | 1018 | UINT8 target_mask = m_graphics_controller.data[8]; |
| 994 | 1019 | |
| r15502 | r15503 | |
| 1000 | 1025 | // Pass through barrel shifter |
| 1001 | 1026 | data = ( ( ( data << 8 ) | data ) >> ( m_graphics_controller.data[3] & 0x07 ) ) & 0xFF; |
| 1002 | 1027 | |
| 1003 | | // Pass through ALUs |
| 1004 | | switch( m_graphics_controller.data[3] & 0x18 ) |
| 1028 | d[0] = d[1] = d[2] = d[3] = data; |
| 1029 | |
| 1030 | /* Apply Set/Reset settings */ |
| 1031 | if ( m_graphics_controller.data[1] & 0x01 ) |
| 1005 | 1032 | { |
| 1006 | | case 0x00: // Unmodified |
| 1007 | | alu[0] = data; |
| 1008 | | alu[1] = data; |
| 1009 | | alu[2] = data; |
| 1010 | | alu[3] = data; |
| 1011 | | break; |
| 1033 | d[0] = ( m_graphics_controller.data[0] & 0x01 ) ? 0xff : 0x00; |
| 1034 | } |
| 1035 | if ( m_graphics_controller.data[1] & 0x02 ) |
| 1036 | { |
| 1037 | d[1] = ( m_graphics_controller.data[0] & 0x02 ) ? 0xff : 0x00; |
| 1038 | } |
| 1039 | if ( m_graphics_controller.data[1] & 0x04 ) |
| 1040 | { |
| 1041 | d[2] = ( m_graphics_controller.data[0] & 0x04 ) ? 0xff : 0x00; |
| 1042 | } |
| 1043 | if ( m_graphics_controller.data[1] & 0x08 ) |
| 1044 | { |
| 1045 | d[3] = ( m_graphics_controller.data[0] & 0x08 ) ? 0xff : 0x00; |
| 1046 | } |
| 1012 | 1047 | |
| 1013 | | case 0x08: // AND |
| 1014 | | alu[0] = m_read_latch[0] & data; |
| 1015 | | alu[1] = m_read_latch[1] & data; |
| 1016 | | alu[2] = m_read_latch[2] & data; |
| 1017 | | alu[3] = m_read_latch[3] & data; |
| 1018 | | break; |
| 1048 | // Pass through ALUs |
| 1049 | alu[0] = alu_op( d[0], m_read_latch[0] ); |
| 1050 | alu[1] = alu_op( d[1], m_read_latch[1] ); |
| 1051 | alu[2] = alu_op( d[2], m_read_latch[2] ); |
| 1052 | alu[3] = alu_op( d[3], m_read_latch[3] ); |
| 1019 | 1053 | |
| 1020 | | case 0x10: // OR |
| 1021 | | alu[0] = m_read_latch[0] | data; |
| 1022 | | alu[1] = m_read_latch[1] | data; |
| 1023 | | alu[2] = m_read_latch[2] | data; |
| 1024 | | alu[3] = m_read_latch[3] | data; |
| 1025 | | break; |
| 1026 | | |
| 1027 | | case 0x18: // XOR |
| 1028 | | alu[0] = m_read_latch[0] ^ data; |
| 1029 | | alu[1] = m_read_latch[1] ^ data; |
| 1030 | | alu[2] = m_read_latch[2] ^ data; |
| 1031 | | alu[3] = m_read_latch[3] ^ data; |
| 1032 | | break; |
| 1033 | | } |
| 1034 | 1054 | break; |
| 1035 | 1055 | |
| 1036 | 1056 | case 1: // Write mode 1 |
| r15502 | r15503 | |
| 1042 | 1062 | return; |
| 1043 | 1063 | |
| 1044 | 1064 | case 2: // Write mode 2 |
| 1045 | | alu[0] = ( data & 0x01 ) ? 0xff : 0x00; |
| 1046 | | alu[1] = ( data & 0x02 ) ? 0xff : 0x00; |
| 1047 | | alu[2] = ( data & 0x04 ) ? 0xff : 0x00; |
| 1048 | | alu[3] = ( data & 0x08 ) ? 0xff : 0x00; |
| 1065 | d[0] = ( data & 0x01 ) ? 0xff : 0x00; |
| 1066 | d[1] = ( data & 0x02 ) ? 0xff : 0x00; |
| 1067 | d[2] = ( data & 0x04 ) ? 0xff : 0x00; |
| 1068 | d[3] = ( data & 0x08 ) ? 0xff : 0x00; |
| 1069 | |
| 1070 | alu[0] = alu_op( d[0], m_read_latch[0] ); |
| 1071 | alu[1] = alu_op( d[1], m_read_latch[1] ); |
| 1072 | alu[2] = alu_op( d[2], m_read_latch[2] ); |
| 1073 | alu[3] = alu_op( d[3], m_read_latch[3] ); |
| 1049 | 1074 | break; |
| 1050 | 1075 | |
| 1051 | 1076 | case 3: // Write mode 3 |
| r15502 | r15503 | |
| 1132 | 1157 | } |
| 1133 | 1158 | |
| 1134 | 1159 | |
| 1135 | | UINT8 isa8_ega_device::pc_ega8_3X0_r(UINT8 offset) |
| 1160 | READ8_MEMBER( isa8_ega_device::pc_ega8_3X0_r ) |
| 1136 | 1161 | { |
| 1137 | 1162 | int data = 0xff; |
| 1138 | 1163 | |
| 1139 | | if ( VERBOSE_EGA ) |
| 1140 | | { |
| 1141 | | logerror("pc_ega_3X0_r: offset = %02x\n", offset ); |
| 1142 | | } |
| 1143 | | |
| 1144 | 1164 | switch ( offset ) |
| 1145 | 1165 | { |
| 1146 | 1166 | /* CRT Controller - address register */ |
| r15502 | r15503 | |
| 1150 | 1170 | |
| 1151 | 1171 | /* CRT Controller - data register */ |
| 1152 | 1172 | case 1: case 3: case 5: case 7: |
| 1153 | | data = crtc_ega_register_r( m_crtc_ega, offset ); |
| 1173 | data = m_crtc_ega->register_r( space, offset ); |
| 1154 | 1174 | break; |
| 1155 | 1175 | |
| 1156 | 1176 | /* Input Status Register 1 */ |
| 1157 | 1177 | case 10: |
| 1158 | | data = m_vblank | m_display_enable; |
| 1178 | data = m_vblank | ( m_hsync | m_vsync ); // m_display_enable; |
| 1159 | 1179 | |
| 1160 | 1180 | if ( m_display_enable ) |
| 1161 | 1181 | { |
| r15502 | r15503 | |
| 1174 | 1194 | return data; |
| 1175 | 1195 | } |
| 1176 | 1196 | |
| 1177 | | void isa8_ega_device::pc_ega8_3X0_w(UINT8 offset, UINT8 data) |
| 1197 | WRITE8_MEMBER( isa8_ega_device::pc_ega8_3X0_w ) |
| 1178 | 1198 | { |
| 1179 | 1199 | if ( VERBOSE_EGA ) |
| 1180 | 1200 | { |
| 1181 | | logerror("pc_ega_3X0_w: offset = %02x, data = %02x\n", offset, data ); |
| 1201 | // logerror("pc_ega_3X0_w: offset = %02x, data = %02x\n", offset, data ); |
| 1182 | 1202 | } |
| 1183 | 1203 | |
| 1184 | 1204 | switch ( offset ) |
| 1185 | 1205 | { |
| 1186 | 1206 | /* CRT Controller - address register */ |
| 1187 | 1207 | case 0: case 2: case 4: case 6: |
| 1188 | | crtc_ega_address_w( m_crtc_ega, offset, data ); |
| 1208 | m_crtc_ega->address_w( space, offset, data ); |
| 1189 | 1209 | break; |
| 1190 | 1210 | |
| 1191 | 1211 | /* CRT Controller - data register */ |
| 1192 | 1212 | case 1: case 3: case 5: case 7: |
| 1193 | | crtc_ega_register_w( m_crtc_ega, offset, data ); |
| 1213 | m_crtc_ega->register_w( space, offset, data ); |
| 1194 | 1214 | break; |
| 1195 | 1215 | |
| 1196 | 1216 | /* Set Light Pen Flip Flop */ |
| r15502 | r15503 | |
| 1212 | 1232 | |
| 1213 | 1233 | READ8_MEMBER(isa8_ega_device::pc_ega8_3b0_r ) |
| 1214 | 1234 | { |
| 1215 | | return ( m_misc_output & 0x01 ) ? 0xFF : pc_ega8_3X0_r(offset); |
| 1235 | return ( m_misc_output & 0x01 ) ? 0xFF : pc_ega8_3X0_r(space, offset); |
| 1216 | 1236 | } |
| 1217 | 1237 | |
| 1218 | 1238 | |
| 1219 | 1239 | READ8_MEMBER(isa8_ega_device::pc_ega8_3d0_r ) |
| 1220 | 1240 | { |
| 1221 | | return ( m_misc_output & 0x01 ) ? pc_ega8_3X0_r(offset) : 0xFF; |
| 1241 | return ( m_misc_output & 0x01 ) ? pc_ega8_3X0_r(space, offset) : 0xFF; |
| 1222 | 1242 | } |
| 1223 | 1243 | |
| 1224 | 1244 | |
| r15502 | r15503 | |
| 1226 | 1246 | { |
| 1227 | 1247 | if ( ! ( m_misc_output & 0x01 ) ) |
| 1228 | 1248 | { |
| 1229 | | pc_ega8_3X0_w(offset, data ); |
| 1249 | pc_ega8_3X0_w( space, offset, data ); |
| 1230 | 1250 | } |
| 1231 | 1251 | } |
| 1232 | 1252 | |
| r15502 | r15503 | |
| 1235 | 1255 | { |
| 1236 | 1256 | if ( m_misc_output & 0x01 ) |
| 1237 | 1257 | { |
| 1238 | | pc_ega8_3X0_w(offset, data ); |
| 1258 | pc_ega8_3X0_w( space, offset, data ); |
| 1239 | 1259 | } |
| 1240 | 1260 | } |
| 1241 | 1261 | |
| r15502 | r15503 | |
| 1246 | 1266 | |
| 1247 | 1267 | if ( VERBOSE_EGA ) |
| 1248 | 1268 | { |
| 1249 | | logerror("pc_ega_3c0_r: offset = %02x\n", offset ); |
| 1269 | // logerror("pc_ega_3c0_r: offset = %02x\n", offset ); |
| 1250 | 1270 | } |
| 1251 | 1271 | |
| 1252 | 1272 | switch ( offset ) |
| r15502 | r15503 | |
| 1305 | 1325 | |
| 1306 | 1326 | if ( VERBOSE_EGA ) |
| 1307 | 1327 | { |
| 1308 | | logerror("pc_ega_3c0_w: offset = %02x, data = %02x\n", offset, data ); |
| 1328 | // logerror("pc_ega_3c0_w: offset = %02x, data = %02x\n", offset, data ); |
| 1309 | 1329 | } |
| 1310 | 1330 | |
| 1311 | 1331 | switch ( offset ) |
src/mess/video/crtc_ega.c
| r15502 | r15503 | |
| 13 | 13 | #define LOG (1) |
| 14 | 14 | |
| 15 | 15 | |
| 16 | | /* device types */ |
| 17 | | enum |
| 18 | | { |
| 19 | | TYPE_CRTC_EGA=0, |
| 20 | | TYPE_CRTC_VGA, |
| 16 | const device_type CRTC_EGA = &device_creator<crtc_ega_device>; |
| 21 | 17 | |
| 22 | | NUM_TYPES |
| 23 | | }; |
| 24 | 18 | |
| 25 | | |
| 26 | | /* tags for state saving */ |
| 27 | | static const char * const device_tags[NUM_TYPES] = { "crtc_ega", "crtc_vga" }; |
| 28 | | |
| 29 | | |
| 30 | | typedef struct _crtc_ega_t crtc_ega_t; |
| 31 | | struct _crtc_ega_t |
| 19 | void crtc_ega_device::device_config_complete() |
| 32 | 20 | { |
| 33 | | int device_type; |
| 34 | | const crtc_ega_interface *intf; |
| 35 | | screen_device *screen; |
| 21 | const crtc_ega_interface *intf = reinterpret_cast<const crtc_ega_interface *>(static_config()); |
| 36 | 22 | |
| 37 | | /* ega/vga register file */ |
| 38 | | UINT8 horiz_char_total; /* 0x00 */ |
| 39 | | UINT8 horiz_disp; /* 0x01 */ |
| 40 | | UINT8 horiz_blank_start; /* 0x02 */ |
| 41 | | UINT8 horiz_blank_end; /* 0x03/0x05 */ |
| 42 | | UINT8 ena_vert_access; /* 0x03 */ |
| 43 | | UINT8 de_skew; /* 0x03 */ |
| 44 | | UINT8 horiz_retr_start; /* 0x04 */ |
| 45 | | UINT8 horiz_retr_end; /* 0x05 */ |
| 46 | | UINT8 horiz_retr_skew; /* 0x05 */ |
| 47 | | UINT16 vert_total; /* 0x06/0x07 */ |
| 48 | | UINT8 preset_row_scan; /* 0x08 */ |
| 49 | | UINT8 byte_panning; /* 0x08 */ |
| 50 | | UINT8 max_ras_addr; /* 0x09 */ |
| 51 | | UINT8 scan_doubling; /* 0x09 */ |
| 52 | | UINT8 cursor_start_ras; /* 0x0a */ |
| 53 | | UINT8 cursor_disable; /* 0x0a */ |
| 54 | | UINT8 cursor_end_ras; /* 0x0b */ |
| 55 | | UINT8 cursor_skew; /* 0x0b */ |
| 56 | | UINT16 disp_start_addr; /* 0x0c/0x0d */ |
| 57 | | UINT16 cursor_addr; /* 0x0e/0x0f */ |
| 58 | | UINT16 light_pen_addr; /* 0x10/0x11 */ |
| 59 | | UINT16 vert_retr_start; /* 0x10/0x07 */ |
| 60 | | UINT8 vert_retr_end; /* 0x11 */ |
| 61 | | UINT8 protect; /* 0x11 */ |
| 62 | | UINT8 bandwidth; /* 0x11 */ |
| 63 | | UINT16 vert_disp_end; /* 0x12/0x07 */ |
| 64 | | UINT8 offset; /* 0x13 */ |
| 65 | | UINT8 underline_loc; /* 0x14 */ |
| 66 | | UINT16 vert_blank_start; /* 0x15/0x07/0x09 */ |
| 67 | | UINT8 vert_blank_end; /* 0x16 */ |
| 68 | | UINT8 mode_control; /* 0x17 */ |
| 69 | | UINT16 line_compare; /* 0x18/0x07/0x09 */ |
| 23 | if ( intf != NULL ) |
| 24 | { |
| 25 | *static_cast<crtc_ega_interface *>(this) = *intf; |
| 26 | } |
| 27 | else |
| 28 | { |
| 29 | m_screen_tag = NULL; |
| 30 | m_hpixels_per_column = 0; |
| 31 | m_begin_update = NULL; |
| 32 | m_update_row = NULL; |
| 33 | m_end_update = NULL; |
| 34 | memset(&m_out_de_func, 0, sizeof(m_out_de_func)); |
| 35 | memset(&m_out_hsync_func, 0, sizeof(m_out_hsync_func)); |
| 36 | memset(&m_out_vsync_func, 0, sizeof(m_out_vsync_func)); |
| 37 | memset(&m_out_vblank_func, 0, sizeof(m_out_vblank_func)); |
| 38 | } |
| 39 | } |
| 70 | 40 | |
| 71 | | /* other internal state */ |
| 72 | | UINT64 clock; |
| 73 | | UINT8 register_address_latch; |
| 74 | | UINT8 hpixels_per_column; |
| 75 | | UINT8 cursor_state; /* 0 = off, 1 = on */ |
| 76 | | UINT8 cursor_blink_count; |
| 77 | 41 | |
| 78 | | /* timers */ |
| 79 | | emu_timer *de_changed_timer; |
| 80 | | emu_timer *hsync_on_timer; |
| 81 | | emu_timer *hsync_off_timer; |
| 82 | | emu_timer *vsync_on_timer; |
| 83 | | emu_timer *vsync_off_timer; |
| 84 | | emu_timer *vblank_on_timer; |
| 85 | | emu_timer *vblank_off_timer; |
| 86 | | emu_timer *light_pen_latch_timer; |
| 87 | | |
| 88 | | /* computed values - do NOT state save these! */ |
| 89 | | UINT16 horiz_pix_total; |
| 90 | | UINT16 vert_pix_total; |
| 91 | | UINT16 max_visible_x; |
| 92 | | UINT16 max_visible_y; |
| 93 | | UINT16 hsync_on_pos; |
| 94 | | UINT16 hsync_off_pos; |
| 95 | | UINT16 vsync_on_pos; |
| 96 | | UINT16 vsync_off_pos; |
| 97 | | UINT16 current_disp_addr; /* the display address currently drawn */ |
| 98 | | UINT8 light_pen_latched; |
| 99 | | int has_valid_parameters; |
| 100 | | }; |
| 101 | | |
| 102 | | //static DEVICE_GET_INFO( crtc_vga ); |
| 103 | | |
| 104 | | static void recompute_parameters(crtc_ega_t *crtc_ega, int postload); |
| 105 | | static void update_de_changed_timer(crtc_ega_t *crtc_ega); |
| 106 | | static void update_hsync_changed_timers(crtc_ega_t *crtc_ega); |
| 107 | | static void update_vsync_changed_timers(crtc_ega_t *crtc_ega); |
| 108 | | static void update_vblank_changed_timers(crtc_ega_t *crtc_ega); |
| 109 | | |
| 110 | | |
| 111 | | /* makes sure that the passed in device is the right type */ |
| 112 | | INLINE crtc_ega_t *get_safe_token(device_t *device) |
| 42 | crtc_ega_device::crtc_ega_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 43 | : device_t(mconfig, CRTC_EGA, "crtc_EGA", tag, owner, clock) |
| 113 | 44 | { |
| 114 | | assert(device != NULL); |
| 115 | | assert((device->type() == CRTC_EGA) || |
| 116 | | /*(device->type() == DEVICE_GET_INFO_NAME(crtc_vga))*/0 ); |
| 117 | | |
| 118 | | return (crtc_ega_t *)downcast<legacy_device_base *>(device)->token(); |
| 119 | 45 | } |
| 120 | 46 | |
| 121 | 47 | |
| 122 | | static void crtc_ega_state_save_postload(crtc_ega_t *state) |
| 48 | void crtc_ega_device::device_post_load() |
| 123 | 49 | { |
| 124 | | recompute_parameters(state, TRUE); |
| 50 | recompute_parameters(true); |
| 125 | 51 | } |
| 126 | 52 | |
| 127 | 53 | |
| 128 | | WRITE8_DEVICE_HANDLER( crtc_ega_address_w ) |
| 54 | WRITE8_MEMBER( crtc_ega_device::address_w ) |
| 129 | 55 | { |
| 130 | | crtc_ega_t *crtc_ega = get_safe_token(device); |
| 131 | | |
| 132 | | crtc_ega->register_address_latch = data & 0x1f; |
| 56 | m_register_address_latch = data & 0x1f; |
| 133 | 57 | } |
| 134 | 58 | |
| 135 | 59 | |
| 136 | | READ8_DEVICE_HANDLER( crtc_ega_register_r ) |
| 60 | READ8_MEMBER( crtc_ega_device::register_r ) |
| 137 | 61 | { |
| 138 | | crtc_ega_t *crtc_ega = get_safe_token(device); |
| 139 | 62 | UINT8 ret = 0; |
| 140 | 63 | |
| 141 | | switch (crtc_ega->register_address_latch) |
| 64 | switch (m_register_address_latch) |
| 142 | 65 | { |
| 143 | | case 0x0c: ret = (crtc_ega->disp_start_addr >> 8) & 0xff; break; |
| 144 | | case 0x0d: ret = (crtc_ega->disp_start_addr >> 0) & 0xff; break; |
| 145 | | case 0x0e: ret = (crtc_ega->cursor_addr >> 8) & 0xff; break; |
| 146 | | case 0x0f: ret = (crtc_ega->cursor_addr >> 0) & 0xff; break; |
| 147 | | case 0x10: ret = (crtc_ega->light_pen_addr >> 8) & 0xff; crtc_ega->light_pen_latched = FALSE; break; |
| 148 | | case 0x11: ret = (crtc_ega->light_pen_addr >> 0) & 0xff; crtc_ega->light_pen_latched = FALSE; break; |
| 66 | case 0x0c: ret = (m_disp_start_addr >> 8) & 0xff; break; |
| 67 | case 0x0d: ret = (m_disp_start_addr >> 0) & 0xff; break; |
| 68 | case 0x0e: ret = (m_cursor_addr >> 8) & 0xff; break; |
| 69 | case 0x0f: ret = (m_cursor_addr >> 0) & 0xff; break; |
| 70 | case 0x10: ret = (m_light_pen_addr >> 8) & 0xff; m_light_pen_latched = FALSE; break; |
| 71 | case 0x11: ret = (m_light_pen_addr >> 0) & 0xff; m_light_pen_latched = FALSE; break; |
| 149 | 72 | |
| 150 | 73 | /* all other registers are write only and return 0 */ |
| 151 | 74 | default: break; |
| r15502 | r15503 | |
| 155 | 78 | } |
| 156 | 79 | |
| 157 | 80 | |
| 158 | | WRITE8_DEVICE_HANDLER( crtc_ega_register_w ) |
| 81 | WRITE8_MEMBER( crtc_ega_device::register_w ) |
| 159 | 82 | { |
| 160 | | crtc_ega_t *crtc_ega = get_safe_token(device); |
| 83 | if (LOG) logerror("CRTC_EGA PC %04x: reg 0x%02x = 0x%02x\n", cpu_get_pc(machine().firstcpu), m_register_address_latch, data); |
| 161 | 84 | |
| 162 | | if (LOG) logerror("CRTC_EGA PC %04x: reg 0x%02x = 0x%02x\n", cpu_get_pc(device->machine().firstcpu), crtc_ega->register_address_latch, data); |
| 163 | | |
| 164 | | switch (crtc_ega->register_address_latch) |
| 85 | switch (m_register_address_latch) |
| 165 | 86 | { |
| 166 | | case 0x00: crtc_ega->horiz_char_total = data & 0xff; break; |
| 167 | | case 0x01: crtc_ega->horiz_disp = data & 0xff; break; |
| 168 | | case 0x02: crtc_ega->horiz_blank_start = data & 0xff; break; |
| 169 | | case 0x03: crtc_ega->horiz_blank_end = ((data & 0x1f) << 0) | (crtc_ega->horiz_blank_end & 0x20); |
| 170 | | crtc_ega->de_skew = ((data & 0x60) >> 5); |
| 171 | | crtc_ega->ena_vert_access = data & 0x80; |
| 87 | case 0x00: m_horiz_char_total = data & 0xff; break; |
| 88 | case 0x01: m_horiz_disp = data & 0xff; break; |
| 89 | case 0x02: m_horiz_blank_start = data & 0xff; break; |
| 90 | case 0x03: m_horiz_blank_end = ((data & 0x1f) << 0) | (m_horiz_blank_end & 0x20); |
| 91 | m_de_skew = ((data & 0x60) >> 5); |
| 92 | m_ena_vert_access = data & 0x80; |
| 172 | 93 | break; |
| 173 | | case 0x04: crtc_ega->horiz_retr_start = data & 0xff; break; |
| 174 | | case 0x05: crtc_ega->horiz_retr_end = data & 0x1f; |
| 175 | | crtc_ega->horiz_retr_skew = ((data & 0x60) >> 5); |
| 176 | | crtc_ega->horiz_blank_end = ((data & 0x80) >> 2) | (crtc_ega->horiz_blank_end & 0x1f); |
| 94 | case 0x04: m_horiz_retr_start = data & 0xff; break; |
| 95 | case 0x05: m_horiz_retr_end = data & 0x1f; |
| 96 | m_horiz_retr_skew = ((data & 0x60) >> 5); |
| 97 | m_horiz_blank_end = ((data & 0x80) >> 2) | (m_horiz_blank_end & 0x1f); |
| 177 | 98 | break; |
| 178 | | case 0x06: crtc_ega->vert_total = ((data & 0xff) << 0) | (crtc_ega->vert_total & 0x0300); break; |
| 179 | | case 0x07: crtc_ega->vert_total = ((data & 0x01) << 8) | (crtc_ega->vert_total & 0x02ff); |
| 180 | | crtc_ega->vert_disp_end = ((data & 0x02) << 7) | (crtc_ega->vert_disp_end & 0x02ff); |
| 181 | | crtc_ega->vert_retr_start = ((data & 0x04) << 6) | (crtc_ega->vert_retr_start & 0x02ff); |
| 182 | | crtc_ega->vert_blank_start = ((data & 0x08) << 5) | (crtc_ega->vert_blank_start & 0x02ff); |
| 183 | | crtc_ega->line_compare = ((data & 0x10) << 4) | (crtc_ega->line_compare & 0x02ff); |
| 184 | | crtc_ega->vert_total = ((data & 0x20) << 4) | (crtc_ega->vert_total & 0x01ff); |
| 185 | | crtc_ega->vert_disp_end = ((data & 0x40) << 3) | (crtc_ega->vert_disp_end & 0x1ff); |
| 186 | | crtc_ega->vert_retr_start = ((data & 0x80) << 2) | (crtc_ega->vert_retr_start & 0x01ff); |
| 99 | case 0x06: m_vert_total = ((data & 0xff) << 0) | (m_vert_total & 0x0300); break; |
| 100 | case 0x07: m_vert_total = ((data & 0x01) << 8) | (m_vert_total & 0x02ff); |
| 101 | m_vert_disp_end = ((data & 0x02) << 7) | (m_vert_disp_end & 0x02ff); |
| 102 | m_vert_retr_start = ((data & 0x04) << 6) | (m_vert_retr_start & 0x02ff); |
| 103 | m_vert_blank_start = ((data & 0x08) << 5) | (m_vert_blank_start & 0x02ff); |
| 104 | m_line_compare = ((data & 0x10) << 4) | (m_line_compare & 0x02ff); |
| 105 | m_vert_total = ((data & 0x20) << 4) | (m_vert_total & 0x01ff); |
| 106 | m_vert_disp_end = ((data & 0x40) << 3) | (m_vert_disp_end & 0x1ff); |
| 107 | m_vert_retr_start = ((data & 0x80) << 2) | (m_vert_retr_start & 0x01ff); |
| 187 | 108 | break; |
| 188 | | case 0x08: crtc_ega->preset_row_scan = data & 0x1f; |
| 189 | | crtc_ega->byte_panning = ((data & 0x60) >> 5); |
| 109 | case 0x08: m_preset_row_scan = data & 0x1f; |
| 110 | m_byte_panning = ((data & 0x60) >> 5); |
| 190 | 111 | break; |
| 191 | | case 0x09: crtc_ega->max_ras_addr = data & 0x1f; |
| 192 | | crtc_ega->vert_blank_start = ((data & 0x20) << 4) | (crtc_ega->vert_blank_start & 0x01ff); |
| 193 | | crtc_ega->line_compare = ((data & 0x40) << 3) | (crtc_ega->line_compare & 0x01ff); |
| 194 | | crtc_ega->scan_doubling = data & 0x80; |
| 112 | case 0x09: m_max_ras_addr = data & 0x1f; |
| 113 | m_vert_blank_start = ((data & 0x20) << 4) | (m_vert_blank_start & 0x01ff); |
| 114 | m_line_compare = ((data & 0x40) << 3) | (m_line_compare & 0x01ff); |
| 115 | m_scan_doubling = data & 0x80; |
| 195 | 116 | break; |
| 196 | | case 0x0a: crtc_ega->cursor_start_ras = data & 0x1f; |
| 197 | | crtc_ega->cursor_disable = data & 0x20; |
| 117 | case 0x0a: m_cursor_start_ras = data & 0x1f; |
| 118 | m_cursor_disable = data & 0x20; |
| 198 | 119 | break; |
| 199 | | case 0x0b: crtc_ega->cursor_end_ras = data & 0x1f; |
| 200 | | crtc_ega->cursor_skew = ((data & 0x60) >> 5); |
| 120 | case 0x0b: m_cursor_end_ras = data & 0x1f; |
| 121 | m_cursor_skew = ((data & 0x60) >> 5); |
| 201 | 122 | break; |
| 202 | | case 0x0c: crtc_ega->disp_start_addr = ((data & 0xff) << 8) | (crtc_ega->disp_start_addr & 0x00ff); break; |
| 203 | | case 0x0d: crtc_ega->disp_start_addr = ((data & 0xff) << 0) | (crtc_ega->disp_start_addr & 0xff00); break; |
| 204 | | case 0x0e: crtc_ega->cursor_addr = ((data & 0xff) << 8) | (crtc_ega->cursor_addr & 0x00ff); break; |
| 205 | | case 0x0f: crtc_ega->cursor_addr = ((data & 0xff) << 0) | (crtc_ega->cursor_addr & 0xff00); break; |
| 206 | | case 0x10: crtc_ega->vert_retr_start = ((data & 0xff) << 0) | (crtc_ega->vert_retr_start & 0x03ff); break; |
| 207 | | case 0x11: crtc_ega->vert_retr_end = data & 0x0f; |
| 208 | | crtc_ega->bandwidth = data & 0x40; |
| 209 | | crtc_ega->protect = data & 0x80; |
| 123 | case 0x0c: m_disp_start_addr = ((data & 0xff) << 8) | (m_disp_start_addr & 0x00ff); break; |
| 124 | case 0x0d: m_disp_start_addr = ((data & 0xff) << 0) | (m_disp_start_addr & 0xff00); break; |
| 125 | case 0x0e: m_cursor_addr = ((data & 0xff) << 8) | (m_cursor_addr & 0x00ff); break; |
| 126 | case 0x0f: m_cursor_addr = ((data & 0xff) << 0) | (m_cursor_addr & 0xff00); break; |
| 127 | case 0x10: m_vert_retr_start = ((data & 0xff) << 0) | (m_vert_retr_start & 0x0300); break; |
| 128 | case 0x11: m_vert_retr_end = data & 0x0f; |
| 129 | m_bandwidth = data & 0x40; |
| 130 | m_protect = data & 0x80; |
| 210 | 131 | break; |
| 211 | | case 0x12: crtc_ega->vert_disp_end = ((data & 0xff) << 0) | (crtc_ega->vert_disp_end & 0x0300); break; |
| 212 | | case 0x13: crtc_ega->offset = data & 0xff; break; |
| 213 | | case 0x14: crtc_ega->underline_loc = data & 0x7f; break; |
| 214 | | case 0x15: crtc_ega->vert_blank_start = ((data & 0xff) << 0) | (crtc_ega->vert_blank_start & 0x0300); break; |
| 215 | | case 0x16: crtc_ega->vert_blank_end = data & 0x7f; break; |
| 216 | | case 0x17: crtc_ega->mode_control = data & 0xff; break; |
| 217 | | case 0x18: crtc_ega->line_compare = ((data & 0xff) << 0) | (crtc_ega->line_compare & 0x0300); break; |
| 132 | case 0x12: m_vert_disp_end = ((data & 0xff) << 0) | (m_vert_disp_end & 0x0300); break; |
| 133 | case 0x13: m_offset = data & 0xff; break; |
| 134 | case 0x14: m_underline_loc = data & 0x7f; break; |
| 135 | case 0x15: m_vert_blank_start = ((data & 0xff) << 0) | (m_vert_blank_start & 0x0300); break; |
| 136 | case 0x16: m_vert_blank_end = data & 0x7f; break; |
| 137 | case 0x17: m_mode_control = data & 0xff; break; |
| 138 | case 0x18: m_line_compare = ((data & 0xff) << 0) | (m_line_compare & 0x0300); break; |
| 218 | 139 | default: break; |
| 219 | 140 | } |
| 220 | 141 | |
| 221 | | // /* display message if the Mode Control register is not zero */ |
| 222 | | // if ((crtc_ega->register_address_latch == 0x08) && (crtc_ega->mode_control != 0)) |
| 223 | | // popmessage("Mode Control %02X is not supported!!!", crtc_ega->mode_control); |
| 224 | | |
| 225 | | recompute_parameters(crtc_ega, FALSE); |
| 142 | recompute_parameters(false); |
| 226 | 143 | } |
| 227 | 144 | |
| 228 | 145 | |
| 229 | | static void recompute_parameters(crtc_ega_t *crtc_ega, int postload) |
| 146 | void crtc_ega_device::recompute_parameters(bool postload) |
| 230 | 147 | { |
| 231 | | if (crtc_ega->intf != NULL) |
| 232 | | { |
| 233 | | UINT16 hsync_on_pos, hsync_off_pos, vsync_on_pos, vsync_off_pos; |
| 148 | UINT16 hsync_on_pos, hsync_off_pos, vsync_on_pos, vsync_off_pos; |
| 234 | 149 | |
| 235 | | /* compute the screen sizes */ |
| 236 | | UINT16 horiz_pix_total = (crtc_ega->horiz_char_total + 5) * crtc_ega->hpixels_per_column; |
| 237 | | UINT16 vert_pix_total = crtc_ega->vert_total + 1; |
| 150 | /* compute the screen sizes */ |
| 151 | UINT16 horiz_pix_total = (m_horiz_char_total + 2) * m_hpixels_per_column; |
| 152 | UINT16 vert_pix_total = m_vert_total + 1; |
| 238 | 153 | |
| 239 | | /* determine the visible area, avoid division by 0 */ |
| 240 | | UINT16 max_visible_x = ( crtc_ega->horiz_disp + 1 ) * crtc_ega->hpixels_per_column - 1; |
| 241 | | UINT16 max_visible_y = crtc_ega->vert_disp_end; |
| 154 | /* determine the visible area, avoid division by 0 */ |
| 155 | UINT16 max_visible_x = ( m_horiz_disp + 1 ) * m_hpixels_per_column - 1; |
| 156 | UINT16 max_visible_y = m_vert_disp_end; |
| 242 | 157 | |
| 243 | | /* determine the syncing positions */ |
| 244 | | int horiz_sync_char_width = ( crtc_ega->horiz_retr_end + 1 ) - ( crtc_ega->horiz_retr_start & 0x1f ); |
| 245 | | int vert_sync_pix_width = crtc_ega->vert_retr_end - ( crtc_ega->vert_retr_start & 0x0f ); |
| 158 | /* determine the syncing positions */ |
| 159 | int horiz_sync_char_width = ( m_horiz_retr_end + 1 ) - ( m_horiz_retr_start & 0x1f ); |
| 160 | int vert_sync_pix_width = m_vert_retr_end - ( m_vert_retr_start & 0x0f ); |
| 246 | 161 | |
| 247 | | if (horiz_sync_char_width <= 0) |
| 248 | | horiz_sync_char_width += 0x10; |
| 162 | if (horiz_sync_char_width <= 0) |
| 163 | horiz_sync_char_width += 0x10; |
| 249 | 164 | |
| 250 | | if (vert_sync_pix_width <= 0) |
| 251 | | vert_sync_pix_width += 0x10; |
| 165 | if (vert_sync_pix_width <= 0) |
| 166 | vert_sync_pix_width += 0x10; |
| 252 | 167 | |
| 253 | | hsync_on_pos = crtc_ega->horiz_retr_start * crtc_ega->hpixels_per_column; |
| 254 | | hsync_off_pos = hsync_on_pos + (horiz_sync_char_width * crtc_ega->hpixels_per_column); |
| 255 | | vsync_on_pos = crtc_ega->vert_retr_start; /* + 1 ?? */ |
| 256 | | vsync_off_pos = vsync_on_pos + vert_sync_pix_width; |
| 168 | hsync_on_pos = m_horiz_retr_start * m_hpixels_per_column; |
| 169 | hsync_off_pos = hsync_on_pos + (horiz_sync_char_width * m_hpixels_per_column); |
| 170 | vsync_on_pos = m_vert_retr_start; /* + 1 ?? */ |
| 171 | vsync_off_pos = vsync_on_pos + vert_sync_pix_width; |
| 257 | 172 | |
| 258 | | if (hsync_off_pos > horiz_pix_total) |
| 259 | | hsync_off_pos = horiz_pix_total; |
| 173 | if (hsync_off_pos > horiz_pix_total) |
| 174 | hsync_off_pos = horiz_pix_total; |
| 260 | 175 | |
| 261 | | if (vsync_off_pos > vert_pix_total) |
| 262 | | vsync_off_pos = vert_pix_total; |
| 176 | if (vsync_off_pos > vert_pix_total) |
| 177 | vsync_off_pos = vert_pix_total; |
| 263 | 178 | |
| 264 | | if ( vsync_on_pos >= vsync_off_pos ) |
| 265 | | { |
| 266 | | vsync_on_pos = vsync_off_pos - 2; |
| 267 | | } |
| 179 | if ( vsync_on_pos >= vsync_off_pos ) |
| 180 | { |
| 181 | vsync_on_pos = vsync_off_pos - 2; |
| 182 | } |
| 268 | 183 | |
| 269 | | /* update only if screen parameters changed, unless we are coming here after loading the saved state */ |
| 270 | | if (postload || |
| 271 | | (horiz_pix_total != crtc_ega->horiz_pix_total) || (vert_pix_total != crtc_ega->vert_pix_total) || |
| 272 | | (max_visible_x != crtc_ega->max_visible_x) || (max_visible_y != crtc_ega->max_visible_y) || |
| 273 | | (hsync_on_pos != crtc_ega->hsync_on_pos) || (vsync_on_pos != crtc_ega->vsync_on_pos) || |
| 274 | | (hsync_off_pos != crtc_ega->hsync_off_pos) || (vsync_off_pos != crtc_ega->vsync_off_pos)) |
| 184 | /* update only if screen parameters changed, unless we are coming here after loading the saved state */ |
| 185 | if (postload || |
| 186 | (horiz_pix_total != m_horiz_pix_total) || (vert_pix_total != m_vert_pix_total) || |
| 187 | (max_visible_x != m_max_visible_x) || (max_visible_y != m_max_visible_y) || |
| 188 | (hsync_on_pos != m_hsync_on_pos) || (vsync_on_pos != m_vsync_on_pos) || |
| 189 | (hsync_off_pos != m_hsync_off_pos) || (vsync_off_pos != m_vsync_off_pos)) |
| 190 | { |
| 191 | /* update the screen if we have valid data */ |
| 192 | if ((horiz_pix_total > 0) && (max_visible_x < horiz_pix_total) && |
| 193 | (vert_pix_total > 0) && (max_visible_y < vert_pix_total) && |
| 194 | (hsync_on_pos <= horiz_pix_total) && (vsync_on_pos <= vert_pix_total) && |
| 195 | (hsync_on_pos != hsync_off_pos)) |
| 275 | 196 | { |
| 276 | | /* update the screen if we have valid data */ |
| 277 | | if ((horiz_pix_total > 0) && (max_visible_x < horiz_pix_total) && |
| 278 | | (vert_pix_total > 0) && (max_visible_y < vert_pix_total) && |
| 279 | | (hsync_on_pos <= horiz_pix_total) && (vsync_on_pos <= vert_pix_total) && |
| 280 | | (hsync_on_pos != hsync_off_pos)) |
| 281 | | { |
| 282 | | attoseconds_t refresh = HZ_TO_ATTOSECONDS(crtc_ega->clock) * (crtc_ega->horiz_char_total + 1) * vert_pix_total; |
| 197 | attoseconds_t refresh = HZ_TO_ATTOSECONDS(m_clock) * (m_horiz_char_total + 2) * vert_pix_total; |
| 283 | 198 | |
| 284 | | rectangle visarea(0, max_visible_x, 0, max_visible_y); |
| 199 | rectangle visarea(0, max_visible_x, 0, max_visible_y); |
| 285 | 200 | |
| 286 | | if (LOG) logerror("CRTC_EGA config screen: HTOTAL: 0x%x VTOTAL: 0x%x MAX_X: 0x%x MAX_Y: 0x%x HSYNC: 0x%x-0x%x VSYNC: 0x%x-0x%x Freq: %ffps\n", |
| 287 | | horiz_pix_total, vert_pix_total, max_visible_x, max_visible_y, hsync_on_pos, hsync_off_pos - 1, vsync_on_pos, vsync_off_pos - 1, 1 / ATTOSECONDS_TO_DOUBLE(refresh)); |
| 201 | if (LOG) logerror("CRTC_EGA config screen: HTOTAL: 0x%x VTOTAL: 0x%x MAX_X: 0x%x MAX_Y: 0x%x HSYNC: 0x%x-0x%x VSYNC: 0x%x-0x%x Freq: %ffps\n", |
| 202 | horiz_pix_total, vert_pix_total, max_visible_x, max_visible_y, hsync_on_pos, hsync_off_pos - 1, vsync_on_pos, vsync_off_pos - 1, 1 / ATTOSECONDS_TO_DOUBLE(refresh)); |
| 288 | 203 | |
| 289 | | crtc_ega->screen->configure(horiz_pix_total, vert_pix_total, visarea, refresh); |
| 204 | if ( m_screen != NULL ) |
| 205 | m_screen->configure(horiz_pix_total, vert_pix_total, visarea, refresh); |
| 290 | 206 | |
| 291 | | crtc_ega->has_valid_parameters = TRUE; |
| 292 | | } |
| 293 | | else |
| 294 | | { |
| 295 | | crtc_ega->has_valid_parameters = FALSE; |
| 296 | | if (LOG) logerror("CRTC_EGA bad config screen: HTOTAL: 0x%x VTOTAL: 0x%x MAX_X: 0x%x MAX_Y: 0x%x HSYNC: 0x%x-0x%x VSYNC: 0x%x-0x%x\n", |
| 297 | | horiz_pix_total, vert_pix_total, max_visible_x, max_visible_y, hsync_on_pos, hsync_off_pos - 1, vsync_on_pos, vsync_off_pos - 1); |
| 207 | m_has_valid_parameters = true; |
| 208 | } |
| 209 | else |
| 210 | { |
| 211 | m_has_valid_parameters = false; |
| 212 | if (LOG) logerror("CRTC_EGA bad config screen: HTOTAL: 0x%x VTOTAL: 0x%x MAX_X: 0x%x MAX_Y: 0x%x HSYNC: 0x%x-0x%x VSYNC: 0x%x-0x%x\n", |
| 213 | horiz_pix_total, vert_pix_total, max_visible_x, max_visible_y, hsync_on_pos, hsync_off_pos - 1, vsync_on_pos, vsync_off_pos - 1); |
| 298 | 214 | |
| 299 | | } |
| 300 | | |
| 301 | | crtc_ega->horiz_pix_total = horiz_pix_total; |
| 302 | | crtc_ega->vert_pix_total = vert_pix_total; |
| 303 | | crtc_ega->max_visible_x = max_visible_x; |
| 304 | | crtc_ega->max_visible_y = max_visible_y; |
| 305 | | crtc_ega->hsync_on_pos = hsync_on_pos; |
| 306 | | crtc_ega->hsync_off_pos = hsync_off_pos; |
| 307 | | crtc_ega->vsync_on_pos = vsync_on_pos; |
| 308 | | crtc_ega->vsync_off_pos = vsync_off_pos; |
| 309 | | |
| 310 | | update_de_changed_timer(crtc_ega); |
| 311 | | update_hsync_changed_timers(crtc_ega); |
| 312 | | update_vsync_changed_timers(crtc_ega); |
| 313 | | update_vblank_changed_timers(crtc_ega); |
| 314 | 215 | } |
| 216 | |
| 217 | m_horiz_pix_total = horiz_pix_total; |
| 218 | m_vert_pix_total = vert_pix_total; |
| 219 | m_max_visible_x = max_visible_x; |
| 220 | m_max_visible_y = max_visible_y; |
| 221 | m_hsync_on_pos = hsync_on_pos; |
| 222 | m_hsync_off_pos = hsync_off_pos; |
| 223 | m_vsync_on_pos = vsync_on_pos; |
| 224 | m_vsync_off_pos = vsync_off_pos; |
| 315 | 225 | } |
| 316 | 226 | } |
| 317 | 227 | |
| 318 | 228 | |
| 319 | | INLINE int is_display_enabled(crtc_ega_t *crtc_ega) |
| 229 | void crtc_ega_device::update_counters() |
| 320 | 230 | { |
| 321 | | return !crtc_ega->screen->vblank() && !crtc_ega->screen->hblank(); |
| 322 | | } |
| 231 | m_character_counter = m_line_timer->elapsed().as_ticks( m_clock ); |
| 323 | 232 | |
| 324 | | |
| 325 | | static void update_de_changed_timer(crtc_ega_t *crtc_ega) |
| 326 | | { |
| 327 | | if (crtc_ega->has_valid_parameters && (crtc_ega->de_changed_timer != NULL)) |
| 233 | if ( m_hsync_off_timer->enabled() ) |
| 328 | 234 | { |
| 329 | | INT16 next_y; |
| 330 | | UINT16 next_x; |
| 331 | | attotime duration; |
| 332 | | |
| 333 | | /* we are in a display region, get the location of the next blanking start */ |
| 334 | | if (is_display_enabled(crtc_ega)) |
| 335 | | { |
| 336 | | /* normally, it's at end the current raster line */ |
| 337 | | next_y = crtc_ega->screen->vpos(); |
| 338 | | next_x = crtc_ega->max_visible_x + 1; |
| 339 | | |
| 340 | | /* but if visible width = horiz_pix_total, then we need |
| 341 | | to go to the beginning of VBLANK */ |
| 342 | | if (next_x == crtc_ega->horiz_pix_total) |
| 343 | | { |
| 344 | | next_y = crtc_ega->max_visible_y + 1; |
| 345 | | next_x = 0; |
| 346 | | |
| 347 | | /* abnormal case, no vertical blanking, either */ |
| 348 | | if (next_y == crtc_ega->vert_pix_total) |
| 349 | | next_y = -1; |
| 350 | | } |
| 351 | | } |
| 352 | | |
| 353 | | /* we are in a blanking region, get the location of the next display start */ |
| 354 | | else |
| 355 | | { |
| 356 | | next_x = 0; |
| 357 | | next_y = (crtc_ega->screen->vpos() + 1) % crtc_ega->vert_pix_total; |
| 358 | | |
| 359 | | /* if we would now fall in the vertical blanking, we need |
| 360 | | to go to the top of the screen */ |
| 361 | | if (next_y > crtc_ega->max_visible_y) |
| 362 | | next_y = 0; |
| 363 | | } |
| 364 | | |
| 365 | | if (next_y != -1) |
| 366 | | duration = crtc_ega->screen->time_until_pos(next_y, next_x); |
| 367 | | else |
| 368 | | duration = attotime::never; |
| 369 | | |
| 370 | | crtc_ega->de_changed_timer->adjust(duration); |
| 235 | m_hsync_width_counter = m_hsync_off_timer->elapsed().as_ticks( m_clock ); |
| 371 | 236 | } |
| 372 | 237 | } |
| 373 | 238 | |
| 374 | 239 | |
| 375 | | static void update_hsync_changed_timers(crtc_ega_t *crtc_ega) |
| 240 | void crtc_ega_device::set_de(int state) |
| 376 | 241 | { |
| 377 | | if (crtc_ega->has_valid_parameters && (crtc_ega->hsync_on_timer != NULL)) |
| 242 | if ( m_de != state ) |
| 378 | 243 | { |
| 379 | | UINT16 next_y; |
| 244 | m_de = state; |
| 380 | 245 | |
| 381 | | /* we are before the HSYNC position, we trigger on the current line */ |
| 382 | | if (crtc_ega->screen->hpos() < crtc_ega->hsync_on_pos) |
| 383 | | next_y = crtc_ega->screen->vpos(); |
| 384 | | |
| 385 | | /* trigger on the next line */ |
| 386 | | else |
| 387 | | next_y = (crtc_ega->screen->vpos() + 1) % crtc_ega->vert_pix_total; |
| 388 | | |
| 389 | | /* if the next line is not in the visible region, go to the beginning of the screen */ |
| 390 | | if (next_y > crtc_ega->max_visible_y) |
| 391 | | next_y = 0; |
| 392 | | |
| 393 | | crtc_ega->hsync_on_timer->adjust(crtc_ega->screen->time_until_pos(next_y, crtc_ega->hsync_on_pos) ); |
| 394 | | crtc_ega->hsync_off_timer->adjust(crtc_ega->screen->time_until_pos(next_y, crtc_ega->hsync_off_pos)); |
| 246 | if ( !m_res_out_de_func.isnull() ) |
| 247 | m_res_out_de_func( m_de ); |
| 395 | 248 | } |
| 396 | 249 | } |
| 397 | 250 | |
| 398 | 251 | |
| 399 | | static void update_vsync_changed_timers(crtc_ega_t *crtc_ega) |
| 252 | void crtc_ega_device::set_hsync(int state) |
| 400 | 253 | { |
| 401 | | if (crtc_ega->has_valid_parameters && (crtc_ega->vsync_on_timer != NULL)) |
| 254 | if ( m_hsync != state ) |
| 402 | 255 | { |
| 403 | | crtc_ega->vsync_on_timer->adjust(crtc_ega->screen->time_until_pos(crtc_ega->vsync_on_pos, 0)); |
| 404 | | crtc_ega->vsync_off_timer->adjust(crtc_ega->screen->time_until_pos(crtc_ega->vsync_off_pos, 0)); |
| 256 | m_hsync = state; |
| 257 | |
| 258 | if ( !m_res_out_hsync_func.isnull() ) |
| 259 | m_res_out_hsync_func( m_hsync ); |
| 405 | 260 | } |
| 406 | 261 | } |
| 407 | 262 | |
| 408 | 263 | |
| 409 | | static void update_vblank_changed_timers(crtc_ega_t *crtc_ega) |
| 264 | void crtc_ega_device::set_vsync(int state) |
| 410 | 265 | { |
| 411 | | if (crtc_ega->has_valid_parameters && (crtc_ega->vblank_on_timer != NULL)) |
| 266 | if ( m_vsync != state ) |
| 412 | 267 | { |
| 413 | | crtc_ega->vblank_on_timer->adjust(crtc_ega->screen->time_until_pos(crtc_ega->vert_disp_end, crtc_ega->hsync_off_pos)); |
| 414 | | crtc_ega->vblank_off_timer->adjust(crtc_ega->screen->time_until_pos(0, crtc_ega->hsync_on_pos)); |
| 268 | m_vsync = state; |
| 269 | |
| 270 | if ( !m_res_out_vsync_func.isnull() ) |
| 271 | m_res_out_vsync_func( m_vsync ); |
| 415 | 272 | } |
| 416 | 273 | } |
| 417 | 274 | |
| 418 | 275 | |
| 419 | | static TIMER_CALLBACK( de_changed_timer_cb ) |
| 276 | void crtc_ega_device::set_vblank(int state) |
| 420 | 277 | { |
| 421 | | device_t *device = (device_t *)ptr; |
| 422 | | crtc_ega_t *crtc_ega = get_safe_token(device); |
| 278 | if ( m_vblank != state ) |
| 279 | { |
| 280 | m_vblank = state; |
| 423 | 281 | |
| 424 | | /* call the callback function -- we know it exists */ |
| 425 | | crtc_ega->intf->on_de_changed(device, is_display_enabled(crtc_ega)); |
| 426 | | |
| 427 | | update_de_changed_timer(crtc_ega); |
| 282 | if ( !m_res_out_vblank_func.isnull() ) |
| 283 | m_res_out_vblank_func( m_vblank ); |
| 284 | } |
| 428 | 285 | } |
| 429 | 286 | |
| 430 | 287 | |
| 431 | | static TIMER_CALLBACK( vsync_on_timer_cb ) |
| 288 | void crtc_ega_device::set_cur(int state) |
| 432 | 289 | { |
| 433 | | device_t *device = (device_t *)ptr; |
| 434 | | crtc_ega_t *crtc_ega = get_safe_token(device); |
| 290 | if ( m_cur != state ) |
| 291 | { |
| 292 | m_cur = state; |
| 435 | 293 | |
| 436 | | /* call the callback function -- we know it exists */ |
| 437 | | crtc_ega->intf->on_vsync_changed(device, TRUE); |
| 294 | // if ( !m_res_out_cur_func.isnull() ) |
| 295 | // m_res_out_cur_func( m_cur ); |
| 296 | } |
| 438 | 297 | } |
| 439 | 298 | |
| 440 | 299 | |
| 441 | | static TIMER_CALLBACK( vsync_off_timer_cb ) |
| 300 | void crtc_ega_device::handle_line_timer() |
| 442 | 301 | { |
| 443 | | device_t *device = (device_t *)ptr; |
| 444 | | crtc_ega_t *crtc_ega = get_safe_token(device); |
| 302 | int new_vsync = m_vsync; |
| 445 | 303 | |
| 446 | | /* call the callback function -- we know it exists */ |
| 447 | | crtc_ega->intf->on_vsync_changed(device, FALSE); |
| 304 | m_character_counter = 0; |
| 305 | m_cursor_x = -1; |
| 448 | 306 | |
| 449 | | update_vsync_changed_timers(crtc_ega); |
| 450 | | } |
| 307 | /* Check if VSYNC is active */ |
| 308 | if ( m_vsync_ff ) |
| 309 | { |
| 310 | m_vsync_width_counter = ( m_vsync_width_counter + 1 ) & 0x0F; |
| 451 | 311 | |
| 312 | /* Check if we've reached end of VSYNC */ |
| 313 | if ( m_vsync_width_counter == m_vert_retr_end ) |
| 314 | { |
| 315 | m_vsync_ff = 0; |
| 452 | 316 | |
| 453 | | static TIMER_CALLBACK( hsync_on_timer_cb ) |
| 454 | | { |
| 455 | | device_t *device = (device_t *)ptr; |
| 456 | | crtc_ega_t *crtc_ega = get_safe_token(device); |
| 317 | new_vsync = FALSE; |
| 318 | } |
| 319 | } |
| 457 | 320 | |
| 458 | | /* call the callback function -- we know it exists */ |
| 459 | | crtc_ega->intf->on_hsync_changed(device, TRUE); |
| 460 | | } |
| 321 | if ( m_raster_counter == m_max_ras_addr ) |
| 322 | { |
| 323 | m_raster_counter = 0; |
| 324 | m_line_address = ( m_line_address + m_horiz_disp + 1 ) & 0xffff; |
| 325 | } |
| 326 | else |
| 327 | { |
| 328 | m_raster_counter = ( m_raster_counter + 1 ) & 0x1F; |
| 329 | } |
| 461 | 330 | |
| 331 | m_line_counter = ( m_line_counter + 1 ) & 0x3ff; |
| 462 | 332 | |
| 463 | | static TIMER_CALLBACK( hsync_off_timer_cb ) |
| 464 | | { |
| 465 | | device_t *device = (device_t *)ptr; |
| 466 | | crtc_ega_t *crtc_ega = get_safe_token(device); |
| 333 | /* Check if we've reached the end of active display */ |
| 334 | if ( m_line_counter == m_vert_disp_end ) |
| 335 | { |
| 336 | m_line_enable_ff = false; |
| 337 | } |
| 467 | 338 | |
| 468 | | /* call the callback function -- we know it exists */ |
| 469 | | crtc_ega->intf->on_hsync_changed(device, FALSE); |
| 339 | /* Check if VSYNC should be enabled */ |
| 340 | if ( m_line_counter == m_vert_retr_start ) |
| 341 | { |
| 342 | m_vsync_width_counter = 0; |
| 343 | m_vsync_ff = 1; |
| 470 | 344 | |
| 471 | | update_hsync_changed_timers(crtc_ega); |
| 472 | | } |
| 345 | new_vsync = TRUE; |
| 346 | } |
| 473 | 347 | |
| 348 | /* Check if we have reached the end of the vertical area */ |
| 349 | if ( m_line_counter == m_vert_total ) |
| 350 | { |
| 351 | m_line_counter = 0; |
| 352 | m_line_address = m_disp_start_addr; |
| 353 | m_line_enable_ff = true; |
| 354 | set_vblank( FALSE ); |
| 355 | /* also update the cursor state now */ |
| 356 | update_cursor_state(); |
| 474 | 357 | |
| 475 | | static TIMER_CALLBACK( vblank_on_timer_cb ) |
| 476 | | { |
| 477 | | device_t *device = (device_t *)ptr; |
| 478 | | crtc_ega_t *crtc_ega = get_safe_token(device); |
| 358 | if (m_screen != NULL) |
| 359 | m_screen->reset_origin(); |
| 360 | } |
| 479 | 361 | |
| 480 | | /* call the callback function -- we know it exists */ |
| 481 | | crtc_ega->intf->on_vblank_changed(device, TRUE); |
| 362 | if ( m_line_enable_ff ) |
| 363 | { |
| 364 | /* Schedule DE off signal change */ |
| 365 | m_de_off_timer->adjust(attotime::from_ticks( m_horiz_disp + 1, m_clock )); |
| 482 | 366 | |
| 483 | | update_vblank_changed_timers(crtc_ega); |
| 484 | | } |
| 367 | /* Is cursor visible on this line? */ |
| 368 | if ( m_cursor_state && |
| 369 | (m_raster_counter >= (m_cursor_start_ras & 0x1f)) && |
| 370 | (m_raster_counter <= m_cursor_end_ras) && |
| 371 | (m_cursor_addr >= m_line_address) && |
| 372 | (m_cursor_addr < (m_line_address + m_horiz_disp + 1)) ) |
| 373 | { |
| 374 | m_cursor_x = m_cursor_addr - m_line_address; |
| 485 | 375 | |
| 376 | /* Schedule CURSOR ON signal */ |
| 377 | m_cur_on_timer->adjust( attotime::from_ticks( m_cursor_x, m_clock ) ); |
| 378 | } |
| 379 | } |
| 486 | 380 | |
| 487 | | static TIMER_CALLBACK( vblank_off_timer_cb ) |
| 488 | | { |
| 489 | | device_t *device = (device_t *)ptr; |
| 490 | | crtc_ega_t *crtc_ega = get_safe_token(device); |
| 381 | /* Schedule HSYNC on signal */ |
| 382 | m_hsync_on_timer->adjust( attotime::from_ticks( m_horiz_blank_start, m_clock ) ); |
| 491 | 383 | |
| 492 | | /* call the callback function -- we know it exists */ |
| 493 | | crtc_ega->intf->on_vblank_changed(device, FALSE); |
| 384 | /* Set VBlank signal */ |
| 385 | if ( m_line_counter == m_vert_disp_end + 1 ) |
| 386 | { |
| 387 | set_vblank( TRUE ); |
| 388 | } |
| 494 | 389 | |
| 495 | | update_vblank_changed_timers(crtc_ega); |
| 390 | /* Schedule our next callback */ |
| 391 | m_line_timer->adjust( attotime::from_ticks( m_horiz_char_total + 2, m_clock ) ); |
| 392 | |
| 393 | /* Set VSYNC and DE signals */ |
| 394 | set_vsync( new_vsync ); |
| 395 | set_de( m_line_enable_ff ? TRUE : FALSE ); |
| 496 | 396 | } |
| 497 | 397 | |
| 498 | 398 | |
| 499 | | |
| 500 | | UINT16 crtc_ega_get_ma(device_t *device) |
| 399 | void crtc_ega_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 501 | 400 | { |
| 502 | | UINT16 ret; |
| 503 | | crtc_ega_t *crtc_ega = get_safe_token(device); |
| 504 | | |
| 505 | | if (crtc_ega->has_valid_parameters) |
| 401 | switch (id) |
| 506 | 402 | { |
| 507 | | /* clamp Y/X to the visible region */ |
| 508 | | int y = crtc_ega->screen->vpos(); |
| 509 | | int x = crtc_ega->screen->hpos(); |
| 403 | case TIMER_LINE: |
| 404 | handle_line_timer(); |
| 405 | break; |
| 510 | 406 | |
| 511 | | /* since the MA counter stops in the blanking regions, if we are in a |
| 512 | | VBLANK, both X and Y are at their max */ |
| 513 | | if ((y > crtc_ega->max_visible_y) || (x > crtc_ega->max_visible_x)) |
| 514 | | x = crtc_ega->max_visible_x; |
| 407 | case TIMER_DE_OFF: |
| 408 | set_de( FALSE ); |
| 409 | break; |
| 515 | 410 | |
| 516 | | if (y > crtc_ega->max_visible_y) |
| 517 | | y = crtc_ega->max_visible_y; |
| 411 | case TIMER_CUR_ON: |
| 412 | set_cur( TRUE ); |
| 518 | 413 | |
| 519 | | ret = (crtc_ega->disp_start_addr + |
| 520 | | (y / (crtc_ega->max_ras_addr + 1)) * ( crtc_ega->horiz_disp + 1 ) + |
| 521 | | (x / crtc_ega->hpixels_per_column)) & 0x3fff; |
| 522 | | } |
| 523 | | else |
| 524 | | ret = 0; |
| 414 | /* Schedule CURSOR off signal */ |
| 415 | m_cur_off_timer->adjust( attotime::from_ticks( 1, m_clock ) ); |
| 416 | break; |
| 525 | 417 | |
| 526 | | return ret; |
| 527 | | } |
| 418 | case TIMER_CUR_OFF: |
| 419 | set_cur( FALSE ); |
| 420 | break; |
| 528 | 421 | |
| 422 | case TIMER_HSYNC_ON: |
| 423 | { |
| 424 | INT8 hsync_width = ( 0x20 | m_horiz_blank_end ) - ( m_horiz_blank_start & 0x1f ); |
| 529 | 425 | |
| 530 | | UINT8 crtc_ega_get_ra(device_t *device) |
| 531 | | { |
| 532 | | UINT8 ret; |
| 533 | | crtc_ega_t *crtc_ega = get_safe_token(device); |
| 426 | if ( hsync_width <= 0 ) |
| 427 | { |
| 428 | hsync_width += 0x20; |
| 429 | } |
| 534 | 430 | |
| 535 | | if (crtc_ega->has_valid_parameters) |
| 536 | | { |
| 537 | | /* get the current vertical raster position and clamp it to the visible region */ |
| 538 | | int y = crtc_ega->screen->vpos(); |
| 431 | m_hsync_width_counter = 0; |
| 432 | set_hsync( TRUE ); |
| 539 | 433 | |
| 540 | | if (y > crtc_ega->max_visible_y) |
| 541 | | y = crtc_ega->max_visible_y; |
| 434 | /* Schedule HSYNC off signal */ |
| 435 | m_hsync_off_timer->adjust( attotime::from_ticks( hsync_width, m_clock ) ); |
| 436 | } |
| 437 | break; |
| 542 | 438 | |
| 543 | | ret = y % (crtc_ega->max_ras_addr + 1); |
| 544 | | } |
| 545 | | else |
| 546 | | ret = 0; |
| 439 | case TIMER_HSYNC_OFF: |
| 440 | set_hsync( FALSE ); |
| 441 | break; |
| 547 | 442 | |
| 548 | | return ret; |
| 443 | case TIMER_LIGHT_PEN_LATCH: |
| 444 | m_light_pen_addr = get_ma(); |
| 445 | m_light_pen_latched = true; |
| 446 | break; |
| 447 | } |
| 549 | 448 | } |
| 550 | 449 | |
| 551 | 450 | |
| 552 | | static TIMER_CALLBACK( light_pen_latch_timer_cb ) |
| 451 | UINT16 crtc_ega_device::get_ma() |
| 553 | 452 | { |
| 554 | | device_t *device = (device_t *)ptr; |
| 555 | | crtc_ega_t *crtc_ega = get_safe_token(device); |
| 453 | update_counters(); |
| 556 | 454 | |
| 557 | | crtc_ega->light_pen_addr = crtc_ega_get_ma(device); |
| 558 | | crtc_ega->light_pen_latched = TRUE; |
| 455 | return m_line_address + m_character_counter; |
| 559 | 456 | } |
| 560 | 457 | |
| 561 | 458 | |
| 562 | | void crtc_ega_assert_light_pen_input(device_t *device) |
| 459 | UINT8 crtc_ega_device::get_ra() |
| 563 | 460 | { |
| 564 | | int y, x; |
| 565 | | int char_x; |
| 461 | return m_raster_counter; |
| 462 | } |
| 566 | 463 | |
| 567 | | crtc_ega_t *crtc_ega = get_safe_token(device); |
| 568 | 464 | |
| 569 | | if (crtc_ega->has_valid_parameters) |
| 570 | | { |
| 571 | | /* get the current pixel coordinates */ |
| 572 | | y = crtc_ega->screen->vpos(); |
| 573 | | x = crtc_ega->screen->hpos(); |
| 574 | | |
| 575 | | /* compute the pixel coordinate of the NEXT character -- this is when the light pen latches */ |
| 576 | | char_x = x / crtc_ega->hpixels_per_column; |
| 577 | | x = (char_x + 1) * crtc_ega->hpixels_per_column; |
| 578 | | |
| 579 | | /* adjust if we are passed the boundaries of the screen */ |
| 580 | | if (x == crtc_ega->horiz_pix_total) |
| 581 | | { |
| 582 | | y = y + 1; |
| 583 | | x = 0; |
| 584 | | |
| 585 | | if (y == crtc_ega->vert_pix_total) |
| 586 | | y = 0; |
| 587 | | } |
| 588 | | |
| 589 | | /* set the timer that will latch the display address into the light pen registers */ |
| 590 | | crtc_ega->light_pen_latch_timer->adjust(crtc_ega->screen->time_until_pos(y, x)); |
| 591 | | } |
| 465 | void crtc_ega_device::assert_light_pen_input() |
| 466 | { |
| 467 | /* compute the pixel coordinate of the NEXT character -- this is when the light pen latches */ |
| 468 | /* set the timer that will latch the display address into the light pen registers */ |
| 469 | m_light_pen_latch_timer->adjust(attotime::from_ticks( 1, m_clock )); |
| 592 | 470 | } |
| 593 | 471 | |
| 594 | 472 | |
| 595 | | void crtc_ega_set_clock(device_t *device, int clock) |
| 473 | void crtc_ega_device::set_clock(int clock) |
| 596 | 474 | { |
| 597 | | crtc_ega_t *crtc_ega = get_safe_token(device); |
| 598 | | |
| 599 | 475 | /* validate arguments */ |
| 600 | 476 | assert(clock > 0); |
| 601 | 477 | |
| 602 | | if (clock != crtc_ega->clock) |
| 478 | if (clock != m_clock) |
| 603 | 479 | { |
| 604 | | crtc_ega->clock = clock; |
| 605 | | recompute_parameters(crtc_ega, FALSE); |
| 480 | m_clock = clock; |
| 481 | recompute_parameters(true); |
| 606 | 482 | } |
| 607 | 483 | } |
| 608 | 484 | |
| 609 | 485 | |
| 610 | | void crtc_ega_set_hpixels_per_column(device_t *device, int hpixels_per_column) |
| 486 | void crtc_ega_device::set_hpixels_per_column(int hpixels_per_column) |
| 611 | 487 | { |
| 612 | | crtc_ega_t *crtc_ega = get_safe_token(device); |
| 613 | | |
| 614 | 488 | /* validate arguments */ |
| 615 | 489 | assert(hpixels_per_column > 0); |
| 616 | 490 | |
| 617 | | if (hpixels_per_column != crtc_ega->hpixels_per_column) |
| 491 | if (hpixels_per_column != m_hpixels_per_column) |
| 618 | 492 | { |
| 619 | | crtc_ega->hpixels_per_column = hpixels_per_column; |
| 620 | | recompute_parameters(crtc_ega, FALSE); |
| 493 | m_hpixels_per_column = hpixels_per_column; |
| 494 | recompute_parameters(true); |
| 621 | 495 | } |
| 622 | 496 | } |
| 623 | 497 | |
| 624 | 498 | |
| 625 | | static void update_cursor_state(crtc_ega_t *crtc_ega) |
| 499 | void crtc_ega_device::update_cursor_state() |
| 626 | 500 | { |
| 627 | 501 | /* save and increment cursor counter */ |
| 628 | | UINT8 last_cursor_blink_count = crtc_ega->cursor_blink_count; |
| 629 | | crtc_ega->cursor_blink_count = crtc_ega->cursor_blink_count + 1; |
| 502 | UINT8 last_cursor_blink_count = m_cursor_blink_count; |
| 503 | m_cursor_blink_count = m_cursor_blink_count + 1; |
| 630 | 504 | |
| 631 | 505 | /* switch on cursor blinking mode */ |
| 632 | | switch (crtc_ega->cursor_start_ras & 0x60) |
| 506 | switch (m_cursor_start_ras & 0x60) |
| 633 | 507 | { |
| 634 | 508 | /* always on */ |
| 635 | | case 0x00: crtc_ega->cursor_state = TRUE; break; |
| 509 | case 0x00: m_cursor_state = true; break; |
| 636 | 510 | |
| 637 | 511 | /* always off */ |
| 638 | | case 0x20: crtc_ega->cursor_state = FALSE; break; |
| 512 | case 0x20: m_cursor_state = false; break; |
| 639 | 513 | |
| 640 | 514 | /* fast blink */ |
| 641 | 515 | case 0x40: |
| 642 | | if ((last_cursor_blink_count & 0x10) != (crtc_ega->cursor_blink_count & 0x10)) |
| 516 | if ((last_cursor_blink_count & 0x10) != (m_cursor_blink_count & 0x10)) |
| 643 | 517 | { |
| 644 | | crtc_ega->cursor_state = !crtc_ega->cursor_state; |
| 518 | m_cursor_state = !m_cursor_state; |
| 645 | 519 | } |
| 646 | 520 | break; |
| 647 | 521 | |
| 648 | 522 | /* slow blink */ |
| 649 | 523 | case 0x60: |
| 650 | | if ((last_cursor_blink_count & 0x20) != (crtc_ega->cursor_blink_count & 0x20)) |
| 524 | if ((last_cursor_blink_count & 0x20) != (m_cursor_blink_count & 0x20)) |
| 651 | 525 | { |
| 652 | | crtc_ega->cursor_state = !crtc_ega->cursor_state; |
| 526 | m_cursor_state = !m_cursor_state; |
| 653 | 527 | } |
| 654 | 528 | break; |
| 655 | 529 | } |
| 656 | 530 | } |
| 657 | 531 | |
| 658 | 532 | |
| 659 | | void crtc_ega_update(device_t *device, bitmap_ind16 &bitmap, const rectangle &cliprect) |
| 533 | UINT32 crtc_ega_device::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) |
| 660 | 534 | { |
| 661 | | crtc_ega_t *crtc_ega = get_safe_token(device); |
| 662 | 535 | assert(bitmap.valid()); |
| 663 | 536 | |
| 664 | | if (crtc_ega->has_valid_parameters) |
| 537 | if (m_has_valid_parameters) |
| 665 | 538 | { |
| 666 | 539 | UINT16 y; |
| 667 | 540 | |
| 668 | 541 | void *param = NULL; |
| 669 | 542 | |
| 670 | | assert(crtc_ega->intf != NULL); |
| 671 | | assert(crtc_ega->intf->update_row != NULL); |
| 543 | assert(m_update_row != NULL); |
| 672 | 544 | |
| 673 | 545 | /* call the set up function if any */ |
| 674 | | if (crtc_ega->intf->begin_update != NULL) |
| 675 | | param = crtc_ega->intf->begin_update(device, bitmap, cliprect); |
| 546 | if (m_begin_update != NULL) |
| 547 | param = m_begin_update(this, bitmap, cliprect); |
| 676 | 548 | |
| 677 | 549 | if (cliprect.min_y == 0) |
| 678 | 550 | { |
| 679 | 551 | /* read the start address at the beginning of the frame */ |
| 680 | | crtc_ega->current_disp_addr = crtc_ega->disp_start_addr; |
| 681 | | |
| 682 | | /* also update the cursor state now */ |
| 683 | | update_cursor_state(crtc_ega); |
| 552 | m_current_disp_addr = m_disp_start_addr; |
| 684 | 553 | } |
| 685 | 554 | |
| 686 | 555 | /* for each row in the visible region */ |
| 687 | 556 | for (y = cliprect.min_y; y <= cliprect.max_y; y++) |
| 688 | 557 | { |
| 689 | 558 | /* compute the current raster line */ |
| 690 | | UINT8 ra = y % (crtc_ega->max_ras_addr + 1); |
| 559 | UINT8 ra = y % (m_max_ras_addr + 1); |
| 691 | 560 | |
| 692 | 561 | /* check if the cursor is visible and is on this scanline */ |
| 693 | | int cursor_visible = crtc_ega->cursor_state && |
| 694 | | (ra >= (crtc_ega->cursor_start_ras & 0x1f)) && |
| 695 | | ( (ra <= (crtc_ega->cursor_end_ras & 0x1f)) || ((crtc_ega->cursor_end_ras & 0x1f) == 0x00 )) && |
| 696 | | (crtc_ega->cursor_addr >= crtc_ega->current_disp_addr) && |
| 697 | | (crtc_ega->cursor_addr < (crtc_ega->current_disp_addr + ( crtc_ega->horiz_disp + 1 ))); |
| 562 | int cursor_visible = m_cursor_state && |
| 563 | (ra >= (m_cursor_start_ras & 0x1f)) && |
| 564 | ( (ra <= (m_cursor_end_ras & 0x1f)) || ((m_cursor_end_ras & 0x1f) == 0x00 )) && |
| 565 | (m_cursor_addr >= m_current_disp_addr) && |
| 566 | (m_cursor_addr < (m_current_disp_addr + ( m_horiz_disp + 1 ))); |
| 698 | 567 | |
| 699 | 568 | /* compute the cursor X position, or -1 if not visible */ |
| 700 | | INT8 cursor_x = cursor_visible ? (crtc_ega->cursor_addr - crtc_ega->current_disp_addr) : -1; |
| 569 | INT8 cursor_x = cursor_visible ? (m_cursor_addr - m_current_disp_addr) : -1; |
| 701 | 570 | |
| 702 | 571 | /* call the external system to draw it */ |
| 703 | | crtc_ega->intf->update_row(device, bitmap, cliprect, crtc_ega->current_disp_addr, ra, y, crtc_ega->horiz_disp + 1, cursor_x, param); |
| 572 | m_update_row(this, bitmap, cliprect, m_current_disp_addr, ra, y, m_horiz_disp + 1, cursor_x, param); |
| 704 | 573 | |
| 705 | 574 | /* update MA if the last raster address */ |
| 706 | | if (ra == crtc_ega->max_ras_addr) |
| 707 | | crtc_ega->current_disp_addr = (crtc_ega->current_disp_addr + crtc_ega->horiz_disp + 1) & 0xffff; |
| 575 | if (ra == m_max_ras_addr) |
| 576 | m_current_disp_addr = (m_current_disp_addr + m_horiz_disp + 1) & 0xffff; |
| 708 | 577 | } |
| 709 | 578 | |
| 710 | 579 | /* call the tear down function if any */ |
| 711 | | if (crtc_ega->intf->end_update != NULL) |
| 712 | | crtc_ega->intf->end_update(device, bitmap, cliprect, param); |
| 580 | if (m_end_update != NULL) |
| 581 | m_end_update(this, bitmap, cliprect, param); |
| 713 | 582 | } |
| 714 | 583 | else |
| 715 | 584 | logerror("Invalid crtc_ega screen parameters - display disabled!!!\n"); |
| 585 | |
| 586 | return 0; |
| 716 | 587 | } |
| 717 | 588 | |
| 718 | 589 | |
| 719 | 590 | /* device interface */ |
| 720 | | static void common_start(device_t *device, int device_type) |
| 591 | void crtc_ega_device::device_start() |
| 721 | 592 | { |
| 722 | | crtc_ega_t *crtc_ega = get_safe_token(device); |
| 723 | | |
| 724 | 593 | /* validate arguments */ |
| 725 | | assert(device != NULL); |
| 726 | | assert(device->tag() != NULL); |
| 727 | | assert(device->clock() > 0); |
| 594 | assert(m_clock > 0); |
| 595 | assert(m_hpixels_per_column > 0); |
| 728 | 596 | |
| 729 | | crtc_ega->intf = (const crtc_ega_interface*)device->static_config(); |
| 730 | | crtc_ega->device_type = device_type; |
| 597 | /* resolve callbacks */ |
| 598 | m_res_out_de_func.resolve(m_out_de_func, *this); |
| 599 | m_res_out_hsync_func.resolve(m_out_hsync_func, *this); |
| 600 | m_res_out_vsync_func.resolve(m_out_vsync_func, *this); |
| 601 | m_res_out_vblank_func.resolve(m_out_vblank_func, *this); |
| 731 | 602 | |
| 732 | | if (crtc_ega->intf != NULL) |
| 603 | /* get the screen device */ |
| 604 | if ( m_screen_tag != NULL ) |
| 733 | 605 | { |
| 734 | | assert(crtc_ega->intf->hpixels_per_column > 0); |
| 735 | | |
| 736 | | /* copy the initial parameters */ |
| 737 | | crtc_ega->clock = device->clock(); |
| 738 | | crtc_ega->hpixels_per_column = crtc_ega->intf->hpixels_per_column; |
| 739 | | |
| 740 | | /* get the screen device */ |
| 741 | 606 | astring tempstring; |
| 742 | | crtc_ega->screen = downcast<screen_device *>(device->machine().device(device->owner()->subtag(tempstring,crtc_ega->intf->screen_tag))); |
| 743 | | assert(crtc_ega->screen != NULL); |
| 744 | | |
| 745 | | /* create the timers */ |
| 746 | | if (crtc_ega->intf->on_de_changed != NULL) |
| 747 | | crtc_ega->de_changed_timer = device->machine().scheduler().timer_alloc(FUNC(de_changed_timer_cb), (void *)device); |
| 748 | | |
| 749 | | if (crtc_ega->intf->on_hsync_changed != NULL) |
| 750 | | { |
| 751 | | crtc_ega->hsync_on_timer = device->machine().scheduler().timer_alloc(FUNC(hsync_on_timer_cb), (void *)device); |
| 752 | | crtc_ega->hsync_off_timer = device->machine().scheduler().timer_alloc(FUNC(hsync_off_timer_cb), (void *)device); |
| 753 | | } |
| 754 | | |
| 755 | | if (crtc_ega->intf->on_vsync_changed != NULL) |
| 756 | | { |
| 757 | | crtc_ega->vsync_on_timer = device->machine().scheduler().timer_alloc(FUNC(vsync_on_timer_cb), (void *)device); |
| 758 | | crtc_ega->vsync_off_timer = device->machine().scheduler().timer_alloc(FUNC(vsync_off_timer_cb), (void *)device); |
| 759 | | } |
| 760 | | |
| 761 | | if (crtc_ega->intf->on_vblank_changed != NULL) |
| 762 | | { |
| 763 | | crtc_ega->vblank_on_timer = device->machine().scheduler().timer_alloc(FUNC(vblank_on_timer_cb), (void *)device); |
| 764 | | crtc_ega->vblank_off_timer = device->machine().scheduler().timer_alloc(FUNC(vblank_off_timer_cb), (void *)device); |
| 765 | | } |
| 607 | m_screen = downcast<screen_device *>(machine().device(siblingtag(tempstring,m_screen_tag))); |
| 608 | assert(m_screen != NULL); |
| 766 | 609 | } |
| 610 | else |
| 611 | m_screen = NULL; |
| 767 | 612 | |
| 768 | | crtc_ega->light_pen_latch_timer = device->machine().scheduler().timer_alloc(FUNC(light_pen_latch_timer_cb), (void *)device); |
| 613 | /* create the timers */ |
| 614 | m_line_timer = timer_alloc(TIMER_LINE); |
| 615 | m_de_off_timer = timer_alloc(TIMER_DE_OFF); |
| 616 | m_cur_on_timer = timer_alloc(TIMER_CUR_ON); |
| 617 | m_cur_off_timer = timer_alloc(TIMER_CUR_OFF); |
| 618 | m_hsync_on_timer = timer_alloc(TIMER_HSYNC_ON); |
| 619 | m_hsync_off_timer = timer_alloc(TIMER_HSYNC_OFF); |
| 620 | m_light_pen_latch_timer = timer_alloc(TIMER_LIGHT_PEN_LATCH); |
| 769 | 621 | |
| 770 | | /* register for state saving */ |
| 622 | /* Use some large startup values */ |
| 623 | m_horiz_char_total = 0xff; |
| 624 | m_max_ras_addr = 0x1f; |
| 625 | m_vert_total = 0x3ff; |
| 771 | 626 | |
| 772 | | device->machine().save().register_postload(save_prepost_delegate(FUNC(crtc_ega_state_save_postload), crtc_ega)); |
| 773 | | |
| 774 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->clock); |
| 775 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->hpixels_per_column); |
| 776 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->register_address_latch); |
| 777 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->horiz_char_total); |
| 778 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->horiz_disp); |
| 779 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->horiz_blank_start); |
| 780 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->mode_control); |
| 781 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->cursor_start_ras); |
| 782 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->cursor_end_ras); |
| 783 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->disp_start_addr); |
| 784 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->cursor_addr); |
| 785 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->light_pen_addr); |
| 786 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->light_pen_latched); |
| 787 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->cursor_state); |
| 788 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->cursor_blink_count); |
| 789 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->horiz_blank_end); |
| 790 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->ena_vert_access); |
| 791 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->de_skew); |
| 792 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->horiz_retr_start); |
| 793 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->horiz_retr_end); |
| 794 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->horiz_retr_skew); |
| 795 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->vert_total); |
| 796 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->preset_row_scan); |
| 797 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->byte_panning); |
| 798 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->max_ras_addr); |
| 799 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->scan_doubling); |
| 800 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->cursor_disable); |
| 801 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->cursor_skew); |
| 802 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->vert_retr_start); |
| 803 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->vert_retr_end); |
| 804 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->protect); |
| 805 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->bandwidth); |
| 806 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->vert_disp_end); |
| 807 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->offset); |
| 808 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->underline_loc); |
| 809 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->vert_blank_start); |
| 810 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->vert_blank_end); |
| 811 | | state_save_register_item(device->machine(), device->tag(), NULL, 0, crtc_ega->line_compare); |
| 627 | /* register for state saving */ |
| 628 | save_item(NAME(m_hpixels_per_column)); |
| 629 | save_item(NAME(m_register_address_latch)); |
| 630 | save_item(NAME(m_horiz_char_total)); |
| 631 | save_item(NAME(m_horiz_disp)); |
| 632 | save_item(NAME(m_horiz_blank_start)); |
| 633 | save_item(NAME(m_mode_control)); |
| 634 | save_item(NAME(m_cursor_start_ras)); |
| 635 | save_item(NAME(m_cursor_end_ras)); |
| 636 | save_item(NAME(m_disp_start_addr)); |
| 637 | save_item(NAME(m_cursor_addr)); |
| 638 | save_item(NAME(m_light_pen_addr)); |
| 639 | save_item(NAME(m_light_pen_latched)); |
| 640 | save_item(NAME(m_cursor_state)); |
| 641 | save_item(NAME(m_cursor_blink_count)); |
| 642 | save_item(NAME(m_horiz_blank_end)); |
| 643 | save_item(NAME(m_ena_vert_access)); |
| 644 | save_item(NAME(m_de_skew)); |
| 645 | save_item(NAME(m_horiz_retr_start)); |
| 646 | save_item(NAME(m_horiz_retr_end)); |
| 647 | save_item(NAME(m_horiz_retr_skew)); |
| 648 | save_item(NAME(m_vert_total)); |
| 649 | save_item(NAME(m_preset_row_scan)); |
| 650 | save_item(NAME(m_byte_panning)); |
| 651 | save_item(NAME(m_max_ras_addr)); |
| 652 | save_item(NAME(m_scan_doubling)); |
| 653 | save_item(NAME(m_cursor_disable)); |
| 654 | save_item(NAME(m_cursor_skew)); |
| 655 | save_item(NAME(m_vert_retr_start)); |
| 656 | save_item(NAME(m_vert_retr_end)); |
| 657 | save_item(NAME(m_protect)); |
| 658 | save_item(NAME(m_bandwidth)); |
| 659 | save_item(NAME(m_vert_disp_end)); |
| 660 | save_item(NAME(m_offset)); |
| 661 | save_item(NAME(m_underline_loc)); |
| 662 | save_item(NAME(m_vert_blank_start)); |
| 663 | save_item(NAME(m_vert_blank_end)); |
| 664 | save_item(NAME(m_line_compare)); |
| 812 | 665 | } |
| 813 | 666 | |
| 814 | 667 | |
| 815 | | static DEVICE_START( crtc_ega ) |
| 668 | void crtc_ega_device::device_reset() |
| 816 | 669 | { |
| 817 | | common_start(device, TYPE_CRTC_EGA); |
| 818 | | } |
| 819 | | |
| 820 | | |
| 821 | | static DEVICE_RESET( crtc_ega ) |
| 822 | | { |
| 823 | | crtc_ega_t *crtc_ega = get_safe_token(device); |
| 824 | | |
| 825 | 670 | /* internal registers other than status remain unchanged, all outputs go low */ |
| 826 | | if (crtc_ega->intf != NULL) |
| 827 | | { |
| 828 | | if (crtc_ega->intf->on_de_changed != NULL) |
| 829 | | crtc_ega->intf->on_de_changed(device, FALSE); |
| 671 | if ( !m_res_out_de_func.isnull() ) |
| 672 | m_res_out_de_func( FALSE ); |
| 830 | 673 | |
| 831 | | if (crtc_ega->intf->on_hsync_changed != NULL) |
| 832 | | crtc_ega->intf->on_hsync_changed(device, FALSE); |
| 674 | if ( !m_res_out_hsync_func.isnull() ) |
| 675 | m_res_out_hsync_func( FALSE ); |
| 833 | 676 | |
| 834 | | if (crtc_ega->intf->on_vsync_changed != NULL) |
| 835 | | crtc_ega->intf->on_vsync_changed(device, FALSE); |
| 836 | | } |
| 677 | if ( !m_res_out_vsync_func.isnull() ) |
| 678 | m_res_out_vsync_func( FALSE ); |
| 837 | 679 | |
| 838 | | crtc_ega->light_pen_latched = FALSE; |
| 839 | | } |
| 680 | if ( !m_res_out_vblank_func.isnull() ) |
| 681 | m_res_out_vblank_func( FALSE ); |
| 840 | 682 | |
| 841 | | |
| 842 | | DEVICE_GET_INFO( crtc_ega ) |
| 843 | | { |
| 844 | | switch (state) |
| 683 | if ( ! m_line_timer->enabled( ) ) |
| 845 | 684 | { |
| 846 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 847 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(crtc_ega_t); break; |
| 848 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 685 | m_line_timer->adjust( attotime::from_ticks( m_horiz_char_total + 2, m_clock ) ); |
| 686 | } |
| 849 | 687 | |
| 850 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 851 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(crtc_ega); break; |
| 852 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 853 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(crtc_ega); break; |
| 688 | m_light_pen_latched = false; |
| 854 | 689 | |
| 855 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 856 | | case DEVINFO_STR_NAME: strcpy(info->s, "IBM EGA CRTC"); break; |
| 857 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "EGA CRTC"); break; |
| 858 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.00"); break; |
| 859 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 860 | | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright the MESS Team"); break; |
| 861 | | } |
| 690 | m_cursor_addr = 0; |
| 691 | m_line_address = 0; |
| 692 | m_horiz_disp = 0; |
| 693 | m_cursor_x = 0; |
| 862 | 694 | } |
| 863 | 695 | |
| 864 | | #if 0 |
| 865 | | DEVICE_GET_INFO( crtc_vga ) |
| 866 | | { |
| 867 | | switch (state) |
| 868 | | { |
| 869 | | default: DEVICE_GET_INFO_CALL( crtc_ega ); break; |
| 870 | | } |
| 871 | | } |
| 872 | | #endif |
| 873 | | |
| 874 | | DEFINE_LEGACY_DEVICE(CRTC_EGA, crtc_ega); |
src/mess/video/crtc_ega.h
| r15502 | r15503 | |
| 7 | 7 | #ifndef __CRTC_EGA__ |
| 8 | 8 | #define __CRTC_EGA__ |
| 9 | 9 | |
| 10 | #include "emu.h" |
| 11 | #include "machine/devhelpr.h" |
| 10 | 12 | |
| 11 | | DECLARE_LEGACY_DEVICE(CRTC_EGA, crtc_ega); |
| 13 | #define CRTC_EGA_INTERFACE(name) \ |
| 14 | const crtc_ega_interface (name) = |
| 12 | 15 | |
| 13 | 16 | #define MCFG_CRTC_EGA_ADD(_tag, _clock, _intrf) \ |
| 14 | 17 | MCFG_DEVICE_ADD(_tag, CRTC_EGA, _clock) \ |
| 15 | 18 | MCFG_DEVICE_CONFIG(_intrf) |
| 16 | 19 | |
| 20 | |
| 21 | class crtc_ega_device; |
| 22 | |
| 17 | 23 | /* callback definitions */ |
| 18 | | typedef void * (*crtc_ega_begin_update_func)(device_t *device, bitmap_ind16 &bitmap, const rectangle &cliprect); |
| 19 | | #define CRTC_EGA_BEGIN_UPDATE(name) void *name(device_t *device, bitmap_ind16 &bitmap, const rectangle &cliprect) |
| 24 | typedef void * (*crtc_ega_begin_update_func)(crtc_ega_device *device, bitmap_ind16 &bitmap, const rectangle &cliprect); |
| 25 | #define CRTC_EGA_BEGIN_UPDATE(name) void *name(crtc_ega_device *device, bitmap_ind16 &bitmap, const rectangle &cliprect) |
| 20 | 26 | |
| 21 | | typedef void (*crtc_ega_update_row_func)(device_t *device, bitmap_ind16 &bitmap, |
| 27 | typedef void (*crtc_ega_update_row_func)(crtc_ega_device *device, bitmap_ind16 &bitmap, |
| 22 | 28 | const rectangle &cliprect, UINT16 ma, UINT8 ra, |
| 23 | 29 | UINT16 y, UINT8 x_count, INT8 cursor_x, void *param); |
| 24 | | #define CRTC_EGA_UPDATE_ROW(name) void name(device_t *device, bitmap_ind16 &bitmap, \ |
| 30 | #define CRTC_EGA_UPDATE_ROW(name) void name(crtc_ega_device *device, bitmap_ind16 &bitmap, \ |
| 25 | 31 | const rectangle &cliprect, UINT16 ma, UINT8 ra, \ |
| 26 | 32 | UINT16 y, UINT8 x_count, INT8 cursor_x, void *param) |
| 27 | 33 | |
| 28 | | typedef void (*crtc_ega_end_update_func)(device_t *device, bitmap_ind16 &bitmap, const rectangle &cliprect, void *param); |
| 29 | | #define CRTC_EGA_END_UPDATE(name) void name(device_t *device, bitmap_ind16 &bitmap, const rectangle &cliprect, void *param) |
| 34 | typedef void (*crtc_ega_end_update_func)(crtc_ega_device *device, bitmap_ind16 &bitmap, const rectangle &cliprect, void *param); |
| 35 | #define CRTC_EGA_END_UPDATE(name) void name(crtc_ega_device *device, bitmap_ind16 &bitmap, const rectangle &cliprect, void *param) |
| 30 | 36 | |
| 31 | | typedef void (*crtc_ega_on_de_changed_func)(device_t *device, int display_enabled); |
| 32 | | #define CRTC_EGA_ON_DE_CHANGED(name) void name(device_t *device, int display_enabled) |
| 33 | 37 | |
| 34 | | typedef void (*crtc_ega_on_hsync_changed_func)(device_t *device, int hsync); |
| 35 | | #define CRTC_EGA_ON_HSYNC_CHANGED(name) void name(device_t *device, int hsync) |
| 36 | | |
| 37 | | typedef void (*crtc_ega_on_vsync_changed_func)(device_t *device, int vsync); |
| 38 | | #define CRTC_EGA_ON_VSYNC_CHANGED(name) void name(device_t *device, int vsync) |
| 39 | | |
| 40 | | typedef void (*crtc_ega_on_vblank_changed_func)(device_t *device, int vblank); |
| 41 | | #define CRTC_EGA_ON_VBLANK_CHANGED(name) void name(device_t *device, int vblank) |
| 42 | | |
| 43 | | |
| 44 | 38 | /* interface */ |
| 45 | 39 | typedef struct _crtc_ega_interface crtc_ega_interface; |
| 46 | 40 | struct _crtc_ega_interface |
| 47 | 41 | { |
| 48 | | const char *screen_tag; /* screen we are acting on */ |
| 49 | | int hpixels_per_column; /* number of pixels per video memory address */ |
| 42 | const char *m_screen_tag; /* screen we are acting on */ |
| 43 | int m_hpixels_per_column; /* number of pixels per video memory address */ |
| 50 | 44 | |
| 51 | 45 | /* if specified, this gets called before any pixel update, |
| 52 | 46 | optionally return a pointer that will be passed to the |
| 53 | 47 | update and tear down callbacks */ |
| 54 | | crtc_ega_begin_update_func begin_update; |
| 48 | crtc_ega_begin_update_func m_begin_update; |
| 55 | 49 | |
| 56 | 50 | /* this gets called for every row, the driver must output |
| 57 | 51 | x_count * hpixels_per_column pixels. |
| 58 | 52 | cursor_x indicates the character position where the cursor is, or -1 |
| 59 | 53 | if there is no cursor on this row */ |
| 60 | | crtc_ega_update_row_func update_row; |
| 54 | crtc_ega_update_row_func m_update_row; |
| 61 | 55 | |
| 62 | 56 | /* if specified, this gets called after all row updating is complete */ |
| 63 | | crtc_ega_end_update_func end_update; |
| 57 | crtc_ega_end_update_func m_end_update; |
| 64 | 58 | |
| 65 | 59 | /* if specified, this gets called for every change of the disply enable signal */ |
| 66 | | crtc_ega_on_de_changed_func on_de_changed; |
| 60 | devcb_write_line m_out_de_func; |
| 67 | 61 | |
| 68 | 62 | /* if specified, this gets called for every change of the HSYNC signal */ |
| 69 | | crtc_ega_on_hsync_changed_func on_hsync_changed; |
| 63 | devcb_write_line m_out_hsync_func; |
| 70 | 64 | |
| 71 | 65 | /* if specified, this gets called for every change of the VSYNC signal */ |
| 72 | | crtc_ega_on_vsync_changed_func on_vsync_changed; |
| 66 | devcb_write_line m_out_vsync_func; |
| 73 | 67 | |
| 74 | | /* if specificed, this gets called for every change of the VBLANK signal */ |
| 75 | | crtc_ega_on_vblank_changed_func on_vblank_changed; |
| 68 | devcb_write_line m_out_vblank_func; |
| 76 | 69 | }; |
| 77 | 70 | |
| 78 | | /* select one of the registers for reading or writing */ |
| 79 | | WRITE8_DEVICE_HANDLER( crtc_ega_address_w ); |
| 80 | 71 | |
| 81 | | /* read from the currently selected register */ |
| 82 | | READ8_DEVICE_HANDLER( crtc_ega_register_r ); |
| 72 | class crtc_ega_device : public device_t, |
| 73 | public crtc_ega_interface |
| 74 | { |
| 75 | public: |
| 76 | crtc_ega_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 83 | 77 | |
| 84 | | /* write to the currently selected register */ |
| 85 | | WRITE8_DEVICE_HANDLER( crtc_ega_register_w ); |
| 78 | /* select one of the registers for reading or writing */ |
| 79 | DECLARE_WRITE8_MEMBER( address_w ); |
| 86 | 80 | |
| 87 | | /* return the current value on the MA0-MA15 pins */ |
| 88 | | UINT16 crtc_ega_get_ma(device_t *device); |
| 81 | /* read from the currently selected register */ |
| 82 | DECLARE_READ8_MEMBER( register_r ); |
| 89 | 83 | |
| 90 | | /* return the current value on the RA0-RA4 pins */ |
| 91 | | UINT8 crtc_ega_get_ra(device_t *device); |
| 84 | /* write to the currently selected register */ |
| 85 | DECLARE_WRITE8_MEMBER( register_w ); |
| 92 | 86 | |
| 93 | | /* simulates the LO->HI clocking of the light pen pin (pin 3) */ |
| 94 | | void crtc_ega_assert_light_pen_input(device_t *device); |
| 87 | /* return the current value on the MA0-MA15 pins */ |
| 88 | UINT16 get_ma(); |
| 95 | 89 | |
| 96 | | /* set the clock (pin 21) of the chip */ |
| 97 | | void crtc_ega_set_clock(device_t *device, int clock); |
| 90 | /* return the current value on the RA0-RA4 pins */ |
| 91 | UINT8 get_ra(); |
| 98 | 92 | |
| 99 | | /* set number of pixels per video memory address */ |
| 100 | | void crtc_ega_set_hpixels_per_column(device_t *device, int hpixels_per_column); |
| 93 | /* simulates the LO->HI clocking of the light pen pin */ |
| 94 | void assert_light_pen_input(); |
| 101 | 95 | |
| 102 | | /* updates the screen -- this will call begin_update(), |
| 103 | | followed by update_row() reapeatedly and after all row |
| 104 | | updating is complete, end_update() */ |
| 105 | | void crtc_ega_update(device_t *device, bitmap_ind16 &bitmap, const rectangle &cliprect); |
| 96 | /* set the clock of the chip */ |
| 97 | void set_clock(int clock); |
| 106 | 98 | |
| 99 | /* set number of pixels per video memory address */ |
| 100 | void set_hpixels_per_column(int hpixels_per_column); |
| 107 | 101 | |
| 102 | /* updates the screen -- this will call begin_update(), */ |
| 103 | /* followed by update_row() reapeatedly and after all row */ |
| 104 | /* updating is complete, end_update() */ |
| 105 | UINT32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); |
| 106 | |
| 107 | protected: |
| 108 | // device-level overrides |
| 109 | virtual void device_config_complete(); |
| 110 | virtual void device_start(); |
| 111 | virtual void device_reset(); |
| 112 | virtual void device_post_load(); |
| 113 | virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); |
| 114 | |
| 115 | private: |
| 116 | screen_device *m_screen; |
| 117 | |
| 118 | devcb_resolved_write_line m_res_out_de_func; |
| 119 | devcb_resolved_write_line m_res_out_cur_func; |
| 120 | devcb_resolved_write_line m_res_out_hsync_func; |
| 121 | devcb_resolved_write_line m_res_out_vsync_func; |
| 122 | devcb_resolved_write_line m_res_out_vblank_func; |
| 123 | |
| 124 | /* ega/vga register file */ |
| 125 | UINT8 m_horiz_char_total; /* 0x00 */ |
| 126 | UINT8 m_horiz_disp; /* 0x01 */ |
| 127 | UINT8 m_horiz_blank_start; /* 0x02 */ |
| 128 | UINT8 m_horiz_blank_end; /* 0x03/0x05 */ |
| 129 | UINT8 m_ena_vert_access; /* 0x03 */ |
| 130 | UINT8 m_de_skew; /* 0x03 */ |
| 131 | UINT8 m_horiz_retr_start; /* 0x04 */ |
| 132 | UINT8 m_horiz_retr_end; /* 0x05 */ |
| 133 | UINT8 m_horiz_retr_skew; /* 0x05 */ |
| 134 | UINT16 m_vert_total; /* 0x06/0x07 */ |
| 135 | UINT8 m_preset_row_scan; /* 0x08 */ |
| 136 | UINT8 m_byte_panning; /* 0x08 */ |
| 137 | UINT8 m_max_ras_addr; /* 0x09 */ |
| 138 | UINT8 m_scan_doubling; /* 0x09 */ |
| 139 | UINT8 m_cursor_start_ras; /* 0x0a */ |
| 140 | UINT8 m_cursor_disable; /* 0x0a */ |
| 141 | UINT8 m_cursor_end_ras; /* 0x0b */ |
| 142 | UINT8 m_cursor_skew; /* 0x0b */ |
| 143 | UINT16 m_disp_start_addr; /* 0x0c/0x0d */ |
| 144 | UINT16 m_cursor_addr; /* 0x0e/0x0f */ |
| 145 | UINT16 m_light_pen_addr; /* 0x10/0x11 */ |
| 146 | UINT16 m_vert_retr_start; /* 0x10/0x07 */ |
| 147 | UINT8 m_vert_retr_end; /* 0x11 */ |
| 148 | UINT8 m_protect; /* 0x11 */ |
| 149 | UINT8 m_bandwidth; /* 0x11 */ |
| 150 | UINT16 m_vert_disp_end; /* 0x12/0x07 */ |
| 151 | UINT8 m_offset; /* 0x13 */ |
| 152 | UINT8 m_underline_loc; /* 0x14 */ |
| 153 | UINT16 m_vert_blank_start; /* 0x15/0x07/0x09 */ |
| 154 | UINT8 m_vert_blank_end; /* 0x16 */ |
| 155 | UINT8 m_mode_control; /* 0x17 */ |
| 156 | UINT16 m_line_compare; /* 0x18/0x07/0x09 */ |
| 157 | |
| 158 | /* other internal state */ |
| 159 | UINT8 m_register_address_latch; |
| 160 | UINT8 m_hpixels_per_column; |
| 161 | bool m_cursor_state; /* 0 = off, 1 = on */ |
| 162 | UINT8 m_cursor_blink_count; |
| 163 | |
| 164 | /* output signals */ |
| 165 | int m_cur; |
| 166 | int m_hsync; |
| 167 | int m_vsync; |
| 168 | int m_vblank; |
| 169 | int m_de; |
| 170 | |
| 171 | /* internal counters */ |
| 172 | UINT8 m_character_counter; |
| 173 | UINT8 m_hsync_width_counter; |
| 174 | UINT16 m_line_counter; |
| 175 | UINT8 m_raster_counter; |
| 176 | UINT8 m_vsync_width_counter; |
| 177 | bool m_line_enable_ff; /* Internal flip flop which is set when the line_counter is reset and reset when vert_disp is reached */ |
| 178 | UINT8 m_vsync_ff; |
| 179 | UINT8 m_adjust_active; |
| 180 | UINT16 m_line_address; |
| 181 | INT16 m_cursor_x; |
| 182 | |
| 183 | /* timers */ |
| 184 | static const device_timer_id TIMER_LINE = 0; |
| 185 | static const device_timer_id TIMER_DE_OFF = 1; |
| 186 | static const device_timer_id TIMER_CUR_ON = 2; |
| 187 | static const device_timer_id TIMER_CUR_OFF = 3; |
| 188 | static const device_timer_id TIMER_HSYNC_ON = 4; |
| 189 | static const device_timer_id TIMER_HSYNC_OFF = 5; |
| 190 | static const device_timer_id TIMER_LIGHT_PEN_LATCH = 6; |
| 191 | |
| 192 | emu_timer *m_line_timer; |
| 193 | emu_timer *m_de_off_timer; |
| 194 | emu_timer *m_cur_on_timer; |
| 195 | emu_timer *m_cur_off_timer; |
| 196 | emu_timer *m_hsync_on_timer; |
| 197 | emu_timer *m_hsync_off_timer; |
| 198 | emu_timer *m_light_pen_latch_timer; |
| 199 | |
| 200 | /* computed values - do NOT state save these! */ |
| 201 | UINT16 m_horiz_pix_total; |
| 202 | UINT16 m_vert_pix_total; |
| 203 | UINT16 m_max_visible_x; |
| 204 | UINT16 m_max_visible_y; |
| 205 | UINT16 m_hsync_on_pos; |
| 206 | UINT16 m_hsync_off_pos; |
| 207 | UINT16 m_vsync_on_pos; |
| 208 | UINT16 m_vsync_off_pos; |
| 209 | UINT16 m_current_disp_addr; /* the display address currently drawn */ |
| 210 | UINT8 m_light_pen_latched; |
| 211 | bool m_has_valid_parameters; |
| 212 | |
| 213 | void recompute_parameters(bool postload); |
| 214 | void update_counters(); |
| 215 | void set_de(int state); |
| 216 | void set_hsync(int state); |
| 217 | void set_vsync(int state); |
| 218 | void set_vblank(int state); |
| 219 | void set_cur(int state); |
| 220 | void handle_line_timer(); |
| 221 | void update_cursor_state(); |
| 222 | }; |
| 223 | |
| 224 | extern const device_type CRTC_EGA; |
| 225 | |
| 108 | 226 | #endif |