Subversion Repositories Kolibri OS

Rev

Rev 465 | Rev 533 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 465 Rev 521
1
$Revision: 465 $
1
$Revision: 521 $
2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3
;;                                                              ;;
3
;;                                                              ;;
4
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
4
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
5
;; Distributed under terms of the GNU General Public License    ;;
5
;; Distributed under terms of the GNU General Public License    ;;
6
;;                                                              ;;
6
;;                                                              ;;
7
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8
 
8
 
9
uglobal
9
uglobal
10
cd_current_pointer_of_input    dd  0
10
cd_current_pointer_of_input    dd  0
11
cd_current_pointer_of_input_2  dd  0
11
cd_current_pointer_of_input_2  dd  0
12
cd_mem_location                dd  0
12
cd_mem_location                dd  0
13
cd_counter_block               dd  0
13
cd_counter_block               dd  0
14
IDE_Channel_1                  db  0
14
IDE_Channel_1                  db  0
15
IDE_Channel_2                  db  0
15
IDE_Channel_2                  db  0
16
endg
16
endg
17
 
17
 
18
CDDataBuf equ 0x7000
18
CDDataBuf equ 0x7000
19
 
19
 
20
reserve_cd:
20
reserve_cd:
21
 
21
 
22
    cli
22
    cli
23
    cmp   [cd_status],0
23
    cmp   [cd_status],0
24
    je    reserve_ok2
24
    je    reserve_ok2
25
 
25
 
26
    sti
26
    sti
27
    call  change_task
27
    call  change_task
28
    jmp   reserve_cd
28
    jmp   reserve_cd
29
 
29
 
30
  reserve_ok2:
30
  reserve_ok2:
31
 
31
 
32
    push  eax
32
    push  eax
33
    mov   eax,[CURRENT_TASK]
33
    mov   eax,[CURRENT_TASK]
34
    shl   eax,5
34
    shl   eax,5
35
    mov   eax,[eax+CURRENT_TASK+TASKDATA.pid]
35
    mov   eax,[eax+CURRENT_TASK+TASKDATA.pid]
36
    mov   [cd_status],eax
36
    mov   [cd_status],eax
37
    pop   eax
37
    pop   eax
38
    sti
38
    sti
39
    ret
39
    ret
40
 
40
 
41
reserve_cd_channel:
41
reserve_cd_channel:
42
    cmp   [ChannelNumber],1
42
    cmp   [ChannelNumber],1
43
    jne   .IDE_Channel_2
43
    jne   .IDE_Channel_2
44
.IDE_Channel_1:
44
.IDE_Channel_1:
45
    cli
45
    cli
46
    cmp   [IDE_Channel_1],0
46
    cmp   [IDE_Channel_1],0
47
    je    .reserve_ok_1
47
    je    .reserve_ok_1
48
    sti
48
    sti
49
    call  change_task
49
    call  change_task
50
    jmp   .IDE_Channel_1
50
    jmp   .IDE_Channel_1
51
.IDE_Channel_2:
51
.IDE_Channel_2:
52
    cli
52
    cli
53
    cmp   [IDE_Channel_2],0
53
    cmp   [IDE_Channel_2],0
54
    je    .reserve_ok_2
54
    je    .reserve_ok_2
55
    sti
55
    sti
56
    call  change_task
56
    call  change_task
57
    jmp   .IDE_Channel_1
57
    jmp   .IDE_Channel_1
58
.reserve_ok_1:
58
.reserve_ok_1:
59
    mov [IDE_Channel_1],1
59
    mov [IDE_Channel_1],1
60
    ret
60
    ret
61
.reserve_ok_2:
61
.reserve_ok_2:
62
    mov [IDE_Channel_2],1
62
    mov [IDE_Channel_2],1
63
    ret
63
    ret
64
 
64
 
65
free_cd_channel:
65
free_cd_channel:
66
    cmp   [ChannelNumber],1
66
    cmp   [ChannelNumber],1
67
    jne   .IDE_Channel_2
67
    jne   .IDE_Channel_2
68
.IDE_Channel_1:
68
.IDE_Channel_1:
69
    mov [IDE_Channel_1],0
69
    mov [IDE_Channel_1],0
70
    ret
70
    ret
71
.IDE_Channel_2:
71
.IDE_Channel_2:
72
    mov [IDE_Channel_2],0
72
    mov [IDE_Channel_2],0
73
    ret
73
    ret
74
 
74
 
75
uglobal
75
uglobal
76
cd_status dd 0
76
cd_status dd 0
77
endg
77
endg
78
 
78
 
79
;----------------------------------------------------------------
79
;----------------------------------------------------------------
80
;
80
;
81
;  fs_CdRead - LFN variant for reading CD disk
81
;  fs_CdRead - LFN variant for reading CD disk
82
;
82
;
83
;  esi  points to filename /dir1/dir2/.../dirn/file,0
83
;  esi  points to filename /dir1/dir2/.../dirn/file,0
84
;  ebx  pointer to 64-bit number = first wanted byte, 0+
84
;  ebx  pointer to 64-bit number = first wanted byte, 0+
85
;       may be ebx=0 - start from first byte
85
;       may be ebx=0 - start from first byte
86
;  ecx  number of bytes to read, 0+
86
;  ecx  number of bytes to read, 0+
87
;  edx  mem location to return data
87
;  edx  mem location to return data
88
;
88
;
89
;  ret ebx = bytes read or 0xffffffff file not found
89
;  ret ebx = bytes read or 0xffffffff file not found
90
;      eax = 0 ok read or other = errormsg
90
;      eax = 0 ok read or other = errormsg
91
;
91
;
92
;--------------------------------------------------------------
92
;--------------------------------------------------------------
93
fs_CdRead:
93
fs_CdRead:
94
    push    edi
94
    push    edi
95
    cmp    byte [esi], 0
95
    cmp    byte [esi], 0
96
    jnz    @f
96
    jnz    @f
97
.noaccess:
97
.noaccess:
98
    pop    edi
98
    pop    edi
99
.noaccess_2:
99
.noaccess_2:
100
    or    ebx, -1
100
    or    ebx, -1
101
    mov    eax, ERROR_ACCESS_DENIED
101
    mov    eax, ERROR_ACCESS_DENIED
102
    ret
102
    ret
103
 
103
 
104
.noaccess_3:
104
.noaccess_3:
105
    pop     eax edx ecx edi
105
    pop     eax edx ecx edi
106
    jmp  .noaccess_2
106
    jmp  .noaccess_2
107
 
107
 
108
@@:
108
@@:
109
    call    cd_find_lfn
109
    call    cd_find_lfn
110
    jnc    .found
110
    jnc    .found
111
    pop    edi
111
    pop    edi
112
    cmp   [DevErrorCode],0
112
    cmp   [DevErrorCode],0
113
    jne   .noaccess_2
113
    jne   .noaccess_2
114
    or    ebx, -1
114
    or    ebx, -1
115
    mov    eax, ERROR_FILE_NOT_FOUND
115
    mov    eax, ERROR_FILE_NOT_FOUND
116
    ret
116
    ret
117
 
117
 
118
.found:
118
.found:
119
    mov    edi,[cd_current_pointer_of_input]
119
    mov    edi,[cd_current_pointer_of_input]
120
    test   byte [edi+25],10b    ; do not allow read directories
120
    test   byte [edi+25],10b    ; do not allow read directories
121
    jnz    .noaccess
121
    jnz    .noaccess
122
    test    ebx, ebx
122
    test    ebx, ebx
123
    jz    .l1
123
    jz    .l1
124
    cmp    dword [ebx+4], 0
124
    cmp    dword [ebx+4], 0
125
    jz    @f
125
    jz    @f
126
        xor     ebx, ebx
126
        xor     ebx, ebx
127
.reteof:
127
.reteof:
128
    mov    eax, 6 ; end of file
128
    mov    eax, 6 ; end of file
129
    pop    edi
129
    pop    edi
130
    ret
130
    ret
131
@@:
131
@@:
132
    mov    ebx, [ebx]
132
    mov    ebx, [ebx]
133
.l1:
133
.l1:
134
        push    ecx edx
134
        push    ecx edx
135
        push    0
135
        push    0
136
        mov     eax, [edi+10] ; ðåàëüíûé ðàçìåð ôàéëîâîé ñåêöèè
136
        mov     eax, [edi+10] ; ðåàëüíûé ðàçìåð ôàéëîâîé ñåêöèè
137
        sub     eax, ebx
137
        sub     eax, ebx
138
        jb      .eof
138
        jb      .eof
139
        cmp     eax, ecx
139
        cmp     eax, ecx
140
        jae     @f
140
        jae     @f
141
        mov     ecx, eax
141
        mov     ecx, eax
142
        mov     byte [esp], 6
142
        mov     byte [esp], 6
143
@@:
143
@@:
144
     mov    eax,[edi+2]
144
     mov    eax,[edi+2]
145
     mov    [CDSectorAddress],eax
145
     mov    [CDSectorAddress],eax
146
; now eax=cluster, ebx=position, ecx=count, edx=buffer for data
146
; now eax=cluster, ebx=position, ecx=count, edx=buffer for data
147
.new_sector:
147
.new_sector:
148
    test    ecx, ecx
148
    test    ecx, ecx
149
    jz    .done
149
    jz    .done
150
    sub    ebx, 2048
150
    sub    ebx, 2048
151
    jae    .next
151
    jae    .next
152
    add    ebx, 2048
152
    add    ebx, 2048
153
    jnz    .incomplete_sector
153
    jnz    .incomplete_sector
154
    cmp    ecx, 2048
154
    cmp    ecx, 2048
155
    jb    .incomplete_sector
155
    jb    .incomplete_sector
156
; we may read and memmove complete sector
156
; we may read and memmove complete sector
157
    mov  [CDDataBuf_pointer],edx
157
    mov  [CDDataBuf_pointer],edx
158
    call ReadCDWRetr      ; ÷èòàåì ñåêòîð ôàéëà
158
    call ReadCDWRetr      ; ÷èòàåì ñåêòîð ôàéëà
159
    cmp   [DevErrorCode],0
159
    cmp   [DevErrorCode],0
160
    jne   .noaccess_3
160
    jne   .noaccess_3
161
    add    edx, 2048
161
    add    edx, 2048
162
    sub    ecx, 2048
162
    sub    ecx, 2048
163
.next:
163
.next:
164
    inc  dword [CDSectorAddress]
164
    inc  dword [CDSectorAddress]
165
    jmp    .new_sector
165
    jmp    .new_sector
166
.incomplete_sector:
166
.incomplete_sector:
167
; we must read and memmove incomplete sector
167
; we must read and memmove incomplete sector
168
    mov  [CDDataBuf_pointer],CDDataBuf
168
    mov  [CDDataBuf_pointer],CDDataBuf
169
    call ReadCDWRetr      ; ÷èòàåì ñåêòîð ôàéëà
169
    call ReadCDWRetr      ; ÷èòàåì ñåêòîð ôàéëà
170
    cmp   [DevErrorCode],0
170
    cmp   [DevErrorCode],0
171
    jne   .noaccess_3
171
    jne   .noaccess_3
172
    push    ecx
172
    push    ecx
173
    add    ecx, ebx
173
    add    ecx, ebx
174
    cmp    ecx, 2048
174
    cmp    ecx, 2048
175
    jbe    @f
175
    jbe    @f
176
    mov    ecx, 2048
176
    mov    ecx, 2048
177
@@:
177
@@:
178
    sub    ecx, ebx
178
    sub    ecx, ebx
179
     push edi esi ecx
179
     push edi esi ecx
180
     mov edi,edx
180
     mov edi,edx
181
        lea     esi, [CDDataBuf + ebx]
181
        lea     esi, [CDDataBuf + ebx]
182
     cld
182
     cld
183
     rep movsb
183
     rep movsb
184
     pop ecx esi edi
184
     pop ecx esi edi
185
    add    edx, ecx
185
    add    edx, ecx
186
    sub    [esp], ecx
186
    sub    [esp], ecx
187
    pop    ecx
187
    pop    ecx
188
    xor    ebx, ebx
188
    xor    ebx, ebx
189
    jmp    .next
189
    jmp    .next
190
 
190
 
191
.done:
191
.done:
192
        mov     ebx, edx
192
        mov     ebx, edx
193
        pop     eax edx ecx edi
193
        pop     eax edx ecx edi
194
        sub     ebx, edx
194
        sub     ebx, edx
195
        ret
195
        ret
196
.eof:
196
.eof:
197
        mov     ebx, edx
197
        mov     ebx, edx
198
        pop     eax edx ecx
198
        pop     eax edx ecx
199
        sub     ebx, edx
199
        sub     ebx, edx
200
        jmp     .reteof
200
        jmp     .reteof
201
 
201
 
202
;----------------------------------------------------------------
202
;----------------------------------------------------------------
203
;
203
;
204
;  fs_CdReadFolder - LFN variant for reading CD disk folder
204
;  fs_CdReadFolder - LFN variant for reading CD disk folder
205
;
205
;
206
;  esi  points to filename  /dir1/dir2/.../dirn/file,0
206
;  esi  points to filename  /dir1/dir2/.../dirn/file,0
207
;  ebx  pointer to structure 32-bit number = first wanted block, 0+
207
;  ebx  pointer to structure 32-bit number = first wanted block, 0+
208
;                          & flags (bitfields)
208
;                          & flags (bitfields)
209
; flags: bit 0: 0=ANSI names, 1=UNICODE names
209
; flags: bit 0: 0=ANSI names, 1=UNICODE names
210
;  ecx  number of blocks to read, 0+
210
;  ecx  number of blocks to read, 0+
211
;  edx  mem location to return data
211
;  edx  mem location to return data
212
;
212
;
213
;  ret ebx = blocks read or 0xffffffff folder not found
213
;  ret ebx = blocks read or 0xffffffff folder not found
214
;      eax = 0 ok read or other = errormsg
214
;      eax = 0 ok read or other = errormsg
215
;
215
;
216
;--------------------------------------------------------------
216
;--------------------------------------------------------------
217
fs_CdReadFolder:
217
fs_CdReadFolder:
218
        push    edi
218
        push    edi
219
        call    cd_find_lfn
219
        call    cd_find_lfn
220
        jnc     .found
220
        jnc     .found
221
        pop     edi
221
        pop     edi
222
        cmp     [DevErrorCode], 0
222
        cmp     [DevErrorCode], 0
223
        jne     .noaccess_1
223
        jne     .noaccess_1
224
        or      ebx, -1
224
        or      ebx, -1
225
        mov     eax, ERROR_FILE_NOT_FOUND
225
        mov     eax, ERROR_FILE_NOT_FOUND
226
        ret
226
        ret
227
.found:
227
.found:
228
        mov     edi, [cd_current_pointer_of_input]
228
        mov     edi, [cd_current_pointer_of_input]
229
        test    byte [edi+25], 10b    ; do not allow read directories
229
        test    byte [edi+25], 10b    ; do not allow read directories
230
        jnz     .found_dir
230
        jnz     .found_dir
231
        pop     edi
231
        pop     edi
232
.noaccess_1:
232
.noaccess_1:
233
        or      ebx, -1
233
        or      ebx, -1
234
        mov     eax, ERROR_ACCESS_DENIED
234
        mov     eax, ERROR_ACCESS_DENIED
235
        ret
235
        ret
236
.found_dir:
236
.found_dir:
237
        mov     eax, [edi+2]    ; eax=cluster
237
        mov     eax, [edi+2]    ; eax=cluster
238
        mov     [CDSectorAddress], eax
238
        mov     [CDSectorAddress], eax
239
        mov     eax, [edi+10]   ; ðàçìåð äèðåêòðîðèè
239
        mov     eax, [edi+10]   ; ðàçìåð äèðåêòðîðèè
240
.doit:
240
.doit:
241
; init header
241
; init header
242
        push    eax ecx
242
        push    eax ecx
243
        mov     edi, edx
243
        mov     edi, edx
244
        mov     ecx, 32/4
244
        mov     ecx, 32/4
245
        xor     eax, eax
245
        xor     eax, eax
246
        rep     stosd
246
        rep     stosd
247
        pop     ecx eax
247
        pop     ecx eax
248
        mov     byte [edx], 1   ; version
248
        mov     byte [edx], 1   ; version
249
        mov     [cd_mem_location], edx
249
        mov     [cd_mem_location], edx
250
        add     [cd_mem_location], 32
250
        add     [cd_mem_location], 32
251
; íà÷èíàåì ïåðåáðîñêó ÁÄÂÊ â ÓÑÂÊ
251
; íà÷èíàåì ïåðåáðîñêó ÁÄÂÊ â ÓÑÂÊ
252
;.mainloop:
252
;.mainloop:
253
        mov     [cd_counter_block], dword 0
253
        mov     [cd_counter_block], dword 0
254
        dec     dword [CDSectorAddress]
254
        dec     dword [CDSectorAddress]
255
        push    ecx
255
        push    ecx
256
.read_to_buffer:
256
.read_to_buffer:
257
        inc     dword [CDSectorAddress]
257
        inc     dword [CDSectorAddress]
258
        mov     [CDDataBuf_pointer], CDDataBuf
258
        mov     [CDDataBuf_pointer], CDDataBuf
259
        call    ReadCDWRetr         ; ÷èòàåì ñåêòîð äèðåêòîðèè
259
        call    ReadCDWRetr         ; ÷èòàåì ñåêòîð äèðåêòîðèè
260
        cmp     [DevErrorCode], 0
260
        cmp     [DevErrorCode], 0
261
        jne     .noaccess_1
261
        jne     .noaccess_1
262
        call    .get_names_from_buffer
262
        call    .get_names_from_buffer
263
        sub     eax,2048
263
        sub     eax,2048
264
; äèðåêòîðèÿ çàêîí÷èëàñü?
264
; äèðåêòîðèÿ çàêîí÷èëàñü?
265
        ja      .read_to_buffer
265
        ja      .read_to_buffer
266
        mov     edi, [cd_counter_block]
266
        mov     edi, [cd_counter_block]
267
        mov     [edx+8], edi
267
        mov     [edx+8], edi
268
        mov     edi, [ebx]
268
        mov     edi, [ebx]
269
        sub     [edx+4], edi
269
        sub     [edx+4], edi
270
        xor     eax, eax
270
        xor     eax, eax
271
        dec     ecx
271
        dec     ecx
272
        js      @f
272
        js      @f
273
        mov     al, ERROR_END_OF_FILE
273
        mov     al, ERROR_END_OF_FILE
274
@@:
274
@@:
275
        pop     ecx edi
275
        pop     ecx edi
276
        mov     ebx, [edx+4]
276
        mov     ebx, [edx+4]
277
        ret
277
        ret
278
 
278
 
279
.get_names_from_buffer:
279
.get_names_from_buffer:
280
    mov     [cd_current_pointer_of_input_2],CDDataBuf
280
    mov     [cd_current_pointer_of_input_2],CDDataBuf
281
    push    eax esi edi edx
281
    push    eax esi edi edx
282
.get_names_from_buffer_1:
282
.get_names_from_buffer_1:
283
    call    cd_get_name
283
    call    cd_get_name
284
    jc    .end_buffer
284
    jc    .end_buffer
285
    inc    dword [cd_counter_block]
285
    inc    dword [cd_counter_block]
286
    mov    eax,[cd_counter_block]
286
    mov    eax,[cd_counter_block]
287
    cmp    [ebx],eax
287
    cmp    [ebx],eax
288
    jae     .get_names_from_buffer_1
288
    jae     .get_names_from_buffer_1
289
    test    ecx, ecx
289
    test    ecx, ecx
290
    jz    .get_names_from_buffer_1
290
    jz    .get_names_from_buffer_1
291
    mov   edi,[cd_counter_block]
291
    mov   edi,[cd_counter_block]
292
    mov   [edx+4],edi
292
    mov   [edx+4],edi
293
    dec     ecx
293
    dec     ecx
294
    mov   esi,ebp
294
    mov   esi,ebp
295
    mov   edi,[cd_mem_location]
295
    mov   edi,[cd_mem_location]
296
    add   edi,40
296
    add   edi,40
297
    test   dword [ebx+4], 1 ; 0=ANSI, 1=UNICODE
297
    test   dword [ebx+4], 1 ; 0=ANSI, 1=UNICODE
298
    jnz    .unicode
298
    jnz    .unicode
299
;    jmp  .unicode
299
;    jmp  .unicode
300
.ansi:
300
.ansi:
301
    cmp   [cd_counter_block],2
301
    cmp   [cd_counter_block],2
302
    jbe   .ansi_parent_directory
302
    jbe   .ansi_parent_directory
303
    cld
303
    cld
304
    lodsw
304
    lodsw
305
    xchg ah,al
305
    xchg ah,al
306
    call uni2ansi_char
306
    call uni2ansi_char
307
    cld
307
    cld
308
    stosb
308
    stosb
309
; ïðîâåðêà êîíöà ôàéëà
309
; ïðîâåðêà êîíöà ôàéëà
310
    mov   ax,[esi]
310
    mov   ax,[esi]
311
    cmp   ax,word 3B00h ; ñåïàðàòîð êîíöà ôàéëà ';'
311
    cmp   ax,word 3B00h ; ñåïàðàòîð êîíöà ôàéëà ';'
312
    je   .cd_get_parameters_of_file_1
312
    je   .cd_get_parameters_of_file_1
313
; ïðîâåðêà äëÿ ôàéëîâ íå çàêàí÷èâàþùèõñÿ ñåïàðàòîðîì
313
; ïðîâåðêà äëÿ ôàéëîâ íå çàêàí÷èâàþùèõñÿ ñåïàðàòîðîì
314
    movzx   eax,byte [ebp-33]
314
    movzx   eax,byte [ebp-33]
315
    add   eax,ebp
315
    add   eax,ebp
316
    sub   eax,34
316
    sub   eax,34
317
    cmp   esi,eax
317
    cmp   esi,eax
318
    je   .cd_get_parameters_of_file_1
318
    je   .cd_get_parameters_of_file_1
319
; ïðîâåðêà êîíöà ïàïêè
319
; ïðîâåðêà êîíöà ïàïêè
320
    movzx   eax,byte [ebp-1]
320
    movzx   eax,byte [ebp-1]
321
    add   eax,ebp
321
    add   eax,ebp
322
    cmp   esi,eax
322
    cmp   esi,eax
323
    jb   .ansi
323
    jb   .ansi
324
.cd_get_parameters_of_file_1:
324
.cd_get_parameters_of_file_1:
325
    mov   [edi],byte 0
325
    mov   [edi],byte 0
326
    call  cd_get_parameters_of_file
326
    call  cd_get_parameters_of_file
327
    add   [cd_mem_location],304
327
    add   [cd_mem_location],304
328
    jmp   .get_names_from_buffer_1
328
    jmp   .get_names_from_buffer_1
329
 
329
 
330
.ansi_parent_directory:
330
.ansi_parent_directory:
331
    cmp   [cd_counter_block],2
331
    cmp   [cd_counter_block],2
332
    je    @f
332
    je    @f
333
    mov   [edi],byte '.'
333
    mov   [edi],byte '.'
334
    inc   edi
334
    inc   edi
335
    jmp  .cd_get_parameters_of_file_1
335
    jmp  .cd_get_parameters_of_file_1
336
@@:
336
@@:
337
    mov   [edi],word '..'
337
    mov   [edi],word '..'
338
    add   edi,2
338
    add   edi,2
339
    jmp  .cd_get_parameters_of_file_1
339
    jmp  .cd_get_parameters_of_file_1
340
 
340
 
341
.unicode:
341
.unicode:
342
    cmp   [cd_counter_block],2
342
    cmp   [cd_counter_block],2
343
    jbe   .unicode_parent_directory
343
    jbe   .unicode_parent_directory
344
    cld
344
    cld
345
    movsw
345
    movsw
346
; ïðîâåðêà êîíöà ôàéëà
346
; ïðîâåðêà êîíöà ôàéëà
347
    mov   ax,[esi]
347
    mov   ax,[esi]
348
    cmp   ax,word 3B00h ; ñåïàðàòîð êîíöà ôàéëà ';'
348
    cmp   ax,word 3B00h ; ñåïàðàòîð êîíöà ôàéëà ';'
349
    je   .cd_get_parameters_of_file_2
349
    je   .cd_get_parameters_of_file_2
350
; ïðîâåðêà äëÿ ôàéëîâ íå çàêàí÷èâàþùèõñÿ ñåïàðàòîðîì
350
; ïðîâåðêà äëÿ ôàéëîâ íå çàêàí÷èâàþùèõñÿ ñåïàðàòîðîì
351
    movzx   eax,byte [ebp-33]
351
    movzx   eax,byte [ebp-33]
352
    add   eax,ebp
352
    add   eax,ebp
353
    sub   eax,34
353
    sub   eax,34
354
    cmp   esi,eax
354
    cmp   esi,eax
355
    je   .cd_get_parameters_of_file_2
355
    je   .cd_get_parameters_of_file_2
356
; ïðîâåðêà êîíöà ïàïêè
356
; ïðîâåðêà êîíöà ïàïêè
357
    movzx   eax,byte [ebp-1]
357
    movzx   eax,byte [ebp-1]
358
    add   eax,ebp
358
    add   eax,ebp
359
    cmp   esi,eax
359
    cmp   esi,eax
360
    jb   .unicode
360
    jb   .unicode
361
.cd_get_parameters_of_file_2:
361
.cd_get_parameters_of_file_2:
362
    mov   [edi],word 0
362
    mov   [edi],word 0
363
    call  cd_get_parameters_of_file
363
    call  cd_get_parameters_of_file
364
    add   [cd_mem_location],560
364
    add   [cd_mem_location],560
365
    jmp   .get_names_from_buffer_1
365
    jmp   .get_names_from_buffer_1
366
 
366
 
367
.unicode_parent_directory:
367
.unicode_parent_directory:
368
    cmp   [cd_counter_block],2
368
    cmp   [cd_counter_block],2
369
    je    @f
369
    je    @f
370
    mov   [edi],word 2E00h ; '.'
370
    mov   [edi],word 2E00h ; '.'
371
    add   edi,2
371
    add   edi,2
372
    jmp   .cd_get_parameters_of_file_2
372
    jmp   .cd_get_parameters_of_file_2
373
@@:
373
@@:
374
    mov   [edi],dword 2E002E00h ; '..'
374
    mov   [edi],dword 2E002E00h ; '..'
375
    add   edi,4
375
    add   edi,4
376
    jmp   .cd_get_parameters_of_file_2
376
    jmp   .cd_get_parameters_of_file_2
377
 
377
 
378
.end_buffer:
378
.end_buffer:
379
    pop   edx edi esi eax
379
    pop   edx edi esi eax
380
    ret
380
    ret
381
 
381
 
382
cd_get_parameters_of_file:
382
cd_get_parameters_of_file:
383
    mov   edi,[cd_mem_location]
383
    mov   edi,[cd_mem_location]
384
cd_get_parameters_of_file_1:
384
cd_get_parameters_of_file_1:
385
; ïîëó÷àåì àòðèáóòû ôàéëà
385
; ïîëó÷àåì àòðèáóòû ôàéëà
386
    xor   eax,eax
386
    xor   eax,eax
387
; ôàéë íå àðõèâèðîâàëñ
387
; ôàéë íå àðõèâèðîâàëñ
388
    inc   al
388
    inc   al
389
    shl   eax,1
389
    shl   eax,1
390
; ýòî êàòàëîã?
390
; ýòî êàòàëîã?
391
    test  [ebp-8],byte 2
391
    test  [ebp-8],byte 2
392
    jz    .file
392
    jz    .file
393
    inc   al
393
    inc   al
394
.file:
394
.file:
395
; ìåòêà òîìà íå êàê â FAT, â ýòîì âèäå îòñóòñâóåò
395
; ìåòêà òîìà íå êàê â FAT, â ýòîì âèäå îòñóòñâóåò
396
; ôàéë íå ÿâëÿåòñÿ ñèñòåìíûì
396
; ôàéë íå ÿâëÿåòñÿ ñèñòåìíûì
397
    shl   eax,3
397
    shl   eax,3
398
; ôàéë ÿâëÿåòñÿ ñêðûòûì? (àòðèáóò ñóùåñòâîâàíèå)
398
; ôàéë ÿâëÿåòñÿ ñêðûòûì? (àòðèáóò ñóùåñòâîâàíèå)
399
    test  [ebp-8],byte 1
399
    test  [ebp-8],byte 1
400
    jz    .hidden
400
    jz    .hidden
401
    inc   al
401
    inc   al
402
.hidden:
402
.hidden:
403
    shl   eax,1
403
    shl   eax,1
404
; ôàéë âñåãäà òîëüêî äëÿ ÷òåíèÿ, òàê êàê ýòî CD
404
; ôàéë âñåãäà òîëüêî äëÿ ÷òåíèÿ, òàê êàê ýòî CD
405
    inc   al
405
    inc   al
406
    mov   [edi],eax
406
    mov   [edi],eax
407
; ïîëó÷àåì âðåìÿ äëÿ ôàéëà
407
; ïîëó÷àåì âðåìÿ äëÿ ôàéëà
408
;÷àñ
408
;÷àñ
409
    movzx eax,byte [ebp-12]
409
    movzx eax,byte [ebp-12]
410
    shl   eax,8
410
    shl   eax,8
411
;ìèíóòà
411
;ìèíóòà
412
    mov   al,[ebp-11]
412
    mov   al,[ebp-11]
413
    shl   eax,8
413
    shl   eax,8
414
;ñåêóíäà
414
;ñåêóíäà
415
    mov   al,[ebp-10]
415
    mov   al,[ebp-10]
416
;âðåìÿ ñîçäàíèÿ ôàéëà
416
;âðåìÿ ñîçäàíèÿ ôàéëà
417
    mov   [edi+8],eax
417
    mov   [edi+8],eax
418
;âðåìÿ ïîñëåäíåãî äîñòóïà
418
;âðåìÿ ïîñëåäíåãî äîñòóïà
419
    mov   [edi+16],eax
419
    mov   [edi+16],eax
420
;âðåìÿ ïîñëåäíåé çàïèñè
420
;âðåìÿ ïîñëåäíåé çàïèñè
421
    mov   [edi+24],eax
421
    mov   [edi+24],eax
422
; ïîëó÷àåì äàòó äëÿ ôàéëà
422
; ïîëó÷àåì äàòó äëÿ ôàéëà
423
;ãîä
423
;ãîä
424
    movzx eax,byte [ebp-15]
424
    movzx eax,byte [ebp-15]
425
    add   eax,1900
425
    add   eax,1900
426
    shl   eax,8
426
    shl   eax,8
427
;ìåñÿö
427
;ìåñÿö
428
    mov   al,[ebp-14]
428
    mov   al,[ebp-14]
429
    shl   eax,8
429
    shl   eax,8
430
;äåíü
430
;äåíü
431
    mov   al,[ebp-13]
431
    mov   al,[ebp-13]
432
;äàòà ñîçäàíèÿ ôàéëà
432
;äàòà ñîçäàíèÿ ôàéëà
433
    mov   [edi+12],eax
433
    mov   [edi+12],eax
434
;âðåìÿ ïîñëåäíåãî äîñòóïà
434
;âðåìÿ ïîñëåäíåãî äîñòóïà
435
    mov   [edi+20],eax
435
    mov   [edi+20],eax
436
;âðåìÿ ïîñëåäíåé çàïèñè
436
;âðåìÿ ïîñëåäíåé çàïèñè
437
    mov   [edi+28],eax
437
    mov   [edi+28],eax
438
; ïîëó÷àåì òèï äàííûõ èìåíè
438
; ïîëó÷àåì òèï äàííûõ èìåíè
439
    xor   eax,eax
439
    xor   eax,eax
440
    test   dword [ebx+4], 1 ; 0=ANSI, 1=UNICODE
440
    test   dword [ebx+4], 1 ; 0=ANSI, 1=UNICODE
441
    jnz    .unicode_1
441
    jnz    .unicode_1
442
    mov    [edi+4],eax
442
    mov    [edi+4],eax
443
    jmp   @f
443
    jmp   @f
444
.unicode_1:
444
.unicode_1:
445
    inc    eax
445
    inc    eax
446
    mov    [edi+4],eax
446
    mov    [edi+4],eax
447
@@:
447
@@:
448
; ïîëó÷àåì ðàçìåð ôàéëà â áàéòàõ
448
; ïîëó÷àåì ðàçìåð ôàéëà â áàéòàõ
449
    xor   eax,eax
449
    xor   eax,eax
450
    mov   [edi+32+4],eax
450
    mov   [edi+32+4],eax
451
    mov   eax,[ebp-23]
451
    mov   eax,[ebp-23]
452
    mov   [edi+32],eax
452
    mov   [edi+32],eax
453
    ret
453
    ret
454
 
454
 
455
;----------------------------------------------------------------
455
;----------------------------------------------------------------
456
;
456
;
457
;  fs_CdGetFileInfo - LFN variant for CD
457
;  fs_CdGetFileInfo - LFN variant for CD
458
;                     get file/directory attributes structure
458
;                     get file/directory attributes structure
459
;
459
;
460
;----------------------------------------------------------------
460
;----------------------------------------------------------------
461
fs_CdGetFileInfo:
461
fs_CdGetFileInfo:
462
        cmp     byte [esi], 0
462
        cmp     byte [esi], 0
463
        jnz     @f
463
        jnz     @f
464
        mov     eax, 2
464
        mov     eax, 2
465
        ret
465
        ret
466
@@:
466
@@:
467
        push    edi ebp
467
        push    edi ebp
468
        call    cd_find_lfn
468
        call    cd_find_lfn
469
        pushfd
469
        pushfd
470
        cmp     [DevErrorCode], 0
470
        cmp     [DevErrorCode], 0
471
        jz      @f
471
        jz      @f
472
        popfd
472
        popfd
473
        pop     ebp edi
473
        pop     ebp edi
474
        mov     eax, 11
474
        mov     eax, 11
475
        ret
475
        ret
476
@@:
476
@@:
477
        popfd
477
        popfd
478
        jnc     @f
478
        jnc     @f
479
        pop     ebp edi
479
        pop     ebp edi
480
        mov     eax, ERROR_FILE_NOT_FOUND
480
        mov     eax, ERROR_FILE_NOT_FOUND
481
        ret
481
        ret
482
@@:
482
@@:
483
 
483
 
484
        mov     edi, edx
484
        mov     edi, edx
485
        call    cd_get_parameters_of_file_1
485
        call    cd_get_parameters_of_file_1
486
        and     dword [edi+4], 0
486
        and     dword [edi+4], 0
487
        pop     ebp edi
487
        pop     ebp edi
488
        xor     eax, eax
488
        xor     eax, eax
489
        ret
489
        ret
490
 
-
 
491
;----------------------------------------------------------------
-
 
492
;
-
 
493
;  fs_CdExecute - LFN variant for executing from CD
-
 
494
;
-
 
495
;  esi  points to hd filename (e.g. 'dir1/name')
-
 
496
;  ebp  points to full filename (e.g. '/hd0/1/dir1/name')
-
 
497
;  dword [ebx] = flags
-
 
498
;  dword [ebx+4] = cmdline
-
 
499
;
-
 
500
;  ret ebx,edx destroyed
-
 
501
;      eax > 0 - PID, < 0 - error
-
 
502
;
-
 
503
;--------------------------------------------------------------
-
 
504
fs_CdExecute:
-
 
505
        mov     edx, [ebx]
-
 
506
        mov     ebx, [ebx+4]
-
 
507
        test    ebx, ebx
-
 
508
        jz      @f
-
 
509
    ;    add     ebx, std_application_base_address
-
 
510
@@:
-
 
511
 
-
 
512
;----------------------------------------------------------------
-
 
513
;
-
 
514
; fs_CdExecute.flags - second entry
-
 
515
;
-
 
516
;  esi  points to floppy filename (kernel address)
-
 
517
;  ebp  points to full filename
-
 
518
;  edx  flags
-
 
519
;  ebx  cmdline (kernel address)
-
 
520
;
-
 
521
;  ret  eax > 0 - PID, < 0 - error
-
 
522
;
-
 
523
;--------------------------------------------------------------
-
 
524
 
-
 
525
.flags:
-
 
526
        cmp     byte [esi], 0
-
 
527
        jnz     @f
-
 
528
; cannot execute root!
-
 
529
        mov     eax, -ERROR_ACCESS_DENIED
-
 
530
        ret
-
 
531
@@:
-
 
532
        push    edi
-
 
533
        call    cd_find_lfn
-
 
534
        jnc     .found
-
 
535
        pop     edi
-
 
536
        mov     eax, -ERROR_FILE_NOT_FOUND
-
 
537
        cmp     [DevErrorCode], 0
-
 
538
        jz      @f
-
 
539
        mov     al, -11
-
 
540
@@:
-
 
541
        ret
-
 
542
.found:
-
 
543
        mov     edi,[cd_current_pointer_of_input]
-
 
544
        mov    eax,[edi+2]
-
 
545
        push    0
-
 
546
        push    eax
-
 
547
        push    dword [edi+10]          ; size
-
 
548
        push    .DoRead
-
 
549
        call    fs_execute
-
 
550
        add     esp, 16
-
 
551
        pop     edi
-
 
552
        ret
-
 
553
 
-
 
554
.DoRead:
-
 
555
; read next block
-
 
556
; in: eax->parameters, edi->buffer
-
 
557
; out: eax = error code
-
 
558
        pushad
-
 
559
        cmp     dword [eax], 0  ; file size
-
 
560
        jz      .eof
-
 
561
        cmp     [eax+8],dword 0
-
 
562
        jne     @f
-
 
563
        mov     ecx,[eax+4]
-
 
564
        inc     dword [eax+4]
-
 
565
        mov     [CDSectorAddress],ecx
-
 
566
        mov     [CDDataBuf_pointer],CDDataBuf  ;edi
-
 
567
        call    ReadCDWRetr
-
 
568
        cmp     [DevErrorCode], 0
-
 
569
        jnz     .err
-
 
570
@@:
-
 
571
        push    esi edi ecx
-
 
572
        mov     esi,512
-
 
573
        imul    esi,[eax+8]
-
 
574
        add     esi,CDDataBuf
-
 
575
        mov     ecx,512/4
-
 
576
        cld
-
 
577
        rep     movsd
-
 
578
        pop     ecx edi esi
-
 
579
 
-
 
580
        mov     eax, [esp+28]
-
 
581
        mov     ecx, [eax]
-
 
582
        sub     ecx, 512
-
 
583
        jae     @f
-
 
584
        lea     edi, [edi+ecx+512]
-
 
585
        neg     ecx
-
 
586
        push    eax
-
 
587
        xor     eax, eax
-
 
588
        rep     stosb
-
 
589
        pop     eax
-
 
590
@@:
-
 
591
        mov     [eax], ecx
-
 
592
        mov     edx, [eax+8]
-
 
593
        inc     edx
-
 
594
        cmp     edx, 4  ; 2048/512=4
-
 
595
        jb      @f
-
 
596
        xor     edx, edx
-
 
597
@@:
-
 
598
        mov     [eax+8], edx
-
 
599
        popad
-
 
600
        xor     eax, eax
-
 
601
        ret
-
 
602
.eof:
-
 
603
        popad
-
 
604
        mov     eax, 6
-
 
605
        ret
-
 
606
.err:
-
 
607
        popad
-
 
608
        mov     eax, 11
-
 
609
        ret
-
 
610
 
490
 
611
cd_find_lfn:
491
cd_find_lfn:
612
; in: esi->name
492
; in: esi+ebp -> name
613
; out: CF=1 - file not found
493
; out: CF=1 - file not found
614
;      else CF=0 and [cd_current_pointer_of_input] direntry
494
;      else CF=0 and [cd_current_pointer_of_input] direntry
615
        push eax esi
495
        push eax esi
616
; 16 ñåêòîð íà÷àëî íàáîðà äåñêðèïòîðîâ òîìîâ
496
; 16 ñåêòîð íà÷àëî íàáîðà äåñêðèïòîðîâ òîìîâ
617
        mov  [CDSectorAddress],dword 15
497
        mov  [CDSectorAddress],dword 15
618
.start:
498
.start:
619
        inc  dword [CDSectorAddress]
499
        inc  dword [CDSectorAddress]
620
       mov  [CDDataBuf_pointer],CDDataBuf
500
       mov  [CDDataBuf_pointer],CDDataBuf
621
       call  ReadCDWRetr
501
       call  ReadCDWRetr
622
       cmp   [DevErrorCode],0
502
       cmp   [DevErrorCode],0
623
       jne   .access_denied
503
       jne   .access_denied
624
; ïðîâåðêà íà âøèâîñòü
504
; ïðîâåðêà íà âøèâîñòü
625
        cmp  [CDDataBuf+1],dword 'CD00'
505
        cmp  [CDDataBuf+1],dword 'CD00'
626
        jne  .access_denied
506
        jne  .access_denied
627
        cmp  [CDDataBuf+5],byte '1'
507
        cmp  [CDDataBuf+5],byte '1'
628
        jne  .access_denied
508
        jne  .access_denied
629
; ñåêòîð ÿâëÿåòñÿ òåðìèíàòîðîì íàáîð äåñêðèïòîðîâ òîìîâ?
509
; ñåêòîð ÿâëÿåòñÿ òåðìèíàòîðîì íàáîð äåñêðèïòîðîâ òîìîâ?
630
        cmp  [CDDataBuf],byte 0xff
510
        cmp  [CDDataBuf],byte 0xff
631
        je  .access_denied
511
        je  .access_denied
632
; ñåêòîð ÿâëÿåòñÿ äîïîëíèòåëüíûì è óëó÷øåííûì äåñêðèïòîðîì òîìà?
512
; ñåêòîð ÿâëÿåòñÿ äîïîëíèòåëüíûì è óëó÷øåííûì äåñêðèïòîðîì òîìà?
633
        cmp  [CDDataBuf],byte 0x2
513
        cmp  [CDDataBuf],byte 0x2
634
        jne  .start
514
        jne  .start
635
; ñåêòîð ÿâëÿåòñÿ äîïîëíèòåëüíûì äåñêðèïòîðîì òîìà?
515
; ñåêòîð ÿâëÿåòñÿ äîïîëíèòåëüíûì äåñêðèïòîðîì òîìà?
636
        cmp  [CDDataBuf+6],byte 0x1
516
        cmp  [CDDataBuf+6],byte 0x1
637
        jne  .start
517
        jne  .start
638
; ïàðàìåòðû root äèðåêòðîðèè
518
; ïàðàìåòðû root äèðåêòðîðèè
639
        mov  eax,[CDDataBuf+0x9c+2] ; íà÷àëî root äèðåêòðîðèè
519
        mov  eax,[CDDataBuf+0x9c+2] ; íà÷àëî root äèðåêòðîðèè
640
        mov  [CDSectorAddress],eax
520
        mov  [CDSectorAddress],eax
641
        mov  eax,[CDDataBuf+0x9c+10] ; ðàçìåð root äèðåêòðîðèè
521
        mov  eax,[CDDataBuf+0x9c+10] ; ðàçìåð root äèðåêòðîðèè
642
        cmp    byte [esi], 0
522
        cmp    byte [esi], 0
643
        jnz    @f
523
        jnz    @f
644
        mov   [cd_current_pointer_of_input],CDDataBuf+0x9c
524
        mov   [cd_current_pointer_of_input],CDDataBuf+0x9c
645
        jmp   .done
525
        jmp   .done
646
@@:
526
@@:
647
; íà÷èíàåì ïîèñê
527
; íà÷èíàåì ïîèñê
648
.mainloop:
528
.mainloop:
649
        dec  dword [CDSectorAddress]
529
        dec  dword [CDSectorAddress]
650
.read_to_buffer:
530
.read_to_buffer:
651
        inc  dword [CDSectorAddress]
531
        inc  dword [CDSectorAddress]
652
        mov  [CDDataBuf_pointer],CDDataBuf
532
        mov  [CDDataBuf_pointer],CDDataBuf
653
        call ReadCDWRetr         ; ÷èòàåì ñåêòîð äèðåêòîðèè
533
        call ReadCDWRetr         ; ÷èòàåì ñåêòîð äèðåêòîðèè
654
        cmp   [DevErrorCode],0
534
        cmp   [DevErrorCode],0
655
        jne   .access_denied
535
        jne   .access_denied
656
        call cd_find_name_in_buffer
536
        call cd_find_name_in_buffer
657
        jnc    .found
537
        jnc    .found
658
        sub  eax,2048
538
        sub  eax,2048
659
; äèðåêòîðèÿ çàêîí÷èëàñü?
539
; äèðåêòîðèÿ çàêîí÷èëàñü?
660
        cmp  eax,0
540
        cmp  eax,0
661
        ja   .read_to_buffer
541
        ja   .read_to_buffer
662
; íåò èñêîìîãî ýëåìåíòà öåïî÷êè
542
; íåò èñêîìîãî ýëåìåíòà öåïî÷êè
663
.access_denied:
543
.access_denied:
664
        pop  esi eax
544
        pop  esi eax
665
        stc
545
        stc
666
        ret
546
        ret
667
; èñêîìûé ýëåìåíò öåïî÷êè íàéäåí
547
; èñêîìûé ýëåìåíò öåïî÷êè íàéäåí
668
  .found:
548
  .found:
669
; êîíåö ïóòè ôàéëà
549
; êîíåö ïóòè ôàéëà
670
        cmp    byte [esi-1], 0
550
        cmp    byte [esi-1], 0
671
        jz    .done
551
        jz    .done
-
 
552
  .nested:
672
        mov    eax,[cd_current_pointer_of_input]
553
        mov    eax,[cd_current_pointer_of_input]
673
        push    dword [eax+2]
554
        push    dword [eax+2]
674
        pop     dword [CDSectorAddress]       ; íà÷àëî äèðåêòîðèè
555
        pop     dword [CDSectorAddress]       ; íà÷àëî äèðåêòîðèè
675
        mov    eax,[eax+2+8]  ; ðàçìåð äèðåêòîðèè
556
        mov    eax,[eax+2+8]  ; ðàçìåð äèðåêòîðèè
676
        jmp    .mainloop
557
        jmp    .mainloop
677
; óêàçàòåëü ôàéëà íàéäåí
558
; óêàçàòåëü ôàéëà íàéäåí
678
   .done:
559
   .done:
-
 
560
        test    ebp, ebp
-
 
561
        jz      @f
-
 
562
        mov     esi, ebp
-
 
563
        xor     ebp, ebp
-
 
564
        jmp     .nested
-
 
565
@@:
679
        pop  esi eax
566
        pop  esi eax
680
        clc
567
        clc
681
        ret
568
        ret
682
 
569
 
683
cd_find_name_in_buffer:
570
cd_find_name_in_buffer:
684
        mov     [cd_current_pointer_of_input_2],CDDataBuf
571
        mov     [cd_current_pointer_of_input_2],CDDataBuf
685
.start:
572
.start:
686
        call    cd_get_name
573
        call    cd_get_name
687
        jc    .not_found
574
        jc    .not_found
688
        call    cd_compare_name
575
        call    cd_compare_name
689
        jc    .start
576
        jc    .start
690
.found:
577
.found:
691
        clc
578
        clc
692
        ret
579
        ret
693
.not_found:
580
.not_found:
694
        stc
581
        stc
695
        ret
582
        ret
696
 
583
 
697
cd_get_name:
584
cd_get_name:
698
        push eax
585
        push eax
699
        mov   ebp,[cd_current_pointer_of_input_2]
586
        mov   ebp,[cd_current_pointer_of_input_2]
700
        mov   [cd_current_pointer_of_input],ebp
587
        mov   [cd_current_pointer_of_input],ebp
701
        mov   eax,[ebp]
588
        mov   eax,[ebp]
702
        cmp   eax,0   ; âõîäû çàêîí÷èëèñü?
589
        cmp   eax,0   ; âõîäû çàêîí÷èëèñü?
703
        je    .next_sector
590
        je    .next_sector
704
        cmp   ebp,CDDataBuf+2048     ; áóôåð çàêîí÷èëñÿ?
591
        cmp   ebp,CDDataBuf+2048     ; áóôåð çàêîí÷èëñÿ?
705
        jae   .next_sector
592
        jae   .next_sector
706
        movzx eax, byte [ebp]
593
        movzx eax, byte [ebp]
707
        add   [cd_current_pointer_of_input_2],eax ; ñëåäóþùèé âõîä êàòàëîãà
594
        add   [cd_current_pointer_of_input_2],eax ; ñëåäóþùèé âõîä êàòàëîãà
708
        add   ebp,33 ; óêàçàòåëü óñòàíîâëåí íà íà÷àëî èìåíè
595
        add   ebp,33 ; óêàçàòåëü óñòàíîâëåí íà íà÷àëî èìåíè
709
        pop   eax
596
        pop   eax
710
        clc
597
        clc
711
        ret
598
        ret
712
.next_sector:
599
.next_sector:
713
        pop  eax
600
        pop  eax
714
        stc
601
        stc
715
        ret
602
        ret
716
 
603
 
717
cd_compare_name:
604
cd_compare_name:
718
; compares ASCIIZ-names, case-insensitive (cp866 encoding)
605
; compares ASCIIZ-names, case-insensitive (cp866 encoding)
719
; in: esi->name, ebp->name
606
; in: esi->name, ebp->name
720
; out: if names match: ZF=1 and esi->next component of name
607
; out: if names match: ZF=1 and esi->next component of name
721
;      else: ZF=0, esi is not changed
608
;      else: ZF=0, esi is not changed
722
; destroys eax
609
; destroys eax
723
    push    esi eax edi
610
    push    esi eax edi
724
    mov     edi,ebp
611
    mov     edi,ebp
725
.loop:
612
.loop:
726
    cld
613
    cld
727
    lodsb
614
    lodsb
728
    push ax
615
    push ax
729
    call char_todown
616
    call char_todown
730
    call ansi2uni_char
617
    call ansi2uni_char
731
    xchg ah,al
618
    xchg ah,al
732
    cld
619
    cld
733
    scasw
620
    scasw
734
    pop  ax
621
    pop  ax
735
    je    .coincides
622
    je    .coincides
736
    call char_toupper
623
    call char_toupper
737
    call ansi2uni_char
624
    call ansi2uni_char
738
    xchg ah,al
625
    xchg ah,al
739
    cld
626
    cld
740
    sub  edi,2
627
    sub  edi,2
741
    scasw
628
    scasw
742
    jne   .name_not_coincide
629
    jne   .name_not_coincide
743
.coincides:
630
.coincides:
744
    cmp   [esi],byte '/'  ; ðàçäåëèòåëü ïóòè, êîíåö èìåíè òåêóùåãî ýëåìåíòà
631
    cmp   [esi],byte '/'  ; ðàçäåëèòåëü ïóòè, êîíåö èìåíè òåêóùåãî ýëåìåíòà
745
    je   .done
632
    je   .done
746
    cmp   [esi],byte 0  ; ðàçäåëèòåëü ïóòè, êîíåö èìåíè òåêóùåãî ýëåìåíòà
633
    cmp   [esi],byte 0  ; ðàçäåëèòåëü ïóòè, êîíåö èìåíè òåêóùåãî ýëåìåíòà
747
    je   .done
634
    je   .done
748
    jmp   .loop
635
    jmp   .loop
749
.name_not_coincide:
636
.name_not_coincide:
750
    pop    edi eax esi
637
    pop    edi eax esi
751
    stc
638
    stc
752
    ret
639
    ret
753
.done:
640
.done:
754
; ïðîâåðêà êîíöà ôàéëà
641
; ïðîâåðêà êîíöà ôàéëà
755
    cmp   [edi],word 3B00h ; ñåïàðàòîð êîíöà ôàéëà ';'
642
    cmp   [edi],word 3B00h ; ñåïàðàòîð êîíöà ôàéëà ';'
756
    je   .done_1
643
    je   .done_1
757
; ïðîâåðêà äëÿ ôàéëîâ íå çàêàí÷èâàþùèõñÿ ñåïàðàòîðîì
644
; ïðîâåðêà äëÿ ôàéëîâ íå çàêàí÷èâàþùèõñÿ ñåïàðàòîðîì
758
    movzx   eax,byte [ebp-33]
645
    movzx   eax,byte [ebp-33]
759
    add   eax,ebp
646
    add   eax,ebp
760
    sub   eax,34
647
    sub   eax,34
761
    cmp   edi,eax
648
    cmp   edi,eax
762
    je   .done_1
649
    je   .done_1
763
; ïðîâåðêà êîíöà ïàïêè
650
; ïðîâåðêà êîíöà ïàïêè
764
    movzx   eax,byte [ebp-1]
651
    movzx   eax,byte [ebp-1]
765
    add   eax,ebp
652
    add   eax,ebp
766
    cmp   edi,eax
653
    cmp   edi,eax
767
    jne   .name_not_coincide
654
    jne   .name_not_coincide
768
.done_1:
655
.done_1:
769
    pop   edi eax
656
    pop   edi eax
770
    add   esp,4
657
    add   esp,4
771
    inc   esi
658
    inc   esi
772
    clc
659
    clc
773
    ret
660
    ret
774
 
661
 
775
char_todown:
662
char_todown:
776
; convert character to uppercase, using cp866 encoding
663
; convert character to uppercase, using cp866 encoding
777
; in: al=symbol
664
; in: al=symbol
778
; out: al=converted symbol
665
; out: al=converted symbol
779
        cmp     al, 'A'
666
        cmp     al, 'A'
780
        jb      .ret
667
        jb      .ret
781
        cmp     al, 'Z'
668
        cmp     al, 'Z'
782
        jbe     .az
669
        jbe     .az
783
        cmp     al, '€'
670
        cmp     al, '€'
784
        jb      .ret
671
        jb      .ret
785
        cmp     al, ''
672
        cmp     al, ''
786
        jb      .rus1
673
        jb      .rus1
787
        cmp     al, 'Ÿ'
674
        cmp     al, 'Ÿ'
788
        ja      .ret
675
        ja      .ret
789
; 0x90-0x9F -> 0xE0-0xEF
676
; 0x90-0x9F -> 0xE0-0xEF
790
        add     al, 'à'-''
677
        add     al, 'à'-''
791
.ret:
678
.ret:
792
        ret
679
        ret
793
.rus1:
680
.rus1:
794
; 0x80-0x8F -> 0xA0-0xAF
681
; 0x80-0x8F -> 0xA0-0xAF
795
.az:
682
.az:
796
        add     al, 0x20
683
        add     al, 0x20
797
        ret
684
        ret
798
 
685
 
799
uni2ansi_char:
686
uni2ansi_char:
800
; convert UNICODE character in al to ANSI character in ax, using cp866 encoding
687
; convert UNICODE character in al to ANSI character in ax, using cp866 encoding
801
; in: ax=UNICODE character
688
; in: ax=UNICODE character
802
; out: al=converted ANSI character
689
; out: al=converted ANSI character
803
        cmp     ax, 0x80
690
        cmp     ax, 0x80
804
        jb      .ascii
691
        jb      .ascii
805
        cmp     ax, 0x401
692
        cmp     ax, 0x401
806
        jz      .yo1
693
        jz      .yo1
807
        cmp     ax, 0x451
694
        cmp     ax, 0x451
808
        jz      .yo2
695
        jz      .yo2
809
        cmp     ax, 0x410
696
        cmp     ax, 0x410
810
        jb      .unk
697
        jb      .unk
811
        cmp     ax, 0x440
698
        cmp     ax, 0x440
812
        jb      .rus1
699
        jb      .rus1
813
        cmp     ax, 0x450
700
        cmp     ax, 0x450
814
        jb      .rus2
701
        jb      .rus2
815
.unk:
702
.unk:
816
        mov     al, '_'
703
        mov     al, '_'
817
        jmp     .doit
704
        jmp     .doit
818
.yo1:
705
.yo1:
819
        mov     al, 'ð'
706
        mov     al, 'ð'
820
        jmp     .doit
707
        jmp     .doit
821
.yo2:
708
.yo2:
822
        mov     al, 'ñ'
709
        mov     al, 'ñ'
823
        jmp     .doit
710
        jmp     .doit
824
.rus1:
711
.rus1:
825
; 0x410-0x43F -> 0x80-0xAF
712
; 0x410-0x43F -> 0x80-0xAF
826
        add     al, 0x70
713
        add     al, 0x70
827
        jmp     .doit
714
        jmp     .doit
828
.rus2:
715
.rus2:
829
; 0x440-0x44F -> 0xE0-0xEF
716
; 0x440-0x44F -> 0xE0-0xEF
830
        add     al, 0xA0
717
        add     al, 0xA0
831
.ascii:
718
.ascii:
832
.doit:
719
.doit:
833
        ret
720
        ret