home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / basic / library / qb_pds / qb_lib / qbcopy.asm < prev    next >
Encoding:
Assembly Source File  |  1990-07-22  |  6.0 KB  |  149 lines

  1. ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. ;
  3. ;       Name    - QBCOPY.OBJ
  4. ;
  5. ;       Revised - 07/22/90 03:36pm
  6. ;
  7. ;       Purpose - Allows fairly rapid copying of a file without leaving QB.
  8. ;
  9. ;       This routine should be DECLAREd in your program as an external 
  10. ;       FUNCTION, via the QuickBASIC statement -
  11. ;
  12. ;             DECLARE FUNCTION( InFile$, OutFile$, Segmt%)
  13. ;
  14. ;       Parms   - The three parameters you must pass to this routine are 
  15. ;               defined as follows -
  16. ;
  17. ;               InFile  - The name (optionally including drive and path specs)
  18. ;                       of the file you wish to copy.  THIS MUST END IN CHR$(0)
  19. ;               OutFile - The name (optionally including drive and path specs
  20. ;                       which need not be the same as InFile) to give to the 
  21. ;                       copy.
  22. ;                       Note that the copy will carry the same file date and 
  23. ;                       time as the InFile original.
  24. ;
  25. ;               The remaining one is, as in the example above, the SEGMENT 
  26. ;               portion of the address of the area to use for the copy.
  27. ;               This corresponds to the SEGMENT address of the array you 
  28. ;               DIMmed (see below for more details).
  29. ;
  30. ;       Returns : There are three possible returns -
  31. ;
  32. ;               0 = no errors were detected
  33. ;               1 = could not open InFile
  34. ;               2 = could not open OutFile
  35. ;               3 = error writing Outfile
  36. ;               4 = error reading InFile
  37. ;
  38. ;       NOTE  : This routine REQUIRES you to DIM an array (as a $DYNAMIC array)
  39. ;               defined as DIM array(1 to 16) AS STRING * 4096) prior to 
  40. ;               invoking this routine.
  41. ;               The purpose of this statement is to provide a CONTIGUOUS AREA
  42. ;               in RAM MEMORY which is a full segment in length.
  43. ;               This, by the way, also simplifies things later in the routine,
  44. ;               when we can make the assumption that, when a full segment of RAM
  45. ;               is allocated, the starting offset of that segment MUST be = 0.
  46. ;
  47. ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  48.  
  49.         .MODEL  MEDIUM,BASIC
  50.     .CODE
  51.  
  52. QBCopy  proc USES DS SI, INFILE:word, OUTFILE:word, ASEG:word
  53. LOCAL   INHANDLE:word, OUTHANDLE:word, ORIGDATE:word, ORIGTIME:word
  54.  
  55.         mov     BX,INFILE               ; Get start address of InFile spec
  56.         mov     DX,[BX+2]               ; Put into DX for function
  57.         mov     AX,03D00h               ; We will attempt to open for READ/ONLY
  58.     int    21h
  59.  
  60.         jnc     Open_OutFile            ; IF CARRY, then error in opening the
  61.         mov     AX,1                    ;       the InFile, so set AX = error
  62.         jmp     short   QBCopy_Exit     ;       code 1, and exit
  63.  
  64. Open_OutFile:
  65.  
  66.         mov     INHANDLE,AX             ; If NO CARRY from above open, AX = the
  67.         mov     BX,AX                   ;       DOS File Handle, which we will both
  68.         mov     AX,5700h                ;       store and put into BX.
  69.     int    21h
  70.  
  71.         mov     ORIGTIME,CX             ; Store the original date and time
  72.         mov     ORIGDATE,DX             ;       of InFile so copy will be same
  73.  
  74.         mov     AH,03Ch                 ; "CREATe FILE" service of int 21h
  75.         mov     BX,OUTFILE              
  76.         xor     CX,CX                   ; Make this a NORMAL file
  77.         mov     DX,[BX+2]               ; DX = offset of OutFile spec
  78.     int    21h
  79.  
  80.         jnc     Start_The_Copy          ; If CARRY, then there was an error in
  81.         mov     AH,03Eh                 ;       CREATing the OutFile, so
  82.         mov     BX,INHANDLE             ;       put the InFile handle into BX
  83.         int     21h                     ;       and close InFile since we won't
  84.         mov     AX,2                    ;       need it
  85.                                         ;       put error code 2 into
  86.         jmp     short QBCopy_Exit       ;       AX,     and exit this routine
  87.  
  88. Start_The_Copy:
  89.  
  90.         mov     OUTHANDLE,AX            ; Store file handle for OutFile
  91.     mov    BX,ASEG
  92.     mov    AX,[BX]
  93.         mov     DS,AX                   ; DS = SEGMENT of PassedArray
  94.  
  95. Read_InFile_Contents:
  96.  
  97.         xor     DX,DX                   ; DS:DX = SEGMENT:0000 for array
  98.         mov     AH,03Fh                 ; "READ FROM FILE" srvc of INT 21h
  99.         mov     BX,INHANDLE             ; Read bytes from InFile
  100.         mov     CX,65520                ; Maximum # to read = 65,220 bytes
  101.     int    21h
  102.  
  103.     jnc    InFile_Read_OK
  104.         mov     AX,4                    ; Return error as per above
  105.     jmp    short QBCopy_Exit
  106.  
  107. InFile_Read_OK:
  108.  
  109.         cmp     AX,0                    ; IF NO CARRY, but AX = 0, then we've
  110.         je      QBCopy_Finished         ;       finished reading the InFile
  111.  
  112. Write_Buffer_Contents:
  113.  
  114.         mov     CX,AX                   ; AX = # bytes actually read above
  115.         xor     DX,DX                   ; DS:DX points at start of buffer again
  116.     mov    BX,OUTHANDLE
  117.         mov     AH,040h                 ; Write CX # bytes to OUTHANDLE
  118.     int    21h
  119.  
  120.         jnc     Read_InFile_Contents    ; If any error, just fall thru and
  121.         mov     AX,3                    ;       close both files
  122.  
  123. QBCopy_Finished:
  124.  
  125.         push    AX                      ; Save AX, which may contain error code
  126.     mov    AH,03Eh
  127.     mov    BX,INHANDLE
  128.         int     21h                     ; Close the InFile
  129.  
  130.         mov     AX,5701h                ; Set the OutFile Date and Time = 
  131.                                         ;       the original
  132.         mov     CX,ORIGTIME             ;       date and time of InFile
  133.     mov    DX,ORIGDATE
  134.     mov    BX,OUTHANDLE
  135.     int    21h
  136.  
  137.     mov    AH,03Eh
  138.     mov    BX,OUTHANDLE
  139.         int     21h                     ; Close the OutFile
  140.         pop     AX                      ; Retrieve entry AX value
  141.  
  142. QBCopy_Exit:
  143.  
  144.     ret
  145.  
  146. QBCopy          ENDP
  147.         END
  148.  
  149. ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++