Personal Log »

Introducing TR-8

Over the years I have been playing with the idea of writing interpreters and compilers, and I say idea on purpose, because I haven’t been very successful at it. Something similar happens with operating systems and virtual machines, although I have been a bit better with the latter, I had many projects started over the years without results.

Considering that I have been doing game development consistently for almost 10 years now, the idea of a fantasy console is so perfect if you want to write those, that I would say it was almost inevitable I made one.

And that’s why the TR-8 fantasy console came about.

It is all very work in progress and, instead of spending a lot of time planing and designing without getting to make anything, I decided to start implementing and put together things as I go. And you can tell when you look at the design of the 8-bit CPU.

Without getting in too much detail, an example program:

.org 0

; address of the frame interrupt vector
.equ INT_VECT 0xff00

    ; setup an int handler so we
    ; can use the frame int to sync
    ld a, >INT_VECT
    ld x, <INT_VECT
    ld b, <int_handler
    ld [a : x], b
    inc x
    ld b, >int_handler
    ld [a : x], b

    ; enable interrupts
    cif

    ; loop filling the screen with one
    ; colour cycling the whole palette
    ld b, 0
loop:
    call fill
    inc b
    and b, 15

    ; wait 1 second
    ld x, 60
wait_loop:
    halt
    dec x
    bnz
    jmp wait_loop

    jmp loop

    ; fill frame-buffer with a color in reg b
fill:
    ld a, 0xbf
    ld x, 0
    ld y, 0x40
fill_loop:
    ld [a : x], b
    inc x
    bno
    jmp fill_loop
    inc a
    dec y
    bnz
    jmp fill_loop
    ret

int_handler:
    iret

That may give a bit of a taste of what is TR-8.

At the moment I’m working on three essential components:

  • a virtual machine for the CPU
  • an assembler
  • a “player” that uses the virtual machine and provides the other bits of that make it “a console”

All written in C –hopefully portable–, with SDL2 for the player.

As I say, it is a work in progress, but this is what I have decided so far:

  • Display: 128 x 128 pixels 16 colors (using the default EGA palette for now)
  • Memory: 64K
  • CPU: TR-8, 8-bit, 8M instr/sec (for now, likely make it slower when I add the hardware blitter)
  • Sound: TBD, likely to be either a PSG or perhaps FM (OPL3?)
  • Programming: ASM

The TR-8 CPU is inspired by the 8-bit CPUs I have programmed: the Z80 and the 6502; but also the MIPS (specially on how I’m encoding the instructions). This is not about a good design but about having some fun.

The main features of the CPU are:

  • 16-bit registers: stack pointer (SP) and program counter (PC)
  • 8-bit registers: 4 general purpose registers (a, b, x, y), flags register (F)
  • frame interrupt (60Hz)
  • port based IO (very Z80)
  • a frame buffer (16K of RAM as video RAM; I thought about implementing a VDP but then I realised I was copying the MSX!)

I don’t know how far I’m going to get. I guess I will implement enough to feel satisfied, perhaps making a game for it, and that’s probably it. I don’t expect anybody using this, when you can make games for actual 8-bit machines –or more user-friendly fantasy consoles like the Pico-8 or the Tic-80–.

Would you like to discuss the post? You can send me an email!