Subversion Repositories Kolibri OS

Rev

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

Rev 431 Rev 465
1
$Revision: 431 $
1
$Revision: 465 $
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
 
490
 
491
;----------------------------------------------------------------
491
;----------------------------------------------------------------
492
;
492
;
493
;  fs_CdExecute - LFN variant for executing from CD
493
;  fs_CdExecute - LFN variant for executing from CD
494
;
494
;
495
;  esi  points to hd filename (e.g. 'dir1/name')
495
;  esi  points to hd filename (e.g. 'dir1/name')
496
;  ebp  points to full filename (e.g. '/hd0/1/dir1/name')
496
;  ebp  points to full filename (e.g. '/hd0/1/dir1/name')
497
;  dword [ebx] = flags
497
;  dword [ebx] = flags
498
;  dword [ebx+4] = cmdline
498
;  dword [ebx+4] = cmdline
499
;
499
;
500
;  ret ebx,edx destroyed
500
;  ret ebx,edx destroyed
501
;      eax > 0 - PID, < 0 - error
501
;      eax > 0 - PID, < 0 - error
502
;
502
;
503
;--------------------------------------------------------------
503
;--------------------------------------------------------------
504
fs_CdExecute:
504
fs_CdExecute:
505
        mov     edx, [ebx]
505
        mov     edx, [ebx]
506
        mov     ebx, [ebx+4]
506
        mov     ebx, [ebx+4]
507
        test    ebx, ebx
507
        test    ebx, ebx
508
        jz      @f
508
        jz      @f
509
        add     ebx, std_application_base_address
509
    ;    add     ebx, std_application_base_address
510
@@:
510
@@:
511
 
511
 
512
;----------------------------------------------------------------
512
;----------------------------------------------------------------
513
;
513
;
514
; fs_CdExecute.flags - second entry
514
; fs_CdExecute.flags - second entry
515
;
515
;
516
;  esi  points to floppy filename (kernel address)
516
;  esi  points to floppy filename (kernel address)
517
;  ebp  points to full filename
517
;  ebp  points to full filename
518
;  edx  flags
518
;  edx  flags
519
;  ebx  cmdline (kernel address)
519
;  ebx  cmdline (kernel address)
520
;
520
;
521
;  ret  eax > 0 - PID, < 0 - error
521
;  ret  eax > 0 - PID, < 0 - error
522
;
522
;
523
;--------------------------------------------------------------
523
;--------------------------------------------------------------
524
 
524
 
525
.flags:
525
.flags:
526
        cmp     byte [esi], 0
526
        cmp     byte [esi], 0
527
        jnz     @f
527
        jnz     @f
528
; cannot execute root!
528
; cannot execute root!
529
        mov     eax, -ERROR_ACCESS_DENIED
529
        mov     eax, -ERROR_ACCESS_DENIED
530
        ret
530
        ret
531
@@:
531
@@:
532
        push    edi
532
        push    edi
533
        call    cd_find_lfn
533
        call    cd_find_lfn
534
        jnc     .found
534
        jnc     .found
535
        pop     edi
535
        pop     edi
536
        mov     eax, -ERROR_FILE_NOT_FOUND
536
        mov     eax, -ERROR_FILE_NOT_FOUND
537
        cmp     [DevErrorCode], 0
537
        cmp     [DevErrorCode], 0
538
        jz      @f
538
        jz      @f
539
        mov     al, -11
539
        mov     al, -11
540
@@:
540
@@:
541
        ret
541
        ret
542
.found:
542
.found:
543
        mov     edi,[cd_current_pointer_of_input]
543
        mov     edi,[cd_current_pointer_of_input]
544
        mov    eax,[edi+2]
544
        mov    eax,[edi+2]
545
        push    0
545
        push    0
546
        push    eax
546
        push    eax
547
        push    dword [edi+10]          ; size
547
        push    dword [edi+10]          ; size
548
        push    .DoRead
548
        push    .DoRead
549
        call    fs_execute
549
        call    fs_execute
550
        add     esp, 16
550
        add     esp, 16
551
        pop     edi
551
        pop     edi
552
        ret
552
        ret
553
 
553
 
554
.DoRead:
554
.DoRead:
555
; read next block
555
; read next block
556
; in: eax->parameters, edi->buffer
556
; in: eax->parameters, edi->buffer
557
; out: eax = error code
557
; out: eax = error code
558
        pushad
558
        pushad
559
        cmp     dword [eax], 0  ; file size
559
        cmp     dword [eax], 0  ; file size
560
        jz      .eof
560
        jz      .eof
561
        cmp     [eax+8],dword 0
561
        cmp     [eax+8],dword 0
562
        jne     @f
562
        jne     @f
563
        mov     ecx,[eax+4]
563
        mov     ecx,[eax+4]
564
        inc     dword [eax+4]
564
        inc     dword [eax+4]
565
        mov     [CDSectorAddress],ecx
565
        mov     [CDSectorAddress],ecx
566
        mov     [CDDataBuf_pointer],CDDataBuf  ;edi
566
        mov     [CDDataBuf_pointer],CDDataBuf  ;edi
567
        call    ReadCDWRetr
567
        call    ReadCDWRetr
568
        cmp     [DevErrorCode], 0
568
        cmp     [DevErrorCode], 0
569
        jnz     .err
569
        jnz     .err
570
@@:
570
@@:
571
        push    esi edi ecx
571
        push    esi edi ecx
572
        mov     esi,512
572
        mov     esi,512
573
        imul    esi,[eax+8]
573
        imul    esi,[eax+8]
574
        add     esi,CDDataBuf
574
        add     esi,CDDataBuf
575
        mov     ecx,512/4
575
        mov     ecx,512/4
576
        cld
576
        cld
577
        rep     movsd
577
        rep     movsd
578
        pop     ecx edi esi
578
        pop     ecx edi esi
579
 
579
 
580
        mov     eax, [esp+28]
580
        mov     eax, [esp+28]
581
        mov     ecx, [eax]
581
        mov     ecx, [eax]
582
        sub     ecx, 512
582
        sub     ecx, 512
583
        jae     @f
583
        jae     @f
584
        lea     edi, [edi+ecx+512]
584
        lea     edi, [edi+ecx+512]
585
        neg     ecx
585
        neg     ecx
586
        push    eax
586
        push    eax
587
        xor     eax, eax
587
        xor     eax, eax
588
        rep     stosb
588
        rep     stosb
589
        pop     eax
589
        pop     eax
590
@@:
590
@@:
591
        mov     [eax], ecx
591
        mov     [eax], ecx
592
        mov     edx, [eax+8]
592
        mov     edx, [eax+8]
593
        inc     edx
593
        inc     edx
594
        cmp     edx, 4  ; 2048/512=4
594
        cmp     edx, 4  ; 2048/512=4
595
        jb      @f
595
        jb      @f
596
        xor     edx, edx
596
        xor     edx, edx
597
@@:
597
@@:
598
        mov     [eax+8], edx
598
        mov     [eax+8], edx
599
        popad
599
        popad
600
        xor     eax, eax
600
        xor     eax, eax
601
        ret
601
        ret
602
.eof:
602
.eof:
603
        popad
603
        popad
604
        mov     eax, 6
604
        mov     eax, 6
605
        ret
605
        ret
606
.err:
606
.err:
607
        popad
607
        popad
608
        mov     eax, 11
608
        mov     eax, 11
609
        ret
609
        ret
610
 
610
 
611
cd_find_lfn:
611
cd_find_lfn:
612
; in: esi->name
612
; in: esi->name
613
; out: CF=1 - file not found
613
; out: CF=1 - file not found
614
;      else CF=0 and [cd_current_pointer_of_input] direntry
614
;      else CF=0 and [cd_current_pointer_of_input] direntry
615
        push eax esi
615
        push eax esi
616
; 16 ñåêòîð íà÷àëî íàáîðà äåñêðèïòîðîâ òîìîâ
616
; 16 ñåêòîð íà÷àëî íàáîðà äåñêðèïòîðîâ òîìîâ
617
        mov  [CDSectorAddress],dword 15
617
        mov  [CDSectorAddress],dword 15
618
.start:
618
.start:
619
        inc  dword [CDSectorAddress]
619
        inc  dword [CDSectorAddress]
620
       mov  [CDDataBuf_pointer],CDDataBuf
620
       mov  [CDDataBuf_pointer],CDDataBuf
621
       call  ReadCDWRetr
621
       call  ReadCDWRetr
622
       cmp   [DevErrorCode],0
622
       cmp   [DevErrorCode],0
623
       jne   .access_denied
623
       jne   .access_denied
624
; ïðîâåðêà íà âøèâîñòü
624
; ïðîâåðêà íà âøèâîñòü
625
        cmp  [CDDataBuf+1],dword 'CD00'
625
        cmp  [CDDataBuf+1],dword 'CD00'
626
        jne  .access_denied
626
        jne  .access_denied
627
        cmp  [CDDataBuf+5],byte '1'
627
        cmp  [CDDataBuf+5],byte '1'
628
        jne  .access_denied
628
        jne  .access_denied
629
; ñåêòîð ÿâëÿåòñÿ òåðìèíàòîðîì íàáîð äåñêðèïòîðîâ òîìîâ?
629
; ñåêòîð ÿâëÿåòñÿ òåðìèíàòîðîì íàáîð äåñêðèïòîðîâ òîìîâ?
630
        cmp  [CDDataBuf],byte 0xff
630
        cmp  [CDDataBuf],byte 0xff
631
        je  .access_denied
631
        je  .access_denied
632
; ñåêòîð ÿâëÿåòñÿ äîïîëíèòåëüíûì è óëó÷øåííûì äåñêðèïòîðîì òîìà?
632
; ñåêòîð ÿâëÿåòñÿ äîïîëíèòåëüíûì è óëó÷øåííûì äåñêðèïòîðîì òîìà?
633
        cmp  [CDDataBuf],byte 0x2
633
        cmp  [CDDataBuf],byte 0x2
634
        jne  .start
634
        jne  .start
635
; ñåêòîð ÿâëÿåòñÿ äîïîëíèòåëüíûì äåñêðèïòîðîì òîìà?
635
; ñåêòîð ÿâëÿåòñÿ äîïîëíèòåëüíûì äåñêðèïòîðîì òîìà?
636
        cmp  [CDDataBuf+6],byte 0x1
636
        cmp  [CDDataBuf+6],byte 0x1
637
        jne  .start
637
        jne  .start
638
; ïàðàìåòðû root äèðåêòðîðèè
638
; ïàðàìåòðû root äèðåêòðîðèè
639
        mov  eax,[CDDataBuf+0x9c+2] ; íà÷àëî root äèðåêòðîðèè
639
        mov  eax,[CDDataBuf+0x9c+2] ; íà÷àëî root äèðåêòðîðèè
640
        mov  [CDSectorAddress],eax
640
        mov  [CDSectorAddress],eax
641
        mov  eax,[CDDataBuf+0x9c+10] ; ðàçìåð root äèðåêòðîðèè
641
        mov  eax,[CDDataBuf+0x9c+10] ; ðàçìåð root äèðåêòðîðèè
642
        cmp    byte [esi], 0
642
        cmp    byte [esi], 0
643
        jnz    @f
643
        jnz    @f
644
        mov   [cd_current_pointer_of_input],CDDataBuf+0x9c
644
        mov   [cd_current_pointer_of_input],CDDataBuf+0x9c
645
        jmp   .done
645
        jmp   .done
646
@@:
646
@@:
647
; íà÷èíàåì ïîèñê
647
; íà÷èíàåì ïîèñê
648
.mainloop:
648
.mainloop:
649
        dec  dword [CDSectorAddress]
649
        dec  dword [CDSectorAddress]
650
.read_to_buffer:
650
.read_to_buffer:
651
        inc  dword [CDSectorAddress]
651
        inc  dword [CDSectorAddress]
652
        mov  [CDDataBuf_pointer],CDDataBuf
652
        mov  [CDDataBuf_pointer],CDDataBuf
653
        call ReadCDWRetr         ; ÷èòàåì ñåêòîð äèðåêòîðèè
653
        call ReadCDWRetr         ; ÷èòàåì ñåêòîð äèðåêòîðèè
654
        cmp   [DevErrorCode],0
654
        cmp   [DevErrorCode],0
655
        jne   .access_denied
655
        jne   .access_denied
656
        call cd_find_name_in_buffer
656
        call cd_find_name_in_buffer
657
        jnc    .found
657
        jnc    .found
658
        sub  eax,2048
658
        sub  eax,2048
659
; äèðåêòîðèÿ çàêîí÷èëàñü?
659
; äèðåêòîðèÿ çàêîí÷èëàñü?
660
        cmp  eax,0
660
        cmp  eax,0
661
        ja   .read_to_buffer
661
        ja   .read_to_buffer
662
; íåò èñêîìîãî ýëåìåíòà öåïî÷êè
662
; íåò èñêîìîãî ýëåìåíòà öåïî÷êè
663
.access_denied:
663
.access_denied:
664
        pop  esi eax
664
        pop  esi eax
665
        stc
665
        stc
666
        ret
666
        ret
667
; èñêîìûé ýëåìåíò öåïî÷êè íàéäåí
667
; èñêîìûé ýëåìåíò öåïî÷êè íàéäåí
668
  .found:
668
  .found:
669
; êîíåö ïóòè ôàéëà
669
; êîíåö ïóòè ôàéëà
670
        cmp    byte [esi-1], 0
670
        cmp    byte [esi-1], 0
671
        jz    .done
671
        jz    .done
672
        mov    eax,[cd_current_pointer_of_input]
672
        mov    eax,[cd_current_pointer_of_input]
673
        push    dword [eax+2]
673
        push    dword [eax+2]
674
        pop     dword [CDSectorAddress]       ; íà÷àëî äèðåêòîðèè
674
        pop     dword [CDSectorAddress]       ; íà÷àëî äèðåêòîðèè
675
        mov    eax,[eax+2+8]  ; ðàçìåð äèðåêòîðèè
675
        mov    eax,[eax+2+8]  ; ðàçìåð äèðåêòîðèè
676
        jmp    .mainloop
676
        jmp    .mainloop
677
; óêàçàòåëü ôàéëà íàéäåí
677
; óêàçàòåëü ôàéëà íàéäåí
678
   .done:
678
   .done:
679
        pop  esi eax
679
        pop  esi eax
680
        clc
680
        clc
681
        ret
681
        ret
682
 
682
 
683
cd_find_name_in_buffer:
683
cd_find_name_in_buffer:
684
        mov     [cd_current_pointer_of_input_2],CDDataBuf
684
        mov     [cd_current_pointer_of_input_2],CDDataBuf
685
.start:
685
.start:
686
        call    cd_get_name
686
        call    cd_get_name
687
        jc    .not_found
687
        jc    .not_found
688
        call    cd_compare_name
688
        call    cd_compare_name
689
        jc    .start
689
        jc    .start
690
.found:
690
.found:
691
        clc
691
        clc
692
        ret
692
        ret
693
.not_found:
693
.not_found:
694
        stc
694
        stc
695
        ret
695
        ret
696
 
696
 
697
cd_get_name:
697
cd_get_name:
698
        push eax
698
        push eax
699
        mov   ebp,[cd_current_pointer_of_input_2]
699
        mov   ebp,[cd_current_pointer_of_input_2]
700
        mov   [cd_current_pointer_of_input],ebp
700
        mov   [cd_current_pointer_of_input],ebp
701
        mov   eax,[ebp]
701
        mov   eax,[ebp]
702
        cmp   eax,0   ; âõîäû çàêîí÷èëèñü?
702
        cmp   eax,0   ; âõîäû çàêîí÷èëèñü?
703
        je    .next_sector
703
        je    .next_sector
704
        cmp   ebp,CDDataBuf+2048     ; áóôåð çàêîí÷èëñÿ?
704
        cmp   ebp,CDDataBuf+2048     ; áóôåð çàêîí÷èëñÿ?
705
        jae   .next_sector
705
        jae   .next_sector
706
        movzx eax, byte [ebp]
706
        movzx eax, byte [ebp]
707
        add   [cd_current_pointer_of_input_2],eax ; ñëåäóþùèé âõîä êàòàëîãà
707
        add   [cd_current_pointer_of_input_2],eax ; ñëåäóþùèé âõîä êàòàëîãà
708
        add   ebp,33 ; óêàçàòåëü óñòàíîâëåí íà íà÷àëî èìåíè
708
        add   ebp,33 ; óêàçàòåëü óñòàíîâëåí íà íà÷àëî èìåíè
709
        pop   eax
709
        pop   eax
710
        clc
710
        clc
711
        ret
711
        ret
712
.next_sector:
712
.next_sector:
713
        pop  eax
713
        pop  eax
714
        stc
714
        stc
715
        ret
715
        ret
716
 
716
 
717
cd_compare_name:
717
cd_compare_name:
718
; compares ASCIIZ-names, case-insensitive (cp866 encoding)
718
; compares ASCIIZ-names, case-insensitive (cp866 encoding)
719
; in: esi->name, ebp->name
719
; in: esi->name, ebp->name
720
; out: if names match: ZF=1 and esi->next component of name
720
; out: if names match: ZF=1 and esi->next component of name
721
;      else: ZF=0, esi is not changed
721
;      else: ZF=0, esi is not changed
722
; destroys eax
722
; destroys eax
723
    push    esi eax edi
723
    push    esi eax edi
724
    mov     edi,ebp
724
    mov     edi,ebp
725
.loop:
725
.loop:
726
    cld
726
    cld
727
    lodsb
727
    lodsb
728
    push ax
728
    push ax
729
    call char_todown
729
    call char_todown
730
    call ansi2uni_char
730
    call ansi2uni_char
731
    xchg ah,al
731
    xchg ah,al
732
    cld
732
    cld
733
    scasw
733
    scasw
734
    pop  ax
734
    pop  ax
735
    je    .coincides
735
    je    .coincides
736
    call char_toupper
736
    call char_toupper
737
    call ansi2uni_char
737
    call ansi2uni_char
738
    xchg ah,al
738
    xchg ah,al
739
    cld
739
    cld
740
    sub  edi,2
740
    sub  edi,2
741
    scasw
741
    scasw
742
    jne   .name_not_coincide
742
    jne   .name_not_coincide
743
.coincides:
743
.coincides:
744
    cmp   [esi],byte '/'  ; ðàçäåëèòåëü ïóòè, êîíåö èìåíè òåêóùåãî ýëåìåíòà
744
    cmp   [esi],byte '/'  ; ðàçäåëèòåëü ïóòè, êîíåö èìåíè òåêóùåãî ýëåìåíòà
745
    je   .done
745
    je   .done
746
    cmp   [esi],byte 0  ; ðàçäåëèòåëü ïóòè, êîíåö èìåíè òåêóùåãî ýëåìåíòà
746
    cmp   [esi],byte 0  ; ðàçäåëèòåëü ïóòè, êîíåö èìåíè òåêóùåãî ýëåìåíòà
747
    je   .done
747
    je   .done
748
    jmp   .loop
748
    jmp   .loop
749
.name_not_coincide:
749
.name_not_coincide:
750
    pop    edi eax esi
750
    pop    edi eax esi
751
    stc
751
    stc
752
    ret
752
    ret
753
.done:
753
.done:
754
; ïðîâåðêà êîíöà ôàéëà
754
; ïðîâåðêà êîíöà ôàéëà
755
    cmp   [edi],word 3B00h ; ñåïàðàòîð êîíöà ôàéëà ';'
755
    cmp   [edi],word 3B00h ; ñåïàðàòîð êîíöà ôàéëà ';'
756
    je   .done_1
756
    je   .done_1
757
; ïðîâåðêà äëÿ ôàéëîâ íå çàêàí÷èâàþùèõñÿ ñåïàðàòîðîì
757
; ïðîâåðêà äëÿ ôàéëîâ íå çàêàí÷èâàþùèõñÿ ñåïàðàòîðîì
758
    movzx   eax,byte [ebp-33]
758
    movzx   eax,byte [ebp-33]
759
    add   eax,ebp
759
    add   eax,ebp
760
    sub   eax,34
760
    sub   eax,34
761
    cmp   edi,eax
761
    cmp   edi,eax
762
    je   .done_1
762
    je   .done_1
763
; ïðîâåðêà êîíöà ïàïêè
763
; ïðîâåðêà êîíöà ïàïêè
764
    movzx   eax,byte [ebp-1]
764
    movzx   eax,byte [ebp-1]
765
    add   eax,ebp
765
    add   eax,ebp
766
    cmp   edi,eax
766
    cmp   edi,eax
767
    jne   .name_not_coincide
767
    jne   .name_not_coincide
768
.done_1:
768
.done_1:
769
    pop   edi eax
769
    pop   edi eax
770
    add   esp,4
770
    add   esp,4
771
    inc   esi
771
    inc   esi
772
    clc
772
    clc
773
    ret
773
    ret
774
 
774
 
775
char_todown:
775
char_todown:
776
; convert character to uppercase, using cp866 encoding
776
; convert character to uppercase, using cp866 encoding
777
; in: al=symbol
777
; in: al=symbol
778
; out: al=converted symbol
778
; out: al=converted symbol
779
        cmp     al, 'A'
779
        cmp     al, 'A'
780
        jb      .ret
780
        jb      .ret
781
        cmp     al, 'Z'
781
        cmp     al, 'Z'
782
        jbe     .az
782
        jbe     .az
783
        cmp     al, '€'
783
        cmp     al, '€'
784
        jb      .ret
784
        jb      .ret
785
        cmp     al, ''
785
        cmp     al, ''
786
        jb      .rus1
786
        jb      .rus1
787
        cmp     al, 'Ÿ'
787
        cmp     al, 'Ÿ'
788
        ja      .ret
788
        ja      .ret
789
; 0x90-0x9F -> 0xE0-0xEF
789
; 0x90-0x9F -> 0xE0-0xEF
790
        add     al, 'à'-''
790
        add     al, 'à'-''
791
.ret:
791
.ret:
792
        ret
792
        ret
793
.rus1:
793
.rus1:
794
; 0x80-0x8F -> 0xA0-0xAF
794
; 0x80-0x8F -> 0xA0-0xAF
795
.az:
795
.az:
796
        add     al, 0x20
796
        add     al, 0x20
797
        ret
797
        ret
798
 
798
 
799
uni2ansi_char:
799
uni2ansi_char:
800
; convert UNICODE character in al to ANSI character in ax, using cp866 encoding
800
; convert UNICODE character in al to ANSI character in ax, using cp866 encoding
801
; in: ax=UNICODE character
801
; in: ax=UNICODE character
802
; out: al=converted ANSI character
802
; out: al=converted ANSI character
803
        cmp     ax, 0x80
803
        cmp     ax, 0x80
804
        jb      .ascii
804
        jb      .ascii
805
        cmp     ax, 0x401
805
        cmp     ax, 0x401
806
        jz      .yo1
806
        jz      .yo1
807
        cmp     ax, 0x451
807
        cmp     ax, 0x451
808
        jz      .yo2
808
        jz      .yo2
809
        cmp     ax, 0x410
809
        cmp     ax, 0x410
810
        jb      .unk
810
        jb      .unk
811
        cmp     ax, 0x440
811
        cmp     ax, 0x440
812
        jb      .rus1
812
        jb      .rus1
813
        cmp     ax, 0x450
813
        cmp     ax, 0x450
814
        jb      .rus2
814
        jb      .rus2
815
.unk:
815
.unk:
816
        mov     al, '_'
816
        mov     al, '_'
817
        jmp     .doit
817
        jmp     .doit
818
.yo1:
818
.yo1:
819
        mov     al, 'ð'
819
        mov     al, 'ð'
820
        jmp     .doit
820
        jmp     .doit
821
.yo2:
821
.yo2:
822
        mov     al, 'ñ'
822
        mov     al, 'ñ'
823
        jmp     .doit
823
        jmp     .doit
824
.rus1:
824
.rus1:
825
; 0x410-0x43F -> 0x80-0xAF
825
; 0x410-0x43F -> 0x80-0xAF
826
        add     al, 0x70
826
        add     al, 0x70
827
        jmp     .doit
827
        jmp     .doit
828
.rus2:
828
.rus2:
829
; 0x440-0x44F -> 0xE0-0xEF
829
; 0x440-0x44F -> 0xE0-0xEF
830
        add     al, 0xA0
830
        add     al, 0xA0
831
.ascii:
831
.ascii:
832
.doit:
832
.doit:
833
        ret
833
        ret