Separate the three addresses before choosing a region
Suppose the survey needs a table of tile properties. The C64 has RAM at $e000, but the default CPU mapping shows KERNAL ROM there. Put the table and its reader together in that RAM, and keep console calls in resident code where KERNAL remains visible.
| Address | What it controls | In this program |
|---|---|---|
| PRG load | Where the loader puts the image. | $0801, including a BASIC stub. |
| Program entry | Where the stub transfers control. | $1000, where startup begins. |
| Placed section run | Where the CPU uses the bytes after startup. | $2000 for direct code and $e000 for the copied section. |
A raw image can omit the BASIC stub. Its loader must transfer control to the declared entry. See the raw-entry example when building for a host that supplies that transfer.
Place the reader beside the table
Declare where it runs
region hidden_code: c64 at 0xe000 size 0x0100
bank .ram_under_kernal;
placement hidden in hidden_code load .startup_copy;
Declare what goes there
const hidden_values linksection("hidden") = [_]u8{ 0x21, 0x42, 0x63 };
fn hiddenLookup(index: u8) linksection("hidden") u8 {
return hidden_values[index];
}
Startup copies the bytes to RAM under ROM. When resident code calls hiddenLookup(1), a generated gateway exposes that RAM, calls the reader, then restores the CPU mapping while keeping the result. Predict $42 from the second table element. The complete program also calls a visible function placed directly at $2000 and uses a separate near arena.
Expect PLACEMENT ARENA OK. Open the generated .zpmap.json and find memory_placements. The direct section has matching load and run addresses. The hidden section loads with the resident image and runs at $e000. Read your build's map for the exact load address.
Keep the banking and zero-page contracts separate
Banking changes what the CPU sees at addresses such as $e000. Zero-page policy governs the low 256 bytes, where the compiler, firmware, and your assembly may all need scratch space. Name each reservation where you declare the memory plan.
Try reading hidden_values[1] directly from the resident main in place of the call. The compiler rejects the access because the resident mapping would see ROM. Restore the call and keep console output outside the hidden reader.
In the separate reservation exercise, use a .kernal zero-page profile and reserve $30–$31. The program saves the previous byte before borrowing it and restores it after the operation. Compare reserved_ranges and claims in the map. Expect INPUT AND STORE 81D4.