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

Last change on this file since 50 was 50, checked in by aitotat, 13 years ago

Changes to Assembly Library:
Removed Memory_ExchangeSSBPwithESDI since it obviously corrupted stack.
CGA detection is now only done once when initializing Display Context.
Moved File Library defines to File.inc.

File size: 3.5 KB
Line 
1; File name     :   FileIO.asm
2; Project name  :   Assembly Library
3; Created date  :   1.9.2010
4; Last update   :   8.10.2010
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
30    ret
31
32
33;--------------------------------------------------------------------
34; FileIO_CloseUsingHandleFromBX
35;   Parameters:
36;       BX:     File handle
37;   Returns:
38;       AX:     DOS error code if CF set
39;       CF:     Clear if file closed successfully
40;               Set if error
41;   Corrupts registers:
42;       AX
43;--------------------------------------------------------------------
44ALIGN JUMP_ALIGN
45FileIO_CloseUsingHandleFromBX:
46    mov     ah, CLOSE_FILE
47    int     DOS_INTERRUPT_21h
48    ret
49
50
51;--------------------------------------------------------------------
52; File position is updated so next read will start where
53; previous read stopped.
54; 
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:
70    xchg    dx, si              ; DS:DX now points to source buffer
71    mov     ah, READ_FROM_FILE_OR_DEVICE
72    int     DOS_INTERRUPT_21h
73    xchg    si, dx
74    ret
75
76
77;--------------------------------------------------------------------
78; File position is updated so next write will start where
79; previous write stopped.
80; 
81; FileIO_WriteCXbytesFromDSSIusingHandleFromBX:
82;   Parameters:
83;       BX:     File handle
84;       CX:     Number of bytes to write
85;       DS:SI:  Ptr to source buffer
86;   Returns:
87;       AX:     Number of bytes actually written if successfull (EOF check)
88;               DOS error code if CF set
89;       CF:     Clear if successfull
90;               Set if error
91;   Corrupts registers:
92;       Nothing
93;--------------------------------------------------------------------
94ALIGN JUMP_ALIGN
95FileIO_WriteCXbytesFromDSSIusingHandleFromBX:
96    xchg    dx, si              ; DS:DX now points to source buffer
97    mov     ah, WRITE_TO_FILE_OR_DEVICE
98    int     DOS_INTERRUPT_21h
99    xchg    si, dx
100    ret
101
102
103;--------------------------------------------------------------------
104; FileIO_SeekFromOriginInALtoOffsetInDXAXusingHandleFromBX:
105;   Parameters:
106;       AL:     SEEK_FROM.(origin)
107;       BX:     File handle
108;       DX:AX:  Seek offset (signed)
109;   Returns:
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_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
123    mov     ah, SET_CURRENT_FILE_POSITION
124    int     DOS_INTERRUPT_21h
125
126    pop     cx
127    pop     dx
128    ret
Note: See TracBrowser for help on using the repository browser.