• Aucun résultat trouvé

the attack and release of a note. Variable f2 indicates how

Dans le document Publishing is (Page 144-148)

many sixtieths of a second come between the release of the note and the attack of the next note. The values for Tl and T2 are the first two numbers in the first DATA statement. Making these values larger or smaller will decrease or increase the tempo.

The next two values in the first DATA statement are read into the variables El and E2, which control the envelope.

These variables correspond to the locations AD (attack and decay) and SR (sustain and release). Remember that each parameter has a range from 0 to 15, and the first one of each pair must be multiplied by 16. An attack rate of 2 with a decay rate of 3 means that the third number in the DATA statement would be 2*16+3, which equals 35.

The last number is for the waveform; it can be 16, 32, 64, or 128. If it is 64, which designates the pulse wave, an addi tional number will be read, to specify the pulse width.

The remaining DATA statements contain note informa tion. There is one frequency number for each note. Notice how the AND operator is used in line 160 to separate the fre quency number into low and high bytes. This method is sim pler than using the integer function, but because the AND operator works only on numbers up to 32767, the frequency range is not as great.

A frequency number of 0 indicates a rest. A rest has the j ( duration of a normal note, but no tone is produced. Negative w numbers flag the end of a tune.

Redefining the Character Set U

When you look at the numbers 24, 60, 102, 126, 102, 102, 102, and 0, they do not seem to have any special meaning.

Even when you represent them in binary form (00011000, LJ 00111100, 01100110, 01111110, 01100110, 01100110,

01100110, and 00000000), there does not seem to be any

1 >

134

H

H

Data Storage

n

significance to them. But if you look at them stacked vertically, you will notice that these numbers are indeed special.

00011000 00111100 01100110 01111110 01100110 01100110 01100110

00000000 m

pa

n H

r

The bit patterns of these numbers form the letter A. Where a bit is set, the character color shows. Where a bit is clear, the background color shows through. The eight rows of bytes and eight columns of bits create an 8 by 8 matrix which is suf ficient to define the image for any character. Each character that can be displayed on the screen has its own set of eight numbers. Collectively, these character definitions form what is called a character set. By changing the numbers for a character, you can change its shape to create an entirely different image.

This section shows you how to redefine the characters in a character set.

To set up a character set in memory so that it can be changed, you must follow a certain procedure. To illustrate that procedure, enter this program, SAVE it to disk or tape, LIST it, and then RUN it. If you RUN the program a second time, it will appear as if nothing is happening. This is because the character set has already been moved during the first run.

If you wish to see the characters change a second time, turn off your computer then turn it back on and reLOAD the

program.

Moveset

10 POKE 56,48 : CLR : REM RESERVE MEMORY :rem 193 20 POKE 53272,(PEEK(53272)AND240)OR12 : REM SELECT

CHARACTER SET :rem 78

30 POKE 56334,PEEK(56334)AND254 : REM DISABLE KEYB

OARD :rem 15

Data Storage

40 POKE 1,PEEK(1)AND251 : REM ACCESS STANDARD CHAR ~"

ACTERS :rem 3

50 K=0 : REM START AT BEGINNING OF NEW CHARACTER S i ]

ET :rem 231 LJ

60 POKE 12288+K,PEEK(53248+K) : K=K+1 : IF K<512 G

OTO 60 :rem 30

70 POKE 1/PEEK(1)OR4 : POKE 56334,PEEK(56334)OR1 : t J

END * :rem 103 ^—'

At first, all of the characters on the screen will be changed to very unusual shapes. Then, one by one, each character will be defined, until the first 64 characters have been moved into memory starting at location 12288. Since the cursor is not one of these characters, it is not properly defined, but this will not affect the operation of the computer. Also, the amount of free memory has been greatly reduced, which can be verified by using the free memory function. Advanced methods beyond the scope of this book let you get around this limitation.

To redefine a single character, such as the letter A, you must first locate its set of eight bytes. The location of the defining bytes for a character is determined by the screen POKE value for the character. The first eight bytes define character 0, the next eight bytes define character 1, and so on.

Since the letter A appears on the screen when you POKE screen memory with the value 1, the definition for this charac ter must be stored in the second set of eight bytes, from loca tions 12288 + 8 to 12288 + 15. Enter the following two lines to turn the letter A upside down.

POKE 12296,102:POKE 12297, 102:POKE 12298,102:POKE 12299,126

POKE 12300,102:POKE 12301,60:POKE 12302,24

Only the letter A was inverted; none of the other characters

was affected. Now, wherever an A appears on the screen, it is . upside down. Try POKEing some other values into these loca- LJ tions to see how the eight bytes correspond with the character

definition. L

With a few modifications to the original program, you can \_!

invert all of the characters.

Invertset U

10 POKE 56,48 : CLR : REM RESERVE MEMORY :rem 193

20 POKE 53272,(PEEK(53272)AND240)OR12 : REM SELECT .

CHARACTER SET :rem 78 LJ

136

u

n

30 POKE 56334,PEEK(56334)AND254 : REM DISABLE KEYB

OARD :rem 15

|—1 40 POKE 1,PEEK(1)AND251 : REM ACCESS STANDARD CHAR

1 ' ACTERS :rem 3

50 K=0 : REM START AT BEGINNING OF NEW CHARACTER S

ET :rem 231

j] 60 J=0 :rem 29

70 POKE 12288+K+J,PEEK(53248+7+K-J) : J=J+1 : IF J

<8 GOTO 70 :rem 11

80 K=K+8 : IF K<512 GOTO 60 :rem 37 90 POKE 1,PEEK(1)OR4 : POKE 56334,PEEK(56334)OR1 :

END :rem 105

Of course, it is very difficult to read anything that is upside down on the screen. The fastest way to restore the character set is to press RUN/STOP and RESTORE, but you will have to run the set-moving program again before redefin ing any more characters.

There are many practical applications for redefined

characters. The first use is to create stylized lettering. It adds a nice touch to a program when instructions and scores are printed in something other than the normal characters. Here are two examples of different lettering styles. The first pro gram gives the letters a fancy look, and the second gives the appearance of scanner-readable printing (also known as com puter type), such as is found on the lower-left margin of checks.

Fancyset

10 POKE 56,48 : CLR : REM RESERVE MEMORY :rem 193 20 POKE 53272,(PEEK(53272)AND240)OR12 : REM SELECT

CHARACTER SET :rem 78

Data Storage

808 DATA 102,102,102,102,60,0,0,102,102,102,60,60, I I

24,0,0,198,198,214,254,238 :rem 110 L-1

Dans le document Publishing is (Page 144-148)