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

📄 sample.c

📁 一个关于s1d13806的应用程序
💻 C
字号:
/*
**===========================================================================
**  Sample.c - Sample application
**---------------------------------------------------------------------------
**  Created 1999, Epson Research & Development
**  Vancouver Design Centre
**  Copyright (c) Epson Research & Development, 1999, 2001  All rights reserved.
**---------------------------------------------------------------------------
**	Hungarian notation is used in this example so the reader need not
**	continually refer to the top of the file or to the header files to
**  see the type of arguments.
**	sz ... Zero terminated String
**	 u ... Unsigned
**	 n ... Integer
**	dw ... DWord
**
**  This code has been compiled with the Microsoft Visual C/C++ 5.0 compiler.
**	The generated code was run under Windows 98 with an S1D13806 PCI
**	evaluation card.
**	Modifications will be necessary to compile for other platforms.
**===========================================================================
*/

/*
** Build for the Intel PCI evaluation card.
*/
#define INTEL_W32

#include <stdio.h>

#include "Hal.h"
#include "Appcfg.h"
#include "Hal_regs.h"

/*
** These constants will set all the appropriate bits of for each color
** at 15/16 bit per pixel. They will be used for setting colors in the
** hardware cursor and as display colors if the display is configured
** for a color depth of 15/16 BPP.
*/
#define RED16BPP   0xF800
#define GREEN16BPP 0x07E0
#define BLUE16BPP  0x001F

int main()
{
	char *szVersion, *szStatus, *szRevision;
	DWORD dwMemSize, dwMemAvail;
	unsigned uWidth, uHeight;
	int nBPP;
	WORD wColorRed, wColorGreen, wColorBlue;
	BYTE byBlackRedBlue[4][3] =
	{
		{   0,    0,    0},		/* Black */
		{0xF0,    0,    0},		/* Red */
		{   0, 0xF0,    0},		/* Green */
		{   0,    0, 0xF0}		/* Blue */
	};
	DWORD dwDisplayAddr, dwMem;
	DWORD dwOffset;
	BYTE byData;
	WORD wData;
	long x1, x2, y1, y2;
	long lRadius;
	int x;

	/*
	** Register with the HAL.
	** HalInfo is a HAL_STRUCT structure and is defined in appcfg.h
	** The return value from seRegisterDevice() must be ERR_OK.
	** This example does not handle specific error cases.
	*/
	if (seRegisterDevice(&HalInfo) != ERR_OK)
	{
		printf("\nERROR: Unable to register device with HAL.");
		return 1;
	}
	
	/*
	** Retrieve the HAL version information and display it.
	*/
	seGetHalVersion(&szVersion, &szStatus, &szRevision);
	printf("\n13806 HAL version: %s %s %s\n", szVersion, szStatus, szRevision);
	
	/*
	** Initialize the S1D13806.
	** Use the default values stored in the HalInfo structure and clear
	** display memory as part of the initialization.
	** If we don't recieve a return value of ERR_OK then print an error
	** message and exit the program.
	*/
	if (seInitReg(0, CLEAR_MEM) != ERR_OK)
	{
		printf("\nERROR: Unable to initialize the S1D13806");
		return 1;
	}

	/*
	** The user could configure this application with 13806CFG.EXE.
	** Before continuing we have to retrieve a few things about our
	** current environment.
	*/
	dwMemSize  = seGetInstalledMemorySize();
	dwMemAvail = seGetAvailableMemorySize();
	printf("\nInstalled memory is %ld", dwMemSize);
	printf("\nAvailable memory is %ld", dwMemAvail);
	
	if (seGetResolution(&uWidth, &uHeight) != ERR_OK)
	{
		printf("\nERROR: Unable to get screen size.");
		return 1;
	}
	printf("\nDimensions (width x height): %d x %d", uWidth, uHeight);

	/*
	** Retrieve and display the color depth.
	*/
	nBPP = seGetBitsPerPixel();
	printf("\nColor depth (BPP): %d", nBPP);
	
	/*
	** Set the first four LUT entries to be Black, Red, Green, and Blue.
	**
	** At 15/16 bit-per-pixel we don't need to program the lookup table
	** as the display uses direct color.
	*/
	switch(nBPP)
	{
		case 4:
		case 8:
			seWriteLut(&byBlackRedBlue[0][0], 4);
			wColorRed    = 1;		/* LUT offset 1 is red. */
			wColorGreen  = 2;		/* LUT offset 2 is green. */
			wColorBlue   = 3;		/* LUT offset 3 is blue. */
			break;

		default:
			wColorRed = RED16BPP;
			wColorGreen = GREEN16BPP;
			wColorBlue = BLUE16BPP;
		break;
	}

	/*
	** Get a pointer to display memory and fill all of memory with blue, then
	** green, then red.
	*/
	dwDisplayAddr = seGetLinearDisplayAddress();
	for (x = 3; x > 0; x--)
	{
		dwMem = dwDisplayAddr;
		byData = x;
		switch (nBPP)
		{
			case 4:
				byData = x | x << 4;
			case 8:
				for (dwOffset = 0; dwOffset < dwMemAvail; dwOffset++, dwMem++)
					*(BYTE*)dwMem = byData;
				break;

			case 15:
			case 16:
				if (x == 3)
					wData = wColorBlue;
				if (x == 2)
					wData = wColorGreen;
				if (x == 1)
 					wData = wColorRed;
				for (dwOffset = 0; dwOffset < dwMemAvail; dwOffset++, dwMem += 2)
					*(WORD*)dwMem = wData;
		}
	}

	/*
	** Clear memory by setting to black using a memory access API.
	** Start at offset 0, write zeros and fill all of display memory.
	*/
	seWriteDisplayBytes(0, 0, dwMemAvail);

	/* Delay for 2 seconds. */
	seDelay(2);

	/*
	** Draw a green line from top-left to bottom-right corner.
	*/
	seDrawLine(0, 0, uWidth - 1, uHeight - 1, wColorGreen);

	/* Delay for 2 seconds. */
	seDelay(2);

	/*
	** Draw a filled rectangle centered at 1/4 x,y and 3/4 x,y
	*/
	x1 = uWidth / 4;
	x2 = uWidth / 2 + x1;
	y1 = uHeight/ 4;
	y2 = uHeight/ 2 + y1;
	seDrawRect(x1, y1, x2, y2, wColorRed, TRUE);

	/* Delay for 2 seconds. */
	seDelay(2);

	/*
	** Draw a blue circle centered in the rectangle.
	** Draw the circle to fit inside the smaller of width or height.
	*/
	x1 = x1 + uWidth / 4;
 	y1 = y1 + uHeight / 4;
	if (uWidth > uHeight)
		lRadius = (uHeight / 4) - 2;
	else
		lRadius = (uHeight / 4) - 2;
	seDrawLcdCircle(x1, y1, lRadius, wColorBlue);

	/* Delay for 2 seconds. */
	seDelay(2);

	/*
	** Draw a box around the screen using line draws.
	** (as opposed to drawing with a rectangle)
	*/
	seDrawLine(        0,          0, uWidth -1,          0, wColorBlue);
	seDrawLine(        0, uHeight -1, uWidth -1, uHeight -1, wColorBlue);
	seDrawLine(        0,          0,         0, uHeight -1, wColorBlue);
	seDrawLine(uWidth -1,          0, uWidth -1, uHeight -1, wColorBlue);

	/* Delay for 2 seconds. */
	seDelay(2);
	
	/*
	** Prepare the cursor for use. The cursor we will draw will be transparent
	** with a one pixel blue border and a three pixel green X. 
	**
	** The cursor color routines require a  16-bit color regardless
	** of the display color depth.
	*/
	seInitCursor();
	seEnableCursor(FALSE);
	seSetCursorColor(0, 0x00003F00);
	seSetCursorColor(1, 0x0000001F);

	seDrawCursorRect(0, 0, 63, 63, 2, TRUE);	/* Clear interior. */
	seDrawCursorLine(1, 1, 62, 62, 0);			/* "\" leg of the X. */
	seDrawCursorLine(2, 1, 62, 61, 0);
	seDrawCursorLine(1, 2, 61, 62, 0);
	seDrawCursorLine(1, 62, 62, 1, 0);			/* "/" leg of the X. */
	seDrawCursorLine(2, 62, 62, 2, 0);
	seDrawCursorLine(1, 61, 61, 1, 0);
	seDrawCursorRect(0, 0, 63, 63, 1, FALSE);	/* Blue border. */
							  
	seEnableCursor(TRUE);

	/* Delay for 2 seconds. */
	seDelay(2);

	/*
	**	Move the cursor
	*/
	x1 = 0;
	y1 = 0;
	for (x = 1; x < 10; x++)
	{
		seDelay(1);
		x1 += 20;
		y1 += 20;
		seMoveCursor(x1, y1);
	}

	printf("\n\n");
	return 0;
}

⌨️ 快捷键说明

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