graph.pp 24 KB

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