CP/M Gently

If you are interested in retrocomputers, you might be like us and old enough to remember the old systems and still have some of the books. But what if you aren’t? No one is born knowing how to copy a file with PIP, for example, so [Kraileth] has the answer: A Gentle Introduction to CP/M.

Of course, by modern standards, CP/M isn’t very hard. You had disks and they had a single level of files in them. No subdirectories. We did eventually get user areas, and the post covers that near the end. It was a common mod to treat user 0 as a global user, but by default, no.

That leads to one of the classic dragon and egg problems. PIP copies files, among other things. It knows about user areas, too, but only for source files. You can copy from user 3, for example, but you can’t copy to user 3. But that leads to a problem.

Suppose you switch to user 3 for the first time. The disk is empty. So there’s no PIP command. To get it, you’ll need to copy it from user 0, but… you can’t without PIP. The solution is either genius or madness. You essentially load PIP into memory as user 0, switch users, then dump memory out to the disk. Who wouldn’t think of that?

Some people would load PIP with the debugger instead, but it is the same idea. But this is why you need some kind of help to use this important but archaic operating system.

Of course, this just gets you started. Formatting disks and adapting software to your terminal were always a challenge with CP/M. But at least this gives you a start.

Can’t afford a vintage CP/M machine? Build one. Or just emulate it.

13 thoughts on “CP/M Gently

  1. A Zenith/Heathkit Z89 with disks but no documentation dropped in my lap for a few weeks when I was thirteen. Pre-internet times. Knowing nothing of CP/M at the time I was able to find my way around using what I knew of MS-DOS, enough to explore the file system and play some games. I remember Hangman as the killer app.

    1. MS-DOS is very similar to CP/M, in part because early versions of the former are practically a clone of the latter.

      Later releases of MS-DOS diverge somewhat, but afaik some significant fundamental concepts are retained.

    2. Leor Zolman’s BDS C compiler came with the source to many simple games: Snake, Pacman, others. All simply using cursor move commands which we would hack into the source with the ‘non-ANSI’ vendor specific cursor commands – poor man’s “curses”. I spent countless hours learning C with that code. BDS stood for “Brain Damaged Software”, said Leor.

  2. CP/M had other interesting technologies, too.
    Such as hardware-independent GSX graphics system,
    when IBM PCs were stuck to CGA for compatibility (lowest common denominator).

    https://www.seasip.info/Cpm/gsx.html
    http://toastytech.com/guis/gsx.html

    Or MP/M, CP/Net and MP/M II operating systems.
    MP/M was like the power user version of CP/M, with multitasking and multiuser capabilities.

    Example videos found here:
    https://hackaday.io/project/163683-the-thing-fpga-stm32/log/165910-the-mpm-experiment

    On x86 PC-side, they’ve existed, too.

    Concurrent DOS, Wendin DOS and PC-MOS/386 were DOS compatible OSes that had similar features.
    You could run well-behaved DOS programs on serial terminals, even.
    Meanwhile, DOS had CTTY command at best (no ANSI support).

  3. CP/M user areas are thoroughly cursed — most of the operating system is spectacularly well designed, but not those. They were clearly added after the fact and don’t fit in well with the rest of the system. They work well enough as ‘virtual drives’, but user-area-aware programs are difficult to write and I think they’re best avoided.

    (The reason they work so badly is that the current user area isn’t part of the FCB you use to refer to open files — it’s a global setting. This means you have to set the current user area before every system call. If you get it wrong, you risk corrupting your data as the filesystem overwrites extents in the wrong user area! What they should have done was to extend the FCB by one byte and storing the file’s user area there, but that would have broken compatibilitiy.)

    BTW, if you want Yet Another CP/M Emulator, I have a minimal emulator intended for running individual programs, complete with stuff like host OS support and a debugger: https://github.com/davidgiven/cpmish/tree/master/utils/emu It was originally written for running compiler tests, but I find it rather useful for quickly testing CP/M programs without needing to spin up a system emulator.

    1. This is brill, I have been trying to get a full browser-based CP/M emulator working for development use as part of my online IDE but so far only simple stuff like text adventures and microsoft basic run, still need a lot of biosish stuff and remaining instructions I think. I will definitely check out your repo :)

    2. that’s funny because in describing the problem you describe the remedy. just put a wrapper around your file i/o functions that manages this extra byte, munging the global state as needed at every sys call. but – man! – i remember how expensive wrappers seemed even 30 years ago!

    3. I used an open source alternative to CP/M called ZCPR. It was written in Z80 assembly language, and so wouldn’t run on an 8080 or 8085 box. It had good support for the user areas notion.

      I think CP/M’s biggest problem was that you couldn’t ask it for the exact size of a file. It allocated storage with a granularity of 128 bytes, and expected you to drop a CtrlZ at the end of your text file so your app could find the end. Binary files had to do some trickery like reserve the 1st four bytes to hold the actual length or use metadata in another file to know the size.

  4. I still have some fond memories of dealing with CP/M on an Osborne-I. It wasn’t just the 52×24 screen size, but that it could emulate a 80×25 screen that you needed to scroll around to see all of. The keyboard was rock solid, and if detached from the system could be used as a blunt weapon in self defense, or a hammer in home construction. It’s still out there somewhere collecting dust. I think I need to go find it now.

Leave a Reply to valkyrie0528Cancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.