📄 hpi32.lst
字号:
222 1 return TRUE;
223 1 }
224
225
226 unsigned char ReadFile32(unsigned long readLength,unsigned char *pBuffer)
227 {
228 1
229 1 unsigned int len,i;
230 1 unsigned int tlen;
231 1 unsigned long blen;
232 1
233 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
234 1 return FALSE;
235 1 if(!ThisFile.bFileOpen)
236 1 return FALSE;
237 1
238 1 blen=readLength;
239 1 tlen=0;
240 1 if(readLength>MAX_READ_LENGTH)
241 1 return FALSE;
C51 COMPILER V7.06 HPI32 08/10/2005 23:36:35 PAGE 5
242 1
243 1 if(readLength+ThisFile.pointer>ThisFile.LengthInByte)
244 1 return FALSE;
245 1
246 1 ////////////////////////////////////////////
247 1 while(readLength>0)
248 1 {
249 2 if(readLength+ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec)
250 2 len=DeviceInfo.BPB_BytesPerSec;
251 2 else
252 2 len=readLength+ThisFile.OffsetofSector;
253 2
254 2 //////////////////////////////////////////////////////
255 2 if(ThisFile.OffsetofSector>0)
256 2 {
257 3 if(RBC_Read(ThisFile.SectorPointer,1,DBUF))
258 3 {
259 4
260 4 len=len-ThisFile.OffsetofSector;
261 4 for(i=0;i<len;i++)
262 4
263 4 *(pBuffer+i)=DBUF[ThisFile.OffsetofSector+i];
264 4 ThisFile.OffsetofSector=ThisFile.OffsetofSector+len;
265 4 }
266 3 else
267 3 return FALSE;
268 3 }
269 2 else
270 2 {
271 3 if(!RBC_Read(ThisFile.SectorPointer,1,pBuffer+tlen))
272 3 return FALSE;
273 3 ThisFile.OffsetofSector=len;
274 3 }
275 2 ////////////////////////////////////////////////////////////
276 2 readLength-=len;
277 2 tlen+=len;
278 2
279 2 /////////////////////////////////////////////////////////
280 2 if((ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec-1)&&(tlen+ThisFile.pointer<ThisFile.LengthInBy
-te))
281 2 {
282 3 ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
283 3 ThisFile.SectorofCluster+=1;
284 3 if(ThisFile.SectorofCluster>DeviceInfo.BPB_SecPerClus-1)
285 3 {
286 4 ThisFile.SectorofCluster=0;
287 4 ThisFile.ClusterPointer=GetNextClusterNum32(ThisFile.ClusterPointer);
288 4 if(ThisFile.ClusterPointer>DeviceInfo.TotCluster)
289 4 return FALSE;
290 4 ThisFile.SectorPointer=FirstSectorofCluster32(ThisFile.ClusterPointer);
291 4 }
292 3 else
293 3 ThisFile.SectorPointer=ThisFile.SectorPointer+1;
294 3 }
295 2 //////////////////////////////////////////////////////////////////
296 2 }//end while
297 1
298 1 ThisFile.bFileOpen=1;
299 1 ThisFile.pointer+=tlen;
300 1 //////////////////////////////////////////////
301 1 Response.len=blen;
302 1
C51 COMPILER V7.06 HPI32 08/10/2005 23:36:35 PAGE 6
303 1 return TRUE;
304 1 }
305
306 unsigned char SetFilePointer32(unsigned long pointer)
307 {
308 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
309 1 return FALSE;
310 1 if(!ThisFile.bFileOpen)
311 1 return FALSE;
312 1 ///////////////////////////////////////////////////////////
313 1 ThisFile.pointer=pointer;
314 1 if(ThisFile.pointer>ThisFile.LengthInByte)
315 1 return FALSE;
316 1
317 1 if(!GoToPointer32(ThisFile.pointer))
318 1 {
319 2 ThisFile.bFileOpen=0;
320 2 return FALSE;
321 2 }
322 1 //////////////////////////////////////////////
323 1 return TRUE;
324 1 }
325
326 unsigned char CreateFile32(unsigned long len,unsigned char *pBuffer,unsigned char *pName)
327 {
328 1 unsigned int sector,i,j,DirCount;
329 1 unsigned long cnum;
330 1 unsigned char xdata bstop,InByte,bwrite;
331 1 unsigned long ClusterPointer;
332 1
333 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
334 1 return FALSE;
335 1 if((len%32)!=0)
336 1 return FALSE;
337 1 if((len+32)>DeviceInfo.BPB_BytesPerSec)
338 1 return FALSE;
339 1
340 1 ThisFile.bFileOpen=0;
341 1
342 1 cnum=GetFreeCusterNum32();
343 1 if(cnum<0x02)
344 1 return FALSE;
345 1
346 1 pBuffer[21]=(unsigned char)(cnum>>24);
347 1 pBuffer[20]=(unsigned char)(cnum>>16);
348 1 pBuffer[27]=(unsigned char)(cnum>>8);
349 1 pBuffer[26]=(unsigned char)(cnum);
350 1
351 1 pBuffer[28]=0;pBuffer[29]=0;pBuffer[30]=0;pBuffer[31]=0;
352 1 bstop=0;
353 1
354 1 NowCluster32=DirStartCluster32;
355 1 do
356 1 {
357 2 NowSector=FirstSectorofCluster32(NowCluster32);
358 2 ClusterPointer=NowCluster32;
359 2 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
360 2 {
361 3 if(!RBC_Read(NowSector+sector,1,DBUF))
362 3 return FALSE;
363 3 DirCount=0;bwrite=0;
364 3
C51 COMPILER V7.06 HPI32 08/10/2005 23:36:35 PAGE 7
365 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
366 3 {
367 4 if(len==0)
368 4 {
369 5 if((DBUF[i]==0x00)||(DBUF[i]==0xE5))
370 5 {
371 6 for(j=0;j<32;j++)
372 6 DBUF[i+j]=*(pBuffer+j);
373 6 if(!RBC_Write(NowSector+sector,1,DBUF))
374 6 return FALSE;
375 6 bstop=1;
376 6 break;
377 6 }
378 5 }
379 4 else
380 4 {
381 5 if(DirCount==0)
382 5 InByte=i;
383 5 if(DBUF[i]==0xE5)
384 5 DirCount++;
385 5 else if(DBUF[i]==0x00)
386 5 {
387 6 DirCount++;
388 6 DBUF[i]=0xE5;
389 6 bwrite=1;
390 6 }
391 5 else
392 5 DirCount=0;
393 5
394 5 if((DirCount*32)>=(len+32))
395 5 {
396 6 for(j=0;j<len;j++)
397 6 DBUF[InByte+j]=*(pName+j);
398 6 for(j=0;j<32;j++)
399 6 DBUF[InByte+len+j]=*(pBuffer+j);
400 6 if(!RBC_Write(NowSector+sector,1,DBUF))
401 6 return FALSE;
402 6 bstop=1;
403 6 break;
404 6 }
405 5 }
406 4 }
407 3 if(bstop==1)break;
408 3
409 3 if((len!=0)&&(bwrite==1))
410 3 {
411 4 if(!RBC_Write(NowSector+sector,1,DBUF))
412 4 return FALSE;
413 4 }
414 3 }
415 2 if(bstop==1)break;
416 2
417 2 NowCluster32=GetNextClusterNum32(NowCluster32);
418 2 if(NowCluster32>DeviceInfo.TotCluster)
419 2 {
420 3 NowCluster32=CreateClusterLink32(ClusterPointer);
421 3 if(NowCluster32==0x00)
422 3 return FALSE;
423 3 NowSector=FirstSectorofCluster32(NowCluster32);
424 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i++) DBUF[i]=0x00;
425 3 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
426 3 {
C51 COMPILER V7.06 HPI32 08/10/2005 23:36:35 PAGE 8
427 4 if(!RBC_Write(NowSector+sector,1,DBUF))
428 4 return FALSE;
429 4 }
430 3 }
431 2 }while(NowCluster32<=DeviceInfo.TotCluster);
432 1 ////////////////////////////////////////////////////////////////
433 1
434 1 ThisFile.StartCluster=cnum;
435 1 ThisFile.LengthInByte=0;
436 1 ThisFile.ClusterPointer=ThisFile.StartCluster;
437 1 ThisFile.SectorPointer=FirstSectorofCluster32(ThisFile.StartCluster);
438 1 ThisFile.OffsetofSector=0;
439 1 ThisFile.SectorofCluster=0;
440 1 ThisFile.bFileOpen=1;
441 1 ThisFile.pointer=0;
442 1 ThisFile.FatSectorPointer=0;
443 1
444 1 return TRUE;
445 1 }
446
447
448 unsigned char WriteFile32(unsigned long writeLength,unsigned char *pBuffer)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -