From C64-Wiki
Jump to: navigation, search
Site Under Construction Sign This article or section is in the process of an expansion or major restructuring and is therefore classed as a work in progress. You are welcome to assist in its construction by editing it as well. If this article or section has not been edited in several days, please remove this template.

The C64 Keyboard has 66 keys on it. Keyboard reads are done using the CIA.


[edit] Definition

The C64 is a keyboard computer, that is, a computer which is built inside a keyboard. Other homecomputers are built this way, such as Commodore VC 20, C16, C116, C128, Plus/4, Amiga or Atari ST.

The Keyboard is the main Input Device of the C64. Most typically, it is used to type BASIC-commands such as LOAD, LIST, RUN etc.

[edit] Pictures of C64 keyboards

VIC20-C64: orange functions keys
C64: grey functions keys

Aldi-C64: light grey functions keys
C64C / C64G: upper gfx chars

[edit] Keyboard Map

CIA 1 Port B ($DC01) Joy 2

Port A

PA6 / ^ = RSHIFT HOME  ; * £
PA5 , @  : . - L P +
PA4 N O K M 0 J I 9 Fire
PA3 V U H B 8 G Y 7 Right
PA2 X T F C 6 D R 5 Left
PA1 LSHIFT E S Z 4 A W 3 Down
Joy 1 Fire Right Left Down Up

[edit] Programming

[edit] Assembler

[edit] direct addressing of a key

; This program waits until the key "S" was pushed.
; Start with SYS 49152

*=$c000                  ; startaddress 

PRA  =  $dc00            ; CIA#1 (Port Register A)
DDRA =  $dc02            ; CIA#1 (Data Direction Register A)

PRB  =  $dc01            ; CIA#1 (Port Register B)
DDRB =  $dc03            ; CIA#1 (Data Direction Register B)

start    sei             ; interrupts deactivated

         lda #%11111111  ; CIA#1 port A = outputs 
         sta DDRA             

         lda #%00000000  ; CIA#1 port B = inputs
         sta DDRB             

         lda #%11111101  ; testing column 1 (COL1) of the matrix
         sta PRA
loop     lda PRB
         and #%00100000  ; masking row 5 (ROW5) 
         bne loop        ; wait until key "S" 

         cli             ; interrupts activated

ende     rts             ; back to BASIC
.c000  78         sei
.c001  a9 ff      lda #$ff
.c003  8d 02 dc   sta $dc02
.c006  a9 00      lda #$00
.c008  8d 03 dc   sta $dc03
.c00b  a9 fd      lda #$fd
.c00d  8d 00 dc   sta $dc00
.c010  ad 01 dc   lda $dc01
.c013  29 20      and #$20
.c015  d0 f9      bne $c010
.c017  58         cli
.c018  60         rts

[edit] Keyboardrequest in BASIC

  • With the BASIC-Command INPUT:
10 INPUT "Write here something"; A$
20 PRINT "You write: "; A$

Remark: The keyboard input must be a confirmation by pushing the key <RETURN> to continue the program. The keyboard input is saved after the input in variable A$.

  • With the BASIC-Command GET:
10 PRINT "Push a key, please:": A$ = ""
20 GET A$: IF A$="" THEN 20
30 PRINT "You push: "; A$

Remark: The keyboard input occurs key by key. Control and function keys work, too, but the screen output isn't always correct.
When no key is pressed the variable A$ gets an empty char string. For simulation a wait mode must be checked A$. Then A$ is empty, the program must be jumping to the command GET.

  • With the BASIC-Command PEEK:
10 PRINT "Push a key, please:": T = ""
20 T = PEEK(197): IF T=64 THEN 20
30 PRINT "You push the key <"; CHR$(T) ;"> with the keycode: "; T

Remark: The keyboard input is occur key by key with reading the memory adress 197 ($00C5).
Then not a key is pushing, is the confirmation value 64. After that (for the wait mode) must be jumping to the command PEEK.
Control and function keys can clicking, too. The screen output isn't correct, but the keycode is correct.

[edit] PEEKs & POKEs


POKE 650,128 activate the autorepeat by pushing a key for a longer time
POKE 650,0 deactivate this function.


POKE 649,0 blocks the keyboard, because the keyboard puffer has got the length 0
POKE 649,10: POKE 808,237 deactivate the lock.


POKE 655,71 change the pointer of the keyboard codetable; now keyboardlock
POKE 655,72 deactivate the lock


POKE 56322,224 deactivated the keyboard, because the pointer of the CIA 1 is changed. This POKE is using for the joystickscans.
POKE 56322,255 activated the keyboard.

or by deactivation the interrupt (exception: <RUN/STOP>+<RESTORE>) or ports.

Deactivate separate keys:

  • <RUN/STOP>: Off: POKE 788,52 - On: POKE 788,49
  • <RESTORE>: Off: POKE 792,193 - On: POKE 792,234

Keyboardcache: In the memory adresses 631-640 is the keyboardchache (puffer). It has got a cache for 10 chars and be by using PEEK read off or by using POKE simulat keyboard input. POKE 198,0 cleared the keyboard chache.

[edit] Links

WP-W11.png Wikipedia: Keyboard_(computing)
Personal tools
In other languages