home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 17 / CD_ASCQ_17_101194.iso / vrac / pbcode.zip / AHNUTS.BAS next >
BASIC Source File  |  1994-07-30  |  9KB  |  209 lines

  1. ' ***************************************************************************
  2. '   AHNUTS.BAS
  3. '   VERSION 2.0a, 7/29/1993
  4. '   Released to the PUBLIC DOMAIN by the author: Lewis E. Balentine
  5. ' ***************************************************************************
  6. ' 29 July 1994
  7. ' The previous version of Power Basic would allow the use of a semicolon
  8. ' or an apostophe to designate remarks in inline assembly code. The
  9. ' current version does nut. That is te only change for this version
  10. ' -----------------------------------------------------------------------------
  11. ' 14 August 1993
  12. ' Version 1.0 was written in assembly language for MS-PDS 7.0
  13. ' This is a port to PB3 and function much differently due to the my lack
  14. ' of determination when I rewrote it. I also had a different need at this
  15. ' time. Whatever .... 
  16. '
  17. ' --------------- DOS directory functions for PB3 -----------------
  18. '   Among my list of complaints is the inability to read subdirectory names,
  19. '   files sizes and dates. This file is a direct result of that flustration. 
  20. '
  21. '   I ordered a third party library so I would have those functions. Its
  22. '   directory functions were very fancy ... but not what I needed. All I 
  23. '   really wanted is a simple implimentation of DOS findfirst and findnext 
  24. '   functions.
  25. '
  26. '   All else has failed... ... ... Ah Nuts ! ! ! ----------------------------
  27. '
  28. ' WARNING #1: ASSEMBLER code is not my cup of tea. 
  29. '
  30. ' WARNING #2: What you see is what you get. There is no warranty exspressed,
  31. '   implied or otherwise.
  32. '
  33. ' REFFERENCES:
  34. '   The following manuals/books were used in developing this code:
  35. '   Basic Programer's Guide version 7.0 (c)1989,1988,1887, Microsoft
  36. '   Macro Assembler 5.0 Programers Guide (c)1987, Microsoft
  37. '   Macro Assembler 5.1 Update (c)1987, Microsoft
  38. '   Disk Operating System Ver 3.3 Technical Reference (c)1987,1985, IBM
  39. '   The 8086 Book (c)1980, Osborne/McGraw-Hill, Russell Rector, George Alexy
  40. '
  41. ' ***************************************************************************
  42.  
  43. type dtatype
  44.     reserve     as string * 21                ' reserved for use by DOS
  45.     atrib       as byte                    ' file atribute
  46.     filetime    as Word                    ' file time
  47.     filedate    as Word                    ' file date
  48.     filesize    as Dword                ' size of file in bytes
  49.     filename    as String * 12            ' dos file name
  50.     terminator  as byte                    ' chr$(0)
  51. end type
  52. ' ----------------------------------------------------------------------------
  53. ' code for testing and debugging
  54. ' ----------------------------------------------------------------------------
  55. ' test$="C:\autoexec.bat"
  56. ' cls
  57. ' p$= "dir "+test$
  58. ' shell p$
  59. ' s$ = FileInfo$(test$)
  60. ' print
  61. ' print
  62. ' print
  63. ' print
  64. ' print
  65. ' print
  66. ' print
  67. ' print
  68. ' print
  69. ' print
  70. ' print s$
  71. ' print "123456789012345678901234567890123456789012345678901234567890"
  72. ' end
  73. ' -----------------------------------------------------------------------------
  74. Function FileInfo$ (Search$) static
  75.     ' The format of the retruned string is as follows:
  76.     ' FILENAME.EXT   YYYY-MM-DD  HH:MM:SS  FILE0SIZE
  77.     ' 1234567890123456789012345678901234567890123456
  78.     dim olddtaoff as Word            ' PB3's Disk Transfer Area offset
  79.     dim olddtaseg as Word            ' PB3's Disk Transfer Area segment
  80.     dim ourdtaoff as Word            ' our Disk Transfer Area offset
  81.     dim ourdtaseg as Word            ' our Disk Transfer Area segment
  82.     dim specoff   as Word            ' our Search String offset
  83.     dim specseg   as Word            ' our Search String segment
  84.     dim ourdta    as dtatype        ' Our DTA
  85.     dim ourerr    as Integer
  86.     dim temp1     as dword
  87.     dim temp2     as dword
  88.     dim temp3     as dword
  89.  
  90.     ourerr = 0
  91.     a?=16
  92.     spec$ = ucase$(rtrim$(search$))+chr$(0)
  93.     if Len(spec$) <  1   then FileInfo$ = "": exit Function
  94.     ourdtaseg = varseg(ourdta)
  95.     ourdtaoff = varptr(ourdta)
  96.     specseg      = strseg(spec$)
  97.     specoff   = strptr(spec$)
  98.  
  99.         '------------------------------------------------------------------
  100.         ' This routine uses calls to DOS FindFirst function.
  101.         ' We need to save the existing DTA and replace it
  102.         ' with our own static data area.
  103.         '------------------------------------------------------------------
  104.         ' save PB3's DTA
  105.         ! push    es
  106.         ! mov     ah,&h2F                 ; DOS function: Get DTA
  107.         ! int     &h21                    ; Call DOS
  108.         ! mov     olddtaoff,bx            ; Save old dta offset.
  109.         ! mov     olddtaseg,es            ; Save old dta segment.
  110.         ! pop      es
  111.         '------------------------------------------------------------------
  112.         ' set up our DTA
  113.         ! push      ds
  114.         ! mov      dx,ourdtaoff            ; put location in DS:DX
  115.         ! mov      ds,ourdtaseg
  116.         ! mov       ah, &h1A              ; DOS function: Set DTA
  117.         ! int       &h21                  ; call DOS
  118.         ! pop      ds
  119.         '------------------------------------------------------------------
  120.         ' Now we set up the DOS call to find first.
  121.         ' DOS exspect the address of the spec in DS:DX and the
  122.         ' 8 bit atribute in CX.
  123.         '------------------------------------------------------------------
  124.         ! push      ds                    ; save data segment
  125.         ! xor       cx,cx                 ; Zero the top half.
  126.         ! mov       cl, a?
  127.         ! mov      dx, specoff            ; put location in DS:DX
  128.         ! mov      ds, specseg
  129.         '------------------------------------------------------------------
  130.  
  131.         ! mov       ax,&h4E00             ; DOS FIND FIRST function.
  132.         '------------------------------------------------------------------
  133.         ! int       &h21                  ; Call DOS
  134.         ! pop      ds                    ; restore data seg
  135.         ' Error code (if carry flag set) will be returned in AX.
  136.         ! jnc       ahnuts1               ; If no error
  137.         ! mov      ourerr,ax             ; Save the error code
  138.         '------------------------------------------------------------------
  139. ahnuts1:
  140.          ' restore PB3's DTA.
  141.         ! push    ds                      ; Save our data segment
  142.         ! mov     ax, olddtaseg           ; Place new data segment in AX.
  143.         ! mov     dx, olddtaoff           ; Place new offset in DX.
  144.         ! mov     ds, ax                  ; Set the data segment.
  145.         ! mov     ah, &h1A                ; point DOS to our static DTA
  146.         ! int     &h21                    ; call DOS
  147.         ! pop     ds                      ; restore our data segment
  148.         '------------------------------------------------------------------
  149.         ' Our DTA should now contain the information we desire.
  150.         spec$=""
  151.         if ourerr<>0 then FileInfo$ = "" : exit function
  152.         spec$=ourdta.filename
  153.         t$=""
  154.         for i%=1 to len(spec$)
  155.             c$=mid$(spec$,i%,1)
  156.             if c$>chr$(32) then t$=t$+c$
  157.         next i%
  158.         Spec$=left$(t$+space$(25),15)
  159.         ' fill in the date$
  160.         ' I have chosen to format the DateTime$ in order from year to seconds
  161.         ' This was done to make it easy to compare the dates of two files
  162.         ' or to sort a list of files by date and time.
  163.         temp1 = ourdta.filedate
  164.         ! mov       ax, temp1                  ; Retrieve file date
  165.         ! push      ax
  166.         ! push      ax
  167.         ! and       ax, &b0000000000011111  ; Mask off the day.
  168.          ! mov      temp1,ax
  169.         ! pop      ax
  170.         ! and       ax, &b0000000111100000  ; Mask off the month
  171.         ! mov       cl, 5                   ; We rotate the Month to the right
  172.         ! ror       ax,cl                   ; 5 bits.
  173.         ! mov       temp2,ax
  174.         ! pop      ax
  175.         ! and       ax, &b1111111000000000  ; Mask off the year
  176.         ! mov       cl, 7                   ; We rotate the year to the left
  177.         ! rol       ax,cl                   ; 7 bits.
  178.         ! add       ax,1980                 ; Add the base year 1980 to AX.
  179.         ! mov      temp3,ax
  180.         Spec$ = spec$ + val2str$(temp3,4)+"-"+val2str$(temp2,2)+"-"+val2str(temp1,2)+ "  "
  181.         ' fill in the time
  182.         temp1 = ourdta.filetime
  183.         ! mov       ax, temp1             ; Retrieve file time.
  184.         ! push      ax
  185.         ! push      ax
  186.         ! and       ax, &b0000000000011111  ; Mask off the seconds.
  187.         ! rol       ax,1                    ; DOS stores time in 2 sec increments.
  188.         ! mov      temp1,ax
  189.         ! pop      ax
  190.         ! and       ax, &b0000011111100000  ; Mask off the minutes.
  191.         ! mov       cl, 5                   ; We rotate minutes to the right
  192.         ! ror       ax, cl                  ; 5 bits.
  193.         ! mov      temp2,ax
  194.         ! pop       ax
  195.         ! and       ax, &b1111100000000000  ; Mask off the hours
  196.         ! mov       cl, 5                   ; We rotate hours to the left
  197.         ! rol       ax, cl                  ; 5 bits.
  198.         ! mov       temp3,ax
  199.         Spec$ = Spec$+val2str$(temp3,2)+":"+val2str$(temp2,2)+":"+val2str(temp1,2)+"  "
  200.         Spec$ = Spec$+val2str$(ourdta.FileSize,9)
  201.         FileInfo$=Spec$
  202. end function
  203.  
  204. ' -----------------------------------------------------------------------------
  205. function val2str$(v???,digits%)
  206.     val2str$=right$((string$(digits%,"0")+ltrim$(str$(v???))),digits%)
  207. end function
  208. ' -EOF------------------------------------------------------------------------
  209.