home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / DISK1.ASM < prev    next >
Assembly Source File  |  1994-11-15  |  3KB  |  135 lines

  1.     page    66,132
  2. ;******************************** DISK1.ASM  *********************************
  3.  
  4. LIBSEG           segment byte public "LIB"
  5.         assume cs:LIBSEG , ds:nothing
  6.  
  7. ;----------------------------------------------------------------------------
  8. .xlist
  9.     include  mac.inc
  10.     include  common.inc
  11. .list
  12. ;----------------------------------------------------------------------------
  13.     extrn    dos_mem_allocate:far
  14.     extrn    dos_mem_release:far
  15. comment 
  16. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  DISK   )
  17. FILE_COPY - copy a file
  18. ;
  19. ; inputs:    DS:[SI] = address of source filename
  20. ;            ES:[DI] = address of destination filename
  21. ;            Both filenames must be ASCIIZ strings.
  22. ;            
  23. ; output:    if CF = 0, no problem
  24. ;            if CF = 1, AX = DOS error code (AX = -1 if insufficient memory)
  25. ;            All registers unchanged except for -AX-
  26. ;* * * * * * * * * * * * * *
  27. 
  28. fc_date1    dw    0    ;file date
  29. fc_date2    dw    0    ;file date
  30.  
  31.     public    FILE_COPY
  32. FILE_COPY    PROC    FAR
  33.     apush    ax,bx,cx,dx,si,di,ds,es
  34.     mov    ax,3d00h
  35.     int    21h            ;open input file
  36.     jc    fc_error1        ; jmp if open error
  37.     mov    si,ax            ;save file handle
  38.  
  39.     mov    dx,cx
  40.     mov    ah,3ch
  41.     xor    cx,cx
  42.     int    21h            ;create output file
  43.     jc    fc_error2        ;  jmp if create error
  44.     mov    di,ax            ;save file handle
  45.     
  46.     mov    bx,si
  47.     mov    ax,5700h
  48.     int    21h            ;get input file date
  49.     mov    cs:fc_date1,cx
  50.     mov    cs:fc_date2,dx
  51.         
  52.     mov    dx,0
  53.     mov    ax,-1
  54.     call    dos_mem_allocate    ;allocate memory
  55.     jc    fc_error3        ;  jmp if out of memory
  56.  
  57.     push    es
  58.     pop    ds            ;es & ds point at allocated memory
  59. ;
  60. ; setup to read & write data
  61. ;
  62.     mov    cx,-1            ;number of bytes to read
  63.     xor    dx,dx            ;ds:dx = buffer pointer
  64. ;
  65. ; read loop, bx=file handle,  cx=read buffer size  ds:dx = buffer pointer
  66. ;    
  67. fc_loop:mov    bx,si            ;get file handle
  68.     mov    ah,3fh
  69.     int    21h            ;read file
  70.     jc    fc_error4        ;  jmp if read error
  71.     cmp    ax,0            ;check if any data read
  72.     je    fc_done            ;  jmp if all done
  73.     
  74.     mov    cx,ax
  75.     mov    ah,40h
  76.     mov    bx,di            ;get file handle
  77.     int    21h            ;write data
  78.     jc    fc_error4        ;  jmp if error
  79.     cmp    ax,cx
  80.     jne    fc_error4
  81.     cmp    cx,-1
  82.     je    fc_loop            ;loop till done
  83. ;
  84. ; file has been copied, set date of new file
  85. ;    
  86. fc_done:    
  87.     mov    bx,di            ;get output file handle
  88.     mov    cx,cs:fc_date1
  89.     mov    dx,cs:fc_date2
  90.     mov    ax,5701h        ;set file date
  91.     int    21h            ;
  92.     clc
  93.     jmp    fc_getout1
  94.     
  95. fc_error3:
  96.     call    fc_close1        ;close both files
  97.     mov    al,7
  98.     jmp    fc_errc
  99.     
  100. fc_error2:
  101.     call    fc_close2        ;close the input file
  102. fc_error1:
  103. fc_errc:    
  104.     stc
  105.     jmp    fc_getout3
  106.  
  107. fc_error4:
  108.     stc
  109. fc_getout1:
  110.     pushf    
  111.     call    fc_close1        ;close both files
  112.     popf
  113. fc_getout2:
  114.     pushf    
  115.     call    dos_mem_release
  116.     popf
  117. fc_getout3:    
  118.     apop    es,ds,di,si,dx,cx,bx,ax
  119.     retf
  120. FILE_COPY    ENDP
  121. ;------------------------------------
  122.  
  123. fc_close1:
  124.     mov    bx,di            ;file2 handle
  125.     mov    ah,3eh
  126.     int    21h
  127. fc_close2:    
  128.     mov    bx,si            ;file1 handle
  129.     mov    ah,3eh
  130.     int    21h
  131.     ret    
  132.  
  133. LIBSEG    ENDS
  134.     end
  135.