Thoughts on BASIC

A project log for JJ65C02

Working on my own version of a 65C02-based SBC. Everything is open source and permissively licensed.

jim-jagielskiJim Jagielski 12/18/2023 at 14:080 Comments

Now that a lot of the hardware work has been done on the latest revision of JJ65C02, it's time to circle back and dive into the software side of things. My previous logs have described the updates to my miniOS for the system, and the integration with the Pi Pico, but the next stage is to see how best to update EhBasic to add graphics capabilities. This meant another deep-dive into the source for EhBasic and some thoughts about it which seemed like a good idea to post.

As noted in an older logEhBasic was chosen over some other BASIC alternatives that exist out there. I touched on some reasons for picking it, instead of the others, but there were other factors that went into that decision. First of all, although not ideal, EhBasic did, at least, have pretty clear licensing behind it. The others had (and still have, IMO) somewhat questionable IP provenance: what are the exact copyright considerations for these codebases? They don't seem to have been released into the Public Domain, or under an Open Source license, which really means that we actually don't have any rights to use them. Sure, MSBasic and others have been around for awhile, and some could (and have) argue that if Gates were going to complain or sue, they would have done so by now. But for someone who takes these things seriously, that isn't good enough. 

I also mentioned how of all the others, EhBasic was the easiest to port over to the ca65 toolchain, a non-trivial concern. Since I've baselined that development tool for all my work, and since it seems that most other serious 6502 hackers use it as well, providing an up-to-date port seemed like a worthwhile effort.

And finally, the code itself is well-enough architectured that after some time looking it over and playing around with it, you get a good understanding of how it all works, which is important when you want to fix or enhance it.

Which leads me into the next "theme" of this post, which is modifying EhBasic to support LOAD and SAVE.


Now miniOS does not include any sort of file-system capability; it's expected that in addition to the actual console of the SBC (the PS/2 keyboard and VGA monitor), that any sort of file transfers will be done using the RS232/serial interface. This means that, at a core level, both LOAD and SAVE will use XMODEM as the actual xfer mechanism, and that all LOAD and SAVE need to do is setup the correct pointers so that XMODEM knows where to read or write. This itself was trivial.

The real trick was that EhBasic doesn't store the text version of the BASIC program, but rather stores away its tokenized version which has already been "translated" from its original text. In essence, when you SAVE the program, you don't get (receive) the text version of your program, but a sort of binary version of it, meaning you can't then take that file and edit it with a standard text editor to make changes. It also means that you can't write the BASIC program on the host machine and then load it to EhBasic to run as-is. LOAD and SAVE all operate on this internal version of the BASIC program, not the original source itself.

The simple way around this is to use the functionality of whatever terminal emulator you have and save/load the source of the program by doing a LIST and then a text capture of what is printed, or a slow text paste of the source at the EhBasic prompt (so it thinks you are typing in the program). This is ugly and I'm looking into how to instead implement  PLOAD and PSAVE which work on the actual source.


Also as previously mentioned, I want to add to EhBasic the ability to use the graphics primitives provided by the Pi Pico support chip. Currently, one can easily call them using an extended set of ANSI/Xterm escape sequences (see here) but I was thinking that creating DRAW, PLOT, etc... BASIC commands might be easier. Adding the commands isn't really complicated, but the actual glue which then converts the BASIC parameters to the actual ANSI Escape sequence seems like a lot of work for no real benefit, especially since one can easily create a BASIC function to, for example, draw a line, and call that without an actual BASIC command itself.

In a similar way, I'm not sure if I need to create actual 6502 graphics library subroutine in miniOS that can be called directly; that would require another interface to the Pi Pico beyond the escape sequences, which to me would again be adding complexity for little real value. I need to think about this some more.

Onwards and upwards...