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 / BDOS / SUPRDOS2.LBR / PUBLIC.SZC / PUBLIC.SRC
Text File  |  2000-06-30  |  8KB  |  559 lines

  1. ; PUBLIC - SET AND CLEAR PUBLIC FILE ATTRIBUTE 3/6/85
  2.  
  3.  
  4. FALSE        EQU    0
  5. TRUE        EQU    NOT FALSE
  6.  
  7. LISTPUBBIT    EQU    0
  8. MAKPUBBIT    EQU    1
  9. FENCE        EQU    '|'
  10.  
  11. NULL        EQU    0
  12. BELL        EQU    7
  13. CR        EQU    0DH
  14. LF        EQU    0AH
  15. ESC        EQU    1BH
  16. SPACE        EQU    ' '
  17. DEL        EQU    7FH
  18.  
  19. drivefn        equ    14
  20. openfn        equ    15
  21. closefn        equ    16
  22. srchfstfn    equ    17
  23. srchnxtfn    equ    18
  24. deletefn    equ    19
  25. readfn        equ    20
  26. writefn        equ    21
  27. makefn        equ    22
  28. renamefn    equ    23
  29. logvecfn    equ    24
  30. curdskfn    equ    25
  31. dmafn        equ    26
  32. setattrfn    equ    30
  33. getaddrfn    equ    31
  34. userfn        equ    32
  35. readrfn        equ    33
  36. writerfn    equ    34
  37. sizefn        equ    35
  38.  
  39. reccnt        equ    15
  40. currec        equ    32
  41. r0        equ    33
  42. tbuff        equ    80h
  43. fcb        equ    5ch
  44. fcb2        equ    fcb+16
  45.  
  46. boot        equ    0000h
  47. bdos        equ    0005h
  48. bdoslen        equ    0e00h
  49.  
  50.     org    100h
  51. top:
  52.     jmp    start
  53.  
  54. usage:
  55.     db    CR,LF,'Usage:  PUBLIC [d:]           -- list PUBLIC files [on d:]'
  56.     db    CR,LF,'        PUBLIC [d:]file.ext   -- make file PUBLIC'
  57.     db    CR,LF,'        PUBLIC [d:]file.ext X -- make file private'
  58.     db    CR,LF,'$'
  59. header:
  60.     db    CR,LF,'The currently PUBLIC files are:',CR,LF,'$'
  61. tomsg:
  62.     db    '  set to ==> $'
  63. pubnam:
  64.     db    'PUBLIC   $'
  65. privnam:
  66.     db    'PRIVATE  $'
  67. ismsg:
  68.     db    '  ==> is already $'
  69. nopubs:
  70.     db    CR,LF,'(There are no PUBLIC files.)$'
  71.  
  72. multimsg:
  73.     db    CR,LF,LF,BELL,"*** Multiple copies, can't change!$"
  74. nonemsg:
  75.     db    CR,LF,BELL,'*** No File!$'
  76. cantmsg:
  77.     db    CR,LF,BELL,"*** Can't make file $"
  78.  
  79. start:
  80.     sspd    ustack
  81.     lxi    sp,stack
  82.  
  83.     lxi    h,fcb+1
  84.     mov    a,m
  85.     cpi    SPACE
  86.     lxi    h,flags
  87.     res    LISTPUBBIT,m
  88.     jrnz    setup
  89.  
  90.     bset    LISTPUBBIT,m
  91.     lxi    d,header
  92.     call    printde
  93. setup:
  94.     mvi    c,dmafn        ; set directory buffer
  95.     lxi    d,buf
  96.     call    bdos
  97.  
  98.     mvi    c,curdskfn    ; save current drive
  99.     call    bdos
  100.     sta    drive
  101.     sta    udrive
  102.  
  103.     lda    fcb        ; check for specified drive
  104.     ora    a
  105.     jrz    savusr
  106.  
  107.     dcr    a
  108.     sta    drive        ; login specified drive
  109.     mov    e,a
  110.     mvi    c,drivefn
  111.     call    bdos
  112. savusr:
  113.     mvi    c,userfn    ; save user number
  114.     lxi    d,0ffh
  115.     call    bdos
  116.     sta    uuser
  117.  
  118.     mvi    c,getaddrfn    ; get extent mask for this drive
  119.     call    bdos
  120.     inx    h
  121.     inx    h
  122.     inx    h
  123.     inx    h
  124.     mov    a,m
  125.     sta    EXTMASK
  126.  
  127.     xra    a
  128.     sta    count
  129.  
  130.     lda    fcb2+1
  131.     cpi    'X'
  132.     lxi    h,flags
  133.     res    MAKPUBBIT,m
  134.     jrz    find
  135.  
  136.     bset    MAKPUBBIT,m
  137.  
  138. ;
  139. ; find all filename entries in all user numbers
  140. ;
  141.  
  142. find:
  143.     lxi    h,fcb
  144.     mvi    m,'?'        ; match ALL dir entries
  145.     xchg
  146.     mvi    c,srchfstfn
  147.     call    bdos
  148.     sta    indx        ; save position in buffer
  149.     inr    a
  150.     jrz    done        ; no entries at all
  151. findall:
  152.     call    chknxt        ; is entry PUBLIC or specified filename?
  153.     jrnz    findnxt
  154.  
  155.     call    savefcb        ; yes -- save it
  156.     call    setcol
  157.     call    printentry    ; list it
  158.     lxi    h,count        ; and count it
  159.     inr    m
  160. findnxt:
  161.     mvi    c,srchnxtfn    ;
  162.     lxi    d,fcb
  163.     call    bdos
  164.  
  165.     sta    indx
  166.     inr    a
  167.     jrnz    findall
  168. nomore:
  169.     lxi    h,flags
  170.     bit    LISTPUBBIT,m
  171.     lda    count
  172.     jrz    nom0
  173.  
  174.     ora    a
  175.     jrnz    done
  176.  
  177.     lxi    d,nopubs
  178.     call    printde
  179.     jr    done
  180. nom0:
  181.     sui    1
  182.     jrc    none
  183.     jrnz    nochanges
  184.  
  185.     lxi    h,flags        ; exactly 1 file found
  186.     bit    MAKPUBBIT,m
  187.     jrz    nom1
  188.  
  189.     call    setpub
  190.     jr    done
  191. nom1:
  192.     call    setpriv
  193.     jr    done
  194.  
  195.  
  196. ;
  197. ; can't be PUBLIC if > 1 match on drive
  198. ;
  199.  
  200. nochanges:
  201.     lxi    d,multimsg
  202.     call    printde
  203.     jr    done
  204. none:
  205.     lxi    d,nonemsg
  206.     call    printde
  207.     jr    done
  208. nopub:
  209.     lxi    d,pubnam
  210.     call    cant
  211.  
  212. ;
  213. ; all done -- restore drive/user and return
  214. ;
  215.  
  216. done:
  217.     call    crlf
  218.     lxi    h,flags
  219.     bit    LISTPUBBIT,m
  220.     jrz    done0
  221.  
  222.     lxi    d,usage
  223.     call    printde
  224. done0:
  225.     lda    udrive        ; relogin user's drive
  226.     mov    e,a
  227.     mvi    c,drivefn
  228.     call    bdos
  229. done1:
  230.     lda    uuser
  231.     mov    e,a
  232.     mvi    c,userfn
  233.     call    bdos
  234.     call    crlf
  235. xit:
  236.     lspd    ustack
  237.     ret
  238.  
  239. ;
  240. ; set the PUBLIC attribute bit
  241. ;
  242.  
  243. setpub:
  244.     lxi    h,pubfcb+2    ; test attr bit 2
  245.     bit    7,m
  246.     jrnz    ispub        ; quit if already PUBLIC
  247.  
  248.     bset    7,m        ; set attr bit 2
  249.     lda    pubfcb        ; save user number for output
  250.     mov    e,a        ; set user number for this file
  251.     mvi    c,userfn    ;
  252.     call    bdos        ;
  253.  
  254.     lxi    h,pubfcb
  255.     mvi    m,0        ; put default drive into fcb
  256.     xchg
  257.     mvi    c,setattrfn    ;
  258.     call    bdos
  259.     inr    a
  260.     jrz    nopub
  261.  
  262.     lxi    d,tomsg
  263.     call    printde
  264.  
  265.     lxi    d,pubnam
  266.     call    printde
  267. setpend:
  268.     lxi    h,pubfcb
  269.     jmp    prnent1
  270. ispub:
  271.     lxi    d,pubnam
  272.     jmp    istype
  273.  
  274. ;
  275. ; reset the public attribute bit
  276. ;
  277.  
  278. setpriv:
  279.     lda    pubfcb        ; save file user number
  280.     mov    e,a        ; set user number of fcb
  281.     mvi    c,userfn
  282.     call    bdos
  283.  
  284.     lxi    h,pubfcb+2    ; reset PUBLIC attr bit
  285.     bit    7,m        ;
  286.     jrz    ispriv        ; quit if it's alread private
  287.  
  288.     res    7,m
  289.     lxi    h,pubfcb
  290.     mvi    m,0        ; default drive
  291.     xchg
  292.     mvi    c,setattrfn    ;
  293.     call    bdos
  294.     inr    a
  295.     jrz    nopriv
  296.  
  297.     lxi    d,tomsg
  298.     call    printde
  299.  
  300.     lxi    d,privnam
  301.     call    printde
  302.     jr    setpend
  303.  
  304. nopriv:
  305.     lxi    d,privnam
  306.     jmp    cant
  307.  
  308. ispriv:
  309.     lxi    d,privnam
  310. istype:
  311.     push    d
  312.     lxi    d,ismsg
  313.     call    printde
  314.     pop    d
  315. printde:
  316.     mvi    c,9
  317.     jmp    bdos
  318.  
  319. cant:
  320.     push    d
  321.     lxi    d,cantmsg
  322.     call    printde
  323.     pop    d
  324.     jr    printde
  325.  
  326. ;
  327. ; check next directory entry
  328. ; if listing PUBLIC files, ret Z if PUBLIC and 0th extent.
  329. ; if matching a filename, ret Z if same name, type and extent
  330. ; else ret NZ
  331. ;
  332.  
  333. chknxt:
  334.     call    findentry
  335.     mov    a,m
  336.     cpi    0e5h        ; don't match erased entries
  337.     jrnz    chkn0
  338.  
  339.     ora    a        ; set NZ
  340.     ret
  341. chkn0:
  342.     inx    h
  343.     lda    flags
  344.     bit    LISTPUBBIT,a
  345.     jrz    chkn1
  346.  
  347. ;
  348. ; list all PUBLIC files
  349. ;
  350.  
  351.     inx    h        ; point at 2nd char of filename
  352.     mov    a,m
  353.     cma
  354.     ani    80h        ; check complement of attr bit
  355.     rnz            ; not PUBLIC -- ret NZ
  356.  
  357.     lxi    d,12-2        ; have a PUBLIC file
  358.     dad    d        ; point at its extent byte
  359.     xra    a        ; and check for extent 0
  360.     jr    chkn3
  361.  
  362. ;
  363. ; check for match with specified filename / extent 0
  364. ;
  365. ; note: doesn't allow wiled cards.
  366. ;
  367.  
  368. chkn1:
  369.     lxi    d,fcb+1
  370.     mvi    b,11        ; name & type
  371. chkn2:
  372.     ldax    d
  373.     sub    m
  374.     ani    7fh        ; don't test attr bits
  375.     inx    h
  376.     inx    d
  377.     rnz            : NZ if no match
  378.     djnz    chkn2
  379.  
  380.     ldax    d        ; now check the extent
  381. chkn3:
  382.     mov    c,m
  383.  
  384. ;
  385. ; check for same extent in a,c
  386. ;
  387.  
  388. samext:
  389.     push    psw
  390. extmask    equ    $+1
  391.     mvi    a,0
  392.     cma
  393.     mov    b,a        ; save mask
  394.     mov    a,c        ; mask c
  395.     ana    b
  396.     mov    c,a        ; save in c
  397.     pop    psw        ;
  398.     ana    b
  399.     sub    c
  400.     ani    1fh        ; check only legal bits 0..4
  401.     ret
  402.  
  403. savefcb:
  404.     call    findentry
  405.     mov    a,m        ; save the user number
  406.     sta    fileuserno
  407.     lxi    d,pubfcb
  408.     lxi    b,32
  409.     ldir
  410.     ret
  411.  
  412. ;
  413. ; find entry in buffer
  414. ;
  415.  
  416. findentry:
  417.     lda    indx        ; point to fcb found
  418.     add    a        ; * 32
  419.     add    a
  420.     add    a
  421.     add    a
  422.     add    a
  423.     lxi    h,buf
  424.     add    l
  425.     mov    l,a
  426.     rnc
  427.  
  428.     inr    h
  429.     ret
  430.  
  431.  
  432. setcol:
  433.     lda    count
  434.     ani    3
  435.     jz    crlf
  436.  
  437.     call    twosp
  438.     mvi    c,fence
  439.     call    charout
  440. twosp:
  441.     mvi    c,SPACE
  442.     call    charout
  443.     mvi    c,SPACE
  444.     jmp    charout
  445.  
  446. ;
  447. ; print drive/user/filename
  448. ;
  449.  
  450. printentry:
  451.     call    findentry
  452. prnent1:
  453.     push    h
  454.     call    printdrv
  455. fileuserno    equ    $+1
  456.     mvi    a,0
  457.     call    printuser
  458.     pop    h
  459. print$fn:
  460.     inx    h        ; print finename.ext
  461.     mvi    b,8
  462.     call    prfn
  463.     mvi    c,'.'
  464.     call    charout
  465.     mvi    b,3
  466. prfn:
  467.     mov    a,m        ; print filename char, lowercase if attr bit set
  468.     ani    7fh        ; kill attr bit when printing
  469.     cmp    m        ;
  470.     jrz    prfn1
  471.  
  472.     ori    20h        ; set lower case
  473. prfn1:
  474.     mov    c,a
  475.     call    charout
  476.     inx    h
  477.     djnz    prfn
  478.     ret
  479.  
  480. printdrv:
  481.     lda    drive        ; print drive
  482.     adi    'A'
  483.     mov    c,a
  484.     jr    charout
  485.  
  486. crlf:
  487.     mvi    c,CR
  488.     call    charout
  489.     mvi    c,LF
  490. charout:
  491.     push    h
  492.     push    b
  493.     push    d
  494.     mov    e,c
  495.     mvi    c,2
  496.     call    bdos
  497.     pop    d
  498.     pop    b
  499.     pop    h
  500.     ret
  501.  
  502. printuser:
  503.     cpi    10        ; print A as user number
  504.     jrnc    printu1
  505.  
  506.     push    psw        ; 1 space if single digit
  507.     mvi    c,SPACE
  508.     call    charout
  509.     pop    psw
  510. printu1:
  511.     mov    l,a
  512.     mvi    h,0
  513.     call    printdec
  514.     mvi    c,':'
  515.     jr    charout
  516.  
  517. printdec:
  518. decout:
  519.     push    psw
  520.     push    b
  521.     push    d
  522.     push    h
  523.     lxi    b,-10
  524.     lxi    d,-1
  525. decou2:
  526.     dad    b
  527.     inx    d
  528.     jc    decou2
  529.  
  530.     lxi    b,10
  531.     dad    b
  532.     xchg
  533.     mov    a,h
  534.     ora    l
  535.     cnz    decout        ; recursive
  536.  
  537.     mov    a,e
  538.     adi    '0'
  539.     mov    c,a
  540.     call    charout
  541.     pop    h
  542.     pop    d
  543.     pop    b
  544.     pop    psw
  545.     ret
  546.  
  547.  
  548. flags    db    0
  549. indx    db    0
  550. drive    db    0
  551. count    db    0
  552. udrive    db    0
  553. uuser    db    0
  554. ustack    dw    0
  555. pubfcb    equ    $
  556. stack    equ    pubfcb+32+48
  557. buf    equ    stack
  558.     end
  559.