Page 1 of 1

Implementing SAVE and LOAD

Posted: Tue Jun 05, 2012 3:34 pm
by tranter
Is anyone familiar with how to save and load EhBASIC programs? It's not clear to me what range of memory needs to be saved and restored.

I'm working on integrating the CFFA1 flash memory card with EhBASIC on Apple 1/Replica 1 systems. It's further complicated by the fact that the CFFA1 firmware uses a lot of locations in page zero that are also used by EhBASIC so they need to be correctly saved and restored.

Any pointers would be appreciated.

Re: Implementing SAVE and LOAD

Posted: Tue Jun 05, 2012 3:55 pm
by 8BIT
I did this on my SBC's. If you download this zip file:

http://sbc.rictor.org/download/sbc2os.zip

And open the os_src.zip file, there is a basldsv.asm file.

The psave routine provided the start and end address that was used to allow the xmodem file transfer to save the file. This was done from the command line.

the pload routine assumes that the basic file was loaded, starting at the smem address. It then scans the entire program until it finds the end. it then updates EHBASIC's pointers and jumps into the LAB_1319 whre it does some house keeping and returns to the input mode.

Using these two routines, you can interface any file storage system to EHBASIC.

Hope that gets you started.

Daryl

Re: Implementing SAVE and LOAD

Posted: Tue Jun 05, 2012 4:04 pm
by tranter
Thanks, I'll take a look at that.

Re: Implementing SAVE and LOAD

Posted: Tue Jun 05, 2012 6:42 pm
by leeeeee
If you want to save the program as binary you should save (Smeml) to (Svarl)-1.

If you want to save the program as ASCII you should redirect the character output vector to write to your filesystem and then call LIST. Doing this can also allow you to specify line numbers or ranges as with LIST. The output vector should be restored and the file closed when LIST returns or an error is encountered.

To load a binary program start loading it at (Smeml) and set (Svarl) to the last address + 1 then call LAB_1477 to clear the variables and reset the execution pointer. An easy way to do the first part is by copying (Smeml) to (Svarl) and using (Svarl) as a post incremented save pointer. If there is a chance that the program has been relocated it's probably a good idea to rebuild the line pointer chain.

To load an ASCII program redirect the character input vector to read from your filesystem and return to the main interpreter loop. The input vector should be restored and the file closed when the file end is reached or an error is encountered.

I prefer ASCII format as it's far more portable, easier to manipulate and can include direct commands and comment lines that aren't saved to memory.

Lee.

Re: Implementing SAVE and LOAD

Posted: Tue Jun 05, 2012 7:04 pm
by tranter
Thanks, this will be helpful too.

I was also thinking about using ASCII format, and may pursue that, but the CFFA1 APIs don't directly support reading and writing text files, so that would take a little more effort.

Re: Implementing SAVE and LOAD

Posted: Wed Jun 06, 2012 12:57 pm
by tranter
I've got it working. Thanks again.

Is there an easy way to support a filename in the LOAD and save COMMANDs, and get access to that from my code? Right now I am prompting the user for it.

Re: Implementing SAVE and LOAD

Posted: Wed Jun 06, 2012 5:10 pm
by leeeeee
Quote:
Is there an easy way to support a filename in the LOAD and save COMMANDs
Call the evaluate following expression routine, LAB_EVEZ, and look for a string by testing if the data type flag, Dtypef, is negative. If it is the string descriptor is on the descriptor stack so don't forget to pop it off there by calling LAB_22B6 once you're done with it.

Lee.

Re: Implementing SAVE and LOAD

Posted: Sat Jan 23, 2021 3:01 pm
by JenniferDigital
I just thought I'd pop by to say thank you for this post and Daryl for his code here. I didn't realise I'd be needing to update any pointers upon loading BASIC code until things went sideways :oops: but once again, it's the brains trust to the rescue. :D