BASLOAD

Stefan
Posts: 448
Joined: Thu Aug 20, 2020 8:59 am

BASLOAD

Post by Stefan »

Purpose
BASLOAD is a BASIC tokenizer/compiler that runs natively on the X16.

It loads BASIC programs stored in plain text format on the SD Card, and converts them to runnable BASIC programs stored in RAM.

The purpose of the utility is to make BASIC programming more convenient:
  • You may write BASIC code in the editor of your choosing; special bindings exist for X16 Edit
  • Line numbers are not used; instead you define labels as targets for GOTO, GOSUB and THEN statements
Example program

Code: Select all

LOOP:
   PRINT "HELLO WORLD"
   GOTO LOOP
Usage
Init BASLOAD by loading and running it as a normal BASIC program (LOAD"BASLOAD" and then RUN)

Store the example program on the SD Card in plain text format as "HELLO.BAS".

Type !L and press ENTER. This will start the loader.

Type in the file name "HELLO.BAS" and press ENTER.

The tokenized program should now be loaded into RAM. You can inspect the BASIC code by typing LIST, and start it by typing RUN.

More information and help
Go to https://github.com/stefan-b-jakobsson/basload to get more information and help on using BASLOAD.

#R44
Attachments
BASLOAD-0.2.6.PRG
(3.84 KiB) Downloaded 1167 times
Last edited by Stefan on Thu Nov 02, 2023 5:21 am, edited 8 times in total.
TomXP411
Posts: 1760
Joined: Tue May 19, 2020 8:49 pm

Re: BASLOAD

Post by TomXP411 »

Kudos for making this run on the Commander. The more compilers and dev tools we have on the machine, the closer we move to making this self-hosted.

The one thing I can suggest (without actually running the program yet) is maybe adding some notes to the Readme telling people what is needed to compile this: knowing which OS and toolchain are required would help for people wanting to roll their own version or make changes.
Stefan
Posts: 448
Joined: Thu Aug 20, 2020 8:59 am

Re: BASLOAD

Post by Stefan »

Thanks!

It’s built with ca65 same as the Kernal project. There’s also the script file build.sh you can use to build it with.

Anyway, I will look at the documentation.
User avatar
Cyber
Posts: 482
Joined: Mon Apr 27, 2020 7:36 am

Re: BASLOAD

Post by Cyber »

I'm also very glad to see such tool running natively on Commander. Cool stuff!
Stefan
Posts: 448
Joined: Thu Aug 20, 2020 8:59 am

Re: BASLOAD

Post by Stefan »

Version 0.1.1 uploaded. It's intended to fix some compatibility issues with R41.
The previous version did not correctly tokenize all new BASIC statements and functions added in R40 and R41.
Stefan
Posts: 448
Joined: Thu Aug 20, 2020 8:59 am

Re: BASLOAD

Post by Stefan »

Hi,

A new version of BASLOAD is now available that supports Kernal version R42, including development of the Kernal after R42.
Stefan
Posts: 448
Joined: Thu Aug 20, 2020 8:59 am

Re: BASLOAD

Post by Stefan »

Hi,

I think I now found the last major bug preventing BASLOAD from working under R43. A new version is uploaded.
voidstar
Posts: 445
Joined: Thu Apr 15, 2021 8:05 am

Re: BASLOAD

Post by voidstar »

Working well. Some notes: [wrt 0.2.1.PRG and r43]

- I can't use dash in the label. (I avoid underscore because they look funny over in PETSCII). This is fine, just might be handy to have a divider character for long labels (understood they are basically limited to 12 chars anyway). Small issue (I think in your instructions you were clear the label is starting with alphabet, then alphanumeric thereafter - so that's fair).

- While using a dash (mentioned above), I had an error in my code. When BASLOAD loaded the TEXT, it reported a line number of the error (the error was that the THEN had a missing label, because I had a dash in it). The error line number reported is of the converted program, not the original line number from the source text input file. Not sure if there is a way to get around that easily - but in fixing a program, I suspect most would be using the original text, not the tokenized code.

- I tried to "trick" BASLOAD using a mixture of lower case and upper case in the input! And it handled it greatly :) [ but as you know, when you open that text contain lower case in X16EDIT, you'll need to CTRL-E to cycle until lower case chars show up correctly -- but BASLOAD itself will nicely just convert the lower case to upper case ]


Sample:

Code: Select all

START:
    PRINT "HOW MANY?";
    INPUT N
    GOSUB SHOWHOWMANY
    
NEXTREAD:
    READ P
    IF (P=255) THEN DONEGRAPH
    GOSUB DOGRAPH
    GOTO NEXTREAD
DONEGRAPH:

    REM determine a guess value
    Z=INT(RND(TI)*100)
TRYAGAIN:   
    PRINT "GUESS? ";
    INPUT G
    IF G=Z THEN CORRECT
    IF (G>Z) THEN TOOHIGH
    IF (G<Z) THEN TOOLOW
    GOTO TRYAGAIN

TOOHIGH:
    PRINT "TOO HIGH"
    GOTO TRYAGAIN
TOOLOW:
    PRINT "TOO LOW"
    GOTO TRYAGAIN

CORRECT:
    PRINT "CORRECT!"
    GOTO START
    END

SHOWHOWMANY:
    FOR I = 1 TO N
      PRINT I,I*3.14159
    NEXT I
    RETURN
    
DOGRAPH:
    REM ARBITRARILY DECIDED 60 IS FAR ENOUGH
    A=0:IF P>60 THEN A=1:P=60
    FOR I = 1 TO P
      PRINT "*";
    NEXT I
    IF (A=1) THEN PRINT "+++";
    PRINT
    RETURN    
    
REM SOME GRAPH VALUES...
DATA 35, 25, 65, 55, 100, 5, 40, 50, 20, 255

Last edited by voidstar on Sat Aug 12, 2023 3:42 am, edited 1 time in total.
voidstar
Posts: 445
Joined: Thu Apr 15, 2021 8:05 am

Re: BASLOAD

Post by voidstar »

So, Stefan, what do you think about supporting long variable names?


The idea would be you could do INPUT ANS and then use ANS in the rest of the program. Then when it gets parsed, the tokenized version just starts with A (or A$) and "increments" on up. Obviously eventually you'd run out of space with long variables, so errors have to reported on that.

I imagine it'll be a little rough to support. How do you tell the difference between "ANS" and three variables "A" "N" and "S", maybe? Maybe that's a non-issue, but probably there is some other corner case I haven't thought of.

Labels can only be used in about 3 places (GOSUB, GOTO, THEN). But variables can be used in a lot more places. Getting passed line numbers is good, but then stomping over variables is next how people get themselves cornered in traditional BASIC. And it may be tough (on 6502 native) to add the intelligence to decide when it's "safe" to re-use a BASIC variable name.

Food for thought... (maybe use of arrays can somehow help?)
Stefan
Posts: 448
Joined: Thu Aug 20, 2020 8:59 am

Re: BASLOAD

Post by Stefan »

Dash (-) can’t easily be used in labels, as it’s also the subtraction sign and considering BASIC doesn’t require blank spaces anywhere. What about dot (.)?

Long variable names would be nice, but it requires a lot of changes. I’m not sure the current code base is good enough. Maybe I need to start over
Post Reply