graph.pp 22 KB

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