home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / cpm68k / sd68k.lbr / SD.SQ / SD.S
Encoding:
Text File  |  1986-06-11  |  10.4 KB  |  502 lines

  1. ****    SD -- Sorted Directory
  2. **
  3. **
  4. **        Sorted Directory Program
  5. **
  6. **            by
  7. **            James M. Knox
  8. **            TriSoft
  9. **
  10. **            (C) 1983 by TriSoft
  11. **
  12. **            modified 14Feb85 jmk /fixed for high TPA/
  13. **
  14. **
  15. **    Function:
  16. **        Print sorted directory to CON: or disk file.
  17. **    Inputs:
  18. **        Command line of the form:
  19. **
  20. **        SD [filespec] [-optionlist] [>outfilespec]
  21. **
  22. **        where
  23. **            filespec == description of files to be listed
  24. **
  25. **            optionlist == list of options selected
  26. **
  27. **                -F == display file flags (R*eadonly)
  28. **                             (S*ystem file)
  29. **                             (A*rchived)
  30. **
  31. **                -S == (don't) display system files
  32. **
  33. **                -K == (don't) display file size
  34. **
  35. **            note: option list may be combined or separate, and
  36. **                may use $ instead of - for indicator.  ex)
  37. **
  38. **                SD -S -F -K
  39. **                SD -SFK
  40. **                SD $SF -K
  41. **                        all perform the same function.
  42. **
  43. **            outfilespec == output is written to disk file rather
  44. **                than to CON:
  45. **
  46.     .globl    endjob
  47.     .globl    crlf
  48.     .globl    cout
  49.     .globl    sort
  50.     .globl    cmpa12
  51.     .globl    md5dc
  52.     .globl    optscn
  53. *
  54. cr    equ    13        * carriage return
  55. lf    equ    10        * line feed
  56. *
  57.     .text
  58. **    initialize
  59. *
  60. sd:    clr    tblcnt        * clear table count
  61.     clr    filcnt        * clear file count
  62.     move.l    #table,tblptr
  63. *
  64.     move.l    #secb,d1    * set DMA pointer
  65.     move    #26,d0
  66.     trap    #2
  67. *
  68.     move    #$19,d0
  69.     trap    #2        * get current disk #
  70.     ext.w    d0
  71.     move    d0,curdsk
  72. *
  73.     move.l    4(a7),bpage
  74.     move.l    4(a7),d0
  75.     addi.l    #$81,d0
  76.     move.l    #opttbl,d1
  77.     move.l    #fcb,d2
  78.     clr.l    d3        * no input re-direct
  79.     move.l    #outfcb,d4    * output fcb
  80.     move.b    #$ff,outfcb    * set to default
  81.     jsr    optscn        * scan command line
  82.     tst.l    d1
  83.     beq    endjob        * if errors found, abort
  84.     move.b    #'?',fcb+12    * get all extents
  85. *
  86. *
  87. **    get first DIR entry
  88. *
  89.     move.l    #fcb,d1
  90.     move    #17,d0
  91.     trap    #2
  92.     bra    gtnxt1
  93. *
  94. **    get next DIR entry
  95. *
  96. gtnext:    move.l    #fcb,d1
  97.     move    #18,d0
  98.     trap    #2
  99. gtnxt1:    cmpi.b    #$ff,d0        * check for last
  100.     beq    dsort
  101. *
  102.     andi.l    #3,d0        * compute ptr to entry
  103.     rol    #5,d0
  104.     addi.l    #secb+1,d0
  105.     moveq    #11,d1        * eleven characters in name
  106.     move.l    d0,a0        * plus extent
  107.     move.l    tblptr,a1
  108.     tst.b    sflag
  109.     bne    gtnxt2        * wants all files
  110.     btst    #7,9(a0)    * test system bit
  111.     bne    gtnext        * skip if system file
  112. gtnxt2:    move.b    (a0)+,(a1)+
  113.     dbra    d1,gtnxt2    * loop for file name
  114. *
  115. gtnxt3:    move.b    2(a0),(a1)+    * pick up size
  116.     addq    #1,a1
  117.     move.l    a1,tblptr
  118.     addq    #1,tblcnt
  119.     jmp    gtnext
  120. *
  121. **    sort table
  122. *
  123. dsort:
  124. *
  125.     tst    tblcnt        * check for empty directory
  126.     beq    nofil        * plum clean
  127. *
  128.     move.l    #ssbtbl,d1
  129.     move.w    tblcnt,ssbtbl+4
  130.     jsr    sort        * sort names
  131. *
  132.     move.l    #table,a0
  133.     move    tblcnt,a1
  134.     jsr    prtbl
  135.     jmp    endjob
  136. *
  137. **    no files found
  138. *
  139. nofil:    move.l    #mnofil,d1    * print message
  140.     moveq    #9,d0
  141.     trap    #2
  142.     jmp    endjob
  143. *
  144. *
  145. **    print table
  146. *
  147. *        A0 = table pointer
  148. *        A1 = # of entries
  149. *
  150. prtbl:
  151.     move.b    outfcb,d1
  152.     cmpi.b    #$ff,d1
  153.     beq    prtbl0        * no output file spec
  154. *
  155.     movem.l    a0-a1,-(a7)
  156.     move.l    #outbuf,a0
  157.     move    #31,d0
  158. opof1:    move.l    #$1a1a1a1a,(a0)+  * clear buffer
  159.     dbra    d0,opof1
  160.     move.l    #outfcb,d1
  161.     move    #$13,d0        * delete existing file
  162.     trap    #2
  163.     move.l    #outfcb,d1
  164.     move    #$16,d0        * make new file
  165.     trap    #2
  166.     cmpi.b    #3,d0
  167.     bgt    sdperr        * error opening file
  168.     move.l    #outbuf,d1
  169.     move    #$1a,d0
  170.     trap    #2        * set dma to OUTBUF
  171.     movem.l    (a7)+,a0-a1
  172. *
  173. prtbl0:    move.b    fcb,d1
  174.     beq    prtbl1        * if default drive chosen
  175.     ext.w    d1
  176.     subq    #1,d1
  177.     move    #$0e,d0
  178.     trap    #2        * select disk
  179. prtbl1:    move.l    #secb,d1
  180.     move    #$1f,d0
  181.     trap    #2        * get disk parameter table
  182.     move.b    secb+3,d0    * get block mask
  183.     ext.w    d0
  184.     move    d0,blm
  185.     move.b    secb+4,d0
  186.     ext.w    d0
  187.     move    d0,exm
  188.     tst.b    fcb
  189.     beq    prtbl2        * default, no need to reset
  190.     move    curdsk,d1
  191.     move    #$0e,d0
  192.     trap    #2        * re-select default
  193. prtbl2:
  194. *
  195.     move    #6,fplin    * files per line
  196.     move.b    kflag,d1    * check for options
  197.     add.b    fflag,d1
  198.     cmpi.b    #0,d1
  199.     beq    prtbl8        * no display options
  200.     addq.b    #1,d1
  201.     ext.w    d1
  202.     sub    d1,fplin
  203. *
  204. prtbl8:    clr    nflin        * # of files on line
  205.     clr    totsiz
  206.     clr    fcount
  207. *
  208. prnxt:    clr    fsize        * files size
  209. prnxt0:    move.b    12(a0),d2    * fsize=fsize+reccnt
  210.     andi    #$00ff,d2
  211.     move    blm,d3        * block mask size
  212.     add    d3,d2
  213.     not    d3
  214.     and    d3,d2
  215.     ext.l    d2
  216.     ror.l    #3,d2            * convert to k-bytes
  217.     add    d2,fsize
  218.     clr    d3
  219.     move.b    11(a0),d2    * extent mask
  220.     and    exm,d2
  221. prnx00:    beq    prnx01        * if end of extent overflows
  222.     addi    #16,d3
  223.     subq    #1,d2
  224.     bra    prnx00
  225. prnx01:    add    d3,fsize    * add overflow
  226.     moveq    #10,d0        * compare file names
  227.     move.l    a0,a2
  228.     move.l    a0,a3
  229.     add.l    #14,a3
  230. prnxt1:    cmpm.b    (a0)+,(a3)+
  231.     bne    prnxt2        * if no match
  232.     dbra    d0,prnxt1    * loop for 11 characters
  233.     move.l    a2,a0        * restore pointer to fcb
  234.     subq    #1,a1        * one less entry
  235.     add    #14,a0        * move to next fcb
  236.     bra    prnxt0
  237. *
  238. prnxt2:    addq    #1,fcount    * bump file count (names dont match)
  239.     move    fsize,d2    * totsiz=totsiz+fsiz
  240.     add    d2,totsiz
  241.     movea.l    #prbuf,a3
  242.     move.l    a2,a0        * restore pointer to fcb
  243.     move    (a0)+,(a3)+
  244.     move    (a0)+,(a3)+
  245.     move    (a0)+,(a3)+
  246.     move    (a0)+,(a3)+
  247.     addq    #1,a3
  248.     move.b    (a0)+,(a3)
  249.     move.b    (a3),fcb+1
  250.     bclr.b    #7,(a3)+
  251.     move.b    (a0)+,(a3)
  252.     move.b    (a3),fcb+2
  253.     bclr.b    #7,(a3)+
  254.     move.b    (a0)+,(a3)
  255.     move.b    (a3),fcb+3
  256.     bclr.b    #7,(a3)+
  257.     cmpi.b    #0,kflag
  258.     beq    prnxt3        * if size not wanted
  259.     move.l    a3,d0        * buffer
  260.     move    fsize,d1    * size in 128 byte recs
  261.     ext.l    d1
  262.     jsr    md5dc        * put number in buffer
  263.     move.l    d0,a3
  264.     move.b    #$20,(a3)+    * add blank
  265. *
  266. prnxt3:    cmpi.b    #0,fflag    * if no flags wanted
  267.     beq    prnxt7        * if no flags wanted
  268. *
  269.     move.l    #'    ',(a3)+    * second blank and flags
  270.     subq.l    #3,a3
  271.     move.l    #fcb+1,a4    * first ext. char
  272.     btst.b    #7,(a4)+    * check read-only flag
  273.     beq    prflg2        * nope, its r/w
  274.     move.b    #'R',(a3)
  275. prflg2:    addq.l    #1,a3
  276.     btst.b    #7,(a4)+
  277.     beq    prflg3        * not a system file either
  278.     move.b    #'S',(a3)
  279. prflg3:    addq.l    #1,a3
  280.     btst.b    #7,(a4)
  281.     beq    prflg4        * hasn't been archived
  282.     move.b    #'A',(a3)
  283. prflg4:    addq.l    #1,a3
  284.     move.b    #' ',(a3)+
  285.     move.b    #' ',(a3)+
  286. *
  287. *
  288. *
  289. prnxt7:    move.b    #$20,(a3)+    * add final blank
  290.     move.b    #$24,(a3)+    * add $ terminator
  291.     move.l    prbuf+2,d1
  292.     andi.l    #$7f7f7f7f,d1    * clear flags
  293.     move.l    d1,prbuf+2
  294. *
  295.     move.l    a2,a0        * restore pointer again
  296.     move.l    #prbuf,d1    * print file name
  297.     movem.l    a0-a1,-(a7)
  298.     jsr    sdout        * print to CON: or file
  299.     movem.l    (a7)+,a0-a1
  300.     move    nflin,d2    * at end-of-line?
  301.     addq    #1,d2
  302.     move    d2,nflin
  303.     cmp    fplin,d2
  304.     bne    prnxt8        * go get next one
  305. *
  306.     clr    nflin        * at EOL
  307.     bsr    crlfx
  308. *
  309. prnxt8:    add    #14,a0        * bump to next file
  310.     subq    #1,a1        * at end of files?
  311.     move.l    a1,d0
  312.     bne    prnxt        * not yet
  313. *
  314.     tst    nflin        * at end of line
  315.     beq    prnxt9        * yes, don't need crlf
  316.     bsr    crlfx        * one last cr lf
  317. *
  318. prnxt9:    move.b    fcb,d1
  319.     bne    pfm1        * if not default
  320.     move    curdsk,d1
  321.     addq    #1,d1
  322. pfm1:    subq    #1,d1
  323.     move    d1,-(a7)    * save disk
  324.     move    #$2e,d0
  325.     move.l    outbuf,d6    * save outbuf first word
  326.     trap    #2        * get free space
  327.     move.l    secb,d1        * free sectors
  328.     move.b    outfcb,d0
  329.     cmpi.b    #$ff,d0
  330.     beq    pfm2        * output to CON:
  331.     move.l    outbuf,d1    * the free space value was written
  332.     move.l    d6,outbuf    * to outbuf, not secb.
  333. pfm2:    ror.l    #3,d1        * convert to k
  334.     move.l    #mfre,d0
  335.     andi    #$7fff,d1
  336.     jsr    md5dc        * free space
  337. *
  338.     move    (a7)+,d0
  339.     addi.b    #'A',d0
  340.     move.b    d0,mdrun    * drive #
  341. *
  342.     move    #$20,d0
  343.     move.l    #$ff,d1
  344.     trap    #2        * get user number
  345.     move.l    d0,d1
  346.     move.l    #secb,d0
  347.     jsr    md5dc        * convert to text
  348.     move.b    secb+3,musrn    * and move last two digits
  349.     move.b    secb+4,musrn+1
  350. *
  351.     move.l    #mfsz,d0
  352.     move    totsiz,d1
  353.     ext.l    d1
  354.     jsr    md5dc        * total file size
  355. *
  356.     move.l    #mfcnt,d0
  357.     move    filcnt,d1
  358.     jsr    md5dc        * total # of files
  359. *
  360.     move.l    #endm,d1    * print ending msg
  361.     jsr    sdout        * print to CON: or file
  362.     move.b    outfcb,d0
  363.     cmpi.b    #$ff,d0
  364.     beq    pfm8        * CON: output, no problem
  365.     move.b    outbuf,d1
  366.     cmpi.b    #$1a,d1
  367.     beq    pfm6        * buffer is empty
  368.     move.l    #outfcb,d1
  369.     move    #$15,d0
  370.     trap    #2
  371.     tst.b    d0        * write o.k.?
  372.     bne    sdperr        * nope
  373. pfm6:    move.l    #outfcb,d1
  374.     move    #$10,d0
  375.     trap    #2        * close file
  376.     cmpi.b    #3,d0
  377.     bgt    sdperr        * error closing file
  378. pfm8:
  379. *
  380.     rts
  381. *
  382. *
  383. sdout:                * print (D1.L) to CON: or file
  384.     move.b    outfcb,d0
  385.     cmpi.b    #$ff,d0
  386.     bne    sdoutc        * not console output
  387.     moveq    #9,d0
  388.     trap    #2
  389.     rts
  390. *
  391. sdoutc:                * write is to a file
  392.     move.l    d1,a1        * pointer to msg
  393. sdotc1:    move.b    (a1)+,d0    * get char
  394.     cmpi.b    #'$',d0
  395.     beq    sdoutx        * if end of string
  396.     bsr    sdpout        * put char in d0.b
  397.     bra    sdotc1
  398. *
  399. sdoutx:    rts
  400. *
  401. sdpout:                * write char in d0.b to file
  402.     movem.l    a0-a1,-(a7)
  403.     move.l    outbfp,a0
  404.     move.b    d0,(a0)+
  405.     move.l    a0,outbfp
  406. *
  407.     cmpa.l    #outbuf+128,a0
  408.     beq    sdp2        * end of buffer
  409. sdpx:    movem.l    (a7)+,a0-a1
  410.     rts
  411. *
  412. sdp2:                * write buffer
  413.     move.l    #outbuf,outbfp
  414.     move.l    #outfcb,d1
  415.     moveq    #$15,d0        * write sequential
  416.     trap    #2
  417.     tst.b    d0
  418.     beq    sdp3        * good write
  419. sdperr:    move.l    #errwf,d1    * error writing file
  420.     moveq    #9,d0
  421.     trap    #2
  422.     bra    endjob
  423. *
  424. sdp3:                * clear new buffer
  425.     move.l    #outbuf,a0
  426.     move    #31,d0
  427. sdp4:    move.l    #$1a1a1a1a,(a0)+
  428.     dbra    d0,sdp4
  429.     bra    sdpx
  430. *
  431. *
  432. crlfx:    movem.l    a0-a1,-(a7)
  433.     move.l    #crstr,d1
  434.     bsr    sdout
  435.     movem.l    (a7)+,a0-a1
  436.     rts
  437. *
  438. *
  439.     .data
  440. fcb:    .dc.b    0,'????????????',0,0,0
  441.     .dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  442.     .dc.b    0,0,0,0
  443. outfcb:    .dc.b    0,'DIRLIST LIS',0,0,0,0
  444.     .dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  445.     .dc.b    0,0,0,0
  446. *
  447. mnofil:    .dc.b    cr,lf,'No files',cr,lf,'$',0
  448. errwf:    .dc.b    cr,lf,'  Error writing output file.',cr,lf,'$'
  449. *
  450. prbuf:    .dc.l    'xxxxxxxx.xxxnnnnn  ars   $'    * file name
  451. prbfe    equ    prbuf+9
  452. *
  453. crstr:    .dc.b    cr,lf,'$',0
  454. endm:    .dc.b    '    Drive '    * ending SD message
  455. mdrun:    .dc.b    'x, user '
  456. musrn:    .dc.b    'nn, contains'
  457. mfsz:    .dc.b    'nnnnnk in '
  458. mfcnt:    .dc.b    'nnnnn files with'
  459. mfre:    .dc.b    'nnnnnk free.',cr,lf,'$'
  460. *
  461. *
  462. bpage:    .dc.l    0        * base page address
  463. outbfp:    .dc.l    outbuf        * output buffer pointer
  464. curdsk:    .dc.w    0        * current default disk
  465. blm:    .dc.w    0        * block mask size
  466. exm:    .dc.w    0        * extent mask
  467. *
  468. ssbtbl:    .dc.l    table        * start of records
  469.     .dc.w    1        * number of records
  470.     .dc.w    14        * size of records
  471.     .dc.l    cmpa12        * compare ascending
  472.     .dc.l    0
  473.     .dc.b    0
  474.     .dc.b    0
  475. *
  476. **    options table
  477. *
  478. opttbl:    .dc.b    'F',0        * Flags
  479.     .dc.b    'K',1        * size
  480.     .dc.b    'S',0        * system files
  481.     .dc.b    0,0        * termination
  482. fflag:    .equ    opttbl+1    * flag print option
  483. kflag:    .equ    fflag+2        * size print option
  484. sflag:    .equ    kflag+2        * system file option
  485. *
  486. *
  487.     .bss
  488. tblcnt:    .ds.w    1        * table count
  489. filcnt:    .ds.w    1        * file count
  490. fcount    .equ    filcnt
  491. fplin:    .ds.w    1        * number of files per line
  492. nflin:    .ds.w    1        * number of files currently on line
  493. fsize:    .ds.w    1        * size of current file
  494. totsiz:    .ds.w    1        * total size of all files
  495. secb:    .ds.l    32        * sector buffer
  496. outbuf:    .ds.l    32        * output buffer
  497. tblptr:    .ds.l    1        * table pointer
  498. table:    .ds.l    13000        * actual file table (12 bytes/entry)
  499. *
  500. *
  501.     .end
  502.