Expaneded Video.pas and addec color.pas

Backbuffer will need modification to lmemorymanager to remove the limits to allocation size.
This commit is contained in:
Kieron Morris 2021-06-23 22:19:55 +01:00
parent e4621c8aaa
commit d057bfc3ff
3 changed files with 91 additions and 19 deletions

View File

@ -3,29 +3,59 @@ unit video;
interface interface
uses uses
multiboot, lmemorymanager, tracer, color, rand; multiboot, lmemorymanager, tracer, color, rand, console;
procedure init(); procedure init();
procedure DrawPixel(X : uint32; Y : uint32; Pixel : TRGB32); procedure DrawPixel(X : uint32; Y : uint32; Pixel : TRGB32);
procedure Flush();
type type
VideoBuffer = uint64;
TVESALinearBuffer = record TVESALinearBuffer = record
Location : uint64; Initialized : Boolean;
Location : VideoBuffer;
BitsPerPixel : uint8;
Width : uint32;
Height : uint32;
end;
TBackBuffer = record
Initialized : Boolean;
Location : VideoBuffer;
BitsPerPixel : uint8; BitsPerPixel : uint8;
Width : uint32; Width : uint32;
Height : uint32; Height : uint32;
end; end;
TVESA = record TVESA = record
initialized : Boolean; DefaultBuffer : VideoBuffer;
Framebuffer : TVESALinearBuffer; Framebuffer : TVESALinearBuffer;
BackBuffer : TBackBuffer;
end; end;
PVESA = ^TVESA;
implementation implementation
var var
VESA : TVESA; VESA : TVESA;
procedure allocateFrameBuffer(Address : uint32; Width : uint32; Height : uint32); function allocateBackBuffer(Width : uint32; Height : uint32; BitsPerPixel : uint8) : uint64;
begin
Outputln('VIDEO','Start Kalloc Backbuffer');
//This doesn't currently work... Needs a rework of lmemorymanager
allocateBackBuffer:= uint64(kalloc((Width * Height) * BitsPerPixel));
Outputln('VIDEO','End Kalloc Backbuffer');
end;
procedure initBackBuffer(VESAInfo : PVESA; Width : uint32; Height : uint32; BitsPerPixel : uint8);
begin
VESAInfo^.BackBuffer.Width:= Width;
VESAInfo^.BackBuffer.Height:= Height;
VESAInfo^.BackBuffer.BitsPerPixel:= BitsPerPixel;
VESAInfo^.BackBuffer.Location:= allocateBackBuffer(VESAInfo^.BackBuffer.Width, VESAInfo^.BackBuffer.Height, VESAInfo^.BackBuffer.BitsPerPixel);
VESAInfo^.DefaultBuffer:= VESAInfo^.BackBuffer.Location;
VESAInfo^.BackBuffer.Initialized:= True;
end;
procedure allocateVESAFrameBuffer(Address : uint32; Width : uint32; Height : uint32);
var var
LowerAddress, UpperAddress : uint32; LowerAddress, UpperAddress : uint32;
Block : uint32; Block : uint32;
@ -40,6 +70,19 @@ begin
tracer.push_trace('video.allocateFrameBuffer.enter'); tracer.push_trace('video.allocateFrameBuffer.enter');
end; end;
procedure initVESAFrameBuffer(VESAInfo : PVESA; Location : uint64; Width : uint32; Height : uint32; BitsPerPixel : uint8);
begin
if not(VESAInfo^.Framebuffer.Initialized) then begin
VESAInfo^.Framebuffer.Location:= Location;
VESAInfo^.Framebuffer.BitsPerPixel:= BitsPerPixel;
VESAInfo^.Framebuffer.Width:= Width;
VESAInfo^.Framebuffer.Height:= Height;
allocateVESAFrameBuffer(VESAInfo^.Framebuffer.Location, VESAInfo^.Framebuffer.Width, VESAInfo^.Framebuffer.Height);
VESAInfo^.DefaultBuffer:= VESAInfo^.Framebuffer.Location;
VESAInfo^.Framebuffer.Initialized:= True;
end;
end;
procedure init(); procedure init();
var var
RGB : TRGB32; RGB : TRGB32;
@ -47,14 +90,12 @@ var
begin begin
tracer.push_trace('video.init.enter'); tracer.push_trace('video.init.enter');
If not(VESA.initialized) then begin console.Outputln('VIDEO', 'Init VESA Framebuffer');
VESA.Framebuffer.Location:= multiboot.multibootinfo^.framebuffer_addr; initVESAFrameBuffer(@VESA, multiboot.multibootinfo^.framebuffer_addr, multiboot.multibootinfo^.framebuffer_width, multiboot.multibootinfo^.framebuffer_height, multiboot.multibootinfo^.framebuffer_bpp);
VESA.Framebuffer.BitsPerPixel:= multiboot.multibootinfo^.framebuffer_bpp; console.Outputln('VIDEO', 'Init VESA Backbuffer');
VESA.Framebuffer.Width:= multiboot.multibootinfo^.framebuffer_width; //initBackBuffer(@VESA, multiboot.multibootinfo^.framebuffer_width, multiboot.multibootinfo^.framebuffer_height, multiboot.multibootinfo^.framebuffer_bpp);
VESA.Framebuffer.Height:= multiboot.multibootinfo^.framebuffer_height;
allocateFrameBuffer(VESA.Framebuffer.Location, VESA.Framebuffer.Width, VESA.Framebuffer.Height); console.Outputln('VIDEO', 'Start Test Draw Loop');
VESA.initialized:= true;
end;
srand(98354754397); srand(98354754397);
while true do begin while true do begin
Inc(RGB.R); Inc(RGB.R);
@ -65,19 +106,40 @@ begin
Inc(RGB.B); Inc(RGB.B);
end; end;
end; end;
console.Outputln('VIDEO', 'Call flush');
Flush();
end; end;
tracer.push_trace('video.init.exit'); tracer.push_trace('video.init.exit');
end; end;
procedure DrawPixel(X : uint32; Y : uint32; Pixel : TRGB32); procedure DrawPixel(X : uint32; Y : uint32; Pixel : TRGB32);
var var
Location : PuInt32; Location : PuInt32;
Increment : Uint32; LocationIndex : Uint32;
begin begin
Location:= Puint32(VESA.Framebuffer.Location); Location:= Puint32(VESA.DefaultBuffer);
Increment:= (Y * VESA.Framebuffer.Width) + X; LocationIndex:= (Y * VESA.Framebuffer.Width) + X;
Location[Increment]:= uint32(Pixel); Location[LocationIndex]:= uint32(Pixel);
end;
procedure Flush();
var
x,y : uint32;
Back,Front : PuInt32;
begin
writestringln('Flush Start');
if not(VESA.BackBuffer.Initialized) then exit;
Back:= PUint32(VESA.BackBuffer.Location);
Front:= PuInt32(VESA.Framebuffer.Location);
for x:=0 to VESA.Framebuffer.Width-1 do begin
for y:=0 to VESA.Framebuffer.Height-1 do begin
Front[(Y * VESA.Framebuffer.Width)+X]:= Back[(Y * VESA.Framebuffer.Width)+X];
end;
end;
writestringln('Flush End');
end; end;
end. end.

View File

@ -10,6 +10,12 @@ type
A : uint8; A : uint8;
end; end;
TRGB24 = bitpacked record
B : uint8;
G : uint8;
R : uint8;
end;
TRGB16 = bitpacked record TRGB16 = bitpacked record
B : UBit5; B : UBit5;
G : UBit6; G : UBit6;
@ -22,6 +28,10 @@ type
R : UBit2; R : UBit2;
end; end;
const
black : TRGB32 = (B: 000; G: 000; R: 000; A: 000);
white : TRGB32 = (B: 255; G: 255; R: 255; A: 000);
implementation implementation
end. end.

View File

@ -200,6 +200,8 @@ begin
{ Call Tracer } { Call Tracer }
tracer.init(); tracer.init();
video.init();
{ VFS Init } { VFS Init }
vfs.init(); vfs.init();
@ -262,8 +264,6 @@ begin
tracer.push_trace('kmain.TICK'); tracer.push_trace('kmain.TICK');
video.init();
while true do begin while true do begin
tracer.push_trace('kmain.RedrawWindows'); tracer.push_trace('kmain.RedrawWindows');
console.redrawWindows; console.redrawWindows;