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

📄 create_data.asm

📁 BlackFin LCD 显示, 简单GUI图形显示
💻 ASM
字号:
/********************************************************************************************
**
**  File:   Create_Data.asm
**  Date:   9-27-05
**  Author: Sam Haidar
**  Use:    Convert a 24bit BMP picture formatted input buffer to a 16bit (565 RGB format) output
**			excluding the BMP image header information
**  Note:   Resolution of the BMP picture should be 640 x 480 pixels.
**
**	Info:   Total BMP Byte Size = 0xE1036 Bytes
**          
**	 
*********************************************************************************************/

// Resolution
#define Pixels_Per_Line 640		
#define Lines_Per_BMP 480		
#define horizontal_Count 3*Pixels_Per_Line	// 640 *3 bytes
#define vertical_Count 2*3*Pixels_Per_Line	// 640 *3*2 bytes
#define BMP_Header_Length	54				// 54 Byte header
#define BMP_File_Length (Pixels_Per_Line*Lines_Per_BMP*3) + BMP_Header_Length // Size of BMP file in bytes
#define BMP_Width_Offset 0x0012				// Per BMP file specification
#define BMP_Length_Offset 0x0016			// Per BMP file specification

//#define line_byte_offset 	44800		// Offset = 640*2*(35 lines)
#define line_byte_offset	(Pixels_Per_Line*2)*34


.section program;
.global _Create_Data;
_Create_Data:

// When calling ASM from C, ensure all return Pointers & Data Registers, 
// loop counters, and status Registers are pushed onto the STACK
	[--sp] = rets;	//Return Functions
	[--sp] = (r7:0, p5:0);
	[--sp] = lc0;
	[--sp] = lc1;
	[--sp] = astat;

	P1=R0;    // Output Buffer Pointer   
	P0=R1;	  // Input Buffer Pointer 
	  
/********************Check the BMP Resolution****************************/

// BMP Resolution is limited to 640*480. If the requirment is not met, the code
// will generate an error.

//Point to the Width value of the BMP Header 	
	R2 = BMP_Width_Offset (Z);	
	R2 = R1 + R2;
	P2 = R2;
	
//Point to the length value of the BMP Header 
	R3 = BMP_Length_Offset (Z);	
	R3 = R1 + R3;
	P3 = R3;
	nop;nop;nop;nop;
	
	R3= W[P3](z);	// fetch length
	R2= W[P2](z);	// fetch width

//Check image resolution to be 640 *480
//If the resolution is not correct, Jump to Error.
	R2 = R2.L * R3.L (FU);
	R4.L = lo(Pixels_Per_Line *Lines_Per_BMP);
	R4.H = hi(Pixels_Per_Line *Lines_Per_BMP);
	CC = R2 == R4;
	IF !CC Jump Error; 
	
	
/**************************PROGRAM***********************************/
	
	// Offset the pointer to the end of the last line of the BMP header
	// This is because images in BMP files are inverted
	R1.L = lo(BMP_File_Length);	
	R1.H = hi(BMP_File_Length);	
	R2 = P0;
	R1 = R1 + R2;
	P0 = R1;
		
	// Offset the pointer to where the Active Video resides in the Image buffer
	R1 = line_byte_offset (z);	
	R2 = P1;
	R1 = R1 + R2;
	P1 = R1;
	
	// Decrement pointer to first pixel in last line of BMP header
	R1 = horizontal_Count;	//640*3 = 0x780
	R2 = P0;
	R3 = R2 - R1;
	P4 = R3;  //1st line in the bottom to be dispalyed on top

	R0 = Lines_Per_BMP;	//480
	P2 = R0;
	
	//Pointer register requires 4 cycles to read. This instruction is required to meet the timing
	nop;nop;nop;nop; 

lsetup(Begin_mainLOOP, End_mainLOOP) LC0 = P2;
	Begin_mainLOOP:

//This loop is needed to perform a read to the lines in the image where each
// line is generated by reading 640 times.  	
	
	R0 = Pixels_Per_Line;	//640
	P5 = R0;
	
	//Pointer register requires 4 cycles to read. This instruction is required to meet the timing
	nop;nop;nop;nop; 
	
lsetup(Begin_LOOP2, End_LOOP2) LC1 = P5;
	Begin_LOOP2:
		
// 1st Pixel  -- 24bit RGB (8bit, 8bit, 8bit)	
	R0= B[P4](z);		//1st byte -- Blue subpixel
	R1= B[P4 + 0x1](z);	//2nd byte -- Green Subpixel
	R2= B[P4 + 0x2](z);	//3rd byte -- Red Subpixel
	
//Shift the Blue, Green, & Red subpixels to create the 16bit RGB value in 565 format.
	R0 >>=3;	//Clear the last 3 LSB (Blue Subpixel)
	R0 <<=11;	//Put the value in the upper part of the 16 bit Reg
	
	R1 >>=2;	//Clear the last 2 LSB (Green Subpixel)
	R1 <<=5;	//Put the Value in the middle part of the 16 bit Reg
	
	R2 >>=3;	//Clear the last 3 LSB	(Red Subpixel)
	
	R3= R0|R1;
	R4= R2|R3;	//16 bit RGB value in a 565 format
		
	W[P1] = R4;	//Write the 16 bit value into P1
	P1+= 0x2;	//Then increment the pointer by 2 to write the next 16 bit value. 
	
	P4 += 0x3;	//Increment this pointer by 3 to read the next 24bit RGB values.
	
//So we get a 24bit RGB value, convert it to 16bit RGB (565 format). Then increment the pointer
//(that is used to read the 24bit value) by 3 and increment the pointer (that is used to 
//to write the 16 bit value in 565 format) by 2 until the whole image is generated.  
	
End_LOOP2: nop;
	
// After the 1st line is proceeded, go to the line above that and process it.
// Then do the loop again and go to the third line above and process it (and so on...)
	P3 = vertical_Count;
	R0 = P3;
	R1 = P4;
	R2 = R1 - R0;
	P4 = R2;
	
End_mainLOOP: nop;	


// After executing the code above, all Return Functions, Pointer & Data Registers, 
// Loop counters, and Arithmetic Status Registers  should be poped from
// the STACK
	astat= [sp++];
	lc1  = [sp++];
	lc0  = [sp++];
	(r7:0, p5:0) = [sp++];
	r0 = 0x0000 (z);	// Return 0
	rets = [sp++];
	ssync;
	
_Create_Data.END: RTS; 	

//Error: The resolution is not 640*480.
Error:
// After executing the code above, all Return Functions, Pointer & Data Registers, 
// Loop counters, and Arithmetic Status Registers  should be poped from
// the STACK
	astat= [sp++];
	lc1  = [sp++];
	lc0  = [sp++];
	(r7:0, p5:0) = [sp++];
	r0 = 0x0001 (z);	// Return Error
	rets = [sp++];
	ssync;
Error.End: RTS;

⌨️ 快捷键说明

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