Subversion Repositories Kolibri OS

Rev

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

Rev 91 Rev 94
1
; System function 70 - files with long names (LFN)
1
; System function 70 - files with long names (LFN)
2
; diamond, 2006
2
; diamond, 2006
3
 
3
 
4
iglobal
4
iglobal
5
; in this table names must be in lowercase
5
; in this table names must be in lowercase
6
rootdirs:
6
rootdirs:
7
        db      2,'rd'
7
        db      2,'rd'
8
        dd      fs_OnRamdisk
8
        dd      fs_OnRamdisk
9
        dd      fs_NextRamdisk
9
        dd      fs_NextRamdisk
10
        db      7,'ramdisk'
10
        db      7,'ramdisk'
11
        dd      fs_OnRamdisk
11
        dd      fs_OnRamdisk
12
        dd      fs_NextRamdisk
12
        dd      fs_NextRamdisk
13
        db      2,'fd'
13
        db      2,'fd'
14
        dd      fs_OnFloppy
14
        dd      fs_OnFloppy
15
        dd      fs_NextFloppy
15
        dd      fs_NextFloppy
16
        db      10,'floppydisk'
16
        db      10,'floppydisk'
17
        dd      fs_OnFloppy
17
        dd      fs_OnFloppy
18
        dd      fs_NextFloppy
18
        dd      fs_NextFloppy
19
        db      3,'hd0'
19
        db      3,'hd0'
20
        dd      fs_OnHd0
20
        dd      fs_OnHd0
21
        dd      fs_NextHd0
21
        dd      fs_NextHd0
22
        db      3,'hd1'
22
        db      3,'hd1'
23
        dd      fs_OnHd1
23
        dd      fs_OnHd1
24
        dd      fs_NextHd1
24
        dd      fs_NextHd1
25
        db      3,'hd2'
25
        db      3,'hd2'
26
        dd      fs_OnHd2
26
        dd      fs_OnHd2
27
        dd      fs_NextHd2
27
        dd      fs_NextHd2
28
        db      3,'hd3'
28
        db      3,'hd3'
29
        dd      fs_OnHd3
29
        dd      fs_OnHd3
30
        dd      fs_NextHd3
30
        dd      fs_NextHd3
31
;**********************************************
31
;**********************************************
32
        db      3,'cd0'
32
        db      3,'cd0'
33
        dd      fs_OnCd0
33
        dd      fs_OnCd0
34
        dd      fs_NextCd
34
        dd      fs_NextCd
35
        db      3,'cd1'
35
        db      3,'cd1'
36
        dd      fs_OnCd1
36
        dd      fs_OnCd1
37
        dd      fs_NextCd
37
        dd      fs_NextCd
38
        db      3,'cd2'
38
        db      3,'cd2'
39
        dd      fs_OnCd2
39
        dd      fs_OnCd2
40
        dd      fs_NextCd
40
        dd      fs_NextCd
41
        db      3,'cd3'
41
        db      3,'cd3'
42
        dd      fs_OnCd3
42
        dd      fs_OnCd3
43
        dd      fs_NextCd
43
        dd      fs_NextCd
44
;***********************************************        
44
;***********************************************        
45
        db      0
45
        db      0
46
 
46
 
47
 
47
 
48
virtual_root_query:
48
virtual_root_query:
49
        dd      fs_HasRamdisk
49
        dd      fs_HasRamdisk
50
        db      'rd',0
50
        db      'rd',0
51
        dd      fs_HasFloppy
51
        dd      fs_HasFloppy
52
        db      'fd',0
52
        db      'fd',0
53
        dd      fs_HasHd0
53
        dd      fs_HasHd0
54
        db      'hd0',0
54
        db      'hd0',0
55
        dd      fs_HasHd1
55
        dd      fs_HasHd1
56
        db      'hd1',0
56
        db      'hd1',0
57
        dd      fs_HasHd2
57
        dd      fs_HasHd2
58
        db      'hd2',0
58
        db      'hd2',0
59
        dd      fs_HasHd3
59
        dd      fs_HasHd3
60
        db      'hd3',0
60
        db      'hd3',0
61
;**********************************************
61
;**********************************************
62
        dd      fs_HasCd0
62
        dd      fs_HasCd0
63
        db      'cd0',0
63
        db      'cd0',0
64
        dd      fs_HasCd1
64
        dd      fs_HasCd1
65
        db      'cd1',0
65
        db      'cd1',0
66
        dd      fs_HasCd2
66
        dd      fs_HasCd2
67
        db      'cd2',0
67
        db      'cd2',0
68
        dd      fs_HasCd3
68
        dd      fs_HasCd3
69
        db      'cd3',0
69
        db      'cd3',0
70
;**********************************************
70
;**********************************************
71
        dd      0
71
        dd      0
72
endg
72
endg
73
 
73
 
74
file_system_lfn:
74
file_system_lfn:
75
; in: eax->fileinfo block
75
; in: eax->fileinfo block
76
; operation codes:
76
; operation codes:
77
; 0 : read file
77
; 0 : read file
78
; 1 : read folder
78
; 1 : read folder
79
; 2 : create/rewrite file
79
; 2 : create/rewrite file
80
; 3 : write/append to file - not implemented yet
80
; 3 : write/append to file - not implemented yet
81
; 4 : set end of file - not implemented yet
81
; 4 : set end of file - not implemented yet
82
; 5 : get file/directory attributes structure
82
; 5 : get file/directory attributes structure
83
; 6 : set file/directory attributes structure
83
; 6 : set file/directory attributes structure
84
; 7 : start application
84
; 7 : start application
85
; 8 : delete file - not implemented yet
85
; 8 : delete file - not implemented yet
86
; 9 : create directory - not implemented yet
86
; 9 : create directory - not implemented yet
87
; 10: rename file/directory - not implemented yet
87
; 10: rename file/directory - not implemented yet
88
 
88
 
89
        add     eax, std_application_base_address
89
        add     eax, std_application_base_address
90
; parse file name
90
; parse file name
91
        xchg    ebx, eax
91
        xchg    ebx, eax
92
        lea     esi, [ebx+20]
92
        lea     esi, [ebx+20]
93
        mov     ebp, esi        ; for 'start app' function full path must be known
93
        mov     ebp, esi        ; for 'start app' function full path must be known
94
        lodsb
94
        lodsb
95
        test    al, al
95
        test    al, al
96
        jnz     @f
96
        jnz     @f
97
        mov     esi, [esi]
97
        mov     esi, [esi]
98
        add     esi, std_application_base_address
98
        add     esi, std_application_base_address
99
        mov     ebp, esi
99
        mov     ebp, esi
100
        lodsb
100
        lodsb
101
@@:
101
@@:
102
        cmp     al, '/'
102
        cmp     al, '/'
103
        jz      @f
103
        jz      @f
104
.notfound:
104
.notfound:
105
        mov     dword [esp+36], 5       ; file not found
105
        mov     dword [esp+36], 5       ; file not found
106
        ret
106
        ret
107
@@:
107
@@:
108
        cmp     byte [esi], 0
108
        cmp     byte [esi], 0
109
        jz      .rootdir
109
        jz      .rootdir
110
        mov     edi, rootdirs-8
110
        mov     edi, rootdirs-8
111
        xor     ecx, ecx
111
        xor     ecx, ecx
112
        push    esi
112
        push    esi
113
.scan1:
113
.scan1:
114
        pop     esi
114
        pop     esi
115
        add     edi, ecx
115
        add     edi, ecx
116
        scasd
116
        scasd
117
        scasd
117
        scasd
118
        mov     cl, byte [edi]
118
        mov     cl, byte [edi]
119
        jecxz   .notfound
119
        jecxz   .notfound
120
        inc     edi
120
        inc     edi
121
        push    esi
121
        push    esi
122
@@:
122
@@:
123
        lodsb
123
        lodsb
124
        or      al, 20h
124
        or      al, 20h
125
        scasb
125
        scasb
126
        loopz   @b
126
        loopz   @b
127
        jnz     .scan1
127
        jnz     .scan1
128
        lodsb
128
        lodsb
129
        cmp     al, '/'
129
        cmp     al, '/'
130
        jz      .found1
130
        jz      .found1
131
        test    al, al
131
        test    al, al
132
        jnz     .scan1
132
        jnz     .scan1
133
        pop     eax
133
        pop     eax
134
; directory /xxx
134
; directory /xxx
135
.maindir:
135
.maindir:
136
        cmp     dword [ebx], 1
136
        cmp     dword [ebx], 1
137
        jnz     .access_denied
137
        jnz     .access_denied
138
        xor     eax, eax
138
        xor     eax, eax
139
        mov     ebp, [ebx+12]
139
        mov     ebp, [ebx+12]
140
        mov     edx, [ebx+16]
140
        mov     edx, [ebx+16]
141
        add     edx, std_application_base_address
141
        add     edx, std_application_base_address
142
        push    dword [ebx+4]   ; first block
142
        push    dword [ebx+4]   ; first block
143
        mov     ebx, [ebx+8]    ; flags
143
        mov     ebx, [ebx+8]    ; flags
144
        mov     esi, [edi+4]
144
        mov     esi, [edi+4]
145
; ebx=flags, [esp]=first block, ebp=number of blocks, edx=return area, esi='Next' handler
145
; ebx=flags, [esp]=first block, ebp=number of blocks, edx=return area, esi='Next' handler
146
        mov     edi, edx
146
        mov     edi, edx
147
        mov     ecx, 32/4
147
        mov     ecx, 32/4
148
        rep     stosd
148
        rep     stosd
149
        mov     byte [edx], 1   ; version
149
        mov     byte [edx], 1   ; version
150
.maindir_loop:
150
.maindir_loop:
151
        call    esi
151
        call    esi
152
        jc      .maindir_done
152
        jc      .maindir_done
153
        inc     dword [edx+8]
153
        inc     dword [edx+8]
154
        dec     dword [esp]
154
        dec     dword [esp]
155
        jns     .maindir_loop
155
        jns     .maindir_loop
156
        dec     ebp
156
        dec     ebp
157
        js      .maindir_loop
157
        js      .maindir_loop
158
        inc     dword [edx+4]
158
        inc     dword [edx+4]
159
        mov     dword [edi], 0x10       ; attributes: folder
159
        mov     dword [edi], 0x10       ; attributes: folder
160
        mov     dword [edi+4], 1        ; name type: UNICODE
160
        mov     dword [edi+4], 1        ; name type: UNICODE
161
        push    eax
161
        push    eax
162
        xor     eax, eax
162
        xor     eax, eax
163
        add     edi, 8
163
        add     edi, 8
164
        mov     ecx, 40/4-2
164
        mov     ecx, 40/4-2
165
        rep     stosd
165
        rep     stosd
166
        pop     eax
166
        pop     eax
167
        push    eax edx
167
        push    eax edx
168
; convert number in eax to decimal UNICODE string
168
; convert number in eax to decimal UNICODE string
169
        push    edi
169
        push    edi
170
        push    -'0'
170
        push    -'0'
171
        mov     cl, 10
171
        mov     cl, 10
172
@@:
172
@@:
173
        xor     edx, edx
173
        xor     edx, edx
174
        div     ecx
174
        div     ecx
175
        push    edx
175
        push    edx
176
        test    eax, eax
176
        test    eax, eax
177
        jnz     @b
177
        jnz     @b
178
@@:
178
@@:
179
        pop     eax
179
        pop     eax
180
        add     al, '0'
180
        add     al, '0'
181
        stosb
181
        stosb
182
        test    bl, 1           ; UNICODE name?
182
        test    bl, 1           ; UNICODE name?
183
        jz      .ansi2
183
        jz      .ansi2
184
        mov     byte [edi], 0
184
        mov     byte [edi], 0
185
        inc     edi
185
        inc     edi
186
.ansi2:
186
.ansi2:
187
        test    al, al
187
        test    al, al
188
        jnz     @b
188
        jnz     @b
189
        mov     byte [edi-1], 0
189
        mov     byte [edi-1], 0
190
        pop     edi
190
        pop     edi
191
; UNICODE name length is 520 bytes, ANSI - 264
191
; UNICODE name length is 520 bytes, ANSI - 264
192
        add     edi, 520
192
        add     edi, 520
193
        test    bl, 1
193
        test    bl, 1
194
        jnz     @f
194
        jnz     @f
195
        sub     edi, 520-264
195
        sub     edi, 520-264
196
@@:
196
@@:
197
        pop     edx eax
197
        pop     edx eax
198
        jmp     .maindir_loop
198
        jmp     .maindir_loop
199
.maindir_done:
199
.maindir_done:
200
        pop     eax
200
        pop     eax
201
        mov     ebx, [edx+4]
201
        mov     ebx, [edx+4]
202
        xor     eax, eax
202
        xor     eax, eax
203
        dec     ebp
203
        dec     ebp
204
        js      @f
204
        js      @f
205
        mov     al, ERROR_END_OF_FILE
205
        mov     al, ERROR_END_OF_FILE
206
@@:
206
@@:
207
        mov     [esp+36], eax
207
        mov     [esp+36], eax
208
        mov     [esp+24], ebx
208
        mov     [esp+24], ebx
209
        ret
209
        ret
210
; directory /
210
; directory /
211
.rootdir:
211
.rootdir:
212
        cmp     dword [ebx], 1  ; read folder?
212
        cmp     dword [ebx], 1  ; read folder?
213
        jz      .readroot
213
        jz      .readroot
214
.access_denied:
214
.access_denied:
215
        mov     dword [esp+36], 10      ; access denied
215
        mov     dword [esp+36], 10      ; access denied
216
        ret
216
        ret
217
 
217
 
218
.readroot:
218
.readroot:
219
; virtual root folder - special handler
219
; virtual root folder - special handler
220
        mov     esi, virtual_root_query
220
        mov     esi, virtual_root_query
221
        mov     ebp, [ebx+12]
221
        mov     ebp, [ebx+12]
222
        mov     edx, [ebx+16]
222
        mov     edx, [ebx+16]
223
        add     edx, std_application_base_address
223
        add     edx, std_application_base_address
224
        push    dword [ebx+4]   ; first block
224
        push    dword [ebx+4]   ; first block
225
        mov     ebx, [ebx+8]    ; flags
225
        mov     ebx, [ebx+8]    ; flags
226
        xor     eax, eax
226
        xor     eax, eax
227
; eax=0, [esp]=first block, ebx=flags, ebp=number of blocks, edx=return area
227
; eax=0, [esp]=first block, ebx=flags, ebp=number of blocks, edx=return area
228
        mov     edi, edx
228
        mov     edi, edx
229
        mov     ecx, 32/4
229
        mov     ecx, 32/4
230
        rep     stosd
230
        rep     stosd
231
        mov     byte [edx], 1   ; version
231
        mov     byte [edx], 1   ; version
232
.readroot_loop:
232
.readroot_loop:
233
        cmp     dword [esi], eax
233
        cmp     dword [esi], eax
234
        jz      .readroot_done
234
        jz      .readroot_done
235
        call    dword [esi]
235
        call    dword [esi]
236
        add     esi, 4
236
        add     esi, 4
237
        test    eax, eax
237
        test    eax, eax
238
        jnz     @f
238
        jnz     @f
239
.readroot_next:
239
.readroot_next:
240
        or      ecx, -1
240
        or      ecx, -1
241
        xchg    esi, edi
241
        xchg    esi, edi
242
        repnz   scasb
242
        repnz   scasb
243
        xchg    esi, edi
243
        xchg    esi, edi
244
        jmp     .readroot_loop
244
        jmp     .readroot_loop
245
@@:
245
@@:
246
        xor     eax, eax
246
        xor     eax, eax
247
        inc     dword [edx+8]
247
        inc     dword [edx+8]
248
        dec     dword [esp]
248
        dec     dword [esp]
249
        jns     .readroot_next
249
        jns     .readroot_next
250
        dec     ebp
250
        dec     ebp
251
        js      .readroot_next
251
        js      .readroot_next
252
        inc     dword [edx+4]
252
        inc     dword [edx+4]
253
        mov     dword [edi], 0x10       ; attributes: folder
253
        mov     dword [edi], 0x10       ; attributes: folder
254
        mov     dword [edi+4], 1        ; name type: UNICODE
254
        mov     dword [edi+4], 1        ; name type: UNICODE
255
        add     edi, 8
255
        add     edi, 8
256
        mov     ecx, 40/4-2
256
        mov     ecx, 40/4-2
257
        rep     stosd
257
        rep     stosd
258
        push    edi
258
        push    edi
259
@@:
259
@@:
260
        lodsb
260
        lodsb
261
        stosb
261
        stosb
262
        test    bl, 1
262
        test    bl, 1
263
        jz      .ansi
263
        jz      .ansi
264
        mov     byte [edi], 0
264
        mov     byte [edi], 0
265
        inc     edi
265
        inc     edi
266
.ansi:
266
.ansi:
267
        test    eax, eax
267
        test    eax, eax
268
        jnz     @b
268
        jnz     @b
269
        pop     edi
269
        pop     edi
270
        add     edi, 520
270
        add     edi, 520
271
        test    bl, 1
271
        test    bl, 1
272
        jnz     .readroot_loop
272
        jnz     .readroot_loop
273
        sub     edi, 520-264
273
        sub     edi, 520-264
274
        jmp     .readroot_loop
274
        jmp     .readroot_loop
275
.readroot_done:
275
.readroot_done:
276
        pop     eax
276
        pop     eax
277
        mov     ebx, [edx+4]
277
        mov     ebx, [edx+4]
278
        xor     eax, eax
278
        xor     eax, eax
279
        dec     ebp
279
        dec     ebp
280
        js      @f
280
        js      @f
281
        mov     al, ERROR_END_OF_FILE
281
        mov     al, ERROR_END_OF_FILE
282
@@:
282
@@:
283
        mov     [esp+36], eax
283
        mov     [esp+36], eax
284
        mov     [esp+24], ebx
284
        mov     [esp+24], ebx
285
        ret
285
        ret
286
 
286
 
287
.found1:
287
.found1:
288
        pop     eax
288
        pop     eax
289
        cmp     byte [esi], 0
289
        cmp     byte [esi], 0
290
        jz      .maindir
290
        jz      .maindir
291
; read partition number
291
; read partition number
292
        xor     ecx, ecx
292
        xor     ecx, ecx
293
        xor     eax, eax
293
        xor     eax, eax
294
@@:
294
@@:
295
        lodsb
295
        lodsb
296
        cmp     al, '/'
296
        cmp     al, '/'
297
        jz      .done1
297
        jz      .done1
298
        test    al, al
298
        test    al, al
299
        jz      .done1
299
        jz      .done1
300
        sub     al, '0'
300
        sub     al, '0'
301
        cmp     al, 9
301
        cmp     al, 9
302
        ja      .notfound
302
        ja      .notfound
303
        imul    ecx, 10
303
        imul    ecx, 10
304
        add     ecx, eax
304
        add     ecx, eax
305
        jmp     @b
305
        jmp     @b
306
.done1:
306
.done1:
307
        test    ecx, ecx
307
        test    ecx, ecx
308
        jz      .notfound
308
        jz      .notfound
309
        test    al, al
309
        test    al, al
310
        jnz     @f
310
        jnz     @f
311
        dec     esi
311
        dec     esi
312
@@:
312
@@:
313
; now [edi] contains handler address, ecx - partition number,
313
; now [edi] contains handler address, ecx - partition number,
314
; esi points to ASCIIZ string - rest of name
314
; esi points to ASCIIZ string - rest of name
315
        jmp     dword [edi]
315
        jmp     dword [edi]
316
 
316
 
317
; handlers for devices
317
; handlers for devices
318
; in: ecx = 0 => query virtual directory /xxx
318
; in: ecx = 0 => query virtual directory /xxx
319
; in: ecx = partition number
319
; in: ecx = partition number
320
;     esi -> relative (for device) name
320
;     esi -> relative (for device) name
321
;     ebx -> fileinfo
321
;     ebx -> fileinfo
322
; out: [esp+36]=image of eax, [esp+24]=image of ebx
322
; out: [esp+36]=image of eax, [esp+24]=image of ebx
323
 
323
 
324
fs_OnRamdisk:
324
fs_OnRamdisk:
325
        cmp     ecx, 1
325
        cmp     ecx, 1
326
        jnz     file_system_lfn.notfound
326
        jnz     file_system_lfn.notfound
327
        mov     eax, [ebx]
327
        mov     eax, [ebx]
328
        cmp     eax, fs_NumRamdiskServices
328
        cmp     eax, fs_NumRamdiskServices
329
        jae     .not_impl
329
        jae     .not_impl
330
        mov     ecx, [ebx+12]
330
        mov     ecx, [ebx+12]
331
        mov     edx, [ebx+16]
331
        mov     edx, [ebx+16]
332
        add     edx, std_application_base_address
332
        add     edx, std_application_base_address
333
        add     ebx, 4
333
        add     ebx, 4
334
        call    dword [fs_RamdiskServices + eax*4]
334
        call    dword [fs_RamdiskServices + eax*4]
335
        mov     [esp+36], eax
335
        mov     [esp+36], eax
336
        mov     [esp+24], ebx
336
        mov     [esp+24], ebx
337
        ret
337
        ret
338
.not_impl:
338
.not_impl:
339
        mov     dword [esp+36], 2       ; not implemented
339
        mov     dword [esp+36], 2       ; not implemented
340
        ret
340
        ret
341
 
341
 
342
fs_NotImplemented:
342
fs_NotImplemented:
343
        mov     eax, 2
343
        mov     eax, 2
344
        ret
344
        ret
345
 
345
 
346
fs_RamdiskServices:
346
fs_RamdiskServices:
347
        dd      fs_RamdiskRead
347
        dd      fs_RamdiskRead
348
        dd      fs_RamdiskReadFolder
348
        dd      fs_RamdiskReadFolder
349
        dd      fs_RamdiskRewrite
349
        dd      fs_RamdiskRewrite
350
        dd      fs_NotImplemented
350
        dd      fs_NotImplemented
351
        dd      fs_NotImplemented
351
        dd      fs_NotImplemented
352
        dd      fs_RamdiskGetFileInfo
352
        dd      fs_RamdiskGetFileInfo
353
        dd      fs_RamdiskSetFileInfo
353
        dd      fs_RamdiskSetFileInfo
354
        dd      fs_RamdiskExecute
354
        dd      fs_RamdiskExecute
355
fs_NumRamdiskServices = ($ - fs_RamdiskServices)/4
355
fs_NumRamdiskServices = ($ - fs_RamdiskServices)/4
356
 
356
 
357
fs_OnFloppy:
357
fs_OnFloppy:
358
        cmp     ecx, 2
358
        cmp     ecx, 2
359
        ja      file_system_lfn.notfound
359
        ja      file_system_lfn.notfound
360
        mov     eax, [ebx]
360
        mov     eax, [ebx]
361
        cmp     eax, fs_NumFloppyServices
361
        cmp     eax, fs_NumFloppyServices
362
        jae     fs_OnRamdisk.not_impl
362
        jae     fs_OnRamdisk.not_impl
363
        call    reserve_flp
363
        call    reserve_flp
364
        mov     [flp_number], cl
364
        mov     [flp_number], cl
365
        mov     ecx, [ebx+12]
365
        mov     ecx, [ebx+12]
366
        mov     edx, [ebx+16]
366
        mov     edx, [ebx+16]
367
        add     edx, std_application_base_address
367
        add     edx, std_application_base_address
368
        add     ebx, 4
368
        add     ebx, 4
369
        call    dword [fs_FloppyServices + eax*4]
369
        call    dword [fs_FloppyServices + eax*4]
370
        and     [flp_status], 0
370
        and     [flp_status], 0
371
        mov     [esp+36], eax
371
        mov     [esp+36], eax
372
        mov     [esp+24], ebx
372
        mov     [esp+24], ebx
373
        ret
373
        ret
374
 
374
 
375
fs_FloppyServices:
375
fs_FloppyServices:
376
        dd      fs_FloppyRead
376
        dd      fs_FloppyRead
377
        dd      fs_FloppyReadFolder
377
        dd      fs_FloppyReadFolder
378
        dd      fs_FloppyRewrite
378
        dd      fs_FloppyRewrite
379
        dd      fs_NotImplemented
379
        dd      fs_NotImplemented
380
        dd      fs_NotImplemented
380
        dd      fs_NotImplemented
381
        dd      fs_FloppyGetFileInfo
381
        dd      fs_FloppyGetFileInfo
382
        dd      fs_FloppySetFileInfo
382
        dd      fs_FloppySetFileInfo
383
        dd      fs_FloppyExecute
383
        dd      fs_FloppyExecute
384
fs_NumFloppyServices = ($ - fs_FloppyServices)/4
384
fs_NumFloppyServices = ($ - fs_FloppyServices)/4
385
 
385
 
386
fs_OnHd0:
386
fs_OnHd0:
387
        call    reserve_hd1
387
        call    reserve_hd1
388
        mov     [hdbase], 0x1F0
388
        mov     [hdbase], 0x1F0
389
        mov     [hdid], 0
389
        mov     [hdid], 0
390
        push    1
390
        push    1
391
        jmp     fs_OnHd
391
        jmp     fs_OnHd
392
fs_OnHd1:
392
fs_OnHd1:
393
        call    reserve_hd1
393
        call    reserve_hd1
394
        mov     [hdbase], 0x1F0
394
        mov     [hdbase], 0x1F0
395
        mov     [hdid], 0x10
395
        mov     [hdid], 0x10
396
        push    2
396
        push    2
397
        jmp     fs_OnHd
397
        jmp     fs_OnHd
398
fs_OnHd2:
398
fs_OnHd2:
399
        call    reserve_hd1
399
        call    reserve_hd1
400
        mov     [hdbase], 0x170
400
        mov     [hdbase], 0x170
401
        mov     [hdid], 0
401
        mov     [hdid], 0
402
        push    3
402
        push    3
403
        jmp     fs_OnHd
403
        jmp     fs_OnHd
404
fs_OnHd3:
404
fs_OnHd3:
405
        call    reserve_hd1
405
        call    reserve_hd1
406
        mov     [hdbase], 0x170
406
        mov     [hdbase], 0x170
407
        mov     [hdid], 0x10
407
        mov     [hdid], 0x10
408
        push    4
408
        push    4
409
fs_OnHd:
409
fs_OnHd:
410
        pop     eax
410
        pop     eax
411
        mov     [hdpos], eax
411
        mov     [hdpos], eax
412
        cmp     ecx, 0x100
412
        cmp     ecx, 0x100
413
        jae     .nf
413
        jae     .nf
414
        cmp     cl, [0x40001+eax]
414
        cmp     cl, [0x40001+eax]
415
        jbe     @f
415
        jbe     @f
416
.nf:
416
.nf:
417
        and     [hd1_status], 0
417
        and     [hd1_status], 0
418
        mov     dword [esp+36], 5       ; not found
418
        mov     dword [esp+36], 5       ; not found
419
        ret
419
        ret
420
@@:
420
@@:
421
        mov     [fat32part], ecx
421
        mov     [fat32part], ecx
422
        push    ebx esi
422
        push    ebx esi
423
        call    choice_necessity_partition_1
423
        call    choice_necessity_partition_1
424
        pop     esi ebx
424
        pop     esi ebx
425
        mov     ecx, [ebx+12]
425
        mov     ecx, [ebx+12]
426
        mov     edx, [ebx+16]
426
        mov     edx, [ebx+16]
427
        add     edx, std_application_base_address
427
        add     edx, std_application_base_address
428
        mov     eax, [ebx]
428
        mov     eax, [ebx]
429
        cmp     eax, fs_NumHdServices
429
        cmp     eax, fs_NumHdServices
430
        jae     .not_impl
430
        jae     .not_impl
431
        add     ebx, 4
431
        add     ebx, 4
432
        call    dword [fs_HdServices + eax*4]
432
        call    dword [fs_HdServices + eax*4]
433
        and     [hd1_status], 0
433
        and     [hd1_status], 0
434
        mov     [esp+36], eax
434
        mov     [esp+36], eax
435
        mov     [esp+24], ebx
435
        mov     [esp+24], ebx
436
        ret
436
        ret
437
.not_impl:
437
.not_impl:
438
        and     [hd1_status], 0
438
        and     [hd1_status], 0
439
        mov     dword [esp+36], 2       ; not implemented
439
        mov     dword [esp+36], 2       ; not implemented
440
        ret
440
        ret
441
 
441
 
442
fs_HdServices:
442
fs_HdServices:
443
        dd      fs_HdRead
443
        dd      fs_HdRead
444
        dd      fs_HdReadFolder
444
        dd      fs_HdReadFolder
445
        dd      fs_HdRewrite
445
        dd      fs_HdRewrite
446
        dd      fs_NotImplemented
446
        dd      fs_NotImplemented
447
        dd      fs_NotImplemented
447
        dd      fs_NotImplemented
448
        dd      fs_HdGetFileInfo
448
        dd      fs_HdGetFileInfo
449
        dd      fs_HdSetFileInfo
449
        dd      fs_HdSetFileInfo
450
        dd      fs_HdExecute
450
        dd      fs_HdExecute
451
fs_NumHdServices = ($ - fs_HdServices)/4
451
fs_NumHdServices = ($ - fs_HdServices)/4
452
 
452
 
453
;*******************************************************
453
;*******************************************************
454
fs_OnCd0:
454
fs_OnCd0:
455
        call    reserve_cd
455
        call    reserve_cd
456
        mov  [ChannelNumber],1
456
        mov  [ChannelNumber],1
457
        mov  [DiskNumber],0
457
        mov  [DiskNumber],0
458
        push    6
458
        push    6
459
        jmp     fs_OnCd
459
        jmp     fs_OnCd
460
fs_OnCd1:
460
fs_OnCd1:
461
        call    reserve_cd
461
        call    reserve_cd
462
        mov  [ChannelNumber],1
462
        mov  [ChannelNumber],1
463
        mov  [DiskNumber],1
463
        mov  [DiskNumber],1
464
        push    4
464
        push    4
465
        jmp     fs_OnCd
465
        jmp     fs_OnCd
466
fs_OnCd2:
466
fs_OnCd2:
467
        call    reserve_cd
467
        call    reserve_cd
468
        mov  [ChannelNumber],2
468
        mov  [ChannelNumber],2
469
        mov  [DiskNumber],0
469
        mov  [DiskNumber],0
470
        push    2
470
        push    2
471
        jmp     fs_OnCd
471
        jmp     fs_OnCd
472
fs_OnCd3:
472
fs_OnCd3:
473
        call    reserve_cd
473
        call    reserve_cd
474
        mov  [ChannelNumber],2
474
        mov  [ChannelNumber],2
475
        mov  [DiskNumber],1
475
        mov  [DiskNumber],1
476
        push    0
476
        push    0
477
fs_OnCd:
477
fs_OnCd:
478
 
478
 
479
        pop     eax
479
        pop     eax
480
        mov     [hdpos], eax
480
        mov     [hdpos], eax
481
        cmp     ecx, 0x100
481
        cmp     ecx, 0x100
482
        jae     .nf
482
        jae     .nf
483
        push    cx bx
483
        push    cx bx
484
        mov     cl,al
484
        mov     cl,al
485
        mov     bl,[0x40001]
485
        mov     bl,[0x40001]
486
        shr     bl,cl
486
        shr     bl,cl
487
        test    bl,2
487
        test    bl,2
488
        pop     bx cx
488
        pop     bx cx
489
 
489
 
490
        jnz     @f
490
        jnz     @f
491
.nf:
491
.nf:
492
        and    [cd_status], 0
492
        and    [cd_status], 0
493
        mov     dword [esp+36], 5       ; not found
493
        mov     dword [esp+36], 5       ; not found
494
        ret
494
        ret
495
@@:
495
@@:
496
        mov     ecx, [ebx+12]
496
        mov     ecx, [ebx+12]
497
        mov     edx, [ebx+16]
497
        mov     edx, [ebx+16]
498
        add     edx, std_application_base_address
498
        add     edx, std_application_base_address
499
        mov     eax, [ebx]
499
        mov     eax, [ebx]
500
        cmp     eax,fs_NumCdServices
500
        cmp     eax,fs_NumCdServices
501
        jae      .not_impl
501
        jae      .not_impl
502
        add     ebx, 4
502
        add     ebx, 4
503
        call    dword [fs_CdServices + eax*4]
503
        call    dword [fs_CdServices + eax*4]
504
        and     [cd_status], 0
504
        and     [cd_status], 0
505
        mov     [esp+36], eax
505
        mov     [esp+36], eax
506
        mov     [esp+24], ebx
506
        mov     [esp+24], ebx
507
        ret
507
        ret
508
.not_impl:
508
.not_impl:
509
        and     [cd_status], 0
509
        and     [cd_status], 0
510
        mov     dword [esp+36], 2       ; not implemented
510
        mov     dword [esp+36], 2       ; not implemented
511
        ret
511
        ret
512
 
512
 
513
fs_CdServices:
513
fs_CdServices:
514
        dd      fs_CdRead
514
        dd      fs_CdRead
515
        dd      fs_CdReadFolder
515
        dd      fs_CdReadFolder
516
        dd      fs_NotImplemented
516
        dd      fs_NotImplemented
517
        dd      fs_NotImplemented
517
        dd      fs_NotImplemented
518
        dd      fs_NotImplemented
518
        dd      fs_NotImplemented
519
        dd      fs_CdGetFileInfo
519
        dd      fs_CdGetFileInfo
520
        dd      fs_NotImplemented
520
        dd      fs_NotImplemented
-
 
521
        dd      fs_CdExecute
521
fs_NumCdServices = ($ - fs_CdServices)/4
522
fs_NumCdServices = ($ - fs_CdServices)/4
522
 
523
 
523
;*******************************************************
524
;*******************************************************
524
 
525
 
525
fs_HasRamdisk:
526
fs_HasRamdisk:
526
        mov     al, 1   ; we always have ramdisk
527
        mov     al, 1   ; we always have ramdisk
527
        ret
528
        ret
528
 
529
 
529
fs_HasFloppy:
530
fs_HasFloppy:
530
        cmp     byte [0x40000], 0
531
        cmp     byte [0x40000], 0
531
        setnz   al
532
        setnz   al
532
        ret
533
        ret
533
 
534
 
534
fs_HasHd0:
535
fs_HasHd0:
535
        mov     al, [0x40001]
536
        mov     al, [0x40001]
536
        and     al, 11000000b
537
        and     al, 11000000b
537
        cmp     al, 01000000b
538
        cmp     al, 01000000b
538
        setz    al
539
        setz    al
539
        ret
540
        ret
540
fs_HasHd1:
541
fs_HasHd1:
541
        mov     al, [0x40001]
542
        mov     al, [0x40001]
542
        and     al, 00110000b
543
        and     al, 00110000b
543
        cmp     al, 00010000b
544
        cmp     al, 00010000b
544
        setz    al
545
        setz    al
545
        ret
546
        ret
546
fs_HasHd2:
547
fs_HasHd2:
547
        mov     al, [0x40001]
548
        mov     al, [0x40001]
548
        and     al, 00001100b
549
        and     al, 00001100b
549
        cmp     al, 00000100b
550
        cmp     al, 00000100b
550
        setz    al
551
        setz    al
551
        ret
552
        ret
552
fs_HasHd3:
553
fs_HasHd3:
553
        mov     al, [0x40001]
554
        mov     al, [0x40001]
554
        and     al, 00000011b
555
        and     al, 00000011b
555
        cmp     al, 00000001b
556
        cmp     al, 00000001b
556
        setz    al
557
        setz    al
557
        ret
558
        ret
558
 
559
 
559
;*******************************************************
560
;*******************************************************
560
fs_HasCd0:
561
fs_HasCd0:
561
        mov     al, [0x40001]
562
        mov     al, [0x40001]
562
        and     al, 11000000b
563
        and     al, 11000000b
563
        cmp     al, 10000000b
564
        cmp     al, 10000000b
564
        setz    al
565
        setz    al
565
        ret
566
        ret
566
fs_HasCd1:
567
fs_HasCd1:
567
        mov     al, [0x40001]
568
        mov     al, [0x40001]
568
        and     al, 00110000b
569
        and     al, 00110000b
569
        cmp     al, 00100000b
570
        cmp     al, 00100000b
570
        setz    al
571
        setz    al
571
        ret
572
        ret
572
fs_HasCd2:
573
fs_HasCd2:
573
        mov     al, [0x40001]
574
        mov     al, [0x40001]
574
        and     al, 00001100b
575
        and     al, 00001100b
575
        cmp     al, 00001000b
576
        cmp     al, 00001000b
576
        setz    al
577
        setz    al
577
        ret
578
        ret
578
fs_HasCd3:
579
fs_HasCd3:
579
        mov     al, [0x40001]
580
        mov     al, [0x40001]
580
        and     al, 00000011b
581
        and     al, 00000011b
581
        cmp     al, 00000010b
582
        cmp     al, 00000010b
582
        setz    al
583
        setz    al
583
        ret
584
        ret
584
;*******************************************************        
585
;*******************************************************        
585
 
586
 
586
; fs_NextXXX functions:
587
; fs_NextXXX functions:
587
; in: eax = partition number, from which start to scan
588
; in: eax = partition number, from which start to scan
588
; out: CF=1 => no more partitions
589
; out: CF=1 => no more partitions
589
;      CF=0 => eax=next partition number
590
;      CF=0 => eax=next partition number
590
 
591
 
591
fs_NextRamdisk:
592
fs_NextRamdisk:
592
; we always have /rd/1
593
; we always have /rd/1
593
        test    eax, eax
594
        test    eax, eax
594
        stc
595
        stc
595
        jnz     @f
596
        jnz     @f
596
        mov     al, 1
597
        mov     al, 1
597
        clc
598
        clc
598
@@:
599
@@:
599
        ret
600
        ret
600
 
601
 
601
fs_NextFloppy:
602
fs_NextFloppy:
602
; we have /fd/1 iff (([0x40000] and 0xF0) != 0) and /fd/2 iff (([0x40000] and 0x0F) != 0)
603
; we have /fd/1 iff (([0x40000] and 0xF0) != 0) and /fd/2 iff (([0x40000] and 0x0F) != 0)
603
        test    byte [0x40000], 0xF0
604
        test    byte [0x40000], 0xF0
604
        jz      .no1
605
        jz      .no1
605
        test    eax, eax
606
        test    eax, eax
606
        jnz     .no1
607
        jnz     .no1
607
        inc     eax
608
        inc     eax
608
        ret     ; CF cleared
609
        ret     ; CF cleared
609
.no1:
610
.no1:
610
        test    byte [0x40000], 0x0F
611
        test    byte [0x40000], 0x0F
611
        jz      .no2
612
        jz      .no2
612
        cmp     al, 2
613
        cmp     al, 2
613
        jae     .no2
614
        jae     .no2
614
        mov     al, 2
615
        mov     al, 2
615
        clc
616
        clc
616
        ret
617
        ret
617
.no2:
618
.no2:
618
        stc
619
        stc
619
        ret
620
        ret
620
 
621
 
621
; on hdx, we have partitions from 1 to [0x40002+x]
622
; on hdx, we have partitions from 1 to [0x40002+x]
622
fs_NextHd0:
623
fs_NextHd0:
623
        push    0
624
        push    0
624
        jmp     fs_NextHd
625
        jmp     fs_NextHd
625
fs_NextHd1:
626
fs_NextHd1:
626
        push    1
627
        push    1
627
        jmp     fs_NextHd
628
        jmp     fs_NextHd
628
fs_NextHd2:
629
fs_NextHd2:
629
        push    2
630
        push    2
630
        jmp     fs_NextHd
631
        jmp     fs_NextHd
631
fs_NextHd3:
632
fs_NextHd3:
632
        push    3
633
        push    3
633
fs_NextHd:
634
fs_NextHd:
634
        pop     ecx
635
        pop     ecx
635
        movzx   ecx, byte [0x40002+ecx]
636
        movzx   ecx, byte [0x40002+ecx]
636
        cmp     eax, ecx
637
        cmp     eax, ecx
637
        jae     fs_NextFloppy.no2
638
        jae     fs_NextFloppy.no2
638
        inc     eax
639
        inc     eax
639
        clc
640
        clc
640
        ret
641
        ret
641
        
642
        
642
;*******************************************************
643
;*******************************************************
643
fs_NextCd:
644
fs_NextCd:
644
; we always have /cdX/1
645
; we always have /cdX/1
645
        test    eax, eax
646
        test    eax, eax
646
        stc
647
        stc
647
        jnz     @f
648
        jnz     @f
648
        mov     al, 1
649
        mov     al, 1
649
        clc
650
        clc
650
@@:
651
@@:
651
        ret
652
        ret
652
;*******************************************************
653
;*******************************************************