Ejemplo n.º 1
0
static DWORD WINAPI ScreenBuffer_ReceiverThread(LPVOID param)
{
	SIOPCB *		cb = (SIOPCB *)param;
	DWORD			work;
	INPUT_RECORD	input_record;

	assert(cb != NULL);
	assert(cb->Handle != NULL && cb->Handle != 0);

	while((work = WaitForSingleObject(cb->Handle, INFINITE)) != WAIT_FAILED)
	{
		assert(work == WAIT_OBJECT_0);	/* オブジェクトはシグナル状態になった */

		ReadConsoleInput(cb->Handle, &input_record, 1, &work);

		if(input_record.EventType == KEY_EVENT && input_record.Event.KeyEvent.bKeyDown == TRUE)
		{
			cb->ReceiveBuffer = (char)input_record.Event.KeyEvent.uChar.AsciiChar;

			BITSET(cb->Flag, SIO_STA_INTRCV);
			HALInterruptRequest(INHNO_SERIAL);
		}
	}

	return 0;
}
Ejemplo n.º 2
0
static DWORD WINAPI WinConsole_ReceiverThread(LPVOID param)
{
	SIOPCB *		cb = (SIOPCB *)param;
	DWORD			work;
	HANDLE			stdin;
	INPUT_RECORD	input_record;

	assert(cb != NULL);
	assert(cb->Handle != NULL && cb->Handle != 0);

	stdin = GetStdHandle(STD_INPUT_HANDLE);
	FatalAssertion(stdin != 0, "WinConsole_ReceiverThread failed to acquire the handle of standard input.");

	while((work = WaitForSingleObject(cb->Handle, INFINITE)) != WAIT_FAILED)
	{
		assert(work == WAIT_OBJECT_0);	/* オブジェクトはシグナル状態になった */

		ReadConsoleInput(stdin, &input_record, 1, &work);

		if(input_record.EventType == KEY_EVENT && input_record.Event.KeyEvent.bKeyDown == TRUE)
		{
			cb->ReceiveBuffer = (char)input_record.Event.KeyEvent.uChar.AsciiChar;

			BITSET(cb->Flag, SIO_STA_INTRCV);
			HALInterruptRequest(INHNO_SERIAL);
		}
	}

	return 0;
}
Ejemplo n.º 3
0
static BOOL SerialConsole_PutChar(SIOPCB * cb, INT chr, BOOL rasint)
{
	char	buffer[2];
	int		textlength;
	HANDLE	console;

	assert(cb != NULL);
	assert(BITTEST(cb->Flag, SIO_TYP_CONSOLE));
	assert(cb->Handle != NULL);

	console = GetDlgItem(cb->Handle, IDC_CONSOLE);
	buffer[0] = (char) chr;
	buffer[1] = '\x0';

	textlength = GetWindowTextLength(console);
	if(textlength > BUFSZ_UPPERBOUND)
	{
			/* 古い情報を消す */
		SendMessage(console,EM_SETSEL,0,textlength - BUFSZ_LOWERBOUND);
		SendMessage(console,EM_REPLACESEL,(WPARAM)FALSE,(LPARAM)"");
		textlength = GetWindowTextLength(console);
	}
		/* 末尾に文字を置く */
	SendMessage(console,EM_SETSEL,textlength,textlength);
	SendMessage(console,EM_REPLACESEL,(WPARAM)FALSE,(LPARAM)buffer);

	if(rasint == TRUE)
	{
		BITSET(cb->Flag, SIO_STA_INTSND);
		HALInterruptRequest(INHNO_SERIAL);
	}

	return TRUE;
}
Ejemplo n.º 4
0
ER
ena_int(unsigned int ims)
{
	BOOL lock;
	int  i;

	enter_system_critical_section(&lock);
	i = isns_int(CurrentInterruptLevel);
	CPUStatus &= ~CPU_STAT_LOCK;
	LockerThreadID = 0;
	leave_system_critiacl_section(&lock);

	if(i != 0)
		HALInterruptRequest(0);

	return 0 /*E_OK*/;
}
Ejemplo n.º 5
0
static DWORD WINAPI RawSerial_ReceiverThread(LPVOID param)
{
	SIOPCB *	cb = (SIOPCB *)param;
	DWORD		work;
	char	    buffer;

	assert(cb != NULL);
	assert(cb->Handle != NULL && cb->Handle != 0);

	while((work = WaitForSingleObject(cb->Handle, INFINITE)) != WAIT_FAILED)
	{
		assert(work == WAIT_OBJECT_0);	/* オブジェクトはシグナル状態になった */

		ReadFile(cb->Handle, &buffer, 1, &work, NULL);

		cb->ReceiveBuffer = (char)buffer;
		BITSET(cb->Flag, SIO_STA_INTRCV);
		HALInterruptRequest(INHNO_SERIAL);
	}

	return 0;
}
Ejemplo n.º 6
0
static BOOL RawSerial_PutChar(SIOPCB * cb, INT chr, BOOL rasint)
{
	BOOL  result;
	DWORD written;
	char  word;

	assert(cb != NULL);
	assert(BITTEST(cb->Flag, SIO_TYP_RAWSIO));
	assert(cb->Handle != NULL && cb->Handle != 0);

		/* 標準出力に一文字送信 */
	word   = (char)chr;
	result = WriteFile(cb->Handle, &word, 1, &written, NULL);

		/* 割込み発生フラグが立っていたら、送信完了割込み要求を起こす */
	if(result != 0 && rasint == TRUE)
	{
		BITSET(cb->Flag, SIO_STA_INTSND);
		HALInterruptRequest(INHNO_SERIAL);
	}

	return result != 0 ? TRUE : FALSE;
}
Ejemplo n.º 7
0
ER
chg_ims(unsigned int ims)
{
	BOOL lock;
	int  i;

		//chg_ims は ims==0 を許す
	if(ims != 0 && !CHECK_IMS(ims))
		return -17 /*E_PAR*/;

	enter_system_critical_section(&lock);
	CurrentInterruptLevel = ims;
	if(CurrentInterruptLevel == INT_NUMINTERRUPTS)
		CPUStatus |= CPU_STAT_LOCK;
	else
		CPUStatus &= ~CPU_STAT_LOCK;
	i = isns_int(ims);
	leave_system_critiacl_section(&lock);

	if(i != 0)
		HALInterruptRequest(0);

	return 0 /*E_OK*/;
}
Ejemplo n.º 8
0
static BOOL CALLBACK ConsoleProc(HWND hDlg,UINT Msg,WPARAM wParam,LPARAM lParam)
{
	switch(Msg)
	{
	case SERMSG_CREATE:
		{
			SIOPCB * work;
			void   * DefWndProc;
			HWND     hConsole;

			hConsole = GetDlgItem(hDlg, IDC_CONSOLE);

				/* テキストボックスのWndProcにフックをかける */
			DefWndProc = (void *)GetWindowLong(hConsole,GWL_WNDPROC);
			SetWindowLong(hConsole, GWL_USERDATA, (LONG) DefWndProc);

			work = (SIOPCB *)lParam;
			SetWindowLong(hDlg,GWL_USERDATA,lParam);
			SetWindowLong(hConsole, GWL_WNDPROC, (long)KeyEventTrapper);

			SetTimer(hDlg, 100, 300, NULL);

			ShowWindow(hDlg,SW_SHOWNA);
			break;
		}

	case WM_DESTROY:
		{
			SIOPCB * scope;
			KillTimer(hDlg, 100);
			scope = (SIOPCB *)GetWindowLong(hDlg,GWL_USERDATA);
			if(scope != 0)
				scope->Handle = NULL;
			break;
		}

	case WM_CLOSE:	/* ユーザによるウィンドウクローズを抑止 */
		break;

	case WM_CHAR:
		{
			SIOPCB * scope;
			scope = (SIOPCB *)GetWindowLong(hDlg,GWL_USERDATA);
			if(scope != 0)
			{
				scope->ReceiveBuffer = (char)wParam;
				BITSET(scope->Flag, SIO_STA_INTRCV);
				HALInterruptRequest(INHNO_SERIAL);
			}
			break;
		}

	case WM_SETFONT:
		return TRUE;

	case WM_INITDIALOG:
    case WM_SIZE:
		{
			RECT client;
			GetClientRect(hDlg,&client);
			MoveWindow(GetDlgItem(hDlg,IDC_CONSOLE),0,0,client.right,client.bottom,TRUE);
			break;
		}

	case WM_COMMAND:
		return ConsoleCommandHandler(hDlg, LOWORD(wParam), HIWORD(wParam), lParam);

		//一定時間たったら改行がこなくても出力する
	case WM_TIMER:
		if(wParam == 100)
		{
			SIOPCB * scope;
			struct tagSerialConsoleParameters * param;

			scope = (SIOPCB *)GetWindowLong(hDlg, GWL_USERDATA);
            if(scope != 0) {
			    param = (struct tagSerialConsoleParameters *)scope->versatile;
			    if(param->position == 0)
				    break;

			    lParam = TRUE;
            }
            else
                break;  //まだ初期化が終わってないので何もしない
		}

		//lParam : 送信が終わった後に割込みをかけるかどうか (FALSE:かけない TRUE:かける)
	case SERMSG_UPDATE:
		{
			LRESULT  result;
			int		 textlength;
			HANDLE	 console;
			SIOPCB * scope;
			struct tagSerialConsoleParameters * param;

			scope = (SIOPCB *)GetWindowLong(hDlg, GWL_USERDATA);
            if(scope != 0) {
			    param = (struct tagSerialConsoleParameters *)scope->versatile;

                console = GetDlgItem(hDlg, IDC_CONSOLE);

			    textlength = GetWindowTextLength(console);
			    if(textlength > BUFSZ_UPPERBOUND)
			    {
					    /* 古い情報を消す */
				    SendMessage(console,EM_SETSEL,0,textlength - BUFSZ_LOWERBOUND);
				    SendMessage(console,EM_REPLACESEL,(WPARAM)FALSE,(LPARAM)"");
				    textlength = GetWindowTextLength(console);
			    }
				    /* 末尾に文字を置く */
			    result = SendMessage(console,EM_SETSEL,textlength,textlength);

			    EnterCriticalSection(&param->cs);
			    param->buffer[param->position] = '\x0';
			    result = SendMessage(console,EM_REPLACESEL,(WPARAM)FALSE,(LPARAM)param->buffer);
			    param->position = 0;
			    LeaveCriticalSection(&param->cs);

			    if(lParam == TRUE)
			    {
				    BITSET(scope->Flag, SIO_STA_INTSND);
				    HALInterruptRequest(INHNO_SERIAL);
			    }
            }
            else
                PostMessage(hDlg, Msg, wParam, lParam);     //まだ初期化が終わってないので末尾につけなおす

			break;
		}

	default:
		return FALSE;
	}

	return TRUE;
}