Vesa32 additions + util functions to support

This commit is contained in:
Kieron Morris 2022-01-23 16:58:46 +00:00
parent ee17f69115
commit 6b81c4ece0
5 changed files with 200 additions and 28 deletions

View File

@ -35,11 +35,11 @@ var
LocationIndex : Uint32; LocationIndex : Uint32;
begin begin
tracer.push_trace('vesa32.DrawPixel.enter'); //tracer.push_trace('vesa32.DrawPixel.enter');
Location:= Puint32(Buffer^.Location); Location:= Puint32(Buffer^.Location);
LocationIndex:= (Y * Buffer^.Width) + X; LocationIndex:= (Y * Buffer^.Width) + X;
Location[LocationIndex]:= uint32(Pixel); Location[LocationIndex]:= uint32(Pixel);
tracer.push_trace('vesa32.DrawPixel.exit'); //tracer.push_trace('vesa32.DrawPixel.exit');
end; end;
procedure init(DrawRoutines : PDrawRoutines); procedure init(DrawRoutines : PDrawRoutines);

View File

@ -22,13 +22,18 @@ unit video;
interface interface
uses uses
lmemorymanager, tracer, color, videotypes, hashmap; lmemorymanager, tracer, color, videotypes, hashmap, util;
procedure init(); procedure init();
procedure DrawPixel(X : uint32; Y : uint32; Pixel : TRGB32); procedure DrawPixel(X : uint32; Y : uint32; Pixel : TRGB32);
procedure DrawLine(x1,y1,x2,y2 : uint32; thickness : uint32; Color : TRGB32);
procedure DrawRect(x1,y1,x2,y2 : uint32; line_thickness : uint32; Color : TRGB32);
procedure FillRect(x1,y1,x2,y2 : uint32; line_thickness : uint32; Line_Color : TRGB32; Fill_Color : TRGB32);
procedure Flush(); procedure Flush();
function register(DriverIdentifier : pchar; EnableCallback : FEnableDriver) : boolean; function register(DriverIdentifier : pchar; EnableCallback : FEnableDriver) : boolean;
function enable(DriverIdentifier : pchar) : boolean; function enable(DriverIdentifier : pchar) : boolean;
function frontBufferWidth : uint32; function frontBufferWidth : uint32;
function frontBufferHeight : uint32; function frontBufferHeight : uint32;
function frontBufferBpp : uint8; function frontBufferBpp : uint8;
@ -41,13 +46,125 @@ implementation
Procedure dummyFDrawPixel(Buffer : PVideoBuffer; X : uint32; Y : uint32; Pixel : TRGB32); Procedure dummyFDrawPixel(Buffer : PVideoBuffer; X : uint32; Y : uint32; Pixel : TRGB32);
begin begin
tracer.push_trace('video.dummyFDrawPixel.enter'); tracer.push_trace('video.dummyFDrawPixel.enter');
//Do nothing //Do nothing, this is the most basic function that must be implemented by a driver.
end; end;
Procedure dummyFFlush(FrontBuffer : PVideoBuffer; BackBuffer : PVideoBuffer); Procedure basicFFlush(FrontBuffer : PVideoBuffer; BackBuffer : PVideoBuffer);
var
x, y : uint32;
Back,Front : puint32;
begin begin
tracer.push_trace('video.dummyFFlush.enter'); tracer.push_trace('video.basicFFlush.enter');
//Do nothing If not(FrontBuffer^.Initialized and BackBuffer^.Initialized) then exit;
if (BackBuffer^.Width > FrontBuffer^.Width) or (BackBuffer^.Height > FrontBuffer^.Height) then exit;
Back:= puint32(BackBuffer^.Location);
Front:= puint32(FrontBuffer^.Location);
for x:=0 to BackBuffer^.Width-1 do begin
for y:=0 to BackBuffer^.Height-1 do begin
Front[(Y * BackBuffer^.Width) + X]:= Back[(Y * BackBuffer^.Width) + X];
end;
end;
end;
procedure basicFDrawLine(Buffer : PVideoBuffer; x1,y1,x2,y2 : uint32; thickness : uint32; Color : TRGB32);
var
X, Y, DX, DY, DX1, DY1, PX, PY, XE, YE, I : sint32;
begin
tracer.push_trace('video.basicFDrawLine.enter');
if(x1 = x2) then begin
for Y:=Y1 to Y2 do begin
DrawPixel(X1,Y,Color);
end;
end else if (y1 = y2) then begin
for X:=X1 to X2 do begin
DrawPixel(X,Y1,Color);
end;
end else begin
DX:= X2 - X1;
DY:= Y2 - Y1;
DX1:= util.abs(DX);
DY1:= util.abs(DY);
PX:= 2 * DY1 - DX1;
PY:= 2 * DX1 - DY1;
if (DY1 <= DX1) then begin
if (dx >= 0) then begin
X:= X1; Y:= Y1; XE:= X2;
end else begin
X:= X2; Y:= Y2; XE:= X1;
end;
DrawPixel(X, Y, Color);
I:=0;
while (x < xe) do begin
X:= X + 1;
if (PX < 0) then begin
PX:= PX + 2 + DY1;
end else begin
if(((dx < 0) and (dy < 0)) OR ((dx > 0) and (dy > 0))) then begin
Y:= Y + 1;
end else begin
Y:= Y - 1;
end;
PX:= PX + 2 * (DY1 - DX1);
end;
DrawPixel(X,Y,Color);
I:= I + 1;
end;
end else begin
if (DY >= 0) then begin
X:= X1; Y:= Y1; YE:= Y2;
end else begin
X:= X2; Y:= Y2; YE:= Y1;
end;
DrawPixel(X, Y, Color);
I:=0;
while (Y < YE) do begin
Y:= Y + 1;
if (PY <= 0) then begin
PY:= PY + 2 * DX1;
end else begin
if (((dx < 0) and (dy < 0)) OR ((dx > 0) and (dy > 0))) then begin
X:= X + 1;
end else begin
X:= X - 1;
end;
PY:= PY + 2 * (dx1 - dy1);
end;
DrawPixel(X,Y,Color);
I:= I + 1;
end;
end;
end;
end;
procedure basicFDrawRect(Buffer : PVideoBuffer; x1,y1,x2,y2 : uint32; line_thickness : uint32; Color : TRGB32);
begin
tracer.push_trace('video.basicFDrawRect.enter');
DrawLine(x1,y1,x2,y1,line_thickness,Color);
DrawLine(x1,y2,x2,y2,line_thickness,Color);
DrawLine(x1,y1,x1,y2,line_thickness,Color);
DrawLine(x2,y1,x2,y2,line_thickness,Color);
end;
procedure basicFFillRect(Buffer : PVideoBuffer; x1,y1,x2,y2 : uint32; line_thickness : uint32; Line_Color : TRGB32; Fill_Color : TRGB32);
var
Y : uint32;
begin
tracer.push_trace('video.basicFFillRect.enter');
for Y:=y1 to y2 do begin
DrawLine(x1,y,x2,y,line_thickness,Fill_Color);
end;
DrawRect(x1,y1,x2,y2,line_thickness,Line_Color);
end; end;
var var
@ -61,12 +178,34 @@ var
begin begin
tracer.push_trace('video.init.enter'); tracer.push_trace('video.init.enter');
//Ensure the frontbuffer is empty & nil, ready for initialization by a driver.
VideoInterface.FrontBuffer.Initialized:= false; VideoInterface.FrontBuffer.Initialized:= false;
VideoInterface.FrontBuffer.Width:= 0;
VideoInterface.FrontBuffer.Height:= 0;
VideoInterface.FrontBuffer.BitsPerPixel:= 0;
VideoInterface.FrontBuffer.Location:= 0;
//Ensure the backbuffer is empty & nil, ready for initialization by a driver.
VideoInterface.BackBuffer.Initialized:= false; VideoInterface.BackBuffer.Initialized:= false;
VideoInterface.BackBuffer.Width:= 0;
VideoInterface.BackBuffer.Height:= 0;
VideoInterface.BackBuffer.BitsPerPixel:= 0;
VideoInterface.BackBuffer.Location:= 0;
//Set the default buffer to be the FrontBuffer, assume no double buffering to begin with.
VideoInterface.DefaultBuffer:= @VideoInterface.FrontBuffer; VideoInterface.DefaultBuffer:= @VideoInterface.FrontBuffer;
{ Set the draw routines to point to dummy/empty routines.
Calls will still succeed but do nothing until a driver has registered. }
VideoInterface.DrawRoutines.DrawPixel:= @dummyFDrawPixel; VideoInterface.DrawRoutines.DrawPixel:= @dummyFDrawPixel;
VideoInterface.DrawRoutines.Flush:= @dummyFFlush; VideoInterface.DrawRoutines.Flush:= @basicFFlush;
VideoInterface.DrawRoutines.DrawLine:= @basicFDrawLine;
VideoInterface.DrawRoutines.DrawRect:= @basicFDrawRect;
VideoInterface.DrawRoutines.FillRect:= @basicFFillRect;
//Initialize our 'DriverMap', a hashmap of loadable display drivers.
DriverMap:= hashmap.new; DriverMap:= hashmap.new;
tracer.push_trace('video.init.exit'); tracer.push_trace('video.init.exit');
end; end;
@ -101,16 +240,31 @@ end;
procedure DrawPixel(X : uint32; Y : uint32; Pixel : TRGB32); procedure DrawPixel(X : uint32; Y : uint32; Pixel : TRGB32);
begin begin
tracer.push_trace('video.DrawPixel.enter'); //tracer.push_trace('video.DrawPixel.enter');
VideoInterface.DrawRoutines.DrawPixel(VideoInterface.DefaultBuffer, X, Y, Pixel); VideoInterface.DrawRoutines.DrawPixel(VideoInterface.DefaultBuffer, X, Y, Pixel);
tracer.push_trace('video.DrawPixel.exit'); //tracer.push_trace('video.DrawPixel.exit');
end; end;
procedure Flush(); procedure Flush();
begin begin
tracer.push_trace('video.Flush.enter'); //tracer.push_trace('video.Flush.enter');
VideoInterface.DrawRoutines.Flush(@VideoInterface.FrontBuffer, @VideoInterface.BackBuffer); VideoInterface.DrawRoutines.Flush(@VideoInterface.FrontBuffer, @VideoInterface.BackBuffer);
tracer.push_trace('video.Flush.exit'); //tracer.push_trace('video.Flush.exit');
end;
procedure DrawLine(x1,y1,x2,y2 : uint32; thickness : uint32; Color : TRGB32);
begin
VideoInterface.DrawRoutines.DrawLine(VideoInterface.DefaultBuffer,x1,y1,x2,y2,thickness,Color);
end;
procedure DrawRect(x1,y1,x2,y2 : uint32; line_thickness : uint32; Color : TRGB32);
begin
VideoInterface.DrawRoutines.DrawRect(VideoInterface.DefaultBuffer,x1,y1,x2,y2,line_thickness,color);
end;
procedure FillRect(x1,y1,x2,y2 : uint32; line_thickness : uint32; Line_Color : TRGB32; Fill_Color : TRGB32);
begin
VideoInterface.DrawRoutines.FillRect(VideoInterface.DefaultBuffer,x1,y1,x2,y2,line_thickness,Line_Color,Fill_Color);
end; end;
function frontBufferWidth : uint32; function frontBufferWidth : uint32;

View File

@ -25,7 +25,7 @@ uses
color; color;
type type
//Arbitrary pointer to a video buffer in memory //Arbitrary pointer to a raw video buffer in memory
VideoBuffer = uint32; VideoBuffer = uint32;
//Struct representing a Memory Mapped Video Buffer //Struct representing a Memory Mapped Video Buffer
@ -48,11 +48,20 @@ type
FDrawPixel = procedure(Buffer : PVideoBuffer; X : uint32; Y : uint32; Pixel : TRGB32); FDrawPixel = procedure(Buffer : PVideoBuffer; X : uint32; Y : uint32; Pixel : TRGB32);
//(Abstract) Flush backbuffer to MMIO Buffer //(Abstract) Flush backbuffer to MMIO Buffer
FFlush = procedure(FrontBuffer : PVideoBuffer; BackBuffer : PVideoBuffer); FFlush = procedure(FrontBuffer : PVideoBuffer; BackBuffer : PVideoBuffer);
//(Abstract) Draw a line to the screen
FDrawLine = procedure(Buffer : PVideoBuffer; x1,y1,x2,y2 : uint32; thickness : uint32; Color : TRGB32);
//(Abstract) Draw a rect to the screen
FDrawRect = procedure(Buffer : PVideoBuffer; x1,y1,x2,y2 : uint32; line_thickness : uint32; Color : TRGB32);
//(Abstract) Draw a filled rect to the screen
FFillRect = procedure(Buffer : PVideoBuffer; x1,y1,x2,y2 : uint32; line_thickness : uint32; Line_Color : TRGB32; Fill_Color : TRGB32);
//Routines for drawing to the screen //Routines for drawing to the screen
TDrawRoutines = record TDrawRoutines = record
DrawPixel : FDrawPixel; DrawPixel : FDrawPixel;
Flush : FFlush; Flush : FFlush;
DrawLine : FDrawLine;
DrawRect : FDrawRect;
FillRect : FFillRect;
end; end;
//Pointer to drawing routines //Pointer to drawing routines
PDrawRoutines = ^TDrawRoutines; PDrawRoutines = ^TDrawRoutines;

View File

@ -80,6 +80,8 @@ function RorDWord(AValue : uint32; Dist : uint8) : uint32;
function MsSinceSystemBoot : uint64; function MsSinceSystemBoot : uint64;
function abs(x : sint32) : uint32;
var var
endptr : uint32; external name '__end'; endptr : uint32; external name '__end';
stack : uint32; external name 'KERNEL_STACK'; stack : uint32; external name 'KERNEL_STACK';
@ -89,6 +91,15 @@ implementation
uses uses
console, RTC, cpu, serial, strings, isr_types; console, RTC, cpu, serial, strings, isr_types;
function abs(x : sint32) : uint32;
var
y : uint32;
begin
y:= x SHR 31;
abs:= (x XOR y) - y;
end;
function MsSinceSystemBoot : uint64; function MsSinceSystemBoot : uint64;
begin begin
MsSinceSystemBoot:= div6432(getTSC, (CPUID.ClockSpeed.Hz div 1000)); MsSinceSystemBoot:= div6432(getTSC, (CPUID.ClockSpeed.Hz div 1000));

View File

@ -208,23 +208,21 @@ begin
doublebuffer.init(@video.register); doublebuffer.init(@video.register);
video.enable('VESA'); video.enable('VESA');
video.enable('BASIC_DOUBLE_BUFFER'); video.enable('BASIC_DOUBLE_BUFFER');
colour:= color.red; colour:= color.white;
while true do begin
for i:=0 to video.frontBufferWidth-1 do begin for i:=0 to video.frontBufferWidth-1 do begin
for z:=0 to video.frontBufferHeight-1 do begin for z:=0 to video.frontBufferHeight-1 do begin
video.DrawPixel(i, z, colour); video.DrawPixel(i, z, colour);
end; end;
end; end;
if uint32(colour) = uint32(color.red) then video.DrawLine(50,50,100,100,1,color.black);
colour:= color.green video.DrawRect(50,150,100,200,1,color.black);
else if uint32(colour) = uint32(color.green) then video.FillRect(50,250,100,300,1,color.black,color.red);
colour:= color.blue video.DrawLine(50,350,100,350,1,color.black);
else if uint32(colour) = uint32(color.blue) then
colour:= color.red;
video.Flush(); video.Flush();
end;
while true do begin end;
{ VFS Init } { VFS Init }
vfs.init(); vfs.init();