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

📄 xlcd.c

📁 ARM_显示器_键盘_源代码
💻 C
字号:
#include <stdio.h>

#include "xlcd.h"
#include "..\console.h"
#include "..\console_rpc.h"

/***** Win32 version *****/

#include <windows.h>
#include <process.h>
#include <io.h>
#include <fcntl.h>

#define MAX_LCDEVENT_QUEUE  50

int n_lcdevents_in=0;
int n_lcdevents_out=0;

LcdEvent lcdevents[MAX_LCDEVENT_QUEUE];

int LcdModelInit(void)
{
    /* Initialise the Lcd model library */
	
	/* Set up Remote Procedure Call (RPC) */
	RPC_STATUS status;
    char * pszProtocolSequence = "ncalrpc";
    char * pszSecurity     = NULL; /*Security not implemented */
    char * pszEndpoint    = "console_rdi";

    unsigned int    cMinCalls           = 1;
    unsigned int    cMaxCalls           = 20;
    unsigned int    fDontWait           = TRUE;
	RPC_BINDING_VECTOR* vec;

	char buf[100];
 
    /*status = RpcServerUseProtseqEp((unsigned char*)pszProtocolSequence,
                                   cMaxCalls,
                                   (unsigned char*)pszEndpoint,
                                   pszSecurity); 
 */

	/* if we're changing model, make sure all pending calls finish first!! */
	RpcMgmtWaitServerListen();

	status = RpcServerUseProtseq(pszProtocolSequence, cMaxCalls, NULL);

    if (status != RPC_S_OK ) {
		// determine exactly what the error was
		wsprintf( buf, "Invalid server RPC String: status=%d", status );

		switch( status ) {
		case RPC_S_PROTSEQ_NOT_SUPPORTED:
			strcat( buf, ": Protocol sequence not supported on this host" );
			break;

		case RPC_S_INVALID_RPC_PROTSEQ:
			strcat( buf, ": Invalid protocol sequence" );
			break;

		case RPC_S_INVALID_ENDPOINT_FORMAT:
			strcat( buf, ": Invalid endpoint format" );
			break;

		case RPC_S_OUT_OF_MEMORY:
			strcat( buf, ": Out of memory" );
			break;

		case RPC_S_DUPLICATE_ENDPOINT:
			strcat( buf, ": Endpoint is duplicate" );
			break;

		case RPC_S_INVALID_SECURITY_DESC:
			strcat( buf, ": Security descriptor invalid" );
		}

        MessageBox( NULL, buf, "console.dll", MB_OK );
    }
 
    status = RpcServerRegisterIf(console_rpc_v1_0_s_ifspec,  
                                 NULL,   
                                 NULL); 
 
	// Get binding vector for subsequent calls
	status = RpcServerInqBindings(&vec);

	// Register endpoint with endpoint mapper
	status = RpcEpRegister(console_rpc_v1_0_s_ifspec,
			vec,
			NULL,
			pszEndpoint);

	status = RpcBindingVectorFree( &vec );

    status = RpcServerListen(cMinCalls,
                             cMaxCalls,
                             fDontWait);
 
	return TRUE;
}

void LcdModelClose(void)
{
	/* shut down the RPC server */
	RPC_STATUS status;
	HWND hwnd;
	RPC_BINDING_VECTOR* vec;
	unsigned i;

	// close down the viewer window
	hwnd = FindWindow( "Afx:400000:0", "ARM Virtual LCD" );

	if( hwnd != NULL ) {
		SendMessage( hwnd, WM_CLOSE, 0, 0l );
	}
 
    status = RpcMgmtStopServerListening(NULL);
	if( status != RPC_S_OK )
		MessageBox( NULL, "RpcMgmtStopServerListening failed", "console.dll", MB_OK );

	status = RpcServerUnregisterIf(NULL, NULL, 0);
	if( status != RPC_S_OK )
		MessageBox( NULL, "RpcServerUnregisterIf failed", "console.dll", MB_OK );

	status = RpcServerInqBindings( &vec );

	// set vectors to NULL
	for( i = 0; i < vec->Count; i++ ) {
		vec->BindingH[i] = NULL;
	}

	status = RpcEpUnregister( console_rpc_v1_0_s_ifspec, vec, NULL );
	if( status != RPC_S_OK )
		MessageBox( NULL, "RpcEpUnregister failed", "console.dll", MB_OK );

	status = RpcBindingVectorFree( &vec );
}

LcdModel *LcdModelCreate(int XPos, int YPos, unsigned int Width, unsigned int Height)
{

    LcdModel *TheLcd;
	unsigned alignment_tweak;
    TheLcd = (LcdModel *)malloc(sizeof(LcdModel));

    if (TheLcd) {
		DWORD dwErr;

        TheLcd -> PosX   = XPos;
        TheLcd -> PosY   = YPos;
        TheLcd -> Width  = Width;
        TheLcd -> Height = Height;

		alignment_tweak = 4 - Width % 4;
		if( alignment_tweak == 4 ) alignment_tweak = 0;

		/* LCD: create File Mapping object backed by system paging file */
		TheLcd->hMap = CreateFileMapping((HANDLE)-1, NULL, PAGE_READWRITE, 0,
			(Width+alignment_tweak)*Height / (8/BITS_PER_PIXEL), "wince");

	    dwErr = GetLastError();
		if(TheLcd->hMap == NULL) {
			char buf[100];
			sprintf(buf, "GetLastError returned %d\n", dwErr);
			MessageBox(NULL, "File mapping error", buf, MB_OK);

		}

		TheLcd->lpvFile = MapViewOfFile(TheLcd->hMap, FILE_MAP_WRITE, 0, 0, 0); // map whole file

		/* Spawn LCD viewer app */
		{

			char threadidbuf[10];
			int temp = 0;

			sprintf(threadidbuf, "%d", GetCurrentThreadId());

			/* DR amended */
			/*TheLcd->ChildId = _spawnlp(_P_NOWAIT, LCD_NAME, LCD_NAME, threadidbuf, "wince", NULL);*/
			TheLcd->ChildId = _spawnlp(_P_NOWAIT, "lcd.exe", "lcd.exe", threadidbuf, "wince", NULL);

			temp = errno;

			if (TheLcd->ChildId == 0)
			{
				free(TheLcd);
				return 0;
			}
		}
    }

    return TheLcd;
}

void LcdModelDestroy(LcdModel *lcd)
{
	if (lcd) {
        free(lcd);
    }
}

int LcdModelCheckEvents(LcdModel *lcd, LcdEvent *event)
{
	if (n_lcdevents_out != n_lcdevents_in)
	{
		*event = lcdevents[n_lcdevents_out];
		if (n_lcdevents_out == MAX_LCDEVENT_QUEUE)
			n_lcdevents_out = 0;
		n_lcdevents_out++;
	}
	else
		event->Type = LCDNone;

    return 0;
}

void LcdModelWrite(LcdModel * lcd, unsigned int Address, unsigned char Byte)
{
	((unsigned char *)(lcd->lpvFile))[Address] = Byte;
}

// RPC stuff

void QueueKey( int keycode, int type )
{
	//int scancode = getscancode(keycode);
	int scancode = keycode;

	if (scancode) {
		lcdevents[n_lcdevents_in].Type = (type == 0) ? LCDKeyPress : LCDKeyRelease;
		lcdevents[n_lcdevents_in].KeyScanCode = scancode;
		if (n_lcdevents_in == MAX_LCDEVENT_QUEUE)
			n_lcdevents_in = 0;
		n_lcdevents_in++;
	}
}

/******************************************************/
/*         MIDL allocate and free                     */
/******************************************************/
 
void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len)
{
    return(malloc(len));
}
 
void __RPC_USER midl_user_free(void __RPC_FAR * ptr)
{
    free(ptr);
}

⌨️ 快捷键说明

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