Virtual Basic is a set of rules for coding, and tools for writing programs in Applesoft Basic, in easily way with better productivity.
Virtual Basic extends the properties of Applesoft Basic adding new features like unnumered code, indent code, insert files and extends comments for better documentation.
Virtual Basic is not a new Apple II language, it's only "virtual" but it helps you to make your programs richer.
All you need is Applesoft Basic knowledge and a few new pratices.
About Applesoft Basic refer to http://en.wikipedia.org/wiki/Applesoft_BASIC
Before converting into applesoft basic, open you text editor
Create a new text file with baz extension for exemple myproject.baz and open/edit it.
You are now ready to write Virtual basic, first example :
s$= "hello world" print s$ a= 10: b= 5 print a + b
You don't need to number lines as usual in Applesoft Basic.
Now give a name to this code with the £ symbol as the first letter and add the word return at the bottom. Now you have a subscript with an anchor £printhello.
Warning you can't use specials characters (space, -, underscore...) in anchors.
£printhello s$ = "hello world" print s$ a= 10:b= 5 print a + b return
Insert this code after the end of the main program, the gosub @printhello will execute the subscript beginning at the anchor £printhello
rem my main program print "this is my first test" gosub @printhello end rem my subscript £printhello s$ = "hello world" print s$ a= 10:b= 5 print a + b return
Your don't need to remember what line number match with your subscript, it will be automatically numbered by the convert program.
If you want to use special characters like # £ and @ in you code (ex: in# command) just put a escape char like this \# \£ or \@ before.
Now it's time to convert the code in Applesoft Basic using the online converting tool (after we'll try the python script).
Copy the Virtual Basic code on the left and paste it in the online converting form and submit, you will get the code on the right
Virtual Basic | Applesoft Basic |
---|---|
rem my main program print "this is my first test" gosub @printhello end rem my subscript £printhello s$ = "hello world" print s$ a= 10:b= 5 print a + b return |
10 REM - BASIC - SCRIPT - 28/01/2011 - 05h44 20 REM MY MAIN PROGRAM 30 PRINT "THIS IS MY FIRST TEST" 40 GOSUB 80 50 END 60 REM MY SUBSCRIPT 70 REM->PRINTHELLO 80 S$ = "HELLO WORLD" 90 PRINT S$ 100 A= 10:B= 5 110 PRINT A + B 120 RETURN |
As you can see it's a perfect Applesoft Basic code, gosub @printhello has been converted to "GOSUB 80" and the lines are normally numbered, you can load and run it in your Apple II computer.
Now we will add some code in the middle of the Virtual Basic program and ignore the first print line with # symbol.
After that you have converted, you get this code on the right, try it into your emulator, as you can see the code is ready to be load and run.
If you want to add more information in your code try remgo option in the online tool.
Virtual Basic | Applesoft Basic | Applesoft Basic with "remgo" option |
---|---|---|
rem my main program £mainprogram # print "this is my first test" c= c + 1 if c > 2 then gosub @printhello if c > 5 then goto @endprogram goto @mainprogram £endprogram end rem my subscript £printhello s$ = "hello world" print s$ a= 10:b= 5 print a + b + c return |
10 REM - BASIC - SCRIPT - 28/01/2011 - 05h44 20 REM MY MAIN PROGRAM 30 REM->MAINPROGRAM 40 C= C + 1 50 IF C > 2 THEN GOSUB 120 60 IF C > 5 THEN GOTO 90 70 GOTO 40 80 REM->ENDPROGRAM 90 END 100 REM MY SUBSCRIPT 110 REM->PRINTHELLO 120 S$ = "HELLO WORLD" 130 PRINT S$ 140 A= 10:B= 5 150 PRINT A + B + C 160 RETURN |
10 REM - BASIC - SCRIPT - 28/01/2011 - 05h44 20 REM MY MAIN PROGRAM 30 REM->MAINPROGRAM 40 C= C + 1 50 IF C > 2 THEN GOSUB 120:REM GO->PRINTHELLO 60 IF C > 5 THEN GOTO 90:REM GO->ENDPROGRAM 70 GOTO 40:REM GO->MAINPROGRAM 80 REM->ENDPROGRAM 90 END 100 REM MY SUBSCRIPT 110 REM->PRINTHELLO 120 S$ = "HELLO WORLD" 130 PRINT S$ 140 A= 10:B= 5 150 PRINT A + B + C 160 RETURN |
The ignored code is gone, the lines are numbered again and the anchors are visible in the form of comment (REM->ANCHOR).
Isn't it easier than adding and playing with lines numbers ?
Now we will use some types of comments to make the script more understandable.
Virtual Basic | Applesoft Basic with "c" option |
---|---|
rem * this comment won't be seen in compact and ultracompact compression rem but this comment will be seen in compact compression [ this multiline comment is hidden ] {comment between braces are always ignored} # lines beginning with "#" are ignored too a{this is the first value}= 100 b{the second value}= 10 for i=b to a print "value ";a{first value} - i next {faster than next a} end |
10 REM - VIRTUALBASIC.ORG - ONLINE.BAS - 13/04/2011 - 17h39 20 REM BUT THIS COMMENT WILL BE SEEN IN COMPACT COMPRESSION 30 A= 100 40 B= 10 50 FOR I=B TO A 60 ? "VALUE ";A - I 70 NEXT 80 END |
Rem comments use memory space in Applesoft Basic, you must use Virtual Basic comments.
Virtual Basic allows you to add more features. You can split your code in sections with the keyword section and closesection.
Virtual Basic | Applesoft Basic with "c" option |
---|---|
section functions def fn alea{RandomNumber}(x) = int(rnd(peek(78)+peek(79)*256) * x + 1) closesection section main program £begin rem * my basic program r= fn alea(10) for i= 1 to r print i;" hello world" next if r < 9 goto @begin print "end program" closesection end |
10 REM - VIRTUALBASIC.ORG - ONLINE.BAS - 13/04/2011 - 17h48 20 DEF FN ALEA(X) = INT(RND(PEEK(78)+PEEK(79)*256) * X + 1) 30 REM->BEGIN 40 R= FN ALEA(10) 50 FOR I= 1 TO R 60 ? I;" HELLO WORLD" 70 NEXT 80 IF R < 9 GOTO 40 90 ? "END PROGRAM" 100 END |
It doesn't affect the code but it helps you to organise the code better.
Now you know the main pratices of Virtual Basic !
You can download the python script at the download page
It's very easy to run virtualbasic.py
1. Write your VirtualBasic code in a file (text mode with .baz or .txt extension)
2. Run virtualbasic.py and choose 1
3. virtualbasic.py create a new file with .bas extension
4. Open the new file and check it
5. Paste the code of the new file into emulator an run it
6. Save it if you want
You can try others options as the same way
In Virtual Basic you can import Applesoft Basic and Virtual Basic files into you program, it's very usefull if you want to reuse your code. But this feature it's only avaible with the python script on local computer.
Example : put in a text file random.baz this:
def fn alea{RandomNumber}(x) = int(rnd(peek(78)+peek(79)*256) * x + 1)
In your main program you can import the file random.baz adding "===insert " + filename + "===":
Run baz-to-bas.py python script, as you see the function fn alea() is imported | |
Virtual Basic | Applesoft Basic |
---|---|
# import random.baz and the function fn alea() defined before ===insert random.baz=== section main program £begin rem * my basic program r= fn alea(10) for i= 1 to r print i;" ";r;" hello world" next if r < 9 goto @begin print "end program" closesection end |
10 REM - BASIC - SCRIPT - 28/01/2011 - 05h44 20 DEF FN ALEA(X) = INT(RND(PEEK(78)+PEEK(79)*256) * X + 1) 30 REM->BEGIN 40 R= FN ALEA(10) 50 FOR I= 1 TO R 60 ? I;" ";R;" HELLO WORLD" 70 NEXT 80 IF R < 9 GOTO 40 90 ? "END PROGRAM" 100 END |
All the rules of Virtual Basic are listed before. If you have suggestions or questions you can contact me
and asc at atn call chr clear color cont cos data def dim draw end exp flash fn fre get gr hcolor hgr hgr2 himem hlin home hplot htab if in input int inverse left len let list load log lomem mid new normal not notrace on onerr or pdl peek plot poke pop pos pr print read recall restore resume right rnd rot run save scale scrn sgn sin shload spc speed sqr step stop store str tab tan text then to trace usr val vlin vtab wait xdraw xplot
,