Skip to content

RetroMake / hardware

How the Commodore 64 hides 20K of ROM inside 64K of RAM

by The RetroMake desk 26 October 2026

Three control lines on the 6510 and one custom logic chip decide, address by address, whether the processor sees memory, firmware or the chips that draw and sing. Here is the map, the switch that rearranges it, and the tricks it made possible.

verified 26 Oct 2026. 1314 words.

Every Commodore 64 advertisement led with the number in its name, and the number was honest: the machine shipped with 64 kilobytes of dynamic RAM, eight 4164 chips, at a time when its rivals offered 16 or 48. The number that mattered to anyone who programmed it was smaller. Switch the machine on and it reports 38911 BASIC bytes free, which is what remains after the firmware, the video chip, the sound chip and the screen have taken their share of a 6502-family processor's 65536 addresses.

The arithmetic looks impossible. The BASIC interpreter is 8K of ROM. The KERNAL, Commodore's operating system, is another 8K. The character generator is 4K. The registers of the VIC-II video chip, the SID sound chip, two CIA interface chips and the 1K of colour memory need 4K of address space between them. That is 24K of the map spoken for before any RAM is counted, and 64K of RAM besides. It adds up to 88K wanted in a 64K space, and the C64 gives you all of it, just not all at once.

Three bits on the processor

The 6510 that Commodore used is a 6502 with one addition: a six-bit input/output port that lives at addresses 0 and 1, the first two bytes of the zero page. Address 0 sets which bits are inputs and which are outputs. Address 1 carries the bits themselves. Three of them leave the chip on pins and are wired, with the two signals from the cartridge port, into a programmable logic array next to the processor. Commodore's part number for it is 906114-01; it is a mask-programmed equivalent of the Signetics 82S100, a chip with sixteen inputs, eight outputs and a grid of fuses that implements whatever sum-of-products logic the designer burned in.

The three bits are called LORAM, HIRAM and CHAREN. On reset the port reads 55, binary 00110111, so all three are set and the map looks the way the manuals draw it: RAM from 0 to 40959, BASIC ROM from 40960 to 49151, 4K of RAM at 49152, the chip registers at 53248 to 57343, and the KERNAL from 57344 to the top. Clearing a bit removes something. Clear LORAM and the BASIC ROM is gone, replaced by the RAM that was always underneath it. Clear HIRAM and the KERNAL goes too, and because BASIC cannot run without the KERNAL, the PLA takes BASIC away at the same time. CHAREN chooses what the processor sees at 53248: with it set, the chip registers and colour memory; with it clear, the character ROM, which is otherwise reachable only by the video chip.

The eight combinations are worth tabulating, because most of the machine's programming folklore is a row of this table.

Value in address 140960 to 4915153248 to 5734357344 to 65535
55 (default)BASIC ROMI/O chipsKERNAL ROM
54RAMI/O chipsKERNAL ROM
53RAMI/O chipsRAM
52RAMRAMRAM
51BASIC ROMcharacter ROMKERNAL ROM
50RAMcharacter ROMKERNAL ROM
49RAMcharacter ROMRAM
48RAMRAMRAM

Machine-language programmers lived at 53 and 54. Storing 53 in address 1 removes both ROMs and leaves the I/O chips in place, which gives a program 60K of contiguous RAM plus the hardware, as long as it brings its own interrupt handlers, because the KERNAL's are gone with the KERNAL. Storing 52 or 48 removes even the I/O block, and that is the only way to read or write the 4K of RAM that lives under the chip registers. A program that does it must disable interrupts first: if an interrupt arrives while the chips are switched out, the processor fetches its handler address from RAM that nobody initialised.

Writes go through

The PLA's most consequential decision is one that most users never noticed. When the processor reads from an address that currently shows ROM, the PLA selects the ROM. When it writes to the same address, the PLA selects the RAM. ROM cannot be written, so every write lands in the RAM underneath, whatever the map says. Giesel's 2012 analysis of the PLA's equations, made from a chip he read out, shows the read/write line as a term in every ROM select, which is why the behaviour is exact rather than a side effect.

This made a trick possible that would have been a hardware modification on other machines. A program could copy the BASIC interpreter from ROM into the RAM at the same addresses with a simple loop, since reading fetched the ROM byte and writing stored it one layer down, then clear LORAM and run from the copy. The copy was patchable. Speed-up loaders replaced the KERNAL's serial routines this way, and programmers who wanted a modified BASIC did not have to burn an EPROM to get one.

The video chip has its own map

The VIC-II does not share the processor's view. It addresses 16K at a time, selected by two bits in the second CIA, and within that window it sees RAM, with one exception that the PLA arranges on its behalf. In banks 0 and 2, the character ROM appears to the video chip at offsets 4096 to 8191, which is why a freshly started machine can show text at all: the screen lives at 1024, the characters come from the ROM shadow at 4096, and neither needs the processor's CHAREN bit. A program that puts its own character set at 4096 in bank 0 will find the video chip ignoring it, which is the first thing most people learn about redefining characters and the reason so many games keep their graphics in bank 1 or 3.

What a cartridge can do

The two remaining inputs on the PLA come from the expansion port. A cartridge pulls EXROM low to put 8K of its own ROM at 32768, and GAME low as well for a second 8K at 40960 in place of BASIC. Pull GAME low and leave EXROM high and the machine enters the mode Commodore designed for the Japanese MAX Machine, with the cartridge at 57344, most of the RAM gone and the KERNAL with it. Nobody shipped a MAX cartridge in volume, but freezer cartridges used the mode for years: by forcing the map into that configuration for a few cycles they could take control from any running program, which is the whole basis of a freezer.

Why 38911

The last piece of the arithmetic is the number on the start-up screen. BASIC programs begin at 2049, one byte past the 2048 boundary where the zero page, the stack, the screen and the KERNAL's working storage end. They can grow to 40959, the last byte before the BASIC ROM. The difference is 38911. The 4K from 49152 to 53247 is RAM in every configuration and belongs to no ROM, which is why a generation of machine-language routines and the SYS 49152 that started them lived there: it was the one place a program could sit without BASIC overwriting it and without any switching at all.

The design was cheap, which was the point. One custom chip, three bits and a convention about writes turned a crowded address space into a machine that could be a BASIC computer, a game console and a 64K development system depending on what the program chose to see. The PLA ran hot and failed often, and it is still the first suspect when a C64 shows a black screen, but the idea it implemented outlived the chip.