Subversion Repositories Kolibri OS

Rev

Rev 437 | Rev 465 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
425 victor 1
$Revision: 442 $
431 serge 2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3
;;                                                              ;;
4
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
5
;; Distributed under terms of the GNU General Public License    ;;
6
;;                                                              ;;
7
;; RAMDISK functions                                            ;;
8
;; (C) 2004 Ville Turjanmaa, License: GPL                       ;;
9
;; Addings by M.Lisovin                                         ;;
10
;; LFN support by diamond                                       ;;
11
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1 ha 12
 
5 halyavin 13
; calculate fat chain
1 ha 14
 
5 halyavin 15
calculatefatchain:
16
 
17
   pushad
18
 
381 serge 19
   mov  esi,RAMDISK+512
20
   mov  edi,RAMDISK_FAT
5 halyavin 21
 
22
 fcnew:
23
   mov  eax,dword [esi]
24
   mov  ebx,dword [esi+4]
25
   mov  ecx,dword [esi+8]
26
   mov  edx,ecx
27
   shr  edx,4   ;8 ok
28
   shr  dx,4    ;7 ok
29
   xor  ch,ch
30
   shld ecx,ebx,20 ;6 ok
31
   shr  cx,4     ;5 ok
32
   shld ebx,eax,12
33
   and  ebx,0x0fffffff  ;4 ok
34
   shr  bx,4    ;3 ok
35
   shl  eax,4
36
   and  eax,0x0fffffff  ;2 ok
37
   shr  ax,4  ;1 ok
78 diamond 38
   mov  dword [edi],eax
39
   mov  dword [edi+4],ebx
40
   mov  dword [edi+8],ecx
41
   mov  dword [edi+12],edx
42
   add  edi,16
5 halyavin 43
   add  esi,12
44
 
381 serge 45
   cmp  edi,RAMDISK_FAT+2856*2   ;2849 clusters
5 halyavin 46
   jnz  fcnew
47
 
48
   popad
49
   ret
50
 
51
 
52
restorefatchain:   ; restore fat chain
53
 
54
   pushad
55
 
381 serge 56
   mov  esi,RAMDISK_FAT
57
   mov  edi,RAMDISK+512
5 halyavin 58
 
59
  fcnew2:
60
   mov  eax,dword [esi]
61
   mov  ebx,dword [esi+4]
62
   shl  ax,4
63
   shl  eax,4
64
   shl  bx,4
65
   shr  ebx,4
66
   shrd eax,ebx,8
67
   shr  ebx,8
78 diamond 68
   mov  dword [edi],eax
69
   mov  word [edi+4],bx
70
   add  edi,6
5 halyavin 71
   add  esi,8
72
 
381 serge 73
   cmp  edi,RAMDISK+512+4278     ;4274 bytes - all used FAT
5 halyavin 74
   jb   fcnew2
75
 
381 serge 76
   mov  esi,RAMDISK+512           ; duplicate fat chain
77
   mov  edi,RAMDISK+512+0x1200
5 halyavin 78
   mov  ecx,1069        ;4274/4
79
   cld
80
   rep  movsd
81
 
82
   popad
83
   ret
84
 
85
 
1 ha 86
ramdisk_free_space:
87
;---------------------------------------------
88
;
89
; returns free space in edi
90
; rewr.by Mihasik
91
;---------------------------------------------
92
 
93
        push   eax ebx ecx
94
 
381 serge 95
        mov  edi,RAMDISK_FAT ;start of FAT
1 ha 96
        xor  ax,ax    ;Free cluster=0x0000 in FAT
97
        xor  ebx,ebx  ;counter
5 halyavin 98
        mov  ecx,2849 ;2849 clusters
1 ha 99
        cld
100
    rdfs1:
101
        repne scasw
102
        jnz  rdfs2    ;if last cluster not 0
103
        inc  ebx
78 diamond 104
        test    ecx, ecx
105
        jnz     rdfs1
1 ha 106
    rdfs2:
107
        shl  ebx,9    ;free clusters*512
108
        mov  edi,ebx
247 serge 109
 
1 ha 110
        pop    ecx ebx eax
111
        ret
112
 
113
 
114
expand_filename:
115
;---------------------------------------------
116
;
117
; exapand filename with '.' to 11 character
118
; eax - pointer to filename
119
;---------------------------------------------
120
 
121
        push esi edi ebx
122
 
123
        mov  edi,esp                  ; check for '.' in the name
124
        add  edi,12+8
125
 
126
        mov  esi,eax
127
 
128
        mov  eax,edi
129
        mov  [eax+0],dword '    '
130
        mov  [eax+4],dword '    '
131
        mov  [eax+8],dword '    '
132
 
133
      flr1:
134
 
135
        cmp  [esi],byte '.'
136
        jne  flr2
137
        mov  edi,eax
138
        add  edi,7
139
        jmp  flr3
140
 
141
      flr2:
142
 
143
        mov  bl,[esi]
144
        mov  [edi],bl
145
 
146
      flr3:
147
 
148
        inc  esi
149
        inc  edi
150
 
151
        mov  ebx,eax
152
        add  ebx,11
153
 
154
        cmp  edi,ebx
155
        jbe  flr1
156
 
157
        pop  ebx edi esi
158
        ret
159
 
160
fileread:
161
;----------------------------------------------------------------
162
;
163
;  fileread - sys floppy
164
;
165
;  eax  points to filename 11 chars
166
;  ebx  first wanted block       ; 1+ ; if 0 then set to 1
167
;  ecx  number of blocks to read ; 1+ ; if 0 then set to 1
168
;  edx  mem location to return data
169
;  esi  length of filename 12*X 0=root
170
;
171
;  ret ebx = size or 0xffffffff file not found
172
;      eax = 0 ok read or other = errormsg
173
;
174
;--------------------------------------------------------------
175
        test   ebx,ebx ;if ebx=0 - set to 1
176
        jnz    frfl5
177
        inc    ebx
178
      frfl5:
179
        test   ecx,ecx ;if ecx=0 - set to 1
180
        jnz    frfl6
181
        inc    ecx
182
      frfl6:
183
        test   esi,esi          ; return ramdisk root
184
        jnz    fr_noroot        ;if not root
185
        cmp    ebx,14           ;14 clusters=root dir
186
        ja     oorr
187
        cmp    ecx,14
188
        ja     oorr
189
        jmp    fr_do
190
      oorr:
191
        mov    eax,5            ;out of root range (fnf)
192
        xor    ebx,ebx
193
        dec    ebx              ;0xffffffff
194
        ret
195
 
196
      fr_do:                    ;reading rootdir
197
        mov    edi,edx
198
        dec    ebx
199
        push   edx
247 serge 200
        mov    edx,ecx
1 ha 201
        add    edx,ebx
5 halyavin 202
        cmp    edx,15     ;ebx+ecx=14+1
1 ha 203
        pushf
204
        jbe    fr_do1
205
        sub    edx,14
206
        sub    ecx,edx
207
      fr_do1:
208
        shl    ebx,9
381 serge 209
        mov    esi,RAMDISK+512*19
1 ha 210
        add    esi,ebx
211
        shl    ecx,7
212
        cld
213
        rep    movsd
214
        popf
215
        pop    edx
5 halyavin 216
        jae    fr_do2
1 ha 217
        xor    eax,eax ; ok read
218
        xor    ebx,ebx
219
        ret
220
      fr_do2:        ;if last cluster
221
        mov    eax,6  ;end of file
222
        xor    ebx,ebx
223
        ret
224
 
225
     fr_noroot:
226
 
227
        sub    esp,32
228
        call   expand_filename
229
 
230
        dec    ebx
231
 
232
        push   eax
233
 
234
        push   eax ebx ecx edx esi edi
235
        call   rd_findfile
236
        je     fifound
237
        add    esp,32+28   ;if file not found
238
        ret
239
 
240
     fifound:
241
 
242
        mov    ebx,[edi-11+28]          ;file size
243
        mov    [esp+20],ebx
244
        mov    [esp+24],ebx
245
        add    edi,0xf
246
        movzx  eax,word [edi]
247
        mov    edi,eax                  ;edi=cluster
248
 
249
      frnew:
250