• Please review our updated Terms and Rules here

CP/M bios/bdos calls and files

Dr_Acula

Experienced Member
Joined
Nov 14, 2008
Messages
225
Location
Adelaide, Australia
A quick couple of questions for any resident CP/M experts: I'm using the CP/M bdos calls to read and write sequential files. For reading a file it is fairly easy as you put the file name in the FCB, set the temp DMA to the default DMA location of 80H, then call the openfile function, then the readseq function then the closefile function.

For writes however, I've found you need to two more things. First, call the erasefile function (in case the file already exists), and then call the createfile function. Then open the file, write a record and close it.

Is this the correct way to go about doing things?

And do I need to terminate all files with a ^Z?

Help would be very much appreciated.
 
Last things first.

Only text files need to be terminated with the ^Z.

What you've described with writing a file is the pretty close to the usual way of doing things--but you don't need to open the file after a "Make" call--the file is already open and the FCB is set up.
 
Thanks Chuck for the quick response. This is for adding a 2 gig drive to any CP/M computer that has a serial port. Many things are working now. DIR, ERA, initialise, write and (almost) read. Just some problems handling files coming over from FAT that are of random lengths that are not multiples of 128. I'll publish it all when it is working, as it could be a great way to get files quickly to and from a PC and a vintage machine.

Will it matter if a file is already open with 'make' and you open it again?

I've also found that deleting the file seems to delete the FCB too so the steps are:
set temp dma to 80H
put name and extension into fcb
delete file
put name and extension into fcb
make the file
?open thefile (I'll test leaving this out)
write seq
close file
 
Will it matter if a file is already open with 'make' and you open it again?

Not on CP/M, but MP/M tracks opens, so it may matter there. CP/M is dumb-as-a-stump--there's no open file table and if you feel like twiddling the fields in the FCB, there's no checking done. (A very handy way to physically read a whole disk without making CBIOS calls).

I've also found that deleting the file seems to delete the FCB too so the steps are:
set temp dma to 80H
put name and extension into fcb
delete file
put name and extension into fcb
make the file
?open thefile (I'll test leaving this out)
write seq
close file

The reason that DELETE screws up the FCB is because there's an implied "FIND FIRST/FIND NEXT" associated with that function. In other words, you can delete files with wildcard "?" characters to kill multiple files.
 
Dr Acula (strange name for a Doctor! Are you sure it is your vocation, Medecine?), I saw some of your messages. Too bad you are so far away: I need to do some work on XMODEM, KERMIT, etc. That's why I retyped the historical article where Ward Chirstensen explains the story of XMODEM. Anyway, I also saw that you have lots of questions about CP/M. First thing: which version of CP/M do you use? CP/M had a long history for microcomputers: 10 years. Meanwhile, CP/M was made multi-user, multi-tasking (MP/M-II), had *portable* graphics (running the same under CP/M, CP/M-86, and MS-DOS), and also had a network version (CP/NET under 8-bit systems, DR-Net for 16-bit systems). Finally, any respectable CP/M programmer should have several books in his library. For example, "The Programmer's CP/M Handbook", Andy Johnson-Laird, Osborne-McGraw Hill, 1983 (the files of this book were released one or two years ago). Also, if you program in 8080 or Z-80. Most Old Timers like me prefer the 8080. As far as I know, the last place on Earth where CP/M Old Timers gather (including Allison J. Parent, who start all sentences with "30 years, I made...") is the comp.os.cpm Newsgroup.

Yours Sincerely,
Mr. Emmanuel Roche, France
 
Bonjour, Mr. Emmanuel Roche,

Well sometimes I feel like a vampire when the first 10 patients I see in a morning all need blood tests. Things were so much easier when the art of medicine simply meant knowing which leech to use.

I am using CP/M 2.2. It is the operating system on the N8VEM and it was the operating system on my first computer. I always wanted MP/M though...

My reference book is The CP/M handbook by Rodney Zaks. It is well worn, and it has all the function calls for CP/M. But some things are missing, eg the entire source code for CP/M. We are most fortunate that is now freely available on the internet. I also have "How to program the Z80" also by Zaks, and "The Z80 microcomputer handbook" by W. Barden.

So theoretically, I have access to all the information. But every time I ask a question here, so many kind people post answers containing all sorts of helpful and valuable hints.

Plus also, if I get something working and post it here, I don't want someone to say "well there is a way to do it that is much simpler and uses much less code". That could well have been the case with the fdos calls. So much simpler to use the ones inside CP/M.

I have patched and modified xmodem several times. It needed a patch for the N8VEM so that it talked directly to the UART, as this is quicker than calling routines in CP/M. And I patched it again recently so it starts downloading much faster when files are being sent from a program on a PC.

I have about 10 CP/M boards. Each new design adds a few more features. http://drvernacula.topcities.com/

I have some ideas for creating two add-on serial peripherals for any CP/M machine. One is the uDrive with 2 gig of storage. And the other is a wireless link to other CP/M machines to enable networking. The hardware works for both but the software still needs working on.

Thanks for the link to the newsgroup and for the book suggestion.

What are you working on with xmodem? Is there something you might need help with?
 
You know, I've worked with CP/M since it came with the IMSAI 2-board floppy controller (1.30?) and I've never bought a book on it. CP/M (the 8 bit versions) is simply not that complicated. How much code can one cram into 20K? If you have a question about how CP/M does something, a little probing with a decent debugger will tell you what you need to know, even without web resources. There are no tricks, no copy protection. It's simplicity itself.

ED is easily as complicated if not more so, as the "OS" part of CP/M.
 
Back
Top