ROM Computer Magazine Archive ROM MAGAZINE ISSUE 2 — OCTOBER/NOVEMBER 1983 / PAGE 26

Scrolling Your Atari
by Bob Cockroft

    In order to allow the screen to scroll horizontally one must find the starting address of the display list. This address is located in memory location 560,561 (230,231 hex) (symbol+SDLSTL). It is important to note that the starting address of.the display list is using the LSB/MSB system. What this means is that the 560 represents the least significant bit of the display list address and the 561 the most significant bite. Therefore to get the correct address you must multiple the most significant bite by 256 and add to this the least significant bite.(see below)

    ADDRESS=PEEK (560)+256*PEEK(561)

    What we have now is only the starting address of the display list. What we need now is the rest of the value composing the display list. The remaining values are located in the higher locations immediately following the starting address of the display list. A complete picture of the display list can be easily found by copying and running the following program

    REM **** PRESENT DISPLAY LIST ON SCREEN (GR.2) ***

    10 DIM DL(200)
    20 FINISH=176
    30 GRAPHICS 2
    40 DIS=PEEK(560)+256*PEEK(561)
    50 COUNT=1
    60 DL(COUNT)=PEEK(DIS+COUNT-1)
    70 COUNT=COUNT+1
    80 IF COUNT<=FINISH THEN 60
    90 GRAPHICS 0
    100 FOR C2=1 TO FINISH
    110 PRINT DL(C2);",";
    120 NEXT C2
    140 END

    The display list values vary both in length and content with the graphic mode. Its main purpose is to tell the ANTIC chip what to display on the screen. But in this article, however, we will only concentrate on locations relative to scrolling. We will first attempt to understand the principles of horizontal scrolling then later move onto vertical scrolling
    In order for us to begin to create a program that will scroll horizontally we must first locate the LMS instruction. The LMS is an 3 byte instruction that tells the ANTIC chip which address to jump to in order to repeat or continue the display list. This instruction is located 3 bytes after the display list base address. If you look at the top of the list given to by the above program you will notice that 3 has a value of 112 and then a value of 71. This 71 is the first byte of the LMS(note: this value 71 will change slightly with different graphics modes). The first byte of this instruction prepares the computer to jump. The second and third bytes is the address that it will jump to(note: this address is in LSB/MSB form).
    Horizontally scrolling is done by incrementing or decrementing the value in the least significant byte of the LMS. This least significant byte is located immediately AFTER the first byte of the LMS and appears as a 112 in the list. At this point it is best for you to copy in the following program(note: the least significant byte being used to horizontal scroll is equal to the display list base address plus 4 (DL+4)).

    REM **** HORIZONTAL SCROLLING ****
    10 GR.7
    12 COLOR 1
    14 SETCOLOR 2,16,1
    15 REM ** DRAW FIGURE **
    20 PLOT 40,20:DRAWTO 40,60:DRAWTO 65,60
    25 DRAWTO 65,20:DRAWTO 40,20
    30 DL=PEEK(560)+256*PEEK(561)
    40 LSB=DL+4
    45 B=PEEK(LSB)
    50 IF STICK(0)=11 THEN B=B+1
    60 IF STICK(0)=7 THEN B=B-1
    79 REM ** POKE NEW VALUES**
    70 POKE LSB,B
    80 GOTO 50

    If the above program was copied out correctly you now have seen the block move across the screen, careful observation will reveal if one moves the block in one direction for a long period, the figure slowly moves up or down. This effect is a result of the fact that the screen is stored as one long row of bytes starting from the top left corner and moves horizontally in line until it reaches the lower right hand corner. Therefore when one changes the least significant byte by 40 the screen is scrolled vertically by one byte(note: this is a 40 character screen). You have just discovered vertical scrolling! Before you start celebrating it is best I tell you about a few complications I have not yet mentioned. It is true by just incrementing or decrementing the least signficant byte of the LMS you can scroll vertically, but not very far. This limitation became very obvious with only a little thought. After all, when you must add 40 every time you want to move vertically to a byte that can only hold a value between 0 and 255, it seems obvious you are not moving very far. However, there is a way to solve this. Remember the LMS's MOST SIGNIFICANT BYTE, the one following the least significant byte,(note: the value on the display list program was 158) by changing this we will end the problems. Every time the Least Significant Byte goes below 0 and 256 to the LSB to reset it and subtract 1 from the Most Signifcant byte. By doing this, the LMS pointer is increased by 256 bytes.
    You must also subtract 256 from the LSB and add 1 to the MSB ever time the LSB goes above 255. After all this is done the new MSB and LSB value must be poked into their respective locations. If you are still confused or perhaps want to practice what you have learned, copy in the following program. It is designed to scroll both vertically and horizontally.

    10 REM **VERT & HOR SCROLLING **
    12 GR. 6
    14 COLOR 1
    15 SE 2,16,1
    18 REM *DRAW FIGURE
    20 PLOT 40,20:DRAWTO 40,60:DRAWTO 65,60
    22 DRAWTO 65,20:DRAWTO 40,20
    30 DL=PEEK(560)+256*PEEK(561)
    40 LSB=DL+4
    50 MSB=DL+5
    60 BL=PEEK(LSB)
    70 BM=PEEK(MSB)
    79 REM *CHANGE VALUES*
    80 IF STICK(0)=14 THEN BL=BL+40
    85 IF STICK(0)=13 THEN BL=BL-40
    90 IF STICK(0)=11 THEN BL=BL+1
    95 IF STICK(0)=7 THEN BL=BL-1
    100 IF BL<0 THEN BM=BM-1:BL=BL+256
    110 IF BL>255 THEN BM=BM+1 :BL=BL-256
    180 IF BM<0 OR BM>255 THEN 80
    199 REM *POKE NEW VALUES
    200 POKE LSB,BL
    210 POKE MSB,BM
    220 GOTO 80

    After running this program you may have noticed ghost images when moving vertically. Nothing can be done about this in basic. They result from the slowness of the basic and can only be eliminated by a faster language.
    This article has not revealed all that can be revealed about scrolling, nor was it intended to. What I have tried to do is provided a simple and hopefully practical introduction to this useful technique. HAPPY SCROLLING!