Move, compare, fill, and swap bytes
A C64 pointer addresses the CPU's 64 KiB address space. A far address names a byte in the REU. The REU controller moves bytes between the two spaces using DMA. The CPU can then read the copied bytes in ordinary C64 RAM.
Use ZeroPage.reu.present() before a transfer on a machine where the REU may be absent. Configure the emulator with a 16 MiB REU for the examples in this guide. On hardware, check that every configured range fits the installed capacity. Presence alone gives no capacity guarantee.
| Call | What changes |
|---|---|
copyC64ToReu(c64_addr, reu_addr, len) | The REU receives the bytes. |
copyReuToC64(reu_addr, c64_addr, len) | The C64 destination receives the bytes. |
compare(c64_addr, reu_addr, len) | Returns whether the ranges match. Both ranges keep their contents. |
fill(reu_addr, value, len) | Writes the same byte into every position in the REU range. |
swap(c64_addr, reu_addr, len) | Exchanges the contents of both ranges. |
The raw far address is a compile-time value from 0x000000 to 0x00ffffff. The C64 address and byte count accept supported runtime expressions. Supply a nonzero byte count. The REU interprets a zero count as a 64 KiB transfer. The compiler rejects a literal zero. Check a runtime count before issuing DMA.
const c64 = @import("c64");
const ZeroPage = @import("ZeroPage");
memory {
region scratch_reu: reu at 0x010000 size 16;
}
export fn main() void {
c64.console.clear();
if (ZeroPage.reu.present() == true) {
const source: [*]volatile u8 = @ptrFromInt(0x0500);
const result: [*]volatile u8 = @ptrFromInt(0x0528);
source[0] = 0x11;
source[1] = 0x22;
ZeroPage.reu.copyC64ToReu(0x0500, 0x010000, 2);
ZeroPage.reu.copyReuToC64(0x010000, 0x0528, 2);
if (ZeroPage.reu.compare(0x0528, 0x010000, 2)) {
ZeroPage.reu.fill(0x010000, 0x55, 2);
ZeroPage.reu.swap(0x0528, 0x010000, 2);
if (result[0] == 0x55 and result[1] == 0x55 and
ZeroPage.reu.compare(0x0500, 0x010000, 2))
{
c64.console.print("REU TRANSFER OK\n", .{});
c64.vic.border = 5;
} else {
c64.console.print("REU SWAP FAILED\n", .{});
c64.vic.border = 2;
}
} else {
c64.console.print("REU COPY FAILED\n", .{});
c64.vic.border = 2;
}
} else {
c64.console.print("ENABLE AN REU\n", .{});
c64.vic.border = 2;
}
}
The example first copies 11 22 through the REU and checks the result. It then fills the REU range with 55 55 and swaps it with the result buffer. The C64 result now holds 55 55, and the REU again holds 11 22. Expect REU TRANSFER OK.
The scratch_reu declaration records the range in the program's memory map. A raw DMA call still uses the address supplied at its call site. Keep raw transfers within the ranges you own, away from far arenas, DLL caches, and saved state. Transfer and compare assertions · Literal zero-count diagnostic
Choose an REU size from the addresses you use
For each fixed region, add its size to its base. The sum is the exclusive end, so the expansion must have at least that many bytes. Use the greatest end across raw transfers, far arenas, module caches, and saved-state ranges. An REU that answers the presence check can still be too small for a particular address.
| Example | Highest exclusive end | Smallest tested VICE setting for this layout |
|---|---|---|
| Bounded DMA | $010008 | 128 KiB |
| Artwork and mutable state | $021004 | 256 KiB |
| Score updater and DLL cache | $032000 | 256 KiB |
The linked commands use 16 MiB so they work across the whole guide. To reproduce the smaller configurations above, replace -reusize 16384 with -reusize 128 or -reusize 256 for the matching example. The original smoke demo touches $100000 through $100002, beyond a 1 MiB address range. On physical hardware, choose a layout that fits the installed unit before running any transfers. The compiler validates layouts against the address space, and the program owns the installed-capacity assumption.
Check the transfer length before starting DMA
When a count comes from input or a calculation, check both ends before touching the REU. The example gives the source and destination eight bytes each. It rejects 0 and 9, then copies exactly three bytes. The fourth byte stays zero. For a transfer starting partway through either range, check the count against the remaining capacity of both ranges.
const c64 = @import("c64");
const ZeroPage = @import("ZeroPage");
memory {
region pattern: reu at 0x010000 size 8;
region output_row: c64 at 0x9000 size 8;
}
fn fetch(count: u16) bool {
if (count == 0 or count > 8) {
return false;
}
ZeroPage.reu.copyReuToC64(0x010000, 0x9000, count);
return true;
}
fn check() bool {
const output: [*]volatile u8 = @ptrFromInt(0x9000);
output[0] = 0;
output[3] = 0;
ZeroPage.reu.fill(0x010000, 0x55, 8);
const empty = fetch(0);
const too_large = fetch(9);
const stayed_empty = output[0] == 0;
const copied = fetch(3);
return empty == false and too_large == false and stayed_empty and
copied and output[0] == 0x55 and output[2] == 0x55 and output[3] == 0;
}
export fn main() void {
c64.console.clear();
if (ZeroPage.reu.present() == false) {
c64.console.print("ENABLE AN REU\n", .{});
} else if (check()) {
c64.console.print("BOUNDED COPY OK\n", .{});
c64.vic.border = 5;
} else {
c64.console.print("BOUNDED COPY FAILED\n", .{});
c64.vic.border = 2;
}
}
Expect BOUNDED COPY OK. The four bytes starting at $9000 are 55 55 55 00. This uses ordinary visible RAM and the standard I/O mapping for the REU registers at $df00–$df0a. The raw helpers program those registers directly. They do not select a ROM bank for a buffer or validate its extent against the map. Keep staging in visible RAM unless the calling code explicitly provides and verifies a different mapping.
The older 33_reu_copy_smoke demo exercises a far address above one MiB's last byte. The bounded copy here uses $010000. Match the highest address touched to the actual expansion size. Original high-address copy demo · Rejected runtime far address · Raw transfer reference
Allocate far bytes without choosing an address at each call
A far arena carves allocations out of a named REU region. A successful allocation gives you a FarBytes handle. The handle identifies the allocation and carries its length. Use copyFromC64 and copyToC64 to move bytes using the handle's base address. Keep the transfer length within the allocation and the C64 buffer. The copy still takes an explicit byte count.
const maybe_far = assets.allocBytes(2);
if (maybe_far) |far| {
ZeroPage.reu.copyFromC64(far, 0x0500, 2);
ZeroPage.reu.copyToC64(far, 0x0528, 2);
}
The first argument stays far in both handle-based operations. Read the verbs from the handle's point of view: copyFromC64 writes the handle's range, and copyToC64 reads it. When the arena is exhausted, allocation returns null. Reset reclaims the entire arena. Finish using its handles and views before resetting. There is no per-allocation free for a far arena.
Use this approach for raw data such as a tile map or a collection of fixed-size blocks. Use a typed view when you need to read and replace individual records. Complete far arena copy demo · Exhaustion, reset, and independent arenas · Rejected far pointer dereference
Allocate and update rich records
Allocate @sizeOf(Enemy) * count bytes and bind the handle to the record type and a compile-time count with ZeroPage.reu.view. Initialize the records you plan to read. The view supports 1–255 records of 1–255 bytes each. view.len reports the number of records. The compiler checks literal indexes. Keep runtime get and set indexes within the view yourself.
The example stores nested coordinates, a word score, an enum, and a fixed patrol array. A typed get or set transfers one record through compiler-owned staging. Supported layouts include scalar and enum fields, nested records, and fixed scalar or enum arrays. Pointer, optional, union, string, and array-of-record fields are outside the far-record subset.
const c64 = @import("c64");
const ZeroPage = @import("ZeroPage");
const Team = enum(u8) { red = 1, blue = 2 };
const Position = struct { x: u8, y: u8 };
const Enemy = struct {
hp: u8,
score: u16,
team: Team,
pos: Position,
patrol: [2]u8,
};
memory {
region work_ram: c64 at 0x9000 size 0x0010;
region asset_ram: reu at 0x010000 size 0x0100;
arena scratch in work_ram;
arena assets in asset_ram;
}
export fn main() void {
c64.console.clear();
if (assets.allocBytes(@sizeOf(Enemy) * 3)) |far| {
var enemies = ZeroPage.reu.view(Enemy, far, 3);
enemies.set(1, Enemy{
.hp = 9,
.score = 0x1200,
.team = .blue,
.pos = Position{ .x = 12, .y = 3 },
.patrol = [_]u8{ 4, 8 },
});
enemies.set(2, Enemy{
.hp = 4,
.score = 0x2300,
.team = .red,
.pos = Position{ .x = 6, .y = 7 },
.patrol = [_]u8{ 2, 5 },
});
if (enemies.materializeRange(scratch, 1, 2)) |local| {
var enemy = local.get(0);
enemy.hp -= 2;
enemy.score += 1;
local.set(0, enemy);
enemies.flushRange(1, local);
scratch.reset();
const saved = enemies.get(1);
const untouched = enemies.get(2);
if (saved.hp == 7 and saved.score == 0x1201 and saved.team == .blue and
saved.pos.x == 12 and saved.patrol[1] == 8 and untouched.score == 0x2300)
{
c64.console.print("REU RECORDS OK\n", .{});
c64.vic.border = 5;
}
}
}
assets.reset();
}
Expect REU RECORDS OK. The working arena is 16 bytes. The two 8-byte records at indexes 1 and 2 fit. The whole three-record view would require 24 bytes.
Materialize, edit, flush, reset
materializeRange(scratch, 1, 2)reserves space in a named near arena and copies far indexes 1 and 2 into local indexes 0 and 1. The range count is a compile-time literal. A supported runtime start is allowed.local.getandlocal.setaccess C64 RAM. Edits to the near view leave the far records unchanged until a flush.flushRange(1, local)writes the local range back starting at far index 1. Reset the near arena only after the final flush and after you are done with all its live views.- Check results with a fresh far
get. Reset the far arena when its handles are no longer needed.
When the whole table fits in C64 RAM, materialize(scratch) and flush(local) move all records at once. Whole-view flush requires a near view of the same record type and count. Range flush uses the near view's count and the supplied far start. For a runtime start, preserve the value that succeeded during materialization. The flush emitter checks literal starts, so your code must keep a runtime destination in bounds.
Materialization needs a named near arena and the static-frame subset. Copying a range once can avoid a DMA setup for each record access in a loop. The tradeoff is temporary C64 RAM and the cost of copying every record in the range. If you only read one record, a far get keeps that working memory small. If you make no edits, skip the write-back and reset the arena when the near view is no longer needed.
const c64 = @import("c64");
const ZeroPage = @import("ZeroPage");
const Enemy = struct {
hp: u8,
x: u8,
score: u16,
};
memory {
region main_ram: c64 at 0x9000 size 32;
region assets_ram: reu at 0x010000 size 0x0100;
arena near_heap in main_ram;
arena assets in assets_ram;
}
export fn main() void {
c64.console.clear();
c64.console.print("FAR MATERIALIZE\n", .{});
const maybe_far = assets.allocBytes(@sizeOf(Enemy) * 2);
if (maybe_far) |far| {
var enemies = ZeroPage.reu.view(Enemy, far, 2);
enemies.set(0, Enemy{ .hp = 3, .x = 4, .score = 0x1234 });
enemies.set(1, Enemy{ .hp = 5, .x = 6, .score = 0x3456 });
if (enemies.materialize(near_heap)) |local| {
const enemy = local.get(0);
local.set(0, Enemy{ .hp = enemy.hp + 2, .x = enemy.x + 2, .score = enemy.score + 1 });
enemies.flush(local);
near_heap.reset();
}
const loaded = enemies.get(0);
if (loaded.hp == 5 and loaded.x == 6 and loaded.score == 0x1235) {
c64.console.print("FLUSH OK\n", .{});
c64.vic.border = 5;
} else {
c64.console.print("FLUSH BAD\n", .{});
c64.vic.border = 2;
}
} else {
c64.console.print("FAR ALLOC BAD\n", .{});
c64.vic.border = 2;
}
}
Choose how much data to bring near
| Workload | Read | Write back |
|---|---|---|
| Read or replace one record | enemies.get(index) | enemies.set(index, replacement) |
| Edit a small table that fits | enemies.materialize(scratch) | enemies.flush(local) |
| Edit part of a large table | enemies.materializeRange(scratch, start, count) | enemies.flushRange(start, local) |
For an eight-byte record, far index 2 starts sixteen bytes after the allocation base. If a range starts at far index 1, that same record is local index 1. Keep these two indexes separate when editing. Single-record get and set · Whole-view round trip · Range round trip with a runtime start
Handle a range that does not fit
A literal range outside the far view is a build error. At runtime, both an out-of-range start and an exhausted near arena can return null. Keep the edit and flush inside the successful capture. Check the range first when the program needs to distinguish the two causes.
if (start > 36) {
c64.console.print("PAGE OUT OF RANGE\n", .{});
} else if (sectors.materializeRange(scratch, start, 4)) |page| {
const sector = page.get(0);
const visits: u16 = sector.visits;
c64.console.print("VISITS {x16}\n", .{visits});
scratch.reset();
} else {
c64.console.print("PAGE DOES NOT FIT\n", .{});
}
Try both cases with the complete 40-sector map program. Start at 37 to exceed the view. Start at 36 with only 31 scratch bytes to exhaust the arena.
Match the source view to the destination
Whole-view flush requires the same record type and count on both sides. A local view of one Enemy cannot stand in for a far table of two Enemy records. To update just the first record, use two.flushRange(0, local) with that one-record local view. The local count determines the number of records written.
if (one.materialize("main")) |local| {
two.flush(local);
}
Both forms require the matching record type. Equal byte widths alone give no conversion between types. If you are migrating a record format, read the old fields, construct a new record explicitly, and write it through the new view. When troubleshooting, check type, count, and destination start before looking at DMA or banking.
Whole-view count mismatch · Range flush record-type mismatch · Successful partial write-back
Process a table larger than its C64 working space
For a game-sized example, update 200 enemies in batches of 20. Each batch stays in C64 RAM for movement and collision passes before one write-back.
Four three-byte sectors occupy twelve bytes in REU. The C64 scratch arena has six bytes, enough for two sectors. Process starts 0 and 2 in sequence. For each range, bring in both records, run three update passes in C64 RAM, and write back once. The same arena serves the next range after reset. This works because the first near view has gone out of use before the second allocation.
const c64 = @import("c64");
const ZeroPage = @import("ZeroPage");
const Sector = struct { visits: u8, score: u16 };
memory {
region work_ram: c64 at 0x9000 size 6;
region asset_ram: reu at 0x010000 size 0x0100;
arena scratch in work_ram;
arena assets in asset_ram;
}
fn update(sector: Sector, bonus: u8) Sector {
return Sector{
.visits = sector.visits + 1,
.score = sector.score + @as(u16, bonus),
};
}
fn run() bool {
if (ZeroPage.reu.present() == false) {
return false;
}
if (assets.allocBytes(@sizeOf(Sector) * 4)) |storage| {
var sectors = ZeroPage.reu.view(Sector, storage, 4);
sectors.set(0, Sector{ .visits = 0, .score = 0x1000 });
sectors.set(1, Sector{ .visits = 0, .score = 0x2000 });
sectors.set(2, Sector{ .visits = 0, .score = 0x3000 });
sectors.set(3, Sector{ .visits = 0, .score = 0x4000 });
var start: u8 = 0;
while (start < 4) {
if (sectors.materializeRange(scratch, start, 2)) |local| {
var pass: u8 = 0;
while (pass < 3) {
const a = local.get(0);
const b = local.get(1);
const updated_a = update(a, 1);
const updated_b = update(b, 2);
local.set(0, updated_a);
local.set(1, updated_b);
pass += 1;
}
sectors.flushRange(start, local);
} else {
assets.reset();
return false;
}
scratch.reset();
start += 2;
}
const first = sectors.get(0);
const second = sectors.get(1);
const third = sectors.get(2);
const last = sectors.get(3);
assets.reset();
return first.visits == 3 and first.score == 0x1003 and
second.visits == 3 and second.score == 0x2006 and
third.visits == 3 and third.score == 0x3003 and
last.visits == 3 and last.score == 0x4006;
}
return false;
}
export fn main() void {
c64.console.clear();
if (run()) {
c64.console.print("WORKING SET OK\n", .{});
c64.vic.border = 5;
} else {
c64.console.print("WORKING SET FAILED\n", .{});
c64.vic.border = 2;
}
}
Predict the final scores 1003, 2006, 3003, and 4006. Every sector has three visits. The repeated edits use only near view operations. A fresh set of far reads checks the flushes. Expect WORKING SET OK and a green border with the REU enabled. Boot with it disabled to see WORKING SET FAILED and a red border.
The range count is fixed at two, and the runtime start advances by two. For a table with an odd record count, handle the last record with a single get and set or a separate range with literal count one. The sample allocates through a far arena and verifies copies through the target REU. It allocates no additional C64 working range for the second pair.
Stage read-only tile bytes in a fixed REU range
The PRG starts with two four-byte tiles. The program copies their screen codes into a near arena, transfers all eight bytes to a fixed REU region, and resets the near arena. Later it fetches the second tile directly into screen RAM. This needs one staging buffer for initialization. No typed record view is needed because the renderer consumes four consecutive bytes.
const c64 = @import("c64");
const ZeroPage = @import("ZeroPage");
const tiles = [_]u8{ 'R', 'O', 'A', 'D', 'L', 'A', 'K', 'E' };
memory {
region work_ram: c64 at 0x9000 size 8;
region tiles_reu: reu at 0x020000 size 8;
arena scratch in work_ram;
}
fn drawSecondTile() bool {
if (ZeroPage.reu.present() == false) {
return false;
}
if (scratch.allocBytes(tiles.len)) |staging| {
for (tiles, 0..) |byte, i| {
staging[i] = byte;
}
ZeroPage.reu.copyC64ToReu(@intFromPtr(staging), 0x020000, tiles.len);
scratch.reset();
// The second four-byte tile starts four bytes into the fixed slot.
ZeroPage.reu.copyReuToC64(0x020004, 0x0400, 4);
return true;
}
return false;
}
export fn main() void {
c64.screen.clear();
if (drawSecondTile()) {
c64.vic.border = 5;
} else {
c64.screen.putsAt(0, 0, "ASSET UNAVAILABLE");
c64.vic.border = 2;
}
}
Expect LAKE at the start of the screen. The second tile starts at $020004, four bytes after the declared base. These bytes were encoded as screen codes in the source. The REU copy preserves bytes exactly. Keep this fixed slot separate from your mutable REU tables. Choose a far arena when the program needs to allocate storage for multiple assets at runtime.
In this exercise the source asset is embedded in the PRG. The copy demonstrates staging and reuse of the C64 work buffer. The original table still occupies its compiled read-only storage. Raw DMA and allocation contracts
Keep artwork and frequently edited state in separate tables
The same tile ID selects two representations. ID 1 means the four bytes of LAKE in a fixed artwork slot and the second record in a far state arena. Artwork goes straight to screen RAM. Visits and flags pass through a typed near view. Editing a tile transfers just its two state bytes in each direction. The artwork stays in its own range until the renderer asks for it.
const c64 = @import("c64");
const ZeroPage = @import("ZeroPage");
const glyphs = [_]u8{ 'R', 'O', 'A', 'D', 'L', 'A', 'K', 'E' };
const TileState = struct { visits: u8, flags: u8 };
memory {
region scratch_ram: c64 at 0x9000 size 8;
region artwork: reu at 0x020000 size 8;
region state_reu: reu at 0x021000 size 4;
arena scratch in scratch_ram;
arena states in state_reu;
}
fn stageArtwork() bool {
if (scratch.allocBytes(glyphs.len)) |staging| {
for (glyphs, 0..) |byte, i| {
staging[i] = byte;
}
ZeroPage.reu.copyC64ToReu(@intFromPtr(staging), 0x020000, glyphs.len);
scratch.reset();
return true;
}
return false;
}
fn updateLake() bool {
if (states.allocBytes(@sizeOf(TileState) * 2)) |allocation| {
var table = ZeroPage.reu.view(TileState, allocation, 2);
table.set(0, TileState{ .visits = 0, .flags = 0 });
table.set(1, TileState{ .visits = 2, .flags = 0 });
if (table.materializeRange(scratch, 1, 1)) |page| {
var lake = page.get(0);
lake.visits += 1;
lake.flags |= 0x04;
page.set(0, lake);
table.flushRange(1, page);
scratch.reset();
const saved = table.get(1);
const road = table.get(0);
states.reset();
return saved.visits == 3 and saved.flags == 0x04 and road.visits == 0;
}
states.reset();
}
return false;
}
export fn main() void {
c64.screen.clear();
if (ZeroPage.reu.present() and stageArtwork() and updateLake()) {
ZeroPage.reu.copyReuToC64(0x020004, 0x0400, 4);
c64.screen.putsAt(0, 2, "STATE SAVED");
c64.vic.border = 5;
} else {
c64.screen.putsAt(0, 0, "MAP UNAVAILABLE");
c64.vic.border = 2;
}
}
Expect LAKE and STATE SAVED. After the flush, the lake has three visits and flag $04. The road still has zero visits. The program reuses one near arena for the initial artwork staging and the later state edit. Its states.reset() ends the state allocation's lifetime after verification. In a game, keep the handle until the map is unloaded.
Combine fields in one record when you routinely need them together. Separate tables help when one path wants raw bytes and another wants structured edits with a different lifetime. In either layout, preserve a stable mapping from tile ID to the data you load or write.
Compare repeated far updates with a working copy
The same four sectors can be updated directly in REU. This variant keeps the same initial data, the same three passes over each pair, and the same final checks. Each pass reads and writes both far records. In the materialized version, each pair crosses the bus once in each direction and the passes access C64 RAM.
var start: u8 = 0;
while (start < 4) {
var pass: u8 = 0;
while (pass < 3) {
const a = sectors.get(start);
const b = sectors.get(start + 1);
const updated_a = update(a, 1);
const updated_b = update(b, 2);
sectors.set(start, updated_a);
sectors.set(start + 1, updated_b);
pass += 1;
}
start += 2;
}
| Update method | DMA transfers during editing | Bytes moved during editing | Additional near arena | PRG bytes | VICE stopwatch cycles |
|---|---|---|---|---|---|
Far get and set | 24 | 72 | 0 | 2,675 | 20,689 |
| Materialize and flush each pair | 4 | 24 | 6 bytes | 2,846 | 16,507 |
The transfer columns count the edit loop only. Both programs also do four initial writes and four verification reads. The VICE measurement covers main through the generated test-exit label, including setup, verification, and screen output. Both produced WORKING SET OK. This preview build trades 171 more file bytes and six reserved C64 bytes for 4,182 fewer cycles in this run. VIC timing and build layout can change the measured values.
When each record needs one update, copying it into a separate arena adds another representation to manage and may offer little benefit. With repeated accesses, the savings grow with the passes you can keep local. Count the transfers and working RAM first, then time the actual path.
Complete direct-update source · Complete materialized version
Build both versions and look up their measurement addresses
In VICE with REU enabled, break at the .main address, note STOPWATCH from the register display, and continue to a breakpoint at .zeropage_test_exit. Subtract the first reading from the second. Use a fresh emulator run with the same configuration for each PRG. The labels use the address chosen by that build.
Size a map and its working pages
A map with 40 sectors needs 320 REU bytes. Each sector has one byte for terrain, one for flags, two for visits, and four for tiles. The record has no padding. Four sectors at a time fit in 32 bytes of C64 scratch. A request starting at sector 36 covers indexes 36 through 39. The edit marks each sector as visited and preserves its terrain and tile data.
const c64 = @import("c64");
const ZeroPage = @import("ZeroPage");
const Terrain = enum(u8) { grass = 1, water = 2 };
const Sector = struct {
terrain: Terrain,
flags: u8,
visits: u16,
tiles: [4]u8,
};
memory {
region work_ram: c64 at 0x9000 size 32;
region map_reu: reu at 0x020000 size 320;
arena scratch in work_ram;
arena map in map_reu;
}
fn visitPage(start: u8, mark: u8) bool {
if (ZeroPage.reu.present() == false) {
return false;
}
if (map.allocBytes(@sizeOf(Sector) * 40)) |bytes| {
var sectors = ZeroPage.reu.view(Sector, bytes, 40);
const initial = Sector{
.terrain = .grass,
.flags = 0,
.visits = 0,
.tiles = [_]u8{ 1, 2, 3, 4 },
};
var index: u8 = 0;
while (index < 40) {
sectors.set(index, initial);
index += 1;
}
var ok = false;
if (sectors.materializeRange(scratch, start, 4)) |page| {
for (0..4) |i| {
var sector = page.get(i);
sector.visits += 1;
sector.flags |= mark;
page.set(i, sector);
}
sectors.flushRange(start, page);
scratch.reset();
const changed = sectors.get(start);
const last_changed = sectors.get(start + 3);
const unchanged = sectors.get(0);
ok = changed.visits == 1 and changed.flags == mark and
changed.terrain == .grass and changed.tiles[3] == 4 and
last_changed.visits == 1 and unchanged.visits == 0;
}
map.reset();
return ok;
}
return false;
}
export fn main() void {
c64.console.clear();
if (visitPage(36, 0x04)) {
c64.console.print("MAP SECTORS OK\n", .{});
c64.vic.border = 5;
} else {
c64.console.print("MAP SECTORS FAILED\n", .{});
c64.vic.border = 2;
}
}
Expect MAP SECTORS OK. Try start 37 and keep scratch at 32 bytes. The range exceeds the far view and materialization returns null. Restore start 36 and reduce scratch to 31 bytes. The range is valid, but the near allocation fails. Both variations reach MAP SECTORS FAILED before editing. If your real program must report separate errors, validate the input range before making the allocation request.
Store tile IDs and flags as bytes. Keep the visit counter as a word so it can grow past 255. Initialize every far record before reading it. If the table grows beyond a view's supported record count, split the data into separately managed views and choose the view before making the local index. Far record and view constraints