Tantal: a small compiled language for the 6502, tested on a PAL-2

Following my earlier PAL-2 experiments, including getting CP/M-65 running on the physical machine, I wanted a quicker way to write small hardware-oriented 6502 programs without moving too far away from the processor itself.

The result is Tantal, a small compiled language for the NMOS 6502. I developed the first version with Claude Code, but the language design is driven by the limitations of the real target: my PAL-2, a KIM-1-compatible computer running at 1 MHz.

The original inspiration was Action! for the Atari. I encountered it almost by accident in a Czech series on Root.cz and liked the idea of a structured language whose constructs remain recognisably close to the machine.

One central design decision is to avoid using the 6502 hardware stack for parameters and local variables. Procedure frames have fixed addresses, and frames belonging to procedures that cannot be active at the same time can share memory. The compiler calculates this overlay from the call graph. The first three parameter bytes are passed in A, X and Y; additional parameters use frame slots. A byte result is returned in A and a 16-bit result in A/X. Recursion is consequently a compile-time error.

The first intended application is a simple logic analyser for relatively slow signals on the PAL-2 user port. This led to explicit language constructs for waiting on ports and pins:

ring byte[256] log noinit
byte PAD_OLD, cur
card changes

PADD = $00
PAD_OLD = PAD
clear(log)

do
  cur = wait change PAD from PAD_OLD timeout 2 s
  if timedout then exit fi
  log <- cur
  changes += 1
od

wait change PAD from PAD_OLD compares the current port value with the caller-supplied previous value, returns the complete new port byte, and updates PAD_OLD. There are also wait rising and wait falling forms for individual bits. Optional timeouts use the user RIOT timer and set the built-in timedout value.

The compiler is written in Go and includes its own assembler and 6502 emulator. It emits a raw binary, Intel HEX, KIM-1 paper-tape format, an assembly listing with cycle counts, a memory map, and a symbol table. The built-in PAL-2 target describes the memory map, both RIOTs, monitor routines, and the IRQ/NMI vectors.

I have now tested the display.tantal example both in the KIM-1 simulator and on the physical PAL-2. The program writes directly to the system RIOT and multiplexes the six LED digits; the real board successfully displays HELLO.

The display.tantal example running on the physical PAL-2.

The project is still version 0.1. It currently supports unsigned byte and 16-bit values, fixed-address I/O registers, named bits and bit fields, procedures, interrupts, inline assembly, strings, ring buffers, and the signal-oriented wait forms. Signed types, 65C02 instructions, automatic serial upload, and enforcement of .cycles limits are not implemented yet.

Code, documentation, examples, and the compiler source:

A longer description of the design and the PAL-2 test:

The earlier PAL-2 thread that led into this work:

Do you think there is still a need for a new 6502 language like Tantal? If not, what do you currently use to write 6502 software, and what makes it a better fit?

1 Like

For reference/comparison, here’s the Wikipedia entry for the Action! programming language (various resources linked at the bottom of the page):

2 Likes

I think a new language was needed since the 1980’s for micros like the z80 and 6502.
The PDP 11 had C for all the same features but long and floating point made it too
complex for the 8 bit micros.CP/M and BASIC where written in assembler and it was expected applications and operating systems would be the same.

1 Like

I’ve no idea about need and based on many (many!) years of 6502 usage, inhabiting various forums, boards, etc. I sort of get that a lot of the 6502 users are quite happy with what they currently have. some may even say stuck in their ways…

So trying to encourage adoption is relatively hard. I tried to get people interested in my TinyBasic but nope. I tried to get people (outside the UK) interested in BBC Basic. Nope. And so on.

What I think there may be a desire for is self-hosted things - so write the compiler in something (itself?) that might run directly on the 6502.

So-far there are few things that do this relatively well - UCSD Pascal worked on the Apple II and there is a Pascal for the BBC Micro. C was always tricky on the 6502 - there is the Aztec compiler for the Apple II and a tiny-C on the BBC Micro.

The other system I’ve used (and still use today) is BCPL. There is a good compiler/editor, etc. for the .. BBC Micro. But I’ve no idea if any other 6502 systems ever had it. I’ve written my own for the 65816.

And of-course that brings us to the actual platform. One thing that happened with the 6502 was a maze of twisty platforms - all different. The Z80 world has CP/M as well as the smaller (home) micros, but even some of them can be bludgeoned into running CP/M and from there the world is your bivalve…

And now there are 2 CP/M-like systems for the 6502. How compatible with each other are they?

So (sadly) 6502 world really is a bit of a fragmented minefield. Of-course the flip-side is that some might say it has more and varied platforms than anything else which might be considered a strong point?

To encourage use, I tried to make my TinyBasic as portable as possible. Even that didn’t help… OK, One issue was “Why TinyBasic when I have my favourite old MS Basic variant”. But you get the drift.

And an interesting ponderation: If I have to cross compile why am I writing in a new language that needs another language subsystem to run when there are now several good C compilers for the 6502? This is in no way a criticism aimed at you/Tantal, it’s just another hurdle to overcome, sadly. I am moderately biased here as my own ideals are for self-hosting systems.

So I use BCPL - but other things I’ve looked at - BitLash for AVRs. A sort of interactive C. I’ve looked at Cowgol - but sort of BBC Micro only. Plasma (mostly Apple II specific) PL/M (as in porting/(re)writing) and I’m sure a few others I’ve forgotten or just don’t know. Of-course these may not always predictable in their timings or simply be too slow for some things.

Now - one place where guaranteed predictable timings is needed is the Atari 2600… That might be a nice thing to try to target. Race that beam!

-Gordon

3 Likes

Thanks, Gordon.

Initially, I felt that a language for the 6502 ought to have a compiler that could run on the 6502. I suspect my view changed because I am looking at this as a PAL-2 owner. To use its serial terminal I already need another computer, so running the compiler there does not add much inconvenience. I might feel differently if the target had a keyboard with more than twenty keys!

Before starting Tantal I looked at existing software, including several BASICs and Forth. They are attractive for interactive and self-hosted use, but the implementations I tried did not fit my particular timing requirements. My intended application is, rather grandly put, a small logic analyzer: checking whether relatively slow signals follow an expected pattern, for example on a serial bus using a custom protocol.

Then I discovered Action! and became rather enthusiastic about its approach. It feels much closer to the 6502 than a conventional C implementation and does not carry the same assumptions about stacks, calling conventions and data types. Tantal came out of experimenting with those ideas rather than from an expectation that it would replace established 6502 toolchains.

Tantal is a cross compiler, but the generated program is native 6502 code and does not require a language runtime on the target. I like being able to write the PAL-2 display routine in a few lines while still seeing a fairly direct relationship between the source and the generated instructions.

You are probably right that adoption will be difficult, especially given how fragmented the 6502 world is. For now I intend to use Tantal for my own PAL-2 projects and see which direction actual use pushes it in.

The Atari 2600 is an interesting suggestion!

Best regards,
Jan (AKA dz3jar)

3 Likes