Tuesday, November 20, 2018

Something old for something newish

Every so often I build using 8085 or a member of the Z80 family and I tend to run CP/M usually V2.2 on it as a OS.  This is the reason why and it still hold true to this day.

Looking at Grant Searle's  and Lee Hart's pages made me think of this.

http://searle.hostei.com/grant/cpm/index.html

http://www.sunrise-ev.com/z80.htm


Why CP/M?

For most OS and hardware the classification is vendor specific or not. Examples of vendor specific is Apple 6502 based systems programs didn't run on Commodore systems without significant modification while the CPU was identical the surrounding OS support and hardware tended to differ sometimes greatly.  In the Z80 would a good example was TRS80, it ran an OS unique to that machine and only on that machine or possibly a handmade clone with copies on the Roms.  There is not a thing wrong with this is you want to clone a system.

CP/M however was totally different because it ran on many machines based on the heirs of 8080, or put differently if a program runs under CP/M-80 on an 8080 then some machine with a Z80 and CP/M installed will run it and likely faster.  CP/M didn't care if the CPU was 8080, 8085, Z80, Z180, Z280 or even NSC800 as they at the base binary level of 8080 were the same.   What CP/M did was make the hardware look the same by abstraction in a new for the time section of code called the BIOS. Different machines could and likely had different BIOS to deal with NEC or WD floppy controller or maybe even a built from TTL controller and also same for the different serial devices (SIO, 8251, USART, ACE, 6850). 

This standardization allow program portability for things like all manner of programming languages, Multiplan, Dbase, Wordstar, as well as programming editors, debuggers, and both cross and native assemblers to run on nearly any CP/M system that had reasonable ram usually 48K, enough storage and for some IO(terminal) that was compatible (mostly editors).  This allowed a great deal of software to be made and distributed much of it free as well as commercial.

So, CP/M as modules!

CP/M is basically three modules, CCP (command control processor) or what we call the user interface to the system.  The program interface is the BDOS Basic Disk Operating system, its the set of APIs to read and write files print to the printer and handle basic console IO.  The last already mentioned is the BIOS, it takes a standardized interface and turns it into real IO.

The only one written by the developer is the BIOS for a specific machine.  The whole of the machine specific IO and storage system is defined here.

The BDOS is a 3.5K chunk of code that was early on a black box with a matching relocator if needed now the source is easily available and can be assembled for any address.  This is largely the same for the CCP, early on it was a 2K lump with a relocator.  With time it was also rewritten from scratch as ZCPR or CCPR as an improved user interface.

How the blocks are used.

The system used to be loaded from non file system parts of the disk known as system tracks.  The boot ROM would load about 2-4k (the BIOS) to high memory and then jump to the ColdBoot where the BIOS code would set up devices and also initialize page 0 (the first 256 bytes of ram) with vectors as needed.  After doing that the system does a WarmBoot where the rest of the system is loaded including the BDOS and CCP. CP/M assume the CCP is overlaid by applications and can even accommodate overlaying the BDOS and will reload both after a warm boot.  That is done to allow most all of the ram to be available to applications.

I'll stop here and point out that in the early days System tracks stored this that image but with larger Eproms it was possible to copy from Eprom to memory that being far faster than floppy or disk in general and for small floppies made about 8k of space available for storage.  The other assumption is CP/M only cares that storage is block addressable and not if its disk, tape, Ram, or Flash.  Another feature is the loaded version can even load a improved version so an improved CP/M can be a file that can be edited and assembled for test on the system with the ability to recover.


Functions:

CCP allow doing basic operations like directory, loading, saving, erasing, or executing files.  DOS largely used the same command line interface and the history of that form of command reaches back to PDP-11 RT-11.

The BDOS allow for functions like open a file, read a file test for file presence and also allocating space to a file.  Other functions are get a char from terminal putting one to the terminal and testing for a char waiting among others (about 40 in all).

The BIOS can be used directly if one needs to write to a block of disk that is not part of the file system or even edit the file system directly.  For that there are set Track, Set sector, Read and write a block (usually logical sector).  Also the serial and printer ports are handled at the IN and OUT level.  Its features is it was written to a standard specification as needed by the BDOS and it also made for likely the most widely varied code that all performed a standardized set of tasks.

The history of CP/M is that it begat PC-DOS aka MSdos which for the early years even supported the same FCB structure for files.  Its legacy is in the idea of a BIOS to make disparate hardware look similar if not the same. to the applications.  But its greater impact was a software industry be it freeware, shareware or commercial paid code that could be used on a wider population of machines no matter who made it.  That level of functionality and advancing performance or disks and CPU in the z80 space kept it on the map till the late 80s and in some case mid 90s.  It remained so because the cost of computers is not only hardware though it was significant.   For once who made the machine did not determine if you were locked to a software vendor and code that was good on an old machine will still remain useful on newer hardware.