graph.pp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077
  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. bankswitchptr :pointer;
  312. isDPMI :Boolean;
  313. SwitchCS,SwitchIP : word;
  314. function ColorsEqual(c1,c2 : longint) : boolean;
  315. Begin
  316. ColorsEqual:=((BytesPerPixel=1) and ((c1 and $FF)=(c2 and $FF))) or
  317. ((GetMaxColor=$7FFF) and ((c1 and $F8F8F8)=(c2 and $F8F8F8))) or
  318. ((GetMaxColor=$FFFF) and ((c1 and $F8FCF8)=(c2 and $F8FCF8))) or
  319. ((BytesPerPixel>2) and ((c1 and $FFFFFF)=(c2 and $FFFFFF)));
  320. End;
  321. function GraphErrorMsg(ErrorCode: Integer): string;
  322. Begin
  323. GraphErrorMsg:='';
  324. case ErrorCode of
  325. grOk,grFileNotFound,grInvalidDriver: exit;
  326. grNoInitGraph: GraphErrorMsg:='Graphics driver not installed';
  327. grNotDetected: GraphErrorMsg:='Graphics hardware not detected';
  328. grNoLoadMem,grNoScanMem,grNoFloodMem: GraphErrorMsg := 'Not enough memory for graphics';
  329. grNoFontMem: GraphErrorMsg := 'Not enough memory to load font';
  330. grFontNotFound: GraphErrorMsg:= 'Font file not found';
  331. grInvalidMode: GraphErrorMsg := 'Invalid graphics mode';
  332. grError: GraphErrorMsg:='Graphics error';
  333. grIoError: GraphErrorMsg:='Graphics I/O error';
  334. grInvalidFont,grInvalidFontNum: GraphErrorMsg := 'Invalid font';
  335. grInvalidVersion: GraphErrorMsg:='Invalid driver version';
  336. end;
  337. end;
  338. procedure GraphFault(ErrString:String);
  339. begin
  340. CloseGraph;
  341. writeln('Error in Unit VESA: ',ErrString);
  342. halt;
  343. end;
  344. {$I MOVE.PPI}
  345. {$I IBM.PPI}
  346. procedure WaitRetrace;
  347. begin
  348. asm
  349. cli
  350. movw $0x03Da,%dx
  351. .LWaitNotHSyncLoop:
  352. inb %dx,%al
  353. testb $0x8,%al
  354. jnz .LWaitNotHSyncLoop
  355. .LWaitHSyncLoop:
  356. inb %dx,%al
  357. testb $0x8,%al
  358. jz .LWaitHSyncLoop
  359. sti
  360. end;
  361. end;
  362. {$I COLORS.PPI}
  363. procedure graphdefaults;
  364. begin
  365. _graphresult:=grOk;
  366. if not isgraphmode then
  367. begin
  368. _graphresult:=grnoinitgraph;
  369. exit;
  370. end;
  371. { Linientyp }
  372. aktlineinfo.linestyle:=solidln;
  373. aktlineinfo.thickness:=normwidth;
  374. { std colors }
  375. setstdcolors;
  376. { Zeichenfarbe }
  377. setcolor(white);
  378. setbkcolor(black);
  379. { F�llmuster }
  380. setfillstyle(solidfill,white);
  381. { necessary to load patternbuffer !! (PM)
  382. aktfillsettings.color:=white;
  383. aktfillsettings.pattern:=solidfill; }
  384. { Viewport setzen }
  385. aktviewport.clip:=true;
  386. aktviewport.x1:=0;
  387. aktviewport.y1:=0;
  388. aktviewport.x2:=_maxx-1;
  389. aktviewport.y2:=_maxy-1;
  390. aktscreen:=aktviewport;
  391. { normaler Schreibmodus }
  392. setwritemode(normalput);
  393. { Schriftart einstellen }
  394. akttextinfo.font:=DefaultFont;
  395. akttextinfo.direction:=HorizDir;
  396. akttextinfo.charsize:=1;
  397. akttextinfo.horiz:=LeftText;
  398. akttextinfo.vert:=TopText;
  399. { VergrӇerungsfaktoren}
  400. XAsp:=10000; YAsp:=10000;
  401. aspectratio:=1;
  402. end;
  403. { ############################################################### }
  404. { ################# Ende der internen Routinen ################ }
  405. { ############################################################### }
  406. {$I PALETTE.PPI}
  407. {$I PIXEL.PPI}
  408. {$I LINE.PPI}
  409. {$I ELLIPSE.PPI}
  410. {$I TRIANGLE.PPI}
  411. {$I ARC.PPI}
  412. {$I IMAGE.PPI}
  413. {$I TEXT.PPI}
  414. {$I FILL.PPI}
  415. function GetDrivername:String;
  416. begin
  417. if not isgraphmode then
  418. begin
  419. _graphresult:=grNoInitGraph;
  420. Exit;
  421. end;
  422. GetDriverName:=('internal VESA-Driver');
  423. end;
  424. function GetModeName(Mode:Integer):String;
  425. var s1,s2,s3:string;
  426. begin
  427. if not isgraphmode then
  428. begin
  429. _graphresult:=grNoInitGraph;
  430. Exit;
  431. end;
  432. str(_maxx,s1);
  433. str(_maxy,s2);
  434. str(getmaxcolor+1,s3);
  435. GetModeName:=('VESA '+s1+'x'+s2+'x'+s3);
  436. end;
  437. function GetGraphMode:Integer;
  438. begin
  439. if InTempCRTMode then
  440. begin
  441. GetGraphMode:=oldCRTMode;
  442. exit;
  443. end;
  444. if not isgraphmode then
  445. begin
  446. _graphresult:=grNoInitGraph;
  447. GetGraphMode:=grNoInitGraph;
  448. Exit;
  449. end;
  450. GetGraphMode:=GetVesaMode;
  451. end;
  452. procedure ClearViewport;
  453. var bank1,bank2,diff,c:longint;
  454. ofs1,ofs2 :longint;
  455. y : integer;
  456. storewritemode : word;
  457. begin
  458. if not isgraphmode then
  459. begin
  460. _graphresult:=grNoInitGraph;
  461. Exit;
  462. end;
  463. c:=aktcolor;
  464. aktcolor:=aktbackcolor;
  465. storewritemode:=aktwritemode;
  466. aktwritemode:=normalput;
  467. ofs1:=Y_ARRAY[aktviewport.y1] + X_ARRAY[aktviewport.x1];
  468. ofs2:=Y_ARRAY[aktviewport.y1] + X_ARRAY[aktviewport.x2];
  469. for y:=aktviewport.y1 to aktviewport.y2 do
  470. begin
  471. bank1:=ofs1 shr winshift;
  472. bank2:=ofs2 shr winshift;
  473. if bank1 <> A_BANK then
  474. begin
  475. Switchbank(bank1);
  476. end;
  477. if bank1 <> bank2 then
  478. begin
  479. diff:=((bank2 shl winshift)-ofs1) div BytesPerPixel;
  480. horizontalline(aktviewport.x1, aktviewport.x1+diff-1, y);
  481. Switchbank(bank2);
  482. horizontalline(aktviewport.x1+diff, aktviewport.x2, y);
  483. end else horizontalline(aktviewport.x1, aktviewport.x2, y);
  484. ofs1:=ofs1 + BytesPerLine;
  485. ofs2:=ofs2 + BytesPerLine;
  486. end;
  487. aktwritemode:=storewritemode;
  488. aktcolor:=c;
  489. end;
  490. procedure GetAspectRatio(var _Xasp,_Yasp : word);
  491. begin
  492. _graphresult:=grOk;
  493. if not isgraphmode then
  494. begin
  495. _graphresult:=grnoinitgraph;
  496. exit;
  497. end;
  498. _XAsp:=XAsp; _YAsp:=YAsp;
  499. end;
  500. procedure SetAspectRatio(_Xasp, _Yasp : word);
  501. begin
  502. _graphresult:=grOk;
  503. if not isgraphmode then
  504. begin
  505. _graphresult:=grnoinitgraph;
  506. exit;
  507. end;
  508. Xasp:=_XAsp; YAsp:=_YAsp;
  509. end;
  510. procedure ClearDevice;
  511. var Viewport:ViewportType;
  512. begin
  513. if not isgraphmode then
  514. begin
  515. _graphresult:=grNoInitGraph;
  516. Exit;
  517. end;
  518. Viewport:=aktviewport;
  519. SetViewport(0,0,_maxx-1,_maxy-1,Clipon);
  520. ClearViewport;
  521. aktviewport:=viewport;
  522. end;
  523. procedure Rectangle(x1,y1,x2,y2:integer);
  524. begin
  525. if not isgraphmode then
  526. begin
  527. _graphresult:=grNoInitGraph;
  528. Exit;
  529. end;
  530. Line(x1,y1,x2,y1);
  531. Line(x1,y1,x1,y2);
  532. Line(x2,y1,x2,y2);
  533. Line(x1,y2,x2,y2);
  534. end;
  535. procedure Bar(x1,y1,x2,y2:integer);
  536. var y : Integer;
  537. origcolor : longint;
  538. origlinesettings: Linesettingstype;
  539. begin
  540. if not isgraphmode then
  541. begin
  542. _graphresult:=grNoInitGraph;
  543. Exit;
  544. end;
  545. origlinesettings:=aktlineinfo;
  546. origcolor:=aktcolor;
  547. aktlineinfo.linestyle:=solidln;
  548. aktlineinfo.thickness:=normwidth;
  549. case aktfillsettings.pattern of
  550. emptyfill : begin
  551. aktcolor:=aktbackcolor;
  552. for y:=y1 to y2 do line(x1,y,x2,y);
  553. end;
  554. solidfill : begin
  555. aktcolor:=aktfillsettings.color;
  556. for y:=y1 to y2 do line(x1,y,x2,y);
  557. end;
  558. else for y:=y1 to y2 do patternline(x1,x2,y);
  559. end;
  560. aktcolor:=origcolor;
  561. aktlineinfo:=origlinesettings;
  562. end;
  563. procedure bar3D(x1, y1, x2, y2 : integer;depth : word;top : boolean);
  564. begin
  565. if not isgraphmode then
  566. begin
  567. _graphresult:=grNoInitGraph;
  568. Exit;
  569. end;
  570. Bar(x1,y1,x2,y2);
  571. Rectangle(x1,y1,x2,y2);
  572. if top then begin
  573. Moveto(x1,y1);
  574. Lineto(x1+depth,y1-depth);
  575. Lineto(x2+depth,y1-depth);
  576. Lineto(x2,y1);
  577. end;
  578. Moveto(x2+depth,y1-depth);
  579. Lineto(x2+depth,y2-depth);
  580. Lineto(x2,y2);
  581. end;
  582. procedure SetGraphBufSize(BufSize : longint);
  583. begin
  584. if assigned(buffermem) then
  585. freemem(buffermem,buffersize);
  586. getmem(buffermem,bufsize);
  587. if not assigned(buffermem) then
  588. buffersize:=0
  589. else buffersize:=bufsize;
  590. end;
  591. const
  592. { Vorgabegr”áe f�r Hilfsspeicher }
  593. bufferstandardsize = 64*8196; { 0,5 MB }
  594. procedure CloseGraph;
  595. begin
  596. if isgraphmode then
  597. begin
  598. SetVESAMode(startmode);
  599. { DoneVESA; only in exitproc !! PM }
  600. isgraphmode:=false;
  601. if assigned(buffermem) then
  602. freemem(buffermem,buffersize);
  603. buffermem:=nil;
  604. buffersize:=0;
  605. end;
  606. end;
  607. procedure SetArrays;
  608. var
  609. index:Integer;
  610. begin
  611. for index:=0 to VESAInfo.XResolution do
  612. X_Array[index]:=index * BytesPerPixel;
  613. for index:=0 to VESAInfo.YResolution do
  614. Y_Array[index]:=index * BytesPerLine + AktPageOffset;
  615. end;
  616. procedure InitGraph(var GraphDriver:Integer;var GraphMode:Integer;const PathToDriver:String);
  617. var i : Integer;
  618. begin
  619. { Pfad zu den Fonts }
  620. bgipath:=PathToDriver;
  621. if bgipath[length(bgipath)]<>'\' then
  622. bgipath:=bgipath+'\';
  623. if Graphdriver=detect then GraphMode:=GetMaxMode;
  624. { Standardfonts installieren }
  625. InstallUserFont('TRIP');
  626. InstallUserFont('LITT');
  627. InstallUserFont('SANS');
  628. InstallUserFont('GOTH');
  629. InstallUserFont('SCRI');
  630. InstallUserFont('SIMP');
  631. InstallUserFont('TSCR');
  632. InstallUserFont('LCOM');
  633. InstallUserFont('EURO');
  634. InstallUserFont('BOLD');
  635. GetVESAInfo(GraphMode);
  636. {$IFDEF DEBUG}
  637. {$I VESADEB.PPI}
  638. {$ENDIF}
  639. for i:=VESANumber downto 0 do
  640. if GraphMode=VESAModes[i] then break;
  641. { the modes can be refused due to the monitor ? }
  642. { that happens by me at home Pierre Muller }
  643. while i>=0 do begin
  644. isgraphmode:=SetVESAMode(GraphMode);
  645. if isgraphmode then begin
  646. GetVESAInfo(GraphMode);
  647. if UseLinearFrameBuffer then
  648. isgraphmode:=SetVESAMode(GraphMode or EnableLinearFrameBuffer);
  649. { set zero page }
  650. AktPageOffset:=0;
  651. SetActivePage(0);
  652. SetVisualPage(0);
  653. SetArrays;
  654. SetGraphBufSize(bufferstandardsize);
  655. graphdefaults;
  656. InTempCRTMode:=false;
  657. exit;
  658. end;
  659. dec(i);
  660. GraphMode:=VESAModes[i];
  661. end;
  662. _graphresult:=grInvalidMode
  663. end;
  664. procedure SetGraphMode(GraphMode:Integer);
  665. begin
  666. _graphresult:=grOk;
  667. if not isgraphmode and not InTempCRTMode then
  668. begin
  669. _graphresult:=grNoInitGraph;
  670. Exit;
  671. end;
  672. if GetVesaInfo(GraphMode) then
  673. begin
  674. isgraphmode:=SetVESAMode(GraphMode);
  675. if isgraphmode then
  676. begin
  677. if UseLinearFrameBuffer then
  678. isgraphmode:=SetVESAMode(GraphMode or EnableLinearFrameBuffer);
  679. { set zero page }
  680. AktPageOffset:=0;
  681. SetActivePage(0);
  682. SetVisualPage(0);
  683. SetArrays;
  684. graphdefaults;
  685. InTempCRTMode:=false;
  686. exit;
  687. end;
  688. end;
  689. _graphresult:=grInvalidMode;
  690. end;
  691. function RegisterBGIdriver(driver : pointer) : integer;
  692. begin
  693. RegisterBGIdriver:=grerror;
  694. end;
  695. function InstallUserDriver(const DriverFileName : string;AutoDetectPtr : pointer) : integer;
  696. begin
  697. installuserdriver:=grerror;
  698. end;
  699. function GetMaxMode:Integer;
  700. var i:Byte;
  701. begin
  702. for i:=VESANumber downto 0 do
  703. if GetVesaInfo(VESAModes[i]) then
  704. begin
  705. GetMaxMode:=VESAModes[i];
  706. Exit;
  707. end;
  708. end;
  709. function GetMaxX:Integer;
  710. begin
  711. if not isgraphmode then
  712. begin
  713. _graphresult:=grNoInitGraph;
  714. Exit;
  715. end;
  716. GetMaxX:=VESAInfo.XResolution-1;
  717. end;
  718. function GetMaxY:Integer;
  719. begin
  720. if not isgraphmode then
  721. begin
  722. _graphresult:=grNoInitGraph;
  723. Exit;
  724. end;
  725. GetMaxY:=VESAInfo.YResolution-1;
  726. end;
  727. function GetX : integer;
  728. begin
  729. _graphresult:=grOk;
  730. if not isgraphmode then
  731. begin
  732. _graphresult:=grNoInitGraph;
  733. Exit;
  734. end;
  735. GetX:=curx;
  736. end;
  737. function GetY : integer;
  738. begin
  739. _graphresult:=grOk;
  740. if not isgraphmode then
  741. begin
  742. _graphresult:=grNoInitGraph;
  743. Exit;
  744. end;
  745. GetY:=cury;
  746. end;
  747. procedure SetViewPort(x1,y1,x2,y2 : integer;clip : boolean);
  748. begin
  749. _graphresult:=grOk;
  750. if not isgraphmode then
  751. begin
  752. _graphresult:=grNoInitGraph;
  753. exit;
  754. end;
  755. { Daten �berpr�fen }
  756. if (x1<0) or (y1<0) or (x2>=_maxx) or (y2>=_maxy) then exit;
  757. aktviewport.x1:=x1;
  758. aktviewport.y1:=y1;
  759. aktviewport.x2:=x2;
  760. aktviewport.y2:=y2;
  761. aktviewport.clip:=clip;
  762. end;
  763. procedure GetViewSettings(var viewport : ViewPortType);
  764. begin
  765. _graphresult:=grOk;
  766. if not isgraphmode then
  767. begin
  768. _graphresult:=grNoInitGraph;
  769. exit;
  770. end;
  771. viewport:=aktviewport;
  772. end;
  773. { mehrere Bildschirmseiten werden nicht unterst�tzt }
  774. { Dummy aus Kompatibilit„tsgr�nden }
  775. procedure SetVisualPage(page : word);
  776. begin
  777. _graphresult:=grOk;
  778. if not isgraphmode then
  779. begin
  780. _graphresult:=grNoInitGraph;;
  781. exit;
  782. end
  783. else if (Page<VESAInfo.NumberOfPages) and (AktVisualPage<>Page) then
  784. begin
  785. SetVESADisplayStart(Page,0,0);
  786. {SetDisplayPage(Page);}
  787. AktVisualPage:=Page;
  788. end;
  789. end;
  790. function GetVisualPage : word;
  791. begin
  792. GetVisualPage:=AktVisualPage;
  793. end;
  794. function GetActivePage : word;
  795. begin
  796. GetActivePage:=AktPage;
  797. end;
  798. { mehrere Bildschirmseiten werden nicht unterst�tzt }
  799. { Dummy aus Kompatibilit„tsgr�nden }
  800. procedure SetActivePage(page : word);
  801. begin
  802. _graphresult:=grOk;
  803. if not isgraphmode then
  804. begin
  805. _graphresult:=grNoInitGraph;;
  806. exit;
  807. end
  808. else if (Page<VESAInfo.NumberOfPages) and (Page<>AktPage) then
  809. begin
  810. AktPageOffset:=Page*BytesPerLine*_maxy;
  811. AktPage:=Page;
  812. SetArrays;
  813. end;
  814. end;
  815. function GetNumberOfPages : word;
  816. begin
  817. GetNumberOfPages:=VESAInfo.NumberOfPages;
  818. end;
  819. procedure SetWriteMode(WriteMode : integer);
  820. begin
  821. _graphresult:=grOk;
  822. if not isgraphmode then
  823. begin
  824. _graphresult:=grNoInitGraph;;
  825. exit;
  826. end;
  827. if ((writemode and 7)<>xorput) and ((writemode and 7)<>normalput) then
  828. begin
  829. _graphresult:=grError;
  830. exit;
  831. end;
  832. aktwritemode:=(writemode and 7);
  833. if (writemode and BackPut)<>0 then
  834. ClearText:=true
  835. else
  836. ClearText:=false;
  837. end;
  838. function GraphResult:Integer;
  839. begin
  840. GraphResult:=_graphresult;
  841. end;
  842. procedure RestoreCRTMode;
  843. begin
  844. if not isgraphmode then
  845. begin
  846. _graphresult:=grNoInitGraph;
  847. Exit;
  848. end;
  849. OldCRTMode:=GetGraphMode;
  850. InTempCRTMode:=true;
  851. SetVESAMode(startmode);
  852. isgraphmode:=false;
  853. end;
  854. var PrevExitProc : pointer;
  855. procedure GraphExit;
  856. begin
  857. ExitProc:=PrevExitProc;
  858. CloseGraph;
  859. DoneVesa; { frees the ldt descriptors seg_read and seg_write !! }
  860. end;
  861. begin
  862. InitVESA;
  863. if not DetectVESA then
  864. GraphFault('VESA-BIOS not found...');
  865. startmode:=GetVESAMode;
  866. PrevExitProc:=ExitProc;
  867. ExitProc:=@GraphExit;
  868. bankswitchptr:=@switchbank;
  869. Getdefaultfont;
  870. if not isDPMI then begin
  871. wrbuffer:=pointer($D0000000);
  872. rbuffer:=pointer($D0200000);
  873. wbuffer:=pointer($D0200000);
  874. end else begin
  875. wrbuffer:=pointer($0);
  876. rbuffer:=pointer($0);
  877. wbuffer:=pointer($0);
  878. end;
  879. AktPageOffset:=0;
  880. AktPage:=0;
  881. AktVisualPage:=0;
  882. end.
  883. {
  884. $Log$
  885. Revision 1.6 1999-09-08 18:55:29 peter
  886. - graphget/freememptr
  887. Revision 1.5 1999/05/04 17:17:31 florian
  888. * some explicit language removed
  889. Revision 1.4 1999/04/08 12:23:00 peter
  890. * removed os.inc
  891. Revision 1.3 1999/03/02 13:56:34 peter
  892. * use ATT assembler in profile
  893. * use AS output in graph
  894. Revision 1.2 1999/02/01 13:19:01 pierre
  895. * getgraphmode returns -1 if not in graphic mode
  896. Revision 1.1 1998/12/21 13:07:03 peter
  897. * use -FE
  898. Revision 1.15 1998/12/15 22:42:50 peter
  899. * removed temp symbols
  900. Revision 1.14 1998/11/25 22:59:23 pierre
  901. * fillpoly works
  902. Revision 1.13 1998/11/25 13:04:43 pierre
  903. + added multi page support
  904. Revision 1.12 1998/11/23 10:04:16 pierre
  905. * pieslice and sector work now !!
  906. * bugs in text writing removed
  907. + scaling for defaultfont added
  908. + VertDir for default font added
  909. * RestoreCRTMode corrected
  910. Revision 1.11 1998/11/20 18:42:04 pierre
  911. * many bugs related to floodfill and ellipse fixed
  912. Revision 1.10 1998/11/20 10:16:01 pierre
  913. * Found out the LinerFrameBuffer problem
  914. Was an alignment problem in VesaInfoBlock (see graph.pp file)
  915. Compile with -dDEBUG and answer 'y' to 'Use Linear ?' to test
  916. Revision 1.9 1998/11/19 15:09:33 pierre
  917. * several bugfixes for sector/ellipse/floodfill
  918. + graphic driver mode const in interface G800x600x256...
  919. + added backput mode as in linux graph.pp
  920. (clears the background of textoutput)
  921. Revision 1.8 1998/11/19 09:48:45 pierre
  922. + added some functions missing like sector ellipse getarccoords
  923. (the filling of sector and ellipse is still buggy
  924. I use floodfill but sometimes the starting point
  925. is outside !!)
  926. * fixed a bug in floodfill for patterns
  927. (still has problems !!)
  928. Revision 1.7 1998/11/18 09:31:29 pierre
  929. * changed color scheme
  930. all colors are in RGB format if more than 256 colors
  931. + added 24 and 32 bits per pixel mode
  932. (compile with -dDEBUG)
  933. 24 bit mode with banked still as problems on pixels across
  934. the bank boundary, but works in LinearFrameBufferMode
  935. Look at install/demo/nmandel.pp
  936. Revision 1.6 1998/10/22 09:44:57 pierre
  937. * PatternBuffer was not set on entry !!
  938. Revision 1.5 1998/09/16 16:47:25 peter
  939. * merged fixes
  940. Revision 1.4.2.1 1998/09/16 16:15:41 peter
  941. * no smartlinking!
  942. Revision 1.4 1998/05/31 14:18:14 peter
  943. * force att or direct assembling
  944. * cleanup of some files
  945. Revision 1.3 1998/05/22 00:39:23 peter
  946. * go32v1, go32v2 recompiles with the new objects
  947. * remake3 works again with go32v2
  948. - removed some "optimizes" from daniel which were wrong
  949. }