Home -> Magazines -> Issues -> Articles in this issue -> View
Micromusic | |
Music programming on the Sharp MZ-80K in Pascal and FORTHArticle from Electronics & Music Maker, October 1981 | |
Pascal and FORTH will speed up your music making.
Earlier issues of Electronics and Music Maker have detailed the programming techniques which enable the Sharp MZ-80K micro to play tunes written in BASIC or machine code. Two further languages are now available for the Sharp - Pascal and FORTH. Both support music statements, and programming sounds presents an interesting challenge and greatly assists in learning the new languages.
Pascal was originally developed as a teaching aid and in that respect it is excellent as it encourages programmers to adopt a systematic and logical approach towards writing structured software. Sharp have released a Pascal interpreter for the MZ-80K which occupies 17K of RAM leaving 31K for programming on the 48K Sharp. Sharp's interpreter has many of the features as defined by Niklaus Wirth, the inventor of Pascal, with the addition of TEMPO and MUSIC.

An example of a music program written in Sharp Pascal appears in Figure 1. The first thing to notice about a Pascal program is that there are no line numbers - those that appear on the left hand side of the listing are merely used by the text editor to make preparation of a program easier. These numbers have been left in the listing to make the explanations somewhat easier. A semi-colon is used to denote the end of a statement line. The indentation of the listing is not essential but is advisable in order to make the programs readable and lucid.
All variables in a Pascal program must be declared before use along with their type, which may be real, integer, character (car), or boolean. Line 0 declares a variable A which is used to store an integer. BEGIN in line 1 signifies the end of all declarations of variables and denotes the start of the main program block, which is terminated by the word END. (note the full stop). Line 2 sets the tempo for the music calls and can be in the range 1 to 7. Line 3 initialises variable A with the value 6 and it is worth noting that a variable is of indeterminate value between declaration and initialisation. Line 4 is the equivalent of a BASIC PRINT statement as Sharp Pascal accepts the usual print formatting characters.

Lines 5 to 12 demonstrate one of Pascal's best features, the WHILE-DO loop. If the test at the start of the i loop is true, the loop is repeated until such a time as the condition finally becomes false. With a REPEAT-UNTIL loop it is possible to place the test at the bottom of the loop. The music statements in lines 7 to 10 are very similar to the BASIC music commands. The use of a comma as in line 8 programs a small rest to produce the distinctive dotted quaver - semi-quaver rhythm. Each time the loop is executed the value of A is decreased by 1 until finally the test registers false and the program ends.
Obviously there is far more to Pascal than can be shown in this small example but it gives an indication why Pascal is being hotly tipped to become the successor to BASIC in the world of personal microcomputing.
Another language which is now available on tape for the Sharp MZ-80K is FORTH and again the implementation supports the Sharp music facility. Originally developed by a radio astronomer, FORTH is a compiled stack-based language utilising Reverse Polish Notation. FORTH is capable of a very high speed of execution as it is kept as simple as possible - indeed the programmer is left to define any extra commands required, apart from those previously defined by the language. In other words FORTH allows the programmer to strip the language down to the bare minimum of commands thus allowing programs to run at over ten times the speed of BASIC programs.

To access music in FORTH on the Sharp MZ-80K it is necessary to start by defining the Z80 CPU registers for use under program control. An example is given in Figure 2. Next it is necessary to define the MUSIC command (see Figure 3). Programming music in FORTH is then as easy as programming in BASIC (see Figure 4), but it must be remembered that the string to be played must end with a (shifted C) followed by a space and the command MUSIC.


Those users new to Pascal and FORTH may wish to start learning by using the music commands first. Errors in ordinary programs are sometimes difficult to spot and often take a long time to appear on the screen. Errors in programming music in Pascal and FORTH will be heard instantly and provide an excellent introduction to these powerful languages.
Further details of these languages from: Knights Computers, (Contact Details).
Amiga Notes |
Atari Notes |
What The Computer Does... An Introduction |
Card Tricks - Music On The PC |
Lab Notes: The Polyphonic Synthesizer |
Mac Notes |
Chip Parade (Part 1) |
Amiga Notes |
Amiga Notes |
Software Support - Hints, Tips & News From The World Of Music Software |
Amiga Notes |
The Gentle Art Of Transcription - Setting the Scene (Part 1) |
Browse by Topic:
Micro-Music - Sharp MZ-80K — the Melody Micro
(EMM Mar 81)
Micro-Music - Learning morse by computer.
(EMM May 81)
Micro-Music - Music Composer Program
(EMM Jun 81)
Micro-Music - Music on the Screen
(EMM Aug 81)
Micromusic - Rhythm Sequencer for the MZ80K
(EMM Mar 83)
Browse category: Computer > Sharp
Feature by Graham Knight
mu:zines is the result of thousands of hours of effort, and will require many thousands more going forward to reach our goals of getting all this content online.
If you value this resource, you can support this project - it really helps!
New issues that have been donated or scanned for us this month.
All donations and support are gratefully appreciated - thank you.
Do you have any of these magazine issues?
If so, and you can donate, lend or scan them to help complete our archive, please get in touch via the Contribute page - thanks!