home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume4 / dos2coco / dirc.asm next >
Encoding:
Assembly Source File  |  1989-02-03  |  11.8 KB  |  548 lines

  1. CSEG        SEGMENT PARA PUBLIC 'CODE'
  2.  
  3. ;---------------
  4. ;
  5. ;    DIRC.COM -- all segments set to CSEG upon entry
  6. ;
  7. ;    USAGE:
  8. ;        DIRC [filename[.ext]]<CR>
  9. ;
  10. ;        [filename[.ext]] is used to specify the file(s) whose
  11. ;            directory you want to list.
  12. ;
  13. ;        The information provided includes the free space on the disk.
  14. ;            The freespace is listed both in Granules and Bytes.
  15. ;            The display for each file includes its size in bytes,
  16. ;                the number of granules it occupies, the file
  17. ;                type, and the file mode.
  18. ;
  19. ;        You may use the global characters ? and * in the filename and
  20. ;            extention parameters.
  21. ;
  22. ;        If you do not specify a filename, it defaults to *.*
  23. ;
  24. ;        If you do not specify a filename extention, it defaults to *.
  25. ;
  26. ;
  27. ;        To assemble this program, do the following:
  28. ;
  29. ;
  30. ;        masm dirc;
  31. ;        link dirc;
  32. ;        exe2bin dirc.exe dirc.com
  33. ;        erase dirc.exe
  34. ;
  35. ;---------------
  36.         ASSUME    CS:CSEG,DS:CSEG,SS:CSEG,ES:CSEG
  37.  
  38.         ORG    100H
  39. ;---------------
  40. ;
  41. ;    ENTRY -- Link to start of program (past variables)
  42. ;
  43. ;---------------
  44. ENTRY:        JMP    START
  45. ;---------------
  46. ;
  47. ;    TEXT -- Directory listing header
  48. ;
  49. ;---------------
  50. DRIVENAME    EQU    'A'
  51.  
  52. TEXT        DB    ' Volume in drive ',DRIVENAME,' is COCO disk',13,10
  53.         DB    ' Directory of COCO disk',13,10,10,'$'
  54.  
  55. DRIVENO        EQU    DRIVENAME-'A'
  56. ;---------------
  57. ;
  58. ;    TYPETAB, TYPEn -- Types for COCO directory entries
  59. ;
  60. ;---------------
  61. TYPETAB        DW    TYPE0
  62.         DW    TYPE1
  63.         DW    TYPE2
  64.         DW    TYPE3
  65. TYPE0        DB    'BASIC    $'
  66. TYPE1        DB    'Data     $'
  67. TYPE2        DB    'Program  $'
  68. TYPE3        DB    'Text     $'
  69. ;---------------
  70. ;
  71. ;    ASCII, ASCIIn -- File modes for COCO directory entries
  72. ;
  73. ;---------------
  74. ASCII        DW    ASCII0
  75.         DW    ASCII1
  76. ASCII0        DB    'Binary$'
  77. ASCII1        DB    'ASCII$'
  78. ;---------------
  79. ;
  80. ;    NUMFILES, GRANSFREE, BYTESFREE -- Text for directory ending printout
  81. ;
  82. ;---------------
  83. NUMFILES    DB    ' File(s)$'
  84. GRANSFREE    DB    ' Grans, $'
  85. BYTESFREE    DB    ' Bytes free$'
  86. ;---------------
  87. ;
  88. ;    NUMBUF -- Expansion buffer for binary to decinal conversions
  89. ;
  90. ;---------------
  91. NUMBUF        DB    6 DUP (?)
  92. ;---------------
  93. ;
  94. ;    FCOUNT, GCOUNT -- File count and Granule count for dir info
  95. ;
  96. ;---------------
  97. FCOUNT        DW    0
  98. GCOUNT        DW    0
  99. ;---------------
  100. ;
  101. ;    FILAOK, FILOK -- For wildcarding, File always ok and this file ok
  102. ;
  103. ;---------------
  104. FILAOK        DB    0
  105. FILOK        DB    0
  106. ;---------------
  107. ;
  108. ;    GRANS, GSIZE, SECSIZE -- Number of grans on the disk, number of
  109. ;        bytes per gran, and sector size
  110. ;
  111. ;---------------
  112. GRANS        DW    68
  113. GSIZE        DW    2304
  114. SECSIZE        DW    256
  115. ;---------------
  116. ;
  117. ;    NBSEC -- Save area for MSDOS bytes per sector (changed, must restore)
  118. ;
  119. ;---------------
  120. NBSEC        DB    0
  121. ;---------------
  122. ;
  123. ;    FAT -- FAT information buffer read from COCO disk
  124. ;
  125. ;---------------
  126. FAT        DB    256 DUP (?)
  127. ;---------------
  128. ;
  129. ;    DIRBUF -- Directory sector buffer read from COCO disk
  130. ;
  131. ;---------------
  132. DIRBUF        DB    256 DUP (?)
  133. ;---------------
  134. ;
  135. ;    START -- Start of DIRC.COM
  136. ;
  137. ;---------------
  138. START:        CALL    CHECKAOK        ;Set filaok if all files are
  139.                         ;to be listed
  140.         MOV    DX,OFFSET TEXT        ;Print out directory header
  141.         MOV    AH,9
  142.         INT    21H
  143.  
  144.         XOR    AX,AX            ;Get MSDOS disk info pointer
  145.         MOV    ES,AX
  146.         LES    BX,ES:[78H]
  147.  
  148.         MOV    AL,ES:[BX+3]        ;Get MSDOS bytes per sector
  149.         MOV    NBSEC,AL        ;and save it
  150.  
  151.         MOV    BYTE PTR ES:[BX+3],1    ;Set bytes per sector to 256
  152.  
  153.         PUSH    CS            ;Restore ES to CSEG
  154.         POP    ES
  155. ;---------------
  156. ;
  157. ;    Do disk FAT read, 1 sector, buffer=FAT, track 17, sector 2, side 0
  158. ;        disk B:
  159. ;
  160. ;---------------
  161.         MOV    AX,0201H
  162.         MOV    BX,OFFSET FAT
  163.         MOV    CX,1102H
  164.         MOV    DX,DRIVENO
  165.         INT    13H
  166.  
  167.         MOV    CX,9            ;# of directory sectors
  168. ;---------------
  169. ;
  170. ;    RLOOP -- Main loop for directory read
  171. ;
  172. ;---------------
  173. RLOOP:        PUSH    CX            ;Save loop counter
  174.  
  175.         MOV    AX,12            ;Calc sector number (3-11)
  176.         SUB    AX,CX
  177.         MOV    CX,AX
  178.  
  179.         MOV    CH,17            ;Track number 17
  180.         MOV    BX,OFFSET DIRBUF    ;Buffer=DIRBUF
  181.         MOV    AX,0201H        ;Read 1 sector
  182.         MOV    DX,DRIVENO        ;Head 0, disk B:
  183.         INT    13H            ;Do BIOS read
  184.  
  185.         MOV    CX,8            ;Number of entries in sector
  186. ;---------------
  187. ;
  188. ;    PNEXT -- Secondary loop, for each file within directory sector
  189. ;
  190. ;---------------
  191. PNEXT:        MOV    AL,[BX]            ;Get entry first byte
  192.  
  193.         OR    AL,AL            ;Zero, file has been killed
  194.         JZ    NEXTENT
  195.  
  196.         CMP    AL,0FFH            ;0FFh, no more in sector
  197.         JZ    LASTENT
  198.  
  199.         CALL    CHECKFIL        ;Check if entry is ok to list
  200.                         ;result: filok=1, yes
  201.  
  202.         PUSH    CX            ;Save count and buffer pointer
  203.         PUSH    BX
  204.  
  205.         ADD    BX,11            ;Offset to file info
  206.  
  207.         CMP    FILOK,1            ;This file to be listed ?
  208.         JNZ    NODISP1            ;No, skip display
  209.  
  210.         SUB    BX,11            ;Point to file name again
  211.  
  212.         INC    FCOUNT            ;Count one more file listed
  213.  
  214.         MOV    CX,8            ;Print out file name, 1 space,
  215.         CALL    PSTRING            ;File extention, and 4 more
  216.         MOV    CX,1            ;Spaces. Adjust BX to file
  217.         CALL    SPACES            ;Info
  218.         MOV    CX,3
  219.         CALL    PSTRING
  220.         MOV    CX,4
  221.         CALL    SPACES
  222.  
  223. NODISP1:    MOV    AX,[BX+1]        ;AL=file mode, AH=first gran #
  224.         MOV    CX,[BX+3]        ;CX=# of bytes in last sector
  225.         XCHG    CH,CL            ;6809 format (HIGH, LOW)
  226.         MOV    BL,[BX]            ;BL is file type
  227.  
  228.         PUSH    AX            ;Save mode, gran, and type
  229.         PUSH    BX
  230.         CALL    CALCDISP        ;Calc file size, and display
  231.  
  232.         POP    BX            ;Restore mode, gran, and type
  233.         CMP    FILOK,1            ;File ok to use?
  234.         JNZ    NODISP2            ;No, dont display
  235.  
  236.         XOR    BH,BH            ;Find text for file type
  237.         SHL    BX,1
  238.         MOV    DX,TYPETAB[BX]
  239.  
  240.         MOV    AH,9            ;Print text
  241.         INT    21H
  242.  
  243.         POP    BX            ;BL=file mode
  244.         PUSH    BX            ;Maintain stack integrety
  245.  
  246.         XOR    BH,BH            ;Z=nonascii file type
  247.         OR    BL,BL
  248.         JZ    NONASCII
  249.  
  250.         MOV    BL,2            ;Offset for ASCII message
  251.  
  252. NONASCII:    MOV    DX,ASCII[BX]        ;Get message and print it
  253.         MOV    AH,9
  254.         INT    21H
  255.         CALL    CRLF            ;Followed by CRLF
  256.  
  257. NODISP2:    POP    AX            ;Pop stack information
  258.         POP    BX
  259.         POP    CX            ;Restore count for entries
  260.  
  261. NEXTENT:    ADD    BX,20H            ;Point to next entry
  262.         LOOP    PNEXT            ;Loop for all 8 in sector
  263.  
  264. LASTENT:    POP    CX            ;Restore outer loop count
  265.         LOOP    RLOOPX            ;Loop for all 9 sectors
  266.  
  267.         MOV    CX,3            ;Last line, print disk info
  268.         CALL    SPACES            ;3 spaces in
  269.  
  270.         MOV    AX,FCOUNT        ;Number of files
  271.         CALL    MAKENUM            ;Make numeric and print
  272.  
  273.         MOV    DX,OFFSET NUMFILES    ;Print "File(s)" message
  274.         MOV    AH,9
  275.         INT    21H
  276.  
  277.         MOV    AX,GRANS        ;Number of grans free
  278.         CALL    MAKENUM            ;Make numeric and print
  279.  
  280.         MOV    DX,OFFSET GRANSFREE    ;Print "Grans" message
  281.         MOV    AH,9
  282.         INT    21H
  283.  
  284.         MOV    AX,GRANS        ;Number of grans free
  285.         MOV    CX,2304            ;Compute bytes free
  286.         MUL    CX
  287.         CALL    MAKEBNUM        ;Make big numeric and print
  288.  
  289.         MOV    DX,OFFSET BYTESFREE    ;Print "Bytes" message
  290.         MOV    AH,9
  291.         INT    21H
  292.  
  293.         CALL    CRLF            ;Do a CRLF
  294.  
  295.         XOR    AX,AX            ;Point to MSDOS disk info
  296.         MOV    ES,AX
  297.         LES    BX,ES:[78H]
  298.  
  299.         MOV    AL,NBSEC        ;Get MSDOS bytes per sector
  300.         MOV    ES:[BX+3],AL        ;Restore to old value
  301.  
  302.         MOV    AX,4C00H        ;Exit to DOS, no errors
  303.         INT    21H
  304.  
  305. RLOOPX:        JMP    RLOOP            ;Vector for loop (too far)
  306. ;---------------
  307. ;
  308. ;    SPACES -- print CX spaces on screen
  309. ;
  310. ;---------------
  311. SPACES:        MOV    AH,2
  312.         MOV    DL,' '
  313.         INT    21H
  314.         LOOP    SPACES
  315.         RET
  316. ;---------------
  317. ;
  318. ;    PSTRING -- print string at BX with length CX, return BX=BX+CX
  319. ;
  320. ;---------------
  321. PSTRING:    MOV    DL,[BX]
  322.         INC    BX
  323.         MOV    AH,2
  324.         INT    21H
  325.         LOOP    PSTRING
  326.         RET
  327. ;---------------
  328. ;
  329. ;    CRLF -- Do CRLF to screen, dont use any registers
  330. ;
  331. ;---------------
  332. CRLF:        PUSH    AX
  333.         PUSH    DX
  334.         MOV    AH,2
  335.         MOV    DL,13
  336.         INT    21H
  337.         MOV    DL,10
  338.         INT    21H
  339.         POP    DX
  340.         POP    AX
  341.         RET
  342. ;---------------
  343. ;
  344. ;    CALCDISP -- calculate file size, and display if necessary
  345. ;
  346. ;---------------
  347. CALCDISP:    MOV    GCOUNT,0        ;File currently has no grans
  348.         JMP    CALCDISP1        ;Initialized, continue...
  349.  
  350. NEXTGRAN:    ADD    CX,GSIZE        ;Count more bytes in file
  351.  
  352. CALCDISP1:    MOV    AL,AH            ;Get gran number in AX
  353.         XOR    AH,AH
  354.  
  355.         DEC    GRANS            ;Drop gran from free space
  356.         INC    GCOUNT            ;And add gran to file size
  357.  
  358.         MOV    BX,OFFSET FAT        ;Point to FAT info
  359.         ADD    BX,AX            ;Point to GRAN entry for file
  360.  
  361.         MOV    AH,[BX]            ;Get next gran number or end
  362.         OR    AH,AH            ;Sign set, last gran in file
  363.         JNS    NEXTGRAN
  364.  
  365.         XOR    AL,AL            ;Compute number of bytes left
  366.         AND    AH,3FH            ;AH is number of sects, so
  367.         DEC    AH            ;AX is number of bytes.  Dont
  368.         JS    NOADD            ;Count last (CX had it)
  369.  
  370.         ADD    CX,AX            ;More than 1 left, add 256*AH
  371.  
  372. NOADD:        MOV    AX,CX            ;Get number of bytes in file
  373.         CMP    FILOK,1            ;Do we print this?
  374.         JNZ    NODISP3            ;No...
  375.  
  376.         CALL    MAKENUM            ;Make numeric and print
  377.  
  378.         MOV    AX,GCOUNT        ;Get gran count for file
  379.         CALL    MAKENUM            ;Make numeric and print
  380.  
  381.         MOV    CX,2            ;Print 2 spaces
  382.         CALL    SPACES
  383.  
  384. NODISP3:    RET                ;Done with calcdisp
  385. ;---------------
  386. ;
  387. ;    MAKENUM -- Make AX a decimal value, and print it to the screen
  388. ;
  389. ;---------------
  390. MAKENUM:    MOV    BX,OFFSET NUMBUF    ;NUMBUF is area for conversion
  391.  
  392.         XOR    DX,DX            ;DX:AX is number
  393.  
  394.         MOV    CX,10000        ;Initial divisor
  395.  
  396. DIVLP1:        DIV    CX            ;AX=AX/CX, DX is remainder
  397.  
  398.         ADD    AL,30H            ;Convert it to ASCII
  399.  
  400.         MOV    [BX],AL            ;And put it in buffer
  401.         INC    BX
  402.  
  403.         MOV    AX,CX            ;Divide divisor by 10
  404.         PUSH    DX            ;Save remainder
  405.         MOV    CX,10
  406.         XOR    DX,DX            ;DX:AX is divisor
  407.         DIV    CX
  408.         MOV    CX,AX            ;New divisor in CX
  409.         POP    AX            ;Old remainder in AX
  410.  
  411.         CMP    CX,1            ;Divisor=1 (done indicator)
  412.         JNZ    DIVLP1            ;No, loop for next character
  413.  
  414.         MOV    CX,4            ;# of possible leading 0's
  415. ;---------------
  416. ;
  417. ;    LZDROPCOM -- Drop leading zero's (change to spaces) for CX counts
  418. ;             Also puts last character in buffer at [BX] for callers
  419. ;
  420. ;---------------
  421. LZDROPCOM:    PUSH    CX            ;Save number of possible 0's
  422.  
  423.         ADD    AL,30H            ;Put last character in buffer
  424.         MOV    [BX],AL
  425.  
  426.         MOV    BX,OFFSET NUMBUF    ;Point to head of buffer
  427.  
  428. LZDROP:        CMP    BYTE PTR [BX],30H    ;Is this character a 0?
  429.         JNZ    DONE            ;No, finished
  430.  
  431.         MOV    BYTE PTR [BX],' '    ;Blank it
  432.         INC    BX
  433.  
  434.         LOOP    LZDROP            ;Go for CX characters
  435.  
  436. DONE:        MOV    BX,OFFSET NUMBUF    ;Print NUMBUF for CX+1 chars
  437.         POP    CX
  438.         INC    CX
  439.         CALL    PSTRING
  440.         RET
  441. ;---------------
  442. ;
  443. ;    MAKENUM -- Make DX:AX a decimal value, and print it to the screen
  444. ;           Max value is 199999
  445. ;---------------
  446. MAKEBNUM:    MOV    BX,OFFSET NUMBUF    ;Output buffer
  447.         MOV    CX,10000        ;Initial divisor
  448.  
  449. BDIVLP1:    DIV    CX            ;AX DX:AX/CX, DX is remainder
  450.         CMP    CX,10000        ;If first division, make 2 dig
  451.         JNZ    DDD1            ;Not first...
  452.  
  453.         MOV    AH,30H            ;Set first digit to 0
  454.         CMP    AL,10            ;2nd digit >9?
  455.         JB    NOAH            ;No
  456.  
  457.         MOV    AH,31H            ;First digit=1
  458.         SUB    AL,10            ;2nd digit is AL-10
  459.  
  460. NOAH:        MOV    [BX],AH            ;Place first digit
  461.         INC    BX            ;Position to second
  462.  
  463. DDD1:        ADD    AL,30H            ;Convert this digit to ASCII
  464.  
  465.         MOV    [BX],AL            ;Place digit in buffer
  466.         INC    BX
  467.  
  468.         MOV    AX,CX            ;Divisor=divisor/10
  469.         PUSH    DX            ;Save old remainder
  470.         MOV    CX,10
  471.         XOR    DX,DX            ;DX:AX is divisor
  472.         DIV    CX
  473.         MOV    CX,AX            ;CX is new divisor
  474.         POP    AX            ;AX is old remainder
  475.  
  476.         CMP    CX,1            ;Divisor=1?
  477.         JNZ    BDIVLP1            ;No, continue
  478.  
  479.         MOV    CX,5            ;Max number of leading zeros
  480.         JMP    LZDROPCOM        ;Go drop any leading zeros
  481. ;---------------
  482. ;
  483. ;    CHECKAOK -- check if all are ok, and if not, set up compare buffer for
  484. ;            comparisons
  485. ;
  486. ;---------------
  487. CHECKAOK:    MOV    DI,5DH            ;Command line filespec
  488.         MOV    CX,11            ;Number of characters to scan
  489.  
  490.         MOV    FILAOK,1        ;Preset value for true
  491.  
  492.         MOV    AX,3F20H        ;Use both ? and space until it
  493.                         ;Is determined what it is
  494.  
  495. CHECKAOK1:    CMP    BYTE PTR [DI],AL    ;Is it the same as last?
  496.         JZ    CHECK1            ;Yes, ok so far
  497.         CMP    BYTE PTR [DI],AH    ;Alternate for ?
  498.         JZ    CHECK1A            ;Yes, ok so far
  499.  
  500.         MOV    FILAOK,0        ;File is not always ok
  501.         RET                ;Done
  502.  
  503. CHECK1:        MOV    AH,AL            ;Copy char, we know what they
  504.                         ;All must be
  505.         INC    DI            ;Point to next char
  506.         LOOP    CHECKAOK1        ;Go for all 11 characters
  507.         RET                ;Done, file always ok
  508.  
  509. CHECK1A:    MOV    AL,AH            ;Copy char, we know what they
  510.         INC    DI            ;All must be. point to next
  511.         LOOP    CHECKAOK1        ;And go for all 11 characters
  512.         RET                ;Done, file always ok
  513. ;---------------
  514. ;
  515. ;    CHECKFIL -- check a file to see if it matches comparison value
  516. ;
  517. ;---------------
  518. CHECKFIL:    MOV    FILOK,1            ;Set to true for now
  519.  
  520.         CMP    FILAOK,1        ;Always ok?
  521.         JNZ    CHECKFIL1        ;No, check this one
  522.         RET                ;Yes, return with this one ok
  523.  
  524. CHECKFIL1:    PUSH    BX            ;Save important regs
  525.         PUSH    CX
  526.         MOV    CX,11            ;File spec length
  527.         MOV    DI,5DH            ;Offset to comparison string
  528. CHECKF2:    MOV    AL,[DI]            ;Get first char to compare
  529.         CMP    AL,'?'            ;Wildcard?
  530.         JZ    CHECKN            ;Yes, this character always ok
  531.         CMP    AL,[BX]            ;No, check with current value
  532.         JZ    CHECKN            ;Yes, ok so far
  533.         POP    CX            ;No, restore registers
  534.         POP    BX
  535.         MOV    FILOK,0            ;File is not ok
  536.         RET                ;Done
  537.  
  538. CHECKN:        INC    BX            ;Point to next character
  539.         INC    DI
  540.         LOOP    CHECKF2            ;Go for all 11 characters
  541.         POP    CX            ;Restore important registers
  542.         POP    BX
  543.         RET                ;Done, file is ok
  544.  
  545. CSEG        ENDS
  546.  
  547.         END    ENTRY
  548.