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); tracepagetable(KernelPageTable);
#endif #endif
#if defined(__amd64__) || defined(__i386__) #if defined(__amd64__) || defined(__i386__)
asm volatile("mov %0, %%cr3" ::"r"(KernelPageTable)); asmv("mov %0, %%cr3" ::"r"(KernelPageTable));
#elif defined(__aarch64__) #elif defined(__aarch64__)
asm volatile("msr ttbr0_el1, %0" ::"r"(KernelPageTable)); asmv("msr ttbr0_el1, %0" ::"r"(KernelPageTable));
#endif #endif
if (strstr(Info->Kernel.CommandLine, "xallocv1")) if (strstr(Info->Kernel.CommandLine, "xallocv1"))
{ {

View File

@ -17,86 +17,96 @@ namespace Video
{ {
case '\b': case '\b':
{ {
if (Buffers[Index]->CursorX > 0) if (this->Buffers[Index]->CursorX > 0)
Buffers[Index]->CursorX -= this->GetCurrentFont()->GetInfo().Width; this->Buffers[Index]->CursorX -= this->GetCurrentFont()->GetInfo().Width;
return Char; return Char;
} }
case '\t': case '\t':
{ {
Buffers[Index]->CursorX = (Buffers[Index]->CursorX + 8) & ~(8 - 1); this->Buffers[Index]->CursorX = (this->Buffers[Index]->CursorX + 8) & ~(8 - 1);
return Char; return Char;
} }
case '\r': case '\r':
{ {
Buffers[Index]->CursorX = 0; this->Buffers[Index]->CursorX = 0;
return Char; return Char;
} }
case '\n': case '\n':
{ {
Buffers[Index]->CursorX = 0; this->Buffers[Index]->CursorX = 0;
Buffers[Index]->CursorY += this->GetCurrentFont()->GetInfo().Height; this->Buffers[Index]->CursorY += this->GetCurrentFont()->GetInfo().Height;
return Char; 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; this->Buffers[Index]->CursorY -= this->GetCurrentFont()->GetInfo().Height;
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->Buffers[Index]->CursorX = 0;
this->SetBuffer(Index); this->Buffers[Index]->CursorY += this->GetCurrentFont()->GetInfo().Height;
Scroll(Index, 1);
} }
if (CurrentFont->GetInfo().Type == FontType::PCScreenFont2) switch (this->CurrentFont->GetInfo().Type)
{ {
// if (CurrentFont->PSF2Font->GlyphBuffer == (uint16_t *)0x01) // HAS UNICODE TABLE case FontType::PCScreenFont1:
// Char = CurrentFont->PSF2Font->GlyphBuffer[Char]; {
int bytesperline = (CurrentFont->GetInfo().PSF2Font->Header->width + 7) / 8; uint32_t *PixelPtr = (uint32_t *)this->Buffers[Index]->Buffer;
char *FontPtr = (char *)CurrentFont->GetInfo().StartAddress + char *FontPtr = (char *)this->CurrentFont->GetInfo().PSF1Font->GlyphBuffer + (Char * this->CurrentFont->GetInfo().PSF1Font->Header->charsize);
CurrentFont->GetInfo().PSF2Font->Header->headersize + for (uint64_t Y = this->Buffers[Index]->CursorY; Y < this->Buffers[Index]->CursorY + 16; Y++)
(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++)
{ {
for (unsigned long X = Buffers[Index]->CursorX; X < Buffers[Index]->CursorX + CurrentFont->GetInfo().PSF2Font->Header->width; X++) for (uint64_t X = this->Buffers[Index]->CursorX; X < this->Buffers[Index]->CursorX + 8; X++)
if ((*FontPtr & (0b10000000 >> (X - Buffers[Index]->CursorX))) > 0) if ((*FontPtr & (0b10000000 >> (X - this->Buffers[Index]->CursorX))) > 0)
*(uint32_t *)((uint64_t)Buffers[Index]->Buffer + (Y * Buffers[Index]->Width + X) * (framebuffer.BitsPerPixel / 8)) = 0xFFFFFF; *(unsigned int *)(PixelPtr + X + (Y * this->Buffers[Index]->Width)) = this->Buffers[Index]->Color;
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;
FontPtr++; FontPtr++;
} }
Buffers[Index]->CursorX += 8; this->Buffers[Index]->CursorX += 8;
return Char;
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; return Char;
} }
Display::Display(BootInfo::FramebufferInfo Info, bool LoadDefaultFont) Display::Display(BootInfo::FramebufferInfo Info, bool LoadDefaultFont)
{ {
framebuffer = Info; this->framebuffer = Info;
if (LoadDefaultFont) if (LoadDefaultFont)
{ {
CurrentFont = new Font(&_binary_files_ter_powerline_v12n_psf_start, &_binary_files_ter_powerline_v12n_psf_end, FontType::PCScreenFont2); this->CurrentFont = new Font(&_binary_files_ter_powerline_v12n_psf_start, &_binary_files_ter_powerline_v12n_psf_end, FontType::PCScreenFont2);
FontInfo Info = CurrentFont->GetInfo(); FontInfo Info = this->CurrentFont->GetInfo();
debug("Font loaded: %dx%d %s", debug("Font loaded: %dx%d %s",
Info.Width, Info.Height, Info.Type == FontType::PCScreenFont1 ? "PSF1" : "PSF2"); 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 SetCurrentFont(Font *Font) { CurrentFont = Font; }
void CreateBuffer(uint32_t Width, uint32_t Height, int Index) 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; ScreenBuffer *buffer = new ScreenBuffer;
buffer->Buffer = KernelAllocator.RequestPages(TO_PAGES(Size)); buffer->Buffer = KernelAllocator.RequestPages(TO_PAGES(Size));
buffer->Width = Width; buffer->Width = Width;
@ -105,32 +105,32 @@ namespace Video
buffer->Color = 0x000000; buffer->Color = 0x000000;
buffer->CursorX = 0; buffer->CursorX = 0;
buffer->CursorY = 0; buffer->CursorY = 0;
Buffers[Index] = buffer; this->Buffers[Index] = buffer;
memset(buffer->Buffer, 0, Size); memset(buffer->Buffer, 0, Size);
} }
void SetBuffer(int Index) { memcpy(framebuffer.BaseAddress, Buffers[Index]->Buffer, Buffers[Index]->Size); } void SetBuffer(int Index) { memcpy(this->framebuffer.BaseAddress, this->Buffers[Index]->Buffer, this->Buffers[Index]->Size); }
void ClearBuffer(int Index) { memset(Buffers[Index]->Buffer, 0, Buffers[Index]->Size); } void ClearBuffer(int Index) { memset(this->Buffers[Index]->Buffer, 0, this->Buffers[Index]->Size); }
void DeleteBuffer(int Index) void DeleteBuffer(int Index)
{ {
if (Buffers[Index] == nullptr) if (this->Buffers[Index] == nullptr)
return; return;
KernelAllocator.FreePages(Buffers[Index]->Buffer, TO_PAGES(Buffers[Index]->Size)); KernelAllocator.FreePages(this->Buffers[Index]->Buffer, TO_PAGES(this->Buffers[Index]->Size));
delete Buffers[Index]; delete this->Buffers[Index];
} }
void SetPixel(uint32_t X, uint32_t Y, uint32_t Color, int 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; 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; *Pixel = Color;
} }
uint32_t GetPixel(uint32_t X, uint32_t Y, int Index) 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; 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; return *Pixel;
} }
@ -141,13 +141,16 @@ namespace Video
if (Lines > 0) if (Lines > 0)
{ {
memmove(Buffers[Index]->Buffer, for (uint32_t i = 0; i < this->CurrentFont->GetInfo().Height; i++) // TODO: Make this more efficient.
(uint8_t *)Buffers[Index]->Buffer + (Buffers[Index]->Width * (framebuffer.BitsPerPixel / 8) * Lines), {
Buffers[Index]->Size - (Buffers[Index]->Width * (framebuffer.BitsPerPixel / 8) * Lines)); 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)), memset((uint8_t *)this->Buffers[Index]->Buffer + (this->Buffers[Index]->Size - (this->Buffers[Index]->Width * (this->framebuffer.BitsPerPixel / 8) * Lines)),
0, 0,
Buffers[Index]->Width * (framebuffer.BitsPerPixel / 8) * Lines); this->Buffers[Index]->Width * (this->framebuffer.BitsPerPixel / 8) * Lines);
}
} }
} }