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 / ZCPR2 / CD.MQC / CD.MAC
Text File  |  2000-06-30  |  9KB  |  406 lines

  1. ;
  2. ;  Program:  CD
  3. ;  Version:  2.4
  4. ;  Author:  Richard Conn
  5. ;  Date:  18 Aug 83
  6. ;  Previous Versions:  2.3 (6 Jan 83), 2.2 (19 Dec 82), 2.1 (7 Dec 82)
  7. ;  Derivation:  CD.MAC was derived in concept from CD.C, Version 1.2
  8. ;
  9. vers    equ    24
  10.  
  11. ;
  12. ;    This program is Copyright (c) 1982, 1983 by Richard Conn
  13. ;    All Rights Reserved
  14. ;
  15. ;    ZCPR2 and its utilities, including this one, are released
  16. ; to the public domain.  Anyone who wishes to USE them may do so with
  17. ; no strings attached.  The author assumes no responsibility or
  18. ; liability for the use of ZCPR2 and its utilities.
  19. ;
  20. ;    The author, Richard Conn, has sole rights to this program.
  21. ; ZCPR2 and its utilities may not be sold without the express,
  22. ; written permission of the author.
  23. ;
  24.  
  25. ;
  26. ;    CD is designed to allow the user to quickly change to another
  27. ; working directory (CD=Change Directory).
  28. ;     Intended to be small in size, CD accepts a command of the
  29. ; following forms:
  30. ;
  31. ;        CD //            <-- Print Help Message
  32. ;        CD dir or CD dir:    <-- Log Into Directory
  33. ;
  34.  
  35. ;
  36. ;  CP/M Constants
  37. ;
  38. cpm    equ    0    ; Warm Boot Address
  39. udflag    equ    cpm+4    ; User/Disk Flag
  40. fcb    equ    5ch    ; Location of Default FCB
  41. tbuff    equ    80h    ; Temporary Input Line Buffer
  42. cr    equ    0dh
  43. lf    equ    0ah
  44.  
  45. ;
  46. ;  Externals
  47. ;
  48.     ext    zgpins    ; init ZCPR2 buffers
  49.     ext    zdnfind    ; used to determine directory user/disk
  50.     ext    zmcptr    ; MC buffer ptr
  51.     ext    logud    ; log in user/disk
  52.     ext    retud    ; return current user/disk
  53.     ext    initfcb    ; init FCB
  54.     ext    f$exist    ; file exist test
  55.     ext    print    ; print routine
  56.     ext    cout    ; char output
  57.     ext    crlf    ; new line
  58.     ext    inline    ; input line editor, external buffer
  59.     ext    cin    ; char input
  60.     ext    codend    ; end of code
  61.  
  62. ;
  63. ;  Branch to Start of Program
  64. ;
  65.     jmp    start
  66.  
  67. ;
  68. ;******************************************************************
  69. ;
  70. ;  SINSFORM -- ZCPR2 Utility Standard General Purpose Initialization Format
  71. ;
  72. ;    This data block precisely defines the data format for
  73. ; initial features of a ZCPR2 system which are required for proper
  74. ; initialization of the ZCPR2-Specific Routines in SYSLIB.
  75. ;
  76.  
  77. ;
  78. ;  EXTERNAL PATH DATA
  79. ;
  80. EPAVAIL:
  81.     DB    0FFH    ; IS EXTERNAL PATH AVAILABLE? (0=NO, 0FFH=YES)
  82. EPADR:
  83.     DW    40H    ; ADDRESS OF EXTERNAL PATH IF AVAILABLE
  84.  
  85. ;
  86. ;  INTERNAL PATH DATA
  87. ;
  88. INTPATH:
  89.     DB    0,0    ; DISK, USER FOR FIRST PATH ELEMENT
  90.             ; DISK = 1 FOR A, '$' FOR CURRENT
  91.             ; USER = NUMBER, '$' FOR CURRENT
  92.     DB    0,0
  93.     DB    0,0
  94.     DB    0,0
  95.     DB    0,0
  96.     DB    0,0
  97.     DB    0,0
  98.     DB    0,0    ; DISK, USER FOR 8TH PATH ELEMENT
  99.     DB    0    ; END OF PATH
  100.  
  101. ;
  102. ;  MULTIPLE COMMAND LINE BUFFER DATA
  103. ;
  104. MCAVAIL:
  105.     DB    0FFH    ; IS MULTIPLE COMMAND LINE BUFFER AVAILABLE?
  106. MCADR:
  107.     DW    0FF00H    ; ADDRESS OF MULTIPLE COMMAND LINE BUFFER IF AVAILABLE
  108.  
  109. ;
  110. ;  DISK/USER LIMITS
  111. ;
  112. MDISK:
  113.     DB    4    ; MAXIMUM NUMBER OF DISKS
  114. MUSER:
  115.     DB    31    ; MAXIMUM USER NUMBER
  116.  
  117. ;
  118. ;  FLAGS TO PERMIT LOG IN FOR DIFFERENT USER AREA OR DISK
  119. ;
  120. DOK:
  121.     DB    0FFH    ; ALLOW DISK CHANGE? (0=NO, 0FFH=YES)
  122. UOK:
  123.     DB    0FFH    ; ALLOW USER CHANGE? (0=NO, 0FFH=YES)
  124.  
  125. ;
  126. ;  PRIVILEGED USER DATA
  127. ;
  128. PUSER:
  129.     DB    10    ; BEGINNING OF PRIVILEGED USER AREAS
  130. PPASS:
  131.     DB    'chdir',0    ; PASSWORD FOR MOVING INTO PRIV USER AREAS
  132.     DS    41-($-PPASS)    ; 40 CHARS MAX IN BUFFER + 1 for ending NULL
  133.  
  134. ;
  135. ;  CURRENT USER/DISK INDICATOR
  136. ;
  137. CINDIC:
  138.     DB    '$'    ; USUAL VALUE (FOR PATH EXPRESSIONS)
  139.  
  140. ;
  141. ;  DMA ADDRESS FOR DISK TRANSFERS
  142. ;
  143. DMADR:
  144.     DW    80H    ; TBUFF AREA
  145.  
  146. ;
  147. ;  NAMED DIRECTORY INFORMATION
  148. ;
  149. NDRADR:
  150.     DW    00000H    ; ADDRESS OF MEMORY-RESIDENT NAMED DIRECTORY
  151. NDNAMES:
  152.     DB    64    ; MAX NUMBER OF DIRECTORY NAMES
  153. DNFILE:
  154.     DB    'NAMES   '    ; NAME OF DISK NAME FILE
  155.     DB    'DIR'        ; TYPE OF DISK NAME FILE
  156.  
  157. ;
  158. ;  REQUIREMENTS FLAGS
  159. ;
  160. EPREQD:
  161.     DB    0FFH    ; EXTERNAL PATH?
  162. MCREQD:
  163.     DB    0FFH    ; MULTIPLE COMMAND LINE?
  164. MXREQD:
  165.     DB    0FFH    ; MAX USER/DISK?
  166. UDREQD:
  167.     DB    0FFH    ; ALLOW USER/DISK CHANGE?
  168. PUREQD:
  169.     DB    0FFH    ; PRIVILEGED USER?
  170. CDREQD:
  171.     DB    0FFH    ; CURRENT INDIC AND DMA?
  172. NDREQD:
  173.     DB    0FFH    ; NAMED DIRECTORIES?
  174. Z2CLASS:
  175.     DB    0    ; CLASS 0
  176.     DB    'ZCPR2'
  177.     DS    10    ; RESERVED
  178.  
  179. ;
  180. ;  END OF SINSFORM -- STANDARD DEFAULT PARAMETER DATA
  181. ;
  182. ;******************************************************************
  183. ;
  184. stfile:
  185.     db    0
  186.     db    'ST      '    ; file name
  187.     db    'COM'        ; file type
  188.     ds    4
  189.     ds    16
  190.     ds    4        ; 36 bytes total
  191. ;
  192. ;  Start of Program
  193. ;
  194. start:
  195.     call    zgpins    ; install ZCPR2 variables
  196.  
  197.     call    print    ; print banner
  198.     db    'CD, Version '
  199.     db    vers/10+'0','.',(vers mod 10)+'0',0
  200.  
  201.     lxi    h,tbuff    ; pt to input line
  202.     mov    a,m    ; get input line size
  203.     inx    h    ; pt to first char
  204.     push    h    ; save ptr to first char
  205.     add    l    ; pt to after last char
  206.     mov    l,a
  207.     mov    a,h
  208.     aci    0
  209.     mov    h,a    ; hl pts to after last char
  210.     mvi    m,0    ; store ending zero
  211.     pop    h    ; pt to first char
  212.     lxi    d,cbuff    ; temp storage for line
  213.  
  214. ;
  215. ;  Copy input line into temporary buffer
  216. ;
  217. start0:
  218.     mov    a,m    ; get byte
  219.     stax    d    ; put byte
  220.     inx    h    ; pt to next
  221.     inx    d
  222.     ora    a    ; end of line?
  223.     jnz    start0
  224.  
  225. ;
  226. ;  Skip to first non-blank and process if Help requested
  227. ;
  228.     lxi    h,cbuff    ; pt to first char
  229. sblank:
  230.     mov    a,m    ; pt to char
  231.     inx    h    ; pt to next
  232.     cpi    ' '    ; <sp>?
  233.     jz    sblank
  234.     dcx    h    ; pt to first non-blank
  235.     ora    a    ; print directory info?
  236.     jz    help
  237.     cpi    '/'    ; help option?
  238.     jnz    cd    ; change dir processing if not help
  239.  
  240. ;
  241. ;  Print Help Message
  242. ;
  243. help:
  244.     call    print
  245.     db    cr,lf,'    CD is a ZCPR2 named directory move utility'
  246.     db    cr,lf,'(CD=Change Directory).  Command Forms are:'
  247.     db    cr,lf,'        CD or CD //        <-- Print Help Message'
  248.     db    cr,lf,'        CD dir or CD dir:    <-- Log Into Dir'
  249.     db    cr,lf,0
  250.     ret
  251.  
  252. ;
  253. ;  Scan Line for Colon and append Colon if none present
  254. ;
  255. cd:
  256.     push    h    ; save ptr to first char for later
  257. scolon:
  258.     mov    a,m    ; get char
  259.     ora    a    ; eol?
  260.     jz    pcolon    ; append colon
  261.     cpi    ' '    ; <sp>?
  262.     jz    pcolon    ; append colon
  263.     cpi    ':'    ; colon?
  264.     jz    cd2    ; continue processing
  265.     inx    h    ; pt to next char
  266.     jmp    scolon
  267. pcolon:
  268.     mvi    m,':'    ; place colon at end of token
  269.     inx    h    ; pt to next char
  270.     mvi    m,0    ; place ending zero
  271.  
  272. ;
  273. ;  Extract User/Disk Numbers
  274. ;
  275. cd2:
  276.     call    retud    ; get current user/disk
  277.     mov    a,b    ; store disk
  278.     sta    cdisk
  279.     mov    a,c    ; store user
  280.     sta    cuser
  281.     pop    h    ; get ptr to first char
  282.     xra    a    ; do not allow du: form
  283.     call    zdnfind    ; extract user/disk info
  284.     jnz    cd3
  285.     call    print
  286.     db    cr,lf,'Dir Name Not Found',0
  287.     ret
  288.  
  289. ;
  290. ;  Set Current User/Disk
  291. ;
  292. cd3:
  293.     mov    a,b    ; get disk number
  294.     cpi    0ffh    ; current?
  295.     jnz    setd    ; set disk if not
  296.     lda    cdisk    ; get current disk
  297.     inr    a    ; increment because of ZDNFIND offset
  298. setd:
  299.     mov    b,a    ; disk in B
  300.     lda    mdisk    ; max disk number
  301.     cmp    b    ; must be less
  302.     jnc    setd1    ; error if selected > max
  303. uderr:
  304.     call    print
  305.     db    cr,lf,'Dir Range Error -- Abort',0
  306.     ret
  307. setd1:
  308.     mov    a,c    ; get user number
  309.     cpi    0ffh    ; current?
  310.     jnz    setu    ; set user if not
  311.     lda    cuser    ; get current user
  312. setu:
  313.     mov    c,a    ; user in C
  314.     lda    muser    ; max user number
  315.     cmp    c    ; must be less
  316.     jc    uderr    ; error if selected > max
  317.     call    pass    ; ask for password if not priv cding into priv
  318.     dcr    b    ; adjust disk to 0 to n-1
  319.     lda    mcavail    ; multiple commands available?
  320.     ora    a    ; 0=no
  321.     jz    login
  322.     call    logud    ; log into new directory
  323.     lxi    d,stfile    ; check for presence of startup file
  324.     call    initfcb    ; init FCB
  325.     call    f$exist    ; does it exist?
  326.     jz    login
  327.     call    zmcptr    ; get ptr to next char in MC line
  328.     dcx    h    ; back up two chars
  329.     lda    stfile+2
  330.     mov    m,a
  331.     dcx    h
  332.     lda    stfile+1    ; store new file name
  333.     mov    m,a
  334.     lhld    mcadr    ; get address of line
  335.     mov    a,m    ; get low-order byte
  336.     dcr    a    ; back up 2 chars
  337.     dcr    a
  338.     mov    m,a    ; set new count
  339. login:
  340.     mov    a,c    ; user in A
  341.     ora    a    ; clear carry
  342.     rlc        ; move user into high nybble
  343.     rlc
  344.     rlc
  345.     rlc
  346.     ora    b    ; mask in new disk
  347.     sta    udflag    ; set loc 4
  348.     jmp    cpm
  349.  
  350. ;
  351. ;  Ask for password if non-priveleged user (cuser) is trying to CD into
  352. ;  a priveleged user area (=>puser)
  353. ;
  354. pass:
  355.     push    b    ; save desired user/disk
  356.     lda    puser    ; get priv user number
  357.     mov    b,a    ; ... in B
  358.     lda    cuser    ; get current user
  359.     cmp    b    ; is current user priveleged?
  360.     pop    b
  361.     rnc        ; done if so
  362.     lda    puser    ; see if desired to move into priveleged user area
  363.     dcr    a    ; just under priveleged user area
  364.     cmp    c    ; is C >= puser?
  365.     rnc        ; done if PUSER-1 >= desired user
  366. ;
  367. ;  Non-priv wants to CD into Priv ... ask password
  368. ;
  369.     push    b    ; save desired user/disk
  370.     call    print
  371.     db    cr,lf,'Access Password? ',0
  372.     call    codend    ; pt to scratch area
  373.     xra    a    ; no echo
  374.     call    inline    ; input line editor
  375.     lxi    d,ppass    ; pt to password stored
  376. scomp:
  377.     ldax    d    ; get byte
  378.     cmp    m    ; compare
  379.     jnz    nomatch
  380.     inx    h    ; pt to next
  381.     inx    d
  382.     ora    a    ; end of strings?
  383.     jnz    scomp
  384.     call    print
  385.     db    cr,lf,'** Access Granted **',0
  386.     pop    b    ; match -- return normally
  387.     ret
  388. nomatch:
  389.     pop    b    ; clear BC
  390.     pop    h    ; clear stack
  391.     call    print
  392.     db    cr,lf,'** Invalid Password -- Access Denied **',0
  393.     ret
  394.  
  395. ;
  396. ;  Buffers
  397. ;
  398. cuser:
  399.     ds    1    ; current user
  400. cdisk:
  401.     ds    1    ; current disk
  402. cbuff:
  403.     ds    250    ; command line buffer
  404.  
  405.     end
  406.