⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main_cf.asm

📁 ADI BF DSP的CF卡的读写源码
💻 ASM
字号:

/************************************************************************************************/
/*	Main Routine.																				*/
/*	Last Modified 03-06-03:	Fixed EBIU ASYNCB1 initialization code.								*/
/*				  04-25-03: Put in benchmark code (commented out)								*/
/*																					   H. Desai */
/************************************************************************************************/

#include <def21535.h>
#include "Boot_Sector_Parameters.h"
#define Mem_Mapped_Registers 0x24000800

.EXTERN _InitMp3Decoder;
.EXTERN _MP3Decode;

.EXTERN Check_CF_Inserted;
.EXTERN CF_Soft_Reset;
.EXTERN Check_CF_Busy;
.EXTERN FAT_File_System;
.EXTERN Identify_MP3s;
.EXTERN Calc_CHS;
.EXTERN Read_MP3;
.EXTERN Sport_Setup_Play;
.EXTERN Cluster_to_Sector;
.EXTERN Get_Next_Cluster;
.EXTERN Get_Sector_of_Clusters;
.EXTERN Clusters;
.EXTERN Determine_Num0fClusters_To_Read_In;
.EXTERN Partially_Full_Flag;
.EXTERN Small_CF;
.EXTERN Big_CF;

.SECTION mem_start;

	/**Initialize Benchmarking**/
	//R0 = 0x0 (Z);
	//CYCLES = R0;
	//CYCLES2 = R0;
	//R0 = SYSCFG;
	//BITSET(R0,1);
	//SYSCFG = R0;
	/**Start Benchmarking Initialization Code Here**/

SP.H = 0xF003;
SP.L = 0XDFFC;

/*******ASYNC Setup************/
Setup_ASYNC:
	P3.L = EBIU_AMGCTL & 0xFFFF;				
	P3.H = (EBIU_AMGCTL >> 16) & 0xFFFF;	//Asynchronous Memory Global Control Register
	R7 = [P3];
	R6.L = (AMBEN_B4_B5 | B5PEN) & 0xFFFF;
	R6.H = (AMBEN_B4_B5 | B5PEN) >> 16;
	R7 = R7 | R6;
	[P3] = R7;						//Enable external async memory Bank 4 with 16-bit packing

	P3.L = EBIU_AMBCTL0 & 0xFFFF;	//Asynchronous Memory Bank Control Register
	R6 = [P3];
	R7.H = (B5RDYPOL | B5HT_3 | B5RAT_15 | B5WAT_15) & 0xFFFF;
	R7.L = 0x0000;
	R7 = R6 | R7;
	[P3] = R7;						//Enable 3 hold cycles (max) and 15 wait states (max) for bank 4
/******************************/

P0.L = FIO_DIR & 0xFFFF;
P0.H = FIO_DIR >> 16;
R0 = W[P0];
R1.L = 0xFEFF;
R0 = R0 & R1;
W[P0] = R0;							//Set PF8 (/CD1) as input

CALL Check_CF_Inserted;
CALL CF_Soft_Reset;
CALL Check_CF_Busy;
CALL FAT_File_System;
CALL Identify_MP3s;

CALL Sport_Setup_Play;

P1.H = Parameters;
P1.L = Parameters;
R0 = [P1+0x28];						//# Of MP3 Songs
R1 = 0x2(Z);						//2 bytes for each start cluster
R0 = R0.L * R1.L (IS);
R1.H = MP3_Startclusters;
R1.L = MP3_Startclusters;
P0.H = MP3_Cluster_Ptr;
P0.L = MP3_Cluster_Ptr;
[P0] = R1;							//Initialize Cluster Ptr to start of MP3 StartClusters buffer
R0 = R0 + R1;
P0.H = MP3_END_Cluster_Ptr;
P0.L = MP3_END_Cluster_Ptr;
[P0] = R0;							//Save of end of MP3 StartCluster Ptr

CALL _InitMp3Decoder;

	/**Disable Benchmarking and Read Cycles Count**/
	//R0 = SYSCFG;
	//BITCLR(R0,1);
	//SYSCFG = R0;	//Stop Benchmarking Here
	//R0 = CYCLES;
	//R1 = CYCLES2;
	//P0.H = Init_Code_Benchmark;
	//P0.L = Init_Code_Benchmark;
	//[P0] = R0;
	//[P0+4] = R1;

Next_MP3:
P0.H = MP3_Cluster_Ptr;
P0.L = MP3_Cluster_Ptr;
P1 = [P0];
R0 = W[P1++];
P2.H = MP3_END_Cluster_Ptr;
P2.L = MP3_END_Cluster_Ptr;
P3 = [P2];
CC = P1 == P3;						//Have we reached the last song?
If !CC JUMP Not_Last_Song; 
P1.H = MP3_Startclusters;
P1.L = MP3_Startclusters;

Not_Last_Song:
[P0] = P1;							//If so, reset MP3 Cluster Ptr back to top of playlist

P0.H = Parameters;
P0.L = Parameters;
R1 = [P0+0x14];
P0.H = Sectors_Left;
P0.L = Sectors_Left;
W[P0] = R1;							//Initialize Sectors_Left to # of sectors per cluster (for use with large CFs)

P0.H = Current_Cluster;
P0.L = Current_Cluster;
W[P0] = R0;

CALL Get_Sector_of_Clusters;

R0 = 0x8;							//Bring in 8 sectors initially to fill up pack_buffer
P0.H = Sectors_To_Read;
P0.L = Sectors_To_Read;
W[P0] = R0;
CALL Determine_Num0fClusters_To_Read_In;
R6 = R0;							//R6 = # of clusters to read
JUMP FillDataRoutine;				//Fill Pack Buffer initially

/**Pack Buffer Filled Space Check**/
CheckPackBuffer:

	/**Initialize Benchmarking**/
	//R0 = 0x0 (Z);
	//CYCLES = R0;
	//CYCLES2 = R0;
	//R0 = SYSCFG;
	//BITSET(R0,1);
	//SYSCFG = R0;
	/**Start Benchmarking Single Loop Code Here**/

R0 = 0x4;							//Bring in 4 sectors to fill up half of pack_buffer
P0.H = Sectors_To_Read;
P0.L = Sectors_To_Read;
W[P0] = R0;
CALL Determine_Num0fClusters_To_Read_In;
R6 = R0;							//R6 = # of clusters to read

P0.H = pack_buffer_rdptr;
P0.L = pack_buffer_rdptr;
R0 = [P0];

P0.H = pack_buffer_wrptr;
P0.L = pack_buffer_wrptr;
R1 = [P0];

R0 = R1 - R0;						//Difference, write pointer - read pointer

R1 = 0x1000(Z);						//R1 = 4096 bytes = 1024 32-bit words

R2 = R0 + R1;
cc = R0 < 0;
IF cc R0 = R2;						//If difference is negative then add length of buffer

R1 = 0x0800(Z);

cc = R0 <= R1;
IF cc JUMP FillDataRoutine;		//If buffer has insufficient amount of data, jump to fill data routine

/**Predac Buffer Empty Space Check**/
CheckPredacSpace:
P0.H = predac_buffer_rdptr;
P0.L = predac_buffer_rdptr;
R0 = [P0];

P0.H = predac_buffer_wrptr;
P0.L = predac_buffer_wrptr;
R1 = [P0];

R0 = R0 - R1;

R1 = 0x4800(Z);						//R1 = 18432 bytes = 4608 32-bit words

R2 = R1 + R0;
cc = R0 < 0;
IF cc R0 = R2;						//If difference is negative then add length of buffer

R1 = 0x2400(Z);

cc = R0 < R1;
IF cc JUMP CheckPredacSpace;		//Check for half empty space in predac buffer

CALL _MP3Decode;

	/**Disable Benchmarking and Read Cycles Count**/
	//R0 = SYSCFG;
	//BITCLR(R0,1);
	//SYSCFG = R0;	//Stop Benchmarking Here
	//R0 = CYCLES;
	//R1 = CYCLES2;
	//P0.H = Single_Loop_Benchmark;
	//P0.L = Single_Loop_Benchmark;
	//[P0] = R0;
	//[P0+4] = R1;

JUMP CheckPackBuffer;

FillDataRoutine:
P0.H = Partially_Full_Flag;
P0.L = Partially_Full_Flag;
R0 = B[P0];
CC = BITTST(R0,0);
IF CC JUMP Big_CF;					//Determine if we have a big CF
JUMP Small_CF;


.SECTION Data_CDMP3;
.ALIGN 4;
.BYTE Drive_Info[512];
.BYTE Boot_Sector[512];
.BYTE Root_Directory[512];
.BYTE4 Parameters[11] =	0x0,	//Offset 0x00 = Start of Root Directory
						0x0,	//Offset 0x04 = Start of Data Region
						0x0,	//Offset 0x08 = # of Root Directory Sectors
						0x0,	//Offset 0x0C = # of Hidden Sectors
						0x0,	//Offset 0x10 = # of Sectors in Data Region
						0x0,	//Offset 0x14 = # of Sectors per Cluster
						0x0,	//0ffset 0x18 = Sector Extractor
						0x0,	//Offset 0x1C = Head Extractor
						0x0,	//Offset 0x20 = Head Shifter
						0x0,	//Offset 0x24 = Cylinder Shifter
						0x0;	//Offset 0x28 = # of MP3 Songs
.BYTE Namearray[512];
.BYTE MP3_Startclusters[128];
.BYTE Filesize[256];
.BYTE MP3_Buffer[512];
.BYTE LF_Name = 0;
.BYTE Num_MP3songfiles = 0;
.BYTE2 Current_Cluster;
.BYTE Clusters[512];
.VAR Save_IMASK;
.VAR MP3_Cluster_Ptr;
.VAR MP3_END_Cluster_Ptr;
.BYTE2 Sectors_To_Read;
.BYTE2 Sectors_Left;
.BYTE2 Current_Sector_Number;
.ALIGN 4;
.VAR Init_Code_Benchmark[2];
.VAR Single_Loop_Benchmark[2];
.VAR Single_Sector_Benchmark[2];


.GLOBAL Drive_Info;
.GLOBAL Boot_Sector;
.GLOBAL Namearray;
.GLOBAL MP3_Startclusters;
.GLOBAL Filesize;
.GLOBAL Root_Directory;
.GLOBAL Parameters;
.GLOBAL LF_Name;
.GLOBAL Current_Cluster;
.GLOBAL Save_IMASK;
.GLOBAL Next_MP3;
.GLOBAL MP3_Cluster_Ptr;
.GLOBAL MP3_Startclusters;
.GLOBAL MP3_END_Cluster_Ptr;
.GLOBAL Sectors_Left;
.GLOBAL Sectors_To_Read;
.GLOBAL Current_Sector_Number;
.GLOBAL CheckPredacSpace;
.GLOBAL Single_Sector_Benchmark;

.ALIGN 4;
.VAR predac_buffer[4608];		//MP3 Decoded PCM Sample Buffer
.VAR pack_buffer[1024];			//MP3 Encoded Input Buffer

.VAR predac_buffer_wrptr = predac_buffer; //used in the MP3 Decoder Library
.VAR predac_buffer_rdptr = predac_buffer; //used in the MP3 Decoder Library

.VAR pack_buffer_rdptr = pack_buffer; //used in the MP3 Decoder Library
.VAR pack_buffer_wrptr = pack_buffer; //used in the MP3 Decoder Library

.GLOBAL predac_buffer;
.GLOBAL pack_buffer;
.GLOBAL predac_buffer_wrptr;
.GLOBAL predac_buffer_rdptr;
.GLOBAL pack_buffer_rdptr;
.GLOBAL pack_buffer_wrptr;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -