Egghead.page Logo

How Commodore 128 Handles Raster Beam Palette Changes

This article examines the technical process of modifying color registers mid-frame on the Commodore 128. It details the specific hardware components involved, primarily the VIC-IIe chip, and explains how raster interrupts synchronize the CPU with the video beam. Readers will learn about the critical timing constraints, the difference between 40 and 80-column modes, and the necessary CPU speed settings required to execute stable palette changes without visual artifacts.

Understanding the Video Architecture

The Commodore 128 features two distinct video chips, but raster-based palette changes are exclusively handled by the VIC-IIe. This chip is active when the computer is operating in 40-column mode, which is compatible with Commodore 64 software. The 80-column mode utilizes the VDC chip, which does not support dynamic color register changes during the raster beam in the same manner. Therefore, developers aiming to create split-screen effects or color bars must target the VIC-IIe memory map and registers.

Utilizing Raster Interrupts

To change colors at specific vertical positions on the screen, the software must utilize raster interrupts. The VIC-IIe chip generates an interrupt request when the electron beam reaches a predefined scan line. The CPU pauses its current task, executes a specific routine to update the color registers, and then returns to the main program. This synchronization ensures that the color change occurs precisely when the beam is drawing a specific part of the screen, typically during the horizontal blanking interval to avoid visible glitches.

CPU Speed and Timing Constraints

A unique constraint of the Commodore 128 is its dual-speed CPU. The VIC-IIe chip only functions when the processor is running at 1MHz. If the system is switched to 2MHz fast mode, the video chip is halted, and no raster effects can occur. Consequently, any routine handling palette changes must ensure the computer is in 1MHz mode. Furthermore, the code must be cycle-exact, as the VIC-IIe steals memory cycles from the CPU to generate the video signal, requiring precise timing to prevent the raster position from drifting.

Register Modification Techniques

The VIC-IIe provides sixteen color registers that control the background, border, and sprite hues. By writing new values to these memory addresses during the raster interrupt, programmers can create the illusion of more colors on screen than hardware normally allows. Advanced techniques involve changing the background color multiple times per frame to create gradient effects or distinct color zones. Successful implementation relies on minimizing the code within the interrupt routine to ensure the CPU finishes before the beam moves to the next critical section.