ggigraph.inc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team
  5. GGI implementation of graph unit.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$LINKLIB c}
  13. {$PACKRECORDS C}
  14. const
  15. InternalDriverName = 'LinuxGGI';
  16. var
  17. SavePtr: Pointer;
  18. { ---------------------------------------------------------------------
  19. GGI bindings [(c) 1999 Sebastian Guenther]
  20. ---------------------------------------------------------------------}
  21. const
  22. GLASTMODE = 49;
  23. ModeNames: array[0..GLastMode] of PChar =
  24. ('[]', {Let GGI choose a default mode}
  25. 'S320x200[GT_4BIT]',
  26. 'S640x200[GT_4BIT]',
  27. 'S640x350[GT_4BIT]',
  28. 'S640x480[GT_4BIT]',
  29. 'S320x200[GT_8BIT]',
  30. 'S320x240[GT_8BIT]',
  31. 'S320x400[GT_8BIT]',
  32. 'S360x480[GT_8BIT]',
  33. 'S640x480x[GT_1BIT]',
  34. 'S640x480[GT_8BIT]',
  35. 'S800x600[GT_8BIT]',
  36. 'S1024x768[GT_8BIT]',
  37. 'S1280x1024[GT_8BIT]',
  38. 'S320x200[GT_15BIT]',
  39. 'S320x200[GT_16BIT]',
  40. 'S320x200[GT_24BIT]',
  41. 'S640x480[GT_15BIT]',
  42. 'S640x480[GT_16BIT]',
  43. 'S640x480[GT_24BIT]',
  44. 'S800x600[GT_15BIT]',
  45. 'S800x600[GT_16BIT]',
  46. 'S800x600[GT_24BIT]',
  47. 'S1024x768[GT_15BIT]',
  48. 'S1024x768[GT_16BIT]',
  49. 'S1024x768[GT_24BIT]',
  50. 'S1280x1024[GT_15BIT]',
  51. 'S1280x1024[GT_16BIT]',
  52. 'S1280x1024[GT_24BIT]',
  53. 'S800x600[GT_4BIT]',
  54. 'S1024x768[GT_4BIT]',
  55. 'S1280x1024[GT_4BIT]',
  56. 'S720x348x[GT_1BIT]',
  57. 'S320x200[GT_32BIT]',
  58. 'S640x480[GT_32BIT]',
  59. 'S800x600[GT_32BIT]',
  60. 'S1024x768[GT_32BIT]',
  61. 'S1280x1024[GT_32BIT]',
  62. 'S1152x864[GT_4BIT]',
  63. 'S1152x864[gt_8BIT]',
  64. 'S1152x864[GT_15BIT]',
  65. 'S1152x864[GT_16BIT]',
  66. 'S1152x864[GT_24BIT]',
  67. 'S1152x864[GT_32BIT]',
  68. 'S1600x1200[GT_4BIT]',
  69. 'S1600x1200[gt_8BIT]',
  70. 'S1600x1200[GT_15BIT]',
  71. 'S1600x1200[GT_16BIT]',
  72. 'S1600x1200[GT_24BIT]',
  73. 'S1600x1200[GT_32BIT]');
  74. type
  75. TGGIVisual = Pointer;
  76. TGGIResource = Pointer;
  77. TGGICoord = record
  78. x, y: SmallInt;
  79. end;
  80. TGGIPixel = LongWord;
  81. PGGIColor = ^TGGIColor;
  82. TGGIColor = record
  83. r, g, b, a: Word;
  84. end;
  85. PGGIClut = ^TGGIClut;
  86. TGGIClut = record
  87. size: SmallInt;
  88. data: PGGIColor;
  89. end;
  90. TGGIGraphType = LongWord;
  91. TGGIAttr = LongWord;
  92. TGGIMode = record // requested by user and changed by driver
  93. Frames: LongInt; // frames needed
  94. Visible: TGGICoord; // vis. pixels, may change slightly
  95. Virt: TGGICoord; // virtual pixels, may change
  96. Size: TGGICoord; // size of visible in mm
  97. GraphType: TGGIGraphType; // which mode ?
  98. dpp: TGGICoord; // dots per pixel
  99. end;
  100. const
  101. libggi = 'ggi';
  102. function ggiInit: Longint; cdecl; external libggi;
  103. procedure ggiExit; cdecl; external libggi;
  104. function ggiOpen(display: PChar; args: Array of const): TGGIVisual; cdecl; external libggi;
  105. function ggiClose(vis: TGGIVisual): Longint; cdecl; external libggi;
  106. function ggiParseMode(s: PChar; var m: TGGIMode): Longint; cdecl; external libggi;
  107. function ggiSetMode(visual: TGGIVisual; var tm: TGGIMode): Longint; cdecl; external libggi;
  108. function ggiGetMode(visual: TGGIVisual; var tm: TGGIMode): Longint; cdecl; external libggi;
  109. function ggiCheckMode(visual: TGGIVisual; var tm: TGGIMode): Longint; cdecl; external libggi;
  110. function ggiMapColor(vis: TGGIVisual; Color: TGGIColor): TGGIPixel; cdecl; external libggi;
  111. function ggiPutPixel(vis: TGGIVisual; x, y: Longint; pixel: TGGIPixel): Longint; cdecl; external libggi;
  112. function ggiGetPixel(vis: TGGIVisual; x, y: Longint; var pixel: TGGIPixel): Longint; cdecl; external libggi;
  113. function ggiDrawBox(vis: TGGIVisual; x, y, w, h: Longint): Longint; cdecl; external libggi;
  114. function ggiPutBox(vis: TGGIVisual; x, y, w, h: Longint; var buffer): Longint; cdecl; external libggi;
  115. function ggiGetBox(vis: TGGIVisual; x, y, w, h: Longint; var buffer): Longint; cdecl; external libggi;
  116. function ggiGetPalette(vis: TGGIVisual; s, len: Longint; var cmap: TGGIColor): Longint; cdecl; external libggi;
  117. function ggiSetPalette(vis: TGGIVisual; s, len: Longint; var cmap: TGGIColor): Longint; cdecl; external libggi;
  118. var
  119. Visual: TGGIVisual;
  120. CurrentMode, OldMode: TGGIMode;
  121. procedure ggi_savevideostate;
  122. begin
  123. ggiGetMode(Visual, OldMode);
  124. end;
  125. procedure ggi_restorevideostate;
  126. begin
  127. ggiSetMode(Visual, OldMode);
  128. end;
  129. const
  130. BgiColors: array[0..15] of TGGIColor = (
  131. (r: $0000; g: $0000; b: $0000; a: 0),
  132. (r: $0000; g: $0000; b: $8000; a: 0),
  133. (r: $0000; g: $8000; b: $0000; a: 0),
  134. (r: $0000; g: $8000; b: $8000; a: 0),
  135. (r: $8000; g: $0000; b: $0000; a: 0),
  136. (r: $8000; g: $0000; b: $8000; a: 0),
  137. (r: $8000; g: $8000; b: $0000; a: 0),
  138. (r: $C000; g: $C000; b: $C000; a: 0),
  139. (r: $8000; g: $8000; b: $8000; a: 0),
  140. (r: $0000; g: $0000; b: $FFFF; a: 0),
  141. (r: $0000; g: $FFFF; b: $0000; a: 0),
  142. (r: $0000; g: $FFFF; b: $FFFF; a: 0),
  143. (r: $FFFF; g: $0000; b: $0000; a: 0),
  144. (r: $FFFF; g: $0000; b: $FFFF; a: 0),
  145. (r: $FFFF; g: $FFFF; b: $0000; a: 0),
  146. (r: $FFFF; g: $FFFF; b: $FFFF; a: 0));
  147. procedure ggi_initmodeproc;
  148. begin
  149. ggiParseMode(ModeNames[IntCurrentMode], CurrentMode);
  150. ggiSetMode(Visual, CurrentMode);
  151. end;
  152. function ClipCoords(var x, y: SmallInt): Boolean;
  153. { Adapt to viewport, return TRUE if still in viewport,
  154. false if outside viewport}
  155. begin
  156. x := x + StartXViewPort;
  157. x := y + StartYViewPort;
  158. ClipCoords := not ClipPixels;
  159. if ClipCoords then begin
  160. ClipCoords := (y < StartXViewPort) or (x > (StartXViewPort + ViewWidth));
  161. ClipCoords := ClipCoords or
  162. ((y < StartYViewPort) or (y > (StartYViewPort + ViewHeight)));
  163. ClipCoords := not ClipCoords;
  164. end;
  165. end;
  166. procedure ggi_directpixelproc(X, Y: smallint);
  167. var
  168. Color, CurCol: TGGIPixel;
  169. begin
  170. CurCol := ggiMapColor(Visual, BgiColors[CurrentColor]);
  171. case CurrentWriteMode of
  172. XORPut: begin
  173. { getpixel wants local/relative coordinates }
  174. ggiGetPixel(Visual, x-StartXViewPort, y-StartYViewPort, Color);
  175. Color := CurCol xor Color;
  176. end;
  177. OrPut: begin
  178. { getpixel wants local/relative coordinates }
  179. ggiGetPixel(Visual, x-StartXViewPort, y-StartYViewPort, Color);
  180. Color := CurCol or Color;
  181. end;
  182. AndPut: begin
  183. { getpixel wants local/relative coordinates }
  184. ggiGetPixel(Visual, x-StartXViewPort, y-StartYViewPort, Color);
  185. Color := CurCol and Color;
  186. end;
  187. NotPut:
  188. Color := not Color;
  189. else
  190. Color := CurCol;
  191. end;
  192. ggiPutPixel(Visual, x, y, Color);
  193. end;
  194. procedure ggi_putpixelproc(X,Y: smallint; Color: Word);
  195. begin
  196. If Not ClipCoords(X,Y) Then exit;
  197. ggiputpixel(Visual,x, y, Color);
  198. end;
  199. function ggi_getpixelproc (X,Y: smallint): word;
  200. Var i : TGGIPixel;
  201. begin
  202. ClipCoords(X,Y);
  203. ggigetpixel(Visual,x, y,I);
  204. ggi_getpixelproc:=i;
  205. end;
  206. procedure ggi_clrviewproc;
  207. begin
  208. ggidrawbox(Visual,StartXViewPort,StartYViewPort,ViewWidth,ViewHeight);
  209. end;
  210. { Bitmap utilities }
  211. type
  212. PBitmap = ^TBitmap;
  213. TBitmap = record
  214. Width, Height: longint;
  215. reserved : longint;
  216. Data: record end;
  217. end;
  218. procedure ggi_putimageproc (X,Y: smallint; var Bitmap; BitBlt: Word);
  219. begin
  220. With TBitMap(BitMap) do
  221. ggiputbox(Visual,x, y, width, height, @Data);
  222. end;
  223. procedure ggi_getimageproc (X1,Y1,X2,Y2: smallint; Var Bitmap);
  224. begin
  225. with TBitmap(Bitmap) do
  226. begin
  227. Width := x2 - x1 + 1;
  228. Height := y2 - y1 + 1;
  229. ggigetbox(Visual,x1,y1, x2 - x1 + 1, y2 - y1 + 1, @Data);
  230. end;
  231. end;
  232. function ggi_imagesizeproc (X1,Y1,X2,Y2: smallint): longint;
  233. begin
  234. // 32 bits per pixel -- change ASAP !!
  235. ggi_imagesizeproc := SizeOf(TBitmap) + (x2 - x1 + 1) * (y2 - y1 + 1) * SizeOF(longint);
  236. end;
  237. procedure ggi_hlineproc (x, x2,y : smallint);
  238. begin
  239. end;
  240. procedure ggi_vlineproc (x,y,y2: smallint);
  241. begin
  242. end;
  243. procedure ggi_patternlineproc (x1,x2,y: smallint);
  244. begin
  245. end;
  246. procedure ggi_ellipseproc (X,Y: smallint;XRadius: word;
  247. YRadius:word; stAngle,EndAngle: word; fp: PatternLineProc);
  248. begin
  249. end;
  250. procedure ggi_lineproc (X1, Y1, X2, Y2 : smallint);
  251. begin
  252. end;
  253. procedure ggi_getscanlineproc (X1, X2, Y : smallint; var data);
  254. begin
  255. end;
  256. procedure ggi_setactivepageproc (page: word);
  257. begin
  258. end;
  259. procedure ggi_setvisualpageproc (page: word);
  260. begin
  261. end;
  262. procedure ggi_savestateproc;
  263. begin
  264. end;
  265. procedure ggi_restorestateproc;
  266. begin
  267. end;
  268. procedure ggi_setrgbpaletteproc(ColorNum, RedValue, GreenValue, BlueValue: smallint);
  269. Var Col : TGGIcolor;
  270. begin
  271. col.r:=redvalue;
  272. col.g:=greenvalue;
  273. col.b:=bluevalue;
  274. ggisetpalette(Visual,ColorNum,1,col);
  275. end;
  276. procedure ggi_getrgbpaletteproc (ColorNum: smallint;
  277. var RedValue, GreenValue, BlueValue: smallint);
  278. Var Col : TGGIColor;
  279. begin
  280. ggigetpalette(Visual,ColorNum,1,col);
  281. RedValue:=Col.R;
  282. GreenValue:=Col.G;
  283. BlueValue:=Col.B;
  284. end;
  285. {************************************************************************}
  286. {* General routines *}
  287. {************************************************************************}
  288. procedure CloseGraph;
  289. begin
  290. if not IsGraphMode then
  291. begin
  292. _graphresult := grnoinitgraph;
  293. exit
  294. end;
  295. RestoreVideoState;
  296. isgraphmode := false;
  297. end;
  298. function QueryAdapterInfo:PModeInfo;
  299. { This routine returns the head pointer to the list }
  300. { of supported graphics modes. }
  301. { Returns nil if no graphics mode supported. }
  302. { This list is READ ONLY! }
  303. var
  304. ModeInfo: TGGIMode;
  305. procedure AddGGIMode(i: smallint); // i is the mode number
  306. var
  307. mode: TModeInfo;
  308. begin
  309. InitMode(Mode);
  310. with Mode do begin
  311. ModeNumber := i;
  312. ModeName := ModeNames[i];
  313. // Pretend we're VGA always.
  314. DriverNumber := VGA;
  315. MaxX := ModeInfo.Visible.X;
  316. MaxY := ModeInfo.Visible.Y;
  317. // MaxColor := ModeInfo.colors;
  318. MaxColor := 255;
  319. PaletteSize := MaxColor;
  320. HardwarePages := 0;
  321. // necessary hooks ...
  322. DirectPutPixel := @ggi_DirectPixelProc;
  323. GetPixel := @ggi_GetPixelProc;
  324. PutPixel := @ggi_PutPixelProc;
  325. SetRGBPalette := @ggi_SetRGBPaletteProc;
  326. GetRGBPalette := @ggi_GetRGBPaletteProc;
  327. ClearViewPort := @ggi_ClrViewProc;
  328. PutImage := @ggi_PutImageProc;
  329. GetImage := @ggi_GetImageProc;
  330. ImageSize := @ggi_ImageSizeProc;
  331. { Add later maybe ?
  332. SetVisualPage := SetVisualPageProc;
  333. SetActivePage := SetActivePageProc;
  334. GetScanLine := @ggi_GetScanLineProc;
  335. Line := @ggi_LineProc;
  336. InternalEllipse:= @ggi_EllipseProc;
  337. PatternLine := @ggi_PatternLineProc;
  338. HLine := @ggi_HLineProc;
  339. VLine := @ggi_VLineProc;
  340. }
  341. InitMode := @ggi_InitModeProc;
  342. end;
  343. AddMode(Mode);
  344. end;
  345. var
  346. i: longint;
  347. OldMode: TGGIMode;
  348. begin
  349. QueryAdapterInfo := ModeList;
  350. { If the mode listing already exists... }
  351. { simply return it, without changing }
  352. { anything... }
  353. if Assigned(ModeList) then
  354. exit;
  355. SaveVideoState:=ggi_savevideostate;
  356. RestoreVideoState:=ggi_restorevideostate;
  357. If ggiInit <> 0 then begin
  358. _graphresult := grNoInitGraph;
  359. exit;
  360. end;
  361. Visual := ggiOpen(nil, []); // Use default visual
  362. ggiGetMode(Visual, OldMode);
  363. ggiParseMode('', ModeInfo);
  364. ggiSetMode(Visual, ModeInfo);
  365. ggiGetMode(Visual, ModeInfo);
  366. ggiSetMode(Visual, OldMode);
  367. AddGGIMode(0);
  368. for i := 1 to GLastMode do begin
  369. // WriteLn('Testing mode: ', ModeNames[i]);
  370. ggiParseMode(ModeNames[i], ModeInfo);
  371. If ggiCheckMode(visual, ModeInfo) = 0 then begin
  372. Writeln('OK for mode: ', ModeNames[i]);
  373. AddGGIMode(i);
  374. end;
  375. end;
  376. end;
  377. {
  378. $Log$
  379. Revision 1.8 2000-01-07 16:41:40 daniel
  380. * copyright 2000
  381. Revision 1.7 1999/12/20 11:22:38 peter
  382. * modes moved to interface
  383. * integer -> smallint
  384. Revision 1.6 1999/12/11 23:41:39 jonas
  385. * changed definition of getscanlineproc to "getscanline(x1,x2,y:
  386. smallint; var data);" so it can be used by getimage too
  387. * changed getimage so it uses getscanline
  388. * changed floodfill, getscanline16 and definitions in Linux
  389. include files so they use this new format
  390. + getscanlineVESA256 for 256 color VESA modes (banked)
  391. Revision 1.5 1999/11/12 02:13:01 carl
  392. * Bugfix if getimage / putimage, format was not standard with FPC
  393. graph.
  394. Revision 1.4 1999/11/10 10:54:24 sg
  395. * Fixed a LOT of bugs:
  396. * - Default mode should be determined by GGI now
  397. * - Colors are working (only the 16 standard VGA colors, though)
  398. Revision 1.3 1999/11/08 20:04:55 sg
  399. * GGI programs must link to libc, or ggiOpen will fail!
  400. * Changed max length of ModeNames string from 18 to 20 chars
  401. Revision 1.2 1999/11/08 00:08:43 michael
  402. * Fist working version of svgalib new graph unit
  403. * Initial implementation of ggi new graph unit
  404. Revision 1.1 1999/11/07 16:57:26 michael
  405. + Start of common graph implementation
  406. }