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

  1.  
  2. ;    FILENAME: OFILREAD.ASM
  3. ;    Copyright (c) 1988 by Borland International, Inc.
  4. ;
  5. ;    Description: This module implements the routine FileRead. FileRead
  6. ;    reads from a file.
  7. ;
  8. ;    ASSEMBLY INSTRUCTIONS: To assemble this module use the following 
  9. ;    TASM command line. 
  10. ;        TASM ofilread
  11.  
  12. include globals.inc
  13.  
  14. _TEXT   segment
  15.  
  16.     FileRead proc
  17.  
  18.     ;    Input 
  19.     ;        bx - file record offset
  20.     ;        cx - buffer size
  21.     ;        di - location of bytes
  22.     ;    Output
  23.     ;        cf - set if error occurred
  24.     ;        ax - error code
  25.     ;        (cf set and ax = 0 if EOF)
  26.     ;            0 - if EOF and 0 bytes are read
  27.     ;        cx - number of bytes read
  28.     ;    Registers modified
  29.     ;        None
  30.  
  31.     pushf
  32.     push    cx
  33.     push    dx
  34.     push    di
  35.     push    si
  36.     cld
  37.     mov     dx, [bx+6]      ;buffer segment
  38.  
  39.     ;--- read bytes from buffer
  40.  
  41. filred1:
  42.     mov     ax, [bx+10]     ;bytes in buffer
  43.     mov     si, [bx+4]      ;data pointer
  44.     sub     ax, si          ;bytes available
  45.     jz      filred3         ;jump if none
  46.  
  47.     push    ds
  48.     push    cx
  49.     cmp     ax, cx          ;check if enough
  50.     jae     filred2
  51.     mov     cx, ax          ;read what's available
  52.  
  53. filred2:
  54.     push    cx
  55.     mov     ds, dx
  56.     rep     movsb                   ;copy bytes
  57.     pop     ax
  58.     pop     cx
  59.     pop     ds
  60.     mov     [bx+4], si      ;save data pointer
  61.     sub     cx, ax          ;get bytes not yet read
  62.     jz      filred4         ;jump if finished
  63.  
  64.     ;--- read into buffer
  65.  
  66. filred3:
  67.     call    FileFill        ;read a buffer full
  68.     jnc     filred1
  69.  
  70.     ;--- finished
  71.  
  72. filred4:
  73.     pop     si
  74.     pop     di
  75.     pop     dx
  76.     pop     cx
  77.     jc      filred5
  78.     popf
  79.     clc
  80.     ret
  81.  
  82. filred5:
  83.     popf
  84.     stc
  85.     ret
  86.     FileRead endp
  87.  
  88. _TEXT    ends
  89.  
  90. end
  91.