Subversion Repositories Kolibri OS

Rev

Rev 1689 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1689 Rev 3487
1
;;                                                              ;;
1
;;                                                              ;;
2
;; Copyright (C) KolibriOS team 2004-2009. All rights reserved. ;;
2
;; Copyright (C) KolibriOS team 2004-2009. All rights reserved. ;;
3
;; Distributed under terms of the GNU General Public License    ;;
3
;; Distributed under terms of the GNU General Public License    ;;
4
;;                                                              ;;
4
;;                                                              ;;
5
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6
 
6
 
7
$Revision: 1689 $
7
$Revision: 3487 $
8
 
8
 
9
 
9
 
10
image_of_eax EQU esp+32
10
image_of_eax EQU esp+32
11
image_of_ebx EQU esp+20
11
image_of_ebx EQU esp+20
12
 
12
 
13
; System function 70 - files with long names (LFN)
13
; System function 70 - files with long names (LFN)
14
; diamond, 2006
14
; diamond, 2006
15
 
15
 
16
iglobal
16
iglobal
17
; in this table names must be in lowercase
17
; in this table names must be in lowercase
18
rootdirs:
18
rootdirs:
19
	db	2,'rd'
19
	db	2,'rd'
20
	dd	fs_OnRamdisk
20
	dd	fs_OnRamdisk
21
	dd	fs_NextRamdisk
21
	dd	fs_NextRamdisk
22
	db	7,'ramdisk'
22
	db	7,'ramdisk'
23
	dd	fs_OnRamdisk
23
	dd	fs_OnRamdisk
24
	dd	fs_NextRamdisk
24
	dd	fs_NextRamdisk
25
	db	2,'fd'
-
 
26
	dd	fs_OnFloppy
-
 
27
	dd	fs_NextFloppy
-
 
28
	db	10,'floppydisk'
-
 
29
	dd	fs_OnFloppy
-
 
30
	dd	fs_NextFloppy
-
 
31
	db	3,'hd0'
25
	db	3,'hd0'
32
	dd	fs_OnHd0
26
	dd	fs_OnHd0
33
	dd	fs_NextHd0
27
	dd	fs_NextHd0
34
	db	3,'hd1'
28
	db	3,'hd1'
35
	dd	fs_OnHd1
29
	dd	fs_OnHd1
36
	dd	fs_NextHd1
30
	dd	fs_NextHd1
37
	db	3,'hd2'
31
	db	3,'hd2'
38
	dd	fs_OnHd2
32
	dd	fs_OnHd2
39
	dd	fs_NextHd2
33
	dd	fs_NextHd2
40
	db	3,'hd3'
34
	db	3,'hd3'
41
	dd	fs_OnHd3
35
	dd	fs_OnHd3
42
	dd	fs_NextHd3
36
	dd	fs_NextHd3
43
	db	0
37
	db	0
44
 
38
 
45
 
39
 
46
virtual_root_query:
40
virtual_root_query:
47
	dd	fs_HasRamdisk
41
	dd	fs_HasRamdisk
48
	db	'rd',0
42
	db	'rd',0
49
	dd	fs_HasFloppy
43
	dd	fs_HasFloppy
50
	db	'fd',0
44
	db	'fd',0
51
	dd	fs_HasHd0
45
	dd	fs_HasHd0
52
	db	'hd0',0
46
	db	'hd0',0
53
	dd	fs_HasHd1
47
	dd	fs_HasHd1
54
	db	'hd1',0
48
	db	'hd1',0
55
	dd	fs_HasHd2
49
	dd	fs_HasHd2
56
	db	'hd2',0
50
	db	'hd2',0
57
	dd	fs_HasHd3
51
	dd	fs_HasHd3
58
	db	'hd3',0
52
	db	'hd3',0
59
	dd	0
53
	dd	0
60
 
54
 
61
fs_additional_handlers:
55
fs_additional_handlers:
62
        dd      biosdisk_handler, biosdisk_enum_root
56
        dd      biosdisk_handler, biosdisk_enum_root
63
; add new handlers here
57
; add new handlers here
64
        dd      0
58
        dd      0
65
 
59
 
66
endg
60
endg
67
file_system_lfn:
61
file_system_lfn:
68
; in: ebx->fileinfo block
62
; in: ebx->fileinfo block
69
; operation codes:
63
; operation codes:
70
; 0 : read file
64
; 0 : read file
71
; 1 : read folder
65
; 1 : read folder
72
; 2 : create/rewrite file
66
; 2 : create/rewrite file
73
; 3 : write/append to file
67
; 3 : write/append to file
74
; 4 : set end of file
68
; 4 : set end of file
75
; 5 : get file/directory attributes structure
69
; 5 : get file/directory attributes structure
76
; 6 : set file/directory attributes structure
70
; 6 : set file/directory attributes structure
77
; 7 : start application
71
; 7 : start application
78
; 8 : delete file
72
; 8 : delete file
79
; 9 : create directory
73
; 9 : create directory
80
 
74
 
81
; parse file name
75
; parse file name
82
	lea	esi, [ebx+20]
76
	lea	esi, [ebx+20]
83
	lodsb
77
	lodsb
84
	test	al, al
78
	test	al, al
85
	jnz	@f
79
	jnz	@f
86
	mov	esi, [esi]
80
	mov	esi, [esi]
87
	lodsb
81
	lodsb
88
@@:
82
@@:
89
	cmp	al, '/'
83
	cmp	al, '/'
90
	jz	.notcurdir
84
	jz	.notcurdir
91
	dec	esi
85
	dec	esi
92
	mov	ebp, esi
86
	mov	ebp, esi
93
	test	al, al
87
	test	al, al
94
	jnz	@f
88
	jnz	@f
95
	xor	ebp, ebp
89
	xor	ebp, ebp
96
@@:
90
@@:
97
	mov	esi, [current_slot]
91
	mov	esi, [current_slot]
98
	mov	esi, [esi+APPDATA.cur_dir]
92
	mov	esi, [esi+APPDATA.cur_dir]
99
	jmp	.parse_normal
93
	jmp	.parse_normal
100
.notcurdir:
94
.notcurdir:
101
	cmp	byte [esi], 0
95
	cmp	byte [esi], 0
102
	jz	.rootdir
96
	jz	.rootdir
103
	call	process_replace_file_name
97
	call	process_replace_file_name
104
.parse_normal:
98
.parse_normal:
105
	cmp dword [ebx], 7
99
	cmp dword [ebx], 7
106
	jne @F
100
	jne @F
107
	mov edx, [ebx+4]
101
	mov edx, [ebx+4]
108
	mov ebx, [ebx+8]
102
	mov ebx, [ebx+8]
109
	call fs_execute  ; esi+ebp, ebx, edx
103
	call fs_execute  ; esi+ebp, ebx, edx
110
	mov [image_of_eax], eax
104
	mov [image_of_eax], eax
111
	ret
105
	ret
112
@@:
106
@@:
113
	mov	edi, rootdirs-8
107
	mov	edi, rootdirs-8
114
	xor	ecx, ecx
108
	xor	ecx, ecx
115
	push	esi
109
	push	esi
116
.scan1:
110
.scan1:
117
	pop	esi
111
	pop	esi
118
	add	edi, ecx
112
	add	edi, ecx
119
	scasd
113
	scasd
120
	scasd
114
	scasd
121
	mov	cl, byte [edi]
115
	mov	cl, byte [edi]
122
	test	cl, cl
116
	test	cl, cl
123
	jz	.notfound_try
117
	jz	.notfound_try
124
	inc	edi
118
	inc	edi
125
	push	esi
119
	push	esi
126
@@:
120
@@:
127
	lodsb
121
	lodsb
128
	or	al, 20h
122
	or	al, 20h
129
	scasb
123
	scasb
130
	loopz	@b
124
	loopz	@b
131
	jnz	.scan1
125
	jnz	.scan1
132
	lodsb
126
	lodsb
133
	cmp	al, '/'
127
	cmp	al, '/'
134
	jz	.found1
128
	jz	.found1
135
	test	al, al
129
	test	al, al
136
	jnz	.scan1
130
	jnz	.scan1
137
	pop	eax
131
	pop	eax
138
; directory /xxx
132
; directory /xxx
139
.maindir:
133
.maindir:
140
	mov	esi, [edi+4]
134
	mov	esi, [edi+4]
141
.maindir_noesi:
135
.maindir_noesi:
142
	cmp	dword [ebx], 1
136
	cmp	dword [ebx], 1
143
	jnz	.access_denied
137
	jnz	.access_denied
144
	xor	eax, eax
138
	xor	eax, eax
145
	mov	ebp, [ebx+12]			;êîëè÷åñòâî áëîêîâ äëÿ ñ÷èòûâàíèÿ
139
	mov	ebp, [ebx+12]			;êîëè÷åñòâî áëîêîâ äëÿ ñ÷èòûâàíèÿ
146
	mov	edx, [ebx+16]			;êóäà çàïèñûâàòü ðóçåëüòàò
140
	mov	edx, [ebx+16]			;êóäà çàïèñûâàòü ðóçåëüòàò
147
    ;    add     edx, std_application_base_address
141
    ;    add     edx, std_application_base_address
148
	push	dword [ebx+4]	; first block
142
	push	dword [ebx+4]	; first block
149
	mov	ebx, [ebx+8]	; flags
143
	mov	ebx, [ebx+8]	; flags
150
; ebx=flags, [esp]=first block, ebp=number of blocks, edx=return area, esi='Next' handler
144
; ebx=flags, [esp]=first block, ebp=number of blocks, edx=return area, esi='Next' handler
151
	mov	edi, edx
145
	mov	edi, edx
152
	push    ecx
146
	push    ecx
153
	mov	ecx, 32/4
147
	mov	ecx, 32/4
154
	rep	stosd
148
	rep	stosd
155
	pop     ecx
149
	pop     ecx
156
	mov	byte [edx], 1	; version
150
	mov	byte [edx], 1	; version
157
.maindir_loop:
151
.maindir_loop:
158
	call	esi
152
	call	esi
159
	jc	.maindir_done
153
	jc	.maindir_done
160
	inc	dword [edx+8]
154
	inc	dword [edx+8]
161
	dec	dword [esp]
155
	dec	dword [esp]
162
	jns	.maindir_loop
156
	jns	.maindir_loop
163
	dec	ebp
157
	dec	ebp
164
	js	.maindir_loop
158
	js	.maindir_loop
165
	inc	dword [edx+4]
159
	inc	dword [edx+4]
166
	mov	dword [edi], 0x10	; attributes: folder
160
	mov	dword [edi], 0x10	; attributes: folder
167
	mov	dword [edi+4], 1	; name type: UNICODE
161
	mov	dword [edi+4], 1	; name type: UNICODE
168
	push	eax
162
	push	eax
169
	xor	eax, eax
163
	xor	eax, eax
170
	add	edi, 8
164
	add	edi, 8
171
	push    ecx
165
	push    ecx
172
	mov	ecx, 40/4-2
166
	mov	ecx, 40/4-2
173
	rep	stosd
167
	rep	stosd
174
	pop     ecx
168
	pop     ecx
175
	pop	eax
169
	pop	eax
176
	push	eax edx
170
	push	eax edx
177
; convert number in eax to decimal UNICODE string
171
; convert number in eax to decimal UNICODE string
178
	push	edi
172
	push	edi
179
	push    ecx
173
	push    ecx
180
	push	-'0'
174
	push	-'0'
181
	mov	ecx, 10
175
	mov	ecx, 10
182
@@:
176
@@:
183
	xor	edx, edx
177
	xor	edx, edx
184
	div	ecx
178
	div	ecx
185
	push	edx
179
	push	edx
186
	test	eax, eax
180
	test	eax, eax
187
	jnz	@b
181
	jnz	@b
188
@@:
182
@@:
189
	pop	eax
183
	pop	eax
190
	add	al, '0'
184
	add	al, '0'
191
	stosb
185
	stosb
192
	test	bl, 1		; UNICODE name?
186
	test	bl, 1		; UNICODE name?
193
	jz	.ansi2
187
	jz	.ansi2
194
	mov	byte [edi], 0
188
	mov	byte [edi], 0
195
	inc	edi
189
	inc	edi
196
.ansi2:
190
.ansi2:
197
	test	al, al
191
	test	al, al
198
	jnz	@b
192
	jnz	@b
199
	mov	byte [edi-1], 0
193
	mov	byte [edi-1], 0
200
	pop     ecx
194
	pop     ecx
201
	pop	edi
195
	pop	edi
202
; UNICODE name length is 520 bytes, ANSI - 264
196
; UNICODE name length is 520 bytes, ANSI - 264
203
	add	edi, 520
197
	add	edi, 520
204
	test	bl, 1
198
	test	bl, 1
205
	jnz	@f
199
	jnz	@f
206
	sub	edi, 520-264
200
	sub	edi, 520-264
207
@@:
201
@@:
208
	pop	edx eax
202
	pop	edx eax
209
	jmp	.maindir_loop
203
	jmp	.maindir_loop
210
.maindir_done:
204
.maindir_done:
211
	pop	eax
205
	pop	eax
212
	mov	ebx, [edx+4]
206
	mov	ebx, [edx+4]
213
	xor	eax, eax
207
	xor	eax, eax
214
	dec	ebp
208
	dec	ebp
215
	js	@f
209
	js	@f
216
	mov	al, ERROR_END_OF_FILE
210
	mov	al, ERROR_END_OF_FILE
217
@@:
211
@@:
218
	mov	[image_of_eax], eax
212
	mov	[image_of_eax], eax
219
	mov	[image_of_ebx], ebx
213
	mov	[image_of_ebx], ebx
220
	ret
214
	ret
221
; directory /
215
; directory /
222
.rootdir:
216
.rootdir:
223
	cmp	dword [ebx], 1	; read folder?
217
	cmp	dword [ebx], 1	; read folder?
224
	jz	.readroot
218
	jz	.readroot
225
.access_denied:
219
.access_denied:
226
	mov	dword [image_of_eax], 10      ; access denied
220
	mov	dword [image_of_eax], 10      ; access denied
227
	ret
221
	ret
228
 
222
 
229
.readroot:
223
.readroot:
230
; virtual root folder - special handler
224
; virtual root folder - special handler
231
	mov	esi, virtual_root_query
225
	mov	esi, virtual_root_query
232
	mov	ebp, [ebx+12]
226
	mov	ebp, [ebx+12]
233
	mov	edx, [ebx+16]
227
	mov	edx, [ebx+16]
234
    ;    add     edx, std_application_base_address
228
    ;    add     edx, std_application_base_address
235
	push	dword [ebx+4]	; first block
229
	push	dword [ebx+4]	; first block
236
	mov	ebx, [ebx+8]	; flags
230
	mov	ebx, [ebx+8]	; flags
237
	xor	eax, eax
231
	xor	eax, eax
238
; eax=0, [esp]=first block, ebx=flags, ebp=number of blocks, edx=return area
232
; eax=0, [esp]=first block, ebx=flags, ebp=number of blocks, edx=return area
239
	mov	edi, edx
233
	mov	edi, edx
240
	mov	ecx, 32/4
234
	mov	ecx, 32/4
241
	rep	stosd
235
	rep	stosd
242
	mov	byte [edx], 1	; version
236
	mov	byte [edx], 1	; version
243
.readroot_loop:
237
.readroot_loop:
244
	cmp	dword [esi], eax
238
	cmp	dword [esi], eax
245
	jz	.readroot_done_static
239
	jz	.readroot_done_static
246
	call	dword [esi]
240
	call	dword [esi]
247
	add	esi, 4
241
	add	esi, 4
248
	test	eax, eax
242
	test	eax, eax
249
	jnz	@f
243
	jnz	@f
250
.readroot_next:
244
.readroot_next:
251
	or	ecx, -1
245
	or	ecx, -1
252
	xchg	esi, edi
246
	xchg	esi, edi
253
	repnz	scasb
247
	repnz	scasb
254
	xchg	esi, edi
248
	xchg	esi, edi
255
	jmp	.readroot_loop
249
	jmp	.readroot_loop
256
@@:
250
@@:
257
	xor	eax, eax
251
	xor	eax, eax
258
	inc	dword [edx+8]
252
	inc	dword [edx+8]
259
	dec	dword [esp]
253
	dec	dword [esp]
260
	jns	.readroot_next
254
	jns	.readroot_next
261
	dec	ebp
255
	dec	ebp
262
	js	.readroot_next
256
	js	.readroot_next
263
	inc	dword [edx+4]
257
	inc	dword [edx+4]
264
	mov	dword [edi], 0x10	; attributes: folder
258
	mov	dword [edi], 0x10	; attributes: folder
265
	mov	dword [edi+4], ebx	; name type: UNICODE
259
	mov	dword [edi+4], ebx	; name type: UNICODE
266
	add	edi, 8
260
	add	edi, 8
267
	mov	ecx, 40/4-2
261
	mov	ecx, 40/4-2
268
	rep	stosd
262
	rep	stosd
269
	push	edi
263
	push	edi
270
@@:
264
@@:
271
	lodsb
265
	lodsb
272
	stosb
266
	stosb
273
	test	bl, 1
267
	test	bl, 1
274
	jz	.ansi
268
	jz	.ansi
275
	mov	byte [edi], 0
269
	mov	byte [edi], 0
276
	inc	edi
270
	inc	edi
277
.ansi:
271
.ansi:
278
	test	eax, eax
272
	test	eax, eax
279
	jnz	@b
273
	jnz	@b
280
	pop	edi
274
	pop	edi
281
	add	edi, 520
275
	add	edi, 520
282
	test	bl, 1
276
	test	bl, 1
283
	jnz	.readroot_loop
277
	jnz	.readroot_loop
284
	sub	edi, 520-264
278
	sub	edi, 520-264
285
	jmp	.readroot_loop
279
	jmp	.readroot_loop
286
.readroot_done_static:
280
.readroot_done_static:
287
        mov     esi, fs_additional_handlers-8
281
        mov     esi, fs_additional_handlers-8
288
        sub     esp, 16
282
        sub     esp, 16
289
.readroot_ah_loop:
283
.readroot_ah_loop:
290
        add     esi, 8
284
        add     esi, 8
291
        cmp     dword [esi], 0
285
        cmp     dword [esi], 0
292
        jz      .readroot_done
286
        jz      .readroot_done
293
        xor     eax, eax
287
        xor     eax, eax
294
.readroot_ah_loop2:
288
.readroot_ah_loop2:
295
        push    edi
289
        push    edi
296
        lea     edi, [esp+4]
290
        lea     edi, [esp+4]
297
        call    dword [esi+4]
291
        call    dword [esi+4]
298
        pop     edi
292
        pop     edi
299
        test    eax, eax
293
        test    eax, eax
300
        jz      .readroot_ah_loop
294
        jz      .readroot_ah_loop
301
        inc     dword [edx+8]
295
        inc     dword [edx+8]
302
        dec     dword [esp+16]
296
        dec     dword [esp+16]
303
        jns     .readroot_ah_loop2
297
        jns     .readroot_ah_loop2
304
        dec     ebp
298
        dec     ebp
305
        js      .readroot_ah_loop2
299
        js      .readroot_ah_loop2
306
        push    eax
300
        push    eax
307
        xor     eax, eax
301
        xor     eax, eax
308
        inc     dword [edx+4]
302
        inc     dword [edx+4]
309
        mov     dword [edi], 0x10       ; attributes: folder
303
        mov     dword [edi], 0x10       ; attributes: folder
310
        mov     dword [edi+4], ebx
304
        mov     dword [edi+4], ebx
311
        add     edi, 8
305
        add     edi, 8
312
        mov     ecx, 40/4-2
306
        mov     ecx, 40/4-2
313
        rep     stosd
307
        rep     stosd
314
        push    esi edi
308
        push    esi edi
315
        lea     esi, [esp+12]
309
        lea     esi, [esp+12]
316
@@:
310
@@:
317
        lodsb
311
        lodsb
318
        stosb
312
        stosb
319
        test    bl, 1
313
        test    bl, 1
320
        jz      .ansi3
314
        jz      .ansi3
321
        mov     byte [edi], 0
315
        mov     byte [edi], 0
322
        inc     edi
316
        inc     edi
323
.ansi3:
317
.ansi3:
324
        test    al, al
318
        test    al, al
325
        jnz     @b
319
        jnz     @b
326
        pop     edi esi eax
320
        pop     edi esi eax
327
        add     edi, 520
321
        add     edi, 520
328
        test    bl, 1
322
        test    bl, 1
329
        jnz     .readroot_ah_loop2
323
        jnz     .readroot_ah_loop2
330
        sub     edi, 520-264
324
        sub     edi, 520-264
331
        jmp     .readroot_ah_loop2
325
        jmp     .readroot_ah_loop2
332
.readroot_done:
326
.readroot_done:
333
        add     esp, 16
327
        add     esp, 16
334
	pop	eax
328
	pop	eax
335
	mov	ebx, [edx+4]
329
	mov	ebx, [edx+4]
336
	xor	eax, eax
330
	xor	eax, eax
337
	dec	ebp
331
	dec	ebp
338
	js	@f
332
	js	@f
339
	mov	al, ERROR_END_OF_FILE
333
	mov	al, ERROR_END_OF_FILE
340
@@:
334
@@:
341
	mov	[image_of_eax], eax
335
	mov	[image_of_eax], eax
342
	mov	[image_of_ebx], ebx
336
	mov	[image_of_ebx], ebx
343
	ret
337
	ret
344
.notfound_try:
338
.notfound_try:
345
        mov     edi, fs_additional_handlers
339
        mov     edi, fs_additional_handlers
346
@@:
340
@@:
347
        cmp     dword [edi], 0
341
        cmp     dword [edi], 0
348
        jz      .notfound
342
        jz      .notfound
349
        call    dword [edi]
343
        call    dword [edi]
350
        scasd
344
        scasd
351
        scasd
345
        scasd
352
        jmp     @b
346
        jmp     @b
353
.notfound:
347
.notfound:
354
	mov	dword [image_of_eax], ERROR_FILE_NOT_FOUND
348
	mov	dword [image_of_eax], ERROR_FILE_NOT_FOUND
355
	and	dword [image_of_ebx], 0
349
	and	dword [image_of_ebx], 0
356
	ret
350
	ret
357
 
351
 
358
.notfounda:
352
.notfounda:
359
        cmp     edi, esp
353
        cmp     edi, esp
360
        jnz     .notfound
354
        jnz     .notfound
361
        add     esp, 8
355
        add     esp, 8
362
        jmp     .notfound
356
        jmp     .notfound
363
 
357
 
364
.found1:
358
.found1:
365
	pop	eax
359
	pop	eax
366
	cmp	byte [esi], 0
360
	cmp	byte [esi], 0
367
	jz	.maindir
361
	jz	.maindir
368
.found2:
362
.found2:
369
; read partition number
363
; read partition number
370
	xor	ecx, ecx
364
	xor	ecx, ecx
371
	xor	eax, eax
365
	xor	eax, eax
372
@@:
366
@@:
373
	lodsb
367
	lodsb
374
	cmp	al, '/'
368
	cmp	al, '/'
375
	jz	.done1
369
	jz	.done1
376
	test	al, al
370
	test	al, al
377
	jz	.done1
371
	jz	.done1
378
	sub	al, '0'
372
	sub	al, '0'
379
	cmp	al, 9
373
	cmp	al, 9
380
	ja	.notfounda
374
	ja	.notfounda
381
	lea	ecx, [ecx*5]
375
	lea	ecx, [ecx*5]
382
	lea	ecx, [ecx*2+eax]
376
	lea	ecx, [ecx*2+eax]
383
	jmp	@b
377
	jmp	@b
384
.done1:
378
.done1:
385
	jecxz	.notfounda
379
	jecxz	.notfounda
386
	test	al, al
380
	test	al, al
387
	jnz	@f
381
	jnz	@f
388
	dec	esi
382
	dec	esi
389
@@:
383
@@:
390
	cmp	byte [esi], 0
384
	cmp	byte [esi], 0
391
	jnz	@f
385
	jnz	@f
392
	test	ebp, ebp
386
	test	ebp, ebp
393
	jz	@f
387
	jz	@f
394
	mov	esi, ebp
388
	mov	esi, ebp
395
	xor	ebp, ebp
389
	xor	ebp, ebp
396
@@:
390
@@:
397
; now [edi] contains handler address, ecx - partition number,
391
; now [edi] contains handler address, ecx - partition number,
398
; esi points to ASCIIZ string - rest of name
392
; esi points to ASCIIZ string - rest of name
399
	jmp	dword [edi]
393
	jmp	dword [edi]
400
 
394
 
401
; handlers for devices
395
; handlers for devices
402
; in: ecx = 0 => query virtual directory /xxx
396
; in: ecx = 0 => query virtual directory /xxx
403
; in: ecx = partition number
397
; in: ecx = partition number
404
;     esi -> relative (for device) name
398
;     esi -> relative (for device) name
405
;     ebx -> fileinfo
399
;     ebx -> fileinfo
406
;     ebp = 0 or pointer to rest of name from folder addressed by esi
400
;     ebp = 0 or pointer to rest of name from folder addressed by esi
407
; out: [image_of_eax]=image of eax, [image_of_ebx]=image of ebx
401
; out: [image_of_eax]=image of eax, [image_of_ebx]=image of ebx
408
 
402
 
409
fs_OnRamdisk:
403
fs_OnRamdisk:
410
	cmp	ecx, 1
404
	cmp	ecx, 1
411
	jnz	file_system_lfn.notfound
405
	jnz	file_system_lfn.notfound
412
	mov	eax, [ebx]
406
	mov	eax, [ebx]
413
	cmp	eax, fs_NumRamdiskServices
407
	cmp	eax, fs_NumRamdiskServices
414
	jae	.not_impl
408
	jae	.not_impl
415
	mov	ecx, [ebx+12]
409
	mov	ecx, [ebx+12]
416
	mov	edx, [ebx+16]
410
	mov	edx, [ebx+16]
417
   ;     add     edx, std_application_base_address
411
   ;     add     edx, std_application_base_address
418
	add	ebx, 4
412
	add	ebx, 4
419
	call	dword [fs_RamdiskServices + eax*4]
413
	call	dword [fs_RamdiskServices + eax*4]
420
	mov	[image_of_eax], eax
414
	mov	[image_of_eax], eax
421
	mov	[image_of_ebx], ebx
415
	mov	[image_of_ebx], ebx
422
	ret
416
	ret
423
.not_impl:
417
.not_impl:
424
	mov	dword [image_of_eax], 2       ; not implemented
418
	mov	dword [image_of_eax], 2       ; not implemented
425
	ret
419
	ret
426
 
420
 
427
fs_NotImplemented:
421
fs_NotImplemented:
428
	mov	eax, 2
422
	mov	eax, 2
429
	ret
423
	ret
430
 
424
 
431
fs_RamdiskServices:
425
fs_RamdiskServices:
432
	dd	fs_RamdiskRead
426
	dd	fs_RamdiskRead
433
	dd	fs_RamdiskReadFolder
427
	dd	fs_RamdiskReadFolder
434
	dd	fs_RamdiskRewrite
428
	dd	fs_RamdiskRewrite
435
	dd	fs_RamdiskWrite
429
	dd	fs_RamdiskWrite
436
	dd	fs_RamdiskSetFileEnd
430
	dd	fs_RamdiskSetFileEnd
437
	dd	fs_RamdiskGetFileInfo
431
	dd	fs_RamdiskGetFileInfo
438
	dd	fs_RamdiskSetFileInfo
432
	dd	fs_RamdiskSetFileInfo
439
	dd	0
433
	dd	0
440
	dd	fs_RamdiskDelete
434
	dd	fs_RamdiskDelete
441
	dd	fs_RamdiskCreateFolder
435
	dd	fs_RamdiskCreateFolder
442
fs_NumRamdiskServices = ($ - fs_RamdiskServices)/4
436
fs_NumRamdiskServices = ($ - fs_RamdiskServices)/4
443
 
-
 
444
fs_OnFloppy:
-
 
445
	cmp	ecx, 2
-
 
446
	ja	file_system_lfn.notfound
-
 
447
	mov	eax, [ebx]
-
 
448
	cmp	eax, fs_NumFloppyServices
-
 
449
	jae	fs_OnRamdisk.not_impl
-
 
450
	call	reserve_flp
-
 
451
	mov	[flp_number], cl
-
 
452
	mov	ecx, [ebx+12]
-
 
453
	mov	edx, [ebx+16]
-
 
454
   ;     add     edx, std_application_base_address
-
 
455
	add	ebx, 4
-
 
456
	call	dword [fs_FloppyServices + eax*4]
-
 
457
	and	[flp_status], 0
-
 
458
	mov	[image_of_eax], eax
-
 
459
	mov	[image_of_ebx], ebx
-
 
460
	ret
-
 
461
 
-
 
462
fs_FloppyServices:
-
 
463
	dd	fs_FloppyRead
-
 
464
	dd	fs_FloppyReadFolder
-
 
465
	dd	fs_FloppyRewrite
-
 
466
	dd	fs_FloppyWrite
-
 
467
	dd	fs_FloppySetFileEnd
-
 
468
	dd	fs_FloppyGetFileInfo
-
 
469
	dd	fs_FloppySetFileInfo
-
 
470
	dd	0
-
 
471
	dd	fs_FloppyDelete
-
 
472
	dd	fs_FloppyCreateFolder
-
 
473
fs_NumFloppyServices = ($ - fs_FloppyServices)/4
-
 
474
 
437
 
475
fs_OnHd0:
438
fs_OnHd0:
476
	call	reserve_hd1
439
	call	reserve_hd1
477
	mov	[hdbase], 0x1F0
440
	mov	[hdbase], 0x1F0
478
	mov	[hdid], 0
441
	mov	[hdid], 0
479
	push	1
442
	push	1
480
	jmp	fs_OnHd
443
	jmp	fs_OnHd
481
fs_OnHd1:
444
fs_OnHd1:
482
	call	reserve_hd1
445
	call	reserve_hd1
483
	mov	[hdbase], 0x1F0
446
	mov	[hdbase], 0x1F0
484
	mov	[hdid], 0x10
447
	mov	[hdid], 0x10
485
	push	2
448
	push	2
486
	jmp	fs_OnHd
449
	jmp	fs_OnHd
487
fs_OnHd2:
450
fs_OnHd2:
488
	call	reserve_hd1
451
	call	reserve_hd1
489
	mov	[hdbase], 0x170
452
	mov	[hdbase], 0x170
490
	mov	[hdid], 0
453
	mov	[hdid], 0
491
	push	3
454
	push	3
492
	jmp	fs_OnHd
455
	jmp	fs_OnHd
493
fs_OnHd3:
456
fs_OnHd3:
494
	call	reserve_hd1
457
	call	reserve_hd1
495
	mov	[hdbase], 0x170
458
	mov	[hdbase], 0x170
496
	mov	[hdid], 0x10
459
	mov	[hdid], 0x10
497
	push	4
460
	push	4
498
fs_OnHd:
461
fs_OnHd:
499
	call	reserve_hd_channel
462
	call	reserve_hd_channel
500
	pop	eax
463
	pop	eax
501
	mov	[hdpos], eax
464
	mov	[hdpos], eax
502
	cmp	ecx, 0x100
465
	cmp	ecx, 0x100
503
	jae	fs_OnHdAndBd.nf
466
	jae	fs_OnHdAndBd.nf
504
	cmp	cl, [DRIVE_DATA+1+eax]
467
	cmp	cl, [DRIVE_DATA+1+eax]
505
fs_OnHdAndBd:
468
fs_OnHdAndBd:
506
	jbe	@f
469
	jbe	@f
507
.nf:
470
.nf:
508
	call	free_hd_channel
471
	call	free_hd_channel
509
	and	[hd1_status], 0
472
	and	[hd1_status], 0
510
	mov	dword [image_of_eax], 5       ; not found
473
	mov	dword [image_of_eax], 5       ; not found
511
	ret
474
	ret
512
@@:
475
@@:
513
	mov	[known_part], ecx ;	mov	[fat32part], ecx
476
	mov	[known_part], ecx ;	mov	[fat32part], ecx
514
	push	ebx esi
477
	push	ebx esi
515
	call	choice_necessity_partition_1
478
	call	choice_necessity_partition_1
516
	pop	esi ebx
479
	pop	esi ebx
517
	mov	ecx, [ebx+12]
480
	mov	ecx, [ebx+12]
518
	mov	edx, [ebx+16]
481
	mov	edx, [ebx+16]
519
    ;    add     edx, std_application_base_address
482
    ;    add     edx, std_application_base_address
520
	mov	eax, [ebx]
483
	mov	eax, [ebx]
521
	cmp	eax, fs_NumHdServices
484
	cmp	eax, fs_NumHdServices
522
	jae	.not_impl
485
	jae	.not_impl
523
	add	ebx, 4
486
	add	ebx, 4
524
	call	dword [fs_HdServices + eax*4]
487
	call	dword [fs_HdServices + eax*4]
525
	call	free_hd_channel
488
	call	free_hd_channel
526
	and	[hd1_status], 0
489
	and	[hd1_status], 0
527
	mov	[image_of_eax], eax
490
	mov	[image_of_eax], eax
528
	mov	[image_of_ebx], ebx
491
	mov	[image_of_ebx], ebx
529
	ret
492
	ret
530
.not_impl:
493
.not_impl:
531
	call	free_hd_channel
494
	call	free_hd_channel
532
	and	[hd1_status], 0
495
	and	[hd1_status], 0
533
	mov	dword [image_of_eax], 2       ; not implemented
496
	mov	dword [image_of_eax], 2       ; not implemented
534
	ret
497
	ret
535
 
498
 
536
fs_HdServices:
499
fs_HdServices:
537
	dd	fs_HdRead
500
	dd	fs_HdRead
538
	dd	fs_HdReadFolder
501
	dd	fs_HdReadFolder
539
	dd	fs_HdRewrite
502
	dd	fs_HdRewrite
540
	dd	fs_HdWrite
503
	dd	fs_HdWrite
541
	dd	fs_HdSetFileEnd
504
	dd	fs_HdSetFileEnd
542
	dd	fs_HdGetFileInfo
505
	dd	fs_HdGetFileInfo
543
	dd	fs_HdSetFileInfo
506
	dd	fs_HdSetFileInfo
544
	dd	0
507
	dd	0
545
	dd	fs_HdDelete
508
	dd	fs_HdDelete
546
	dd	fs_HdCreateFolder
509
	dd	fs_HdCreateFolder
547
fs_NumHdServices = ($ - fs_HdServices)/4
510
fs_NumHdServices = ($ - fs_HdServices)/4
548
 
511
 
549
 
512
 
550
fs_HasRamdisk:
513
fs_HasRamdisk:
551
	mov	al, 1	; we always have ramdisk
514
	mov	al, 1	; we always have ramdisk
552
	ret
515
	ret
553
 
516
 
554
fs_HasFloppy:
517
fs_HasFloppy:
555
	cmp	byte [DRIVE_DATA], 0
518
	cmp	byte [DRIVE_DATA], 0
556
	setnz	al
519
	setnz	al
557
	ret
520
	ret
558
 
521
 
559
fs_HasHd0:
522
fs_HasHd0:
560
	mov	al, [DRIVE_DATA+1]
523
	mov	al, [DRIVE_DATA+1]
561
	and	al, 11000000b
524
	and	al, 11000000b
562
	cmp	al, 01000000b
525
	cmp	al, 01000000b
563
	setz	al
526
	setz	al
564
	ret
527
	ret
565
fs_HasHd1:
528
fs_HasHd1:
566
	mov	al, [DRIVE_DATA+1]
529
	mov	al, [DRIVE_DATA+1]
567
	and	al, 00110000b
530
	and	al, 00110000b
568
	cmp	al, 00010000b
531
	cmp	al, 00010000b
569
	setz	al
532
	setz	al
570
	ret
533
	ret
571
fs_HasHd2:
534
fs_HasHd2:
572
	mov	al, [DRIVE_DATA+1]
535
	mov	al, [DRIVE_DATA+1]
573
	and	al, 00001100b
536
	and	al, 00001100b
574
	cmp	al, 00000100b
537
	cmp	al, 00000100b
575
	setz	al
538
	setz	al
576
	ret
539
	ret
577
fs_HasHd3:
540
fs_HasHd3:
578
	mov	al, [DRIVE_DATA+1]
541
	mov	al, [DRIVE_DATA+1]
579
	and	al, 00000011b
542
	and	al, 00000011b
580
	cmp	al, 00000001b
543
	cmp	al, 00000001b
581
	setz	al
544
	setz	al
582
	ret
545
	ret
583
 
546
 
584
;*******************************************************
547
;*******************************************************
585
fs_HasCd0:
548
fs_HasCd0:
586
	mov	al, [DRIVE_DATA+1]
549
	mov	al, [DRIVE_DATA+1]
587
	and	al, 11000000b
550
	and	al, 11000000b
588
	cmp	al, 10000000b
551
	cmp	al, 10000000b
589
	setz	al
552
	setz	al
590
	ret
553
	ret
591
fs_HasCd1:
554
fs_HasCd1:
592
	mov	al, [DRIVE_DATA+1]
555
	mov	al, [DRIVE_DATA+1]
593
	and	al, 00110000b
556
	and	al, 00110000b
594
	cmp	al, 00100000b
557
	cmp	al, 00100000b
595
	setz	al
558
	setz	al
596
	ret
559
	ret
597
fs_HasCd2:
560
fs_HasCd2:
598
	mov	al, [DRIVE_DATA+1]
561
	mov	al, [DRIVE_DATA+1]
599
	and	al, 00001100b
562
	and	al, 00001100b
600
	cmp	al, 00001000b
563
	cmp	al, 00001000b
601
	setz	al
564
	setz	al
602
	ret
565
	ret
603
fs_HasCd3:
566
fs_HasCd3:
604
	mov	al, [DRIVE_DATA+1]
567
	mov	al, [DRIVE_DATA+1]
605
	and	al, 00000011b
568
	and	al, 00000011b
606
	cmp	al, 00000010b
569
	cmp	al, 00000010b
607
	setz	al
570
	setz	al
608
	ret
571
	ret
609
;*******************************************************
572
;*******************************************************
610
 
573
 
611
; fs_NextXXX functions:
574
; fs_NextXXX functions:
612
; in: eax = partition number, from which start to scan
575
; in: eax = partition number, from which start to scan
613
; out: CF=1 => no more partitions
576
; out: CF=1 => no more partitions
614
;      CF=0 => eax=next partition number
577
;      CF=0 => eax=next partition number
615
 
578
 
616
fs_NextRamdisk:
579
fs_NextRamdisk:
617
; we always have /rd/1
580
; we always have /rd/1
618
	test	eax, eax
581
	test	eax, eax
619
	stc
582
	stc
620
	jnz	@f
583
	jnz	@f
621
	mov	al, 1
584
	mov	al, 1
622
	clc
585
	clc
623
@@:
586
@@:
624
	ret
587
	ret
625
 
588
 
626
fs_NextFloppy:
589
fs_NextFloppy:
627
; we have /fd/1 iff (([DRIVE_DATA] and 0xF0) != 0) and /fd/2 iff (([DRIVE_DATA] and 0x0F) != 0)
590
; we have /fd/1 iff (([DRIVE_DATA] and 0xF0) != 0) and /fd/2 iff (([DRIVE_DATA] and 0x0F) != 0)
628
	test	byte [DRIVE_DATA], 0xF0
591
	test	byte [DRIVE_DATA], 0xF0
629
	jz	.no1
592
	jz	.no1
630
	test	eax, eax
593
	test	eax, eax
631
	jnz	.no1
594
	jnz	.no1
632
	inc	eax
595
	inc	eax
633
	ret	; CF cleared
596
	ret	; CF cleared
634
.no1:
597
.no1:
635
	test	byte [DRIVE_DATA], 0x0F
598
	test	byte [DRIVE_DATA], 0x0F
636
	jz	.no2
599
	jz	.no2
637
	cmp	al, 2
600
	cmp	al, 2
638
	jae	.no2
601
	jae	.no2
639
	mov	al, 2
602
	mov	al, 2
640
	clc
603
	clc
641
	ret
604
	ret
642
.no2:
605
.no2:
643
	stc
606
	stc
644
	ret
607
	ret
645
 
608
 
646
; on hdx, we have partitions from 1 to [0x40002+x]
609
; on hdx, we have partitions from 1 to [0x40002+x]
647
fs_NextHd0:
610
fs_NextHd0:
648
	push	0
611
	push	0
649
	jmp	fs_NextHd
612
	jmp	fs_NextHd
650
fs_NextHd1:
613
fs_NextHd1:
651
	push	1
614
	push	1
652
	jmp	fs_NextHd
615
	jmp	fs_NextHd
653
fs_NextHd2:
616
fs_NextHd2:
654
	push	2
617
	push	2
655
	jmp	fs_NextHd
618
	jmp	fs_NextHd
656
fs_NextHd3:
619
fs_NextHd3:
657
	push	3
620
	push	3
658
fs_NextHd:
621
fs_NextHd:
659
	pop	ecx
622
	pop	ecx
660
	movzx	ecx, byte [DRIVE_DATA+2+ecx]
623
	movzx	ecx, byte [DRIVE_DATA+2+ecx]
661
	cmp	eax, ecx
624
	cmp	eax, ecx
662
	jae	fs_NextFloppy.no2
625
	jae	fs_NextFloppy.no2
663
	inc	eax
626
	inc	eax
664
	clc
627
	clc
665
	ret
628
	ret
666
 
629
 
667
;*******************************************************
630
;*******************************************************
668
fs_NextCd:
631
fs_NextCd:
669
; we always have /cdX/1
632
; we always have /cdX/1
670
	test	eax, eax
633
	test	eax, eax
671
	stc
634
	stc
672
	jnz	@f
635
	jnz	@f
673
	mov	al, 1
636
	mov	al, 1
674
	clc
637
	clc
675
@@:
638
@@:
676
	ret
639
	ret
677
;*******************************************************
640
;*******************************************************
678
 
641
 
679
; Additional FS handlers.
642
; Additional FS handlers.
680
; This handler gets the control each time when fn 70 is called
643
; This handler gets the control each time when fn 70 is called
681
; with unknown item of root subdirectory.
644
; with unknown item of root subdirectory.
682
; in: esi -> name
645
; in: esi -> name
683
;     ebp = 0 or rest of name relative to esi
646
;     ebp = 0 or rest of name relative to esi
684
; out: if the handler processes path, he must not return in file_system_lfn,
647
; out: if the handler processes path, he must not return in file_system_lfn,
685
;      but instead pop return address and return directly to the caller
648
;      but instead pop return address and return directly to the caller
686
;      otherwise simply return
649
;      otherwise simply return
687
 
650
 
688
; here we test for /bd/... - BIOS disks
651
; here we test for /bd/... - BIOS disks
689
biosdisk_handler:
652
biosdisk_handler:
690
        cmp     [NumBiosDisks], 0
653
        cmp     [NumBiosDisks], 0
691
        jz      .ret
654
        jz      .ret
692
        mov     al, [esi]
655
        mov     al, [esi]
693
        or      al, 20h
656
        or      al, 20h
694
        cmp     al, 'b'
657
        cmp     al, 'b'
695
        jnz     .ret
658
        jnz     .ret
696
        mov     al, [esi+1]
659
        mov     al, [esi+1]
697
        or      al, 20h
660
        or      al, 20h
698
        cmp     al, 'd'
661
        cmp     al, 'd'
699
        jnz     .ret
662
        jnz     .ret
700
        push    esi
663
        push    esi
701
        inc     esi
664
        inc     esi
702
        inc     esi
665
        inc     esi
703
        cmp     byte [esi], '0'
666
        cmp     byte [esi], '0'
704
        jb      .ret2
667
        jb      .ret2
705
        cmp     byte [esi], '9'
668
        cmp     byte [esi], '9'
706
        ja      .ret2
669
        ja      .ret2
707
        xor     edx, edx
670
        xor     edx, edx
708
@@:
671
@@:
709
        lodsb
672
        lodsb
710
        test    al, al
673
        test    al, al
711
        jz      .ok
674
        jz      .ok
712
        cmp     al, '/'
675
        cmp     al, '/'
713
        jz      .ok
676
        jz      .ok
714
        sub     al, '0'
677
        sub     al, '0'
715
        cmp     al, 9
678
        cmp     al, 9
716
        ja      .ret2
679
        ja      .ret2
717
        lea     edx, [edx*5]
680
        lea     edx, [edx*5]
718
        lea     edx, [edx*2+eax]
681
        lea     edx, [edx*2+eax]
719
        jmp     @b
682
        jmp     @b
720
.ret2:
683
.ret2:
721
        pop     esi
684
        pop     esi
722
.ret:
685
.ret:
723
        ret
686
        ret
724
.ok:
687
.ok:
725
        cmp     al, '/'
688
        cmp     al, '/'
726
        jz      @f
689
        jz      @f
727
        dec     esi
690
        dec     esi
728
@@:
691
@@:
729
        add     dl, 80h
692
        add     dl, 80h
730
        xor     ecx, ecx
693
        xor     ecx, ecx
731
@@:
694
@@:
732
        cmp     dl, [BiosDisksData+ecx*4]
695
        cmp     dl, [BiosDisksData+ecx*4]
733
        jz      .ok2
696
        jz      .ok2
734
        inc     ecx
697
        inc     ecx
735
        cmp     ecx, [NumBiosDisks]
698
        cmp     ecx, [NumBiosDisks]
736
        jb      @b
699
        jb      @b
737
        jmp     .ret2
700
        jmp     .ret2
738
.ok2:
701
.ok2:
739
        add     esp, 8
702
        add     esp, 8
740
        test    al, al
703
        test    al, al
741
        jnz     @f
704
        jnz     @f
742
        mov     esi, fs_BdNext
705
        mov     esi, fs_BdNext
743
        jmp     file_system_lfn.maindir_noesi
706
        jmp     file_system_lfn.maindir_noesi
744
@@:
707
@@:
745
        push    ecx
708
        push    ecx
746
        push    fs_OnBd
709
        push    fs_OnBd
747
        mov     edi, esp
710
        mov     edi, esp
748
        jmp     file_system_lfn.found2
711
        jmp     file_system_lfn.found2
749
 
712
 
750
fs_BdNext:
713
fs_BdNext:
751
        cmp     eax, [BiosDiskPartitions+ecx*4]
714
        cmp     eax, [BiosDiskPartitions+ecx*4]
752
	inc	eax
715
	inc	eax
753
	cmc
716
	cmc
754
	ret
717
	ret
755
 
718
 
756
fs_OnBd:
719
fs_OnBd:
757
        pop     edx edx
720
        pop     edx edx
758
; edx = disk number, ecx = partition number
721
; edx = disk number, ecx = partition number
759
; esi+ebp = name
722
; esi+ebp = name
760
	call	reserve_hd1
723
	call	reserve_hd1
761
	add     edx, 0x80
724
	add     edx, 0x80
762
	mov     [hdpos], edx
725
	mov     [hdpos], edx
763
	cmp     ecx, [BiosDiskPartitions+(edx-0x80)*4]
726
	cmp     ecx, [BiosDiskPartitions+(edx-0x80)*4]
764
	jmp     fs_OnHdAndBd
727
	jmp     fs_OnHdAndBd
765
 
728
 
766
; This handler is called when virtual root is enumerated
729
; This handler is called when virtual root is enumerated
767
; and must return all items which can be handled by this.
730
; and must return all items which can be handled by this.
768
; It is called several times, first time with eax=0
731
; It is called several times, first time with eax=0
769
; in: eax = 0 for first call, previously returned value for subsequent calls
732
; in: eax = 0 for first call, previously returned value for subsequent calls
770
; out: eax = 0 => no more items
733
; out: eax = 0 => no more items
771
;      eax != 0 => buffer pointed to by edi contains name of item
734
;      eax != 0 => buffer pointed to by edi contains name of item
772
 
735
 
773
; here we enumerate existing BIOS disks /bd
736
; here we enumerate existing BIOS disks /bd
774
biosdisk_enum_root:
737
biosdisk_enum_root:
775
        cmp     eax, [NumBiosDisks]
738
        cmp     eax, [NumBiosDisks]
776
        jae     .end
739
        jae     .end
777
        push    eax
740
        push    eax
778
        movzx   eax, byte [BiosDisksData+eax*4]
741
        movzx   eax, byte [BiosDisksData+eax*4]
779
        sub     al, 80h
742
        sub     al, 80h
780
        push    eax
743
        push    eax
781
        mov     al, 'b'
744
        mov     al, 'b'
782
        stosb
745
        stosb
783
        mov     al, 'd'
746
        mov     al, 'd'
784
        stosb
747
        stosb
785
        pop     eax
748
        pop     eax
786
        cmp     al, 10
749
        cmp     al, 10
787
        jae     .big
750
        jae     .big
788
        add     al, '0'
751
        add     al, '0'
789
        stosb
752
        stosb
790
        mov     byte [edi], 0
753
        mov     byte [edi], 0
791
        pop     eax
754
        pop     eax
792
        inc     eax
755
        inc     eax
793
        ret
756
        ret
794
.end:
757
.end:
795
        xor     eax, eax
758
        xor     eax, eax
796
        ret
759
        ret
797
.big:
760
.big:
798
        push    ecx edx
761
        push    ecx edx
799
        push    -'0'
762
        push    -'0'
800
        mov     ecx, 10
763
        mov     ecx, 10
801
@@:
764
@@:
802
        xor     edx, edx
765
        xor     edx, edx
803
        div     ecx
766
        div     ecx
804
        push    edx
767
        push    edx
805
        test    eax, eax
768
        test    eax, eax
806
        jnz     @b
769
        jnz     @b
807
        xchg    eax, edx
770
        xchg    eax, edx
808
@@:
771
@@:
809
        pop     eax
772
        pop     eax
810
        add     al, '0'
773
        add     al, '0'
811
        stosb
774
        stosb
812
        jnz     @b
775
        jnz     @b
813
        pop     edx ecx
776
        pop     edx ecx
814
        pop     eax
777
        pop     eax
815
        inc     eax
778
        inc     eax
816
        ret
779
        ret
817
 
780
 
818
process_replace_file_name:
781
process_replace_file_name:
819
	mov	ebp, [full_file_name_table]
782
	mov	ebp, [full_file_name_table]
820
	mov	edi, [full_file_name_table.size]
783
	mov	edi, [full_file_name_table.size]
821
	dec	edi
784
	dec	edi
822
	shl	edi, 7
785
	shl	edi, 7
823
	add	edi, ebp
786
	add	edi, ebp
824
.loop:
787
.loop:
825
	cmp	edi, ebp
788
	cmp	edi, ebp
826
	jb	.notfound
789
	jb	.notfound
827
	push	esi edi
790
	push	esi edi
828
@@:
791
@@:
829
	cmp	byte [edi], 0
792
	cmp	byte [edi], 0
830
	jz	.dest_done
793
	jz	.dest_done
831
	lodsb
794
	lodsb
832
	test	al, al
795
	test	al, al
833
	jz	.cont
796
	jz	.cont
834
	or	al, 20h
797
	or	al, 20h
835
	scasb
798
	scasb
836
	jz	@b
799
	jz	@b
837
	jmp	.cont
800
	jmp	.cont
838
.dest_done:
801
.dest_done:
839
	cmp	byte [esi], 0
802
	cmp	byte [esi], 0
840
	jz	.found
803
	jz	.found
841
	cmp	byte [esi], '/'
804
	cmp	byte [esi], '/'
842
	jnz	.cont
805
	jnz	.cont
843
	inc	esi
806
	inc	esi
844
	jmp	.found
807
	jmp	.found
845
.cont:
808
.cont:
846
	pop	edi esi
809
	pop	edi esi
847
	sub	edi, 128
810
	sub	edi, 128
848
	jmp	.loop
811
	jmp	.loop
849
.found:
812
.found:
850
	pop	edi eax
813
	pop	edi eax
851
	mov	ebp, esi
814
	mov	ebp, esi
852
	cmp	byte [esi], 0
815
	cmp	byte [esi], 0
853
	lea	esi, [edi+64]
816
	lea	esi, [edi+64]
854
	jnz	.ret
817
	jnz	.ret
855
.notfound:
818
.notfound:
856
	xor	ebp, ebp
819
	xor	ebp, ebp
857
.ret:
820
.ret:
858
	ret
821
	ret
859
 
822
 
860
sys_current_directory:
823
sys_current_directory:
861
;	mov	esi, [current_slot]
824
;	mov	esi, [current_slot]
862
;	mov	esi, [esi+APPDATA.cur_dir]
825
;	mov	esi, [esi+APPDATA.cur_dir]
863
;	mov	edx, esi
826
;	mov	edx, esi
864
 
827
 
865
;get length string of appdata.cur_dir
828
;get length string of appdata.cur_dir
866
	mov	eax, [current_slot]
829
	mov	eax, [current_slot]
867
	mov	edi, [eax+APPDATA.cur_dir]
830
	mov	edi, [eax+APPDATA.cur_dir]
868
 
831
 
869
	dec	ebx
832
	dec	ebx
870
	jz	.set
833
	jz	.set
871
	dec	ebx
834
	dec	ebx
872
	jz	.get
835
	jz	.get
873
	ret
836
	ret
874
.get:
837
.get:
875
; sysfunction 30.2: [for app] eax=30,ebx=2,ecx->buffer,edx=len
838
; sysfunction 30.2: [for app] eax=30,ebx=2,ecx->buffer,edx=len
876
; for our code: ebx->buffer,ecx=len
839
; for our code: ebx->buffer,ecx=len
877
max_cur_dir	equ	0x1000
840
max_cur_dir	equ	0x1000
878
 
841
 
879
	mov	ebx,edi
842
	mov	ebx,edi
880
 
843
 
881
	push	ecx
844
	push	ecx
882
	push	edi
845
	push	edi
883
 
846
 
884
	xor	eax,eax
847
	xor	eax,eax
885
	mov	ecx,max_cur_dir
848
	mov	ecx,max_cur_dir
886
 
849
 
887
	repne	scasb		;find zerro at and string
850
	repne	scasb		;find zerro at and string
888
	jnz     .error		; no zero in cur_dir: internal error, should not happen
851
	jnz     .error		; no zero in cur_dir: internal error, should not happen
889
 
852
 
890
	sub	edi,ebx		;lenght for copy
853
	sub	edi,ebx		;lenght for copy
891
	inc	edi
854
	inc	edi
892
        mov	[esp+32+8],edi	;return in eax
855
        mov	[esp+32+8],edi	;return in eax
893
 
856
 
894
	cmp	edx, edi
857
	cmp	edx, edi
895
	jbe     @f
858
	jbe     @f
896
	mov     edx, edi
859
	mov     edx, edi
897
@@:
860
@@:
898
;source string
861
;source string
899
	pop	esi
862
	pop	esi
900
;destination string
863
;destination string
901
	pop	edi
864
	pop	edi
902
	cmp	edx, 1
865
	cmp	edx, 1
903
	jbe	.ret
866
	jbe	.ret
904
 
867
 
905
	mov	al,'/'		;start string with '/'
868
	mov	al,'/'		;start string with '/'
906
	stosb
869
	stosb
907
	mov	ecx,edx
870
	mov	ecx,edx
908
	rep	movsb           ;copy string
871
	rep	movsb           ;copy string
909
.ret:	ret
872
.ret:	ret
910
 
873
 
911
.error: add	esp,8
874
.error: add	esp,8
912
	or	dword [esp+32],-1	;error not found zerro at string ->[eax+APPDATA.cur_dir]
875
	or	dword [esp+32],-1	;error not found zerro at string ->[eax+APPDATA.cur_dir]
913
	ret
876
	ret
914
.set:
877
.set:
915
; sysfunction 30.1: [for app] eax=30,ebx=1,ecx->string
878
; sysfunction 30.1: [for app] eax=30,ebx=1,ecx->string
916
; for our code: ebx->string to set
879
; for our code: ebx->string to set
917
; use generic resolver with APPDATA.cur_dir as destination
880
; use generic resolver with APPDATA.cur_dir as destination
918
	push	max_cur_dir	;0x1000
881
	push	max_cur_dir	;0x1000
919
	push	edi	;destination
882
	push	edi	;destination
920
	mov	ebx,ecx
883
	mov	ebx,ecx
921
	call	get_full_file_name
884
	call	get_full_file_name
922
	ret
885
	ret
923
 
886
 
924
; in: ebx = file name, [esp+4] = destination, [esp+8] = sizeof destination
887
; in: ebx = file name, [esp+4] = destination, [esp+8] = sizeof destination
925
; destroys all registers except ebp,esp
888
; destroys all registers except ebp,esp
926
get_full_file_name:
889
get_full_file_name:
927
	push	ebp
890
	push	ebp
928
	mov	esi, [current_slot]
891
	mov	esi, [current_slot]
929
	mov	esi, [esi+APPDATA.cur_dir]
892
	mov	esi, [esi+APPDATA.cur_dir]
930
	mov	edx, esi
893
	mov	edx, esi
931
@@:
894
@@:
932
	inc	esi
895
	inc	esi
933
	cmp	byte [esi-1], 0
896
	cmp	byte [esi-1], 0
934
	jnz	@b
897
	jnz	@b
935
	dec	esi
898
	dec	esi
936
	cmp	byte [ebx], '/'
899
	cmp	byte [ebx], '/'
937
	jz	.set_absolute
900
	jz	.set_absolute
938
; string gives relative path
901
; string gives relative path
939
	mov	edi, [esp+8]	; destination
902
	mov	edi, [esp+8]	; destination
940
.relative:
903
.relative:
941
	cmp	byte [ebx], 0
904
	cmp	byte [ebx], 0
942
	jz	.set_ok
905
	jz	.set_ok
943
	cmp	word [ebx], '.'
906
	cmp	word [ebx], '.'
944
	jz	.set_ok
907
	jz	.set_ok
945
	cmp	word [ebx], './'
908
	cmp	word [ebx], './'
946
	jnz	@f
909
	jnz	@f
947
	add	ebx, 2
910
	add	ebx, 2
948
	jmp	.relative
911
	jmp	.relative
949
@@:
912
@@:
950
	cmp	word [ebx], '..'
913
	cmp	word [ebx], '..'
951
	jnz	.doset_relative
914
	jnz	.doset_relative
952
	cmp	byte [ebx+2], 0
915
	cmp	byte [ebx+2], 0
953
	jz	@f
916
	jz	@f
954
	cmp	byte [ebx+2], '/'
917
	cmp	byte [ebx+2], '/'
955
	jnz	.doset_relative
918
	jnz	.doset_relative
956
@@:
919
@@:
957
	dec	esi
920
	dec	esi
958
	cmp	byte [esi], '/'
921
	cmp	byte [esi], '/'
959
	jnz	@b
922
	jnz	@b
960
	add	ebx, 3
923
	add	ebx, 3
961
	jmp	.relative
924
	jmp	.relative
962
.set_ok:
925
.set_ok:
963
	cmp	edx, edi	; is destination equal to APPDATA.cur_dir?
926
	cmp	edx, edi	; is destination equal to APPDATA.cur_dir?
964
	jz	.set_ok.cur_dir
927
	jz	.set_ok.cur_dir
965
	sub	esi, edx
928
	sub	esi, edx
966
	cmp	esi, [esp+12]
929
	cmp	esi, [esp+12]
967
	jb	.set_ok.copy
930
	jb	.set_ok.copy
968
.fail:
931
.fail:
969
	mov	byte [edi], 0
932
	mov	byte [edi], 0
970
	xor	eax, eax	; fail
933
	xor	eax, eax	; fail
971
	pop	ebp
934
	pop	ebp
972
	ret	8
935
	ret	8
973
.set_ok.copy:
936
.set_ok.copy:
974
	mov	ecx, esi
937
	mov	ecx, esi
975
	mov	esi, edx
938
	mov	esi, edx
976
	rep	movsb
939
	rep	movsb
977
	mov	byte [edi], 0
940
	mov	byte [edi], 0
978
.ret.ok:
941
.ret.ok:
979
	mov	al, 1	; ok
942
	mov	al, 1	; ok
980
	pop	ebp
943
	pop	ebp
981
	ret	8
944
	ret	8
982
.set_ok.cur_dir:
945
.set_ok.cur_dir:
983
	mov	byte [esi], 0
946
	mov	byte [esi], 0
984
	jmp	.ret.ok
947
	jmp	.ret.ok
985
.doset_relative:
948
.doset_relative:
986
	cmp	edx, edi
949
	cmp	edx, edi
987
	jz	.doset_relative.cur_dir
950
	jz	.doset_relative.cur_dir
988
	sub	esi, edx
951
	sub	esi, edx
989
	cmp	esi, [esp+12]
952
	cmp	esi, [esp+12]
990
	jae	.fail
953
	jae	.fail
991
	mov	ecx, esi
954
	mov	ecx, esi
992
	mov	esi, edx
955
	mov	esi, edx
993
	mov	edx, edi
956
	mov	edx, edi
994
	rep	movsb
957
	rep	movsb
995
	jmp	.doset_relative.copy
958
	jmp	.doset_relative.copy
996
.doset_relative.cur_dir:
959
.doset_relative.cur_dir:
997
	mov	edi, esi
960
	mov	edi, esi
998
.doset_relative.copy:
961
.doset_relative.copy:
999
	add	edx, [esp+12]
962
	add	edx, [esp+12]
1000
	mov	byte [edi], '/'
963
	mov	byte [edi], '/'
1001
	inc	edi
964
	inc	edi
1002
	cmp	edi, edx
965
	cmp	edi, edx
1003
	jae	.overflow
966
	jae	.overflow
1004
@@:
967
@@:
1005
	mov	al, [ebx]
968
	mov	al, [ebx]
1006
	inc	ebx
969
	inc	ebx
1007
	stosb
970
	stosb
1008
	test	al, al
971
	test	al, al
1009
	jz	.ret.ok
972
	jz	.ret.ok
1010
	cmp	edi, edx
973
	cmp	edi, edx
1011
	jb	@b
974
	jb	@b
1012
.overflow:
975
.overflow:
1013
	dec	edi
976
	dec	edi
1014
	jmp	.fail
977
	jmp	.fail
1015
.set_absolute:
978
.set_absolute:
1016
	lea	esi, [ebx+1]
979
	lea	esi, [ebx+1]
1017
	call	process_replace_file_name
980
	call	process_replace_file_name
1018
	mov	edi, [esp+8]
981
	mov	edi, [esp+8]
1019
	mov	edx, [esp+12]
982
	mov	edx, [esp+12]
1020
	add	edx, edi
983
	add	edx, edi
1021
.set_copy:
984
.set_copy:
1022
	lodsb
985
	lodsb
1023
	stosb
986
	stosb
1024
	test	al, al
987
	test	al, al
1025
	jz	.set_part2
988
	jz	.set_part2
1026
.set_copy_cont:
989
.set_copy_cont:
1027
	cmp	edi, edx
990
	cmp	edi, edx
1028
	jb	.set_copy
991
	jb	.set_copy
1029
	jmp	.overflow
992
	jmp	.overflow
1030
.set_part2:
993
.set_part2:
1031
	mov	esi, ebp
994
	mov	esi, ebp
1032
	xor	ebp, ebp
995
	xor	ebp, ebp
1033
	test	esi, esi
996
	test	esi, esi
1034
	jz	.ret.ok
997
	jz	.ret.ok
1035
	mov	byte [edi-1], '/'
998
	mov	byte [edi-1], '/'
1036
	jmp	.set_copy_cont
999
	jmp	.set_copy_cont
1037
 
1000
 
1038
; ===============  moved from fs/iso9660.inc
1001
; ===============  moved from fs/iso9660.inc
1039
 
1002
 
1040
char_todown:
1003
char_todown:
1041
; convert character to uppercase, using cp866 encoding
1004
; convert character to uppercase, using cp866 encoding
1042
; in: al=symbol
1005
; in: al=symbol
1043
; out: al=converted symbol
1006
; out: al=converted symbol
1044
	cmp	al, 'A'
1007
	cmp	al, 'A'
1045
	jb	.ret
1008
	jb	.ret
1046
	cmp	al, 'Z'
1009
	cmp	al, 'Z'
1047
	jbe	.az
1010
	jbe	.az
1048
	cmp	al, '€'
1011
	cmp	al, '€'
1049
	jb	.ret
1012
	jb	.ret
1050
	cmp	al, ''
1013
	cmp	al, ''
1051
	jb	.rus1
1014
	jb	.rus1
1052
	cmp	al, 'Ÿ'
1015
	cmp	al, 'Ÿ'
1053
	ja	.ret
1016
	ja	.ret
1054
; 0x90-0x9F -> 0xE0-0xEF
1017
; 0x90-0x9F -> 0xE0-0xEF
1055
	add	al, 'à'-''
1018
	add	al, 'à'-''
1056
.ret:
1019
.ret:
1057
	ret
1020
	ret
1058
.rus1:
1021
.rus1:
1059
; 0x80-0x8F -> 0xA0-0xAF
1022
; 0x80-0x8F -> 0xA0-0xAF
1060
.az:
1023
.az:
1061
	add	al, 0x20
1024
	add	al, 0x20
1062
	ret
1025
	ret
1063
 
1026
 
1064
uni2ansi_char:
1027
uni2ansi_char:
1065
; convert UNICODE character in al to ANSI character in ax, using cp866 encoding
1028
; convert UNICODE character in al to ANSI character in ax, using cp866 encoding
1066
; in: ax=UNICODE character
1029
; in: ax=UNICODE character
1067
; out: al=converted ANSI character
1030
; out: al=converted ANSI character
1068
	cmp	ax, 0x80
1031
	cmp	ax, 0x80
1069
	jb	.ascii
1032
	jb	.ascii
1070
	cmp	ax, 0x401
1033
	cmp	ax, 0x401
1071
	jz	.yo1
1034
	jz	.yo1
1072
	cmp	ax, 0x451
1035
	cmp	ax, 0x451
1073
	jz	.yo2
1036
	jz	.yo2
1074
	cmp	ax, 0x410
1037
	cmp	ax, 0x410
1075
	jb	.unk
1038
	jb	.unk
1076
	cmp	ax, 0x440
1039
	cmp	ax, 0x440
1077
	jb	.rus1
1040
	jb	.rus1
1078
	cmp	ax, 0x450
1041
	cmp	ax, 0x450
1079
	jb	.rus2
1042
	jb	.rus2
1080
.unk:
1043
.unk:
1081
	mov	al, '_'
1044
	mov	al, '_'
1082
	jmp	.doit
1045
	jmp	.doit
1083
.yo1:
1046
.yo1:
1084
	mov	al, 'ð'
1047
	mov	al, 'ð'
1085
	jmp	.doit
1048
	jmp	.doit
1086
.yo2:
1049
.yo2:
1087
	mov	al, 'ñ'
1050
	mov	al, 'ñ'
1088
	jmp	.doit
1051
	jmp	.doit
1089
.rus1:
1052
.rus1:
1090
; 0x410-0x43F -> 0x80-0xAF
1053
; 0x410-0x43F -> 0x80-0xAF
1091
	add	al, 0x70
1054
	add	al, 0x70
1092
	jmp	.doit
1055
	jmp	.doit
1093
.rus2:
1056
.rus2:
1094
; 0x440-0x44F -> 0xE0-0xEF
1057
; 0x440-0x44F -> 0xE0-0xEF
1095
	add	al, 0xA0
1058
	add	al, 0xA0
1096
.ascii:
1059
.ascii:
1097
.doit:
1060
.doit:
1098
	ret
1061
	ret