; PROGRAM: CMD ; VERSION: 1.0 ; DATE: 19 July 84 ; AUTHOR: Richard Conn ; PREVIOUS VERSIONS: None ; Z3ENV EQU 0F400H VERS EQU 11 ; Version number ; CMD is copyright (c) 1984 by Richard Conn ; All Rights Reserved ; CMD may be used freely by the ZCPR3 Community ; ; CMD is used to define and run a command line. It either accepts ; the command line (including semicolons) which follow the verb CMD onto ; the command line buffer or, if no input is provided, it prompts the ; user for input and then places this into the command line buffer. ; ; Syntax: ; CMD cmd1;cmd2;... ; or CMD ; ; The sequence of commands "cmd1;cmd2;..." becomes the command line. ; ; Version 1.1 adds PUTCST call in order to allow ; shells to be nested when CMD is part of a SHSET ; sequence. SHSET.COM leaves the command status ; set as a shell, which would inhibit other shells ; such as VFILER from installing themselves as a ; shell. 3/19/87 Royce W. Shofner ; ; SYSLIB, Z3LIB, and VLIB References ; EXT Z3INIT,PUTCST EXT GETCL1,GETCL2,PUTER2,PUTZEX,DUTDIR EXT EPRINT,PAFDC,COUT,BLINE EXT RETUD EXT CODEND ; ; Basic Definitions ; TRUE EQU 0FFH ; Define true and.. FALSE EQU 0 ; ..false. ; ; System Addresses ; OS$BASE EQU 000H ; System base.. BDOS EQU OS$BASE+05H FCB EQU OS$BASE+5CH FCB2 EQU OS$BASE+6CH TBUFF EQU OS$BASE+80H TPA EQU OS$BASE+100H ; ; ASCII Chars ; LF EQU 0AH ; ..linefeed.. CR EQU 0DH ; ..carriage return.. ; ; Environment Definition ; IF Z3ENV NE 0 ; ; External ZCPR3 Environment Descriptor ; JP START DEFB 'Z3ENV' ; This is a ZCPR3 Utility DEFB 1 ; External Environment Descriptor Z3EADR: DEFW Z3ENV START: LD HL,(Z3EADR) ; Pt to ZCPR3 environment ; ELSE ; ; Internal ZCPR3 Environment Descriptor ; MACLIB Z3BASE.LIB MACLIB SYSENV.LIB Z3EADR: JP START SYSENV START: LD HL,Z3EADR ; Pt to ZCPR3 environment ENDIF ; ; Mainline ; CALL Z3INIT ; Initialize the ZCPR3 Env ; ; Check for Help or Prompt ; LD A,(FCB+1) ; Check for help request CP ' ' ; Prompted input? JP Z,PROMPT CP '/' ; Help? JP NZ,CINIT ; ; Print Help Message ; HELP: CALL EPRINT DEFB 'CMD, Version ' DEFB (VERS/10)+'0','.',(VERS MOD 10)+'0' DEFB CR,LF,' Syntax: CMD cmd1;cmd2;... or CMD (prompted input)' DEFB CR,LF,' CMD defines the command line in the CL buffer' DEFB 0 RET ; ; Initialize Command Line ; CINIT: CALL GETCL1 ; Check for command line buffer JP Z,NOCL ; ; HL now points to the command line buffer ; CALL CODEND ; Pt to free area INC HL ; Skip 2 bytes INC HL EX DE,HL ; ... in DE LD HL,TBUFF+2 ; Pt to option input CALL COPYSTR ; Copy string LD C,1 ; Set not empty ; ; Entry point to build rest of command line, where DE=next address ; and C=empty line flag (C=0 means line was empty) ; CHECKCL: LD A,C ; Get empty flag CALL PUTER2 ; Set error flag CALL GETCL2 ; Get address of command line JP Z,SETSH ; Set shell command CALL COPYSTR ; Copy string SETSH: XOR A ; 0 in a = normal cmd status CALL PUTCST ; tell zcpr3 next is a normal command CALL GETCL1 ; Pt to command line buffer EX DE,HL ; ... in DE LD HL,4 ; Pt to first char position ADD HL,DE LD (LSTART),HL ; Save start address in case of abort EX DE,HL LD (HL),E ; Store pointer INC HL LD (HL),D INC HL ; Pt to buffer size LD B,(HL) ; Get it in B CALL CODEND ; Pt to string INC HL ; Skip 2 bytes INC HL CLCOPY: LD A,(HL) ; Get char LD (DE),A ; Put char INC HL ; Pt to next INC DE OR A ; Done? RET Z DEC B ; Count down JP NZ,CLCOPY ; ; Command Line Too Long ; LD HL,(LSTART) ; Zero command line LD (HL),0 CALL EPRINT DEFB ' Command Line too Long for Buffer',0 RET ; ; Print no command line buffer message and exit ; NOCL: CALL EPRINT DEFB ' No Command Line Buffer',0 RET ; ; Copy string from HL to DE ; Store ending 0 and leave pointer in DE to it ; COPYSTR: LD A,(HL) ; Get char LD (DE),A ; Store it OR A ; Done? RET Z INC HL ; Pt to next INC DE JP COPYSTR ; ; Prompt User for Input ; PROMPT: CALL EPRINT DEFB 'CMD ',0 CALL RETUD ; Get DU ; ; Print DU ; LD A,B ; Output disk ADD A,'A' CALL COUT LD A,C ; Output user CALL PAFDC LD A,':' ; Separator CALL COUT ; ; Print DIR ; CALL DUTDIR ; Convert to name JP Z,PROMPT2 ; No name input ; ; DIR is defined ; LD B,8 ; 8 chars max PROMPT1: LD A,(HL) ; Get char CP ' ' ; Done if space JP Z,PROMPTX CALL COUT ; Echo it INC HL ; Pt to next DEC B ; Count down JP NZ,PROMPT1 JP PROMPTX ; ; DIR is not defined ; PROMPT2: CALL EPRINT ; Name not found DEFB 'Noname',0 ; ; Complete prompt and get user input ; PROMPTX: CALL EPRINT DEFB '> ',0 LD A,1 ; Tell ZEX that it is prompted CALL PUTZEX CALL CODEND ; Use buffer area LD (HL),254 ; Set large line size LD A,0 ; No caps CALL BLINE ; Get input line XOR A ; No more prompt CALL PUTZEX CALL CODEND ; Skip to EOL INC HL INC HL EX DE,HL ; Ptr in DE LD A,(DE) ; Get first char LD C,A ; Save flag ; ; Skip to end of input line ; FINDEOL: LD A,(DE) ; Get char OR A ; Done? JP Z,CHECKCL INC DE ; Pt to next JP FINDEOL ; ; Buffers ; LSTART: DEFS 2 ; Start of command line END