Coarse Scrolling with LMS: Moving the Window, Not the Data
On most 1980s computers, scrolling meant copying the whole screen's worth of bytes one line or column over — slow, and in BASIC painfully slow. The Atari offers a better way. Because ANTIC reads screen data from whatever address the display list's Load Memory Scan (LMS) instruction gives it, you can leave the data where it is and simply move the "window". By changing just two address bytes you get the same effect as moving the entire screen RAM.
What you'll learn: the principle of LMS scrolling, a pure vertical scroll, how to lay out memory for horizontal scrolling, and a complete four-way joystick-scrolled map in Atari BASIC. This is also the foundation for smooth (fine) scrolling, covered in the companion guide.
What you need: Atari BASIC on any 8-bit Atari, a joystick, and familiarity with display lists (see Display Lists Explained).
The principle
In a standard display list the first mode line carries the LMS bit, and its two operand bytes at DLIST+4 and DLIST+5 (low, high) hold the start of screen memory. ANTIC reads sequentially from there. Change those bytes and the screen instantly shows a different part of memory:
- Add the line length (40 bytes in GRAPHICS 0) and the picture moves up one line.
- Add 1 and every line moves left by one character — but on a normal screen the leftmost character of each line reappears at the right end of the line above, because the lines are stored back to back.
Mark Andrews puts the rule simply in his Antic tutorial: incrementing the LMS address scrolls the display from right to left; decrementing it scrolls from left to right.
Example 1: a vertical memory viewer
This adapts De Re Atari's vertical-scroll demonstration. It sweeps the GRAPHICS 0 window through the entire 64K address space, 40 bytes at a time — you'll see page zero, the OS variables, your BASIC program, the screen itself and finally the ROMs scroll past as characters.
10 GRAPHICS 0:DL=PEEK(560)+256*PEEK(561)
20 AD=0
30 H=INT(AD/256):L=AD-256*H
40 POKE DL+5,H:POKE DL+4,L
50 AD=AD+40:IF AD<65536-960 THEN 30
60 GRAPHICS 0:PRINT "DONE"
Two-byte arithmetic is the only fiddly part: compute the full address in a BASIC variable and split it into high and low bytes each time. Press BREAK at any point; the display list is restored the next time a GRAPHICS statement or RESET runs.
Laying out memory for horizontal scrolling
To scroll sideways without the wrap-around effect, De Re Atari's solution is to give every mode line its own LMS instruction and its own long row of data in memory. The screen becomes a small window onto a wide map:
map row 0: [..........................128 bytes...........................]
map row 1: [..........................128 bytes...........................]
^-- LMS of screen line 0 points here + X
To scroll right, add 1 to every LMS address; to scroll left, subtract 1. To scroll vertically, point each screen line at the next or previous map row. Diagonal scrolling is just both at once.
Two cautions from the sources:
- Keep the window within each row: the largest useful offset is the row length minus the visible line length.
- Don't let a displayed line straddle a 4K boundary. ANTIC's memory scan counter only increments its lower 12 bits, and an LMS only takes effect at the start of a line, so a line that crosses a 4K boundary wraps back to the start of the 4K block mid-line. Aligning rows to 128 or 256 bytes avoids the problem entirely.
Example 2: a four-way scrolling map in BASIC
This program builds a map 128 characters wide and 24 rows tall in GRAPHICS 2-sized characters (ANTIC mode 7, 20 characters per line, 12 lines on screen), writes a custom display list in page 6 with an LMS on every line, and lets you scroll around with the joystick.
10 REM COARSE SCROLLING MAP WITH LMS
20 A=INT((PEEK(106)-16)/16)*16:POKE 106,A:GRAPHICS 2+16
30 BASE=A*256:POKE 559,0
40 FOR R=0 TO 23:FOR C=0 TO 127
50 POKE BASE+R*128+C,33+(C+R)-26*INT((C+R)/26)+64*(INT(C/8)-4*INT(C/32))
60 NEXT C:NEXT R
70 DL=1536:FOR I=0 TO 2:POKE DL+I,112:NEXT I
80 FOR L=0 TO 11:POKE DL+3+3*L,71:NEXT L
90 POKE DL+39,65:POKE DL+40,0:POKE DL+41,6
100 X=0:Y=0:GOSUB 500
110 POKE 560,0:POKE 561,6:POKE 559,34
200 S=STICK(0)
210 IF S=11 AND X>0 THEN X=X-1:GOSUB 500
220 IF S=7 AND X<108 THEN X=X+1:GOSUB 500
230 IF S=14 AND Y>0 THEN Y=Y-1:GOSUB 500
240 IF S=13 AND Y<12 THEN Y=Y+1:GOSUB 500
250 GOTO 200
500 FOR L=0 TO 11:AD=BASE+(Y+L)*128+X
510 H=INT(AD/256):POKE DL+5+3*L,H:POKE DL+4+3*L,AD-256*H
520 NEXT L:RETURN
How it works
- Line 20 reserves at least 16 pages (4K) below RAMTOP, rounded down to a 4K-aligned address, then opens a full-screen GRAPHICS 2 display below it. The 3K map (24 rows × 128 bytes) therefore sits inside one 4K block, and every 128-byte row stays within a single page.
- Line 30 turns ANTIC DMA off (SDMCTL, 559 = 0). The screen goes blank, but the fill loop runs faster (by around 30%). Even so, 3,072 POKEs with this much arithmetic take Atari BASIC a good while — expect a blank screen for the better part of a minute before the map appears.
- Lines 40–60 fill the map with letters. Screen bytes are internal character codes: 33–58 are A–Z. In ANTIC modes 6 and 7 the top two bits choose the colour register, so adding 0, 64, 128 or 192 gives bands of four colours every 8 columns, which makes the scrolling easy to follow.
- Lines 70–90 write the display list at 1536: three blank-8 lines (112), twelve mode-7 lines each with the LMS bit (64 + 7 = 71) followed by space for an address, and a JVB (65) back to 1536.
- Lines 500–520 compute each line's address — map base + row × 128 + column offset — and poke it into that line's LMS operand.
- Line 110 installs the new list while DMA is still off, then turns the display back on with the default value 34.
- Lines 200–250 read the joystick (11 left, 7 right, 14 up, 13 down) and keep the window inside the map: at most 128 − 20 = 108 columns across and 24 − 12 = 12 rows down.
Each move rewrites 24 bytes. In BASIC that takes long enough that you may occasionally catch ANTIC mid-update and see a one-frame tear. In assembly you would do the same update inside the vertical blank interrupt, when ANTIC isn't reading the display list, and the motion would be perfectly clean.
Why coarse scrolling looks jerky (and what to do)
Coarse scrolling moves in whole-character steps — 8 or 16 scan lines vertically, 4 to 8 colour clocks horizontally. That's fine for menus, map viewers and editors, but in action games the jumps are obvious. ANTIC's answer is the HSCROL ($D404, 54276) and VSCROL ($D405, 54277) registers, which shift enabled mode lines by single colour clocks or scan lines. Combining them with the LMS technique above gives smooth scrolling of unlimited distance; see the Fine Scrolling guide.
De Re Atari's own vision for this technique is still a good design list: a huge character-graphics map (the author built one of Russia about ten screens in size in roughly 4K of memory), schematic and blueprint viewers, and even scrolling menus where the user steers to the option they want with the joystick.
Troubleshooting
- Screen fills with garbage after scrolling far: your LMS address went beyond the end of the data. Check the limits in your joystick code.
- One line shows data from the wrong place halfway across: the line crosses a 4K boundary. Realign the rows.
- Display list "falls apart" (random modes): the display list itself crossed a 1K boundary or was overwritten. Page 6 (1536–1791) is safe for lists under 256 bytes.
- Everything resets when you press BREAK and type a command: the OS editor scrolled or re-opened the screen. Re-run the program.
- Colours are odd in the map: remember the high two bits of each byte select colour registers 708–711 in modes 6 and 7.
Further reading
- De Re Atari (Atari, 1982), Chapter 6, "Scrolling".
- Mark Andrews, "Fine Scrolling World" Parts I and II, Antic, September 1985 onward — coarse scrolling in assembly using MAC/65 or the Assembler Editor.
- James Capparell, "Scrolling", in The Best of Antic, Volume 1 (originally in MICRO).
- Atari Graphics and Arcade Game Design by Jeffrey Stanton and Dan Pinal (Arrays, 1984).
Credits
- Picture: The top-left corner of the 128-column map in the LMS scrolling example; the joystick moves this window by rewriting the display list's twelve LMS addresses. — Program authors; screenshot by the site
- De Re Atari, Chapter 6: Scrolling — Chris Crawford (Section 6 of De Re Atari)
- Mapping the Atari (revised edition) — 560-561 SDLSTL, 54276 HSCROL, 54277 VSCROL — AtariArchives.org
- Best of Antic Volume 1 — Scrolling (James Capparell, reprinted from MICRO) — AtariMagazines.com (Kevin Savetz)
- Antic Vol. 4 No. 5 — Fine Scrolling World Part I: Coarse Scrolling (Mark Andrews) — AtariMagazines.com (Kevin Savetz)
- Altirra Hardware Reference Manual, sections 4.6-4.7 — Avery Lee (Altirra)
