Magazine Archive

Home -> Magazines -> Issues -> Articles in this issue -> View

Micromusic

Music programming on the Sharp MZ-80K in Pascal and FORTH

Article from Electronics & Music Maker, October 1981

Pascal and FORTH will speed up your music making.


Pascal Music



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.

Figure 1. A Pascal Program.


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.

FORTH



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.

Figure 2.


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.

Figure 3.


Figure 4.


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).


More with this topic


Browse by Topic:

Computing


Also featuring gear in this article



Previous Article in this issue

Computing News

Next article in this issue

The Blacet Syn-Bow


Publisher: Electronics & Music Maker - Music Maker Publications (UK), Future Publishing.

The current copyright owner/s of this content may differ from the originally published copyright notice.
More details on copyright ownership...

 

Electronics & Music Maker - Oct 1981

Topic:

Computing


Gear in this article:

Computer > Sharp > MZ-80K

Feature by Graham Knight

Previous article in this issue:

> Computing News

Next article in this issue:

> The Blacet Syn-Bow


Help Support The Things You Love

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!

Donations for January 2025
Issues donated this month: 0

New issues that have been donated or scanned for us this month.

Funds donated this month: £22.00

All donations and support are gratefully appreciated - thank you.


Magazines Needed - Can You Help?

Do you have any of these magazine issues?

> See all issues we need

If so, and you can donate, lend or scan them to help complete our archive, please get in touch via the Contribute page - thanks!

Please Contribute to mu:zines by supplying magazines, scanning or donating funds. Thanks!

Monetary donations go towards site running costs, and the occasional coffee for me if there's anything left over!
muzines_logo_02

Small Print

Terms of usePrivacy