Changeset 51 in xtideuniversalbios for trunk/Assembly_Library/Src/File/FileIO.asm


Ignore:
Timestamp:
Oct 11, 2010, 8:27:43 AM (14 years ago)
Author:
aitotat
google:author:
aitotat
Message:

Changes to Assembly Library:
File handle is now properly returned when opening file.
Added function for getting file size by using file handle.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Assembly_Library/Src/File/FileIO.asm

    r50 r51  
    22; Project name  :   Assembly Library
    33; Created date  :   1.9.2010
    4 ; Last update   :   8.10.2010
     4; Last update   :   10.10.2010
    55; Author        :   Tomi Tilli
    66; Description   :   Functions for file access.
     
    2828    int     DOS_INTERRUPT_21h
    2929    xchg    si, dx
     30    mov     bx, ax      ; Copy file handle to BX
    3031    ret
    3132
     
    6869ALIGN JUMP_ALIGN
    6970FileIO_ReadCXbytesToDSSIusingHandleFromBX:
    70     xchg    dx, si              ; DS:DX now points to source buffer
     71    xchg    dx, si              ; DS:DX now points to destination buffer
    7172    mov     ah, READ_FROM_FILE_OR_DEVICE
    7273    int     DOS_INTERRUPT_21h
     
    102103
    103104;--------------------------------------------------------------------
     105; FileIO_GetFileSizeToDXAXusingHandleFromBXandResetFilePosition:
     106;   Parameters:
     107;       BX:     File handle
     108;   Returns:
     109;       DX:AX:  Signed file size (if CF cleared)
     110;       AX:     DOS error code (if CF set)
     111;       CF:     Clear if successfull
     112;               Set if error
     113;   Corrupts registers:
     114;       Nothing
     115;--------------------------------------------------------------------
     116ALIGN JUMP_ALIGN
     117FileIO_GetFileSizeToDXAXusingHandleFromBXandResetFilePosition:
     118    push    cx
     119
     120    ; Get file size to DX:AX
     121    xor     cx, cx
     122    xor     dx, dx
     123    mov     al, SEEK_FROM.endOfFile
     124    call    FileIO_SeekFromOriginInALtoOffsetInDXAXusingHandleFromBX
     125    jc      SHORT .ReturnFileError
     126    push    dx
     127    push    ax
     128
     129    ; Reset file position
     130    xor     dx, dx
     131    mov     al, SEEK_FROM.startOfFile
     132    call    FileIO_SeekFromOriginInALtoOffsetInDXAXusingHandleFromBX
     133    pop     ax
     134    pop     dx
     135
     136.ReturnFileError:
     137    pop     cx
     138    ret
     139
     140
     141;--------------------------------------------------------------------
    104142; FileIO_SeekFromOriginInALtoOffsetInDXAXusingHandleFromBX:
    105143;   Parameters:
    106144;       AL:     SEEK_FROM.(origin)
    107145;       BX:     File handle
    108 ;       DX:AX:  Seek offset (signed)
     146;       CX:DX:  Signed offset to seek starting from AL
    109147;   Returns:
    110 ;       AX:     DOS error code if CF set
     148;       DX:AX:  New file position in bytes from start of file (if CF cleared)
     149;       AX:     DOS error code (if CF set)
    111150;       CF:     Clear if successfull
    112151;               Set if error
     
    116155ALIGN JUMP_ALIGN
    117156FileIO_SeekFromOriginInALtoOffsetInDXAXusingHandleFromBX:
    118     push    dx
    119     push    cx
    120 
    121     mov     cx, dx              ; DOS wants high word in CX
    122     xchg    dx, ax              ; DOS wants low word in DX
    123157    mov     ah, SET_CURRENT_FILE_POSITION
    124158    int     DOS_INTERRUPT_21h
    125 
    126     pop     cx
    127     pop     dx
    128159    ret
Note: See TracChangeset for help on using the changeset viewer.