Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
Add cursor blinking functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
EnderIce2 committed Feb 29, 2024
1 parent d3a22aa commit 10aa3d3
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions kshell/shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <driver.hpp>
#include <lock.hpp>
#include <debug.h>
#include <thread>

#include "../kernel.h"
#include "../driver.h"
Expand Down Expand Up @@ -81,6 +82,77 @@ static Command commands[] = {
{"dump", cmd_dump},
};

std::atomic_uint32_t CurX = 0x10, CurY = 0x10;
std::atomic_bool CurBlinking = false;
std::atomic_bool CurHalt = true;
std::atomic_uint64_t BlinkerSleep = 0;

NewLock(BlinkerLock);

void PrintBlinker(uint32_t fx, uint32_t fy)
{
for (uint32_t i = 0; i < fx; i++)
{
for (uint32_t j = 0; j < fy; j++)
{
uint32_t px = CurX.load() + i;
uint32_t py = CurY.load() + j;
uint32_t color = Display->GetPixel(px, py);
Display->SetPixel(px, py, ~color);
}
}
}

void UpdateBlinker()
{
if (CurBlinking.load())
{
SmartLock(BlinkerLock);
uint32_t fx = 0, fy = 0;
if (unlikely(fx == 0 || fy == 0))
{
fx = Display->GetCurrentFont()->GetInfo().Width;
fy = Display->GetCurrentFont()->GetInfo().Height;
}

PrintBlinker(fx, fy);
CurBlinking.store(false);
Display->UpdateBuffer();
}
}

void CursorBlink()
{
uint32_t fx, fy;
fx = Display->GetCurrentFont()->GetInfo().Width;
fy = Display->GetCurrentFont()->GetInfo().Height;
while (true)
{
if (CurHalt.load() ||
BlinkerSleep.load() > TimeManager->GetCounter())
{
TaskManager->Sleep(250);
continue;
}

{
SmartLock(BlinkerLock);
PrintBlinker(fx, fy);
CurBlinking.store(!CurBlinking.load());
Display->UpdateBuffer();
}
TaskManager->Sleep(500);

{
SmartLock(BlinkerLock);
PrintBlinker(fx, fy);
CurBlinking.store(!CurBlinking.load());
Display->UpdateBuffer();
}
TaskManager->Sleep(500);
}
}

void StartKernelShell()
{
if (ShellLock.Locked())
Expand All @@ -106,6 +178,8 @@ void StartKernelShell()
return;
}

std::thread thd(CursorBlink);

printf("Using \eCA21F6/dev/key\eCCCCCC for keyboard input.\n");
while (true)
{
Expand All @@ -127,6 +201,12 @@ void StartKernelShell()
ssize_t nBytes;
while (true)
{
uint32_t cx, cy;
Display->GetBufferCursor(&cx, &cy);
CurX.store(cx);
CurY.store(cy);
CurHalt.store(false);

nBytes = fread(kfd, scBuf, 2);
if (nBytes == 0)
continue;
Expand All @@ -140,6 +220,10 @@ void StartKernelShell()
if (scBuf[0] == 0x00)
continue;

UpdateBlinker();
BlinkerSleep.store(TimeManager->CalculateTarget(250, Time::Units::Milliseconds));
CurHalt.store(true);

uint8_t sc = scBuf[0];
switch (sc & ~KEY_PRESSED)
{
Expand Down

0 comments on commit 10aa3d3

Please sign in to comment.