home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / sampler0 / sdl32.asm < prev    next >
Assembly Source File  |  1988-08-16  |  25KB  |  1,003 lines

  1. page    80,132
  2. title    SDL 3.2 - Sorted Directory List
  3. sdl    segment
  4. sdlp    proc    far
  5.     assume    cs:sdl,ds:sdl,es:sdl
  6. ;
  7. ; SORTED DIRECTORY LIST 3.2
  8. ;
  9. ; SDL [d:][path][filename[.ext]][/options]
  10. ;
  11. ; Options:  General
  12. ;         E    erase screen
  13. ;         P    pause when screen full
  14. ;         W    4 column format (2 if width 40)
  15. ;        Sort options (sort on filename.ext is the default)
  16. ;         N    do not sort entries
  17. ;         S    sort by file size
  18. ;         D    sort by date and time
  19. ;         X    sort by file type (ext)
  20. ;        Sub-directories
  21. ;         T    list sub-directory names
  22. ;         F    use with T to list file names by directory
  23. ;         I    use with TF to indent file lists (not supported on
  24. ;            width 40 screens)
  25. ;         A    use with T to list all file names together
  26. ;
  27. ; Default:  *.* sorted by name.ext, 2 cols wide (1 on width 40 screen), no
  28. ;        screen erase or pause at end of page, using current directory.
  29. ;
  30. ; Notes:
  31. ;   1. Path specifications:
  32. ;      a. paths must end with \.
  33. ;      b. specifying a leading \ starts the path search at the root directory.
  34. ;      No leading \ will start the path at the current directory.
  35. ;      c. not specifying a path starts the operation at the current directory.
  36. ;   2. The space used by sub-directories is not accounted for.
  37. ;   3. Directory listings do not include the '.' or '..' entries.
  38. ;   4. The specified filename.ext may include ? and/or *.
  39. ;
  40. ; Output formats:  Width 80 - 2 or 4 columns   (option TFI - 1 or 2 columns)
  41. ;           Width 40 - 1 or 2 columns
  42. ;
  43. ; Filename in listing may be preceeded by one of the following char.:
  44. ;        r - read-only file
  45. ;        h - hidden file
  46. ;        s - system file
  47. ;        \ - sub-directory name
  48. ;   If a file has more than 1 attribute, only the last is shown.
  49. ;
  50. ; Written by W. C. Bodycomb
  51. ;        Version 1.0 - original version, runs under DOS 1.0 and 1.1
  52. ;        Version 2.0 - support for DOS 2.0, runs under DOS 1.0, 1.1, 2.0
  53. ;        Version 3.0 - support for paths and sub-directories, runs under
  54. ;              DOS 2.0.
  55. ;        Version 3.2 - Sort in descending order for date and file size 
  56. ;        options.  Make file extension ".*" by default.  Fix MASM 3 errors. 
  57. ;        Reversed test for 80 column display because some MS-DOS systems do 
  58. ;        not use the fixed address that PC-DOS does. Print the directory 
  59. ;        name instead of "<curr>". Ted Shapin, 11/21/85.
  60. ;
  61.     org    100h        ;set up for COM
  62. subp    proc    near
  63. ;
  64. ; get current or specified drive
  65. ;
  66. bgn:    call    clear        ;clear ctrs
  67.     cld            ;set direction
  68.     mov    si,offset init    ;init.
  69.     mov    di,offset dxfcb ;  the
  70.     mov    cx,19        ;    dummy
  71.     repz movsb        ;      FCB
  72.     mov    ah,19h        ;get
  73.     int    21h        ;  current
  74.     add    al,65        ;    disk
  75.     mov    si,offset path    ;      and
  76.     mov    [si],al     ;     save
  77.     mov    di,80h        ;get
  78.     mov    ch,0        ;  lth of
  79.     mov    cl,[di]     ;    of param
  80.     jcxz    vol1        ;br if no parms
  81.     inc    di        ;start of parms
  82.     mov    al,' '          ;scan off
  83.     repe scasb        ;  blanks
  84.     je    vol1        ;br if no parm
  85.     dec    di        ;adj
  86.     inc    cx        ;  values
  87.     cmp    cx,2        ;long enough
  88.     jb    vol1        ;br no
  89.     cmp    byte ptr [di]+1,':' ;is drive specified
  90.     jne    vol1        ;br no
  91.     mov    al,[di]     ;save
  92.     and    al,0dfh     ;  drive
  93.     mov    [si],al     ;    letter
  94.     inc    di        ;incr
  95.     inc    di        ;  adr
  96.     dec    cx        ;decr
  97.     dec    cx        ;  count
  98. ;
  99. ; get volume label
  100. ;
  101. vol1:    push    di        ;save
  102.     push    cx        ;  regs
  103.     mov    dx,offset da    ;set
  104.     mov    ah,1ah        ;  dta
  105.     int    21h        ;    adr
  106.     mov    al,[si]     ;put drive
  107.     mov    tia+9,al    ;  in header
  108.     sub    al,64        ;set
  109.     mov    byte ptr dfcb,al     ;  drive
  110.     mov    di,offset svvol ;save area
  111.     mov    ah,11h        ;set get first
  112.     mov    dx,offset dxfcb ;look for
  113.     int    21h        ;  vol label
  114.     or    al,al        ;any vol label
  115.     jnz    fpth        ;br no
  116.     mov    si,offset da+8    ;label adr
  117.     mov    cx,11        ;save
  118.     repz movsb        ;  label
  119. ;
  120. ; save specified path
  121. ;
  122. fpth:    mov    byte ptr [di],' ' ;mark end
  123.     pop    cx        ;restore
  124.     pop    di        ;  regs
  125.     jcxz    fopt1        ;br if no path/fnm
  126.     mov    dx,cx        ;save count
  127.     mov    bp,di        ;  and adr
  128.     add    di,cx        ;start
  129.     dec    di        ;  at
  130.     std            ;    end
  131.     mov    al,'\'          ;find end
  132.     repne scasb        ;  of path
  133.     cld            ;set direction
  134.     jne    fopt        ;br-not found
  135.     inc    cx        ;adj count
  136.     mov    si,bp        ;copy start adr
  137.     sub    dx,cx        ;save non-path lth
  138.     mov    di,offset path+2 ;move
  139.     repz movsb        ;  path
  140.     mov    fspca,di    ;save path end adr
  141.     mov    bp,si        ;set new start adr
  142. ;
  143. ; get options
  144. ;
  145. fopt:    mov    di,bp        ;get start adr
  146.     mov    cx,dx        ;  and lth
  147. fopt1:    jcxz    eopt        ;br-no options or filename
  148.     mov    al,'/'          ;find
  149.     repne scasb        ;  options
  150.     jne    gfspc        ;br-no options
  151.     dec    di        ;adj
  152.     inc    cx        ;  values
  153.     mov    si,di        ;copy adr
  154.     push    di        ;  and save
  155.     sub    dx,cx        ;save filespec size
  156. opt:    cmp    byte ptr [si],'/' ;is it /
  157.     je    opt3        ;keep looking
  158.     mov    al,byte ptr [si] ;get char
  159.     and    al,0dfh     ;force upper case
  160.     mov    di,offset swn    ;set adr
  161.     mov    bx,400h     ;  and flag
  162. opt1:    scasb            ;option found
  163.     je    opt2        ;br yes
  164.     shr    bx,1        ;check next
  165.     jnz    opt1        ;  option
  166.     jz    opt3        ;not valid option
  167. opt2:    or    word ptr sw,bx    ;set option
  168. opt3:    inc    si        ;check
  169.     loop    opt        ;  all char
  170.     pop    di        ;restore reg
  171. ;
  172. ; get specified filespec
  173. ;
  174. gfspc:    mov    byte ptr [di],' ' ;set delimiter
  175.     mov    cx,dx        ;get count
  176.     mov    si,bp        ;  and adr
  177.     jcxz    eopt        ;br-no filespec
  178.     cmp    byte ptr [si],' ' ;any filespec
  179.     je    eopt        ;br no
  180.     push    di        ;save end ptr
  181.     std    ;look for filename extension
  182.     mov    al,'.'        ;by scanning for
  183.     repne    scasb        ;a period
  184.     cld        ;reset to up
  185.     pop    di        ;restore pointer
  186.     je    gfspc2        ;we found one
  187.     mov    si,offset wild    ;point to ".*"
  188.     movsb        ;and move
  189.     movsb        ;it
  190.     mov    byte ptr [di],' ' ; add delimiter again
  191.     mov    si,bp        ;restore ptr to filespec
  192. gfspc2:    mov    di,offset dfcb    ;let DOS
  193.     mov    ax,2900h    ;  parse
  194.     int    21h        ;    filespec
  195. ;
  196. ; initialize options
  197. ;
  198. eopt:    mov    di,fspca    ;move dir.
  199.     call    mvfs        ;  filespec
  200.     test    byte ptr sw1,4        ;T option
  201.     jnz    eopt1        ;br yes
  202.     and    byte ptr sw1,0fch    ;clear A and F
  203. eopt1:    test    byte ptr sw1,1        ;A option
  204.     jz    eopt2        ;br no
  205.     and    byte ptr sw1,0fdh    ;clear F option
  206.     mov    cx,19        ;set count
  207.     mov    si,offset dirm    ;change
  208.     mov    di,offset h2+25 ;  hdrs
  209.     repz movsb        ;    to dir#
  210. eopt2:    test    byte ptr sw,8        ;wide
  211.     jz    eopt3        ;br no
  212.     mov    coln,4        ;set cols to 4
  213.     mov    si,offset h3    ;hdr adr
  214.     mov    di,offset h2+15 ;change
  215.     mov    cx,5        ;  bytes to
  216.     repz movsb        ;    sector
  217. eopt3:    push    ds        ;save data segment
  218.     mov    ax,40h        ;point to
  219.     mov    ds,ax        ;  data area
  220.     mov    ax,ds:4ah    ;get screen cols
  221.     pop    ds        ;restore data segment
  222.     cmp    ax,40        ;40 col
  223.     jne    eopt4        ;br no
  224.     or    byte ptr sw1,128     ;set 40 col
  225.     shr    coln,1        ;cols
  226.     jnz    fa        ;  /2
  227. eopt4:    test    byte ptr sw1,2        ;option F
  228.     jz    fa        ;br no
  229.     test    byte ptr sw,1        ;I option
  230.     jz    fa        ;br no
  231.     shr    coln,1        ;cols/2
  232.     mov    colp,40     ;set offset
  233. ;
  234. ; get FAT info
  235. ;
  236. fa:    mov    dl,path     ;get
  237.     sub    dl,64        ;  drive no
  238.     mov    ah,36h        ;get DOS 2
  239.     int    21h        ;  fat info
  240.     cmp    ax,0ffffh    ;br if
  241.     jne    fa1        ;  drive ok
  242.     int    20h        ;give up
  243. fa1:    mov    word ptr bpsc,cx     ;save bytes/sec
  244.     mov    ah,0        ;clear high byte
  245.     mov    word ptr scpf,ax     ;save sec/fat
  246.     xchg    cx,dx        ;find bytes per
  247.     mul    dx        ;  alloc. unit
  248.     mul    bx        ;free bytes
  249.     mov    word ptr free,ax     ;save low
  250.     mov    word ptr free+2,dx    ;  and high
  251. ;
  252. ; clear screen
  253. ;
  254. clr:    test    byte ptr sw,128        ;screen clear
  255.     jz    sdlh        ;br no
  256.     sub    cx,cx        ;col 0, row 0
  257.     mov    dx,184fh    ;last row, col
  258.     test    byte ptr sw1,128     ;80 cols
  259.     jz    clr1        ;br yes
  260.     mov    dx,1827h    ;set 40 col
  261. clr1:    mov    bh,7        ;color
  262.     mov    ax,600h     ;scroll
  263.     int    10h        ;  screen
  264.     sub    dx,dx        ;set
  265.     mov    ah,2        ;  cursor
  266.     mov    bh,0        ;    to
  267.     int    10h        ;      0
  268. ;
  269. ; print SDL header
  270. ;
  271. sdlh:    mov    dx,offset h1    ;print
  272.     call    prt        ;  header
  273.     mov    si,offset svvol ;label adr
  274. sdlh1:    lodsb            ;get char
  275.     cmp    al,' '          ;end of label
  276.     je    sdlh2        ;br yes
  277.     mov    dl,al        ;print
  278.     call    prtc        ;  char
  279.     jmp    sdlh1        ;next char
  280. sdlh2:    mov    ah,2ah        ;get
  281.     int    21h        ;  date
  282.     mov    si,offset mth    ;field start
  283.     mov    al,dh        ;convert
  284.     call    x2        ;  month
  285.     mov    al,dl        ;convert
  286.     call    x2        ;  day
  287.     mov    ax,cx        ;adjust
  288.     sub    ax,1900     ;  year
  289.     call    x2        ;convert year
  290.     mov    ah,2ch        ;get
  291.     int    21h        ;  time
  292.     mov    si,offset ti    ;field start
  293.     mov    al,ch        ;convert
  294.     call    x2        ;  hour
  295.     mov    al,cl        ;convert
  296.     call    x2        ;  minutes
  297.     mov    dx,offset h1evl ;print
  298.     call    prt        ;  hdr
  299.     test    byte ptr sw1,128     ;width 40
  300.     jz    sdlh3        ;br no
  301.     call    ckpg        ;print cr
  302. sdlh3:    mov    dx,offset h1a    ;print
  303.     call    prt        ;  hdr
  304.     mov    si,word ptr free     ;convert
  305.     mov    di,word ptr free+2    ;  free
  306.     call    w0        ;    bytes
  307.     mov    dx,offset h1b    ;print
  308.     call    prt        ;  hdr
  309. ; Note: DOS 4.0 and disks larger than 32 megabytes gives overflow
  310. ; so sectors are not printed.
  311. ;    mov    ax,word ptr free     ;convert
  312. ;    mov    dx,word ptr free+2    ;  free
  313. ;    call    v0        ;    sectors
  314. ;    call    v3        ;      and print
  315. ;    mov    dx,offset h1c    ;print
  316. ;    call    prt        ;  hdr
  317.     call    ckpg        ;print cr
  318.     call    ckpg        ;print cr
  319.     mov    mtha+8,'$'      ;set end of field
  320.     mov    tia+5,'$'       ;set end of field
  321.     test    byte ptr sw1,4        ;T option
  322.     jnz    tinit        ;br yes
  323. ;
  324. ; list one directory
  325. ;
  326.     call    prtb        ;print a blank
  327.     call    dirnam        ;print the dir name
  328.     call    prtcr        ;and a CRLF
  329.     call    dir        ;get directory
  330.     call    sr        ;process entries
  331.     jmp    return        ;all done
  332. ;
  333. ; get current directory full name and print it
  334. ;
  335. dirnam:    mov    ah,47h        ;get name of current directory
  336.     mov    dl,byte ptr path    ;has the disk drive
  337.     and    dl,0fh        ;mask off binary part
  338.     mov    si,nx        ;put it in the table area
  339.     int    21h
  340.     mov    di,nx        ;point to the name
  341.     mov    cx,64        ;max possible name length
  342.     mov    al,0        ;look for the end
  343.     repne    scasb        ;of the string
  344.     dec    di        ;and change the
  345.     mov    byte ptr [di],'$' ;delimiter
  346.     mov    dx,nx        ;and then print
  347.     call    prt        ;the dir name
  348.     ret        ;return
  349. ;
  350. ; initialize for sub-directories
  351. ;
  352. tinit:    mov    di,fspca    ;get fspec adr
  353.     mov    si,offset path+2 ;path adr
  354.     cmp    byte ptr [si],'\' ;start at root
  355.     je    tinit1        ;br yes
  356.     push    si        ;save 
  357.     push    di        ;regs
  358.     call    dirnam        ;print current dir name
  359.     pop    di        ;restore
  360.     pop    si        ;regs
  361.     cmp    si,di        ;any path
  362.     je    tinit3        ;br no
  363. tinit1: mov    dl,byte ptr [si] ;get path byte
  364.     cmp    dl,61h        ;force
  365.     jb    tinit2        ;  upper
  366.     sub    dl,20h        ;    case
  367. tinit2: call    prtc        ;print
  368.     inc    si        ;  name
  369.     cmp    si,di        ;end of path
  370.     jb    tinit1        ;br no
  371. tinit3: test    byte ptr sw1,1        ;option A
  372.     jz    tinit4        ;br no
  373.     push    di        ;save reg
  374.     xor    si,si        ;print
  375.     call    v3        ;  dir no
  376.     pop    di        ;restore reg
  377. tinit4: call    ckpg        ;print cr
  378.     jmp    tre7        ;get 1st dir
  379. ;
  380. ; list sub-directories
  381. ;
  382. tre:    test    byte ptr [si]+15,16 ;sub-dir
  383.     jnz    tre2        ;br yes
  384. tre1:    add    si,26        ;next entry
  385.     cmp    si,[di]+10    ;end of dir
  386.     jb    tre        ;br no
  387.     cmp    word ptr [di]+6,0 ;any previous dir.
  388.     je    tred        ;br no
  389.     mov    di,[di]+6    ;prev dir.
  390.     mov    prvt,di     ;save adr
  391.     mov    si,[di]+8    ;curr. entry
  392.     sub    col,2        ;decr col
  393.     jnz    tre1        ;step to next
  394. tre2:    mov    cx,[di]+4    ;space
  395. tre3:    call    prtb        ;  to
  396.     loop    tre3        ;    col
  397.     mov    [di]+8,si    ;save curr entry
  398.     inc    dirn        ;incr dir no
  399.     inc    si        ;step to
  400.     inc    si        ;  filename
  401.     mov    cx,12        ;print
  402.     mov    di,[di]+2    ;  sub
  403. tre4:    lodsb            ;    dir
  404.     cmp    al,' '          ;blank
  405.     je    tre5        ;br yes
  406.     stosb            ;move char
  407.     mov    dl,al        ;print
  408.     call    prtc        ;  char
  409. tre5:    loop    tre4        ;next char
  410.     test    byte ptr sw1,1        ;A option
  411.     jz    tre6        ;br no
  412.     mov    si,dirn     ;print
  413.     push    di        ;  out
  414.     call    v3        ;    dir
  415.     pop    di        ;      no.
  416. tre6:    call    ckpg        ;print cr
  417.     mov    byte ptr [di],'\' ;end
  418.     inc    di        ;  path
  419.     mov    fspca,di    ;save adr
  420. tre7:    call    mvfs        ;move fspec
  421.     add    col,2        ;incr col
  422.     call    dir        ;get directory
  423.     test    byte ptr sw1,2        ;F option
  424.     jz    tre        ;br no
  425.     push    si        ;save
  426.     push    di        ;  regs
  427.     call    sr        ;process entries
  428.     pop    di        ;restore
  429.     pop    si        ;  regs
  430.     jmp    tre        ;process table
  431. tred:    test    byte ptr sw1,1        ;A option
  432.     jz    return        ;br no
  433.     mov    di,offset tb    ;table start
  434.     call    sr        ;process entries
  435. return: call    ckpg1        ;allow for DOS cr
  436.     int    20h        ;all done
  437. ;
  438. ; get directory entries and build table
  439. ;
  440. dir:    mov    di,nx        ;get
  441.     push    di        ;  start
  442.     add    di,26        ;save
  443.     mov    nx,di        ;  end
  444.     pop    di        ;restore
  445.     push    di        ;  start
  446.     inc    di        ;+
  447.     inc    di        ;  2
  448.     mov    si,offset fspca ;set up
  449.     mov    cx,3        ;  fspec adr, col
  450.     repz movsw        ;    and prev table
  451.     pop    di        ;restore
  452.     push    di        ;  start
  453.     mov    byte ptr [di]+15,8 ;mark control
  454.     mov    prvt,di     ;save as prev
  455.     mov    [di]+8,di    ; and curr sub-dir
  456.     mov    ah,4eh        ;get 1st
  457. dir1:    mov    cx,16h        ;get
  458.     mov    dx,offset path    ;  directory
  459.     int    21h        ;    entry
  460.     or    al,al        ;br if entry
  461.     jz    dir2        ;  found
  462.     mov    ax,nx        ;save
  463.     pop    si        ;  tbl
  464.     mov    [si]+10,ax    ;    end
  465.     mov    di,si        ;copy table adr
  466.     ret            ;return
  467. dir2:    cmp    byte ptr dan,'.' ;path
  468.     je    dir6        ;br yes
  469.     mov    bx,nx        ;set next
  470.     lea    di,[bx+2]    ;  entry adr
  471.     push    di        ;save reg
  472.     push    di        ;  twice
  473.     mov    si,offset blnk    ;blanks
  474.     mov    cx,13        ;blank$
  475.     repz movsb        ;  fname
  476.     pop    di        ;restore reg
  477.     mov    si,offset dan    ;returned fn adr
  478. dir3:    cmp    byte ptr [si],0 ;end of name
  479.     je    dir5        ;br yes
  480.     cmp    byte ptr [si],'.' ;separator
  481.     jne    dir4        ;br no
  482.     lea    di,[bx+2]    ;position
  483.     add    di,8        ;  file type
  484. dir4:    movsb            ;move char
  485.     jmp    dir3        ;repeat
  486. dir5:    pop    di        ;restore reg
  487.     add    di,13        ;re-position
  488.     mov    si,offset daa    ;save
  489.     movsb            ;  attribute
  490.     movsw            ;save time
  491.     movsw            ;  and date
  492.     movsw            ;move file
  493.     movsw            ;  size
  494.     mov    si,offset dirn    ;move
  495.     movsw            ;  dir. no
  496.     inc    word ptr ct    ;incr file count
  497.     mov    nx,di        ;incr table adr
  498.     cmp    di,sp        ;more
  499.     jb    dir6        ;  room
  500.     mov    dx,offset max    ;print
  501.     call    prt        ;  msg
  502.     int    20h        ;give up
  503. dir6:    mov    ah,4fh        ;get next
  504.     jmp    dir1        ;  directory entry
  505. ;
  506. ; insertion sort
  507. ;
  508. sr:    cmp    di,nx        ;more entries
  509.     jb    sr1        ;br yes
  510.     jmp    dcl        ;set up columns
  511. sr1:    test    byte ptr [di]+15,8 ;control entry
  512.     jnz    sr2        ;br yes
  513.     mov    bp,di        ;save reg
  514.     lea    si,[di+2]    ;compare
  515.     mov    di,offset fspc    ;  dir
  516.     mov    cx,8        ;    entry
  517.     call    cknm        ;check
  518.     jcxz    sr3        ;  filename
  519. sr2:    jmp    snx        ;skip entry
  520. sr3:    inc    si        ;step over .
  521.     mov    cx,3        ;check
  522.     call    cknm        ;  ext
  523.     jcxz    sr4        ;br ok
  524.     jmp    snx        ;skip entry
  525. sr4:    mov    di,bp        ;restore reg
  526.     mov    si,offset t1    ;start of chain
  527. sr5:    mov    bx,si        ;get next
  528.     mov    si,[bx]     ;  chain entry
  529.     or    si,si        ;br if end
  530.     jz    sch        ;  of chain
  531.     test    byte ptr sw,4        ;no sorting
  532.     jnz    sr5        ;br yes
  533.     mov    ax,si        ;save
  534.     mov    dx,di        ;  adrs
  535.     mov    bp,22        ;size offset
  536.     test    byte ptr sw,64        ;sort size
  537.     jnz    sz        ;br yes
  538.     mov    bp,18        ;date offset
  539.     test    byte ptr sw,32        ;sort date
  540.     jnz    sz        ;br yes
  541.     test    byte ptr sw,16        ;sort type
  542.     jnz    sx        ;br yes
  543. sn:    mov    bp,2        ;compare
  544.     mov    cx,8        ;  file
  545.     call    ssn        ;    names
  546.     jb    sr5        ;try again
  547.     ja    sch        ;chain in entry
  548.     test    byte ptr sw,16        ;type sort
  549.     jnz    sr5        ;br yes
  550.     call    ssx        ;compare file types
  551.     jbe    sr5        ;try again
  552.     jg    sch        ;chain in entry
  553. sx:    call    ssx        ;compare
  554.     jb    sr5
  555.     jmp    sz1        ;  file type
  556. sz:    add    si,bp        ;compare
  557.     add    di,bp        ;  the
  558.     mov    cx,2        ;    size
  559.     std            ;      or
  560.     repz cmpsw        ;     date
  561.     cld            ;restore direction
  562.     mov    di,dx        ;restore
  563.     mov    si,ax        ;  regs
  564.     ja    sr5        ;try again
  565. sz1:    je    sn        ;check name
  566. sch:    mov    [di],si     ;chain in
  567.     mov    [bx],di     ;  entry
  568. snx:    add    di,26        ;check next
  569.     jmp    sr        ;  entry
  570. ;
  571. ; sort file name or type sub-rout.
  572. ;
  573. ssx:    mov    bp,11        ;type offset
  574.     mov    cx,3        ;  and lth
  575. ssn:    add    si,bp        ;sort
  576.     add    di,bp        ;  file name
  577.     repz cmpsb        ;    or type
  578.     mov    di,dx        ;restore
  579.     mov    si,ax        ;  regs
  580.     ret            ;return
  581. ;
  582. ; set up columns
  583. ;
  584. dcl:    mov    ax,word ptr ct        ;# of files
  585.     cmp    ax,0        ;any entries
  586.     je    dcl4        ;br no
  587.     cmp    coln,1        ;only 1 col
  588.     je    hr        ;br yes
  589.     cmp    ax,2        ;0 or 1
  590.     jb    hr        ;br yes
  591.     xor    dx,dx        ;clear reg
  592.     div    coln        ;/# of cols
  593.     mov    word ptr fcrm,dx     ;save remainder
  594.     mov    bp,1        ;set col ctr
  595.     mov    si,offset t1    ;1st chain
  596. dcl1:    mov    bx,si        ;copy adr
  597.     call    dcl2        ;get 1 col entries
  598.     dec    si        ;next col
  599.     dec    si        ;  adr
  600.     mov    [si],dx     ;save start of next chain
  601.     inc    bp        ;incr col ctr
  602.     cmp    bp,coln     ;done
  603.     jb    dcl1        ;br no
  604.     jge    hr        ;print header
  605. dcl2:    mov    cx,ax        ;copy count
  606.     cmp    bp,word ptr fcrm     ;need 1 more
  607.     ja    dcl3        ;br no
  608.     inc    cx        ;add 1 more
  609. dcl3:    mov    bx,[bx]     ;count out
  610.     loop    dcl3        ;  entries for col
  611.     mov    dx,[bx]     ;start of next chain
  612.     mov    [bx],cx     ;end this chain
  613. dcl4:    ret            ;return
  614. ;
  615. ; print file headers
  616. ;
  617. hr:    call    fsp        ;option F spacing
  618.     mov    cx,coln     ;# of cols
  619.     jmp    hr2        ;skip blank
  620. hr1:    call    prtb        ;blank
  621. hr2:    mov    dx,offset h2    ;hdr adr
  622.     call    prt        ;print hdr
  623.     loop    hr1        ;do all cols
  624.     call    ckpg        ;print cr
  625. ;
  626. ; process table entries
  627. ;
  628. pr:    mov    bp,coln     ;# of cols
  629.     mov    si,offset t1    ;1st col adr
  630.     cmp    word ptr [si],0 ;end of entries
  631.     je    trlr        ;br yes
  632. pr1:    call    fsp        ;option F
  633.     jcxz    pr3        ;  spacing
  634. pr2:    call    prtb        ;blank
  635. pr3:    mov    bx,[si]     ;next in chain
  636.     or    bx,bx        ;end of chain
  637.     jz    pr4        ;br yes
  638.     mov    ax,[bx]     ;save next
  639.     mov    [si],ax     ;  in chain
  640.     push    si        ;save reg
  641.     call    pf        ;process entry
  642.     pop    si        ;restore reg
  643.     dec    si        ;next
  644.     dec    si        ;  col
  645.     dec    bp        ;decr
  646.     jnz    pr2        ;do next chain
  647. pr4:    call    ckpg        ;print cr
  648.     jmp    pr        ;repeat to end of 1st chain
  649. ;
  650. ; print no. of files
  651. ;
  652. trlr:    call    fsp        ;option F
  653.     mov    si,word ptr ct        ;convert file
  654.     call    v3        ;  count
  655.     mov    dx,offset h1d    ;print
  656.     call    prt        ;  hdr
  657.     mov    si,word ptr dused    ;convert
  658.     mov    di,word ptr dused+2    ;  used
  659.     call    w0        ;    bytes
  660.     mov    dx,offset h1b    ;print
  661.     call    prt        ;  hdr
  662.     mov    si,word ptr sused    ;convert
  663.     call    v3        ;    sectors
  664.     call    clear        ;clear ctrs
  665.     mov    dx,offset h1c    ;print
  666.     call    prt        ;  hdr
  667.     jmp    ckpg        ;print cr
  668. ;
  669. ; print file entry
  670. ;
  671. pf:    mov    cx,4        ;set count
  672.     mov    dl,' '          ;blank
  673.     mov    di,offset atr    ;attr table
  674. pf1:    mov    al,byte ptr [di] ;test
  675.     inc    di        ;  for
  676.     test    byte ptr [bx+15],al ;attr
  677.     jz    pf2        ;br no
  678.     mov    dl,byte ptr [di] ;get
  679. pf2:    inc    di        ;  attr
  680.     loop    pf1        ;try again
  681.     call    prtc        ;print attr
  682.     lea    di,[bx+2]    ;file name adr
  683.     mov    cx,12        ;print
  684. pfn:    mov    dl,byte ptr [di] ; file
  685.     call    prtc        ;    name
  686.     inc    di        ;      and
  687.     loop    pfn        ;     ext
  688.     clc            ;clear carry
  689.     mov    ax,[bx+20]    ;sum
  690.     add    word ptr dused,ax    ;  up
  691.     mov    dx,[bx+22]    ;    file
  692.     adc    word ptr dused+2,dx    ;      sizes
  693.     call    v0        ;get sectors
  694.     add    word ptr sused,si    ;add to sum
  695.     test    byte ptr sw,8        ;wide
  696.     jz    pf5        ;br no
  697.     test    byte ptr sw1,1        ;option A
  698.     jz    pf3        ;br no
  699.     mov    si,[bx+24]    ;print
  700.     call    v3        ;  dir#
  701.     jmp    prtb        ;blank
  702. pf3:    test    byte ptr [bx+15],16 ;sub-dir
  703.     jz    pf4        ;br no
  704.     mov    dx,offset b8+2    ;print
  705.     jmp    prt        ;  blanks
  706. pf4:    call    v3        ;convert sectors
  707.     jmp    prtb        ;blank
  708. pf5:    test    byte ptr [bx+15],16 ;sub-dir
  709.     jz    pf6        ;br no
  710.     mov    dx,offset b8    ;print
  711.     call    prt        ;  blanks
  712.     jmp    pf7        ;skip size
  713. pf6:    push    bx        ;save reg
  714.     mov    si,[bx+20]    ;convert
  715.     mov    di,[bx+22]    ;  file
  716.     call    w0        ;    size
  717.     pop    bx        ;restore reg
  718. pf7:    call    prt2b        ;2 blank
  719.     mov    ax,[bx+18]    ;convert
  720.     call    x0        ;  date
  721.     call    prtb        ;blank
  722.     test    byte ptr sw1,1        ;option A
  723.     jz    pf8        ;br no
  724.     mov    si,[bx+24]    ;print
  725.     call    v3        ;  dir#
  726.     jmp    prt2b        ;2 blanks
  727. pf8:    mov    ax,[bx+16]    ;convert
  728.     call    y0        ;  time
  729.     jmp    prt2b        ;2 blank
  730. ;
  731. ; convert bytes to sectors
  732. ;
  733. v0:    div    word ptr bpsc        ;bytes/sector
  734.     or    dx,dx        ;any remainder
  735.     jz    v1        ;br no
  736.     inc    ax        ;add 1 sector
  737. v1:    xor    dx,dx        ;clear reg
  738.     div    word ptr scpf        ;/ by sec/fat
  739.     or    dx,dx        ;any remainder
  740.     jz    v2        ;br no
  741.     inc    ax        ;add 1 fat
  742. v2:    mul    word ptr scpf        ;find no. of sectors
  743.     mov    si,ax        ;copy value
  744.     ret            ;return
  745. v3:    xor    di,di        ;clear reg
  746.     call    sum        ;convert to BCD
  747.     mov    cx,1410h    ;left zero supp. for 4 digits
  748.     mov    dl,al        ;convert
  749.     call    w3        ;  one digit
  750.     mov    ax,bx        ;convert
  751.     jmp    w1        ;  4 digits
  752. ;
  753. ; convert file size
  754. ;
  755. w0:    call    sum        ;convert to BCD
  756.     mov    cx,1710h    ;left zero supp. for 7 digits
  757.     call    w1        ;convert 4
  758.     mov    ax,bx        ;last 4
  759. w1:    push    ax        ;save reg
  760.     mov    dl,ah        ;convert
  761.     call    w2        ;  left 2
  762.     pop    dx        ;convert right 2
  763. w2:    mov    dh,dl        ;save right digit
  764.     shr    dl,1        ;shift
  765.     shr    dl,1        ;  over
  766.     shr    dl,1        ;    left
  767.     shr    dl,1        ;      digit
  768.     call    w3        ;print digit
  769.     mov    dl,dh        ;convert right digit
  770. w3:    and    dl,0fh        ;isolate digit
  771.     jz    w4        ;br if 0
  772.     mov    cl,0        ;kill zero suppress
  773. w4:    dec    ch        ;zero
  774.     and    cl,ch        ;  suppress
  775.     or    dl,'0'          ;convert to
  776.     sub    dl,cl        ;  digit
  777.     jnz    prtc        ;    or blank
  778. prt2b:    call    prtb        ;print 2 blanks
  779. prtb:    mov    dl,' '          ;print blank
  780. prtc:    mov    ah,2        ;print
  781.     int    21h        ;  char
  782.     ret            ;return
  783. ;
  784. ; convert to 8 BCD digits
  785. ;
  786. sum:    xor    ax,ax        ;clear
  787.     mov    bx,ax        ;  regs
  788.     mov    cx,32        ;set dble word shift
  789. sum1:    shl    si,1        ;shift
  790.     rcl    di,1        ;  dble word
  791.     xchg    bx,ax        ;double
  792.     call    sum2        ;  all
  793.     xchg    bx,ax        ;    and add
  794.     call    sum2        ;      in
  795.     loop    sum1        ;     bit
  796.     ret            ;return
  797. sum2:    adc    al,al        ;double
  798.     daa            ;  each
  799.     xchg    al,ah        ;    digit
  800.     adc    al,al        ;      in
  801.     daa            ;     word
  802.     xchg    al,ah        ;       accumulator
  803.     ret            ;return
  804. ;
  805. ; convert time
  806. ;
  807. y0:    mov    dx,offset b8+3    ;blanks
  808.     or    ax,ax        ;any time
  809.     jz    prt        ;br no
  810.     mov    si,offset tia    ;field start
  811.     push    ax        ;save time
  812.     and    ax,0f800h    ;isolate
  813.     mov    cl,11        ;  hours
  814.     call    x1        ;convert hours
  815.     pop    ax        ;restore time
  816.     and    ax,7e0h     ;isolate
  817.     mov    cl,5        ;  minutes
  818.     call    x1        ;convert minutes
  819.     mov    dx,offset tia    ;print
  820.     jmp    prt        ;  time
  821. ;
  822. ; convert date
  823. ;
  824. x0:    mov    dx,offset b8    ;blanks
  825.     or    ax,ax        ;is date 0
  826.     jz    prt        ;br yes
  827.     mov    si,offset mth    ;field start
  828.     push    ax        ;save date
  829.     and    ax,1e0h     ;isolate
  830.     mov    cl,5        ;  month
  831.     call    x1        ;convert
  832.     pop    ax        ;get and
  833.     push    ax        ;  save date
  834.     and    ax,1fh        ;convert
  835.     call    x2        ;  day
  836.     pop    ax        ;restore date
  837.     and    ax,0fe00h    ;isolate and
  838.     mov    cl,9        ;  position
  839.     shr    ax,cl        ;    year
  840.     add    ax,80        ;add 80
  841.     call    x2        ;convert year
  842.     mov    dx,offset mth    ;print
  843.     jmp    prt        ;  date
  844. x1:    shr    ax,cl        ;position
  845. x2:    aam            ;convert
  846.     or    ax,'00'         ;  2 digits
  847.     xchg    al,ah        ;add to
  848.     mov    [si],ax     ;  field
  849.     add    si,3        ;next field
  850.     ret            ;return
  851. ;
  852. ; check for end of page
  853. ;
  854. ckpg:    call    prtcr        ;print cr
  855. ckpg1:    test    byte ptr sw,2        ;pause option
  856.     jz    fsp2        ;br no
  857.     dec    lct        ;decr line count
  858.     jnz    fsp2        ;br if not end of page
  859.     mov    lct,24        ;reset line count
  860.     mov    dx,offset wait    ;print
  861.     call    prt        ;  pause
  862.     mov    al,8        ;wait
  863.     mov    ah,0ch        ;  for
  864.     int    21h        ;    key
  865. prtcr:    mov    dx,offset cr    ;print cr
  866. prt:    mov    ah,9        ;print
  867.     int    21h        ;  routine
  868.     ret            ;return
  869. ;
  870. ; space for option F
  871. ;
  872. fsp:    mov    cx,colp     ;offset
  873.     jcxz    fsp2        ;  cols
  874. fsp1:    call    prtb        ;    for
  875.     loop    fsp1        ;      option
  876. fsp2:    ret            ;     F
  877. ;
  878. ; move directory file spec
  879. ;
  880. mvfs:    push    cx        ;save
  881.     push    si        ;  regs
  882.     mov    cx,4        ;move
  883.     mov    si,offset dfspc ;  file
  884.     repz movsb        ;    spec
  885.     pop    si        ;restore
  886.     pop    cx        ;  regs
  887.     ret            ;return
  888. ;
  889. ; match directory entry against specified filespec
  890. ;
  891. cknm:    cmp    byte ptr [di],'?' ;any char
  892.     je    cknm1        ;br yes
  893.     cmpsb            ;char match
  894.     je    cknm2        ;br yes
  895.     dec    word ptr ct    ;decr count
  896.     mov    di,bp        ;restore reg
  897.     ret            ;return
  898. cknm1:    cmpsb            ;step pointers
  899. cknm2:    loop    cknm        ;check next char
  900.     ret            ;return
  901. ;
  902. ; clear counters
  903. ;
  904. clear:    mov    cx,8        ;clear
  905.     mov    di,offset ct    ;  all
  906.     xor    ax,ax        ;    the
  907.     repz    stosw        ;      counters
  908.     ret            ;return
  909. ;
  910. ; work area
  911. ;
  912. nx    dw    tb        ;adr of table
  913. coln    dw    2        ;# of cols
  914. lct    dw    24        ;line count
  915. sw    db    0        ;options
  916. ;                   128-erase screen
  917. ;                    64-sort by size
  918. ;                    32-sort by date
  919. ;                    16-sort by file ext
  920. ;                     8-4 col. format
  921. ;                     4-no sort
  922. ;                     2-pause at page end
  923. ;                     1-indent
  924. sw1    db    0        ;options
  925. ;                   128-width 40 screen
  926. ;                    64-not used
  927. ;                    32-not used
  928. ;                    16-not used
  929. ;                     8-not used
  930. ;                     4-option T
  931. ;                     2-option F
  932. ;                     1-option A
  933. swn    db    'TFAESDXWNPI'   ;option letters
  934. blnk    db    '    '          ;blanks
  935. b8    db    '        $'
  936. wait    db    'more...$'
  937. max    db    'Max Stor$'
  938. h1    db    'SDL-3.2 $'
  939. h1evl    db    ' '
  940. mth    label    word
  941. mtha    db    '00/00/00 '
  942. ti    label    word
  943. tia    db    '00:00 Dr @$'
  944. h1a    db    '  Free Space: $'
  945. h1b    db    ' Bytes $'
  946. h1c    db    ' Sec.$'
  947. cr    db    13,10,'$'
  948. h1d    db    ' Files, $'
  949. h2    db    ' Filename.Ext   Bytes    Last Update   $'
  950. h3    db    'Sec.$'
  951. dirm    db    'Date    Dir#  $Dir#'
  952. atr    db    1,'r',2,'h',4,'s',16,'\'
  953. init    db    0ffh,5 dup(0),8 ;dummy extended fcb
  954.     db    ' '             ;dummy fcb
  955.     db    11 dup('?')     ;default filespec
  956. dfspc    db    '*.*',0         ;read dir. filespec
  957. wild    equ    $-3        ;use ".*" when no extension is given
  958. fspca    dw    path+2        ;fspec adr in path
  959. col    dw    1        ;col offset
  960. prvt    dw    0        ;prev tbl adr
  961. dirn    dw    0        ;dir no.
  962. colp    dw    0        ;opt F col spacing
  963. path    db    ' :\*.*',0      ;drive and root/filespec
  964. ; use equates to decrease the size of the COM module
  965. xpath    equ    $        ;64-path
  966. da    equ    $+64        ;21-DTA, DOS use
  967. daa    equ    da+21        ;1-file attributes
  968. das    equ    daa+1        ;8-file time, date, and size
  969. dan    equ    das+8        ;13-file name
  970. free    equ    dan+13        ;4-free space
  971. fcrm    equ    free+4        ;2-rem.-files/cols
  972. bpsc    equ    fcrm+2        ;2-bytes/sec
  973. scpf    equ    bpsc+2        ;2-sectors/fat
  974. ct    equ    scpf+2        ;2-file count
  975. dused    equ    ct+2        ;4-bytes used by files in dir.
  976. sused    equ    dused+4     ;2-sec used by files in dir.
  977. t4    equ    sused+2     ;6-4th, 3rd, 2nd chain
  978. t1    equ    t4+6        ;2-1st chain
  979. svvol    equ    t1+2        ;12-label save area
  980. dxfcb    equ    svvol+12    ;7-dummy extended fcb
  981. dfcb    equ    dxfcb+7     ;1-dummy fcb
  982. fspc    equ    dfcb+1        ;36-default filespec
  983. tb    equ    fspc+36     ;start of table
  984. ;   control: 2-not used   normal: 2-chain adr
  985. ;offset +2   2-fspec adr      12-filename.ext
  986. ;     4   2-column offset
  987. ;     6   2-prev. tbl adr
  988. ;     8   2-curr sub-dir adr
  989. ;    10   2-table end adr
  990. ;    12   2-not used
  991. ;    14   1-not used       1-end of filename ($)
  992. ;    15   1-attribute/switch   1-attribute/switch
  993. ;           8-control entry        8-control entry
  994. ;    16   2-not used       2-time
  995. ;    18   2-not used       2-date
  996. ;    20   4-not used       4-file size
  997. ;    24   2-not used       2-dir # (TA option)
  998. subp    endp
  999. sdlp    endp
  1000. sdl    ends
  1001.     end    bgn
  1002.  
  1003.