Skip to content
GattoDev edited this page Jul 22, 2026 · 5 revisions

RAM

The RAM stores data. Memory is stored as a PackedByteArray with a configurable size. By default, the RAM contains 256 bytes.


What it does on startup

When the RAM is created, it:

  1. Allocates a PackedByteArray
  2. Resizes it to the configured memory size

The default size is:

size = 256

Changing size before the node enters the scene changes how much memory is allocated.


Memory layout

Memory is stored as one contiguous array of bytes.

Each index represents one memory address.

Address   Value
-------   -----
0         0x00
1         0x2F
2         0x80
...
255       0x00

Every address stores a single byte (0–255).

The RAM does reserve the last address for FPS (255 in this case), Every other memory address is entirely up to the ROM.


Reading memory

Read a byte using:

var value = ram.read(address)

Example:

var health = ram.read(12)

The value stored at the requested address is returned.


Writing memory

Write a byte using:

ram.write(address, value)

Example:

ram.write(12, 100)

The new value is immediately stored in memory.

Increasing and Decreasing memory

You may increase a byte by value using:

ram.inc(address, value)

You may also decrease a byte by value using:

ram.dec(address, value)

Clearing memory

To erase all allocated memory:

ram.clear()

This clears the underlying PackedByteArray.


Bounds checking

Every memory access is checked against the configured RAM size.

If an address outside the available memory is accessed, the CPU immediately panics:

cpu.panic("OUT OF BOUNDS MEMORY")

This applies to both read() and write().


CPU integration

The RAM holds a reference to the CPU:

var cpu : CPU

This is only used to report fatal memory errors through cpu.panic().

Like the other hardware components, this reference is injected automatically by the CPU during startup.


Summary

The RAM provides four operations:

Function Purpose
_ready() Allocates the memory array
read(address) Reads one byte
write(address, value) Writes one byte
inc(address, value) Increases one byte by value
dec(address, value) Decreases one byte by value
clear() Clears the allocated memory

Clone this wiki locally