src/mess/video/m6845.c
| r3933 | r3934 | |
| 80 | 80 | /* *** Not implemented yet *** */ |
| 81 | 81 | #define R17_light_pen_address_L crtc.registers[17] |
| 82 | 82 | |
| 83 | typedef struct m6845_state |
| 84 | { |
| 85 | const struct m6845_interface *intf; |
| 86 | m6845_personality_t personality; |
| 83 | 87 | |
| 88 | /* Register Select */ |
| 89 | int address_register; |
| 90 | /* register data */ |
| 91 | int registers[32]; |
| 92 | /* vertical and horizontal sync widths */ |
| 93 | int vertical_sync_width, horizontal_sync_width; |
| 94 | |
| 95 | int screen_start_address; /* = R12<<8 + R13 */ |
| 96 | int cursor_address; /* = R14<<8 + R15 */ |
| 97 | int light_pen_address; /* = R16<<8 + R17 */ |
| 98 | |
| 99 | int scan_lines_increment; |
| 100 | |
| 101 | int Horizontal_Counter; |
| 102 | int Horizontal_Counter_Reset; |
| 103 | |
| 104 | int Scan_Line_Counter; |
| 105 | int Scan_Line_Counter_Reset; |
| 106 | |
| 107 | int Character_Row_Counter; |
| 108 | int Character_Row_Counter_Reset; |
| 109 | |
| 110 | int Horizontal_Sync_Width_Counter; |
| 111 | int Vertical_Sync_Width_Counter; |
| 112 | |
| 113 | int HSYNC; |
| 114 | int VSYNC; |
| 115 | |
| 116 | int Vertical_Total_Adjust_Active; |
| 117 | int Vertical_Total_Adjust_Counter; |
| 118 | |
| 119 | int Memory_Address; |
| 120 | int Memory_Address_of_next_Character_Row; |
| 121 | int Memory_Address_of_this_Character_Row; |
| 122 | |
| 123 | int Horizontal_Display_Enabled; |
| 124 | int Vertical_Display_Enabled; |
| 125 | int Display_Enabled; |
| 126 | int Display_Delayed_Enabled; |
| 127 | |
| 128 | int Cursor_Delayed_Status; |
| 129 | |
| 130 | int Cursor_Flash_Count; |
| 131 | |
| 132 | int Delay_Flags; |
| 133 | int Cursor_Start_Delay; |
| 134 | int Display_Enabled_Delay; |
| 135 | int Display_Disable_Delay; |
| 136 | |
| 137 | int Vertical_Adjust_Done; |
| 138 | // int cycles_to_vsync_start; |
| 139 | // int cycles_to_vsync_end; |
| 140 | } m6845_state; |
| 141 | |
| 142 | |
| 84 | 143 | static m6845_state crtc; |
| 85 | | static m6845_personality_t personality; |
| 86 | 144 | |
| 87 | 145 | #if 0 |
| 88 | 146 | /* VSYNC functions */ |
| r3933 | r3934 | |
| 92 | 150 | /* timer to reset vsync */ |
| 93 | 151 | static void *m6845_vsync_clear_timer = NULL; |
| 94 | 152 | |
| 95 | | static void m6845_vsync_set_timer_callback(int); |
| 96 | | static void m6845_vsync_clear_timer_callback(int); |
| 153 | static void TIMER_CALLBACK( m6845_vsync_set_timer_callback ); |
| 154 | static void TIMER_CALLBACK( m6845_vsync_clear_timer_callback ); |
| 97 | 155 | static void m6845_remove_vsync_set_timer(void); |
| 98 | 156 | static void m6845_remove_vsync_clear_timer(void); |
| 99 | 157 | static void m6845_set_new_vsync_set_time(int); |
| r3933 | r3934 | |
| 103 | 161 | |
| 104 | 162 | #endif |
| 105 | 163 | |
| 106 | | // local copy of the 6845 external procedure calls |
| 107 | | static struct m6845_interface crct6845_calls = |
| 108 | | { |
| 109 | | 0,// Memory Address register |
| 110 | | 0,// Row Address register |
| 111 | | 0,// Horizontal status |
| 112 | | 0,// Vertical status |
| 113 | | 0,// Display Enabled status |
| 114 | | 0,// Cursor status |
| 115 | | |
| 116 | | |
| 117 | | 0,// Cursor status allways called |
| 118 | | // As the BBC video emulation does not redraw all off the screen every time |
| 119 | | // This function outputs: |
| 120 | | // B1 set to 1 when at cursor position, set to 0 when past cursor |
| 121 | | // B0 set to 1 when the cursor is on and 0 when the cursor is off |
| 122 | | // this function is call at the cursor location even if the cursor is off |
| 123 | | // this means that the cursor will get clear from the screen |
| 124 | | |
| 125 | | }; |
| 126 | | |
| 127 | 164 | /* set up the local copy of the 6845 external procedure calls */ |
| 128 | 165 | void m6845_config(const struct m6845_interface *intf) |
| 129 | 166 | { |
| 130 | | crct6845_calls.out_MA_func=*intf->out_MA_func; |
| 131 | | crct6845_calls.out_RA_func=*intf->out_RA_func; |
| 132 | | crct6845_calls.out_HS_func=*intf->out_HS_func; |
| 133 | | crct6845_calls.out_VS_func=*intf->out_VS_func; |
| 134 | | crct6845_calls.out_DE_func=*intf->out_DE_func; |
| 135 | | crct6845_calls.out_CR_func=*intf->out_CR_func; |
| 136 | | crct6845_calls.out_CRE_func=*intf->out_CRE_func; |
| 137 | | personality = M6845_PERSONALITY_GENUINE; |
| 167 | memset(&crtc, 0, sizeof(crtc)); |
| 168 | crtc.intf = intf; |
| 169 | crtc.personality = M6845_PERSONALITY_GENUINE; |
| 170 | m6845_reset(); |
| 138 | 171 | } |
| 139 | 172 | |
| 140 | | void m6845_start(void) |
| 141 | | { |
| 142 | | #if 0 |
| 143 | | m6845_vsync_set_timer = NULL; |
| 144 | | m6845_vsync_clear_timer = NULL; |
| 145 | | #endif |
| 146 | | } |
| 147 | | |
| 148 | 173 | /* 6845 registers */ |
| 149 | 174 | |
| 150 | 175 | /* functions to set the 6845 registers */ |
| r3933 | r3934 | |
| 153 | 178 | crtc.address_register=data & 0x1f; |
| 154 | 179 | } |
| 155 | 180 | |
| 156 | | void m6845_get_state(int offset, m6845_state *state) |
| 181 | void m6845_set_address(int address) |
| 157 | 182 | { |
| 158 | | memcpy(state, &crtc, sizeof(m6845_state)); |
| 183 | crtc.Memory_Address_of_next_Character_Row = address; |
| 184 | crtc.Memory_Address_of_this_Character_Row = address; |
| 185 | crtc.Memory_Address = address; |
| 159 | 186 | } |
| 160 | 187 | |
| 161 | | void m6845_set_state(int offset, m6845_state *state) |
| 162 | | { |
| 163 | | memcpy(&crtc, state, sizeof(m6845_state)); |
| 164 | | } |
| 165 | 188 | |
| 166 | | |
| 167 | 189 | void m6845_register_w(int offset, int data) |
| 168 | 190 | { |
| 169 | 191 | switch (crtc.address_register) |
| r3933 | r3934 | |
| 262 | 284 | switch (crtc.address_register) |
| 263 | 285 | { |
| 264 | 286 | case 12: |
| 265 | | switch(personality) |
| 287 | switch(crtc.personality) |
| 266 | 288 | { |
| 267 | 289 | case M6845_PERSONALITY_UM6845: |
| 268 | 290 | case M6845_PERSONALITY_HD6845S: |
| r3933 | r3934 | |
| 278 | 300 | } |
| 279 | 301 | break; |
| 280 | 302 | case 13: |
| 281 | | switch(personality) |
| 303 | switch(crtc.personality) |
| 282 | 304 | { |
| 283 | 305 | case M6845_PERSONALITY_UM6845: |
| 284 | 306 | case M6845_PERSONALITY_HD6845S: |
| r3933 | r3934 | |
| 313 | 335 | } |
| 314 | 336 | |
| 315 | 337 | |
| 316 | | void m6845_reset(int which) |
| 338 | void m6845_reset(void) |
| 317 | 339 | { |
| 318 | 340 | memset(&crtc.registers[0], 0, sizeof(int)*32); |
| 319 | 341 | crtc.address_register = 0; |
| r3933 | r3934 | |
| 418 | 440 | /*crtc.Scan_Line_Counter=(crtc.Scan_Line_Counter+crtc.scan_lines_increment)%32;*/ |
| 419 | 441 | crtc.Scan_Line_Counter=(crtc.Scan_Line_Counter+crtc.scan_lines_increment)&0x01f; |
| 420 | 442 | |
| 421 | | if (crtc.Vertical_Total_Adjust_Active) |
| 443 | if (crtc.Vertical_Total_Adjust_Active) |
| 422 | 444 | { |
| 423 | 445 | /* update counter */ |
| 424 | 446 | crtc.Vertical_Total_Adjust_Counter = (crtc.Vertical_Total_Adjust_Counter+1) & 0x01f; |
| r3933 | r3934 | |
| 485 | 507 | if (crtc.Character_Row_Counter==R7_vertical_sync_position) |
| 486 | 508 | { |
| 487 | 509 | crtc.VSYNC=True; |
| 488 | | if (crct6845_calls.out_VS_func) (crct6845_calls.out_VS_func)(machine, 0,crtc.VSYNC); /* call VS update */ |
| 510 | if (crtc.intf->out_VS_func) (crtc.intf->out_VS_func)(machine, 0,crtc.VSYNC); /* call VS update */ |
| 489 | 511 | } |
| 490 | 512 | |
| 491 | 513 | |
| r3933 | r3934 | |
| 499 | 521 | { |
| 500 | 522 | crtc.Vertical_Sync_Width_Counter=0; |
| 501 | 523 | crtc.VSYNC=False; |
| 502 | | if (crct6845_calls.out_VS_func) (crct6845_calls.out_VS_func)(machine, 0,crtc.VSYNC); /* call VS update */ |
| 524 | if (crtc.intf->out_VS_func) (crtc.intf->out_VS_func)(machine, 0,crtc.VSYNC); /* call VS update */ |
| 503 | 525 | } |
| 504 | 526 | } |
| 505 | 527 | |
| r3933 | r3934 | |
| 525 | 547 | if (crtc.Character_Row_Counter==R7_vertical_sync_position) |
| 526 | 548 | { |
| 527 | 549 | crtc.VSYNC=True; |
| 528 | | if (crct6845_calls.out_VS_func) (crct6845_calls.out_VS_func)(machine,0,crtc.VSYNC); /* call VS update */ |
| 550 | if (crtc.intf->out_VS_func) (crtc.intf->out_VS_func)(machine,0,crtc.VSYNC); /* call VS update */ |
| 529 | 551 | } |
| 530 | 552 | } |
| 531 | 553 | } |
| r3933 | r3934 | |
| 536 | 558 | { |
| 537 | 559 | crtc.Scan_Line_Counter_Reset=True; |
| 538 | 560 | } |
| 539 | | if (crct6845_calls.out_RA_func) (crct6845_calls.out_RA_func)(0,crtc.Scan_Line_Counter); /* call RA update */ |
| 561 | if (crtc.intf->out_RA_func) (crtc.intf->out_RA_func)(0,crtc.Scan_Line_Counter); /* call RA update */ |
| 540 | 562 | } |
| 541 | 563 | /* end of vertical clock pulse */ |
| 542 | 564 | |
| r3933 | r3934 | |
| 568 | 590 | if (crtc.horizontal_sync_width!=0) |
| 569 | 591 | { |
| 570 | 592 | crtc.HSYNC=True; |
| 571 | | if (crct6845_calls.out_HS_func) (crct6845_calls.out_HS_func)(machine, 0,crtc.HSYNC); /* call HS update */ |
| 593 | if (crtc.intf->out_HS_func) (crtc.intf->out_HS_func)(machine, 0,crtc.HSYNC); /* call HS update */ |
| 572 | 594 | } |
| 573 | 595 | } |
| 574 | 596 | |
| r3933 | r3934 | |
| 580 | 602 | |
| 581 | 603 | crtc.Horizontal_Sync_Width_Counter=0; |
| 582 | 604 | crtc.HSYNC=False; |
| 583 | | if (crct6845_calls.out_HS_func) (crct6845_calls.out_HS_func)(machine, 0,crtc.HSYNC); /* call HS update */ |
| 605 | if (crtc.intf->out_HS_func) (crtc.intf->out_HS_func)(machine, 0,crtc.HSYNC); /* call HS update */ |
| 584 | 606 | } |
| 585 | 607 | } |
| 586 | | if (crct6845_calls.out_MA_func) (crct6845_calls.out_MA_func)(0,crtc.Memory_Address); /* call MA update */ |
| 608 | if (crtc.intf->out_MA_func) (crtc.intf->out_MA_func)(0,crtc.Memory_Address); /* call MA update */ |
| 587 | 609 | |
| 588 | 610 | |
| 589 | 611 | |
| r3933 | r3934 | |
| 607 | 629 | { |
| 608 | 630 | crtc.Delay_Flags=crtc.Delay_Flags^Cursor_On_Flag; |
| 609 | 631 | crtc.Cursor_Delayed_Status=False; |
| 610 | | if (crct6845_calls.out_CR_func) (crct6845_calls.out_CR_func)(0,crtc.Cursor_Delayed_Status); /* call CR update */ |
| 611 | | if (crct6845_calls.out_CRE_func) (crct6845_calls.out_CRE_func)(0,0); /* call CRE update */ |
| 632 | if (crtc.intf->out_CR_func) (crtc.intf->out_CR_func)(0,crtc.Cursor_Delayed_Status); /* call CR update */ |
| 633 | if (crtc.intf->out_CRE_func) (crtc.intf->out_CRE_func)(0,0); /* call CRE update */ |
| 612 | 634 | } |
| 613 | 635 | |
| 614 | 636 | /* cursor enabled delay */ |
| r3933 | r3934 | |
| 621 | 643 | { |
| 622 | 644 | crtc.Delay_Flags=(crtc.Delay_Flags^Cursor_Start_Delay_Flag)|Cursor_On_Flag; |
| 623 | 645 | crtc.Cursor_Delayed_Status=True; |
| 624 | | if ((crct6845_calls.out_CR_func)&&(crtc.Cursor_Flash_Count>25)) (crct6845_calls.out_CR_func)(0,crtc.Cursor_Delayed_Status); /* call CR update */ |
| 625 | | if (crct6845_calls.out_CRE_func) (crct6845_calls.out_CRE_func)(0,2|((crtc.Cursor_Flash_Count>25)&1)); /* call CR update */ |
| 646 | if ((crtc.intf->out_CR_func)&&(crtc.Cursor_Flash_Count>25)) (crtc.intf->out_CR_func)(0,crtc.Cursor_Delayed_Status); /* call CR update */ |
| 647 | if (crtc.intf->out_CRE_func) (crtc.intf->out_CRE_func)(0,2|((crtc.Cursor_Flash_Count>25)&1)); /* call CR update */ |
| 626 | 648 | } |
| 627 | 649 | } |
| 628 | 650 | } |
| r3933 | r3934 | |
| 635 | 657 | { |
| 636 | 658 | crtc.Delay_Flags=crtc.Delay_Flags^Display_Enabled_Delay_Flag; |
| 637 | 659 | crtc.Display_Delayed_Enabled=True; |
| 638 | | if (crct6845_calls.out_DE_func) (crct6845_calls.out_DE_func)(0,crtc.Display_Delayed_Enabled); /* call DE update */ |
| 660 | if (crtc.intf->out_DE_func) (crtc.intf->out_DE_func)(0,crtc.Display_Delayed_Enabled); /* call DE update */ |
| 639 | 661 | } |
| 640 | 662 | } |
| 641 | 663 | |
| r3933 | r3934 | |
| 647 | 669 | { |
| 648 | 670 | crtc.Delay_Flags=crtc.Delay_Flags^Display_Disable_Delay_Flag; |
| 649 | 671 | crtc.Display_Delayed_Enabled=False; |
| 650 | | if (crct6845_calls.out_DE_func) (crct6845_calls.out_DE_func)(0,crtc.Display_Delayed_Enabled); /* call DE update */ |
| 672 | if (crtc.intf->out_DE_func) (crtc.intf->out_DE_func)(0,crtc.Display_Delayed_Enabled); /* call DE update */ |
| 651 | 673 | } |
| 652 | 674 | } |
| 653 | 675 | } |
| r3933 | r3934 | |
| 665 | 687 | |
| 666 | 688 | void m6845_set_personality(m6845_personality_t p) |
| 667 | 689 | { |
| 668 | | personality = p; |
| 690 | crtc.personality = p; |
| 669 | 691 | } |
| 670 | 692 | |
| 671 | 693 | // A few helper functions to help avoid heavy use of m6845_get/set_state() |
| r3933 | r3934 | |
| 808 | 830 | |
| 809 | 831 | if (crtc_cycles_to_vsync_start!=-1) |
| 810 | 832 | { |
| 811 | | m6845_vsync_set_timer = timer_set(machine, ATTOTIME_IN_USEC(crtc_cycles_to_vsync_start), NULL, 0, m6845_vsync_set_timer_callback); |
| 833 | m6845_vsync_set_timer = timer_set(machine, ATTOTIME_IN_USEC(crtc_cycles_to_vsync_start), machine, 0, m6845_vsync_set_timer_callback); |
| 812 | 834 | } |
| 813 | 835 | } |
| 814 | 836 | |
| r3933 | r3934 | |
| 833 | 855 | |
| 834 | 856 | static TIMER_CALLBACK( m6845_vsync_clear_timer_callback ) |
| 835 | 857 | { |
| 836 | | const running_machine *machine = ptr; |
| 837 | | |
| 838 | 858 | /* clear vsync */ |
| 839 | 859 | crtc.VSYNC = 0; |
| 840 | 860 | |
| 841 | 861 | /* call function to let emulation "know" */ |
| 842 | | if (crct6845_calls.out_VS_func) (crct6845_calls.out_VS_func)(machine,0,crtc.VSYNC); /* call VS update */ |
| 862 | if (crtc.intf->out_VS_func) (crtc.intf->out_VS_func)(machine,0,crtc.VSYNC); /* call VS update */ |
| 843 | 863 | |
| 844 | 864 | |
| 845 | 865 | /* if we got to here the vsync has just ended */ |
| r3933 | r3934 | |
| 853 | 873 | } |
| 854 | 874 | |
| 855 | 875 | /* called when vsync is set */ |
| 856 | | static void m6845_vsync_set_timer_callback(int dummy) |
| 876 | static TIMER_CALLBACK( m6845_vsync_set_timer_callback ) |
| 857 | 877 | { |
| 858 | 878 | /* set vsync */ |
| 859 | 879 | crtc.VSYNC = 1; |
| 860 | 880 | |
| 861 | 881 | /* call function to let emulation "know" */ |
| 862 | | if (crct6845_calls.out_VS_func) (crct6845_calls.out_VS_func)(Machine,0,crtc.VSYNC); /* call VS update */ |
| 882 | if (crtc.intf->out_VS_func) (crtc.intf->out_VS_func)(machine,0,crtc.VSYNC); /* call VS update */ |
| 863 | 883 | |
| 864 | 884 | |
| 865 | 885 | /* if we got to here the vsync has just been set, and has just started */ |