Subversion Repositories Kolibri OS

Rev

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