Batari BASIC - a Basic Compiler for the Atari 2600 By Fred Quimby c9r@hotmail.com __________________________________________ Batari Basic is free and fully redistributable for non-commercial purposes. We are still trying to figure out the best license for this software, but Batari Basic will always be free. You can do whatever you want with Batari BASIC except sell it. You may also create derivative works from the source however you wish, but you must also provide these for free. Atari 2600 games created with Batari BASIC are exempt from the above rules, however. You may make cartridges of any games you write with Batari BASIC and sell them, provided someone out there will buy them, that is. ______________________________________ First and foremost: Why did I do this? Answer: Batari BASIC is intended as a beginner's platform so that one may become accustomed to the intricacies of the system. Although Batari BASIC is a viable development platform on its own, its real purpose is as a stepping stone toward 2600 programming using assembly language. Batari BASIC "lowers the bar" so that others with limited programming experience can write games that can run on a real Atari 2600 or an emulator. Although Batari BASIC uses a "canned" kernel which displays two player objects of any height, two missiles of any height, an asymmetric playfield, and a 6-digit score, the sources are included such that one may learn from them, and possibly even write one's own kernel for use with the compiler. Note also that it is also possible to adapt existing kernels to work with Batari BASIC. Batari BASIC is a Win32 command line program but is written in C, so it can easily be compiled for any platform. Soon a Mac OSX port will be available, but for now you can download the source code and compile it on nearly any platform that has a suitable C compiler. HOW IT WORKS _____________ Batari BASIC compiles a BASIC program written as a text file and converts it to an assembly-language program in DASM syntax. DASM is a free 6502 assembler. The DOS version of DASM is included with Batari BASIC and will be as long as the folks who wrote DASM don't tell me to quit including it. If you are using something other than DOS, you should download DASM for your platform. After Batari BASIC has generated an assembly file, it invokes DASM to convert the assembly-language to a binary that will run on an emulator or can be burned onto an EPROM and played on a real Atari 2600. The two-step compilation was done for two reasons: 1. It was easier to do this way. 2. This will hopefully encourage beginning programmers to look at the assembly-language program created by Atari 2600 BASIC so that they may see how it was translated, and ultimately so that they may learn how to write in assembly directly. About this version ______________________________________________________________________ This is Alpha version 0.3. It is fully functional but likely contains bugs. If you find any bugs, please report them to me at c9r@hotmail.com and include "batari" somewhere in the subject line. To learn how to use Batari Basic, please refer to FAQ, the help file (help.html) and the User's Guide, all included in this release. ______________________________________________________________________________ 1 set smartbranching on RUNNING THE COMPILER: _____________________ Extract the contents of the zip file to a new directory. The name of the directory doesn't matter. If you need to compile the source and are using a C compiler that supports makefiles, simply typing "make" will compile it. It has been compiled successfully on Linux and Mac OSX without any issues, and probably just about any other platform will work. Batari Basic is a DOS program which must run at the command line. However, if you prefer to use Windows only, Atari Age user Attendo has written a Windows-based interface that will run the compiler for you, plus run an emulator so you can immediately see the results of your program. The interface, called 2600IDE, also contains a sprite editor so you can easily design player sprites for use with Batari BASIC. 2600IDE is available at the Batari BASIC homepage. Note that to use Alpha 0.3 with 2600IDE, you must use the included 2600baside.bat file and not the one that comes with 2600ide. The easiest way to run Atari 2600 BASIC is to use the included batch file (2600bas.bat.) This is because the batch file will automatically do 3 things for you: 1. Run the preprocessor, then pipe the output to the batari BASIC compiler. 2. Concatenate the provided assembly files with the one generated by step 1. 3. Run DASM with the proper parameters to create a binary that will run on an emulator or a real 2600. To run the batch file, simply type: 2600bas where filename is the name of the BASIC source file you wish to compile. A sample file is included for you to test your setup, called sample.bas. To test this, type: 2600bas sample.bas If successful, a file called sample.bas.bin will be generated that you can run on an emulator. That the sample program is not very interesting, but note how simple it was to write... Open sample.bas in a text editor and take a look at how it was written. Revision History ________________ Alpha 0.3: August 23, 2005 Major changes: standard kernel now has the ball 8.8 and 4.4 fixed point types - automatic conversion from one type to another in assignments - addition/subtraction routines do automatic conversion if multiple types are used - immediate decimal numbers allowed, either negative or positive - 8.8 types can be used wherever integers are used - 4.4 can't be used anywhere but can be added/subtracted/assigned to other types data statement length keyword remove trailing commas from data statements set optimization for size/speed full divide/multiply - optional: multiply can produce a16-bit result or divide can produce remainder bit operations - assign one bit to another for-next loop bug fixed (foward loops by step >1 ended too soon) "else" allowed in if-thens Able to set the filename of variable alias file set ROM size to 2k or 4k smartbranching now accessed via set instead of rem REFPX bug fixed uses includes file for spcifying kernels and organizing modules include additional modules with include command pfread function (determine if pixel is off or on) fixed bug in decreasing for-next loops function declaration for user functions: - functions can be in bB or asm - optinally can be compiled separately and included as modules score=score+ var now supports vars other than a-z fixed bugs in if-thens for bit reads longer variable names allowed (50 chars max.) allow arrays as arguments in all functions (in user functions or built-in fns like pfpixel) improved error handling/reporting: - more descriptive errors - line in file now echoed const statement for defining constants optimized code fixed < and > comparisons, and added <= and >= fixed collision checks used lex to help with parsing/preprocessing score=score-1 bug fixed fixed bogus gosub/return errors on...goto now allows labels instead of just linenumbers allow negative numbers in code {whew!} Alpha 0.2: July 15, 2005 Major changes: score calculation improved. slight kernel improvements alphanumeric labels allowed, and labels/linenumbers are now optional. blank lines allowed indexing (array-like feature) implemented data statement implemented fixed bug in inline asm where it was impossible to add labels one boolean now allowed in an if-then (&&,||) ability to access individual bits fixed bug where return command wasn't recognized for-next loops added vastly improved parser - not nearly as sensitive to spacing dim statement for alternate variable names Upon compilation, DASM shows bytes free in ROM removed exotic illegal opcodes that would cause problems in some emulators, like PCAE Included files are now in cr/lf format to patch a limitation of DASM fixed various bugs in pfpixel and pfhline routines on....goto added Fixed problem where duplicate labels were created Alpha 0.1: July 7, 2005 Initial release.