Fixed display (still slower than I wanted to be)

This commit is contained in:
Alex 2022-10-10 07:01:58 +03:00
parent f0690df9c4
commit 2bf2bf3280
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
3 changed files with 78 additions and 65 deletions

View File

@ -127,9 +127,9 @@ void InitializeMemoryManagement(BootInfo *Info)
tracepagetable(KernelPageTable);
#endif
#if defined(__amd64__) || defined(__i386__)
asm volatile("mov %0, %%cr3" ::"r"(KernelPageTable));
asmv("mov %0, %%cr3" ::"r"(KernelPageTable));
#elif defined(__aarch64__)
asm volatile("msr ttbr0_el1, %0" ::"r"(KernelPageTable));
asmv("msr ttbr0_el1, %0" ::"r"(KernelPageTable));
#endif
if (strstr(Info->Kernel.CommandLine, "xallocv1"))
{

View File

@ -17,86 +17,96 @@ namespace Video
{
case '\b':
{
if (Buffers[Index]->CursorX > 0)
Buffers[Index]->CursorX -= this->GetCurrentFont()->GetInfo().Width;
if (this->Buffers[Index]->CursorX > 0)
this->Buffers[Index]->CursorX -= this->GetCurrentFont()->GetInfo().Width;
return Char;
}
case '\t':
{
Buffers[Index]->CursorX = (Buffers[Index]->CursorX + 8) & ~(8 - 1);
this->Buffers[Index]->CursorX = (this->Buffers[Index]->CursorX + 8) & ~(8 - 1);
return Char;
}
case '\r':
{
Buffers[Index]->CursorX = 0;
this->Buffers[Index]->CursorX = 0;
return Char;
}
case '\n':
{
Buffers[Index]->CursorX = 0;
Buffers[Index]->CursorY += this->GetCurrentFont()->GetInfo().Height;
this->Buffers[Index]->CursorX = 0;
this->Buffers[Index]->CursorY += this->GetCurrentFont()->GetInfo().Height;
return Char;
}
}
if (Buffers[Index]->CursorX + this->GetCurrentFont()->GetInfo().Width >= Buffers[Index]->Width)
if (this->Buffers[Index]->CursorY + this->GetCurrentFont()->GetInfo().Height >= this->Buffers[Index]->Height)
{
Buffers[Index]->CursorX = 0;
Buffers[Index]->CursorY += this->GetCurrentFont()->GetInfo().Height;
this->Buffers[Index]->CursorY -= this->GetCurrentFont()->GetInfo().Height;
this->Scroll(Index, 1);
}
if (Buffers[Index]->CursorY + this->GetCurrentFont()->GetInfo().Height >= Buffers[Index]->Height)
if (this->Buffers[Index]->CursorX + this->GetCurrentFont()->GetInfo().Width >= this->Buffers[Index]->Width)
{
Buffers[Index]->CursorY = Buffers[Index]->Height - this->GetCurrentFont()->GetInfo().Height;
this->SetBuffer(Index);
Scroll(Index, 1);
this->Buffers[Index]->CursorX = 0;
this->Buffers[Index]->CursorY += this->GetCurrentFont()->GetInfo().Height;
}
if (CurrentFont->GetInfo().Type == FontType::PCScreenFont2)
switch (this->CurrentFont->GetInfo().Type)
{
// if (CurrentFont->PSF2Font->GlyphBuffer == (uint16_t *)0x01) // HAS UNICODE TABLE
// Char = CurrentFont->PSF2Font->GlyphBuffer[Char];
int bytesperline = (CurrentFont->GetInfo().PSF2Font->Header->width + 7) / 8;
char *FontPtr = (char *)CurrentFont->GetInfo().StartAddress +
CurrentFont->GetInfo().PSF2Font->Header->headersize +
(Char > 0 && (unsigned char)Char < CurrentFont->GetInfo().PSF2Font->Header->length ? Char : 0) *
CurrentFont->GetInfo().PSF2Font->Header->charsize;
for (unsigned long Y = Buffers[Index]->CursorY; Y < Buffers[Index]->CursorY + CurrentFont->GetInfo().PSF2Font->Header->height; Y++)
case FontType::PCScreenFont1:
{
uint32_t *PixelPtr = (uint32_t *)this->Buffers[Index]->Buffer;
char *FontPtr = (char *)this->CurrentFont->GetInfo().PSF1Font->GlyphBuffer + (Char * this->CurrentFont->GetInfo().PSF1Font->Header->charsize);
for (uint64_t Y = this->Buffers[Index]->CursorY; Y < this->Buffers[Index]->CursorY + 16; Y++)
{
for (unsigned long X = Buffers[Index]->CursorX; X < Buffers[Index]->CursorX + CurrentFont->GetInfo().PSF2Font->Header->width; X++)
if ((*FontPtr & (0b10000000 >> (X - Buffers[Index]->CursorX))) > 0)
*(uint32_t *)((uint64_t)Buffers[Index]->Buffer + (Y * Buffers[Index]->Width + X) * (framebuffer.BitsPerPixel / 8)) = 0xFFFFFF;
FontPtr += bytesperline;
}
Buffers[Index]->CursorX += CurrentFont->GetInfo().PSF2Font->Header->width;
return Char;
}
else if (CurrentFont->GetInfo().Type == FontType::PCScreenFont1)
{
uint32_t *PixelPtr = (uint32_t *)Buffers[Index]->Buffer;
char *FontPtr = (char *)CurrentFont->GetInfo().PSF1Font->GlyphBuffer + (Char * CurrentFont->GetInfo().PSF1Font->Header->charsize);
for (unsigned long Y = Buffers[Index]->CursorY; Y < Buffers[Index]->CursorY + 16; Y++)
{
for (unsigned long X = Buffers[Index]->CursorX; X < Buffers[Index]->CursorX + 8; X++)
if ((*FontPtr & (0b10000000 >> (X - Buffers[Index]->CursorX))) > 0)
*(unsigned int *)(PixelPtr + X + (Y * Buffers[Index]->Width)) = Buffers[Index]->Color;
for (uint64_t X = this->Buffers[Index]->CursorX; X < this->Buffers[Index]->CursorX + 8; X++)
if ((*FontPtr & (0b10000000 >> (X - this->Buffers[Index]->CursorX))) > 0)
*(unsigned int *)(PixelPtr + X + (Y * this->Buffers[Index]->Width)) = this->Buffers[Index]->Color;
FontPtr++;
}
Buffers[Index]->CursorX += 8;
return Char;
this->Buffers[Index]->CursorX += 8;
break;
}
case FontType::PCScreenFont2:
{
// if (this->CurrentFont->PSF2Font->GlyphBuffer == (uint16_t *)0x01) // HAS UNICODE TABLE
// Char = this->CurrentFont->PSF2Font->GlyphBuffer[Char];
int BytesPerLine = (this->CurrentFont->GetInfo().PSF2Font->Header->width + 7) / 8;
char *FontPtr = (char *)this->CurrentFont->GetInfo().StartAddress +
this->CurrentFont->GetInfo().PSF2Font->Header->headersize +
(Char > 0 && (unsigned char)Char < this->CurrentFont->GetInfo().PSF2Font->Header->length ? Char : 0) *
this->CurrentFont->GetInfo().PSF2Font->Header->charsize;
uint32_t fonthdrWidth = this->CurrentFont->GetInfo().PSF2Font->Header->width;
uint32_t fonthdrHeight = this->CurrentFont->GetInfo().PSF2Font->Header->height;
for (uint64_t Y = this->Buffers[Index]->CursorY; Y < this->Buffers[Index]->CursorY + fonthdrHeight; Y++)
{
for (uint64_t X = this->Buffers[Index]->CursorX; X < this->Buffers[Index]->CursorX + fonthdrWidth; X++)
if ((*FontPtr & (0b10000000 >> (X - this->Buffers[Index]->CursorX))) > 0)
*(uint32_t *)((uint64_t)this->Buffers[Index]->Buffer +
(Y * this->Buffers[Index]->Width + X) * (this->framebuffer.BitsPerPixel / 8)) = 0xFFFFFF;
FontPtr += BytesPerLine;
}
this->Buffers[Index]->CursorX += fonthdrWidth;
break;
}
default:
warn("Unsupported font type");
break;
}
return Char;
}
Display::Display(BootInfo::FramebufferInfo Info, bool LoadDefaultFont)
{
framebuffer = Info;
this->framebuffer = Info;
if (LoadDefaultFont)
{
CurrentFont = new Font(&_binary_files_ter_powerline_v12n_psf_start, &_binary_files_ter_powerline_v12n_psf_end, FontType::PCScreenFont2);
FontInfo Info = CurrentFont->GetInfo();
this->CurrentFont = new Font(&_binary_files_ter_powerline_v12n_psf_start, &_binary_files_ter_powerline_v12n_psf_end, FontType::PCScreenFont2);
FontInfo Info = this->CurrentFont->GetInfo();
debug("Font loaded: %dx%d %s",
Info.Width, Info.Height, Info.Type == FontType::PCScreenFont1 ? "PSF1" : "PSF2");
}

View File

@ -96,7 +96,7 @@ namespace Video
void SetCurrentFont(Font *Font) { CurrentFont = Font; }
void CreateBuffer(uint32_t Width, uint32_t Height, int Index)
{
uint64_t Size = framebuffer.Pitch * Height;
uint64_t Size = this->framebuffer.Pitch * Height;
ScreenBuffer *buffer = new ScreenBuffer;
buffer->Buffer = KernelAllocator.RequestPages(TO_PAGES(Size));
buffer->Width = Width;
@ -105,32 +105,32 @@ namespace Video
buffer->Color = 0x000000;
buffer->CursorX = 0;
buffer->CursorY = 0;
Buffers[Index] = buffer;
this->Buffers[Index] = buffer;
memset(buffer->Buffer, 0, Size);
}
void SetBuffer(int Index) { memcpy(framebuffer.BaseAddress, Buffers[Index]->Buffer, Buffers[Index]->Size); }
void ClearBuffer(int Index) { memset(Buffers[Index]->Buffer, 0, Buffers[Index]->Size); }
void SetBuffer(int Index) { memcpy(this->framebuffer.BaseAddress, this->Buffers[Index]->Buffer, this->Buffers[Index]->Size); }
void ClearBuffer(int Index) { memset(this->Buffers[Index]->Buffer, 0, this->Buffers[Index]->Size); }
void DeleteBuffer(int Index)
{
if (Buffers[Index] == nullptr)
if (this->Buffers[Index] == nullptr)
return;
KernelAllocator.FreePages(Buffers[Index]->Buffer, TO_PAGES(Buffers[Index]->Size));
delete Buffers[Index];
KernelAllocator.FreePages(this->Buffers[Index]->Buffer, TO_PAGES(this->Buffers[Index]->Size));
delete this->Buffers[Index];
}
void SetPixel(uint32_t X, uint32_t Y, uint32_t Color, int Index)
{
if (X >= Buffers[Index]->Width || Y >= Buffers[Index]->Height)
if (X >= this->Buffers[Index]->Width || Y >= this->Buffers[Index]->Height)
return;
uint32_t *Pixel = (uint32_t *)((uint64_t)Buffers[Index]->Buffer + (Y * Buffers[Index]->Width + X) * (framebuffer.BitsPerPixel / 8));
uint32_t *Pixel = (uint32_t *)((uint64_t)this->Buffers[Index]->Buffer + (Y * this->Buffers[Index]->Width + X) * (this->framebuffer.BitsPerPixel / 8));
*Pixel = Color;
}
uint32_t GetPixel(uint32_t X, uint32_t Y, int Index)
{
if (X >= Buffers[Index]->Width || Y >= Buffers[Index]->Height)
if (X >= this->Buffers[Index]->Width || Y >= this->Buffers[Index]->Height)
return 0;
uint32_t *Pixel = (uint32_t *)((uint64_t)Buffers[Index]->Buffer + (Y * Buffers[Index]->Width + X) * (framebuffer.BitsPerPixel / 8));
uint32_t *Pixel = (uint32_t *)((uint64_t)this->Buffers[Index]->Buffer + (Y * this->Buffers[Index]->Width + X) * (this->framebuffer.BitsPerPixel / 8));
return *Pixel;
}
@ -141,13 +141,16 @@ namespace Video
if (Lines > 0)
{
memmove(Buffers[Index]->Buffer,
(uint8_t *)Buffers[Index]->Buffer + (Buffers[Index]->Width * (framebuffer.BitsPerPixel / 8) * Lines),
Buffers[Index]->Size - (Buffers[Index]->Width * (framebuffer.BitsPerPixel / 8) * Lines));
for (uint32_t i = 0; i < this->CurrentFont->GetInfo().Height; i++) // TODO: Make this more efficient.
{
memmove(this->Buffers[Index]->Buffer,
(uint8_t *)this->Buffers[Index]->Buffer + (this->Buffers[Index]->Width * (this->framebuffer.BitsPerPixel / 8) * Lines),
this->Buffers[Index]->Size - (this->Buffers[Index]->Width * (this->framebuffer.BitsPerPixel / 8) * Lines));
memset((uint8_t *)Buffers[Index]->Buffer + (Buffers[Index]->Size - (Buffers[Index]->Width * (framebuffer.BitsPerPixel / 8) * Lines)),
0,
Buffers[Index]->Width * (framebuffer.BitsPerPixel / 8) * Lines);
memset((uint8_t *)this->Buffers[Index]->Buffer + (this->Buffers[Index]->Size - (this->Buffers[Index]->Width * (this->framebuffer.BitsPerPixel / 8) * Lines)),
0,
this->Buffers[Index]->Width * (this->framebuffer.BitsPerPixel / 8) * Lines);
}
}
}