Classic Computer Magazine Archive ANTIC VOL. 4, NO. 5 / SEPTEMBER 1985

Assembly Language


Speedy, smooth moves in assembly language


Learn how to fine scroll with all the speed and power of machine language. This is the start of a two-part tutorial by Mark Andrews, author of Atari Roots. The demo program is written in assembly language and requires the MAC/65 assembler or the Atari Assembler Editor. It will run on any 8-bit Atari computer, with disk or cassette. The article is intended for those with at least an introductory knowledge of assembly language.


Mark Andrews wrote what is probably the finest introduction to Atari assembly language: Atari Roots. So popular was this book that it sold out and is currently out of print. Antic published excerpts from the book in November"' and December 1984 We continue this practice with the following two part tutorial which was specially adapted from the book by Mark for Antic -ANTIC ED

If you haven't been able to find a good fine scrolling program written in BASIC, I can tell you why: There's no such thing!

To implement fine scrolling on an Atari computer; you have to shift the position of every dot on the screen 60 times per second. BASIC is far too slow to handle that kind of data-juggling. So when you try to write a fine scrolling program in BASIC, what you usually windup with is a lot of jerking, jumping and smearing on your video screen. To take advantage of the fine scrolling capabilities of your Atari computer; you have to use-you guessed it-assembly language.

In this month's article, I'll explain display lists and coarse scrolling using a type-in assembly language listing. Next time we'll go into fine scrolling and the use of vertical blank interrupts.


To understand how coarse scrolling and fine scrolling work, it's necessary to have at least a fundamental under-standing of a programming technique called display list modification.

In Atari computing, a display list is a special kind of data table that is used to set up a screen display. Display list modification is a method for altering a display list to suit the needs of an individual program. Actually, a display list is a kind of program within a program. When a display list is included in an assembly language program, it can then be used as a program in its own right by ANTIC, the intelligent graphics chip built into every Atari computer. This progrinmable chip has just one job-generating video displays. To carry out this job, the ANTIC chip must always have access to a display list of some kind. Several steps are involved in designing a customized display list. First you have to create the list, and store it somewhere in RAM. Then you have to POKE the address of the list, low byte first, into two memory registers in your computer-memory registers $0230 and $0231.


Before we examine Listing 1, let's talk about typing it in. MAC/65 owners should type in Listing 1 exactly as printed, then assemble and RUN it according to MAC/65 instructions. Those with Atari Assembler Editor should use the lines in Listing 2 in-stead of the corresponding lines in Listing 1.

Antic Disk subscribers: You will find the MAC/65 source code on disk 28 COARSE.M65. If you own the Assembler Editor, again, type in the lines from Listing 2. We have also included the assembled object code under the filename COARSE.EXE. To run the assembled object code from DOS 2, type [L] [RETURN] COARSE.EXE [RETURN].


Examine Listing I and you'll see a customized display list in lines 330 through 470 As you'll discover when you RUN the program, this list is designed to display three different text modes on a screen simultaneously. Before the display list can be used, however; its address must be stored in memory registers $0230 and $0231. This is done in lines 570 through 640.

Now let's take a look at what happens-pens when your computer's ANTIC chip encounters the display list. look at the display list beginning at line 340. The first eight bytes it contains are identical, the value of each byte is the hex number $70.

When ANTIC encounters the number $70 in a display list, it prints one blank Graphics 0 line on the screen. Because of the overscan characteristics of television sets and video monitors, three of the blank lines in Listing I are out of viewing range at the top of the screen. So when you run the program in Listing 1, you'll see only three blank Graphics 0 lines at the top of your screen.


After these three blank lines are printed, the next value that your ANTIC chip will encounter is the number $46. In an Atari display list, a byte that begins with the digit 4 is always a code number called a load Memory Scan (LMS) instruction. An LMS instruction tells the ANTIC chip two things. First, it instructs ANTIC to display a line of text in a certain graphics mode. Then it tells ANTIC exactly where the text to be used on that line can be found. For example, the LMS instruction in line 360 orders ANTIC to display a line of GR. 1 text. (In ANTIC language, Mode 6 is the equivalent of BASIC's Graphics Mode I). Then it tells ANTIC to look at the next two bytes of the display list for the starting address of the line of GR. 1 text which it is to display.


In the display list we're looking at, the address of the text to be displayed is entered as the label LINE 1. In Listing 1, line 240 is labeled LINE 1. look at line 240, and you'll see that it's the line which contains the words ~ ANTIC PRESENTS (Atari Assembler Editor uses BYTE hex internal characters instead.) So, when your computer's ANTIC chip encounters the LMS byte in line 360 of Listing 1, it will display the centered line 'ANTIC PRESENTS" in GR. 1 on your video screen.

Examine the display list in Listing 1 further and you'll see several other LMS instructions. In line 410, there's an LMS byte that tells ANTIC to display the line "On Your Atari" in BASIC Text Mode 0 (ANTIC Mode 2). In line 430, there's an LMS instruction that instructs ANTIC to display the words "BY YOUR NAME)" in BASIC Mode 1.

And in line 460, there's a special kind of LMS instruction which is used at the end of every display list. It orders ANTIC to loop back to the beginning of the display list every 1/60th of a second, and to display the list again.

Although you can't detect it by what I've told you so far, there's also a special kind of LMS instruction in line 380 of Listing 1. If you're a sharp-eyed reader, you may have noticed that the two bytes after this instruction are blank. You'll learn why later...


Now that you know what a display list looks like, what a display list does, and a little bit about how it does it, we're ready to take a closer look at our program.

The most common way to implement coarse scrolling is to set up a loop that keeps incrementing or decrementing certain bytes in a display list-specifically the bytes that follow the LMS instructions for the lines that are to be scrolled.

As I've pointed out, the two bytes that follow an LMS instruction always contain the starting address of the text lines which the LMS instruction will display. So, to set up a coarse horizontal scroll, all you have to do is write a loop that progressively increments or decrements the byte that follows the LMS instruction for each line you want scrolled.

If your loop increments the bytes that follow your LMS instructions, your display will scroll from right to left. If your loop decrements those bytes, then your lines controlled by the LMS instruction will scroll from left to right.

If your scrolling program is written in assembly language, it will ordinarily have to include some sort of delay loop since machine language is so fast that it will cause a scroll line to zoom by in a blur. In the coarse-scrolling program which I've written for this article, only one line of text is scrolled. But you can use coarse scrolling to scroll any number of lines you like, up to-and including-the maximum number of lines in a full-screen display. If you want to scroll your entire screen, you can precede every line with an LMS instruction.


It's almost as easy to do coarse vertical scrolling as it is to do coarse horizontal scrolling. To scroll a screen display vertically, all you have to do is increment or decrement the LMS address of each line you want scrolled, by the number of characters in the lines being scrolled instead of by just one character at a time.

When you set up this kind of scrolling action, you have to count the number of characters in each line very carefully, so your characters won't move back and forth on the screen as they scroll up or down. Next time we'll go on to actual fine scrolling, now that the groundwork has been laid.

Executable: COARSE.EXE Download

Listing 1: COARSE.M65 Download / View

Listing 2: COARSE.FIX Download