graph.pp 28 KB

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