source: xtideuniversalbios/trunk/Assembly_Library/Src/File/FileIO.asm@ 57

Last change on this file since 57 was 51, checked in by Tomi Tilli, 14 years ago

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

File size: 4.4 KB
RevLine 
[41]1; File name : FileIO.asm
2; Project name : Assembly Library
3; Created date : 1.9.2010
[51]4; Last update : 10.10.2010
[41]5; Author : Tomi Tilli
6; Description : Functions for file access.
7
8; Section containing code
9SECTION .text
10
11;--------------------------------------------------------------------
12; FileIO_OpenWithPathInDSSIandFileAccessInAL
13; Parameters:
14; AL: FILE_ACCESS.(mode)
15; DS:SI: Ptr to NULL terminated path or file name
16; Returns:
17; AX: DOS error code if CF set
18; BX: File handle if CF cleared
19; CF: Clear if file opened successfully
20; Set if error
21; Corrupts registers:
22; AX, BX
23;--------------------------------------------------------------------
24ALIGN JUMP_ALIGN
25FileIO_OpenWithPathInDSSIandFileAccessInAL:
26 xchg dx, si ; Path now in DS:DX
27 mov ah, OPEN_EXISTING_FILE
28 int DOS_INTERRUPT_21h
29 xchg si, dx
[51]30 mov bx, ax ; Copy file handle to BX
[41]31 ret
32
33
34;--------------------------------------------------------------------
35; FileIO_CloseUsingHandleFromBX
36; Parameters:
37; BX: File handle
38; Returns:
39; AX: DOS error code if CF set
40; CF: Clear if file closed successfully
41; Set if error
42; Corrupts registers:
43; AX
44;--------------------------------------------------------------------
45ALIGN JUMP_ALIGN
46FileIO_CloseUsingHandleFromBX:
47 mov ah, CLOSE_FILE
48 int DOS_INTERRUPT_21h
49 ret
50
51
52;--------------------------------------------------------------------
53; File position is updated so next read will start where
54; previous read stopped.
55;
56; FileIO_ReadCXbytesToDSSIusingHandleFromBX
57; Parameters:
58; BX: File handle
59; CX: Number of bytes to read
60; DS:SI: Ptr to destination buffer
61; Returns:
62; AX: Number of bytes actually read if successfull (0 if at EOF before call)
63; DOS error code if CF set
64; CF: Clear if successfull
65; Set if error
66; Corrupts registers:
67; Nothing
68;--------------------------------------------------------------------
69ALIGN JUMP_ALIGN
70FileIO_ReadCXbytesToDSSIusingHandleFromBX:
[51]71 xchg dx, si ; DS:DX now points to destination buffer
[41]72 mov ah, READ_FROM_FILE_OR_DEVICE
73 int DOS_INTERRUPT_21h
74 xchg si, dx
75 ret
76
77
78;--------------------------------------------------------------------
79; File position is updated so next write will start where
80; previous write stopped.
81;
82; FileIO_WriteCXbytesFromDSSIusingHandleFromBX:
83; Parameters:
84; BX: File handle
85; CX: Number of bytes to write
86; DS:SI: Ptr to source buffer
87; Returns:
88; AX: Number of bytes actually written if successfull (EOF check)
89; DOS error code if CF set
90; CF: Clear if successfull
91; Set if error
92; Corrupts registers:
93; Nothing
94;--------------------------------------------------------------------
95ALIGN JUMP_ALIGN
96FileIO_WriteCXbytesFromDSSIusingHandleFromBX:
97 xchg dx, si ; DS:DX now points to source buffer
98 mov ah, WRITE_TO_FILE_OR_DEVICE
99 int DOS_INTERRUPT_21h
100 xchg si, dx
101 ret
102
103
104;--------------------------------------------------------------------
[51]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;--------------------------------------------------------------------
[41]142; FileIO_SeekFromOriginInALtoOffsetInDXAXusingHandleFromBX:
143; Parameters:
144; AL: SEEK_FROM.(origin)
145; BX: File handle
[51]146; CX:DX: Signed offset to seek starting from AL
[41]147; Returns:
[51]148; DX:AX: New file position in bytes from start of file (if CF cleared)
149; AX: DOS error code (if CF set)
[41]150; CF: Clear if successfull
151; Set if error
152; Corrupts registers:
153; Nothing
154;--------------------------------------------------------------------
155ALIGN JUMP_ALIGN
156FileIO_SeekFromOriginInALtoOffsetInDXAXusingHandleFromBX:
157 mov ah, SET_CURRENT_FILE_POSITION
158 int DOS_INTERRUPT_21h
159 ret
Note: See TracBrowser for help on using the repository browser.