• Please review our updated Terms and Rules here

CP/M 2.2 Source Code

Mike_Z

Veteran Member
Joined
Dec 1, 2013
Messages
1,713
Location
Near Milwaukee Wisconsin
On the unofficial CP/M site I found the source code for CP/M in afile called CPM22.ASM. I am unfamiliar with this assembler and would like a little help deciphering it. Here is a clip from it,

Code:
;   Set origin for CP/M
;
	ORG	(MEM-7)*1024
;
CBASE	JMP	COMMAND	;execute command processor (ccp).
	JMP	CLEARBUF	;entry to empty input buffer before starting ccp.

;
;   Standard cp/m ccp input buffer. Format is (max length),
; (actual length), (char #1), (char #2), (char #3), etc.
;
INBUFF	DB	127	;length of input buffer.
	DB	0	;current length of contents.
	DB	'Copyright'
	DB	' 1979 (c) by Digital Research      '
	DB	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	DB	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	DB	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	DB	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
INPOINT	DW	INBUFF+2;input line pointer
NAMEPNT	DW	0	;input line pointer used for error message. Points to
;			;start of name in error.
;
;   Routine to print (A) on the console. All registers used.
;
PRINT	MOV	E,A	;setup bdos call.
	MVI	C,2
	JMP	ENTRY

I want to recreate the 20k system so the ORG which should be the start of CCP would be 3400H. I suspect that the first code at 3400H would a jump C3 and then the address of COMMAND then another jump C3 and the address of CLEARBUF. What is the next mnemonic? MOVEA, MVIC, 02, C3 and the address of ENTRY?
I'm trying to id the code I have gotten from another file CPM.SYS.
Thanks Mike
 
Mike, the code looks like plain old CP/M ASM. Get yourself an emulator on a PC and run the genuine CP/M assembler--there are manuals online in the CP/M repositories that describe the very simple ASM assembler. My guess is that ENTRY is defined somewhere as absolute location 0005, the common entry point to the BDOS API in CP/M (and even Windows, for that matter--it never went away).
 
Tell me about an emulator. Could I run that on a DOS pc? It would look like a cp/m machine? Could I put the above source code in it? to inspect it and re assemble it? Mike
 
Mike_Z said:
...Tell me about an emulator....

MyZ80 can run in DOS or in a Windows "Window" that looks like DOS. The advantage of the latter is that you can have other tasks open which is convenient when you're looking for a download on your hard drive that you'd like to IMPORT into MyZ80's emulation. You don't have to exit if you decide you need to go download something to IMPORT into the MyZ80 emulation.

It comes with a emulated CP/M that works fine. It explains how to install CPM 2.2 or 3.0 if you want. You can link its serial and printer port to ports on the PC.

You can get the ASM assembler that DRI provides in that same KP483.zip file I linked you to yesterday. There are much better assemblers but as you write in 8080 assembly language for an 8080 processor, ASM would be fine.

Personally I always bought SLR Z80 family assemblers. Z80, HD64180... just wish they did eZ80.

Here are some URLs:

http://www.z80.eu/downloads/myz80124.zip (buried in the URL page below)
http://www.z80.eu/myz80cpm.html
http://www.znode51.de/specials/myz80.htm
 
Last edited:
Thanks for the info. I just read the first K or so of the CPM.SYS file I reconstituted. It is CPM and matchs the source code that I shown above. That code is written for CP/M that has been configured for a 62K machine. I don't think that I'll use that file. I would have to re assemble it by hand to get it back to a 20k system. Maybe a better route would be to look into one of these emulators and re assemble the source code with some changes so that I can have a 20K system. I want to go through the entire method of going from the 20k system, writting the get and put, etal. thanks again, Mike
 
Here's a ZIP with the CPM20.COM file and the MOVCPM.COM file that goes with it as described on page 6 of the "CPM 2.2 Alteration Guide". In other words, the MOVCPM 20 * and SAVE 34 CPM20.COM has been done. You'll need the MOVCPM.COM (patched so that it works with any CP/M 2.2 copy). You should be able to take things off from there. Note that the CCP entry point isn't until offset 880h in the CPM20.COM file.
 
Thank you very much for the files. I downloaded them and have the CPM20.COM & MOVCPM.COM. Forgive me if I appear a little dense here but I don't understand what you said.

In other words, the MOVCPM 20 * and SAVE 34 CPM20.COM has been done. You'll need the MOVCPM.COM (patched so that it works with any CP/M 2.2 copy).

What is MOVCPM * and SAVE 34 CPM20.COM? Do you mean that the MOVCPM.COM *, you provided, was used and that changed it? My plan was to get the CPM20.COM into my 8080 machine and then use 'MY' MOVCPM.COM to reconfigure it to a larger memory size. The SAVE 34 CPM20.COM, is a cpm command that saves 34 - 256 byte blocks from 0100H to a file called CPM20.COM. So that is just saving the file?

I'm hoping that I can make a IMD image file of your CPM20.COM. That way I can get it onto one of my 8" disks and hence into the 8080 machine. I've written some code for CONST, CONIN and CONOUT, which I'll first add to the CPM20. I'm hoping that with this, I can boot up CPM on my 8080, just to see if 'something' works. After that I can add the other BIOS routines, until I have all the stuff and the CPM20 version works. Only then would I consider moving it to the full memory size.

Thanks a million, Mike
 
DRI used a little bit of copy-protection on their systems--when a new system is generated (for example, when chaniging the size), MOVCPM is used. Ever since about CP/M 1.4, each copy of MOVCPM and the actual working copy of CP/M have a serial number embedded (6 bytes). If you try running MOVCPM on system whose serial number doesn't match, you get the message "SYNCHRONIZATION ERROR", interrupts are disabled and a HLT instruction is executed. The patch merely makes the check for the 6-byte serial number come out always true, so the version that I've included can be used on ANY system.

As I mentioned in an earlier post, the CP/M resident occurs in two places. The first is on the boot tracks of a system disk; the second is in MOVCPM itself. One is used to boot the machine; the other is used to resize and generate new systems. The MOVCPM copy also contains a page relocation list--what DRI sis was to assemble CP/M twice, ORG-ed 100h bytes apart, then compare the two and generate a list of offsets that tells the code in MOVCPM how to relocate any address references.

Follow the instructions from the CP/M alteration manual and you should be fine--I've gotten you something to work with. All of the code in the alteration manual assumes the DRI ASM assembler. So right now, your job is to write a boot loader, and a minimal CBIOS, put the whole thing together as a disk image and generate a disk. You don't have to worry about GETSYS and PUTSYS since you're obviously working on a PC.
 
This morning I successfully converted the CPM20.COM to an IMD file, wrote it to the 8" disk and read it into the 8080 machine. I then hand coded the jump vector table and CONST, CONIN and CONOUT into this code and saved it onto the 8" disk. BUT, I'm having trouble determining the start address to test this code. I though of using 3400H, but that has a jump into TPA, I looked at 0880H into CPM20.COM. I figured that address is the beginning of the 18th sector, here there is a Jump to 375C H, which jumps to a boat load of NOP's and the a RST7, which doesn't work. Am I thinking about this correctly? Thanks Mike.
 
I just noticed that when I posted the last post, Chuck(G) posted something just before me, maybe while I was typing.

The boot loader should load the first two tracks of the new CPM20 file into memory starting at 3400H or 064 000 Octal, did that.

Then I wrote the vector jump table for all the commands and CONST, CONIN and CONOUT. Copied that onto the disk.

I figured that with the console routines I could start CP/M and see if I get the sign on message and maybe the A:>.

Problem is, as stated in the prior post, where do I start the program. I thought of at the beginning of the CCP at 3400H, but that jumps to the TPA at 01 5C Octal. This is where my loader is. I looked at your suggestion of an offset of 880H. I'm assuming that an 'OFFSET' means 880H bytes into the program. This, by my calculations is the beginning of the 18th sector, which as I said a bunch of NOP's. Could this be the location where some of the disk routines should be? I was assuming that I could test the code with just the console routines. Mike
 
Okay, let's start with the elements.

First, "CP/M" as in the resident code is actually two bits--the command line processor or CCP, which can be overwritten by a program if extra storage is needed and the never-should-be-overwritten BDOS with its I/O support routines (BIOS). A "cold boot" loads everything, as well as initializes the key locations in low memory (i.e. IOBYTE, and the jumps at 0000 (cold reboot) and 0005 (entry to BDOS). Note that, without those low memory locations set up (the BDOS initialization has to do this), your system won'd run. It's entirely possible that you'll need the disk routines present also, at least to return appropriate dummy status.

A "warm boot" reloads only the CCP, leaving everything else in place. So your BIOS has two "end of program" entry points. Both transfer control at the end of initialization to the CCP.

In the CPM20.COM file I sent you, the CCP entry point is at an offset of 880H in the file:

Code:
00000880  c3 5c 37 c3 58 37 7f 00  20 20 20 20 20 20 20 20  |.\7.X7..        |
00000890  20 20 20 20 20 20 20 20  43 4f 50 59 52 49 47 48  |        COPYRIGH|
000008a0  54 20 28 43 29 20 31 39  37 39 2c 20 44 49 47 49  |T (C) 1979, DIGI|
000008b0  54 41 4c 20 52 45 53 45  41 52 43 48 20 20 00 00  |TAL RESEARCH  ..|
000008c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

If you're seeing something else, check your utilities. As far as disk layout, the first sector is boot 80h bytes, followed by 16 sectors of BIOS (800h bytes), followed by the CCP, BDOS and BIOS. BTW, that string of spaces preceded by a 00 byte can be patched at boot time with a command to implement an "AUTOEXEC.BAT" sort of facility.

The actual locations on the boot tracks are somewhat arbitrary, as the disk locations are important only to your BIOS, which does the loading. So you can expand this area if need be, or even locate it somewhere else on disk. Your "boot sector" area can be likewise expanded.

Again, read and understand the "CP/M 2.2 Alteration Guide". Everything you need is there.
 
OK, I've got something to look at. I can tell you that the data you show in the code clip above is exactly what I have. The C3 5C 37 is a jump instruction to 067 134 Octal. Here, there is a bunch of NOP's. Let me digest this for a while, maybe the light will go on. Thanks Mike
 
What tool are you using to look at the data? Remember that DEBUG, for example, loads files at 0100h, not 0. So you'd see the code at location 980h.

The late Vern Buerg's LIST is still a very valuable DOS tool for looking at files. For the above clip, I used Linux "hd".
 
I think I have a larger hole in what should be the CCP code. I have NOP's from offset 0320H thru 0778H of your cpm20.com file. Is that correct? Mike
 
I show the following holes (taken from the downloaded CPM20.COM):

Code:
00000290  20 43 50 2f 4d 20 76 65  72 73 20 32 2e 32 24 00  | CP/M vers 2.2$.|
000002a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000006f0  00 00 00 00 00 00 00 00  ff 22 00 00 00 1a 3d 03  |........."....=.|
00000700  fa 00 1a 1d 3e fa cd a6  1d c9 11 00 00 0e 03 cd  |....>...........|

and

Code:
000007f0  05 00 32 ae 1e c9 21 bf  1e 70 2b 71 2a be 1e eb  |..2...!..p+q*...|
00000800  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000880  c3 5c 37 c3 58 37 7f 00  20 20 20 20 20 20 20 20  |.\7.X7..        |
00000890  20 20 20 20 20 20 20 20  43 4f 50 59 52 49 47 48  |        COPYRIGH|

and, much later:

Code:
00001030  20 20 20 20 20 53 55 42  00 00 00 00 00 00 00 00  |     SUB........|
00001040  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00001080  02 16 00 00 01 6f c3 11  3c 99 3c a5 3c ab 3c b1  |.....o..<.<.<.<.|
00001090  3c eb 22 43 3f eb 7b 32  d6 49 21 00 00 22 45 3f  |<."C?.{2.I!.."E?|

and

Code:
00001380  3d 32 45 3f c9 3e 01 c3  01 3f 00 00 00 00 00 00  |=2E?.>...?......|
00001390  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000013c0  00 00 00 00 00 00 00 21  0b 3c 5e 23 56 eb e9 0c  |.......!.<^#V...|
000013d0  0d c8 1a 77 13 23 c3 50  3f 3a 42 3f 4f cd 1b 4a  |...w.#.P?:B?O..J|

Those should give you a way to check your bearings. That "hole" between 0000h and 0880h is where your bootloader and CBIOS go. MOVCPM does not process those.
 
OK, I checked the file and I have those NOP holes just as you show. But your last statement confuses me.
That "hole" between 0000h and 0880h is where your bootloader and CBIOS go.
The manual states that the 1st sector is the boot sector, the next 16 sectors are the CCP, followed by 28 sectors of BDOS and the last 7 sectors is the BIOS. Shouldn't the CBIOS be placed in the last 7 sectors and not between 0080h and 0880h? Mike
 
There's no hard-and-fast convention--it's whatever your BIOS wants to do. There's a lot of flexibility. For example on one CP/M version that I did, the ROM disk loader uses Intel "hex" format input, which is used to load the BIOS; the BIOS then proceeds to load the CCP and BDOS. What you describe is the most common convention, but by no means the only one. You could, for example, put the CP/M system and BIOS in the middle of the floppy--I have one such system from National Semiconductor that does just that.

Just forget what I'm saying and follow the alteration guide; it won't steer you wrong. :)
 
OK, but the manual still is confusing me. It is telling me that the CCP starts at 3400H, so I loaded the tracks 0 & 1 to 063 200 Octal. This is were the boot sector starts and CCP would be at 064 000 Octal. Then as I'm looking around, I'm finding that all the CALLS are off by 2k. So just for grins, I loaded tracks 0 & 1 at 053 200 Octal, 2k lower and now the CALL's are lined up. By that I mean they are calling the correct routines. OK, I'm quitting for tonight. Tomorrow, I think I need a little more in my crude CBIOS. I have to set up page zero. Thanks for the help. Mike
 
Back
Top