CP/M ON THE C128 (Noel Nyman)

Started by Blacklord, September 26, 2024, 10:15 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Blacklord

CP/M ON THE C128 (ARTICLE 1)

by Noel Nyman

(Copyright 1986 by Geoduck Developmental Systems. Permission
to reprint this material is hereby granted, provided this
notice is included in the reprinted material.)

In this column we plan to explore CP/M (Control Program for
Microcomputers) and how to use it on the C128.  A special
INPUT CP/M1 disk is also available with the latest CP/M
operating system, several programs, and reprints of these
columns (see the disk order form elsewhere in this issue).

To understand the what and why of CP/M, we have to go back
to the early days of microcomputing.  In this primitive time
there were mainframes, huge and expensive computers.
Communicating with one required a "console" which had a
keyboard and an output device.  The output was frequently a
printer, although the cathode ray tube (CRT or tv screen)
was becoming more common. Refurbished teletype machines were
often used as consoles.

In the early 1970's a revolution began that would change the
course of computing...the LSI (Large Scale Integration)
micro chip.  It became possible to produce on a single piece
of silicon all the logic in CPU's (Central Processing Units)
requiring several circuit boards on the mainframes.  The
first popular microprocessor chip, the 8080 designed by
Intel, was used to make intelligent terminals.  These were
consoles that contained a keyboard and CRT monitor, a small
amount of RAM (Random Access Memory) and some means of
communicating with a mainframe.

The large hard disks and tape drives used by the main frames
were too complex for a microcomputer to control (there
wasn't enough RAM to hold the controller program required).
So the micros used paper tape. A punch poked rows of up to
seven holes in the half-inch wide tape, each hole
representing a bit in a seven bit character or command.  A
paper tape reader translated these holes into binary data to
store in the micro.  Storing a program was noisy and slow.

In 1973 IBM developed the first floppy disks as alternatives
to the then popular punch cards used on mainframes.  Gary
Kildall at Intel obtained a used drive from a small company
named Shugart and began working on a controller program to
interface it with an 8080 based microcomputer.  He and John
Torode developed the controller into a full disk drive
operating system, which they called CP/M.  Intel wasn't much
interested in the project, and Kildall and Torode began
marketing the product on their own through Digital Research
in 1976. The rest, as they say, is history.

CP/M is an operating system.  Every computer needs an
operating system in order to interface with the console, the
disk drives, and any other peripherals such as modems and
printers.  In the relatively advanced age we live in, home
computers usually come with their operating systems in ROM
(Read Only Memory). When you power up your C128, it "knows"
how to talk to the keyboard, screen, etc.  The Commodore
disk drives have their operating systems in ROM also.  You
don't need to LOAD any program in order to type on the
keyboard, print characters on the screen, or find a file on
a floppy disk.

In 1973 computers were much less smart. Partly this was due
to the high costs of both RAM and ROM. A 32K machine cost in
excess of $3000 without peripherals (1973 dollars, gasoline
was still under $0.20 a litre then).  ROM was very expensive
and difficult to program, EPROM's (Erasable Programmable
Read Only Memory) weren't available.

Each time you turned the power on, you had to teach the
computer how to be a computer all over again.  You did that
by writing a program called the operating system, and
SAVEing on disk or paper tape.  You used another smaller
program that often was typed in by hand each time to LOAD
the larger program.  This method of using a program to LOAD
other programs was called "bootstrapping" since the
computer was in a sense lifting itself by its own
bootstraps.  The idea of "BOOTing" an operating system
remains with us, and is a command recognized by Basic 7.0.

CP/M provided a standardized operating environment on many
different computers.  For example, the TRS-80 machines use
the command LPRINT to send strings to a printer.  Commodore
uses PRINT# followed by a file number. But any printer
routine written on a machine running under CP/M will run on
any other CP/M machine (I'm not sure why "running under" is
used, but that's the proper term).

CP/M comes in four main sections.  The first is the LOADing
routine, which is usually on reserved tracks on CP/M disks.
On the C128, the LOADer is found in ROM.  The two workhorses
of CP/M are the BDOS (Basic Disk Operating System) and the
BIOS (Basic Input-Output System).  Note that the term
"Basic" as used here is a synonym for "primary" or
"essential" and does not refer to the BASIC programming
language.

The BDOS is identical for all CP/M systems of the same
version.  BDOS works much like the Kernal jump table in
Commodore machines, providing access to the routines for
opening disk files, printing strings, and such by simply
calling them by number.  The BIOS is customized for each
computer model.  When the BDOS is asked to open a file, it
uses several BIOS routines which are customized for the disk
drives, data buss structure, etc.

The last section is a program call CCP (Console Command
Processor).  The CCP accepts input from the keyboard,
displays it on the screen, and places it in memory where
appropriate for execution by other programs.  On most
systems the CCP must be reLOADed after other programs finish
execution.  On the C128, the CCP is always resident.

There have been several versions of CP/M produced since
1973.  The C128 runs under CP/M 3.0 (sometimes called
CP/M+).  This is the most advanced CP/M available, used
computers with bank switching capability and over 64K of RAM
can use it.

If you'd like to read more about CP/M, there are many books
available.  Since it's a relatively old system, your library
may be a good source of information.  Try to get material
for CP/M+, since some commands for older CP/M versions are
different.  Some good references are:

THE CP/M PLUS HANDBOOK, Alan R. Miller, Sybex

CP/M AND THE PERSONAL COMPUTER, Dwyer & Critchfield,
Addison-Wesley

If the date on the screen when you BOOT CP/M is older than
December 4, 1985, you should get a copy of the new operating
system.  This is available from CompuServe, Q-Link, the
INPUT CP/M1 disk, or perhaps a user in your area has one.

----Some additional references----

DR DOBB'S JOURNAL, especially earlier issues, covers CP/M
extensively, you local library may have past issues
available.  For an interesting article by Gary Kildall on
the start of CP/M, see the January 1980 issue.

Old copies of BYTE, KILOBAUD MICROCOMPUTING, and INTERFACE
AGE also have articles on CP/M.  For a series on CP/M+,
check the February 1983 issue of MICROSYSTEMS.

Two CP/M user groups have disks available with a variety of
programs.  The 1571 drive will read KayPro IV format.  For                       
more information, contact:

    CPMUG/Lifelines
    1651 Third Ave
    New York NY  10028
    USA

    SIG/M
    PO Box 97
    Iselin NJ  08830
    USA

The Dwyer & Critchfield book above has excellent reference
sections on programming under CP/M in Z80 and 8080 machine
code.  For more details on Z80, try:

    Z80 ASSEMBLY LANGUAGE PROGRAMMING
    Lance Leventhal
    Osborne/McGraw-Hill

    Z80 ASSEMBLY LANGUAGE ROUTINES
    Leventhal and Saville
    Osborne/McGraw-Hill

Blacklord

CP/M ON THE C128 (ARTICLE 2)

by Noel Nyman

(Copyright 1986 by Geoduck Developmental Systems. Permission
to reprint this material is hereby granted, provided this
notice is included in the reprinted material.)

Last time we looked at the origins of CP/M and the component
programs that make up a CP/M operating system.  Before we
look at how to work with CP/M, it's important to understand
what CP/M isn't.

CP/M is NOT a programming language.  Commodore operating
systems rely heavily on the BASIC programming language ROM
to communicate with the user.  CP/M has no high level
language in it.  To program in BASIC, you must LOAD a BASIC
language into the computer.

CP/M does NOT contain a word processor, data base, or any
other sophisticated programs.  It is only an operating
system.  It gives you the ability to LOAD other programs and
utilities, to view disk directories and text files, and to
rename or erase disk files.  It combines some of the
features of the Commodore DOS 5.1 wedge and a sequential
file reading program.  It also gives programs written in
8080 or Z80 microprocessor machine code a universal way to
access the screen, keyboard, disk drives, printer, and
modem.  Most of these programs will run on the C128, even
though they were written many years ago on different
machines running under an earlier version of CP/M.

To start or BOOT CP/M on the C128, place the "system" disk
(the disk that has the CP/M operating system on it) in your
disk drive and turn on the computer or reset it with the
reset button next to the power switch.  If you are in C128
mode, you can type the command BOOT instead.

The older CP/M operating systems supplied with the C128 used
either the forty or eighty column screens.  The systems
dated December 4th and later use only eighty columns.  To
use CP/M effectively, you should be using the newest
version.  This will require an eighty column monitor.

You can use an RGBI monitor, such as the 1902, simply by
plugging in the 9 pin connecting cable.  You can have
excellent eighty column video at much lower cost by using a
monochrome monitor.  Some are even available with audio
amplifiers, for under $100.  You can also use a 1702 monitor
for monochrome with lower resolution.

To use a 1702 or monochrome monitor, you'll need a cable
with an RCA type phono plug on one end and a DB-9 connector
on the other.  You can make one (connect the center of the
RCA plug to pin 7 and the shield to pin 1 of the DB-9), or
purchase one ready made.  Check with your local dealer, or
the ads in Commodore oriented magazines.

Once you BOOT CP/M, you'll see the opening message with the
date and finally

A>

with a flashing cursor behind it.  This is the user prompt,
the CP/M equivalent of Commodore's "READY".  CP/M is
awaiting your command.

The tasks that CP/M can be told to perform in direct mode
are called "utilities".  Six of these utilities are called
"resident" because they are a permanent part of CP/M as it
sits in the C128's RAM.  All other utilities are
"transient", they must be LOADed from disk into memory and
executed, just like a program.

To execute a utility, just type its name at the system
prompt.  For example, type the following:

A> dir

and press RETURN.  The disk drive will spin briefly and
you'll see the names of the files on the disk in drive A.
CP/M uses letters to identify drives, where Commodore uses
numbers.  The C128 CP/M system supports four disk drives,
the defaults are:

      A=8  B=9  C=10  D=11

These can be changed, as we'll see later.  If you only have
one disk drive, the CP/M system will let you use drive E as
a "virtual" drive.  Drive E doesn't exist, but when you
refer to it, CP/M will use available RAM in place of a
drive, or prompt you to put the "E" disk in drive A.  You'll
use drive E to hold files when copying, much as the program
1541 BACKUP uses the C64 RAM to hold files when copying
disks on a single drive.

Each file listed on the directory has two parts, the name
and the extension.  For the program CPM+, the extension is
SYS.  The name and extension together are called the
"filespec".  Files on a CP/M disk can have as many as eight
characters in their file names and up to three character
extensions.  Although the "dir" command shows the file names
and extensions separated by spaces on your screen, you'll
enter filespecs by separating the name and extension with a
"."  as in

    CPM+.SYS

Since CP/M uses the "." to tell where the name ends and the
extension begins, don't use a "." as part of the file name.
In fact, it's best to avoid any characters in file names
except letters and numbers.

You can use any extension you like when naming or renaming a
file.  Some of the extensions have special meaning to CP/M
or some utilities.  But unlike the Commodore DOS, CP/M will
let you rename any program, including its extension, at any
time.

The most important extension for now is ".COM".  Files with
this extension are "command" files.  They are Z80 or 8080
machine language programs.  Usually they are self starting.
To "RUN" a command file, simply type its name at the system
prompt.  Do NOT type the ".COM" extension.  On the INPUT
CP/M1 disk is a simple card game called TWENTY1.COM.  Try
the game now by typing:

A> twenty1

The disk drive will spin, the program will be LOADed and RUN
automatically.  To end the game at any time hold the CONTROL
key and press the "C" key.  This is the CP/M equivalent of
RUN/STOP-RESTORE plus SYS 64738, and is usually abbreviated
CTRL-C or sometimes shown as an "up-arrow C" in texts that
can print an up-arrow symbol.

If you have a second disk drive, you can LOAD programs or
other files from it in one of two ways.  First try

A> b:twenty1

If you forgot to move the disk to drive B, you'll get a
"TWENTY1?" from CP/M, which is asking you if that's really
what you meant to type.  With the disk in drive B, the
program will LOAD and RUN.  Use CTRL-C to exit, and type

A> b:

and you should see

B>

To change the system or "default" drive at any time, simply
type the new drive number at the system prompt.  Don't
forget the colon, or CP/M will look for a file named "B.COM"
on drive A.

With the system drive changed to B, you can enter the name
of any ".COM" file on the disk in that drive without
including the drive as part of the filespec.

Next time we'll look at more of the resident utilities in
CP/M.

If you don't have the latest CP/M system, dated December
6th, you can get it and several useful CP/M public domain
programs, and text file copies of the first four articles in
this series on the INPUT CP/M1 disk.  See the order form
elsewhere in this issue.

Blacklord

CP/M ON THE C128 (ARTICLE 3)

by Noel Nyman

(Copyright 1986 by Geoduck Developmental Systems.
Permission to reprint this material is hereby granted,
provided this notice is included in the reprinted material.)

Before we discuss more resident utilities, let's look at
using disk drives with the C128 in CP/M mode.  The 1571
drive which was designed to work with the C128 will read
regular 1541 type disks and also the MFM type disks used by
many 5 1/4 inch CP/M disk machines.  This has led to some
confusion about just what a "CP/M" disk is.

Commodore uses a process called GCR (Group Character
Recognition) to record data on its disks.  GCR describes the
way in which the disk electrical system works.  It does not
have anything to do with the number of tracks or sectors, or
their placement on the disk.  Apple also uses a form of GCR,
but their track layout is quite different.

When a disk is formatted on a 1541, the DOS (Disk Operating
System) puts 35 tracks on the disk containing 664 sectors.
A 1571 uses exactly the same layout on the "front" of the
disk, then repeats it on the "back", for a total of 70
tracks and 1328 sectors.

When you format a disk using the CP/M utility "FORMAT.COM",
the layout of the tracks and sectors is IDENTICAL to that
used in the standard 1541 or 1571.  The CP/M disk has its
directory area on different tracks and places a BOOT sector
on each formatted disk, but the layout is the same.  You can
prove this by examining a Commodore CP/M disk in C64 mode
with a "disk doctor" program.

This means that you can use any combination of 1541's and
1571's in a C128 CP/M system.  The CP/M disk that came with
your C128 is a single sided (1541) disk.  You can read it
with either disk drive.  You must turn it over to read the
"back" side.  You can also copy a single sided (1541) CP/M
disk with any "bit" copier or with the backup command on a
dual drive such as the MSD.

However, CP/M is NOT practical with a single 1541 disk
drive.  It's just too slow.  If you want to learn about the
CP/M system, or experiment with some of the programs, the
speed will be tolerable.  But any serious programming,
database or word processor work will take too long.  You are
much better off with existing C64 programs for those tasks.
Using one of the many "fast load" programs or cartridges
will make a C64 system much faster and easier to use than a
1541 CP/M system.

If you have a 1571, you can use a 1541 as the "B" drive with
better results.  The disk operations will still be slow on
the 1541.  But you can do your primary work with the faster
drive.

If you are contemplating the purchase of a C128 and two
1571's JUST to run CP/M, I advise against it.  For the same
money you could purchase a low end or used CP/M computer
such as a Kaypro which will run CP/M many times faster than
a C128.  However, for the combination of a fantastic Basic,
excellent sound and graphics, C64 compatibility (mostly) and
CP/M as frosting on the cake, the C128/1571 system is a
good bargain.

Last time we used the "DIR" resident utility to look at a
disk directory.  Enter the command again, and look at the
bottom of the listing.  If the INPUT CP/M1 disk is in your
drive, you'll see the phrase "System file(s) exist".  Now
enter the command

A> dirsys

You should see only the file "CCP.COM" followed by the
phrase "Non-system file(s) exist".

The term "system" refers to an "attribute" or characteristic
given to certain files.  It does NOT refer to the extension
".SYS".  Notice that the file "CPM+.SYS" appears when you
used the "DIR" command, but is not listed with "DIRSYS".

The system attribute is important for hard disk or
multi-user systems.  We'll look at it more closely when we
discuss the "USER" command.  But system files are also less
likely to be accidentally erased.  To erase a system file,
you must use a special command.  So it makes sense to
protect your most valuable files in this way.  We'll use a
utility called "SET.COM" to change "CPM+.SYS" to a system
file.

Place the original CP/M disk you received with your C128 in
drive A and use "DIR" to be sure you have the side
containing "SET.COM".  Then if you have two disk drives,
place the INPUT CP/M1 disk in drive B and type:

A> set b:cpm+.sys[system]

Don't leave a space between the ".sys" and the left bracket.
Be sure to use brackets, shifted ":" and ";".  If you  have
only one drive, type:

A> set e:cpm+.sys[system]

In either case, CP/M will LOAD the program "SET.COM" from
the disk in drive A.  For a two drives, CP/M will then
change the attribute of the file on the disk in drive B.
For one drive, CP/M will prompt you to place the "E" disk in
drive A, and then changes the attribute.

Now use "DIR" and "DIRSYS" to check your work.  "SET.COM"
has many other uses we'll look at later.

Next time we'll look at the rest of the CP/M resident
utilities.  INPUT CP/M1 disk is available with several
useful programs, the newest CP/M  operating system, and text
files of the first four of these articles.  Check the order
form elsewhere in this issue.

Blacklord

CP/M ON THE C128 (ARTICLE 4)

by Noel Nyman

(Copyright 1986 by Geoduck Developmental Systems.
Permission to reprint this material is hereby granted,
provided this notice is included in the reprinted material.)

In this article, we'll look at the rest of the resident
utilities in CP/M.

USER is a utility that was designed for systems with hard
disk drives or multi-user systems.  It allows you to have
sixteen "user areas" on a single disk.  To illustrate this,
type:

A> user 5

Don't forget the space ahead of the number.  CP/M responds
with

5A>

The system will now only look at disk files that were SAVEd
to disk in the user 5 area.  When you type the DIR command,
you'll get a "no files" message because all the files on
your disk are in user 0.  The user number would be handy for
keeping your files separate from another user's on a hard
disk you both share.  It's not very useful to us, because
you can't access another user area files from the current
user area.  This means that any utilities are shut off from
you unless you copy them into the new user area. However,
when you type a file name, CP/M will look for a ".COM" file
with that name in the current user area.  If it doesn't find
one, it will look for the file in user 0, and LOAD it if it
has a "system attribute".  As we saw last time, the system
attribute is not the same as a ".SYS" extension.  If you
want utilities available in other user areas, use SET.COM to
change them to system attribute files.  Change back to user
0 now by typing:

5A> user 0

"ERASE" and "RENAME" are used to erase (scratch) or rename
files on a disk.  The commands can be abbreviated "ERA" and
"REN".  To change the name of the game TWENTY1.COM on the
INPUT CP/M1 disk, type:

A> ren d:TWENTONE.COM=d:TWENTY1.COM

This is similar to the Commodore DOS format where the new
name comes first.  The "d:" represents the drive number
containing the disk with the file you want renamed.  You can
omit if if the file is on the currently logged drive.  Don't
use more than eight characters for the name and three for
the extension.  If you forget the extension, the file will
be named "TWENTONE.  ".  You can change any extensions at
any time, but some utilities expect certain extensions.
Avoid ".HEX", ".MAC", ".ASM", ".BAS", ".HLP" and ".COM" for
general files.  However, if you find a file on a public
domain disk with ".OBJ" (object code file), or ".BIN"
(binary code file), try changing the extension to ".COM" to
get the program to run under CP/M+.

The Commodore DOS wild card rules apply to CP/M as well.
You can use "?" as a single character wild card, or "*" as a
file name or extension wild card in most commands.  For
example

A> dir *.COM

will show you only the ".COM" files on the disk in drive A.
Using

A> ren d:*.bak=d:*.txt

changes all ".TXT" (text) files to ".BAK" (backup) on the
drive specified by "d:".  Typing

A> era *.*

will erase ALL the file on drive A...be careful!  If you use
a wild card in ERA or REN, CP/M will prompt you for a
"YES/NO" before executing the command.

Although DIR, REN, and ERA are resident utilities, they are
"bare bones" versions.  They have all have advanced features
that require too much memory to keep in RAM.  If you try to
use one of these features, you must have the corresponding
".COM" file on disk.  For example, place any disk except the
CP/M system disk in the drive and enter

A> dir [full]


You will get the message "DIR    COM required".  The
advanced [full] option requires LOADing DIR.COM.  Now place
the CP/M system disk in the drive and re-issue the command.
An easy way to repeat a command on the C128 is to tap the
CURSOR DOWN key next to the SHIFT key, not the one at the
top of the keyboard.  The last command entered will be
retyped on the screen.  Press RETURN to execute it, or use
the cursor and DEL keys to change it.

You should now see a much more complete directory listing.
The files are listed in alphabetical order, and their sizes
in bytes and records are shown. The sizes will be in 1K
increments for single sided disks and 2K for double sided.
CP/M records are 128 bytes each.  The attributes of each
file are shown, either DIR or SYS and either RW for "read or
write" or RO for "read only".  RO files cannot be changed
without changing them to RW with the SET.COM utility.

The [full] option also shows total bytes used and free on
the disk, total files found and directory entries used.
Long files may take up two directory entries.  You can see
the same display on a disk that doesn't have DIR.COM by
typing

a> dir [drive=b]

Place the disk containing DIR.COM in drive A and the disk
you want to view in drive B.  If you have only one drive,
replace the "b" with "e".  CP/M will LOAD DIR.COM and prompt
you for the new disk.

The last resident utility, TYPE, allows you to look at files
on your screen and print them on a printer.  All files on a
CP/M disk are either ASCII (text) files or binary machine
code files.  You can only use TYPE with ASCII files.  You
can't harm anything if you accidentally use TYPE on a binary
file, but you'll only see gibberish on the screen, and CP/M
may crash.  If that happens, just re-BOOT the system.

Any file with ".DOC", or ".TXT" extensions can usually be
viewed with TYPE.  If you have the INPUT CP/M1 disk, enter

A> type readme.txt

CP/M will display part of the file README.TXT on the screen.
When the screen is full, a prompt will appear to press
RETURN (almost any key will do), and more of the file will
be displayed.  If you want to exit TYPE, just press CTRL-C.

You can print a text file on your printer by pressing CTRL-P
before issuing the TYPE command.  CTRL-P toggles the printer
on line, and anything that appears on the screen will be
printed as well.  The CTRL-P command produces a tone when
the printer is toggled on.  Pressing CTRL-P again toggles
the printer off and no tone is heard.

While CTRL-P gives you hard copy from TYPE, it also has all
those "Press RETURN..." prompts in it.  You can avoid them,
by using an advanced TYPE option.  Enter

A> type readme.txt[nopage]

The file will scroll up your screen without stopping, and
will print completely.  Since [nopage] is a non-resident
feature of TYPE, TYPE.COM must be on the disk for it to
work.  You can use [nopage] on another disk by typing

A> type d:readme.txt[nopage]

where "d:" is any valid disk drive.

There are many other utility options, too many to discuss
here.  You can find out about them in the DIGITAL RESEARCH
CP/M PLUS USER'S GUIDE.  This is part of the package you get
by mailing in the card bound in the CP/M section of the C128
SYSTEM GUIDE that came with your C128.  The Digital Research
documentation is extensive and a great bargain at the
offered price.  However, it was written by computer folks
for other computer folks.  For easier reading, you may also
want to purchase the CP/M PLUS HANDBOOK by Alan Miller, or
check out the other references listed in the "ARTICLE1.TXT"
file on the INPUT CP/M1 disk.

You should always keep back-up copies of your system disk
and important utilities.  You can copy files with the
utility PIP.COM.  PIP is explained briefly in the C128
SYSTEM GUIDE.  You can also use DIR+.COM found on the INPUT
CP/M1 disk.  You can make full disk copies of any single
sided CP/M disk using a C64 or C128 bit or nibble copier or
a dual drive copier program in non-CP/M mode.  You cannot
use any program that uses BAM or directory references to
copy a disk.

Text files of the first four articles in this series can be
found, along with several additional utilities and the most
current CP/M operating system on the INPUT CP/M1 disk.  See
the order form elsewhere in this issue.