Task: Make a Playfield in BASIC Using Character Sets
Needed: BASIC
Time: 30-60 minutes
Introduction
I programmed a game called Gene Medic in assembly language for the Atari 2600 in 2017 and am interested in porting it to the Atari 800. I am starting this process using BASIC and may also do an assembly language version once I have that working. I have had a good time diving back into BASIC and learning graphics tricks and techniques that I didn’t learn back in the day or didn’t learn well. BASIC on the Atari 8-bit computer is SO much easier than programming in assembly for the 2600.

My goal here is to document my progress in a series of posts. I am starting with a simple playfield drawn entirely in graphics mode 0 (Antic mode 2) with characters. Graphics mode 0 is one of the three text modes. This one allows 40 8×8 pixel characters to be drawn across the screen with 24 total lines. This is the same graphics mode that the Atari BASIC cartridge and the Memo Pad use. My first thought was that I could draw the entire playfield for Gene Medic in this text mode and use the character set provided for the shapes needed. There are two problems with this. First, I discovered that the shapes provided in the character set couldn’t be used to draw some of the shapes I needed. Second, graphics 0 is limited to one color for the background and the same color for the characters with a different luminance (brightness) that gives it contrast. The first problem is easily overcome by redefining the character set to include the shapes I need. More about this below. The second issue cannot be overcome and will be addressed in a later post on mixing graphics modes with display lists. For now, I will just go with the color limitations to illustrate a playfield drawn only with character sets. The playfield I will ultimately use for my game will be more sophisticated.
I have read a number of sources on character sets. My favorite is “The Beginner’s Guide to Character Sets” on page 46 of the book “The Creative Atari” by Small et al. (1983). I modified their program #27 from the web page (#28 in the actual book) for the demo. The Atari ASCII character set (i.e. ATASCII) consists of 128 characters, shapes, and symbols that can be placed anywhere on the 40×24 graphics 0 text screen using the POSITION X,Y command followed by a PRINT “A” or PRINT CHR$(65) command in BASIC. Note that the next 128 characters in the set that are each coded by eight bytes. Thus, the complete character set occupies 8*128=1024 bytes of memory or one complete page. Here is a website with the characters listed alongside their ATASCII number and internal reference number. The internal reference number is important for pointing to characters in memory and is what I use in my code below. Note that the first 20 or so ATASCII characters are shapes that can be directly used to draw a simple playfield. As I mentioned above, these shapes were not enough for my playfield. This means that I need to define some new characters for my screen. The ability to define new characters was a clear advantage of the Atari over other similar computers back in the day. Here is a description of this from an ANTIC magazine issue from 1984 to complement the Creative Atari book chapter.
I found redefining a character set to be fun. The first thing you need to know is that the character set is located in the ROM where it can’t be modified. You must first copy the character set to RAM where it can then be changed. Once changed you can tell the Atari to use this as the source of characters thus bypassing the fixed set in ROM. This is all pretty straightforward and explained clearly in The Creative Atari chapter I linked to above. I decided to modify 10 letters A through J to make the shapes I needed. The A character has internal reference number 33 with B as 34, C as 35, etc. Each character is defined by an 8×8 bitmap that is read line by line from the top down. For a _ character I used DATA 0,0,0,0,0,0,0,255 where the first seven 0s indicate blank lines for the top seven rows of the 8×8 matrix and the 255 is the decimal value of the binary number 11111111 for the bottom row making the _ character. These data statements are read using the READ statement and then poked into eight consecutive memory locations corresponding to the character being modified. In my new character set below I changed “I” to “_”. So now when I use PRINT “I” a “_” will appear on the screen.
An important issue to consider is that loading the character set from ROM to RAM is really slow in BASIC and there is a noticeable pause of about 5-10 seconds until it completes. I have included a machine language routine from page 59 of the book “Atari Graphics and Arcade Game Design” by Stanton and Pinal (1984) that is much faster. I will present the first code written entirely in BASIC below followed by the code with the machine language routine for comparison. I will also provide fully commented code in the comments section.
Instructions
The following instructions are for running the character set playfield code in the Altirra emulator. You can of course type the code in by hand and run it on original hardware with BASIC.
Step 1
Open Altirra and load BASIC. I used Turbo BASIC XL.
Step 2
Open char-set-redefine from your text editor and copy the text to your clipboard.
Step 3
Click on the View tab of Altirra and choose the paste text option from the bottom of the list. Altirra will slowly paste the text into the BASIC command line. It is important to keep focus on the Altirra window or the paste will stop and it will lose some characters.
Step 4
Once finished with the paste you can LIST to see the program and then RUN to see the result. Note that there is a 5-10 second pause after you RUN while the character set is loaded from ROM to RAM.
Step 5
Repeat with char-set-redefine-ml that includes the machine language code. Compare the speed. You should choose Cold Boot from the System menu to reboot the Atari before loading the new code. A Warm Boot will reset BASIC without purging the code from memory.

Comments
I would encourage you to play with the code to develop your own character set. My simple playfield shown just above is a first attempt to approximate the one I did on the Atari 2600 (see figure further up). In Gene Medic, the playfield is a cell with the thick horizontal line representing the cell membrane. The thin line represents the nuclear membrane. At the bottom is a double-stranded DNA molecule in the nucleus of the cell. Note that the background is dark blue (SETCOLOR 2,9,2) while the characters are all light blue (SETCOLOR 1,9,9).
Here is a heavily commented version of the BASIC code with the machine language routine to make it easier for you to learn how this works so you can make your own playfield: char-set-redefine-ml-comments. I will discuss display lists in an upcoming post to extend this work and give it more functionality by mixing graphics modes. Modifying display lists is an important and useful skill for making Atari 8-bit computer games.