src/mess/machine/mbee.c
| r9377 | r9378 | |
| 15 | 15 | |
| 16 | 16 | static size_t mbee_size; |
| 17 | 17 | static UINT8 mbee_clock_pulse; |
| 18 | static UINT8 mbee256_key_available; |
| 18 | 19 | static UINT8 fdc_status = 0; |
| 19 | 20 | static UINT8 mbee_0a; |
| 20 | 21 | static running_device *mbee_fdc; |
| r9377 | r9378 | |
| 63 | 64 | |
| 64 | 65 | static READ8_DEVICE_HANDLER( pio_port_b_r ) |
| 65 | 66 | { |
| 66 | | UINT8 data = z80pio_pb_r(mbee_z80pio,0) & 0x7e; |
| 67 | UINT8 data = 0; |
| 67 | 68 | |
| 68 | | if (cassette_input(mbee_cassette) > 0.03) |
| 69 | | data |= 0x01; |
| 69 | if (cassette_input(mbee_cassette) > 0.03) data |= 1; |
| 70 | 70 | |
| 71 | 71 | data |= mbee_clock_pulse; |
| 72 | data |= mbee256_key_available; |
| 72 | 73 | |
| 73 | 74 | mbee_clock_pulse = 0; |
| 74 | 75 | |
| r9377 | r9378 | |
| 147 | 148 | |
| 148 | 149 | static UINT8 mbee256_was_pressed[15] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; |
| 149 | 150 | static UINT8 mbee256_q[20]; |
| 150 | | static UINT8 mbee256_q_pos = 0; |
| 151 | static UINT8 mbee256_q_pos; |
| 151 | 152 | |
| 152 | 153 | static TIMER_CALLBACK( mbee256_kbd ) |
| 153 | 154 | { |
| 154 | | /* Keyboard scanner is a '3870' chip. It is not clocked, but is triggered by each read of port 18. |
| 155 | | When a key is detected, it sets bit 1 of port 2 (one of the pio input lines). The next read of |
| 156 | | port 18 will clear this line. The 3870 can store up to 9 keys, and has separate scan codes for |
| 157 | | keys being pressed and being released. With no data sheet available, the following is a guess. */ |
| 155 | /* Keyboard scanner is a '3870' chip. Its speed of operation is determined by a 15k resistor on |
| 156 | pin 2 (XTL2) and is therefore unknown. If a key change is detected (up or down), the /strobe |
| 157 | line activates, sending a high to bit 1 of port 2 (one of the pio input lines). The next read of |
| 158 | port 18 will clear this line, and read the key scancode. It will also signal the 3870 that the key |
| 159 | data has been read, on pin 38 (/extint). The 3870 can cache up to 9 keys. With no data sheet |
| 160 | available, the following is a guess. */ |
| 158 | 161 | |
| 159 | | UINT8 i, j, scancode; |
| 160 | | UINT8 pressed[15] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; |
| 162 | UINT8 i, j; |
| 163 | UINT8 pressed[15]; |
| 161 | 164 | char kbdrow[6]; |
| 162 | 165 | |
| 163 | 166 | |
| 164 | | /* see what is pressed */ |
| 167 | /* see what is pressed */ |
| 165 | 168 | for (i = 0; i < 15; i++) |
| 166 | 169 | { |
| 167 | 170 | sprintf(kbdrow,"LINE%d",i); |
| 168 | 171 | pressed[i] = (input_port_read(machine, kbdrow)); |
| 169 | 172 | } |
| 170 | 173 | |
| 171 | | /* find what has changed */ |
| 174 | /* find what has changed */ |
| 172 | 175 | for (i = 0; i < 15; i++) |
| 173 | 176 | { |
| 174 | 177 | if (pressed[i] != mbee256_was_pressed[i]) |
| r9377 | r9378 | |
| 178 | 181 | { |
| 179 | 182 | if (BIT(pressed[i]^mbee256_was_pressed[i], j)) |
| 180 | 183 | { |
| 181 | | scancode = (i << 3) | j | (BIT(pressed[i], j) ? 0x80 : 0); |
| 182 | 184 | /* put it in the queue */ |
| 183 | | mbee256_q[mbee256_q_pos] = scancode; |
| 185 | mbee256_q[mbee256_q_pos] = (i << 3) | j | (BIT(pressed[i], j) ? 0x80 : 0); |
| 184 | 186 | if (mbee256_q_pos < 19) mbee256_q_pos++; |
| 185 | 187 | } |
| 186 | 188 | } |
| r9377 | r9378 | |
| 188 | 190 | } |
| 189 | 191 | } |
| 190 | 192 | |
| 191 | | /* if anything queued, cause an interrupt */ |
| 193 | /* if anything queued, cause an interrupt */ |
| 192 | 194 | if (mbee256_q_pos) |
| 193 | | { |
| 194 | | i = z80pio_pb_r(mbee_z80pio,0); |
| 195 | | z80pio_pb_w(mbee_z80pio, 0, i | 2); |
| 196 | | } |
| 195 | mbee256_key_available = 2; // set irq |
| 197 | 196 | } |
| 198 | 197 | |
| 199 | 198 | READ8_HANDLER( mbee256_18_r ) |
| 200 | 199 | { |
| 201 | | UINT8 i, ret = 5; // no idea what the 'nokey' value should be |
| 200 | UINT8 i; |
| 201 | UINT8 data = mbee256_q[0]; // get oldest key |
| 202 | |
| 202 | 203 | if (mbee256_q_pos) |
| 203 | 204 | { |
| 204 | 205 | mbee256_q_pos--; |
| 205 | | ret = mbee256_q[0]; // get oldest key |
| 206 | 206 | for (i = 0; i < mbee256_q_pos; i++) mbee256_q[i] = mbee256_q[i+1]; // ripple queue |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | | z80pio_pb_w(mbee_z80pio, 0, z80pio_pb_r(mbee_z80pio,0) & 0xfd); // clear irq |
| 210 | | |
| 211 | | /* time delay of 0.01uf cap and 1.5k resistor */ |
| 212 | | timer_set(space->machine, ATTOTIME_IN_USEC(15), NULL, 0, mbee256_kbd); |
| 213 | | |
| 214 | | /* get next char and return it */ |
| 215 | | |
| 216 | | return ret; |
| 209 | mbee256_key_available = 0; // clear irq |
| 210 | return data; |
| 217 | 211 | } |
| 218 | 212 | |
| 219 | 213 | |
| r9377 | r9378 | |
| 472 | 466 | The bios will support 256 PAKs, although normally only |
| 473 | 467 | 8 are available in hardware. Each PAK is normally a 4K |
| 474 | 468 | ROM. If 8K ROMs are used, the 2nd half becomes PAK+8, |
| 475 | | thus 16 PAKs in total. This is what we support. |
| 469 | thus 16 PAKs in total. This is used in the PC85 models. |
| 476 | 470 | |
| 477 | 471 | ************************************************************/ |
| 478 | 472 | |
| r9377 | r9378 | |
| 725 | 719 | memory_configure_bank(machine, "bank8h", 0, 1, &RAM[0x0800], 0x0000); // rom |
| 726 | 720 | |
| 727 | 721 | timer_pulse(machine, ATTOTIME_IN_HZ(1),NULL,0,mbee_rtc_irq); /* timer for rtc */ |
| 722 | timer_pulse(machine, ATTOTIME_IN_HZ(25),NULL,0,mbee256_kbd); /* timer for kbd */ |
| 728 | 723 | } |
| 729 | 724 | |
| 730 | 725 | |