ULONG TestRead()
{
ULONG i = 100;
CHAR ch;
while (i--)
{
ch = READ_PORT_UCHAR(0x64);
KeStallExecutionProcessor(50);
if (!(ch&OUTPUTFULL))
break;
}
if (i)
return 1;
return 0;
}
ULONG TestWrite()
{
ULONG i = 100;
CHAR ch;
while (i--)
{
ch = READ_PORT_UCHAR(0x64);
KeStallExecutionProcessor(50);
if (!(ch&INPUTFULL))
break;
}
if (i)
return 1;
return 0;
}
BOOLEAN InPreCh(UCHAR CurCh)
{
ULONG i = 0;
for (i = 0; i < CurPos; i++)
if (CurCh == PreCh[i])
return TRUE;
return FALSE;
}
VOID MoveInPreCh(UCHAR CurCh)
{
ULONG i = 0;
for (i = 0; i < CurPos; i++)
{
if (PreCh[i] == 0)
{
PreCh[i] = CurCh;
return;
}
}
PreCh[CurPos++] = CurCh;
}
VOID MoveOutPreCh(UCHAR CurCh)
{
LONG i = 0;
for (i = 0; i < CurPos; i++)
if (CurCh == PreCh[i])
{
PreCh[i] = 0;
break;
}
for (i = CurPos - 1; i >= 0; i--)
{
if (PreCh[i] == 0)
{
--CurPos;
}
else
break;
}
}
VOID MyPortFilter()
{
UCHAR CurCh;
ULONG res = 0;
KIRQL CurIrql, OldIrql;
ULONG ProcessorNo = 0;
CurIrql = KeGetCurrentIrql();
if (CurIrql < DISPATCH_LEVEL)
{
KeAcquireSpinLock(&SpinLock, &OldIrql);
}
else
{
KeAcquireSpinLockAtDpcLevel(&SpinLock);
}
ProcessorNo = KeGetCurrentProcessorNumber();
//DbgPrint("processor no:%d\n",ProcessorNo);
//测试是否可读
while (!res)
{
res = TestRead();
}
res = 0;
CurCh = READ_PORT_UCHAR(0x60);
if (!InPreCh(CurCh))
{
DbgPrint("makecode:%x\n", CurCh);
MoveInPreCh(CurCh);
while (!res)
{
res = TestWrite();
}
res = 0;
WRITE_PORT_UCHAR(0x64, 0xd2);
while (!res)
{
res = TestWrite();
}
res = 0;
WRITE_PORT_UCHAR(0x60, CurCh);
}
else
{
MoveOutPreCh(CurCh);
}