• Aucun résultat trouvé

But changing the setting of the volume control during a blip can create a totally new kind of blip. Here is a routine that uses a

loop to fade the blip:

10 POKE 36876, 200

20 FOR R = 15 TO 0 STEP -1 30 POKE 36878, R

40 NEXT

By changing the STEP value, the fade rate can be altered. The

value - .5, for example, will produce a tone twice as long, while

using the value -2 will make the tone half as long.

Here are some examples of sounds made using the fade function.

Drums

10 POKE 36877f 223 20 FOR I = 0 TO 3

30 FOR R = 7 TO 0 STEP -7/5 40 POKE 36878, R: NEXT 50 NEXT

60 POKE 36874, 128 70 POKE 36877, 0

80 FOR R = 15 TO 0 STEP -3 90 POKE 36878, R: NEXT 100 POKE 36874, 0

110 FOR U = 0 TO 200: NEXT 120 POKE 36877, 223

130 FOR B = 0 TO 1

140 FOR R = 7 TO 0 STEP -7/5 150 POKE 36878, R: NEXT 160 FOR U = 0 TO 200: NEXT 170 NEXT

180 GOTO 20

96

Clumsy Tap-dancer

10 POKE 36877, RND (0) * 127 + 128 20 FOR M = 15 TO 0 STEP -(RND(0) * 15) 30 POKE 36878, M: NEXT

40 GOTO 10

Champagne Glasses Clinking 10 POKE 36876, 250

20 FOR R = 15 TO 0 STEP -3 30 POKE 36878, R: NEXT 40 FOR R = 15 TO 0 STEP -1 50 POKE 36878, R

60 NEXT

Firing Depth Charges 10 POKE 36878, 15

20 FOR R = 128 TO RND(0) * 127 + 128 30 POKE 36876, R: NEXT

40 POKE 36878, 0 50 GOTO 10

Clapping Hands

10 POKE 36877, 241

20 FOR R = 15 TO 0 STEP -(15/8) 30 POKE 36878, R: NEXT

40 FOR I = 0 TO 150: NEXT 50 GOTO 20

We can add a fade feature to the blip editor with just a few additional program lines:

^TF A$ = CHR$()^&) THEN F = F + 1: GOTO F A$ = CHR$(187) AND F > 1 THEN F = F/6?

- 1: GOTO 15

112 IF A$ = "F" AND F$ <> "F" THEN F$ = "

F": GOTO 15

115 IF A$ = "F" AND F$ = "F" THEN F$ = "

11: GOTO 15

125 IF F$ = "F" THEN 160

130 POKE 36878, 15: FOR R = 0 TO C: NEXT 140 POKE B, 0

160 FOR R = 15 TO 0 STEP -(15/F) 170 POKE 36878, R

180 NEXT 190 GOTO 140

You'll also need to change line 15 so it will display the fade func tion and its value:

97

15 PRINT "{CLR}"; A; C; F$; F

And you will need to initialize F to 1 so line 160 will not give you a DIVISION BY ZERO ERROR. Change line 10 to:

10 A = 200: C = 5: F = 1

When you run the editor now, you will see three numbers at the top of the screen. The first two are still the tone value and the length of the blip. The third is the fade length.

If you hit the F key, an F will appear between the second and third numbers. This indicates that the fade function is on. Hitting any of the function keys now will produce a sound with the fade time shown. To increase the fade time, hit SHEPT-INST/DEL. Try increasing the fade time to ten and use the function keys again.

Hitting the INST/DEL key unshifted will decrease the fade time.

Fading In

In addition to fading out a blip, we can also fade in a blip. This means starting the sound softly and gradually increasing the vol ume. Fading in is exactly the opposite of fading out. So instead of counting down the loop value, we count up like this:

10 POKE 36876, 200 20 FOR R = 0 TO 15 30 POKE 36878, R: NEXT 40 POKE 36878, 0

Here are some examples of sounds made using fade-in and fade-out.

Sawing Wood

10 POKE 36877, 200

20 FOR I = 0 TO 15 STEP (15/20) 30 POKE 36878, I: NEXT

40 FOR F = 15 TO 0 STEP-(15/20) 50 POKE 36878, F: NEXT

60 POKE 36878, 0

70 FOR G = 0 TO 20: NEXT 80 GOTO 20

Helicopter Taking Off 10 POKE 36877, 220 20 POKE 36874, 200

30 FOR Y = 15 TO 0 STEP -.05 40 FOR R = 0 TO Y

50 POKE 36878, R 60 POKE 36878, 0

70 NEXT 80 NEXT Frog

10 POKE 36875, 240 20 FOR K = 0 TO 10 30 FOR I = 0 TO 1

40 FOR R = 0 TO 15 STEP 5 50 POKE 36878, R

60 POKE 36878, 0: NEXT 70 FOR M = 0 TO 30: NEXT 90 NEXT

100 FOR D = 0 TO 300: NEXT 110 FOR W = 0 TO 1000: NEXT 120 GOTO 20

Adding this feature to the blip editor is pretty much the same as adding the fade-out feature above. Start by adding these lines:

IF A$ = CHR$(-&§) THEN 1 = 1 + 1: GOTO

15 03

IF A$ = CHR$ (#) AND I > 1 THEN 1 = 1-1: GOTO 15

113 IF A$ = "I" AND 1$ <> "I" THEN 1$ = "

I": GOTO 15

114 IF A$ = "I" AND 1$ = "I" THEN 1$ = "

11: GOTO 15

123 IF 1$ = "I" THEN 200

200 FOR R - 0 TO 15 STEP (15/l) 210 POKE 36878, R: NEXT

220 IF F$ = MF" THEN 160 230 GOTO 140

Once again, you'll need to change line 15, this time to display the fade-in function and its value:

-4^PRINT"{CLR}"; A; C; F$; F; 1$; I

And you will need to initialize I to 1 so you won't get a DIVISION BY ZERO ERROR in line 230. Change line 10 to:

A^K = 200: C = 5: F=l: 1 = 1

Finally, you'll need to change line 120 to:

±2®POKE 36878, 0: POKE B, A and line 130 to:

KE 36878, 15: FOR R = 0 TO C: NEXT

With these modifications in the editor, you will see four

num-99

bers at the top of the screen. The first three are the same as they were before. The fourth is the fade-in function.

If you hit the I key, an I will appear between the third and fourth numbers, indicating that the fade-in function is on. Hitting any of the function keys now will produce a sound with the fade-in time shown. To fade-increase the fade-fade-in time, hif^^^^^^a^/). 4 Hitting thei^^wrik^ rais^j^will decrease the fade-in

time. i

Some Final Tips

Look closely at the program examples. Many of them use some clever tricks that are not obvious with just a casual glance. The frog, for example, does not produce a smooth fade-in. It's broken into raspy pulses by turning the sound on and then off again right in the middle of the fade.

With the examples given and the blip editor, you should be able to produce some very interesting sounds. The whole point is not to be afraid of experimenting. That's what the blip editor is all about. And any time you get something interesting, write down the values so you'll be able to turn the numbers into a separate

program.

100

, ■£.■■■■■ ]

U^r^7

o G O O o

a

o o o o o o o o o o o G G G G G G G G G G G

a G G G G

Q

JimWilcox

It would be nice ifyou could just touch one key and then a BASIC pro gram would immediately be USTed. Well it can be done. Here's how.

The function keys are often used simply as an extension of the keyboard. Wouldn't it be nice to really be able to program the function keys? Well, that is exactly what is presented here.

The routine is in machine language, but no knowledge of machine language is needed to use this program. Once the pro gram is typed in, double-check the DAIA statements, since one error can cause the program to crash. SiWE the program before RUNning it. After you've typed RUN and pressed RETURN, the following should appear: Fl =? . Type in the BASIC command or statement you would like the function-one key to equal. For every carriage return you would like, type in the back arrow located on the upper left-hand corner of the VIC. Once you are sure the function key has been defined properly, press the RETURN key. The program will then ask for the rest of the func tion keys' definitions. After you have defined the eighth function key, the computer will print READY. The function keys are now ready to be used. Just press the appropriate function key, and the characters for which it was programmed will be printed.

RUN

list F2=?POKE R=?PEEK(

F5=?GOTO F6=?GOSUB F7 =

What If It Doesn't Work?

If the VIC just locks up or if you don't get the READY message,

103

turn the VIC off and reLOAD the program. Recheck the program with the listing provided, from the beginning to line 65, especially the DAIA statements.

When the READY message occurs after all eight keys have been defined and the VIC doesn't print the characters corre sponding to the function key, check the program from lines 70 to 95.

If it still doesn't work, check the subroutine in lines 100 through 115.

How the Program Works

The BASIC program will POKE two machine language programs into your VIC. One goes into the cassette buffer, the other in the uppermost memory position. The program in the cassette buffer asks for the definition of each function key. Once the RETURN key is pressed, the program will store the ASCII value of the characters pressed in the uppermost portion of memory. After all eight keys have been programmed, the program will tell the com puter to go to the other program in the top of memory every six tieth of a second. The original program is not needed once the above operations have been performed and will be erased after any command for the cassette recorder is given. This is done to save 147 bytes of VIC's memory.

The second program will constantly check for a function key pressed. If one is pressed, the program will print the characters for which the function key was defined.

How to Save Memory

The longer each command for a function key, the more memory will be used up. If the commands are short, only about 200 bytes will be used up. The maximum amount of memory that can be used by this routine is about 800 bytes. To use the least number of bytes, the commands can be typed in the shorthand method shown on pages 133-34 in Personal Computing on the VLC-20, which came with your computer.

Having programmable keys can be a great aid to a computer operator. The VIC is equipped with eight keys which you can use for whatever purpose you want. Time can be saved in writing and debugging programs.

104

Programming Function Keys

105 IFASC(A$)=7 6THENA=VAL(RIGHT $(A$,LEN(

A$)-l))+PEEK(55):IFA>255THENA=A-256:

Gary L. Engstrom

As more and more VIC owners add expansion memory to their com puters, there is an increasing need for programs which run on all VICs, ofany memory size. Herds how to write them.

The "where's my memory located now" problem can be over come by careful programming. With or without RAM expansion in place, you should be able to run any of your own programs that require 3.5K or less of RAM. Of course, you will have to put up with removing and installing the expansion cartridge when using programs written by others, but you can have the convenience of universal VIC programs you write yourself.

For programs to be universal, they need to fulfill three requirements:

1. The program must not need more than 3.5K of memory.

You just cannot squeeze more than that into the unexpanded VIC-20.

2. The program must contain memory locatioiunformation for both the expanded and unexpanded VIC-20.

3. The program must be able to determine if expansion is in place and be able to choose between the two sets of memory locations.

To understand how a program can conform to these last two requirements, you need to understand that when the VIC-20 is turned on, its operating system goes through an initialization pro cedure. During initialization, one of the tasks that the operating system does is check to see if memory expansion is in place.

If so, the operating system sets certain pointers to one set of memory locations; if there is no memory expansion, these pointers are set to a different set of memory locations. If you have 8K or more RAM memory expansion for your VIC-20, you should be familiar with three of these memory locations (see Table 1).

The computer uses the correct locations because, during

initiali-106

zation, pointers are set to the correct locations. It is the knowledge of the alternate memory locations and the existence of these pointers that make universal programs possible.

Table 1. Memory Locations

epends on the exact amountot mem