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 / DOSPLSOR.ARK / ALIAS.MAC < prev    next >
Text File  |  1986-11-13  |  6KB  |  287 lines

  1. ;
  2. ; Create an alias directory entry for file on same user
  3. ; Mark original and alias as read-only.  Preserve any
  4. ; other attribute bits.
  5. ;
  6. ; File must be described in one directory entry.
  7. ;
  8. reboot        equ    0
  9. bdos        equ    reboot+5
  10. ;
  11. tfcb        equ    reboot+05ch
  12. tfcb.ro        equ    tfcb+9;        high bit only
  13. tfcb.xtnt    equ    tfcb+12
  14. tfcb.nxt    equ    tfcb+32
  15. tfcb.rr        equ    tfcb+33
  16. ;
  17. afcb        equ    tfcb+16;    2nd parameter here
  18. ;
  19. ; Bdos calls
  20. @tstr    equ    9
  21. @ver    equ    12
  22. @seldsk    equ    14
  23. @fopen    equ    15
  24. @fclose    equ    16
  25. @make    equ    22
  26. @curdsk    equ    25
  27. @sfattr    equ    30;        set file attributes
  28. @dparms    equ    31;        get disk parameters
  29. @fsize    equ    35;        get file size
  30. ;
  31. cr    equ    0dh
  32. lf    equ    0ah
  33. ;
  34. ;    -----------
  35. ;
  36.     lxi    h,0
  37.     dad    sp
  38.     lxi    sp,stack
  39.     push    h
  40.     lda    tfcb+1
  41.     cpi    ' '
  42.     stc
  43.     lxi    h,help
  44.     jz    msgxit
  45.     mvi    c,@ver
  46.     call    bdos;        get hl value
  47.     inr    h
  48.     dcr    h
  49.     stc
  50.     lxi    h,badver
  51.     jnz    msgxit;        MPM?
  52.     cpi    22h
  53.     cnc    alias;        version ok
  54. msgxit:    cc    tstr;        message on failure
  55. exit:    pop    h
  56.     sphl
  57.     ret
  58. ;
  59. ; Create alias.  Exit with carry & hl pointer to message on error.
  60. ; a,f,b,c,d,e,h,l
  61. alias:    lxi    h,afcb;        save 2nd parameter
  62.     lxi    d,fcb
  63.     mvi    b,16
  64.     call    move
  65. ;    "    "
  66. ; Now verify all the things that can go wrong.
  67.     lxi    d,fcb
  68.     call    wldchk
  69.     jc    nowild
  70.     inx    d
  71.     ldax    d
  72.     cpi    ' '
  73.     lxi    h,needf
  74.     stc
  75.     rz
  76.     lxi    d,tfcb;        1st parameter
  77.     ldax    d
  78.     ora    a
  79.     sta    fcb;        jam to same drives
  80.     lxi    h,spec
  81.     stc
  82.     rz;            must specify drive
  83.     call    wldchk
  84.     jc    nowild
  85.     mvi    a,0ffh
  86.     sta    tfcb.nxt;    to get byte size returned
  87.     mvi    a,@fopen
  88.     call    dos
  89.     lxi    h,nofile
  90.     inr    a
  91.     stc
  92.     rz;            open failure
  93.     lda    tfcb.nxt;    CPM2.2 returns garbage
  94.     sta    bytcnt;        (harmless). DOS+/CPM3 rtn size.
  95.     mvi    a,@fopen
  96.     call    foper
  97.     inr    a
  98.     stc
  99.     lxi    h,exists
  100.     rnz;            alias exists
  101.     mvi    a,@curdsk
  102.     call    dos
  103.     push    psw;        save current drive
  104.     lda    tfcb
  105.     dcr    a
  106.     mov    e,a
  107.     mvi    a,@seldsk
  108.     call    dos;        select appropriate drive
  109.     mvi    c,@dparms
  110.     call    bdos;        need hl result here
  111.     inx    h
  112.     inx    h
  113.     inx    h
  114.     inx    h
  115.     mov    a,m;        get extent mask (extents/entry)
  116.     inr    a;        count of 16k blocks/dir entry
  117.     lxi    h,0
  118.     lxi    d,128;        records/16k block
  119. alias1:    dad    d;        * blocks/entry
  120.     dcr    a;        = records/entry
  121.     jnz    alias1;        compute max size in 1 dir entry
  122.     pop    psw
  123.     mov    e,a
  124.     mvi    a,@seldsk;    have info, so
  125.     call    dos;        restore current drive
  126.     push    h;        save max size value
  127.     lxi    d,tfcb
  128.     mvi    a,@fsize
  129.     call    dos;        get size of file
  130.     pop    b;        max size to bc
  131.     lda    tfcb.rr+2
  132.     ora    a
  133.     lxi    h,toobig
  134.     stc
  135.     rnz;            file too large
  136.     xchg
  137.     lhld    tfcb.rr
  138.     xchg
  139.     mov    a,c
  140.     sub    e
  141.     mov    a,b
  142.     sbb    d
  143.     rc;            file too large for 1 dir entry
  144.     mvi    a,@make
  145.     call    foper;        create empty file
  146.     inr    a
  147.     stc
  148.     lxi    h,nodir
  149.     rz;            no directory space
  150. ;    "    "
  151. ; Now the source file is open, destination created on same drive,
  152. ; and we know that the source is described in one directory entry.
  153. ; Copy its allocation/size information to the alias FCB
  154.     lxi    h,tfcb.xtnt
  155.     lxi    d,fcb.xtnt
  156.     mvi    b,20
  157.     call    move
  158. ;    "    "
  159. ; Mark the alias modified (to record on close) and close.  Then set
  160. ; r/o attribute in original, and set bytecount/attributes in alias.
  161. ; On DOS+ the alias create/modify date will set to current time.
  162.     lxi    h,fcb.s2
  163.     mov    a,m
  164.     ani    07fh
  165.     mov    m,a;        mark file dirty
  166.     mvi    a,@fclose
  167.     call    foper
  168.     lxi    h,tfcb.ro
  169.     mov    a,m
  170.     ori    080h
  171.     mov    m,a;        mark read only
  172.     lxi    d,tfcb
  173.     mvi    a,@sfattr
  174.     call    dos
  175.     lxi    h,fcb
  176.     push    h
  177.     mvi    b,11
  178. alias2:    inx    d
  179.     inx    h
  180.     ldax    d
  181.     ani    080h;        copy all file attributes
  182.     ora    m
  183.     mov    m,a
  184.     dcr    b
  185.     jnz    alias2
  186.     lxi    h,fcb.ifc6
  187.     mov    a,m
  188.     ori    80h;        set interface attribute for bytecount
  189.     mov    m,a
  190.     lda    bytcnt;        this for DOS+ and CPM3 only
  191.     sta    fcb.nxt
  192.     pop    d;        fcb
  193.     mvi    a,@sfattr
  194.     call    dos;        and set attributes/byte count
  195.     xra    a;        signal success
  196.     ret
  197. ;
  198. ; No wild card message
  199. nowild:    lxi    h,nowld
  200.     call    tstr
  201.     lxi    h,help
  202.     stc
  203.     ret
  204. ;
  205. ; Type string hl^ to console
  206. ; a,f
  207. tstr:    xchg
  208.     mvi    a,@tstr
  209.     call    dos
  210.     xchg
  211.     ret
  212. ;
  213. ; operate on file fcb
  214. ; a,f,d,e
  215. foper:    lxi    d,fcb
  216. ;    "    "
  217. ; protected dos call, function a, set flags on returned value
  218. ; a,f
  219. dos:    push    h
  220.     push    d
  221.     push    b
  222.     mov    c,a
  223.     call    bdos
  224.     pop    b
  225.     pop    d
  226.     pop    h
  227.     ora    a
  228.     ret
  229. ;
  230. ; scan fcb de^ for wildcards. Carry if any
  231. ; a,f,b
  232. wldchk:    push    d
  233.     xchg
  234.     mvi    b,11
  235.     mvi    a,'?'
  236. wldck1:    inx    h
  237.     cmp    m
  238.     stc
  239.     jz    wldck2;        wild card
  240.     dcr    b
  241.     jnz    wldck1
  242.     xra    a;        ok, no wilds
  243. wldck2:    xchg
  244.     pop    d
  245.     ret
  246. ;
  247. ; move b bytes from hl^ to de^
  248. move:    mov    a,m
  249.     stax    d
  250.     inx    h
  251.     inx    d
  252.     dcr    b
  253.     jnz    move
  254.     ret    
  255. ;
  256. nodir:    db    'No directory space available$'
  257. spec:    db    'Must specify drive$'
  258. exists:    db    'Alias name already exists$'
  259. nowld:    db    'No wild cards allowed',cr,lf,cr,lf,'$'
  260. nofile:    db    'Can''t find file$'
  261. badver:    db    'Need CPM 2.2 or DOS+$'
  262. toobig:    db    'File too large for alias entry$'
  263. needf:    db    'No alias name specified',cr,lf,cr,lf
  264. help:    db    'usage: ALIAS d:fn.ft newnm.newt',cr,lf
  265.     db    ' creates an alias directory entry for fn.ft',cr,lf
  266.     db    ' allowing fn.ft to be referanced as newnm.newt',cr,lf
  267.     db    'BOTH files are then marked read/only',cr,lf,cr,lf
  268.     db    'IF EITHER erased, do immediate ^C to protect other$'
  269. ;
  270. fcb:        ds    1
  271. fcb.nm        ds    8
  272. fcb.ifc6    equ    fcb+6;    high bit only, interface attribute
  273. fcb.typ:    ds    3
  274. fcb.xtnt:    ds    1
  275. fcb.s1:        ds    1;    bytecount kept here
  276. fcb.s2:        ds    1;    high extent, clean bit
  277. fcb.rc        ds    1;    records in last xtnt
  278. fcb.dm        ds    16;    disk map
  279. fcb.nxt:    ds    1
  280. fcb.rr:        ds    3;    random rcd #    
  281. ;
  282. bytcnt:    ds    1
  283.  
  284.     ds    64
  285. stack:
  286.     end
  287. ╓