graph.pp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1993-98 by Florian Klaempf & Gernot Tenchio
  5. members of the Free Pascal development team.
  6. Graph unit for BP7 compatible RTL
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. unit GRAPH;
  14. { there are some problems with ranges in this file !! (PM) }
  15. {$R-}
  16. {$Q-}
  17. { $DEFINE DEBUG}
  18. {$I os.inc}
  19. {$ifdef DEBUG}
  20. {$define TEST_24BPP}
  21. {$define Test_Linear}
  22. {$endif DEBUG}
  23. { Don't use smartlinking, because of the direct assembler that is used }
  24. {$ifndef VER0_99_8}
  25. {$SMARTLINK OFF}
  26. {$endif not VER0_99_8}
  27. interface
  28. uses go32,mmx;
  29. {$I GLOBAL.PPI}
  30. {$I STDCOLOR.PPI}
  31. procedure CloseGraph;
  32. function GraphResult : Integer;
  33. procedure InitGraph(var GraphDriver:Integer;var GraphMode:Integer;const PathToDriver:String);
  34. procedure SetGraphMode(GraphMode : integer);
  35. procedure GraphDefaults;
  36. procedure RestoreCRTMode;
  37. procedure SetGraphBufSize(BufSize : longint);
  38. function RegisterBGIdriver(driver : pointer) : integer;
  39. function InstallUserDriver(const DriverFileName : string;AutoDetectPtr : pointer) : integer;
  40. function GetDriverName: String;
  41. function GetModeName(Mode:Integer):String;
  42. function GetGraphMode:Integer;
  43. procedure GetAspectRatio(var _Xasp,_Yasp : word);
  44. procedure SetAspectRatio(_Xasp,_Yasp : word);
  45. function GraphErrorMsg(ErrorCode: Integer): string;
  46. function GetMaxMode : Integer;
  47. function GetMaxX : Integer;
  48. function GetMaxY : Integer;
  49. function GetX : Integer;
  50. function GetY : Integer;
  51. procedure Bar(x1,y1,x2,y2 : Integer);
  52. procedure bar3D(x1, y1, x2, y2 : integer;depth : word;top : boolean);
  53. procedure GetViewSettings(var viewport : ViewPortType);
  54. procedure SetActivePage(page : word);
  55. procedure SetVisualPage(page : word);
  56. procedure SetWriteMode(WriteMode : integer);
  57. procedure SetViewPort(x1,y1,x2,y2 : integer;clip : boolean);
  58. procedure Cleardevice;
  59. procedure ClearViewport;
  60. procedure Rectangle(x1,y1,x2,y2 : integer);
  61. { PIXEL.PPI }
  62. function GetPixel(x,y : integer):longint;
  63. procedure PutPixel(x,y : integer; Colour: longint);
  64. { LINE.PPI }
  65. procedure Line(x1,y1,x2,y2 : integer);
  66. procedure LineTo(x,y : integer);
  67. procedure LineRel(dx,dy : integer);
  68. procedure MoveTo(x,y : integer);
  69. procedure MoveRel(dx,dy : integer);
  70. procedure GetLineSettings(var LineInfo : LineSettingsType);
  71. procedure SetLineStyle(LineStyle : word;pattern : word;thickness : word);
  72. procedure DrawPoly(points : word;var polypoints);
  73. { PALETTE.PPI }
  74. procedure GetRGBPalette(ColorNum:byte; var RedValue,GreenValue,BlueValue:byte);
  75. procedure SetRGBPalette(ColorNum,RedValue,GreenValue,BlueValue:byte);
  76. procedure SetAllPalette(var Palette : PaletteType);
  77. procedure GetPalette(var Palette : PaletteType);
  78. procedure SetPalette(ColorNum:word;Color:byte);
  79. { ELLIPSE.PPI }
  80. procedure FillEllipse(x,y:Integer;XRadius,YRadius:Word);
  81. procedure Circle(x,y:Integer;Radius:Word);
  82. procedure Ellipse(x,y,alpha,beta:Integer;XRad,YRad:word);
  83. procedure Sector(X,Y,alpha,beta:integer;XRadius,YRadius: Word);
  84. { ARC.PPI }
  85. procedure Arc(x,y,alpha,beta:Integer;Radius:Word);
  86. procedure GetArcCoords(var ArcCoords:ArcCoordsType);
  87. procedure PieSlice(X,Y,alpha,beta:integer;Radius: Word);
  88. { COLORS.PPI }
  89. function GetBkColor : longint;
  90. function GetColor : longint;
  91. function GetMaxColor : longint;
  92. procedure SetColor(Color : longint);
  93. procedure SetBkColor(Color : longint);
  94. { FILL.PPI }
  95. procedure FloodFill(x,y:integer; Border:longint);
  96. procedure GetFillSettings(var FillInfo : FillSettingsType);
  97. procedure GetFillPattern(var FillPattern : FillPatternType);
  98. procedure SetFillStyle(pattern : word;color : longint);
  99. procedure SetFillPattern(pattern : FillPatternType;color : longint);
  100. { just dummy not implemented yet }
  101. procedure FillPoly(points : word;var polypoints);
  102. { IMAGE.PPI }
  103. function ImageSize(x1,y1,x2,y2 : integer) : longint;
  104. procedure GetImage(x1,y1,x2,y2 : integer;var BitMap);
  105. procedure PutImage(x,y : integer;var BitMap;BitBlt : word);
  106. { TEXT.PPI }
  107. procedure GetTextSettings(var TextInfo : TextSettingsType);
  108. procedure OutText(const TextString : string);
  109. procedure OutTextXY(x,y : integer;const TextString : string);
  110. procedure OutText(const Charakter : char);
  111. procedure OutTextXY(x,y : integer;const Charakter : char);
  112. procedure SetTextJustify(horiz,vert : word);
  113. procedure SetTextStyle(Font, Direction : word; CharSize : word);
  114. procedure SetUserCharSize(Multx,Divx,Multy,Divy : word);
  115. function TextHeight(const TextString : string) : word;
  116. function TextWidth(const TextString : string) : word;
  117. function RegisterBGIfont(font : pointer) : integer;
  118. function InstallUserFont(const FontFileName : string) : integer;
  119. { extended non Borland-compatible }
  120. { TRIANGLE.PPI }
  121. procedure FillTriangle(A,B,C:Pointtype);
  122. { to compare colors on different resolutions }
  123. function ColorsEqual(c1,c2 : longint) : boolean;
  124. { this will return true if the two colors will appear
  125. equal in the current video mode }
  126. procedure WaitRetrace;
  127. {$ifdef debug}
  128. procedure pixel(offset:longint);
  129. function Convert(color:longint):longint;
  130. function UnConvert(color:longint):longint;
  131. {$endif debug}
  132. {$ifdef Test_linear}
  133. const
  134. UseLinear : boolean = false;
  135. { the two below are the settings the work for ATI 3D Rage Pro !! }
  136. switch_physical_address : boolean = true;
  137. split_physical_address : boolean = false;
  138. {$endif Test_linear}
  139. {$I MODES.PPI}
  140. implementation
  141. {$ASMMODE DIRECT}
  142. type
  143. PString=^String;
  144. PInteger=^integer;
  145. PWord=^word;
  146. PLong=^longint;
  147. VgaInfoBlock = record
  148. VESASignature: array[1..4]of Char;
  149. VESAloVersion: Byte;
  150. VESAhiVersion: Byte;
  151. OEMStringPtr : longint;
  152. Capabilities : longint;
  153. VideoModePtr : longint;
  154. TotalMem : word;
  155. { VESA 2.0 }
  156. OEMversion : word;
  157. VendorPtr : longint;
  158. ProductPtr : longint;
  159. RevisionPtr : longint;
  160. filler : Array[1..478]of Byte;
  161. end;
  162. VesaInfoBlock=record
  163. ModeAttributes : word;
  164. WinAAttributes : byte;
  165. WinBAttributes : byte;
  166. WinGranularity : word;
  167. WinSize : word;
  168. segWINA : word;
  169. segWINB : word;
  170. RealWinFuncPtr : longint;
  171. BPL : word;
  172. { VESA 1.2 }
  173. XResolution : word;
  174. YResolution : word;
  175. XCharSize : byte;
  176. YCharSize : byte;
  177. MumberOfPlanes : byte;
  178. BitsPerPixel : byte;
  179. NumberOfBanks : byte;
  180. MemoryModel : byte;
  181. BankSize : byte;
  182. NumberOfPages : byte;
  183. reserved : byte;
  184. rm_size : byte;
  185. rf_pos : byte;
  186. gm_size : byte;
  187. gf_pos : byte;
  188. bm_size : byte;
  189. bf_pos : byte;
  190. res_mask : word;
  191. DirectColorInfo: byte;
  192. { VESA 2.0 }
  193. PhysAddress : longint;
  194. OffscreenPtr : longint;
  195. OffscreenMem : word;
  196. reserved2 : Array[1..458]of Byte;
  197. end;
  198. const
  199. CheckRange : Boolean=true;
  200. isVESA2 : Boolean=false;
  201. core : longint=$E0000000;
  202. var { X/Y Verhaeltnis des Bildschirm }
  203. AspectRatio : real;
  204. XAsp , YAsp : Word;
  205. { Zeilen & Spalten des aktuellen Graphikmoduses }
  206. _maxx,_maxy : longint;
  207. { Current color internal format (depending on bitsperpixel) }
  208. aktcolor : longint;
  209. { Current color RGB value }
  210. truecolor : longint;
  211. { Current background color internal format (depending on bitsperpixel) }
  212. aktbackcolor : longint;
  213. { Current background color RGB value }
  214. truebackcolor : longint;
  215. { Videospeicherbereiche }
  216. wbuffer,rbuffer,wrbuffer : ^byte;
  217. { aktueller Ausgabebereich }
  218. aktviewport : ViewPortType;
  219. aktscreen : ViewPortType;
  220. { der Graphikmodus, der beim Start gesetzt war }
  221. startmode : byte;
  222. { Position des Graphikcursors }
  223. curx,cury : longint;
  224. { true, wenn die Routinen des Graphikpaketes verwendet werden d�rfen }
  225. isgraphmode : boolean;
  226. { Einstellung zum Linien zeichnen }
  227. aktlineinfo : LineSettingsType;
  228. { Fehlercode, wird von graphresult zur�ckgegeben }
  229. _graphresult : integer;
  230. { aktuell eingestellte F�llart }
  231. aktfillsettings : FillSettingsType;
  232. aktfillbkcolor : longint;
  233. { aktuelles F�llmuster }
  234. aktfillpattern : FillPatternType;
  235. { Schreibmodus }
  236. aktwritemode : word;
  237. { put background color around text }
  238. ClearText : boolean;
  239. { Schrifteinstellung }
  240. akttextinfo : TextSettingsType;
  241. { momentan gesetzte Textskalierungswerte }
  242. aktmultx,aktdivx,aktmulty,aktdivy : word;
  243. { Pfad zu den Fonts }
  244. bgipath : string;
  245. { Pointer auf Hilfsspeicher }
  246. buffermem : pointer;
  247. { momentane GrӇe des Buffer }
  248. buffersize : longint;
  249. { in diesem Puffer werden bei SetFillStyle bereits die Pattern in der }
  250. { zu verwendenden Farbe abgelegt }
  251. PatternBuffer : Array[0..63]of LongInt;
  252. X_Array : array[0..1280]of LongInt;
  253. Y_Array : array[0..1024]of LongInt;
  254. Sel,Seg : word;
  255. VGAInfo : VGAInfoBlock;
  256. VESAInfo : VESAInfoBlock;
  257. { Selectors for Protected Mode }
  258. seg_WRITE : word;
  259. seg_READ : word;
  260. { linear Frame Buffer }
  261. LinearFrameBufferSupported : boolean;
  262. FrameBufferLinearAddress : longint;
  263. UseLinearFrameBuffer : Boolean;
  264. const
  265. EnableLinearFrameBuffer = $4000;
  266. { Registers for RealModeInterrupts in DPMI-Mode }
  267. var
  268. dregs : TRealRegs;
  269. { read and write bank are allways equal !! }
  270. A_Bank : longint;
  271. AW_window : longint;
  272. AR_Window : longint;
  273. same_window : boolean;
  274. const
  275. AWindow = 0;
  276. BWindow = 1;
  277. { Variables for Bankswitching }
  278. var
  279. BytesPerLine : longint;
  280. BytesPerPixel: Word;
  281. WinSize : longint; { Expample $0x00010000 . $0x00008000 }
  282. WinLoMask : longint; { $0x0000FFFF $0x00007FFF }
  283. WinLoMaskMinusPixelSize : longint; { $0x0000FFFF $0x00007FFF }
  284. WinShift : byte;
  285. GranShift : byte;
  286. Granular : longint;
  287. Granularity : longint;
  288. graphgetmemptr,
  289. graphfreememptr,
  290. bankswitchptr :pointer;
  291. isDPMI :Boolean;
  292. SwitchCS,SwitchIP : word;
  293. function ColorsEqual(c1,c2 : longint) : boolean;
  294. Begin
  295. ColorsEqual:=((BytesPerPixel=1) and ((c1 and $FF)=(c2 and $FF))) or
  296. ((GetMaxColor=$7FFF) and ((c1 and $F8F8F8)=(c2 and $F8F8F8))) or
  297. ((GetMaxColor=$FFFF) and ((c1 and $F8FCF8)=(c2 and $F8FCF8))) or
  298. ((BytesPerPixel>2) and ((c1 and $FFFFFF)=(c2 and $FFFFFF)));
  299. End;
  300. function GraphErrorMsg(ErrorCode: Integer): string;
  301. Begin
  302. GraphErrorMsg:='';
  303. case ErrorCode of
  304. grOk,grFileNotFound,grInvalidDriver: exit;
  305. grNoInitGraph: GraphErrorMsg:='Graphics driver not installed';
  306. grNotDetected: GraphErrorMsg:='Graphics hardware not detected';
  307. grNoLoadMem,grNoScanMem,grNoFloodMem: GraphErrorMsg := 'Not enough memory for graphics';
  308. grNoFontMem: GraphErrorMsg := 'Not enough memory to load font';
  309. grFontNotFound: GraphErrorMsg:= 'Font file not found';
  310. grInvalidMode: GraphErrorMsg := 'Invalid graphics mode';
  311. grError: GraphErrorMsg:='Graphics error';
  312. grIoError: GraphErrorMsg:='Graphics I/O error';
  313. grInvalidFont,grInvalidFontNum: GraphErrorMsg := 'Invalid font';
  314. grInvalidVersion: GraphErrorMsg:='Invalid driver version';
  315. end;
  316. end;
  317. procedure Oh_Kacke(ErrString:String);
  318. begin
  319. CloseGraph;
  320. writeln('Error in Unit VESA: ',ErrString);
  321. halt;
  322. end;
  323. {$I MOVE.PPI}
  324. {$I IBM.PPI}
  325. procedure WaitRetrace;
  326. begin
  327. asm
  328. cli
  329. movw $0x03Da,%dx
  330. WaitNotHSyncLoop:
  331. inb %dx,%al
  332. testb $0x8,%al
  333. jnz WaitNotHSyncLoop
  334. WaitHSyncLoop:
  335. inb %dx,%al
  336. testb $0x8,%al
  337. jz WaitHSyncLoop
  338. sti
  339. end;
  340. end;
  341. procedure getmem(var p : pointer;size : longint);
  342. begin
  343. asm
  344. pushl 12(%ebp)
  345. pushl 8(%ebp)
  346. movl _GRAPHGETMEMPTR,%eax
  347. call %eax
  348. end;
  349. end;
  350. procedure freemem(var p : pointer;size : longint);
  351. begin
  352. asm
  353. pushl 12(%ebp)
  354. pushl 8(%ebp)
  355. movl _GRAPHFREEMEMPTR,%eax
  356. call %eax
  357. end;
  358. end;
  359. {$I COLORS.PPI}
  360. procedure graphdefaults;
  361. begin
  362. _graphresult:=grOk;
  363. if not isgraphmode then
  364. begin
  365. _graphresult:=grnoinitgraph;
  366. exit;
  367. end;
  368. { Linientyp }
  369. aktlineinfo.linestyle:=solidln;
  370. aktlineinfo.thickness:=normwidth;
  371. { std colors }
  372. setstdcolors;
  373. { Zeichenfarbe }
  374. aktcolor:=convert(white);
  375. aktbackcolor:=convert(black);
  376. { F�llmuster }
  377. setfillstyle(solidfill,white);
  378. { necessary to load patternbuffer !! (PM)
  379. aktfillsettings.color:=white;
  380. aktfillsettings.pattern:=solidfill; }
  381. { Viewport setzen }
  382. aktviewport.clip:=true;
  383. aktviewport.x1:=0;
  384. aktviewport.y1:=0;
  385. aktviewport.x2:=_maxx-1;
  386. aktviewport.y2:=_maxy-1;
  387. aktscreen:=aktviewport;
  388. { normaler Schreibmodus }
  389. setwritemode(normalput);
  390. { Schriftart einstellen }
  391. akttextinfo.font:=DefaultFont;
  392. akttextinfo.direction:=HorizDir;
  393. akttextinfo.charsize:=1;
  394. akttextinfo.horiz:=LeftText;
  395. akttextinfo.vert:=TopText;
  396. { VergrӇerungsfaktoren}
  397. XAsp:=10000; YAsp:=10000;
  398. aspectratio:=1;
  399. end;
  400. { ############################################################### }
  401. { ################# Ende der internen Routinen ################ }
  402. { ############################################################### }
  403. {$I PALETTE.PPI}
  404. {$I PIXEL.PPI}
  405. {$I LINE.PPI}
  406. {$I ELLIPSE.PPI}
  407. {$I TRIANGLE.PPI}
  408. {$I ARC.PPI}
  409. {$I IMAGE.PPI}
  410. {$I TEXT.PPI}
  411. {$I FILL.PPI}
  412. function GetDrivername:String;
  413. begin
  414. if not isgraphmode then
  415. begin
  416. _graphresult:=grNoInitGraph;
  417. Exit;
  418. end;
  419. GetDriverName:=('internal VESA-Driver');
  420. end;
  421. function GetModeName(Mode:Integer):String;
  422. var s1,s2,s3:string;
  423. begin
  424. if not isgraphmode then
  425. begin
  426. _graphresult:=grNoInitGraph;
  427. Exit;
  428. end;
  429. str(_maxx,s1);
  430. str(_maxy,s2);
  431. str(getmaxcolor+1,s3);
  432. GetModeName:=('VESA '+s1+'x'+s2+'x'+s3);
  433. end;
  434. function GetGraphMode:Integer;
  435. begin
  436. if not isgraphmode then
  437. begin
  438. _graphresult:=grNoInitGraph;
  439. Exit;
  440. end;
  441. GetGraphMode:=GetVesaMode;
  442. end;
  443. procedure ClearViewport;
  444. var bank1,bank2,diff,c:longint;
  445. ofs1,ofs2 :longint;
  446. y : integer;
  447. storewritemode : word;
  448. begin
  449. if not isgraphmode then
  450. begin
  451. _graphresult:=grNoInitGraph;
  452. Exit;
  453. end;
  454. c:=aktcolor;
  455. aktcolor:=aktbackcolor;
  456. storewritemode:=aktwritemode;
  457. aktwritemode:=normalput;
  458. ofs1:=Y_ARRAY[aktviewport.y1] + X_ARRAY[aktviewport.x1] ;
  459. ofs2:=Y_ARRAY[aktviewport.y1] + X_ARRAY[aktviewport.x2] ;
  460. for y:=aktviewport.y1 to aktviewport.y2 do
  461. begin
  462. bank1:=ofs1 shr winshift;
  463. bank2:=ofs2 shr winshift;
  464. if bank1 <> A_BANK then
  465. begin
  466. Switchbank(bank1);
  467. end;
  468. if bank1 <> bank2 then
  469. begin
  470. diff:=((bank2 shl winshift)-ofs1) div BytesPerPixel;
  471. horizontalline(aktviewport.x1, aktviewport.x1+diff-1, y);
  472. Switchbank(bank2);
  473. horizontalline(aktviewport.x1+diff, aktviewport.x2, y);
  474. end else horizontalline(aktviewport.x1, aktviewport.x2, y);
  475. ofs1:=ofs1 + BytesPerLine;
  476. ofs2:=ofs2 + BytesPerLine;
  477. end;
  478. aktwritemode:=storewritemode;
  479. aktcolor:=c;
  480. end;
  481. procedure GetAspectRatio(var _Xasp,_Yasp : word);
  482. begin
  483. _graphresult:=grOk;
  484. if not isgraphmode then
  485. begin
  486. _graphresult:=grnoinitgraph;
  487. exit;
  488. end;
  489. _XAsp:=XAsp; _YAsp:=YAsp;
  490. end;
  491. procedure SetAspectRatio(_Xasp, _Yasp : word);
  492. begin
  493. _graphresult:=grOk;
  494. if not isgraphmode then
  495. begin
  496. _graphresult:=grnoinitgraph;
  497. exit;
  498. end;
  499. Xasp:=_XAsp; YAsp:=_YAsp;
  500. end;
  501. procedure ClearDevice;
  502. var Viewport:ViewportType;
  503. begin
  504. if not isgraphmode then
  505. begin
  506. _graphresult:=grNoInitGraph;
  507. Exit;
  508. end;
  509. Viewport:=aktviewport;
  510. SetViewport(0,0,_maxx-1,_maxy-1,Clipon);
  511. ClearViewport;
  512. aktviewport:=viewport;
  513. end;
  514. procedure Rectangle(x1,y1,x2,y2:integer);
  515. begin
  516. if not isgraphmode then
  517. begin
  518. _graphresult:=grNoInitGraph;
  519. Exit;
  520. end;
  521. Line(x1,y1,x2,y1);
  522. Line(x1,y1,x1,y2);
  523. Line(x2,y1,x2,y2);
  524. Line(x1,y2,x2,y2);
  525. end;
  526. procedure Bar(x1,y1,x2,y2:integer);
  527. var y : Integer;
  528. origcolor : longint;
  529. origlinesettings: Linesettingstype;
  530. begin
  531. if not isgraphmode then
  532. begin
  533. _graphresult:=grNoInitGraph;
  534. Exit;
  535. end;
  536. origlinesettings:=aktlineinfo;
  537. origcolor:=aktcolor;
  538. aktlineinfo.linestyle:=solidln;
  539. aktlineinfo.thickness:=normwidth;
  540. case aktfillsettings.pattern of
  541. emptyfill : begin
  542. aktcolor:=aktbackcolor;
  543. for y:=y1 to y2 do line(x1,y,x2,y);
  544. end;
  545. solidfill : begin
  546. aktcolor:=aktfillsettings.color;
  547. for y:=y1 to y2 do line(x1,y,x2,y);
  548. end;
  549. else for y:=y1 to y2 do patternline(x1,x2,y);
  550. end;
  551. aktcolor:=origcolor;
  552. aktlineinfo:=origlinesettings;
  553. end;
  554. procedure bar3D(x1, y1, x2, y2 : integer;depth : word;top : boolean);
  555. begin
  556. if not isgraphmode then
  557. begin
  558. _graphresult:=grNoInitGraph;
  559. Exit;
  560. end;
  561. Bar(x1,y1,x2,y2);
  562. Rectangle(x1,y1,x2,y2);
  563. if top then begin
  564. Moveto(x1,y1);
  565. Lineto(x1+depth,y1-depth);
  566. Lineto(x2+depth,y1-depth);
  567. Lineto(x2,y1);
  568. end;
  569. Moveto(x2+depth,y1-depth);
  570. Lineto(x2+depth,y2-depth);
  571. Lineto(x2,y2);
  572. end;
  573. procedure SetGraphBufSize(BufSize : longint);
  574. begin
  575. if assigned(buffermem) then
  576. freemem(buffermem,buffersize);
  577. getmem(buffermem,bufsize);
  578. if not assigned(buffermem) then
  579. buffersize:=0
  580. else buffersize:=bufsize;
  581. end;
  582. const
  583. { Vorgabegr”áe f�r Hilfsspeicher }
  584. bufferstandardsize = 64*8196; { 0,5 MB }
  585. procedure CloseGraph;
  586. begin
  587. if isgraphmode then
  588. begin
  589. SetVESAMode(startmode);
  590. { DoneVESA; only in exitproc !! PM }
  591. isgraphmode:=false;
  592. if assigned(buffermem) then
  593. freemem(buffermem,buffersize);
  594. buffermem:=nil;
  595. buffersize:=0;
  596. end;
  597. end;
  598. procedure InitGraph(var GraphDriver:Integer;var GraphMode:Integer;const PathToDriver:String);
  599. var i,index:Integer;
  600. begin
  601. { Pfad zu den Fonts }
  602. bgipath:=PathToDriver;
  603. if bgipath[length(bgipath)]<>'\' then
  604. bgipath:=bgipath+'\';
  605. if Graphdriver=detect then GraphMode:=GetMaxMode;
  606. { Standardfonts installieren }
  607. InstallUserFont('TRIP');
  608. InstallUserFont('LITT');
  609. InstallUserFont('SANS');
  610. InstallUserFont('GOTH');
  611. InstallUserFont('SCRI');
  612. InstallUserFont('SIMP');
  613. InstallUserFont('TSCR');
  614. InstallUserFont('LCOM');
  615. InstallUserFont('EURO');
  616. InstallUserFont('BOLD');
  617. GetVESAInfo(GraphMode);
  618. {$IFDEF DEBUG}
  619. {$I VESADEB.PPI}
  620. {$ENDIF}
  621. for i:=VESANumber downto 0 do
  622. if GraphMode=VESAModes[i] then break;
  623. { the modes can be refused due to the monitor ? }
  624. { that happens by me at home Pierre Muller }
  625. while i>=0 do begin
  626. isgraphmode:=SetVESAMode(GraphMode);
  627. if isgraphmode then begin
  628. GetVESAInfo(GraphMode);
  629. if UseLinearFrameBuffer then
  630. isgraphmode:=SetVESAMode(GraphMode or EnableLinearFrameBuffer);
  631. for index:=0 to VESAInfo.XResolution do X_Array[index]:=index * BytesPerPixel;
  632. for index:=0 to VESAInfo.YResolution do Y_Array[index]:=index * BytesPerLine;
  633. SetGraphBufSize(bufferstandardsize);
  634. graphdefaults;
  635. exit;
  636. end;
  637. dec(i);
  638. GraphMode:=VESAModes[i];
  639. end;
  640. _graphresult:=grInvalidMode
  641. end;
  642. procedure SetGraphMode(GraphMode:Integer);
  643. var index:Integer;
  644. begin
  645. _graphresult:=grOk;
  646. if not isgraphmode then
  647. begin
  648. _graphresult:=grNoInitGraph;
  649. Exit;
  650. end;
  651. if GetVesaInfo(GraphMode) then
  652. begin
  653. isgraphmode:=SetVESAMode(GraphMode);
  654. if isgraphmode then
  655. begin
  656. if UseLinearFrameBuffer then
  657. isgraphmode:=SetVESAMode(GraphMode or EnableLinearFrameBuffer);
  658. for index:=0 to VESAInfo.XResolution do
  659. X_Array[index]:=index * BytesPerPixel;
  660. for index:=0 to VESAInfo.YResolution do
  661. Y_Array[index]:=index * BytesPerLine;
  662. graphdefaults;
  663. exit;
  664. end;
  665. end;
  666. _graphresult:=grInvalidMode;
  667. end;
  668. function RegisterBGIdriver(driver : pointer) : integer;
  669. begin
  670. RegisterBGIdriver:=grerror;
  671. end;
  672. function InstallUserDriver(const DriverFileName : string;AutoDetectPtr : pointer) : integer;
  673. begin
  674. installuserdriver:=grerror;
  675. end;
  676. function GetMaxMode:Integer;
  677. var i:Byte;
  678. begin
  679. for i:=VESANumber downto 0 do
  680. if GetVesaInfo(VESAModes[i]) then
  681. begin
  682. GetMaxMode:=VESAModes[i];
  683. Exit;
  684. end;
  685. end;
  686. function GetMaxX:Integer;
  687. begin
  688. if not isgraphmode then
  689. begin
  690. _graphresult:=grNoInitGraph;
  691. Exit;
  692. end;
  693. GetMaxX:=VESAInfo.XResolution-1;
  694. end;
  695. function GetMaxY:Integer;
  696. begin
  697. if not isgraphmode then
  698. begin
  699. _graphresult:=grNoInitGraph;
  700. Exit;
  701. end;
  702. GetMaxY:=VESAInfo.YResolution-1;
  703. end;
  704. function GetX : integer;
  705. begin
  706. _graphresult:=grOk;
  707. if not isgraphmode then
  708. begin
  709. _graphresult:=grNoInitGraph;
  710. Exit;
  711. end;
  712. GetX:=curx;
  713. end;
  714. function GetY : integer;
  715. begin
  716. _graphresult:=grOk;
  717. if not isgraphmode then
  718. begin
  719. _graphresult:=grNoInitGraph;
  720. Exit;
  721. end;
  722. GetY:=cury;
  723. end;
  724. procedure SetViewPort(x1,y1,x2,y2 : integer;clip : boolean);
  725. begin
  726. _graphresult:=grOk;
  727. if not isgraphmode then
  728. begin
  729. _graphresult:=grNoInitGraph;
  730. exit;
  731. end;
  732. { Daten �berpr�fen }
  733. if (x1<0) or (y1<0) or (x2>=_maxx) or (y2>=_maxy) then exit;
  734. aktviewport.x1:=x1;
  735. aktviewport.y1:=y1;
  736. aktviewport.x2:=x2;
  737. aktviewport.y2:=y2;
  738. aktviewport.clip:=clip;
  739. end;
  740. procedure GetViewSettings(var viewport : ViewPortType);
  741. begin
  742. _graphresult:=grOk;
  743. if not isgraphmode then
  744. begin
  745. _graphresult:=grNoInitGraph;
  746. exit;
  747. end;
  748. viewport:=aktviewport;
  749. end;
  750. { mehrere Bildschirmseiten werden nicht unterst�tzt }
  751. { Dummy aus Kompatibilit„tsgr�nden }
  752. procedure SetVisualPage(page : word);
  753. begin
  754. _graphresult:=grOk;
  755. if not isgraphmode then
  756. begin
  757. _graphresult:=grNoInitGraph;;
  758. exit;
  759. end;
  760. end;
  761. { mehrere Bildschirmseiten werden nicht unterst�tzt }
  762. { Dummy aus Kompatibilit„tsgr�nden }
  763. procedure SetActivePage(page : word);
  764. begin
  765. _graphresult:=grOk;
  766. if not isgraphmode then
  767. begin
  768. _graphresult:=grNoInitGraph;;
  769. exit;
  770. end;
  771. end;
  772. procedure SetWriteMode(WriteMode : integer);
  773. begin
  774. _graphresult:=grOk;
  775. if not isgraphmode then
  776. begin
  777. _graphresult:=grNoInitGraph;;
  778. exit;
  779. end;
  780. if ((writemode and 7)<>xorput) and ((writemode and 7)<>normalput) then
  781. begin
  782. _graphresult:=grError;
  783. exit;
  784. end;
  785. aktwritemode:=(writemode and 7);
  786. if (writemode and BackPut)<>0 then
  787. ClearText:=true
  788. else
  789. ClearText:=false;
  790. end;
  791. function GraphResult:Integer;
  792. begin
  793. GraphResult:=_graphresult;
  794. end;
  795. procedure RestoreCRTMode;
  796. begin
  797. if not isgraphmode then
  798. begin
  799. _graphresult:=grNoInitGraph;
  800. Exit;
  801. end;
  802. SetVESAMode(startmode);
  803. isgraphmode:=false;
  804. end;
  805. var PrevExitProc : pointer;
  806. procedure GraphExit;
  807. begin
  808. ExitProc:=PrevExitProc;
  809. CloseGraph;
  810. DoneVesa; { frees the ldt descriptos seg_read and seg_write !! }
  811. end;
  812. begin
  813. InitVESA;
  814. if not DetectVESA then
  815. Oh_Kacke('VESA-BIOS not found...');
  816. startmode:=GetVESAMode;
  817. bankswitchptr:=@switchbank;
  818. GraphGetMemPtr:[email protected];
  819. GraphFreeMemPtr:[email protected];
  820. Getdefaultfont;
  821. if not isDPMI then begin
  822. wrbuffer:=pointer($D0000000);
  823. rbuffer:=pointer($D0200000);
  824. wbuffer:=pointer($D0200000);
  825. end else begin
  826. wrbuffer:=pointer($0);
  827. rbuffer:=pointer($0);
  828. wbuffer:=pointer($0);
  829. end;
  830. end.
  831. {
  832. $Log$
  833. Revision 1.9 1998-11-19 15:09:33 pierre
  834. * several bugfixes for sector/ellipse/floodfill
  835. + graphic driver mode const in interface G800x600x256...
  836. + added backput mode as in linux graph.pp
  837. (clears the background of textoutput)
  838. Revision 1.8 1998/11/19 09:48:45 pierre
  839. + added some functions missing like sector ellipse getarccoords
  840. (the filling of sector and ellipse is still buggy
  841. I use floodfill but sometimes the starting point
  842. is outside !!)
  843. * fixed a bug in floodfill for patterns
  844. (still has problems !!)
  845. Revision 1.7 1998/11/18 09:31:29 pierre
  846. * changed color scheme
  847. all colors are in RGB format if more than 256 colors
  848. + added 24 and 32 bits per pixel mode
  849. (compile with -dDEBUG)
  850. 24 bit mode with banked still as problems on pixels across
  851. the bank boundary, but works in LinearFrameBufferMode
  852. Look at install/demo/nmandel.pp
  853. Revision 1.6 1998/10/22 09:44:57 pierre
  854. * PatternBuffer was not set on entry !!
  855. Revision 1.5 1998/09/16 16:47:25 peter
  856. * merged fixes
  857. Revision 1.4.2.1 1998/09/16 16:15:41 peter
  858. * no smartlinking!
  859. Revision 1.4 1998/05/31 14:18:14 peter
  860. * force att or direct assembling
  861. * cleanup of some files
  862. Revision 1.3 1998/05/22 00:39:23 peter
  863. * go32v1, go32v2 recompiles with the new objects
  864. * remake3 works again with go32v2
  865. - removed some "optimizes" from daniel which were wrong
  866. }