graph.pp 28 KB

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