graph.pp 27 KB

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