Difference between revisions of "F256K Keyboard"

From C256 Foenix Wiki
Jump to navigation Jump to search
(Device Information)
 
(4 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 25: Line 25:
 
VIA1_DDRB =  $db02  ; VIA#1 (Data Direction Register B)</nowiki>
 
VIA1_DDRB =  $db02  ; VIA#1 (Data Direction Register B)</nowiki>
  
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 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, to detect the user hitting the space bar, first initialize the keyboard as follows:
+
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:
  
 
  <nowiki>
 
  <nowiki>
Line 47: Line 47:
 
BEQ SpaceBarPressed</nowiki>
 
BEQ SpaceBarPressed</nowiki>
  
See this chart for a complete reference, for all the keys using VIA1 Port A and B:
+
See this chart for a complete reference to use VIA1 Port A and B to detect the rest of the keys:
  
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
 
! scope="col"|   
 
! scope="col"|   
! scope="col"| PB0
+
! scope="col"| VIA1 PB0
! scope="col"| PB1
+
! scope="col"| VIA1 PB1
! scope="col"| PB2
+
! scope="col"| VIA1 PB2
! scope="col"| PB3
+
! scope="col"| VIA1 PB3
! scope="col"| PB4
+
! scope="col"| VIA1 PB4
! scope="col"| PB5
+
! scope="col"| VIA1 PB5
! scope="col"| PB6
+
! scope="col"| VIA1 PB6
! scope="col"| PB7
+
! scope="col"| VIA1 PB7
 
|-
 
|-
! scope="row"| PA0
+
! scope="row"| VIA1 PA0
 
| Delete
 
| Delete
 
| Return
 
| Return
Line 71: Line 71:
 
| Up Arrow
 
| Up Arrow
 
|-
 
|-
! scope="row"| PA1
+
! scope="row"| VIA1 PA1
 
| 3
 
| 3
 
| W
 
| W
Line 81: Line 81:
 
| Left Shift
 
| Left Shift
 
|-
 
|-
! scope="row"| PA2
+
! scope="row"| VIA1 PA2
 
| 5
 
| 5
 
| R
 
| R
Line 91: Line 91:
 
| X
 
| X
 
|-
 
|-
! scope="row"| PA3
+
! scope="row"| VIA1 PA3
 
| 7
 
| 7
 
| Y
 
| Y
Line 101: Line 101:
 
| V
 
| V
 
|-
 
|-
! scope="row"| PA4
+
! scope="row"| VIA1 PA4
 
| 9
 
| 9
 
| I
 
| I
Line 111: Line 111:
 
| N
 
| N
 
|-
 
|-
! scope="row"| PA5
+
! scope="row"| VIA1 PA5
 
| Minus
 
| Minus
 
| P
 
| P
Line 121: Line 121:
 
| Comma
 
| Comma
 
|-
 
|-
! scope="row"| PA6
+
! scope="row"| VIA1 PA6
 
| Plus
 
| Plus
 
| Asterisk
 
| Asterisk
Line 131: Line 131:
 
| Forward Slash
 
| Forward Slash
 
|-
 
|-
! scope="row"| PA7
+
! scope="row"| VIA1 PA7
 
| 1
 
| 1
 
| Backspace
 
| Backspace
Line 142: Line 142:
 
|}
 
|}
  
For the right arrow:
 
* Write to VIA1 port A bit 0.
 
* Read from VIA0 port B.
 
If bit 7 is clear, the right arrow is pressed.
 
  
For the down arrow:
+
The right and down arrows use both VIA0 and VIA1 controllers.
* Write to VIA port A bit 6.
+
For the right and down arrows:
* Read from VIA0 port B.
 
If bit 7 is clear, the down arrow is pressed.
 
  
Finally, the Restore key is controlled through the NMI signal of the CPU.
+
{| class="wikitable"
 +
|-
 +
! scope="col"| 
 +
! scope="col"| VIA0 PB0
 +
! scope="col"| VIA0 PB1
 +
! scope="col"| VIA0 PB2
 +
! scope="col"| VIA0 PB3
 +
! scope="col"| VIA0 PB4
 +
! scope="col"| VIA0 PB5
 +
! scope="col"| VIA0 PB6
 +
! scope="col"| VIA0 PB7
 +
|-
 +
! scope="row"| VIA1 PA0
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
| Down Arrow
 +
|-
 +
! scope="row"| VIA1 PA1
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
|-
 +
! scope="row"| VIA1 PA2
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
|-
 +
! scope="row"| VIA1 PA3
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
|-
 +
! scope="row"| VIA1 PA4
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
|-
 +
! scope="row"| VIA1 PA5
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
|-
 +
! scope="row"| VIA1 PA6
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
| Right Arrow
 +
|-
 +
! scope="row"| VIA1 PA7
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
| -
 +
|}
 +
 
 +
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.

F256k ResizedPicture-scaled.jpg