src/mess/drivers/pcw.c
| r9863 | r9864 | |
| 740 | 740 | * T0: Paper sensor (?) |
| 741 | 741 | * T1: Print head location (1 if not at left margin) |
| 742 | 742 | */ |
| 743 | static TIMER_CALLBACK(pcw_stepper_callback) |
| 744 | { |
| 745 | pcw_state *state = machine->driver_data<pcw_state>(); |
| 746 | |
| 747 | //popmessage("PRN: P2 bits %s %s %s\nSerial: %02x\nHeadpos: %i",state->printer_p2 & 0x40 ? " " : "6",state->printer_p2 & 0x20 ? " " : "5",state->printer_p2 & 0x10 ? " " : "4",state->printer_shift_output,state->printer_headpos); |
| 748 | if((state->printer_p2 & 0x10) == 0) // print head motor active |
| 749 | { |
| 750 | UINT8 stepper_state = (state->printer_shift_output >> 4) & 0x0f; |
| 751 | if(stepper_state == full_step_table[(state->head_motor_state + 1) & 0x03]) |
| 752 | { |
| 753 | state->printer_headpos += 2; |
| 754 | state->head_motor_state++; |
| 755 | logerror("Printer head moved forward by 2 to %i\n",state->printer_headpos); |
| 756 | } |
| 757 | if(stepper_state == half_step_table[(state->head_motor_state + 1) & 0x03]) |
| 758 | { |
| 759 | state->printer_headpos += 1; |
| 760 | state->head_motor_state++; |
| 761 | logerror("Printer head moved forward by 1 to %i\n",state->printer_headpos); |
| 762 | } |
| 763 | if(stepper_state == full_step_table[(state->head_motor_state - 1) & 0x03]) |
| 764 | { |
| 765 | state->printer_headpos -= 2; |
| 766 | state->head_motor_state--; |
| 767 | logerror("Printer head moved back by 2 to %i\n",state->printer_headpos); |
| 768 | } |
| 769 | if(stepper_state == half_step_table[(state->head_motor_state - 1) & 0x03]) |
| 770 | { |
| 771 | state->printer_headpos -= 1; |
| 772 | state->head_motor_state--; |
| 773 | logerror("Printer head moved back by 1 to %i\n",state->printer_headpos); |
| 774 | } |
| 775 | if(state->printer_headpos < 0) |
| 776 | state->printer_headpos = 0; |
| 777 | if(state->printer_headpos > PCW_PRINTER_WIDTH) |
| 778 | state->printer_headpos = PCW_PRINTER_WIDTH; |
| 779 | state->head_motor_state &= 0x03; |
| 780 | state->printer_p2 |= 0x10; |
| 781 | } |
| 782 | if((state->printer_p2 & 0x20) == 0) // line feed motor active |
| 783 | { |
| 784 | UINT8 stepper_state = state->printer_shift_output & 0x0f; |
| 785 | if(stepper_state == full_step_table[(state->linefeed_motor_state + 1) & 0x03]) |
| 786 | { |
| 787 | state->paper_feed++; |
| 788 | if(state->paper_feed > PCW_PRINTER_HEIGHT*2) |
| 789 | state->paper_feed = 0; |
| 790 | state->linefeed_motor_state++; |
| 791 | } |
| 792 | if(stepper_state == half_step_table[(state->linefeed_motor_state + 1) & 0x03]) |
| 793 | { |
| 794 | state->paper_feed++; |
| 795 | if(state->paper_feed > PCW_PRINTER_HEIGHT*2) |
| 796 | state->paper_feed = 0; |
| 797 | state->linefeed_motor_state++; |
| 798 | } |
| 799 | state->linefeed_motor_state &= 0x03; |
| 800 | state->printer_p2 |= 0x20; |
| 801 | } |
| 802 | } |
| 803 | |
| 804 | static TIMER_CALLBACK(pcw_pins_callback) |
| 805 | { |
| 806 | pcw_state *state = machine->driver_data<pcw_state>(); |
| 807 | |
| 808 | pcw_printer_fire_pins(machine,state->printer_pins); |
| 809 | state->printer_p2 |= 0x40; |
| 810 | } |
| 811 | |
| 743 | 812 | static READ8_HANDLER(mcu_printer_p1_r) |
| 744 | 813 | { |
| 745 | 814 | pcw_state *state = space->machine->driver_data<pcw_state>(); |
| r9863 | r9864 | |
| 774 | 843 | //logerror("PRN: MCU writing %02x to P2\n",data); |
| 775 | 844 | state->printer_p2 = data & 0x70; |
| 776 | 845 | |
| 777 | | if((data & 0x40) == 0 && (state->printer_p2_prev & 0x40) != 0) |
| 778 | | pcw_printer_fire_pins(space->machine,state->printer_pins); |
| 779 | | |
| 780 | 846 | // handle shift/store |
| 781 | 847 | state->printer_serial = data & 0x04; // data |
| 782 | 848 | if((data & 0x02) != 0) // clock |
| r9863 | r9864 | |
| 791 | 857 | { |
| 792 | 858 | logerror("Strobe active [%02x]\n",state->printer_shift); |
| 793 | 859 | state->printer_shift_output = state->printer_shift; |
| 794 | | if((state->printer_p2 & 0x10) == 0) // print head motor active |
| 795 | | { |
| 796 | | UINT8 stepper_state = (state->printer_shift_output >> 4) & 0x0f; |
| 797 | | if(stepper_state == full_step_table[(state->head_motor_state + 1) & 0x03]) |
| 798 | | { |
| 799 | | state->printer_headpos += 2; |
| 800 | | state->head_motor_state++; |
| 801 | | logerror("Printer head moved forward by 2 to %i\n",state->printer_headpos); |
| 802 | | } |
| 803 | | if(stepper_state == half_step_table[(state->head_motor_state + 1) & 0x03]) |
| 804 | | { |
| 805 | | state->printer_headpos += 1; |
| 806 | | state->head_motor_state++; |
| 807 | | logerror("Printer head moved forward by 1 to %i\n",state->printer_headpos); |
| 808 | | } |
| 809 | | if(stepper_state == full_step_table[(state->head_motor_state - 1) & 0x03]) |
| 810 | | { |
| 811 | | state->printer_headpos -= 2; |
| 812 | | state->head_motor_state--; |
| 813 | | logerror("Printer head moved back by 2 to %i\n",state->printer_headpos); |
| 814 | | } |
| 815 | | if(stepper_state == half_step_table[(state->head_motor_state - 1) & 0x03]) |
| 816 | | { |
| 817 | | state->printer_headpos -= 1; |
| 818 | | state->head_motor_state--; |
| 819 | | logerror("Printer head moved back by 1 to %i\n",state->printer_headpos); |
| 820 | | } |
| 821 | | if(state->printer_headpos < 0) |
| 822 | | state->printer_headpos = 0; |
| 823 | | if(state->printer_headpos > PCW_PRINTER_WIDTH) |
| 824 | | state->printer_headpos = PCW_PRINTER_WIDTH; |
| 825 | | state->head_motor_state &= 0x03; |
| 826 | | } |
| 827 | | if((state->printer_p2 & 0x20) == 0) // line feed motor active |
| 828 | | { |
| 829 | | UINT8 stepper_state = state->printer_shift_output & 0x0f; |
| 830 | | if(stepper_state == full_step_table[(state->linefeed_motor_state + 1) & 0x03]) |
| 831 | | { |
| 832 | | state->paper_feed++; |
| 833 | | if(state->paper_feed > PCW_PRINTER_HEIGHT*2) |
| 834 | | state->paper_feed = 0; |
| 835 | | state->linefeed_motor_state++; |
| 836 | | } |
| 837 | | if(stepper_state == half_step_table[(state->linefeed_motor_state + 1) & 0x03]) |
| 838 | | { |
| 839 | | state->paper_feed++; |
| 840 | | if(state->paper_feed > PCW_PRINTER_HEIGHT*2) |
| 841 | | state->paper_feed = 0; |
| 842 | | state->linefeed_motor_state++; |
| 843 | | } |
| 844 | | state->linefeed_motor_state &= 0x03; |
| 845 | | } |
| 860 | timer_adjust_oneshot(state->prn_stepper,PERIOD_OF_555_MONOSTABLE(22000,0.00000001),0); |
| 846 | 861 | } |
| 862 | |
| 863 | if(data & 0x40) |
| 864 | timer_adjust_oneshot(state->prn_pins,PERIOD_OF_555_MONOSTABLE(22000,0.0000000068),0); |
| 865 | |
| 847 | 866 | if(data & 0x01) |
| 848 | 867 | state->printer_pins |= 0x0100; |
| 849 | 868 | else |
| 850 | 869 | state->printer_pins &= ~0x0100; |
| 851 | 870 | state->printer_p2_prev = data; |
| 852 | | //popmessage("PRN: P2 bits %s %s %s\nSerial: %02x\nHeadpos: %i",data & 0x40 ? " " : "6",data & 0x20 ? " " : "5",data & 0x10 ? " " : "4",state->printer_shift_output,state->printer_headpos); |
| 853 | 871 | } |
| 854 | 872 | |
| 855 | 873 | // Paper sensor |
| r9863 | r9864 | |
| 1103 | 1121 | timer_pulse(machine, ATTOTIME_IN_HZ(300), NULL, 0, pcw_timer_interrupt); |
| 1104 | 1122 | |
| 1105 | 1123 | timer_set(machine, attotime_zero, NULL, 0, setup_beep); |
| 1124 | |
| 1125 | state->prn_stepper = timer_alloc(machine,pcw_stepper_callback,NULL); |
| 1126 | state->prn_pins = timer_alloc(machine,pcw_pins_callback,NULL); |
| 1106 | 1127 | } |
| 1107 | 1128 | |
| 1108 | 1129 | |
| r9863 | r9864 | |
| 1364 | 1385 | MDRV_SCREEN_VISIBLE_AREA(0, PCW_PRINTER_WIDTH-1, 0, PCW_PRINTER_HEIGHT-1) |
| 1365 | 1386 | |
| 1366 | 1387 | MDRV_DEFAULT_LAYOUT( layout_pcw ) |
| 1388 | |
| 1367 | 1389 | MACHINE_CONFIG_END |
| 1368 | 1390 | |
| 1369 | 1391 | static MACHINE_CONFIG_DERIVED( pcw8512, pcw ) |