Category : BASIC Source Code
Archive   : BASICCLS.ZIP
Filename : BASIC6W
.N:23
.R:
.H :PAGE $$$ BASIC LANGUAGE COURSE INFORMATION SHEET - (C) TRILOGY MICRO SYSTEMS 1989
.H :
.F :
.f : -------- TRILOGY MICRO SYSTEMS - TEL. (301) 764-0816 ---------
Creating Sounds
There are two statements for creating music on the computer, SOUND and
PLAY.
The SOUND frequency,duration statement plays one note. The frequency
is in hertz (cycles per second), and the duration is in clock ticks (18.2
per second). Middle C is approximately 523 hertz. A quarter note can be
given duration 4 (depending on the tempo you want). Frequency can range
from 37 to 32767. A frequency of 32767 produces a period of silence
(pause). Duration can range from 0 to 65535.
If the piano keys (black and white) are each assigned a number for the
notes the computer can play, there would be 82 keys and middle C would be
46. For each key, if I is the key number, the formula for calculating the
frequency is: 36.8 * (2^(1/12))^I. If you double the frequency, you will
get the same note in the next octave. Since there are twelve notes in an
octave, you would raise each note by 1/12th of a whole octave. This method
is used by the IBM music program (provided with early versions of PC-DOS).
The following program assigns a frequency to the keys (leaving 0 for
pauses) and plays Mikimi from DATA statements which have the key number
and duration. Other songs can be played by changing the DATA statements.
10 DIM F(82)
20 M(0) = 32767
30 FOR I = 1 TO 82
40 F(I) = 36.8*(2^1/12))^I
50 NEXT I
60 READ I,D
70 IF I = -1 THEN END
80 SOUND F(I),D
90 SOUND 32767,1 'leave out for staccato
100 GOTO 60
110 DATA 34,2,34,2,34,4,37,2,39,4,37,3,34,1,34,2,34,4,37,2,39,4,37,3,37,1
120 DATA 41,2,41,4,41,2,41,2,41,4,41,2,39,4,41,2,39,2,37,6,34,2,34,2,34,4
130 DATA 37,2,39,4,37,3,34,1,34,2,34,4,37,2,39,4,37,3,37,1,41,2,41,4,41,2
140 DATA 41,2,41,4,41,2,39,4,41,2,39,2,37,6,41,2,39,2,39,4,39,2,39,2,39,4
150 DATA 39,2,39,2,41,2,42,2,41,2,39,6,39,2,37,2,37,4,37,2,37,2,37,4,37,2
160 DATA 37,2,39,2,41,2,39,2,37,6,41,2,39,2,39,4,39,2,39,2,39,4,39,2,39,2
170 DATA 41,2,42,2,41,2,39,6,46,2,46,2,46,4,44,2,46,2,46,4,44,2,46,2,44,2
180 DATA 46,2,44,2,46,6,-1,-1
The PLAY statement is used to play music on the computer. The format is
PLAY string. The string is composed of playing instructions including:
A-G Play the indicated note. A + or # following the note produces a
sharp, a - produces a flat. A number following the note changes
the length for that note, e.g. F1 plays a whole note F, F4 plays a
quarter note F.
Ln Sets the length of all following notes (except those followed by a
number) from L1 for whole notes to L64 for 64th notes. L4 plays
quarter notes.
. A period following the note increases its length by 1/2.
Ml Describes how the music will be played. MF plays in foreground one
note at a time. MB plays in background while the BASIC program
continues to execute. MN - normal, ML - legato, MS - staccato.
On Sets the octave. There are 7 octaves - 0 through 6. The default is
4. Middle C starts octave 3.
Pn Pause. The length of the pause is 1 - 64 like the notes.
Tn Sets the tempo (the number of quarter notes in a minute from 32 -
255. The default is 120.
Xstring; Plays the string. The string name must be followed by a
semicolon. X is very useful for repeated phrases.
> Changes to the next higher octave.
< Changes to the next lower octave.
10 REM Auld Lang Syne
20 p1$ = "d.
40 PLAY "t240o2dg.g8gba.g8abggb>de2.exp1$;xp2$;g2p4>exp1$;>ed.
exp1$;xp2$;g2.p4"
Drawing Pictures
The SCREEN mode statement selects text or graphics modes. Mode can be
0 Text mode
1 Medium resolution graphics 320 x 200 dots (CGA or EGA)
2 High resolution graphics 640 x 200 dots (CGA or EGA)
In medium resolution mode each dot is twice as thick as it is in high
resolution mode, so circles and diagonals will have more jagged edges.
However, more colors can be used in medium resolution mode.
On monochrome displays the graphics modes will not work. There is a
program, SIMCGA that lets a monochrome graphics display (such as we
have), behave like it is a CGA (color graphics adapter) display.
Plotting points
Graphics instructions require you to specify the location of points on the
screen (the end point of a line, the center of a circle). You do this by
specifying x and y coordinates as you would in trigonometry.
x is the horizontal dot number. A dot at the left edge of the screen would
be 0. A dot at the right edge of the screen in high resolution mode would
be 640 (there are 640 dots across on the line). In medium resolution mode,
a dot at the right edge would be 320. 100 would be approximately 1/6 of
the screen across in high resolution mode.
y is the vertical dot number. There are only 200 dots down the screen in
either medium or high resolution mode. 0 is the top of the screen. 200 is
the bottom. 100 would be in the center.
The LINE statement draws a line or box on the screen. You supply the
horizontal and vertical dot numbers for the starting and ending points.
Optional color and box codes can be included. The format is
LINE (x1,y1) - (x2,y2),color,box. x1 or x2 from 0 to 640 will appear on
the screen in high resolution mode. y1 or y2 from 0 to 200 will appear on
the screen. Higher numbers will be cropped. Color 0 is black and is used
to erase a line. Box codes are B to draw a box with the starting and
ending points in opposite corners; and BF to fill the box.
10 SCREEN 2 'HIGH RESOLUTION
20 LINE (0,0) - (640,0) 'HORIZONTAL LINE ACROSS TOP
30 LINE (0,0) - (0,200) 'VERTICAL LINE AT LEFT
40 LINE (0,0) - (640,200) 'DIAGONAL LINE TOP LEFT TO BOTTOM RIGHT
50 LINE (0,0) - (640,200),,B 'BOX ENTIRE SCREEN
60 LINE (0,0) - (640,200),,BF 'FILLED BOX ENTIRE SCREEN
70 LINE (0,0) - (640,200),0,BF 'ERASE FILLED BOX
The CIRCLE statement draws a circle, curve or angle on the screen. The
format is CIRCLE (xcenter,ycenter),radius,color,start,end,aspect. The
aspect is used for ellipses. Radius is in the size of horizontal dots.
Start and end are used for drawing curves and angles. They are numbers
from 0 to 2 * pi (approx. 6.3) representing an angle for an arc. If either
number is negative an angle is drawn to the center of the circle.
ã/2 (1.6)
³
2.4 ³ .8
³
ã (3.14) ÄÄÄÄÄÄÄÄÄÄ CENTER ÄÄÄÄÄÄÄÄÄÄ 0 & 2ã (6.3)
4 ³ 5.5
³
³
3ã/2 (4.7)
10 SCREEN 2
20 CIRCLE(320,200),100 'CIRCLE IN CENTER WITH DIAMETER FROM 220 TO 420
30 CIRCLE(320,200),100,0 'ERASE CIRCLE
40 CIRCLE(320,200),100,,4,5.5 'CURVE AT BOTTOM OF CIRCLE
50 CIRCLE(320,200),100,,.8,2.4 'CURVE AT TOP OF CIRCLE
Animation
You can create animation by drawing a line, erasing it, changing its
location and drawing the line again. If the change in location is small,
you will create slow movement. A larger change in location creates faster
movement. Depending on which points you change, you can create different
kinds of motion. You can make a horizontal line appear to grow by changing
the x coordinate of only one end point. A line can appear to move
horizontally if you change the x coordinate of both end points by the same
amount. A line will appear to fan out, if you change both the x and y
coordinates of only one end point.
The following program draws a stick man and moves the arms and legs up and
down. It plays LONDON BRIDGE before and after each set of movements.
10 screen 2 : circle(100,35),50 :REM HEAD
15 circle(75,30),2 : circle(125,30),2 : circle(100,35),4 :REM EYES & NOSE
16 circle(100,28),40,,4,5.5 :REM MOUTH
20 line (100,55) - (100,100) :REM TORSO
30 gosub 200 :REM ARMS
40 gosub 250 :REM LEGS
45 phrase$ = "o3c.d16co2b-ab->c4"
50 y = 60 : ys = 100 : ye = 35 : xs = 100 : xd = 75 : st = 5
60 gosub 500 :REM PLAY LONDON BRIDGE
70 for arms = 1 to 10
80 gosub 300 :REM MOVE ARMS UP AND DOWN
90 next arms
100 gosub 200 :REM REDRAW ARMS
110 y = 100 : ys = 150 : ye = 125 : xs = 100 : xd = 50 : st = 5
120 gosub 500 :REM PLAY MUSIC
130 for legs = 1 to 10
140 gosub 300 :REM MOVE LEGS UP AND DOWN
150 next legs
160 gosub 250 :REM REDRAW LEGS
170 gosub 500 :REM PLAY MUSIC
180 end
200 line (100,60) - (25,100) :REM LEFT ARM
210 line (100,60) - (175,100):REM RIGHT ARM
220 return
250 line (100,100) - (50,150) :REM LEFT LEG
260 line (100,100) - (150,150):REM RIGHT LEG
270 return
300 for x = ys to ye step -st
310 line (xs,y) - (xs - xd, x) :REM MOVE LEFT ARM OR LEG UP
320 line (xs,y) - (xs + xd, x) :REM MOVE RIGHT ARM OR LEG UP
330 line (xs,y) - (xs - xd, x), 0 :REM ERASE LEFT ARM OR LEG
340 line (xs,y) - (xs + xd, x), 0 :REM ERASE RIGHT ARM OR LEG
350 next x
360 for x = ye to ys step st
370 line (xs,y) - (xs - xd, x) :REM MOVE LEFT ARM OR LEG DOWN
380 line (xs,y) - (xs + xd, x) :REM MOVE RIGHT ARM OR LEG DOWN
390 line (xs,y) - (xs - xd, x), 0 :REM ERASE LEFT ARM OR LEG
400 line (xs,y) - (xs + xd, x), 0 :REM ERASE RIGHT ARM OR LEG
410 next x
420 return
500 play "l8xphrase$;
New Statements used in the Hangman program
The DEFINT variable statement declares that variable will be an integer.
It will have no decimal places. Multiple variables can be declared. They
will be separated by commas.
The COLOR statement defines which colors will appear on the screen if you
have a color video adapter. In medium resolution mode (SCREEN 1), the
syntax is COLOR background,palette. For the other modes the syntax is
COLOR foreground,background,border. However, border can only be used in
text mode (SCREEN 0). The foreground, background and border are integers
which represent the color.
0 Black 8 Gray
1 Blue 9 Light Blue
2 Green 10 Light Green
3 Cyan 11 Light Cyan
4 Red 12 Light Red
5 Magenta 13 Light Magenta
6 Brown 14 Yellow
7 White 15 High Intensity white
The background is black if not otherwise specified. The palette determines
the color to be drawn, if the color in a LINE or CIRCLE statement is 1,2
or 3. If palette = 0 then 1 = green, 2 = red, and 3 = yellow.
If palette = 1 then 1 = cyan, 2 = magenta and 3 = hi. int. white
The LOCATE row, column statement moves the cursor to the row and column
specified. LOCATE is used before printing, especially when mixing text and
graphics, to print at a particular location on the screen.
TIME$ is a variable in the form hh:mm:ss (hours, minutes, seconds) which
contains the time of the system clock.
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/