Browse Source

--- Merging r15490 into '.':
U packages/graph/src/go32v2/vesa.inc
--- Merging r15556 into '.':
G packages/graph/src/go32v2/vesa.inc
--- Merging r15597 into '.':
G packages/graph/src/go32v2/vesa.inc
--- Merging r15675 into '.':
U packages/graph/src/go32v2/graph.pp
G packages/graph/src/go32v2/vesa.inc
--- Merging r15739 into '.':
G packages/graph/src/go32v2/vesa.inc
--- Merging r15746 into '.':
G packages/graph/src/go32v2/vesa.inc
--- Merging r15748 into '.':
G packages/graph/src/go32v2/vesa.inc
--- Merging r15758 into '.':
G packages/graph/src/go32v2/vesa.inc
U packages/graph/src/go32v2/vesah.inc
--- Merging r15791 into '.':
G packages/graph/src/go32v2/vesa.inc
--- Merging r15869 into '.':
A packages/graph/tests/polytest.txt
A packages/graph/tests/polytest.pas
A packages/graph/tests/polytst2.txt
U packages/graph/src/inc/fills.inc
U packages/graph/src/inc/graph.inc
--- Merging r15870 into '.':
G packages/graph/src/go32v2/graph.pp
--- Merging r15872 into '.':
G packages/graph/src/go32v2/graph.pp
--- Merging r15874 into '.':
G packages/graph/src/inc/graph.inc
--- Merging r15908 into '.':
G packages/graph/src/go32v2/graph.pp
U packages/graph/src/sdlgraph/sdlgraph.pp
U packages/graph/src/inc/graphh.inc
--- Merging r15927 into '.':
G packages/graph/src/go32v2/graph.pp
--- Merging r15947 into '.':
G packages/graph/src/go32v2/graph.pp
--- Merging r15962 into '.':
G packages/graph/src/inc/graph.inc
--- Merging r15963 into '.':
G packages/graph/src/inc/graph.inc
--- Merging r15964 into '.':
G packages/graph/src/go32v2/graph.pp
G packages/graph/src/go32v2/vesa.inc
--- Merging r15965 into '.':
G packages/graph/src/go32v2/graph.pp
G packages/graph/src/go32v2/vesa.inc
--- Merging r15967 into '.':
G packages/graph/src/go32v2/graph.pp
--- Merging r15968 into '.':
G packages/graph/src/go32v2/graph.pp
G packages/graph/src/sdlgraph/sdlgraph.pp
G packages/graph/src/inc/graphh.inc
--- Merging r15969 into '.':
G packages/graph/src/go32v2/graph.pp
--- Merging r15970 into '.':
U packages/graph/src/inc/modes.inc
--- Merging r15973 into '.':
G packages/graph/src/inc/modes.inc
--- Merging r15985 into '.':
G packages/graph/src/inc/modes.inc
--- Merging r15986 into '.':
G packages/graph/src/inc/modes.inc
G packages/graph/src/inc/graphh.inc
G packages/graph/src/inc/graph.inc
--- Merging r15987 into '.':
G packages/graph/src/go32v2/graph.pp
--- Merging r15989 into '.':
G packages/graph/src/go32v2/graph.pp
--- Merging r16003 into '.':
A packages/graph/tests/drawtest.pas
--- Merging r16004 into '.':
U packages/graph/tests/drawtest.pas
--- Merging r16005 into '.':
G packages/graph/src/go32v2/graph.pp
--- Merging r16012 into '.':
G packages/graph/src/go32v2/graph.pp

# revisions: 15490,15556,15597,15675,15739,15746,15748,15758,15791,15869,15870,15872,15874,15908,15927,15947,15962,15963,15964,15965,15967,15968,15969,15970,15973,15985,15986,15987,15989,16003,16004,16005,16012
------------------------------------------------------------------------
r15490 | jonas | 2010-06-29 11:22:09 +0200 (Tue, 29 Jun 2010) | 3 lines
Changed paths:
M /trunk/packages/graph/src/go32v2/vesa.inc

* fixed 16 color vesa get/putpixel offsets (patch by Nikolay Nikolov,
mantis #16806)

------------------------------------------------------------------------
------------------------------------------------------------------------
r15556 | marco | 2010-07-12 10:43:22 +0200 (Mon, 12 Jul 2010) | 3 lines
Changed paths:
M /trunk/packages/graph/src/go32v2/vesa.inc

* YOffset-pageswitch moved later into directputpix procedure, since an
intermediate read might otherwise fail (yoffset is a global) mantis #16911

------------------------------------------------------------------------
------------------------------------------------------------------------
r15597 | jonas | 2010-07-18 11:48:56 +0200 (Sun, 18 Jul 2010) | 3 lines
Changed paths:
M /trunk/packages/graph/src/go32v2/vesa.inc

* always use the read window to read from video memory (patch by
Nikolay Nikolov, mantis #16926)

------------------------------------------------------------------------
------------------------------------------------------------------------
r15675 | marco | 2010-07-31 20:57:10 +0200 (Sat, 31 Jul 2010) | 2 lines
Changed paths:
M /trunk/packages/graph/src/go32v2/graph.pp
M /trunk/packages/graph/src/go32v2/vesa.inc

* Patch from Nikolay adding a hline variant for VESA modes. Mantis 17073

------------------------------------------------------------------------
------------------------------------------------------------------------
r15739 | marco | 2010-08-08 13:51:38 +0200 (Sun, 08 Aug 2010) | 3 lines
Changed paths:
M /trunk/packages/graph/src/go32v2/vesa.inc

* patch from Nikolay that fixes a copy paste bug in hlinevesa256 (and ->or)
Mantis 17128

------------------------------------------------------------------------
------------------------------------------------------------------------
r15746 | marco | 2010-08-08 16:02:33 +0200 (Sun, 08 Aug 2010) | 2 lines
Changed paths:
M /trunk/packages/graph/src/go32v2/vesa.inc

* patch from Nicolay for VLineVESA256 off-by-one error in calculation of BankRest, Mantis 17131

------------------------------------------------------------------------
------------------------------------------------------------------------
r15748 | marco | 2010-08-08 16:54:26 +0200 (Sun, 08 Aug 2010) | 2 lines
Changed paths:
M /trunk/packages/graph/src/go32v2/vesa.inc

* Patch from Nikolay (GetScanLineVESA256 reads from the write window, instead of the read window) mantis 17132

------------------------------------------------------------------------
------------------------------------------------------------------------
r15758 | nickysn | 2010-08-10 02:01:06 +0200 (Tue, 10 Aug 2010) | 1 line
Changed paths:
M /trunk/packages/graph/src/go32v2/vesa.inc
M /trunk/packages/graph/src/go32v2/vesah.inc

VESA 3.0 support
------------------------------------------------------------------------
------------------------------------------------------------------------
r15791 | nickysn | 2010-08-13 02:08:49 +0200 (Fri, 13 Aug 2010) | 1 line
Changed paths:
M /trunk/packages/graph/src/go32v2/vesa.inc

VESA 1.0 fix - zero fill the real mode ModeInfo struct, not the protected mode struct
------------------------------------------------------------------------
------------------------------------------------------------------------
r15869 | nickysn | 2010-08-21 23:18:23 +0200 (Sat, 21 Aug 2010) | 1 line
Changed paths:
M /trunk/packages/graph/src/inc/fills.inc
M /trunk/packages/graph/src/inc/graph.inc
A /trunk/packages/graph/tests/polytest.pas
A /trunk/packages/graph/tests/polytest.txt
A /trunk/packages/graph/tests/polytst2.txt

* DrawPoly and FillPoly TP7 compatibility fixes
------------------------------------------------------------------------
------------------------------------------------------------------------
r15870 | nickysn | 2010-08-22 00:07:52 +0200 (Sun, 22 Aug 2010) | 1 line
Changed paths:
M /trunk/packages/graph/src/go32v2/graph.pp

* fixed GetPixel320
------------------------------------------------------------------------
------------------------------------------------------------------------
r15872 | nickysn | 2010-08-22 12:16:17 +0200 (Sun, 22 Aug 2010) | 1 line
Changed paths:
M /trunk/packages/graph/src/go32v2/graph.pp

* Mode-X fixed (regcall-related bugfix in the asm of SetVisualX)
------------------------------------------------------------------------
------------------------------------------------------------------------
r15874 | nickysn | 2010-08-22 14:54:00 +0200 (Sun, 22 Aug 2010) | 1 line
Changed paths:
M /trunk/packages/graph/src/inc/graph.inc

* fixed Rectangle, Bar and Bar3D for the cases when x1>x2 or y1>y2
------------------------------------------------------------------------
------------------------------------------------------------------------
r15908 | nickysn | 2010-08-26 00:55:05 +0200 (Thu, 26 Aug 2010) | 1 line
Changed paths:
M /trunk/packages/graph/src/go32v2/graph.pp
M /trunk/packages/graph/src/inc/graphh.inc
M /trunk/packages/graph/src/sdlgraph/sdlgraph.pp

* Added CGA and MCGA graphics modes
------------------------------------------------------------------------
------------------------------------------------------------------------
r15927 | nickysn | 2010-09-01 01:08:58 +0200 (Wed, 01 Sep 2010) | 1 line
Changed paths:
M /trunk/packages/graph/src/go32v2/graph.pp

* fixed HLine16 and VLine16 to support multiple video pages
------------------------------------------------------------------------
------------------------------------------------------------------------
r15947 | nickysn | 2010-09-07 22:56:08 +0200 (Tue, 07 Sep 2010) | 1 line
Changed paths:
M /trunk/packages/graph/src/go32v2/graph.pp

* Hercules support added (tested with dosbox, machine=hercules)
------------------------------------------------------------------------
------------------------------------------------------------------------
r15962 | nickysn | 2010-09-10 01:26:07 +0200 (Fri, 10 Sep 2010) | 1 line
Changed paths:
M /trunk/packages/graph/src/inc/graph.inc

* do not reset aspect ratio in GraphDefaults (TP7 compatibility fix)
------------------------------------------------------------------------
------------------------------------------------------------------------
r15963 | nickysn | 2010-09-10 01:30:41 +0200 (Fri, 10 Sep 2010) | 1 line
Changed paths:
M /trunk/packages/graph/src/inc/graph.inc

* aspect ratio adjustment added to Arc and PieSlice
------------------------------------------------------------------------
------------------------------------------------------------------------
r15964 | nickysn | 2010-09-10 22:42:12 +0200 (Fri, 10 Sep 2010) | 1 line
Changed paths:
M /trunk/packages/graph/src/go32v2/graph.pp
M /trunk/packages/graph/src/go32v2/vesa.inc

* optimized all 16-colour routines to use 16-bit port writes to the EGA/VGA Graphics Controller
------------------------------------------------------------------------
------------------------------------------------------------------------
r15965 | nickysn | 2010-09-10 23:19:01 +0200 (Fri, 10 Sep 2010) | 1 line
Changed paths:
M /trunk/packages/graph/src/go32v2/graph.pp
M /trunk/packages/graph/src/go32v2/vesa.inc

* optimized DirectPutPixel16 and DirectPutPixVESA16 to use the EGA/VGA hardware ALU, instead of calling slow GetPixel for XORPut, ANDPut and ORPut write modes
------------------------------------------------------------------------
------------------------------------------------------------------------
r15967 | nickysn | 2010-09-11 19:56:36 +0200 (Sat, 11 Sep 2010) | 1 line
Changed paths:
M /trunk/packages/graph/src/go32v2/graph.pp

* CGA modes are now supported on a real CGA or EGA (tested with dosbox, machine=cga/ega)
------------------------------------------------------------------------
------------------------------------------------------------------------
r15968 | nickysn | 2010-09-11 21:17:47 +0200 (Sat, 11 Sep 2010) | 1 line
Changed paths:
M /trunk/packages/graph/src/go32v2/graph.pp
M /trunk/packages/graph/src/inc/graphh.inc
M /trunk/packages/graph/src/sdlgraph/sdlgraph.pp

* EGA support added
------------------------------------------------------------------------
------------------------------------------------------------------------
r15969 | nickysn | 2010-09-11 21:28:28 +0200 (Sat, 11 Sep 2010) | 1 line
Changed paths:
M /trunk/packages/graph/src/go32v2/graph.pp

* only enable the save/restore state hack on cards, older than VGA
------------------------------------------------------------------------
------------------------------------------------------------------------
r15970 | nickysn | 2010-09-11 22:42:33 +0200 (Sat, 11 Sep 2010) | 1 line
Changed paths:
M /trunk/packages/graph/src/inc/modes.inc

* GetModeName fixed to work with the 'old' mode numbers also
------------------------------------------------------------------------
------------------------------------------------------------------------
r15973 | nickysn | 2010-09-12 19:05:44 +0200 (Sun, 12 Sep 2010) | 1 line
Changed paths:
M /trunk/packages/graph/src/inc/modes.inc

* always set both IntCurrentDriver and IntCurrentNewDriver to the correct old & new style driver numbers
------------------------------------------------------------------------
------------------------------------------------------------------------
r15985 | jonas | 2010-09-14 19:48:34 +0200 (Tue, 14 Sep 2010) | 2 lines
Changed paths:
M /trunk/packages/graph/src/inc/modes.inc

* fixed compilation after r15973 (patch by javivf, mantis #17397)

------------------------------------------------------------------------
------------------------------------------------------------------------
r15986 | nickysn | 2010-09-15 00:11:41 +0200 (Wed, 15 Sep 2010) | 1 line
Changed paths:
M /trunk/packages/graph/src/inc/graph.inc
M /trunk/packages/graph/src/inc/graphh.inc
M /trunk/packages/graph/src/inc/modes.inc

* SetBkColor and GetBkColor made hookable
------------------------------------------------------------------------
------------------------------------------------------------------------
r15987 | nickysn | 2010-09-15 01:02:20 +0200 (Wed, 15 Sep 2010) | 1 line
Changed paths:
M /trunk/packages/graph/src/go32v2/graph.pp

* implemented SetBkColor and GetBkColor for CGA
------------------------------------------------------------------------
------------------------------------------------------------------------
r15989 | nickysn | 2010-09-15 12:33:18 +0200 (Wed, 15 Sep 2010) | 1 line
Changed paths:
M /trunk/packages/graph/src/go32v2/graph.pp

* do not hook SetVisualPage and SetActivePage for modes that only have 1 video page
------------------------------------------------------------------------
------------------------------------------------------------------------
r16003 | nickysn | 2010-09-18 14:53:49 +0200 (Sat, 18 Sep 2010) | 1 line
Changed paths:
A /trunk/packages/graph/tests/drawtest.pas

+ new graph unit test DrawTest for PutPixel, GetPixel, HLine, VLine and write modes
------------------------------------------------------------------------
------------------------------------------------------------------------
r16004 | nickysn | 2010-09-18 15:19:58 +0200 (Sat, 18 Sep 2010) | 1 line
Changed paths:
M /trunk/packages/graph/tests/drawtest.pas

* fixed memory leak in DrawTest, when running more than one test
------------------------------------------------------------------------
------------------------------------------------------------------------
r16005 | nickysn | 2010-09-19 00:23:59 +0200 (Sun, 19 Sep 2010) | 1 line
Changed paths:
M /trunk/packages/graph/src/go32v2/graph.pp

* implemented SetBkColor and GetBkColor for mode MCGAHi (640x480x2)
------------------------------------------------------------------------
------------------------------------------------------------------------
r16012 | nickysn | 2010-09-19 17:41:56 +0200 (Sun, 19 Sep 2010) | 1 line
Changed paths:
M /trunk/packages/graph/src/go32v2/graph.pp

* added SetBkColor and GetBkColor for Hercules
------------------------------------------------------------------------

git-svn-id: branches/fixes_2_4@16387 -

marco 14 years ago
parent
commit
ad36a22cba

+ 4 - 0
.gitattributes

@@ -2075,6 +2075,10 @@ packages/graph/src/unix/graph16.inc svneol=native#text/plain
 packages/graph/src/win32/graph.pp svneol=native#text/plain
 packages/graph/src/win32/wincrt.pp svneol=native#text/plain
 packages/graph/src/win32/winmouse.pp svneol=native#text/plain
+packages/graph/tests/drawtest.pas svneol=native#text/plain
+packages/graph/tests/polytest.pas svneol=native#text/plain
+packages/graph/tests/polytest.txt svneol=native#text/plain
+packages/graph/tests/polytst2.txt svneol=native#text/plain
 packages/gtk1/Makefile svneol=native#text/plain
 packages/gtk1/Makefile.fpc svneol=native#text/plain
 packages/gtk1/README.txt svneol=native#text/plain

File diff suppressed because it is too large
+ 1367 - 0
packages/graph/src/go32v2/graph.pp


+ 207 - 53
packages/graph/src/go32v2/vesa.inc

@@ -239,6 +239,13 @@ end;
 {$endif fpc}
     { get the segment value }
     RealSeg := word(Ptr shr 16);
+    { we have to init everything to zero, since VBE < 1.1  }
+    { may not setup fields correctly.                      }
+{$ifndef fpc}
+    FillChar(VESAPtr^, sizeof(ModeInfo), #0);
+{$else fpc}
+    DosMemFillChar(RealSeg, 0, sizeof(ModeInfo), #0);
+{$endif fpc}
     { setup interrupt registers }
     FillChar(regs, sizeof(regs), #0);
     { call VESA mode information...}
@@ -327,7 +334,10 @@ end;
         begin
           { we have to init everything to zero, since VBE < 1.1  }
           { may not setup fields correctly.                      }
+          { bugfix: for DPMI this is now done in GetVESAModeInfo }
+{$IFNDEF DPMI}
           FillChar(VESAModeInfo, sizeof(VESAModeInfo), #0);
+{$ENDIF}
           If GetVESAModeInfo(VESAModeInfo, Mode) And
              ((VESAModeInfo.attr and modeAvail) <> 0) then
             ModeSupported := TRUE
@@ -515,7 +525,7 @@ end;
           {$endif logging}
           For l := 0 to (Bankrest div 4)-1 Do
             begin
-              pixels := MemL[WinWriteSeg:word(offs)+l*4];
+              pixels := MemL[WinReadSeg:word(offs)+l*4];
               WordArray(Data)[index+l*4] := pixels and $ff;
               pixels := pixels shr 8;
               WordArray(Data)[index+l*4+1] := pixels and $ff;
@@ -798,7 +808,7 @@ end;
                          setreadbank(offs shr 16);
                          setwritebank(offs shr 16);
                          Mem[WinWriteSeg:word(offs)] :=
-                           Mem[WinReadSeg:word(offs)] And byte(currentColor);
+                           Mem[WinReadSeg:word(offs)] Or byte(currentColor);
                          inc(offs);
                        end;
                      HLength := 0
@@ -925,10 +935,10 @@ end;
                  {$ifdef logging2}
                  LogLn('set bank '+strf(curbank)+' for offset '+hexstr(offs,8));
                  {$endif logging}
-                 If (VLength-1)*bytesperline <= ($10000-(Offs and $ffff)) Then
+                 If (VLength-1)*bytesperline <= ($ffff-(Offs and $ffff)) Then
                    bankrest := VLength
                  else {the rest won't fit anymore in the current window }
-                   bankrest := (($10000 - (Offs and $ffff)) div bytesperline)+1;
+                   bankrest := (($ffff - (Offs and $ffff)) div bytesperline)+1;
                  {$ifdef logging2}
                  LogLn('Rest to be drawn in this window: '+strf(bankrest));
                  {$endif logging}
@@ -953,10 +963,10 @@ end;
                  {$ifdef logging2}
                  LogLn('set bank '+strf(curbank)+' for offset '+hexstr(offs,8));
                  {$endif logging}
-                 If (VLength-1)*bytesperline <= ($10000-(Offs and $ffff)) Then
+                 If (VLength-1)*bytesperline <= ($ffff-(Offs and $ffff)) Then
                    bankrest := VLength
                  else {the rest won't fit anymore in the current window }
-                   bankrest := (($10000 - (Offs and $ffff)) div bytesperline)+1;
+                   bankrest := (($ffff - (Offs and $ffff)) div bytesperline)+1;
                  {$ifdef logging2}
                  LogLn('Rest to be drawn in this window: '+strf(bankrest));
                  {$endif logging}
@@ -981,10 +991,10 @@ end;
                  {$ifdef logging2}
                  LogLn('set bank '+strf(curbank)+' for offset '+hexstr(offs,8));
                  {$endif logging}
-                 If (VLength-1)*bytesperline <= ($10000-(Offs and $ffff)) Then
+                 If (VLength-1)*bytesperline <= ($ffff-(Offs and $ffff)) Then
                    bankrest := VLength
                  else {the rest won't fit anymore in the current window }
-                   bankrest := (($10000 - (Offs and $ffff)) div bytesperline)+1;
+                   bankrest := (($ffff - (Offs and $ffff)) div bytesperline)+1;
                  {$ifdef logging2}
                  LogLn('Rest to be drawn in this window: '+strf(bankrest));
                  {$endif logging}
@@ -1010,10 +1020,10 @@ end;
                  {$ifdef logging2}
                  LogLn('set bank '+strf(curbank)+' for offset '+hexstr(offs,8));
                  {$endif logging}
-                 If (VLength-1)*bytesperline <= ($10000-(Offs and $ffff)) Then
+                 If (VLength-1)*bytesperline <= ($ffff-(Offs and $ffff)) Then
                    bankrest := VLength
                  else {the rest won't fit anymore in the current window }
-                   bankrest := (($10000 - (Offs and $ffff)) div bytesperline)+1;
+                   bankrest := (($ffff - (Offs and $ffff)) div bytesperline)+1;
                  {$ifdef logging2}
                  LogLn('Rest to be drawn in this window: '+strf(bankrest));
                  {$endif logging}
@@ -1495,16 +1505,17 @@ end;
      Y := Y + YOffset; { adjust pixel for correct virtual page }
      { }
      offs := longint(y) * BytesPerLine + (x div 8);
+     SetReadBank(smallint(offs shr 16));
      SetWriteBank(smallint(offs shr 16));
 
      PortW[$3ce] := $0f01;       { Index 01 : Enable ops on all 4 planes }
      PortW[$3ce] := color shl 8; { Index 00 : Enable correct plane and write color }
 
-     Port[$3ce] := 8;           { Index 08 : Bitmask register.          }
-     Port[$3cf] := $80 shr (x and $7); { Select correct bits to modify }
+     { Index 08 : Bitmask register.          }
+     PortW[$3ce] := ($8000 shr (x and $7)) or 8; { Select correct bits to modify }
 
-     dummy := Mem[WinWriteSeg: offs];  { Latch the data into host space.  }
-     Mem[WinWriteSeg: offs] := dummy;  { Write the data into video memory }
+     dummy := Mem[WinReadSeg: word(offs)];  { Latch the data into host space.  }
+     Mem[WinWriteSeg: word(offs)] := dummy;  { Write the data into video memory }
      PortW[$3ce] := $ff08;         { Enable all bit planes.           }
      PortW[$3ce] := $0001;         { Index 01 : Disable ops on all four planes.         }
      { }
@@ -1512,23 +1523,23 @@ end;
 
 
  Function GetPixVESA16(X,Y: smallint):word; {$ifndef fpc}far;{$endif fpc}
- Var dummy, offset: Word;
+ Var dummy: Word;
+     offset: longint;
      shift: byte;
   Begin
     X:= X + StartXViewPort;
     Y:= Y + StartYViewPort + YOffset;
     offset := longint(Y) * BytesPerLine + (x div 8);
     SetReadBank(smallint(offset shr 16));
-    Port[$3ce] := 4;
+    PortW[$3ce] := $0004;
     shift := 7 - (X and 7);
-    Port[$3cf] := 0;
-    dummy := (Mem[WinReadSeg:offset] shr shift) and 1;
+    dummy := (Mem[WinReadSeg:word(offset)] shr shift) and 1;
     Port[$3cf] := 1;
-    dummy := dummy or (((Mem[WinReadSeg:offset] shr shift) and 1) shl 1);
+    dummy := dummy or (((Mem[WinReadSeg:word(offset)] shr shift) and 1) shl 1);
     Port[$3cf] := 2;
-    dummy := dummy or (((Mem[WinReadSeg:offset] shr shift) and 1) shl 2);
+    dummy := dummy or (((Mem[WinReadSeg:word(offset)] shr shift) and 1) shl 2);
     Port[$3cf] := 3;
-    dummy := dummy or (((Mem[WinReadSeg:offset] shr shift) and 1) shl 3);
+    dummy := dummy or (((Mem[WinReadSeg:word(offset)] shr shift) and 1) shl 3);
     GetPixVESA16 := dummy;
   end;
 
@@ -1539,48 +1550,181 @@ end;
      dummy : byte;
      Color : word;
   begin
-    y:= Y + YOffset;
-    case CurrentWriteMode of
-      XORPut:
-        begin
-      { getpixel wants local/relative coordinates }
-          Color := GetPixVESA16(x-StartXViewPort,y-StartYViewPort);
-          Color := CurrentColor Xor Color;
-        end;
-      OrPut:
-        begin
-      { getpixel wants local/relative coordinates }
-          Color := GetPixVESA16(x-StartXViewPort,y-StartYViewPort);
-          Color := CurrentColor Or Color;
-        end;
-      AndPut:
-        begin
-      { getpixel wants local/relative coordinates }
-          Color := GetPixVESA16(x-StartXViewPort,y-StartYViewPort);
-          Color := CurrentColor And Color;
-        end;
-      NotPut:
-        begin
-          Color := Not Color;
-        end
-      else
-        Color := CurrentColor;
-    end;
+     If CurrentWriteMode <> NotPut Then
+       Color := CurrentColor
+     else Color := not CurrentColor;
+
+     case CurrentWriteMode of
+        XORPut:
+          PortW[$3ce]:=((3 shl 3) shl 8) or 3;
+        ANDPut:
+          PortW[$3ce]:=((1 shl 3) shl 8) or 3;
+        ORPut:
+          PortW[$3ce]:=((2 shl 3) shl 8) or 3;
+        {not needed, this is the default state (e.g. PutPixel16 requires it)}
+        {NormalPut, NotPut:
+          PortW[$3ce]:=$0003
+        else
+          PortW[$3ce]:=$0003}
+     end;
+
+     Y := Y + YOffset;
      offs := longint(y) * BytesPerLine + (x div 8);
+     SetReadBank(smallint(offs shr 16));
      SetWriteBank(smallint(offs shr 16));
      PortW[$3ce] := $0f01;       { Index 01 : Enable ops on all 4 planes }
      PortW[$3ce] := color shl 8; { Index 00 : Enable correct plane and write color }
 
-     Port[$3ce] := 8;           { Index 08 : Bitmask register.          }
-     Port[$3cf] := $80 shr (x and $7); { Select correct bits to modify }
+     { Index 08 : Bitmask register.          }
+     PortW[$3ce] := ($8000 shr (x and $7)) or 8; { Select correct bits to modify }
 
-     dummy := Mem[WinWriteSeg: offs];  { Latch the data into host space.  }
-     Mem[WinWriteSeg: offs] := dummy;  { Write the data into video memory }
+     dummy := Mem[WinReadSeg: word(offs)];  { Latch the data into host space.  }
+     Mem[WinWriteSeg: word(offs)] := dummy;  { Write the data into video memory }
      PortW[$3ce] := $ff08;         { Enable all bit planes.           }
      PortW[$3ce] := $0001;         { Index 01 : Disable ops on all four planes.         }
+     if (CurrentWriteMode = XORPut) or
+        (CurrentWriteMode = ANDPut) or
+        (CurrentWriteMode = ORPut) then
+       PortW[$3ce] := $0003;
   end;
 
 
+  procedure HLineVESA16(x,x2,y: smallint); {$ifndef fpc}far;{$endif fpc}
+  var
+      xtmp: smallint;
+      ScrOfs, BankRest: longint;
+      HLength : word;
+      LMask,RMask : byte;
+  begin
+
+    { must we swap the values? }
+    if x > x2 then
+      Begin
+        xtmp := x2;
+        x2 := x;
+        x:= xtmp;
+      end;
+    { First convert to global coordinates }
+    X   := X + StartXViewPort;
+    X2  := X2 + StartXViewPort;
+    Y   := Y + StartYViewPort;
+    if ClipPixels then
+      Begin
+         if LineClipped(x,y,x2,y,StartXViewPort,StartYViewPort,
+                StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
+            exit;
+      end;
+    Y := Y + YOffset;
+    ScrOfs := longint(y) * BytesPerLine + (x div 8);
+    SetReadBank(smallint(ScrOfs shr 16));
+    SetWriteBank(smallint(ScrOfs shr 16));
+    HLength:=x2 div 8-x div 8;
+    LMask:=$ff shr (x and 7);
+{$ifopt r+}
+{$define rangeOn}
+{$r-}
+{$endif}
+{$ifopt q+}
+{$define overflowOn}
+{$q-}
+{$endif}
+    RMask:=$ff shl (7-(x2 and 7));
+{$ifdef rangeOn}
+{$undef rangeOn}
+{$r+}
+{$endif}
+{$ifdef overflowOn}
+{$undef overflowOn}
+{$q+}
+{$endif}
+    if HLength=0 then
+      LMask:=LMask and RMask;
+    If CurrentWriteMode <> NotPut Then
+      PortW[$3ce]:= CurrentColor shl 8
+    else PortW[$3ce]:= (not CurrentColor) shl 8;
+    PortW[$3ce]:=$0f01;
+    case CurrentWriteMode of
+       XORPut:
+         PortW[$3ce]:=((3 shl 3) shl 8) or 3;
+       ANDPut:
+         PortW[$3ce]:=((1 shl 3) shl 8) or 3;
+       ORPut:
+         PortW[$3ce]:=((2 shl 3) shl 8) or 3;
+       NormalPut, NotPut:
+         PortW[$3ce]:=$0003
+       else
+         PortW[$3ce]:=$0003
+    end;
+
+    PortW[$3ce]:=(LMask shl 8) or 8;
+{$ifopt r+}
+{$define rangeOn}
+{$r-}
+{$endif}
+{$ifopt q+}
+{$define overflowOn}
+{$q-}
+{$endif}
+    Mem[WinWriteSeg:word(ScrOfs)]:=Mem[WinReadSeg:word(ScrOfs)]+1;
+{$ifdef rangeOn}
+{$undef rangeOn}
+{$r+}
+{$endif}
+{$ifdef overflowOn}
+{$undef overflowOn}
+{$q+}
+{$endif}
+    {Port[$3ce]:=8;}{not needed, the register is already selected}
+    if HLength>0 then
+      begin
+         dec(HLength);
+         inc(ScrOfs);
+         while (HLength>0) do
+           begin
+              SetReadBank(smallint(ScrOfs shr 16));
+              SetWriteBank(smallint(ScrOfs shr 16));
+              Port[$3cf]:=$ff;
+              if HLength <= ($10000-(ScrOfs and $ffff)) Then
+                 BankRest := HLength
+              else {the rest won't fit anymore in the current window }
+                BankRest := $10000 - (ScrOfs and $ffff);
+{$ifndef tp}
+              seg_bytemove(dosmemselector,(WinReadSeg shl 4)+word(ScrOfs),dosmemselector,(WinWriteSeg shl 4)+word(ScrOfs),BankRest);
+{$else}
+              move(Ptr(WinReadSeg,word(ScrOfs))^, Ptr(WinWriteSeg,word(ScrOfs))^, BankRest);
+{$endif}
+              ScrOfs := ScrOfs + BankRest;
+              HLength := HLength - BankRest;
+           end;
+         SetReadBank(smallint(ScrOfs shr 16));
+         SetWriteBank(smallint(ScrOfs shr 16));
+         Port[$3cf]:=RMask;
+{$ifopt r+}
+{$define rangeOn}
+{$r-}
+{$endif}
+{$ifopt q+}
+{$define overflowOn}
+{$q-}
+{$endif}
+         Mem[WinWriteSeg:word(ScrOfs)]:=Mem[WinReadSeg:word(ScrOfs)]+1;
+{$ifdef rangeOn}
+{$undef rangeOn}
+{$r+}
+{$endif}
+{$ifdef overflowOn}
+{$undef overflowOn}
+{$q+}
+{$endif}
+      end;
+    { clean up }
+    {Port[$3cf]:=0;}{not needed, the register is reset by the next operation:}
+    PortW[$3ce]:=$ff08;
+    PortW[$3ce]:=$0001;
+    PortW[$3ce]:=$0003;
+   end;
+
+
 
 
  {************************************************************************}
@@ -1976,6 +2120,12 @@ Const
   function SetupLinear(var ModeInfo: TVESAModeInfo;mode : word) : boolean;
    begin
      SetUpLinear:=false;
+
+     if VESAInfo.Version >= $0300 then
+       BytesPerLine := VESAModeInfo.LinBytesPerScanLine
+     else
+       BytesPerLine := VESAModeInfo.BytesPerScanLine;
+
 {$ifdef FPC}
      case mode of
        m320x200x32k,
@@ -2073,6 +2223,9 @@ Const
   procedure SetupWindows(var ModeInfo: TVESAModeInfo);
    begin
      InLinear:=false;
+
+     BytesPerLine := VESAModeInfo.BytesPerScanLine;
+
      { now we check the windowing scheme ...}
      if (ModeInfo.WinAAttr and WinSupported) <> 0 then
        { is this window supported ... }
@@ -2222,7 +2375,8 @@ Const
         Inc(BankShift);
      CurrentWriteBank := -1;
      CurrentReadBank := -1;
-     BytesPerLine := VESAModeInfo.BytesPerScanLine;
+{    nickysn: setting BytesPerLine moved to SetupLinear and SetupWindowed
+     BytesPerLine := VESAModeInfo.BytesPerScanLine;}
 
      { These are the window adresses ... }
      WinWriteSeg := 0;  { This is the segment to use for writes }

+ 16 - 1
packages/graph/src/go32v2/vesah.inc

@@ -31,6 +31,7 @@ TYPE
   end;                             { VESA standard because of bugs on }
                                    { some video cards.                }
   *)
+  { VESA 1.1 }
     TotalMem     : word;
   { VESA 2.0 }
     OEMversion   : word;
@@ -82,7 +83,21 @@ TYPE
     PhysAddress    : longint; { pos $28 }
     OffscreenPtr   : longint; { pos $2C }
     OffscreenMem   : word; { pos $30 }
-    reserved2      : Array[1..458]of Byte; { pos $32 }
+  { VESA 3.0 }
+    LinBytesPerScanLine: Word;   {bytes per scan line for linear modes}
+    BnkNumberOfImagePages: Byte; {number of images for banked modes}
+    LinNumberOfImagePages: Byte; {number of images for linear modes}
+    LinRedMaskSize: Byte;        {size of direct color red mask (linear modes)}
+    LinRedFieldPosition: Byte;   {bit position of lsb of red mask (linear modes)}
+    LinGreenMaskSize: Byte;      {size of direct color green mask (linear modes)}
+    LinGreenFieldPosition: Byte; {bit position of lsb of green mask (linear modes)}
+    LinBlueMaskSize: Byte;       {size of direct color blue mask (linear modes)}
+    LinBlueFieldPosition: Byte;  {bit position of lsb of blue mask (linear modes)}
+    LinRsvdMaskSize: Byte;       {size of direct color reserved mask (linear modes)}
+    LinRsvdFieldPosition: Byte;  {bit position of lsb of reserved mask (linear modes)}
+    MaxPixelClock: longint;      {maximum pixel clock (in Hz) for graphics mode}
+
+    reserved2: array [1..189] of Byte; {remainder of ModeInfoBlock}
    end;
 
 

+ 57 - 2
packages/graph/src/inc/fills.inc

@@ -57,6 +57,8 @@ var
 
   ptable : ^pointtype;
 
+  LastPolygonStart : Longint;
+  Closing, PrevClosing : Boolean;
 
 begin
 { /********************************************************************
@@ -74,12 +76,34 @@ begin
  { check for getmem success }
 
   nEdges := 0;
+  LastPolygonStart := 0;
+  Closing := false;
   for i := 0 to (numpoints-1) do begin
     p0 := ptable[i];
     if (i+1) >= numpoints then p1 := ptable[0]
     else p1 := ptable[i+1];
+    { save the 'closing' flag for the previous edge }
+    PrevClosing := Closing;
+    { check if the current edge is 'closing'. This means that it 'closes'
+      the polygon by going back to the first point of the polygon.
+      Also, 0-length edges are never considered 'closing'. }
+    if ((p1.x <> ptable[i].x) or
+        (p1.y <> ptable[i].y)) and
+        (LastPolygonStart < i) and
+       ((p1.x = ptable[LastPolygonStart].x) and
+        (p1.y = ptable[LastPolygonStart].y)) then
+    begin
+      Closing := true;
+      LastPolygonStart := i + 2;
+    end
+    else
+      Closing := false;
+    { skip current edge if the previous edge was 'closing'. This is TP7 compatible }
+    if PrevClosing then
+      continue;
    { draw the edges }
-    Line(p0.x,p0.y,p1.x,p1.y);
+{    nickysn: moved after drawing the filled area
+    Line(p0.x,p0.y,p1.x,p1.y);}
    { ignore if this is a horizontal edge}
     if (p0.y = p1.y) then continue;
    { swap ptable if necessary to ensure p0 contains yMin}
@@ -167,7 +191,7 @@ begin
     { Fill in desired pixels values on scan line y by using pairs of x
     coordinates from the AET }
     i := 0;
-    while (i < nActive) do begin
+    while (i < (nActive - 1)) do begin
       x0 := AET^[i]^.x;
       x1 := AET^[i+1]^.x;
       {Left edge adjustment for positive fraction.  0 is interior. }
@@ -209,6 +233,37 @@ begin
     inc(y);
     if (y >= ViewHeight) then break;
   end;
+
+  { finally, draw the edges }
+  LastPolygonStart := 0;
+  Closing := false;
+  for i := 0 to (numpoints-1) do begin
+    p0 := ptable[i];
+    if (i+1) >= numpoints then p1 := ptable[0]
+    else p1 := ptable[i+1];
+    { save the 'closing' flag for the previous edge }
+    PrevClosing := Closing;
+    { check if the current edge is 'closing'. This means that it 'closes'
+      the polygon by going back to the first point of the polygon.
+      Also, 0-length edges are never considered 'closing'. }
+    if ((p1.x <> p0.x) or
+        (p1.y <> p0.y)) and
+        (LastPolygonStart < i) and
+       ((p1.x = ptable[LastPolygonStart].x) and
+        (p1.y = ptable[LastPolygonStart].y)) then
+    begin
+      Closing := true;
+      LastPolygonStart := i + 2;
+    end
+    else
+      Closing := false;
+    { skip edge if the previous edge was 'closing'. This is TP7 compatible }
+    if PrevClosing then
+      continue;
+   { draw the edges }
+    Line(p0.x,p0.y,p1.x,p1.y);
+  end;
+
   System.freemem(et, sizeof(tedge) * numpoints);
   System.freemem(get, sizeof(pedge) * numpoints);
   System.freemem(aet, sizeof(pedge) * numpoints);

+ 73 - 13
packages/graph/src/inc/graph.inc

@@ -896,8 +896,21 @@ var
 
 
   procedure Rectangle(x1,y1,x2,y2:smallint);
-
+   var
+     tmp: smallint;
    begin
+     if x1 > x2 then
+     begin
+       tmp := x1;
+       x1 := x2;
+       x2 := tmp;
+     end;
+     if y1 > y2 then
+     begin
+       tmp := y1;
+       y1 := y2;
+       y2 := tmp;
+     end;
      { Do not draw the end points }
      Line(x1,y1,x2-1,y1);
      Line(x1,y1+1,x1,y2);
@@ -1241,6 +1254,8 @@ end;
 
   procedure OutTextXYDefault(x,y : smallint;const TextString : string);forward;
   procedure CircleDefault(X, Y: smallint; Radius:Word);forward;
+  procedure SetBkColorDefault(ColorNum: Word);forward;
+  function GetBkColorDefault: Word;forward;
 
 {$i palette.inc}
 
@@ -1279,6 +1294,8 @@ end;
     VLine := {$ifdef fpc}@{$endif}VLineDefault;
     OuttextXY := {$ifdef fpc}@{$endif}OuttextXYDefault;
     Circle := {$ifdef fpc}@{$endif}CircleDefault;
+    SetBkColor := {$ifdef fpc}@{$endif}SetBkColorDefault;
+    GetBkColor := {$ifdef fpc}@{$endif}GetBkColorDefault;
   end;
 
   Procedure InitVars;
@@ -1343,7 +1360,7 @@ end;
 {     OldWriteMode := CurrentWriteMode;
      if (LineInfo.Thickness = NormWidth) then
        CurrentWriteMode := NormalPut;}
-     InternalEllipse(X,Y,Radius,Radius,StAngle,Endangle,{$ifdef fpc}@{$endif}DummyPatternLine);
+     InternalEllipse(X,Y,Radius,(longint(Radius)*XAspect) div YAspect,StAngle,Endangle,{$ifdef fpc}@{$endif}DummyPatternLine);
 {     CurrentWriteMode := OldWriteMode;}
    end;
 
@@ -1561,6 +1578,12 @@ end;
           y1:=y2;
           y2:=y;
        end;
+     if x1>x2 then
+       begin
+          y:=x1;
+          x1:=x2;
+          x2:=y;
+       end;
 
      { Always copy mode for Bars }
      origwritemode := CurrentWriteMode;
@@ -1603,6 +1626,19 @@ var
  origwritemode : smallint;
  OldX, OldY : smallint;
 begin
+  if x1 > x2 then
+  begin
+    OldX := x1;
+    x1 := x2;
+    x2 := OldX;
+  end;
+  if y1 > y2 then
+  begin
+    OldY := y1;
+    y1 := y2;
+    y2 := OldY;
+  end;
+
   origwritemode := CurrentWriteMode;
   CurrentWriteMode := CopyPut;
   Bar(x1,y1,x2,y2);
@@ -1654,14 +1690,14 @@ end;
      GetColor := CurrentColor;
    end;
 
-  function GetBkColor: Word;
+  function GetBkColorDefault: Word;
 
    Begin
-     GetBkColor := CurrentBkColor;
+     GetBkColorDefault := CurrentBkColor;
    end;
 
 
-  procedure SetBkColor(ColorNum: Word);
+  procedure SetBkColorDefault(ColorNum: Word);
   { Background color means background screen color in this case, and it is  }
   { INDEPENDANT of the viewport settings, so we must clear the whole screen }
   { with the color.                                                         }
@@ -1829,7 +1865,8 @@ end;
      CurrentTextInfo.horiz:=LeftText;
      CurrentTextInfo.vert:=TopText;
 
-     XAspect:=10000; YAspect:=10000;
+     {fix by nickysn: TP7 doesn't reset aspect ratio in GraphDefaults }
+     {XAspect:=10000; YAspect:=10000;}
    end;
 
 
@@ -1871,24 +1908,47 @@ end;
       ppointtype = ^pointtype;
       pt = array[0..16000] of pointtype;
     var
-      i : longint;
+      i, j, LastPolygonStart: longint;
+      Closing: boolean;
     begin
       if numpoints < 2 then
         begin
-          _GraphResult := grError;
+          { nickysn: TP7 doesn't return error here }
+          {_GraphResult := grError;}
           exit;
         end;
+      Closing := false;
+      LastPolygonStart := 0;
       for i:=0 to numpoints-2 do
-        line(pt(polypoints)[i].x,
-             pt(polypoints)[i].y,
-             pt(polypoints)[i+1].x,
-             pt(polypoints)[i+1].y);
+      begin
+        { skip an edge after each 'closing' edge }
+        if not Closing then
+          line(pt(polypoints)[i].x,
+               pt(polypoints)[i].y,
+               pt(polypoints)[i+1].x,
+               pt(polypoints)[i+1].y);
+
+        { check if the current edge is 'closing'. This means that it 'closes'
+          the polygon by going back to the first point of the polygon.
+          Also, 0-length edges are never considered 'closing'. }
+        if ((pt(polypoints)[i+1].x <> pt(polypoints)[i].x) or
+            (pt(polypoints)[i+1].y <> pt(polypoints)[i].y)) and
+            (LastPolygonStart < i) and
+           ((pt(polypoints)[i+1].x = pt(polypoints)[LastPolygonStart].x) and
+            (pt(polypoints)[i+1].y = pt(polypoints)[LastPolygonStart].y)) then
+        begin
+          Closing := true;
+          LastPolygonStart := i + 2;
+        end
+        else
+          Closing := false;
+      end;
     end;
 
 
   procedure PieSlice(X,Y,stangle,endAngle:smallint;Radius: Word);
   begin
-    Sector(x,y,stangle,endangle,radius,radius);
+    Sector(x,y,stangle,endangle,radius,(longint(Radius)*XAspect) div YAspect);
   end;
 
 {$i fills.inc}

+ 39 - 3
packages/graph/src/inc/graphh.inc

@@ -321,7 +321,12 @@ type
        { graphic drivers }
        CurrentDriver = -128;
        Detect        = 0;
-       LowRes        = 1;
+       CGA           = 1;
+       MCGA          = 2;
+       EGA           = 3;
+       EGA64         = 4;
+       EGAMono       = 5;
+       LowRes        = 6; { nickysn: used to be 1, but moved to 6, because I added CGA }
        HercMono      = 7;
        VGA           = 9;
        VESA          = 10;
@@ -346,6 +351,32 @@ type
        { graph modes }
        Default = 0;
 
+       { CGA Driver modes }
+       CGAC0 = 0;
+       CGAC1 = 1;
+       CGAC2 = 2;
+       CGAC3 = 3;
+       CGAHi = 4;
+
+       { MCGA Driver modes }
+       MCGAC0 = 0;
+       MCGAC1 = 1;
+       MCGAC2 = 2;
+       MCGAC3 = 3;
+       MCGAMed = 4;
+       MCGAHi = 5;
+
+       { EGA Driver modes }
+       EGALo      = 0;  { 640x200 16 color 4 page }
+       EGAHi      = 1;  { 640x350 16 color 2 page }
+
+       { EGA64 Driver modes }
+       EGA64Lo    = 0;  { 640x200 16 color 1 page }
+       EGA64Hi    = 1;  { 640x350 4 color  1 page }
+
+       { EGAMono Driver modes }
+       EGAMonoHi  = 3;  { 640x350 64K on card, 1 page; 256K on card, 2 page }
+
        { VGA Driver modes }
        VGALo   = 0;
        VGAMed  = 1;
@@ -558,6 +589,9 @@ TYPE
 
        CircleProc = procedure(X, Y: smallint; Radius:Word);
 
+       SetBkColorProc = procedure(ColorNum: Word);
+       GetBkColorProc = function: Word;
+
 
 TYPE
     {-----------------------------------}
@@ -608,6 +642,8 @@ TYPE
       Circle         : CircleProc;
       InitMode       : InitModeProc;
       OutTextXY : OutTextXYProc;
+      SetBKColor     : SetBkColorProc;
+      GetBKColor     : GetBkColorProc;
       next: PModeInfo;
     end;
 
@@ -634,6 +670,8 @@ VAR
   GetRGBPalette  : GetRGBPaletteProc;
   SetAllPalette  : SetAllPaletteProc;
   OutTextXY      : OutTextXYProc;
+  SetBkColor     : SetBkColorProc;
+  GetBkColor     : GetBkColorProc;
 
   GraphFreeMemPtr: graphfreememprc;
   GraphGetMemPtr : graphgetmemprc;
@@ -738,9 +776,7 @@ Function GetDriverName: string;
  function GetDirectVideo: boolean;
 
  { -------------------- Color/Palette ------------------------------- }
- procedure SetBkColor(ColorNum: Word);
  function  GetColor: Word;
- function  GetBkColor: Word;
  procedure SetColor(Color: Word);
  function  GetMaxColor: word;
 

+ 14 - 2
packages/graph/src/inc/modes.inc

@@ -316,7 +316,10 @@ end;
       mode:=nil;
       GetModeName:='';
       { only search in the current driver modes ... }
-      mode:=SearchMode(IntCurrentNewDriver,ModeNumber);
+      if (ModeNumber >= lowNewMode) and (ModeNumber <= highNewMode) then
+          mode:=SearchMode(IntCurrentNewDriver,ModeNumber)
+      else
+          mode:=SearchMode(IntCurrentDriver,ModeNumber);
       if assigned(mode) then
           GetModeName:=Mode^.ModeName
       else
@@ -392,6 +395,7 @@ end;
     var
      modeinfo: PModeInfo;
      usedDriver: Integer;
+     dummyNewModeNr: smallint;
     begin
       { check if the mode exists... }
       { Depending on the modenumber, we search using the old or new }
@@ -520,9 +524,17 @@ end;
          SetActivePage := modeInfo^.SetActivePage;
       if assigned(modeInfo^.OutTextXY) then
          OutTextXY:=modeInfo^.OutTextXY;
+      if assigned(modeInfo^.SetBkColor) then
+         SetBkColor:=modeInfo^.SetBkColor;
+      if assigned(modeInfo^.GetBkColor) then
+         GetBkColor:=modeInfo^.GetBkColor;
 
       IntCurrentMode := modeinfo^.ModeNumber;
-      IntCurrentDriver := usedDriver;
+      { fix by nickysn: always set *both* IntCurrentDriver and IntCurrentNewDriver to the
+        *correct* old & new style driver numbers. Solves a lot of bugs, e.g. when using InitGraph
+	with a new style driver/mode and then later using SetGraphMode(GetGraphMode) }
+      IntCurrentDriver := modeinfo^.DriverNumber;
+      res2Mode(modeinfo^.maxx+1, modeinfo^.maxy+1, modeinfo^.maxColor, IntCurrentNewDriver, dummyNewModeNr);
 {$ifdef logging}
        logln('Entering mode '+strf(intCurrentMode)+' of driver '+strf(intCurrentDriver));
 {$endif logging}

+ 21 - 21
packages/graph/src/sdlgraph/sdlgraph.pp

@@ -64,11 +64,11 @@ It's highly recommended to use Detect (0 constant) for grDriver and grmode: init
 }
 
  //Detect      =0;     is in the graphh.inc
- CGA           =1;
- MCGA	       =2;
- EGA           =3;
- EGA64         =4;
- EGAMono       =5;
+ //CGA           =1;   is in graphh.inc
+ //MCGA	       =2;   is in graphh.inc
+ //EGA           =3;   is in graphh.inc
+ //EGA64         =4;   is in graphh.inc
+ //EGAMono       =5;   is in graphh.inc
  IBM8514       =6;
  //HercMono      =7;   is in the graphh.inc
  ATT400        =8;
@@ -76,29 +76,29 @@ It's highly recommended to use Detect (0 constant) for grDriver and grmode: init
  PC3270        =10;
 
 {Graphics Modes for Each Driver}
- CGAC0         =0;
- CGAC          =1;
- CGAC2         =2;
- CGAC3         =3;
- CGAHi         =4;
+ //CGAC0         =0;   is in graphh.inc
+ //CGAC          =1;   is in graphh.inc
+ //CGAC2         =2;   is in graphh.inc
+ //CGAC3         =3;   is in graphh.inc
+ //CGAHi         =4;   is in graphh.inc
  
- MCGAC0        =0;
- MCGAC         =1;
- MCGAC2        =2;
- MCGAC3        =3;
- MCGAMed       =4;
- MCGAHi        =5;
+ //MCGAC0        =0;   is in graphh.inc
+ //MCGAC         =1;   is in graphh.inc
+ //MCGAC2        =2;   is in graphh.inc
+ //MCGAC3        =3;   is in graphh.inc
+ //MCGAMed       =4;   is in graphh.inc
+ //MCGAHi        =5;   is in graphh.inc
  
- EGAMonoHi     =3;
+ //EGAMonoHi     =3;   is in graphh.inc
  //HercMonoHi    =0;      is in the graphh.inc
  //VGALo         =0;      is in the graphh.inc
  //VGAMed        =1;      is in the graphh.inc
  //VGAHi         =2;      is in the graphh.inc
  
- EGALo         =0;
- EGAHi         =1;
- EGA64Lo       =0;
- EGA64Hi       =1;
+ //EGALo         =0;   is in graphh.inc
+ //EGAHi         =1;   is in graphh.inc
+ //EGA64Lo       =0;   is in graphh.inc
+ //EGA64Hi       =1;   is in graphh.inc
  
  ATT400C0      =0;
  ATT400C1      =1;

+ 207 - 0
packages/graph/tests/drawtest.pas

@@ -0,0 +1,207 @@
+{
+  Test for the basic graph operations - PutPixel, GetPixel and HLine/VLine
+  drawing with different colours and write modes
+
+  Test draws random pixels and H/V lines with the graph unit and performs the
+  same operations in memory. Finally it reads the whole resulting image, pixel
+  by pixel, via GetPixel and compares the result with the expected value from
+  the PixArray
+
+  Useful for testing the platform-specific parts of the FPC graph unit (in
+  various modes and operating systems)
+
+  This test works also with TP7
+}
+
+program DrawTest;
+
+uses
+  Graph;
+
+type
+  TTestParams = record
+    Driver: Integer;
+    Mode: Integer;
+    NumberOfObjectsToDraw: Integer;
+    ProbabilityPixel: Integer;
+    ProbabilityHLine: Integer;
+    ProbabilityVLine: Integer;
+  end;
+
+  TPixelColor = Word;
+  PRow = ^TRow;
+  TRow = array [0..1279] of TPixelColor;
+
+var
+  XRes, YRes: Integer;
+  PixArray: array [0..1023] of PRow;
+
+procedure InitPixArray(AXRes, AYRes: Integer);
+var
+  Y: Integer;
+begin
+  XRes := AXRes;
+  YRes := AYRes;
+  for Y := 0 to AYRes - 1 do
+  begin
+    GetMem(PixArray[Y], AXRes * SizeOf(TPixelColor));
+    FillChar(PixArray[Y]^, AXRes * SizeOf(TPixelColor), 0);
+  end;
+end;
+
+procedure FreePixArray;
+var
+  Y: Integer;
+begin
+  for Y := 0 to YRes - 1 do
+    FreeMem(PixArray[Y], XRes * SizeOf(TPixelColor));
+end;
+
+procedure TestFinalResult;
+var
+  X, Y: Integer;
+begin
+  for Y := 0 to YRes - 1 do
+    for X := 0 to XRes - 1 do
+      if GetPixel(X, Y) <> PixArray[Y]^[X] then
+      begin
+        CloseGraph;
+        Writeln('Error at X = ', X, ', Y = ', Y);
+        Halt(1);
+      end;
+end;
+
+procedure TestPutPixel(X, Y: Integer; Color: TPixelColor);
+begin
+  PutPixel(X, Y, Color);
+
+  PixArray[Y]^[X] := Color;
+end;
+
+procedure DirectPutPixel(X, Y: Integer; Color: TPixelColor; WriteMode: Integer);
+begin
+  case WriteMode of
+    NormalPut, OrPut, NotPut: PixArray[Y]^[X] := Color;
+    XORPut, AndPut: PixArray[Y]^[X] := PixArray[Y]^[X] xor Color;
+
+    { TODO: add some sort of SetWriteModeExtended to the FPC graph unit, so
+      we can test these as well: }
+{    OrPut: PixArray[Y]^[X] := PixArray[Y]^[X] or Color;}
+{    AndPut: PixArray[Y]^[X] := PixArray[Y]^[X] and Color;}
+{    NotPut: PixArray[Y]^[X] := Color xor GetMaxColor;}
+  end;
+end;
+
+procedure TestHLine(Y, X1, X2: Integer; Color: TPixelColor; WriteMode: Integer);
+var
+  tmp, X: Integer;
+begin
+  SetWriteMode(WriteMode);
+  SetColor(Color);
+  Line(X1, Y, X2, Y);
+
+  if X1 > X2 then
+  begin
+    tmp := X1;
+    X1 := X2;
+    X2 := tmp;
+  end;
+
+  for X := X1 to X2 do
+  begin
+    DirectPutPixel(X, Y, Color, WriteMode);
+  end;
+
+  SetWriteMode(NormalPut);
+end;
+
+procedure TestVLine(X, Y1, Y2: Integer; Color: TPixelColor; WriteMode: Integer);
+var
+  tmp, Y: Integer;
+begin
+  SetWriteMode(WriteMode);
+  SetColor(Color);
+  Line(X, Y1, X, Y2);
+
+  if Y1 > Y2 then
+  begin
+    tmp := Y1;
+    Y1 := Y2;
+    Y2 := tmp;
+  end;
+
+  for Y := Y1 to Y2 do
+  begin
+    DirectPutPixel(X, Y, Color, WriteMode);
+  end;
+
+  SetWriteMode(NormalPut);
+end;
+
+procedure TestDraw(const TestParams: TTestParams);
+var
+  I: Integer;
+  R: Integer;
+begin
+  for I := 1 to TestParams.NumberOfObjectsToDraw do
+  begin
+    R := Random(TestParams.ProbabilityPixel + TestParams.ProbabilityHLine + TestParams.ProbabilityVLine);
+    if R < TestParams.ProbabilityPixel then
+      TestPutPixel(Random(XRes), Random(YRes), Random(GetMaxColor + 1))
+    else
+      if (R >= TestParams.ProbabilityPixel) and (R < TestParams.ProbabilityPixel + TestParams.ProbabilityHLine) then
+        TestHLine(Random(YRes), Random(XRes), Random(XRes), Random(GetMaxColor + 1), Random(NotPut + 1))
+      else
+        TestVLine(Random(XRes), Random(YRes), Random(YRes), Random(GetMaxColor + 1), Random(NotPut + 1));
+  end;
+end;
+
+procedure PerformTest(const TestParams: TTestParams);
+var
+  GraphDriver, GraphMode: Integer;
+begin
+  GraphDriver := TestParams.Driver;
+  GraphMode := TestParams.Mode;
+  InitGraph(GraphDriver, GraphMode, 'C:\TP\BGI');
+
+  InitPixArray(GetMaxX + 1, GetMaxY + 1);
+
+  TestDraw(TestParams);
+
+  TestFinalResult;
+
+  FreePixArray;
+
+  CloseGraph;
+  Writeln('Ok');
+end;
+
+var
+  TestsCount: Integer;
+  TestParams: TTestParams;
+  Code: Integer;
+  I: Integer;
+begin
+  if ParamCount <> 3 then
+  begin
+    Writeln('Usage: ', ParamStr(0), ' <driver number> <mode number> <tests count>');
+    Writeln;
+    Writeln('For example: ', ParamStr(0), ' 9 2 20');
+    Writeln('performs 20 tests in 640x480x16 VGA mode (VGA = 9, VGAHi = 2)');
+    Halt;
+  end;
+  Val(ParamStr(1), TestParams.Driver, Code);
+  Val(ParamStr(2), TestParams.Mode, Code);
+  Val(ParamStr(3), TestsCount, Code);
+
+  Randomize;
+
+  for I := 1 to TestsCount do
+  begin
+    TestParams.NumberOfObjectsToDraw := Random(30000);
+    TestParams.ProbabilityPixel := Random(10);
+    TestParams.ProbabilityHLine := Random(2);
+    TestParams.ProbabilityVLine := Random(2);
+    PerformTest(TestParams);
+  end;
+end.

+ 83 - 0
packages/graph/tests/polytest.pas

@@ -0,0 +1,83 @@
+{
+ test for graph unit's DrawPoly and FillPoly procedures
+ compiles with Turbo Pascal 7 and Free Pascal
+ used for TP7 compatibily testing
+}
+
+program PolyTest;
+
+uses
+  graph;
+
+const
+  MaxPoints = 1000;
+
+var
+  InF: Text;
+  NumPoints: Integer;
+  Poly: array [1..MaxPoints] of PointType;
+
+procedure ReadPoly;
+var
+  I: Integer;
+begin
+  Readln(InF, NumPoints);
+  for I := 1 to NumPoints do
+    Readln(InF, Poly[I].X, Poly[I].Y);
+end;
+
+procedure CheckGraphResult;
+var
+  ErrorCode: Integer;
+begin
+  ErrorCode := GraphResult;
+  if ErrorCode <> grOk then
+  begin
+    CloseGraph;
+    Writeln(ErrorCode, ': ', GraphErrorMsg(ErrorCode));
+    Readln;
+    Halt(1);
+  end;
+end;
+
+procedure Tralala;
+var
+  I: Integer;
+  IStr: string;
+begin
+  if ParamStr(1) <> '' then
+    Assign(InF, ParamStr(1))
+  else
+    Assign(InF, 'polytest.txt');
+  Reset(InF);
+  I := 1;
+  while not Eof(InF) do
+  begin
+    ReadPoly;
+    ClearDevice;
+    Str(I, IStr);
+    OutTextXY(0, 0, IStr);
+    DrawPoly(NumPoints, Poly);
+    CheckGraphResult;
+    Readln;
+
+    ClearDevice;
+    OutTextXY(0, 0, IStr + ' fill');
+    FillPoly(NumPoints, Poly);
+    CheckGraphResult;
+    Readln;
+    Inc(I);
+  end;
+  Close(InF);
+end;
+
+var
+  GraphDriver, GraphMode: Integer;
+begin
+  GraphDriver := VGA;
+  GraphMode := VGAHi;
+  InitGraph(GraphDriver, GraphMode, '');
+  SetFillStyle(SolidFill, 9);
+  Tralala;
+  CloseGraph;
+end.

+ 89 - 0
packages/graph/tests/polytest.txt

@@ -0,0 +1,89 @@
+0
+1
+320 240
+2
+310 240
+330 240
+2
+320 230
+320 250
+4
+325 250
+320 240
+330 240
+325 250
+5
+325 250
+320 240
+330 240
+325 250
+330 260
+5
+325 250
+320 240
+330 240
+326 250
+330 260
+6
+325 250
+320 240
+330 240
+325 250
+330 260
+320 260
+7
+325 250
+320 240
+330 240
+325 250
+330 260
+320 260
+325 250
+8
+325 250
+320 240
+330 240
+325 250
+325 250
+330 260
+320 260
+325 250
+9
+325 250
+320 240
+330 240
+325 250
+325 250
+325 250
+330 260
+320 260
+325 250
+12
+300 200
+310 200
+300 210
+300 200
+350 250
+360 250
+350 260
+350 250
+355 200
+370 210
+360 250
+370 250
+6
+300 250
+325 250
+320 240
+330 240
+325 250
+330 260
+3
+320 200
+320 200
+330 200
+4
+320 200
+320 200
+320 200
+330 200

+ 680 - 0
packages/graph/tests/polytst2.txt

@@ -0,0 +1,680 @@
+679
+351 284
+457 405
+385 411
+348 406
+271 299
+413 184
+280 142
+570 27
+616 130
+245 229
+506 389
+338 230
+363 188
+592 401
+45 161
+55 311
+12 176
+532 459
+498 67
+556 417
+626 227
+511 384
+295 249
+499 325
+75 345
+409 279
+91 257
+604 364
+333 50
+265 227
+169 89
+495 353
+291 103
+363 64
+12 155
+395 71
+391 106
+394 185
+603 433
+436 215
+230 294
+279 433
+446 47
+38 465
+426 313
+429 82
+134 171
+82 360
+201 291
+232 156
+364 18
+280 304
+632 460
+65 313
+133 304
+103 477
+417 279
+162 198
+298 227
+156 299
+101 162
+70 323
+420 152
+88 373
+125 455
+235 318
+525 6
+62 298
+536 323
+61 466
+624 421
+299 244
+625 26
+387 216
+473 9
+25 212
+180 470
+76 172
+189 230
+75 330
+203 422
+265 440
+41 104
+443 271
+362 415
+169 244
+334 440
+60 442
+368 39
+594 133
+203 4
+427 404
+84 310
+458 403
+185 127
+117 190
+375 265
+12 79
+530 177
+3 70
+433 273
+172 337
+470 138
+615 207
+159 362
+368 190
+378 430
+366 306
+142 427
+609 326
+286 215
+541 469
+447 55
+190 368
+520 197
+253 324
+563 119
+372 150
+564 463
+443 282
+464 316
+320 255
+611 110
+412 189
+271 297
+388 227
+12 225
+193 343
+422 138
+185 184
+395 359
+274 421
+86 49
+190 44
+364 169
+378 264
+367 16
+418 465
+417 154
+276 106
+573 67
+235 46
+278 472
+570 124
+515 257
+450 215
+64 47
+588 169
+457 225
+639 403
+95 434
+555 18
+103 243
+393 80
+79 373
+542 415
+516 197
+364 67
+260 15
+44 471
+446 179
+290 201
+462 24
+554 175
+624 7
+547 110
+7 367
+230 453
+467 359
+109 162
+333 234
+34 162
+127 86
+11 82
+507 222
+143 419
+221 453
+593 291
+450 286
+20 376
+105 240
+397 24
+369 335
+152 476
+597 128
+392 325
+342 414
+377 360
+467 462
+199 266
+254 101
+134 106
+119 104
+604 273
+473 217
+313 465
+145 326
+162 40
+37 27
+278 234
+199 422
+445 468
+241 296
+114 260
+15 410
+43 357
+434 229
+290 324
+343 291
+573 343
+633 225
+138 218
+424 435
+168 65
+13 110
+485 423
+204 434
+245 309
+376 155
+531 249
+402 0
+558 149
+175 204
+510 424
+118 326
+609 218
+439 232
+137 378
+606 110
+467 422
+162 150
+136 459
+331 226
+16 341
+132 73
+271 350
+239 310
+296 103
+177 89
+375 387
+552 358
+75 323
+331 132
+84 83
+458 338
+253 222
+361 403
+117 98
+92 79
+312 59
+227 346
+601 14
+489 358
+479 44
+578 104
+53 359
+353 351
+374 21
+615 100
+186 137
+154 325
+64 30
+10 266
+594 4
+428 399
+502 472
+180 337
+375 87
+40 245
+310 278
+625 378
+560 291
+216 104
+615 218
+148 421
+607 236
+602 343
+511 233
+403 340
+559 239
+187 405
+543 93
+395 371
+8 467
+222 413
+94 374
+628 472
+306 361
+318 1
+409 129
+235 197
+87 205
+526 142
+121 192
+327 57
+143 470
+62 194
+551 273
+622 164
+614 378
+580 197
+495 172
+213 191
+51 144
+260 372
+148 444
+84 156
+34 457
+464 6
+7 256
+493 146
+94 423
+50 120
+57 325
+430 389
+157 207
+269 361
+356 398
+550 181
+465 46
+173 122
+84 284
+35 228
+193 234
+167 220
+291 251
+437 212
+445 409
+181 208
+243 396
+115 244
+504 41
+36 316
+446 99
+498 406
+497 327
+166 85
+239 33
+376 4
+174 428
+237 64
+126 374
+294 444
+28 343
+511 235
+49 225
+332 423
+196 234
+369 198
+614 83
+413 228
+22 376
+275 267
+326 76
+343 69
+436 311
+177 258
+82 156
+251 70
+612 76
+119 62
+578 277
+348 44
+292 437
+564 39
+293 384
+463 421
+255 44
+578 204
+441 227
+447 278
+209 343
+484 12
+407 351
+153 368
+102 4
+509 147
+613 111
+293 241
+378 457
+548 267
+292 46
+609 298
+368 414
+525 75
+581 476
+521 40
+102 45
+402 304
+254 455
+40 449
+271 214
+165 349
+543 356
+21 147
+613 57
+227 213
+228 188
+10 255
+118 405
+256 257
+594 326
+63 292
+604 47
+556 44
+290 26
+209 41
+148 113
+393 402
+21 250
+9 246
+274 311
+43 261
+161 15
+141 278
+162 370
+83 180
+7 235
+73 471
+395 117
+623 179
+633 21
+261 148
+104 399
+408 387
+313 307
+633 176
+41 150
+501 384
+184 33
+154 328
+424 182
+157 304
+426 444
+331 409
+271 238
+355 205
+183 394
+452 354
+265 214
+230 465
+530 174
+591 190
+29 354
+148 215
+223 449
+521 123
+630 183
+620 334
+579 430
+189 58
+634 115
+159 109
+67 234
+608 427
+149 171
+441 184
+37 440
+467 54
+564 302
+174 63
+242 179
+239 155
+479 326
+152 381
+109 241
+287 142
+194 425
+537 168
+152 354
+321 266
+603 96
+405 263
+555 249
+601 167
+480 11
+447 71
+619 63
+636 339
+289 340
+45 293
+187 322
+97 214
+267 334
+84 181
+386 48
+244 460
+573 34
+619 9
+350 470
+175 71
+379 124
+573 103
+260 278
+353 468
+173 131
+291 465
+257 12
+158 426
+323 340
+198 133
+238 429
+335 12
+480 300
+213 158
+591 464
+551 80
+31 432
+162 158
+285 426
+66 245
+223 245
+473 185
+435 254
+398 453
+454 428
+131 325
+218 306
+432 263
+562 130
+347 71
+180 411
+19 304
+454 143
+5 220
+238 11
+339 267
+590 173
+57 241
+259 73
+15 204
+219 434
+398 4
+178 465
+134 331
+74 47
+369 139
+444 258
+430 347
+607 186
+1 109
+414 218
+384 466
+376 400
+616 439
+10 320
+445 211
+520 328
+326 311
+213 13
+506 441
+62 260
+282 475
+332 183
+444 387
+58 221
+145 396
+262 258
+398 425
+567 422
+396 157
+85 194
+627 261
+557 298
+321 182
+590 260
+346 58
+590 326
+531 137
+619 20
+588 55
+23 51
+111 151
+249 118
+609 270
+192 435
+102 278
+567 287
+285 114
+581 278
+102 70
+423 161
+281 300
+48 173
+445 437
+158 421
+25 208
+38 248
+39 227
+580 88
+473 208
+574 90
+430 343
+338 251
+194 153
+638 1
+231 286
+301 311
+242 2
+626 465
+111 318
+209 140
+435 96
+40 444
+388 148
+305 193
+181 303
+152 427
+329 207
+235 445
+292 284
+215 207
+621 284
+85 170
+61 315
+219 313
+378 394
+421 193
+254 18
+639 472
+225 215
+461 450
+408 322
+520 128
+624 270
+569 459
+489 54
+446 130
+214 39
+94 367
+40 10
+154 65
+276 125
+334 418
+494 86
+613 207
+75 156
+68 280
+377 449
+477 451
+542 25
+598 286
+629 428
+255 374
+243 101
+94 367
+438 90
+420 431
+551 4
+62 43
+318 297
+371 183
+154 46
+108 472
+550 430
+37 130
+301 227
+74 230
+292 244
+627 464
+271 47
+548 19
+75 232
+173 219
+258 112
+255 28
+429 59
+220 411
+456 191
+409 183
+255 10
+276 179
+393 317
+44 300
+526 438
+418 322
+464 155
+343 151
+70 399

Some files were not shown because too many files changed in this diff