• Aucun résultat trouvé

Faced with this problem, I decided to write a machine language (ML) program for the VIC which adds speed to its sound genera tion capabilities. Most of the sound effects we use in game pro grams are sounds with increasing or decreasing tones. For ex ample, a simple way to simulate the sound of a laser with the VIC is:

FOR K =250 TO 240 STEP -1:POKE36876,K:NEXT

The ML program works along these lines, except that it is neces sary to use only one POKE command. It generates sounds with increasing or decreasing frequency to make almost any kind of sound effect possible.

The program "VIC Sound" places a machine language pro gram in the cassette buffer of the VIC. This means, of course, that you cannot transfer data using the cassette player while you are running the program. By changing the contents of memory loca tions 788-789 (decimal), the interrupt system of the computer is used to run the ML program.

The VIC has four "speakers" to make music and noise. The first and second speakers, activated by POKEing memory loca tions 36874 and 36875, are used for sounds with increasing tones.

The third speaker (36876) is used for sounds with decreasing

tones. The fourth speaker, activated by memory location 36877, is used mainly for explosions.

The ML program stores a starting number into the appro priate location and increases or decreases it for the period speci fied by the user. The interrupt of the computer will run through the program 60 times a second, which means that the starting number or tone will increase or decrease 60 times in one second.

Sound Duration

To make this a little clearer, let me explain that four memory loca tions have been assigned in the ML program to activate the four speakers, and four others to control the duration of the sounds.

Speaker To Activate Duration

1st 846 858

2nd 847 888

3rd 848 918

4th 849 948

The number POKEd into locations 846-849 is the starting number, which is stored in location 853 (dec); the initial value is 222, but this may be changed for the kind of sound you require. Locations 858, 888, 918, and 948 control the duration of the sounds. The pro gram will generate the sounds for the number of jiffies (the 1/60 second interval used to measure time in Commodore

machines) specified in these locations.

For a demonstration, RUN the program and then type SYS828; this will trap the interrupt. It will also set the volume control (location 36878) to maximum. Now POKE 846,222.

Location 858 contains 10 (dec), so the sound you heard was for ten jiffies. The program has stored 222 in location 36874 (first speaker), incremented it by one every sixtieth of a second until ten jiffies elapsed, then stored 0 into the memory location to switch off the speaker. To change the duration of the sound to, say, 20 jiffies, POKE 858,20. Now POKE 846,222.

The same method can be used for the other speakers. POKE 858,10. To change the starting number (that is, to get a tone which starts higher or lower), simply POKE into memory location 853.

R>r example, POKE 853,240. Now POKE 846,240.

Explosion Simulation

It is necessary to POKE the starting number into locations 846-849; any other number will give only silence. Try POKE

89

cmzi

847,240 (second speaker); it gives a sound of increasing frequency like the first. Now POKE 853,222:POKE 848,222. You notice this gives a sound that decreases in frequency. POKE 849,222 will sim ulate an explosion. By manipulating the durations and starting number, you can get almost any kind of sound from the first three speakers and explosions from the fourth. However, when you are changing the duration of the sounds, make sure it is not too long;

for example, if you POKE 853,50:POKE 846,222 the program will store 222 in location 36874 and increment by one every jiffy for 50 jiffies. But in this case the contents of 36874 would increase to 255 and then cycle back to zero. You would hear a note for only 33 jiffies, since a number less than 128 in the sound generators of the VIC produces silence.

When using this program, you cannot generate sounds the normal way. To do so, you must first reset the interrupt vector by SYS996. This will also set the volume control to zero. To use the ML program, add the subroutine starting at line 8900 to your own BASIC program; and you can create sound effects using just one POKE, which would otherwise require a series of POKEs.

In a BASIC program with lines 8900-9240 added, you would first have a line like this in the main program to enter the ML into

memory:

10 GOSUB 8900: REM SOUND GENERATOR

VIC Sound Generator 10 PRINT"{CLR}"

20 PRINT"{3 DOWN}{8 RIGHT}{RED}{RVS}VIC2 0{OFF}"

30 PRINT"{2 DOWN}{6 RIGHTlVIC SOUND"

800 GOSUB8900 900 END

8900 FORJ=828TO1019:READF:POKEJ,F:NEXT 9000 DATA169,15,141,14,144,120,169,82 9010 DATA141,20,3,169,3,141,21,3 9020 DATA88,96,10,15,16,64,160,0 9030 DATA162,222,173,78,3,201,10,176 9040 DATA9,238,78,3,238,10,144,76 9050 DATA116,3,140,10,144,236,78,3 9060 DATA208,6,140,78,3,142,10,144 9070 DATA173,79,3,201,25,176,9,238 9080 DATA79,3,238,11,144,76,146,3 9090 DATA140,11,144,236,79,3,208,6 9100 DATA140,79,3,142,11,144,173,80 9110 DATA3,201,16,176,9,238,80,3

90

9120 DATA206,12,144,76,176,3,140,12 9130 DATA144,236,80,3,208,6,140,80 9140 DATA3,142,12,144,173,81,3,201 9150 DATA64,176,28,238,81,3,173,81 9160 DATA3,201,22,208,7,169,176,141 9170 DATA13,144,240,25,201,43,208,21 9180 DATA169,160,141,13,144,240,14,140 9190 DATA13,144,236,81,3,208,6,140 9200 DATA81,3,142,13,144,76,191,234 9210 DATA169,0,141,14,144,120,169,191 9224 DATA141,20,3,169,234,141,21,3 9230 DATA88,96,0,0,0,0,0,0

9240 RETURN

91

John Heilborn

This tutorial on using the VIC sound registers presents manyfine ex amples. Also offered here is a simple sound editor that can be used to de velop your awn sounds.

A blip is the simplest kind of sound you can make with the VIC-20. You can make the most basic form of a blip by turning a tone on and then off again quickly. To get an idea of what this sounds like, enter and RUN the following program:

10 POKE 36878, 15: REM TURN ON THE VOLUME 20 POKE 36876, 200: REM TURN ON VOICE THR

EE

30 POKE 36876, 0:REM TURN OFF VOICE THREE

By changing the value you POKE into 36876 (on line 20), you can produce blips that sound very different. For example, try POKEing 252 into 36876 instead of 200 to make a sound like a hammer hitting a chisel. Change the value to 128, and you'll get a tennis racket hitting a ball.

If you use different sound registers, you can get still greater variations with the blip. Try using the noise register (36877) in stead of the third voice (36876) in lines 20 and 30:

10 POKE 36878,15 20 POKE 36877, 200 30 POKE 36877, 0

and you're chopping down a tree.

Another way you can change blips is to make them longer by

adding a delay loop. Here's a line that will put a delay between

lines 20 and 30. With it, the blip will sound for a longer time.

25 FOR R = 0 TO 5: NEXT

Try using different values in the delay loop, and notice the different sounds you can get from changing just the length of the blip.

92

Here are some sounds you can make using simple blips:

Alarm Clock

10 POKE 36878, 15 20 FOR T = 0 TO 10 30 POKE 36876, 240 40 POKE 36876, 0

50 FOR R = 0 TO 500: NEXT 60 POKE 36876, 237

70 POKE 36876, 0

80 FOR R= 0 TO 500: NEXT 90 NEXT

100 POKE 36876, 237 110 POKE 36875, 232 120 FOR A = 0 TO 5 130 FOR R = 0 TO 30 140 POKE 36878, 5 150 POKE 36878, 15 160 NEXT: NEXT 170 POKE 36876, 0 180 POKE 36875, 0 190 POKE 36878, 0 Dial Telephone

10 FOR I = 0 TO 6 20 POKE 36878, 3 30 G = RND(0) * 9 + 1 40 FOR R = 0 TO G * 1.5 50 POKE 36877, 228 60 POKE 36877, 0 70 NEXT

80 FOR K = 0 TO 200: NEXT 90 POKE 36878, 10

100 FOR R = 0 TO G 110 POKE 36874, 128 120 FOR D = 0 TO 1: NEXT 130 POKE 36874, 0

140 FOR O = 0 TO 50: NEXT 150 NEXT

160 FORJ=0TO350: NEXT: NEXT Touch-Tone* Phone

80 A(7)=248:B(7)=236 90 A(8)=249:B(8)=236 100 A(9)=250:B(9)=236 110 FOR I = 0 TO 6 120 R = RND(0) * 9 130 POKE 36875, A(R) 140 POKE 36876, B(R) 150 POKE 36878, 10

160 FOR K = 0 TO 100: NEXT 170 POKE 36878, 0

180 FOR M = 0 TO 50: NEXT 190 NEXT

Motor Boat

10 POKE 36878, 4 20 FOR G = 0 TO 100 30 FOR E = 0 TO 2 40 POKE 36874, 230 50 POKE 36874, 0 60 NEXT

70 FOR H = 0 TO 40 80 NEXT

90 NEXT Geiger Counter

10 POKE 36877, 128 20 POKE 36878, 15 30 POKE 36878, 0

40 FOR R = 0 TO RND(0) * 300: NEXT 50 GOTO 20

A Nip Editor

As you can see, blips can be very versatile sounds. Of course, one of the disadvantages of having many different ways of changing a sound is that it can take a long time to make the changes — espe cially if you have to make them all by POKEing the values into each register by hand. So to make your life a little easier, here's a little blip editor. With it you'll be able to change the tones and lis ten to the dynamics of each register. That way, when you find a sound you like, you can just write down the values indicated by the program and incorporate the sounds into your own

programs.

Basic Blip Editor

*T0 A=200: C=5

1-5 PRINT "{CLR}"; A; C 36878, 15

94

3^GET A$: IF A$ = "" THEN 30

40 IF A$ = CHR$(133) THEN B = 36874: GOTO y 120

50 IF A$ = CHR$(134) THEN B = 36875: GOTO

, 120

m IF A$ = CHR$(135) THEN B = 36876: GOTO 120

7-0 IF A$ = CHR$(136) THEN B = 36877: GOTO

^ 120A$ = CHR$(145) AND A < 255 THEN A = A + 1: GOTO 15

A$ = CHR$(17) AND A > 128 THEN A = A - 1: GOTO 15

A$ = CHR$(29) AND C > 0 THEN C = C - 1: GOTO 15

Oi0 IF A$ = CHR$(157) AND C < 255 THEN C

= C + 1: GOTO 15 120 POKE B,A

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

150 GOTO 30

This editor will allow you to manipulate the various tone registers and length of the blips you produce. When you RUN this program, the screen will clear and two numbers will appear.

The left-hand number is the value that will be POKEd into the tone register you choose. The right-hand number is the length of the blip.

The function keys (Fl, F3, F5, F7) select the tone registers.

Press each of the function keys and listen to the difference be tween the sounds produced.

The cursor UP/DOWN key controls the tone by changing the value POKEd into the selected register. Unshifted, this key will lower the tone and shifted, it will raise the tone. Note that the lowest value allowed by this program is 128, and the highest value is 255. Press the cursor UP/DOWN key, and you will be able to see the value change. If you hold the key down, it will continue to change until it reaches its limit.

The cursor LEFT/RIGHT key controls the length of the blip.

The larger the number, the longer the blip. Unshifted, this key will lower the number (shorten the blip). Shifted, it will raise the number, which will lengthen the blip.

Once you have some values chosen, hitting almost any key on the keyboard will replay the same sound. The only ones that won't work are: the COMMODORE key, RESTORE, CTRL, the

95

SHIFT keys, and RUN/STOP.

The last feature of this editor is the repeat function. Pressing

the space bar or INST/DEL will repeat the selected sound

continuously.

SAVE a copy of the blip editor; we will be adding features to it later.

Fading Blips

One of the most under-used features of the VIC sound system is

the volume control, location 36878. Usually, we just set it for maxi

mum volume and forget it until we want to turn the sound off.

But changing the setting of the volume control during a blip