home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / ZCPR33 / A-R / CMD11.LBR / CMD11.ZZ0 / CMD11.Z80
Text File  |  2000-06-30  |  6KB  |  277 lines

  1. ;  PROGRAM:  CMD
  2. ;  VERSION:  1.0
  3. ;  DATE:  19 July 84
  4. ;  AUTHOR:  Richard Conn
  5. ;  PREVIOUS VERSIONS:  None
  6. ;
  7. Z3ENV    EQU    0F400H
  8. VERS    EQU    11        ; Version number
  9.  
  10. ; CMD is copyright (c) 1984 by Richard Conn
  11. ; All Rights Reserved
  12. ; CMD may be used freely by the ZCPR3 Community
  13.  
  14. ;
  15. ;    CMD is used to define and run a command line.  It either accepts
  16. ; the command line (including semicolons) which follow the verb CMD onto
  17. ; the command line buffer or, if no input is provided, it prompts the
  18. ; user for input and then places this into the command line buffer.
  19. ;
  20. ; Syntax:
  21. ;    CMD cmd1;cmd2;...
  22. ; or    CMD
  23. ;
  24. ; The sequence of commands "cmd1;cmd2;..." becomes the command line.
  25. ;
  26.  
  27. ; Version 1.1 adds PUTCST call in order to allow
  28. ; shells to be nested when CMD is part of a SHSET
  29. ; sequence. SHSET.COM leaves the command status
  30. ; set as a shell, which would inhibit other shells
  31. ; such as VFILER from installing themselves as a
  32. ; shell.        3/19/87        Royce W. Shofner
  33.  
  34. ;
  35. ;  SYSLIB, Z3LIB, and VLIB References
  36. ;
  37.     EXT Z3INIT,PUTCST
  38.     EXT GETCL1,GETCL2,PUTER2,PUTZEX,DUTDIR
  39.     EXT EPRINT,PAFDC,COUT,BLINE
  40.     EXT RETUD
  41.     EXT CODEND
  42.  
  43. ;
  44. ;  Basic Definitions
  45. ;
  46. TRUE    EQU    0FFH        ; Define true and..
  47. FALSE    EQU    0        ; ..false.
  48.  
  49. ;
  50. ; System Addresses
  51. ;
  52. OS$BASE EQU    000H        ; System base..
  53. BDOS    EQU    OS$BASE+05H
  54. FCB    EQU    OS$BASE+5CH
  55. FCB2    EQU    OS$BASE+6CH
  56. TBUFF    EQU    OS$BASE+80H
  57. TPA    EQU    OS$BASE+100H
  58.  
  59. ;
  60. ;  ASCII Chars
  61. ;
  62. LF    EQU    0AH        ; ..linefeed..
  63. CR    EQU    0DH        ; ..carriage return..
  64.  
  65. ;
  66. ; Environment Definition
  67. ;
  68.      IF    Z3ENV NE 0
  69. ;
  70. ; External ZCPR3 Environment Descriptor
  71. ;
  72.     JP    START
  73.     DEFB    'Z3ENV'        ; This is a ZCPR3 Utility
  74.     DEFB    1        ; External Environment Descriptor
  75. Z3EADR:
  76.     DEFW    Z3ENV
  77. START:
  78.     LD    HL,(Z3EADR)    ; Pt to ZCPR3 environment
  79. ;
  80.      ELSE
  81. ;
  82. ; Internal ZCPR3 Environment Descriptor
  83. ;
  84.     MACLIB Z3BASE.LIB
  85.     MACLIB SYSENV.LIB
  86. Z3EADR:
  87.     JP    START
  88.     SYSENV
  89. START:
  90.     LD    HL,Z3EADR    ; Pt to ZCPR3 environment
  91.      ENDIF
  92.  
  93. ;
  94. ; Mainline
  95. ;
  96.     CALL    Z3INIT        ; Initialize the ZCPR3 Env
  97.  
  98. ;
  99. ; Check for Help or Prompt
  100. ;
  101.     LD    A,(FCB+1)    ; Check for help request
  102.     CP    ' '        ; Prompted input?
  103.     JP    Z,PROMPT
  104.     CP    '/'        ; Help?
  105.     JP    NZ,CINIT
  106. ;
  107. ; Print Help Message
  108. ;
  109. HELP:
  110.     CALL    EPRINT
  111.     DEFB    'CMD, Version '
  112.     DEFB    (VERS/10)+'0','.',(VERS MOD 10)+'0'
  113.     DEFB    CR,LF,' Syntax:  CMD cmd1;cmd2;... or CMD (prompted input)'
  114.     DEFB    CR,LF,' CMD defines the command line in the CL buffer'
  115.     DEFB    0
  116.     RET
  117. ;
  118. ; Initialize Command Line
  119. ;
  120. CINIT:
  121.     CALL    GETCL1        ; Check for command line buffer
  122.     JP    Z,NOCL
  123. ;
  124. ; HL now points to the command line buffer
  125. ;
  126.     CALL    CODEND        ; Pt to free area
  127.     INC    HL        ; Skip 2 bytes
  128.     INC    HL
  129.     EX    DE,HL        ; ... in DE
  130.     LD    HL,TBUFF+2    ; Pt to option input
  131.     CALL    COPYSTR        ; Copy string
  132.     LD    C,1        ; Set not empty
  133. ;
  134. ; Entry point to build rest of command line, where DE=next address
  135. ;   and C=empty line flag (C=0 means line was empty)
  136. ;
  137. CHECKCL:
  138.     LD    A,C        ; Get empty flag
  139.     CALL    PUTER2        ; Set error flag
  140.     CALL    GETCL2        ; Get address of command line
  141.     JP    Z,SETSH        ; Set shell command
  142.     CALL    COPYSTR        ; Copy string
  143. SETSH:
  144.     XOR    A        ; 0 in a = normal cmd status
  145.     CALL    PUTCST        ; tell zcpr3 next is a normal command
  146.  
  147.     CALL    GETCL1        ; Pt to command line buffer
  148.     EX    DE,HL        ; ... in DE
  149.     LD    HL,4        ; Pt to first char position
  150.     ADD    HL,DE
  151.     LD    (LSTART),HL    ; Save start address in case of abort
  152.     EX    DE,HL
  153.     LD    (HL),E        ; Store pointer
  154.     INC    HL
  155.     LD    (HL),D
  156.     INC    HL        ; Pt to buffer size
  157.     LD    B,(HL)        ; Get it in B
  158.     CALL    CODEND        ; Pt to string
  159.     INC    HL        ; Skip 2 bytes
  160.     INC    HL
  161. CLCOPY:
  162.     LD    A,(HL)        ; Get char
  163.     LD    (DE),A        ; Put char
  164.     INC    HL        ; Pt to next
  165.     INC    DE
  166.     OR    A        ; Done?
  167.     RET    Z
  168.     DEC    B        ; Count down
  169.     JP    NZ,CLCOPY
  170. ;
  171. ; Command Line Too Long
  172. ;
  173.     LD    HL,(LSTART)    ; Zero command line
  174.     LD    (HL),0
  175.     CALL    EPRINT
  176.     DEFB    ' Command Line too Long for Buffer',0
  177.     RET
  178.  
  179. ;
  180. ; Print no command line buffer message and exit
  181. ;
  182. NOCL:
  183.     CALL    EPRINT
  184.     DEFB    ' No Command Line Buffer',0
  185.     RET
  186.  
  187. ;
  188. ; Copy string from HL to DE
  189. ;   Store ending 0 and leave pointer in DE to it
  190. ;
  191. COPYSTR:
  192.     LD    A,(HL)        ; Get char
  193.     LD    (DE),A        ; Store it
  194.     OR    A        ; Done?
  195.     RET    Z
  196.     INC    HL        ; Pt to next
  197.     INC    DE
  198.     JP    COPYSTR
  199.  
  200. ;
  201. ; Prompt User for Input
  202. ;
  203. PROMPT:
  204.     CALL    EPRINT
  205.     DEFB    'CMD ',0
  206.     CALL    RETUD        ; Get DU
  207. ;
  208. ; Print DU
  209. ;
  210.     LD    A,B        ; Output disk
  211.     ADD    A,'A'
  212.     CALL    COUT
  213.     LD    A,C        ; Output user
  214.     CALL    PAFDC
  215.     LD    A,':'        ; Separator
  216.     CALL    COUT
  217. ;
  218. ; Print DIR
  219. ;
  220.     CALL    DUTDIR        ; Convert to name
  221.     JP    Z,PROMPT2    ; No name input
  222. ;
  223. ; DIR is defined
  224. ;
  225.     LD    B,8        ; 8 chars max
  226. PROMPT1:
  227.     LD    A,(HL)        ; Get char
  228.     CP    ' '        ; Done if space
  229.     JP    Z,PROMPTX
  230.     CALL    COUT        ; Echo it
  231.     INC    HL        ; Pt to next
  232.     DEC    B        ; Count down
  233.     JP    NZ,PROMPT1
  234.     JP    PROMPTX
  235. ;
  236. ; DIR is not defined
  237. ;
  238. PROMPT2:
  239.     CALL    EPRINT        ; Name not found
  240.     DEFB    'Noname',0
  241. ;
  242. ; Complete prompt and get user input
  243. ;
  244. PROMPTX:
  245.     CALL    EPRINT
  246.     DEFB    '> ',0
  247.     LD    A,1        ; Tell ZEX that it is prompted
  248.     CALL    PUTZEX
  249.     CALL    CODEND        ; Use buffer area
  250.     LD    (HL),254    ; Set large line size
  251.     LD    A,0        ; No caps
  252.     CALL    BLINE        ; Get input line
  253.     XOR    A        ; No more prompt
  254.     CALL    PUTZEX
  255.     CALL    CODEND        ; Skip to EOL
  256.     INC    HL
  257.     INC    HL
  258.     EX    DE,HL        ; Ptr in DE
  259.     LD    A,(DE)        ; Get first char
  260.     LD    C,A        ; Save flag
  261. ;
  262. ; Skip to end of input line
  263. ;
  264. FINDEOL:
  265.     LD    A,(DE)        ; Get char
  266.     OR    A        ; Done?
  267.     JP    Z,CHECKCL
  268.     INC    DE        ; Pt to next
  269.     JP    FINDEOL
  270. ;
  271. ; Buffers
  272. ;
  273. LSTART:
  274.     DEFS    2        ; Start of command line
  275.  
  276.     END
  277.