vgagraph.inc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999 by the Free Pascal development team
  5. svgalib 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. const
  13. InternalDriverName = 'LinuxVGA';
  14. var SavePtr : Pointer;
  15. { ---------------------------------------------------------------------
  16. SVGA bindings.
  17. ---------------------------------------------------------------------}
  18. { Link with VGA, gl and c libraries }
  19. {$linklib vga}
  20. {$linklib vgagl}
  21. {$linklib c}
  22. Const
  23. { Text }
  24. WRITEMODE_OVERWRITE = 0;
  25. WRITEMODE_MASKED = 1;
  26. FONT_EXPANDED = 0;
  27. FONT_COMPRESSED = 2;
  28. { Types }
  29. type
  30. pvga_modeinfo = ^vga_modeinfo;
  31. vga_modeinfo = record
  32. width,
  33. height,
  34. bytesperpixel,
  35. colors,
  36. linewidth, { scanline width in bytes }
  37. maxlogicalwidth, { maximum logical scanline width }
  38. startaddressrange, { changeable bits set }
  39. maxpixels, { video memory / bytesperpixel }
  40. haveblit, { mask of blit functions available }
  41. flags: Longint; { other flags }
  42. { Extended fields: }
  43. chiptype, { Chiptype detected }
  44. memory, { videomemory in KB }
  45. linewidth_unit: Longint; { Use only a multiple of this as parameter for set_displaystart }
  46. linear_aperture: PChar; { points to mmap secondary mem aperture of card }
  47. aperture_size: Longint; { size of aperture in KB if size>=videomemory.}
  48. set_aperture_page: procedure (page: Longint);
  49. { if aperture_size<videomemory select a memory page }
  50. extensions: Pointer; { points to copy of eeprom for mach32 }
  51. { depends from actual driver/chiptype.. etc. }
  52. end;
  53. PGraphicsContext = ^TGraphicsContext;
  54. TGraphicsContext = record
  55. ModeType: Byte;
  56. ModeFlags: Byte;
  57. Dummy: Byte;
  58. FlipPage: Byte;
  59. Width: LongInt;
  60. Height: LongInt;
  61. BytesPerPixel: LongInt;
  62. Colors: LongInt;
  63. BitsPerPixel: LongInt;
  64. ByteWidth: LongInt;
  65. VBuf: pointer;
  66. Clip: LongInt;
  67. ClipX1: LongInt;
  68. ClipY1: LongInt;
  69. ClipX2: LongInt;
  70. ClipY2: LongInt;
  71. ff: pointer;
  72. end;
  73. Const
  74. { VGA modes }
  75. GTEXT = 0; { Compatible with VGAlib v1.2 }
  76. G320x200x16 = 1;
  77. G640x200x16 = 2;
  78. G640x350x16 = 3;
  79. G640x480x16 = 4;
  80. G320x200x256 = 5;
  81. G320x240x256 = 6;
  82. G320x400x256 = 7;
  83. G360x480x256 = 8;
  84. G640x480x2 = 9;
  85. G640x480x256 = 10;
  86. G800x600x256 = 11;
  87. G1024x768x256 = 12;
  88. G1280x1024x256 = 13; { Additional modes. }
  89. G320x200x32K = 14;
  90. G320x200x64K = 15;
  91. G320x200x16M = 16;
  92. G640x480x32K = 17;
  93. G640x480x64K = 18;
  94. G640x480x16M = 19;
  95. G800x600x32K = 20;
  96. G800x600x64K = 21;
  97. G800x600x16M = 22;
  98. G1024x768x32K = 23;
  99. G1024x768x64K = 24;
  100. G1024x768x16M = 25;
  101. G1280x1024x32K = 26;
  102. G1280x1024x64K = 27;
  103. G1280x1024x16M = 28;
  104. G800x600x16 = 29;
  105. G1024x768x16 = 30;
  106. G1280x1024x16 = 31;
  107. G720x348x2 = 32; { Hercules emulation mode }
  108. G320x200x16M32 = 33; { 32-bit per pixel modes. }
  109. G640x480x16M32 = 34;
  110. G800x600x16M32 = 35;
  111. G1024x768x16M32 = 36;
  112. G1280x1024x16M32 = 37;
  113. { additional resolutions }
  114. G1152x864x16 = 38;
  115. G1152x864x256 = 39;
  116. G1152x864x32K = 40;
  117. G1152x864x64K = 41;
  118. G1152x864x16M = 42;
  119. G1152x864x16M32 = 43;
  120. G1600x1200x16 = 44;
  121. G1600x1200x256 = 45;
  122. G1600x1200x32K = 46;
  123. G1600x1200x64K = 47;
  124. G1600x1200x16M = 48;
  125. G1600x1200x16M32 = 49;
  126. GLASTMODE = 49;
  127. ModeNames : Array[0..GLastMode] of string [18] =
  128. ('Text',
  129. 'G320x200x16',
  130. 'G640x200x16',
  131. 'G640x350x16',
  132. 'G640x480x16',
  133. 'G320x200x256',
  134. 'G320x240x256',
  135. 'G320x400x256',
  136. 'G360x480x256',
  137. 'G640x480x2',
  138. 'G640x480x256',
  139. 'G800x600x256',
  140. 'G1024x768x256',
  141. 'G1280x1024x256',
  142. 'G320x200x32K',
  143. 'G320x200x64K',
  144. 'G320x200x16M',
  145. 'G640x480x32K',
  146. 'G640x480x64K',
  147. 'G640x480x16M',
  148. 'G800x600x32K',
  149. 'G800x600x64K',
  150. 'G800x600x16M',
  151. 'G1024x768x32K',
  152. 'G1024x768x64K',
  153. 'G1024x768x16M',
  154. 'G1280x1024x32K',
  155. 'G1280x1024x64K',
  156. 'G1280x1024x16M',
  157. 'G800x600x16',
  158. '1024x768x16',
  159. '1280x1024x16',
  160. 'G720x348x2',
  161. 'G320x200x16M32',
  162. 'G640x480x16M32',
  163. 'G800x600x16M32',
  164. 'G1024x768x16M32',
  165. 'G1280x1024x16M32',
  166. 'G1152x864x16',
  167. 'G1152x864x256',
  168. 'G1152x864x32K',
  169. 'G1152x864x64K',
  170. 'G1152x864x16M',
  171. 'G1152x864x16M32',
  172. 'G1600x1200x16',
  173. 'G1600x1200x256',
  174. 'G1600x1200x32K',
  175. 'G1600x1200x64K',
  176. 'G1600x1200x16M',
  177. 'G1600x1200x16M32');
  178. var
  179. PhysicalScreen: PGraphicsContext;
  180. { vga functions }
  181. Function vga_init: Longint; Cdecl; External;
  182. Function vga_hasmode(mode: Longint): Boolean; Cdecl; External;
  183. Function vga_getmodeinfo(mode: Longint): pvga_modeinfo; Cdecl; External;
  184. Function vga_setmode(mode: Longint): Longint; Cdecl; External;
  185. { gl functions }
  186. procedure gl_setpixel(x, y, c: LongInt); Cdecl; External;
  187. function gl_getpixel(x, y: LongInt): LongInt; cdecl; external;
  188. procedure gl_fillbox(x, y, w, h, c: LongInt); Cdecl; External;
  189. procedure gl_getbox(x, y, w, h: LongInt; dp: pointer); Cdecl; External;
  190. procedure gl_putbox(x, y, w, h: LongInt; dp: pointer); Cdecl; External;
  191. function gl_setcontextvga(m: LongInt): LongInt; Cdecl; External;
  192. function gl_allocatecontext: PGraphicsContext; Cdecl; External;
  193. procedure gl_getcontext(gc: PGraphicsContext); Cdecl; External;
  194. procedure gl_setrgbpalette; Cdecl; External;
  195. Procedure gl_setpalettecolor(c, r, b, g: LongInt); cdecl;external;
  196. Procedure gl_getpalettecolor(c: LongInt; var r, b, g: LongInt); cdecl;external;
  197. { ---------------------------------------------------------------------
  198. Required procedures
  199. ---------------------------------------------------------------------}
  200. procedure libvga_savevideostate;
  201. begin
  202. end;
  203. procedure libvga_restorevideostate;
  204. begin
  205. vga_setmode(Gtext);
  206. end;
  207. const
  208. BgiColors: array[0..15] of LongInt
  209. = ($000000, $000080, $008000, $008080,
  210. $800000, $800080, $808000, $C0C0C0,
  211. $808080, $0000FF, $00FF00, $00FFFF,
  212. $FF0000, $FF00FF, $FFFF00, $FFFFFF);
  213. procedure InitColors;
  214. var
  215. i: Integer;
  216. begin
  217. for i:=0 to 15 do
  218. gl_setpalettecolor(I,BgiColors[i] shr 16,
  219. (BgiColors[i] shr 8) and 255,
  220. BgiColors[i] and 255)
  221. end;
  222. procedure libvga_initmodeproc;
  223. begin
  224. vga_setmode(IntCurrentMode);
  225. gl_setcontextvga(IntCurrentMode);
  226. PhysicalScreen := gl_allocatecontext;
  227. gl_getcontext(PhysicalScreen);
  228. if (PhysicalScreen^.colors = 256) then gl_setrgbpalette;
  229. InitColors;
  230. end;
  231. Function ClipCoords (Var X,Y : Integer) : Boolean;
  232. { Adapt to viewport, return TRUE if still in viewport,
  233. false if outside viewport}
  234. begin
  235. X:= X + StartXViewPort;
  236. Y:= Y + StartYViewPort;
  237. ClipCoords:=Not ClipPixels;
  238. if ClipCoords then
  239. Begin
  240. ClipCoords:=(X < StartXViewPort) or (X > (StartXViewPort + ViewWidth));
  241. ClipCoords:=ClipCoords or
  242. ((Y < StartYViewPort) or (Y > (StartYViewPort + ViewHeight)));
  243. ClipCoords:=Not ClipCoords;
  244. end;
  245. end;
  246. procedure libvga_directpixelproc(X,Y: Integer);
  247. Var Color : Word;
  248. begin
  249. case CurrentWriteMode of
  250. XORPut:
  251. begin
  252. { getpixel wants local/relative coordinates }
  253. Color := GetPixel(x-StartXViewPort,y-StartYViewPort);
  254. Color := CurrentColor Xor Color;
  255. end;
  256. OrPut:
  257. begin
  258. { getpixel wants local/relative coordinates }
  259. Color := GetPixel(x-StartXViewPort,y-StartYViewPort);
  260. Color := CurrentColor Or Color;
  261. end;
  262. AndPut:
  263. begin
  264. { getpixel wants local/relative coordinates }
  265. Color := GetPixel(x-StartXViewPort,y-StartYViewPort);
  266. Color := CurrentColor And Color;
  267. end;
  268. NotPut:
  269. begin
  270. Color := Not Color;
  271. end
  272. else
  273. Color:=CurrentColor;
  274. end;
  275. gl_setpixel(x, y, Color);
  276. end;
  277. procedure libvga_putpixelproc(X,Y: Integer; Color: Word);
  278. begin
  279. If Not ClipCoords(X,Y) Then exit;
  280. gl_setpixel(x, y, Color);
  281. end;
  282. function libvga_getpixelproc (X,Y: Integer): word;
  283. begin
  284. ClipCoords(X,Y);
  285. libvga_getpixelproc:=gl_getpixel(x, y);
  286. end;
  287. procedure libvga_clrviewproc;
  288. begin
  289. gl_fillbox(StartXViewPort,StartYViewPort,ViewWidth,ViewHeight,CurrentBkColor);
  290. end;
  291. { Bitmap utilities }
  292. type
  293. PBitmap = ^TBitmap;
  294. TBitmap = record
  295. Width, Height: Integer;
  296. Data: record end;
  297. end;
  298. procedure libvga_putimageproc (X,Y: Integer; var Bitmap; BitBlt: Word);
  299. begin
  300. With TBitMap(BitMap) do
  301. gl_putbox(x, y, width, height, @Data);
  302. end;
  303. procedure libvga_getimageproc (X1,Y1,X2,Y2: Integer; Var Bitmap);
  304. begin
  305. with TBitmap(Bitmap) do
  306. begin
  307. Width := x2 - x1 + 1;
  308. Height := y2 - y1 + 1;
  309. gl_getbox(x1,y1, x2 - x1 + 1, y2 - y1 + 1, @Data);
  310. end;
  311. end;
  312. function libvga_imagesizeproc (X1,Y1,X2,Y2: Integer): longint;
  313. begin
  314. libvga_imagesizeproc := SizeOf(TBitmap) + (x2 - x1 + 1) * (y2 - y1 + 1) * PhysicalScreen^.BytesPerPixel;
  315. end;
  316. procedure libvga_hlineproc (x, x2,y : integer);
  317. begin
  318. end;
  319. procedure libvga_vlineproc (x,y,y2: integer);
  320. begin
  321. end;
  322. procedure libvga_patternlineproc (x1,x2,y: integer);
  323. begin
  324. end;
  325. procedure libvga_ellipseproc (X,Y: Integer;XRadius: word;
  326. YRadius:word; stAngle,EndAngle: word; fp: PatternLineProc);
  327. begin
  328. end;
  329. procedure libvga_lineproc (X1, Y1, X2, Y2 : Integer);
  330. begin
  331. end;
  332. procedure libvga_getscanlineproc (X1,X2,Y : integer; var data);
  333. begin
  334. end;
  335. procedure libvga_setactivepageproc (page: word);
  336. begin
  337. end;
  338. procedure libvga_setvisualpageproc (page: word);
  339. begin
  340. end;
  341. procedure libvga_savestateproc;
  342. begin
  343. end;
  344. procedure libvga_restorestateproc;
  345. begin
  346. end;
  347. procedure libvga_setrgbpaletteproc(ColorNum, RedValue, GreenValue, BlueValue: Integer);
  348. begin
  349. gl_setpalettecolor(ColorNum,RedValue,GreenValue,BlueValue);
  350. end;
  351. procedure libvga_getrgbpaletteproc (ColorNum: integer;
  352. var RedValue, GreenValue, BlueValue: Integer);
  353. Var R,G,B : longint;
  354. begin
  355. gl_getpalettecolor(ColorNum,R,G,B);
  356. RedValue:=R;
  357. GreenValue:=G;
  358. BlueValue:=B;
  359. end;
  360. {************************************************************************}
  361. {* General routines *}
  362. {************************************************************************}
  363. procedure CloseGraph;
  364. Begin
  365. If not isgraphmode then
  366. begin
  367. _graphresult := grnoinitgraph;
  368. exit
  369. end;
  370. RestoreVideoState;
  371. isgraphmode := false;
  372. end;
  373. function QueryAdapterInfo:PModeInfo;
  374. { This routine returns the head pointer to the list }
  375. { of supported graphics modes. }
  376. { Returns nil if no graphics mode supported. }
  377. { This list is READ ONLY! }
  378. var
  379. mode: TModeInfo;
  380. modeinfo : vga_modeinfo;
  381. i : longint;
  382. begin
  383. QueryAdapterInfo := ModeList;
  384. { If the mode listing already exists... }
  385. { simply return it, without changing }
  386. { anything... }
  387. if assigned(ModeList) then
  388. exit;
  389. SaveVideoState:=libvga_savevideostate;
  390. RestoreVideoState:=libvga_restorevideostate;
  391. vga_init;
  392. For I:=0 to GLastMode do
  393. begin
  394. If vga_hasmode(I) then
  395. begin
  396. ModeInfo:=vga_getmodeinfo(i)^;
  397. InitMode(Mode);
  398. With Mode do
  399. begin
  400. ModeNumber:=I;
  401. ModeName:=ModeNames[i];
  402. // Pretend we're VGA always.
  403. DriverNumber := VGA;
  404. MaxX:=ModeInfo.Width;
  405. MaxY:=ModeInfo.height;
  406. MaxColor := ModeInfo.colors;
  407. PaletteSize := MaxColor;
  408. HardwarePages := 0;
  409. // necessary hooks ...
  410. DirectPutPixel := @libvga_DirectPixelProc;
  411. GetPixel := @Libvga_GetPixelProc;
  412. PutPixel := @libvga_PutPixelProc;
  413. SetRGBPalette := @libvga_SetRGBPaletteProc;
  414. GetRGBPalette := @libvga_GetRGBPaletteProc;
  415. ClearViewPort := libvga_ClrViewProc;
  416. PutImage := @Libvga_PutImageProc;
  417. GetImage := @libvga_GetImageProc;
  418. ImageSize := @libvga_ImageSizeProc;
  419. { Add later maybe ?
  420. SetVisualPage := SetVisualPageProc;
  421. SetActivePage := SetActivePageProc;
  422. GetScanLine := @libvga_GetScanLineProc;
  423. Line := @libvga_LineProc;
  424. InternalEllipse:= @libvga_EllipseProc;
  425. PatternLine := @libvga_PatternLineProc;
  426. HLine := @libvga_HLineProc;
  427. VLine := @libvga_VLineProc;
  428. }
  429. InitMode := @libvga_InitModeProc;
  430. end;
  431. AddMode(Mode);
  432. end;
  433. end;
  434. end;
  435. {
  436. $Log$
  437. Revision 1.3 1999-12-11 23:41:39 jonas
  438. * changed definition of getscanlineproc to "getscanline(x1,x2,y:
  439. integer; var data);" so it can be used by getimage too
  440. * changed getimage so it uses getscanline
  441. * changed floodfill, getscanline16 and definitions in Linux
  442. include files so they use this new format
  443. + getscanlineVESA256 for 256 color VESA modes (banked)
  444. Revision 1.2 1999/11/08 00:08:43 michael
  445. * Fist working version of svgalib new graph unit
  446. * Initial implementation of ggi new graph unit
  447. Revision 1.1 1999/11/07 16:57:26 michael
  448. + Start of common graph implementation
  449. }