src/mess/machine/pecom.c
| r3552 | r3553 | |
| 12 | 12 | #include "devices/cassette.h"
|
| 13 | 13 | #include "includes/pecom.h"
|
| 14 | 14 |
|
| 15 | | UINT8 pecom_caps_state = 4;
|
| 16 | | UINT8 pecom_prev_caps_state = 4;
|
| 15 | static UINT8 pecom_caps_state = 4;
|
| 16 | static UINT8 pecom_prev_caps_state = 4;
|
| 17 | 17 | |
| 18 | | static UINT8 pecom_key_press_line;
|
| 19 | | static UINT8 pecom_key_pressed;
|
| 20 | | static UINT8 pecom_key_state = 0;
|
| 21 | | static UINT8 pecom_prev_key_state = 0;
|
| 22 | | static UINT8 pecom_key_read_line = 0;
|
| 23 | | static UINT8 pecom_key_real = 0;
|
| 24 | | |
| 25 | | |
| 26 | 18 | /* Driver initialization */
|
| 27 | 19 | DRIVER_INIT(pecom)
|
| 28 | 20 | {
|
| r3552 | r3553 | |
| 60 | 52 |
|
| 61 | 53 | pecom_caps_state = 4;
|
| 62 | 54 | pecom_prev_caps_state = 4;
|
| 63 | |
|
| 64 | | pecom_key_press_line = 0;
|
| 65 | | pecom_key_pressed = 0;
|
| 66 | | pecom_key_state = 0;
|
| 67 | | pecom_prev_key_state = 0;
|
| 68 | | pecom_key_read_line = 0;
|
| 69 | |
|
| 55 | |
| 70 | 56 | state->cdp1802_mode = CDP1802_MODE_RESET;
|
| 71 | 57 | state->dma = 0;
|
| 72 | 58 | timer_adjust_oneshot(state->reset_timer, ATTOTIME_IN_MSEC(5), 0);
|
| r3552 | r3553 | |
| 97 | 83 | READ8_HANDLER (pecom_keyboard_r)
|
| 98 | 84 | {
|
| 99 | 85 | static const char *keynames[] = { "LINE0", "LINE1", "LINE2", "LINE3", "LINE4", "LINE5", "LINE6", "LINE7",
|
| 100 | | "LINE8", "LINE9", "LINE10", "LINE11", "LINE12", "LINE13", "LINE14", "LINE15", "LINE16",
|
| 101 | | "LINE17", "LINE18", "LINE19", "LINE20", "LINE21", "LINE22", "LINE23", "LINE24","LINE25" };
|
| 102 | | pecom_key_state = input_port_read(machine, keynames[pecom_key_read_line]) & 0x03;
|
| 103 | | // If key has been clicked
|
| 104 | | if ((pecom_key_pressed==0) &&(pecom_key_state!=0) && ((pecom_prev_key_state & pecom_key_state)==0)) {
|
| 105 | | // key is pressed |
| 106 | | pecom_key_press_line = pecom_key_read_line;
|
| 107 | | pecom_key_read_line = 0;
|
| 108 | | pecom_key_pressed = 1; |
| 109 | | pecom_key_real = 0;
|
| 110 | | } else |
| 111 | | if (pecom_key_pressed==1 && pecom_key_read_line==pecom_key_press_line) {
|
| 112 | | // key is released
|
| 113 | | if ((pecom_key_state==0) && (pecom_key_real==0)) {
|
| 114 | | // if first read value is 0 then we act as button is already released
|
| 115 | | // so move to next as usual but mark as it is released
|
| 116 | | pecom_key_read_line++;
|
| 117 | | pecom_key_pressed = 0;
|
| 118 | | pecom_key_press_line = 0;
|
| 119 | | pecom_key_real = 0; |
| 120 | | } else { |
| 121 | | // If button is not yet released then we need to give |
| 122 | | // read value until it became 0
|
| 123 | | if (pecom_key_real==0) { |
| 124 | | pecom_key_real = pecom_key_state; // Take first value while it is pressed
|
| 125 | | }
|
| 126 | |
|
| 127 | | if ((pecom_key_state & pecom_key_real)!=pecom_key_real) {
|
| 128 | | // If key is released clear all counters
|
| 129 | | pecom_key_pressed = 0;
|
| 130 | | pecom_key_read_line = 0;
|
| 131 | | pecom_key_press_line = 0;
|
| 132 | | pecom_key_real = 0; |
| 133 | | }
|
| 134 | | }
|
| 135 | | } |
| 136 | | else
|
| 137 | | {
|
| 138 | | // Else just increment counter
|
| 139 | | pecom_key_read_line++;
|
| 140 | | pecom_key_state = 0;
|
| 141 | | } |
| 142 | | if (pecom_key_read_line>25) {
|
| 143 | | pecom_key_read_line=0;
|
| 144 | | }
|
| 145 | | pecom_prev_key_state = pecom_key_state;
|
| 146 | | return pecom_key_state;
|
| 147 | |
|
| 86 | "LINE8", "LINE9", "LINE10", "LINE11", "LINE12", "LINE13", "LINE14", "LINE15", "LINE16",
|
| 87 | "LINE17", "LINE18", "LINE19", "LINE20", "LINE21", "LINE22", "LINE23", "LINE24","LINE25" };
|
| 88 | /* |
| 89 | INP command BUS -> M(R(X)) BUS -> D |
| 90 | so on each input, address is also set, 8 lower bits are used as input for keyboard |
| 91 | Address is available on address bus during reading of value from port, and that is |
| 92 | used to determine keyboard line reading
|
| 93 | */
|
| 94 | UINT16 addr = cpunum_get_reg(0,CDP1802_R0 + cpunum_get_reg(0,CDP1802_X)) & 0xff;
|
| 95 | /* just in case somone is reading non existing ports */
|
| 96 | if (addr<0xca || addr>0xe3) return 0; |
| 97 | return input_port_read(machine, keynames[addr - 0xca]) & 0x03;
|
| 148 | 98 | }
|
| 149 | 99 | |
| 150 | 100 | /* CDP1802 Interface */
|