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

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

Initial commit for Assembly Library.

File size: 3.8 KB
RevLine 
[41]1; File name : FileIO.asm
2; Project name : Assembly Library
3; Created date : 1.9.2010
4; Last update : 3.9.2010
5; Author : Tomi Tilli
6; Description : Functions for file access.
7
8
9; File access and sharing modes
10struc FILE_ACCESS
11 .ReadOnly resb 1
12 .WriteOnly resb 1
13 .ReadAndWrite resb 1
14endstruc
15
16; Origin of file seek
17struc SEEK_FROM
18 .startOfFile resb 1
19 .currentFilePosition resb 1
20 .endOfFile resb 1
21endstruc
22
23
24; Section containing code
25SECTION .text
26
27;--------------------------------------------------------------------
28; FileIO_OpenWithPathInDSSIandFileAccessInAL
29; Parameters:
30; AL: FILE_ACCESS.(mode)
31; DS:SI: Ptr to NULL terminated path or file name
32; Returns:
33; AX: DOS error code if CF set
34; BX: File handle if CF cleared
35; CF: Clear if file opened successfully
36; Set if error
37; Corrupts registers:
38; AX, BX
39;--------------------------------------------------------------------
40ALIGN JUMP_ALIGN
41FileIO_OpenWithPathInDSSIandFileAccessInAL:
42 xchg dx, si ; Path now in DS:DX
43 mov ah, OPEN_EXISTING_FILE
44 int DOS_INTERRUPT_21h
45 xchg si, dx
46 ret
47
48
49;--------------------------------------------------------------------
50; FileIO_CloseUsingHandleFromBX
51; Parameters:
52; BX: File handle
53; Returns:
54; AX: DOS error code if CF set
55; CF: Clear if file closed successfully
56; Set if error
57; Corrupts registers:
58; AX
59;--------------------------------------------------------------------
60ALIGN JUMP_ALIGN
61FileIO_CloseUsingHandleFromBX:
62 mov ah, CLOSE_FILE
63 int DOS_INTERRUPT_21h
64 ret
65
66
67;--------------------------------------------------------------------
68; File position is updated so next read will start where
69; previous read stopped.
70;
71; FileIO_ReadCXbytesToDSSIusingHandleFromBX
72; Parameters:
73; BX: File handle
74; CX: Number of bytes to read
75; DS:SI: Ptr to destination buffer
76; Returns:
77; AX: Number of bytes actually read if successfull (0 if at EOF before call)
78; DOS error code if CF set
79; CF: Clear if successfull
80; Set if error
81; Corrupts registers:
82; Nothing
83;--------------------------------------------------------------------
84ALIGN JUMP_ALIGN
85FileIO_ReadCXbytesToDSSIusingHandleFromBX:
86 xchg dx, si ; DS:DX now points to source buffer
87 mov ah, READ_FROM_FILE_OR_DEVICE
88 int DOS_INTERRUPT_21h
89 xchg si, dx
90 ret
91
92
93;--------------------------------------------------------------------
94; File position is updated so next write will start where
95; previous write stopped.
96;
97; FileIO_WriteCXbytesFromDSSIusingHandleFromBX:
98; Parameters:
99; BX: File handle
100; CX: Number of bytes to write
101; DS:SI: Ptr to source buffer
102; Returns:
103; AX: Number of bytes actually written if successfull (EOF check)
104; DOS error code if CF set
105; CF: Clear if successfull
106; Set if error
107; Corrupts registers:
108; Nothing
109;--------------------------------------------------------------------
110ALIGN JUMP_ALIGN
111FileIO_WriteCXbytesFromDSSIusingHandleFromBX:
112 xchg dx, si ; DS:DX now points to source buffer
113 mov ah, WRITE_TO_FILE_OR_DEVICE
114 int DOS_INTERRUPT_21h
115 xchg si, dx
116 ret
117
118
119;--------------------------------------------------------------------
120; FileIO_SeekFromOriginInALtoOffsetInDXAXusingHandleFromBX:
121; Parameters:
122; AL: SEEK_FROM.(origin)
123; BX: File handle
124; DX:AX: Seek offset (signed)
125; Returns:
126; AX: DOS error code if CF set
127; CF: Clear if successfull
128; Set if error
129; Corrupts registers:
130; Nothing
131;--------------------------------------------------------------------
132ALIGN JUMP_ALIGN
133FileIO_SeekFromOriginInALtoOffsetInDXAXusingHandleFromBX:
134 push dx
135 push cx
136
137 mov cx, dx ; DOS wants high word in CX
138 xchg dx, ax ; DOS wants low word in DX
139 mov ah, SET_CURRENT_FILE_POSITION
140 int DOS_INTERRUPT_21h
141
142 pop cx
143 pop dx
144 ret
Note: See TracBrowser for help on using the repository browser.