📄 main.lst
字号:
232 1 bootinfo.root_dir_size=((struct sBoot*)data_buf)->bsRootDirEnts[1]*256+((struct sBoot*)data_buf)->bsRootD
-irEnts[0];
233 1 bootinfo.total_sector=((struct sBoot*)data_buf)->bsSectors[1]*256+((struct sBoot*)data_buf)->bsSectors[0]
-;
234 1 bootinfo.media_flag=((struct sBoot*)data_buf)->bsMedia;
235 1 bootinfo.fat_size=((struct sBoot*)data_buf)->bsFATsecs[1]*256+((struct sBoot*)data_buf)->bsFATsecs[0];
236 1 bootinfo.sec_per_track=((struct sBoot*)data_buf)->bsSecPerTrack[1]*256+((struct sBoot*)data_buf)->bsSecPe
-rTrack[0];
C51 COMPILER V7.07 MAIN 12/01/2005 22:22:50 PAGE 5
237 1 bootinfo.heads=((struct sBoot*)data_buf)->bsHeads[1]*256+((struct sBoot*)data_buf)->bsHeads[0];
238 1 bootinfo.hidden_sector=((struct sBoot*)data_buf)->bsHiddenSecs[1]*256+((struct sBoot*)data_buf)->bsHidden
-Secs[0];
239 1 bootinfo.boot_code=((struct sBoot*)data_buf)->bsBootCode[1]*256+((struct sBoot*)data_buf)->bsBootCode[0];
240 1 bootinfo.huge_sec=((struct sBoot*)data_buf)->bsHugeSectors[3]*16777216
241 1 +((struct sBoot*)data_buf)->bsHugeSectors[2]*65536
242 1 +((struct sBoot*)data_buf)->bsHugeSectors[1]*256
243 1 +((struct sBoot*)data_buf)->bsHugeSectors[0];
244 1 bootinfo.drive_num=((struct sBoot*)data_buf)->bsDriveNumber;
245 1 bootinfo.boot_signature=((struct sBoot*)data_buf)->bsBootSignature;
246 1 for(i=0;i<4;i++)
247 1 {
248 2 bootinfo.volume_id[i]=((struct sBoot*)data_buf)->bsVolumeID[i];
249 2 }
250 1 for(i=0;i<11;i++)
251 1 {
252 2 bootinfo.volume_lab[i]=((struct sBoot*)data_buf)->bsVolumeLabel[i];
253 2 }
254 1 for(i=0;i<8;i++)
255 1 {
256 2 bootinfo.file_sys_type[i]=((struct sBoot*)data_buf)->bsFileSysType[i];
257 2 }
258 1 return 1;
259 1 }
260
261 void SystemInit()
262 {
263 1 CommInit();
264 1 AUXR=0xfc;
265 1 EA=1;
266 1 CFInit();
267 1 }
268
269 unsigned int TestAddr(unsigned int len)
270 {
271 1 int i;
272 1 unsigned char num=0;
273 1 for(i=len-1;i>=0;i--)
274 1 {
275 2 #ifdef TEST_RAM
ram_addr[i]=num;
#endif
278 2 num++;
279 2 }
280 1 num=0;
281 1 for(i=len-1;i>=0;i--)
282 1 {
283 2 #ifdef TEST_RAM
if(ram_addr[i]!=num)
#endif
286 2 return i;
287 2 num++;
288 2 }
289 1 return 0xffff;
290 1 }
291
292 char TestRam(unsigned int len,unsigned char num)
293 {
294 1 data unsigned int i;
295 1 for(i=0;i<len;i++)
296 1 {
297 2 #ifdef TEST_RAM
C51 COMPILER V7.07 MAIN 12/01/2005 22:22:50 PAGE 6
ram_addr[i]=num;
#endif
300 2 }
301 1 for(i=0;i<len;i++)
302 1 {
303 2 // printf("%d,",(int)ram_addr[i]);
304 2 #ifdef TEST_RAM
if(ram_addr[i]!=num)
#endif
307 2 return 0;
308 2 }
309 1 return 1;
310 1 }
*** WARNING C280 IN LINE 292 OF MAIN.C: 'num': unreferenced local variable
311
312 void ListFile()
313 {
314 1 unsigned char i,j;
315 1 xdata struct sRootDir root_directory;
316 1 for(i=0;data_buf[32*i]!=0;i++)
317 1 {
318 2 memcpy(&root_directory,data_buf+i*32,32);
319 2 if(root_directory.file_attribute==0x20
320 2 && (unsigned char)root_directory.file_name[0]!=0xe5) //list file
321 2 {
322 3 printf("\n");
323 3 for(j=0;j<8;j++)
324 3 {
325 4 putchar(root_directory.file_name[j]);
326 4 }
327 3 putchar('.');
328 3 for(j=0;j<3;j++)
329 3 {
330 4 putchar(root_directory.exten_name[j]);
331 4 }
332 3 }
333 2 if(root_directory.file_attribute==0x10
334 2 && (unsigned char)root_directory.file_name[0]!=0xe5) //list directory
335 2 {
336 3 printf("\n");
337 3 for(j=0;j<8;j++)
338 3 {
339 4 putchar(root_directory.file_name[j]);
340 4 }
341 3 putchar('.');
342 3 for(j=0;j<3;j++)
343 3 {
344 4 putchar(root_directory.exten_name[j]);
345 4 }
346 3 printf(" %x",root_directory.first_clust[1]*256+root_directory.first_clust[0]);
347 3 }
348 2 }
349 1 }
350
351 //返回所指定文件或目录的首簇扇区号,范围为根目录,文件名为11 bytes定长,不足用空格填充
352 //未找到返回0xffff
353 unsigned long CFFindFileInRoot(char *file_name,unsigned int *file_record_sec,unsigned int *file_record_pos
-)
354 {
355 1 unsigned int i,j;
356 1 xdata struct sRootDir root_directory;
357 1 for(j=bootinfo.fat_size*2+1;j<=bootinfo.fat_size*2+1+bootinfo.root_dir_size*32/512;j++)
C51 COMPILER V7.07 MAIN 12/01/2005 22:22:50 PAGE 7
358 1 {
359 2 if(ReadOneSec(j)==0)
360 2 {
361 3 return 0xffffffff;
362 3 }
363 2 // for(i=0;data_buf[32*i]!=0 && i<=bootinfo.root_dir_size*32/512;i++)
364 2 for(i=0;data_buf[32*i]!=0 && i<16;i++)
365 2 {
366 3 memcpy(&root_directory,data_buf+i*32,32);
367 3 if((root_directory.file_attribute==0x20 || root_directory.file_attribute==0x10)
368 3 && (unsigned char)root_directory.file_name[0]!=0xe5) //list file
369 3 {
370 4 if(strncmp(file_name,root_directory.file_name,8)==0x00)
371 4 {
372 5 *file_record_sec=j;
373 5 *file_record_pos=i;
374 5 // return root_directory.first_clust[1]*256+root_directory.first_clust[0];
375 5
376 5 return (root_directory.first_clust[1]*256+root_directory.first_clust[0]-2)
377 5 *bootinfo.sec_per_clust
378 5 +(1+bootinfo.fat_size*bootinfo.fat_num+bootinfo.root_dir_size*32/512);
379 5 }
380 4 }
381 3 }
382 2 // if(data_buf[32*i]==0)
383 2 // return 0xffff;
384 2 }
385 1 return 0xffffffff;
386 1 }
387
388 //note:in this version only 16 records could be stored in sub directory
389 //return value:error 0xffff,other case return file or directory first clustor in FAT table
390 unsigned int CFFindFileInDir(char *file_name,unsigned int dir_clustor,
391 unsigned int *file_record_sec,unsigned int *file_record_pos)
392 {
393 1 xdata struct sSubDir sub_dir;
394 1 xdata unsigned int fat_pos=0;
395 1 xdata unsigned int fat_sector=0;
396 1 xdata unsigned int in_sector_pos=0;
397 1 xdata unsigned int next_clustor=0;
398 1 xdata unsigned int current_clustor=0;
399 1 xdata unsigned char out_count=0;
400 1 unsigned int i;
401 1 unsigned int k;
402 1 unsigned int clustor;
403 1 clustor=dir_clustor-(bootinfo.fat_num*bootinfo.fat_size+bootinfo.root_dir_size*32/512+1);
404 1 clustor=clustor/bootinfo.sec_per_clust+2;
405 1 #ifdef DEBUG
printf("\ndir clus=%x,clus=%x",dir_clustor,clustor);
#endif
408 1 fat_sector=(clustor*2)/512;
409 1 in_sector_pos=(clustor*2)%512;
410 1 if(ReadOneSec(fat_sector+1)==0) //read FAT table
411 1 {
412 2 return 0xffff;
413 2 }
414 1 next_clustor=data_buf[in_sector_pos+1]*256+data_buf[in_sector_pos];
415 1 #ifdef DEBUG
printf("fat_sector=%x,in_sec_pos=%x,next_clustor=%x",fat_sector,in_sector_pos,next_clustor);
#endif
418 1 if(next_clustor==0xffff) //the sub directory used only one clustor
419 1 {
C51 COMPILER V7.07 MAIN 12/01/2005 22:22:50 PAGE 8
420 2 #ifdef DEBUG
printf("\nno next clustor\n");
#endif
423 2 clustor=dir_clustor;
424 2 for(i=0;i<bootinfo.sec_per_clust;i++) //read one clustor
425 2 {
426 3 if(ReadOneSec(i+dir_clustor)==0) //read one sector
427 3 {
428 4 return 0xffff;
429 4 }
430 3 for(k=0;data_buf[32*k]!=0 && k<16;k++)
431 3 {
432 4 #ifdef DEBUG
printf("\nk=%x\n",k);
#endif
435 4 memcpy(&sub_dir,data_buf+k*32,32);
436 4 if((sub_dir.file_attribute==0x20 || sub_dir.file_attribute==0x10)
437 4 && (unsigned char)sub_dir.file_name[0]!=0xe5)
438 4 {
439 5 if(strncmp(file_name,(unsigned char*)(&sub_dir),11)==0x00)
440 5 {
441 6 #ifdef DEBUG
printf("succ\n");
#endif
444 6 *file_record_sec=i+dir_clustor;
445 6 *file_record_pos=k;
446 6 return sub_dir.first_clust[1]*256+sub_dir.first_clust[0];
447 6 }
448 5 }
449 4 }
450 3 if(data_buf[32*k]==0)
451 3 return 0xffff;
452 3 }
453 2 }
454 1 else if(next_clustor<0xfff0) //the file use more then one sector
455 1 {
456 2 out_count=0;
457 2 current_clustor=dir_clustor;
458 2 while(next_clustor!=0xffff && out_count++<20)
459 2 {
460 3 for(i=0; i<bootinfo.sec_per_clust; i++)
461 3 {
462 4 if(ReadOneSec(i+current_clustor)==0)
463 4 {
464 5 return 0xffff;
465 5 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -