CSerial() { dword PortBase = 0x3F8; KeLinkIrq(4); KeEnableNotification(NfKe_TerminateProcess); KeOutPortByte(PortBase + 1, 0x00); // Int Off KeOutPortByte(PortBase + 3, 0x80); // DLAB On KeOutPortByte(PortBase + 0, 0x60); // Divisor Latch Low [1200] KeOutPortByte(PortBase + 1, 0x00); // Divisor Latch High [1200] KeOutPortByte(PortBase + 3, 0x02); // 7 Bits, No Parity, 1 Stop Bit, DLAB Off KeOutPortByte(PortBase + 1, 0x01); // Int On KeOutPortByte(PortBase + 4, 0x00); // DTR Off, RTS Off KeWaitTicks(5); KeOutPortByte(PortBase + 4 , 0x0B); // DTR On, RTS On, OUT2 On CNotification<4> N; for (;;) { KeWaitFor(1); N.Recv(); if (N.GetID() == NfKe_Irq) { byte B = KeInPortByte(PortBase); KeNotify(NfCom_Data, &B, 1); KeEndOfInterrupt(4); } else if (N.GetID() == NfKe_TerminateProcess) return; } }
CBenchmark() { for (dword i = 0; i < 4; i++) m_PerfData[i] = 0; m_SurfID = CreateSurface(300, 200, 256, 256 + 16); FillSurface(m_SurfID, 0xFFFFFFFF); DrawFrameRect(m_SurfID, 0, 0, 256, 256 + 16, 0xFF808080); ShowSurface(m_SurfID); KeEnableNotification(Nf_VirtualKey); KeEnableNotification(NfKe_TerminateProcess); double T = 0.0; dword FPS = 0; dword T1 = KeGetTime(); for (;;) { for (dword i = 0; i < 6; i++) DrawIter(T - 4.0 * (5 - i), 0xFFFFFFFF); T += 1.0; for (dword i = 0; i < 6; i++) DrawIter(T - 4.0 * (5 - i), 0x004070FF | (((i + 1) * 0x10) << 24)); WaitRedraw(); FPS++; dword T2 = KeGetTime(); if (T2 - T1 >= 1000) { dword AvgFPS = AddPerfData(FPS); T1 = T2; FPS = 0; ShowStat(AvgFPS); } CNotification<4> Nf; dword NfCount = KeGetNotificationCount(); for (dword i = 0; i < NfCount; i++) { Nf.Recv(); if (Nf.GetID() == Nf_VirtualKey) { if (Nf.GetByte(0) == VK_Esc) return; } else if (Nf.GetID() == NfKe_TerminateProcess) return; } } }
CPS2Mouse() { buttonPressed[0] = false; buttonPressed[1] = false; m_Flags = 0; m_DeltaX = 0; m_DeltaY = 0; m_DataIndex = 0; KeEnableNotification(NfKe_TerminateProcess); KeEnableNotification(Nfi8043_MouseData); CNotification<1> N; for (;;) { KeWaitFor(1); N.Recv(); if (N.GetID() == Nfi8043_MouseData) { byte Param = N.GetByte(0); if (m_DataIndex == 0) { byte Flags = Param; if (Flags & 0x8) { m_Flags = Flags; m_DataIndex++; } } else if (m_DataIndex == 1) { m_DeltaX = Param; m_DataIndex++; } else { m_DeltaY = Param; m_DataIndex = 0; int DeltaX = m_DeltaX; int DeltaY = m_DeltaY; DeltaX |= TestBit(m_Flags, 4) * 0xFFFFFF00; DeltaY |= TestBit(m_Flags, 5) * 0xFFFFFF00; DeltaY = -DeltaY; bool buttonPressedNew[2] = { TestBit(m_Flags, 0), TestBit(m_Flags, 1) }; if ((DeltaX != 0) || (DeltaY != 0)) { int moveData[2] = {DeltaX, DeltaY}; KeNotify(Nf_MouseDeltaMove, (byte*)moveData, 8); } for (int i = 0; i < 2; i++) { if (buttonPressed[i] != buttonPressedNew[i]) { if (buttonPressedNew[i]) KeNotify(Nf_MouseButtonDown, (byte*)(&i), 1); else KeNotify(Nf_MouseButtonUp, (byte*)(&i), 1); buttonPressed[i] = buttonPressedNew[i]; } } } } else if (N.GetID() == NfKe_TerminateProcess) { return; } } }
CFileSystem() { KeEnableNotification(NfKe_TerminateProcess); KeEnableNotification(NfFileSystem_AddDisk); KeEnableCallRequest(ClFileSystem_GetDiskCount); KeEnableCallRequest(ClFileSystem_ReadFile); KeEnableCallRequest(ClFileSystem_GetFileSize); KeEnableCallRequest(ClFileSystem_FindFirstFile); KeEnableCallRequest(ClFileSystem_FindNextFile); KeSetSymbol(SmFileSystem_Ready); CCallRequest<0x100> CR; CNotification<0x100> N; for (;;) { KeWaitFor(3); dword NfCount; dword CallCount; KeGetNfClCount(NfCount, CallCount); for (dword z = 0; z < NfCount; z++) { N.Recv(); if (N.GetID() == NfFileSystem_AddDisk) { CFileSystemDeviceInfo FSDI; FSDI.m_DeviceID = N.GetDword(0); FSDI.m_ReadFileFunc = N.GetDword(1); FSDI.m_GetFileSizeFunc = N.GetDword(2); FSDI.m_FindFirstFileFunc = N.GetDword(3); FSDI.m_FindNextFileFunc = N.GetDword(4); m_FSDIs.PushBack(FSDI); KeSetSymbol(SmFileSystem_DiskReady); } else if (N.GetID() == NfKe_TerminateProcess) return; } for (dword z = 0; z < CallCount; z++) { CR.Recv(); if (CR.GetTypeID() == ClFileSystem_GetDiskCount) { CR.Respond(m_FSDIs.Size()); } else if (CR.GetTypeID() == ClFileSystem_ReadFile) { dword SMID = CR.GetDword(0); CStringA FSPath; CStringA Path = CStringA(PC(CR.GetBuf() + 4)); dword FSDevID = ParsePath(Path, FSPath); byte Buf[256]; (PD(Buf))[0] = SMID; (PD(Buf))[1] = m_FSDIs[FSDevID].m_DeviceID; for (dword i = 0; i < FSPath.Len(); i++) Buf[i + 8] = FSPath.GetCh(i); Buf[FSPath.Len() + 8] = 0; KeRequestCall(m_FSDIs[FSDevID].m_ReadFileFunc, Buf, FSPath.Len() + 8 + 1, null, 0); CR.Respond(); } else if (CR.GetTypeID() == ClFileSystem_GetFileSize) { dword FileSize = 0; CStringA FSPath; CStringA Path = CStringA(PC(CR.GetBuf())); dword FSDevID = ParsePath(Path, FSPath); byte Buf[256]; (PD(Buf))[0] = m_FSDIs[FSDevID].m_DeviceID; for (dword i = 0; i < FSPath.Len(); i++) Buf[i + 4] = FSPath.GetCh(i); Buf[FSPath.Len() + 4] = 0; KeRequestCall(m_FSDIs[FSDevID].m_GetFileSizeFunc, Buf, FSPath.Len() + 4 + 1, PB(&FileSize), 4); CR.Respond(FileSize); } else if (CR.GetTypeID() == ClFileSystem_FindFirstFile) { byte OutBuf[64]; dword BufSize = 4; dword DeviceIndex = CR.GetDword(0); KeRequestCall(m_FSDIs[DeviceIndex].m_FindFirstFileFunc, PB(&m_FSDIs[DeviceIndex].m_DeviceID), 4, OutBuf, 64); for (; OutBuf[BufSize]; BufSize++); BufSize++; CR.Respond(PB(&OutBuf), BufSize); } else if (CR.GetTypeID() == ClFileSystem_FindNextFile) { byte OutBuf[64]; dword BufSize = 4; dword PrevPosition = CR.GetDword(0); dword DeviceIndex = CR.GetDword(1); dword FindBuf[2]; FindBuf[0] = PrevPosition; FindBuf[1] = m_FSDIs[DeviceIndex].m_DeviceID; KeRequestCall(m_FSDIs[DeviceIndex].m_FindNextFileFunc, PB(&FindBuf), 8, OutBuf, 64); for (; OutBuf[BufSize]; BufSize++); BufSize++; CR.Respond(PB(&OutBuf), BufSize); } } } }
Ci8042() { m_IsScrollActive = false; m_IsNumActive = false; m_IsCapsActive = false; KeLinkIrq(1); KeLinkIrq(12); KeEnableNotification(NfKe_Irq); KeEnableNotification(NfKe_TimerTick); KeEnableNotification(NfKe_TerminateProcess); KeEnableNotification(NfKeyboard_SwitchLEDStatus); InitDevices(); CNotification<16> N; for (;;) { KeWaitFor(1); dword NfCount = KeGetNotificationCount(); for (dword z = 0; z < NfCount; z++) { N.Recv(); if (N.GetID() == NfKe_TimerTick) { m_TimeoutTimer++; if (m_TimeoutTimer >= 20) { KeDisableNotification(NfKe_TimerTick); //DebugOut("[MouseInitTimeout]", 18); KeInPortByte(0x60); m_IsInitFinished = true; } } else if (N.GetID() == NfKe_Irq) { if (N.GetByte(0) == 1) { byte D = KeInPortByte(0x60); //DebugOut("[fK:", 4); //DebugOut(D); //DebugOut("]", 1); OnKeybByte(D); KeEndOfInterrupt(1); } else if (N.GetByte(0) == 12) { bool M = false; if (KeInPortByte(0x64) & 0x20) M = true; byte D = KeInPortByte(0x60); //if (M) // DebugOut("[fM:", 4); //else // DebugOut("[fm:", 4); //DebugOut(D); //DebugOut("]", 1); if (M) OnMouseByte(D); KeEndOfInterrupt(12); } } else if (N.GetID() == NfKeyboard_SwitchLEDStatus) { SwitchLEDStatus(N.GetByte(0)); } else if (N.GetID() == NfKe_TerminateProcess) return; } if (KeGetNotificationCount() == 0) { if (m_LEDSwitchState == 1) { SendKeyboardData(0xED); m_LEDSwitchState = 2; } else if (m_LEDSwitchState == 3) { SendKeyboardData(m_LEDStatus); m_LEDSwitchState = 4; } } } }
CProcInfo() { KeWaitForSymbol(Sm_InitStage2); m_TickCount = 0; m_KernelTime = 0; m_VisualProgressIndex = 6; m_SurfaceActivated = true; m_X = 20; m_Y = 20; m_Width = 236; m_Height = m_Margin * 4 + (m_VisibleProcCount + 4) * m_FontH; char Digit = '0'; KeRequestCall(ClFont_GetTextWidth, PB(&Digit), 1, PB(&m_DigitW), 4); m_SurfaceID = CreateSurface(m_X, m_Y, m_Width, m_Height); DrawActiveBorder(); DrawRect(m_SurfaceID, 1, 1, m_Width - 2, m_Margin * 3 + m_FontH * 4 - 1, m_BGColor); OutText(m_SurfaceID, m_Margin, m_Margin + m_FontH * 0, 0xFFA020A0, "Page Usage:"); OutText(m_SurfaceID, m_Margin, m_Margin + m_FontH * 1, 0xFFA020A0, "Heap Usage:"); OutText(m_SurfaceID, m_Margin, m_Margin + m_FontH * 2, 0xFFA020A0, "Kernel Time:"); OutText(m_SurfaceID, m_Margin+4, m_Margin*2 + m_FontH * 3, 0xFF2020A0, "ID"); OutText(m_SurfaceID, m_Margin+18, m_Margin*2 + m_FontH * 3, 0xFF20A020, "Mem"); OutText(m_SurfaceID, m_Margin+52, m_Margin*2 + m_FontH * 3, 0xFFA0A020, "Nf"); OutText(m_SurfaceID, m_Margin+74, m_Margin*2 + m_FontH * 3, 0xFF20A0A0, "Usr"); OutText(m_SurfaceID, m_Margin+104, m_Margin*2 + m_FontH * 3, 0xFF20A0A0, "Krn"); OutText(m_SurfaceID, m_Margin+128, m_Margin*2 + m_FontH * 3, 0xFFA02020, "Name"); KeEnableNotification(NfKe_TimerTick); KeEnableNotification(Nf_SurfaceActivated); KeEnableNotification(NfKe_TerminateProcess); CNotification<4> N; for (;;) { KeWaitFor(1); N.Recv(); if (N.GetID() == Nf_SurfaceActivated) { dword activatedSurfaceID = N.GetDword(0); if (activatedSurfaceID == m_SurfaceID) { if (!m_SurfaceActivated) { m_SurfaceActivated = true; DrawActiveBorder(); } } else { if (m_SurfaceActivated) { m_SurfaceActivated = false; DrawActiveBorder(); } } } else if (N.GetID() == NfKe_TimerTick) { if (m_TickCount % 144 == 0) { m_ProcList.Clear(); CProcData PD; char Name[128]; dword PrevPID = 0; for (;;) { dword PID = KeGetNextProcessInfo(PrevPID, PD.m_UsedPageCount, PD.m_NotificationCount, PD.m_UserPerfData, PD.m_KernelPerfData, Name); if (PID == 0xFFFFFFFF) break; PD.m_PID = PID; PD.m_Name = CStringA(Name); m_ProcList.PushBack(PD); PrevPID = PID; } qword UserTotalG = 0; qword KernelTotalG = 0; for (dword i = 0; i < m_ProcList.Size(); i++) { qword UserTotalL = 0; qword KernelTotalL = 0; for (dword j = 0; j < 128; j++) { UserTotalL += m_ProcList[i].m_UserPerfData[j]; KernelTotalL += m_ProcList[i].m_KernelPerfData[j]; } m_ProcList[i].m_UserTotal = UserTotalL; m_ProcList[i].m_KernelTotal = KernelTotalL; UserTotalG += UserTotalL; KernelTotalG += KernelTotalL; } for (dword i = 0; i < m_ProcList.Size(); i++) { m_ProcList[i].m_UserPercent = (m_ProcList[i].m_UserTotal << 16) / UserTotalG; m_ProcList[i].m_KernelPercent = (m_ProcList[i].m_KernelTotal << 16) / KernelTotalG; } m_KernelTime = (KernelTotalG << 16) / (KernelTotalG + UserTotalG); DrawRect(m_SurfaceID, 1, m_Margin * 3 + m_FontH * 4, m_Width - 2, m_Height - (m_Margin * 3 + m_FontH * 4) - 1, m_BGColor); dword VisibleProcCount = m_ProcList.Size(); if (VisibleProcCount > m_VisibleProcCount) VisibleProcCount = m_VisibleProcCount; for (dword i = 0; i < VisibleProcCount; i++) { char CharBuf[5] = {0}; dword XOffset = m_Margin + 14; dword YOffset = m_Margin * 3 + m_FontH * (4 + i); OutDecimal(XOffset, YOffset, m_ProcList[i].m_PID, 0xFF2020A0); XOffset += 24; OutDecimal(XOffset, YOffset, m_ProcList[i].m_UsedPageCount, 0xFF20A020); XOffset += 22; OutDecimal(XOffset, YOffset, m_ProcList[i].m_NotificationCount, 0xFFA0A020); XOffset += 0; OutPercent(XOffset, YOffset, m_ProcList[i].m_UserPercent, 0xFF20A0A0); XOffset += 32; OutPercent(XOffset, YOffset, m_ProcList[i].m_KernelPercent, 0xFF20A0A0); XOffset += 36; OutText(m_SurfaceID, XOffset, YOffset, 0xFFA02020, m_ProcList[i].m_Name._ptr()); } } if (m_TickCount % 24 == 0) { dword HeapUsed; dword HeapTotal; dword PageUsed; dword PageTotal; KeGetMemInfo(HeapUsed, HeapTotal, PageUsed, PageTotal); dword PageUsage = dword((qword(PageUsed) * 0x10000) / PageTotal); dword HeapUsage = dword((qword(HeapUsed) * 0x10000) / HeapTotal); dword KernelTime = 0; dword HeapColor = 0xFF20A0A0; if (HeapUsage > 0x9999) HeapColor = 0xFFF8BF16; if (HeapUsage > 0xB333) HeapColor = 0xFFFA5914; DrawRect(m_SurfaceID, m_Margin + 74, m_Margin, 48, m_FontH * 3, m_BGColor); OutPercent(m_Margin + 74, m_Margin + m_FontH * 0, PageUsage, 0xFF20A0A0, true); OutPercent(m_Margin + 74, m_Margin + m_FontH * 1, HeapUsage, HeapColor, true); OutPercent(m_Margin + 74, m_Margin + m_FontH * 2, m_KernelTime, 0xFF20A0A0, true); dword PrevVP = m_VisualProgressIndex; m_VisualProgressIndex++; if (m_VisualProgressIndex >= 6) m_VisualProgressIndex = 0; dword C1 = 0xFFB0B8FF; dword C2 = 0xFFD0D4FF; if (m_VisualProgressIndex == 0) { C1 = 0xFFFFA393; C2 = 0xFFFFCCC4; } DrawRect(m_SurfaceID, 140 + PrevVP * 12, m_FontH + m_Margin + 4, 8, 8, m_BGColor); DrawRect(m_SurfaceID, 140 + m_VisualProgressIndex * 12, m_FontH + m_Margin + 4, 8, 8, C1); DrawRect(m_SurfaceID, 140 + m_VisualProgressIndex * 12 + 1, m_FontH + m_Margin + 4 + 1, 6, 6, C2); } if (m_TickCount == 0) { ShowSurface(m_SurfaceID); } m_TickCount++; } else if (N.GetID() == NfKe_TerminateProcess) { return; } } }