DragonOSA RedPower revival

Dragon-16 and 65EL02 machine code

The Dragon-16 instruction set and disk format, banked RAM, and the Dual-Core 65EL02's worker core.

This page is for writing programs below DragonOS and Forth: raw machine code on the two processors.

Dragon-16

Dragon-16 is the custom 16-bit processor of the DragonCPU. DragonOS runs on it.

  • Eight registers start at zero, except r6 and r7, which hold the configured floppy and display addresses.
  • Arithmetic wraps at 16 bits. Memory loads and stores are byte-wide.
  • 0000–1FFF is internal RAM; 2000–FFFF addresses the seven backplane slots.
  • Disk offsets and instruction words are little endian.
Opcode Operands Operation
00 — Halt
01 — Yield until the next tick
02 destination register, immediate word Load literal
03 destination, source register Copy register
04–05 destination, source register Add, subtract
06 destination, address register Load byte
07 address, source register Store byte
08 address word Jump
09 condition register, address word Jump if zero
0A destination, device, port registers Read Redbus
0B device, port, source registers Write Redbus
0C source register Select RAM bank from its low two bits
0D–0F destination, source registers Bitwise AND, OR, XOR
10 address word Call, saving the return address in r5
11 — Return to r5

Boot disk format

Sector zero starts with ASCII DR16, a 16-bit payload length and a 16-bit entry address. Sector one starts the executable payload, which is loaded at address zero and may be up to 8 KiB. Pad the image to a 128-byte boundary. Copy a custom image to a writable floppy with the floppy import command.

DragonOS draws into the terminal's 80 × 50 character framebuffer; a program can set display cursor mode 3 for the desktop palette.

Device registers

Device Registers
Hard drive 0: signature 0x48. 1–2: capacity in MiB (low, high). 3: percent used. 4–5: item types. 6: 1 when DragonOS is installed.
Storage ports 1: slot count. 2: occupied slots.

RAM banks

A 32 KiB Banked RAM module shows one 8 KiB bank at a time in its backplane slot. Bank zero is selected at reset, so a freshly booted Forth program sees the usual layout. Plain 8 KiB modules appear in every bank.

  • On Dragon-16, opcode 0C selects the bank.
  • On 65EL02, write the low bank byte to register 1 and the high byte to register 9 of the expansion controller at Redbus address 254. The same works for RAM Card Case memory.

The 65EL02 expansion controller

The controller at Redbus address 254 is on the Dual-Core 65EL02 CPU, and on an original CPU with expanded memory attached. It takes priority over any device at that address.

Register Purpose
0 Controller version, currently 1
1 Read or select this core's RAM bank, 0 to 3
2 Number of cores
3 Worker status. The primary writes 1 to launch at the pointer, 0 to halt
4–5 Worker RAM pointer, little endian. Writable while the worker is halted
6 Worker RAM byte at the pointer; writing advances the pointer
7 Write a mailbox byte to the other core, or read the last byte it sent
8 Core ID: 0 for the primary, 1 for the worker

Each core chooses its bank independently; when both select the same bank they see the same memory.

The worker core

The worker has its own 8 KiB of RAM, registers and instruction pointer, and runs while the primary's firmware keeps going. Halting the primary suspends the worker; resetting the primary resets both. Put entry points below address 8192 in worker RAM and keep clear of the default stacks.

This example, run with the RedForth disk on a dual-core CPU, loads LDA #99, STA $10 and a yield loop into the worker, starts it, then reads the result:

254 RBP! 64 772 C! 0 773 C!
254 RBP! 169 774 C! 99 774 C! 133 774 C! 16 774 C!
254 RBP! 203 774 C! 128 774 C! 253 774 C!
254 RBP! 64 772 C! 1 771 C!
20 TICKS
254 RBP! 0 771 C! 16 772 C! 774 C@ .

It prints 99.