MDOS command line

From Ninerpedia
Revision as of 23:23, 5 November 2011 by Mizapf (talk | contribs) (Created page with "== Getting the arguments from the MDOS command line == There is only little documentation on the MDOS environment. One of the most interesting questions is how to retrieve the c...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Getting the arguments from the MDOS command line

There is only little documentation on the MDOS environment. One of the most interesting questions is how to retrieve the command line arguments in order to process them in the own program. TIC seems to be able to do, so our assembly language program should as well.

The answer is that the command line arguments are stored as a single string (with leading length byte) in a linked list of chunks of 6 bytes each. The pointer to this list is at address >0128 of the memory page at 0000-1FFF that was set when the program was started (so take care when you change the mapper). Here is an illustration:

Args.png

The command line arguments do not contain the program name, and they are not parsed, that is, you have to analyze the string in your application program. The memory location at >0128 contains a 0000 when there are no arguments. The end of the list is indicated by a next pointer that is set to 0000. Be aware that the last chunk may have arbitrary content after the end of the string. The pointers are 2 bytes each and start at word boundaries.

The following code is an example how to retrieve the list contents:

BUF    BSS  80           Reserve 80 bytes of space

START  MOV  @>0128,R0    Get pointer to list
       JEQ  NOARGS       If it is 0, skip all 

ST1    LI   R3,BUF       Pointer to buffer
       MOV  *R0+,R1      Store next pointer in R1
       LI   R5,6         Number of bytes in chunk
       MOVB *R0+,R2      Get length byte
       DEC  R5           Count down one for that byte
       SRL  R2,8         Move length byte to the low byte
       MOV  R2,*R3+      and write it at the head of the buffer

GL1    MOVB *R0+,*R3+    Copy the current byte to the buffer
       DEC  R2           Count down remaining string bytes
       JEQ  GOTALL       Done?
GL2    DEC  R5           No, count down chunk counter
       JNE  GL1          Chunk done? 
GL3    MOV  R1,R0        Yes, put the next address in R0
       JEQ  DONE         Is it null? 
       MOV  *R0+,R1      No, so there is another chunk
       LI   R5,6         Reset chunk counter
       JMP  GL1          End of loop

DONE ...
NOARGS ...