0% found this document useful (0 votes)
97 views

Using CPM

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views

Using CPM

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 129

Using CP/M

Peter Gosling

M
MACMILLAN
© Peter Gosling 1985

All rights reserved. No reproduction, copy or transmission


of this publication may be made without written permission.
No paragraph of this publication may be reproduced, copied
or transmitted save with written permission or in accordance
with the provisions of the Copyright Act 1956 (as amended).
Any person who does any unauthorised act in relation to
this publication may be liable to criminal prosecution and
civil claims for damages.

First published 1985

Published by
MACMILLAN EDUCATION LTD
Houndmills, Basingstoke, Hampshire RG 21 2XS
and London
Companies and representatives
throughout the world

British Library Cataloguing in Publication Data


Gosling, Peter
Using CP/M .
1 . CP/M (Computer operating system)
2. Microcomputers
I. Title
001.64'25 QA76.6

ISBN 978-0-333-38403-9 ISBN 978-1-349-07676-5 (eBook)


DOI 10.1007/978-1-349-07676-5
Contents

Preface iv

1 What is CP/M? 1

2 Formatting a New Disk 5

3 CP/M Resident Commands 9

4 PIP, the Peripheral Interchange Program 14

5 The STAT Command 21

6 ED, the CP/M Line Editor 29

7 using MBASIC 42

8 Using a Compiler 58

9 ASM, the CP/M Assembler and DDT 69

10 CP/M Plus (CP/M Version 3.1) 86

11 CP/M-86 102

12 MP/M 107

13 Concurrent CP/M 111

14 CP/NET 114

Appendix A: ASCII Character Codes 119

Appendix B: CP/M Console Editing Commands 120

Appendix C: CP/M Packages 121

Index 123
Preface

This book i s int end ed t o gi v e n ew com e rs to th e CP/ M


operating s ystem an insight into its ca pabiliti es and
method of use. So many microcomputers now us e this
operating s ystem that ther e i s a ne ed for a simpl e ye t
comprehensi ve guide to the man y commands and functions
off ered. Manuals suppli ed with computer s yst ems ar e
notoriously difficult to follow ev e n by the spe cialist,
l et alon e th e n ewcomer . Th is book a i ms at being as
general and non-specific as possibl e, since ther e are
man y microcomputers on the market that consist of
e x t r a s added onto the main cor e of CP/M. It is to co v er
this common cor e that this book has be en wr i t t e n .
The author would like to thank in particular Digital
Research (UK) Ltd for a mass of v e ry useful information
and permission to reproduce certain diagrams in th e
text. Help was also ver y grat efully r eceiv ed from
Mid I and Micro Serv ices and Burgh I e y Comput ers of
Stamford, and Stamford College for Further Education.
The addresses of Digital Research and the CP/M Users
Group for the UK are given in Appendix C.

PETER GOSLING

CP /M and CP /NET are registered trademarks of Digital


Research . CP/NOS, MP /M II and CP/M Plus are trademarks
of Digital Research .

Zilog and ZaD are trademarks of ZILOG Inc.


1 What IS CP/M?

CP/M stands for "Control Program for Microcomputers",


or "Control Program and Monitor"; no-one now seems
quite certain exactly which of these is correct. It is
an operating system for the range of microcomputers
that have a Zilog Z80 - or look-alike - microchip as
their central processor.
The first CP/M operating system saw the light of day
in the early 1970s and was written by Dr Gary Kildall
who was one of the scientists behind the early
development of software for the Intel 8080
microprocessor.
As a multiplicity of disk drives (all of different
sizes and recording formats) came onto the market, it
rapidly became apparent that there was going to be no
future in designing a different operating system for
each set of peripherals attached to the computer. This
gave rise to the concept that gives CP /M its great
f 1 exibi 1 i ty and portabi 1 i ty. The operating system
consists of three parts. These are called the BIOS, the
Basic Input and Output System, the BOOS, the Basic Disk
Operating System and the CCP which is the Console
Command Processor.
The BIOS is the only part of CP/M that is dependent
on the hardware. It is the non-proprietary part of the
operating system and can be modified by a microcomputer
manufacturer in order to cope with his particular
arrangement of disk drives, console VDU and printers. A
source listing of BIOS code is available from Digital
Research Inc.
The BOOS is a fixed, invariant and proprietary piece
of software which control s all the disk dri ves. It is
quite independent of the hardware being used.
The CCP is the software, also invariant and
proprietary, which translates the commands issued by
the user at the console keyboard into code ready for
the microprocessor to execute.
When CP /M is loaded into memory it is stored in
2 Using CP/M

segments with the BIOS at the highest p a r t of memor y,


the BOOS just below it and the CCP b elow that. The bulk
of the remainder of memor y is left for use by programs
and is called the TPA, the Transient Program Area . This
is the extent of memor y that is addressable by a
running program. Th e amount of memor y used up b y the
BIOS depends on the hardwar e con figuration and
typically would be around 3K bytes . BOOS , which is
always of c onstant size, occu pies 3.5K bytes. This is
because , whatever the disk format in use, CP /M always
handles disk reading and writing in 128 byte blocks on
up to sixteen disk drives . The actual phys ical transfer
o f da ta between disk and RAM is dealt with by the BIOS .

High Memory

BIOS
(up to 3K by tes)

BOOS
(3.5K bytes)

CCP
(2K bytes)

Tra ns i e n t
Pr ogram
Area

OlO OH

256 bytes re served


OOOOH
Low Memory
What is CP/M? 3

Below the BIOS and BOOS lies the CCP and the TPA,
and right at the bottom of memory is a 256 byte block
holding the system parameters. It is through these that
the program being run communicates with the resident
CP/M utilities. This means that when a disk write
operation is initiated by your program the actual
writing is handed over to the BOOS and then to the BIOS
to execute the transfer of data. Incidentally, since
256 in hexadecimal is 100 this is the lowest address in
the TPA and is the starting address of many programs. A
typical memory map for CP/M is shown.
Part of CP/M, as can be seen from the memory map, is
always "resident" in memory . There are other
"transient" parts of the operating system which are
loaded f rom disk as required. These commands are
described in chapter 3.
When you switch on your microcomputer, the first
operation is to load CP/M into memory. This is called
"bootstrapping" or the system "booting" for short.
Sometimes this is initiated by pressing certain keys on
the console keyboard, sometimes i t happens
automatically as soon as the system disk is inserted
and the drive door is closed. You can tell when the
loading is complete when some sort of "commercial"
appears on the screen followed by the familiar CP/M

A>

prompt. This tells us that the CCP is in operation and


that it is ready to respond to a command line.
If for some reason you need to restart your CP/M
system after having switched on the system, you can
perform a so-called "warm boot" . This is often
necessary after an error has occurred and this error
has been indicated by one of CP/M's notorious error
messages. A warm boot is usually effected by pressing
CONTROL-C (that is, the CONTROL and C keys) What this
does is to reload the BOOS and CCP into memory and
place the computer into command mode.
A common CP/M error message is

Orive=nn,Track=nn,Sector=nn:Error=nn
Bdos error on X:bad sector

which indicates a hardware prob 1 em of some sort.


CONTROL-C will reboot the system and you can try again.
4 Using CP/M

If you press RETURN, th e error is ignor ed and y o u are


returned to the CCP. Th e dri ve number, track number,
sector number and e r r o r code are all in hexadecimal .
All the error codes prefixed uy a 1 indicate that a
sector cannot be found . Codes prefixed b y a 2 indicate
that a sector cannot be read. A 3 prefix tells us that
there is an error in verifying what is on the sector.
Finally a code prefixed with a 4 indicates a formatting
error.
Another i s

Bdos err on X:R /O

which tells us that the drive spec ified i s designated


read /only. Again CONTROL-C will return you to th e CCP.
2 Formatting a New Disk

Before using any new disks on a CP/M system, or any


computer system for that matter, these disks have to be
"formatted". Formatting disks is the operation of
preparing them to have data recorded on them and it is
very similar to the operation of ruling lines to
provide blank columns in a ledger. Because every
computer system seems to have a different way of laying
out its disks, they cannot be supplied ready formatted
by the manufacturers. It is perhaps worth while at this
stage, before going into how disks are formatted, to
describe the layout of the disks used by typical
microcomputer systems. At present there are three kinds
of disk storage available: these are on 5-1 /4 inch
diameter floppy disks, 8 inch diameter floppy disks and
the so-called "Winchester" or hard disks.
Each of the disk systems stores data magnetically on
a series of concentric tracks. The smallest disks can
store data on one or both sides and on either 40 or 80
tracks. The larger floppy disks can also be single or
double sided and usually store their data on 77
concentric tracks . To add to the confusion, the data
storage can be either at double or single density; this
refers to the amount of data that can be packed into
each track and is decided by the disk manufacturer. In
other words it is a measure of the "magnetisability" of
the magnetic substance that coats the plastic base of
which the disk is made. The Winchester drives consist
of more than one aluminium disk, coated with magnetic
material, mounted on a common spindle and hermetically
sealed into a box.
Each track of a disk is made up of a series of
"sectors" which can store a specified number of bytes,
or characters . In some cases the number of bytes per
sector and indeed the number of sectors per track can
be determined by the user although in general they are
decided by the manufacturer of the computer system. If

5
6 Using CP/M

the number of sectors per track can be decided prior to


formatting, then th e disks ar e said to be "soft-
sectored". Such disks can be identifi ed by the fact
that there is only one hole punched in the disk just
outside the centre h o l e . A strobing 1 ight shining
through this hole ensures that the disk rotat es at
constant speed. Manufacturers can suppl y " h a r d -
sectored" disks for certain disk dri v es and these have
a number of holes punched in the disk around the centre
hole. Hard-sectored disks and soft-sectored disks are
not interchangeable. On th e smaller flopp y disks a
typical format might be 80 tracks on each sid e with
each track divided into five sectors. Each sector holds
1024 bytes (lK in computer language) and so e a c h disk
can store 5 x 80 x 2 x lK bytes = 800K b ytes. Another
disk on another system might be single-sided with 80
tracks each of 64 sectors and with a total capacity of
574K bytes.
A further complication is that some computer systems
using double-sided disks can read both sides of the
disk at once, having saved data in what are called
"cylinders" in the same way that mainfram e and mini-
comput ers organise their disks. This means that, in
simple terms half of each byte is stored on one surface
and the oth er half on the bottom sur face. This
considerably reduces the access time of data on the
disk. Winchester disks on microcomputers store their
data this way. Some floppy disk systems, however, can
have each side of a disk treated as a different drive
so that a two disk system can have four "logical"
drives , named A,B,C and 0, each of which have to be
formatted separately. "Drives" A and C are on one disk
and "drives" Band 0 on the other.
Recently, a magazine produced a l i s t of
microcomputers using CP/M; this list contained some 130
different machines. It is more than likely that only a
very few of these use a disk format that allows a disk
created on one machine to be read by another. This
causes a succession of problems on compatibility, as
can well be imagined.
The action of formatting a disk to work on any
particular system is therefore that of setting up the
appropriate number of tracks and sectors per track so
that it is ready to receive the data to be recorded .
Every CP/M system has a format program which is
invoked by simply typing the instruction
Formatting a New Disk 7

A>FORMAT

The usual response is a dialogue that asks you which


drive you wish to format; for example

Diskette FORMAT Utilit y - Version 2.7


Format drive? (A or B; press r eturn key to end)
Format drive B. Press space bar when ready
Format drive B
Format drive B complete
Format drive ? (A or B; press return key to end)
A>

This sequence gives you the opportunity to place a


clean unformatted disk in drive B before the formatting
process takes place. If you were to put a disk into
dr ive B that already had data recorded on it, then the
action of formatting would destroy whatever was there.
Hence if you had only one drive, drive A, then you must
remove the disk with the formatting program on it
(FORMAT.COM or FORMAT.CMD) and replace it with a fresh
disk before allowing formatting to proceed.
At this point you have a disk that is ready to
receive any files that you may wish to have stored on
it. However, it is but a "slave" disk; it should always
be in drive B with a CP /M system disk in drive A, since
any CP /M uti 1 i ties you may wish to use must come from a
disk that is in the main drive - unless you transfer
the master drive privilege to dri ve B by typing

A>B:
B>

However, if you switch off and attempt to start the


system (boot it up), it is always drive A that must
contain the CP/M system. In other words, if you want to
make a new system disk you must perform an operation
that transfers the CP/M programs and utilities not just
to the new disk but to specific tracks on the new disk.
This is performed by a utility known as COPYSYS in CP /M
systems of Version 2.2 and beyond and SYSGEN in up to
Version 2.2. For the version of CP /M-86 suppl ied wi th
the ACT Sirius, the equivalent command is called
BOOTCOPY. Whatever the name of the utility, the effect
is the same in that it copies the CP /M system onto
8 Using CP/M

specific tracks of the disk s o th at if th e n ew disk is


now loaded into dri ve A and th e s ystem "reboot ed", CP/M
will start automatically . COPYSYS, SYSGEN and BOOTCOPY
can all be placed on a disk without aff ect ing an y fil es
alr eady stored on it.
For CP/M systems prior to Ve r s i o n 2.2, there is also
a MOVCPM utility; this allows you to relocate CP/M in
memory, depending on the amount of memory available in
y o u r particular s ystem. Ju st how it works is outside
the scope of this book; suffice it to sa y that it is
used prior to the use of SYSGEN in ord er to relocat e
CP/M to take advantag e of the amount of memor y actuall y
available. For exampl e if y o u have a v e r s i o n of the
operating system that works in 32K and your machine has
64K of RAM, then the first thing to do is to mo ve the
existing CP/M to take advantage of the extra memory by
typing

A>MOVCPM64 (RET)

Then you can SYSGEN and sa ve the new op erating


system.
When you use one of the utilities to copy th e
operating system onto another disk, the dialogue looks
something like

A>COPYSYS
Source drive name (or RETURN for default drive) (RET)
Source on A then type RETURN (RET)
Function complete (This tells us that CP/M
has been loaded into
memory)
Destination drive (RETURN to reboot) B
(This a llows you
to change your mind and
abandon the operation)
Destination on B then type RETURN (RET)
Function complete

The sequence, therefore, is to format a new disk for


your system; once having formatted it, a copy of the
CP /M system is placed on what are called the "system
tracks" so that the new disk will be capable of acting
as a master disk. This does not mean that the utilities
such as PIP, STAT, ASM and others will have been
copied. They have to be copied onto the new disk using
PIP.
3 CP/M Resident Commands

Apart from the CP /M commands that e x i s t on th eir own


and are identified by their names followed b y the .COM
or the .CMO ext ension, ther e are several that form a
part o f the built -in CP/M util ities. Thes e command s are
OI R, ERA , REN and TYPE.

The DIR command


An index to a l l the files sa ved on a disk is stored in
a director y on the sp ecial system tracks of a disk.
This directory stores the name of each file together
with the important parameters relating to the file: its
start address and length. If the command

A>OIR

is issued, then all the file names in the directory are


listed on the console VOU; fo r example

A>OI R
A:PIP COM:MBASIC COM: STAT COM:PROGl BAS:PROG2 BAS
A:WS COM:WSMSGS OVR:WSOVLYl OVR:TEXT TXT:TEXT BAK
A>

If we wished we could verify the existence of a


particular file by t yping

A>OIR WS.COM

If the f i 1 e were present on tha t disk then its name


would be displayed. If it were not then the NO FILE
message would be seen.
CP /M filenames can contain up to eight characters
but must not contain any of the following

0 . ,: ;=/*[ 1

9
10 Using CP/M

A fil ename can be e n te red in e i t he r u p pe r o r lower


case; CP/M automat icall y stores all fi lenames i n up pe r
case.
Fil enames can be pref ixed b y the dr i ve name f o l l owe d
b y a colon (:) so that th e fil es A : F I L E .D AT and
B:FILE.DAT are two diff erent fil e s , one held on d ri ve A
and the other on dr i v e B.
So-called "wild-card" c ha r a c te r s can be incl ud ed in
f il e names when DIR and c ertai n oth er commands are
used. This enabl es us to r ef er to a s et of fi le s in a
gen eral wa y. For e x a mp le , to obtain a l ist o f th e files
whos e names ha v e c ertain common featur es, sa y, all the
BASIC files, we could t y p e

A>DIR *.BAS

and receive a list of all the files on that disk with


the .BAS extens ion.
A second "wild-ca rd" character is th e "?"; and this
is used to stand f o r "an y character, or no character at
all in this pos ition" . Th e "*" sign p a d s out a l l th e
spac es after it wi t h "?" characters a n d so we cannot
use it as a prefix. For e xa mp le , we could t y pe

A>DIR CPM??? *

and get a list o f a ll th e f i l e s on th e mast e r dri v e


that start with the l ett ers "CPM" and h a v e a possibl e
extension;

A: CP MCOM :CPMCOM BAK:CPM 31 :CPM31 BAK :CPMASM

but we could not t ype

A>DIR * 31.*

In order to list all those files with the digits 31


at the end, we would need to type

A>DIR ??????31.*

For a 1 ist of a 11 the f i 1 es on a disk other than the


one in the default dri ve, all that is needed is the
drive name

A>DIR B:
CP/M Resident Commands 11

which will give a list of all the files on drive B.


In Version 3 .1 of CP/M the capabilities of OIR have
been considerably extended, and in that version of the
operating system DIR is now a command in its own right
(se e chapter 10) .

The ERA command


The ERA command will erase (that is, d elete) a file
from a disk. To be strictly accurate, the file itself
is not d elet ed, only its entry in the directory. This
means that a "deleted" file can be revived if you ha ve
the programming capability to restore the entry in the
director y. That is always provided that the file has
not b een ov erwritten by another fil e . When a file is
erased, its entry in the directory is deleted and the
space that was occupied by that file on the disk is
left free to be overwritten by another file or part of
another file . To erase a file, type ERA followed by the
filename, which must be complete and with the extension
if there is one

A>ERA PROG1.BAS

If, by any chance, the specified file does not exist


on the disk then the NO FILE message is displayed.
In order to delete groups of files at one fell
swoop, "wild-card" characters can be used aga in; for
instance

A>ERA *.BAS

will cause all the files with the . BAS extension to be


deleted. In fact one you go a stage further and type

A>ERA *.*

and de 1 ete every f i 1 e on the disk - drastic, but


sometimes necessary! In order to make sure that you
really do want that rather wholesale operation, you
will get the question

ALL(Y/N)?

to which you have to reply (Y)es or (N)o before the


erasure takes place.
12 Using CP/M

The REN corrunand


The REN command will allow y o u to RENa me a f i le ; again
it is onl y th e di rector y e n t ry that wi l l b e am e n de d .
All that is need ed is to t y p e

A>REN newname=oldnam e
A>

So, i f we want to ch ang e the nam e of , s a y, the file


TEXT1.BAK on dri v e B to TESTl on dri v e B, th en we t ype

A>REN B:TEST1=TEST1.BAK
A>

"Wild-card" characters cannot be us ed in REN and the


new name given to th e file must not alr ead y e x i s t . As
well as that, you cannot r ename acros s di sks so that

A>REN B:TEST1=A:TESTl

is illegal and CP/M will query y o u r instruct ion.


An y filename can b e changed, so that if yo u b e c o me
fed up with t yping CBAS86 then this command can b e
changed to BAS b y t y ping

A>REN BAS.CMD=CBAS86.CMD
A>

Then e very time the command

A>BAS

is typed, the CBAS86 program is executed.

The TYPE corrunand


TYPE will cause the contents of a named file to be
displayed on the console VDU screen. So that

A>TYPE TEXT1.TXT

will list the entire contents of the file on the screen


a page at a time. At the end of each page y o u will be
invited to press RETURN in order to obtain the next
page. This gives yo u time to read each page as it comes
up on the screen. Typing
CP/M Resident Commands 13

A>TYPE B:TEXT2.TXT

will likewise display the file called TEXT2.TXT which


is stored on the disk in drive B.
Be careful, however, to make sure that you only TYPE
files that you can read. This is not a silly as it
sounds since not all files are stored as ASCII
characters. A BASIC program, for example, that has been
SAVEd by MBASIC will be stored in a compressed form
using what are called "tokens" for the BASIC reserved
words. An attempt to TYPE that program from CP /M will
result in an unreadable series of symbols being
displayed on the screen. If the same program had been
SAVED in ASCII characters by typing

SAVE "PROG1",A

while in MBASIC, then it is perfectly all right to TYPE


it from CP/M. Similarly, it is no use typing

A>TYPE PIP.COM

since PIP, and all the other commands, are stored in


machine code format which will probably produce garbage
on the screen when TYPEd and qui te possib 1 y crash the
system as well! So beware.
4 PIP, the Peripheral Interchange
Program

P IP, as wi t h t h e l i ne ed i to r , c a n trac e it s origins


back to th e ea r l y d a ys (a r ound 1 968) o f min i co mput ers
and th e DEC PDP- 8 s eri e s o f machin e s. At that time th e
pr og r a m was us ed to link f i le s on disk t o a pa pe r tape
de vic e, e i t he r a r eader or a punch. By u s i ng P IP it was
then possibl e to c opy a f i le stored on p u nc he d paper
tape straight onto disk. Similarl y a file on d isk could
b e copi ed onto punched paper tape. Henc e th e name of
Peripheral Inter chang e Pr ogram. In the b e ginn ing it wa s
just that; an int erchang e of data be t wee n a p air o f
pe ri pheral de vic e s, a disk dri v e and p aper ta pe r eader
or p u n ch . Th e ve r si o n o f PI P in u s e und er CP /M i s n o w
f a r mo r e ver s a t i le and allows u s t o mov e d ata b e twee n
ma ny pa ir s of peripheral de vices a nd eve n int e rnall y on
th e same de vic e. Sinc e P IP is a c omma n d f i le ( it h as
th e ex t e n s i o n .C OM or . CMD) all th at i s n e ed ed to
i n vo ke it is i t s , n ame and so we g e t

A>PI P
*
th e * p r o mp t ind icating t ha t furth er instructions a r e
being awaited.
The general fo r m of a PIP command is that of

Destination f i le=So u r c e fil e

so that if we type

A>PIP
*B:FILEl=A:FILE2

th en the file called FILE 2 on drive A (the A: before


th e f i l e name t ells CP /M th e dri ve on which the file is
cur r entl y stor ed) is to b e copied onto dri ve B under
the name of FILEI. On p r e s s i ng the RETURN ke y y o u will

14
PIP, the Peripheral Interchange Program 15

hear the drives whirring and the indicator lights com e


on as the file is copi ed from driv e A onto dri ve B.
When the transfer is compl ete the * prompt r e-appears
and we can either transfer another file from one de vice
to another or come out of PIP. The latter operation is
accomplished by depressing the RETURN key. So in total
we see

A>PIP
*B:FILE1=A :FILE2
* (ret)
A>

But th ere is more to PIP than that. In fact there


are numerous short cuts. For example, if only on e file
was to be moved, then all that needs to be typed is

A>PIP B:FILE1=A:FILE2
A>

If no file specifier is given then PIP always


assumes that the default drive, drive A, is meant . So
our command would be equally valid if we typed

A>PIP B:FILE1=FILE2
A>

Should we want to copy the file from one disk to


another whi I e retaining the f i 1 ename, so tha t we ha ve
identical files with identical names on both disks, all
that is needed is

A>PIP B:=FILE2
A>

or

A>PIP B:FILE2=A:
A>

instead of

A>PIP B:FILE2=A:FILE2
A>
16 Us ing CP/M

Of cours e , on e co u ld pr o d u ce a co p y of a f i I e on the
same disk , und er a ne w na me , b y t y pi ng

A>PIP NEWFI LE=OLDFI LE


A>

wher eupon there wo u ld be t wo cop ies o f t h e sa me f i le on


dri ve A, but with on e cal l ed OLDFILE and on e called
NEWFI LE . Th e r e might not b e a lot of point in doing
t h i s, bu t i t is sometimes o f use and PIP do es al low us
t o do it .
PIP a lso a l lows u s t o perfor m th e o pe r a t i o n of
concatenation of fi l e s. This is the opera tion of
st r i ng i ng mo re t ha n o ne fi l e to g eth e r i n t o on e l ar g e
fi le . This i s us efu l i n t he c a s e of t ex t fi le s ,
s e p a r at e c hapters or paragrap hs , t hat wer e cr ea te d o n
th ei r ow n and are t h e n draw n t o g e th e r in to on e lar ge
tex t fi le . For exampl e

A>P IP B:NEWTEXT .TXT =A: TEXT I.TXT ,A:TE XT2.TXT


A>

wi l l pro d uce the f i le cal le d NEWTE XT.TXT on dr ive B


which will co nsist o f th e files on dr i ve A called
TEXTI.TXT and TE XT2. TXT strung toge th er in on e larg e
file.
Other fi les c a n b e manipulated u s ing PIP b y
includin g "wil d- c a r d" char ac ters so that a group of
file s wi th c e r t a i n common f eatures i n t heir n a me s ca n
be move d. So if we t yp e

A>PIP B:= *.BAS

the n n ot onl y wi l l a l l t he fi les wi t h a . BAS e x t e n s i o n


th at a re locat e d on th e de f a u l t d riv e , d rive A, b e
mo v ed acros s to d r i v e B, but the y a lso wil l b e list ed
fo r you as the y a re t r a ns f e r r ed

A>PIP B:=*.BAS

COPYING-
PROG I .B AS
PROG2 .BAS
PROG 4. BAS
PROG5 .BAS
PROG8 .BAS
PIP, the Peripheral Interchange Program 17

A>

The abo v e i s oft en a qu ick an d simp le way o f


produ cing "ba c k - up" co pi e s o f fil e s onto anoth er disk
and ind e ed is a good way o f copying eve ry f i 1 e from on e
dis k to another by t ypin g

A>P IP B'=* *

But be carefu l , yo u mus t mak e sure that ther e is e noug h


s pac e on th e t arg et dis k to re ceive a ll t h e fil es. A
fu 11 disk co p y using this met h od c an ta ke time and it
wou l d be a p i ty i f i t cra s he d out just befor e th e last
fil e wa s transf err ed bec a u se of l ack of s pac e. It has
happ en ed!
P IP c a n al so be us ed to transf er fil es f r o m disk,
sa y, t o a d e v ic e. Aft er a l l , th at wa s th e original
conc e pt of th e pr og r a m. But now th e d evice can b e an y
of t h e pe ripher al s conn ect e d to yo u r com put er. For
ex amp le , y ou co uld d e fi n e th e d estinat io n o f th e
trans f e r to be the p r i n ter b y t yping

A>PIP LST :=B:TEXT.TXT


A>

and the file will be printed out on the list ing d evice
specif i ed on th e s ystem, norma l ly th e p r i n t e r . In fact,
in ord er to e n s u re tha t th e t ext do es not go o ve r the
per forations on th e continuous s t a t i o nery in the
p r in ter we can f or ce it t o thr ow a n ew pag e eve r y 60
lines by including an ex tr a "tail" to th e command

A>PIP LST:=B:TEXT.TXT[P60]
A>

A fi le can also be transferred from a device t o


eith er a disk file or anoth er de vice b y specif ying an
input d e vic e as , sa y, RDR: , and th e output d e v ice as
CON:(th e consol e VDU). Typing

A>PIP CON:=RDR:
A>

wi l l displa y the incoming fi l e on the VDU scr e en and


t yping
18 Using CP/M

A>PIP FILE I =RDR:


A>

wi l l transf er t he i nc omi ng fi le t o a di s k f il e.
The a bo v e c an t hen be u se d t o t r ans f e r fil e s fro m
one com p uter to another b y c o n ne c t in g a n o ut put d e vice
of one ma c h i ne to an i npu t d e v i c e of a nother.
Ano t h e r use ful "tail" to the c ommand is t he one that
t ells PIP to start th e t r ansfer a t a s pe ci f i ed s t r i n g.
For exa mp l e

A>PIP LST:=B:TEXT.T XT[SREM*** AZ]


A>

Note that Z is CONTROL-Z and i s th e r esult of


A

holding down th e CONTROL key and then p r e ss i n g Z. This


will force printing to st art from th e strin g " REM***"
in the file call ed TE XT.T XT on dri v e B. S imilarl y we
can t ell the trans fer to ce a se when a pa r t i c u la r string
is reached . So that

A>PIP B:=TEXTI.TXT[QEND AZ]


A>

wi l l transf er all t he fi le on the d efa ult dri v e c a lled


TEXTI.TXT up to and including the string "END".
Th er e are man y other "tails" - command parameter
strings - which can us e d , but these can b e experimented
with once the us er has become fa mi liar with using PIP.
A complete list of these is gi ven.

Parameter Effect

B Transfers in block mode, so


allowing data to b e
transferred from, say, a
tape cassette onto a disk
file
On Deletes all characters
beyond co I umn n
E Echoes the output to the
console
F Removes the form feeds
from the file being
transferred
PIP, the Peripheral Interchange Program 19

Gn Gets the fil e f r om user


area n. Allows yo u to
copy from one us er area
to another
H Transf er s only valid
hexadecimal data
I Ignores any ":00" records
and transfers only
h exadecimal characters
L Converts all upper-cas e
characters to lower case
N Numbers each line, starting
at 1 and incrementing by 1
N2 As with N parameter, but
places leading zeros in
front of line number and
a "tab" character after it
o Transfers non-ASCII object
files and ignores the
normal end-of-file markers
Pn Inserts a form feed character
after ev ery n lines of text.
If n=l or is omitted, then
the form feeds are included
after eve ry 60 lines. Used
in conjunction with the F
parameter
Qstring ~Z Quits copying when th e string
is e nc o u n t e r e d
R Transfers system files
otherwise not accessible
to PIP
Copies file from the first
occurrence of the string in
the source file
Tn Places a "tab" character
in every nth column
U Translates all upper-case
characters to lower-case
v Verifies that data has been
correctly transferred
w Ov e r wr i t e s files that have
been protected as RiO (read
only)
x Copies files that are not
strings of ASCII characters
20 Using CP/M

z Sets the parit y bit of all


ASCI I character s in the
fil e b eing transferred to
zero

PIP error messages


DESTINATION IS R/ O, Yo ur d estination fil e already
DELETE (Y/N) ? e x is ts and is a r ead only
fil e. Do y o u wa n t it del eted
b efor e y o u r transf er takes
place ?
DISK READ ERROR: Cannot r ead th e input file
fil ename
DISK WRITE ERROR : Cannot open f i le to wr i te to
filename
NO FILE:-filename Sour c e f i le does not e x i s t
CANNOT WRITE: Th e targ et d e vic e do e s not
de vic e nam e exist or is i l le g a l . Could be
that you ha v e tri ed to write
to CDR
INVALID FORMAT : Your instruction is not in
entr y valid PIP format
CANNOT READ: Illegal source. Reading from
device /filename LPT for exampl e
QUIT NOT FOUND: The string argument specified
=source in a Q parameter not found
START NOT FOUND: The string argument specified
=source in an S parameter not found
ABORTED:filename PIP aborted after a key
depression
VERIFY ERROR: When copying using the V
filename option PIP has found a
difference between the data
read and the data as written
5 The STAT Command

STAT is used to det ermine the STATus of either files


stored on a disk or the disks themselves, plus a few
other pieces of useful information, as will be
described later.
In its simplest form the STAT command tells us how
much space is available on the disks currently loaded
into the disk drives. For example, we might see this

A>STAT
A:R /W,Space :200K
B:R/O,Space:16K
A>

which tells us that on drive A we have 200K bytes of


space left and that we can both read and write to files
on the disk. Disk B, however, is in read only mode and
has 16K bytes of space left, which is available for
further files. Note that if anything is to be written
into that 16K space the status of th e disk must be
changed since we are only, at this point in time,
allowed to read from and not write to the disk .
If we want to estab 1 ish the status of the disk in a
single drive we can type, say

A>STAT B:

and obta in the status of the disk in drive B only; but


this will only give us the number of bytes free and not
the read /write status.
In order to give us more information about the files
on a disk, apart from just their names which DIR gives
us, we can, for example, type

A>STAT B:* .BAS

so that we get information r egarding all the files on

21
22 Using CP/M

drive B with a .BAS extension. Th e result might be

Recs Bytes Ext Acc


3 2k 1 R/W B :BASE16.BAS
16 2k 1 R/W B:CREOIT.BAS
2 2k 1 R/W B:GREAT.BAS
3 2k 1 R/W B:FILEBM.BAS
57 8k 1 R/W B:PINSTALL.BAS
2 2k 1 R/W B:PRINT.BAS
14 2k 1 R/W B: SLOT. BAS
6 2k 1 R/W B:SORTCL.BAS
Bytes Remaining on B: 28k

The information displa yed to us in th ese tables


tells us a lot of things about each of th e fil es, all
BASIC programs as it happens, and indirectly about CP/M
as well. You will notice that the information is split
up into "Recs" which are the number of 128 byte records
that are stored in each "extent" of the file, each
"Ext" being 16K bytes. The number of b ytes allocated to
the file is always a multiple of 2K, even though the
actual content of the file is quite small. For example,
in the table shown, the program SLOT is over one -
hundred lines long, whereas the program BASE16 is only
a fifth of that length. They are both allocated the
same amount of space on the disk by CP /M which can work
only in chunks of 2K bytes. Before the name of the
file, preceded by its drive name, is the access to the
file; in this case they are all files that can be read
from or written to.
If you type $S after the file name stated in a STAT
command, you obtain an extra column of information.
This is headed "Size". If the file specified is a
serial file then the entry under "Size" will be the
same as that under "Recs". This is because the "Size"
entry is the number of records actua 11 y a vai 1 ab 1 e to
the file at that point. However, if the file is a
random file where a number of records have been
allocated but not all of them have been filled then
"Size" will be less than "Recs" as shown below

Size Recs Bytes Ext Acc


500 8 2k 1 R/W A:RANOOM.OAT

We can also use STAT to make certain files


"transparent" to OIR and PIP commands by making them
The STAT Command 23

into "system" files. This is done by putting a $SYS


"tail " on a STAT command

A>STAT PIP.CMD $SYS

The response of CP/M is

PIP.CMD set to SYS


A>

This ensures that when the directory is listed, PIP


does not appear in that list and with a STAT listing of
f i l e s , as with STAT *.CMD for example, the SYS files
are listed with their names in brackets.
Th e following will now be displayed

A>DIR PIP.CMD
A> (No response, PIP is hidden)

A>STAT *.CMD
Recs Bytes Ext Acc
227 30k 2 R/W A:BASIC86.CMD
43 6k 1 R/W A:DCOPY.CMD
64 8k 1 R/W A: (PIP.CMD)
Bytes remaining on A: 486k

To return a file to its prev ious status we use $DIR


instead of $SYS.
We can also use STAT to make a whole dri ve read
only, or read /write . For example

A>STAT A:R/O

will make the di sk in drive A into a read only disk, so


that no files on it can be altered or erased. However,
this is operational only while the disk is in the drive
and until the system is rebooted. If the disk is
inserted afresh after rebooting all files revert to
their read /write status . If you want to make any file
into one that is permanently in a read only state then
the command is

STAT A:PROGl.DAT $R/O

and the only way to undo the status, which is


24 Using CP/M

permanently attributed to that file , is to re-attribute


its read /write status by typing

STAT A:PROGI.DAT $R/W

Notice that the $ sign is us ed when referring to


files on a disk and no $ sign is required when
referring to the disk as a whol e.
Next we come to a very important aspect of the STAT
command: that which deals with the status of de vices,
both logical and physical, which the system r ecogn ises.
A logical device is one that is known to the operating
system and consists of

CON: The combined input and output device


that is the principal device used
to communicate with the processor;
usually a Video Displa y Unit complete
with keyboard
LST: An output device to which all "listings"
are made; in other words, a printing or
other hard copy devic e
RDR : An input device, traditionally a punched
paper tape reader
PUN: An output device, again this is tradit-
ionally a paper tape punch

A physical device is the actual type of device that


is connected to the logical device. Usually the
connectors are at the back of the computer. There are
generally at least two of these; one will be a large
socket known as a "Centronics" connector which is
usually for connection to a parallel printer. The
other, smaller, socket is known as an RS 232 connector
and is used ei ther for connection to a seria I printer
or another device - even another computer. A parallel
printer is one that gets its data along eight wires
simultaneously (in parallel) and a serial printer is
one that gets its data in a stream of eight bits one
after the other along a single wire. These are very
simplified descriptions of the differences between the
two communication methods, but they will suffice for
the moment. The possible physical device names which
CP/M recognises are

TTY: A teletype-like device which operates


The STAT Command 25

at low speed and rec ei v es its data


seriall y. Can be an in put and output
d evice s ince t elet ypes are a combined
p ri n te r and k e yboard
CRT: A v er y h i g h s peed combined i n p u t and
output d evice , usual l y a VD U t yp e of
device wi th a k e yboard
LPT : A p r i nt i n g d e vic e which works through
the para ll el port - that is, it is a
Centronics t ype devic e
PTP : High spe ed paper tape punching device
PTR : High spe ed pape r ta p e reading device
BAT: Batch mod e processing; the input device
b ecomes RDR: and the output devic e
becomes LST :. This e na b l e s t he computer
to work in batch mod e
UPI: and UP2 : are us er d e fined punches; that is,
output de vices numb er ed I and 2
URI: and UR2 : are user d efined readers; that is,
input d e vices number ed I and 2
ULI : A second list ing devic e; that is, another
serial printer
UCI : A s econd , u se r d e fin ed, consol e

In order to disco v er what the c urrent con figuration


of y o u r compute r is you t ype

A>STAT DEV:

and the r espons e might b e

CON: is CRT :
RDR: is TTY:
PUN: is TTY:
LST: is LPT :

The above tells us t ha t t h e current c ons ole device


i s a CRT - in other words the video screen and its
ke yboard. The current listing device is a Centronics
typ e prin ter and both RDR : and PTP: are capab le o f
communicating with a telet ype-like device - a slow-
speed serial input and output device.
We c a n list the p o s s i b l e allocations of devices b y
t y ping

A>STAT VAL:
26 Using CP/M

and we will g et

Temp R/O Disk: d:R /O


Set Indicator: d : filename: t yp $ R/O $R /W $SYS $DIR
Disk Status DSK: d:DSK:
USER Status USR:
Iobyte Assign:
CON:= TTY : CRT: BAT: UCI:
RDR:= TTY: PTR : URI : UR2 :
PUN:= TTY : PTP: UPI : UP2:
LST:= TTY: CRT : LPT: ULI:

The abo ve tabl e tells us all the re-assignments that


can be made by the STAT command . The first two lines
hav e in fact been covered earlier in this chapter. The
last four lines show all the possible configurations
that we can have for the four devices. For example the
listing device LST: can be a serial printer (TTY:), the
v ideo screen (CRT:), a Centronics para 11 e 1 printer
(LPT:) or the other serial port (ULI:) . We perform this
re-assignment by typing

A>STAT LST:=CRT :

so that now when we t ype

A>STAT DEV:

we get

CON: is CRT:
RDR: is TTY:
PUN: is TTY:
LST: is CRT:

and this will mean that every time we want a listing,


or issue the p command which usually directs all
A

further output to the printer, i t will come up on the


video screen instead.
STAT DEV: commands can be strung together so that we
can type

A>STAT DEV:LST:=LPT:,CON:=TTY:

Before going any further it should be noted that all


The STAT Command 27

the STAT command does is to pair up e a c h log ical device


with a physical device. If we think of the
microprocessor as having four "channels" through which
i t can communicate with the outside world - and through
which the outside world can communicate with it - then
we have the concept of these four logical devices. We
can then begin to realise that there are many
different physical devices that can be connected to
these four channels; printers of various types and
makes, card readers, bar-code readers and indeed other
computers. It is through these input and output ports
that computers can "talk" to each other over telephone
lines via a device called a "mod em". The modem (short
for modulator /demodulator) is connected to an
input /output port and this converts the computer 's
stream of data into a form that can be carried over the
pub 1 ic telephone network. At the other end of the
telephone line is another modem connected via one of
i t s input ports to another computer which decodes the
data and communicates that to the second computer
system.
Serial devices in particular do not all have the
same operating characteristics. Additional things have
to be done, apart from just saying that i t is a
"teletype-like" device, in order to make the computer
"talk" to them intelligibly. For example, if we
instruct CP /M that we are going to use a serial printer
as the listing device, then we have also to tell CP /M
the rate at which data is going to be transmitted to it
and other significant information as well . The speed is
the "Ba ud Rate", which is the number of bits per second
that is going to be transmitted. Incidentally, it is
worth noting that not all the bits are data bits; a
number of them will contain information enabling the
transfer rate to be synchronised with the rate at which
the receiving device can cope with the stream of data.
For example, it is no use transmitting data at 9600
bits per second to a device that can cope with only 110
bits per second. A further program in CP /M of up to
Version 2.2 is called CONFIG and this allows us to
configure a CP/M system to match the way that data is
output from any of the ports with the format in which
the receiving device needs the data. Version 3 of CP/M
allows us to perform this matching operation much more
easily and this will be dealt with in chapter 10.
Fina 11 y, we can use STAT to prov ide us wi th
28 Using CP/M

information regarding the characteristics of the disk


drives. We do this by typing

A>STAT DSK:

and we might get a response such as

A: Drive Characteristics
4512 : 128 Byte Record Capacity
564: Kilobyte drive Capacity
128: 32 Byte Directory Entries
128: Checked Directory Entries
128: Records / Extent
16: Records / Block
64: Sectors / Track
0: Reserved Tracks

This tells us a number of interesting pieces of


informat ion, including just how many directory entries
we are allowed to have. In this cas e it is 128 . This
means that however small the files may be, and r emember
that the smallest file is 2K bytes long, the maximum
number of files held on that disk is 128. Since the
maximum ~umber of byt es of information that can be
stored on the disk is quoted as 564K, this means that
we could have a situation where we have 128 small files
taking up 128 x 2 K bytes = 256K bytes and we could get
no more files on the disk because the directory, not
the disk, i s full. The result is that over half the
disk space is unusable. So be careful about having too
many very small fi les on one disk . For example, if a
company was using a CP/M-based program such as WORDSTAR
to produce standard quotations, then details of no more
than 128 different product lines could be kept on one
disk.
6 ED, the CP/M Line Editor

The standard editor supplied with all versions of CP/M


has a long and honourable lineage. It exhibits great
similarities to a number of editors developed initiall y
for minicomput ers in the 1960s, in particular to the
DEC series of machines and the Data General Nova and
Eclipse line. Anyone using a microcomputer with CP /M
wi ll immediately feel at home with ED if he has had
some experience at operating system level on a
minicomputer.
ED is a line editor in that its main use is creating
source code for programs in languages other than BASIC;
languages in fact that need to be either assembled,
using the various assemblers available on CP /M
operating systems, or compiled using compilers for such
languages as COBOL, FORTRAN and CBASIC. It has always
struck the author as rather odd that, despite the fact
that the main use of ED is as described above, the
manuals and many other texts insist on explaining it
with the aid of poems or quotations from Shake speare!
This book is going to treat the editor for what it
really is.
Firstly the reader must appreciate that the editor
holds text in memory, in a buffer area, as a series of
strings of characters separated by "carriage return"
characters. Each of these str ings of characters is
identif ied by a unique 1 ine number given to it by the
editor, hence it is referred to as a "line editor" as
opposed to an editor that looks at "blocks" of text, as
in a word-processor program. The 1 ine numbers are
supplied by ED merely to act as reference points and do
not form part of the f ile being edited. A character
pointer (referred to as CP) moves through the buffer on
commands from the keyboard.
To start wi th, 1 et us see wha t happens when we want

29
30 Using CP/M

to create a file containing characters that are going


to be in the format of a CBASIC program, hence the .BAS
extension after the filename. CBASIC is a version of
the well-known BASIC language, which is compiled, as we
shall see in chapter 10. It is characterised by a lack
of the familiar line numbers and the use of numeric
"labels" to flag lines of program to be jumped to. If
we type

ED DEMO . BAS

ED will respond with the star prompt

NEW FILE
: *
and await our further instructions.
Recognising that a file named DEMO.BAS does not
already exist, ED tells us that a new file has been
created and that an empty buffer area has been provided
in which the 1 ines of our "program" wi 11 be stored as
they are typed in. Our first task is to indicate that
we wish to Insert text into the buffer, and ED will
then respond by providing us with an empty 1 ine 1, as
shown

ED DEMO. BAS

NEW FILE
*1
1:

We are now ready to type in the first line of


program and when we have pressed the RETURN key the
line is placed in the buffer and the next line is
"opened up" for us. This is shown as

ED DEMO. BAS

NEW FILE
*1
1: REM***DEMONSTRATION CBASIC PROGRAM***
2:

It is rather like entering an ordinary MBASIC


program using the AUTO facility . We enter each line in
ED. the CP/M Line Editor 31

turn of our program until we have something that looks


like

ED DEMO. BAS

NEW FILE
*1
1: REM***DEMONSTRATION CBASIC PROGRAM***
2: OPEN "DEMFILE" AS 1
3: INPUT "HOW MANY RECORDS ";N
4: FOR I = 1 TO N
5: INPUT "TYPE IN A STRING ";A$
6: PRINT#l;A$
7: NEXT I
8: CLOSE 1
9: END
10:

Now that the text has been completely entered, the


editing session is terminated by ~Z which returns us to
the * prompt

ED DEMO . BAS

NEW FILE
*1
1: REM***DEMONSTRATION CBASIC PROGRAM***
2: OPEN "DEMFILE" AS 1
3: INPUT "HOW MANY RECORDS ";N
4: FOR I = 1 TO N
5: INPUT "TYPE IN A STRING ";A$
6: PRINT#l;A$
7: NEXT I
8: CLOSE 1
9: END
10: ~Z (Not echoed at the screen)

*
Type E - for Ending the editing session - and the
file is automatically saved on disk under the name
DEMO. BAS.
It is at this point that you might attempt to run
the program (this attempt will be shown and expla ined
in Chapter 8) and it will be seen that an error has
been made in the CBASIC program. This needs to be
corrected. It invo 1 ves a change being made by the
32 Using CP/M

insertion, or so it is thought, of another line. So the


next thing we do is to recall th e original file into
memory. This is done in two stages. First of all

ED DEMO . BAS

produces

*
We have to instruct the editor to call in the named
file into the buffer area, and so we t ype 9A since
there ha ve be en nine lines in our original program. A
"shorthand" method is to typ e "#A" to cop y the e n t i r e
file into the buffer. 9A copies the fir st nin e lines of
the f i 1 e into th e buf fer and so th e screen looks 1 ike

ED DEMO. BAS
*9A
1: *
and we now know that the file has b een loaded into
memory and the CP (character pointer) is at the
beginning of the first line of the file. At this point
we cou 1 d ask for a numbe r of 1 in es to b e disp 1 ay ed by
typing 3T if we wanted the next three lines to be
displayed, or 9T if we wanted all nine lines to be
displayed, and so on. "#T" displays the entire contents
of the buffer, of course. The number of lines displayed
are counted from the current position of the point er.
To move the pointer we type a number followed by the
letter L to instruct the editor to move forwards a
number of lines; prefix the number by - and the CP
moves backwards the required number of lines. So we
might have

ED DEMO. BAS
*9A
1: *3T
1: REM***DEMONSTRATION CBASIC PROGRAM***
2: OPEN "DEMFILE" AS 1
3: INPUT " HOW MANY RECORDS ";N
1: * (Note that the line number returns
to 1 showing that the CP has not moved)

or we could have
ED, the CP/M Line Editor 33

ED DEMO. BAS
* 9A
1: * 2L
3: *
thus p o s i t i on i n g the CP at the start o f the third line.
We can mo v e the p oi n te r a s p e ci fi ed nu mb er of
cha r act er s at a t im e if req u i red - rememberi ng t ha t the
"ca r r iage retu rn-lin e fe ed" at the e n d o f ea c h lin e of
t e xt counts as t wo c ha r a c ter s . So we could ha v e

ED DEMO. BAS
* 9A
1: *2L (Move on two lines)
3 : *8C (Move CP on 8 cha racters)
3 : * 2T (T ype two lines)
OW MAN Y RECORDS ";N
3 : FOR I = 1 TO N
3: *

Th is is b ecaus e we h av e moved the po inter along line


3 b y ei gh t char act ers and the displa y starts at th e
c u rre n t p o i n ter p o s i ti o n ; s o we g et the remai n i ng p ar t
of li ne 3 and al l l i n e 4.
To att e mpt to cor rect our error we mus t ins ert a new
1 in e b efore 1 i ne 3 ; in other word s we cr eat e a n e w 1 in e
2 . To do this we move the p o i n te r to t he lin e whe r e the
ins ertion is to b e ma de . We wi l l t hen ins ert our e x t r a
1 i ne . So we mo v e th e point e r to th e be g i n ni n g o f 1 i ne 2
with lL. Note that lL wi l l take us f r o m lin e 1 to the
sta rt o f 1 ine 2 . 2 L will take us from th e start o f 1 ine
1 to the start of lin e thre e; lOL wo uld tak e us to the
start of line 11. We issue the I, for i n se r t , command
and then press "carriage return"; th en we can t ype in
our extra 1 ine, terminat ing that with a "carriage
return" which takes us onto the next line. We could, if
we so wished, t yp e in another 1 ine and another unti 1 we
had inserted as man y 1 in es as we wished. When we ha v e
t yp ed in all the lines we need we terminat e the
ins ertion with a ~Z , as shown

ED DEMO. BAS
*9A
1: *lL
2: *I
34 Using CP/M

2: CREATE "DEMFILE" AS 1
3: A
Z
3: *E

The End command will terminate the editing session


and return you to the CP 1 M prompt

A>

You now have the latest edited version of the file


called DEMO.BAS. The original, unedited version is
retained and renamed as DEMO.BAK (a back -up file in
case of accidents).
In fact our program is sti 11 not quite correct, as
you will see, and needs further amendment as follows

ED DEMO. BAS
*9A
1 : *lL
2: *1
2: IF END#l THEN 5
3: Z (Not echoed)
A

3 : *lK (The K command Kills lines


3: *IT from the current line)
3: OPEN "OEMFILE" AS 1
3: *L
4: *1
4: GOTO 10 (These two extra lines are
5: 5 inserted at line 4)
6: ZA

6: *B (The B command takes you Back to the


1: *6T head of the file)
1 : REM***DEMONSTRATION CBASIC PROGRAM***
2: I F END#l THEN 5
3: OPEN "DEMFILE" AS 1
4: GOTO 10
5: 5
6: INPUT "HOW MANY RECORDS ";N
1: *5L
6: *1
6: CREATE "DEMFILE" AS 1 (Two more lines
7: 10 inserted at line 6)
8: A
Z
8: *B
1: *8T
1: REM***DEMONSTRATION CBASIC PROGRAM***
ED, the CP/M Line Editor 35

2: IF END#l THEN 5
3: OPEN "DEMFILE" AS 1
4: GOTO 10
5: 5
6: CREATE "DEMFILE" AS 1
7: 10
8: INPUT "HOW MANY RECORDS "iN
1: *E

If you follow the above sequence of commands


carefully you will see that the file of CBASIC
instructions has been amended so that it now runs
correctly as is shown in chapter 8.
But how do we make an alteration to aline in order
to make, in our example, i t look a little better when
the program runs? In fact, we can do i t in severa 1 ways
and the easiest is to issue a command that says "find
the offending piece of text and replace i t by another
piece of texti do this a certain number of times"

ED DEMO. BAS
*14A (The file now contains 14 lines
1: * of program)

and we type SRECORDSAZRECORDS ?:


The "S" stands for "Search and Rep 1 ace" the
following string, whose end is marked by the AZ and
whose replacement follows it. Pressing "Return" will
ensure that the operation is carried out. We have now
repl aced "RECORDS" by "RECORDS ?:".
The CP is now on line 8 immediately after the last
character replaced, so that an instruction to print the
line will print what remains of it, namely "iN. To see
if the amendment has been made correctly, we can
type -lL2T which tell s the edi tor to go back one 1 ine
and then type the next two 1 ines, and we wi 1 1 get

ED DEMO. BAS
*14A
1: *SRECORDSAZRECORDS ?:
8: *T
II iN
8: *-lL2T
7: 10
8: INPUT "HOW MANY RECORDS ?:"iN
7: *
36 Using CP/M

Next we shall change the "INPUT" on line 10 into a


"PRINT" and then insert a new INPUT line after it. We
move the pointer to before the lines to be altered so
we type
7: *2L
9: *SINPUT~ZPRINT
10: *

We then change STRING ";A$ into STRING #:";1; and


follow this with a new line containing the instruction
INPUT A$, as follows

10: *SSTRING " ;A$~ZSTRING #:";1;


10 : *lL
11 : *1
11: INPUT A$
12: ~Z
12: *

Then display the whole file

12: *B
1 : *#T
1: REM***DEMONSTRATION CBASIC PROGRAM***
2: IF END#l THEN 5
3: OPEN "DEMFILE" AS 1
4: GOTO 10
5: 5
6: CREATE "DEMFILE" AS 1
7: 10
8: INPUT "HOW MANY RECORDS 7: ";N
9: FOR I = 1 TO N
10: PRINT "TYPE IN STRING #:";1;
11 : INPUT A$
12 : PRINT#l;A$
13 : NEXT I
14 : CLOSE 1
15: END
1: *
Once the editing is complete the new version of the
text can be saved by typing E in response to the *
prompt. The latest version of the file is saved under
the current filename and a back-up version of the
original, unedited, file is retained with the file
ED. the CP/M Line Editor 37

extension .BAK.
There are, of course, many other commands that
control the editor. For example, lines are deleted,
from the current position of the CP b y the command

nK

where "n" is the number of lines to be deleted.

Similarly

nD

deletes a specified number of characters before (n


negative) or after (n positive) the CPo
Specific strings of characters can be located by the
use of "F", for Find, so that, for example

3FCOUNTER~Z

will find the third occurrence of the word "COUNTER" in


a file and will position the CP after the last
character in the last matched string.
The command "E" will terminate the editing and close
all the files, writing the latest version of the file
to the named file. The command "H", for Home, will save
the file as it has so far been modified and will return
you to the editing mode. This is of particular use if
the file being edited is lengthy and needs much
alteration. Saving a file at intervals is a good
insurance against the possibility of the entire file
being lost owing to power or equipment failure.
Files can be moved into and out of the edit buffer
by the use of

Rfilename

to Read a file into the edit buffer in front of the


current position of the CPo The only thing to watch is
that the file read in must have a .LIB extension,
although this can be omitted in the command.
Similarly the command

nX

will transfer n lines of text from the current CP out


38 Using CP/M

of th e edit buf f er int o anoth er fi le that wi l l b e


named X$$ $$$$ $. LI B. It is then up to th e user to r ename
t his fil e as req u i red .
If yo u ha v e Version 3. 1 of CP/M then anoth er useful
job that ED can do is to cr eat e a PROFILE.SUB file
that is the file s earch ed for when CP/ M is first booted
up. If this file is not f o und then th e usual

A>

p r o mp t i s dis pla y ed. Howe v e r, if a PROF I LE. SUB f i le


ex ists then CP/ M e xe cutes it and the us e r c a n go
straight into wh a t eve r routin e i s re q u i re d . For
exampl e, if we create a PROFILE.SUB l ik e this

ED PROFILE. SUB

NEW FILE
*1
1: MBASI C DEMPROG
2: ~Z

*E

A>

then when the system is started th e first thing to


happen is that MBASIC is loaded. Th e program called
"DEMOPROG" i s th en load ed and run. This is onl y one
exampl e: PROFILE.SUB can consist of s everal lin es if
required.
Similarl y we can use ED t o cr eate .SUB f iles whic h
can contain a constantly us ed set of instructions. For
example, if it is often necessar y to set up a
complicated command string, then the commands can be
placed i n t o a file with the extension .SUB and then
the single command SUBMIT followed by the filename will
cause all the commands within that fil e to be executed.
A simple example of this is with the s etting up of the
WORDSTAR package on the well-known SIRIUS
microcomputer. This machine has a series of
programmable k ey s which a re very useful when using
WORDS TAR. These are set up b y a program called WS.KEY.
So if a file called EDIT.SUB is created that contains
the two instructions SET WS.KEY and WS using the editor
ED. the CP/M Line Editor 39

ED EDIT.SUB

NEW FILE
*1
I: SET WS.KEY
2: WS
3: ~Z

*E

then whenever the command

A>SUBMIT EDIT

is i s s u e d the computer is set up as a dedicated word


processor, provided of course, that the files called
WS.KEY, WS.CMD and SUBMIT.CMD are present on the disk
being used.
If we are using Version 3.1 of CP /M then we could
rename EDIT.SUB as PROFILE.SUB so tha t WORDSTAR wou Id
be set up on booting the system and this would be ready
to use without any intervention from the operator.
The complete set of ED commands are

nA Places n lines from the or iginal


text file after the last character
in the editor buffer
nW Writes n lines from the editor
buffer in a temporary file
E Ends ED. The contents of the editor
buffer are copied into a temporary
file and files are renamed
H Save editing performed so far. Editor
buffer is emptied and the temporary
file becomes the new source file and
a new temporary file is created
o Restarts editing with the original
file
Q Quits the editor - exits to CP/M
rfilename Reads file <filename > into editor
buffer
nX Transfers n lines of text from
editor buffer into temporary file
called X$$$$$$$.LIB
nL Moves pointer backwards or forwards
n lines. If n is zero moves pointer
to start of current line
40 Using CP/M

nT Displays n lines of text - current


line plus (n-l) lines. Displays
preceding line if n is negative.
If n is zero displays the current
line from the pointer position to
the end of the line
OTT Displays the current line, whatever
the position of the pointer within
that line
B Moves pointer to start of editor
buffer. If prefixed by - sign, moves
pointer to the end of the buffer
nC Moves pointer n characters forwards
or backwards from the current pointer
position
n: Moves the pointer, as does the L
command, and displays the current
line
:n Defines the range of text between
the current line and line numbered n
nO Deletes n characters following
(n positive) or preceding (n negative)
the pointer
nK Deletes n lines following (n
positive) or preceding (n negative)
the pointer
nfstring Finds the nth match of the string in
the text. The pointer is left after
the last character of the matched
string
nsstringAAZstringB
Substitutes stringB for stringA n
times
istring Inserts string in front of present
position of the pointer
jstringAAZstringBAZstringC
Replaces the text between stringA
and stringC with stringB
nmstring Where string is a string of commands
rather than text. If n is zero or
I then string command is executed
repeatedly until the end of the
buffer is reached. If n is greater
than I then the command is executed
n times
nnstring Finds the specified string n times.
ED, the CP/M Line Editor 41

Continually refills buffer from


source file until e i t he r t he n
matches have been found or the whole
file has been searched

While editing is carried on, the temporary file is


gi ven the extension .$$$ . After editing has taken place
the original, unedited, text file is retained but with
the extension . BAK and the edited file is giv en th e
original nam e of the file. This means that if the
sourc e file is cal led TRIAL.BAS, then during editing
the temporar y file is TRIAL.$$$ . After the e d i t i n g
session has been completed the new edited file is
called TRIAL.BAS and the original file is renamed
TRIAL.BAK .
7 Using MBASIC

The commonest version of the popular BASIC languag e


used on CP/M systems is that known as MBASIC; this is a
copyright program by Microsoft Inc. The version used
under CP/M-86 is known as BASIC-86, which is identical
with MBASIC. It is an interacti ve programming language
developed initially for teaching th e principles of
programming back in the 1 ate 196 Os. Since then it has
undergone many variations as each computer manufacturer
has produced his own customised version of the
language. Luckily we have in the Microsoft version
something that is very close to a standard for the
language. At a simple level Microsoft BASIC is easy to
use and at its present level of development it provides
a powerful and sophisticated programming tool.
Anyone who comes to MBASIC after using a version of
BASIC on a mini or a mainframe computer will find that
it provides a number of facilities that are not
available on the larger machines. A feature that is
missing, however, is the set of commands to manipulate
matrices. An extra that is not found in minicomputer
BASICs is that arrays can be of either numerical or
string type so that we can declare

10 DIM A(10,20),A$(10,20)

and both statements mean similar things; that is, we


are to have, firstly, a table of numbers called A with
10 rows and 20 columns, and secondly a table of strings
(names, for example) with 10 rows and 20 columns. This
resolves an inconsistency which exists in the more
common minicomputer versions of BASIC.
While on the topic of strings we also have a very
neat way of referring to substrings by using the LEFT$,
RIGHT$ and MID$ keywords. These were actually first

42
Using MBASIC 43

us ed on a v ersion o f BASIC suppl i ed o n t h e DEC 10


computer s e v eral ye a rs bef ore mi c r o s came on th e scene.

LEFT$( A$, K) - s p ecifi es t h e first K ch a r a c te r s i n the


s tr i ng A$

RI GHT $ ( A$ , K) - s p ec i f i es the last K charact ers in th e


str ing A$

MID$( A$,K,L) - s pecifies the substring of L characters


start ing at the Kth character o f the
string A$

MBASIC variabl es can have names that contain up to


40 characters and thes e variables can b e d efined to be
of single precision, doubl e precision or i nte ge r types
by using a !,# or % r especti v ely, a s th e final
cha ra cter in the name.
I f y ou hav e th e MBASIC command fil e, MBASIC.COM or
BASIC86.CMD,then all that is required is:-

A>MBASIC

or

A>BASIC86

a nd CP/M will load the MBAS I C interpreter into memory


an d re s po nd with a s i g n-o n mes s a g e s uc h as

BASIC-86 Vers ion 5.22


[CP /M-86 Version]
Copyright 1977-1982 (C) by Microsoft
Created: 5-Ma r - 82
52294 Bytes free
Ok

At that point y o u are in a position to t ype in a


BASIC program. Synta x checking is not done u n t L 1 run-
time. So, if y o u write a program wher e t h e r e ar e man y
branches to th e algorithm, take care to t est them all;
otherwise you will eve nt ua lly find yo ur se l f on a path
not tra versed before a n d disaster will str ike!
MBASIC allows us to incorporate a modicum of
structure in our programming since it pro vides a WHILE
instruct ion as well as the FOR... NEXT t ype o f loop. In
44 Using CP/M

addition, it allows us to use IF ... THEN . . . ELSE and


multiple instructions on one line.
To i l l ustrate the way MBASIC uses the FOR... NEXT
loop, the following program can be run

10 INPUT I,F,S
20 FOR J=I TO F STEP S
30 PRINT J
40 NEXT J
50 PRINT J

If the start, finish and step variables are made in


turn 1,10,1, then 1,1,1 and finally 1,0,1, you will see
that not only will the counting variable (J in this
case) emerge from the loop equal to one greater than
the variable called F in the first two cases, but it
will also end up with a value of unity in the third
case. The last situation tells us that when the loop is
not traversed at all the final value of the control
variable is that of I, its initial value. It is worth
trying this program on a number of microsystems and
seeing the variations in the results that you get.
The WHILE instruction can be best explained in a
program such as

10 INPUT NUMBER
20 WHILE NUMBER< >O
30 TOTAL=TOTAL + NUMBER
40 INPUT NUMBER
50 WEND
60 PRINT TOTAL

This program takes us around the loop between lines


20 and 50 so long as the variable called NUMBER is not
equal to zero. Once a zero v a l u e is input we exit to
line 60. If we omit the first line of the program so
that we get

20 WHILE NUMBER<>O
30 TOTAL=TOTAL + NUMBER
40 INPUT NUMBER
50 WEND
60 PRINT TOTAL

we find that the loop is not entered at all since all


variables are set to zero by MBASIC at run-time. This
Using MBASIC 45

does show that, unless th e v a l u e of the control


variable 1S non-zero in this example, the loop will not
be entered at all.
A simple program to add up a series of numbers,
terminating input with a zero valu e, and print their
total and average is shown below using conventional
BASIC GOTO statements

10 SUM=O:NUMBER %=O
20 INPUT "TYPE IN A NUMBER"iNUMBER
30 IF NUMBER=O THEN 70
40 SUM=SUM+NUMBER
50 NUMBER %=NUMBER %+l
60 GOTO 20
70 AVERAGE=SUM/NUMBER %
80 PRINT "THE TOTAL IS "iSUM
90 PRINT "THE AVERAGE IS "iAVERAGE
100 END

Notice the use of the integer NUMBER % to count the


number of entries, which is bound to be an int eg er
anyway. This is not the same as the variable NUMBER
which is the input value being summed.
Using the WHILE and WEND stat ements this program
becomes

10 SUM=O :NUMBER %=O


20 INPUT "TYPE IN A NUMBER"iNUMBER
30 WHILE NUMBER <>O
40 SUM=SUM+NUMBER
50 NUMBER%=NUMBER %+l
60 INPUT "ANOTHER NUMBER "iNUMBER
70 WEND
80 AVERAGE=SUM/NUMBER %
90 PRINT "THE TOTAL IS "iSUM
100 PRINT "THE AVERAGE IS "iAVERAGE
110 END

Notice how much easier it is to follow the logic of


the second program compared with the first.
The IF ... THEN ... ELSE type of statement is very
useful as it helps to reduce the amount of "spaghetti"
type programming which BASIC tends to encourage. This,
together with the WHILE and WEND statements, helps to
move towards the better structuring of programs. We can
write some program very economically, such as
46 Using CP/M

10 INPUT X
20 IF X>lOO THEN PRINT "HIGH" ELSE PRINT "LOW"
30 END

The ability to type more than one instruction on a


line also results in economical programming since if we
write

10 INPUT X
20 IF X<lOO THEN PRINT "TOO LOW":GOTO 10
30 PRINT X
40 END

this means that if th e value of X is l ess than 100 th en


not only is the "TOO LOW" message printed but also a
jump back to line 10 is made to ask for another input.
If the value of X is equal to or greater than 100 then
line 30 is executed.
A very useful feature of MBASle is that line editing
is available. For example, if a line requires
al teration then we can go into EDIT mode b y typing

EDIT 200

and the 1 ine number is disp 1 ayed. We are now in a


position to amend the line. If line 200 was

200 INPUT "TYPE IN A NUMBER",N

and we needed to change the comma into a semi-colon,


then by typing "5," we are setting the editor to search
for the comma and we wi 1 1 get

A>EDIT 200

200 (You type "S,"IINPUT "TYPE IN A NUMBER"

and the cursor wi 11 now be in fron t of the character to


be changed. Type D and that wi 11 de 1 ete the character
immediately following the cursor and you will see

200 INPUT "TYPE IN A NUMBER"\,\

where the backslash character delimits the deleted


character. Then type I, for Insert, type in the new
Using MBASIC 47

character (the ; ) and follow this by a RETURN. You will


get

200 INPUT "TYPE IN A NUMBER" \, \;N

Notice that neither th e D, for Delete, nor the I,


for Insert, are printed. If you now type

A>LIST 200

you will have

200 INPUT "TYPE IN A NUMBER";N

which is what you wanted .


If you pre cede the D command wi th a number, y o u wi 11
del ete that number of characters from the present
cursor position. After the I command y o u can typ e as
man y characters as you like and they are inserted at
the current cursor position. By pressing the RETURN key
you enter the insertions and exit from the editor.
Other commands are as follows

H deletes all characters to the right of the cursor .


Note that we move the cursor to the right by pressing
the space bar and to the left by pressing the RUBOUT
key .
K deletes all charact ers up to a specified
character. Th is means that if the cursor was as shown
here

200 INPUT (You do this by typing EDIT 200


and pressing the RETURN key 5 times)

then "3KN" will delete everything up to and including


the comma and position the cursor at the third occurrence
of the letter N as shown

A>EDIT 200

200 INPUT (You type "3KN") \ " TYPE IN A NUMBER," \

then if we press the RETURN key we will have a new line


200 as follows

200 INPUT N
48 Using CP/M

C changes the charact er aft er th e curs or into th e


character immediat el y follo wing th e C. To r ep e at th e
command f or se veral characters we pr e f ix the C b y wi t h
th e number of characters to b e changed.
L lists what there is l eft of the lin e and tak e s us
back to its start, lea ving us s t i l l in EDIT mode . This
is particularl y useful if ther e are a numb er of chang e s
to b e made to a l i n e.
A allows us to abandon the e d i t i n g don e s o fa r and
go back to the b eginning. This i s ve ry u s eful if we
ha v e mad e a mess of th e e d i t i n g a nd wish t o s t a r t
again.
Q quits th e e d i t i n g without sa v in g an y of th e
changes made.
Finally, a ve r y useful and not alwa ys well-
documented f ea ture of the e d i tor shou 1 d be not ed. You
might have noticed that EDIT always produces the lin e
number first and then waits for y o u to e d i t that lin e.
But suppose that y o u ha ve spent a lot of time and
effort in typing a ver y complicated lin e of program
and, having got it right, find that you need that line,
or one v e ry similar to it, in anoth er part o f th e
program. EDIT allows you to duplicat e th e lin e wi t h
another line number. Suppose the line is

40 X=SQR(SIN(LOG(I))~2)+EXP(COS(I))~.4

and you want the sam e instruction on lin e 100. You


first of all type

EDIT 40

and you will get

40

as expected. Then you press E followed by CONTROL and A


(pressed simultaneously) and you will get a prompt with
the! character. Type I for Insert and the new lin e
number. You now have two lines containing the same
instructions but with different line numbers. The whole
sequence looks like this
Using MBASIC 49

A>EDIT 40
40 (You type "E", followed by "RETURN")
(You type CONTROL-A)
! 100 (You type "I" followed by the
"100" and "RETURN")
100 X=SQR(SIN(LOG(I))A 2)+EXP(COS(I))A.4

If you type the "LIST" command you will find


that you now have

40 X=SQR(SIN(LOG(I))A2)+EXP(COS(I))A. 4
100 X=SQR(SIN(LOG(I))~2)+EXP(COS(I))A.4

If a program requires stopping for any reason, such


as it having gone into an endless loop, then the
pressing of the CONTROL and C keys will cause it to
stop. If you want the program to continue then the CONT
command will allow the program to continue execution
from the point where i t stopped. If you edit the
program at all after you have stopped it, then you will
not be able to continue it and you will get the "Can 't
Continue" message on the screen. If you want to
continue then you can always type

GOTO nnnn

where nnnn is a line number. This will allow execution


to start from the specified line. There is no
equivalent to the RUN nnnn command in other versions of
BASIC.
File handling in MBASIC needs a close watch,
especially if you have become accustomed to using files
in other versions of the language. Both serial and
random access files are supported, but they are treated
in quite different ways. First of all, serial files
have to opened in either Input mode or Output mode. A
channel number has to be assigned to the file while it
is opened and the file being used has to be named. So
we will have a command such as

10 OPEN "O",l,"DATAFILE"

when we want to open a file to be written to . This


command will open the file called "DATAFILE" in output
mode and, if a file with that name already exists, it
will be automatically deleted. Files in output mode are
50 Using CP/M

PRINTed to.
If we write

10 OPEN "I",l,"DATAFILE"

then the file called "DATAFILE", which must already be


in existence, is opened ready to allow us to INPUT data
from it. What is happening is that we are replacing the
keyboard, which is the usual device for communicating
wi th the microprocessor, by the f i 1 e and the same
statements, INPUT and PRINT, are used. The only
difference is that the channel has to be specified
after the INPUT or PRINT. This means that if we write

5 INPUT A$
10 OPEN "O",l,"DATAFILE"
20 PRINT#l,A$ (PRINT to the file,not the screen)

we will print the characters contained within the


variable called A$ onto the file on channell, which is
called "DATAFILE". If we write

10 OPEN "I",l,"DATAFILE"
20 INPUT#l,A$ (INPUT data from the file,
30 PRINT A$ not the keyboard)

we wi 11 read the characters contained wi thin the


variable called A$ from the file and print them on the
screen. Now we have to start being careful. Writing the
data contained in a single variable to a file and
reading this back again is easy and not prone to
unexpected error. However, when we come to writing the
values contained in a set of variables and reading them
back we can run into problems. Take the following
program, which looks innocent enough

10 OPEN "O",l,"DEMOFILE"
15 FOR 1=1 TO 3
20 INPUT A$,B$,C$
30 PRINT#l,A$,B$,C$
40 NEXT I
50 CLOSE#!
60 OPEN "I",l,"DEMOFILE"
70 FOR 1=1 TO 3
80 INPUT#l,A$,B$,C$
Using MBASIC 51

90 PRINT A$,B$,C$
100 NEXT I
110 CLOSE

If we run the above program the output is not quite


as expected. In fact we get the data back that we typed
in, but followed by the message

Input past end in 80

If we investigate more closely by typing

PRINT A$

we find that this variable contains not one string of


characters, but three! In fact, A$ contains three
strings, and so does B$ and so does C$. Hence the
program attempts to read for data beyond a point where
there is any in the file. What has happened is that the
INPUT and PRINT instructions when referred to files are
just the same as when referred to the keyboard or
screen. So that PRINT# prints data to the file exactly
as it would to the screen. This means that if the
printed data is separated by commas, as it is in our
program, it prints it to the file with spaces between
the strings. When it is read back from the file the
system looks for a delimiter which is either a comma,
or semi-colon, or a carriage return character . It sees
the carriage return which we used to end each set of
original input from the keyboard, and so assigns
everything up to that character to the first variable.
This results in A$,B$ and C$ containing three times as
much information as we wanted them to.
The data on the file would look like this

TOM DICK HARRY


FRED GEORGE JIM (No commas present)
RON TIM MARY

The way out of the problem is actually to write the


delimiters, commas, to the file as we write the data.
This means that our program will have to be as
follows
10 OPEN "O",l,"DEMOFILE"
15 FOR 1=1 TO 3
20 INPUT A$,B$,C$
52 Using CP/M

30 PRINT#l,A$;",";B$;",";C$
40 NEXT I
50 CLOSE#l
60 OPEN "I",l,"DEMOFILE"
70 FOR 1=1 TO 3
80 INPUT#l,A$,B$,C$
90 PRINT A$,B$,C$
100 NEXT I
110 CLOSE

Notice the small, but very important, change that


has been made to line 30. Th e data on the fil e now
looks 1 ike

RON,TOM,DAN
FRED,MEG,HARRY (Note the commas)
DICK, BILL, NORMAN

If we write numerical data, as opposed to string


data, to a file we can write

10 OPEN "O",l,"DEMOFILE"
15 FOR 1=1 TO 3
20 INPUT A,B,C
30 PRINT#l,A,S,C
40 NEXT I
50 CLOSE#l
60 OPEN "I",l,"DEMOFILE"
70 FOR 1=1 TO 3
80 INPUT#l,A,B,C
90 PRINT A,B,C
100 NEXT I
110 CLOSE

Notice that on line 30 the fields are delimited by


commas and so we shall have data on the file stored as,
for example

34 45 32
32 21 11
67 68 69

just as it would be if it was printed on the screen. If


we replace the commas in line 30 by semi-colons the
data will be stored as
Using MBASIC 53

44 55 66
66 77 88
77 88 99

So the second v e r s i o n takes up less file space than


the first. You have probably noticed that there is no
need for commas to be specifically printed between the
variable names in the case of numerical data, although
you can put them in if you wish. But the system needs
to know when a str ing of characters starts and finishes
as all strings tend to be of different lengths ;
luckily, numbers are stored i n a standard fixed length
format and thus delimiters are not required in this
case.
The contents of these files were printed out by
using the CP/M TYPE command, not from BASIC of course,
but after control has been returned to the operating
system.
If you are reading a ser ia 1 f i 1 e and ha ve no idea of
how many records there are to be read, then a command
to stop when the end of file marker is found is needed.
That is common practice in all versions of BASIC. But
watch where you put the instruction. The usual thing to
do is to order the commands so that you open the file,
read a record and if i t contains an end of file marker
then stop the reading. Otherwise go back and read the
next record, and so on. However, Microsoft BASIC does
not wo rk in this way. A program to read records until
the end of file is reached will look like this

10 OPEN "I",l,"DEMOFILE"
20 IF EOF(l) THEN 60
30 INPUT#l,A,B,C
40 PRINT A,B,C
50 GOTO 20
60 CLOSE

Note that the test for end of file is.in line 20 and
tha t is the 1 ine to which we loop back every time. In
other words we are saying "if the next thing read from
the file is an end of file marker then ... " ,

Microsoft BASIC also allows us to create and use


random access files. A random file is created by a
similar command to that used in the opening of a serial
file. Thus
54 Using CP/M

10 OPEN "R",1,"RFILE",48

will open a random access file called RFILE with a


record length of 48 bytes. If the record length is not
specified then its default length is 128 bytes.
Remember that a random file is opened for both reading
and writing, since we can access any record directly
and either read the data held there or write new data
into it. All the reading and writing to a random file
is done through a buffer, one record long, which is
defined by a statement such as

20 FIELD#1,38 AS A$,2 AS B$,8 AS C$

where the numbers of bytes to be occupied by the named


variables are specified and must add up to the record
length as indicated in the OPEN statement. All the data
written to a random file must be in string format . When
stored on disk the data is actually converted from
string format into a packed binary format in order to
save space.
Before a record is written into the file its fields
must be placed in the buffer. This is done by using the
LSET and RSET commands. LSET and RSET 1 eft- justify or
right-justify a string into a field, padding the extra
spaces with blanks. Numeric variables are converted
into strings by using MKI$, MKS$ and MKD$, depending on
whether they are to be stored as integers, sing 1 e
precision numbers or double precision numbers. Integers
are kept as a 2-byte string. A single precision number
is stored as a 4-byte string and a double precision
number as an 8-byte string. So we might have a section
of program that looked like this

10 OPEN "R",1,"RFILE",48
20 FIELD#1,38 AS A$,2 AS B$,8 AS C$
30 INPUT X$, Y, Z
40 LSETA$=X$
50 LSETB$=MKI$(Y)
60 LSETC$=MKD$(Z)

Line 40 1 eft-justifies the variable X$ into the 38


bytes allocated to A$. Line 50 converts Y into an
integer and then left-justifies its string equivalent
into the 2 bytes allowed for B$. Finally Z is converted
Using MBASIC 55

into a double precision number and its string


equivalent is placed in the 8 bytes allotted to C$.
The contents of the buffer are transferred to a
specified record of the file by

70 PUT#1, 10

which PUTs the whole buffer into record 10, in this


case, of the file.
In order to retrieve data from a specified record we
use the reverse of PUT, which is GET, and this
transfers the record as a whole into the buffer. Then
we have to decode the numeric data by using CVI,CVS and
CVD to convert back from the string format into an
integer, single precision or double precision number.
So we might write

80 GET#1, 10
90 Y=CVI(B$)
100 Z=CVD(C$)
110 PRINT A$,Y,Z

Notice that we do not have to decode the contents of


the string A$ because it was kept as a string all the
time. This is not true for the other variables used in
this example.
Using files in Microsoft BASIC is not difficult but
you do have to think about exactly how the records
within the files are structured and how the space on
disk is used. This does mean, however, that MBASIC can
be used for writing commercial type programs to quite
considerable effect.
These notes are not intended to be an exhaustive
description of MBASIC; this task is left to the
language manual. They are, however, designed to give a
few pointers to anyone who knows some BASIC already and
who wants to avoid some of th~ possible pitfalls
wi thou t por ing over the manua 1 . One 1 as t thing is the
useful commands that you can actually issue to MBASIC
from CP /M. These are operations that are invoked as
MBASIC is loaded. For example, if you type

A>MBASIC TESTPROG

then not only will the MBASIC interpreter be loaded


into memory but also the BASIC program called TESTPROG
56 Using CP/M

will be load ed and run. You can also issu e more


complicated commands such as

A>MBASIC FILEPROG/S:256

which not on 1 y loads and runs the program ca lIed


FILEPROG but also alters the r ecord size of any random
files used to 256 bytes . Normall y, b y d efault, th e
maximum record size is 128 bytes. The above command
will alter this size.
Finally, while on the subject of files h ere is how
we can save program files on disk in a number of
different forms. If we simply t ype

SAVE "PROGl"

then a file called "PROGl.BAS" will be saved in


compressed binary format on the currently logged driv e .
Type

SAVE "B:PROGl"

and the program will be saved on dri ve B.


Save the program with

SAVE "PROGl",A

and it will be saved in its ASCII characters so that it


can be edi ted if need be by a word-processing package
such as WORDSTAR or by CP/M 's own ED.
Save the prqgram with

SAVE "PROGl",P

and it will be saved in an encoded binary format and


any attempts to list it or edit it will not succeed. It
can onl y be run. A protected program cannot be un
protected . Note, by the way, that MBASIC does not
differentiate between upper-case and lower-case
instructions: the line

10 INPUT X

is just the same as

10 input x
Using MBASle 57

But you do need to be careful with anything in


in verted commas - and tha t inc 1 udes program names. If
you type the command

load "progl"

you will get the "program not found" message, if you


saved the program as "PROG1" .
To leave l-lBASIC for CP /M i t is alwa ys best to type

RESET

which updates th e disk directory and c loses any f il es


that you may ha ve left open. Then you can type

SYSTEM

which will return you back to CP/M.


8 Using a Compiler

The CP /M operating s ystem allows th e use of man y


different languages apart from MBASIC, which is
probabl y the commonest. MBASIC was conc ei ved, and is
widely used, as an interacti ve languag e to enabl e
programmers to learn the techniques of programming. The
commands and program instructions are e xecu t e d either
in an "immediate " mode, when the comput er i s made to
behave as if it were a desk calculator, or after the
command RUN has been issued. This is dealt with in more
detail in the previous chapter. A compiled language, on
the other hand, has its programs initially written as a
string of text characters and thus they c a n be created
by any editor that works under CP/M, for e xa mp l e its
own ED uti 1 i ty, WORDSTAR, T/ MA KER or any other text
editor that produces a set of ASCII characters . In the
example shown in Chapt er 6 we ha v e us ed ED to cr eate
and subsequently modify a CBASIC program.
CBASIC is a version of MBASIC which will produce
programs that run faster and more efficiently than the
same programs written in interactive MBASIC . The
interacti ve v e r s i o n of the language stores the program
in what is called its "source" form and each time it is
run a process has to be carried out that conv erts the
program from its source form into a sequence of
instructions that can be understood and acted upon by
the processor. For a fuller explanation of this see the
author's "Mastering Computer Programming" (Macmillan,
1982), Chapter 1. Interpreting a program into a machine
readable form is very slow and takes up a lot of
processor time. However, if a program can be stored in
such a way that this conversion process is by-passed,
much time will be saved and more efficient use of the
processor is made. The CBASIC compiler is a program
that accepts lines of text as input. It then analyses

58
Using a Compiler 59

these lines according to the rules of CBASIC, which are


laid down in its own manual, and outputs a file that is
much clos er to the machin e code that the processor
understands. If the program runs successfully then the
source program can be discarded and this intermediate
file is the one that is used at run-time .
CBASIC consists of two programs, one called CBAS2,
or CBAS86, and another called CRUN2, or CRUN86 . Which
one is used depends on whether you are using 8-b i t CP/M
or the 16 -bit CP /M -86. The input file to CBAS2 must
have the file extension .BAS and after compilation a
new file is created, called by the same name as the
original program but with a .INT extension (that is,
the intermediate file). CRUN2 then takes over and runs
the intermediate file. The file with the .BAS extension
can be stored away on another disk and the .INT file is
the working one. If any amendments have to be made to a
CBASIC program then the . BAS file has to be edited.
This is recompiled and replaces the previous . I NT file.
In order to show how CBASIC compares with BASIC we
will write a simple three lin e program; first of all in
BASIC

10 FOR 1%=1 TO 50
20 PRINT I %;I %~2
30 NEXT 1%

This, of course, runs easi 1 y and with expected


results. Then we save this program as it stands, but in
ASCII format - this means that it is stored as a string
of characters just as it is typed in at the keyboard.
We do this by typing

SAVE "PROG",A

By doing this we will in fact have saved the program


with an automatic .BAS extension, so if we issue a DIR
command to CP/M we will see that the system has called
our program PROG.BAS.
Then we present our program to the CBASIC compil er
program by typing

CBAS86 PROG (No need for the .BAS extension)

and we get
60 Using CP/M

CBASIC/86 COMPILER VER 1.00


COPYRIGHT COMPILER SYSTEMS INC.
1* 10 FOR 1 %=1 TO 50
2* 20 PRINT I %;I %~2
3* 30 NEXT 1 %
4: END
NO ERRORS DETECTED
CONSTANT AREA : 8
CODE SIZE : 38
DATA STMT AREA: 0
VARIABLE AREA : 8
A>

Notice that the compiler has placed an END statement


after our last program instruction, so we will ne ed to
watch our programming and make sure that we do not
place an END in the middle of a program, as we do
sometimes instead of using the STOP instruction. END is
a word understood by the compiler to mean that the end
of the program to be compiled has been r each ed. As
there are no errors detected in our use of the
1 anguage, then we can run the compi 1 ed pr ogram b y
typing

CRUN86 PROG

and the program will run just as it did using the


interpreter version of the language.
However, we can modify the program by taking out the
1 ine numbers, using the edi tor, ED, see chapter 6, and
we end up wi th a program that looks 1 ike

FOR 1%=1 TO 50
PRINT I% ;I %A2
NEXT 1%

This can be compiled

CBASIC86 PROG

CBASIC/86 COMPILER VER 1.00


COPYRIGHT COMPILER SYSTEMS INC.
1: FOR 1%=1 TO 50
2: PRINT I%;I%A 2
3: NEXT 1%
Using a Compiler 61

4: END
NO ERRORS DETECTED
CONSTANT AREA: 8
CODE SIZE: 38
DATA STMT AREA: 0
VARIABLE AREA: 8
A>

and the program will run just as before . Note, by the


way, that the compiler supplies line numbers, which do
not form part of the program. They are for reference
purposes only.
As another example, let us look at a simple
mathematica 1 routine for ca lculating square roots. In
MBASIC it looks like this

10 FOR 1=1 TO 4
20 READ X
30 Xl=l
40 Y=(Xl+X/Xll /2
50 IF Xl=Y THEN 100
60 Xl=Y
70 GOTO 40
100 PRINT Y
110 NEXT I
120 STOP
130 DATA 10,100,1000,10000

which when run results in the following output

3.162278
10
31.62278
100

We save the program in its ASCII form under the name


of ROOTS and then exit from MBASIC. We are then back in
CP /M and we can compile our program quite
satisfactorily using CBAS . But when we come to run the
program, apparently nothing happens. There is no result
at all displayed on the screen. It becomes obvious
after a time that the program has gone i nt o an endless
loop and the usual CONTROL-C will not stop the program.
The computer has to be re-booted before the program can
be edited and tried aga in. What is needed is a
modification to the fifth line of the program, as shown
62 Using CP/M

below

CBAS86 ROOTS

CBASIC/86 COMPILER VER 1.00


COPYRIGHT COMPILER SYSTEMS INC.
1* 10 FOR 1=1 TO 4
2* 20 READ X
3* 30 Xl=l
4: 40 Y=(Xl+X/Xl) /2
5* 50 IF ABS(Xl=Y) <.OOOOOl THEN 100
6* 60 Xl=Y
7* 70 GOTO 40
8: 100 PRINT Y
9* 110 NEXT I
10* 120 STOP
11* 130 DATA 10,100,1000,10000
12: END
NO ERRORS DETECTED
CONSTANT AREA : 16
CODE SIZE : 86
DATA STMT AREA: 20
VARIABLE AREA: 32
A>

Note that the lines of th e program that carry


redundant line numbers from the original MBASIC program
have a * after them.

Now if we run this we get

CRUN86 ROOTS
CRUN86 VER 1. 00
COPYRIGHT 1981 COMPILER SYSTEMS INC.
3.16227766017
10
31.6227766017
100
A>

So now we should be in a position to write a simple


CBASIC program from scratch, remembering that there is
no "direct" way of writing the program as when we use
the BASIC interpreter. We have to enter the program
using the editor, save the program as a text file and
then present it to the CBAS compiler. If that produces
Using a Compiler 63

no error messages then we can run the program using the


CRUN program. But before we do this let us be a little
more adventurous and write a sl ightly more complex
program, just to get the feel of CBASIC. The program is
this, in BASIC

10 FOR 1=1 TO 50 STEP 0.25


20 PRINT I;TAB(8);I
A2;TAB(20);SQR(I)

30 NEXT I

and this works without any problems. So we save it in


ASCII form and present it to the CBAS compiler. We will
get

CBAS86 PROGl

CBAS /86 COMPILER VER 1.00


COPYRIGHT 1981 COMPILER SYSTEMS INC.
1* 10 FOR 1=1 TO 50 STEP 0.25
ERROR FE IN LINE 1 AT POSITION 8
2* 20 PRINT I;TAB(8);I
A2;TAB(20);SQR(I)

3* 30 NEXT I
4: END
1 ERROR DETECTED
CONSTANT AREA: 16
CODE SIZE: 66
DATA STMT AREA: 0
VARIABLE AREA: 8
A>

So something has gone wrong. If we look in the error


message list in the CBASIC manual we will find that it
says that we have a " FOR" error. This means that we
have what is called, in CBASIC, a "mixed mode"
expression - something we never normally worry about in
"ordinary" BASIC. What we have in fact is a statement
in the first 1 ine of the program - position 8 refers to
the fact that there is something wrong with the
variable I - with some inconsistency. The cure is to
insist that all the variables are of the same type,
because we are asking the variable to be incremented in
steps of 0.25, not 1 as before. I is a counting
variable and has to be forced to count, not in integers
but in floating point numbers. So we have to resolve
the ambiguity by expressing the target variables in the
loop as decimals . Then all is well . To look at the
64 Using CP/M

topic of storage of variables in mor e detail the reader


is r eferred to Gos 1 ing and La a r h o v e n is "Codes for
Computers and Microprocessors" (Macmillan, 1980). The
result of making this alteration and the elimination of
line numbers will result in this

CBAS86 PROGI

CBAS /86 COMPILER VER 1.00


COPYRIGHT 1981 COMPILER SYSTEMS INC .
1: FOR 1=1.00 TO 50.00 STEP 0.25
2: PRINT IiTAB(8)iI A2iTAB(20)iSQR(I)
3 : NEXT I
4 : END
CONSTANT AREA : 32
CODE SIZE: 67
DATA STMT AREA: 0
VARIABLE AREA : 8
A>

Now let us look at the specimen CBASIC program


created in chapter 6 by ED. It was saved under the name
of DEMO.BAS and when we present it to CBAS86 remember
that we need not bother to use the .BAS extensioni
CBAS looks for i t without our help. CBASIC is fairly
similar to, but not exactly the same as, MBASIC and so
it is tempting to suppose that we can wr ite a program
more or 1 ess as in MBASIC but wi thout the 1 ine numb ers,
as in fact we have already s e e n r always provided that
we remember some of the little quirks relating to the
storage of numbers. Having been caught already, we look
at the manual and find that the statement to open a
file is slightly different and that the instruction to
print to a file is also different in that we need a
semicolon instead of a comma after the file number. So
we create our file of program statements and, having
saved it away, proceed to give it to CBAS86 to see what
happens

A>CBAS86 DEMO

CBASIC/86 COMPILER VER 1.00


COPYRIGHT 1981 COMPILER SYSTEMS INC.
1: REM***DEMONSTRATION CBASIC PROGRAM***
2: OPEN "DEMFILE" AS 1
3: INPUT "HOW MANY RECORDS "iN
Using a Compiler 65

4 : FOR I = 1 TO N
5: INPUT "TYPE IN A STRING ";A$
6: PRINT#l;A$
7: CLOSE 1
8: END
NO ERRORS DETECTED
CONSTANT AREA: 8
CODE SIZE: 108
DATA STMT AREA: 0
VARIABLE AREA: 24
A>

That looks good; we seem to have got our program


right first time. So we attempt to run it

A>CRUN86 DEMO (Again, CRUN86 assumes that


the file has a .INT extension)

CRUN86 VER 1.00


COPYRIGHT 1981 COMPILER SYSTEMS INC .

ERROR OE

A>

Something appears to have gone wrong . The program


has compiled correctly, so we must have used correct
CBASIC statements, but it has failed to run owing to an
er ror of logic somewhere. We must return to the manual
and find out what ERROROE stands for. So back to the
manual. In i t we wi l l find that error OE is an "OPEN"
error and this means that we have attempted to open a
file that does not exist. CBASIC insists that before we
wri te to a new f i 1 e we must CREATE i t first. MBASIC i s
very forgiving and if a file does not exist i t will
create one for us. CBASIC does not work that way - also
its error messages are not quite so helpful. We always
have to go back to the manual.
Having found out that we have to create a file
before opening i t for output, we go back to the editor
and insert a new line. Then we try again

A>CBAS86 DEMO

CBASIC/86 COMPILER VER 1.00


COPYRIGHT 1981 COMPILER SYSTEMS INC.
66 Using CP/M

1: REM***DEMONSTRATION CBASIC PROGRAM***


2: CREATE "DEMFI LE " AS 1
3: OPEN "DEMFILE" AS 1
4: INPUT "HOW MANY RECORDS ";N
5: FOR I = 1 TO N
6: INPUT "TYPE IN A STRING ";AS
7: PRINT#!; AS
8: CLOSE 1
9: END
NO ERRORS DETECTED
CONSTANT AREA: 8
CODE SIZE: 126
DATA STMT AREA: 0
VARIABLE AREA: 24
A>

Again, our use of the language is correct, otherwise


we will get compiler error messages which tell us that
our "syntax" is in error. So we have anoth er tr y at
running the program

A>CRUN86 DEMO

CRUN86 VER 1.00


COPYRIGHT 1981 COMPILER SYSTEMS INC.

ERROR OF

A>

Now error OF tells us that an attempt has been made


to OPEN or CREATE a file with a number that was already
active. This means that if we OPEN a file it must be in
existence already, but if we CREATE a file we do not
need to OPEN i t . So a further piece of program has to
be written which sees if a file already exists. If it
does not, then it is CREATEd; if it does exist, then it
is OPENed. The re-arranged first six lines of the
program do just that. So now we can try again

A>CBAS86 DEMO

CBASIC /86 COMPILER VER 1.00


COPYRIGHT 1981 COMPILER SYSTEMS INC.
1: REM***DEMONSTRATION CBASIC PROGRAM***
2: IF END#l THEN 5
Using a Compiler 67

3: OPEN "DEMFILE" AS 1
4: GOTO 10
5: 5
6: CREATE "DEMFILE" AS 1
7: 10
8: OPEN "DEMFILE" AS 1
9: INPUT "HOW MANY RECORDS ";N
10: FOR I = 1 TO N
11: INPUT "TYPE IN A STRING ";A$
12: PRINT#l;A$
13: CLOSE 1
14: END
NO ERRORS DETECTED
CONSTANT AREA: 8
CODE SIZE : 135
DATA STMT AREA: 0
VARIABLE AREA: 24
A>CRUN DEMO

CRUN86 VER 1.00


COPYRIGHT 1981 COMPILER SYSTEMS INC.
HOW MANY RECORDS 4

TYPE IN A STRING FRED

TYPE IN A STRING GEORGE


TYPE IN A STRING HENRY

TYPE IN A STRING JOANNA

A>

So it works at last. Notice how each time a change


is made we have to go back to the editor to edit the
file with the .BAS extension. That file is compiled and
then the resulting .INT file is run. The effort is
really worth it. Now all we have to do is to tidy up
the program and make it look better. Back to the editor
again and then

A>CBAS86 DEMO

CBASIC/86 COMPILER VER 1.00


COPYRIGHT 1981 COMPILER SYSTEMS INC.
1: REM***DEMONSTRATION CBASIC PROGRAM***
2: IF END#l THEN 5
68 Using CP/M

3 : OPEN "DEMFILE" AS 1
4 : GOTO 10
5: 5
6 : CREATE " DEMFI LE" AS 1
7: 10
8 : OPEN "DEMFILE" AS 1
9 : I NPUT "HOW MANY RECORDS ? : " ;N
10 : FOR I = 1 TO N
11 : PRINT "TYPE IN A STRING #:" ;1 ;
1 2: INPUT A$
1 3 : PRINT# l ;A$
1 4 : CLOSE 1
15 : END
NO ERRORS DETECTED
CONSTANT AREA : 8
CODE SIZE : 1 47
DATA STMT AREA : 0
VARIABLE AREA : 24
A>CRUN86 DEMO

CRUN86 VER 1 .00


COPYRIGHT 1981 COMPI LER SYSTEMS INC.
HOW MANY RECORDS ? : 5

TYPE IN A STRING # : 1 ? TOMMY

TYPE IN A STRING # : 2 ? HARRY

TYPE IN A STRING # : 3 ? KENNETH

TYPE IN A STRING # : 4 ? JOSEPHINE

TYPE IN A STRING # : 5 ? LARRY

A>

So there we are. Th is method of creating, compil ing


and running programs - provided that you have bought
the correct software - i s us ed fo r handling programs
written i n FORTRAN, COBOL, PL /l and other compiled
languages.
9 ASM, the CP/M Assembler and
DDT

If you r ea lly want to get to the "heart" of a computer


system then it is necessary to learn to talk to it in,
as near as possible, a language that it understands.
Using high-level programming languages such as MBASIC
means that you are talking to the computer through an
interpreter and hence all the instructions that you
issue in a program take that much longer to be carried
out. That is why we use a compiler; see chapter 8. But
even if we use a compiled language we cannot control a
number of aspects of the computer 's operation at what
we could call the "bit level". This is the lowest level
of communication with the microprocessor and in the
past, when computers were still in their infancy, this
was the only way of programming. It was actually
performed in the binary code of zeros and ones. This is
not surpris ing since this is the only kind of code that
the processor understands. High-level languages have
taken a lot of the hard work out of programming, but a
lot of detail has been lost on the way. It is only by
using what we call "Assembler Code Programming" that we
can, when necessary, get down to the fine detail of
making the computer do exactly our bidding.
An assembler code uses references to the actual
locations i n the computer's memory, rather than the
more general "variable name" used in, say, BASIC . It
also r e f e r s to a number of "registers" which the
microprocessor uses in the course of its arithmetic
operations . The tasks involved in, say, performing a
simple arithmetic operation have to broken down into
their elements. This can, with careful programming,
result in far more efficient use of the memory
available. For a full explanation of the Z8D assembly
code the reader is recommended to study Roger Hutty's
"Programming in Z8D Assembly Language" (Macmillan,

69
70 Using CP/M

1984). The content of this chapter are just a brief


explanation of how CP/M treats assembler cod e and how a
program is written and run under CP/M.
The sequence of events leading up to running a
program using this programming language is as follows.
First of all a source code program is entered using
either a word -processing package, such as WORDSTAR, or
CP/M 's own ED utility in just the same wa y as a program
in a high-level language which needs compiling. The
program must have a name that has the extension . AS M.
Then this program is assembled into what is known as
"machine code" by the assembler, the program b eing
known as ASM.COM. This produces two further files with
the same names as the original program but with the
extensions .PRN and .HEX. The first of these is a copy
of the source file, the original .ASM file, but with
line numbers and the actual locations allocated to the
various instructions in the program displayed. Th e .HEX
file is a file containing the program instructions but
expressed in hexadecimal form. It is this file that has
to be presented to the program called LOAD.COM in order
to produce an executable program, this time with a . COM
extension. It is this program, which is in binary
format, and hence closest to the language that the
microprocessor under stands, that is actually executed
by CP/M.
In order to understand what is going on, it is
necessary to describe a 1 i t t l e about how the
microprocessor is constructed. The Zi log Z8D
microprocessor chip consists of nine 8-bit registers
and four 16-bit registers.
The 8-bit registers are

Register A - the Accumulator.


Register F - the Flag Register
Registers B,C,D,E,H,L - secondary or temporary registers
Register I - the Interrupt vector register

Registers Band C, 0 and E, Hand L can be combined


into three 16-bit registers if needed.

The 16-bit registers are

Register SP - the stack pointer register


Register PC - the program counter
Register IX - X index register
ASM. the CP/M Assembler and DDT 71

Register IY - Y index register

Each memory location used by the zao is a bits (one


byte) long. In the course of assembler code programming
we use the convention that by enclosing an address
within brackets we are saying "the contents of the byte
whose address is". Hence (10) means "the contents of
the byte whose address is 10 ",
A program written in zao Assembler Code takes
the form

(1) a label followed by :


(2) an "opcode" followed by one or more operands
(3) i followed by a comment which is ignored by the
assembler

The labels and comments are optional but each field


must be separated from the next by a space. A line
cou I d just consist of a comment. A typica 1 1 ine of code
might therefore be

LABELl: ADD A,A i A x 2

The label is LABELl, the instruction is that the


contents of register A, the Accumulator, must be added
to the contents of A and the comment is that the
effect is of multiplying the contents of the
Accumulator by 2. In other words, the contents of the
Accumulator is added to itself and the result stored
back in the Accumulator. A simple program which will be
used to illustrate just how the assembler is used is
taken from Roger Hutty's book, page 12, Program 3.1. We
type it in using an editor and saving it under the name
of DEMO.ASM. The program is

ORG 100H
PROGRAM 3.1 MULTIPLIES TWO NUMBERS BY 4

LD A,(Nl) istart of main program


CALL QUAD icompute Nl x 4
LD (Rl),A iRl=Nl x 4

LD A, (N2)
CALL QUAD
LD (R2),A iR2=N2 x 4
HALT
72 Using CP/M

Nl: DEFB 31
N2: DEFB 25
Rl: DEFB 0
R2: DEFB 0

; Subroutine - multiplies the accumulator b y 4

QUAD: ADD A,A A x 2


ADD A,A (A x 2) x 2 A x 4
RET

Notice how the program is made legible by th e us e of


blank comment lines. Some explanation about what is
going on is now required. The first instruction - ORG
lOOH - tells the assembler program that the first
instruction is to be stored in location lOOH, the start
of the TPA - see chapter 1. The Hat the end te 11 s the
assembler that the number is in hexadecimal notation. B
after a number indicates that it is coded in binary . 0
or Q denotes an octal number and D, or no code at all,
is a decimal number.
The line that says "LD A,(Nl)" is the instruction to
load the contents of the location known as Nl into the
Accumulator. The "DEFB 31" with the label Nl is the
instruction that the location known as Nl, its actual
location will be allocated by the assembler later, is
to contain the number 31. DEFB actually stands for
"DEFine a Byte value ". The two numbers are called Nl
and N2 and the results of the multiplication by four
are to be stored in locations, initially set to zero,
called Rl and R2. The subroutine labelled QUAD is
called in order to perform the multiplication in the
Accumulator, where all arithmetic operations end up,
and then the contents of the Accumulator are stored in
the appropriate places after the calls to QUAD . RET is
the instruction to return to the main program from the
subroutine and HALT is the instruction for the program
to stop.
We can actually see what the contents of memory are
when DEMO.ASM is resident in memory by using the DUMP
utility. This tells us exactly what characters are
stored in specific memory locations

A>DUMP DEMO.ASM
ASM, the CP/M Assembler and DDT 73

0000 20 20 20 20 20 20 20 20 20 20 20 4F 52 47 20 31
0010 30 30 48 00 OA 3B 20 50 52 4F 47 52 41 40 20 33
0020 2E 31 20 40 55 4C 54 49 50 4C 49 45 53 20 54 57
0030 4F 20 4E 55 40 42 45 52 53 20 42 59 20 34 00 OA
0040 3B 00 OA 20 20 20 20 20 20 20 20 20 20 4C 44 20
0050 41 2C 28 4E 31 29 20 3B 53 54 41 52 54 20 4F 46
0060 ........
If you translate the above portion of the file
DEMO.ASM from the hexadecimal form into ASCII
characters you' will see that the text that constitutes
the file is stored in memory starting at location 0000.
The commonest character is 20H which is a space, 4FH is
"0", 52H is "R", 47H is "G", 31H is "1", 30H is "0" and
so on. ODH is the "CARRIAGE RETURN" character and OAH
is " LI NE FEED", so it is all there exactly as it was
typed in and stored in memory. A dump of this type is
often the 1 ast resort of the programmer whose program
will not work and there are those in that profession
who can read a dump just as you or I wou 1 d read Eng 1 ish
text!
Now let us submit this text file, because that is
what it is, to ASM.COM as follows

A>ASM DEMO No need for the .ASM extension


ASM Z80 ASSEMBLER V 3.0 A

7E42 bytes free


No errors
A>

At this point a file called DEMO.PRN and a file


called DEMO.HEX have been created and we can see what
they contain by telling CP/M to type them out

A>TYPE DEMO.PRN
0100 ORG 100H
PROGRAM 3.1 MULTIPLIES TWO NUMBERS BY 4

0100 3A1301 LD A, (N1) ;start of main program


0103 CD1701 CALL QUAD ;compute N1 x 4
0106 321501 LD (R1) ,A ;R1=N1 x 4

0109 3A1401 LD A, (N2)


010C CD1701 CALL QUAD
74 Using CP/M

OlOF 321601 LD (R2),A ;R2=N2 x 4


0112 76 HALT
0113 IF Nl: DEFB 31
0114 19 N2: DEFB 25
0115 00 Rl : DEFB 0
0116 00 R2: DEFB 0

Subroutine - multiplies the accumulator by 4

0117 87 QUAD: ADD A,A A x 2


0118 87 ADD A,A (A x 2) x 2 A x 4
0119 C9 RET

0113 Nl 0114 N2 011 7 QUAD 0115 Rl 0116 R2

The first of the two columns down the left-hand side


is a 1 ist of addresses, starting with address 100 (in
hexadecimal). The second col umn 1 ists th e contents of
the addresses. This means that the address 100 contains
the characters "3A", the address 101 contains "13" and
102 contains "01". You might notice that the contents
of 101 and 102 contain the address of the number to be
loaded into the Accumulator; but, as is always the
case, backwards . The high byte (1 3) comes before th e
low byte (01) which is the address 0113. And we s ee
that location 113 contains the hexadecimal number IF,
which is 31 in decimal and location 115 contains zero,
which is what we want them to contain. The label QUAD
is stored at location 117 so that when the program
jumps to the subroutine the actual location of the
first instruction in it is known . This happens because
both locations 103 and 10C contain the code CD followed
by the address to jump to, which is coded as 1701 -
location 0117 which is where the label QUAD is stored.
The last line printed is the symbol table which
gives us the addresses of each of the labels that we
have used in the program.
If we type out the contents of DEMO. HEX we will
get

A>TYPE DEMO. HEX


:100100003A1301CD17013215013A1401CD1701320E
:OAOII0001601761F1900008787C949
:0000000000
ASM , the CP/M Assembler and DDT 75

which, hopefully, you can see contains all the


information about the program : its start address and
the coded contents of all the locations.
Finally, the .HEX file has to be converted into a
binary file with a .COM extension and this is done by
the LOAD command

A>LOAD DEMO Note how the extension is not


required. LOAD looks for a
file with the .HEX extension

and we will get a response such as

FIRST ADDRESS 0100


LAST ADDRESS 0119
BYTES READ OOlA
RECORDS WRITTEN 01
A>

Now we can run the program from CP/M simply by


typing its name, since we have a file called DEMO.COM.
But since this is a program that produces no output on
the screen, there is going to be nothing learned by
typing

A>DEMO

since all that will happen is that the computer will


stop dead. We can see just what is happening and why
that takes place by using the very powerful utility
ca 11 ed DDT (Dynami c Debugging Too 1). Thi s program
enables us to look at a program and see just what is
going on i n memory and the various registers used by
the Z80 microprocessor. All we do is to type

A>DDT DEMO.COM

and get the response

DDT VERS 2.2


NEXT PC
0180 0100

The number under PC gives us the in it ial value of


the program counter, in this case 0100 which is the
76 Using CP/M

starting address of the program that is now in memory.


In other words it tells us that the first instruction
in the program is held in location 0100. Under the word
NEXT is the location number 0180. This is the first
location after the end of the loaded program. CP /M
always allows us spare space after a loaded program, as
you will see shortly.

The - sign is DOT's prompt. It now waits for a


command. The command L will cause us to get a listing
of the program instructions starting from the
instruction in location 0100. So we get

0100 LOA 0113 (LOA means "load the


0103 CALL 0117 Accumulator")
0106 STA 0115 (STA means "store the contents
0109 LOA 0114 of A")
OlOC CALL 0117
OlOF STA 0116
0112 HLT
0113 RAR
0114 DAD 0
0115 NOP (NOP is "no-op" - zero in location)
0116 NOP

If we press L again we would get the instructions in


the next ten locations

-L
0117 ADD A
0118 ADD A
0119 RET
011A NOP
011B NOP
011C NOP
0110 NOP
011E NOP
011F NOP
0120 NOP

These are the remaining instructions followed by


NOPs, as you will see next. The NOPs in locations 115
and 116 are zeros because we requested the program to
p I ace zeros there. They are, after all, the locations
labelled Rl and R2.
What the L instruction has actually done is to
ASM , the CP/M Assembler and DDT 77

"dis ass em b l e" th e h e xade c i ma l cod e which is s t o r e d in


me mo ry. Howe v er, y o u ma y not ice that th e c od e int o
which the program ha s now been con vert ed i s not in the
form of the zao mnemonics that we start ed wi t h. The
significance of thi s wi l l b e s een shortl y.
We can now look into memor y b y asking fo r a du mp.
Th is list s memor y address es down th e left -hand side,
then their contents in hexadecimal c ode and finall y on
th e right -hand si de th e ASCII e q u iva l e n t of th es e
codes, if the y can be translated.

-0
0 100 3A 1 6 0 1 CO 1 3 0 1 3 2 76 00 3A 17 01 CO I 3 01 32 : . . ... 2 v .: . . . .. 2
0 110 78 00 76 87 87 C9 I F 1 9 00 00 00 00 00 00 00 00 x .v . . .. . .. . . . . . .
0 120 00 00 00 00 00 00 00 00 00 00 00 00 00 0 0 00 00 . . . . . ...... .... .... . . . .
0130 00 00 00 00 00 00 00 00 00 00 00 00 00 0 0 00 00 . . .... . . . . . . . .... ......
1040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 . . . . . .... ...... . .... ......
10 50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 . . ...... . . . .... . . . .... .
1060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .... ...... . . .... . . .... .... .
1070 00 00 00 00 0 0 00 00 0 0 00 00 00 00 00 00 00 00 . .... . . . .... .... ........ ....
1080 I A 84 12 13 C3 69 01 01 2E 00 E9 DE 1 0 CO 0 5 00 . . . . . i . .. . . . . . . .
1090 3 2 5F I E C9 2 1 66 IE 7 0 2B 7 1 2A 65 I E EB DE I I 2_ . . !f.p+q*e ... .
lOAD CO 05 00 32 5 F IE C9 II 00 00 DE 12 CO 05 00 3 2 . .. 2- .. . .• .. . . . 2
lOBO 5 F I E C9 2 1 58 I E 70 2B 71 2A 67 IE EB DE 13 CD _ . . ! h . p +q *g . . .. .

Th is tell s u s that location 100 conta in s th e


hexadecimal code 3A, 0101 c o nt a i n s 1 3 and so on . If yo u
look in the tabl e of ASCII codes and thei r equi valents
in hexadecimal given in appendix A, yo u will find t hat
3AH is a colon ( ":"), 32 H i s the di git 2 and 76H i s
"v " , If the c o d e ha s no ASCII equival ent then DDT do es
its b es t to transla te, or prints a full st op. If fa ct
if you take a look around an y CP /M .COM f il e y o u wi l l
usuall y find text gi ving a c o pyr i g ht notice

07 40 43 4 F 50 59 5 2 49 47 4 8 5 4 2 0 3 1 39 38 3 1 20 4 3 COPYRIGHT 198 1 C
0750 4F 40 50 49 4C 4 5 52 20 53 59 53 54 45 40 53 2C OMPILER SYSTEMS ,
0760 20 4 9 4E 43 00 OA 45 4E 4 4 00 OA 00 18 23 DC 28 INC . . ENO . . . . # . (

But going back to our example, we can use DDT to see


just what is happening as the program proceeds. To do
th is we use the Trac e instruction and tel l DDT to
execute a number of instructions. In our example there
are i n total twelve instructions after the first one to
be executed f rom start to f inish . So we t ype
78 Using CP/M

- T 12
COZOMOEOIO A=OO B=OOOO D=OOOO H=OOOO 5=0 100 P~O I O O LOA 0113
COZOMOEOI O A= IF B=OOOO 0=0000 H=OOOO 5=0100 P=0103 CALL 0 1 17
COZOM OEO IO A=I F B=OOOO 0 =0000 H=OOOO 5 =OOFE P =0117 AOD A
COZO MOEO II A=3E 8 =000 0 0=0000 H=OOOO 5=00FE P=0118 AOO A
COZOM OEO II A=7C B=OOOO 0 =0000 H=OO OO 5 =00FE P =0 1 19 HET
COZOMOEO II A=7C B=O000 0=0000 H=OOOO 5=0100 P=0 106 5TA 01 15
COZOM OEO II A=7C B=OOOO 0 =0000 H=OOOO 5 =0 100 P =0 109 LOA 0 1 14
COZOMOE OI I A=19 B=OOO O 0=0 00 0 H=OOOO 5= 0 100 P=O IOC CALL 0 117
COZOMOEOIl A=19 B=OOOO 0=0000 H=OOOO 5= 00FE P=0 1 17 AOO A
COZOM OEOII A=32 B=OOOO 0=0000 H=OOOO 5 =00FE P=0 1 1 8 ADD A
COZOMOEOIO A=64 B=OOOO 0 =0 000 H=OOOO 5=00FE P= 0119 I<ET
COZOM OEOI O A=64 B=OOOO 0 =0000 H=OOOO 5 =0 10 0 P=OI 0 F 5TA 0 1 16
COZOMO EOI O A=6 4 B= OOOO 0 =0 0 0 0 H=OOOO 5 =0100 P =0 1 12 HLT

Yo u should be abl e to s e e th at th e c o n te n ts o f th e
Accumula to r , A, go fr om IFH ( 31 0) to 3 EH (6 2 0 ) to 7 CH
(12 40) and then from 1 9H (2 50) to 32 H ( 50 0 ) a nd fin all y
to 6 4H (1000). Th e p r o g ra m c ounter, P , goe s in ord e r t o
the locations wher e th e instructions ar e s t o red , n amel y
100,10 3,1 17,118,11 9,106,10 9, 10C, 11 7, 11 8, 1 19 ,
10F and finall y to 11 2 which i s wh er e the HALT
inst ruction is s t o red.
The t en charact ers at th e sta rt o f e ach 1 in e tell u s
the state o f C (the carr y flag), Z ( th e z ero f la g ) , M
(t he minus flag), E (the eve n p a r i ty fl ag) a nd I (th e
inter-digit car r y flag) . Thes e a re s et, a s yo u can s e e ,
ei t h e r to z e ro or unity.
Th e T command allo ws y o u manu all y to ste p through
th e p rogram on e i n s t r u c t i o n at a t ime. In this ca s e we
get an output similar to that we g et from the "global"
T12 comm and to e x ecut e tw el ve comm ands . Th e only
diff erenc e i s that we ar e gi ven the addr ess of the
next instruction to be executed at the end of th e line .
This i s shown below

-T
COZOMO EOIO A=OO B=OOOO 0 =0000 H=OOOO 5 = 01 00 P=O IOO LOA 0 11 3* 01 0 3

A fu r t he r T comma n d wi l l p r oduce thi s

-T
COZOMOEOI O A=I F B= OOOO 0 =00 0 0 H=OO OO 5=010 0 P =010 3 CALL 0 1 1 7 *0 1 17

and s o o n .
To e x i t f r o m OOT t o CP /M pre s s GO.
ASM . the CP/M Assembler and DDT 79

Now, it is quite possible that y o u might want to tr y


out this program, or one similar to it, y o u r s e l f . So
off you go and type in the program using the editor,
and when you attempt to assemble i t you get the
following

CP/M ASSEMBLER - VER 2.0


100 ORG 100H
S LD A, (Nl) ;START OF MAIN PROGRAM
P0100 CD0601 CALL QUAD ;compute Nl x 4
P LD (Rl) ,A ;Rl=Nl x 4
S LD A, (N2)
P0103 CD0601 CALL QUAD
S LD (R2),A ;R2=N2 x 4
L Nl : DEFB 31
L N2: DEFB 25
L Rl: DEFB 0
L R2: DEFB 0
SOl06 87 QUAD : ADD A,A A x 2
SOl07 87 ADD A,A (A x 2) x 2 A x 4
0109
OOOH USE FACTOR
END OF ASSEMBLY

all of which seems to indicate that everything has not


gone well. If you examine the .HEX file that is
produced, using DDT, you will find that the only
instructions that have been translated are those that
reside in locations as follows

0100 CALL 0106


0103 CALL 0106
0106 ADD A
0107 ADD A
0108 RET

This all looks very confusing until y o u realise that


i t is not only the Zilog Z80 chip that is used in CP /M
systems, but also its "look -alike", the Inte l 8080
chip . This, although it ends up with the same final,
native code, after assembly, needs to be fed with 8080
code and not Z80 code. The end product ma y be the same,
but the source code is different. In fact the assembler
converts from one or the other assembly language into
the same target code. So we have to rewrite the program
using 8080 mnemonics as follows
80 Using CP/M

;An 8080 assembler program similar to Program 3.1


ORG 100H
LOA Nl
CALL QUAD
STA 0118
LOA N2
CALL QUAD
STA 0120
HLT
QUAD; ADD A
ADD A
RET
Nl: DB 31
N2: DB 25
END

The STA, STore the contents of A, command gives the


actual location number where the number is to go. But
beware because, as in this case, if there is no H to
signify tha t the number is in hexadecima 1 it wi 1 1 be
converted from the decimal number into hex. So location
0118 becomes 0076H and 0120 becomes 0078H. presenting
this revised program to the assembler, we get

A>ASM DEMO
CP/M ASSEMBLER - VER 2.0
0018
OOOH USE FACTOR
END OF ASSEMBLY

If we type the .PRN file we see that we have

A>TYPE DEMO.PRN
;An 8080 assembler program similar to Program 3.1
0100 ORG 100H
0100 3A1601 LOA Nl
0103 CDl301 CALL QUAD
0106 327600 STA 0118
0109 3A1701 LOA N2
OlOC CDl301 CALL QUAD
OlOF 327800 STA 0120
0112 76 HLT
0113 87 QUAD: ADD A
0114 87 ADD A
0115 C9 RET
ASM. the CP/M Assembler and DDT 81

0116 IF Nl: DB 31
0117 19 N2: DB 25
0118 END

Next, if we examine the .HEX file we get

A>TYPE DEMO. HEX


:100100003A1601CD13013276003A1701CD130132BO
: 0 8 0 1 1 0 0 0 78 0 0 76 8 7 87C9 1F 1 9EA
:0000000000

A dump, using the command DUMP DEMO. HEX, gives us

0000 3A 31 30 30 31 30 30 30 30 33 41 31 36 30 31 43
0010 44 31 33 30 31 33 32 37 36 30 30 33 41 31 37 30
0020 31 43 44 31 33 30 31 33 32 42 30 OD OA 3A 30 38
0030 30 31 31 30 30 30 37 38 30 30 37 36 38 37 38 37
0040 43 39 31 46 31 39 45 41 OD OA 3A 30 30 30 30 30
0050 30 30 30 30 30 OD OA lA lA lA lA lA lA lA lA lA
0060 lA lA lA lA lA lA lA lA lA lA lA lA lA lA lA lA
0070 lA lA lA lA lA lA lA lA lA lA lA lA lA lA lA lA

Remember that at this point the source code has been


assembled but not loaded, since the starting address
has been specified to be OlOOH, not OOOOH. So we load
it, just as before and we get

A>LOAD DEMO

FIRST ADDRESS 0100


LAST ADDRESS 0117
BYTES READ 0018
RECORDS WRITTEN 01

The next thing is to examine the final code using


DDT

A>DDT DEMO. COM


DOT VERS 2.2
NEXT PC
0180 0100
-L (Lists the "native code")
0100 LDA 011 6
0103 CALL 0 11 3
0106 STA 0076
0109 LOA 0117
82 Using CP/M

OIOC CALL 0 113


OIOF STA 0 07 8
0 112 HLT
011 3 ADD A
0 11 4 ADD A
0115 RET
0116 RAR
-L
011 7 DAD 0
0118 NOP
011 9 NOP
OllA NOP
011B NOP
OllC NOP
0 11 0 NOP
011E NOP
OllF NOP
01 20 NOP
01 21 NOP

A "d ump" of th e program wi l l s how us wh at i s now


s t o re d in th e location s s tarti n g at l oca t i on OIOOH

- 0
0100 3A 1 3 0 1 CO 17 0 1 32 1 5 01 3A 1 4 01 CO 17 01 3 2 : . .. . . S . . : . . .. . 2
0 11 0 16 0 1 76 IF 1 ~ 00 00 87 8 7 C9 00 00 0 0 00 00 00 .. v . .. . .. . .. . . . .
0 120 00 0 0 00 00 00 00 00 00 00 00 00 0 0 00 00 00 00 .. .. .. . ... . .... .
0 13 0 00 00 00 00 0 0 00 00 0 0 00 00 00 00 00 00 00 00 .... . . ........ ...... .... .... .
01 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ........ .... ...... .... . .... . .
01 50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 . . ...... .... ........ ...... . .
0160 00 00 00 00 00 00 00 00 00 00 00 0 0 00 00 00 00 . . .... . .... ...... .... . .... .
0170 00 0 0 00 00 00 00 00 00 00 0 0 00 00 00 00 00 00 . . .... .... .... . . .... .......
0180 lA 8 4 1 2 1 3 C3 69 01 0 1 2E 00 E9 DE 10 CD 05 00 . . . . . i . . . . . . .. . .
0190 32 SF IE C9 2 1 66 I E 70 2B 7 1 2 A 65 IE EB OE 11 2_ .• ! f .p+q *e . . . .
01AO CD 05 00 3 2 SF 1 E C9 11 00 00 OE 12 CD 0 5 00 32 .•. 2- .. .. .. . . . . 2
l OBO SF I E C9 21 68 I E 70 2B 7 1 2A 67 I E EB DE 1 3 CD _ .. !h .p+q*g ... ..

If we ask for a dump of th e contents of th e


locations from OOOOH onward we will see that the
locations numbered 0076H and 0078H are empty

- 0 00 00
0000 C3 03 F2 8 1 00 C3 00 0 4 FF 00 F F 11 FF 00 FF 00 ....... .. .. ... ..
0010 F5 00 FF 1 2 B7 0 0 F F 02 of 00 FF 00 6F 00 FF 90 •• • • • • • • •• •• 0 • • •
00 20 FF 00 FF 1 3 FD 0 0 F F 1 0 EF 00 FF 10 EF 00 FF 42 • . •• . . . • . .. . • . . B
0030 BF 00 FF 4 8 EF 0 0 FF 18 C3 86 DA 1 2 EF 00 6B BE • •• H •••••••• • • k ,
ASM . the CP/M Assembler and DDT 83

00 40 FF 00 FF 00 FF 00 FF 00 FF 0 0 FF 0 0 FF 00 FF 00 .... . . . .... . . . . ...... . .


0050 FF 00 FF 00 FF 00 FF 00 FF 00 FF 0 0 00 44 45 40 . . .. . . . . . . . . . OEM
0060 4F 20 20 20 20 43 4F 40 00 00 80 01 CO 13 01 32 0 COM. ... w •••
007 0 00 00 00 00 00 00 00 0 0 00 00 00 00 01 FB AS 28 ............... (
0080 3A 00 76 87 87 C9 i F 1 9 0 0 00 00 00 00 0 0 00 00 : ..... 2v : .. • . •• 2
0090 78 00 76 87 87 C9 iF 19 00 00 00 00 00 00 00 00 x .v ... .. . . • • ....
OOAD 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 . .... . . . ...... . . . . . ....
OOBO 0 0 00 00 00 00 00 0 0 0 0 00 00 0 0 00 0 0 00 00 00 ...... ...... . .... . . . . . . .

Now i f we t r ac e t h e e x e c u t i o n o f t he p r o gr a ~ b y
t ell ing DD T t o exe c u te th e f i r s t t wel v e in s t ru c t i o n s in
th e pr o gr a m, we c a n see th e mo v e ment o f the dat a
be t ween r e g ist e rs a s b e for e

-T1 2
COZOMOEOIO A=OO B=OOOO 0=0000 H=OOOO 5=0100 P=OlOO LOA 0116
CO ZO MO EOIO A=l F B=OOOO 0 =0 00 0 H=OOOO 5=010 0 P=01 0 3 CALL 0 1 13
CO ZO MOEOIO A=lF B=OOOO 0=0 0 00 H=OOOO 5 =00FE P=01l 3 ADD A
CO ZO MOEO Il A=3E B=OOOO 0= 00 00 H=OOOO 5 =00FE P= 0 114 ADD A
COZ OM OEOIl A=7 C B=O OOO 0 =0 0 0 0 H=OOOO 5=00FE P=0115 RET
COZ OM OEOIl A=7C B=OOOO 0= 0 000 H=OOO O 5=0 100 P=0 106 5TA 0077
CO ZO MO EOIl A=7C B=OOOO 0=000 0 H=OOO O 5 =0 100 P= 0 10 9 LOA 011 3
CO ZOMOEO Il A=1 9 B=OOOO 0=0000 H=OOOO 5 =0 10 0 P=Ol OC CALL 0 11
CO ZO MOEOIl A=1 9 B=OOOO 0 =0 0 0 0 H=OOOO 5 =00FE P=011 3 ADD A
COZOMOEOIl A=3 2 B=OOOO 0=0000 H=OOOO 5=00FE P=O114 ADD A
CO ZOMOEOIO A=64 B=OOOO 0=0000 H=OOOO 5=00FE P=011 5 RET
CO ZOMOEO IO A=64 B=OOOO 0=0 000 H=OOOO 5=0100 P=OlOF 5TA 007 8

An d no w if we dump t h e cont ents o f memor y f rom


l oca ti on OOOO H o nwa rds, we c a n s e e t hat t h e contents of
l o c at i o ns 0 076 H a n d 0078 H h ave c ha nged, as we int ended
that t h e y sho u ld

- 0 00 00
0000 C3 03 F2 8 1 00 C3 0 0 0 4 FF 00 FF 11 FF 00 FF 00 .... ... ..... .. ..
001 0 F5 00 FF 1 2 B7 00 FF 02 OF 00 FF 00 6F 00 FF 90 • . • • • •• . • • • • 0 . . •
0020 FF 00 FF 1 3 F D 00 FF 1 0 EF 00 FF 10 EF 00 FF 4 2 .. .. .. . . . . . . . . . B
00 30 BF 00 FF 4 8 EF 00 FF 18 C3 86 OA 12 EF 00 6B BE • . . H • • •. . • • • • • k ,
0040 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 0 0 .............. .... ........ .... .
0050 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 00 44 45 40 ... •.. . . ... . . OEM
0 06 0 4F 20 20 20 2 0 43 4 F 4 0 00 00 80 01 CO 13 01 32 0 COM . . . . w • • •
0070 00 00 00 00 00 00 7C 00 64 00 00 00 01 FB A5 2 8 ... . . · I· d.. .... (
0080 3A 00 76 87 8 7 C9 I F 1 9 00 00 00 00 00 00 00 00 : .. • • • 2v : •• • • . • 2
009 0 7 8 00 76 8 7 87 C9 IF 1 9 00 00 00 00 00 00 00 00 x . v .. .. . . .. . . ...
OOAO 00 00 00 00 00 0 0 00 00 00 00 00 00 00 00 00 00 . .............. ...... ...... ....
OO BO 00 00 00 00 00 00 0 0 00 00 00 00 00 00 00 00 00 . . . . . . . .... . . .... . .. .
84 Using CP/M

The other commands for DDT are as follows

A<address>
Enter Assembler Code (Assembl e)

F<start address>,<end address),<constant>


Place a specified constant in memor y to/from
an address (Fill)

G<start address>
Go to start address and comm enc e execution from
there

G,<breakpointl>
Execute up to the address of the gi v en breakpoint

G,<start address>,<breakpointl >,<breakpoint2>


Execute from the start address until either of the
two breakpoint addresses are found

GO
Exit to CP/M

H,a,b
Perform hexadecima 1 arithmetic on a pair of
numbers
Display a+b and a-b in Hex (Hex)

I<fi lename>
Input a filename into the File Control Block
preparatory to reading the file (Input)

M<original start address>,<original end address>,


<new start address>
Move a block (Move)

R
Read the file named in the I command into
memory (Read)

S<start address>
Change the contents of a specified address
(Substi tute)

u
ASM, the CP/M Assembler and DDT 85

Execute instructions with register list after


last instruction. The trace command lists
after each instruct ion (untrace)

X
Display the contents of all the registers (Examine)

X<r>
Examine contents of a specified register
10 CP/M Plus (CP/M Version 3.1)

Now that memory is ver y cheapl y and easily available


for microcomputers it is noticeable that, as e a c h yea r
goes by, the size of memor y commonly i ns t a l l e d
increases by a factor of two. At pr esent 64K o f RAM is
the norm for the 8-bit micro and the step up to 128K
has produced a problem . An 8-bit processor cannot
address, directly at least, more than 64K. This is
because the largest integer that can b e stored in a Z8 0
processor address register of 16 bits is 655 35 in
decimal notation, or FFFF in hexadecimal. 65535 is in
fact 64 times 1024 minus 1; lK being, of course, 2 to
the power 10, not 1000.
Howe ver, because of a technique known as "memory
banking" it is now possible to have an 8-bit
microcomputer that can usefully use more than 64K of
RAM. Of course, with a 16-bi t processor we do not ha ve
this problem and memory up to several megabytes in size
can be directly addressed from such a device. But that
is the province of the version of CP /M known as CP/M-
86. This is dealt with in chapter 11.
A memory map of a ~ypical CP /M Plus system which
uses 128K bytes of memory is shown in the figure.
The BIOS is extended to become a version of BIOS
customised for a specific manufacturer's hardware. The
normal BDOS, since it is invariant, is there as well
and a TPA (Transient Program Area) of 60K bytes is
provided. The two banks of memory are of 64K bytes
each.
Because of the extra amount of memory available to
CP/M Plus, it provides a number of features that did
not exist in earlier versions. For example, there is a
HELP facility, an extended DIR command, date and time
stamping on files and the ability to allow several

86
CP/M Plus (CP/M Version 3 .1) 87

BANK 0 BANK 1

Track C-BIOS
Buffers and
(16K Bytes) BOOS

Banked
C-BIOS TPA
and (60K Bytes)
BOOS

OlOOH
CCP
256 Bytes Reserved
OOOOH

independent partitions on a single disk which can be


password protected. In addi tion, there is an extended
assembler known as MAC and a relocatable assembler
which is RMAC; but more of those later, together with
the new version of DDT which is known as SID.
CP/M Plus can control a mixture of disk types, mini-
floppy disks, 8 inch floppy disks and a controller for
a Winchester drive.
The specification of files is now extended so that a
CP/M file can be identified by up to a maximum of four
characteristics . These are the drive name, the
filename, the extension and a password . Thus a filename
can be of the form

drive:filename.extension;password

1. HELP
It is a well-known fact that computer manuals are
difficult to follow, especially for the newcomer to
computing. CP /M Plus allows us to call for help on a
large number of its features and so saves us the
tedious task of hunting for the correct section of the
very extensive manual that Digital Research provide.
All you do is to type

A>HELP

and a list of the features that can be explained to you


88 Using CP/M

will be displayed. You then typ e in the name of the


feature that you are interested in and explanatory text
appears on the screen. For example, we might get

A>HELP ERASE

ERASE

Syntax:

ERASE {filespec} {[CONFIRM]}

Explanation:

The ERASE command removes one or more files from the


directory of a disk. Wild-card characters are accepted
in the filespec. Directory and data space are
automatically reclaimed for later use by another file.
The ERASE command can be abbreviated to ERA.

OPTION

[CONFIRM] option informs the system to prompt for


verification before erasing each file that
matches the filespec. Confirm can be
abbreviated to C.

EXAMPLES

A>ERASE X.PAS

Removes the file X.PAS from the disk in drive A.

A>ERA *.PRN
Confirm (Y/N)?Y

All files with the filetype PRN are removed from


the disk in drive A.

B>ERA A:MY*.* [CONFIRM]

Each file on drive A with a filename that begins


with MY is displayed with the question mark for
confirmation. Type Y to erase the file displayed,
N to keep the file.
CP/M Plus (CP/M Vers ion 3 .1) 89

A>ERA B:*.*
Confirm (Y/N)?Y

All files on drive B are removed from the disk.

Not on I y do es th e HELP c o mma n d t ell yo u how to use


man y o f the CP /M fe a t u re s but also i f y o u t ype

A>HELP HELP

it wi l l t ell y o u how to us e the HELP facilit y i t s e l f.


In add i t ion, i t is p o s s ib le to add other e x p la nat ions
to the HELP fil e, call ed HELP.HLP.

2.DIR
In e a r l ier v e r s i on s of CP/M the DIR command is r esident
wi t h i n CP/ M itself. This st ill e xists, but in addition
th ere is now a DI R.COM f i le which pro vid es u s wi t h a
much mo re comprehensi v e rang e of informat ion about the
f il es on a di sk. For e xample, if we t ype

A>DI R[FU LL]

we wi l l get the files listed in al phabetical ord e r with


all their attributes and much informat ion about how the
space is allocated on the disk. In addition we c an see
from th e v e ry last entr y just how much director y space
has b e en us ed - in this case 50 out of 128 possible
ent r ies in th e dir ector y . Th e out put will look lik e
this

Scanning Directory •••

Sorting Directory •••

Name Bytes Recs Attributes Name Bytes Recs Attributes


-- --- --- - - - - - - - - - ------------- - --- - - - - - -- ------ - ------ --- - -- -- -- -- - ------ -
AFFIXTAB SPL 2k 6 Dir RO ALIGN TMK 6k 33 Di r RW
ARRANGE TMK 2k 9 Dir RW BAR TMK 14k 106 Dir RW
CCP COM 4k 25 Dir RW CDATA BAS 2k 3 Dir RW
COMBINE TMK 12k 85 Dir RW COMPUTE TMK 14k 110 Di r RW
CPM3 SYS 28k 214 Dir RW CUSTOMER DAT 2k 4 Dir RW
CUSTOMER KEY 2k 1 Dir RW DEMO 8k 64 Dir RW
DEMO 1 8k 59 Dir RW DEMO 2 6k 37 Dir RW
90 Using CP/M

DEMO 3 2k 16 Dir RW DEMO 4 6k 33 Dir RW


DICTNARY SPL 30k 236 Dir RW DIR COM 16k 114 Dir RW
EDITOR TMK 16k 116 Dir RW INCOME BAS 6k 41 Dir RW
INCOME 1 BAS 4k 30 Dir RW KEYS BAS 2k 2 Dir RW
LABELS BAS 2k 2 Dir RW LOAD TMK 6k 37 Dir RW
MAIL BAS 12k 93 Dir RW MAILI BAS 12k 94 Dir RW
MAILLIST MLL 2k 4 Dir RW MAILLOOK BAS 2k 3 Dir RW
MATCH TMK 2k 15 Dir RW MBASIC COM 24k 190 Dir RW
MCOUNTER FIL 2k 1 Dir RW PARAMTER FIL 2k 1 Dir RW
PIP COM 10k 68 Dir RW PRINT TMK 12k 90 Dir RW
Press RETURN to continue
Directory For Drive A: User 0

Name Bytes Recs Attributes Name Byte s Recs Attributes


--------------------------------------------------------------------------
PS COM 14k 104 Dir RW SETUP BAS 2k 8 Dir RW
SORT TMK 4k 27 Dir RW TALLY TMK 6k 42 Dir RW
TERMINAL UTL 6k 38 Dir RW TMAKER COM 8k 53 Dir RW
TMAKER UTL 4k 26 Dir RW TMAKER2 COM 10k 66 Dir RW
TMODIFY COM 6k 42 Dir RW TMODIFY UTL 12k 95 Dir RW
TRANS BAS 2k 2 Dir RW TRANSACT DAT 2k 2 Dir RW
UNLOAD TMK 4k 23 Dir RW

Total Bytes 360k Total Records 2470 Files found 47


Total lk Blocks 333 Used/Max Dir Entries For Drive A: 50 / 128

The options available with the DrR utility, as


opposed to the built-in DIR command, are considerable

OPTION EFFECT

ATT Gives the file attributes


DATE Gives data and time stamp on each
file
DIR Gives only those files with the
DIR attribute
DR IVE= ( A, B, .. ) Gives files on those listed drives
DRIVE=ALL As above but for all drives
EXCLUDE Gives all files that do not match
the specification
FF Sends a form-feed character to the
printer - if it has been started
with the CONTROL-P character
FULL Shown in above example
LENGTH=n Displays n lines on printer before
printing a table header (5<n<65536)
CP/M Plus (CP/M Version 3 .1) 91

MESSAGE Displays the drive names and user


numbers being searched by DIR
RO Gives read-only files
RW Gives only read-write files
SYS Gives only files with the SYS
attribute
USER=(O, .. l5) Gives only those files for the
specified users
USER=ALL Gives files for all users on that
drive

A further extension of DIR is DIRS which is another


built-in utility. It allows files with system
attributes to be displayed. We could type

A>DIRS

and display all the system files for user 0 on drive A.


I f we type

4B>DIRS *.COM

we will see the names of all the system files for user
4 on drive B that have the .COM extension.

3. USER
The reader may have noticed that the heading of the
directory listing mentions a "user number". This is
because this version of CP/M a 11 ows the disk space to
be divided up among as many as sixteen different users,
each with their own directory, or rather a sub
directory. Every user's directory is kept quite
separate from every other user, and each user can have
a password in order to protect his directory. To
estab lish a new user partition the command is

A>USER 3

for examp 1 e, in order to use one of these parti tions.


CP/M responds to this with a prompt that contains not
only the drive name but also the user number

3A>

However, this directory has no files in it and what


is more it is not possible, at this stage at least, to
92 Using CP/M

move files from one partition and sa ve them i n another.


So what do we do ? It looks as if we ha v e a director y
which we cannot use! Howeve r, the CP/ M Plus ver s i o n of
PIP allows us to mo ve a S AVEd fil e into into a nother
directory.
In order to do this we start from outsid e, back in
the main director y of th e d isk, and we load PIP into
memory and then enter the new user area. We then us e
th e SAVE command to save a cop y of PIP i n that
directory. The sequence looks like this

A>USER 1 This puts us into pa r t i t i o n 1


lA>DIR Ask for a dir ector y listing
No File None there
lA >USER
Enter User #: 0 Back into the main directory
A>PIP
CP/M 3 PIP VERSION 3.0
* At this point press RETURN

A>USER 1 SAVE 3 0 PIP.COM


lA>P IP PIP.COM[Gl]=A:PIP.COM
The [Gl] tells the s ystem to PIP
into user a rea 1. Not ic e that
the r e is no space be t we en th e f il e
name and the n umbe r of the user
area whic h is its dest ination

lA >DIR
A:PIP.COM
lA >

Now a copy of, say, MBASIC can be copied into the


user area

lA>PIP BASIC.COM[Gl]=A:MBASIC.COM
lA >DIR
A: PIP COM: BASIC COM

Other files can then be PIPped across and sa ved in


that user area. So now we can do a full directory
listing of this user area and get
CP/M Plus (CP/M Version 3.1) 93

Scanning Directory •••

Sorting Directory •••

Directory For Drive A: User 1

Name Bytes Recs Attributes Name Bytes Recs Attributes

BASIC COM 24k 190 Dir RW DIR COM 16k 114 Dir RW
TEST BAS 2k 2 Dir RW PIP COM 10k 68 Dir RW
DEMO BAS 2k 6 Dir RW

Total Bytes 54k Total Records 380 Files Found ; 5


Total lk Blocks 50 Used/Max Dir Entries For Drive A: 113/ 128

Notice that by separating the disk up into various


user areas you do not get addi tiona 1 directory space.
The 128 entries in the directory are merely split up
among the users.

4.SHOW
In CP /M Plus the STAT command has been replaced by SHOW
and the information it provides is extended. For
e xample, after the last directory listing shown above
we could type

lA>SHOW [USERS]

and get

A: Active User: 1
A: Active Files: 0 1
A: # of files 98 5

A: Number of free directory entries: 15

Typing

A>SHOW [SPACE]

will show the access mode and amount of space available


on the drives that are logged into the system.

A>SHOW [DRIVE]

will give you the drive characteristics of drive A and


94 Using CP/M

A>SHOW B: [DIR]

will display the number of free director y entries


available on drive B. Finall y

A>SHOW [LABEL]

will give the label information for the dr i ve A.

5.INITDIR
Before you can set date and time stamps onto the files
in a directory, the directory has to be initialised b y
the INITDIR program. When we do this we get

A>INITDIR 0:

INTIDIR WILL ACTIVATE TIME-STAMPS FOR SPECIFIED DRIVE


Do you want to re-format the directory on 0: (y iN)?

Then you can use SET to date and time-stamp the


files and issue passwords as required.

6.SET
In order to protect f i I es in the user areas b y pa s s wo r d
we use t he SET command. We do this in two stages. First
of all we ha ve to turn the password protection o n b y
t yping

A>SET [PROTECT=ON]

Then we can assign passwords to the files by t yping

A>SET FILE. OAT [PASSWORD=MUFFIN, PROTECT=WRITE]

which will produce the response

A:FILE.DAT Protection = Write, Password = MUFFIN

and this will protect the file called FILE.DAT from


unauthorised updating and will allow it to be written
to only if the filename contains the password "MUFFIN".
To use the f i I e now we must inc I ude the password wi th
the filename as follows

FILE.DATiMUFFIN
CP/M Plus (CP/M Version 3.1) 95

We could protect, for example, the DIR command in


the same way

A>SET DIR .COM [PASSWORD=MUFFIN, PROTECT=READ]

A:DIR.COM Protection = Read, Password = MUFFIN

so that in order to use the DIR command we must now


type

A>DIR:MUFFIN[FULL]

We can a I so set PROTECT to DELETE which means that


we need the password only if we wish to rename or
delete the file . By setting PROTECT to NONE we release
the file from all password protection.
SET will also allow you to place a "Label" on a disk
and password protect that label if required. We first
have to activate protection

A>SET [PROTECT=ON]

then label the disk

A>SET [NAME=MYDISK]

and give that labelled disk a password

A>SET [PASSWORD=FRED]

To abandon the existing password type

A>SET [PASSWORD= Press RETURN

We can add further information to the directory by


da te-stamping and time-stamping f i I es . We can set the
date by typing

A>DATE SET

and the response will be

Enter today 's date (MM/DD/YY): You respond in the


required format.
Enter the time (HH:MM:SS): You respond with the
time as requested.
96 Using CP/M

Press any ke y to set time

No w all you have to do i s to type the command

A>DATE

and you will get, for example

Tue 01 /10 /84 16 :27 :00

This now gives us another feature which we can SET.


I f we t ype

A>SET [CREATE=ON]

then we will place the date and time of creation of


files into the directory. If we type

A>SET [ACCESS=ON]

we place the date and time of last access into the


directory. However, we cannot have CREATE and ACCESS on
at the same time. We can have only one or the other. We
can, though, type

A>SET [UPDATE=ON]

and record the date and time of the last update of


files. Now if we ask for a directory listing we get
additional information regarding the dates of creation
and last update and whether the file is "Read", "Write"
or "Delete" protected.

7.DEVICE
Not onl y has the STAT command been repl aced by SHOW but
a l s o the command DEVICE has been raised to the status
of a command all on its own. In CP /M 3.1 we can now
change all the attributes of the various physical and
logical devices recognised by CP /M instead of going
through the SYSGEN routine necessary in earlier
versions.
Typing

A>DEVICE
CP/M Plus (CP/M Version 3 .1) 97

will display the names of the phyical devices and their


assignments to logical devices, while

A>DEVICE NAMES

will list all the physical devices and their


characteristics and

A>DEVICE VALUES

will list the current logical device assignments.


You can also discover the current state of any
physical device by typing

A>DEVICE LPT

and you can change the characteristics of a device by


typing its name followed by the new characteristics

A>DEVICE LPT [XON,2400)


A>

which allows the current printing device to be one that


operates at 2400 baud and accepts the XON /XOFF
protocol. This protocol is to do with the fact that
CP/M can send data to a device either when it is asked
for (that is, when the printer is ready for it) or
without waiting to be asked . The former is called
XON /XOFF protocol and the latter is NOXON. Both the
baud rate and the protocol are characteristics of the
device . Once these characteristics have been set they
exist as part of the operating system which is held in
memory . When the machine is switched off these
assignments are lost and they can only be made
permanently part of the operating system by performing
a GENCPM. The details of how this is done are
complicated and are detailed fully in the CP /M Plus
manual. They are outside the scope of this book.
However, if one wished to it wou I d be easy to take
advantage of a PROFILE.SUB file which can execute any
CP/M command as the system is booted up. So it is quite
poss ible to set up devices from within a PROFILE.SUB
file and also to set the time and the date and enter a
specific user space. Using ED we could create a file
like
98 Using CP/M

A>ED PROFILE. SUB

NEW FILE
*1
1: DEVICE LPT[XON,9600]
2: USER 1
3: DATE SET
4: MBASIC
5: A
Z
*E

then when the system is booted up it first of all sets


the physical printing de vice to be one with XON /XOFF
protocol and that operates at 9600 baud. Then it places
the system into user area 1, asks for the date and
time, and loads MBASIC ready for use.

8.PIP
There are two more parameters available to the PIP
command in this version of CP/M. These are

Command Effect

A Archive. Will copy onl y those


files that have been updated
since the last copy
C Confirm. PIP now asks for a
confirmation that the copy
should take place. Useful if
wild-cards are used in the
filenames
Gn Allows a file to be placed in
another user's area

The B, block read, parameter is not now available in


Version 3.1.

9.GENCOM
GENCOM allows us to create a new .COM file from a
series of RSX (Resident System eXtension) files. These
are files which must be in memory for the period of the
execution of the .COM file but be discarded later to
release that portion of memory. These files are said to
be "attached" to an area of CP/M. Such RSX files could
be modules which handle graphics or drive a particular
peripheral device. GENCOM will also place a header
CP/M Plus (CP/M Version 3.1) 99

block at the start of the .COM file. If we wanted to


include certain RSX files temporarily in with an
existing .COM file, ethen we would type

A>GENCOM PIP DRIVERI DRIVER2

where PIP.COM will have the files DRIVERI and DRIVER2


temporarily attached. If we subsequently type

A>GENCOM PIP

then the additional files will be detached and PIP


returned to its normal self .

IO.COPYSYS
After a disk has been formatted it is necessary to
place the essential system track information on the new
disk if it is going to be used subsequently for booting
up the system. COPYSYS will copy the essential CP /M
information across when you issue the command

A>COPYSYS

with the master disk in drive A as the "source" and the


new disk in drive B as the "destination". The message
"function complete" will inform you that the copying
has been successful.
COPYSYS can be used on a disk that already has files
saved on it . Whatever is on the disk is not affected by
the COPYSYS program. This is because the system tracks
are reserved for one th ing only and are not overwritten
by directories or files .

II.MAC, RMAC and SID


Instead of a single assembler CP/M Plus offers two . The
first of these is known as MAC. This accepts the same
assembler source code as the previous ASM program but
in addition it accepts macro commands as well . For
example, there is a "write character" function called
"wchar" which can be placed within an assembler
program, thus sa v ing the tedium of wri ting a separate
output routine. The conventional .PRN, .HEX and .SYM
are produced just as before and the assembled file is
loaded by the same LOAD.COM file as with other versions
of CP/M.
CP/M Plus has replaced DDT with SID - the Symbolic
100 Using CP/M

Instruction Debugger. This works in the same way as DDT


and uses the same commands. In addition, SID provides a
TRACE and HIST pair of util ities so that , for the
former, you can backtrack from a breakpoint and find
the instructions that led up to that point. TRACE
collects up the addresses of a maximum 256
instructions. The HIST draws a bar chart to show the
relative frequency of parts of the code within certain
segments of code. This means that you can find out
which parts of the code are executed most frequ ently.
SID commands are a superset of the DDT commands
described earlier, with the inclusion of

C Call a subroutine given its start address


E Employ - that is, load a program and symbol table
for execution
E* Employ a symbol table
P Pass point set, reset and display. This
records the number of times that a program
passes through a stated address
V Value - display the current value of the SID
parameters . These are NEXT, the next location
in memory, MSIZE which is the next location in
memory after the largest file read in, PC
which is the current value of the program
counter and the value of END which is the
address at the end of available memory
W Write the contents of a specified segment of
memory to a specified filename

RMAC is a more useful tool than MAC when developing


large assembler code programs, since RMAC is a
relocating macro assemb ler. This means that a starting
address does not need to be spec ified in the source
code, as is usual in other ASM programs. The output
fi les from RMAC are .SYM, .PRN and .REL. Any number of
files with the .REL extension that have been produced
by RMAC can be 1 inked together by the use of the LINK
command and a start address generated. The result is
that we create a .COM file ready for use. For example,
if there are four modules produced by RMAC, they will
all have .REL extensions. These can then be combined
wi th a 11 the externa 1 references and reso 1 ved into a
single executable file by typing

A>LINK MAIN=PROGl,PROG2,PROG3,PROG4
CP/M Plus (CP/M Version 3.1) 101

thus producing a file called MAIN.COM by the linkage of


the four files called PROGl.REL, PROG2.REL, PROG3.REL
and PROG4.REL. This operation will be familar to ex-
minicomputer users who compiled, say, a FORTRAN program
and all its subroutines and then linked them together
with the FORTRAN run-time library so that all the
macros referred to in the original FORTRAN modules were
resolved with appropriate contents of the run-time
library. The complete module can then be executed.
11 CP/M-86

When the Intel 8088 and 8086 IS-bit p r o c e s s o r chips


became available for a new generation of microcomputers
then CP/M was soon amended to run on these. CP/M-86 is
a version of CP /M 2.2 and contains all the standard
CP/M commands. Because of the greater addressing
capabilities of the new 16-bit processors application
programs written with CP/M -86 in mind can address up to
a megabyte (1 048 576 bytes) of RAM. All files written
by CP/M-86 are compatible with 8-bit versions of CP/M
and this allows easy communication of data between 8-
bit and 16 -bit machines.
In addition to the above there is far greater
flexibility of control of disk drives. CP/M-86 allows
up to 16 logical drives of up to eight megabytes each,
and so a maximum of 128 megabytes of on-l ine storage is
available.
All the standard resident CP/M commands of DIR, ERA,
TYPE and REN are exactly the same as with CP/M 2.2. The
files with the .COM extension in earlier versions of
the operating system become known as .CMD files and
PIP.CMD, ED.CMD, FORMAT.CMD, STAT.CMD and SUBMIT.CMD
work in the same way as before. The assembler becomes
known as ASM86.CMD, DDT is known as DDT86.CMD and
MBASIC is run from a command file called BASIC86.CMD.
When assembler code, written in 8086 code, has been
assembled the LOAD command has to be replaced with
GENCMD. Assemb 1 er code programs must have a f i 1 ename
with a .A86 extension and the hex code files that
result from the execution of ASM86 will have the
extension .H86. Assembly produces in addition a .LST
file and a symbol table in a .SYM file. DDT86 uses all
the standard DDT commands with the exception of GO,
which usua lly returns you to CP /M command 1 eve 1. The

102
CP/M-86 103

way to exit from DDT86 is to press CONTROL-C. ASM86


also allows the use of macros and can be suppl ied in
cross-assembler form to run under CP /M on an 8-bit
system.
Here is a program written in 8086 code showing the
use of ASM86 and DDT86

A>TYPE DEMOl.A86

iAN 8086 PROGRAM SIMILAR TO PROGRAM 3.1

ORG 100H
Nl EQU 31
N2 EQU 25
MOV AX, (Nl)
CALL QUAD
MOV BX,AX
MOV AX, (N2)
CALL QUAD
MOV CX,AX
STOP: JMP STOP
iSUBROUTINE STARTS
QUAD: ADD AX,AX
ADD AX,AX
RET
END

Note that the registers have slightly different


names from the on es used in the 8-bit assembler .

Then we assemble the program

A>ASM86 DEMOI

CP/M 8086 ASSEMBLER VER 1.0


END OF PASS 1
END OF PASS 2
END OF ASSEMBLY. NUMBER OF ERRORS: 0

We can now look at the files that result from the


assembly

A>TYPE DEMOl.LST
10 4 Using CP/M

ASM8 6 VER 1 .0 SOURCE : DEMO l.A8 6

; AN 8 086 PROGRAM SI MILAR TO PROGRAM 3 . 1

ORG 10 0H
OO IF Nl EQU 31
00 1 9 N2 EQU 2 5
0100 B8IF 00 MOV AX , ( Nl)
010 3 E8OD 00 CALL QUAD
0106 8BD8 MOV BX ,AX
01 08 B81 9 00 MOV AX , (N2 )
OIOB E805 00 CAL L QUAD
OIOE 8BC8 MOV CX,A X
01 0 0 E9FD FF STOP: J MP STOP
; SUBROUTINE STARTS
QUAD : ADD AX, AX
011 3 0 3 CO ADD AX ,AX
0 115 03 CO RET
0 117 C3 END

END OF ASSEMBLY. NUMBER OF ERRORS : 0

Then we c a n e xamine t h e s ymbo l tabl e

A>TYPE DEMOl .SYM


00 0 0 VAR IABLES
0000 NUMBERS
001 9 N2 OOIF Nl
0000 LABELS
0110 STOP 011 3 QUAD

Th e he x fi le ca n s i mil a r l y be d isp la yed

A>TYPE DEM01 .H86


: 04 0 0 0 0 0 3 00 0 0 01 0 0F 8
: 180 1 0 0 8 1BBIFOOE80DOOBBD8B8 1900E8 05 0 08BC8E9 FDFF0 3C00 3COC3F8
:O OOO OOOlF F

Th e n we can l oad the as s e mbl ed fil e using GENCMD

A>GENCl>1D DEMOI

BYTES READ OD I C
RECORDS WRITTEN 0 4
CP/M-86 105

Finall y we can e xa mi n e th e re s u l t i n g .C MD f iles


us ing DDT86

A>DDT86 DEMOl .CMD


DDT86 X. O
START END
CS 14CD :000 0 14CD :OIIF Notice that the addres ses
-L are gi ven in the form of an
l4CD:OlOO MOV AX,OOIF offset from a base address
l4CD :010 3 CALL 0113 since we c a nno t stor e an y
14CD: 0106 MOV BX,AX addres s b e yond FFFF i n two
l4CD iOl08 MOV AX,001 9 b ytes.
14CD :OIOB CALL 0113
14 CD:OIOE MOV CX,AX
l4CD:Oll O J MP 0100
1 4CD:01l 3 ADD AX,AX
14 CD: 0 1l 5 ADD AX,A X
14CD:01l7 RET
14CD: 011 8 ADD [BX+SI) ,AL
14CD:O ll A llDD [ BX · I-S I ] I" !'..L
-0 100

1 4CD:O IOO B8 IF 00 E8 OD 00 8B D8 B8 19 00 E8 05 00 8B C8 .. .. . . . .. . . .... .. .


14CD :O llO E9 FD FF 03 CO 03 CO C3 00 00 00 00 00 00 00 00 . .. .. . ... . ... ...
14CD: 01 20 7F 37 00 DF 14 01 7F 37 00 00 00 00 00 00 00 00 . 7 . .• . • 7 . . . •.. . •
14 CD; 0 13 0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ..... . . . . . . . . . . . . ..
14CD:0140 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ... . .... . . . . . . . ...
14CD: 01 5 0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 . .. . . . . . ... . . . . .
14CD:0 160 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ... . . . 0 .. . .. . . . .. ..

14CD :0170 00 00 00 00 00 00 00 00 00 00 00 00 00 20 20 20 . .. ... . .. .. .. . 0 ..

14CD:0 180 20 20 20 20 20 20 20 20 00 00 00 00 00 20 20 20
14CD:0190 20 20 20 20 20 20 20 20 00 00 00 00 00 00 00 00 . . ... . ..
14CD:OIAO 00 00 44 45 4D 4F 31 2E 43 4D 44 00 00 00 00 00 . . DEMOl . CMD. . . . .
14 CD: OI BO 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 . .. . . .. . ... .. . .. .

-T 13
AX BX CX DX SP BP SI DI IP
--1------ 0000 00 00 0000 0 000 11 9E 0 000 000 0 0 0 00 0 100 MOV AX,OOl F
--1------ OOI F 0000 00 00 0000 11 9 E 0 000 0000 0000 0 103 CALL 0 113
--1------ 00 1F 0000 0 00 0 000 0 11 9C 0000 0000 0000 0 113 ADD AX ,AX
- - I -- - A- - 003E 0 000 0 000 0 000 11 9C 0000 0 000 0 000 011 5 ADD AX, AX
- -I ---A-- 00 7C 0 000 00 00 0000 11 9C 0000 0000 0000 0 11 7 RET
--I--- A-- 00 7C 00 00 0000 0 000 11 9 E 0 000 00 00 00 00 0106 MOV BX,AX
--I -- - A- - 007C 0000 0000 0000 11 9E 0000 00 00 0 000 0 108 MOV AX ,00 19
-- I- -- A-- 0 019 007C 00 00 0000 11 9 E 0000 000 0 0000 010 B CALL 0 113
- - I- - -A - - 00 19 007C 0000 0000 11 9C 0000 0000 0000 01 13 ADD AX,AX
- - I - - - A- - 00 32 00 7C 0000 0000 1 19C 0000 0000 000 0 0 115 ADD AX,AX
106 Using CP/M

- - 1- - --- - 0064 007C 0000 0000 1 19C 0000 0000 0000 0117 RET
-- 1-- -- -- 0064 007C 0000 0000 1 19 E 0000 0000 0000 a lOE ~1 0 V CX,I\X
--1 - - - -- - 006 4 007C 006 4 00 00 1 19E 0000 00 00 0000 01 10 JMP a 11 a
--1------ 0064 007C 0 0 64 00 00 1 19E 0000 0 000 000 0 0110 JMP 0 110
- -1- -- - -- 006 4 007C 0 0 6 4 0 000 11 9 E 0000 0 000 0 00 0 0110 J~lP 01 10
--1-- - --- 0064 0 0 7C 0 0 64 000 0 1 19E 00 00 0000 00 00 a 110 J~I P 0 110
'c

The CONTROL-C command wi 11 s top the running of the


program under DDT86 and return the user to CP/M.
12 MP/M

With the continued popularity of the CP /M operating


system for running programs relating to business
requirements - spreadsheets, word processors, databases
and accounting systems - it was a logical step to make
the files and programs written under the system
available to more than one user at a time. with
microcomputers becoming so cheap and communications
technology becoming so sophisticated it was no real
surprise when the multi-user version of CP /M came
along. MP /M exists in both 8-bit and l6-bit versions:
MP/M and MP/M-86.
MP /M, the current version of which is generically
known as MP /M II, is a multi-user, multi-tasking
operating system. Connected to a computer running MP/M
are a series of terminals, printers and other
per ipheral devices. MP /M can support up to sixteen
logical drives of up to 512 Megabytes capacity each.
254 logical devices, such as printers, terminals and
other input/output devices, can be supported by MP/M. A
separate job can be run at each terminal quite
independently such that it appears as if ordinary CP/M
is being used. MP /M operates in a similar manner to a
minicomputer time-sharing system but, it must be said,
its speed does not compare.
In order to cope with the extra demands of a number
of users MP /M II uses extended versions of the BIOS and
BDOS, known as the XIOS (Extended Input/Output System)
and the XDOS (Extended Disk Operating System). The
XDOS, and notice that the fixed BDOS still exists as
we 11, does all the control 1 ing of the mu 1 ti-tasking,
the terminals and the queues awaiting the use of the
peripherals. The command line interpreter is contained
wi thin XDOS.
The arrangement of CP /M in the memory of an MP/M

107
108 Using CP/M

operating s ystem i s shown in the fig ur e.

High Hemo ry

XI OS
( Up to 6K Bytes)

XDOS
(8K Bytes)

BDOS
( 2K Bytes)

Trans i ent
Prog ram
Area

OIOOH

256 Bytes Reserved


OOOOH
Low Memory

MP/M II has been designed to run most CP/M programs


at the terminal s which are connected to the main
processor. Each user has access to files stored on the
system disks and one or more printers connected to the
s ystem. In order to make sure that clashes do not occur
when more than one person wishes to modi f y the same
fil e th ere is a s ystem o f record locking. If a f i l e is
locked then only one user ma y open it at a given time.
If a f ile is unlocked then, although mult iple open file
requests can be made, groups of records can be locked
temporarily b y a user. Files can also be made read-onl y
MP/M 109

so that the information retained in them can be read by


all but not modified.
CP /M commands such as PIP, STAT, DIR, TYPE, REN and
ERA are all exactly as in conventional CP /M. In
fact, the only immediately obvious difference to th e
casual user is that the normal

A>

prompt will become prefixed by a user number such as

OA >

which is very similar to th e partitioning of a disk


available i n CP/M Plus as described earlier. Users are
"logged in" by the USER command in just the same way.
In fact there are a number of similar features between
MP /M II and CP/M Plus. Another is the way in which the
user directory is displayed by the DIR command. The
similarity is not very surprising in that both of these
operating systems need a microcomputer with a banked
memory.
MP /M II is designed to be used with a hard disk
system, although mini floppy disks could be used, and
it has the facility of being able to use a "virtual"
disk. This is a section of RAM which is arranged to
look like a disk drive, usually of 256K bytes or 5l2K
bytes size, but because it is contained within RAM its
access times are a fraction, around one-tenth, of thos e
of a comparable hard disk. This makes the accessing of
data stored, albeit temporarily, on such a virtual disk
very fast indeed and it is ideally suited to a multi-
user , system. However, a file has to be loaded onto the
virtual disk before it can be used, using PIP . The
file is, of course, lost when the system is powered
down since information held in RAM is always volatile.
A virtual disk is created by using the command

OA >VDSK:=ON

and its "drive name" is allocated by using ASSIGN

OA>ASSIGN D:VDSK

From then on "drive" D is treated as if it were any


other drive.
110 Using CP/M

Other specialised MP /M II commands are

ABORT Stops the running of a program, at your or


another termina I, by specifying the
console number from which the program was
run
ATTACH Attaches a program to a consol e
CONSOLE Each terminal on the MP/M system has a
console number, which is not the same as
the user number. MPMSTAT lists its
information by console number rather than
user number
CONTROL-DDetaches a program and runs it while
the user runs another ATTACHed
program thus providing a method of running
programs concurrently.
DSKRESET Resets the allocation map of a disk
drive after the disk has been changed
ERAQ Just as with ERA in CP/M but asks whether
you wish to erase or not. In other words
you can use ERAQ in conjunction with a
generalised filename including wild cards
and each specific name is displayed with a
YIN query. Similar to the CP /M Plus ERA
with the C (Confirm) option
MPMSTAT Lists all the activities in progress at
the time that the command was issued
PRINTER This allocates a printing device for a
particular console. Several users can have
access to a printer but only one can use
it at any time
SCHED Will allow program to be loaded and run at
a specified time in the future
SDIR Displays and lists all MP /M file
including system files
SPOOL Sends a file to the spool queue for the
listing device
STOPSPLR Terminates the spooling and empties the
spool queue
TOD Displays or sets the date and time - as in
CP/M Plus
13 Concurrent CP/M

Most central processors spend their time doing very


little. This is because many of the jobs being done by
the computer, 1 arge or sma 11, mainframe or micro, are
protracted by the slowness of the data input and
output. The input device is usually the keyboard, and
even the speediest of typists cannot supply data at
anything 1 ike the speed that it can be processed.
Similarly, the speed of printers is far slower than the
speed that the computer can hand over the data - hence
the need for printer buffers. This is a problem that
will be familiar to former users of mainframe and
minicomputers; it was overcome b y the use of a
technique known as multi-programming. This enabled the
computer to handle more than one program at a time. The
result meant that, fo r example, wh ile someone was
editing a program on line the central processor could
be getting on with some other task, say that of
compiling a program in FORTRAN, i n between the editing
keystrokes .
Concurrent CP/M and Concurrent CP /M-86 therefore
allow several tasks to be going on at the same time by
use of a mu 1 ti-programming technique. This is done by
allowing a single microcomputer running Concurrent CP/M
to have up to four separate "virtual" consoles, each
running a different program, to be operating at once.
In theory up to sixteen virtual consoles can be used,
but a considerable degradation of response would be
noticed if each task were of any useful size.
A good example of the practical use of Concurrent
CP /M is one where a word-processing package, a
portfolio management package and a f inancial modelling
package are running three of the virtual consoles while
the fourth is connected by telephone line to a
stockbrokers' bureau service.

111
112 Using CP/M

Concurr ent CP /M allows a job to b e s et running at


one of these virtual consol es and, when it is und er
way, the user can start another job at another consol e;
and so on unti 1 all four are running a t onc e. It is a
very simple task to switch windows in order to look in
at any v i r t u a l console. This is done b y the operator
pressing the CONTROL key in conjunction with the 0,1,2
or 3 key. CONTROL and 0 gets you to v i r t u a l consol e 0,
then CONTROL and 3 tak es y o u to look at wh a t is
happening on virtual console 3, and so on.
The latest v ersions of Concurr ent CP /M allo w
"windowing" to take place, a ve ry popular pastim e on
microcomput ers these days . This means that th e scr e en
can be di vided up into four smaller screens so that
each mini-screen can show one of the programs while it
is running.
Remember that this is all done on a singl e
microcomputer which has a minimum of 128K bytes of RAM.
Concurrent CP/M can support up to sixteen logical disk
drives of up to 512 Megabytes each.
As with MP /M, record locking is us ed so that a
program running from one v i r t ua l consol e cannot corrupt
files being used by another since Concurrent CP/M is a
single-user multi-tasking operating syst em. Th e
execution of the various programs is done by di viding
up central processor time by "time-slicing" in the same
way tha t many of the mul ti-user minicomputersoperate.
Users of Concurrent CP /M can identif y themselv es
with a user number which is then attached to a specif ic
directory of files. Pi les can be date-stamped, time -
stamped and password protected as well.
When running a microcomputer using Concurrent CP/M
the first thing one would notice is that there is a
status line at the bottom of the screen to tell you
which console you are logged into, the name of the
program being run at that console and which printer is
being used by that program. The display could there
have the information

CONSOLE=l DYNAMIC SC PRINTER=l

which tells you that you are using virtual console 1,


running the SuperCalc spreadsheet program and that the
printer relating to that console is printer 1. The
DYNAMIC mode is a mode of operation such that all the
output that would normally go to the screen is sent to
Concurrent CP/M 113

an area of RAM ready for display when the console i s


made active. Howev er, if in DYNAMIC mode, this area of
RAM contains only the last screen display created. If
it was in BUFFERED mode then, as each screen fills up,
the operation of the program is suspended until the
contents of that "screen " ha ve actually been displayed.
So if you set a program going in DYNAMIC mode, there is
a possibility of certain screen displays being lost for
ever - error messages in a compilation for example .
Concurrent CP/M uses all the usual CP/M commands of
PIP, STAT, DIR, etc., together with a number that are
specific to this operating system . For example, there
are the following

ABORT Allows a specified background program to be


stopped. This allows the user at one virtual
console to stop a program running at
another. Very much the same as the MP /M
instruction of the same name
SYSTATshows the state of the four consoles as well
as the state of the processes going on at them
VCMODE s ets the mode of a virtual console- as DYNAMIC
or BUFFERED - and the maximum file size for the
buffered mode

Release 3.1 of Concurrent CP /M allows programs


written for the IBM PC under their PC-DOS 1.1 operating
system to be run. As yet only Version 1.1 programs can
be run on the PC, but Version 2.0 emulation will be
available before long. In addition, this version of the
operating system can be multi-user as well with up to
four separate "real" consoles connected to the same
microprocessor and each running four "virtual"
consoles. However, as has been said already, if the
system became anything other than lightly loaded, there
would be a considerable reduction in response times.
14 CP/NET

Now that the networking of microcomputers has become


qui te commonp lace it is not unexpected tha t th e CP /M
operating s ystem and the programs that operate under
its direction should be available on a network.
At first sight it would seem that an MP /M system and
networked CP /M are not too different from each other.
However, this is not really the case. An MP/M system
requir e s a single computer that has a number of "slave"
terminals each sharing the resources of the master. In
CP/NET a series of independent CP/M computers, possibly
of different manufacture, are linked together in such a
way as to share not only common resources but also each
other 's. The separate machines can function on their
own under their own CP /1'1 system but by the use of the
CP /NET software the y can communicate with other
computers on the network.
CP /NET can interface with a number of different
network systems, among which are Ethernet (R) and
OMNINET (R). The configuration of computers on a
network is usually one of the three shown

1) The Star

Requester
- nooo 02 Floppy Disks
A :, B:

Requester
- node 03

Floppy
Disks
A:
B:

Request er
- node 04
conSOle~~~~~
114
CP/NET 115

2) Th e Ring

. o~~
\0
Network
Server Floppy
Disk' A :, B:

t, Requester
Floppy Disk'
A :,B :

3) Mu l t i d r o p

Network
Server

Floppy Di'k'
A :.B:

In any of these networks there has to be at least


one "Server" running MP /M II which looks after the
system as a who le o Then there are a series of
"requesters", or nodes, which will either be free-
standing CP/M microcomputers or intelligent terminals.
Up to sixteen requesters can be supported by a singl e
MP/M I! network server. The free-standing micros will
116 Using CP/M

h a v e th e normal CP/M o p er atin g s y st e m, bu t wi l l in


a d d i t i o n ha v e th e CP/ NET so ft war e wh i ch wi l l e na b l e
t h e m to communi c a t e wi th th e r est o f th e ne t wo r k . The
in te llige n t t ermi nals wil l ha v e a s mall amo un t of RAM
a nd th eir o wn mic ro proc e s sor, but no di sks. Howe ver,
t h es e wi ll n eed to hav e a 4K ROM cont ainin g CP/NO S
wh i ch i s a c ut-down ve r sio n o f CP/ NET and c o n t a in s onl y
th e software r e q uir ed fo r t he intellig ent t erminal to
lo g i n t o th e n et work . F r o m th en o nw a rd a l l th e
so ft ware r equired a t that nod e of the network is down-
loaded from th e s ystem s er v er through th e network. The
result of all this is that all processin g is pe rf o r med
locall y and onl y when a f a c i l i ty that is e l sewhe r e on
the n etwork is r equired does the communic ation between
processors tak e plac e. To e a c h us er it a pp ears as if a
powerful dedicat ed CP /M system i s o n his d esk. A
complex CP/NET s ystem is s hown in th e d iagram

CP INOS

Intelligent Terrmnats

CP /M
CP /NET
CP/NET 117

In addition to the usual CP /M commands, there are


several that are particular to a network. These are

LOGIN Connects a requester to the system


LOGOFF Disconnects the requester from the
system
NETWORK Enables a user to change the network
environment. This is done by mapping
logical device names to physical devices
elsewhere on the network. For example

A>NETWORK H:=c:(Oll

will assign drive C: on the network server, node 01, to


logical drive H: . This means that a user at the node
where that command was issued from can refer to device
H: and actually access drive C: on the server. This can
be done for any device, disk drives or printers

LOCAL Restores a requester back to its own local


environment
CPNETSTS Displays the status of the network and
the mappings current at the requester's
node . For example

A>CPNETSTS

CP/NET 1.2 Status

Requester 10 = 02H
Network Status Byte 14H
Disk device status
Drive A: = LOCAL
Drive B: LOCAL
Drive C : Dr ive A: on Network Server ID OlH
Drive 0: LOCAL
Drive E: = Drive B: on Network Server 1D OlH
Drive F: LOCAL
Drive G: LOCAL
Drive H: = Drive C: on Network Server 1D OlH
Drive I : LOCAL
Drive J: LOCAL
Drive K: LOCAL
Drive L: LOCAL
Drive M: LOCAL
118 Using CP/M

Drive N: LOCAL
Drive 0: LOCAL
Drive P : LOCAL
Console Device = LOCAL
List Device = List #0 on Network Server ID = OIH

This table tells us that when we refer to drives


A,B,D,F,G,I,J,K,L,M,N,O or P they are local drives - on
the requester system. However, when we refer to drives
C,E or H, then they are in fact drives A,B and C on the
network server. The listing device is actually printer
#0 on the network server and is not a local printer. To
the user all these devices are addressed as if they are
local devices. This means that if a user at, say, node
02, issues the command

A>H:DBASE

then he will load the DBASE package that is situated on


dr ive C: of the server. This is because his drive H: is
mapped to drive C: on the server. In addition, all the
output from his database program will be sent to
printer #0 on the server.

MAIL Allows messages to be transmitted across


the network between nodes.
Appendix A: ASCII Character Codes

Decimal Hex Char Decimal Hex Char Decimal Hex Char


000 OOH NUL 043 2BH -+- 086 56H -V-
001 OlH SOH 044 2CH 087 57H W
002 02H STX 045 2DH 088 58H X
003 03H ETX 046 2EH 089 59H Y
004 04H EOT 047 2FH / 090 5AH Z
005 05H ENQ 048 30H 0 091 5BH [
006 06H ACK 049 31H 1 092 5CH \
007 07H BEL 050 32H 2 093 5DH 1
008 08H BS 051 3JH 3 094 5EH
009 09H HT 052 34H 4 095 5FH ""7
010 OAH LF 053 35H 5 096 60H
011 OBH VT 054 36H 6 097 61H a
012 OCH FF 055 37H 7 098 62H b
013 ODH CR 056 38H 8 099 63H c
014 OEH SO 057 39H 9 100 64H d
015 OFH S1 058 3AH 101 65H e
016 10H DLE 059 3BH 102 66H f
017 llH DC1 060 3CH < 103 67H g
018 12H DC2 061 3DH 104 68H h
019 13H DC3 062 3EH > 105 69H i
020 14H DC4 063 3FH ? 106 6AH j
021 ISH NAK 064 40H @ 107 6BH k
022 16H SYN 065 41H A 108 6CH 1
023 17H ETB 066 41H B 109 6DH m
024 18H CAN 067 42H C 110 6EH n
025 19H EM 068 43H D III 6FH 0
026 lAH SUB 069 44H E 112 70H P
027 1BH ESC 070 45H F 113 71H q
028 lCH FS 071 46H G 114 72H r
029 IDH GS 072 47H H 115 73H s
030 lEH RS 073 48H I 116 74H t
031 IFH US 074 49H J 117 75H u
032 20H SPC 075 4AH K 118 76H v
033 21H 076 4BH L 119 77H w
034 22H " 077 4CH M 120 78H x
035 23H # 078 4DH N 121 79H Y
036 24H s 079 4EH 0 122 7AH z
037 25H % 080 4FH P 123 7BH {
038 26H & 081 SOH Q 124 7CH I
039 27H 082 51H R 125 7DH }
040 28H ( 083 52H S 126 7EH
041 29H ) 084 53H T 127 7FH DEL
042 2AH * 085 54H U

Note: The first 32 ASCII codes can be generated on the


keyboard as "Control Codes", that is, codes generated
by depression of the "CONTROL" key in combination with
other keys. Code 000 is "CONTROL" , Code 001 is
"CONTROL-A", Code 002 is "CONTROL-B" and so on. Codes
028 to 032 are "CONTROL-SHIFT" and K,L,M,N,O
respectively.

119
Appendix B: CP/M Console Editing
Commands
These commands can be used on the majority of
microcomputers to edit CP/M commands. Those followed by
(3) are usually a vailable with CP/M Plus only. It is a
matter for experiment to see whether they 'all work on
the machine that you are using and the version of CP/M
that you are using.

Command Effect
CTRL-A Moves cursor one character to left
(banked systems only) (3)
CTRL-B Moves cursor through command l i n e
(banked systems only) (3)
CTRL-C Stops program execution. Returns
user to command level
CTRL-E Forces physical carriage return
without sending the command to
CP/M
CTRL-F Moves cursor one character to
right (banked systems onl y) (3)
CTRL-G Deletes character at cursor
position if not at line end
(banked systems onl y) (3)
CTR1-H Deletes character to left of
cursor
CTRL-I Tabs to right ( 3)
CTRL-J Line feed
CTRL-K Deletes character und er cursor
and all characters to its right(3)
CTRL-M Carriage return
CTRL-P Printer toggle
CTRL-Q Restarts screen scrolling after
CTRL-S (3)
CTRL-R Retypes the characters to left of
cursor on a new line
CTRL-S Stops screen scrolling.
(for Versions 2.2 or earlier the
scrolling will recommence i f any
key is pressed)
CTRL-U Deletes current line. Updates the
command line buffer to contain the
characters to left of cursor
CTRL-W Recalls previous command line if
current line is empty
(banked systems only) (3)
CTRL-X Deletes all characters to left of
cursor

120
Appendix C: CP/M Packages
Th e number of software packages ava ilable for CP/M
systems is very large and growing almost daily . There
follows a selective list of some of the more popular
packages together with a brief description of what they
do. Apologies are offered to any software house who
feel that any products of theirs should be included.
Attempts will be made to keep this list as up to date
as possible within the constrictions of the publishing
world.

WORDSTAR Word-processing package. Powerful


and, once learnt, easy to use
MAIL-MERGE Add-on package for WORDSTAR.
Mailing list and personalisation
of letters
SPELLSTAR Add-on for WORDSTAR. Spelling checker
STARINDEX Add -on for WORDSTAR. Creates indexes,
tables of contents and documents
in standard formats
DATASTAR Screen-orientated data entry and
retrieval system
REPORTSTAR Report generator used in conjunction
with DATASTAR
INFOSTAR Database management system used in
conjunction with REPORTSTAR and
DATASTAR
CALC STAR Spreadsheet package
PROSTAR Training package for above products
SUPERSORT Sort, merge package
Dbase II Database management system .
Includes reports. Suitable for
invoicing, stock control, payroll
QUICKCODE Easy creation of Dbase II command
files
dGRAPH Extracts data from Dbase II records
in graphical form
OMS Data base management system
THE LAST ONE Code generator for MBASIC
CARDBOX Information retrieval system
MULTIPLAN Electronic spreadsheet
SUPERCALC Electronic spreadsheet
MICROMODELLER Financial planning package
BASIC-80
COMPILER Compiler BASIC for faster execution
FORTRAN-80 ANSI 66 FORTRAN compiler
COBOL-80 ANSI 74 COBOL compiler
CIS -COBOL Level 1 ANSI 7 4 compiler. Supports
indexed sequential files, interactive
operation
LEVEL II COBOL Interfaces with FORMS2, FILESHARE
and ANIMATOR
PASCAL/MT+ Compiler Pascal
CBASIC Compiler and run-t ime package for
BASIC
PLl /80 Subset G of the compiler

121
122 Using CP/M

'c' COMPILER Two pass compiler


BSTAM Allows f iles to be ex c h a n g e d between
CP/M systems
XLT-86 Converts 8080 Assembler into 8086
code
PERFECT WRITER Word-processing package
PERFECT Spelling checke r for PERFECT WRITER
SPELLER files
PERFECT CALC Electronic spreadsheet
PERFECT FILER Data retrieval s ystem
T/Maker Combined word-processor, spreadsheet,
file-maintainance package
SAGE Integrated accounts s ystem
Pulsar Full financial package including
modelling facilities

The address of Digital Research in the United Kingdom


is

Digital Research (UK) Ltd


Oxford House
Oxford Street
Newbury
Berks. RG13 lJB (Telephone : (0635) 35394)

The address of the CP/M Users ' Group i s

CP/M Users Group UK


11 Sun Street
Finsbury Square
London EC2D 2QD
(Telephone: (01-247) 0691 )
Index

ABORT 110 ,113 FIELD 54


Assembl e r Code 69 Files in BASIC 49
ASM86 102 FORMAT 6, 7
ASSIGN 109
ATTACH 110 GENCOM 98
GENCMD 10 2
BASIC 86 43
BDOS 1 HELP 87
BIOS 1
BOOTCOPY 7 INITDIR 94

CCP 1,3 LOAD 75


CBASIC 58 LOCAL 11 7
COPYSYS 7,8,99 LOGIN 117
CONSOLE 110 LOGOFF 117
CPNETSTS 117
CP/ NOS 116
MAC 99
DDT 75 MAIL 118
DDT86 102 MBAS IC 42
DDT Commands 84 MOVCPM 8
Device names 24,25 MPMSTAT 110
DEVICE 96
DIM 42
DIR 9,89 NETWORK 117
DIRS 91
DSKRESET 110 OPEN 49
DUMP 72
PIP 1 4,98
ED 29 PIP Pa rameters 18
ED Commands 39 PRINTER 110
EDIT (In BASIC) 46
EOF 53 REN 12
ERA 11 RESET 57
ERAQ 110 RMAC 99

123
124 Index

SAVE ( In BASIC) 56 TOD 110


SCHED 110 TPA 2
SDIR 110 TYPE 1 2,7 3
SET 94
SHOW 93 USER 91
SID 99
SPOOL 110 VCMODE 11 3
STAT 21 VDSK 10 9
STOPSPLR 110
SYSGEN 7 WHILE,WEND 44
SYSTAT 113
SYSTEr-t 57 XDOS 107
XI OS 10 7

You might also like