MICRODRIVE UTILITY SYSTEM by JB Souter from Sinclair User, October 1984 EASY ACCESS Interface 1 and the microdrives have been criticized frequently as they are difficult to use. J B Souter shows how to make them flexible friends. THERE IS GOOD NEWS and bad news for Spectrum owners who have upgraded their micros by adding the Sinclair Interface 1 and microdrives. The good news is that several new powerful commands are available. The bad news is that syntax of those commands is both unfriendly and unwieldy. For example, it takes 22 keystrokes, not counting shift keys, to merge a BASIC program which has a 10 character filename. Although the Interface 1 contains an RS232 port to which a serial printer can be connected, the commands "COPY" and "LLIST" which do screen dump and listing to the ZX Printer either do not work or require additional commands first. In the case of "LLIST", a subroutine is required as follows: 9000 REM: list to printer subroutine, set baud rate first 9010 FORMAT "t" ; baud rate 9020 OPEN #3; "t" 9030 LLIST 9040 CLOSE #3 9050 RETURN That gets tedious after a while, so a better solution is needed. What is required is a set of utilities that can be loaded and accessed easily, which enhance the operating system provided by Sinclair and which can be customised by the user to suit their individual needs. The first requirement is easily met, since Sinclair provided the facility to save one auto-loading BASIC program on each Microdrive cartridge. That is done by saving the program with the name "run"; the file can then be loaded and run with one keystroke - simply press the RUN key - at power-on or after a complete reset - typing NEW or RANDOMIZE USR 0. The demonstration cartridge provided with the Microdrive by Sinclair utilises this technique. My own system grew as I either thought of new things to add, or became irritated with the long-winded syntax, or both. Loading, erasing, merging and producing a cartridge catalogue are the commands used most often and also the ones which require you to hop on and off the shift keys in a very unfriendly manner. So they were my first choice for a simple utilities system. A utility to load a program of any sort saves typing: LOAD *"m";1;"... your filename each time - ten keywords/characters, seven of which require the shift key. The utility is in lines 8000-8099 of Listing 1. A similar utility for erasing a file saves nine keywords/characters, and is given in lines 8700-8799. I will leave file merging until later as that has other implications. My first catalogue facility simply did a plain CAT 1, which can only display 22 filenames before the SCROLL? prompt appears and consequently a cartridge with many files cannot be catalogued on one screen. Printing a catalogue list requires a stream to be opened, as for the LLIST example given above. Lines 8200-8299 of Listing 1 give a routine which tries to present you with the best of both alternatives; either a simple printed list or a routine called "neat catalogue" from the book Master Your ZX Microdrive by Andrew Pennell. The "neat catalogue" routine formats the output on the screen into two filenames per line and adds titles to make it less cryptic. However, the machine-code element of the latter, stored in a microdrive cartridge file called "stream14z$", is missing, as Pennell retains the copyright of this. So you have two choices: either replace lines 8220-8290 by: 8220 CAT 1: PAUSE 0: GOTO origin or buy the book. You will have noticed several things about the listing which need explanation. A variable called "origin" has been used at the end of all the main menu option segments to redirect control to the main menu. That has been done for two reasons of which the most important is flexibility. The variable "origin" can be reset before calling the segment by a simple LET statement. The second reason is because I have used GOTOs rather than GOSUBs as some routines cannot be RETURNed gracefully. Note that the CLEAR statement at line 7005 will cause "origin" to lose its value, so always set it to 7010 rather than 7000. Another point of style concerns the routine at lines 9941-9949 which is used for choosing input options. The routine uses two parameters, "highest" and "lowest", which must be defined before calling the routine to ensure that only the required range of numeric keys can be used. All other keys, except BREAK, are inoperative, which should prevent unnecessary crashes and other odd things from happening. The third point is that a variable called "baud" is set in line 7120. That can be altered if your printer will accept a higher baud-rate than mine. Returning to the main-menu options, an early challenge after I bought the Interface 1 was to link it to my printer via the RS232 port. As my printer is a Tandy Lineprinter VII, that was not a simple task. I ended up experimenting with ways of producing a pixel by pixel screen dump. Lines 8300-8399 give a routine which should work with the Seikosha GP8O/GP100, the Epson MX8O/FX8O/RX8O and the ZX Printer. The Epson routine has been tested on an Epson FX8O. The Seikosha routine has not been tested, but as Seikosha makes the Tandy printer and it seems similar in operation, it should work. The ZX Printer version simply uses COPY. I make no apologies for the appallingly slow speed of the routines, but leave it as an exercise for the reader to produce a quicker version, probably by resorting to machine code. After a menu asking which printer you have, you will be asked which screen-file you wish to print. Since LINE INPUT has been used, simply pressing the RETURN key will produce a printed version of whatever is on the screen at the time. Otherwise you must give the name of a SCREEN$ type file stored on the cartridge and you will see from the listing that I use a convention here which I have incorporated into the program. As the catalogue of a cartridge does not distinguish between the various types of file - BASIC, CODE, DATA - I restrict screen file-names to seven letters and add SCREEN$ to the end of them. SCREEN$ is a token and therefore the suffix is only three characters long. I recommend that you do something similar as that has the additional advantage of performing some validation of the input filename. The remaining utilities are based on concepts borrowed from Basicode and in a very modest way the idea of programming support environments. The latter concept involves the surrounding of your developing program code with tried and trusted supporting utilities which can then be used either as sub-routines for the program or called directly by the programmer. Basicode is a system which enables software written in a subset of common Basics to be broadcast by radio by dedicating certain line numbers to tasks such as clearing the screen, which are handled in different ways by different systems. The Basicode will have lines like GOSUB 10; line 10 must then have the machine specific code - CLS on the Spectrum. What do these utilities offer? First, the ability to MERGE a Basic program with the auto-run utilities software - see lines 8100-8199. Once MERGEd, the program can be run with the support of the utilities, provided care is taken not to use line numbers greater than 7000, where the utilities are. Then, if a screen dump is required, that can be done by calling the utility in lines 8300-8399; return is achieved by setting the value of the variable "origin" to the following line number in your code. For example: 440 ... your program code ... 450 LET origin=460: LET choice=2: GOTO 8340: REM screen dump 460 ... your program code continues ... Note that the variable "choice", indicating the second printer option from the menu given in lines 9921-9929 - that is, the Epson - must be set first and the alternative entry point at line 8340 used to prevent your desired screen being replaced by a menu. Listing to the printer is also available - see lines 8400-8499 - although I know of only a crude way to stop that before the utilities section is printed - press the SHIFT and BREAK keys. Do not worry about restarting gracefully, because all the routines close the appropriate stream before opening it, thus preventing a "stream already open" error. Note that the routine opens stream 4 to channel "t"; all other printer routines use stream 3 so that LPRINT can be used instead of PRINT #3;. Finally, a simple but invaluable machine code utility was published in the November 83 issue of Sinclair User to block delete BASIC program lines. I have modified that slightly (lines 8600-8699) but I acknowledge David Maxwell as original author. The inclusion of that makes up for a glaring omission in the Spectrum interpreter/editor and of course enables you to delete the utilities from around your BASIC program if you do not need them. The routine asks you to input the start and end line numbers and then deletes those two lines and all lines between. An error will result if you use the routine to delete itself, but it does not crash the system so other program code is preserved. I encourage you to extend the principle to your own individual uses; some possible improvements have already been indicated. Others that I have thought about for the future are: 1 - use LIST to a stream, where the stream has been opened to the microdrive channel; the resulting file is then in data format and can be searched for keywords or variable names - when you are debugging, for example; 2 - set up a screen menu of commonly used programs on the cartridge, so that programs can be run by two key presses, one to auto-load the utilities and one to select the program; 3 - add a line renumbering facility; and 4 - use MOVE to produce printed listings of any BASIC program stored on a microdrive cartridge.