Image Map Image Map
Page 1 of 8 12345 ... LastLast
Results 1 to 10 of 72

Thread: Guidelines for writing software for CP/M?

  1. #1

    Question Guidelines for writing software for CP/M?

    Hi everyone,

    Apologies if that has been asked or answered elsewhere, but I've search the interweb, skim-read a couple of CP/M books and can't find a concise answer to my question.

    I've recently built a single-board computer running CP/M 2.2 on a Z80, mostly as an education in digital electronics but also as an excuse to learn Z80 assembly. What I'd really like to do right now is write my own CP/M programs. I have SLR Z80ASM on the system (which can compile straight to COM file) and the usual software for CP/M 2.2, along with TASM that I'm using on the PC to assemble the monitor ROM program etc, so these are both at my disposal.

    What I really need though is a brief overview of what is required to write a basic program that I can run as a file in CP/M. My understanding so far is that the code should start at 0100h, the start of the TPA. But that's about the limit of my knowledge. I know there are routines that can be called in BDOS and CPM, but I'm not sure what is available, where it is and what its requirements are.

    So, really, an example of a CP/M 'Hello World!' program would be ideal - as would any links to reference material or suggestions where I could look myself for this sort of info.

    Any help would be appreciated!

    Thanks

  2. #2
    Join Date
    Jun 2012
    Location
    UK - Worcester
    Posts
    1,519

    Default

    Hi,

    As this is your first post, welcome to VCFED.

    Most of what you need can be found at http://www.seasip.info/Cpm/index.html. Look for "BDOS". I would suggest starting here
    http://www.seasip.info/Cpm/bdos.html To start with.

    Basically:

    1. Set up your own stack and stack pointer.

    2. Set up register DE to point to your string. Don't forget to terminate your string with '$'.

    3. Call BDOS function 9.

    4. Exit your program. Jump to location 0, call BDOS function 0, or use RST 0.

    Just watch which BDOS calls you are using and compatibility with CP/M 2.2.

    Ask more questions if you need to.

    Dave
    Last edited by daver2; August 28th, 2017 at 12:22 AM.

  3. #3

    Thumbs up

    That's awesome, thanks Dave - exactly what I was after.

  4. #4
    Join Date
    Jan 2007
    Location
    Pacific Northwest, USA
    Posts
    25,230
    Blog Entries
    20

    Default

    Personally, I'd keep things simple and use the DRI-provided tools to start--ASM, LOAD and DDT. While using the Z80 instruction set may be convenient, there's little benefit to using it for simple tasks--and it's considerably more complex for a beginner. Many commercial programs were written in 8080, not Z80 code to appeal to the widest possible group of 8-bit CP/M users. Remember that the Intel 8085 existed at the same time as the Zilog Z80.

  5. #5
    Join Date
    Jan 2010
    Location
    Central VA
    Posts
    3,409

    Default

    I wrote the first part of a multi-part article for 300 Baud Magazine on ASM for CP/M. The magazine is no longer available, but they released the PDFs for free:

    http://filedump.glitchwrks.com/zines...00_Baud_03.pdf

    I stuck to the DRI tools included with CP/M 2.2. I believe I was using VEDIT as my programmer's editor at the time.

  6. #6
    Join Date
    Dec 2013
    Location
    Near Milwaukee Wisconsin
    Posts
    866

    Default

    Here is a link to the CPM BDOS calls (if you don't have them). http://www.gaby.de/cpm/manuals/archive/cpm22htm/ch5.htm The BDOS calls do much of the interface work for you. You do not have to know port numbers etal. I use WordStar for my editor. EDLIN will work but it takes a little extra thinking. I'm not familiar with VEDIT. But you need to have the editor save in the text mode not a document mode. Once you have your file say test.asm you need to run ASM test. If there are errors, fix them else run LOAD which will produce the COM file. It's not rocket science, but can be confusing until you've struggled thru a few times. Try it and ask questions. Good Luck, Mike
    Last edited by Mike_Z; August 28th, 2017 at 12:54 PM.

  7. #7
    Join Date
    Jan 2007
    Location
    Pacific Northwest, USA
    Posts
    25,230
    Blog Entries
    20

    Default

    Easiest thing to do is to start with a "Hello World" test using ASM. It's best if you have experience with assembly language in general.

    First edit and create a program file called "HELLO.ASM":

    Code:
            ORG     100H
    
    BDOS    EQU     0005H                   ; LOCATION OF BDOS ENTRY POINT
    BOOT    EQU     0000H                   ; LOCATION OF BOOT REQUEST
    
    START:
            MVI     C,9                     ; BDOS REQUEST 9 - PRINT STRING
            LXI     D,MESSAGE               ; OUR STRING TO PRING
            CALL    BDOS
            JMP     BOOT                    ; EXIT TO CP/M
    
    MESSAGE:
            DB      13,10,'HELLO WORLD',13,10,'$'
    
            END     START



    To assemble and run the program (assuming that your system is on drive A:

    Code:
    A>ASM HELLO.AAZ
    CP/M ASSEMBLER - VER 2.0
    011B
    000H USE FACTOR
    END OF ASSEMBLY
    A>LOAD HELLO
    
    FIRST ADDRESS 0100
    LAST  ADDRESS 011A
    BYTES READ    001B
    RECORDS WRITTEN 01
    
    A>HELLO
    
    HELLO WORLD
    A>
    Just that simple!

  8. #8

    Thumbs up

    Firstly, thanks everyone for the replies - there's plenty for me to be getting on with. Thanks Chuck for the code example - that's precisely what I needed to get me up and running. I'm certainly no assembler expert, but I'm learning!

    Quote Originally Posted by glitch View Post
    I wrote the first part of a multi-part article for 300 Baud Magazine on ASM for CP/M. The magazine is no longer available, but they released the PDFs for free:

    http://filedump.glitchwrks.com/zines...00_Baud_03.pdf

    I stuck to the DRI tools included with CP/M 2.2. I believe I was using VEDIT as my programmer's editor at the time.
    Thanks for the link to the 300 Baud magazines, glitch - they're really interesting! I'm assuming 300 Baud never got to issue 4?

  9. #9

    Exclamation Error compiling source

    Hmm... I'm trying the example provided by Chuck(G) above and getting the following error:

    Code:
    A>ASM HELLO.AAZ
    CP/M ASSEMBLER - VER 2.0
    NO SOURCE FILE PRESENT
    
    A>
    This is despite there being an .AAZ file present and correctly named. I've tried writing it in ED and still get the same error (I'm using the AltairZ80 emulator, so I initially tried importing a Notepad file.) Pretty much the same error when I use ZASM80 too, although that indicates line 1 as being the cause of the error (line 1 is just ORG 100H)...?

  10. #10
    Join Date
    Jun 2012
    Location
    UK - Worcester
    Posts
    1,519

    Default

    Have you called the file HELLO.ASM or HELLO.AAZ?

    The file should be called HELLO.ASM. The AAZ are the parameters to assemble the source file against. You have told the assembler that the source file HELLO.ASM is on drive A. Is this actually correct?

    Checking the TDL ZASM manual, I can't see an ORG directive (all of the pseudo operations begin with a '.'), so I suspect the error that has been returned is correct in this case! The equivalent to ORG is .LOC in this assembler...

    Do not keep switching assemblers - they are not compatible.

    The question is, do you want to learn 8080 or Z80 mnemonics? You originally stated you wanted to learn Z80 assembly, so my recommendation would be to learn the Zilog mnemonics and pick a compatible assembler (preferably a macro assembler). Z80ASM seems good. If you want to learn to program for CP/M, then 8080 mnemonics would be a good choice, so pick your assembler accordingly (ASM or MAC will be suitable). If I can find some time today I will write a Z80 HELLO WORLD for you.

    Dave
    Last edited by daver2; August 29th, 2017 at 11:59 PM.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •