Magic GOTO lets any ordinary Applesoft program GOTO, GOSUB, or ONERR GOTO to a text label, instead of a line number. This makes programming in Applesoft BASIC much easier. For example, you can have code that looks like this:

(the GOSUB @ preps for the GOTO)




It doesn't matter what the line numbers are, and if you change them, no biggie -- you don't have to go back and fix all your GOTOs and GOSUBs. In fact, you can write your whole program without line numbers, in an editor such as TextWrangler, and then use its line numbering feature to automatically add line numbers when you're done.

You can contain Magic Goto in your Applesoft program by using special REM statements, or you can load it from a separate file on disk.

Choose your download flavor:
Copy-Pasteable text for emulators:  Magic Goto   Magic Goto with NuInput
disk image:  140K DOS 3.3   140K ProDOS   800K ProDOS  
ShrinkIt archive

Everything else you might want to know:
If you wish, you can view the Magic Goto assembly source code, or download it with its assembler (non Apple II friendly)

Magic Goto works on any Apple II with Applesoft BASIC. Applesoft itself is not modified in any way.

Thanks to Stavros and Martin for suggestions and comments.

How Magic Gosub came to be (optional reading): One day, a few years ago, I wanted to program in Applesoft BASIC after a very long hiatus, during which I became accustomed to more structured programming languages. So I decided that I would create rules for writing Structured Applesoft. As part of that, I realized that I really wanted named GOSUB targets instead of having to use line numbers, so I began experimenting, and discovered that Applesoft uses line 0 as a target if it doesn't understand what comes after a GOSUB or GOTO.

So I figured that if line 0 called a machine language routine that could search for the name, it could be done. But then I'd need distribute a file to BLOAD along with any Applesoft program I wrote: yuck. I looked into methods to deliver a routine within a program itself, and was dissatisfied with the options, so I instead came up with Slammer, and while writing its utility, I decided that Applesoft's INPUT statement sucked and there should be a better one, so I developed NuInput, and then got distracted with other stuff and never actually got around to the labeled GOSUB routine which was the reason I made those other things in the first place.

And then there I was at KansasFest 2012, and I decided to create Magic Gosub as my HackFest entry. I then polished it and released it. A couple of years later, I sat down to write some Applesoft, and even with Magic Gosub I found I still needed line numbers for this and that, like being able to GOTO backwards for a while structure. I wanted to code completely without line numbers, because they're awful, and even though it required many more bytes (and hours), we have Magic Goto. Hope ya enjoy it. it.

Version history:
2.0, Nov 2014: Supports GOTO, ONERR GOTO, search direction and start position.
1.0, Fall 2012: First release

Got a question about Magic Gosub?

Apple II Extravaganza Home Page