mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-07-11 07:19:20 +00:00
Implement Virtual Terminal and fix /dev/kcon
This commit is contained in:
@ -24,8 +24,6 @@ NewLock(PrintLock);
|
||||
|
||||
namespace Video
|
||||
{
|
||||
Font *Display::GetCurrentFont() { return CurrentFont; }
|
||||
void Display::SetCurrentFont(Font *Font) { CurrentFont = Font; }
|
||||
uint16_t Display::GetBitsPerPixel() { return this->framebuffer.BitsPerPixel; }
|
||||
size_t Display::GetPitch() { return this->framebuffer.Pitch; }
|
||||
|
||||
@ -83,223 +81,6 @@ namespace Video
|
||||
}
|
||||
}
|
||||
|
||||
void Display::Scroll(int Lines)
|
||||
{
|
||||
if (this->DoNotScroll)
|
||||
return;
|
||||
|
||||
if (Lines == 0)
|
||||
return;
|
||||
|
||||
if (Lines > 0)
|
||||
{
|
||||
uint32_t LineSize = this->Width * (this->framebuffer.BitsPerPixel / 8);
|
||||
uint32_t BytesToMove = LineSize * Lines * this->CurrentFont->GetInfo().Height;
|
||||
size_t BytesToClear = this->Size - BytesToMove;
|
||||
memmove(this->Buffer, (uint8_t *)this->Buffer + BytesToMove, BytesToClear);
|
||||
memset((uint8_t *)this->Buffer + BytesToClear, 0, BytesToMove);
|
||||
|
||||
// memset(this->DirtyMap.data(), true, this->DirtyMap.size());
|
||||
}
|
||||
}
|
||||
|
||||
__no_sanitize("undefined") char Display::Print(char Char,
|
||||
Video::Font *_Font,
|
||||
bool WriteToUART,
|
||||
bool IgnoreSpecialChars)
|
||||
{
|
||||
// SmartLock(PrintLock);
|
||||
|
||||
if (this->ColorIteration)
|
||||
{
|
||||
// RRGGBB
|
||||
if (Char >= '0' && Char <= '9')
|
||||
this->Color = (this->Color << 4) | (Char - '0');
|
||||
else if (Char >= 'a' && Char <= 'f')
|
||||
this->Color = (this->Color << 4) | (Char - 'a' + 10);
|
||||
else if (Char >= 'A' && Char <= 'F')
|
||||
this->Color = (this->Color << 4) | (Char - 'A' + 10);
|
||||
else
|
||||
this->Color = 0xFFFFFF;
|
||||
this->ColorPickerIteration++;
|
||||
if (this->ColorPickerIteration == 6)
|
||||
{
|
||||
this->ColorPickerIteration = 0;
|
||||
this->ColorIteration = false;
|
||||
}
|
||||
return Char;
|
||||
}
|
||||
|
||||
if (WriteToUART && Char != '\e')
|
||||
UniversalAsynchronousReceiverTransmitter::UART(UniversalAsynchronousReceiverTransmitter::COM1).Write(Char);
|
||||
|
||||
if (_Font == nullptr)
|
||||
_Font = this->DefaultFont;
|
||||
this->CurrentFont = _Font;
|
||||
uint32_t FontHeight;
|
||||
|
||||
if (IgnoreSpecialChars)
|
||||
goto IgnoreSpecialChars;
|
||||
|
||||
switch (Char)
|
||||
{
|
||||
case '\e':
|
||||
{
|
||||
this->ColorIteration = true;
|
||||
return Char;
|
||||
}
|
||||
case '\b':
|
||||
{
|
||||
switch (_Font->GetInfo().Type)
|
||||
{
|
||||
case FontType::PCScreenFont1:
|
||||
{
|
||||
fixme("PCScreenFont1");
|
||||
break;
|
||||
}
|
||||
case FontType::PCScreenFont2:
|
||||
{
|
||||
uint32_t fonthdrWidth = _Font->GetInfo().PSF2Font->Header->width;
|
||||
uint32_t fonthdrHeight = _Font->GetInfo().PSF2Font->Header->height;
|
||||
|
||||
for (unsigned long Y = this->CursorY; Y < this->CursorY + fonthdrHeight; Y++)
|
||||
for (unsigned long X = this->CursorX - fonthdrWidth; X < this->CursorX; X++)
|
||||
*(uint32_t *)((uintptr_t)this->Buffer +
|
||||
(Y * this->Width + X) * (this->framebuffer.BitsPerPixel / 8)) = 0;
|
||||
|
||||
// for (size_t i = 0; i < 9; ++i)
|
||||
// {
|
||||
// size_t row = (CursorY / RegionHeight) + (i / 3) - 1;
|
||||
// size_t col = (CursorX / RegionWidth) + (i % 3) - 1;
|
||||
// if (row < Height / RegionHeight && col < Width / RegionWidth)
|
||||
// MarkRegionDirty(row, col);
|
||||
// }
|
||||
break;
|
||||
}
|
||||
default:
|
||||
warn("Unsupported font type");
|
||||
break;
|
||||
}
|
||||
|
||||
if (this->CursorX > 0)
|
||||
this->CursorX -= this->GetCurrentFont()->GetInfo().Width;
|
||||
|
||||
return Char;
|
||||
}
|
||||
case '\t':
|
||||
{
|
||||
this->CursorX = (this->CursorX + 8) & ~(8 - 1);
|
||||
return Char;
|
||||
}
|
||||
case '\r':
|
||||
{
|
||||
this->CursorX = 0;
|
||||
return Char;
|
||||
}
|
||||
case '\n':
|
||||
{
|
||||
this->CursorX = 0;
|
||||
this->CursorY += this->GetCurrentFont()->GetInfo().Height;
|
||||
return Char;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
IgnoreSpecialChars:
|
||||
FontHeight = this->GetCurrentFont()->GetInfo().Height;
|
||||
|
||||
if (this->CursorX + this->GetCurrentFont()->GetInfo().Width >= this->Width)
|
||||
{
|
||||
this->CursorX = 0;
|
||||
this->CursorY += FontHeight;
|
||||
}
|
||||
|
||||
if (this->CursorY + FontHeight >= this->Height)
|
||||
{
|
||||
if (!this->DoNotScroll)
|
||||
{
|
||||
this->CursorY -= FontHeight;
|
||||
this->Scroll(1);
|
||||
}
|
||||
}
|
||||
|
||||
switch (_Font->GetInfo().Type)
|
||||
{
|
||||
case FontType::PCScreenFont1:
|
||||
{
|
||||
uint32_t *PixelPtr = (uint32_t *)this->Buffer;
|
||||
char *FontPtr = (char *)_Font->GetInfo().PSF1Font->GlyphBuffer + (Char * _Font->GetInfo().PSF1Font->Header->charsize);
|
||||
for (uint64_t Y = this->CursorY; Y < this->CursorY + 16; Y++)
|
||||
{
|
||||
for (uint64_t X = this->CursorX; X < this->CursorX + 8; X++)
|
||||
if ((*FontPtr & (0b10000000 >> (X - this->CursorX))) > 0)
|
||||
*(unsigned int *)(PixelPtr + X + (Y * this->Width)) = this->Color;
|
||||
FontPtr++;
|
||||
}
|
||||
this->CursorX += 8;
|
||||
|
||||
break;
|
||||
}
|
||||
case FontType::PCScreenFont2:
|
||||
{
|
||||
// if (_Font->PSF2Font->GlyphBuffer == (uint16_t *)0x01) // HAS UNICODE TABLE
|
||||
// Char = _Font->PSF2Font->GlyphBuffer[Char];
|
||||
|
||||
FontInfo fInfo = _Font->GetInfo();
|
||||
|
||||
int BytesPerLine = (fInfo.PSF2Font->Header->width + 7) / 8;
|
||||
char *FontAddress = (char *)fInfo.StartAddress;
|
||||
uint32_t FontHeaderSize = fInfo.PSF2Font->Header->headersize;
|
||||
uint32_t FontCharSize = fInfo.PSF2Font->Header->charsize;
|
||||
uint32_t FontLength = fInfo.PSF2Font->Header->length;
|
||||
char *FontPtr = FontAddress + FontHeaderSize + (Char > 0 && (uint32_t)Char < FontLength ? Char : 0) * FontCharSize;
|
||||
|
||||
uint32_t FontHdrWidth = fInfo.PSF2Font->Header->width;
|
||||
uint32_t FontHdrHeight = fInfo.PSF2Font->Header->height;
|
||||
|
||||
for (size_t Y = this->CursorY; Y < this->CursorY + FontHdrHeight; Y++)
|
||||
{
|
||||
for (size_t X = this->CursorX; X < this->CursorX + FontHdrWidth; X++)
|
||||
{
|
||||
if ((*FontPtr & (0b10000000 >> (X - this->CursorX))) > 0)
|
||||
{
|
||||
void *FramebufferAddress = (void *)((uintptr_t)this->Buffer +
|
||||
(Y * this->Width + X) *
|
||||
(this->framebuffer.BitsPerPixel / 8));
|
||||
*(uint32_t *)FramebufferAddress = this->Color;
|
||||
}
|
||||
}
|
||||
FontPtr += BytesPerLine;
|
||||
}
|
||||
this->CursorX += FontHdrWidth;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
warn("Unsupported font type");
|
||||
break;
|
||||
}
|
||||
|
||||
// // MarkRegionDirty(CursorY / RegionHeight, CursorX / RegionWidth);
|
||||
// for (size_t i = 0; i < 9; ++i)
|
||||
// {
|
||||
// size_t row = (CursorY / RegionHeight) + (i / 3) - 1;
|
||||
// size_t col = (CursorX / RegionWidth) + (i % 3) - 1;
|
||||
// if (row < Height / RegionHeight && col < Width / RegionWidth)
|
||||
// MarkRegionDirty(row, col);
|
||||
// }
|
||||
return Char;
|
||||
}
|
||||
|
||||
void Display::PrintString(const char *String,
|
||||
Video::Font *Font,
|
||||
bool WriteToUART,
|
||||
bool IgnoreSpecialChars)
|
||||
{
|
||||
for (size_t i = 0; String[i] != '\0'; ++i)
|
||||
Print(String[i], Font, WriteToUART, IgnoreSpecialChars);
|
||||
}
|
||||
|
||||
void Display::UpdateBuffer()
|
||||
{
|
||||
if (!DirectWrite)
|
||||
@ -367,7 +148,6 @@ namespace Video
|
||||
}
|
||||
|
||||
Display::Display(BootInfo::FramebufferInfo Info,
|
||||
bool LoadDefaultFont,
|
||||
bool _DirectWrite)
|
||||
: framebuffer(Info), DirectWrite(_DirectWrite)
|
||||
{
|
||||
@ -380,16 +160,6 @@ namespace Video
|
||||
Buffer = KernelAllocator.RequestPages(TO_PAGES(Size));
|
||||
|
||||
// DirtyMap.resize((Width / RegionWidth) * (Height / RegionHeight), false);
|
||||
|
||||
if (!LoadDefaultFont)
|
||||
return;
|
||||
this->DefaultFont = new Font(&_binary_files_tamsyn_font_1_11_Tamsyn7x14r_psf_start, &_binary_files_tamsyn_font_1_11_Tamsyn7x14r_psf_end, FontType::PCScreenFont2);
|
||||
#ifdef DEBUG
|
||||
FontInfo fInfo = this->DefaultFont->GetInfo();
|
||||
debug("Font loaded: %dx%d %s",
|
||||
fInfo.Width, fInfo.Height,
|
||||
fInfo.Type == FontType::PCScreenFont1 ? "PSF1" : "PSF2");
|
||||
#endif
|
||||
}
|
||||
|
||||
Display::~Display() {}
|
||||
|
Reference in New Issue
Block a user