ide.lst
来自「一款硬盘MP3的源代码」· LST 代码 · 共 466 行 · 第 1/2 页
LST
466 行
219
220 unsigned long int xdata FAT_start_sector[4]; //FAT开始扇区
221 unsigned long int xdata DATA_start_sector[4]; //数据开始扇区
222
223 unsigned char mp3_file_exist=0;
224
225 unsigned char xdata FAT_buffer[512]; //文件分配表FAT缓冲
226
227 ////////////////////////////////////// 写扇区计数寄存器 ///////////////////////////////////////////
228 void write_IDE_sector_count(unsigned char count)
229 {
230 1 write_IDE_8(IDE_Sector_Count,count);
231 1 }
232 /////////////////////////////////////////////////////////////////////////////////////////////////
233
234 ///////////////////////////////// 读取一个FAT扇区,512字节保存在FAT_buffer[]中 ///////////////////////
235 void read_IDE_FAT_sector(unsigned long int LBA)
236 {
237 1 unsigned int i;
238 1 if(LBA>=(dpt[driver_number].start_sector+dpt[driver_number].total_sectors))return;
239 1 write_IDE_LBA(LBA);
240 1 write_IDE_sector_count(1);
241 1 write_IDE_command(IDE_Read_Sectors);
C51 COMPILER V7.50 IDE 11/27/2005 23:13:41 PAGE 5
242 1 IDE_Address=IDE_Data;
243 1 set_IDE_address();
244 1 IDE_DATA_H=0xFF;
245 1 IDE_DATA_L=0xFF;
246 1 for(i=0;i<512;i++)
247 1 {
248 2 while(!IDE_IORDY);
249 2 IDE_DIOR=0;
250 2 FAT_buffer[i]=IDE_DATA_L;
251 2 i++;
252 2 FAT_buffer[i]=IDE_DATA_H;
253 2 IDE_DIOR=1;
254 2 }
255 1 IDE_Address=IDE_Bus_Not_Use;
256 1 set_IDE_address();
257 1 IDE_DATA_L=0xFF;
258 1 }
259 ///////////////////////////////////////////////////////////////////////////////////////////////
260
261 ///////////////////////////////// 读取一个数据扇区,512字节保存在buffer[]中 //////////////////
262 void read_IDE_sector(unsigned long int LBA)
263 {
264 1 unsigned int i;
265 1 if(LBA>=(dpt[driver_number].start_sector+dpt[driver_number].total_sectors))return;
266 1 write_IDE_LBA(LBA);
267 1 write_IDE_sector_count(1);
268 1 write_IDE_command(IDE_Read_Sectors);
269 1 IDE_Address=IDE_Data;
270 1 set_IDE_address();
271 1 IDE_DATA_H=0xFF;
272 1 IDE_DATA_L=0xFF;
273 1 for(i=0;i<512;i++)
274 1 {
275 2 while(!IDE_IORDY);
276 2 IDE_DIOR=0;
277 2 buffer[i]=IDE_DATA_L;
278 2 i++;
279 2 buffer[i]=IDE_DATA_H;
280 2 IDE_DIOR=1;
281 2 }
282 1 IDE_Address=IDE_Bus_Not_Use;
283 1 set_IDE_address();
284 1 IDE_DATA_L=0xFF;
285 1 }
286 ///////////////////////////////////////////////////////////////////////////////////////////////
287
288 unsigned int play_count; //当前文件夹中播放曲号
289
290 ///////////////////////////////////// 获取磁盘信息 /////////////////////////////////////////
291 void get_IDE_information(void)
292 {
293 1 unsigned int i;
294 1 unsigned long int LBA=0;
295 1 mp3_file_exist=0;
296 1 LBA=0;
297 1 read_IDE_sector(LBA);
298 1 for(i=0;i<4;i++)
299 1 {
300 2 dpt[i].file_system_type=buffer[0x1C2+i*16]; //文件系统类型
301 2 ((unsigned char *)&(dpt[i].start_sector))[3]=buffer[0x1C6+i*16];
302 2 ((unsigned char *)&(dpt[i].start_sector))[2]=buffer[0x1C7+i*16];
303 2 ((unsigned char *)&(dpt[i].start_sector))[1]=buffer[0x1C8+i*16];
C51 COMPILER V7.50 IDE 11/27/2005 23:13:41 PAGE 6
304 2 ((unsigned char *)&(dpt[i].start_sector))[0]=buffer[0x1C9+i*16]; //分区开始扇区
305 2 ((unsigned char *)&(dpt[i].total_sectors))[3]=buffer[0x1CA+i*16];
306 2 ((unsigned char *)&(dpt[i].total_sectors))[2]=buffer[0x1CB+i*16];
307 2 ((unsigned char *)&(dpt[i].total_sectors))[1]=buffer[0x1CC+i*16];
308 2 ((unsigned char *)&(dpt[i].total_sectors))[0]=buffer[0x1CD+i*16]; //分区总扇区
309 2 }
310 1
311 1 if((buffer[510]!=0x55)||(buffer[511]!=0xAA))disk_error=1;
312 1 LBA=dpt[0].start_sector; //C盘
313 1 read_IDE_sector(LBA);
314 1 DISK_CAPACITY[7]=buffer[0x0B];
315 1 DISK_CAPACITY[6]=buffer[0x0C]; //每扇区字节数
316 1 ((unsigned char *)&(dbr[0].bytes_per_sectors))[0]=buffer[0x0C];
317 1 ((unsigned char *)&(dbr[0].bytes_per_sectors))[1]=buffer[0x0B]; //每扇区字节数
318 1 dbr[0].sectors_per_cluster=buffer[0x0D]; //每簇扇区数
319 1 ((unsigned char *)&(dbr[0].reserve_sectors))[1]=buffer[0x0E];
320 1 ((unsigned char *)&(dbr[0].reserve_sectors))[0]=buffer[0x0F]; //保留扇区数
321 1 dbr[0].num_of_FAT=buffer[0x10]; //FAT副本数
322 1 ((unsigned char *)&(dbr[0].FAT16_ROOT_num))[1]=buffer[0x11];
323 1 ((unsigned char *)&(dbr[0].FAT16_ROOT_num))[0]=buffer[0x12]; //FAT16文件系统的根目录数
324 1 ((unsigned char *)&(dbr[0].small_sectors))[1]=buffer[0x13];
325 1 ((unsigned char *)&(dbr[0].small_sectors))[0]=buffer[0x14];
326 1 ((unsigned char *)&(dbr[0].sectors_per_FAT16))[1]=buffer[0x16];
327 1 ((unsigned char *)&(dbr[0].sectors_per_FAT16))[0]=buffer[0x17];
328 1 ((unsigned char *)&(dbr[0].hidden_sectors))[3]=buffer[0x1C];
329 1 ((unsigned char *)&(dbr[0].hidden_sectors))[2]=buffer[0x1D];
330 1 ((unsigned char *)&(dbr[0].hidden_sectors))[1]=buffer[0x1E];
331 1 ((unsigned char *)&(dbr[0].hidden_sectors))[0]=buffer[0x1F];
332 1 ((unsigned char *)&(dbr[0].large_sectors))[3]=buffer[0x20];
333 1 ((unsigned char *)&(dbr[0].large_sectors))[2]=buffer[0x21];
334 1 ((unsigned char *)&(dbr[0].large_sectors))[1]=buffer[0x22];
335 1 ((unsigned char *)&(dbr[0].large_sectors))[0]=buffer[0x23];
336 1 DISK_CAPACITY[0]=buffer[0x23];
337 1 DISK_CAPACITY[1]=buffer[0x22];
338 1 DISK_CAPACITY[2]=buffer[0x21];
339 1 DISK_CAPACITY[3]=buffer[0x20];
340 1 ((unsigned char *)&(dbr[0].sectors_per_FAT32))[3]=buffer[0x24];
341 1 ((unsigned char *)&(dbr[0].sectors_per_FAT32))[2]=buffer[0x25];
342 1 ((unsigned char *)&(dbr[0].sectors_per_FAT32))[1]=buffer[0x26];
343 1 ((unsigned char *)&(dbr[0].sectors_per_FAT32))[0]=buffer[0x27];
344 1 ((unsigned char *)&(dbr[0].root_cluster_num))[3]=buffer[0x2C];
345 1 ((unsigned char *)&(dbr[0].root_cluster_num))[2]=buffer[0x2D];
346 1 ((unsigned char *)&(dbr[0].root_cluster_num))[1]=buffer[0x2E];
347 1 ((unsigned char *)&(dbr[0].root_cluster_num))[0]=buffer[0x2F];
348 1 if((buffer[510]!=0x55)||(buffer[511]!=0xAA))disk_error=2;
349 1 FAT_start_sector[0]=dpt[0].start_sector+dbr[0].reserve_sectors;
350 1 DATA_start_sector[0]=FAT_start_sector[0]+(dbr[0].num_of_FAT)*(dbr[0].sectors_per_FAT32);
351 1 LBA=DATA_start_sector[0];
352 1 driver_number=C_;
353 1 current_dir.first_cluster_number=dbr[0].root_cluster_num;
354 1 play_count=1;
355 1 item_count=1;
356 1 get_nst_item();
357 1 }
358 //////////////////////////////////////////////////////////////////////////////////////////////////////////
-//
359
360 /*void read_IDE_buffer(void)
361 {
362 write_IDE_command(IDE_Read_Buffer);
363 }*/
364
C51 COMPILER V7.50 IDE 11/27/2005 23:13:41 PAGE 7
365 /*void write_IDE_buffer(void)
366 {
367 write_IDE_command(IDE_Write_Buffer);
368 }*/
369
370 /*
371 void write_IDE_sector(unsigned long int LBA)
372 {
373 unsigned int i;
374 write_IDE_LBA(LBA);
375 write_IDE_sector_count(1);
376 write_IDE_command(IDE_Write_Sectors);
377 IDE_Address=IDE_Data;
378 set_IDE_address();
379 for(i=0;i<512;i++)
380 {
381 while(!IDE_IORDY);
382 IDE_DIOW=0;
383 IDE_DATA_L=buffer[i];
384 i++;
385 IDE_DATA_H=buffer[i];
386 IDE_DIOW=1;
387 }
388 wait_IDE_busy();
389 IDE_Address=IDE_Bus_Not_Use;
390 set_IDE_address();
391 }
392 */
393
394 ///////////////////////////////////////////// IDE 初始化 /////////////////////////////////////////
395 void IDE_initial(void)
396 {
397 1 unsigned char i;
398 1 reset_IDE();
399 1 for(i=2;i<200;i++)dir_name[i]=0x2020;
400 1 do
401 1 {
402 2 write_IDE_8(IDE_Drive_Head,0xE0);
403 2 read_IDE_status();
404 2 }while(IDE_BSY);
405 1 wait_IDE_busy();
406 1 write_IDE_8(IDE_Device_Control,0xFA);//没有中断模式f
407 1 dir_name[0]='C'+0xA380;
408 1 ((unsigned char *)dir_name)[2]=':';
409 1 ((unsigned char *)dir_name)[3]='\\';
410 1 folder_length=4;
411 1 dir_length=folder_length;
412 1 not_root_dir=0;
413 1 get_IDE_information();
414 1 }
415 ///////////////////////////////////////////////////////////////////////////////////////////////////////
416
417
418
419
420
421
422
423
424
425
426
C51 COMPILER V7.50 IDE 11/27/2005 23:13:41 PAGE 8
427
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1546 ----
CONSTANT SIZE = 11 ----
XDATA SIZE = 1204 ----
PDATA SIZE = ---- ----
DATA SIZE = 17 16
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?