Sunday, October 25, 2026

Patch Commodore KERNAL ROMs to permanently remap keyboard

Figure 1. Result: ROM patch statements for C128


Already there is a solution for Commodore 64 systems including patching ROMs into RAM in real-time, in addition to building a patch file for making your own ROM (e.g. physical EPROM) or file for emulator.

With a few more additions, the following platforms are also supported for EPROM or emulator .bin file:

  • 128
  • plus/4 or 16 (264 series)
  • Vic-20
All of these, plus the 64 are now supported via c-keymaps on github.

(Alternatively drivers are supported in the same project for 128 and Vic-20 for remapping in real-time, using additional system resources, which also allows remapping of the Alt keymap for 128)

Figure 2. Source: C128 DATA statement specifying keymap patches


Directions for patching a ROM.
  1. LOAD the appropriate rom patch file for your system from the files folder, or drive image. You MUST match your system exactly.
    • 64KEYS ROM PATCH
    • 128KEY ROM PATCH
    • TEDKEY ROM PATCH
    • 20KEYS ROM PATCH
  2. LIST the program, and review the keyboard mapping included in DATA statements in the file, refer to keyboard table references for key scan code numbers of your system, and verify the layout changes you desire.
  3. RUN the program
  4. Transfer the patch statements to your modern system.  These are a series of hex offsets, followed by colon, followed by one or more hex bytes.   The offsets have the ROM starting address subtracted, so they are offsets from the start of this individual ROM (see figure 1).
  5. Get an original KERNAL ROM file (image your own ROM, or download from zimmers.net, or copy from VICE emulator).
  6. Make a copy of the KERNAL ROM .bin image file, and name it appropriately anticipating the patch being performed.
  7. Verify the size of the KERNAL ROM file
    • C64: 8K
    • C128: 16K
    • plus/4: 16K
    • C16: 16K
    • Vic-20: 8K
  8. Patch with xxd
    xxd -r patch.txt new.bin
  9. Transfer the file into an EPROM or equivalent compatible for physical system only
  10. Install the physical EPROM into your physical system, or binary file into your emulator (VICE system settings)
  11. Enjoy!
Note: recommended to test your patches on an emulator first (or Commodore 64 in RAM patches, compatible with the most critical C128 keys), especially if not on a C64/128.   The debug/test cycle is faster with an emulator.  And consider whether your mapping is best suited for positional or symbolic keyboard mapping in the emulator.  If you prefer physical machines, use the emulator temporarily, or skip it, and good luck! (It took me over 5 iterations to get it right for the Vic-20.)

You may also have your Commodore save all output of the running program to a .txt file so you can transfer to your computer and extract the patch statements. Note: do not use RUN because it will close the file, use the first statement, and be sure to include CLR first so variables are reset, uninitialized.
CLR:OPEN1,8,3,"PATCH.TXT,S,W":CMD1:GOTO100
When done, be sure to close up
PRINT#1:CLOSE1

No comments:

Post a Comment