Zones

The screen is divided into 5 wide columns, called zones. The leftmost zone is called zone 1; the rightmost zone is called zone 5.

Zones 1, 2, 3, and 4 are each 14 characters wide. Zone 5 is extra-wide: it’s 24 characters wide. So altogether, the width of the entire screen is 14+14+14+14+24, which is 80 characters. The screen is 80 characters wide.

A comma makes the computer jump to a new zone. Here’s an example:

CLS

PRINT "sin", "king"

The computer will print "sin" and "king" on the same line; but because of the comma before "king", the computer will print "king" in the second zone, like this:

sin king

 

first zone second zone third zone fourth zone fifth zone

Here are the words of a poet who drank too much and is feeling spaced out:

CLS

PRINT "love", "cries", "out"

The computer will print "love" in the first zone, "cries" in the second zone, and "out" in the third zone, so the words are spaced out like this:

love cries out

This program’s even spacier:

CLS

PRINT "love", "cries", "out", "to", "me", "at", "night"

The computer will print "love" in the first zone, "cries" in the second, "out" in the third, "to" in the fourth, "me" in the fifth, and the remaining words below, like this:

love cries out to me

at night

This program tells a bad joke:

CLS

PRINT "I think you are ugly!", "I'm joking!"

The computer will print "I think you are ugly!", then jump to a new zone, then print "I’m joking", like this:

I think you are ugly! I'm joking!

 

first zone second zone third zone fourth zone fifth zone

When you combine commas with semicolons, you can get weird results:

CLS

PRINT "eat", "me"; "at"; "balls", "no"; "w"

That line contains commas and semicolons. A comma makes the computer jump to a new zone, but a semicolon does not make the computer jump. The computer will print "eat", then jump to a new zone, then print "me" and "at" and "balls", then jump to a new zone, then print "no" and "w". Altogether, the computer will print:

eat meatballs now

Skip a zone

You can make the computer skip over a zone:

CLS

PRINT "Joe", " ", "loves Sue"

The computer will print "Joe" in the first zone, a blank space in the second zone, and "loves Sue" in the third zone, like this:

Joe loves Sue

 

first zone second zone third zone fourth zone fifth zone

You can type that example even more briefly, like this:

CLS

PRINT "Joe", , "loves Sue"

Loops

This program makes the computer greet you:

CLS

DO

PRINT "hello",

LOOP

The computer will print "hello" many times. Each time will be in a new zone, like this:

hello hello hello hello hello

hello hello hello hello hello

hello hello hello hello hello

etc.

Tables

This program prints a list of words and their opposites:

CLS

PRINT "good", "bad"

PRINT "black", "white"

PRINT "grandparent", "grandchild"

PRINT "he", "she"

Line 2 makes the computer print "good", then jump to the next zone, then print "bad". Altogether, the computer will print:

good bad

black white

grandparent grandchild

he she

The first zone contains a column of words; the second zone contains the opposites. Altogether, the computer’s printing looks like a table. So whenever you want to make a table easily, use zones, by putting commas in your program.

Let’s make the computer print this table:

Number Square

3 9

4 16

5 25

6 36

7 49

8 64

9 81

10 100

Here’s the program:

CLS

PRINT "Number", "Square"

FOR i = 3 TO 10

PRINT i, i * i

NEXT

Line 2 prints the word "Number" at the top of the first column, and the word "Square" at the top of the second. Those words are called the column headings. The FOR line says i goes from 3 to 10; to begin, i is 3. The indented line makes the computer print:

3 9

The bottom line makes the computer do the same thing for the next i, and for the next i, and for the next; so the computer prints the whole table.

TAB

When the computer puts a line of information on your screen, the leftmost character in the line is said to be at position 1. The second character in the line is said to be at position 2.

This program makes the computer skip to position 6 and then print "HOT":

CLS

PRINT TAB(6); "hot"

The computer will print:

hot

12345678

Here’s a fancier example:

PRINT TAB(6); "hot"; TAB(13); "buns"

The computer will skip to the 6th position, then print "hot", then skip to the 13th position, then print "buns":

HOT BUNS

12345678 13

Diagonal

This program prints a diagonal line:

CLS

FOR i = 1 TO 12

PRINT TAB(i); "*"

NEXT

The FOR line says to do the loop 12 times, so the computer does the indented line. The first time the computer does the indented line, the i is 1, so the computer prints an asterisk at position 1:

*

The next time, the i is 2, so the computer skips to position 2 and prints an asterisk:

*

The next time, the i is 3, so the computer skips to position 3 and prints an asterisk:

*

Altogether, the program makes the computer print this picture:

*

*

*

*

*

*

*

*

*

*

*

*

 

Calendar

Let’s make the computer print this message:

January has 31 days

February has 28 days

March has 31 days

April has 30 days

May has 31 days

June has 30 days

July has 31 days

August has 31 days

September has 30 days

October has 31 days

November has 30 days

December has 31 days

Here’s the program:

CLS

DATA January,31,February,28,March,31,April,30,May,31,June,30,July,31

DATA August,31,September,30,October,31,November,30,December,31

FOR i = 1 TO 12

READ month.name$, how.many.days

PRINT month.name$, "has"; how.many.days; "days"

NEXT

The DATA shows each month’s name and how many days are in the month. The READ line says to read a month’s name and how many days are in the month. The PRINT line makes the computer print the month’s name, then skip to the next zone, then print the word "has", then print how many days, then print the word "days".

Print all the days Instead of making the computer say "January has 31 days", let’s make the computer print all the days of each month:

January

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

23 24 25 26 27 28 29 30 31

Let’s make the computer print that on paper, for each month, so the paper shows a crude calendar for the entire year.

To do that, just change the program’s PRINT line to this sequence:

LPRINT month.name$

FOR day = 1 TO how.many.days

LPRINT day;

NEXT

LPRINT

LPRINT

In that sequence, the first LPRINT statement makes the computer print, on paper, the month’s name ("January"). The FOR loop makes the computer print each day (1, 2, 3, etc.). The bottom two lines (which both say LPRINT) make the computer leave blank space under January’s calendar, to separate it from February’s.

Here’s the entire program:

CLS

DATA January,31,February,28,March,31,April,30,May,31,June,30,July,31

DATA August,31,September,30,October,31,November,30,December,31

FOR i = 1 TO 12

READ month.name$, how.many.days

LPRINT month.name$

FOR day = 1 TO how.many.days

LPRINT day;

NEXT

LPRINT

LPRINT

NEXT

It makes the computer print a calendar beginning like this:

January

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

23 24 25 26 27 28 29 30 31

February

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

23 24 25 26 27 28

You must eject the paper from the printer manually. For a leap year, change the DATA’s 28 to 29.

Pretty weeks Although that program makes the computer print the right numbers for each month, it prints the numbers in the wrong places. Let’s make the computer print at most 7 numbers in each row, so each is a week.

To print the numbers in the right places, use TAB. So instead of saying —

LPRINT day;

say:

LPRINT TAB(t); day;

That line will make the computer print each day in the right position… if we define t correctly. But how should we define t?

For Sunday, let’s make t be 1, so that Sunday begins at position 1. For Monday, let’s make t be 5, so that Monday begins at position 5. For Tuesday, let’s make t be 9; for Wednesday, 13; Thursday, 17; Friday, 21; and Saturday, 25. So whenever a day’s been printed, t should normally increase by 4 for the next day:

LPRINT TAB(t); day;

t = t + 4

Saturday’s the last day of the week. After Saturday, we must begin a new week. So if t has passed Saturday (which is 25), we want t to become 1 (for Sunday); and if there are more days left in the month, we want the computer to press the ENTER key (to start a new week):

IF t > 25 THEN

t = 1

IF day < how.many.days THEN LPRINT

END IF

Which year would you like a calendar for: 1995? 1996? 1997? This program makes a pretty calendar for 1997:

CLS

DATA January,31,February,28,March,31,April,30,May,31,June,30,July,31

DATA August,31,September,30,October,31,November,30,December,31

LPRINT "Calendar for 1997"

LPRINT

t = 13

FOR i = 1 TO 12

READ month.name$, how.many.days

LPRINT month.name$

LPRINT "Sun Mon Tue Wed Thu Fri Sat"

FOR day = 1 TO how.many.days

LPRINT TAB(t); day;

t = t + 4

IF t > 25 THEN

t = 1

IF day < how.many.days THEN LPRINT

END IF

NEXT

LPRINT

LPRINT

IF i = 6 OR i = 12 THEN LPRINT CHR$(12);

NEXT

Line 4 prints the heading, "Calendar for 1997". Line 5 puts a blank line underneath the heading. Since 1997 begins on a Wednesday, the next line tells the computer to start t at 13 (which is the position for Wednesday). The next line saying LPRINT "Sun Mon Tue Wed Thu Fri Sat" puts a heading at the top of each month. The next-to-bottom line says: if the computer has reached the end of June (month 6) or December (month 12), eject the paper, so that the first half of the year is on one sheet of paper and the second half of the year is on the other.

The computer will print a calendar beginning like this:

Calendar for 1997

January

Sun Mon Tue Wed Thu Fri Sat

1 2 3 4

5 6 7 8 9 10 11

12 13 14 15 16 17 18

19 20 21 22 23 24 25

26 27 28 29 30 31

February

Sun Mon Tue Wed Thu Fri Sat

1

2 3 4 5 6 7 8

9 10 11 12 13 14 15

16 17 18 19 20 21 22

23 24 25 26 27 28

March

Sun Mon Tue Wed Thu Fri Sat

1

2 3 4 5 6 7 8

9 10 11 12 13 14 15

16 17 18 19 20 21 22

23 24 25 26 27 28 29

30 31

If you want a different year, change lines 4 (which says LPRINT "Calendar for 1997") and line 6 (which says the year starts on Wednesday, t = 13). For a leap year, change the DATA’s 28 to 29.

LOCATE

While your running a program, the black screen show 25 lines of information. The screen’s top line is called line 1; underneath it is line 2; then comes line 3; etc. The bottom line is line 25.

Each line consists of 80 characters. The leftmost character is at position 1; the next character is at position 2; etc. The rightmost character is at position 80.

On the screen, the computer will print wherever you wish.

For example, to make the computer print the word "drown" so that "drown" begins at line 3’s 7th position, type this:

CLS

LOCATE 3, 7: PRINT "drown"

The computer will print the word’s first letter (d) at line 3’s 7th position. The computer will print the rest of the word afterwards.

You’ll see the first letter (d) at line 3’s 7th position, the next letter (r) at the next position (line 3’s 8th position), the next letter (o) at the next position (line 3’s 9th position), etc.

Middle of the screen

Since the screen’s top line is 1 and the bottom line is 25, the middle line is 13. Since the screen’s leftmost position is 1 and the rightmost position is 80, the middle positions are 40 and 41.

To make the computer print the word "Hi" in the middle of the screen, tell the computer to print at the middle line (13) and the middle positions (40 and 41):

CLS

LOCATE 13, 40: PRINT "Hi"

Bottom line

Whenever the computer finishes running a program, the computer prints this message on the black screen’s bottom line:

Press any key to continue

Then the computer waits for you to press the ENTER key, which makes the screen turn blue and show the lines of your program.

That message, "Press any key to continue", is the only message that the computer wants to print on the bottom line.

To force the computer to print anything else on the bottom line, do this: say LOCATE, mention line 25, put a semicolon at the end of the PRINT statement (to prevent the computer from pressing the ENTER key, which would disturb the rest of the screen), and say SLEEP (to make the computer pause awhile so you can admire the printing). For example, this program prints an "x" at the screen’s bottom right corner:

CLS

LOCATE 25, 80: PRINT "x";

SLEEP

 

Pixels

The image on the computer’s screen is called the picture. If you stare at the picture closely, you’ll see the picture’s composed of thousands of tiny dots. Each dot, which is a tiny rectangle, is called a picture’s element, or pic’s el, or pixel, or pel.

Coordinates

The dot in the screen’s top left corner is called pixel (0,0). Just to the right of it is pixel (1,0). Then comes pixel (2,0), etc.

Underneath pixel (0,0) is pixel (0,1). Further down is pixel (0,2).

Here are the positions of the pixels:

pixel (0,0) pixel (1,0) pixel (2,0) pixel (3,0) pixel (4,0) etc.

pixel (0,1) pixel (1,1) pixel (2,1) pixel (3,1) pixel (4,1) etc.

pixel (0,2) pixel (1,2) pixel (2,2) pixel (3,2) pixel (4,2) etc.

pixel (0,3) pixel (1,3) pixel (2,3) pixel (3,3) pixel (4,3) etc.

Each pixel’s name consists of two numbers in parentheses. The first number is the X coordinate; the second number is the Y coordinate. For example, if you’re talking about pixel (4,3), its X coordinate is 4; its Y coordinate is 3.

The X coordinate tells how far to the right the pixel is. The Y coordinate tells how far down. So pixel (4,3) is the pixel that’s 4 to the right and 3 down.

On the computer, the Y coordinate measures how far down, not up. If you’ve read old-fashioned math books in which the Y coordinate measured how far up, you’ll have to reverse your thinking!

Screen modes

How many pixels are on the screen? The answer depends on which screen mode you choose.

Mode 12 Generally speaking, the best screen mode to choose is mode 12.

In that mode, the X coordinate goes from 0 to 639, and the Y coordinate goes from 0 to 479, so the pixel at the screen’s bottom right corner is pixel (639,479). Since you have 640 choices for the X coordinate (numbered from 0 to 639) and 480 choices for the Y coordinate (numbered from 0 to 479), that mode is called a 640-by-480 mode.

In that mode, the computer can display 16 colors simultaneously.

Mode 12 works just if your computer’s video card is modern (VGA).

 

Alternative modes If your computer’s video card is inferior (CGA, EGA, MCGA, Hercules, or Olivetti), mode 12 doesn’t work, and you must use a more primitive mode instead. Here are your choices:

Mode Video card Pixels Colors

1 CGA (or EGA, MCGA, VGA) 320 by 200 4

2 CGA (or EGA, MCGA, VGA) 640 by 200 2

3 Hercules monochrome 720 by 348 2

4 Olivetti color 640 by 400 2

7 EGA (or VGA) 320 by 200 16

8 EGA (or VGA) 640 by 200 16

9 EGA (or VGA) 640 by 350 4 or 16

10 EGA (or VGA) 640 by 350 4

11 MCGA (or VGA) 640 by 480 2

12 VGA 640 by 480 16

13 MCGA (or VGA) 320 by 200 256

For example, here’s what that chart’s bottom row means:

To use mode 13, your video card must be MCGA (or VGA).

That mode lets you use 320 values of X (numbered from 0 to 319).

That mode lets you use 200 values of Y (numbered from 0 to 199).

That mode lets the screen display 256 colors simultaneously.

Mode 12 versus mode 13 As you can see from that chart, mode 12 is generally the best mode, since it gives you lots of pixels (640 by 480) and lots of colors (16).

Mode 13 gives you even more colors (256) but restricts you to fewer pixels (just 320 by 200). That restriction makes mode 13’s drawings look crude.

Special modes The following modes are just for bizarre situations.…

Mode 3 is just for a monochrome monitor attached to a Hercules monochrome card. This mode does not work with color monitors. In this mode, you have just 2 "colors": black and white.

Mode 4 is just for a color video card made by Olivetti. That card is included in the AT&T 6300 computer.

Mode 9 is intended mainly for EGA monitors. It gives you 16 colors usually, but just 4 colors if the video card’s RAM is just 64K.

Mode 10 is intended mainly for monochrome monitors. It gives you 4 "colors": black, bright white, dull white (cream), and blinking bright white.

Pixel shape Each pixel is a tiny rectangular dot. In modes 11 and 12, each pixel is a perfect square, whose width is the same as its height: on a typical 15-inch monitor, each pixel’s width and height is about a 60th of an inch.

In other modes, each pixel is slightly taller than it is wide, so each pixel looks like a little tower.

Text mode There’s also a mode 0, which works on all computers and produces just text (no graphics).

Choosing a mode Here’s which mode to choose:

Video card Which mode to choose

Hercules 3

Olivetti 4

CGA 1 (for many colors) or 2 (for many pixels)

EGA 9 (for color) or 10 (for monochrome)

MCGA 11 (for many pixels) or 13 (for many colors)

VGA 12 (for many pixels) or 13 (for many colors)

To give commands about pixels, begin by telling the computer which mode you want. For example, if you want screen mode 12, say:

SCREEN 12

When you give such a SCREEN command, the computer automatically clears the screen, so the entire screen becomes black. You do not have to say CLS.

Plotting

If your monitor is modern (VGA), this program makes the screen become black, then makes pixel (100,100) turn white:

SCREEN 12

PSET (100, 100)

If your monitor is less than VGA, choose a different screen mode than 12.

In that program, the PSET (100, 100) makes pixel (100,100) turn white. The word "PSET" means "pixel set": "PSET (100, 100)" means "set the pixel (100,100) to white".

LINE This program draws a white line from pixel (0,0) to pixel (100,100):

SCREEN 12

LINE (0, 0)-(100, 100)

This program draws a white line from pixel (0,0) to pixel (100,100), then draws a white line from that pixel (100,100) to pixel (120,70):

SCREEN 12

LINE (0, 0)-(100, 100)

LINE -(120, 70)

CIRCLE This program draws a white circle whose center is pixel (100,100) and whose radius is 40 pixels:

SCREEN 12

CIRCLE (100, 100), 40

In modes 11 and 12, each pixel is a perfect square, and the computer draws the circle easily. The circle’s radius is 40 pixels; the circle’s diameter (width) is 80 pixels.

If you switch to a different screen mode (such as SCREEN 2), each pixel is a tower instead of a square, so a "circle that’s 80 pixels wide and 80 pixels high" would be taller than wide and look like a tall oval. To make sure your "circle of radius 40" looks pretty, the computer cheats: the computer makes the circle’s width be 80 pixels but makes the circle’s height be fewer than 80 pixels, so that the circle’s height is the same number of inches as the width.

Avoid the bottom

When your program finishes, the bottom of the screen automatically shows this advice:

Press any key to continue

To prevent that advice from covering up your drawing, position your drawing near the top of the screen (avoiding the bottom), or else make your program’s bottom line say "SLEEP" so the computer will pause and let you admire the drawing before the advice covers it.

PAINT

After drawing a shape’s outline (by using dots, lines, and circles), you can fill in the shape’s middle, by telling the computer to PAINT the shape.

Here’s how to PAINT a shape that you’ve drawn (such as a circle or a house). Find a pixel that’s in the middle of the shape and that’s still black; then tell the computer to PAINT, starting at that pixel. For example, if pixel (100, 101) is inside the shape and still black, say:

PAINT (100, 101)

Colors

In modes 4, 7, 8, and 12, you can use these 16 colors:

0. black 8. light black (gray)

1. blue 9. light blue

2. green 10. light green

3. cyan (greenish blue) 11. light cyan (aqua)

4. red 12. light red (pink)

5. magenta (purplish red) 13. light magenta

6. brown 14. light brown (yellow)

7. cream (yellowish white) 15. light cream (pure white)

In mode 1, you must choose from these 4 colors instead:

0. black

1. cyan (greenish blue)

2. magenta (purplish red)

3. cream (yellowish white)

In modes 2, 3, and 11, you must choose from these 2 colors instead:

0. black

1. white

In mode 10, you have these 4 choices:

0. black

1. cream

2. blinking white

3. white

Mode 9 usually gives you the 16 colors used in mode 12; but if you’re using mode 9 with an EGA card having just 64K of RAM, you’re restricted to the 4 colors used in mode 1.

Mode 13 gives you the 16 colors used in mode 12 — and many more colors, too! Here’s the spectrum:

0 through 7: black, blue, green, cyan, red, magenta, brown, cream

8 through 15: same colors as above, but lighter

16 through 31: shades of gray (from dark to light)

32 through 55: color blends (from blue to red to green to blue again)

56 through 79: same color blends, but lighter

80 through 103: same color blends, but even lighter

104 through 175: same as 32 through 103, but darker

176 through 247: same as 104 through 175, but even darker

248 through 255: black

Normally, the PLOT, LINE, CIRCLE, and PAINT commands draw in yellowish white (cream). If you prefer a different color, put the color’s number at the end of the command. Put a comma before the color’s number.

For example, if you want to draw a line from (0,0) to (100,0) using color #2, type this:

LINE (0, 0)-(100, 0), 2

When you give a PAINT command, you must make its color be the same color as the outline you’re filling in.

Boxes

If you type —

LINE (0, 0)-(100, 100), 2

the computer draws a line from pixel (0,0) to (100,100) using color #2.

If you put the letter B at the end of the LINE command, like this —

LINE (0, 0)-(100, 100), 2, B

the computer will draw a box instead of a line. One corner of the box will be at pixel (0,0); the opposite corner will be at (100,100); and the box will be drawn using color 2.

If you put BF at the end of the LINE command, like this —

LINE (0, 0)-(100, 100), 2, BF

the computer will draw a box and also fill it in, by painting its interior.

Return to text mode

When you finish drawing pictures, you can return to text mode by saying:

SCREEN 0

If you were using mode 1, 7, or 13, say this instead:

SCREEN 0

WIDTH 80

The "WIDTH 80" makes sure the screen will display 80 characters per line instead of 40.

Sounds

To produce sounds, you can say BEEP, SOUND, or PLAY. BEEP appeals to business executives; SOUND appeals to doctors and engineers; and PLAY appeals to musicians.

BEEP

If your program says —

BEEP

the computer will beep. The beep lasts for about a quarter of a second. Its frequency ("pitch") is about 875 hertz. (The beep’s length and frequency might be slightly higher or lower, depending on which computer you have.)

You can say BEEP in the middle of your program. For example, you can tell the computer to BEEP if a person enters wrong data.

Computerized weddings This program makes the computer act as a priest and perform a marriage ceremony:

CLS

10 INPUT "Do you take this woman to be your lawful wedded wife"; a$

IF a$ <> "I do" THEN BEEP: PRINT "Try again!": GO TO 10

20 INPUT "Do you take this man to be your lawful wedded husband"; a$

IF a$ <> "I do" THEN BEEP: PRINT "Try again!": GO TO 20

PRINT "I now pronounce you husband and wife."

Line 10 makes the computer ask the groom, "Do you take this woman to be your lawful wedded wife?" If the groom doesn’t say "I do", the next line makes the computer beep, say "Try again!", and repeat the question. Line 20 does the same thing to the bride. The bottom line congratulates the couple for answering correctly and getting married.

SOUND

If your program says —

SOUND 440, 18.2

the computer will produce a sound. In that command, the 440 is the frequency ("pitch"), measured in hertz (cycles per second); so the sound will be a musical note whose pitch is 440 hertz. (That note happens to be "the A above middle C").

If you replace the 440 by a lower number, the sound will have a lower pitch; if you replace the 440 by a higher number, the sound will have a higher pitch.

Lowest pitch The lowest pitch that the computer can sing is 37. If you try to go below 37, the computer will gripe by saying:

Illegal function call

Higher pitches The highest pitch that the computer can sing is 32767, but human ears aren’t good enough to hear a pitch that high.

When you were a baby, you could probably hear up to 20000. As you get older, your hearing gets worse, and you can’t hear such high notes. Today, the highest sound you can hear is probably somewhere around 14000.

To find out, give yourself a hearing test, by running this program:

CLS

DO

INPUT "What pitch would you like me to play"; p

SOUND p, 18.2

LOOP

When you run that program, begin by inputting a low pitch (such as 37). Then input a higher number, then an even higher number, until you finally pick a number so high you can’t hear it. (When trying that test, put your ear close to the computer’s speaker, which is in the computer’s front left corner.) When you’ve picked a number too high for you to hear, try a slightly lower number. Keep trying different numbers, until you find the highest number you can hear.

Have a contest with your friends: find out which of your friends can hear best.

If you run that program every year, you’ll see that your hearing gets gradually worse. For example, when I was 36 years old, the highest pitch I could hear was about 14500, but I can’t hear that high anymore. How about you?

 

Longer sounds In those examples, the 18.2 makes the computer produce the sound for 1 second. If you want the sound to last longer — so that it lasts 2 seconds — replace the 18.2 by 18.2*2. For 10 seconds, say 18.2*10. (That’s because the computer’s metronome beats 18.2 times per second.)

PLAY

If your program says —

PLAY "c d g# b- a"

the computer will play the note C, then D, then G sharp, then B flat, then A.

In the PLAY command, the computer ignores the spaces; so if you wish, you can write:

PLAY "cdg#b-a"

Octave The computer can play in seven octaves, numbered from 0 to 6. Octave 0 consists of very bass notes; octave 6 consists of very high-pitched notes. In each octave, the lowest note is a C: the notes in an octave are C, C#, D, D#, E, F, F#, G, G#, A, A#, and B.

"Middle C" is at the beginning of octave 2. Normally, the computer plays in octave 4. To make the computer switch to octave 3, type the letter "o" followed by a 3, like this:

PLAY "o3"

After giving that command, anything else you PLAY will be in octave 3, until you change octaves again.

You can use the symbol ">" to mean "go up an octave", and you can use the symbol "<" to mean "go down an octave". For example, if you say —

PLAY "g > c d < g"

the computer will play the note G, then go up an octave to play C and D in that higher octave, then go down to the original octave to play G again.

Numbered notes The lowest note the computer can play (which is the C in octave 0) is called "note 1". The highest note the computer can play (which is the B in octave 6) is called "note 84".

To make the computer play note 84, you can type this:

PLAY "n84"

To make the computer play its lowest note (1), then its middle note (42), then its highest note (84), type this:

PLAY "n1 n42 n84"

Length Besides playing with pitches, you can also play with rhythms ("lengths" of the notes). Normally each note is a "quarter note". To make the computer switch to eighth notes (which are faster), type this:

PLAY "L8"

Besides using L8 for eighth notes, you can use L16 for sixteenth notes (which are even faster), L32 for thirty-second notes (which are super-fast), and L64 for sixty-fourth notes (which are super-super-fast). For long notes, you can use L2 (which gives a half note) or L1 (which gives a whole note).

You can use any length from L1 to L64. You can even use in-between lengths, such as L7 or L23 (though such rhythms are hard to stamp your foot to).

Dots If you put a period after a note, the computer will multiply the note’s length by 1½.

For example, suppose you say:

PLAY "L8 c e. d"

The C will be an 8th note, E will be 1½ times as long as an 8th note, and D will be an 8th note. Musicians call that E a dotted eighth note.

If you put two periods after a note (like this: e..), the computer will multiply the note’s length by 13/4. Musicians say the note is double dotted.

If you put three periods after a note (like this: e...), the computer will multiply the note’s length by 17/8.

Pause To make the computer pause ("rest") for an eighth note, put a p8 into the music string.

Tempo Normally, the computer plays 120 quarter notes per minute; but you can change that tempo. To switch to 150 quarter notes per minute, say:

PLAY "t150"

You can switch to any tempo from 32 to 255. The 32 is very slow; 255 is very fast. In musical terms, 40=larghissimo, 50=largo, 63=larghetto, 65=grave, 68=lento, 71=adagio, 76=andantino, 92=andante, 114=moderato, 120=allegretto, 144=allegro, 168=vivace, 188=presto, and 208=prestissimo.

Combine them You can combine all those musical commands into a single PLAY statement. For example, to set the tempo to 150, the octave to 3, the length to 8 (which means an eighth note), and then play C and D, and then change the length to 4 and play E, type this:

PLAY "t150 o3 L8 c d L4 e"

PRINT USING

Suppose you want to add $12.47 to $1.03. The correct answer is $13.50. This almost works:

PRINT 12.47 + 1.03

It makes the computer print:

13.5

But instead of 13.5, we should try to make the computer print 13.50.

This command forces the computer to print 13.50:

PRINT USING "##.##"; 12.47 + 1.03

The "##.##" is called the picture or image or format: it says to print two characters, then a decimal point, then two digits. The computer will print:

13.50

This command puts that answer into a sentence:

PRINT USING "You spent ##.## at our store"; 12.47 + 1.03

The computer will print:

You spent 13.50 at our store

Rounding

This program makes the computer divide 300 by 7 but round the answer to two decimal places:

CLS

PRINT USING "##.##"; 300 / 7

When the computer divides 300 by 7, it gets 42.85714, but the format rounds the answer to 42.86. The computer will print:

42.86

Multiple numbers

Every format (such as "###.##") is a string. You can replace the format by a string variable:

CLS

a$ = "###.##"

PRINT USING a$; 247.91

PRINT USING a$; 823

PRINT USING a$; 7

PRINT USING a$; -5

PRINT USING a$; -80.3

The computer will print:

247.91

823.00

7.00

-5.00

-80.30

When the computer prints that column of numbers, notice that the computer prints the decimal points underneath each other so that they line up. So to make decimal points line up, say PRINT USING instead of just PRINT.

To print those numbers across instead of down, say this:

PRINT USING "###.##"; 247.91; 823; 7; -5; -80.3

It makes the computer print 247.91, then 823.00, etc., like this:

247.91823.00 7.00 -5.00-80.30

Since the computer prints those numbers so close together, they’re hard to read. To make the computer insert extra space between the numbers, widen the format by putting a fourth "#" before the decimal point:

PRINT USING "####.##"; 247.91; 823; 7; -5; -80.3

Then the computer will print:

247.91 823.00 7.00 -5.00 -80.30

If you say —

PRINT USING "My ## pals drank ###.# pints of gin"; 24; 983.5

the computer will print:

My 24 pals drank 983.5 pints of gin

Oversized numbers

Suppose you say:

PRINT USING "###.##"; 16238.7

The computer tries to print 16238.7 by using the format "###.##". But since that format allows just three digits before the decimal point, the format isn’t large enough to fit 16238.7. So the computer must disobey the format. But the computer also prints a percent sign, which means, "Warning! I am disobeying you!" Altogether, the computer prints:

%16238.70

Final semicolon

At the end of the PRINT USING statement, you can put a semicolon:

CLS

PRINT USING "##.##"; 13.5;

PRINT "credit"

Line 2 makes the computer print 13.50. The semicolon at the end of line 2 makes the computer print "credit" on the same line, like this:

13.50credit

Advanced formats

Suppose you’re running a high-risk business. On Monday, your business runs badly: you lose $27,931.60, so your "profit" is minus $27,931.60. On Tuesday, your business does slightly better than break-even: your net profit for the day is $8.95.

Let’s make the computer print the word "profit", then the amount of your profit (such as -$27,931.60 or $8.95), then the word "ha" (because you’re cynical about how your business is going).

You can do that printing in several ways. Let’s explore them.…

If you say —

CLS

a$ = "profit######.##ha"

PRINT USING a$; -27931.6

PRINT USING a$; 8.95

the computer will print:

profit-27931.60ha

profit 8.95ha

Comma If you change the format to "profit###,###.##ha", the computer will insert a comma if the number is large:

profit-27,931.60ha

profit 8.95ha

Plus sign If you change the format to "profit+#####.##ha", the computer will print a plus sign in front of any positive number:

profit-27931.60ha

profit +8.95ha

 

Trailing minus To print a negative number, the computer normally prints a minus sign before the number. That’s called a leading minus. You can make the computer put the minus sign after the number instead; that’s called a trailing minus. For example, if you change the format to "profit######.##-ha", the computer will print a minus sign after a negative number (and no minus after a positive number), like this:

profit27931.60-ha

profit 8.95 ha

Dollar sign Normally, a format begins with ##. If you begin with $$ instead (like this: "profit$$#####.##ha"), the computer will print a dollar sign before the digits:

profit-$27931.60ha

profit $8.95ha

Check protection If you begin with ** (like this: "profit**#####.##ha"), the computer will print asterisks before the number:

profit*-27931.60ha

profit******8.95ha

If you begin with **$ (like this: "profit**$#####.##ha"), the computer will print asterisks and a dollar sign:

profit*-$27931.60ha

profit******$8.95ha

When you’re printing a paycheck, use the asterisks to prevent the employee from enlarging his salary. Since the asterisks protect the check from being altered, they’re called check protection.

Combination You can combine several techniques into a single format. For example, you can combine the comma, the trailing minus, and the **$ (like this: "profit**$##,###.##-ha"), so that the computer will print:

profit**$27,931.60-ha

profit*******$8.95 ha

E notation If you change the format to "profit##.#####^^^^ha", the computer will print numbers by using E notation:

profit-2.79316E+04ha

profit 8.95000E+00ha