Goto 10 Retro - 22 Oct 2026
Be sure to check out Mark's Tekkie blog for more of his writings. - Paul
This is something I've been wanting to get out to Atari programmers for a while. It's about how to structure your Turbo-BASIC XL programs so they will translate correctly when run through the Turbo-BASIC XL compiler. While the interpreter is great, the compiler can be annoying at times, because of its limitations, and what it doesn't tell you about them (and Ostrowski may not have had the opportunity to document). Dealing with the compiler without this knowledge has been frustrating to Atari programmers. I kind of doubt this article is a complete list of what one needs to do so the compiler doesn't screw up your program, but I think this information would help quite a bit.
I started checking out Turbo-BASIC XL (which from here on, I'll call "Turbo Basic") on the Atari 8-bit about ten years ago, and was impressed with it, especially since it started life as a machine language type-in program out of a magazine.
It's a superset of Atari BASIC, but runs programs 2-3x faster. It will run any Atari BASIC program. It adds some features that almost negate the need for line numbers, but not completely. It enables structured programming, with added WHILE and REPEAT-UNTIL loops. It also adds IF-THEN-ELSE logic, while still supporting Atari Basic's IF-THEN statement, if you choose. Although, I've found mixing them together, like embedding an IF-THEN inside an IF-THEN-ELSE construct, can cause problems. It enables you to reference parts of a program, and branch, with labels, instead of using line numbers. Its documentation says it adds procedures, but I think of them as "named gosub's." You can branch to a subroutine by name, rather than a line number, but there's no parameter passing, and no automatic returning of a result. All variables are still global.
Turbo Basic expands the size of the variable table 2x, to a maximum of 256 variables (Atari BASIC allows 128). This helps with Turbo Basic's use of labels, since all labels are stored in the variable table.
It adds the benefit of having built-in DOS commands, so you don't need to go to DOS for most operations (except for copying a file, and copying and formatting a disk).
The "star of the show" seems to be its optimized floating-point. In tests I've done, it does floating-point 3x faster than Atari BASIC. Atari BASIC uses the floating-point routines built into the Atari's OS for all numeric operations, which Atarians know is pretty slow. Frank Ostrowski, the author of Turbo Basic, wrote his own routines in RAM, and almost completely ignored the much slower, built-in routines.
Turbo Basic does all this, adding 67 new commands, and 7 new operators, while giving you a bit more free memory than Atari Basic does, by turning the Atari Basic ROM off, and tucking part of itself "underneath" the Atari's operating system, which it can do on XL/XE systems.
That's something else: Turbo Basic only works on XL/XE systems with at least 64K RAM.
The reason having a Basic compiler is a plus is you can make your programs run significantly faster than in the interpreter.
A sad thing I noticed is that while Turbo Basic came with a compiler, it hasn't gotten nearly as much attention as the interpreter. I wondered why, and then I tried using it...
The interpreter works really well, and has been my preference for programming in BASIC on the Atari. The compiler is useful, but I must say it's poorly documented, and doesn't explain itself well at all. This isn't to say that Ostrowski didn't try to document it, since he wrote two magazine articles about it (along with the machine code listing). In my opinion, it's just that he didn't have enough room to fully say what needed to be said about it.
I went through the effort of translating Ostrowski's articles on his compiler from the original German, using Google Translate, with some of my own editing, to clear it up. You can read my English rendition through a couple RTF documents I posted on AtariAge.
How The Turbo Basic Compiler Works By Frank Ostrowski English Translation Of Turbo Basic Xl Compiler Info
76KB PDF file
Download
Download
Turbo Basic Compiler Type In Article By Frank Ostrowski English Translation Of Turbo Basic Xl Compiler Article
328KB PDF file
Download
Download
Ostrowski talked about some do's and don't's when writing your code to be compiled, but that doesn't nearly cover the guidance programmers need to use it. I ended up having to figure out some more do's and don't's through research, and trial and error. So, you can benefit from my experience.
The thing that's really disappointing is that the compiler hardly ever tells you that it had a problem with your program. So often, it gives you a benign message, "No errors", at the end. You hardly ever know whether it's been translated correctly or not. It's rather common for your compiled program to crash, or the runtime to give you an error that doesn't make sense in the context of what your program does. This happens even though your program runs fine in the interpreter. It usually gives you no clues as to why it had a problem.
So, what I'm going to talk about is what I've done to avoid this problem.
The main thing to always keep in mind is keep expressions simple, and lines of code short. This is the best overall advice I can give. Long, complex lines of logic are likely going to be a problem when you try to run your compiled program, with one exception I'll note. Length isn't always the problem. There are cases where it just can't handle anything more than drop-dead simple expressions.
In each example, I'm going to start with what not to do, and then show how to "fix" it so the compiler will translate it properly.
Do not embed array references, like:
100 A=ARR1(ARR2(IDX))
Instead, do something like:
100 B=ARR2(IDX):A=ARR1(B)
Do not involve more than two array references in an expression, like:
100 ARR(IDX-1)=ARR(IDX-1)-ARR(IDX)
Instead do something like:
100 VAL1=ARR(IDX-1):VAL2=ARR(IDX):ARR(IDX-1)=VAL1-VAL2
Like I was saying, something like:
100 ARR(IDX-1)=ARR(IDX)
will work.
You can, however, have many constants, and plain variable references in an expression, like:
A=1+B*SQRT(C)/EXP(D)
and it's not a problem. In my experience, expressions like this will translate correctly.
Do not use more than one boolean operator in a conditional statement, like:
IF COM$(8,8)="D" AND (COM$(9,9)=":" OR COM$(10,10)=":") ... do stuff ... ENDIF
This was the most disappointing limitation, because I find it makes more sense to have conditional expressions like this.
Instead, break it up into an equivalent series of nested expressions:
IF COM$(8,8)="D" IF COM$(9,9)=":" OR COM$(10,10)=":" ... do stuff ... ENDIF ENDIF
Though Ostrowski's documentation talked about having DATA statements at the beginning of a program, and indicated that was fine, I've found it's best to put DATA statements at the very end of your code. I've had situations where I've put DATA statements in the middle of my code, like:
main body
procedures
DATA statements
more procedures
The interpreter is fine with this, but the compiled version didn't work. If I moved the DATA statements to the end, the compiled version worked.
I've found that while it can seem normal to put a lot of code in a single line, maxxing out the line length limitation of code input, this is not a good idea when compiling your program. It's best to break up that code into separate lines, maybe a max of 40 characters each, if not shorter. This isn't strictly a character limit, since the compiler only deals with tokenized (SAVE'd) code. It's just been my experience that longer code lines result in the compiler screwing up the translation.
I also remember reading through an article on AtariWiki (though, I can't find it now) that the compiler has a smaller limit in the maximum size of the variable table than the interpreter does. Don't quote me, but I think I read the compiler's limit is in the range of 190-200 variables/labels. Again, the compiler will say absolutely nothing if you exceed this, in my experience. Your program just won't work.
Seeing these limitations has really made me wish that the source code for the compiler had been saved, and put out on the internet, as was done with the interpreter. I might've gotten interested in trying to improve it.
Once you've compiled your program, how do you run it?
The compiler "package" comes in two parts: the compiler, and the runtime.
Ostrowski's documentation only talked about setting up a boot disk, where you rename the Turbo Basic runtime to AUTORUN.SYS, and your compiled program to AUTORUN.CTB. This will cause your Atari to load the runtime at bootup, which will then automatically load and run your compiled program.
It's possible to, instead, load your compiled program from DOS, but it's a bit quirky. Your compiled program doesn't run by itself. It needs the runtime to run it. You can do this from from DOS by using "L" to load a binary program. Use D:RUNTIME.EXE (or .COM or .OBJ, whatever the extension happens to be) for the program name. When the runtime loads this way, it will give you an Error 170 for "file not found." The reason for this is it expects to find AUTORUN.CTB on the same disk. However, it doesn't just error out. It gives you a brief menu:
DOS, Run, or Load?
If you press "L" for load, it will prompt you for a filename. This is where you can type the name of your compiled program. It will load and run it.
If you hit "D" for DOS, it returns you to DOS. The "R" option is only good if a compiled program is already loaded. It's like typing RUN in the interpreter. It re-runs the program.
More Goto 10 Retro | Headlines
Original: https://www.goto10retro.com/p/advice-on-using-the-turbo-basic-xl