home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol145 / sd1.a86 < prev    next >
Text File  |  1984-04-29  |  15KB  |  682 lines

  1. ;
  2. ;            SD1.A86
  3. ;          (revised 15/Mar/83)
  4. ;
  5. ;        SUPER DIRECTORY PROGRAM
  6. ;          by Bruce R. Ratoff
  7. ;
  8. ;Displays the directory of a CP/M disk, sorted alphabetically,
  9. ;with the file size in K, rounded to the nearest CP/M block size.
  10. ;
  11. ;This latest variation on a common theme will automatically adjust
  12. ;itself for any block size and directory length under CP/M 1.4 or 2.x
  13. ;or MP/M (any version).  If the screen fills, program will pause until
  14. ;a key is struck (see NPL and LPS equates below).  Total space used
  15. ;and number of files are printed at end.
  16. ;
  17. ;Command: SD FILENAME.FILETYPE or just SD
  18. ;
  19. ;Allows '*' or '?' type specifications.  Drive name may also be
  20. ;specified.  Ignores "SYS" files unless SOPT is TRUE and 'S' option
  21. ;is given (i.e., SD *.* S will print all files).
  22. ;
  23. ;15/Mar/83 Fixed up stack preservation, eliminated memory size
  24. ;       check (didn't work properly) and generally tweaked
  25. ;       a few other things to suit CP/M-86 1.1 environment.
  26. ;       Use GENCMD SD1 data[m60,x200] when generating CMD
  27. ;       file. (Bill Bolton, Australia)
  28. ;
  29. ;05/May/81 First 8086 version. (Bruce R. Ratoff)
  30. ;
  31. ;01/21/81 Fixed print abort test so it would work like "DIR"
  32. ;        [aborts on any character, or on ^S, ^C].
  33. ;      (ASB)
  34. ;
  35. ;
  36. ;01/06/81 Made output go through BDOS so if the printer was on,
  37. ;      you could get the output on it. The ^S test was rendered
  38. ;      useless, as was the ^C test, as BDOS buffers one character
  39. ;      ahead when it is writing out to the console. [You now need
  40. ;      to do a ^S ^C combination to abort, and the size message
  41. ;      is not printed, but I don't think that is a major problem.]
  42. ;      (Andrew S. Beals)
  43. ;
  44. ;01/06/81 Added conditional assembly to print user number when in CP/M
  45. ;      2.x. (ASB)
  46. ;
  47. ;12/15/80 Added space suppression when printing file
  48. ;      totals.  (KBP)
  49. ;
  50. ;12/14/80 Added logic to print space remaining on disk.
  51. ;      Changed ^C test so that interrupting character is
  52. ;      not echoed (makes remote use cleaner).  (BRR)
  53. ;
  54. ;12/02/80 Fixed bug in print routine which compared last file
  55. ;      against garbage before printing. (BRR)
  56. ;
  57. ;11/29/80 Changed to allow printing 4 file names. (Ben Bronson
  58. ;      and Keith Petersen)
  59. ;
  60. ;11/22/80 Fixed bug in handling >256 files.  Changed abort test in
  61. ;      print routine to only abort on control-c.  (brr)
  62. ;
  63. ;Based on 'DIRS' by Keith Petersen, W8SDZ
  64. ;
  65. ;Set 'RMAC' TRUE to assemble with relocating assembler (requires
  66. ;link with PAGE 0 equates in separate file).
  67. ;
  68. FALSE    EQU    0        ;DEFINE LOGICAL FALSE
  69. TRUE    EQU    NOT FALSE    ;DEFINE LOGICAL TRUE
  70. ;
  71. SOPT    EQU    TRUE         ;PUT TRUE TO ALLOW 'DIR *.* S' FORM
  72. WIDE    EQU    true         ;PUT TRUE TO ALLOW 4 NAMES ACROSS
  73. user    equ    true        ;print user numbers
  74. ;
  75. ;BDOS equates
  76. ;
  77. RDCHR    EQU    1            ;READ CHAR FROM CONSOLE
  78. WRCHR    EQU    2            ;WRITE CHR TO CONSOLE
  79. DCONIO    EQU    6            ;direct console i/o
  80. PRINT    EQU    9            ;PRINT CONSOLE BUFF
  81. CONST    EQU    11            ;CHECK CONS STAT
  82. SELDSK    EQU    14            ;SELECT DISK
  83. FOPEN    EQU    15            ;0FFH=NOT FOUND
  84. FCLOSE    EQU    16            ;   "    "
  85. FSRCHF    EQU    17            ;   "    "
  86. FSRCHN    EQU    18            ;   "    "
  87. CURDSK    EQU    25            ;GET CURRENTLY LOGGED DISK NAME
  88. GALLOC    EQU    27            ;GET ADDRESS OF ALLOCATION VECTOR
  89. CURDPB    EQU    31            ;GET CURRENT DISK PARAMETERS
  90. CURUSR    EQU    32            ;GET CURRENTLY LOGGED USER NUMBER
  91. ;
  92. CNTRLS    EQU    013H            ;ASCII control S
  93. ;
  94. BASE    EQU    0
  95. TPA    EQU    100H
  96. ;
  97. FCB    EQU    5CH
  98. ;
  99.     IF    WIDE
  100. NPL    EQU    4        ;NUMBER OF NAMES PER LINE
  101.     ENDIF
  102. ;
  103.     IF    NOT WIDE
  104. NPL    EQU    3        ;NUMBER OF NAMES PER LINE
  105.     ENDIF
  106. ;
  107. LPS    EQU    23        ;NUMBER OF LINES PER SCREEN
  108. DELIM    EQU    ':'        ;FENCE (DELIMITER) CHARACTER
  109. ;
  110.     CSEG
  111. ;    org    TPA
  112. ;
  113. START:
  114.     MOV    AX,SS
  115.     MOV    SAVESS,AX
  116.     MOV    AX,SP
  117.     MOV    SAVESP,AX
  118.     PUSHF
  119.     POP    BX
  120.     MOV    AX,DS
  121.     MOV    SS,AX
  122.     MOV    SP,STACKTOP
  123.     PUSH    BX
  124.     POPF
  125.     cld
  126. ;
  127.     IF    SOPT
  128.     mov    al,byte ptr .FCB+17    ;SAVE S OPTION FLAG
  129.     mov    SOPFLG,al         ;(BLANK OR LETTER S)
  130.     ENDIF
  131. ;
  132.     mov    USERNO,0         ;DEFAULT TO USER 0
  133.     mov    LINCNT,0        ;CLEAR COUNT OF LINES ON SCREEN
  134.     mov    cl,12
  135.     CALL    BDOS            ;CHECK CP/M VERSION
  136.     mov    word ptr VERFLG,bx     ;LO ORD >0 IF 2.X, HI ORD>0 IF MP/M
  137.     mov    dl,0FFH
  138.     mov    cl,CURUSR         ;INTERROGATE USER NUMBER
  139.     CALL    BDOS
  140.     mov    USERNO,al
  141. ;
  142.     if    not user
  143.     mov    al,MPMFLG        ;MP/M?
  144.     test    al,al             ;IF SO, TYPC HEADING LINE
  145.     JZ    CHKDRV             ; ELSE SKIP IT
  146.     endif
  147. ;
  148.     mov    dx,offset USRMSG     ;DISPLAY IT
  149.     mov    cl,PRINT
  150.     CALL    BDOS            ;FIRST PART OF MESSAGE
  151.     mov    al,USERNO
  152.     cmp    al,10             ;IF USER NO. > 9 PRINT LEADING 1
  153.     JB    DUX
  154.     mov    al,'1'
  155.     CALL    TYPC
  156.     mov    al,USERNO         ;PRINT LOW DIGIT OF USER NO.
  157.     sub    al,10
  158. ;
  159. DUX:    add    al,'0'
  160.     CALL    TYPC
  161.     mov    dx,offset USRMS2     ;PRINT TAIL OF MESSAGE
  162.     mov    cl,PRINT
  163.     CALL    BDOS
  164.     mov    LINCNT,1        ;WE USED A LINE
  165. ;
  166. CHKDRV:    mov    si,offset FCB
  167.     lods    al            ;get drive name
  168.     test    al,al            ;ANY SPECIFIED?
  169.     JNZ    START2            ;YES SKIP NEXT ROUTINE
  170.     mov    cl,CURDSK
  171.     CALL    BDOS            ;GET CURRENT DISK NR
  172.     inc    al            ;MAKE A:=1
  173.     mov    byte ptr .FCB,al
  174. ;
  175. START2:    add    al,'A'-1        ;MAKE IT PRINTABLE
  176.     mov    DRNAM,al        ;SAVE FOR LATER
  177.     mov    di,offset FCB+1        ;POINT TO NAME
  178.     mov    al,[di]            ;ANY SPECIFIED?
  179.     cmp    al,' '
  180.     JNZ    GOTFCB
  181. ;No FCB - make FCB all '?'
  182.     mov    cx,11            ;FN+FT COUNT
  183.     mov    al,'?'
  184. ;
  185.     rep stos al            ;fill fcb with '?'
  186. ;
  187. GOTFCB:
  188.     mov    byte ptr .FCB+12,'?'    ;FORCE WILD EXTENT
  189.     mov    al,byte ptr .FCB    ;CHECK FOR EXPLICIT DRIVE
  190.     dec    al
  191.     mov    dl,al            ;SELECT SPECIFIED DRIVE
  192.     mov    cl,SELDSK
  193.     CALL    BDOS
  194.     mov    byte ptr .FCB,0
  195. ;
  196.     mov    cl,CURDPB        ;IT'S 2.X OR MP/M...REQUEST DPB
  197.     push    es            ;save current extra segment
  198.     int    224            ;return bx=offset dpb, es=segment dpb
  199.     add    bx,2
  200.     mov    al,es: [bx]
  201.     mov    BLKSHF,al        ;GET BLOCK SHIFT
  202.     inc    bx            ;BUMP TO BLOCK MASK
  203.     mov    al,es: [bx]
  204.     mov    BLKMSK,al
  205.     add    bx,2
  206.     mov    ax,es: [bx]
  207.     mov    BLKMAX,ax
  208.     add    bx,2
  209.     mov    ax,es: [bx]
  210.     mov    DIRMAX,ax        ;SAVE IT
  211.     pop    es            ;restore our extra segment
  212. ;
  213. SETTBL:    inc    ax            ;DIRECTORY SIZE IS DIRMAX+1
  214.     shl    ax,1            ;DOUBLE DIRECTORY SIZE
  215.     add    ax,offset ORDER        ;TO GET SIZE OF ORDER TABLE
  216.     mov    TBLOC,ax         ;NAME TABLE BEGINS WHERE ORDER TABLE ENDS
  217.     mov    NEXTT,ax
  218. ;
  219. ;Look up the FCB in the directory
  220. ;
  221. SFIRST:    mov    cl,FSRCHF         ;GET 'SEARCH FIRST' FNC
  222.     mov    dx,offset FCB
  223.     CALL    BDOS            ;READ FIRST
  224.     inc    al            ;WERE THERE ANY?
  225.     JNZ    SOME            ;GOT SOME
  226. ;
  227. NONE:    mov    dx,offset FNF        ;PREPARE MP/M ERROR MESSAGE
  228.     mov    al,MPMFLG
  229.     test    al,al            ;USE IT IF REALLY MP/M
  230.     jz    NOFILE
  231.     JMP    ERXIT1
  232. NOFILE:    CALL    ERXIT            ;ELSE USE CP/M ERROR MESSAGE
  233.     DB    'NO FILE$'
  234. ;
  235. ;Read more directory entries
  236. ;
  237. MORDIR:    mov    cl,FSRCHN        ;SEARCH NEXT
  238.     mov    dx,offset FCB
  239.     CALL    BDOS            ;READ DIR ENTRY
  240.     inc    al            ;CHECK FOR END (0FFH)
  241.     JZ    SPRINT            ;NO MORE - SORT & PRINT
  242. ;
  243. ;Point to directory entry 
  244. ;
  245. SOME:    dec    al            ;UNDO PREV 'INR A'
  246.     mov    cl,5
  247.     shl    al,cl            ;entry no. times 32
  248.     mov    ah,0
  249.     add    al,80h
  250.     mov    bx,ax            ;POINT TO BUFFER
  251.                     ;(SKIP TO FN/FT)
  252. ;
  253.     IF    SOPT
  254.     mov    al,SOPFLG        ;DID USER REQUEST SYS FILES?
  255.     cmp    al,'S'
  256.     JZ    SYSFOK
  257.     ENDIF
  258. ;
  259.     test    byte ptr 10[bx],80H    ;check bit 7 of SYS byte
  260.     JNZ    MORDIR            ;SKIP THAT FILE
  261. ;
  262. SYSFOK:    mov    al,USERNO        ;GET CURRENT USER
  263.     cmp    al,[bx]
  264.     JNZ    MORDIR            ;IGNORE IF DIFFERENT
  265.     inc    bx
  266. ;
  267. ;Move entry to table
  268. ;
  269.     mov    si,bx            ;si points to name
  270.     mov    di,NEXTT        ;NEXT TABLE ENTRY TO di
  271.     mov    cx,12            ;ENTRY LENGTH (NAME, TYPC, EXTENT)
  272. ;
  273. TMOVE:    lods    al            ;GET ENTRY CHAR
  274.     and    al,7FH            ;REMOVE ATTRIBUTES
  275.     stos    al            ;store in table
  276.     loop    TMOVE
  277.     mov    al,2[si]        ;get sector count
  278.     MOV    [di],al            ;STORE IN TABLE
  279.     inc    di
  280.     mov    NEXTT,di        ;SAVE UPDATED TABLE ADDR
  281.     inc    COUNT
  282.     JMP    MORDIR
  283. ;
  284. ;Sort and print
  285. ;
  286. SPRINT:    mov    cx,COUNT        ;GET FILE NAME COUNT
  287.     test    cx,cx
  288.     jnz    SPRINI
  289.     jmp    NONE            ;NONE, EXIT
  290. ;Init the order table
  291. SPRINI:    mov    ax,TBLOC        ;GET START OF NAME TABLE
  292.     mov    di,ORDER        ;POINT TO ORDER TABLE
  293. ;
  294. BLDORD:    stos    ax
  295.     add    ax,13
  296.     loop    BLDORD
  297.     mov    bx,COUNT        ;GET COUNT
  298.     mov    SCOUNT,bx        ;SAVE AS # TO SORT
  299.     dec    bx            ;only 1 entry?
  300.     JZ    DONE            ;..YES, SO SKIP SORT
  301. ;
  302. SORT:    mov    SWITCH,0        ;SHOW NONE SWITCHED
  303.     mov    bx,SCOUNT        ;GET COUNT
  304.     dec    bx            ;use 1 less
  305.     mov    word ptr TEMP,bx    ;SAVE # TO COMPARE
  306.     mov    SCOUNT,bx        ;SAVE HIGHEST ENTRY
  307.     JZ    DONE            ;EXIT IF NO MORE
  308.     mov    bx,offset ORDER     ;POINT TO ORDER TABLE
  309. ;
  310. SORTLP:    mov    cx,12            ;# BYTES TO COMPARE
  311.     CALL    COMPR            ;COMPARE 2 ENTRIES
  312.     jbe    NOSWAP
  313.     CALL    SWAP            ;SWAP IF NOT IN ORDER
  314. NOSWAP:    add    bx,2            ;bump order table ptr
  315.     dec    TEMP            ;BUMP COUNT
  316.     JNZ    SORTLP            ;CONTINUE
  317. ;One pass of sort done
  318.     mov    al,SWITCH        ;ANY SWAPS DONE?
  319.     test    al,al
  320.     JNZ    SORT
  321. ;
  322. ;Sort is all done - print entries
  323. ;
  324. DONE:    mov    bx,offset ORDER
  325.     mov    NEXTT,bx
  326. ;
  327. ;Print an entry
  328. ;
  329.     IF    NOT WIDE
  330.     CALL    DRPRNT            ;PRINT DRIVE NAME
  331.     ENDIF
  332.     mov    cx,NPL            ;NR. OF NAMES PER LINE
  333.     mov    TOTSIZ,0        ; TOTAL K USED
  334.     mov    TOTFIL,0        ; AND TOTAL FILES
  335. ;
  336. ENTRY:    mov    bx,COUNT        ; CHECK COUNT OF REMAINING FILES
  337.     dec    bx            ; skip compare if only 1 left
  338.     JZ    OKPRNT
  339.     PUSH    cx
  340. ;
  341. PAUSE:    mov    cl,dconio        ;get console status
  342.     mov    dl,0ffh
  343.     call    bdos
  344.     test    al,al            ;char?
  345.     jz    nobrk            ;no char, bypass the other stuff
  346.     cmp    al,CNTRLS        ;freeze?
  347.     je    WAIT            ;Yes, wait for next
  348.     JMP    EXIT            ;No
  349.  
  350. WAIT:    call    CINPUT            ;Wait for another char
  351.     JMP    PAUSE    
  352. ;
  353. NOBRK:    mov    bx,NEXTT
  354.     mov    cx,11
  355.     CALL    COMPR            ;DOES THIS ENTRY MATCH NEXT ONE?
  356.     pop    cx
  357.     JNE    OKPRNT            ;NO, PRINT IT
  358.     add    bx,2            ;SKIP, SINCE HIGHEST EXTENT COMES LAST IN LIST
  359.     mov    NEXTT,bx
  360.     dec    COUNT            ;COUNT DOWN
  361.     JMP    ENTRY            ;GO GET NEXT
  362. ;
  363. OKPRNT:
  364.     push    cx
  365. ;
  366.     IF    NOT WIDE
  367.     CALL    FENCE            ;PRINT FENCE CHAR AND SPACE
  368.     ENDIF
  369. ;
  370.     mov    bx,NEXTT        ;GET ORDER TABLE POINTER
  371.     mov    si,[bx]
  372.     add    bx,2
  373.     mov    NEXTT,bx        ;SAVE UPDATED TABLE POINTER
  374.     mov    cx,8            ;FILE NAME LENGTH
  375.     CALL    TYPCIT            ;TYPC FILENAME
  376.     mov    al,'.'            ;PERIOD AFTER FN
  377.     CALL    TYPC
  378.     mov    cx,3            ;GET THE FILETYPC
  379.     CALL    TYPCIT
  380.     mov    dl,[si]
  381.     mov    dh,0
  382.     inc    si
  383.     mov    al,[si]            ;GET SECTOR COUNT OF LAST EXTENT
  384.     mov    cl,4            ;# OF EXTENTS TIMES 16K
  385.     shl    dx,cl
  386.     ADD    al,BLKMSK        ;ROUND LAST EXTENT TO BLOCK SIZE
  387.     mov    cl,3
  388.     shr    al,cl            ;CONVERT FROM SECTORS TO K
  389.     mov    ah,0
  390.     add    dx,ax            ;add to total K
  391.     mov    al,BLKMSK        ;GET SECTORS/BLK-1
  392.     mov    cl,3
  393.     shr    ax,cl            ;CONVERT TO K/BLK
  394.     not    ax            ;USE TO FINISH ROUNDING
  395.     and    dx,ax
  396.     add    TOTSIZ,dx        ;add to total used
  397.     inc    TOTFIL            ;INCREMENT FILE COUNT
  398.     mov    ax,dx            ;GET BACK FILE SIZE
  399.     CALL    DECPRT            ; AND PRINT IT
  400.     mov    al,'k'            ;FOLLOW WITH K
  401.     CALL    TYPC
  402. ;
  403.     IF    NOT WIDE
  404.     CALL    SPACE
  405.     ENDIF
  406. ;
  407. ;See if more entries
  408. ;
  409.     dec    COUNT            ;COUNT DOWN ENTRIES
  410.     pop    cx
  411.     JZ    PRTOTL            ;IF OUT OF FILES, PRINT TOTALS
  412.     DEC    CX            ;ONE LESS ON THIS LINE
  413.     jz    DOCRLF
  414. ;
  415.     IF    WIDE
  416.     CALL    FENCE            ;NO CR-LF NEEDED, DO FENCE
  417.     ENDIF
  418. ;
  419.     jmps    NOCRLF
  420. ;
  421. DOCRLF:    CALL    CRLF            ;CR-LF NEEDED
  422. NOCRLF:    JMP    ENTRY
  423. ;
  424. ;Print HL in decimal with leading zero suppression
  425. ;
  426. DECPRT:                    ;CLEAR LEADING ZERO FLAG
  427.     mov    LZFLG,0
  428.     mov    bx,1000            ;PRINT 1000'S DIGIT
  429.     CALL    DIGIT
  430.     mov    bx,100            ;ETC
  431.     CALL    DIGIT
  432.     mov    bx,10
  433.     CALL    DIGIT
  434.     add    al,'0'            ;GET 1'S DIGIT
  435.     JMP    TYPC
  436. ;
  437. DIGIT:    mov    dx,0            ;init hi order dividend
  438.     div    bx            ;divide ax by digit value (dx gets rmdr)
  439.     add    al,'0'            ;convert to ASCII digit
  440. ;
  441.     cmp    al,'0'            ;ZERO DIGIT?
  442.     JNZ    DIGNZ            ;NO, TYPC IT
  443.     mov    al,LZFLG        ;LEADING ZERO?
  444.     test    al,al
  445.     mov    al,'0'
  446.     JNZ    DIGPR            ;PRINT DIGIT
  447.     mov    al,SUPSPC        ;GET SPACE SUPPRESSION FLAG
  448.     test    al,al            ;SEE IF PRINTING FILE TOTALS
  449.     jz    DIGNP            ;YES, DON'T GIVE LEADING SPACES
  450.     mov    al,' '
  451.     JMPS    DIGPR            ;LEADING ZERO...PRINT SPACE
  452. ;
  453. DIGNZ:    mov    LZFLG,0ffh         ;SET LEADING ZERO FLAG SO NEXT ZERO PRINTS
  454. DIGPR:    call    TYPC            ;AND PRINT DIGIT
  455. DIGNP:    mov    ax,dx            ;set up remainder for next digit
  456.     ret
  457. ;
  458. ;Show total space and files used
  459. ;
  460. PRTOTL:    mov    SUPSPC,0        ;SUPPRESS LEADING SPACES IN TOTALS
  461.     CALL    CRLF            ;NEW LINE (WITH PAUSE IF NECESSARY)
  462. ;
  463.     IF    WIDE
  464.     mov    dx,offset TOTMS1     ;PRINT FIRST PART OF TOTAL MESSAGE
  465.     ENDIF
  466. ;
  467.     IF    NOT WIDE
  468.     mov    dx,offset TOTMS1+1     ;PRINT FIRST PART OF TOTAL MESSAGE
  469.     ENDIF
  470. ;
  471.     mov    cl,PRINT
  472.     CALL    BDOS
  473.     mov    ax,TOTSIZ        ;PRINT TOTAL K USED
  474.     CALL    DECPRT
  475.     mov    dx,offset TOTMS2    ;NEXT PART OF MESSAGE
  476.     mov    cl,PRINT
  477.     CALL    BDOS
  478.     mov    ax,TOTFIL        ;PRINT COUNT OF FILES
  479.     CALL    DECPRT
  480.     mov    dx,offset TOTMS3    ;TAIL OF MESSAGE
  481.     mov    cl,PRINT
  482.     CALL    BDOS
  483.     mov    cl,GALLOC        ;GET ADDRESS OF ALLOCATION VECTOR
  484.     push    es            ;save our ES
  485.     int    224            ;return bx=offset ALV, es=segment ALV
  486.     mov    dx,BLKMAX        ;GET ITS LENGTH
  487.     inc    dx
  488.     mov    cx,0            ;INIT BLOCK COUNT TO 0
  489. ;
  490. GSPBYT:    PUSH    bx            ;SAVE ALLOC ADDRESS
  491.     mov    al,es: [bx]
  492.     mov    bl,8            ;SET TO PROCESS 8 BLOCKS
  493. ;
  494. GSPLUP:    shl    al,1            ;TEST BIT
  495.     JB    NOTFRE
  496.     inc    cx
  497. ;
  498. NOTFRE:    dec    dx            ;COUNT DOWN BLOCKS
  499.     JZ    ENDALC            ;QUIT IF OUT OF BLOCKS
  500.     dec    bl            ;COUNT DOWN 8 BITS
  501.     JNZ    GSPLUP            ;DO ANOTHER BIT
  502.     POP    bx            ;BUMP TO NEXT BYTE
  503.     INC    bx            ;OF ALLOC. VECTOR
  504.     JMPS    GSPBYT            ;PROCESS IT
  505. ;
  506. ENDALC:    pop    es            ;restore our es
  507.     mov    ax,cx
  508.     mov    cl,BLKSHF        ;GET BLOCK SHIFT FACTOR
  509.     sub    cl,3            ;CONVERT FROM SECTORS TO K
  510.     JZ    PRTFRE            ;SKIP SHIFTS IF 1K BLOCKS
  511. ;
  512.     shl    ax,cl            ;mult blks by k/blk
  513. ;
  514. PRTFRE:    CALL    DECPRT            ;PRINT K FREE
  515.     mov    dx,offset TOTMS4
  516.     mov    cl,PRINT
  517.     CALL    BDOS
  518.     JMP    EXIT            ;ALL DONE...RETURN TO CP/M
  519. ;
  520. ;
  521. FENCE:
  522.     IF    WIDE
  523.     CALL    SPACE
  524.     ENDIF
  525.  
  526.     mov    al,DELIM        ;FENCE CHARACTER
  527.     CALL    TYPC            ;PRINT IT, FALL INTO SPACE
  528. ;
  529. SPACE:    mov    al,' '
  530. ;
  531. ;Type character in A
  532. ;
  533. TYPC:    PUSH    cx
  534.     PUSH    dx
  535.     push    bx
  536.     push    si
  537.     mov    dl,al            ;use bdos calls
  538.     mov    cl,WRCHR
  539.     call    bdos
  540.     pop    si
  541.     POP    bx
  542.     POP     dx
  543.     POP    cx
  544.     RET
  545. ;
  546. TYPCIT:    lods    al
  547.     CALL    TYPC
  548.     loop    TYPCIT
  549.     RET
  550. ;
  551. ;Fetch character from console (without echo)
  552. ;
  553. CINPUT:    mov    cl,dconio
  554.     mov    dl,0ffh
  555.     call    BDOS
  556.     and    al,7FH
  557.     jz    CINPUT
  558.     RET
  559. ;
  560. CRLF:    mov    al,LINCNT        ;CHECK FOR END OF SCREEN
  561.     inc    al
  562.     cmp    al,LPS
  563.     JB    NOTEOS            ;SKIP MESSAGE IF MORE LINES LEFT ON SCREEN
  564.     mov    dx,offset EOSMSG    ;SAY WE'RE PAUSING FOR INPUT
  565.     mov    cl,PRINT
  566.     CALL    BDOS
  567.     CALL    CINPUT            ;WAIT FOR CHAR.
  568.     mov    al,0            ;SET UP TO ZERO LINE COUNT
  569. ;
  570. NOTEOS:    mov    LINCNT,al        ;SAVE NEW LINE COUNT
  571.     mov    al,13            ;print cr
  572.     call    TYPC
  573.     mov    al,10            ;lf
  574.     call    TYPC
  575. ;
  576.     IF    NOT WIDE
  577.     CALL    DRPRNT            ;DRIVE NAME
  578.     ENDIF
  579. ;
  580.     mov    cx,NPL            ;RESET NUMBER OF NAMES PER LINE
  581.     RET
  582. ;
  583. ;
  584.     IF    NOT WIDE
  585. DRPRNT:    mov    al,DRNAM
  586.     JMP    TYPC
  587.     ENDIF
  588. ;
  589. ;Compare routine for sort
  590. ;
  591. COMPR:    mov    si,[bx]
  592.     mov    di,2[bx]
  593.     repe cmps al,al
  594.     ret
  595. ;
  596. ;
  597. ;Swap entries in the order table
  598. ;
  599. SWAP:    mov    SWITCH,1        ;SHOW A SWAP WAS MADE
  600.     mov    dx,[bx]
  601.     xchg    dx,2[bx]
  602.     mov    [bx],dx
  603.     ret
  604. ;
  605. ;Error exit
  606. ;
  607. ERXIT:    POP    dx            ;GET MSG
  608. ;
  609. ERXIT1:    mov    cl,PRINT
  610. ;
  611. CALLB:    CALL    BDOS            ;PERFORM REQUESTED FUNCTION
  612. ;
  613. ;(fall into exit)
  614. ;Exit - all done, restore stack
  615. ;
  616. EXIT:
  617.     PUSHF
  618.     POP    BX
  619.     MOV    AX,SAVESS
  620.     MOV    SS,AX
  621.     MOV    AX,SAVESP
  622.     MOV    SP,AX
  623.     PUSH    BX
  624.     POPF
  625.     MOV    CX,0            ;exit is via BDOS call 0
  626.     MOV    DX,0
  627. ;
  628. BDOS:    push    es            ;preserve es thru bdos call
  629.     int    224            ;call bdos 8086 style
  630.     pop    es
  631.     ret
  632. ;
  633. ENDCS    EQU    $
  634. ;
  635.     DSEG
  636. ;    ORG    Offset ENDCS
  637.     ORG    100H
  638. ;
  639. FNF    DB    'File not found.$'
  640. ;
  641. USRMSG    DB    'Directory for user $'
  642. USRMS2    DB    ':',13,10,'$'
  643. ;
  644. TOTMS1    DB    ' : Total of $'
  645. DRNAM    equ    TOTMS1
  646. TOTMS2    DB    'k in $'
  647. TOTMS3    DB    ' files with $'
  648. TOTMS4    DB    'k space remaining.$'
  649. ;
  650. EOSMSG    DB    13,10,'(Strike any key to continue)$'
  651. ;
  652. ;Temporary storage area
  653. ;
  654. BLKSHF    DB    0            ;# SHIFTS TO MULT BY SEC/BLK
  655. BLKMSK    DB    0            ;SEC/BLK - 1
  656. BLKMAX    DW    0            ;HIGHEST BLOCK # ON DRIVE
  657. DIRMAX    DW    0            ;HIGHEST FILE # IN DIRECTORY
  658. TOTSIZ    DW    0            ;TOTAL SIZE OF ALL FILES
  659. TOTFIL    DW    0            ;TOTAL NUMBER OF FILES
  660. LINCNT    DB    0            ;COUNT OF LINES ON SCREEN
  661. TBLOC    DW    0            ;POINTER TO START OF NAME TABLE
  662. NEXTT    DW    0            ;NEXT TABLE ENTRY
  663. COUNT    DW    0            ;ENTRY COUNT
  664. SCOUNT    DW    0            ;# TO SORT
  665. SWITCH    DB    0            ;SWAP SWITCH FOR SORT
  666. SUPSPC    DB    0FFH            ;LEADING SPACE FLAG FOR DECIMAL RTN.
  667. BUFAD    DW    BASE+80H         ;OUTPUT ADDR
  668. SOPFLG    db    0            ;SET TO 'S' TO ALLOW SYS FILES TO PRINT
  669. USERNO    db    0            ;CONTAINS CURRENT USER NUMBER
  670. TEMP    dw    0            ;SAVE DIR ENTRY
  671. VERFLG    db    0            ;VERSION FLAG
  672. MPMFLG    db    0            ;MP/M FLAG
  673. LZFLG    db    0            ;0 WHEN PRINTING LEADING ZEROS
  674. ;
  675. STACK    RW    200H
  676. STACKTOP EQU    Offset $
  677. SAVESS    DW    0
  678. SAVESP    DW    0
  679. ;
  680. ORDER    EQU    Offset $        ;ORDER TABLE STARTS HERE
  681.     END
  682.