home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / z3shell / shutils2.lbr / RESOLVE.ZZ0 / RESOLVE.Z80
Encoding:
Text File  |  1993-06-08  |  15.0 KB  |  722 lines

  1. ; RESOLVE.MAC       RESOLVE ZCPR3 COMMAND LINE
  2. ;
  3. ;
  4. ; This utility will resolve a multiple-command line passed to it and place
  5. ; that command line in the Multiple-Command Line Buffer in memory.
  6. ; It will resolve references to shell variables, registers, and System
  7. ; File names.  Each of these is signalled by a flag as follows.
  8. ;
  9. ;    Flag                Meaning
  10. ;    ----                -------
  11. ;     %<text>        Shell variable name.
  12. ;     $R<n>        Register number.  (n = 1-9)
  13. ;     $D        Current disk letter.
  14. ;     $U        Current user number.
  15. ;     $F<n>        System File name.  (n = 1-4)
  16. ;     $N<n>        System File name, chars 1-8 only.  (n = 1-4)
  17. ;     $T<n>        System File name, extension only.  (n = 1-4)
  18. ;     $|        Substitute multiple-command separator.
  19. ;
  20. ; The QUIET flag is adhered to; the program will not print its sign-on
  21. ; message or error messages if the QUIET flag is set.
  22. ;
  23. ; If there is no room for the command-line generated, the ERROR flag will
  24. ; be set, and an error message may be printed, depending upon the state
  25. ; of the QUIET flag.  Uninterpretable '$' parameters will also cause the
  26. ; error flag to be set.
  27. ;
  28. ; Author: Dreas Nielsen
  29. ;
  30. ; Shell variable file manipulation routines are adapted from Richard Conn's
  31. ; 'SH.MAC'
  32. ;
  33. ; History --
  34. ;    Version    Date        Comment
  35. ;    -------    ----        -------
  36. ;    1.0    3/2/86        Up and running -- RDN
  37. ;    1.1    1/13/87        Fixed error in which a shell variable reference
  38. ;                in the first character of another shell
  39. ;                variable wasn't being expanded.  Also changed
  40. ;                so that a single '$', when followed by an
  41. ;                unrecognized flag, is not dropped.
  42. ;
  43. ;
  44. VERS    EQU    11
  45. ;
  46. ;
  47. PARMFL    EQU    '/'    ; flag indicating parameter follows
  48. SUBCH    EQU    '%'    ; shell-variable reference flag
  49. SYSFLG    EQU    '$'    ; System File reference flag
  50. SUBSEP    EQU    '|'
  51. CMDSEP    EQU    ';'
  52. LECNT    EQU    20        ;number of pointers on String Ptr Stack
  53. SYSNAM    EQU    0052H        ;offset of system file names from Z3ENV
  54. CTRLZ    EQU    1AH        ;^Z for EOF
  55. FCB    EQU    5CH
  56. TBUFF    EQU    80H
  57. BDOS    EQU    5
  58. CR    EQU    0DH
  59. LF    EQU    0AH
  60. ;
  61. CMDLIN    EQU    80H    ; CP/M's command line buffer
  62. ;
  63. ;
  64. ; SYSLIB and Z3LIB routines
  65. ;
  66.     EXT    Z3INIT,PUTER2,GETREG,PUTCL,QPRINT,ROOT
  67.     EXT    SKSP,PUTUD,LOGUD,INITFCB,MAFDC,FILLB,GETFN1
  68.     EXT    PRINT,F$OPEN,GETUD,F$CLOSE,CAPS,PRINT,CODEND
  69. ;
  70. ; Z3VARS routines
  71. ;
  72.     EXT    VARLOAD, VARDEF
  73. ;
  74. ;
  75. ; Program beginning
  76. ;
  77.     DB    'Z3ENV'
  78.     DB    1
  79. Z3ENV:    DW    00
  80.     DB    VERS        ;embed version number
  81. ;
  82. ; Initialize environment for Z3 routines
  83. START:    LD    HL,(Z3ENV)
  84.     CALL    Z3INIT
  85. ;
  86. ; Print signon message
  87.     CALL    QPRINT
  88. ;    DB    'RESOLVE  v. ',(VERS/10)+'0','.',(VERS MOD 10)+'0',CR,LF,0
  89.     DB    'RESOLVE  v. ',[VERS/10]+'0','.',[VERS MOD 10]+'0',CR,LF,0
  90. ;
  91. ; Reset error flag
  92.     XOR    A
  93.     CALL    PUTER2
  94. ;
  95. ; Save stack and set new one
  96.     LD    H,A
  97.     LD    L,A
  98.     ADD    HL,SP
  99.     LD    (SAVESP),HL
  100.     LD    HL,STACK
  101.     LD    SP,HL
  102. ;
  103. ; Set Pointers
  104.     CALL    CODEND        ;find scratch area
  105.     LD    (INTLINE),HL    ;set ptr to internal line buffer
  106.     LD    DE,200H        ;reserve 200H bytes
  107.     ADD    HL,DE
  108.     LD    (VARLIST),HL    ;set ptr to variable list
  109. ;
  110. ; Point to CP/M's command line
  111.     LD    HL,CMDLIN
  112. ;
  113. ; Quit if no command line passed
  114.     LD    A,(HL)
  115.     OR    A
  116.     JP    Z,HELP
  117. ;
  118. ; Otherwise, store a null at end of command line
  119.     INC    HL
  120.     LD    E,A
  121.     XOR    A
  122.     LD    D,A
  123.     ADD    HL,DE
  124.     LD    (HL),A
  125. ;
  126. ; Now parse command line.
  127. ; First look for option character.  Only option is help, which is exclusive.
  128.     LD    HL,CMDLIN+1
  129.     CALL    SKSP
  130.     LD    A,(HL)
  131.     CP    PARMFL
  132.     JP    Z,HELP
  133.     CP    '?'
  134.     JP    Z,HELP
  135. ;
  136. ; Expand Command Line pointed to by HL, performing variable
  137. ;    substitutions
  138. ;
  139. ;    On exit, Z=command line overflow and Line Pted to by HL
  140. ;
  141. EXPAND:
  142.     EX    DE,HL        ;DE pts to line
  143. ;
  144. ; Init String Pointer Stack
  145. ;
  146.     LD    A,LECNT        ;set local element count
  147.     LD    (LOCELT),A
  148.     LD    HL,LOCSTK    ;set local stack
  149.     LD    (LOCADR),HL
  150.     LD    HL,0        ;set done code on stack
  151.     CALL    LOCPUSH        ;push HL
  152. ;
  153. ; Set Ptrs
  154. ;
  155.     LD    HL,(INTLINE)    ;pt to internal line
  156.     EX    DE,HL        ;DE pts to internal line, HL pt next char
  157.     LD    B,0        ;256 chars max
  158. ;
  159. ; Analyze Next Char
  160. ;
  161. EXP1:
  162.     LD    A,(HL)        ;get next char
  163.     CP    SYSFLG        ;system file or directory substitution?
  164.     JR    NZ,TEST2
  165.     CALL    SYSFIL
  166.     DEC    C
  167.     JR    Z,EXP1        ;no error on return
  168.     JR    EXP2        ;error on return - store offending char in CL
  169. ;
  170. TEST2:
  171.     CP    SUBCH        ;substitution char?
  172.     JR    NZ,EXP2
  173. ;
  174. ; Process Shell Variable
  175. ;
  176.     CALL    EXPVAR        ;resolve variable
  177.     DEC    C        ;error?
  178.     JR    Z,EXP1        ;resume if none
  179. ;
  180. ;
  181. ; Store Next Char
  182. ;
  183. EXP2:
  184.     LD    (DE),A        ;store char
  185.     INC    HL        ;point to next
  186.     INC    DE
  187.     DEC    B        ;count down
  188.     JR    Z,EXPERR    ;error if at 0
  189. ;
  190.     OR    A        ;done?  (was last char stored a null?)
  191.     JR    NZ,EXP1
  192.     INC    B        ;increment count (not counting last 0)
  193.     DEC    DE        ;pt to null in case another string to analyze
  194. ;
  195. ; Pop String Ptr Stack and Check for Analysis Complete
  196. ;
  197.     CALL    LOCPOP        ;get ptr to previous string
  198.     LD    A,H        ;done?
  199.     OR    L
  200.     JR    NZ,EXP1        ;resume
  201.     DEC    A        ;set NZ
  202. ;
  203. ; Expansion Complete
  204. ;    On entry, Z Flag is Set Accordingly (Z=Error)
  205. ;
  206. EXPERR:    CALL    Z,SETERR
  207.     LD    HL,(INTLINE)    ;pt to internal line
  208.     CALL    PUTCL
  209.     JR    NZ,EXIT
  210. ;
  211. ; Print overflow message and set error flag
  212.     CALL    QPRINT
  213.     DB    CR,LF,'Command Line Overflow',CR,LF,0
  214.     CALL    SETERR
  215. ;
  216. ; Return to ZCPR3
  217. ;
  218. EXIT:
  219.     LD    HL,(SAVESP)
  220.     LD    SP,HL
  221.     RET
  222. ;
  223. ; Expand Variable
  224. ;    Return with HL pting to next char, A=char, C=1 if OK, C=2 if error
  225. ;
  226. EXPVAR:
  227.     LD    (VARPTR),HL    ;save ptr to variable
  228.     INC    HL        ;get next char
  229.     LD    C,2        ;prep for error return
  230.     LD    A,(HL)        ;get it
  231.     OR    A        ;EOL?
  232.     RET    Z
  233.     CP    SUBCH        ;double sub char?
  234.     RET    Z        ;place one sub char in line if so
  235. ;
  236. ; Place Variable Into SHVAR
  237. ;
  238.     PUSH    BC        ;save counter
  239.     PUSH    DE        ;save ptr to next char
  240.     PUSH    HL        ;save ptr to shell variable
  241.     LD    HL,SHVAR    ;pt to shell variable buffer
  242.     LD    B,8        ;8 chars max
  243.     LD    A,' '        ;space fill
  244.     CALL    FILLB
  245.     EX    DE,HL        ;DE pts to shell variable buffer
  246.     POP    HL        ;pt to shell variable
  247.     LD    B,8        ;8 chars max
  248. ;
  249. ; Place Shell Variable into Buffer
  250. ;
  251. EXPV1:
  252.     LD    A,(HL)        ;get char
  253.     CALL    DELCK        ;check for delimiter
  254.     JR    Z,EXPV3        ;done if delimiter
  255.     LD    (DE),A        ;save char
  256.     INC    HL        ;pt to next
  257.     INC    DE
  258.     DJNZ    EXPV1
  259. ;
  260. ; Flush Overflow of Shell Variable
  261. ;
  262. EXPV2:
  263.     LD    A,(HL)        ;get char
  264.     INC    HL        ;pt to next
  265.     CALL    DELCK        ;check for delimiter
  266.     JR    NZ,EXPV2
  267.     DEC    HL        ;pt to delimiter
  268. ;
  269. ; Shell Variable in buffer SHVAR
  270. ;    HL pts to delimiter after variable in user line
  271. ;
  272. EXPV3:
  273.     CALL    LOCPUSH        ;stack ptr to next char in current string
  274.     JR    Z,EXPV4        ;error in stack
  275.     LD    HL,(VARLIST)
  276.     CALL    VARLOAD        ;load shell variable list
  277.     JR    NZ,EXPV4    ;failure
  278.     LD    HL,SHVAR
  279.     CALL    VARDEF        ;resolve named variable reference
  280.     JR    Z,EXPV5        ;name found - resolve
  281. ;
  282. ; Shell Variable Not Resolved - Restore Ptr to It
  283. ;
  284. EXPV4:
  285.     CALL    LOCPOP        ;restore ptr
  286.     POP    DE
  287.     POP    BC
  288.     LD    C,2        ;error
  289.     LD    HL,(VARPTR)    ;pt to variable
  290.     LD    A,(HL)
  291.     RET
  292. ;
  293. ; Entry Point for OK Return
  294. ;
  295. EXPV5:
  296.     LD    A,(HL)        ;get char
  297.     POP    DE        ;pt to target
  298.     POP    BC        ;get counter
  299.     LD    C,1
  300.     RET    
  301.  
  302. ;
  303. ; Push HL onto String Ptr Stack
  304. ;    Return with Z if Stack Overflow
  305. ;
  306. LOCPUSH:
  307.     LD    A,(LOCELT)    ;get count
  308.     DEC    A        ;full?
  309.     RET    Z
  310.     LD    (LOCELT),A    ;set count
  311.     PUSH    DE        ;save DE
  312.     EX    DE,HL        ;DE pts to old string
  313.     LD    HL,(LOCADR)    ;get ptr to top of stack
  314.     LD    (HL),E        ;store low
  315.     INC    HL
  316.     LD    (HL),D        ;store high
  317.     INC    HL        ;pt to next
  318.     LD    (LOCADR),HL
  319.     EX    DE,HL        ;restore HL
  320.     POP    DE        ;restore DE
  321.     XOR    A        ;return NZ
  322.     DEC    A
  323.     RET    
  324. ;
  325. ; Pop HL from String Ptr Stack
  326. ;
  327. LOCPOP:
  328.     PUSH    DE
  329.     LD    A,(LOCELT)    ;increment element count
  330.     INC    A
  331.     LD    (LOCELT),A
  332.     LD    HL,(LOCADR)    ;get address
  333.     DEC    HL        ;pt to high
  334.     LD    D,(HL)        ;get high
  335.     DEC    HL        ;pt to low
  336.     LD    E,(HL)        ;get low
  337.     LD    (LOCADR),HL    ;set address
  338.     EX    DE,HL        ;restore ptr
  339.     POP    DE
  340.     RET    
  341. ;
  342. ; Check to see if char in A is a delimiter
  343. ;    Return with Z if so
  344. ;
  345. DELCK:
  346.     PUSH    HL        ;pt to table
  347.     PUSH    BC        ;save BC
  348.     CALL    CAPS        ;capitalize char
  349.     LD    B,A        ;char in B
  350.     LD    HL,DTABLE    ;pt to delimiter table
  351. DELCK1:
  352.     LD    A,(HL)        ;get delimiter
  353.     OR    A        ;done?
  354.     JR    Z,NOTDEL
  355.     CP    B        ;compare
  356.     JR    Z,YESDEL
  357.     INC    HL        ;pt to next
  358.     JR    DELCK1
  359. NOTDEL:
  360.     LD    A,B        ;get char
  361.     OR    A        ;set Z if null, else NZ
  362. YESDEL:
  363.     LD    A,B        ;restore char
  364.     POP    BC        ;restore regs
  365.     POP    HL
  366.     RET    
  367. ;
  368. ; Delimiter Table
  369. ;
  370. DTABLE:
  371.     DB    '<>;:,.=-_ ',0
  372. ;
  373. ;
  374. ;
  375. ; Print help message and exit.
  376. HELP:    CALL    PRINT
  377.     DB    'Resolve command line -- the following flags are '
  378.     DB    'interpreted:',CR,LF
  379.     DB    '    Flag          Meaning',CR,LF
  380.     DB    '    ----          -------',CR,LF
  381.     DB    '     %<text>     Shell variable name.',CR,LF
  382.     DB    '     $R<n>       Register number.  (n = 1-9)',CR,LF
  383.     DB    '     $D          Current drive letter.',CR,LF
  384.     DB    '     $U          Current user number.',CR,LF
  385.     DB    '     $F<n>       System File name.  (n = 1-4)',CR,LF
  386.     DB    '     $N<n>       System File, name only.',CR,LF
  387.     DB    '     $T<n>       System File, extension only.',CR,LF
  388.     DB    '     $|          Substitute command separator (;)',CR,LF
  389.     DB    0
  390.     JP    EXIT
  391. ;
  392. ;
  393. ;  EXPANSION ROUTINES
  394. ; The following routines each expand a particular kind of reference.
  395. ; Inputs : HL contains a pointer to the command line being interpreted;
  396. ;       DE points to the string being built.
  397. ; Outputs: C  contains an error flag: 2=error, 1=OK
  398. ;       HL points to the next char in the CL to interpret if no error (C=1)
  399. ;          points to last char interpreted if error (C=2)
  400. ;       DE points to the next location to fill in the CL being built
  401. ; If any of the flags are followed by incorrect parameters, the entire
  402. ; token, INCLUDING the leading dollar sign, is copied to the command line
  403. ; being built.
  404. ;
  405. SYSFIL:
  406.     INC    HL        ;point to next character
  407.     LD    C,1        ;prepare for no-error return
  408.     LD    A,(HL)        ;get character
  409.     OR    A        ;end of line?
  410.     JR    NZ,SYSF2
  411.     INC    C        ;indicate error
  412.     LD    A,SYSFLG
  413.     LD    (DE),A
  414.     INC    DE
  415.     XOR    A
  416.     RET
  417. ;
  418. SYSF2:    CP    'F'        ;full filename?
  419.     JR    Z,FFNAME
  420.     CP    'N'        ;just the name?
  421.     JR    Z,FNAME
  422.     CP    'T'        ;just the type?
  423.     JR    Z,FTYPE
  424.     CP    'D'        ;current drive?
  425.     JP    Z,CDRIV
  426.     CP    'U'        ;current useer?
  427.     JP    Z,CUSR
  428.     CP    'R'        ;register number?
  429.     JP    Z,REGR
  430.     CP    SUBSEP
  431.     JP    Z,SUBCHR
  432.     CALL    SETERR        ;otherwise, set Z3 error byte
  433.     PUSH    AF
  434.     LD    A,SYSFLG    ;transfer '$' to output
  435.     LD    (DE),A
  436.     INC    DE
  437.     POP    AF
  438.     INC    C        ;and return with error indicator
  439.     RET
  440. ;
  441. ; Character is flag for full filename.  Get number of filename, get filename,
  442. ; and insert in command line being built.
  443. ;
  444. FFNAME:
  445.     INC    HL        ;get number
  446.     LD    A,(HL)
  447.     OR    A
  448.     JR    Z,FFERR
  449. ;
  450. FFNAM2:    CALL    FNCHEK        ;check that number is in range 1-4
  451.     JR    Z,FFERR        ;quit if not
  452. ;
  453.     SUB    31H        ;convert to binary 0-3
  454.     PUSH    HL
  455.     CALL    FNADDR        ;get address of filename in HL
  456.     LD    A,(HL)        ;check for defined name
  457.     CP    ' '
  458.     JR    NZ,FFNAM4
  459. ;
  460.     POP    HL
  461.     INC    HL
  462.     LD    C,1        ;don't store char on return
  463.     RET
  464. ;
  465. FFNAM4:    PUSH    BC
  466.     CALL    TRANS8        ;transfer 1st 8 chars of filename
  467. ;
  468. FFNAM6:    LD    A,'.'        ;name transferred, now do period
  469.     LD    (DE),A
  470.     INC    DE
  471. ;
  472.     CALL    TRANS3        ;transfer filetype
  473.     POP    BC
  474.     POP    HL
  475.     INC    HL
  476.     LD    C,1        ;indicate all OK
  477.     RET
  478. ;
  479. FFERR:                ;erroneous file number
  480.     LD    A,SYSFLG
  481.     LD    (DE),A
  482.     INC    DE
  483.     DEC    HL        ;point to char after SYSFLG
  484.     LD    A,(HL)
  485.     LD    C,2        ;store char on return
  486.     RET
  487. ;
  488. ;
  489. ; Character is flag for filename (8 chars only).  Get filename, issue error
  490. ; message if number is outside range 1-4 or if filename is not defined.
  491. ;
  492. FNAME:
  493.     INC    HL        ;get number
  494.     LD    A,(HL)
  495.     OR    A
  496.     JR    Z,FFERR
  497.     CALL    FNCHEK        ;is number in range 1-4?
  498.     JR    Z,FFERR
  499. ;
  500.     SUB    31H        ;make binary 0-3
  501.     PUSH    HL
  502.     CALL    FNADDR        ;get address of filename in HL
  503.     LD    A,(HL)
  504.     CP    ' '
  505.     JR    NZ,FNAME2
  506.     LD    C,1
  507.     POP    HL
  508.     INC    HL
  509.     RET
  510. ;
  511. FNAME2:    PUSH    BC
  512.     CALL    TRANS8
  513.     POP    BC
  514.     POP    HL
  515.     INC    HL
  516.     LD    C,1        ;indicate all is OK
  517.     RET
  518. ;
  519. ;
  520. ; Character is flag for filetype (3 chars only).
  521. ;
  522. FTYPE:
  523.     INC    HL        ;get number
  524.     LD    A,(HL)
  525.     OR    A
  526.     JR    Z,FFERR
  527.     CALL    FNCHEK        ;check that number is in range 1-4
  528.     JR    Z,FFERR        ;quit if not
  529. ;
  530.     SUB    31H        ;convert to binary 0-3
  531.     PUSH    HL
  532.     CALL    FNADDR        ;get address of filename in HL
  533.     LD    A,(HL)        ;check for defined name
  534.     CP    ' '
  535.     JR    NZ,FTYP2
  536. ;
  537.     POP    HL
  538.     INC    HL
  539.     LD    C,1
  540.     RET
  541. ;
  542. FTYP2:    PUSH    BC
  543.     PUSH    DE
  544.     LD    DE,8
  545.     ADD    HL,DE
  546.     POP    DE
  547.     CALL    TRANS3
  548.     POP    BC
  549.     POP    HL
  550.     INC    HL
  551.     LD    C,1        ;indicate all is OK
  552.     RET
  553. ;
  554. ;
  555. ; ================  FILENAME TRANSFER UTILITIES  ================
  556. ;
  557. ;
  558. ; Check whether char in A is in ASCII range '1'-'4'.  Set the error flag and
  559. ; return with Z set if out of range.
  560. ;
  561. FNCHEK:    CP    '1'        ;less than one?
  562.     JR    C,FNERR
  563.     CP    '5'        ; greater than four?
  564.     JR    NC,FNERR
  565.     OR    A        ;force NZ
  566.     RET
  567. ;
  568. FNERR:    CALL    SETERR
  569.     CP    A        ;set Z without disturbing A
  570.     RET
  571. ;
  572.  
  573. ; Compute address of System File name.  Number of file is passed in A, address
  574. ; of name is returned in HL.  No other registers are affected.
  575. ;
  576. FNADDR:    PUSH    BC
  577.     PUSH    DE
  578.     LD    B,A        ;multiply by 11 to compute offset of name
  579.     ADD    A,A        ;x2
  580.     LD    C,A
  581.     ADD    A,A        ;x4
  582.     ADD    A,A        ;x8
  583.     ADD    A,C        ;x10
  584.     ADD    A,B        ;x11
  585.     LD    E,A
  586.     LD    D,0
  587.     LD    HL,(Z3ENV)
  588.     ADD    HL,DE
  589.     LD    DE,SYSNAM    ;offset of filenames from ENV
  590.     ADD    HL,DE        ;HL now points to fname
  591.     POP    DE
  592.     POP    BC
  593.     RET
  594. ;
  595.  
  596. ; Transfer 8 characters of filename from (HL) to (DE).  If fewer than 8 chars,
  597. ; increment HL to point past eighth anyway.  BC also used, not saved.
  598. ;
  599. TRANS8:    LD    B,8        ;# of chars in name
  600. TR82:    LD    A,(HL)
  601.     CP    ' '
  602.     JR    Z,TR83
  603.     LD    (DE),A
  604.     INC    HL
  605.     INC    DE
  606.     DJNZ    TR82
  607. TR83:    LD    A,B        ;were 8 chars transferred?
  608.     OR    A
  609.     RET    Z
  610. TR84:    INC    HL
  611.     DJNZ    TR84
  612.     RET
  613. ;
  614.  
  615. ; Transfer 3 characters of filename from (HL) to (DE).  BC is also used,
  616. ; not saved.  HL is NOT incremented past filename.
  617. ;
  618. TRANS3:    LD    B,3        ;transfer filetype
  619. TR32:    LD    A,(HL)
  620.     CP    ' '
  621.     RET    Z
  622.     LD    (DE),A
  623.     INC    HL
  624.     INC    DE
  625.     DJNZ    TR32
  626.     RET
  627. ; ================  END OF FILENAME TRANSFER UTILITIES  ================
  628. ;
  629. ;
  630. ; Character is substitute command-line separator.  If next character is the 
  631. ; same, preserve one of them.  Otherwise, replace it with the real command
  632. ; separator.
  633. ;
  634. SUBCHR:    LD    C,2        ;prepare for 'error' return
  635.     INC    HL        ;get next char
  636.     LD    A,(HL)
  637.     OR    A        ;premature end of CL?
  638.     RET    Z
  639. ;
  640. SUBCH2:    CP    SUBSEP        ;also sub. cmd. sep?
  641.     RET    Z        ;if so, return it
  642.     DEC    HL        ;else point before it
  643.     LD    A,CMDSEP    ;and return the real cmd. sep.
  644.     RET            ;('error' status will have it stored)
  645. ;
  646. ; Return current drive.
  647. ;
  648. CDRIV:    PUSH    HL
  649.     PUSH    DE
  650.     LD    C,19H
  651.     CALL    BDOS
  652.     ADD    A,'A'
  653.     POP    DE
  654.     POP    HL
  655.     LD    C,2        ;use char in A
  656.     RET
  657. ;
  658. ; Return current user #.
  659. ;
  660. CUSR:    PUSH    HL
  661.     PUSH    DE
  662.     LD    C,20H
  663.     LD    E,0FFH
  664.     CALL    BDOS        ;user # in A
  665.     POP    DE
  666.     CALL    MAFDC        ;up to 3 dec. digits stored at DE
  667.     POP    HL
  668.     INC    HL
  669.     LD    C,1
  670.     RET
  671. ;
  672. ; Get register #.
  673. ;
  674. REGR:    LD    C,2        ;prepare for error
  675.     INC    HL
  676.     LD    A,(HL)        ;get reg #
  677.     OR    A        ;premature end of CL?
  678.     RET    Z
  679. ;
  680. REGR2:    SUB    '0'
  681.     LD    B,A        ;register # in B
  682.     PUSH    HL
  683.     CALL    GETREG        ;register value now in A
  684.     CALL    MAFDC        ;up to 3 dec. digits stored at DE
  685.     POP    HL
  686.     INC    HL
  687.     LD    C,1
  688.     RET
  689. ;
  690. ;
  691. ; Set transient error code byte.
  692. ;
  693. SETERR:    PUSH    AF
  694.     XOR    A
  695.     DEC    A
  696.     CALL    PUTER2
  697.     POP    AF
  698.     RET
  699. ;
  700. ;
  701. ; Buffers
  702. ;
  703. SAVESP:    DS    2
  704.     DS    48
  705. STACK:    DS    2
  706. SHVAR:
  707.     DB    '        '
  708. LOCELT:
  709.     DS    1        ;string stack element count
  710. LOCADR:
  711.     DS    2        ;ptr to next entry on stack
  712. LOCSTK:
  713.     DS    LECNT*2        ;string ptr stack
  714. VARPTR:
  715.     DS    2        ;ptr to current variable in line
  716. INTLINE:
  717.     DS    2        ;ptr internal expansion line
  718. VARLIST:
  719.     DS    2        ;list of shell variables.
  720.  
  721.     END    START
  722.