Classic Computer Magazine Archive HI-RES VOL. 1, NO. 4 / MAY/JUNE 1984 / PAGE 76

Scrolling Joystick Banner

by Sol Guber


Several of the recent popular arcade games use a horizontal scrolling effect to simulate movement. This is a moderately difficult task since what appears on the screen has little relationship with what is in memory.

This program generates a display on the screen and uses the joystick to control the display. The display is a message the user generates. She can vary the size and shape of the letters in the message. The message can be so long that all the letters can not be seen at one time.

The joystick is used to scroll the banner. When the joystick is moved up, the banner is moved up. When the joystick is moved to the left, the message moves to the left until the end of the banner is reached. When the trigger is pressed, the banner color changes. There can be up to 30 letters in the banner.

Before explaining how to perform horizontal scrolling on a large scale, a little review of the Atari screen memory system seems appropriate.

Screen memory is a term that relates what appears on the monitor screen with a certain portion of the memory of the computer. Atari uses a floating screen memory -- its exact location will vary from Graphics mode, to Graphics mode. The only way the system knows the location of the screen memory is by use of a pointer in locations 88 and 89. The actual start of screen memory can be calculated by PEEK (88) + 256* PEEK (89).

No matter what the Graphics mode, the start of the screen will be this memory value. The screen is mapped linearly in memory. Say that we are in Graphics 0 and the start of screen memory is 40000. Since there are 40 characters per line, locations 40000-40039 will be the first line, locations 40040-40079 will be the second line, locations 40080-40119 will be the third line and so on. From these numbers it can be seen that on the screen the value at location 40038 will be to the left of the value in memory location 40039. The value in memory location 40039, however, will not be to the left of the value in memory location 40040. It will be the end of line 1 and the value of the memory location 40040 is the start of line 2. Thus, the screen memory is linear with each value following the next one, but it is mapped onto the screen in a two-dimensional pattern.

To do large scale horizontal scrolling, it must be remembered that the screen memory is linear, but the screen itself is two-dimensional. To make the system scroll horizontally, there are two methods:

  • Using the display list to vary its parameters.
  • To make up a large string variable that has the information needed to be interpreted in a two-dimensional pattern.

I have used the latter method to make a pattern on the screen. But rather than use some sort of a mapping scheme or other pattern, I have used a message banner that can be moved around the screen with the joystick. The message only will show a portion of it at a time and the joystick is used to move the total message into view. Different size letters are used to vary the interest.

Figure 1 shows what must be done to have a proper picture on the screen. The periods represent the information in memory and the line represents the television screen. The end of the top line of periods is next to the beginning of the second line, etc. The variable is linear in memory. I have called this variable L$ and the length is 960 characters long, divided into eight, 120 characters-long lines. Thus, for the data to be vertical on the screen, it is 120 spaces away in memory. The reason there are eight long lines is there are eight bytes of information needed to define one character in the Atari character set. For the character T, the hex information is 00, 7E, 18, 18, 18, 18, 18, and 18. When the binary information is listed vertically (see Figure 2), the '1's will form a 'T'. When this sort of information is put into the variable L$, the first number 00 will be a memory location, the second number 7E will be 120 memory locations further on, the 18 will be 240 memory locations from the first, and so on. When the information is put on the screen, it starts at a location in L$, and puts the next 10 memory units into the screen memory. It skips to the next line and then skips 120 locations in L$ to get the information for the next line of information. This is done by a machine language subroutine so that it is very quick. The subroutine is shown in Figure 3.

Let me explain the program quickly. Lines 1-18 initialize several variables that are used in the program. The use of variables rather than numerical constants speeds up the program. The string variables are dimensioned. Subroutine 900 puts values into XSTEP and YSTEP which will be used to vary the joystick movements. This is much faster than a series of IF tests to determine the direction the joystick is pointed. Line 15 puts the value of 0 into the string L$ to make the memory blank. Line 18 determines the address of the string variable L$.

Lines 30-120 are used to determine every message. Line 20 and 30 INPUT the message to be put on the banner. Subroutine 1000-1040 determines the size of the letters and if fat or normal size letters are desired.

The major difference between large and small letters is the Graphics mode used, with Graphics 3 using large blocks and Graphics 4 using small blocks with the option of either fat or normal letters. The reason for this has to do with the packing of information in the various Graphics modes.

Graphics 3 is a four-color mode and every byte in memory is made up for four two bits. Each two bits specifies the color register to be used for the color of that square on the screen.

joybanner.gif
Fig. 1

Graphics 4 is a single color mode. Each byte is made up of eight 1 bit portions that specify if the square is to be lit or not. If the same information is used for Graphics 3 and Graphics 4, then the letters will be fat. If the four bites per byte information is changed to eight bits per byte, then the letters will be normal size. Constants are initialized for each situation.

Line 45 puts a statement on the screen and then goes to subroutine 3000. This subroutine reads the data for the machine language subroutine shown in Figure 2 and puts it into hex $0600, a safe place to store subroutines. Lines 50-120 dissect the message into its components. Line 60 determines the letter and subroutine LTT finds the offset from the start of the character memory at 57344.

The exact location of the start of the character is calculated in line 70 and the next eight memory locations are used, one at a time. Line 80 determines the offset from CHARLOC and checks to see what Graphics is used. Y is the value of the location in L$ the next character is to be placed. This value is POKEd into the address plus offset since this is much quicker than using the string transformations. The color of the screen is changed, and a sound is generated, to show that something is happening.

Lines 127-130 determine several variables and the start of the screen memory. Lines 136-190 is the loop controlling the movement. Line 136 determines the value of the joystick and transforms it through XSTEP into a horizontal direction. Lines 138 and 139 determine if the direction is out of bounds. Lines 140-143 do the same thing for the vertical direction. Line 155 is the subroutine that takes a location in the string variable L$ ((LPT + 1) and puts it into screen memory at location (T + 10*J). Lines 160-170 determine if the color of the message is to be changed. If the trigger is pressed, then the color will be changed. Line 190 starts everything over again.

This program is a demonstration of some of the capability of the Atari system. By the use of a string variable it is possible to pack much information into a small amount of memory. In Graphics 3, the whole screen can be put into 400 bytes. Ten screens of information can be put into only 4000 bytes. Using a machine language subroutine like the one in this program, the data can scrolled so it appears instantly when it is needed.



00000000
01111110
00011000
00011000
OOO11OOO
00011000
00011000
00011000

Fig. 2

  SPOT
FROM
TO











LP1
LP2










LP3




LP4


=
=
=
*=
PLA
PLA
STA
PLA
STA
PLA
STA
PLA
STA
LDX
LDY
LDA
STA
DEY
BNE
CLC
LDA
ADC
STA
BCC
INC
CLC
LDA
ADC
STA
BCC
INC
DEX
BNE
RTS
$C6
SPOT
SPOT+2
$0600


FROM+1

FROM

TO+1

TO
#$08
#$0C
(FROM),Y
(TO),Y

LP2

TO
#$OA
TO
LP3
TO+1

FROM
#$78
FROM
LP4
FROM+1

LP1

;Unused memory location


;Start of subroutine




;Put from location in storage



;Put to location in memory
;number of lines of information
;Number of bytes to put on the screen
;Take byte from location and offset
;Put in screen memory plus offset
;Decrement Y register
;Check to see if zero

;Put TO location in accumular
;Add 10 to it
;Put back in memory
;Check to see if greater than 255
;If greater then 255 then increment TO+1

;Load accumultar with FROM location
;Add 120 to it
;Store the new value
;Check for overflow
;If overflow, then increment FROM+1
;decrease X Register by 1
;Check to see if finished

Fig. 3

Listing: JOYBANER.BAS Download