System information

On the Commodore 64, address $00CB is used to read which key that has been pressed for most keys on the
keyboard. On the Commodore 128, it is instead address $00D4 that is used for this purpose. The coding of which
key that has been pressed is not the same for the Commodore 128 as for the Commodore 64. The value for "no
key pressed" also differs. Furthermore, the Commodore 128 has more keys than the Commodore 64. The easiest
way to see which value that corresponds to a certain key is to keep a key pressed and read the value of $00D4.
On the Commodore 64, address $028D is used to read whether SHIFT (SHIFT-LOCK), C= or CTRL has been
pressed. The corresponding address on the Commodore 128 is $00D3. On the Commodore 128, there are two
more bits that are used for the ALT and CAPS LOCK keys. CAPS LOCK is replaced by ASCII/CC on Swedish
keyboards and ASCII/DIN on German keyboards. (CAPS LOCK/ASCII CC/ASCII DIN can also be read through bit
6 at address $01).
The 40/80 DISPLAY key can be read from bit 7 in register $D505 (an MMU register). On both the Commodore
128 and the Commodore 64, NMI (Non Maskable Interrupt) is used to detect that the RESTORE key has been
pressed.
The extra keys on the Commodore 128 keyboard can be used also in Commodore 64 mode as is shown in this
assembly code example .
On the Commodore 128, it is possible to change the key definitions, i.e. you can define which Commodore ASCII
character (0-255) that a press of a certain key on the keyboard should result in. For international keyboards,
there are four key definition tables in the Kernal; one normal (also used when ALT is pressed), one when SHIFT
is pressed, one when C= is pressed and one when CTRL is pressed. If you have a national keyboard (with an
ASCII/CC or ASCII/DIN key instead of a CAPS LOCK key), there are three additional tables that are used when
the ASCII/CC or ASCII/DIN key is pressed; one normal, one when SHIFT is pressed and one when C= is pressed.
When CTRL or ALT is pressed, the same tables are used no matter if the ASCII/CC or ASCII/DIN key is pressed
or not so there are no additional CTRL or ALT tables in the Kernal for national keyboards. The tables are located
between $FA80 and $FBE3.
For international keyboards, there are five vectors that point to the start of the corresponding key definition
tables; one normal, one when SHIFT is pressed, one when C= is pressed, one when CTRL is pressed and one
when ALT is pressed (the one when ALT is pressed points to the same memory location as the normal one).
These vectors are located at $033E-$0347. If you have a national keyboard, there is one additional vector at
$0348-$0349 that points to the normal key definition table when the ASCII/CC or ASCII/DIN key is pressed. For
national keyboards, the Kernal at interrupt level checks whether the ASCII/CC or ASCII/DIN key is pressed or
not. When it detects that the key has been pressed, it uses the vector at $0348-$0349 instead of the vector at
$033E-$033F for the normal keyboard definition table. Furthermore, it uses the same vectors as before for SHIFT
and C= but it changes the values of the vectors so that they point to the national keyboard definition tables for
SHIFT and C=. The values of the CTRL and ALT vectors are kept the same as before.
If you want to change key definitions, then copy one or more tables to RAM memory without any overlying ROM
memory (by default, this means a memory location with an address lower than $4000). Then, modify entries in
the table(s) and change the vector(s) to point to the table(s) in RAM. If you have a national keyboard and the
ASCII/CC or ASCII/DIN key is not pressed, you have to disable the Kernal check of whether the ASCII/CC or
ASCII/DIN key has been pressed or not. Otherwise, the Kernal will just overwrite the values you have written to
the vectors at the next interrupt. You do the disabling by setting bit 7 in the memory location at address $0AC5
equal to 1. One side effect of doing this is that if you do it when the ASCII/CC or ASCII/DIN key is not pressed
and afterwards press the key, you will get the same effect as when pressing the CAPS LOCK key on an
international keyboard, i.e. letter keys will be SHIFTed while numbers will not be SHIFTed.
I have got information about changing key definitions from appendix J of Commodore 128 Bedienungshandbuch
(there you can find the addresses of the key definition tables but one vector is missing and disabling of Kernal
check for ASCII/DIN key is also missing) and from chapter 7 "Rund um die Tastatur" in Commodore 128 Tips &
Tricks (the addresses of the key definition tables are wrong in this book). Since both of these books are a bit
erroneous and contradictory to each other regarding this functionality, I have also had to experiment myself to
see how it really works. Please note that this information does not exist in Commodore 128 System Guide (which
is the English equivalent of Commodore 128 Bedienungshandbuch) nor does it exist in Commodore 128
Programmer's Reference Guide/Das C128 Buch. Commodore 128 Bedienungshandbuch is not a direct translation
of Commodore 128 System Guide from English to German. There is a big difference in the contents. Personally, I
think Commodore 128 Bedienungshandbuch contains much more detailed information than Commodore 128
System Guide. For example, in Commodore 128 Bedienungshandbuch, there is detailed information about
memory management and CP/M is described in much detail along with all CP/M commands in a separate book.
2 MHz mode
The system clock frequency for the Commodore 64 and the Commodore 128 normally is 1 MHz (slightly less or
more depending on if it is a PAL or an NTSC machine). On the Commodore 128, there is a possibility to double
the clock frequency to 2 MHz.