graph.pp 26 KB

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