Ruby816 – Software

Once the board was running and I’d experimented with making existing programs I used on the Ruby6502 board run (Mostly BBC BASIC and C using the cc65 compiler), I wondered “what next” …

I was using the ca65 assembler from the cc65 suite which supports the ‘816 instruction set and was getting on well with it. A plan at the back of my mind was to write a proper ‘816 BASIC with it, however some sense prevailed and that plan was pushed back for another day… The next thing: Get C working – well, it already was. I’d created a target for cc65 (not actually that easy as there is scant documentation on it!) for the Ruby6502 board, so it was trivial to make another for the ‘816 board, however the C compiler doesn’t support the 65C816 directly, so back to the same limitation of 64KB of RAM in Bank 0 unless I did some serious work to address the issue.

WDC have their own C compiler for the ‘816, however it seems to want to run in MS windows only and that is not a development platform I’m interested in.

I started to write a lot of code using ca65 to help with my BASIC, but quickly realised it was not a task I felt like completing. I mentioned earlier that I didn’t enjoy the task and this didn’t help so I decided that I wanted a high level language that was agnostic of the underlying 64K banks and Plan B was hatched.

So BCPL

BCPL was developed in 1966 by Martin Richards – at the time, a recent Cambridge PhD graduate while visiting MIT.  BCPL was used to develop B which was used to develop C and Unix. It claims the first “Hello, world!” program. It also typically compiles into a ‘bytecode’ which is then interpreted or natively translated (so arguably the fore-runner of Java, etc.) It was used to develop the first operating system for the Amiga computer as well as operating systems for other mini computers of the late 60’s and early 70’s. Additionally, Martin has continued to develop BCPL to this day and is now supports most modern 32 and 64 bit platforms. Despite modern additions and updates the language remains mostly the same and the compiler very simple and fast.

Fast?

The compiler can compile itself in under a second on my rather modest Intel i3 3Ghz desktop system.

BCPL 32-bit Cintcode System (21 Oct 2015)
0.000> bcpl com/bcpl.b to /tmp/bcplc bin

BCPL (10 Oct 2014) with simple floating point
Code size = 26276 bytes of 32-bit little ender Cintcode
Code size = 14908 bytes of 32-bit little ender Cintcode
0.192> /tmp/bcplc com/bcpl.b to /tmp/bcpld bin

BCPL (10 Oct 2014) with simple floating point
Code size = 26276 bytes of 32-bit little ender Cintcode
Code size = 14908 bytes of 32-bit little ender Cintcode
0.182> 
SIGINT received

Leaving Cintsys
gordon @ wakko: cmp /tmp/bcplc /tmp/bcpld

To understand what that is… I have run the ‘cintsys’ program on my Linux desktop PC. This is a C program that interprets the BCPL Cintcode (bytecode). It starts, loads the BCPL librarys and the command-line interface. The 0.000> prompt is from a BCPL program.

The command: bcpl com/bcpl.b to /tmp/bcplc bin runs the BCPL compiler and creates a binary output file into /tmp/bcplc. The next prompt: 0.192> shows just how long it took. That’s 192ms. Two Fifths of a second to compile the compiler. I then use this compiler to compile itself again (it took 182ms that time), then I exit and binary compare the files. They are identical.

So it looks like BCPL will make a good target for my Ruby816 system and it’s size (about 42KB) means that it will run very comfortably in the 512KB of RAM that Ruby has.

I’ve done BCPL Before…

My own BCPL experience started in about 1983 on BBC Micros when I was doing lots of post-grad type research into factory automation and I built up a network of BBC Micros all running BCPL and connected together via the Acorn Econet network. Each Beeb had a microcontroller attached (another 6502 system that we designed in-house). It worked better (and faster) than BASIC and allowed a form of concurrent programming using coroutines.

Also, I’d been dabbling with the old BBC Micro BCPL on the Ruby6502 board while investigating C compilers for the 6502 to see if they may be adapted for the ‘816. I also had an idea that the system be “self hosting”. So be able to compile and assemble directly without cross compiling and downloading  from a host. However my experienced of C compilers on a 6502 back in the early 80’s were poor, so more and more it was looking like BCPL is the way to go.

BCPL BooksCintcode

BCPL compiles to an intermediate byte-code for an “ideal” CPU – Ideal for BCPL that is. It’s actually a very CISC style instruction set with variable length operands (byte, half-word or word) however it has been very highly optimised for the task in-hand. The most common operations are coded into a single byte, even to the extent of accessing stack and global variables. This is called cintcodeCompact Intermediate Code. The compiler can also output an older form called OCODE and a newer form call SIAL. The latter is designed to be translated into native code. I decided to stick to cintcode because it’s very compact (The compiler is 42KB of cintcode) and it seemed it would be relatively easy to write enough ‘816 assembler to make it run.

More on that in the next article though…