Toolkit for Applesoft BASIC

14 posts / 0 new
Last post
LoadError's picture
Offline
Last seen: 1 month 3 weeks ago
Joined: May 11 2021 - 04:34
Posts: 24
Toolkit for Applesoft BASIC

Hello everyone,

I'm an Apple IIc owner and I would like to port a little BASIC project to the Apple II platform (so far I've done Commodore 64, Commodore VIC-20, Sinclair ZX Spectrum and Sinclair ZX81 versions).

My goal is to work on Microsoft Windows, test the code in an emulator (AppleWin), and when ready, trasfer the program to a 5,25" floppy disk and to the actual hardware.

I'm having trouble finding a working development toolkit. I'd found two very promising tools, but one (Virtual BASIC) still has its web page but apparently there are no download links (it's unclear if there ever was a version for Windows, as the screenshots apparently are from Ubuntu, but that would not be a major problem) and the other (WASP) does not seem to be working in conjunction with AppleWin (whenever I try to run the code in AppleWin within WASP I get an "emulator not running" error, maybe WASP was using some Windows API that can no longer be leveraged, or maybe it doesn't "talk" to the current version of AppleWin).

I know I can copy and paste code from a text editor to AppleWin, but that is hardly ideal.

Any idea?

Thanks!

 

mmphosis's picture
Offline
Last seen: 1 week 1 day ago
Joined: Aug 18 2005 - 16:26
Posts: 373
AppleCommander

https://applecommander.github.io/ac/

Put standard input BASIC source code onto disk image as a BASIC file

cat sample.bas | ac -bas test.dsk sample

LoadError's picture
Offline
Last seen: 1 month 3 weeks ago
Joined: May 11 2021 - 04:34
Posts: 24
Thanks; that looks like a

Thanks; that looks like a good alternative way to get the code on to the emulator, but what I 'm looking for is really some sort of development tool/programming aid. The main issue with these old BASIC dialects is with line numbers and jump statements, so a renumber feature would be ideal, and a solution to automatically generate line numbers with or without labels would be even better. "Virtual BASIC" apparently did the latter, but it seems to have disappeared from the web.

mmphosis's picture
Offline
Last seen: 1 week 1 day ago
Joined: Aug 18 2005 - 16:26
Posts: 373
Virtual Basic

I found it:  http://virtualbasic.org/

And, all of the source code is on bit bucket:

https://bitbucket.org/andresloz/virtual_basic/src/master/

It is written in Python2, uses tKinter, and includes a gui editor!

Virtual Basic has a command line:

********************************************************

 *** VirtualBasic command line tool ********************

 *** Andres Lozano a.k.a Loz, copyleft, 2011-2015 ******

 1) To convert VirtualBasic => Applesoft Basic

    After choice 1 you can add parameters ex: 1 c remgo

    c) compact code

    e) emulator ready

    u) ultra compact code

    remgo) add goto, gosub information if possible

2) To convert Applesoft Basic => VirtualBasic

3) To compact Applesoft Basic code

4) To merge in one file all inserts VirtualBasic files

 

I also found MAGIC GOSUB, but it is not a full-featured as Virtual Basic.

http://appleii.ivanx.com/magicgosub/

 

mmphosis's picture
Offline
Last seen: 1 week 1 day ago
Joined: Aug 18 2005 - 16:26
Posts: 373
ideas

Thanks for bringing this topic up. Currently, I copy and paste code. It's a bit of a pain. I've been thinking about ideas for how to make this better.

I started creating a command line utility that converts text to Applesoft file format. It got me thinking about how to parse the source code, including automatically generating line numbers. From what I gather, you are trying to make your code more readable. I usually go the other way and make my code less readable to optimize for speed because Applesoft is slow enough already. I compact as many statements onto a single line. I try to store values in single character variables rather than hard-coding the numbers. I order the most frequently used routines to the beginning of the program, for example. I try to avoid using GOTO, and write the code using FOR ... NEXT to avoid line numbers. Virtual Basic looks like it has a "ultra compact code" option that would do some of what I want.

I use a bunch of different Apple II emulators. I've even toyed with and created my own. I like AppleWin and run it even though I run it via Wine on Linux. There is the debugger in AppleWin, and I think there are commands to load files into directly into memory. It would be cool to edit code in a programming editor of our choice, hit F5 (or Command R) and run the code instantly in the emulator. And, I am not talking just about Applesoft, but other languages CC65, 6502 assembly, PLASMA, and many others. I've been thinking about how to run code "hot" and "live" in memory within my own toy emulator.

 

Offline
Last seen: 6 days 13 hours ago
Joined: Jul 5 2018 - 09:44
Posts: 611
You might or might not find

You might or might not find some of these useful.

 

https://github.com/softwarejanitor/applesoft_tokenizer

https://github.com/softwarejanitor/applesoft_detokenizer

https://github.com/softwarejanitor/DOS33

https://github.com/softwarejanitor/ProDOS

 

 

 

LoadError's picture
Offline
Last seen: 1 month 3 weeks ago
Joined: May 11 2021 - 04:34
Posts: 24
Nice find! I am totally going

Nice find! I am totally going to give Virtual BASIC a spin. Thanks!

mmphosis's picture
Offline
Last seen: 1 week 1 day ago
Joined: Aug 18 2005 - 16:26
Posts: 373
re: applesoft_tokenizer.pl

Thanks for those.

 

I am testing applesoft_tokenizer.pl with some test files.  I am not a Perl fan, but bonus points that this is written in Perl.

I like this, it simplifies the code:

# Reverse sort the keys to prevent ATN being turned into AT N

my @tokenstrs = reverse sort keys %tokens;

It doesn't parse quite like Applesoft does, but maybe that's also a bonus.

It allows line numbers > 63999

It allows subsequent lines to have the same line number.

It allows line lengths > 239, and even line lengths > 255, although for really long lines, I think Applesoft starts to have problems.

 

 

 

LoadError's picture
Offline
Last seen: 1 month 3 weeks ago
Joined: May 11 2021 - 04:34
Posts: 24
Lots of solution have come up

Lots of solution have come up! Let's make this a sticky =)

LoadError's picture
Offline
Last seen: 1 month 3 weeks ago
Joined: May 11 2021 - 04:34
Posts: 24
Unfortunately Virtual BASIC

Unfortunately Virtual BASIC does not seem to be compatible with recent versions of python and would need rewriting.

LoadError's picture
Offline
Last seen: 1 month 3 weeks ago
Joined: May 11 2021 - 04:34
Posts: 24
Sorry to answer myself, but

Sorry to answer myself, but the forum does not allow to edit a post after 60 minutes. Just to share that I have been able to run Virtual BASIC with pythonw version 2.7; I used the portable version because I did not want to install it side by side with v3; I just moved all the VB repository in the same directory as python-portable and then launched VBEditor with pythonw-portable.exe virtualbasiceditor.pyw... works. :)

Offline
Last seen: 6 days 13 hours ago
Joined: Jul 5 2018 - 09:44
Posts: 611
mmphosis wrote:Thanks for
mmphosis wrote:

Thanks for those.

 

I am testing applesoft_tokenizer.pl with some test files.  I am not a Perl fan, but bonus points that this is written in Perl.

I like this, it simplifies the code:

# Reverse sort the keys to prevent ATN being turned into AT

 

I wrote that for one thing I needed to do and I haven't done much with it in a while.  I hadn't noticed what you mention about it allowing higher line numbers or long lines.  As you say it could be a bonus.  If it was something that shouldn't be allowed, it would be possible to make the behavior be to prohibit those things normally and provide a command line flag to override them if desired.

 

I write a lot of stuff in Perl.  I know a lot of people hate it, but it gets things done.

 

mmphosis's picture
Offline
Last seen: 1 week 1 day ago
Joined: Aug 18 2005 - 16:26
Posts: 373
AppleWin savestate.aws.yaml

In the "Advanced" tab in AppleWin Configuration, there is a Save State section.

Save State (F11 during emulation)

Load State (F12 during emulation)

I am looking into automatically writing tokenized Applesoft binary directly into this file.

 

So in theory, I write code in an editor of my choice. I press Command+R (or F5) to Run which runs a script which might do all of this...

  • Parse the current source code text file, possibly with some features like
    • use labels instead of line numbers (like Virtual BASIC does.)
    • ignore leading tabs (indented code)
    • long variable names get converted to a pool of single character Applesoft variable names
    • save a symbol table (of routtine & variable names), and optionally append the symbol table as comments in the Applesoft program
  • Tokenize the output into the Applesoft Basic binary format.
  • update savestate.aws.yaml
    • maybe even update the Program Counter (PC) to automatically JuMP to the RUN routine.
  • make AppleWin the frontmost window
  • send F12 (load save state) and enter key (open default save state file) to AppleWin

 

Should also be able to go the other way:

Press F11 (save state), and a daemon watching for the save state file to change, runs a script to detokenize, format, and open the source code the editor of my choice.

LoadError's picture
Offline
Last seen: 1 month 3 weeks ago
Joined: May 11 2021 - 04:34
Posts: 24
That would be **awesome**

That would be **awesome**

Log in or register to post comments