Varvara

From Fantasy Console Wiki
Jump to navigation Jump to search

This article is incomplete. You can help this wiki by expanding it.

Varvara is a fantasy computer system that uses runs a stack-based virtual machine called Uxn. Its main programming language is a Forth-like assembly language called Uxntal.

Uxn[edit]

Memory[edit]

Memory in a uxn computer consists in four separate areas: Main RAM with 64kb, 256 bytes each of: I/O memory, working stack, and return stack. Programs can move stacks into addressable range to allow reading and writing directly into stack memory. In this way, peripherals such as a controller, mouse, and keyboard can be addressed.

Memory RAM Data 64kb
Stacks Working Stack Data 254 bytes
Error 1 byte
Pointer 1 byte
Return Stack Data 254 bytes
Error 1 byte
Pointer 1 byte
I/O Devices Data 256 bytes

Each byte in main memory has an address of 16 bits (2 bytes) in size, while each byte in the i/o memory has an address of 8 bits (1 byte) in size. Both can be accessed randomly.

The first 256 bytes of the main memory constitute a section called the "zero page". this section can be addressed by a single byte and it is meant for data storage during runtime. The main memory stores the program to be executed starting at the 257th byte, or 0x100. This byte is the 0100 starting memory address for a Uxntal program.

Devices[edit]

Devices are external systems connected to the Uxn CPU, such as the screen, the mouse and the keyboard. Each device has 16 bytes, also called ports, of I/O memory. Vectors are ports holding an address in memory to evaluate when a device event is triggered, such as when the mouse is moved, or a key is pressed.

  • 00 - System device
  • 10 - Console device
  • 20 - Screen device
  • 30, 40, 50, 60 - Audio device
  • 70 - MIDI device
  • 80 - Controller
  • 90 - Mouse
  • a0, b0 - File
  • c0 - Datetime
  • d0 - Unused
  • e0, f0 - Reserved

The two reserved devices can be used for implementation specific features that do not need to be part of the specs, or other Uxn/Varvara instances.

Uxntal[edit]

According to the implentation spec, "Tal is the programming language for the Uxn virtual machine." Tal, commonly referred to as Uxntal, is a unique flavor of assembly language. Uxntal source files are assembled from human-readable source files into Uxn-compatible ROM files with the .tal extension.

The language itself works similarly to Forth, another stack-based language.

Opcodes[edit]

Uxn can perform 32 different operations, and each operation has 3 possible modes. The items in the following table include the Program Counter(PC), Memory(M), Devices(D) and Return Stack(rs).

Stack Memory
BRK/LIT - Literal a b c M[PC+1] LDZ - Load Zeropage a b M[c8]
INC - Increment a b c+1 STZ - Save Zeropage a {M[c8]=b}
POP - Pop a b LDR - Load Rel a b M[PC+c8]
NIP - Nip a c STR - Save Rel a {M[PC+c8]=b}
SWP - Swap a c b LDA - Load Abs a b M[c16]
ROT - Rotate c b a STA - Save Abs a {M[c16]=b}
DUP - Duplicate a b c c DEI - Device In a b D[c8]
OVR - Over a b c b DEO - Device Out a {D[c8]=b}
Logic Arithmetic
EQU - Equal a b?c ADD - Add a b+c
NEQ - Not Equal a b!c SUB - Subtract a b-c
GTH - Greater a b>c MUL - Multiply a b*c
LTH - Lesser a b<c DIV - Divide a b/c
JMP - Jump
a b {PC+=c} AND - And a b&c
JCN - JumpCond a {(b8)PC+=c} ORA - Or a b|c
JSR - JumpStash a b {rs.PC PC+=c} EOR - ExclusiveOr a b^c
STH - Stash a b {rs.c} SFT - Shift a b>>c8l<<c8h

The Uxn CPU reads one byte at a time from the main memory starting at 0100. The program counter is a 16-bit word that indicates the address of the byte to read next. Each byte read corresponds to an opcode which may cause a change in the stack(s) or the normal flow of the program counter; instead of pointing to the next byte in memory, it can be made to point elsewhere, "jumping" from one place in memory to another.