Atari Easy Scroll
Eugene D. McMillin
These short, simple BASIC scrolling routines demonstrate a method for scrolling using the Atari computer's string variables. For beginners, there is a detailed explanation of how both programs work.
Sooner or later most BASIC programmers find that they would like to set up multiple screens and scroll through them. For the advanced programmer who understands the inner workings of the machine, this usually isn't too difficult. But for most BASIC programmers, struggling with such things as bytes per line, display lists, write and screen memory locations, pointers, and interrupts can be confusing.
Fortunately the Atari offers a simple way to scroll vertically. This can be done in BASIC without even one PEEK or POKE. The method involves using string variables. With the Atari we have the ability to dimension string variables to almost any size and then to access any portion of them we want. For instance, a string variable named NAME$, dimensioned to a size of 10, could contain two names of five characters each. If we want to view the first name, we PRINT NAME$ (1, 5) and all the letters between the first and fifth are displayed. Or, if we want to view the last name, we PRINT NAME$ (6, 10).
Scrolling An Entire Screen
Program 1 demonstrates how to use a string variable to simulate vertical scrolling of the entire screen. Here's how it works:
Line 10: Sets up a full GRAPHICS 1 screen. This technique will work with any graphics mode. However, in the higher resolution modes the memory requirements are unrealistic.
Line 20: Dimensions a string variable SC$ large enough to accommodate three full screens. A GRAPHICS 1 + 16 screen contains 24 lines with 20 characters on each line. However, it seems that some Ataris won't print to position 19, 23 without getting a CURSOR OUT OF RANGE error. In order to get around this, the screen size is reduced to 23 lines. With this in mind, each screen requires 20 characters per line multiplied by 23 lines for a total of 460 characters per screen. As a result, the three screens require a string variable consisting of three screens multiplied by 460 characters per screen, or 1380 characters.
Line 30: Sets the first 460 characters of the string variable to C. In other words, the first screen will consist entirely of the letter C.
Line 40: Sets the second screen to the letter J.
Line 50: Sets the third screen to the letter W.
Line 60: POS is a variable which designates the first position of the character string SC$ that we will print to the screen. In this case it is the first character in the string.
Line 70: Sets a variable equal to the position of the joystick.
Line 80: If the joystick is forward, the screen will scroll down. As there are 20 characters in each line of GRAPHICS 1, the program subtracts 20 from the variable set up in line 60.
Line 90: The same as line 80 except the joystick is in the opposite direction. Therefore, we add 20 rather than subtract.
Line 100: Tests the variable POS to see if it's less than 1. If it is, resets it to 1 to avoid trying to print a portion of our string variable that is 0 or less, which would result in an error.
Line 110: We test the variable POS to see if it's greater than 921. If it's greater, reset it to avoid printing past the end of the dimensioned string.
Line 120: In order to print the entire screen, this line sets the cursor to the upper left-hand corner.
Line 130: This prints a full screen of 460 characters. The exact portion of the string variable SC$ printed depends on the value of POS.
Line 140: Back up and sample the joystick and try it all over again.
Type in Program 1, hook up your joystick, and see what happens. It isn't quite as smooth or fast as machine language scrolling, but it gets the job done.
Scrolling Part Of A Screen
Program 2 demonstrates this same scrolling technique over a small portion of the screen. In a spreadsheet program or game, you might want stationary text at the top or bottom of your screen while the rest scrolls. For example, when you're looking out the window of an airplane cockpit, the horizon would rise or fall as you dive or climb, but the instrument panel would stay stationary on the screen. Here are the significant changes to Program 1.
Line 20: Sets up three screens; however, each screen will only have ten lines. Twenty characters per line multiplied by 10 lines multiplied by 3 screens gives us a variable size of 600.
Lines 30–50: The size of the FOR-NEXT loops is reduced to take into account the reduced size of the screens.
Lines 51–52: These are new lines. They provide a stationary text for the screen. This stationary text is positioned above and below the portion of the screen that will scroll.
Line 110: This line is changed to account for the reduced size of the string variable SC$.
Line 120: The cursor is positioned part of the way down the screen. This is the top left position of the scrolling portion of the screen.
Line 130: Again the only change is to accommodate the reduced size of the screen.
Program 1: Vertical Scroll
HF 10 GRAPHICS 1 + 16 BD 20 DIM SC$ (1380) MH 30 FOR 1 = 1 TO 460 : SC$ (I, I) = "C" : NEXT I DK 40 FOR 1 = 461 TO 920 : SC$ (I, I) = "J" : NEXT I HK 50 FOR 1 = 921 TO 1380 : SC$ (I, I ) = "W" : NEXT I MG 60 POS = 1 EK 70 ST = STICK (0) BP 80 IF ST = 14 THEN POS = POS - 20 BN 90 IF ST = 13 THEN POS = POS + 20 AD 100 IF POS < 1 THEN POS = 1 OH 110 IF POS > 921 THEN P0S = 921 JE 120 POSITION 0, 0 JN 130 PRINT #6; SC$ (POS, POS + 459) DF 140 GOTO 70
Vertical Scroll With Stationary Section
HF 10 GRAPHICS 1 + 16 NN 20 DIM SC$ (600) LP 30 FOR 1 = 1 TO 200 : SC$ (I, I) = "C" : NEXT I CL 40 FOR 1 = 201 TO 400 : SC$ (I, I) = "J " : NEXT I DN 50 FOR 1 = 401 TO 600 : SC$ (I, I) = "W" : NEXT I GO 51 POSITION 0, 0 : ? #6; "SCROLL DEMONSTRATION" CK 52 POSITION 0, 5 : ? #6; "SPLIT SCREEN" MG 60 POS = 1 EK 70 ST = STICK (0) BP 80 IF ST = 14 THEN POS = POS - 20 BN 90 IF ST = 13 THEN POS = POS + 20 AO 100 IF POS < 1 THEN POS = 1 NJ 110 IF POS > 401 THEN POS = 401 JK 120 POSITION 0, 6 JO 130 PRINT #6; SC$ (POS, POS + 199) DF 140 GOTO 70