2
0

graph.pp 28 KB

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