Subversion Repositories Kolibri OS

Rev

Rev 755 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
220 heavyiron 1
; flat assembler
542 diamond 2
; Copyright (c) 1999-2007, Tomasz Grysztar
31 halyavin 3
; All rights reserved.
4
 
182 serge 5
struc FILEIO
6
{   .cmd            dd ?
7
    .offset         dd ?
8
                    dd ?
9
    .count          dd ?
10
    .buff           dd ?
11
                    db ?
12
    .name           dd ?
13
};
14
 
15
struc FILEINFO
16
{   .attr           dd ?
17
    .flags          dd ?
18
    .cr_time        dd ?
19
    .cr_date        dd ?
20
    .acc_time       dd ?
21
    .acc_date       dd ?
22
    .mod_time       dd ?
23
    .mod_date       dd ?
24
    .size           dd ?
25
}
26
 
27
 
28
 
29
;file_info_open:  dd 0,0,0xffffff,0x20000,0xf0000
174 heavyiron 30
fullpath_open:  ;  db '/RD/1/EXAMPLE.ASM'
31 halyavin 31
		    times MAX_PATH db 0
32
 
174 heavyiron 33
 
182 serge 34
;file_info_write: dd 1,0,0,0,0xf0000
174 heavyiron 35
fullpath_write:; db '/RD/1/EXAMPLE'
31 halyavin 36
		    times MAX_PATH db 0
37
 
542 diamond 38
file_info_start:
174 heavyiron 39
    dd 7
40
    dd 0
41
    dd 0
42
    dd 0
43
    dd 0
44
fullpath_start:  ; db '/RD/1/EXAMPLE'
31 halyavin 45
		    times MAX_PATH db 0
46
 
542 diamond 47
file_info_debug:
48
	dd	7
49
	dd	0
50
	dd	fullpath_start
51
	dd	0, 0
52
	db	'/SYS/DEVELOP/MTDBG',0
53
 
54
_ramdisk	 db '/RD/1/'
31 halyavin 55
filepos 	 dd 0x0
56
 
835 serge 57
 
31 halyavin 58
init_memory:
835 serge 59
 
60
        mov ecx, 16*1024*1024
61
 
62
 allocate_memory:
63
	mov	[memory_setting],ecx
755 diamond 64
	mcall	68, 12
835 serge 65
	or	eax,eax
66
	jz	out_of_memory
67
	mov	[additional_memory],eax
68
	add	eax,[memory_setting]
755 diamond 69
	mov	[memory_end],eax
835 serge 70
	mov	eax,[memory_setting]
71
	shr	eax,2
72
	add	eax,[additional_memory]
73
	mov	[additional_memory_end],eax
74
	mov	[memory_start],eax
31 halyavin 75
	ret
76
 
77
exit_program:
78
	cmp	[_mode],NORMAL_MODE
635 diamond 79
	jne	@f
755 diamond 80
	mcall	68, 13, [memblock]
635 diamond 81
	jmp	still
82
@@:
31 halyavin 83
	or	eax,-1
485 heavyiron 84
	mcall
31 halyavin 85
 
86
make_timestamp:
87
	push	ebx
88
	mcall	26,9
89
	imul	eax,10
90
	pop	ebx
91
	ret
92
 
93
get_environment_variable:
94
	mov	ecx,[memory_end]
95
	sub	ecx,edi
96
	cmp	ecx,7
97
	jb	out_of_memory
98
	cmp	dword[esi],'INCL'
99
	jne	.finish
100
	mov	esi,_ramdisk
101
	mov	ecx,6
102
	cld
103
	rep	movsb
104
  .finish:
105
;       stc
106
	ret
107
 
332 diamond 108
alloc_handle:
109
        call    make_fullpaths
110
        mov     ebx, fileinfos+4
111
@@:
112
        cmp     dword [ebx], -1
113
        jz      .found
114
        add     ebx, 4+20+MAX_PATH
115
        cmp     ebx, fileinfos_end
116
        jb      @b
117
        stc
118
        ret
119
.found:
120
        and     dword [ebx+4], 0
121
        and     dword [ebx+8], 0
122
        push    esi edi ecx
123
        mov     esi, fullpath_open
124
        lea     edi, [ebx+20]
125
        mov     ecx, MAX_PATH
126
        rep     movsb
127
        pop     ecx edi esi
128
        ret	; CF=0
31 halyavin 129
 
130
create:
332 diamond 131
        call    alloc_handle
132
        jc      .ret
133
        and     dword [ebx-4], 0
134
        mov     dword [ebx], 2
135
.ret:
136
        ret
31 halyavin 137
 
182 serge 138
 
139
open:
140
;        call    make_fullpaths
141
 
142
;;       mov     eax,fullpath_open
143
;;       DEBUGF  '"%s"\n',eax
144
 
145
;        mov     dword[file_info_open+8],-1
146
;        mcall   58,file_info_open
147
;        or      eax,eax                 ; found
148
;        jz      @f
149
;        cmp     eax,6
150
;        jne     file_error
151
;@@: mov [filesize],ebx
152
;        clc
153
;        ret
154
;file_error:
155
;        stc
156
;        ret
157
 
332 diamond 158
        call    alloc_handle
159
        jc      .ret
160
        mov     dword [ebx], 5
161
        and     dword [ebx+12], 0
162
        mov     dword [ebx+16], fileinfo
163
        mov     eax, 70
164
        push    ebx
485 heavyiron 165
        mcall
332 diamond 166
        pop     ebx
167
        test    eax, eax
168
        jnz     .fail
169
        mov     eax, [fileinfo.size]
170
        mov     [ebx-4], eax
171
        and     dword [ebx], 0
172
.ret:
173
        ret
182 serge 174
.fail:
332 diamond 175
	or	dword [ebx], -1	; close handle
176
        stc
177
        ret
182 serge 178
 
179
read:
180
;          pusha
181
;          mov     edi,edx
182
;          mov     esi,[filepos]
183
;          add     esi,0x20000
184
;          cld
185
;          rep     movsb
186
;          popa
187
;;         ret
188
 
332 diamond 189
        mov     [ebx+12], ecx
190
        mov     [ebx+16], edx
191
        push    ebx
192
        mov     eax, 70
485 heavyiron 193
        mcall
332 diamond 194
        xchg    eax, [esp]
195
        add     [eax+4], ebx
196
        adc     [eax+8], dword 0
197
        mov     ebx, eax
198
        pop     eax
199
        test    eax, eax
200
        jz      .ok
201
        cmp     eax, 6
202
        jz      .ok
203
        stc
204
.ok:
205
        ret
206
 
182 serge 207
close:
332 diamond 208
        or      dword [ebx], -1
209
        ret
182 serge 210
 
211
 
31 halyavin 212
; ebx file handle
213
; ecx count of bytes to write
214
; edx pointer to buffer
215
write:
182 serge 216
;        pusha
217
;        mov     [file_info_write+8],ecx
218
;        mov     [file_info_write+12],edx
219
;        mov     [filesize],edx
220
;        mov     eax,58
221
;        mov     ebx,file_info_write
485 heavyiron 222
;        mcall
182 serge 223
;        popa
224
;        ret
31 halyavin 225
 
332 diamond 226
        mov     [ebx+12], ecx
227
        mov     [ebx+16], edx
228
        push    ebx
229
        mov     eax, 70
485 heavyiron 230
        mcall
332 diamond 231
        xchg    eax, [esp]
232
        add     [eax+4], ebx
233
        adc     [eax+8], dword 0
234
        mov     ebx, eax
235