Egghead.page Logo

How Did the Commodore 64 Use Bank Switching for Memory?

The Commodore 64 is renowned for its 64 kilobytes of RAM, but accessing this memory required sophisticated management due to the limitations of its processor. This article explores the technical mechanisms behind the C64’s memory architecture, specifically focusing on how bank switching allowed the system to map different combinations of RAM and ROM into the same address space. Readers will learn about the 6510 CPU’s role, the function of the memory configuration register, and how these techniques enabled the computer to exceed standard addressing limits.

The foundation of the Commodore 64’s memory management lies in the MOS Technology 6510 microprocessor. Like many processors of its era, the 6510 features a 16-bit address bus, which theoretically allows it to address 65,536 bytes, or 64 kilobytes, of memory. However, the Commodore 64 physically contained more than just 64KB of random-access memory. The system included the main RAM, the BASIC interpreter ROM, the Kernal operating system ROM, and character generator ROM. To fit all these components into the 64KB addressable space, Commodore engineers implemented a bank switching scheme controlled by the processor’s built-in I/O port.

At the heart of this system is the memory configuration register located at address $0001. This register contains bits that control the visibility of different memory blocks in the upper address space, specifically between $A000 and $FFFF. By changing the values in this register, the computer could swap ROMs out and RAM in, or vice versa. For example, when a user powered on the machine to write a program in BASIC, the system mapped the BASIC ROM and Kernal ROM into the upper memory range. This allowed the CPU to execute the operating system and language interpreter directly from ROM.

Conversely, when running high-performance games or applications, developers often needed full access to the underlying RAM for speed and flexibility. ROM is generally slower to read than RAM, and the memory occupied by ROM could not be used for storing dynamic game data. By toggling the bits in the $0001 register, software could hide the BASIC and Kernal ROMs, replacing them with RAM in the address map. This process, known as banking out the ROMs, gave programs access to the full 64KB of RAM for graphics, sound data, and machine code routines.

This flexibility extended to the I/O area as well, located between $D000 and $DFFF. This range could be configured to show the I/O chips for video and sound, the character generator ROM, or plain RAM. This specific bank switching capability was crucial for advanced graphics techniques. Developers could write custom character sets or sprite data directly into RAM and map it into the visible address space when the video chip needed to fetch it, allowing for smooth animation and custom fonts without hardware modifications.

While the internal bank switching managed the primary 64KB address space, the Commodore 64 also supported external memory expansion through the RAM Expansion Unit (REU). The REU utilized a different form of bank switching that operated via Direct Memory Access (DMA). This allowed the system to transfer data between the main memory and the expansion RAM without tying up the CPU. Although the CPU could not directly execute code from the REU, this method effectively broke the 64KB barrier for data storage, enabling larger documents and more complex software environments.

The ingenuity of the Commodore 64’s memory architecture lies in its ability to maximize limited hardware resources. Through the strategic use of the $0001 register and careful mapping of ROM and RAM, the system provided both the stability of built-in software for casual users and the raw memory access required by programmers. This bank switching technique ensured that the Commodore 64 remained versatile throughout its lifespan, supporting everything from simple BASIC education tools to complex commercial software that pushed the hardware to its absolute limits.