Coarse Scrolling Through Memory (LMS Demo)

Type
Demo
Category
Display list / scrolling demo
Author
David Small, Sandy Small and George Blank (editors)
Published in
The Creative Atari (Creative Computing Press, 1983), "Notes & Discussion" (graphics tutorial), Program 6
Year
1983
Language
Atari BASIC
Requirements
Any Atari 8-bit, 16K RAM, Atari BASIC

About the program

Scrolling a whole screen by copying its 960 bytes is far too slow in Atari BASIC. The Creative Atari's graphics tutorial shows the better way. ANTIC fetches screen data from whatever address the display list gives it, so you can leave the data alone and tell ANTIC to start reading somewhere else. Move the start address 40 bytes on and the screen jumps up a line. Move it one byte on and everything shifts left by one character. Program 6 shows all four directions in turn, using nothing but two POKEs.

What you need

Any Atari 8-bit with Atari BASIC.

Typing it in

Plain ASCII, 31 lines. It is more fun with something on the screen, so LIST a program (or this one) before you RUN it, or simply run it straight after typing.

How to use it

RUN it. The screen rolls up through memory for 20 lines, comes back down, slides left by a full line's width, then slides back, and repeats. Text from the screen and whatever lies in memory after it passes by, including the "garbage" beyond the end of screen memory. Press BREAK, then type GRAPHICS 0 to put the display list back to normal.

How it works

  • Line 20 finds the display list through locations 560/561. In a GRAPHICS 0 display list, the fourth byte (START+3) is the first text-line instruction with the Load Memory Scan bit set, and START+4/START+5 hold the address of screen memory, low byte first.
  • Line 100 reads that address into X.
  • Subroutine 1000 splits a new address Y into high and low bytes and POKEs them into the LMS operand. ANTIC uses the new address from the next frame on.
  • Stepping Y by 40 (lines 200 and 510) moves the window a whole text line, which is vertical coarse scrolling. Stepping by 1 (lines 610 and 650) moves it one character, so every line shifts sideways and the character at the start of each line wraps onto the end of the line above.
  • Only the first LMS is changed, so the whole 24-line window moves as a block. That is why horizontal scrolling looks like a "wrap" rather than a true sideways pan.

Variations to try

  • Program 5 in the same chapter is a stripped-down version that just counts the pointer up through 80 bytes and prints its value as it goes.
  • For true sideways panning, each line needs its own LMS instruction and its own wide memory line. That is the basis of the fine-scrolling playfields used in games (see the HSCROL/VSCROL demos).
  • Remove the delay or add one inside subroutine 1000 to change the speed.

Listing

20 START=PEEK(560)+256*PEEK(561)
30 REM ANTIC DISPLAY MEMORY POINTER
40 REM IS AT START+4 AND START+5
50 REM
100 X=PEEK(START+4)+256*PEEK(START+5)
110 PRINT "START OF DISP MEMORY=";X
130 REM
140 REM SCROLL UP
200 FOR Y=X TO X+(40*20) STEP 40
210 GOSUB 1000
260 REM
270 NEXT Y
500 REM SCROLL DOWN
510 FOR Y=X+(40*20) TO X STEP -40
520 GOSUB 1000
530 NEXT Y
550 REM
600 REM SCROLL LEFT
610 FOR Y=X TO X+40
620 GOSUB 1000
630 NEXT Y
640 REM SCROLL RIGHT
650 FOR Y=X+40 TO X STEP -1
660 GOSUB 1000
670 NEXT Y
680 GOTO 140
990 REM CALCULATE HI, LOW BYTES
1000 YHI=INT(Y/256)
1010 YLO=Y-(YHI*256)
1030 POKE START+4,YLO:POKE START+5,YHI
1040 RETURN

Credits