mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-10 02:49:39 +02:00
+ Some cleanup
* Bugfix of Detect in InitGraph
This commit is contained in:
parent
67d686f8ed
commit
1a45ac6847
@ -448,6 +448,11 @@ TYPE
|
|||||||
{ this routine actually switches to the desired video mode. }
|
{ this routine actually switches to the desired video mode. }
|
||||||
initmodeproc = procedure;
|
initmodeproc = procedure;
|
||||||
|
|
||||||
|
{ this routine is called to save the sate just before a mode set }
|
||||||
|
savestateproc = procedure;
|
||||||
|
{ this routine is called in closegraph to cleanup... }
|
||||||
|
restorestateproc = procedure;
|
||||||
|
|
||||||
TYPE
|
TYPE
|
||||||
{-----------------------------------}
|
{-----------------------------------}
|
||||||
{ Linked list for mode information }
|
{ Linked list for mode information }
|
||||||
@ -510,6 +515,9 @@ VAR
|
|||||||
HLine : HLineProc;
|
HLine : HLineProc;
|
||||||
VLine : VLineProc;
|
VLine : VLineProc;
|
||||||
|
|
||||||
|
SaveVideoState : SaveStateProc;
|
||||||
|
RestoreVideoState: RestoreStateProc;
|
||||||
|
|
||||||
|
|
||||||
Procedure Closegraph;
|
Procedure Closegraph;
|
||||||
procedure SetLineStyle(LineStyle: word; Pattern: word; Thickness: word);
|
procedure SetLineStyle(LineStyle: word; Pattern: word; Thickness: word);
|
||||||
@ -524,6 +532,7 @@ function GetModeName(ModeNumber: integer): string;
|
|||||||
procedure SetGraphMode(Mode: Integer);
|
procedure SetGraphMode(Mode: Integer);
|
||||||
function GetGraphMode: Integer;
|
function GetGraphMode: Integer;
|
||||||
function GetMaxMode: word;
|
function GetMaxMode: word;
|
||||||
|
procedure RestoreCrtMode;
|
||||||
procedure GetModeRange(GraphDriver: Integer; var LoMode, HiMode: Integer);
|
procedure GetModeRange(GraphDriver: Integer; var LoMode, HiMode: Integer);
|
||||||
Function GetX: Integer;
|
Function GetX: Integer;
|
||||||
Function GetY: Integer;
|
Function GetY: Integer;
|
||||||
@ -665,9 +674,6 @@ var
|
|||||||
|
|
||||||
ArcCall: ArcCoordsType; { Information on the last call to Arc or Ellipse }
|
ArcCall: ArcCoordsType; { Information on the last call to Arc or Ellipse }
|
||||||
|
|
||||||
VidMode: Byte; { Old video mode to restore to }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var
|
var
|
||||||
|
|
||||||
@ -1495,7 +1501,7 @@ end;
|
|||||||
Offset, x : Integer;
|
Offset, x : Integer;
|
||||||
Begin
|
Begin
|
||||||
For x:=0 to MaxX Do Begin
|
For x:=0 to MaxX Do Begin
|
||||||
WordArray(Data)[x]:=GetPixel(x, y);
|
WordArray(Data)[x]:=GetPixel(x, y);
|
||||||
End;
|
End;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
@ -2219,85 +2225,13 @@ end;
|
|||||||
{$i fills.inc}
|
{$i fills.inc}
|
||||||
{$i text.inc}
|
{$i text.inc}
|
||||||
|
|
||||||
function GetModeName(ModeNumber: integer): string;
|
|
||||||
{********************************************************}
|
|
||||||
{ Function GetModeName() }
|
|
||||||
{--------------------------------------------------------}
|
|
||||||
{ Checks the known video list, and returns ModeName }
|
|
||||||
{ string. On error returns an empty string. }
|
|
||||||
{********************************************************}
|
|
||||||
var
|
|
||||||
mode: PModeInfo;
|
|
||||||
begin
|
|
||||||
mode:=nil;
|
|
||||||
GetModeName:='';
|
|
||||||
{ only search in the current driver modes ... }
|
|
||||||
mode:=SearchMode(IntCurrentDriver,ModeNumber);
|
|
||||||
if assigned(mode) then
|
|
||||||
GetModeName:=Mode^.ModeName
|
|
||||||
else
|
|
||||||
_GraphResult := grInvalidMode;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function GetGraphMode: Integer;
|
|
||||||
begin
|
|
||||||
GetGraphMode := IntCurrentMode;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function GetMaxMode: word;
|
|
||||||
{ I know , i know, this routine is very slow, and it would }
|
|
||||||
{ be much easier to sort the linked list of possible modes }
|
|
||||||
{ instead of doing this, but I'm lazy!! And anyways, the }
|
|
||||||
{ speed of the routine here is not that important.... }
|
|
||||||
var
|
|
||||||
i: word;
|
|
||||||
mode: PModeInfo;
|
|
||||||
begin
|
|
||||||
mode:=nil;
|
|
||||||
i:=0;
|
|
||||||
repeat
|
|
||||||
inc(i);
|
|
||||||
{ mode 0 always exists... }
|
|
||||||
{ start search at 1.. }
|
|
||||||
mode:=SearchMode(IntCurrentDriver,i);
|
|
||||||
until not assigned(mode);
|
|
||||||
GetMaxMode:=i;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
procedure GetModeRange(GraphDriver: Integer; var LoMode,
|
|
||||||
HiMode: Integer);
|
|
||||||
var
|
|
||||||
i : integer;
|
|
||||||
mode : PModeInfo;
|
|
||||||
begin
|
|
||||||
LoMode:=-1;
|
|
||||||
HiMode:=-1;
|
|
||||||
mode := nil;
|
|
||||||
{ First search if the graphics driver is supported .. }
|
|
||||||
{ since mode zero is always supported.. if that driver }
|
|
||||||
{ is supported it should return something... }
|
|
||||||
mode := SearchMode(GraphDriver, 0);
|
|
||||||
{ driver not supported...}
|
|
||||||
if not assigned(mode) then exit;
|
|
||||||
{ now it exists... find highest available mode... }
|
|
||||||
LoMode := 0;
|
|
||||||
mode:=nil;
|
|
||||||
i:=-1;
|
|
||||||
repeat
|
|
||||||
inc(i);
|
|
||||||
{ start search at 0.. }
|
|
||||||
mode:=SearchMode(GraphDriver,i);
|
|
||||||
until not assigned(mode);
|
|
||||||
HiMode := i;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
procedure InitGraph(var GraphDriver:Integer;var GraphMode:Integer;
|
procedure InitGraph(var GraphDriver:Integer;var GraphMode:Integer;
|
||||||
const PathToDriver:String);
|
const PathToDriver:String);
|
||||||
var i,index:Integer;
|
var i,index:Integer;
|
||||||
LoMode, HiMode: Integer;
|
LoMode, HiMode: Integer;
|
||||||
CpyMode: Integer;
|
CpyMode: Integer;
|
||||||
|
CpyDriver: Integer;
|
||||||
begin
|
begin
|
||||||
{ path to the fonts (where they will be searched)...}
|
{ path to the fonts (where they will be searched)...}
|
||||||
bgipath:=PathToDriver;
|
bgipath:=PathToDriver;
|
||||||
@ -2306,6 +2240,8 @@ end;
|
|||||||
|
|
||||||
{ make sure our driver list is setup...}
|
{ make sure our driver list is setup...}
|
||||||
QueryAdapterInfo;
|
QueryAdapterInfo;
|
||||||
|
if not assigned(SaveVideoState) then
|
||||||
|
RunError(216);
|
||||||
SaveVideoState;
|
SaveVideoState;
|
||||||
InitVars;
|
InitVars;
|
||||||
DriverName:=InternalDriverName; { DOS Graphics driver }
|
DriverName:=InternalDriverName; { DOS Graphics driver }
|
||||||
@ -2314,27 +2250,30 @@ end;
|
|||||||
begin
|
begin
|
||||||
HiMode := -1;
|
HiMode := -1;
|
||||||
LoMode := -1;
|
LoMode := -1;
|
||||||
|
{ We start at VGA-1 }
|
||||||
GraphDriver := VGA;
|
GraphDriver := VGA;
|
||||||
|
CpyMode := 0;
|
||||||
{ search all possible graphic drivers in ascending order...}
|
{ search all possible graphic drivers in ascending order...}
|
||||||
{ usually the new driver numbers indicate newest hardware...}
|
{ usually the new driver numbers indicate newest hardware...}
|
||||||
{ Internal driver numbers start at VGA=9 }
|
{ Internal driver numbers start at VGA=9 }
|
||||||
while (CpyMode<>-1) do
|
repeat
|
||||||
begin
|
|
||||||
GetModeRange(GraphDriver,LoMode,HiMode);
|
GetModeRange(GraphDriver,LoMode,HiMode);
|
||||||
{ save the highest mode possible...}
|
{ save the highest mode possible...}
|
||||||
|
if HiMode = -1 then break;
|
||||||
CpyMode:=HiMode;
|
CpyMode:=HiMode;
|
||||||
|
CpyDriver:=GraphDriver;
|
||||||
{ go to next driver if it exists...}
|
{ go to next driver if it exists...}
|
||||||
Inc(GraphDriver);
|
Inc(GraphDriver);
|
||||||
end;
|
until (CpyMode=-1);
|
||||||
IntCurrentDriver := GraphDriver;
|
IntCurrentDriver := CpyDriver;
|
||||||
{ If this is equal to -1 then no graph mode possible...}
|
{ If this is equal to -1 then no graph mode possible...}
|
||||||
if Himode = -1 then
|
if CpyMode = -1 then
|
||||||
begin
|
begin
|
||||||
_GraphResult := grNotDetected;
|
_GraphResult := grNotDetected;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
{ Actually set the graph mode...}
|
{ Actually set the graph mode...}
|
||||||
SetGraphMode(HiMode);
|
SetGraphMode(CpyMode);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
@ -2352,98 +2291,14 @@ end;
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure SetGraphMode(mode: Integer);
|
|
||||||
var
|
|
||||||
modeinfo: PModeInfo;
|
|
||||||
begin
|
|
||||||
{ check if the mode exists... }
|
|
||||||
modeinfo := searchmode(IntcurrentDriver,mode);
|
|
||||||
if not assigned(modeinfo) then
|
|
||||||
begin
|
|
||||||
_GraphResult := grInvalidMode;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
{ reset all hooks...}
|
|
||||||
DefaultHooks;
|
|
||||||
{ arccall not reset - tested against VGA BGI driver }
|
|
||||||
{ Setup all hooks if none, keep old defaults...}
|
|
||||||
|
|
||||||
{ required hooks - returns error if no hooks to these }
|
|
||||||
{ routines. }
|
|
||||||
if assigned(modeinfo^.DirectPutPixel) then
|
|
||||||
DirectPutPixel := modeinfo^.DirectPutPixel
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
_Graphresult := grInvalidMode;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
|
|
||||||
if assigned(modeinfo^.PutPixel) then
|
|
||||||
PutPixel := modeinfo^.PutPixel
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
_Graphresult := grInvalidMode;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
|
|
||||||
if assigned(modeinfo^.GetPixel) then
|
|
||||||
GetPixel := modeinfo^.GetPixel
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
_Graphresult := grInvalidMode;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ optional hooks. }
|
|
||||||
if assigned(modeinfo^.ClearViewPort) then
|
|
||||||
ClearViewPort := modeinfo^.ClearViewPort;
|
|
||||||
if assigned(modeinfo^.PutImage) then
|
|
||||||
PutImage := modeinfo^.PutImage;
|
|
||||||
if assigned(modeinfo^.GetImage) then
|
|
||||||
GetImage := modeinfo^.GetImage;
|
|
||||||
if assigned(modeinfo^.ImageSize) then
|
|
||||||
ImageSize := modeinfo^.ImageSize;
|
|
||||||
if assigned(modeinfo^.GetScanLine) then
|
|
||||||
GetScanLine := modeinfo^.GetScanLine;
|
|
||||||
if assigned(modeinfo^.Line) then
|
|
||||||
Line := modeinfo^.Line;
|
|
||||||
if assigned(modeinfo^.InternalEllipse) then
|
|
||||||
InternalEllipse := modeinfo^.InternalEllipse;
|
|
||||||
if assigned(modeinfo^.PatternLine) then
|
|
||||||
PatternLine := modeinfo^.PatternLine;
|
|
||||||
if assigned(modeinfo^.HLine) then
|
|
||||||
Hline := modeinfo^.Hline;
|
|
||||||
if assigned(modeinfo^.Vline) then
|
|
||||||
VLine := modeinfo^.VLine;
|
|
||||||
IntCurrentMode := modeinfo^.ModeNumber;
|
|
||||||
IntCurrentDriver := modeinfo^.DriverNumber;
|
|
||||||
XAspect := modeinfo^.XAspect;
|
|
||||||
YAspect := modeinfo^.YAspect;
|
|
||||||
MaxX := modeinfo^.MaxX;
|
|
||||||
MaxY := modeinfo^.MaxY;
|
|
||||||
MaxColor := modeinfo^.MaxColor;
|
|
||||||
{ now actually initialize the video mode...}
|
|
||||||
{ check first if the routine exists }
|
|
||||||
if not assigned(modeinfo^.InitMode) then
|
|
||||||
begin
|
|
||||||
_GraphResult := grInvalidMode;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
modeinfo^.InitMode;
|
|
||||||
{ It is very important that this call be made }
|
|
||||||
{ AFTER the other variables have been setup. }
|
|
||||||
{ Since it calls some routines which rely on }
|
|
||||||
{ those variables. }
|
|
||||||
GraphDefaults;
|
|
||||||
SetViewPort(0,0,MaxX,MaxY,TRUE);
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
var
|
var
|
||||||
ExitSave: pointer;
|
ExitSave: pointer;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
ModeList := nil;
|
ModeList := nil;
|
||||||
|
SaveVideoState := nil;
|
||||||
|
RestoreVideoState := nil;
|
||||||
{ This must be called at startup... because GetGraphMode may }
|
{ This must be called at startup... because GetGraphMode may }
|
||||||
{ be called even when not in graph mode. }
|
{ be called even when not in graph mode. }
|
||||||
QueryAdapterInfo;
|
QueryAdapterInfo;
|
||||||
@ -2452,8 +2307,6 @@ begin
|
|||||||
ExitProc := @CleanMode;
|
ExitProc := @CleanMode;
|
||||||
end.
|
end.
|
||||||
|
|
||||||
RestoreCrtMode
|
|
||||||
|
|
||||||
|
|
||||||
GetDefaultPalette
|
GetDefaultPalette
|
||||||
GetPalette
|
GetPalette
|
||||||
|
Loading…
Reference in New Issue
Block a user