F256K Keyboard

From C256 Foenix Wiki
Revision as of 17:00, 25 June 2023 by HaydenKale (talk | contribs)
Jump to navigation Jump to search

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

See this chart for a complete reference:

PB0 PB1 PB2 PB3 PB4 PB5 PB6 PB7
PA0 Delete Return Left Arrow F7 F1 F3 F5 Up Arrow
PA1 3 W A 4 Z S E Left Shift
PA2 5 R D 6 C F T X
PA3 7 Y G 8 B H U V
PA4 9 I J 0 M K O N
PA5 Minus P L Caps Period Colon At Comma
PA6 Plus Asterisk Semicolon Home Right Shift Alt Tab Forward Slash
PA7 1 Backspace Control 2 Space Foenix Q Run/Stop


For a more complete reference, see the manual.

F256k ResizedPicture-scaled.jpg