Using CPM
Using CPM
Peter Gosling
M
MACMILLAN
© Peter Gosling 1985
Published by
MACMILLAN EDUCATION LTD
Houndmills, Basingstoke, Hampshire RG 21 2XS
and London
Companies and representatives
throughout the world
Preface iv
1 What is CP/M? 1
7 using MBASIC 42
8 Using a Compiler 58
11 CP/M-86 102
12 MP/M 107
14 CP/NET 114
Index 123
Preface
PETER GOSLING
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
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>
Orive=nn,Track=nn,Sector=nn:Error=nn
Bdos error on X:bad sector
5
6 Using CP/M
A>FORMAT
A>B:
B>
A>MOVCPM64 (RET)
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
A>OIR
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>
A>OIR WS.COM
0 . ,: ;=/*[ 1
9
10 Using CP/M
A>DIR *.BAS
A>DIR CPM??? *
A>DIR * 31.*
A>DIR ??????31.*
A>DIR B:
CP/M Resident Commands 11
A>ERA PROG1.BAS
A>ERA *.BAS
A>ERA *.*
ALL(Y/N)?
A>REN newname=oldnam e
A>
A>REN B:TEST1=TEST1.BAK
A>
A>REN B:TEST1=A:TESTl
A>REN BAS.CMD=CBAS86.CMD
A>
A>BAS
A>TYPE TEXT1.TXT
A>TYPE B:TEXT2.TXT
SAVE "PROG1",A
A>TYPE PIP.COM
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
so that if we type
A>PIP
*B:FILEl=A:FILE2
14
PIP, the Peripheral Interchange Program 15
A>PIP
*B:FILE1=A :FILE2
* (ret)
A>
A>PIP B:FILE1=A:FILE2
A>
A>PIP B:FILE1=FILE2
A>
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 B:=*.BAS
COPYING-
PROG I .B AS
PROG2 .BAS
PROG 4. BAS
PROG5 .BAS
PROG8 .BAS
PIP, the Peripheral Interchange Program 17
A>
A>P IP B'=* *
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>PIP CON:=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
Parameter Effect
A>STAT
A:R /W,Space :200K
B:R/O,Space:16K
A>
A>STAT B:
21
22 Using CP/M
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
A>STAT A:R/O
A>STAT DEV:
CON: is CRT :
RDR: is TTY:
PUN: is TTY:
LST: is LPT :
A>STAT VAL:
26 Using CP/M
and we will g et
A>STAT LST:=CRT :
A>STAT DEV:
we get
CON: is CRT:
RDR: is TTY:
PUN: is TTY:
LST: is CRT:
A>STAT DEV:LST:=LPT:,CON:=TTY:
A>STAT DSK:
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
29
30 Using CP/M
ED DEMO . BAS
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:
ED DEMO. BAS
NEW FILE
*1
1: REM***DEMONSTRATION CBASIC PROGRAM***
2:
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:
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
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: *
ED DEMO. BAS
*9A
1: *lL
2: *I
34 Using CP/M
2: CREATE "DEMFILE" AS 1
3: A
Z
3: *E
A>
ED DEMO. BAS
*9A
1 : *lL
2: *1
2: IF END#l THEN 5
3: Z (Not echoed)
A
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
ED DEMO. BAS
*14A (The file now contains 14 lines
1: * of program)
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
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
Similarly
nD
3FCOUNTER~Z
Rfilename
nX
A>
ED PROFILE. SUB
NEW FILE
*1
1: MBASI C DEMPROG
2: ~Z
*E
A>
ED EDIT.SUB
NEW FILE
*1
I: SET WS.KEY
2: WS
3: ~Z
*E
A>SUBMIT EDIT
10 DIM A(10,20),A$(10,20)
42
Using MBASIC 43
A>MBASIC
or
A>BASIC86
10 INPUT I,F,S
20 FOR J=I TO F STEP S
30 PRINT J
40 NEXT J
50 PRINT J
10 INPUT NUMBER
20 WHILE NUMBER< >O
30 TOTAL=TOTAL + NUMBER
40 INPUT NUMBER
50 WEND
60 PRINT TOTAL
20 WHILE NUMBER<>O
30 TOTAL=TOTAL + NUMBER
40 INPUT NUMBER
50 WEND
60 PRINT TOTAL
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
10 INPUT X
20 IF X>lOO THEN PRINT "HIGH" ELSE PRINT "LOW"
30 END
10 INPUT X
20 IF X<lOO THEN PRINT "TOO LOW":GOTO 10
30 PRINT X
40 END
EDIT 200
A>EDIT 200
A>LIST 200
A>EDIT 200
200 INPUT N
48 Using CP/M
40 X=SQR(SIN(LOG(I))~2)+EXP(COS(I))~.4
EDIT 40
40
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
40 X=SQR(SIN(LOG(I))A2)+EXP(COS(I))A. 4
100 X=SQR(SIN(LOG(I))~2)+EXP(COS(I))A.4
GOTO nnnn
10 OPEN "O",l,"DATAFILE"
PRINTed to.
If we write
10 OPEN "I",l,"DATAFILE"
5 INPUT A$
10 OPEN "O",l,"DATAFILE"
20 PRINT#l,A$ (PRINT to the file,not the screen)
10 OPEN "I",l,"DATAFILE"
20 INPUT#l,A$ (INPUT data from the file,
30 PRINT A$ not the keyboard)
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
PRINT A$
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
RON,TOM,DAN
FRED,MEG,HARRY (Note the commas)
DICK, BILL, NORMAN
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
34 45 32
32 21 11
67 68 69
44 55 66
66 77 88
77 88 99
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 ... " ,
10 OPEN "R",1,"RFILE",48
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)
70 PUT#1, 10
80 GET#1, 10
90 Y=CVI(B$)
100 Z=CVD(C$)
110 PRINT A$,Y,Z
A>MBASIC TESTPROG
A>MBASIC FILEPROG/S:256
SAVE "PROGl"
SAVE "B:PROGl"
SAVE "PROGl",A
SAVE "PROGl",P
10 INPUT X
10 input x
Using MBASle 57
load "progl"
RESET
SYSTEM
58
Using a Compiler 59
10 FOR 1%=1 TO 50
20 PRINT I %;I %~2
30 NEXT 1%
SAVE "PROG",A
and we get
60 Using CP/M
CRUN86 PROG
FOR 1%=1 TO 50
PRINT I% ;I %A2
NEXT 1%
CBASIC86 PROG
4: END
NO ERRORS DETECTED
CONSTANT AREA: 8
CODE SIZE: 38
DATA STMT AREA: 0
VARIABLE AREA: 8
A>
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
3.162278
10
31.62278
100
below
CBAS86 ROOTS
CRUN86 ROOTS
CRUN86 VER 1. 00
COPYRIGHT 1981 COMPILER SYSTEMS INC.
3.16227766017
10
31.6227766017
100
A>
30 NEXT I
CBAS86 PROGl
3* 30 NEXT I
4: END
1 ERROR DETECTED
CONSTANT AREA: 16
CODE SIZE: 66
DATA STMT AREA: 0
VARIABLE AREA: 8
A>
CBAS86 PROGI
A>CBAS86 DEMO
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>
ERROR OE
A>
A>CBAS86 DEMO
A>CRUN86 DEMO
ERROR OF
A>
A>CBAS86 DEMO
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
A>
A>CBAS86 DEMO
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
A>
69
70 Using CP/M
ORG 100H
PROGRAM 3.1 MULTIPLIES TWO NUMBERS BY 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
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>TYPE DEMO.PRN
0100 ORG 100H
PROGRAM 3.1 MULTIPLIES TWO NUMBERS BY 4
A>DEMO
A>DDT DEMO.COM
-L
0117 ADD A
0118 ADD A
0119 RET
011A NOP
011B NOP
011C NOP
0110 NOP
011E NOP
011F NOP
0120 NOP
-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 . . .. .
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 . . . . # . (
- 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
-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
A>ASM DEMO
CP/M ASSEMBLER - VER 2.0
0018
OOOH USE FACTOR
END OF ASSEMBLY
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
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
A>LOAD DEMO
- 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 ... ..
- 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
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
- 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
A<address>
Enter Assembler Code (Assembl e)
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
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)
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
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)
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
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
A>HELP ERASE
ERASE
Syntax:
Explanation:
OPTION
EXAMPLES
A>ERASE X.PAS
A>ERA *.PRN
Confirm (Y/N)?Y
A>ERA B:*.*
Confirm (Y/N)?Y
A>HELP HELP
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
OPTION EFFECT
A>DIRS
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
3A>
lA >DIR
A:PIP.COM
lA >
lA>PIP BASIC.COM[Gl]=A:MBASIC.COM
lA >DIR
A: PIP COM: BASIC COM
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
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
Typing
A>SHOW [SPACE]
A>SHOW [DRIVE]
A>SHOW B: [DIR]
A>SHOW [LABEL]
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:
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]
FILE.DATiMUFFIN
CP/M Plus (CP/M Version 3.1) 95
A>DIR:MUFFIN[FULL]
A>SET [PROTECT=ON]
A>SET [NAME=MYDISK]
A>SET [PASSWORD=FRED]
A>DATE SET
A>DATE
A>SET [CREATE=ON]
A>SET [ACCESS=ON]
A>SET [UPDATE=ON]
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
A>DEVICE NAMES
A>DEVICE VALUES
A>DEVICE LPT
NEW FILE
*1
1: DEVICE LPT[XON,9600]
2: USER 1
3: DATE SET
4: MBASIC
5: A
Z
*E
8.PIP
There are two more parameters available to the PIP
command in this version of CP/M. These are
Command Effect
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
A>GENCOM PIP
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
A>LINK MAIN=PROGl,PROG2,PROG3,PROG4
CP/M Plus (CP/M Version 3.1) 101
102
CP/M-86 103
A>TYPE DEMOl.A86
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
A>ASM86 DEMOI
A>TYPE DEMOl.LST
10 4 Using CP/M
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
A>GENCl>1D DEMOI
BYTES READ OD I C
RECORDS WRITTEN 0 4
CP/M-86 105
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
107
108 Using CP/M
High Hemo ry
XI OS
( Up to 6K Bytes)
XDOS
(8K Bytes)
BDOS
( 2K Bytes)
Trans i ent
Prog ram
Area
OIOOH
A>
OA >
OA >VDSK:=ON
OA>ASSIGN D:VDSK
111
112 Using CP/M
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:
CP INOS
Intelligent Terrmnats
CP /M
CP /NET
CP/NET 117
A>NETWORK H:=c:(Oll
A>CPNETSTS
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
A>H:DBASE
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.
121
122 Using CP/M
123
124 Index