Task: Learn About Display List Interrupts in BASIC
Time: 1-2 hours
Atari was far ahead of its competitors when it was released with superior graphics. This was largely due to the ANTIC chip that served as a graphics processor with its own instruction set and program for drawing the screen (i.e. the display list). The display list makes it possible to mix graphics modes giving the programmer great flexibility for drawing screens with both text and graphics. Unfortunately, each graphics mode was limited to small number of colors despite the Atari having 256 total colors to choose from with the GTIA chip. For example, graphics 0 is a text mode that can display 40 columns by 24 rows of characters with only two colors for the background and the text. Graphics 0 is even more limited than that because the color of the text is dependent on the background color and thus can not be set independently. Fortunately, the Atari engineers built in a remedy for these restrictions. The display list interrupt (DLI) makes it possible to control the background color of every line drawn on the screen. Wikipedia generally refers to this method as a raster interrupt or horizontal blank interrupt. The Atari 8-bit home computers were the first to do this.
Learning about DLIs is difficult for several reasons. First, it is used in conjunction with other features of the Atari including display lists and player-missile graphics that each take time to learn and understand. Second, there are a number of details that must be taken care of in the right order to implement a DLI. Third, the code that runs during the interrupt to set the parameters of the next scan line to be drawn must be written in assembly language since it is run during the horizontal blank which has precious few CPU cycles and thus must be executed quickly. Finally, there is no one authoritative source on DLIs. Each source I have read explains it differently and leaves out key details that must be collated to have a complete understanding of the process. I have been playing with DLIs for a few weeks and will try to convey here what I have learned. Please know that I don’t yet consider myself an expert but think I have learned enough to help others get started more efficiently. Unfortunately, this is one of those more complex topics that requires a bit of work and frustration to become an expert. There is no easy way to learn DLIs.
The first thing you need to know is that the ANTIC chip is busy working with the GTIA to draw the screen while the CPU is busy with the computations required by the software. This was a huge advance over the Atari 2600 that lacked a graphics chip resulting in a CPU that was burdened with drawing the screen one scan line at a time. The only time the 2600 CPU had to do in-game computations was during the horizontal blank (a brief pause) at the end of each scan line and the vertical blank (a longer pause) when the last of the 192 scan lines comprising the screen was completed. With the 8-bit computers the ANTIC gets its marching order from its display list that is created automatically when a graphics mode is specified in BASIC or a custom display list with multiple graphics modes is created. With the display list in hand ANTIC goes about its business drawing the screen within the limitations of each graphics mode it is asked to draw. The DLI essentially tells the ANTIC to signal to the CPU that there is a nonmaskable interrupt (NMI). This happens when ANTIC gets to the end of the current scan line. The CPU stops what it is doing and then runs or services an assembly language routine you provide at a specified memory address. This bit of code changes the graphics registers controlling the display. Once the code is executed the CPU goes back to what it was doing. The ANTIC then uses the new graphics settings on the next scan lines until another DLI is called. Calling a DLI every mode line means that you can give each line a different color. This makes it possible to have 24 different colors for each of the 24 different graphics 0 mode lines (eight scan lines per mode line) that make up the 192 scan lines of the screen. Fun!
I am not going to repeat all the details from the various sources here. Instead I will make some reading recommendations and then provide below an example program I cobbled together to illustrate the DLI. I tried to make it as simple as possible but that was hard to do as I will explain below in the comments. The first source I recommend reading is from a series of Atari Tutorials that appeared in BYTE magazine. These tutorials were based on the chapters of De Re Atari. I read somewhere that this was an attempt by Atari to introduce its machines and their programming advantages to a wider audience. Seems like a good move. Tutorial part 4 in the December 1981 issue of BYTE covers DLIs. There are a number of other sources of information about DLIs. Here is the De Re Atari chapter. Here is one from Compute! (1984). Here is a chapter from The Creative Atari book. Here is a chapter from Compute’s Second Book of Atari. Here is a chapter from the book Assembly Language Programming for the Atari Computers. I got my assembly language routine partly from this last source. Here is one from ROM Magazine (1983). Here is a tutorial from a user on the web. Here is another web tutorial.
The following instructions are for running the example DLI code in the Altirra emulator. You can of course type the code in by hand and run it on original hardware with BASIC. Here is the same code marked up with comments.
Open Altirra and load BASIC. I used Turbo BASIC XL. You can also load the built-in BASIC from Altirra from the File->Attach special cartridge menu.
Open the DLI file in your PC text editor or web browser and copy the text to your clipboard. Note that the spaces between lines are necessary for Altirra to read in the code properly.
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.
Once finished with the paste you can LIST to see the program and then RUN to see the result. Below is a screen shot from Altirra showing two alternating colors in graphics 0. Normally you get only one. You can change the color codes in lines 230 and 240 for whatever color you want.
Even though I read all the sources carefully and pieced together what I thought would be a working DLI example I had problems getting it to work correctly. I tried lots of different variations with no luck and eventually phoned a friend and posted for help on the Atari Age 8-bit programming forum. You can see my post and the responses here. As you can see I missed some key details in my readings. A bit complicated as I mentioned earlier in the post. Here is the code from above with comments.
Please email me with comments and suggestions for the DLI post. I still have a lot to learn and will update as I make new insights I think will be useful. My email is moorejh with a 28 at the end followed by a standard gmail ending.