I'm building a home-brew system based on the OSI Superboard II that I started with long ago (HW details in this thread:
http://forum.6502.org/viewtopic.php?f=10&t=5559 ) and one of the things I'd like to improve is the process of saving and loading programs. The original OSI approach was that SAVE just piped text output to the ACIA and thence to the FSK modulator for tape output. The user would then LIST which would spew the code (with some NULLs added after every carriage return to allow BASIC some time to parse the line) and when the listing was over you'd hit the space bar to stop the pipe to serial. LOAD worked similarly, redirecting serial input from tape, with a tap on the space bar to bring the focus back to the keyboard after the stored text was complete.
For my new system I'm going to use a large SPI flash memory instead of serial tape. BigEd pointed out that storing code as untokenized text is most portable and I agree, but that presents a bit of a challenge in getting the human-readable code out automatically. The original MS BASIC code doesn't treat the LIST command as a callable function so I can't easily hijack it.
What I've done is to copy most of the code for LIST and wrap my new SAVE code around it. SAVE now has an argument that lets me specify a "slot" in flash memory that can save up to 32kB. This is bounds checked and then converted to a starting address in flash. Then I hijack the BASIC text output vector and redirect all output to my flash write routine. I generate a listing which is then saved to flash. When the listing is complete I restore the normal output vector.
For LOAD I also take a slot argument, convert it to a memory address and set up to read the flash. Then redirect the input vector to my flash reader and return. When BASIC next asks for a key it gets the stored text from flash until the end of the code is detected (the natural $FF that blank flash contains). At that point I restore the input vector and the LOAD process is over.
This is basically working now, but it's been an interesting bit of research to safely hook in to the ancient BASIC. I've made a lot of use of the "unofficially released" source code that's out there and studying Paul Allen & Bill Gates' code has been enlightening. Now I just need to poke at it some more and see if it's reliable.
Anyone else tried this sort of thing?