elaverick wrote:
Hi Thomas,
Thanks for the code, it looks pretty good. Am I right in thinking that ImportBASIC brings a standard TXT file into Memory and tokenises it, while ExportBASIC takes a BAS memory dump and detokenises it out as plain text? If that is indeed the case then I think I probably want to be taking it the other way (I.E. taking plain text from a char* and then writing that out as tokenized BASIC). To keep things nice and modular I want to keep the program as a seperate EXE so I think I just need to get my head around exactly what's going on and then flip the process.
Yep, you need to call SetupBASICTables() once so that it can prepare some look-up stuff (specifically, a sort-of hash table for faster string -> token lookup), then if you were to use it exactly as ElectrEm does you'd call ImportBASIC to have an ASCII file tokenised and stuffed into memory in the format the BASIC 2 ROM expects, ExportBASIC to have in-memory contents written out as an ASCII text file. Each returns 'true' on success, 'false' on failure. If there is an error, you can call GetBASICError to get a textual description of the error.
I guess you'd want to use a version of ImportBASIC, as it does the ASCII to tokenised conversion. The only internal function you should need to change is int my_fgetc, which acts just like fgetc but ignores \r. Adapt it to get the next ASCII character from wherever you'd prefer, obviously kill the stdio fopen/fclose/etc stuff and seed the Addr variable within ImportBASIC to 0 rather than to PAGE, kill the TOP sanity check and everything should work.
That is, assuming tokenised programs have exactly the same layout on disk/tape as in memory.