This is a sort of spin-off from my recent post where i benchmarked my BCPL system against C... It's a bit rambling - grab a coffee!
Read here if interested:
viewtopic.php?f=1&t=8140As is often the case, the subject drifted to languages and systems I didn't mention, so I thought I'd start afresh.
My interest today is in self-hosted/hosting retro style systems. Along the lines of "what can we do with todays knowledge that we couldn't do
back then".
Spoiler: Not a lot.
One issue appears to be the sheer diversity of 65xx systems. Kim/Sym/Aim, Apple 1, II (e and c), ///, gs. OSI/UK101, Acorn (System 1/2/3/4/5, Atom, BBC Micro/Master/Electron), Tangerine (MicroTan, Oric), Atari, Commodore (PET, VIC20, C64) and I'm sure a few more...
What did they all have in common? Well, apart from the CPU really nothing. Maybe a Microsoft derived BASIC is most (but not all) with a company supplied "monitor" or Operating System.
Compare to the Z80 - Just as much diversity but also a lot of commonality in the OS, or ability to run an OS; CP/M.
And that OS lead to maybe more "grown up" software - compilers, business applications and so on - but the important bit is that it generally wasn't tied to a particular hardware platform. You can run Wordstar on many different CP/M systems - can you do that with Appleworks or Wordwise? (BBC Micro)
OK, that maybe a bit of a sweeping generalisation, but you get the idea - there really isn't a common OS base for the 6502.
My idea was to see what I could do in the self-hosting world. I was after a system with a compiler for a high level language with an operating to support it. Good terminal support, graphics optional.
And it's not been easy.
Everyone wants C - because everyone knows C or knows that is where it's at - it's been popularised over the Arduino microcontrollers (and others) mostly in the form of C++ but most Arduino code I see is more or less C. C is what Unix is traditionally written in - basically its everywhere. The original Arduino while being an 8-bit micro at heart has a plethora of 8, 16 and 32-bit registers and other features which makes it a very good target for C.
Putting together a 6502 system to run BASIC is relatively easy though, so that's what most of us do - and what I did initially. There are dozens of little SBCs out there that all run WozMon and EhBasic...
I wrote my own version of the 2K woz-mon (Apple II variant) and got Applesoft going to a degree, but decided I wanted something better and went on to write my own implementation of Acorns operating system so I could run the much better and faster BBC Basic. That was fine - I could write BASIC and assembler (BBC Basic has one built-in) I had a filing system with an interface to suit BBC Basic, and a graphics terminal but it didn't really satisfy the desire for a C or C like language.
A quick search found that there wasn't really any native C compilers for the 6502. Well, there are - Aztec C runs on the Apple II. Orca C (written in Orca Pascal also support Modula 2) runs on the Apple //gs. There are 2 variants of SmallC that run on the BBC Micro, but finding one that was general purpose enough to port to my system was seemingly not possible.
There was C in the form of cc65 and I had already used the ca65 assembler from that package. It wasn't hard to write a new target for it and implement it on my Ruby system.
But it was still cross-compiled.
And that may be good enough for most - e.g. the Arduino folks who are used to cross compiling but it wasn't what I was after.
I looked at other languages - Forth - used it, not a fan. Same for Lisp and then remembered something I'd used on the old BBC Micro back in the early 80s: BCPL. Dug out my old books, got the Acornsoft ROM image and utilities and it ran beautifully on my Ruby 6502 system.
That all started 6 years ago - what now? Well, we do have better C compilers but they're still cross compilers.
I also wanted to know more about the 65c816 so looked for systems - found none other than the Apple IIgs but they're silly expensive in the UK and the Acorn Communicator is as rare as a rare thing. The 8-bit guy was talking about his ideal micro, Stefany Allaire made the Foenix 816 system (stupidly expensive to get in the UK) so I stuck an '816 in my 6502 board - it worked - then made a new board with the '816 and 512KB of RAM. It worked and I ported my OS to it, got everything working as before but wondered how to use all that extra RAM - No C compiler at the time supported it. Bother.
So, back to BCPL and I figured along the lines: "Well, Acornsoft BCPL is a 16-bit system in an 8-bit CPU, so
how hard can it be to implement a 32-bit BCPL in a 16-bit CPU". Turned out to be harder than I thought and I've grown to dislike the '816 or at least not enjoy writing code for it any more. It's not as easy to write assembly code for as the '02 - it does require a different mind-set to utilise the banked memory system efficiently and effectively and remember the mode/width of the registers. A high level language compiler using its native stack should be possible to generate good code though, but what did a few years back? I'm not sure anything did....
However, once I had the bytecode interpreter going I could concentrate on the high level stuff and very quickly I implemented the run-time libraries (memory allocator, interface to filing systems, termina IO, graphics and so on) wrote a CLI and had the compiler running natively and had re-written my editor in BCPL so I had achieved the goal of self hosting. (Almost - I've yet to write an assembler - small detail!)
What other languages?
In my other thread there was mention of Plasma - which does indeed look good, but just how portable is it?
viewtopic.php?p=109005#p109005It currently runs on an Apple II with ProDOS. It may be portable, but has it been tried?
The same might apply to other Apple languages UCSD Pascal (Does run on other systems, but porting doesn't appear easy) their Logo, Lisp,
Another that's not been mentioned for a while is CowGol.
http://cowlark.com/cowgol/index.htmlit's currently based round the BBC Micro and might be somewhat tricky to port too.
A solution would of-course be for me to write a C compiler in BCPL - after all, C originated from BCPL (via B) so it's been done before... I'm not a great compiler writer though.
And then portability... The current BCPL compiler can output a few different binary formats - one is called cintcode - it's a Compact Intermediate Code - a bytecode representing a sort of ideal cpu - for BCPL anyway.
Could my system be ported to another '816 system? Very probably, but - just how many are there out there and who might actually want it?
What about other systems? Well, actually, yes. And it's turned out to be much easier than I thought. Just re-write the bytecode interpreter and filing system/terminal interface and off you go. I have done this twice now - once to RISC-V and currently to ARM. The beauty of that was that it was portable at the binary level. I did not have to even re-compile the utilities or even the base operating system. Just the slog of writing the bytecode interpreter and run-time...
Anyway, here we are - I'd still like to pursue the idea of another self-hosting high level language on the 6502, but I suspect what it would really need is a common OS to run it on. Currently there are 2 different CP/M type OSs for the 6502 that I know of, but really, it's 2024 and I do not want the CP/M filing system and its 128 byte blocks with no real idea of file length. That might have been good enough for 1978 but also in 1978 I had the Apple II and it's DOS which gave me a good filing system - maybe I've been spoilt since them... And of-course theres the issue of memory - 64K in the 6502 - with various banking schemes to extend it - it does make it fiddly though - the best I know about is that in the BBC Micro but even then the most contiguous RAM you have is some 36KB with the top 16KB of that being switchable ($8000-$BFFF, it's ROM from $C000-$FFFF minus the IO area)
The only other "generic" OS I know about is Fuzix:
https://fuzix.org/ it still needs a cross compiler for the 6502 and mentions:
Quote:
Currently this port targets the RCbus 65C02/65C816 cards and the PZ1. Most of the "classic" 6502 systems have neither the memory or the I/O, and in most cases even when they are upgraded with some of the late era processor upgrades still lack decent I/O.
I think we're stuck in the 6502 world and it's every one for themselves and
https://xkcd.com/927/ be damned!
-Gordon