home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / tasm / oflflush.asm < prev    next >
Assembly Source File  |  1988-08-28  |  2KB  |  80 lines

  1.  
  2. ;    FILENAME: OFLFLUSH.ASM
  3. ;    Copyright (c) 1988 by Borland International, Inc.
  4. ;
  5. ;    Description: This module implements the routine FileFlush. FileFlush
  6. ;    flushes the write buffer.
  7. ;
  8. ;    ASSEMBLY INSTRUCTIONS: To assemble this module use the following 
  9. ;    TASM command line. 
  10. ;        TASM oflflush
  11.  
  12. include globals.inc
  13.  
  14. _TEXT   segment
  15.  
  16.     FileFlush proc
  17.  
  18.     ;    Input 
  19.     ;        bx - file record offset
  20.     ;        cx - number of bytes to write
  21.     ;    Output (of INT 21h, Function 40h)
  22.     ;        cf - set if error occurred
  23.     ;        ax - error code
  24.     ;            0 - if disk full
  25.     ;            5 - if access denied
  26.     ;            6 - if handle invalid or not open
  27.     ;    Registers modified
  28.     ;        ax
  29.  
  30.     push    cx
  31.     push    dx
  32.     push    ds
  33.  
  34.     ;--- check if buffer needs flushing
  35.  
  36.     mov     ax, [bx+8]         ;handle
  37.     lds     cx, [bx+4]         ;data pointer
  38.     or      cx, cx             ;check if any data
  39.     jz      filflu3
  40.  
  41.     ;--- write buffer
  42.  
  43.     mov     WORD PTR es:[bx+4], 0 ;clear data pointer
  44.     push    bx
  45.     mov     bx, ax
  46.     sub     dx, dx             ;start of segment
  47.     mov     ah, 40h            ;function
  48.     int     21h                ;execute
  49.     pop     bx
  50.     jc      filflu2            ;jump if error
  51.     cmp     ax, cx             ;check if all bytes written
  52.     je      filflu3
  53.  
  54.     ;--- finished, error writing buffer
  55.  
  56. filflu1:
  57.     sub     ax, ax             ;code 0 if bytes not all written
  58. filflu2:
  59.     stc
  60.     pop     ds
  61.     pop     dx
  62.     pop     cx
  63.     ret
  64.  
  65.     ;--- finished, no error
  66.  
  67. filflu3:
  68.     clc
  69.     pop     ds
  70.     pop     dx
  71.     pop     cx
  72.     ret
  73.     ret
  74.     FileFlush endp
  75.  
  76. _TEXT    ends
  77.  
  78. end
  79.