Browse Source

* new platform independent mode handling (between -dnewmodes)

Jonas Maebe 25 years ago
parent
commit
27186c9639
3 changed files with 322 additions and 13 deletions
  1. 50 1
      rtl/inc/graph/graph.inc
  2. 67 2
      rtl/inc/graph/graphh.inc
  3. 205 10
      rtl/inc/graph/modes.inc

+ 50 - 1
rtl/inc/graph/graph.inc

@@ -126,6 +126,9 @@ var
   DriverName: String;
   DriverName: String;
   DirectColor : Boolean ; { Is it a direct color mode? }
   DirectColor : Boolean ; { Is it a direct color mode? }
   ModeList : PModeInfo;
   ModeList : PModeInfo;
+{$ifdef newmodes}
+  newModeList: TNewModeInfo;
+{$endif newmodes}
   DirectVideo : Boolean;  { Direct access to video memory? }
   DirectVideo : Boolean;  { Direct access to video memory? }
 
 
 
 
@@ -2147,6 +2150,43 @@ end;
   begin
   begin
     HiMode := -1;
     HiMode := -1;
     LoMode := -1;
     LoMode := -1;
+{$ifdef newmodes}
+    { Search lowest supported bitDepth }
+    graphdriver := D1bit;
+    while (graphDriver <= highNewDriver) and
+          (hiMode = -1) do
+      begin
+        getModeRange(graphDriver,loMode,hiMode);
+        inc(graphDriver);
+      end;
+    dec(graphdriver);
+    if hiMode = -1 then
+      begin
+        _GraphResult := grNotDetected;
+        exit;
+      end;
+    CpyMode := 0;
+    repeat
+       GetModeRange(GraphDriver,LoMode,HiMode);
+       { save the highest mode possible...}
+       {$ifdef logging}
+       logln('Found driver '+strf(graphdriver)+' with modes '+
+              strf(lomode)+' - '+strf(himode));
+       {$endif logging}
+       if HiMode <> -1 then
+         begin
+           CpyMode:=HiMode;
+           CpyDriver:=GraphDriver;
+         end;
+       { go to next driver if it exists...}
+       Inc(graphDriver);
+    until (graphDriver > highNewDriver);
+    if cpyMode = 0 then
+      begin
+        _GraphResult := grNotDetected;
+        exit;
+      end;
+{$else newmodes}
     { We start at VGA }
     { We start at VGA }
     GraphDriver := VGA;
     GraphDriver := VGA;
     CpyMode := 0;
     CpyMode := 0;
@@ -2172,6 +2212,7 @@ end;
         _GraphResult := grNotDetected;
         _GraphResult := grNotDetected;
         exit;
         exit;
       end;
       end;
+{$endif newmodes}
     _GraphResult := grOK;
     _GraphResult := grOK;
     GraphDriver := CpyDriver;
     GraphDriver := CpyDriver;
     GraphMode := CpyMode;
     GraphMode := CpyMode;
@@ -2286,6 +2327,11 @@ begin
 {$endif logging}
 {$endif logging}
  isgraphmode := false;
  isgraphmode := false;
  ModeList := nil;
  ModeList := nil;
+{$ifdef newmodes}
+ fillChar(newModeList.modeinfo,sizeof(newModeList.modeinfo),#0);
+ { lo and hi modenumber are -1 currently (no modes supported) }
+ fillChar(newModeList.loHiModeNr,sizeof(newModeList.loHiModeNr),#255);
+{$endif newmodes}
  SaveVideoState := nil;
  SaveVideoState := nil;
  RestoreVideoState := nil;
  RestoreVideoState := nil;
 {$ifdef oldfont}
 {$ifdef oldfont}
@@ -2324,7 +2370,10 @@ begin
 end;
 end;
 {
 {
   $Log$
   $Log$
-  Revision 1.32  2000-06-07 07:33:42  jonas
+  Revision 1.33  2000-06-17 19:09:22  jonas
+    * new platform independent mode handling (between -dnewmodes)
+
+  Revision 1.32  2000/06/07 07:33:42  jonas
     * calling a graph function when initgraph is not yet called now prints
     * calling a graph function when initgraph is not yet called now prints
       a nice error message instead of giving a Run Time Error
       a nice error message instead of giving a Run Time Error
 
 

+ 67 - 2
rtl/inc/graph/graphh.inc

@@ -196,7 +196,12 @@
   {$G+}
   {$G+}
 {$endif}
 {$endif}
 
 
-type smallint = -32768..32767;
+type
+    smallint = -32768..32767;
+
+    TResolutionRec = record
+      x,y: longint;
+    end;
 
 
     const
     const
        maxsmallint = high(smallint);
        maxsmallint = high(smallint);
@@ -330,6 +335,24 @@ type smallint = -32768..32767;
        VGA           = 9;
        VGA           = 9;
        VESA          = 10;
        VESA          = 10;
 
 
+{$ifdef newmodes}
+
+       detectDriver = 30000;
+       D1bit = 11;
+       D2bit = 12;
+       D4bit = 13;
+       D8bit = 14;
+       D15bit = 15;
+       D16bit = 16;
+       D24bit = 17; { not yet supported }
+       D32bit = 18; { not yet supported }
+       D64bit = 19; { not yet supported }
+
+       lowNewDriver = 11;
+       highNewDriver = 19;
+{$endif newmodes}
+
+
        { graph modes }
        { graph modes }
        Default = 0;
        Default = 0;
 
 
@@ -338,6 +361,36 @@ type smallint = -32768..32767;
        VGAMed  = 1;
        VGAMed  = 1;
        VGAHi   = 2;
        VGAHi   = 2;
 
 
+{$ifdef newmodes}
+       { They start at such a high number to make sure they don't clash     }
+       { with the mode numbers returned by getmoderange (those mode numbers }
+       { are about the same modes, but all supported modes must have a      }
+       { consecutive mode number for that, so they are generated on-the-fly }
+       { starting from 1)                                                   }
+
+       m320x200 = 30001;
+       m512x384 = 30002; { mac resolution }
+       m640x200 = 30003; { vga resolution }
+       m640x350 = 30004; { vga resolution }
+       m640x400 = 30005;
+       m640x480 = 30006;
+       m800x600 = 30007;
+       m832x624 = 30008; { mac resolution }
+       m1024x768 = 30009;
+       m1280x1024 = 30010;
+       m1600x1200 = 30011;
+       m2048x1536 = 30012;
+
+       lowNewMode = 30001;
+       highNewMode = 30012;
+
+       resolutions: array[lowNewMode..highNewMode] of TResolutionRec =
+       ((x:320;y:200),(x:512;y:384),(x:640;y:200),(x:640;y:350),(x:640;y:400),
+        (x:640;y:480),(x:800;y:600),(x:832;y:624),(x:1024;y:768),
+        (x:1280;y:1024),(x:1600;y:1200),(x:2048;y:1536));
+{$endif newmodes}
+
+
        { Hercules mono card }
        { Hercules mono card }
        HercMonoHi = 0;
        HercMonoHi = 0;
 
 
@@ -560,6 +613,15 @@ TYPE
       next: PModeInfo;
       next: PModeInfo;
     end;
     end;
 
 
+{$ifdef newmodes}
+    TNewModeInfo = record
+      modeInfo: array[lowNewDriver..highNewDriver] of PModeInfo;
+      loHiModeNr: array[lowNewDriver..highNewDriver] of record
+        lo,hi: smallint;
+      end;
+    end;
+{$endif newmodes}
+
 
 
 
 
 VAR
 VAR
@@ -731,7 +793,10 @@ Function GetDriverName: string;
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.5  2000-06-17 11:16:07  sg
+  Revision 1.6  2000-06-17 19:09:23  jonas
+    * new platform independent mode handling (between -dnewmodes)
+
+  Revision 1.5  2000/06/17 11:16:07  sg
   * The string translation is now deactivated by default on all platforms.
   * The string translation is now deactivated by default on all platforms.
 
 
   Revision 1.4  2000/06/16 17:06:08  sg
   Revision 1.4  2000/06/16 17:06:08  sg

+ 205 - 10
rtl/inc/graph/modes.inc

@@ -1,4 +1,4 @@
-{
+  {
     $Id$
     $Id$
 
 
     This file is part of the Free Pascal run time library.
     This file is part of the Free Pascal run time library.
@@ -19,7 +19,56 @@
 {                          Internal routines                            }
 {                          Internal routines                            }
 {-----------------------------------------------------------------------}
 {-----------------------------------------------------------------------}
 
 
- procedure addmode(mode: TModeInfo);
+{$ifdef newmodes}
+ procedure res2Mode(x, y, maxColor: longint; var driver,mode: smallInt);
+ var
+   l: longint;
+ begin
+   case maxColor of
+     2: driver := D1bit;
+     4: driver := D2bit;
+     16: driver := D4bit;
+     256: driver := D8bit;
+     32768: driver := D15bit;
+     65536: driver := D16bit;
+{    not yet supported
+     65536*256: driver := D24bit;
+     65536*65536: driver := D32bit;}
+     else
+       begin
+         driver := maxint;
+         exit;
+       end;
+   end;
+   { Check whether this is known/predefined mode }
+   for l := lowNewMode to highNewMode do
+     if (resolutions[l].x = x) and
+        (resolutions[l].y = y) then
+       begin
+         { Found! }
+         mode := l;
+         exit;
+       end;
+   { Not Found }
+   mode := maxint;
+ end;
+
+function mode2res(modeNr: smallInt; var x,y: longint): boolean;
+begin
+  if (modeNr < lowNewMode) or
+     (modeNr > highNewMode) then
+    begin
+      mode2res := false;
+      exit;
+    end;
+  mode2res := true;
+  x := resolutions[modeNr].x;
+  y := resolutions[modeNr].y;
+end;
+{$endif newmodes}
+
+
+ procedure addmode(const mode: TModeInfo);
   {********************************************************}
   {********************************************************}
   { Procedure AddMode()                                    }
   { Procedure AddMode()                                    }
   {--------------------------------------------------------}
   {--------------------------------------------------------}
@@ -27,9 +76,92 @@
   { modes. Duplicates are allowed.                         }
   { modes. Duplicates are allowed.                         }
   {********************************************************}
   {********************************************************}
   var
   var
+{$ifdef newmodes}
+    driverNr, modeNr: smallint;
+    prev: PModeInfo;
+{$endif newmodes}
     list: PModeInfo;
     list: PModeInfo;
     newlst : PModeInfo;
     newlst : PModeInfo;
   begin
   begin
+{$ifdef newmodes}
+    res2Mode(mode.maxx+1,mode.maxy+1,mode.maxColor,driverNr,ModeNr);
+    { bitdepth supported? }
+    if (driverNr <> maxint) then
+      { Yes, add the mode }
+      if not assigned(newModeList.modeinfo[driverNr]) then
+        begin
+          new(newModeList.modeinfo[driverNr]);
+          newModeList.modeinfo[driverNr]^ := mode;
+          with newModeList.modeinfo[driverNr]^ do
+            begin
+              driverNumber := driverNr;
+              modeNumber := 1;
+              next := nil;
+            end;
+          newModeList.loHiModeNr[driverNr].lo := 1;
+          newModeList.loHiModeNr[driverNr].hi := 1;
+        end
+      else
+        begin
+          prev := nil;
+          list := newModeList.modeinfo[driverNr];
+          { sort first by x resolution, then by yresolution }
+          while assigned(list) and
+                ((list^.maxx < mode.maxx) or
+                 ((list^.maxx = mode.maxx) and
+                  (list^.maxy < mode.maxy))) do
+            begin
+              prev := list;
+              list := list^.next;
+            end;
+          { mode already exists? -> replace (assume later added modes are }
+          { better)                                                       }
+          if assigned(list) and
+             (list^.maxx = mode.maxx) and
+             (list^.maxy = mode.maxy) then
+            begin
+              { save/restore next, drivernr and drivermode in list }
+              driverNr := list^.driverNumber;
+              modeNr := list^.modeNumber;
+              prev := list^.next;
+              list^ := mode;
+              list^.driverNumber := driverNr;
+              list^.modeNumber := modeNr;
+              list^.next := prev;
+            end
+          else
+            begin
+              new(newLst);
+              { Increase the number of modes for this driver }
+              inc(newModeList.loHiModeNr[driverNr].hi);
+              newLst^ := mode;
+              newLst^.driverNumber := driverNr;
+              if assigned(list) then
+                newLst^.next := list^.next
+              else
+                newLst^.next := nil;
+              if assigned(prev) then
+                begin
+                  prev^.next := newLst;
+                  newLst^.modeNumber := succ(prev^.modeNumber)
+                end
+              else
+                begin
+                  newModeList.modeinfo[driverNr] := newLst;
+                  newLst^.modeNumber := 1;
+                end;
+              { Increase the modenumbers of all modes coming after this one }
+              { with 1                                                      }
+              newLst := newLst^.next;
+              while assigned(newLst) do
+                begin
+                  inc(newLst^.modeNumber);
+                  newLst := newLst^.next;
+                end;
+            end;
+        end;
+{$endif newmodes}
+    { TP-like mode stuff }
     if not assigned(ModeList) then
     if not assigned(ModeList) then
       begin
       begin
         new(ModeList);
         new(ModeList);
@@ -69,20 +201,80 @@
   { structure.                                             }
   { structure.                                             }
   { note: if reqmode = -32768, the first mode available    }
   { note: if reqmode = -32768, the first mode available    }
   {   for reqdriver is returned (JM)                       }
   {   for reqdriver is returned (JM)                       }
+  {       if reqmode = -32767, the last mode available     }
+  {   for reqdriver is returned (JM)                       }
   {********************************************************}
   {********************************************************}
     var
     var
      list, lastModeInfo: PModeInfo;
      list, lastModeInfo: PModeInfo;
+     x,y: longint;
     begin
     begin
 {$ifdef logging}
 {$ifdef logging}
       LogLn('Searching for driver '+strf(reqdriver)+' and mode '+strf(reqmode));
       LogLn('Searching for driver '+strf(reqdriver)+' and mode '+strf(reqmode));
 {$endif logging}
 {$endif logging}
-        searchmode := nil;
-        list := ModeList;
-        If assigned(list) then
-          lastModeInfo := list;
-        { go to the end of the list }
-        while assigned(list) do
-          begin
+{$ifdef newmodes}
+      if (reqDriver >= lowNewDriver) and
+         (reqDriver <= highNewDriver) then
+        begin
+          case reqMode of
+            -32768:
+              begin
+                reqMode := newModeList.loHiModeNr[reqDriver].lo;
+                searchMode := newModeList.modeinfo[reqDriver];
+              end;
+            -32767:
+              begin
+                reqMode := newModeList.loHiModeNr[reqDriver].hi;
+                searchMode := nil;
+                { Are there any modes available for this driver? }
+                if reqMode <> -1 then
+                  begin
+                    list := newModeList.modeinfo[reqDriver];
+                    while assigned(list^.next) do
+                      list := list^.next;
+                    searchMode := list;
+                  end;
+              end;
+            else
+              begin
+                list := newModeList.modeinfo[reqDriver];
+                searchMode := nil;
+                if not assigned(list) then
+                  exit;
+                if mode2res(reqMode,x,y) then
+                  begin
+                    x := pred(x);
+                    y := pred(y);
+                    while assigned(list) and
+                          ((list^.maxx < x) or
+                           ((list^.maxx = x) and
+                            (list^.maxy < y))) do
+                      list := list^.next;
+                    if not assigned(list) or
+                       (list^.maxx <> x) or
+                       (list^.maxy <> y) then
+                      list := nil;
+                    searchmode := list;
+                  end
+                else
+                  begin
+                    while assigned(list) and
+                          (list^.modeNumber <> reqMode) do
+                      list := list^.next;
+                    searchMode := list;
+                  end;
+                  
+              end;
+          end;
+          exit;
+        end;
+{$endif newmodes}
+       searchmode := nil;
+       list := ModeList;
+       If assigned(list) then
+         lastModeInfo := list;
+       { go to the end of the list }
+       while assigned(list) do
+         begin
 {$ifdef logging}
 {$ifdef logging}
            Log('Found driver '+strf(list^.DriverNumber)+
            Log('Found driver '+strf(list^.DriverNumber)+
                ' and mode $'+hexstr(list^.ModeNumber,4)+'... ');
                ' and mode $'+hexstr(list^.ModeNumber,4)+'... ');
@@ -363,7 +555,10 @@
 
 
 {
 {
 $Log$
 $Log$
-Revision 1.22  2000-04-02 12:13:37  florian
+Revision 1.23  2000-06-17 19:09:23  jonas
+  * new platform independent mode handling (between -dnewmodes)
+
+Revision 1.22  2000/04/02 12:13:37  florian
   * some more procedures can be now hooked by the OS specific implementation
   * some more procedures can be now hooked by the OS specific implementation
 
 
 Revision 1.21  2000/03/24 18:16:33  florian
 Revision 1.21  2000/03/24 18:16:33  florian