Difference between revisions of "F256K Keyboard"
HaydenKale (talk | contribs) (Created page with "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 Informa...") |
HaydenKale (talk | contribs) (→Device Information) |
||
Line 5: | Line 5: | ||
= Device Information = | = 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 [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. | ||
* '''Right arrow''' and '''down arrow''' are controlled by VIA0. | * '''Right arrow''' and '''down arrow''' are controlled by VIA0. |
Revision as of 16:48, 25 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.
- 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.
For example, 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
For a more complete reference, see the manual.