Virtual Machine
vmThe xyw virtual machine is a stack/register virtual machine able to operate on 8bit or 16bit integers.
It uses:
a user stack of 128 bytes.
a system stack used for managing subroutines of 384 bytes (able to store up to 48 frames of 8 bytes each, to preserve state).
64KiB of preallocated memory, of which the last 256 bytes are reserved for devices input/output.
two 8bit registers (x and y).
two 16bit registers (xw and yw).
a 16bit program counter (pc).
Note that:
registers, pc, stacks are not memory-mapped.
no user access is provided to pc and the system stack.
=== Execution Flow
When a .xim image file is executed, its contents are loaded into memory and then evaluated starting from address $0000.
The evaluation happens in a loop performing the following operations sequentially:
if pc >= $FF00 (start of the device page), halt the execution.
check the vm state:
if waiting -> poll devices and execute handlers
tick devices (check error handling, execute image)
execute instruction at pc
increment pc
Currently, the following devices support polling:
terminal -> argument processing and key presses
clock -> timer
Only the system device implements the tick device api to:
execute on error handlers
execute a xim image