Software-switchable KERNAL on the C128

by Marko Mäkelä (Marko.Makela@FTP.FUNET.FI)

My dream finally came true, when I got a 27256 EPROM with the image I had prepared a long time ago. In the top half, it has a specially modified JiffyDOS KERNAL for the C128, with the Swedish/Finnish version of the editor. In the bottom half, it basically has the stock Commodore 128 KERNAL with some modifications.

The flat (not cost-reduced) C128 and the C128D (plastic case) have the C128 mode KERNAL in one 27128 EPROM (16 kilobytes). The BASIC interpreter is in two 23128 ROMs or 27128 EPROMs, and the C64 mode KERNAL and BASIC are on one 23128 or 27128. The C128DCR and the C128CR have only two 23256 ROMs or 27256 EPROMs (32 kilobytes). This hack is also applicable to them, but you will need to use 27512 EPROMs and address line A15 instead of A14.

I want that my C128D looks completely original. Adding switches for disabling my self-built 1-megabyte RAM expansion or for disabling custom ROMs is out of question. Everything must be controllable by software.

C64 mode

The C64 mode ROM was quite easy. Burn a 27256 with the old 27128 contents so that the original contents comes to the bottom part (A14=0) and the new, custom contents comes to the top part (A14=1). Then lift A14 (pin 27) from the socket and connect it to the 40/80 line on the MMU (pin 48), and you're all set. If you want the stock ROM in the C64 mode, either push the 40/80 key down on the keyboard, or turn off the 40/80 line in $d505 when switching to C64 mode:
lda #$3e
sta $ff00
lda #$77
sta $d505
jmp ($fffc)

C128 mode

The C128 mode ROM is slightly more difficult. I chose to use the -GAME line, because -EXROM is used by many cartridges. Of course this requires that the check for -GAME or -EXROM in the boot-up routines must be disabled. With this modification, the computer won't automatically switch to C64 mode when a cartridge is inserted. That's very practical if you don't always want to remove your freezer cartridge, or if you want to copy C64 cartridges. (You can still automatically switch to C64 mode by using a boot sector.)

Burn the original ROM to the low part and the custom ROM to the high part. Bend up A14 and connect it to the MMU's -GAME pin (45). If you want to boot the original ROM, just use the following code:
lda #0
sta $ff00
lda #$87
sta $d505
jmp ($fffc)

Patches

Both ROM banks will require these patches. The addresses are in hexadecimal, counted from the EPROM's base address ($c000 in the C128's memory space).

First, the -GAME and -EXROM check in the Z80 BIOS:
< 1050: e6 30 28 05 3e f1 ed 79 c7 01 0f dc 3e 08 ed 79
> 1050: e6 30 18 05 3e f1 ed 79 c7 01 0f dc 3e 08 ed 79

Then, the (redundant) -GAME and -EXROM check in the C128 KERNAL:
< 2240: ff 60 ad 05 d5 29 30 c9 30 f0 20 a9 e3 85 01 a9
> 2240: ff 60 ad 05 d5 a9 30 c9 30 f0 20 a9 e3 85 01 a9

In addition, the lower bank will need the following patch to the MMU initialization table. This will initialize -GAME and -EXROM to zero (so that you can use -GAME or -EXROM as the EPROM bank selection line):
< 2050: bf 04 00 00 01 00 a2 73 a0 e0 18 86 c3 84 c4 a0
> 2050: 8f 04 00 00 01 00 a2 73 a0 e0 18 86 c3 84 c4 a0