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 / PUBPATCH / PUBLIC.ASM < prev    next >
Assembly Source File  |  2000-06-30  |  9KB  |  496 lines

  1.     title 'PUBLIC.ASM v 1.1 11-14-84 (c) 1984 Plu*Perfect Systems'
  2.     PAGE 55
  3. ;
  4. vers    equ    1$1
  5. ;
  6. ;Utility to set/clear attribute bit 2  of filename.
  7. ;For use with Plu*Perfect Systems' PUBlic-file BDOS patch.
  8. ;
  9. ;usage: PUBLIC [d:]            -- lists PUBlic files (on d:)
  10. ;    PUBLIC [d:]filename.typ     -- makes filename.typ PUBlic
  11. ;    PUBLIC [d:]filename.typ [X]     -- makes filename.typ private
  12. ;    filename,type must be unambiguous - no wildcards
  13. ;
  14. ;prints drive/user number of all files of specified name,
  15. ;  with attribute bits displayed as lower-case characters
  16. ;
  17. ;if just one such file found:
  18. ;    if X, clears attribute bit - making file private in orig user #
  19. ;    else,   sets attribute bit - making file PUBlic
  20. ;
  21. ;
  22. ; v 1.1    Fixed extent match on overflow to S2 byte (11-14-84)
  23. ;
  24.     maclib z80
  25.  
  26. FALSE    EQU    0    
  27. TRUE    EQU    NOT FALSE
  28. ;
  29. LISTPUBBIT    equ    0
  30. MAKPUBBIT    equ    1
  31. fence        equ    '|'
  32. ;
  33. NULL    equ    0
  34. BELL    equ    'G'-'@'
  35. CR    equ    0dh
  36. LF    equ    0ah
  37. ESC    equ    1bh
  38. SPACE    EQU    ' '
  39. DEL    EQU    7FH
  40.  
  41. drivefn    equ    14
  42. openfn    equ    15
  43. closefn    equ    16
  44. srchfstfn equ    17
  45. srchnxtfn equ    18
  46. deletefn equ    19
  47. readfn    equ    20
  48. writefn    equ    21
  49. makefn    equ    22
  50. renamefn equ    23
  51. logvecfn equ    24
  52. curdskfn equ    25
  53. dmafn    equ    26
  54. setattrfn equ    30
  55. getaddrfn equ    31
  56. userfn    equ    32
  57. readrfn    equ    33
  58. writerfn equ    34
  59. sizefn    equ    35
  60. ;
  61. reccnt    equ    15
  62. currec    equ    32
  63. r0    equ    33
  64. tbuff    equ    80h
  65. fcb    equ    5ch
  66. fcb2    equ    fcb+16
  67. ;
  68. BOOT equ    0000h
  69. BDOS equ    0005h
  70. ADDRESS equ    0FFFFh    ;filled in by loader
  71. bdoslen        equ    0e00h
  72.  
  73. dobdos    macro    num,arg
  74.     if not nul arg
  75.     lxi    de,arg
  76.     endif
  77.     mvi    c,num
  78.     call    5
  79.     endm
  80. ;
  81. print    macro    msg
  82.     if not nul msg
  83.     lxi    d,msg
  84.     endif
  85.     call    printde
  86.     endm
  87. ;
  88. $-MACRO
  89.     PAGE
  90.     aseg
  91.     org 100h
  92. ;
  93. top:    jmp    start
  94. ;
  95. banner:    db    CR,LF,'PUBLIC v '
  96.     db    vers/10+'0','.',(vers mod 10)+'0'
  97.     db    ' (c) 1984 Plu*Perfect Systems$'
  98. ;
  99. usage:    db    CR,LF,LF,'Usage:  '
  100.     db    'PUBLIC [d:]           -- list PUBlic files (on d:)'
  101.     db    CR,LF,'        '
  102.     db    'PUBLIC [d:]file.ext   -- make file PUBlic'
  103.     db    CR,LF,'        '
  104.     db    'PUBLIC [d:]file.ext X -- make file private'
  105.     db    CR,LF,LF,'$'
  106. ;
  107. header:    db    CR,LF,LF,'The currently PUBlic files are:',CR,LF,'$'
  108. ;    
  109. tomsg:    db    ' set to ==> $'
  110. pubnam:    db    'PUBLIC   $'
  111. privnam:db    'PRIVATE  $'
  112. ismsg:    db    '  ==> is already $'
  113. ;
  114. multimsg:db    CR,LF,BELL,'*** Multiple copies, can''t change!$'
  115. nonemsg:db    CR,LF,BELL,'*** No file!$'
  116. cantmsg:db    CR,LF,BELL,'*** Can''t make file $'
  117. nopubs:    db    CR,LF,'(None.)$'
  118. ;
  119. ;
  120. start:    sspd    ustack
  121.     lxi    sp,stack
  122.     print    banner
  123.     lxi    h,fcb+1
  124.     mov    a,m
  125.     cpi    SPACE
  126.     lxi    h,flags
  127.     res    LISTPUBBIT,m
  128.     jrnz    setup
  129.     setb    LISTPUBBIT,m
  130.     print    header
  131. ;
  132. setup:    dobdos    dmafn,buf    ;set directory buffer
  133.     dobdos    curdskfn    ;save user's drive
  134.     sta    drive
  135.     sta    udrive
  136.     lda    fcb        ;check for specified drive
  137.     ora    a
  138.     jrz    savusr
  139.     dcr    a
  140.     sta    drive        ;login specified drive
  141.     mov    e,a
  142.     dobdos    drivefn,
  143. ;
  144. savusr:    dobdos    userfn,0ffh    ;save user #
  145.     sta    uuser
  146.     dobdos    getaddrfn    ;get extent mask for this drive
  147.     inx h ! inx h ! inx h ! inx h
  148.     mov    a,m
  149.     sta    EXTMASK
  150.     xra    a
  151.     sta    count
  152.     lda    fcb2+1
  153.     cpi    'X'
  154.     lxi    h,flags
  155.     res    MAKPUBBIT,m
  156.     jrz    find
  157.     setb    MAKPUBBIT,m
  158. ;
  159.     PAGE
  160. ;    find all filename entries in all user numbers
  161. ;
  162. find:    lxi    h,fcb
  163.     mvi    m,'?'        ;match ALL dir entries
  164.     xchg
  165.     dobdos    srchfstfn,
  166.     sta    indx        ;save position in buffer
  167.     inr    a
  168.     jrz    done        ;no entries at all
  169. ;
  170. findall:call    chknxt        ;is entry PUBlic or specified filename?
  171.     jrnz    findnxt
  172.     call    savefcb        ;yes - save it
  173.     call    setcol
  174.     call    printentry    ; list it
  175.     lxi    h,count        ; and count it
  176.     inr    m
  177. findnxt:dobdos    srchnxtfn,fcb
  178.     sta    indx
  179.     inr    a
  180.     jrnz    findall    
  181. ;
  182. nomore:    lxi    h,flags
  183.     bit    LISTPUBBIT,m    
  184.     lda    count
  185.     jrz    nom0
  186.     ora    a
  187.     jrnz    done
  188.     print    nopubs
  189.     jr    done
  190. ;
  191. nom0:    sui    1
  192.     jrc    none
  193.     jrnz    nochanges
  194.     lxi    h,flags        ;exactly 1 file found
  195.     bit    MAKPUBBIT,m
  196.     jrz    nom1
  197.     call    setpub
  198.     jr    done
  199. nom1:    call    setpriv
  200.     jr    done
  201. ;
  202.     PAGE
  203. nochanges:    ;can't be PUBlic if > 1 match on drive
  204.     print    multimsg
  205.     jr    done
  206. ;
  207. none:    print    nonemsg
  208.     jr    done
  209. ;
  210. nopub:    lxi    d,pubnam
  211.     call    cant
  212. ;fall thru
  213. ;
  214. ;    all done, restore drive/user and return
  215. ;
  216. done:    lxi    h,flags
  217.     bit    LISTPUBBIT,m
  218.     jrz    done0
  219.     print    usage
  220. done0:    lda    udrive    ;relogin user's drive
  221.     mov    e,a
  222.     dobdos    drivefn,
  223. done1:    lda    uuser
  224.     mov    e,a
  225.     dobdos    userfn,
  226.     call    crlf
  227. xit:    lspd    ustack
  228.     ret
  229. ;
  230. ;    set the PUBlic attribute bit
  231. ;
  232. setpub:    lxi    h,pubfcb+2    ;test attr bit 2 
  233.     bit    7,m
  234.     jrnz    ispub        ;quit if already PUBlic
  235.     setb    7,m        ;set attr bit 2
  236.     lda    pubfcb        ;save user # for output
  237.     mov    e,a        ;set user # of this file
  238.     dobdos    userfn,
  239.     lxi    h,pubfcb
  240.     mvi    m,0        ;put default drive into fcb
  241.     xchg
  242.     dobdos    setattrfn,
  243.     inr    a
  244.     jrz    nopub
  245.     print    tomsg
  246.     print    pubnam
  247. setpend:
  248.     lxi    h,pubfcb
  249.     jmp    printent1
  250. ;
  251. ispub:    lxi    d,pubnam
  252.     jmp    istype
  253. ;
  254. ;
  255. ;    reset the PUBlic attribute bit
  256. ;
  257. setpriv:
  258.     lda    pubfcb        ;save file user #
  259.     mov    e,a        ;set user # of fcb
  260.     dobdos    userfn,
  261.     lxi    h,pubfcb+2    ;reset PUBlic attr bit
  262.     bit    7,m
  263.     jrz    ispriv        ;quit if it's already private
  264.     res    7,m    
  265.     lxi    h,pubfcb
  266.     mvi    m,0        ;default drive
  267.     xchg
  268.     dobdos    setattrfn
  269.     inr    a
  270.     jrz    nopriv
  271.     print    tomsg
  272.     print    privnam
  273.     jr    setpend
  274. ;
  275.     PAGE
  276. nopriv:    lxi    d,privnam
  277.     jmp    cant
  278. ;
  279. ispriv:    lxi    d,privnam
  280. ;    fall thru
  281. istype:    push    d
  282.     print    ismsg
  283.     pop    d
  284. ;    fall thru
  285. ;
  286. printde:        ;bdos string print function
  287.     mvi    c,9
  288.     jmp    5
  289. ;    
  290. cant:    push    d
  291.     print    cantmsg
  292.     pop    d        ;print 2nd msg
  293.     jr    printde
  294. ;
  295. ;    check next directory entry
  296. ;    if listing PUBlic files, ret Z if PUBlic and 0th extent
  297. ;    if matching a filename,    ret Z if same name,type and extent
  298. ;    else ret NZ
  299. chknxt:    call    findentry
  300.     mov    a,m
  301.     cpi    0E5h        ;don't match erased entries
  302.     jrnz    chkn0
  303.     ora    a        ;set nz
  304.     ret        
  305. chkn0:    inx    h
  306.     lda    flags
  307.     bit    LISTPUBBIT,a
  308.     jrz    chkn1
  309. ;
  310. ;    list all PUBlic files
  311.     inx    h        ;point at 2nd char of filename
  312.     mov    a,m
  313.     cma
  314.     ani    80h        ;check compl of attr bit
  315.     rnz            ;not PUBlic - ret NZ
  316.     lxi    d,12-2        ;have a PUBlic file,
  317.     dad    d        ;point at its extent byte
  318.     xra    a        ;and check for extent 0
  319.     jr    chkn3
  320. ;
  321. ;    check for match with specified filename/extent 0
  322. ;note* doesn't  allow wild cards
  323. chkn1:    lxi    d,fcb+1
  324.     mvi    b,11        ;name & type
  325. chkn2:    ldax    d
  326.     sub    m
  327.     ani    7fh        ;don't test attr bits
  328.     inx    h
  329.     inx    d
  330.     rnz            ;nz if no match
  331.     djnz    chkn2
  332.     xra    a        ;check for extent # 0
  333. chkn3:    mov    c,m
  334. ;
  335. ;    check for same extent in A, C
  336. ;
  337. SAMEXT:            ;z set if same extent
  338.     push    psw
  339. EXTMASK equ $+1
  340.     mvi    a,00h
  341.     cma
  342.     mov    b,a    ;save mask
  343.     mov    a,c    ;mask C
  344.     ana    b
  345.     mov    c,a    ;save in C
  346.     pop    psw    ;now do A
  347.     ana    b
  348.     sub    c
  349.     ani    1Fh    ;check only legal bits 0-4
  350.     rnz        ; v 1.1 11-14-84
  351.     inx    h    ;extent is 0, check overflow (s2) ext.
  352.     inx    h
  353.     mov    a,m
  354.     ani    7fh
  355.     ret
  356. ;
  357. ;
  358. savefcb:
  359.     call    findentry
  360.     mov    a,m    ;save the user #
  361.     sta    fileuserno
  362.     lxi    d,pubfcb
  363.     lxi    b,32
  364.     ldir
  365.     ret
  366. ;        
  367. findentry:            ;find entry in buf
  368.     lda    indx        ;point to fcb found
  369.     add    a        ;*32
  370.     add    a
  371.     add    a
  372.     add    a
  373.     add    a
  374.     lxi    h,buf
  375.     add    l
  376.     mov    l,a
  377.     rnc
  378.     inr    h
  379.     ret
  380. ;
  381. setcol:    lda    count
  382.     ani    03h
  383.     jz    crlf
  384.     call    twosp
  385.     mvi    c,fence
  386.     call    charout
  387. twosp:    mvi    c,space
  388.     call    charout
  389.     mvi    c,space
  390.     jmp    charout    
  391.  
  392. printentry:        ;print drive/user/filename
  393.     call    findentry
  394. printent1:            ;print at (hl)
  395.     push    h
  396.     call    printdrv
  397. fileuserno equ $+1
  398.     mvi    a,00h
  399.     call    printuser
  400.     pop    h
  401. ;fall thru
  402. print$fn:        ;print filename.ext
  403.     inx    h
  404.     mvi    b,8
  405.     call    prfn
  406.     mvi    c,'.'
  407.     call    charout
  408.     mvi    b,3
  409. ;fall thru
  410. prfn:            ;print filename char, lowercase if attr bit set
  411.     mov    a,m
  412.     ani    7fh    ;kill attr bit when printing
  413.     cmp    m
  414.     jrz    prfn1
  415.     ori    20h    ;set lower case
  416. prfn1:    mov    c,a
  417.     call    charout
  418.     inx    h
  419.     djnz    prfn
  420.     ret
  421. ;    
  422. printdrv:        ;print drive
  423.     lda    drive
  424.     adi    'A'
  425.     mov    c,a
  426.     jr    charout
  427. ;
  428. crlf:    mvi    c,CR
  429.     call    charout
  430.     mvi    c,LF
  431. ;fall thru
  432. ;
  433. charout:        ;preserve registers
  434.     push    h
  435.     push    b
  436.     push    d
  437.     mov    e,c
  438.     mvi    c,2
  439.     call    5
  440.     pop    d
  441.     pop    b
  442.     pop    h
  443.     ret
  444. ;
  445. printuser:        ;print A as user # 
  446.     cpi    10
  447.     jrnc    printu1
  448.     push    psw        ;1 space if sgl digit
  449.     mvi    c,' '
  450.     call    charout
  451.     pop    psw
  452. printu1:mov    l,a
  453.     mvi    h,0
  454.     call    printdec
  455.     mvi    c,':'
  456.     jr    charout
  457. ;
  458. printdec:
  459. DECOUT:    PUSH    PSW        ;prints hl in decimal
  460.     PUSH    B
  461.     PUSH    D
  462.     PUSH    H
  463.     LXI    B,-10
  464.     LXI    D,-1
  465. DECOU2:    DAD    B
  466.     INX    D
  467.     JC    DECOU2
  468.     LXI    B,10
  469.     DAD    B
  470.     XCHG
  471.     MOV    A,H
  472.     ORA    L    
  473.     CNZ    DECOUT    ;recursive
  474.     MOV    A,E
  475.     ADI    '0'
  476.     mov    c,a
  477.     call    charout
  478.     POP    H
  479.     POP    D
  480.     POP    B
  481.     POP    PSW
  482.     RET
  483. ;
  484. flags:    db    0
  485. indx:    db    0
  486. drive:    db    0
  487. count:    db    0
  488. udrive:    db    0        ;user's drive
  489. uuser:    db    0
  490. ustack:    dw    0
  491. pubfcb equ $
  492. stack equ pubfcb +32 + 48
  493. ;
  494. buf    equ    stack
  495.     END
  496.