Sharp logo

MZ-800 course Chapter 6 
6. Musical applications


6.2 BASIC-instructions for sound and music

In this part of chapter 6 we shall discuss the BASIC-instructions that make the SHARP produce sound or music. On the pages 6 - 68 up to 6 - 72 of the manual you can also find information about the so-called music control statements. Because this information is more than enough to get started with the instructions, this part of chapter 6 will mostly contain examples for the various instructions.

BEEP -

With the BEEP instruction a short tone of 440 Hz is produced. An example:

10 GET A$:IF A$<>"" THEN BEEP
20 GOTO 10

This little program produces a short tone on each keypress.

     
SOUND - With this instruction you can produce a tone with an arbitrary pitch and length. The instruction works as follows: SOUND(x, y) in which x is the pitch and y is the length. On page 6 - 71 of the manual you will find a table about the SOUND instruction.
     
NOISE - With this instruction you can produce “clear noise”. Contrary to what the manual says, it is not possible to produce two parts of “clear noise” at the same time.

MUSIC:

That brings us to the most important instruction of them all, the MUSIC instruction. Prior to or after this instruction the following instructions can occur:

TEMPO - Controls the tempo at which a piece of music is played.
Here TEMPO 1 is the slowest tempo and TEMPO 7 the fastest.
     
MUSIC STOP - Stops everything that produces a sound at that time, this also applies to
the sounds that are produced by writing to port $F2 directly.
     
MUSIC WAIT - This instruction makes sure that all notes in a piece of music are played
before the program continues.
     
MUSIC INIT - This instruction sets the music and NOISE instructions to their default
values which are “02V15L5T4S8M255”.

Now we will discuss the MUSIC-instruction itself. The options of this instruction and how to use them is described in the manual at pages 6 - 68 up to 6 - 70. Here we shall give some examples of the possibilities of the MUSIC-instruction.

You can do all sorts of things with this instruction, form the sound of a LASER-gun to the BOLERO or something like that. You will find a piece of the BOLERO at the end of this chapter.

The examples we give here are simple examples of sounds and short samples of certain musical pieces.

If a program does not work, you might want to try the instruction MUSIC INIT.

The programs may contain the ‘GRAPH & 2 ’ and ‘GRAPH & SHIFT & 2 ’ characters. You can enter these characters in the following way:

GRAPH & 2 you get by pressing the GRAPH-key first and then the 2.
GRAPH & SHIFT & 2 you get by pressing the GRAPH-key first and then the SHIFT-2.

With this information you can work with the examples.


Example 1: A piece of When the Saint

In this example we only use one chord, this will be the case in most of the examples.

1 MUSIC INIT
2 TEMPO 7
3 MUSIC"C5E5F5G9G5C5E5F5G9G5C5E5F5"
4 MUSIC"G7E7C7E7D9D5E5E5D5"
5 MUSIC"C8R0C5E7G7R0G5F8F7E5F5"
6 MUSIC"G7E7C7D7C9C5R0C5E5F5"
7 MUSIC"G9G5C5E5F5G9G5C5E5F5"
8 MUSIC"G7E7C7E7D9D5E5R0E5D5"
9 MUSIC"C8R0C5E7G7R0G5F8F7E5F5"
10 MUSIC"G7E7C7D7C9"
11 MUSIC WAIT:CLS:END


Example 2: Pac-man music

TEMPO 7:MUSIC"C2GECGGRC4#C2#GF#C#GR#C4C2GECGRC4R0C2DEFGABGRAPH & 2C"


Example 3: Laser-gun

TEMPO 7:MUSIC"CGRAPH & 2CBAGFEDCGRAPH & 2CBAGFEDCRR"


Example 4: Short melody

Many examples consist of very short melodies. Sometimes they are part of a musical piece and sometimes they are from games. Other melodies are complete.

TEMPO 4:MUSIC"CRCEREGR0GRGRGRAPH & 2C2"


Example 5: Short melody

This is a sample from a well known melody.

TEMPO 4:MUSIC"RRGRAPH & SHIFT & 2AD#CDEFEFGAARR"


Example 6: Short melody

This is a sample from a well known melody.

TEMPO 4:MUSIC"GRAPH & 2CC0AARR0DGRAPH & 2CAAR0AGF0F0DDD0R0AA0G0F0DD0RR"


Example 7: Short melody

Another sample from a very well known melody.

TEMPO 4:MUSIC"D1#D1E1GRAPH & 2C2E1GRAPH & 2C2E1GRAPH & 2C4GRAPH & 2C1GRAPH & 2C1GRAPH & 2D1GRAPH & 2#D1GRAPH & 2E1GRAPH & 2C1GRAPH & 2D1GRAPH & 2E1GRAPH & 2E1B1GRAPH & 2D1GRAPH & 2C4"


Example 8: Short melody

A sample from a well known melody.

TEMPO 6:MUSIC"GRAPH & SHIFT & 2#D3GRAPH & SHIFT & 2F4R1GRAPH & SHIFT & 2F7GRAPH & SHIFT & 2F1R1GRAPH & SHIFT & 2#D3GRAPH & SHIFT & 2F5GRAPH & SHIFT & 2#GGRAPH & SHIFT & 2#AGRAPH & SHIFT & 2B3CGRAPH & SHIFT & 2BC5GRAPH & SHIFT & 2#G3GRAPH & SHIFT & 2F5GRAPH & SHIFT & 2C3GRAPH & SHIFT & 2#D3GRAPH & SHIFT & 2F4R1GRAPH & SHIFT & 2F7GRAPH & SHIFT & 2F3"


Example 9: Short melody

A sample from a very well known melody.

TEMPO 6:MUSIC"R3GRAPH & SHIFT & 2C5GRAPH & SHIFT & 2D3GRAPH & SHIFT & 2F4GRAPH & SHIFT & 2GR3R3GRAPH & SHIFT & 2G5GRAPH & SHIFT & 2F3GRAPH & SHIFT & 2D4GRAPH & SHIFT & 2CR3R3GRAPH & SHIFT & 2C5GRAPH & SHIFT & 2D3GRAPH & SHIFT & 2F4GRAPH & SHIFT & 2GR1GRAPH & SHIFT & 2#G1GRAPH & SHIFT & 2
A2R0GRAPH & SHIFT & 2A3GRAPH & SHIFT & 2G0RGRAPH & SHIFT & 2G3GRAPH & SHIFT & 2F1GRAPH & SHIFT & 2
F5RR3C5D3F4GR3R3G5F3D4CR3R3C5D3F4GR1#G1A2R0A3G0RGG3F1F5R5"


Piece of music.

This program plays a larger musical piece.

1 MUSIC INIT:TEMPO 5
2 A1$="GRAPH & 2C2R0GRAPH & 2C2GGRAPH & 2CGRAPH & 2EGRAPH & 2CGRAPH & 2EGRAPH & 2GGRAPH & 2CGRAPH & 2#BGRAPH & 2BGRAPH & 2AGRAPH & 2G6R1"
3 A2$="GRAPH & 2G2GRAPH & 2FGRAPH & 2DBGBGRAPH & 2D"
4 A3$="GRAPH & 2FGRAPH & 2EGRAPH & 2CGRAPH & 2AGRAPH & 2GGRAPH & 2G"
5 A4$="GRAPH & 2#BGRAPH & 2AGRAPH & 2FGRAPH & 2CAGRAPH & 2CGRAPH & 2FGRAPH & 2AGRAPH & 2GGRAPH & 2CGRAPH & 2GGRAPH & 2GR"
6 A5$="GRAPH & 2GR1"
7 A6$="BGRAPH & 2CGGRAPH & 2EGRAPH & 2CGRAPH & 2CGRAPH & 2CR"
8 A7$="BGRAPH & 2CGGRAPH & 2EGRAPH & 2CGRAPH & 2CGRAPH & 2CRR"
9 A8$="RR"
10 MUSIC A1$,A2$,A3$,A5$,A1$,A2$,A6$,A4$,A2$,A3$,A8$,A4$,A8$,A2$,A7
11 MUSIC WAIT:CLS:END


Example 10: Short melody

TEMPO 7:MUSIC"+F5+G5+#D5#A5+#D7R7C5D5-#A5-F5-#A7"


Example 11: The last short melody

This melody also is a sample from a well known melody.

TEMPO 7:MUSIC"F5+C7+D1+C1#A1+C7F5+C7+D1+C1#A1+C7F5+E7+C5F5+E7+C5F5+E1+D1+E1+F7"

These were a number of examples on the possibilities of the MUSIC instruction. Some melodies can only be played after the use of MUSIC INIT. Other melodies however, do not sound as good as they should after the use of MUSIC INIT.

The laser-gun example sounds at its best when the instruction MUSIC INIT is not used yet.

All previous examples only used one chord, while three can be used at the same time. In the last part of this chapter there are some melodies that make use of all three chords. The result is obviously better, but the programs get a lot bigger.

All these melodies can also be made audible with the use of machine language. In the next part of this chapter we shall discuss this thoroughly.

The options of the 800-BASIC are not entirely equal to those of the 700-BASIC. We shall discuss some of the 700-BASIC options in chapter 8.


Previous page
Next page
Contents


Go to the top of this page Home

last updated March 22, 2006
Arjan Habing, Mark de Rover, Jeroen F. J. Laros, sharpmz@sharpmz.org