CP/M is a small operating system whose development was started by Gary Kildall in 1973, and was a primary driving factor for the home micro-computers boom throughout 1980s.
Amstrad CPC 464 was sold with an external disk drive called DDI-1,
that contained a CP/M and AMSDOS as an expansion ROM. The drive came
with CP/M disks, or one could obtain them separately. CP/M is loaded
from a so called CP/M System Disk, typically whose first 2 tracks
contain the CP/M itself. After the system disk is inserted into CPC,
the user needs to issue an RSX command
|CPM to boot CP/M into the
computer. The screen is cleared, and CP/M prompt is presented with the
CP/M 2.2 - Amstrad Consumer Electronics plc A>
A> is the CCP prompt of CP/M, where the letter
A means the current
drive is A. Issuing a
DIR command prints the files in the system
A>DIR MOVCPM .COM : PIP .COM : SUBMIT .COM : XSUB .COM ED .COM : ASM .COM : DDT .COM : LOAD .COM STAT .COM : DUMP .COM : DUMP .ASM : AMSDOS .COM FILECOPY.COM : SYSGEN .COM : BOOTGEN .COM : COPYDISC.COM CHKDISC .COM : DISCCOPY.COM : DISCCHK .COM : SETUP .COM FORMAT .COM : CSAVE .COM : CLOAD .COM : EX1 .BAS EX2 .BAS : ROINTIME.DEM : PARAM .DAT : FLAGDUMP.SRN DUMP .PRN : DUMP .HEX
Some of these files are part of the standard CP/M distribution, and are documented in CP/M manuals. Others come with the DDI-1 Disk Drive and are written by Amstrad. CP/M manuals can be found in public domain in the unofficial CP/M website at the URL http://www.cpm.z80.de/. In addition to these, CP/M 2.2 has the following built-in commands:
ERA, DIR, REN, SAVE, TYPE, USER
First thing we need to do is to format a blank SYSTEM disk, and copy the files we need into it for ease of development. Issue the following command to format a new system disk:
FORMAT.COM is documented in SOFT158 DDI-1 Manual, the second parameter is the type of disc we want to format, in this case a SYSTEM disk. Follow the instructions on the screen.
Once you are done, make sure you have the DDI-1 System Disk in the primary drive, and the newly formatted system disk in the second drive. We will copy the necessary files for development to the new disk. Issue the following commands one after the other:
PIP B:=A:ED.COM PIP B:=A:ASM.COM PIP B:=A:DDT.COM PIP B:=A:LOAD.COM PIP B:=A:DUMP.COM
Note that if you have only one disk drive, you can use COPYDISC.COM utility instead. After entering every command, verify that files are copied correctly by issuing the following:
Having seen all the files we have copied, now remove the DDI-1 System Disk from drive A, and insert the newly created one into drive A. After doing that, restart the CPC, and issue:
to load CPM back again.
At this point we are ready for writing the first "Hello World" application in assembly. One quirky problem is the CPM's assembler ASM.COM uses 8080 mnemonics. Even though Amstrad CPC runs on a Z80 CPU, both 8080 and Z80 are machine code compatible, except the extra features of Z80. This means we are not allowed to use the extra Z80 features such IX and IY and shadow registers, and BIT instructions. Also we have to use 8080 mnemonics to write our code, instead of Z80 mnemonics. This has the advantage that our program will be portable across all CP/M systems using 8080 or Z80.
Issue the following command to edit a source file:
You will be presented with the ED's prompt:
NEW FILE : *
I won't go into details about how to use ED, as it requires special attention and practice to master it. If you make a mistake, use CTRL-Z to exit edit mode, and CTRL-C to quit ED without saving anything, and start over.
Now, enter the following assembly program. I will show keypresses inside brackets except tab characters:
: *I[RET] 1: ORG 100H 2: LXI D,STR1 3: MVI C,9 4: CALL 5 5: RST 0 6: 7: STR1: 8: DB 'Hello, world!' 9:[CTRL-Z] *:E[RET]
We wrote the source code using ED, and saved to the file. You can verify this by issuing the command:
which will print contents of the file HELLO.ASM to screen.
Now we will assemble, and then run the program:
ASM.COM has an interesting format. The last three characters after the period, are not file extensions (file extensions are implicit in CP/M), but which drive the assembler should use for particular outputs, in this case the drive A. Once the source file is assembled, it will generate a file called HELLO.HEX, and HELLO.PRN. The former is an ASCII file containing Intel HEX representation of the machine code output, that you can view the contents of which, using built-in CCP command TYPE. PRN is the assembly listing file. It contains a tabular representation of the machine code as well as assembly mnemonics and the addresses they will be loaded in memory.
Now we need to convert the HEX file into a COM file by issuing the command:
It outputs HELLO.COM, that you can run by typing:
It should print
to the screen if all went well. The reason the output is in capital case, while we entered a lower case "Hello, world!" in the source file is because ED by default converts any input into capital case. We can later use DDT.COM to inspect and debug our program. That I might write down some other time, and this is all for now.