Sunday, November 22, 2026

Commodore 128 Keyboard support in 64 Mode via ROM patch

 

Credit: Evan-Amos CC BY-SA 3.0 (unmodified)

The Commodore 128 has an extra 26 keys, with 24 additional keys in the key matrix, and 2 additional keys hardwired inputs to 8502 (Caps Lock) and MMU (40/80 Display or ASCII/DIN).

Unfortunately, these keys are not normally accessible when in Commodore 64 mode -- until now, via KERNAL patches.

To try out, run the program "64MODE PATCH" which copies the BASIC & KERNAL ROMs into RAM, applies patches in RAM, and switches operation to run the ROMs from RAM.   It is expected that extra keys do not work before the patch, and do work after the patch.  Only the numeric keypad and separate cursor keys work with this patch.

Alternatively, the folder 64mode-ROM-patches/ contains two .txt files, one for patching BASIC ROM, and another for patching KERNAL ROM.  For instance, if you are running VICE emulator, there are ROMs in the C128 directory for 64mode: three versions for KERNAL, one for BASIC.  Copy the desired ROM images to new files, and use the xxd command (Linux, BASH git, etc.) to patch them.

WARNING: if you do not make your own copies, xxd will modify the binaries in place without backups.

xxd -r 64mode-BASIC-patch.txt basic64.bin
xxd -r 64mode-KERNAL-patch.txt kernal64.bin

Once you have modified ROM files, you can configure VICE options to use these instead.

It is recommended to try with VICE first.  Then you can use an option like One ROM to apply to real hardware.

How does it work?  There is limited unused bytes in the ROMs, that's why both BASIC and KERNAL are patched.  56 more bytes in the ROMs are used for code to scan the additional 3 rows, and 23 bytes are used to help translate these extra keys back to keyboard scan codes compatible with C64.  Seven keys were not mapped because one is never available to 64 mode (MMU is disabled in 64 mode), and they don't translate well to unshifted or shifted keys.   There are now 2+5=7 additional unused bytes, feel free to try to use these for additional changes.   Good luck!!!

And enjoy access to your cursor keys and numeric keypad!

All the files are on github: c-keymaps project including other keyboard utilities for testing, and remapping the keyboard, including kernal patches to remap all keys (and support for more systems).

Sunday, November 15, 2026

The Return of TypeScript 64 Emulator


I programmed this back in 2020.  It's a port of my Commodore 64 emulator from C++ to TypeScript/Web.  It supports both BASIC and 6502/6510 programs with D64 drive image (drag and drop, read-only).  Live link: https://c64.davevw.com  (recommend scaling window to see it bigger)

But I didn't get the keyboard just right, it was registering keys on release only.  And I didn't know what the fix was.  Well, given six years have now passed, there are some assistants out there that are willing to give it a go for FREE!  So thanks GitHub Copilot for working with me on a Saturday to investigate and solve the issue.   Seems it had something to do with how when yielding from the Web Worker background service that is the heart of this emulator, while keystrokes and UI are in the scope of the web page with a canvas.

Now that it is working well, and my other emulators have progressed with more features, I've ported in some additional fixes and features including relocatable text screens and graphics support (but sorry -- no sprites, no raster interrupts, no multicolor, yet...)

And I've replaced the D64 that it loads at startup with a sampling of all or most of my C64 github projects, and additional programs.

Usage:

Press SHIFT+ESC which will do the equivalent of:

LOAD"*",8

RUN

will display the menu (named 000BOOT), and there are also submenus -- other programs to launch.

Main Menu

Menu of Programs:

000BOOT
    DIRECTORY
    SNAKEPET
    SNAKE64

    KEYBOARD 
        64KEYMAPS.START
        64SCANKEYS.START

    DEMO6502
        BIT
        PHA
        SBC
        ADC
        REVERSE.STARTUP
        DELAY.STARTUP
        POKE BYTES.START
        BANKTEST.STARTUP
        VWAS6502.START
        WOZMON.START

    GRAPHICS
        CH64EDIT
        LOADHIRES.START
        LORES DEMO

    UTILITIES
        SCRLEDIT
        SCRLEDIT2
        EXTRA1K.START
        EXTRA1228.START
        CBMDETECT

    MATH
        INT64
        CALC64

    SLIDES
        SESSION1A-64
        SESSION1B-64
        SESSION2-64
        SESSION3-64

    THERAPYV2
    RANDOM
    SPEEDTEST

Commodore Logo in high resolution

Note for a link to the source, you can press F9 and then click on the link.

And because the screen is drawn on a canvas, you can right click and save the image as a whopping pixel perfect 320x200 png regardless of how you've scaled it.

And one more thing... since it is not cycle accurate and attempts to run 6510 code flat out, it turns out to run approximately 24MHz on my fairly modern PC.  Your speed will vary, could be much faster.

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, hint: recommend use of One ROM) 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 (hint: One ROM) 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

Saturday, October 24, 2026

My Survival Guide to using a Commodore 64 today

Are you using a Commodore 64 keyboard and disk drive today?  I try to, and I can't live without some combination of the following.  (Self-promotion disclaimer - I created software for 1 & 2)

1. Remap the keys to match my PC keyboard muscle memory

  • patch your KERNAL ROM (physically, virtually, or run in RAM)
    hint: use One ROM for replacing (and electronically switching) physical ROMs
  • run a software keyboard remap driver (pre-built, or edit your own mappings)
  • use positional keyboard mapping if using an emulator

2. scroll through program listings and make editing on the C64 more enjoyable

  • SCRLEDIT Scrolling BASIC Editor original January 1988 Compute!'s Gazette, and updated
  • SCRLEDIT2 Scrolling BASIC Editor updated 2025, more features, different keystrokes

    (note: not currently compatible with remap driver because of the way they sit in memory and hook the keyboard table vector for key presses.)

3. Use microSD or similar solution to managing disk images and files instead of floppies

  • SD2IEC
  • Pi1541
  • Or a modern C64 replacement (Commodore 64 Ultimate, Ultimate64, TheC64)
  • Many emulated C64 solutions support drive images, and host directories (e.g. VICE)

Patch Commodore 64 KERNAL ROMs to remap keyboard

Punctuation remapped Commodore 64 keyboard layout

I have presented software and drivers to remap the Commodore 64 keyboard before.  But those solutions install into lower BASIC RAM at a fixed location, and disappear when you restart your computer.

Because the KERNAL ROM stores the keyboard mappings (4 maps: Normal, Shift, Commodore, and Control), if you can replace the ROM, you can remap the keyboard.

Here I present a new program of mine: 64KEY ROM PATCH (PRG) added to c-keymaps project.

This program will find where the keyboard mappings are, and with a patch list (DATA statements) containing shift mask, key scan code, and PETSCII character, will patch the ROM into RAM with changes and activate the ROM.

From here, you have some choices.  You can use the program on demand as is, or make the change more permanent.

For those with physical machines, there are already processes for replacing your ROMs.  You can search for them.  Now that the ROM is in RAM, you can figure out how to save to a file, transfer to your PC, and flash a ROM replacement to insert into your C64.   This change is semi-permanent in that the keyboard mapping will be there as long as the new ROM (usually EEPROM) is in place.

If you have a ROM switcher capability (Easy Flash 3), or a toggle switch allowing physical switching between multiple ROMs (may be piggy backed with a toggled chip select), then you change on the fly.  (Hint: use of One ROM is recommended).

And if you run an emulator, you can save the patched ROM into your collection of C64 ROMs and choose it as your current ROM.

The BASIC program includes the following maps (effect is shown in the screenshot above):

300 rem patch table
310 rem shift,scancode,petscii
320 data 0,40,45:rem + to -
330 data 0,43,61:rem - to =
340 data 0,46,91:rem @ to [
350 data 0,49,93:rem * to ]
360 data 0,54,92:rem ^ to \
370 data 0,45,59:rem : to ;
380 data 0,50,39:rem ; to '
390 data 0,53,13:rem = to return
391 :
392 data 1,59,64:rem " to @
393 data 1,19,94:rem & to ^
394 data 1,24,38:rem ' to &
395 data 1,27,42:rem ( to *
396 data 1,32,40:rem ) to (
397 data 1,35,41:rem shift 0 to )
398 data 1,40,95:rem shift + to l.arrow
399 data 1,43,43:rem shift - to +
400 data 1,53,141:rem shift = to s.ret
401 data 1,45,58:rem shift : to :
402 data 1,50,34:rem shift ; to "
408 data 1,57,221:rem shift _ to v.bar
409 data 2,57,219:rem cbm _ to cross

More detailed instructions are available.

Sunday, October 18, 2026

Commodore Programmer's Keyboard References

Commodore 128 scan codes

Composite Commodore 64 and 128 keyboard references

Composite Commodore plus/4 and 16 keyboard references

Vic-20 keyboard references


The programs are

  • 64keymaps.prg
  • 128keymaps.prg
  • +4keymaps.prg
  • 16keymaps.prg
  • 20keymaps.prg
These and more are available at the following:

Link: https://github.com/davervw/c-keymaps

C64 keyboard remapper, these keymap displays, and related utilities

Friday, October 9, 2026

Commodore BASIC .TXT listing out and in


This image shows a quick-reference for how to LIST out to a file, and have BASIC type in a listing from a file.  This is not original work except for fixing the port to plus/4 and similar.

Links:

(plus/4,16,116 version is a careful and thoughtful port of the sx64.net version, meaning AI Gemini tried really hard, but kept getting confused by C64 knowledge.  AI got the 2035 and 810 addresses right, but I had to research the values to poke.  Informing AI of the correction, it kept trying to supplement the answer getting it more wrong, so I put an end to that!)