graph.pp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080
  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. Exit;
  466. end;
  467. GetGraphMode:=GetVesaMode;
  468. end;
  469. procedure ClearViewport;
  470. var bank1,bank2,diff,c:longint;
  471. ofs1,ofs2 :longint;
  472. y : integer;
  473. storewritemode : word;
  474. begin
  475. if not isgraphmode then
  476. begin
  477. _graphresult:=grNoInitGraph;
  478. Exit;
  479. end;
  480. c:=aktcolor;
  481. aktcolor:=aktbackcolor;
  482. storewritemode:=aktwritemode;
  483. aktwritemode:=normalput;
  484. ofs1:=Y_ARRAY[aktviewport.y1] + X_ARRAY[aktviewport.x1];
  485. ofs2:=Y_ARRAY[aktviewport.y1] + X_ARRAY[aktviewport.x2];
  486. for y:=aktviewport.y1 to aktviewport.y2 do
  487. begin
  488. bank1:=ofs1 shr winshift;
  489. bank2:=ofs2 shr winshift;
  490. if bank1 <> A_BANK then
  491. begin
  492. Switchbank(bank1);
  493. end;
  494. if bank1 <> bank2 then
  495. begin
  496. diff:=((bank2 shl winshift)-ofs1) div BytesPerPixel;
  497. horizontalline(aktviewport.x1, aktviewport.x1+diff-1, y);
  498. Switchbank(bank2);
  499. horizontalline(aktviewport.x1+diff, aktviewport.x2, y);
  500. end else horizontalline(aktviewport.x1, aktviewport.x2, y);
  501. ofs1:=ofs1 + BytesPerLine;
  502. ofs2:=ofs2 + BytesPerLine;
  503. end;
  504. aktwritemode:=storewritemode;
  505. aktcolor:=c;
  506. end;
  507. procedure GetAspectRatio(var _Xasp,_Yasp : word);
  508. begin
  509. _graphresult:=grOk;
  510. if not isgraphmode then
  511. begin
  512. _graphresult:=grnoinitgraph;
  513. exit;
  514. end;
  515. _XAsp:=XAsp; _YAsp:=YAsp;
  516. end;
  517. procedure SetAspectRatio(_Xasp, _Yasp : word);
  518. begin
  519. _graphresult:=grOk;
  520. if not isgraphmode then
  521. begin
  522. _graphresult:=grnoinitgraph;
  523. exit;
  524. end;
  525. Xasp:=_XAsp; YAsp:=_YAsp;
  526. end;
  527. procedure ClearDevice;
  528. var Viewport:ViewportType;
  529. begin
  530. if not isgraphmode then
  531. begin
  532. _graphresult:=grNoInitGraph;
  533. Exit;
  534. end;
  535. Viewport:=aktviewport;
  536. SetViewport(0,0,_maxx-1,_maxy-1,Clipon);
  537. ClearViewport;
  538. aktviewport:=viewport;
  539. end;
  540. procedure Rectangle(x1,y1,x2,y2:integer);
  541. begin
  542. if not isgraphmode then
  543. begin
  544. _graphresult:=grNoInitGraph;
  545. Exit;
  546. end;
  547. Line(x1,y1,x2,y1);
  548. Line(x1,y1,x1,y2);
  549. Line(x2,y1,x2,y2);
  550. Line(x1,y2,x2,y2);
  551. end;
  552. procedure Bar(x1,y1,x2,y2:integer);
  553. var y : Integer;
  554. origcolor : longint;
  555. origlinesettings: Linesettingstype;
  556. begin
  557. if not isgraphmode then
  558. begin
  559. _graphresult:=grNoInitGraph;
  560. Exit;
  561. end;
  562. origlinesettings:=aktlineinfo;
  563. origcolor:=aktcolor;
  564. aktlineinfo.linestyle:=solidln;
  565. aktlineinfo.thickness:=normwidth;
  566. case aktfillsettings.pattern of
  567. emptyfill : begin
  568. aktcolor:=aktbackcolor;
  569. for y:=y1 to y2 do line(x1,y,x2,y);
  570. end;
  571. solidfill : begin
  572. aktcolor:=aktfillsettings.color;
  573. for y:=y1 to y2 do line(x1,y,x2,y);
  574. end;
  575. else for y:=y1 to y2 do patternline(x1,x2,y);
  576. end;
  577. aktcolor:=origcolor;
  578. aktlineinfo:=origlinesettings;
  579. end;
  580. procedure bar3D(x1, y1, x2, y2 : integer;depth : word;top : boolean);
  581. begin
  582. if not isgraphmode then
  583. begin
  584. _graphresult:=grNoInitGraph;
  585. Exit;
  586. end;
  587. Bar(x1,y1,x2,y2);
  588. Rectangle(x1,y1,x2,y2);
  589. if top then begin
  590. Moveto(x1,y1);
  591. Lineto(x1+depth,y1-depth);
  592. Lineto(x2+depth,y1-depth);
  593. Lineto(x2,y1);
  594. end;
  595. Moveto(x2+depth,y1-depth);
  596. Lineto(x2+depth,y2-depth);
  597. Lineto(x2,y2);
  598. end;
  599. procedure SetGraphBufSize(BufSize : longint);
  600. begin
  601. if assigned(buffermem) then
  602. freemem(buffermem,buffersize);
  603. getmem(buffermem,bufsize);
  604. if not assigned(buffermem) then
  605. buffersize:=0
  606. else buffersize:=bufsize;
  607. end;
  608. const
  609. { Vorgabegr”áe f�r Hilfsspeicher }
  610. bufferstandardsize = 64*8196; { 0,5 MB }
  611. procedure CloseGraph;
  612. begin
  613. if isgraphmode then
  614. begin
  615. SetVESAMode(startmode);
  616. { DoneVESA; only in exitproc !! PM }
  617. isgraphmode:=false;
  618. if assigned(buffermem) then
  619. freemem(buffermem,buffersize);
  620. buffermem:=nil;
  621. buffersize:=0;
  622. end;
  623. end;
  624. procedure SetArrays;
  625. var
  626. index:Integer;
  627. begin
  628. for index:=0 to VESAInfo.XResolution do
  629. X_Array[index]:=index * BytesPerPixel;
  630. for index:=0 to VESAInfo.YResolution do
  631. Y_Array[index]:=index * BytesPerLine + AktPageOffset;
  632. end;
  633. procedure InitGraph(var GraphDriver:Integer;var GraphMode:Integer;const PathToDriver:String);
  634. var i : Integer;
  635. begin
  636. { Pfad zu den Fonts }
  637. bgipath:=PathToDriver;
  638. if bgipath[length(bgipath)]<>'\' then
  639. bgipath:=bgipath+'\';
  640. if Graphdriver=detect then GraphMode:=GetMaxMode;
  641. { Standardfonts installieren }
  642. InstallUserFont('TRIP');
  643. InstallUserFont('LITT');
  644. InstallUserFont('SANS');
  645. InstallUserFont('GOTH');
  646. InstallUserFont('SCRI');
  647. InstallUserFont('SIMP');
  648. InstallUserFont('TSCR');
  649. InstallUserFont('LCOM');
  650. InstallUserFont('EURO');
  651. InstallUserFont('BOLD');
  652. GetVESAInfo(GraphMode);
  653. {$IFDEF DEBUG}
  654. {$I VESADEB.PPI}
  655. {$ENDIF}
  656. for i:=VESANumber downto 0 do
  657. if GraphMode=VESAModes[i] then break;
  658. { the modes can be refused due to the monitor ? }
  659. { that happens by me at home Pierre Muller }
  660. while i>=0 do begin
  661. isgraphmode:=SetVESAMode(GraphMode);
  662. if isgraphmode then begin
  663. GetVESAInfo(GraphMode);
  664. if UseLinearFrameBuffer then
  665. isgraphmode:=SetVESAMode(GraphMode or EnableLinearFrameBuffer);
  666. { set zero page }
  667. AktPageOffset:=0;
  668. SetActivePage(0);
  669. SetVisualPage(0);
  670. SetArrays;
  671. SetGraphBufSize(bufferstandardsize);
  672. graphdefaults;
  673. InTempCRTMode:=false;
  674. exit;
  675. end;
  676. dec(i);
  677. GraphMode:=VESAModes[i];
  678. end;
  679. _graphresult:=grInvalidMode
  680. end;
  681. procedure SetGraphMode(GraphMode:Integer);
  682. begin
  683. _graphresult:=grOk;
  684. if not isgraphmode and not InTempCRTMode then
  685. begin
  686. _graphresult:=grNoInitGraph;
  687. Exit;
  688. end;
  689. if GetVesaInfo(GraphMode) then
  690. begin
  691. isgraphmode:=SetVESAMode(GraphMode);
  692. if isgraphmode then
  693. begin
  694. if UseLinearFrameBuffer then
  695. isgraphmode:=SetVESAMode(GraphMode or EnableLinearFrameBuffer);
  696. { set zero page }
  697. AktPageOffset:=0;
  698. SetActivePage(0);
  699. SetVisualPage(0);
  700. SetArrays;
  701. graphdefaults;
  702. InTempCRTMode:=false;
  703. exit;
  704. end;
  705. end;
  706. _graphresult:=grInvalidMode;
  707. end;
  708. function RegisterBGIdriver(driver : pointer) : integer;
  709. begin
  710. RegisterBGIdriver:=grerror;
  711. end;
  712. function InstallUserDriver(const DriverFileName : string;AutoDetectPtr : pointer) : integer;
  713. begin
  714. installuserdriver:=grerror;
  715. end;
  716. function GetMaxMode:Integer;
  717. var i:Byte;
  718. begin
  719. for i:=VESANumber downto 0 do
  720. if GetVesaInfo(VESAModes[i]) then
  721. begin
  722. GetMaxMode:=VESAModes[i];
  723. Exit;
  724. end;
  725. end;
  726. function GetMaxX:Integer;
  727. begin
  728. if not isgraphmode then
  729. begin
  730. _graphresult:=grNoInitGraph;
  731. Exit;
  732. end;
  733. GetMaxX:=VESAInfo.XResolution-1;
  734. end;
  735. function GetMaxY:Integer;
  736. begin
  737. if not isgraphmode then
  738. begin
  739. _graphresult:=grNoInitGraph;
  740. Exit;
  741. end;
  742. GetMaxY:=VESAInfo.YResolution-1;
  743. end;
  744. function GetX : integer;
  745. begin
  746. _graphresult:=grOk;
  747. if not isgraphmode then
  748. begin
  749. _graphresult:=grNoInitGraph;
  750. Exit;
  751. end;
  752. GetX:=curx;
  753. end;
  754. function GetY : integer;
  755. begin
  756. _graphresult:=grOk;
  757. if not isgraphmode then
  758. begin
  759. _graphresult:=grNoInitGraph;
  760. Exit;
  761. end;
  762. GetY:=cury;
  763. end;
  764. procedure SetViewPort(x1,y1,x2,y2 : integer;clip : boolean);
  765. begin
  766. _graphresult:=grOk;
  767. if not isgraphmode then
  768. begin
  769. _graphresult:=grNoInitGraph;
  770. exit;
  771. end;
  772. { Daten �berpr�fen }
  773. if (x1<0) or (y1<0) or (x2>=_maxx) or (y2>=_maxy) then exit;
  774. aktviewport.x1:=x1;
  775. aktviewport.y1:=y1;
  776. aktviewport.x2:=x2;
  777. aktviewport.y2:=y2;
  778. aktviewport.clip:=clip;
  779. end;
  780. procedure GetViewSettings(var viewport : ViewPortType);
  781. begin
  782. _graphresult:=grOk;
  783. if not isgraphmode then
  784. begin
  785. _graphresult:=grNoInitGraph;
  786. exit;
  787. end;
  788. viewport:=aktviewport;
  789. end;
  790. { mehrere Bildschirmseiten werden nicht unterst�tzt }
  791. { Dummy aus Kompatibilit„tsgr�nden }
  792. procedure SetVisualPage(page : word);
  793. begin
  794. _graphresult:=grOk;
  795. if not isgraphmode then
  796. begin
  797. _graphresult:=grNoInitGraph;;
  798. exit;
  799. end
  800. else if (Page<VESAInfo.NumberOfPages) and (AktVisualPage<>Page) then
  801. begin
  802. SetVESADisplayStart(Page,0,0);
  803. {SetDisplayPage(Page);}
  804. AktVisualPage:=Page;
  805. end;
  806. end;
  807. function GetVisualPage : word;
  808. begin
  809. GetVisualPage:=AktVisualPage;
  810. end;
  811. function GetActivePage : word;
  812. begin
  813. GetActivePage:=AktPage;
  814. end;
  815. { mehrere Bildschirmseiten werden nicht unterst�tzt }
  816. { Dummy aus Kompatibilit„tsgr�nden }
  817. procedure SetActivePage(page : word);
  818. begin
  819. _graphresult:=grOk;
  820. if not isgraphmode then
  821. begin
  822. _graphresult:=grNoInitGraph;;
  823. exit;
  824. end
  825. else if (Page<VESAInfo.NumberOfPages) and (Page<>AktPage) then
  826. begin
  827. AktPageOffset:=Page*BytesPerLine*_maxy;
  828. AktPage:=Page;
  829. SetArrays;
  830. end;
  831. end;
  832. function GetNumberOfPages : word;
  833. begin
  834. GetNumberOfPages:=VESAInfo.NumberOfPages;
  835. end;
  836. procedure SetWriteMode(WriteMode : integer);
  837. begin
  838. _graphresult:=grOk;
  839. if not isgraphmode then
  840. begin
  841. _graphresult:=grNoInitGraph;;
  842. exit;
  843. end;
  844. if ((writemode and 7)<>xorput) and ((writemode and 7)<>normalput) then
  845. begin
  846. _graphresult:=grError;
  847. exit;
  848. end;
  849. aktwritemode:=(writemode and 7);
  850. if (writemode and BackPut)<>0 then
  851. ClearText:=true
  852. else
  853. ClearText:=false;
  854. end;
  855. function GraphResult:Integer;
  856. begin
  857. GraphResult:=_graphresult;
  858. end;
  859. procedure RestoreCRTMode;
  860. begin
  861. if not isgraphmode then
  862. begin
  863. _graphresult:=grNoInitGraph;
  864. Exit;
  865. end;
  866. OldCRTMode:=GetGraphMode;
  867. InTempCRTMode:=true;
  868. SetVESAMode(startmode);
  869. isgraphmode:=false;
  870. end;
  871. var PrevExitProc : pointer;
  872. procedure GraphExit;
  873. begin
  874. ExitProc:=PrevExitProc;
  875. CloseGraph;
  876. DoneVesa; { frees the ldt descriptors seg_read and seg_write !! }
  877. end;
  878. begin
  879. InitVESA;
  880. if not DetectVESA then
  881. Oh_Kacke('VESA-BIOS not found...');
  882. startmode:=GetVESAMode;
  883. PrevExitProc:=ExitProc;
  884. ExitProc:=@GraphExit;
  885. bankswitchptr:=@switchbank;
  886. GraphGetMemPtr:[email protected];
  887. GraphFreeMemPtr:[email protected];
  888. Getdefaultfont;
  889. if not isDPMI then begin
  890. wrbuffer:=pointer($D0000000);
  891. rbuffer:=pointer($D0200000);
  892. wbuffer:=pointer($D0200000);
  893. end else begin
  894. wrbuffer:=pointer($0);
  895. rbuffer:=pointer($0);
  896. wbuffer:=pointer($0);
  897. end;
  898. AktPageOffset:=0;
  899. AktPage:=0;
  900. AktVisualPage:=0;
  901. end.
  902. {
  903. $Log$
  904. Revision 1.1 1998-12-21 13:07:03 peter
  905. * use -FE
  906. Revision 1.15 1998/12/15 22:42:50 peter
  907. * removed temp symbols
  908. Revision 1.14 1998/11/25 22:59:23 pierre
  909. * fillpoly works
  910. Revision 1.13 1998/11/25 13:04:43 pierre
  911. + added multi page support
  912. Revision 1.12 1998/11/23 10:04:16 pierre
  913. * pieslice and sector work now !!
  914. * bugs in text writing removed
  915. + scaling for defaultfont added
  916. + VertDir for default font added
  917. * RestoreCRTMode corrected
  918. Revision 1.11 1998/11/20 18:42:04 pierre
  919. * many bugs related to floodfill and ellipse fixed
  920. Revision 1.10 1998/11/20 10:16:01 pierre
  921. * Found out the LinerFrameBuffer problem
  922. Was an alignment problem in VesaInfoBlock (see graph.pp file)
  923. Compile with -dDEBUG and answer 'y' to 'Use Linear ?' to test
  924. Revision 1.9 1998/11/19 15:09:33 pierre
  925. * several bugfixes for sector/ellipse/floodfill
  926. + graphic driver mode const in interface G800x600x256...
  927. + added backput mode as in linux graph.pp
  928. (clears the background of textoutput)
  929. Revision 1.8 1998/11/19 09:48:45 pierre
  930. + added some functions missing like sector ellipse getarccoords
  931. (the filling of sector and ellipse is still buggy
  932. I use floodfill but sometimes the starting point
  933. is outside !!)
  934. * fixed a bug in floodfill for patterns
  935. (still has problems !!)
  936. Revision 1.7 1998/11/18 09:31:29 pierre
  937. * changed color scheme
  938. all colors are in RGB format if more than 256 colors
  939. + added 24 and 32 bits per pixel mode
  940. (compile with -dDEBUG)
  941. 24 bit mode with banked still as problems on pixels across
  942. the bank boundary, but works in LinearFrameBufferMode
  943. Look at install/demo/nmandel.pp
  944. Revision 1.6 1998/10/22 09:44:57 pierre
  945. * PatternBuffer was not set on entry !!
  946. Revision 1.5 1998/09/16 16:47:25 peter
  947. * merged fixes
  948. Revision 1.4.2.1 1998/09/16 16:15:41 peter
  949. * no smartlinking!
  950. Revision 1.4 1998/05/31 14:18:14 peter
  951. * force att or direct assembling
  952. * cleanup of some files
  953. Revision 1.3 1998/05/22 00:39:23 peter
  954. * go32v1, go32v2 recompiles with the new objects
  955. * remake3 works again with go32v2
  956. - removed some "optimizes" from daniel which were wrong
  957. }