batari Basic

Tutorial - Session 2

by Michael Rideout

To program for the Atari 2600 using batari BASIC, you'll need to have the following:

A Computer

Since the batari BASIC compiler actually runs on a computer, you'll obviously need a computer. And since you're reading this tutorial in an online forum, I presume that you already have a computer! However, your computer must use an operating system for which all of the necessary tools are available.

I'm using a computer running Windows XP, and batari BASIC is probably most readily accessible for a Windows computer-- because the Windows executables for batari BASIC are already built when each new version is released-- so for the most part this tutorial assumes that you're using a Windows computer. (By the way, I was still using Windows 95 up until a few months ago, and I was starting to run into compatibility issues with some of the tools, so if you're still using Windows 95, you might want to consider upgrading to at least Windows 98, if not a more recent version like Windows XP.)

If you're using Mac OS X or Linux, some binaries have been built for your convenience and are available for download on the download page. The OS X version was created under Tiger (10.4) and has not been tested with older versions (if you do try it out on 10.3 or older, let us know.) The Linux binaries were built under Ubuntu, but since they were statically linked, they should work under other distributions and probably older kernel versions as well. Configuration under Linux or OS X is covered in the installation document on this website.

If you can't use the builds available or if you're using some other operating system altogether, you'll probably need to build batari BASIC executables, and possibly executables for some of the other tools, which will run on your system. I encourage anyone using another operating system to contribute comments or instructions, and to post any executables that you've had to build, for the benefit of any other readers who are using the same operating system as you.

A Text Editor or IDE

You'll need a text editor to write your programs with. Any text editor will do, even a word processor, as long as you save your program source code as a plain ASCII text file so batari BASIC and DASM can read it. Note that all text editors are definitely not equal, so you may already have one that you prefer to use.

If you're using a Windows computer, you can use EDIT.COM, Notepad, or WordPad, all of which are included with Windows. EDIT.COM is the old MS-DOS editor, so it runs from the command prompt (just open a command prompt and type "edit"), and it doesn't look as "pretty" as Notepad or WordPad. However, EDIT.COM lets you edit multiple files at the same time, whereas Notepad and WordPad can work with only one open file at a time. On the other hand, you can always open multiple copies of Notepad or WordPad if you want to edit more than one file at a time. In any case, I suggest that you use EDIT.COM, Notepad, or WordPad only if you have no other options available.

Instead, you are strongly urged to use an IDE ("integrated development environment"), which is simply a special text editor that can be set up to compile and run programs in different programming languages. Again, all IDEs are not equal, and if you're a programmer, you may already have an IDE that you prefer. There are some advanced IDEs that are sold commercially, but unfortunately they tend to be a bit pricey, since they're marketed to professional programmers. There are also some good shareware and freeware IDEs available, although they tend not to be as feature-laden as the upscale commercial IDEs.

In this tutorial, I'll be using Crimson Editor, which is a free IDE for Windows that's available over the internet. In Session 3, I'll show you how to set up Crimson Editor to compile and run batari BASIC and 6502 assembly language programs.

Another option is to use the free 2600IDE program which Jacco Mintjes ("Attendo") created specifically for batari BASIC. Although 2600IDE doesn't have all of the editing capabilities (e.g., search, or search and replace) that are standard with most text editors, it does have a built-in sprite editor and playfield editor, and it's easy to use with the batari BASIC compiler and an Atari 2600 emulator. 2600IDE can also be used to write, compile, and run pure 6502 assembly programs.

Finally, there was an MS-DOS based IDE called ADEV that came in the 2600SDK package, which was a package put together by Matthew Ozor, that used to be available on the DASM web site. The IDE was essentially like the EDIT.COM editor, but it included the ability to compile and run programs. Unfortunately, the link to download the 2600SDK package no longer works. Fortunately, Crimson Editor lets you do everything (and more) that the ADEV IDE let you do. Nevertheless, if you'd like to try the ADEV IDE, I've uploaded a copy of it to the AtariAge website.

Non-Windows users are encouraged to post suggestions for text editors and IDEs that run under their chosen operating systems.

The batari Basic Package

This one goes without saying! The next session describes in detail how to download and install it.

The DASM Assembler

Compiling a batari BASIC program is actually a four-step process. First, the batari BASIC program listing runs through a preprocessor, then it's passed to the batari BASIC compiler, which converts it into a 6502 assembly language source file. This assembly file is linked to other assembly files to create a single composite assembly file. Then this assembly file must be compiled into a binary ROM image file using a 6502 assembler. The batari BASIC compiler creates assembly code which is formatted for the DASM assembler, so it's expected that you'll use that assembler. If you insist on using some other 6502 assembler, you'll need to be sure that it can handle the format used by DASM, or else you'll have to convert the DASM-compatible code to a format that's acceptable to your chosen assembler. Obviously, the preferred course is to just use DASM.

Although the batari BASIC package already includes the Windows build of the DASM assembler, you're encouraged to download and install the DASM package separately, if only for the documentation that comes with it. And if you're using a non-Windows system, then you must download the DASM package separately, because it comes with builds for a variety of operating systems. Consequently, once you've downloaded and installed the DASM package, you might want to delete the versions for operating systems that you aren't using.

Instructions for downloading and installing DASM may be found in the next session.

An Atari 2600 Emulator

Although you can run your Atari 2600 programs on an actual Atari 2600 or 7800 if you have the necessary equipment (e.g., a Supercharger, Cuttle Cart, Cuttle Cart 2, Krokodile Cartridge, or a cartridge board with an EPROM socket, along with any other devices that they require for loading ROM images into them), it will be most convenient to run your programs on an Atari 2600 emulator. There are many such emulators available, for a variety of operating systems, so your choice of emulator will be partly dictated by your operating system, and partly based on your personal preferences (since all emulators are not equal).

For this tutorial, I'll primarily be using the Stella emulator, but I'll occasionally also use the z26 and PCAE emulators, and possibly other emulators as well.

Instructions for downloading and installing an emulator may be found in the next session.

Optional Items

In addition to the preceding required tools, there are some optional items that you're strongly encouraged to obtain:

Programming Documentation for the Atari 2600

There are several documents on the internet that explain the memory map of the Atari 2600, what the different memory locations do and how to use them, etc. If you get only one document, I suggest that it be the Stella Programmer's Guide, which is also available in PDF format. But you may want to search the internet for other documents as well. I'll post a list of documents I'm aware of in Session 3.

A Command Reference for batari BASIC

Although I'll be giving you information about the batari BASIC language in this tutorial, you'll also want to have one or more references that provide a handy summary of batari BASIC's commands. There is a help files that comes with bB (help.html). This document is also available online at Duane Alan Hahn's webpage - see "online manual" link to the left. Having handy summaries such as these will be extremely useful as you learn how to program in batari BASIC.

A Reference for the 6502 Assembly Language

If you plan to learn assembly language after mastering bB, you'll want to have one or more references that provide handy summaries of the opcodes and addressing modes in the 6502 assembly language, especially tables that list the number of bytes and the number of machine cycles used by each op code in its various addressing modes. Programming for the Atari 2600 is very different from programming for a computer like the Atari 800, because on the Atari 2600 you must control the way each scan line is drawn on the TV screen. Furthermore, the Atari 2600's processor is slow (e.g., it's only two-thirds as fast as the Atari 800's processor, and the Atari 800 isn't very fast, either), which means you often end up "chasing the raster beam," or trying to perform certain tasks-- like changing colors or modifying the data for the players and playfield registers-- before it's time for them to be drawn on the scan line. Also, the Atari 2600 is limited to only 4K of cartridge ROM (although bankswitching allows this to be stretched to 8K, 12K, 16K, etc.), so Atari 2600 programmers generally try to find ways to squeeze their code into the smallest possible space. Thus, the number of machine cycles and the number of bytes used by the various 6502 assembly instructions will often be critical to know.

A Loose-Leaf Binder

Even though you can download a lot of tutorials and documentation to your computer, and view it onscreen, it's very helpful to be able to leaf through this information in printed form. Thus, it's a good idea to print out these documents and put them in a loose-leaf binder for easy access, with tabbed separator pages to help you quickly flip to the specific document that you're interested in.

You can also put blank sheets of lined notebook paper in the binder, so you can keep notes about game ideas; insights you've gained into an Atari 2600 memory location, 6502 assembly instruction, or batari BASIC command; scratch calculations for memory usage or cycle counts related to a game you're working on; etc.

Graphing Paper and Colored Pens or Pencils

You may also want to put blank sheets of graphing paper in the binder, to help you can draw ideas for game screens, playfield designs, player shapes, etc.

And for this, you might want to buy a selection of colored pencils or felt-tip pens, so you can sketch your ideas in color.

A Paint Program

In addition to (or perhaps instead of) drawing things on paper, you might want to use a paint program to help you design game screens on your computer. Windows comes with a Paint program, but you might have another graphics software program that you prefer. Sometimes you may want to do emulator screen captures of a game you're working on, and load it into a graphics program for inspection or editing, so it's a good idea to use a graphics program that can handle different types of graphics file formats.

An Advanced Calculator

You will frequently find it helpful or necessary to convert between decimal, hexadecimal, and binary number bases, or perform calculations in these number bases. Windows comes with a Calculator program that can be switched to "Scientific" view for such things, but you might also want to get a pocket calculator that can do operations in hexadecimal, and that can convert numbers from decimal to hexadecimal or binary and vice versa.

A File Comparison Utility

When you're working on a game, you might have several different copies of the game where you've tried out different things. In that case, you may find it helpful to be able to quickly compare two files and see where they're different. Windows has a file comparison command, but there are some free file comparison utilities available on the internet that you might want to look into. Also, many of the more up-scale IDEs have built-in file comparison functions, so if you're using a fancy commercial IDE, you might not need to find a separate file comparison utility. In Session 3, I'll show you how to integrate a free file comparison utility with the free Crimson Editor IDE.

A 6502 Disassembler

You may occasionally find it very helpful to disassemble a game that someone else wrote, to see how they did something. There are some commented disassemblies of several Atari 2600 games on the internet, but you might have to disassemble a game yourself. There are two 6502 disassemblers which were specifically designed for disassembling Atari games-- Distella for the 2600 and 7800, and DIS6502 for the 8-bit Atari computers (although with the proper equates file, DIS6502 can also be used to disassemble games for the Atari 2600).

A File Splitter

The Distella disassembler can't disassemble ROMs that are larger than 4K, so if you want to disassemble a game that uses bankswitching, you'll first need to split the ROM into two or more 4K segments. I've written a Windows utility program that can do this.

A Hacking Utility

Finally, you might find it helpful to look at a game ROM with some sort of hacking utility, because such utilities generally display the ROM data in a format that makes it easy to find the player shapes. On the other hand, game graphics are usually considered to be protected by copyright, so you need to be careful and considerate when looking at the player graphics used in someone else's game.

In Session 3, I'll discuss ways to organize everything on your system, and help you get all of the required or optional tools downloaded and installed on your computer.

                                       --> Session 3
Software, site and content © 2005-2007 Fred X. Quimby. All rights reserved.