SIMON N GOODWIN tests Pascal and Fortran 77S compilers from Mira Software, takes a first look at Romantic Robot’s +3 Multiface, and controls that model train — finally
FORTRAN, one of the world’s first computer languages, now runs on the 48K Spectrum, thanks to Mira Software; this small Leicestershire firm has also released a British Standard version of the Pascal language. Fortran and Pascal are widely used in colleges by engineering and computing students and, as a new academic year gets under way, it seems a good time to check out these compilers.
Compilers take programs written in a form that humans can understand and translate them into machine code, the simple, fast language of the processor chip inside the computer.
As any hacker knows, the best way to learn about computing is to get lots of hands-on experience, but students often end up queueing for a small ration of time on overworked mainframes.
So even a Spectrum can help a lot if the right software is available. A few years ago I found it worthwhile to do most of my computing degree coursework on my humble Video Genie — a 48K machine with half the processing power of the Spectrum. For too long the mystique of the mainframe has led people to believe that you can’t run serious languages on a small micro.
Consider the number of students and programming enthusiasts with Spectrums — Mira Software could be on to a winner if their compilers are up to scratch. After all, Turbo Pascal, for bigger micros, has sold half a million copies. Mira Fortran is unique on the Spectrum, and Hi Soft’s ageing Pascal 4T is the only competitor of Mira Pascal.
30 years ago Fortran was a breakthrough, the first programming language that looked anything like English. It was developed to run on an early mainframe — an IBM 704 — and some of the peculiarities of that machine have been enshrined in the language ever since.
Hundreds of better languages followed Fortran, but it built up a following and went through several versions — like the Spectrum 128, but more slowly. Even BASIC was first developed in an attempt to make it easier to teach Fortran. The name stands for FORmula TRANslation.
IBM pitched the language at mathematicians and engineers. Nowadays Fortran is outdated, but it is used in so many standard routines that advanced engineering courses usually include Fortran programming.
Mira Fortran is based on Fortran 77S, a small version of the current standard. Mira Fortran can also compile many programs written using older standards such as Fortran 66 and Fortran IV.
15 quid buys you a 16-page dot-matrix-printed instruction manual, and a cassette containing two copies of the compiler and three demonstration programs.
The A5 manual is too short to do justice to the program. It covers the difference between Mira Fortran and Fortran 77 at breakneck pace, throwing in a few useful hints and tips, and you have to read it several times before you’re really sure what’s going on. If you’re new to Fortran you’ll need a good tutorial; Roger Kaufman’s Fortran Coloring Book, ISBN 0-262-61026-4, is my favourite.
When Fortran was invented, programs were not typed directly into the system but read from cards punched with holes to require a punched-card-reader — indicate the required commands. At least Mira Fortran doesn’t but, like all Fortran systems, it still expects you to enter your program as if it were on a card, strictly laid out in columns.
There are three types of line in a Fortran program. Comment lines (like REMs in BASIC) start with a C or a *. Debug lines start with D. They are used during testing and you can tell the compiler to ignore them, for a finished program, or compile them, for a test run. Thus you can keep test routines in your program text, and choose whether or not to include them just before you compile.
Anything else is a normal program line. The first five characters must be spaces or digits. You can put a line number here if you like, as in a BASIC program, but lines don’t have to have numbers — and the numbers don’t have to be in the correct order, though obviously it helps if they are!
The sixth character on a program line is usually blank, but a + sign indicates that the line is a continuation of the previous line. Mira Fortran is unusually fussy in that anything else gives an error.
Individual Fortran lines have a fixed maximum length of 80 characters, and you can only put one statement on a line. Many Fortran compilers ignore the last eight characters, treating them as a comment, but Mira’s program compiles the entire line. Programs must be on capital letters, apart from comments and messages. Spaces are ignored.
The Mira Fortran editor loads from tape in about 90 seconds, and works much like the ZX BASIC editor. You type in lines character by character at the bottom of the 32-column screen; earlier entries are displayed at the top. Long lines wrap around at the edge of the display. You can move left and right on the usual way to correct mistakes in the line you’re working on.
When you press ENTER the syntax of the line is checked. If all is well Mira Fortran asks for the next line; otherwise you must correct the mistake at the place shown before you can continue.
You stop entering lines by pressing the ↓ key. This gives you access to a set of single-letter commands to edit lines or scan up and down the program, line by line or in eight-line steps — much as in BASIC. Fortran text can be loaded, merged and saved on cassette. The H key calls up a list of commands.
You can list the file to stream 3, usually a ZX printer or Centronics interface, but you must print the whole lot. There’s a block delete command to get rid of several lines, but no way to copy a block without deleting the original. This editor is rather rudimentary, but few people will prefer a card punch.
Mira Fortran recognises most of Fortran 77; the biggest restriction is probably the absence of COMPLEX and DOUBLE data types. Decimal values use the Spectrum’s default precision of about nine digits, and integers are limited to the range -32768 to +32767. Logical (true or false) values are packed into single bits to save space.
Memory permitting, you can declare arrays of any number of dimensions. Variable space can be shared, using COMMON and EQUIVALENCE. DATA statements let you preset variable values.
Maths functions include logarithms, type conversions, trigonometric and hyperbolic functions, things like MOD (to find the remainder after division) and a job lot of MIN and MAX functions to pick out the biggest or smallest of several values.
All the usual numerical comparisons and logical operators are allowed, but Mira Fortran lacks routines to handle characters — you can’t slice strings or stick them together.
Program control facilities are very rudimentary. The DO loop is similar to FOR..NEXT in ZX BASIC, and there are three kinds of IF test, including Fortran 77’s multiline IF..THEN..ELSE.
Functions and subroutines can be defined and called with any type of parameter. Built-in subroutines mimic BASIC’s ARC, BEEP, CIRCLE, DRAW and PLOT commands, but you must write your own POINT function if you need it. The only way to control attributes like INK, PAPER, OVER and so on is to print the appropriate control codes; this isn’t mentioned in the manual.
For a long time Fortran led the way in its range of output-formatting facilities, and Mira Fortran reflects this. The syntax is horrible, but that’s Fortran; however, the facilities are pretty good, and there’s a nonstandard PRINT command which you can use if you don’t want to bother with the bells and whistles of Fortran’s WRITE. Mira Fortran imposes some minor restrictions on FORMAT statements, but all but the most obscure programs should compile without trouble.
You can’t use cassette data files, but you can read and write disk and microdrive files from a Fortran program. The trick is to open the files from BASIC, and then use the appropriate stream number from inside the Fortran program. You can read or write files from the start, but you can’t use random access to move back and forth.
END can be used to check for the end of a file in a READ statement, but the check has an unusual syntax and only works on files which are read a line at a time.
When your program is complete the X key starts the compiler. Before it generates machine code, Mira Fortran scans the whole program at a rate of about 16 lines a second, looking for mistakes that could not be spotted on a line-by-line basis, such as missing ENDs or mistyped names. If a mistake is found one of 15 rather general error messages appears: for instance, an absent END produces the unhelpful message ‘Wrong statement order’.
When an error has been found the appropriate line is marked with a flashing question mark and you are thrown back into the editor. When all the errors have been fixed the computer beeps and the screen shows a mess of dots and lines. This appears because the compiler uses screen memory to hold details of the names in the program. In this way, the size of program you can compile is increased.
The next step is to load the second part of the system, which actually performs the machine-code translation. The translator takes a minute to load, and then it scans through the program at about 30 lines a second, generating machine code. When it has finished it displays a list of numbers: the code address, length, place to CLEAR before running and, for no apparent reason, the address of the program’s COMMON storage area.
As soon as you press a key — by accident or deliberately — the information vanishes and the machine resets, leaving the code at the top of memory.
This two-step approach allows you to compile programs of several hundred lines on a small machine, but it makes Mira Fortran a drag to use; you must reload the editor and translator every time you compile a program. This is not too bad if you’ve got a disk or microdrive, especially if you save the program and editor together with a ‘magic button’ utility, but it is very frustrating on a cassette system.
Compiled Fortran runs without the compiler loaded. You start programs with RAND USR 63500. They are always at least 5K long, because they load a library of utility routines at the top of memory. The code is not particularly concise — the programs I tried used about 50 bytes per line.
Integer arithmetic proved to be fast — between 30 and 100 times quicker than BASIC and similar in speed to Mcoder and Softek’s IS integer BASIC compilers. You can only break into compiled Fortran when SCROLL? is displayed.
Floating-point number-crunching was not very fast. One demonstration routine searched for prime numbers, digging them out at a rate of about two a second. The method proved to be very inefficient, but the compiled code was only about twice as fast as equivalent ZX BASIC, or a fifth quicker than BASIC compiled with Mcoder 3.
Mira Fortran can’t always detect errors in FORMAT statements. One incorrect program compiled without a squeak, but locked up the machine when I ran it. And it took a while to fix, because there was no hint of the position of the error. In the end I kept loading and recompiling the program with extra PRINT statements till I zeroed in on the fault.
Mira has produced a real Fortran compiler for the Spectrum. Unfortunately Mira Fortran is not particularly friendly. It lacks some of the features you’d expect on a larger system — like a run-time debugger and linker — but it is still a useful package for compiling fairly small, independent Fortran programs.
Mira Pascal has many of the features of Mira Fortran and it too costs £15, but it has been produced more recently and has fewer rough edges. It’s a complete, modern version of Pascal. Mira Software says that the microdrive version complies with Level 1 of British Standard 6192.
Like the Fortran compiler, Mira Pascal is supplied on cassette. The A4 instruction manual is only 12 pages long but it is better organised and easier to use then the Fortran manual. If you already know the standard and can puzzle out the rather technical error reports you should not need any other information; otherwise you’ll need a tutorial. The manual recommends a book that deals specifically with British Standard 6192.
The tape has three different versions of the compiler. The cassette version allows about 22K of memory for program text; the microdrive version is a little larger, and both leave about 1800 bytes unused at the top of memory in case you need to load a printer driver there. Then there’s a condensed tape version which allows an extra 3K of program. It loads at the very top of memory, has no help page and uses numbers rather than text to report errors.
Pascal is a very different language from Fortran. It was invented in the late Sixties by a Swiss computing professor, Niklaus Wirth (and named after the 17th-century French mathematician Blaise Pascal); it was designed both to be easy to compile and to learn, and to encourage systematic — structured — programming. This is a style of coding that makes programs easy to read and to modify.
There are usually two stages in the development of a program. First you make it up; then you make it work. Pascal forces you to think before you start coding: it reduces the amount of time you spend debugging, because to use Pascal effectively you have to make plans first.
This is good discipline for professional programmers, because it is almost impossible to write big programs that work unless you plan them carefully from the start. Pascal has a bad name with some hackers because it’s not suitable for bodging small programs together quickly.
Mira Pascal uses an editor similar to the one supplied with the Fortran compiler with all its commands and more besides. Now you can move directly to the start or end of the text, duplicate blocks as well as move them, and load and save files on microdrive as well as on cassette. (The manual tells you to use key S to save to microdrive, but it should say D.)
You can compile text files created by a word-processing system such as Tasword 3, but, sadly, you can’t load Pascal files into the word processor.
All the usual features of Pascal are included: Mira Pascal works with characters, Boolean (true or false) values, integers +/-32767, nine-digit floating-point numbers and subranges, packed into single bytes when possible.
Data structures are the strong point of Pascal, and Mira Pascal works with conformant arrays, variant records, pointers and sets of any size. DISPOSE can only reclaim the space used by the most recent dynamic variable allocated, so programs that make heavy use of pointers may run out of memory after a while.
Besides standard functions and procedures Mira Pascal supports BEEP and the drawing commands and maths functions of ZX BASIC. USR lets you call machine code but does not return a value. Once again POINT is missing, and INK and OVER must be set by printing control codes.
Characters do not appear by default on the screen when they are read from the keyboard. If you want to be able to see and edit your input you must call the procedure EDITOR before using READ or READLN. (This worked well for me except when I typed a blank line — then subsequent input was invisible!)
Mira Pascal can use files opened from BASIC, as can Mira Fortran. It also supports temporary files which automatically disappear when you leave the block of code that created them. Unlike Mira Fortran, the Pascal compiler lets you RESET and REWRITE files, and check EOF as normal.
The microdrive version of Mira Pascal automatically saves your program when you start the compiler and reloads it when you run the editor. Apart from this, the compiler works in two steps, like Mira Fortran. It displays one number after a compilation — the address to CLEAR — just before the compiled code. This number is also printed out, if you have a printer connected.
When I tested the compiler, the speed and size of Mira Pascal code proved to be similar to that of Mira Fortran. Integer handling was again impressive, but floating-point maths was only two or three times faster than ZX BASIC. The compiler worked very quickly, each step processing between 20 and 30 lines per second.
Mira Pascal comes with three demonstration programs. The first searches for all the prime numbers between 1 and 32767, using a sieve method much more efficient than the corresponding Fortran demo. It took 40 seconds to run, and I was able to reduce that to 15 seconds by making minor changes to the listing.
The second demo computes and displays three-dimensional graphs, clipped to fit a box on the screen. It worked quickly and well.
Last on the tape is a well-written spelling-checker. This comes with a dictionary of just 800 words, expandable to 2,000, but it is a fine illustration of the way Mira Pascal can be used to develop sophisticated programs.
I like Mira Pascal — it is a valuable addition to the Spectrum programmer’s armoury, especially if your microdrives are in working order! It should give Hi Soft Pascal some serious competition.
THE FUTURE of the Spectrum +3 Is looking brighter now that Romantic Robot has produced the Multiface Three, with which you can transfer cassette programs for the Spectrum+ and 128 onto disk.
The £44.95 Multiface Three is, in effect, a set of utility programs that you can run any time without disturbing loaded programs. The standard program (in ROM) lets you save screens — or the entire program memory — to disk or tape.
You can also type in POKEs to change the operation of games.
And a Multiface contains RAM as well as ROM, so you can load all sorts of utilities into the space — the Gamester infinite-lives trick reviewed in Issue 41, for instance, or Genie, a friendly machine-code disassembler.
These utilities are the first in a growing market which is increasing the flexibility of the ‘custom’ Spectrum. Like IBM PC users, Spectrum-owners are learning the value of a sidekick.
The Multiface Three also includes two new routines to print screens at any time through the +3’s printer port.
To make space for new files, you can suspend programs and format a disk at any time, or look through the disk directory and erase unwanted flies. Disk files are usually saved in a compressed form and automatically expanded upon reloading, which should help the Multiface Three fit more than one game on a disk. (Each Amstrad disk holds just 173K, but most current 128 games leave lots of memory unused.)
Packing the entire memory into a single code file also helps the Multitace Three save room on the disk and increase loading speed.
Romantic Robot has done Amstrad a big favour by producing an add-on that makes the +3 worth considering. But even if the +3 comes down to £199, with the Multiface Three at £45 you’d be well-advised to check out other disk systems with ‘magic buttons’, such as the Swift Disc (reviewed here last month) and the Disciple (which Franco Frey reviewed in issue 38).
And there are a few problems lurking: the Multiface Three may not operate with software produced specifically for the +3, for instance. Still, the prototype I tested works pretty well — and there’ll be a more detailed report soon.
ADAM SHEPPARD wants to know if it’s possible to control a model train from a Spectrum. It is — but it’s not easy, and you’ll need a good knowledge of programming and digital electronics.
First, you must find an input/output port for the Spectrum. A Centronics parallel printer prirt might be good enough, if you can discover the port addresses and wiring assignments — otherwise you’ll need a purpose-designed interface for experimenters.
Maplin has a Spectrum I/O Controller on page 264 of its current catalogue. You’ll also need the parallel-port kit on the same page. so the whole lot will cost £35–40. Electronic And Computer Workshop sells a similar system. I haven’t used either product, so I can’t vouch for them.
You could design and build your own controller for about £10, but you’d need to know all about digital electronics and Z80 addressing. If you don’t know roughly how to do this already I’d advise you not to try unless you can find someone more knowledgeable to help you.
A controller just lets you set and test digital signals outside the computer. You must write appropriate software, and build extra electronics to interface the controller to sensors and power controls for the railway. Babini has just published a slim £2.95 paperback of suitable circuits, together with a clear and sensible discussion of the problems involved. Electronic Circuits For The Control of Model Railways, ISBN 0-85934-154-2, is written by the prolific R A Penfold. The book assumes you’re wiring things up to the user port of a BBC Micro, but a Spectrum port works in much the same way.