Classic Computer Magazine Archive CREATIVE COMPUTING VOL. 9, NO. 10 / OCTOBER 1983 / PAGE 302

Commodore's port. (tips on the Commodore Vic-20 computer) (column) Julie Knott; Dave Prochnow.

Almost everyone envies the beach dweller. The steady pulsing of the waves sets a body's time to the heartbeat of the earth. This soothing sound, along with the gentle lapping of the water at low tide or the high splashes against the rocks and sand at high tide, is enough to cause all worries of the city to be left behind. Each roar of the ocean, each recession of the tide, takes with it the cares of the day.

The memory of this beauty is transitory and easily lost in the rush of traffic on a homeward voyage, and may not be recaptured until another pilgrimage is made to the sea. If only it were possible to recreate a small portion of the essence of the beach in everyday life.

Let us break for a moment from this sea side scene. Your own trip to the beach can be accomplished with a Commodore Vic-20 computer.

Surf makes extensive use of user-defined characters to create a realistic beach atmosphere. These custom characters eliminate the need to make do with oversized and unwieldy standard graphics that would provide less than the desired results. You must take special care in entering the DATA statements for these characters. The omission of a single number or punctuation mark could result in an address being POKEd with a value that will send you Vic into a state of shock from which it can be revived only by turning off the computer and back on. Getting Started

Several steps must be taken to prepare the Vic for the defining of custom characters. The standard character set, which is stored in ROM, is moved into RAM so the user can shape the characters freely. Room is prepared for this move by program line 11, while the actual move occurs in line 12.

Because this action causes clutter on the screen, the border and screen colors are first set to black (line 5) and the screen is then cleared (line 10). the unfamiliar CHR$(147) in line 10 replaces the inverse heart for clearing the screen. The result is the same because CHR$(147) is the character code for CLR/HOME. Making The Characters

Now for the creation of the actual characters. This is done by POKEing the information for a custom character into the locations that formerly stored a standard character. In Surf, custom characters are used to form the outline of a cliff that borders the beach and for the incoming tide.

Line 14 contains a FOR/NEXT loop with READ and POKE statements within the loop. When the program executes this line, the data for the custom characters are POKEd into RAM where characters @ through J are stored. After this happens, each time one of these characters is called upon in the program it will have this new appearance. The DATA for this metamorphosis are stored in lines 15 through 18.

The special characters are placed on the screen along with all the others that make up the sky, sea, sand, and cliff. Characters are referred to by their screen codes and placed on the screen by FOR/NEXT loops with READ and POKE statements (lines 20-30). This forms only the skeleton of the landscape, however.

Life really comes into the program in lines (33-43). This is where the colors for the sky (blue), the cliff (black) and the sea (cyan) are POKEd into their appropriate color memory locations. Screen and border colors become light yellow and white respectively after the POKE in line 55. Colors

Custom characters are the same as regular characters in that they are composed of two colors--those of the selected screen and character colors. The selected screen and character colors by Surf are yellow and black, respectively. When the special characters that form the base of the cliff are POKEd onto the screen they appear naturally against the sand-colored screen.

However, conventional custom characters could not have been used for the top of the cliff. The black of the cliff characters would have blended in well with the rest of the cliff, but large sand-colored "steps" would have appeared above these characters where sky-blue belongs--a result of having only two colors for each character. Since this ludicrous scene was unacceptable, another method was sought to create a realistic picture.

The Vic has a multi-color mode which it can enter and allows each character to contain up tof our colors. The appearance of any character on the Vic screen is determined by a binary pattern stored in character memory (the one we altered to create custom characters). In normal mode a 1 stands for the character color and a 0 stands for the screen color. Simple. In multi-color mode, the bits are controlled in pairs. Each of the four possible orders of a pair (00, 01, 10 and 11) stands for a color. So four colors can be found in a single character.

Using this method, the custom characters for the top of the cliff were assembled by color pattern rather than by shape. The screen locations where these characters appear are sset to multi-color mode in lines 49 and 50. The sand-steps are eliminated and blue sky prevails! Sound

Now that the seaside scene is set, it is time to describe the surf sound itself. Long before any of the beach appears on the screen at the start of the program, the sound of the breaking surf begins. Line 19 sends program execution to the sound subroutine beginning at line 90 and ending at 104. Two of the Vic voices, the white noise (speaker number 4) and a low tone (speaker number 1), are turned on in line 90.

The variable Z in the 91 is set prior to execution of the subroutine and establishes the number of complete wave swells that should occur. Each of these swells lasts for a random duration set in line 92. The volume of the two tones is increased and decreased using the variable I (lines 93 and 98). This varying volume value is POKEd into the volume memory location (36878).

If you have ever worked with sound on the Vic, you may be confused by the adding of 96 to the volume value. The memory location that is being POKEd with this volume information, 36878, is also affected by the use of multi-color mode. An auxiliary color for the multi-color mode is selected, in this case blue for the sky, and multipled by 16. This number, 96, is POKEd into location 36878 right along with the selected speaker volume.

After all of this initial set-up and after three wave sounds have crashed, dawn breaks on the beach. The title, Surf, appears on the sand at the water's edge. Line 56 POKEs the color memory locations where the title appears with red. The letters themselves are POKEd onto the screen by lines 57 and 58.

The character memory locations for the character F were used for part of the bottom edge of the cliff. An alternate character had to be reformed in the shape of an F for use in the title. This alteration occurs in lines 14 through 18 along with the other characters, and this new F is used normally with the other title characters.

The waves themselves are created in lines 60 through 63. The screen locations where the wave washes up on the shore are POKEd with cyan in lines 60 and 61, and the characters that form the wave are POKEd onto the screen in lines 62 and 63. The visual appearance of the wave corresponds with its sound.

After the water washes up on the shore, line 64 sends program execution to the sound subroutine (line 90), and when this has been completed the wave is erased by line 68. Timing

In one hour Surf will cycle through a complete day of common beach behavior--from dawn to dusk. Within the Vic is a real time clock that may be controlled by the variable TI$. At the beginning of Surf, this variable is set to 000000. As the program progresses, different vignettes occur on the screen. Lines 70 through 74 check to see how the time is advancing and, if appropriate, will send execution of the program to one of these subroutines.

Ten minutes intothe program, line 70 will send program execution to line 110. A pop can is washed up onto the shore and then taken back out to sea to litter the ocean.

Later, at the half hour point, line 71 transfers the program to line 120 where a sea bird is made to hop into view. Lines 120 and 121 create two figures of the bird. The strip of screen across which the bird struts is set to green in line 122. This area retains its yellow beach color and only appears green in the location of the bird figure. Lines 123 and 124 first print a standing bird figure on the screen. The bird stands for the duration of one wave sound and is then replaced by a hopping bird figure. There is a slight delay to allow a viewer's eye to see the hop, and then this screen location is POKEd with an empty space. The bird jumps to the next space and on across the screen.

Just as at a real beach, clouds appear in the sky of our computer beach as the day draws to a close. At 50 minutes into the program line 72 reads the value of TI$ to be greater than or equal to 0045000 and program execution falls to line 130. This line sets a row of screen locations across the sky to multi-color mode. Again, this mode was chosen to allow colors other than those of the border and screen to be used to create the cloud. The figure itself is formed in lines 131 and 132. The cloud floats lazily across the sky as dictated by line 133, with two swells of the surf occurring between each screen animation jump.

Each of the characters--the pop can, the bird, and the cloud--is approximately the same size, but this should not be considered unusual. All are completely in proportion in relation to where they occur on the screen, giving a greater feeling of depth to the beach scene. The bird appears large in the foreground while the smaller, distant cloud passes in the background.

The large gap in the program listing between line 134 and line 150 was reserved for yet another scenic diversion. It was planned to present a ship passing across the horizon, but memory limitations prevented the smooth execution of this animation. For one thing, the ship seemed to skim across the very top of the water, and for another, as soon as the ship reached the cliff, it appeared to be beached. Rather than letting the poor ship run aground on our beach, it was decided to let it rest, more safely, in our imaginations.

Finally, dusk falls on the beach at the end of the day. Line 74 detects this and sends the program onto line 150. Night covers the beach, leaving only shadows and headlights on the cliff and shore. All of the locations in color memory are POKEd with black, leaving only the multi-color spaces with some sand color in them. The duration of this night is the time it takes for two wave swells. On returning fromthe surf sound subroutine the RUN statement is isued, resetting the TI$ clock to 000000 and beginning the entire process again.

After carefully entering Surf, type RUN, press RETURN and get ready for the mind-soothing, lulling action of waves crashing on your private coast. Surf will continue to run until you either press and hold the RUN/STOP key while pressing the RESTORE key or turn the Vic off. Remember, if you elect to turn the Vic off Surf is lost unless you recorded the program on a cassette tape (or disk).

Of course you could re-type the entire program every time that you want to use it. But, a wiser decision would be to purchase the Commodore cassette recorder and make a permanent cassette copy. Then when the winter winds begin to howl you can quickly transport your thoughts to your own isolated, sun drenched computer beach.