Thought I'd do a little write-up on my Ruby SBCs for anyone interested in the story so-far (I'll be posting this in a few places, so sorry if you see it more than once!) [edit - looks like it's gotten a bit long, ah well!]
The back-story is that in 1978 I got to use computers for the first time. I was 15/16 in that year. One of the computers I used was the Apple II with it's 6502.
Forward on 40 years and I decided to mark the occasion ("Ruby" being the 40th anniversary) by making my own little 6502 system. I'd made some little 6502 systems in the early 80's as part of my university project (and used an assembler on the Apple II as development) so it's not something I am particularly new to.
I made the 6502 system with the WDC 65C02, made a quick proof of concept on breadboard, then soldered up some stripboard then made a PCB for it. I eventually migrated it to a 65C816 which was so utterly trivial I really don't know why people don't just start with the '816 these days. The Ruby6502 is fairly well documented here:
https://projects.drogon.net/6502-ruby/Back in the 80's my home computer of choice had become the BBC Micro - Apple II's were just silly expensive in the UK, and the Apple //gs - just don't even think about it, although a good friend of mine did have one (he now works for Apple, go figure!) so while the BBC Micro was the fastest 6502, had the best & fastest Basic (still has IMO) I was still a little envious of the Apple //gs with it's "16-bit" 65816 CPU...
So I decided to go for a 2nd SBC based around the WDC 65C816.
Documentation, experiences, stories, and existing designs using the '816 are abundant but with that also comes conflicting tales, and at times seemingly scarily and daunting articles punctuated with stories of bus and timing conflicts, the criticality of using a transparent latch, bi-directional buffers, TTL types to avoid and ones you must use, PCB layout considerations and so on. I took the suck it and see approach and my board worked first time, and like my Ruby 6502 board the 816 works at 16Mhz. It is a simple board with 512KB of RAM and a 65C22 VIA and 2 GALs in addition to the ATmega "host" processor. If you're familiar with the BBC Micro, then one way to look at it is that the ATmega is the BBC Micro handling screen, keyboard, filing system, etc. and the '816 side is a Tube processor system.
Attachment:
ruby816-3.jpg [ 450.53 KiB | Viewed 1159 times ]
But what to do with it... ?
One thing I had a notion to do/look-at, was taking a retro/old system and use some modern software techniques to see what it might have been back then when the software knowledge I have today... The result is that unless you go to a GUI; "Not a lot different". You end up with a nicer command-line interface but if not careful, you end up throwing so much at it, that it becomes unstably slow - especially if you stick with "period" style hardware and limitations like graphics - no fancy GPUs then to do your scene drawing for you... Back in the late 70's and 80's I was doing development directly on the system I was working on Apple II, BBC Micro and CP/M systems, so "
self hosting" was a goal I set myself.
I looked and used C for a long time - The cc65 package. I used the ca65 assembler to develop all the operating system (I abandoned the concept of a "monitor" early on mostly because my 1981 BBC Micro had an OS and not a monitor) I made it compatible enough with the BBC Micro to be able to run BBC Basic (I did get EhBASIC going, as well as Applesoft, but I really didn't want those MS style BASICs when I had BBC Basic)
C was never going to be part of the self-hosting system - I have bad memories of Aztec C on the Apple II - it took forever and didn't generate good code, and the C compilers for the BBC Micro were never that good, however one thing did stick out - BCPL. I used BCPL on the BBC Micro for a series of factory automation projects while at university - I had a lab of BBC Micros networked together each talking to a 6502 SBC that I'd made that did the actual hardware control. I edited, compiled and tested the BCPL programs directly on a BBC Micro then deployed them via the network to the station Beebs where they ran.
I still had all my old BCPL books so I got that old BCPL system up and running again (on the 6502 board and on the '816 board in emulation mode) to remind myself about it.
Compile times were acceptable, the code it generates was very compact (it compiles to a compact byte-code;
cintcode, which is them interpreted) and is generally 3-5 times faster than BBC Basic.
The old BBC Micro version of BCPL is a 16-bit system. Modern BCPL (It's still in active development by the original creator) is a 32 bit system (64 bit on some systems), so my thoughts were that if the 8-bit BBC Micro can run the old 16-bit BCPL, then my 16-bit '816 can run the 32-bit BCPL.
I'll cut to the chase. I have not particularly enjoyed programming the '816. Frankly I'm not surprised it wasn't that popular back in the day, especially when there were other 16 (and 32-) bit CPUs coming out at the same time. The banks of 64KB just add to the headache of it all. You need to pick your instructions carefully, some will wrap into the next bank and some won't. You have to make sure the assembler is in the right 8/16 bit mode and that the CPU is in the 8/16 right mode too. I decoded that I'd make the underlying memory system transparent to the BCPL code, so that took a little more effort but it now means I can allocate an array of 40,000 words (of 32-bits) and FOR i = 1 to 40000 DO ... with my cintcode system doing the hard work of keeping those 64K banks away from the higher levels. This has probably resulted in it not being a fast as it could be, but it has resulted in a very usable solution.
Cintcode is an interpreted byte-code. There are 255 opcode in it's instruction set, and so-far I'm implemented most of them. Enough to run most programs, including the compiler anyway. The interpreter is about 14KB of '816 assembly code and the bootstrap front-end is about 10K of compiled C. (Under all that is the RubyOS operating system which is about 10KB of mostly 65C02 code as I just ported it over from the old Ruby6502 board) I decided to not code for size, but for speed. Bank 0 holds all the 6502 and '816 executable code as well as the stack(s) and global vector(s) for the BCPL run-time.
I'm slowly working my way to eliminating the C by re-writing it in BCPL, but at some point I'm going to have to write bits of it in assembler as there is a bit of a "hole in my bucket" situation to do with setting up the memory and loading the cintcode interpreter and initial compiled BCPL libraries before you can actually run BCPL.
The compiler is working well but I'm not quite at the stage of compiling it directly on Ruby yet. It's showing up some limitations with my filing system which runs on the host processor, so I'm going to spend some time on that over the next few days.
If you want a quick video of it running, then:
https://www.youtube.com/watch?v=TBdiJiy8HtsFeedback welcome,
Cheers,
-Gordon