-
Notifications
You must be signed in to change notification settings - Fork 0
RAM
The RAM stores data.
Memory is stored as a PackedByteArray with a configurable size. By default, the RAM contains 256 bytes.
When the RAM is created, it:
- Allocates a
PackedByteArray - Resizes it to the configured memory size
The default size is:
size = 256Changing size before the node enters the scene changes how much memory is allocated.
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.
Read a byte using:
var value = ram.read(address)Example:
var health = ram.read(12)The value stored at the requested address is returned.
Write a byte using:
ram.write(address, value)Example:
ram.write(12, 100)The new value is immediately stored in 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)To erase all allocated memory:
ram.clear()This clears the underlying PackedByteArray.
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().
The RAM holds a reference to the CPU:
var cpu : CPUThis 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.
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 |