| Crates.io | retrolang |
| lib.rs | retrolang |
| version | 0.1.1 |
| created_at | 2025-12-09 00:23:27.941731+00 |
| updated_at | 2025-12-09 01:37:40.068786+00 |
| description | A simple systems programming language compiler for Z80 microprocessors |
| homepage | https://github.com/ajokela/retrolang |
| repository | https://github.com/ajokela/retrolang |
| max_upload_size | |
| id | 1974607 |
| size | 113,433 |
A simple systems programming language and compiler for Z80 microprocessors, designed for the RetroShield platform.
# Build the compiler
cargo build --release
# Compile a program to assembly
./target/release/retrolang examples/hello.rl
# Produces hello.asm
# Compile directly to binary (requires retrolang-asm)
./target/release/retrolang examples/hello.rl --binary
# Produces hello.bin ready to load on RetroShield
byte // 8-bit unsigned (0-255)
int // 16-bit signed (-32768 to 32767)
bool // true/false
char // 8-bit character
byte[10] // array of 10 bytes
^int // pointer to int
const MAX: int = 100;
var counter: int = 0;
var buffer: byte[80];
// If statement
if x > 0 then
y := 1;
elsif x < 0 then
y := -1;
else
y := 0;
end;
// While loop
while x > 0 do
x := x - 1;
end;
// For loop
for i := 1 to 10 do
print("*");
end;
// Procedure (no return value)
proc greet(name: ^char)
print("Hello, ");
print(name);
println();
end;
// Function (returns a value)
func add(a: int, b: int): int
return a + b;
end;
print("Hello"); // Print string
println(); // Print newline
printc('A'); // Print character
printi(42); // Print integer
readc(); // Read character (returns char)
proc delay()
asm
ld b, 255
loop:
djnz loop
end;
end;
func factorial(n: int): int
if n <= 1 then
return 1;
else
return n * factorial(n - 1);
end;
end;
proc main()
var i: int;
print("Factorials:");
println();
for i := 1 to 8 do
printi(i);
print("! = ");
printi(factorial(i));
println();
end;
end;
# Install the compiler
cargo install retrolang
# Install the assembler (required for --binary output)
cargo install retrolang-asm
Requires Rust 1.70 or later:
cargo build --release
# Compile to binary (requires retrolang-asm)
retrolang program.rl --binary
# Keep intermediate .asm file for inspection
retrolang program.rl --binary --keep-asm
# Output assembly file only
retrolang program.rl
# Then assemble with any Z80 assembler
retrolang-asm program.asm program.bin
The generated code uses this memory layout for RetroShield:
0x0000 - 0x7FFF Program code and data
0x8000 - 0xFFFF Variables (grows up) / Stack (grows down)
RetroLang supports two serial drivers for I/O, selected with the --serial option:
# Use MC6850 ACIA (default)
./target/release/retrolang program.rl --binary --serial acia
# Use Intel 8251 USART
./target/release/retrolang program.rl --binary --serial intel
Used by kz80_forth, kz80_pascal, and other custom RetroShield firmware. The ACIA emulation is implemented in the RetroShield Z80 firmware.
| Port | Function |
|---|---|
$80 |
Control/Status register |
$81 |
Data register |
Status bits:
Used by the original RetroShield Arduino sketches, Grant Searle's BASIC, and EFEX monitor.
| Port | Function |
|---|---|
$00 |
Data register |
$01 |
Control/Status register |
Status bits:
| Function | Description |
|---|---|
print(s) |
Print null-terminated string |
println() |
Print carriage return + line feed |
printc(c) |
Print single character |
printi(n) |
Print signed 16-bit integer |
readc() |
Wait for and return a character |
The runtime also includes 16-bit arithmetic routines:
_mul16 - 16-bit multiplication (HL × DE → HL)_div16 - 16-bit division (HL ÷ DE → HL, remainder in BC)_mod16 - 16-bit modulo_cmp16 - Signed 16-bit comparisonDesigned for the RetroShield Z80 with Teensy adapter (256KB RAM). The Arduino Mega version has limited RAM (~4KB) which restricts program size.
RetroLang is licensed under the BSD 3-Clause License. See LICENSE for details.