Showing posts with label vice. Show all posts
Showing posts with label vice. Show all posts

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

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.

Monday, September 19, 2022

HIRES for Vic-20 (BASIC 2.0 extension) is READY.

 


The BASIC commands are implemented, small font created, and demonstrations implemented.   Please enjoy this Space War and Omega Race inspired flying ship.

Source, disk image, and more details are on github for Commodore Vic-20 with memory expansion.

BASIC extension command syntax is:

COLOR [foreground[+8][,[background][,[border][,auxillary[,inverse]]]]]

COLOR [foreground[+8]] @ x1,y1 [TO x2,y2]

TEXT

HIRES xresolution, yresolution [,fillbyte]

DELAY jiffies

PLOT COLOR ON|OFF

PLOT [NOT|CLR] (@ x1,y1)|(TO x2,y2)...    **

PLOT 0|1|2|3 (@ x1,y1)|(TO x2,y2)...

PLOT "ABC" @ x,y [,addr [,width,height [,bytes]]]

RECT [NOT|CLR] [@] x1,y1 TO x2,y2

RECT 0|1|2|3 @ x1,y1 TO x2,y2

SHAPE GET|PUT|OR|XOR|AND|NOT|CLR addr @ x1, y1 TO x2, y2


** only first @ optional, when not multi-color

Monday, August 29, 2022

Vic-20 Hi-Res BASIC extension progress

 


Shape operations are functional, and work has begun on leveraging BASIC keyword extensions (borrowing from my own HIRES for C64).

4UPART program listing


While the SYS syntax is implemented, the BASIC keyword work has just begun.

Current vs. Proposed Syntaxes

Source and disk image are on github



Sunday, July 17, 2022

Vic-20 HI-RES in progress - Memory Layout

Vic-20 Graphics Memory Layout

The Vic-20 doesn't have a native graphics mode.  But it can use a character set from onboard RAM, and double the size of character cells from 8x8 to 8x16 pixels.


A solution puts video memory at address 4096 ($1000), and character RAM at ($1000).  Notice they are the same?  Yes, there's only 5K onboard RAM in addition to color RAM.   The first 1K starts at address 0 ($0000), and the other 4K starts at address 4096 ($1000).   Regardless of any other RAM present in the system (can add 35K), only that latter 4K is accessible as video/character RAM to the video chip.  (Even if the earlier 1K is available, there's too many conflicts with BASIC and KERNAL use).

So bitmapped characters (graphics) and video RAM (characters on the screen) have to share the same section of memory.  The way bytes work, at most 256 characters could be displayed on the screen, but that would require a full 4K of RAM for their bitmaps (16*256), so something has to give.   By using only 240 characters on the screen, that reserves 16*16 = 256 bytes for video memory, and the remaining memory can be used for graphics.  For the bitmap to skip over screen memory and avoiding any overlap, the characters used on the screen are indexed starting at 16 ($10).

$1000-$10EF screen (240 bytes), values $10-$FF (16 to 255)
$10F0-$10FF unused (16 bytes)
$1100-$1FFF bitmap (3840 bytes)

BASIC RAM can be moved to either 3K expansion RAM ($400-$FFF) or 8K or greater expansion RAM ($2000 and later).

One layout that is possible is 20 characters wide by 12 characters tall = 240 characters = 160x192 resolution.

The easiest layout of characters is to store them consecutively in memory as shown above.   Character layout for the screen is left to right, then wraps to the next row.   This scheme matches color memory layout as well.   An additional advantage is that time sensitive updates to graphics can be more aligned with the raster line.

Another layout of characters is to line them up vertically as shown below.  This has the advantage that memory is contiguous vertically until advancing to the next column of 8 pixels.   This allows for optimizations in managing graphics memory at the disadvantage of working vertically instead of horizontally, thus fighting the raster line.  But color memory is still horizontally oriented, so the address calculation is different, the same as the earlier layout.

 
As the Vic-20 allows for configuring the number of character columns, character rows, and adjusting top and left margins, a variety of resolutions are possible.

Some notable resolutions include

160x192, 192x160, 200x144, 144x208, 160x160

The last is mentioned as it is the resolution used by the Super Expander cartridge.  But note it only requires 200 bytes of screen memory, so using that resolution leaves 696 bytes of onboard memory unused for graphics/screen that could be available for another use, maybe 506 bytes is still text screen memory. 

Links




Sunday, January 17, 2021

How to Build Vice 3.5 (x64sc, etc.) on Raspberry Pi 400

Raspberry Pi 400


The Raspberry Pi 400 invokes a sense of nostalgia back to the all-in-one systems of the past, such as those commonly available in the 80's (about 40 years ago!) of having the keyboard and computer all in one, with connections at the back of the enclosure, and expansion at the back of the enclosure.

My favorite system released January 1982 was the Commodore 64.

So why not have both?  With emulation, let the Raspberry Pi 400 become a Commodore 64 as well.

Vice 3.5 built, running on Raspian

One way to do this, is using Vice (the Versatile Commodore emulator).  Of course you can use a prepackaged solution like Retropie and Emulation Station.  But since it is open source, you can also just download and build the source yourself.

As vice 3.5 was just released Christmas Eve, 2020, it makes a lot of sense to build yourself, so you can have the latest build relatively easily.  Just think of all those new features!!!

I've attempted this myself on my Raspberry Pi 400 (and expect should work on others fine too) with Raspian.  I've tested with both the latest 32-bit ARM, and beta 64-bit ARM builds.

Following are the steps I took to accomplish building the default configuration.  I followed the basic instructions, and when configuration or build failed due to a dependency, researched the dependencies necessary (thanks Google and all those who have built before me and posted their solutions).  

Grab yourself your favorite beverage, power up your Pi, and get building!   And once you're done, feel free to test my hires.d64 image.  Maybe even pick up some keyboard stickers.   And also can run Pet, Vic-20, Commodore 128, etc.

Summary

  1. Install dependency packages
  2. Download three archives from web: vice 3.5, SDL2, SDL2_image
  3. extract the archives to their respective directories
  4. configure, build, and install each iteratively in the order: SDL2, SDL2_image, vice 3.5
Full Steps (note versions may change, these were the ones available January 2021):

  • sudo apt-get install flex bison xa65 libgtk2.0-dev texinfo libxxf86vm-dev dos2unix libpulse-dev libasound2-dev
  • sudo apt-get install texlive-latex-base texlive-fonts-recommended texlive-fonts-extra texlive-latex-extra