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

Last change on this file since 257 was 133, checked in by krille_n_@…, 14 years ago

Size optimizations in various files in the Assembly Library. Also a very small change to a string in XTIDE_Universal_BIOS_Configurator_v2/Src/Strings.asm

File size: 7.3 KB
RevLine 
[41]1; Project name : Assembly Library
2; Description : Functions for file access.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; FileIO_OpenWithPathInDSSIandFileAccessInAL
9; Parameters:
10; AL: FILE_ACCESS.(mode)
11; DS:SI: Ptr to NULL terminated path or file name
12; Returns:
13; AX: DOS error code if CF set
14; BX: File handle if CF cleared
15; CF: Clear if file opened successfully
16; Set if error
17; Corrupts registers:
18; AX, BX
19;--------------------------------------------------------------------
20ALIGN JUMP_ALIGN
21FileIO_OpenWithPathInDSSIandFileAccessInAL:
22 xchg dx, si ; Path now in DS:DX
23 mov ah, OPEN_EXISTING_FILE
24 int DOS_INTERRUPT_21h
25 xchg si, dx
[51]26 mov bx, ax ; Copy file handle to BX
[41]27 ret
28
29
30;--------------------------------------------------------------------
[66]31; FileIO_ReadDXCXbytesToDSSIusingHandleFromBX
32; Parameters:
33; BX: File handle
34; DX:CX: Number of bytes to read
35; DS:SI: Ptr to destination buffer
36; Returns:
37; AX: DOS error code if CF set
38; CF: Clear if successfull
39; Set if error
40; Corrupts registers:
41; AX
42;--------------------------------------------------------------------
43ALIGN JUMP_ALIGN
44FileIO_ReadDXCXbytesToDSSIusingHandleFromBX:
45 push bp
46 mov bp, FileIO_ReadCXbytesToDSSIusingHandleFromBX
47 call SplitLargeReadOrWritesToSmallerBlocks
48 pop bp
49 ret
50
51;--------------------------------------------------------------------
[41]52; File position is updated so next read will start where
53; previous read stopped.
[133]54;
[41]55; FileIO_ReadCXbytesToDSSIusingHandleFromBX
56; Parameters:
57; BX: File handle
58; CX: Number of bytes to read
59; DS:SI: Ptr to destination buffer
60; Returns:
61; AX: Number of bytes actually read if successfull (0 if at EOF before call)
62; DOS error code if CF set
63; CF: Clear if successfull
64; Set if error
65; Corrupts registers:
66; Nothing
67;--------------------------------------------------------------------
68ALIGN JUMP_ALIGN
69FileIO_ReadCXbytesToDSSIusingHandleFromBX:
[51]70 xchg dx, si ; DS:DX now points to destination buffer
[41]71 mov ah, READ_FROM_FILE_OR_DEVICE
72 int DOS_INTERRUPT_21h
73 xchg si, dx
74 ret
75
76
77;--------------------------------------------------------------------
[66]78; FileIO_WriteDXCXbytesFromDSSIusingHandleFromBX
79; Parameters:
80; BX: File handle
81; DX:CX: Number of bytes to write
82; DS:SI: Ptr to source buffer
83; Returns:
84; AX: DOS error code if CF set
85; CF: Clear if successfull
86; Set if error
87; Corrupts registers:
88; AX
89;--------------------------------------------------------------------
90ALIGN JUMP_ALIGN
91FileIO_WriteDXCXbytesFromDSSIusingHandleFromBX:
92 push bp
93 mov bp, FileIO_WriteCXbytesFromDSSIusingHandleFromBX
94 call SplitLargeReadOrWritesToSmallerBlocks
95 pop bp
96 ret
97
98;--------------------------------------------------------------------
[41]99; File position is updated so next write will start where
100; previous write stopped.
[133]101;
[41]102; FileIO_WriteCXbytesFromDSSIusingHandleFromBX:
103; Parameters:
104; BX: File handle
105; CX: Number of bytes to write
106; DS:SI: Ptr to source buffer
107; Returns:
108; AX: Number of bytes actually written if successfull (EOF check)
109; DOS error code if CF set
110; CF: Clear if successfull
111; Set if error
112; Corrupts registers:
113; Nothing
114;--------------------------------------------------------------------
115ALIGN JUMP_ALIGN
116FileIO_WriteCXbytesFromDSSIusingHandleFromBX:
117 xchg dx, si ; DS:DX now points to source buffer
118 mov ah, WRITE_TO_FILE_OR_DEVICE
119 int DOS_INTERRUPT_21h
120 xchg si, dx
121 ret
122
123
124;--------------------------------------------------------------------
[66]125; SplitLargeReadOrWritesToSmallerBlocks
126; Parameters:
127; BX: File handle
128; BP: Ptr to transfer function
129; DX:CX: Number of bytes to transfer
130; DS:SI: Ptr to transfer buffer
131; Returns:
132; AX: DOS error code if CF set
133; CF: Clear if successfull
134; Set if error
135; Corrupts registers:
136; AX
137;--------------------------------------------------------------------
138ALIGN JUMP_ALIGN
139SplitLargeReadOrWritesToSmallerBlocks:
140 push ds
141 push si
142 push dx
143 push cx
144
145 xchg ax, cx ; DX:AX now holds bytes to transfer
146 mov cx, SPLIT_SIZE_FOR_LARGE_TRANSFERS
147 div cx ; AX = Number of full transfers
148 push dx ; Bytes for last transfer
149 test ax, ax
150 jz SHORT .TransferRemainingBytes
151 xchg dx, ax ; DX = Number of full transfers
152
153ALIGN JUMP_ALIGN
154.TransferNextBytes:
[105]155 call NormalizeDSSI
[66]156 call bp ; Transfer function
157 jc SHORT .ErrorOccurredDuringTransfer
[67]158 add si, SPLIT_SIZE_FOR_LARGE_TRANSFERS
[66]159 dec dx
160 jnz SHORT .TransferNextBytes
161.TransferRemainingBytes:
162 pop cx ; CX = Bytes for last transfer
163 jcxz .ReturnErrorCodeInAX ; No remaining bytes
[105]164 call NormalizeDSSI
[66]165 call bp
166.ReturnErrorCodeInAX:
167 pop cx
168 pop dx
169 pop si
170 pop ds
171 ret
172.ErrorOccurredDuringTransfer:
173 pop cx ; Remove bytes for last transfer
174 jmp SHORT .ReturnErrorCodeInAX
175
[105]176;--------------------------------------------------------------------
177; NormalizeDSSI
178; Parameters
179; DS:SI: Ptr to normalize
180; Returns:
181; DS:SI: Normalized pointer
182; Corrupts registers:
183; Nothing
184;--------------------------------------------------------------------
185ALIGN JUMP_ALIGN
186NormalizeDSSI:
187 push dx
188 push ax
189 NORMALIZE_FAR_POINTER ds, si, ax, dx
190 pop ax
191 pop dx
192 ret
[66]193
[105]194
[66]195;--------------------------------------------------------------------
[51]196; FileIO_GetFileSizeToDXAXusingHandleFromBXandResetFilePosition:
197; Parameters:
198; BX: File handle
199; Returns:
200; DX:AX: Signed file size (if CF cleared)
201; AX: DOS error code (if CF set)
202; CF: Clear if successfull
203; Set if error
204; Corrupts registers:
205; Nothing
206;--------------------------------------------------------------------
207ALIGN JUMP_ALIGN
208FileIO_GetFileSizeToDXAXusingHandleFromBXandResetFilePosition:
209 push cx
210
211 ; Get file size to DX:AX
212 xor cx, cx
213 xor dx, dx
214 mov al, SEEK_FROM.endOfFile
215 call FileIO_SeekFromOriginInALtoOffsetInDXAXusingHandleFromBX
216 jc SHORT .ReturnFileError
217 push dx
218 push ax
219
220 ; Reset file position
221 xor dx, dx
222 mov al, SEEK_FROM.startOfFile
223 call FileIO_SeekFromOriginInALtoOffsetInDXAXusingHandleFromBX
224 pop ax
225 pop dx
226
227.ReturnFileError:
228 pop cx
229 ret
230
231
232;--------------------------------------------------------------------
[133]233; FileIO_CloseUsingHandleFromBX
234; Parameters:
235; BX: File handle
236; Returns:
237; AX: DOS error code if CF set
238; CF: Clear if file closed successfully
239; Set if error
240; Corrupts registers:
241; AX
242;--------------------------------------------------------------------
243ALIGN JUMP_ALIGN
244FileIO_CloseUsingHandleFromBX:
245 mov ah, CLOSE_FILE
246 SKIP2B f ; cmp ax, <next instruction>
247 ; Fall to FileIO_SeekFromOriginInALtoOffsetInDXAXusingHandleFromBX
248
249
250;--------------------------------------------------------------------
[41]251; FileIO_SeekFromOriginInALtoOffsetInDXAXusingHandleFromBX:
252; Parameters:
253; AL: SEEK_FROM.(origin)
254; BX: File handle
[51]255; CX:DX: Signed offset to seek starting from AL
[41]256; Returns:
[51]257; DX:AX: New file position in bytes from start of file (if CF cleared)
258; AX: DOS error code (if CF set)
[41]259; CF: Clear if successfull
260; Set if error
261; Corrupts registers:
262; Nothing
263;--------------------------------------------------------------------
264FileIO_SeekFromOriginInALtoOffsetInDXAXusingHandleFromBX:
265 mov ah, SET_CURRENT_FILE_POSITION
266 int DOS_INTERRUPT_21h
267 ret
Note: See TracBrowser for help on using the repository browser.