graph.pp 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  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. {$ifdef DEBUG}
  19. {$define TEST_24BPP}
  20. {$define Test_Linear}
  21. {$endif DEBUG}
  22. { Output to AT&T for as }
  23. {$OUTPUT_FORMAT AS}
  24. { Use the direct assembler parser }
  25. {$ASMMODE DIRECT}
  26. { Don't use smartlinking, because of the direct assembler that is used }
  27. {$SMARTLINK OFF}
  28. interface
  29. uses go32,mmx;
  30. {$I GLOBAL.PPI}
  31. {$I STDCOLOR.PPI}
  32. procedure CloseGraph;
  33. function GraphResult : Integer;
  34. procedure InitGraph(var GraphDriver:Integer;var GraphMode:Integer;const PathToDriver:String);
  35. procedure SetGraphMode(GraphMode : integer);
  36. procedure GraphDefaults;
  37. procedure RestoreCRTMode;
  38. procedure SetGraphBufSize(BufSize : longint);
  39. function RegisterBGIdriver(driver : pointer) : integer;
  40. function InstallUserDriver(const DriverFileName : string;AutoDetectPtr : pointer) : integer;
  41. function GetDriverName: String;
  42. function GetModeName(Mode:Integer):String;
  43. function GetGraphMode:Integer;
  44. procedure GetAspectRatio(var _Xasp,_Yasp : word);
  45. procedure SetAspectRatio(_Xasp,_Yasp : word);
  46. function GraphErrorMsg(ErrorCode: Integer): string;
  47. function GetMaxMode : Integer;
  48. function GetMaxX : Integer;
  49. function GetMaxY : Integer;
  50. function GetX : Integer;
  51. function GetY : Integer;
  52. procedure Bar(x1,y1,x2,y2 : Integer);
  53. procedure bar3D(x1, y1, x2, y2 : integer;depth : word;top : boolean);
  54. procedure GetViewSettings(var viewport : ViewPortType);
  55. function GetNumberOfPages : word;
  56. procedure SetActivePage(page : word);
  57. function GetActivePage : word;
  58. procedure SetVisualPage(page : word);
  59. function GetVisualPage : word;
  60. procedure SetWriteMode(WriteMode : integer);
  61. procedure SetViewPort(x1,y1,x2,y2 : integer;clip : boolean);
  62. procedure Cleardevice;
  63. procedure ClearViewport;
  64. procedure Rectangle(x1,y1,x2,y2 : integer);
  65. { PIXEL.PPI }
  66. function GetPixel(x,y : integer):longint;
  67. procedure PutPixel(x,y : integer; Colour: longint);
  68. { LINE.PPI }
  69. procedure Line(x1,y1,x2,y2 : integer);
  70. procedure LineTo(x,y : integer);
  71. procedure LineRel(dx,dy : integer);
  72. procedure MoveTo(x,y : integer);
  73. procedure MoveRel(dx,dy : integer);
  74. procedure GetLineSettings(var LineInfo : LineSettingsType);
  75. procedure SetLineStyle(LineStyle : word;pattern : word;thickness : word);
  76. procedure DrawPoly(points : word;var polypoints);
  77. { PALETTE.PPI }
  78. procedure GetRGBPalette(ColorNum:byte; var RedValue,GreenValue,BlueValue:byte);
  79. procedure SetRGBPalette(ColorNum,RedValue,GreenValue,BlueValue:byte);
  80. procedure SetAllPalette(var Palette : PaletteType);
  81. procedure GetPalette(var Palette : PaletteType);
  82. procedure SetPalette(ColorNum:word;Color:byte);
  83. { ELLIPSE.PPI }
  84. procedure FillEllipse(x,y:Integer;XRadius,YRadius:Word);
  85. procedure Circle(x,y:Integer;Radius:Word);
  86. procedure Ellipse(x,y,alpha,beta:Integer;XRad,YRad:word);
  87. procedure Sector(X,Y,alpha,beta:integer;XRadius,YRadius: Word);
  88. { ARC.PPI }
  89. procedure Arc(x,y,alpha,beta:Integer;Radius:Word);
  90. procedure GetArcCoords(var ArcCoords:ArcCoordsType);
  91. procedure PieSlice(X,Y,alpha,beta:integer;Radius: Word);
  92. { COLORS.PPI }
  93. function GetBkColor : longint;
  94. function GetColor : longint;
  95. function GetMaxColor : longint;
  96. procedure SetColor(Color : longint);
  97. procedure SetBkColor(Color : longint);
  98. { FILL.PPI }
  99. procedure FloodFill(x,y:integer; Border:longint);
  100. procedure GetFillSettings(var FillInfo : FillSettingsType);
  101. procedure GetFillPattern(var FillPattern : FillPatternType);
  102. procedure SetFillStyle(pattern : word;color : longint);
  103. procedure SetFillPattern(pattern : FillPatternType;color : longint);
  104. { just dummy not implemented yet }
  105. procedure FillPoly(points : word;var polypoints);
  106. { IMAGE.PPI }
  107. function ImageSize(x1,y1,x2,y2 : integer) : longint;
  108. procedure GetImage(x1,y1,x2,y2 : integer;var BitMap);
  109. procedure PutImage(x,y : integer;var BitMap;BitBlt : word);
  110. { TEXT.PPI }
  111. procedure GetTextSettings(var TextInfo : TextSettingsType);
  112. procedure OutText(const TextString : string);
  113. procedure OutTextXY(x,y : integer;const TextString : string);
  114. procedure OutText(const Charakter : char);
  115. procedure OutTextXY(x,y : integer;const Charakter : char);
  116. procedure SetTextJustify(horiz,vert : word);
  117. procedure SetTextStyle(Font, Direction : word; CharSize : word);
  118. procedure SetUserCharSize(Multx,Divx,Multy,Divy : word);
  119. function TextHeight(const TextString : string) : word;
  120. function TextWidth(const TextString : string) : word;
  121. function RegisterBGIfont(font : pointer) : integer;
  122. function InstallUserFont(const FontFileName : string) : integer;
  123. { extended non Borland-compatible }
  124. { TRIANGLE.PPI }
  125. procedure FillTriangle(A,B,C:Pointtype);
  126. { to compare colors on different resolutions }
  127. function ColorsEqual(c1,c2 : longint) : boolean;
  128. { this will return true if the two colors will appear
  129. equal in the current video mode }
  130. procedure WaitRetrace;
  131. {$ifdef debug}
  132. procedure pixel(offset:longint);
  133. function Convert(color:longint):longint;
  134. function UnConvert(color:longint):longint;
  135. function SetVESADisplayStart(PageNum : word;x,y : integer):Boolean;
  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 GraphFault(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. GetGraphMode:=grNoInitGraph;
  469. Exit;
  470. end;
  471. GetGraphMode:=GetVesaMode;
  472. end;
  473. procedure ClearViewport;
  474. var bank1,bank2,diff,c:longint;
  475. ofs1,ofs2 :longint;
  476. y : integer;
  477. storewritemode : word;
  478. begin
  479. if not isgraphmode then
  480. begin
  481. _graphresult:=grNoInitGraph;
  482. Exit;
  483. end;
  484. c:=aktcolor;
  485. aktcolor:=aktbackcolor;
  486. storewritemode:=aktwritemode;
  487. aktwritemode:=normalput;
  488. ofs1:=Y_ARRAY[aktviewport.y1] + X_ARRAY[aktviewport.x1];
  489. ofs2:=Y_ARRAY[aktviewport.y1] + X_ARRAY[aktviewport.x2];
  490. for y:=aktviewport.y1 to aktviewport.y2 do
  491. begin
  492. bank1:=ofs1 shr winshift;
  493. bank2:=ofs2 shr winshift;
  494. if bank1 <> A_BANK then
  495. begin
  496. Switchbank(bank1);
  497. end;
  498. if bank1 <> bank2 then
  499. begin
  500. diff:=((bank2 shl winshift)-ofs1) div BytesPerPixel;
  501. horizontalline(aktviewport.x1, aktviewport.x1+diff-1, y);
  502. Switchbank(bank2);
  503. horizontalline(aktviewport.x1+diff, aktviewport.x2, y);
  504. end else horizontalline(aktviewport.x1, aktviewport.x2, y);
  505. ofs1:=ofs1 + BytesPerLine;
  506. ofs2:=ofs2 + BytesPerLine;
  507. end;
  508. aktwritemode:=storewritemode;
  509. aktcolor:=c;
  510. end;
  511. procedure GetAspectRatio(var _Xasp,_Yasp : word);
  512. begin
  513. _graphresult:=grOk;
  514. if not isgraphmode then
  515. begin
  516. _graphresult:=grnoinitgraph;
  517. exit;
  518. end;
  519. _XAsp:=XAsp; _YAsp:=YAsp;
  520. end;
  521. procedure SetAspectRatio(_Xasp, _Yasp : word);
  522. begin
  523. _graphresult:=grOk;
  524. if not isgraphmode then
  525. begin
  526. _graphresult:=grnoinitgraph;
  527. exit;
  528. end;
  529. Xasp:=_XAsp; YAsp:=_YAsp;
  530. end;
  531. procedure ClearDevice;
  532. var Viewport:ViewportType;
  533. begin
  534. if not isgraphmode then
  535. begin
  536. _graphresult:=grNoInitGraph;
  537. Exit;
  538. end;
  539. Viewport:=aktviewport;
  540. SetViewport(0,0,_maxx-1,_maxy-1,Clipon);
  541. ClearViewport;
  542. aktviewport:=viewport;
  543. end;
  544. procedure Rectangle(x1,y1,x2,y2:integer);
  545. begin
  546. if not isgraphmode then
  547. begin
  548. _graphresult:=grNoInitGraph;
  549. Exit;
  550. end;
  551. Line(x1,y1,x2,y1);
  552. Line(x1,y1,x1,y2);
  553. Line(x2,y1,x2,y2);
  554. Line(x1,y2,x2,y2);
  555. end;
  556. procedure Bar(x1,y1,x2,y2:integer);
  557. var y : Integer;
  558. origcolor : longint;
  559. origlinesettings: Linesettingstype;
  560. begin
  561. if not isgraphmode then
  562. begin
  563. _graphresult:=grNoInitGraph;
  564. Exit;
  565. end;
  566. origlinesettings:=aktlineinfo;
  567. origcolor:=aktcolor;
  568. aktlineinfo.linestyle:=solidln;
  569. aktlineinfo.thickness:=normwidth;
  570. case aktfillsettings.pattern of
  571. emptyfill : begin
  572. aktcolor:=aktbackcolor;
  573. for y:=y1 to y2 do line(x1,y,x2,y);
  574. end;
  575. solidfill : begin
  576. aktcolor:=aktfillsettings.color;
  577. for y:=y1 to y2 do line(x1,y,x2,y);
  578. end;
  579. else for y:=y1 to y2 do patternline(x1,x2,y);
  580. end;
  581. aktcolor:=origcolor;
  582. aktlineinfo:=origlinesettings;
  583. end;
  584. procedure bar3D(x1, y1, x2, y2 : integer;depth : word;top : boolean);
  585. begin
  586. if not isgraphmode then
  587. begin
  588. _graphresult:=grNoInitGraph;
  589. Exit;
  590. end;
  591. Bar(x1,y1,x2,y2);
  592. Rectangle(x1,y1,x2,y2);
  593. if top then begin
  594. Moveto(x1,y1);
  595. Lineto(x1+depth,y1-depth);
  596. Lineto(x2+depth,y1-depth);
  597. Lineto(x2,y1);
  598. end;
  599. Moveto(x2+depth,y1-depth);
  600. Lineto(x2+depth,y2-depth);
  601. Lineto(x2,y2);
  602. end;
  603. procedure SetGraphBufSize(BufSize : longint);
  604. begin
  605. if assigned(buffermem) then
  606. freemem(buffermem,buffersize);
  607. getmem(buffermem,bufsize);
  608. if not assigned(buffermem) then
  609. buffersize:=0
  610. else buffersize:=bufsize;
  611. end;
  612. const
  613. { Vorgabegr”áe f�r Hilfsspeicher }
  614. bufferstandardsize = 64*8196; { 0,5 MB }
  615. procedure CloseGraph;
  616. begin
  617. if isgraphmode then
  618. begin
  619. SetVESAMode(startmode);
  620. { DoneVESA; only in exitproc !! PM }
  621. isgraphmode:=false;
  622. if assigned(buffermem) then
  623. freemem(buffermem,buffersize);
  624. buffermem:=nil;
  625. buffersize:=0;
  626. end;
  627. end;
  628. procedure SetArrays;
  629. var
  630. index:Integer;
  631. begin
  632. for index:=0 to VESAInfo.XResolution do
  633. X_Array[index]:=index * BytesPerPixel;
  634. for index:=0 to VESAInfo.YResolution do
  635. Y_Array[index]:=index * BytesPerLine + AktPageOffset;
  636. end;
  637. procedure InitGraph(var GraphDriver:Integer;var GraphMode:Integer;const PathToDriver:String);
  638. var i : Integer;
  639. begin
  640. { Pfad zu den Fonts }
  641. bgipath:=PathToDriver;
  642. if bgipath[length(bgipath)]<>'\' then
  643. bgipath:=bgipath+'\';
  644. if Graphdriver=detect then GraphMode:=GetMaxMode;
  645. { Standardfonts installieren }
  646. InstallUserFont('TRIP');
  647. InstallUserFont('LITT');
  648. InstallUserFont('SANS');
  649. InstallUserFont('GOTH');
  650. InstallUserFont('SCRI');
  651. InstallUserFont('SIMP');
  652. InstallUserFont('TSCR');
  653. InstallUserFont('LCOM');
  654. InstallUserFont('EURO');
  655. InstallUserFont('BOLD');
  656. GetVESAInfo(GraphMode);
  657. {$IFDEF DEBUG}
  658. {$I VESADEB.PPI}
  659. {$ENDIF}
  660. for i:=VESANumber downto 0 do
  661. if GraphMode=VESAModes[i] then break;
  662. { the modes can be refused due to the monitor ? }
  663. { that happens by me at home Pierre Muller }
  664. while i>=0 do begin
  665. isgraphmode:=SetVESAMode(GraphMode);
  666. if isgraphmode then begin
  667. GetVESAInfo(GraphMode);
  668. if UseLinearFrameBuffer then
  669. isgraphmode:=SetVESAMode(GraphMode or EnableLinearFrameBuffer);
  670. { set zero page }
  671. AktPageOffset:=0;
  672. SetActivePage(0);
  673. SetVisualPage(0);
  674. SetArrays;
  675. SetGraphBufSize(bufferstandardsize);
  676. graphdefaults;
  677. InTempCRTMode:=false;
  678. exit;
  679. end;
  680. dec(i);
  681. GraphMode:=VESAModes[i];
  682. end;
  683. _graphresult:=grInvalidMode
  684. end;
  685. procedure SetGraphMode(GraphMode:Integer);
  686. begin
  687. _graphresult:=grOk;
  688. if not isgraphmode and not InTempCRTMode then
  689. begin
  690. _graphresult:=grNoInitGraph;
  691. Exit;
  692. end;
  693. if GetVesaInfo(GraphMode) then
  694. begin
  695. isgraphmode:=SetVESAMode(GraphMode);
  696. if isgraphmode then
  697. begin
  698. if UseLinearFrameBuffer then
  699. isgraphmode:=SetVESAMode(GraphMode or EnableLinearFrameBuffer);
  700. { set zero page }
  701. AktPageOffset:=0;
  702. SetActivePage(0);
  703. SetVisualPage(0);
  704. SetArrays;
  705. graphdefaults;
  706. InTempCRTMode:=false;
  707. exit;
  708. end;
  709. end;
  710. _graphresult:=grInvalidMode;
  711. end;
  712. function RegisterBGIdriver(driver : pointer) : integer;
  713. begin
  714. RegisterBGIdriver:=grerror;
  715. end;
  716. function InstallUserDriver(const DriverFileName : string;AutoDetectPtr : pointer) : integer;
  717. begin
  718. installuserdriver:=grerror;
  719. end;
  720. function GetMaxMode:Integer;
  721. var i:Byte;
  722. begin
  723. for i:=VESANumber downto 0 do
  724. if GetVesaInfo(VESAModes[i]) then
  725. begin
  726. GetMaxMode:=VESAModes[i];
  727. Exit;
  728. end;
  729. end;
  730. function GetMaxX:Integer;
  731. begin
  732. if not isgraphmode then
  733. begin
  734. _graphresult:=grNoInitGraph;
  735. Exit;
  736. end;
  737. GetMaxX:=VESAInfo.XResolution-1;
  738. end;
  739. function GetMaxY:Integer;
  740. begin
  741. if not isgraphmode then
  742. begin
  743. _graphresult:=grNoInitGraph;
  744. Exit;
  745. end;
  746. GetMaxY:=VESAInfo.YResolution-1;
  747. end;
  748. function GetX : integer;
  749. begin
  750. _graphresult:=grOk;
  751. if not isgraphmode then
  752. begin
  753. _graphresult:=grNoInitGraph;
  754. Exit;
  755. end;
  756. GetX:=curx;
  757. end;
  758. function GetY : integer;
  759. begin
  760. _graphresult:=grOk;
  761. if not isgraphmode then
  762. begin
  763. _graphresult:=grNoInitGraph;
  764. Exit;
  765. end;
  766. GetY:=cury;
  767. end;
  768. procedure SetViewPort(x1,y1,x2,y2 : integer;clip : boolean);
  769. begin
  770. _graphresult:=grOk;
  771. if not isgraphmode then
  772. begin
  773. _graphresult:=grNoInitGraph;
  774. exit;
  775. end;
  776. { Daten �berpr�fen }
  777. if (x1<0) or (y1<0) or (x2>=_maxx) or (y2>=_maxy) then exit;
  778. aktviewport.x1:=x1;
  779. aktviewport.y1:=y1;
  780. aktviewport.x2:=x2;
  781. aktviewport.y2:=y2;
  782. aktviewport.clip:=clip;
  783. end;
  784. procedure GetViewSettings(var viewport : ViewPortType);
  785. begin
  786. _graphresult:=grOk;
  787. if not isgraphmode then
  788. begin
  789. _graphresult:=grNoInitGraph;
  790. exit;
  791. end;
  792. viewport:=aktviewport;
  793. end;
  794. { mehrere Bildschirmseiten werden nicht unterst�tzt }
  795. { Dummy aus Kompatibilit„tsgr�nden }
  796. procedure SetVisualPage(page : word);
  797. begin
  798. _graphresult:=grOk;
  799. if not isgraphmode then
  800. begin
  801. _graphresult:=grNoInitGraph;;
  802. exit;
  803. end
  804. else if (Page<VESAInfo.NumberOfPages) and (AktVisualPage<>Page) then
  805. begin
  806. SetVESADisplayStart(Page,0,0);
  807. {SetDisplayPage(Page);}
  808. AktVisualPage:=Page;
  809. end;
  810. end;
  811. function GetVisualPage : word;
  812. begin
  813. GetVisualPage:=AktVisualPage;
  814. end;
  815. function GetActivePage : word;
  816. begin
  817. GetActivePage:=AktPage;
  818. end;
  819. { mehrere Bildschirmseiten werden nicht unterst�tzt }
  820. { Dummy aus Kompatibilit„tsgr�nden }
  821. procedure SetActivePage(page : word);
  822. begin
  823. _graphresult:=grOk;
  824. if not isgraphmode then
  825. begin
  826. _graphresult:=grNoInitGraph;;
  827. exit;
  828. end
  829. else if (Page<VESAInfo.NumberOfPages) and (Page<>AktPage) then
  830. begin
  831. AktPageOffset:=Page*BytesPerLine*_maxy;
  832. AktPage:=Page;
  833. SetArrays;
  834. end;
  835. end;
  836. function GetNumberOfPages : word;
  837. begin
  838. GetNumberOfPages:=VESAInfo.NumberOfPages;
  839. end;
  840. procedure SetWriteMode(WriteMode : integer);
  841. begin
  842. _graphresult:=grOk;
  843. if not isgraphmode then
  844. begin
  845. _graphresult:=grNoInitGraph;;
  846. exit;
  847. end;
  848. if ((writemode and 7)<>xorput) and ((writemode and 7)<>normalput) then
  849. begin
  850. _graphresult:=grError;
  851. exit;
  852. end;
  853. aktwritemode:=(writemode and 7);
  854. if (writemode and BackPut)<>0 then
  855. ClearText:=true
  856. else
  857. ClearText:=false;
  858. end;
  859. function GraphResult:Integer;
  860. begin
  861. GraphResult:=_graphresult;
  862. end;
  863. procedure RestoreCRTMode;
  864. begin
  865. if not isgraphmode then
  866. begin
  867. _graphresult:=grNoInitGraph;
  868. Exit;
  869. end;
  870. OldCRTMode:=GetGraphMode;
  871. InTempCRTMode:=true;
  872. SetVESAMode(startmode);
  873. isgraphmode:=false;
  874. end;
  875. var PrevExitProc : pointer;
  876. procedure GraphExit;
  877. begin
  878. ExitProc:=PrevExitProc;
  879. CloseGraph;
  880. DoneVesa; { frees the ldt descriptors seg_read and seg_write !! }
  881. end;
  882. begin
  883. InitVESA;
  884. if not DetectVESA then
  885. GraphFault('VESA-BIOS not found...');
  886. startmode:=GetVESAMode;
  887. PrevExitProc:=ExitProc;
  888. ExitProc:=@GraphExit;
  889. bankswitchptr:=@switchbank;
  890. GraphGetMemPtr:[email protected];
  891. GraphFreeMemPtr:[email protected];
  892. Getdefaultfont;
  893. if not isDPMI then begin
  894. wrbuffer:=pointer($D0000000);
  895. rbuffer:=pointer($D0200000);
  896. wbuffer:=pointer($D0200000);
  897. end else begin
  898. wrbuffer:=pointer($0);
  899. rbuffer:=pointer($0);
  900. wbuffer:=pointer($0);
  901. end;
  902. AktPageOffset:=0;
  903. AktPage:=0;
  904. AktVisualPage:=0;
  905. end.
  906. {
  907. $Log$
  908. Revision 1.5 1999-05-04 17:17:31 florian
  909. * some explicit language removed
  910. Revision 1.4 1999/04/08 12:23:00 peter
  911. * removed os.inc
  912. Revision 1.3 1999/03/02 13:56:34 peter
  913. * use ATT assembler in profile
  914. * use AS output in graph
  915. Revision 1.2 1999/02/01 13:19:01 pierre
  916. * getgraphmode returns -1 if not in graphic mode
  917. Revision 1.1 1998/12/21 13:07:03 peter
  918. * use -FE
  919. Revision 1.15 1998/12/15 22:42:50 peter
  920. * removed temp symbols
  921. Revision 1.14 1998/11/25 22:59:23 pierre
  922. * fillpoly works
  923. Revision 1.13 1998/11/25 13:04:43 pierre
  924. + added multi page support
  925. Revision 1.12 1998/11/23 10:04:16 pierre
  926. * pieslice and sector work now !!
  927. * bugs in text writing removed
  928. + scaling for defaultfont added
  929. + VertDir for default font added
  930. * RestoreCRTMode corrected
  931. Revision 1.11 1998/11/20 18:42:04 pierre
  932. * many bugs related to floodfill and ellipse fixed
  933. Revision 1.10 1998/11/20 10:16:01 pierre
  934. * Found out the LinerFrameBuffer problem
  935. Was an alignment problem in VesaInfoBlock (see graph.pp file)
  936. Compile with -dDEBUG and answer 'y' to 'Use Linear ?' to test
  937. Revision 1.9 1998/11/19 15:09:33 pierre
  938. * several bugfixes for sector/ellipse/floodfill
  939. + graphic driver mode const in interface G800x600x256...
  940. + added backput mode as in linux graph.pp
  941. (clears the background of textoutput)
  942. Revision 1.8 1998/11/19 09:48:45 pierre
  943. + added some functions missing like sector ellipse getarccoords
  944. (the filling of sector and ellipse is still buggy
  945. I use floodfill but sometimes the starting point
  946. is outside !!)
  947. * fixed a bug in floodfill for patterns
  948. (still has problems !!)
  949. Revision 1.7 1998/11/18 09:31:29 pierre
  950. * changed color scheme
  951. all colors are in RGB format if more than 256 colors
  952. + added 24 and 32 bits per pixel mode
  953. (compile with -dDEBUG)
  954. 24 bit mode with banked still as problems on pixels across
  955. the bank boundary, but works in LinearFrameBufferMode
  956. Look at install/demo/nmandel.pp
  957. Revision 1.6 1998/10/22 09:44:57 pierre
  958. * PatternBuffer was not set on entry !!
  959. Revision 1.5 1998/09/16 16:47:25 peter
  960. * merged fixes
  961. Revision 1.4.2.1 1998/09/16 16:15:41 peter
  962. * no smartlinking!
  963. Revision 1.4 1998/05/31 14:18:14 peter
  964. * force att or direct assembling
  965. * cleanup of some files
  966. Revision 1.3 1998/05/22 00:39:23 peter
  967. * go32v1, go32v2 recompiles with the new objects
  968. * remake3 works again with go32v2
  969. - removed some "optimizes" from daniel which were wrong
  970. }