Magazine Archive

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


Rhythm Sequencer for the MZ80K

This month we are returning to the Sharp MZ80K with a program which can create 'Kraftwerk' type rhythm tracks.

Nine 'instruments' are provided representing Bass drum, 2 Side drums, 2 Toms and 4 Wood blocks. These are produced by the Sharp's internal speaker.

The listing, shown in Figure 1, is intended for Standard Basic on the Sharp, but the program breakdown provided should make conversion to other Basics a fairly simple matter.

Rhythms can be entered in two ways; either preprogrammed from DATA statements or step by step from the keyboard. When the latter method is used a moving pointer indicates the type of instrument selected.

Tempo changes can be made while the rhythm is playing, with a visual update on the display.

An editing option allows single steps to be changed and rhythms up to 200 steps in length can be accommodated.

Program breakdown


Line 1: Variables which are to be used are set. These are:

S = 4514 (11A2H) High byte of note frequency.
H = 523248 (D000H) Start of video RAM.
V = 4466 (1172H) Vertical cursor position.
L = 4465 (1171H) Horizontal cursor position.
T = 250 Initial Tempo setting
P = 1 First programmable step
Z = 338 Screen displacement
V (255) Note frequency array
I (255) Screen pointer array
Q (200) Rhythm array
RH = 3 No. of preprogrammed rhythms.

Line 2: The first set of data is read from lines 44 and 45, variable B being used as the subscript to load values into the two arrays V and I.

Lines 3-7: A header, 'Rhythm Sequencer' and selection menu is printed on the screen using a combination of poke and prints.


Line 10: 'Automatic or Programmable mode?' is printed on the screen.

Line 11: Keyboard is continuously scanned until a character W$ is entered.

Line 12: Variable C is set as the ASCII equivalent of the character read.

The remaining data in line 45 is read and poked into locations 24553 to 24560. This machine code routine calls the monitor's keyboard scanning routine at 001BH, transfers the result from the accumulator to location 24560 and then returns from the call. This provides a quicker keyboard read than 'GET', which allows rhythms to run faster.

Line 13: If C = 65 (ASCII 'A') then the program jumps to line 39, the automatic mode; if C = 80 (ASCII 'P') then the program jumps to line 14; anything else and the program is started again.

Line 14: Variable 0 is set to 1 (used in the play mode). The main program loop is entered and message 'Enter voice for step R' printed.

Line 15: USR (24553) calls the machine code routine at location 24553. Variable K is set with the result and used as the subscript for array V. It's value will be 0 if the key pressed was not 0-9 or E, and the keyboard will be continually scanned until a valid key is pressed.

Line 16: An arrow is used to indicate which type of instrument has been selected by pointing to the relevant menu statement. This is accomplished by poking 196 to a location in the video memory pointed to by H plus displacement Z, read from pointer array I with subscript K.

N is set as R-1, or number of steps.

Line 17: If K=69 or key pressed is 'E' then the program jumps to line 22, playback.

Line 18: Rhythm array Q, step R, is loaded with a value from the note array V, pointed to by K. The sound variable, S, is also loaded with the value of V and the monitor sound routine is called, USR (68). Loading S with 0 and calling USR (68) again clears the note. 'CH'>0 Then Return is used in the edit mode.

Line 19: Continue round the loop until R=300.


Lines 22-25: Print playback menu options with 'Step' and 'Tempo'.

Line 26: Main play loop entered, the cursor is moved to the position after the word 'Step' and step number printed. The sound variable, S, is loaded with the value of array Q at step P and the sound routine called.

Line 27: USR (71) called which silences the note emitted from the speaker after which a random element is added to the lower byte of the sound variable, S.

The machine code keyboard scan is called to check if any keys are pressed, if so, then the program jumps to line 29.

Line 28: DL is set to 50 and if 0 is 0, a delay loop entered. The delay time is varied by the value of T (initially 250).

The loop repeats until P=N, then restarts at P=1 to repeat sequence.

Line 29: If A=45 or key pressed is then the value of T is decreased to a minimum of 1. Subroutine at line 38 is called.

Line 30: If A=43 or key pressed is '+' then the value of T is increased to a maximum of 500. Subroutine at line 38 is called.

Line 31: If A=83 or key pressed is 'S' then 0 is set to 0 and play mode re-entered from the start.

Line 32: If A=79 or key pressed is 'O' then 0 is set to 1 and a delay loop entered. DL is set to 0 and a return made for the next step which repeats until P=N.

Line 33: If A=67 or key pressed is 'C' then R is set to the same value as P, that is write step to current play step; D is set to same value as N. as a temporary store of the current number of steps; CH is set to 1 a 'change' flag which allows a return from subroutine call at line 14. After the return N is reset with value of D.

Line 34: If A=91 or key pressed is '[' then run again.

Line 35: Jump to line 27 (rescan) if none of the above.

Line 38: Position cursor after 'Tempo' on screen and print new value of T. Return from subroutine call.

Line 39: Print 'Select rhythm number 1 to 3'.

Line 40: Scan keyboard for character W$.

Line 41: Set A to ASCII value of W$ less 48 to obtain number selected from keyboard.

Line 42: Read data in lines 51-57. M$ is the name of the selection; N, the number of steps; T, the tempo and C the note values.

Line 43: Print 'The sequence prepared is'; number A; name M$. 0 is set to 1 and the program jumps to line 21, the play mode.

Lines 44-45: Array and machine code routine data.

Lines 51-57: Preprogrammed rhythm data.

Figure 1a. Rhythm Sequencer Listing.

Figure 1b. Rhythm Sequencer Listing (contd.).

Also featuring gear in this article

Previous Article in this issue

New Casio Keyboards

Next article in this issue

Aria Professional Microphones

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


Electronics & Music Maker - Mar 1983



Gear in this article:

Computer > Sharp > MZ-80K

Feature by Kenneth McAlpine

Previous article in this issue:

> New Casio Keyboards

Next article in this issue:

> Aria Professional Microphone...

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 June 2020
Issues donated this month: 0

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

Funds donated this month: £0.00

All donations and support are gratefully appreciated - thank you.

If you're enjoying the site, please consider supporting me to help build this archive...

...with a one time Donation, or a recurring Donation of just £2 a month. It really helps - thank you!

Small Print

Terms of usePrivacy