1

For a hobby project I'm porting the Standard C Library to the Digital Research CP/M. Inside CRT0.S (this is the code that runs before your main() C function is called) I have no trouble parsing the tail of the command line arguments from the lower memory, but I'm unable to get the running program name i.e. if I type

memdump 0xfc00 100

I'd like to obtain memdump or memdump.com from CP/M in a nice way so that I can set my args to (pseudo code) correctly

argv[0] = "memdump.com";
argv[1] = "0xfc00";
argv[2] = "100";
Tomaz Stih
  • 529
  • 3
  • 10
  • Maybe argv[0] is not available once the .com has been loaded? (does CP/M have the Program Segment Prefix?) – wildplasser Aug 10 '21 at 10:09
  • 2
    Digging around in the cold storage area of my memory, I came up with `CS:0080h` as the location of the command line buffer in .COM programs. Hopefully the information isn't damaged by frost bite ;) – 500 - Internal Server Error Aug 10 '21 at 10:19
  • Time to dig up the pink-shirt-book... (IIRC QDOS borrowed this part from CP/M) – wildplasser Aug 10 '21 at 10:33
  • The 0080h address (my target is Z80, CP/M 3 Plus) contains only arguments tail. So it starts with argv[1], but there is no program name there. So it would have to be either some weird BDOS/CCP hack, to obtain FCB, or command line. I tried with the 48 function (SCB block), but even there the console buffer is empty. – Tomaz Stih Aug 10 '21 at 10:57
  • @500-InternalServerError lol. I had no idea that jurassic CP/M was in use anywhere. – Martin James Aug 10 '21 at 10:57
  • I checked a lot of code samples. For example this example (it is 8080, not Z80, but ok for the research) suffers the same problem. https://rosettacode.org/wiki/Command-line_arguments#8080_Assembly It just get the args, no command name. – Tomaz Stih Aug 10 '21 at 11:07
  • In DOS, at CS=DS:0x80, there is only the command-tail, prefixed by its length. To obtain the executable file name you may have to peek deeper... – wildplasser Aug 10 '21 at 11:11
  • The HI-TECH Z80 C compiler for CP/M suffers from the same problem. argv[0] is an empty string. The C standard says that argv[0][0] shall be the null character if the program name is not available from the host environment, so that aspect of the HI-TECH C compiler is compliant. – Ian Abbott Aug 10 '21 at 12:44
  • I checked HI-TECH and this is the code they use to get the args : args = _getargs((char *)0x81, "myprog"); So they pass the program name. I guess I could add this to crt0.s as part of the compilation process as I found no other solution. But of course; I wrote a small memory scanner and there is a program name in memory, when you start it. Just don't know how to get to it. :) – Tomaz Stih Aug 10 '21 at 12:49
  • You could set it to a default in `main(argc, argv)`, something like: `static char myarg0 = "myprogname";` `if (argc && !argv[0][0])` `argv[0] = myarg0;`. – Ian Abbott Aug 10 '21 at 13:43

0 Answers0