CP/M Implementation on the MZ-80K
Written by Andrew J. Cornish BSc. / Crystal Electronics
Source: Mike Brinson, SHARPSOFT-magazine November 1982, Volume 6, p. 20 – 25
MZ-80 CP/M Notes ( by SHARPSOFT )
The development of CP/M for the MZ-80K was an innovative step undertaken by Crystal Electronics Ltd. A full account of its development was published in the December 1980 Liverpool Software Gazette. Mr. A. J. Cornish of Crystal Electronics has given us permission to reprint his article. We hope our readers find this article as instructive as we did when first reading it.
An Implementation of CP/M on the SHARP MZ-80K
by A.J. Cornish BSc. ( Crystal Electronics Ltd. )
The SHARP MZ-80K is arguably one of the most versatile microcomputers on the market at the present time, being both simple and inexpensive, while at the same time incorporating a number of useful hardware features. For those who are unfamiliar, these include the following:
|8255||I/O chip which handles cassette, keyboard, VDU / software synchronisation and upper / lower case indicator.|
|8253||Timer chip for real-time clock and musical tones.|
|2716||EPROM containing character set for VDU, including pixel graphics and lower-case letters.|
|4K Monitor ROM.|
Scanned keyboard with all keys software-definable. VDU 40×25 characters, memory-mapped. Cassette – Normal audio type, with numeric indicator, speed approx. 1200 baud, software controlled.
External to the main machine, we have: Floppy discs ( two, expandable to four ), double-sided, single-density, 140K per disc, 70 tracks, 16 sectors per track, 128 bytes per sector, 5 1/4“ disks.
Floppy disc controller – TOSHIBA T3444M.
Printer – 80 column EPSON type, tractor-feed, parallel interface. The floppy discs and printer interface to the main machine via the MZ80I/O interface box.
Having already developed our Xtal BASIC on the MZ-80K ( see LSG No.5 ), we decided to attempt an implementation of the CP/M Disc Operating System, in order to allow the MZ-80K to use the wide variety of languages and software available to other machines already running under CP/M. Apart from that very important advantage, CP/M also offers a system which is itself totally independent of any one high-level language, whereas the operating system normally offered with the MZ-80K is almost entirely centred around SHARP DISC BASIC.
We decided to set ourselves the following goals in our implementation:
1) The implementation should be as near to standard as possible, while hopefully including some of the features peculiar to the MZ-80K. At the same time, it must be possible to run all the existing facilities and software of the MZ-80K.
ii) The disk operations should be speeded up if at all possible. It had already been noted that, although the SHARP DISC BASIC booted impressively quickly, file accesses for loading of programs and data were exceedingly slow.
iii) All of the SHARP MZ-80 peripherals should be supported ( cassette recorder, printer, etc. )
iv) It should be reasonably easy to transfer software from another machine already running CP/M onto the MZ-80K. This is important for software houses, dealers and programmer‘s with other computers running software which they might consider offering on the MZ-80K.
Figure 1 shows the memory map of the MZ-80K as it is in normal use, and, next to it, we see the map of the system required while running CP/M. The main problem is immediately apparent: How do we put 4K of RAM in the area from 0000 – 0FFFH to replace the ROM that site there? It was clear to us that a hardware modification would be necessary, but it soon became clear that there were many different solutions to the problem – all expensive !
Just as despair was beginning to set in, my colleague, Trevor Brownen ( sometimes referred to in our establishment as “The Boss“! ), had an inspiration, and the problem was solved within a few days. Briefly, the solution adopted makes use of the very flexible address decoding of the MZ-80K, so that the 4K blocks of memory 0000 – 0FFH and C000 – CFFFH ( the top 4K of RAM space ) could be interchanged by addressing one of the unused memory-mapped ports. The Monitor ROM and the RAM can be restored to their normal positions by addressing another port. Hence the machine can be operated with all SHARP BASIC software etc., as if no modification had been made. Of course, all of this means that the CBIOS ( Customised Basic I/I System, the part of the CP/M system which must be written by the implementor ) must also contain the necessary monitor routines for scanning the keyboard, driving the VDU, etc. This means that we actually have a 46K CP/M system, even though we have 48K RAM.
The hardware modification involves the removal of an IC on the main board of the MZ-80K replacing it with a socket, and then plugging in a PCB holding three IC’s ( size about 3 inches by 2 ). The author talks about IC47. Finally, two wires must be soldered to complete the task. ( SHARP ( UK ) Ltd. have kindly allowed this modification to be done without invalidating the guarantee so long as it is performed by a SHARP dealer ( but any user who is in doubt should contact his or her dealer ).
KEYBOARD AND CHARACTER SET
Another problem is in the character set employed on the MZ-80K. Although this uses standard ASCII codes for the numerals and upper-case letters, it jumbles up the codes for the lower-case letters. As a matter of fact, the character generator chips does not use ASCII at all, but a special set of display codes, which are generated by means of a look-up table in the Monitor. This problem was solved by writing a different look-up table in the CBIOS ( thus removing the need to re-program the character generator! ). Since the MZ-80 P3 printer also uses the incorrect ASCII codes, we have also made use of a table within the Monitor ROM, which converts display codes into the “SHARP ASCII“ codes. Hence, by applying these two look-up tables one after the other, we convert the standard ASCII code to drive the printer. This again removes the need to reprogram the character generator.
While doing all of this, we decided to take the opportunity to redefine the keyboard and VDU functions. In particular, the MZ-80K does not have a control key, whereas nearly all terminals do, and CP/M requires it. After a little thought, we redefined the “BREAK“ key as “CTRL“. The “SML/CAP“ key has been changed to allow a “toggle“ effect ( i.e., hit once to go to lower case, and again to go back to upper case ). Normally, we have to hit “shift-SML/CAP“ to go to lower case, but this combination is now redefined as an “ESCAPE“ ( another key used frequently in CP/M software ). Apart from these changes, the keyboard behaves exactly as shown on the keytops, and the graphics characters may be used in programs, if desired.
A full list of control-characters is shown at Table 1, together with their effects if printed from within programs. These are in addition to those used in the CP/M line editor ( e.g. CTRL-P turns the printer on and off when typed at the keyboard ). Note the convention of using “^”an abbreviation for “CTRL“.
List of control codes available under CP/M on MZ-80K
^F ( 06H )
^G ( 07H )
^H ( 08H )
^J ( 0AH )
^K ( 0BH )
CLR or ^L ( 0CH )
|Clear screen, or Form feed on printer.|
CR or ^M ( 0DH )
|Carriage Return without Line Feed.|
^N ( 0EH )
|Clear to end of line.|
^O ( 0FH )
|Clear to end of screen.|
^Q ( 11H )
|Line-to-line space reduction on printer.|
^R ( 12H )
|Double-size characters on printer.|
^X ( 18H )
|Cancel special rnodes on printer.|
HOME ( 1EH )
|Home cursor on screen, or Form-feed on printer.|
INST ( 1FH )
|Insert character into 40 character line.|
DEL ( 7FH )
|Delete character from 40 characters line.|
DISC ACCESS SPEED
A study of the disc operating routines in the SHARP DISC BASIC revealed that the software was much more geared to loading or saving many sectors at once, rather than with one sector at a time, as is required under CP/M. The operating system boots very quickly, since that part of the disc is never changed and can be loaded as one large block. With programs, however, a sector does not necessarily set next to the previous one read from or written to. Hence each sector must be read in separately and, since the gap between sectors is small compared with the time required to set up the floppy disc controller for the next sector, the disc has to spin for a complete revolution before the next sector is loaded – a 16 to 1 reduction in speed!
An appreciable increase in speed is achieved by means of INTERLACING, so that, for example, sector 2 of a track actually appears 5 sectors after sector 1. Although this is still not as fast as it COULD be, it is three times faster than it was, and this is roughly the improvement offered by Xtal CP/M over SHARP DISC BASIC.
Since each sector has an indentification mark for the controller, it is a simple matter to achieve interlacing by means of the FORMAT utility program. This program writes the sector identifications as the first stage of initialisation and we can define the order in which the sectors appear on the disc by means of a table within the program. In fact, we format the discs with 1 to 1 interlacing for the first five tracks ( those containing the operating system ), and 5 to 1 interlacing for the directory track and file tracks, thus getting both fast booting and reasonably fast file transfer.
In order to get the most flexibility in Input/Output facilities, the IOBYTE feature of CP/M has been implemented in full, and software included drive the MZ-80 P3 printer as the LPT: device ( the default LST: or listing device ), and up to two serial interface cards ( one of which is the TTY: device ). The Xtal Serial Card has been developed primarily for us with CP/M and is, as far as we know, the first bi-directional serial interface to be made available for the MZ-80K which may be plugged into the MZ-80I/O Interface Box. It offers link-selectable baud rates from 150 – 2400 baud ( adjustable from 110 – 9600 baud ) and is an RS232-compatible interface, meaning that it will interface nearly all standard terminals and serial printers. In particular, it is an absolute necessity for the transfer of software between the MZ-80K and another machine, and thus fulfills the fourth of our goals.
The cassette recorder may be operated by means of a progran on the CP/M disc called TAPE.COM. This allows us to load or save programs between disc and tape.
PROGRAMS ON DISC
All of the usual CP/M utilitles are supplied on the Master discette ( and it IS possible to copy it!! ), except for MOVCPM.COM, the program used for relocating CP/M systems for different RAM sizes. It was decided to work with just 48K, since memory prices are not much of a problem these days, and it also simplifies the effort of determining whether or not a particular item of software will work with this or that memory size !
In addition, the following programs are supplied on the disc:
|EXIT.COM||exits from CP/M right back to the SHARP Monitor.|
|MUSIC.COM||allows the user to type tunes into a file under ED, or one of the many CP/M text editors now available. By typing MUSIC <filename>, this text file is loaded and played as a tune, the format being very similar to that used in SHARP BASIC. An example tune is supplied on the disc.|
|TIME.COM||reads the real-time clock and displays the time. If a time is typed in as part of the command, that time is set as the current time.|
These two programs are included to illustrate the use of the extra BIOS routines for driving the clock and tone GENERATOR.
|AUTOGEN.COM||allows the user to generate a “turn-key“ disc, i.e. one which runs straight into a particular program that he / she may wish to run whenever the sytem boots. Although this can be done without AUTOGEN, it would require a knowledge of machine code and ASCII codes, so this program is a very useful one.|
The standard CP/M utilities supplied on disc are:
|DDT.COM||Dynamic Debugging Tool.|
|STAT.COM||Status of files / devices.|
|PIP.COM||Transfer files, etc.|
|SUBMIT.COM||Batch processing command.|
|XSUB.COM||Used with SUBMIT.|
Finally, having described some of the “workings” of the system, we come to that most important of subjects – what can we do with it all? The answer should be quite straightforward – all of the software that runs on a CP/M system of 46K or smaller will run very happily on the MZ-80K, and will only require modification to take account of the VDU size and printer width ( the MZ-80K VDU has 40 columns instead of the more usual 64 or 80 ). Even the Printer presents no great problem, since the Xtal Serial Card allows the use of many types of printer ( you COULD also use a terminal to replace the VDU for some software! )
Software transfer is best effected by means of the Serial Card since it is unlikely that the discs will load or dump discettes from a machine other than another MZ-80K. A few software houses in this country have already shown interest in moving their programs onto the MZ-80K, and we should welcome enquiries from anyone who has developed CP/M software.
For our own part, we shall soon be producing a CP/M version of the now highly popular Xtal BASIC 2.2 – primarily for the MZ-80K, but also for Z80 CP/M Systems in general. We already have the well-known CBASIC compiler adapted for the MZ-80K, and are obtaining licences for many other languages, including ALGOL, FORTRAN, PASCAL, C, and COBOL.
We feel that the exercise of putting CP/M onto the MZ-80K has been well worthwhile, and opens up the machine to many other uses.