Difference between revisions of "F256K Keyboard"
HaydenKale (talk | contribs) |
HaydenKale (talk | contribs) (→Device Information) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | The F256K has a built-in keyboard, as hinted by the 'K' in its name. | + | The [[F256K]] has a built-in keyboard, as hinted by the 'K' in its name. |
Programs can interact with the keyboard through a kernel, or directly with the device. | Programs can interact with the keyboard through a kernel, or directly with the device. | ||
Line 6: | Line 6: | ||
Programs interacting directly with the keyboard device will communicate with it through two WDC VIA (Versatile Interface Adapter) controllers and the CPU's NMI signal. For the complete description of VIA, see [https://www.westerndesigncenter.com/wdc/documentation/w65c22.pdf WDC's specification]. The keys are controlled as follows: | Programs interacting directly with the keyboard device will communicate with it through two WDC VIA (Versatile Interface Adapter) controllers and the CPU's NMI signal. For the complete description of VIA, see [https://www.westerndesigncenter.com/wdc/documentation/w65c22.pdf WDC's specification]. The keys are controlled as follows: | ||
− | * '''Restore''' key is controlled by NMI signal. | + | * '''Restore''' key is controlled by NMI signal from the CPU. |
* '''Right arrow''' and '''down arrow''' are controlled by VIA0. | * '''Right arrow''' and '''down arrow''' are controlled by VIA0. | ||
* '''Rest of the keys''' are all controlled by VIA1. | * '''Rest of the keys''' are all controlled by VIA1. | ||
Line 239: | Line 239: | ||
|} | |} | ||
− | Finally, the Restore key is | + | Finally, the Restore key is relayed through the NMI signal of the CPU. |
For an additional reference, see the [https://github.com/pweingar/F256Manual manual]. | For an additional reference, see the [https://github.com/pweingar/F256Manual manual]. | ||
[[File:f256k_ResizedPicture-scaled.jpg|400px]] | [[File:f256k_ResizedPicture-scaled.jpg|400px]] |
Latest revision as of 22:50, 26 June 2023
The F256K has a built-in keyboard, as hinted by the 'K' in its name.
Programs can interact with the keyboard through a kernel, or directly with the device.
Device Information
Programs interacting directly with the keyboard device will communicate with it through two WDC VIA (Versatile Interface Adapter) controllers and the CPU's NMI signal. For the complete description of VIA, see WDC's specification. The keys are controlled as follows:
- Restore key is controlled by NMI signal from the CPU.
- Right arrow and down arrow are controlled by VIA0.
- Rest of the keys are all controlled by VIA1.
The VIA controllers themselves are memory-mapped, visible to CPU I/O Page 0. They're memory-mapped to these locations:
VIA0_PRA = $dc01 ; VIA#0 (Port Register A) VIA0_DDRA = $dc03 ; VIA#0 (Data Direction Register A) VIA0_PRB = $dc00 ; VIA#0 (Port Register B) VIA0_DDRB = $dc02 ; VIA#0 (Data Direction Register B) VIA1_PRA = $db01 ; VIA#1 (Port Register A) VIA1_DDRA = $db03 ; VIA#1 (Data Direction Register A) VIA1_PRB = $db00 ; VIA#1 (Port Register B) VIA1_DDRB = $db02 ; VIA#1 (Data Direction Register B)
The typical way to poll for the majority of the keys (i.e., all the keys except right arrow, down arrow, and Restore) is to write to VIA1 port A, then read from VIA1 port B. Functionally, you might observe the reverse to also work on hardware. That said, the role of port A is to short the pin while port B has pull-ups, therefore it is best for the health of the system components to write to port A and read from port B. The examples below assume this standard direction.
For example, the space bar is mapped to bit 7 of port A, bit 4 of port B. So to detect the user hitting the space bar, first initialize the keyboard as follows:
; Initialize matrix keyboard ; Designate port A for write, and port B for read. LDA #$FF STA VIA1_DDRA LDA #$00 STA VIA1_DDRB
Then to poll for input, use
; Space is PB4, PA7 LDA #(1 << 7 ^ $FF) STA VIA1_PRA LDA VIA1_PRB CMP #(1 << 4 ^ $FF) BEQ SpaceBarPressed
See this chart for a complete reference to use VIA1 Port A and B to detect the rest of the keys:
VIA1 PB0 | VIA1 PB1 | VIA1 PB2 | VIA1 PB3 | VIA1 PB4 | VIA1 PB5 | VIA1 PB6 | VIA1 PB7 | |
---|---|---|---|---|---|---|---|---|
VIA1 PA0 | Delete | Return | Left Arrow | F7 | F1 | F3 | F5 | Up Arrow |
VIA1 PA1 | 3 | W | A | 4 | Z | S | E | Left Shift |
VIA1 PA2 | 5 | R | D | 6 | C | F | T | X |
VIA1 PA3 | 7 | Y | G | 8 | B | H | U | V |
VIA1 PA4 | 9 | I | J | 0 | M | K | O | N |
VIA1 PA5 | Minus | P | L | Caps | Period | Colon | At | Comma |
VIA1 PA6 | Plus | Asterisk | Semicolon | Home | Right Shift | Alt | Tab | Forward Slash |
VIA1 PA7 | 1 | Backspace | Control | 2 | Space | Foenix | Q | Run/Stop |
The right and down arrows use both VIA0 and VIA1 controllers.
For the right and down arrows:
VIA0 PB0 | VIA0 PB1 | VIA0 PB2 | VIA0 PB3 | VIA0 PB4 | VIA0 PB5 | VIA0 PB6 | VIA0 PB7 | |
---|---|---|---|---|---|---|---|---|
VIA1 PA0 | - | - | - | - | - | - | - | Down Arrow |
VIA1 PA1 | - | - | - | - | - | - | - | - |
VIA1 PA2 | - | - | - | - | - | - | - | - |
VIA1 PA3 | - | - | - | - | - | - | - | - |
VIA1 PA4 | - | - | - | - | - | - | - | - |
VIA1 PA5 | - | - | - | - | - | - | - | - |
VIA1 PA6 | - | - | - | - | - | - | - | Right Arrow |
VIA1 PA7 | - | - | - | - | - | - | - | - |
Finally, the Restore key is relayed through the NMI signal of the CPU.
For an additional reference, see the manual.