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

📄 opvram_v0.1b.c

📁 一个操作系统源代码 用于嵌入式设备 在Vc++环境下仿真 成功移植到多款处理器上
💻 C
字号:
/************************************
*
*
*
*
*
* FUNCTION LIST
* GetPixel					获取指定位置的像素值
* GetPixelPosition			获取指定像素的物理地址
* GetNextPixel				获取指定像素的下一个像素值
* GetNextPixelPosition		获取指定像素的下一个像素的物理地址
* GetLine					获取指定行的行首像素的物理地址
* GetNextLine				获取指定行的下一行的行首像素的物理地址(同列)
* SetPixel					设置指定像素的值
* PixelOp					对指定像素进行逻辑操作(包括按位与、或、异或、复制等)
* PixelMaskOp				利用掩码对指定像素进行逻辑操作(包括按位与、或、异或、复制等)
* SetLine					设置指定行的值
* LineUnicolorOp			对指定行进行单色逻辑操作(包括按位与、或、异或、复制等)
* LineOp					对指定的两行进行逻辑操作(包括按位与、或、异或、复制等)
* BlockUnicolorOP			对指定块进行单色逻辑操作(包括按位与、或、异或、复制等)
* BlockOP					对指定的两块区域进行逻辑操作(包括按位与、或、异或、复制等)
*
*
*
*
***********************************************************************/
#include <sys\gpc.h>
#include "vramop.h"

static GetNextPixelPosition( PIXEL **nextPixelPos, CHAR *newBitOffset, PIXEL *pixelPos, CHAR bitOffset );

PIXEL PixelMask = 0xfff0;				//0xf/0xff/0xfff0/0x0fff/0xffff/0xffffffff;

//关于vram的操作
//GetPixel 获取指定位置的像素值
GetPixel( PIXEL *pixelValue, PIXEL *pixelPos, CHAR bitOffset )
{
	*pixelValue = (*pixelPos);
}

//GetPixelPosition 获取指定像素的物理地址
GetPixelPosition( PIXEL **pixelPos, CHAR *bitOffset, VRAM *vram, WORD x, WORD y )
{
	DWORD totalOffset;
	
	totalOffset = y * vram->widthInBit + x * BITS_PER_PIXEL;
	*pixelPos = vram->ad +( ( totalOffset +7 )>>3 );
	(*bitOffset) &= 0x7;
}

//GetNextPixel 获取指定像素的下一个像素值
GetNextPixel( PIXEL *pixelValue, PIXEL *pixelPos, CHAR bitOffset )
{
	PIXEL *nextPixelPos;
	CHAR newBitOffset;
	
	GetNextPixelPosition( &nextPixelPos, &newBitOffset, pixelPos, bitOffset );
	GetPixel( pixelValue, nextPixelPos, newBitOffset );
}

//GetNextPixelPosition 获取指定像素的下一个像素的物理地址
GetNextPixelPosition( PIXEL **nextPixelPos, CHAR *newBitOffset, PIXEL *pixelPos, CHAR bitOffset )
{
	*nextPixelPos = pixelPos +1;
	*newBitOffset = 0;
}

//GetLine 获取指定行的行首像素的物理地址
GetLine( PIXEL **pixelPos, CHAR *bitOffset, VRAM *vram, WORD y )
{
	DWORD totalOffset;

	totalOffset = y * vram->widthInBit;
	*pixelPos = vram->ad +( ( totalOffset +7 )>>3 );
	(*bitOffset) &= 0x7;
}

//GetNextLine 获取指定行的下一行的行首像素的物理地址
GetNextLine( PIXEL **nextPixelPos, CHAR *nextBitOffset, PIXEL *pixelPos, CHAR bitOffset, VRAM *vram )
{
	DWORD totalOffset;

	totalOffset = bitOffset + vram->widthInBit;
	*nextPixelPos = pixelPos +( ( totalOffset +7 )>>3 );
	(*nextBitOffset) &= 0x7;
}

//SetPixel 设置指定像素的值
newSetPixel( PIXEL *pixelPos, CHAR bitOffset, PIXEL pixelValue )
{
	*pixelPos = pixelValue;
}

//SetLine 设置指定行的值
SetLine( PIXEL *linePos, CHAR bitOffset, WORD len, PIXEL lineValue )
{
	PIXEL *pixelPos;
	WORD i;
	
	pixelPos = linePos;
	for( i = 0; i < len; i++, pixelPos++ )
		*pixelPos = lineValue;
}

//PixelOp 对指定像素进行逻辑操作(包括按位与、或、异或、复制等)
//PixelOp( PIXEL *desPixelPos, CHAR desBitOffset, PIXEL *srcPixelPos, CHAR srcBitOffset, WORD op )
PixelOp( PIXEL *desPixelPos, CHAR desBitOffset, PIXEL srcValue, WORD op )
{
//	PIXEL srcValue;
	PIXEL desValue;
	
//	GetPixel( &srcValue, srcPixelPos, srcBitOffset );
	GetPixel( &desValue, desPixelPos, desBitOffset );
	
	switch( op )
	{
		case GPC_REPLACE_STYLE:
		case GPC_COPY_STYLE:
			desValue = srcValue;
			break;
		case GPC_XOR_STYLE:
			desValue ^= srcValue;
			break;
		case GPC_AND_STYLE:
			desValue &= srcValue;
			break;
		case GPC_OR_STYLE:
			desValue |= srcValue;
			break;
		default:
			break;
	}
	
	newSetPixel( desPixelPos, desBitOffset, desValue );
	
}

//PixelMaskOp 利用掩码对指定像素进行逻辑操作(包括按位与、或、异或、复制等)
PixelMaskOp( PIXEL *desPixelPos, PIXEL srcValue, PIXEL srcMask, WORD op )
{
	switch( op )
	{
		case GPC_REPLACE_STYLE:
		case GPC_COPY_STYLE:
			(*desPixelPos) = ( (*desPixelPos) & ~srcMask ) | ( srcValue & srcMask );
			break;
		case GPC_XOR_STYLE:
			(*desPixelPos) = (*desPixelPos) ^ ( srcValue & srcMask );
			break;
		case GPC_AND_STYLE:
			(*desPixelPos) = (*desPixelPos) & ( ( ~srcMask ) | ( srcValue & srcMask ) );
			break;
		case GPC_OR_STYLE:
			(*desPixelPos) = (*desPixelPos) | ( srcValue & srcMask );
			break;
		default:
			break;
	}	
}

//LineUnicolorOp 对指定行进行单色逻辑操作(包括按位与、或、异或、复制等)
LineUnicolorOp( PIXEL *desLinePos, CHAR desBitOffset, WORD len, PIXEL srcValue, WORD op )
{
	PIXEL *pixelPos;
	PIXEL unitValue = srcValue;
	WORD i;
		
	pixelPos = desLinePos;
	switch( op )
	{
		case GPC_REPLACE_STYLE:
		case GPC_COPY_STYLE:
			for( i = 0; i < len; i++, pixelPos++ )
				(*pixelPos) = unitValue;
			break;
		case GPC_XOR_STYLE:
			for( i = 0; i < len; i++, pixelPos++ )
				(*pixelPos) ^= unitValue;
			break;
		case GPC_AND_STYLE:
			for( i = 0; i < len; i++, pixelPos++ )
				(*pixelPos) &= unitValue;
			break;
		case GPC_OR_STYLE:
			for( i = 0; i < len; i++, pixelPos++ )
				(*pixelPos) |= unitValue;
			break;
		default:
			break;
	}
}

//LineOp 对指定的两行进行逻辑操作(包括按位与、或、异或、复制等)
LineOp( PIXEL *desLinePos, CHAR desBitOffset, PIXEL *srcLinePos, CHAR srcBitOffset, WORD len, WORD op )
{
	WORD i;
	PIXEL *srcPos = srcLinePos, *desPos = desLinePos;
	
	switch( op )
	{
		case GPC_REPLACE_STYLE:
		case GPC_COPY_STYLE:
			for( i = 0; i < len; i++, desPos++, srcPos++ )
				(*desPos) = (*srcPos);
			break;
		case GPC_XOR_STYLE:
			for( i = 0; i < len; i++, desPos++, srcPos++ )
				(*desPos) ^= (*srcPos);
			break;
		case GPC_AND_STYLE:
			for( i = 0; i < len; i++, desPos++, srcPos++ )
				(*desPos) &= (*srcPos);
			break;
		case GPC_OR_STYLE:
			for( i = 0; i < len; i++, desPos++, srcPos++ )
				(*desPos) |= (*srcPos);
			break;
		default:
			break;
	}
}

//BlockUnicolorOP 对指定块进行单色逻辑操作(包括按位与、或、异或、复制等)
BlockUnicolorOp( PIXEL *desLinePos, CHAR desBitOffset, WORD width, WORD height, PIXEL srcValue, WORD op, VRAM *vram )
{
	PIXEL *curPos = desLinePos, *nextPos;
	CHAR curBitOffset = desBitOffset, nextBitOffset;
	WORD i;

	for( i = 0; i < height; i++ )
	{
		LineUnicolorOp( curPos, curBitOffset, width, srcValue, op );
		GetNextLine( &nextPos, &nextBitOffset, curPos, curBitOffset, vram );
		curPos = nextPos;
		curBitOffset = nextBitOffset;
	}
}

//BlockOP 对指定的两块区域进行逻辑操作(包括按位与、或、异或、复制等)
BlockOp( PIXEL *desLinePos, CHAR desBitOffset, PIXEL *srcLinePos, CHAR srcBitOffset, WORD width, WORD height, WORD op, VRAM *desVram, VRAM *srcVram )
{
	PIXEL *curDesPos = desLinePos, *curSrcPos = srcLinePos;
	PIXEL *nextDesPos, *nextSrcPos;
	CHAR curDesOffset = desBitOffset, curSrcOffset = srcBitOffset;
	CHAR nextDesOffset, nextSrcOffset;
	WORD i;

	for( i = 0; i < height; i++ )
	{
		LineOp( curDesPos, curDesOffset, curSrcPos, curSrcOffset, width, op );
		GetNextLine( &nextDesPos, &nextDesOffset, curDesPos, curDesOffset, desVram );
		GetNextLine( &nextSrcPos, &nextSrcOffset, curSrcPos, curSrcOffset, srcVram );
		curDesPos = nextDesPos;
		curDesOffset = nextDesOffset;
		curSrcPos = nextSrcPos;
		curSrcOffset = nextSrcOffset;
	}
}

//GetBlock 申请一块指定大小的vram

⌨️ 快捷键说明

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