vgagraph.inc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  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. 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. GLASTMODE = 49;
  75. ModeNames : Array[0..GLastMode] of string [18] =
  76. ('Text',
  77. 'G320x200x16',
  78. 'G640x200x16',
  79. 'G640x350x16',
  80. 'G640x480x16',
  81. 'G320x200x256',
  82. 'G320x240x256',
  83. 'G320x400x256',
  84. 'G360x480x256',
  85. 'G640x480x2',
  86. 'G640x480x256',
  87. 'G800x600x256',
  88. 'G1024x768x256',
  89. 'G1280x1024x256',
  90. 'G320x200x32K',
  91. 'G320x200x64K',
  92. 'G320x200x16M',
  93. 'G640x480x32K',
  94. 'G640x480x64K',
  95. 'G640x480x16M',
  96. 'G800x600x32K',
  97. 'G800x600x64K',
  98. 'G800x600x16M',
  99. 'G1024x768x32K',
  100. 'G1024x768x64K',
  101. 'G1024x768x16M',
  102. 'G1280x1024x32K',
  103. 'G1280x1024x64K',
  104. 'G1280x1024x16M',
  105. 'G800x600x16',
  106. '1024x768x16',
  107. '1280x1024x16',
  108. 'G720x348x2',
  109. 'G320x200x16M32',
  110. 'G640x480x16M32',
  111. 'G800x600x16M32',
  112. 'G1024x768x16M32',
  113. 'G1280x1024x16M32',
  114. 'G1152x864x16',
  115. 'G1152x864x256',
  116. 'G1152x864x32K',
  117. 'G1152x864x64K',
  118. 'G1152x864x16M',
  119. 'G1152x864x16M32',
  120. 'G1600x1200x16',
  121. 'G1600x1200x256',
  122. 'G1600x1200x32K',
  123. 'G1600x1200x64K',
  124. 'G1600x1200x16M',
  125. 'G1600x1200x16M32');
  126. var
  127. PhysicalScreen: PGraphicsContext;
  128. { vga functions }
  129. Function vga_init: Longint; Cdecl; External;
  130. Function vga_hasmode(mode: Longint): Boolean; Cdecl; External;
  131. Function vga_getmodeinfo(mode: Longint): pvga_modeinfo; Cdecl; External;
  132. Function vga_setmode(mode: Longint): Longint; Cdecl; External;
  133. { gl functions }
  134. procedure gl_setpixel(x, y, c: LongInt); Cdecl; External;
  135. function gl_getpixel(x, y: LongInt): LongInt; cdecl; external;
  136. procedure gl_fillbox(x, y, w, h, c: LongInt); Cdecl; External;
  137. procedure gl_getbox(x, y, w, h: LongInt; dp: pointer); Cdecl; External;
  138. procedure gl_putbox(x, y, w, h: LongInt; dp: pointer); Cdecl; External;
  139. function gl_setcontextvga(m: LongInt): LongInt; Cdecl; External;
  140. function gl_allocatecontext: PGraphicsContext; Cdecl; External;
  141. procedure gl_getcontext(gc: PGraphicsContext); Cdecl; External;
  142. procedure gl_setrgbpalette; Cdecl; External;
  143. Procedure gl_setpalettecolor(c, r, b, g: LongInt); cdecl;external;
  144. Procedure gl_getpalettecolor(c: LongInt; var r, b, g: LongInt); cdecl;external;
  145. { ---------------------------------------------------------------------
  146. Required procedures
  147. ---------------------------------------------------------------------}
  148. procedure libvga_savevideostate;
  149. begin
  150. end;
  151. procedure libvga_restorevideostate;
  152. begin
  153. vga_setmode(0);
  154. end;
  155. const
  156. BgiColors: array[0..15] of LongInt
  157. = ($000000, $000080, $008000, $008080,
  158. $800000, $800080, $808000, $C0C0C0,
  159. $808080, $0000FF, $00FF00, $00FFFF,
  160. $FF0000, $FF00FF, $FFFF00, $FFFFFF);
  161. procedure InitColors;
  162. var
  163. i: Integer;
  164. begin
  165. for i:=0 to 15 do
  166. gl_setpalettecolor(I,BgiColors[i] shr 16,
  167. (BgiColors[i] shr 8) and 255,
  168. BgiColors[i] and 255)
  169. end;
  170. procedure libvga_initmodeproc;
  171. begin
  172. vga_setmode(IntCurrentMode);
  173. gl_setcontextvga(IntCurrentMode);
  174. PhysicalScreen := gl_allocatecontext;
  175. gl_getcontext(PhysicalScreen);
  176. if (PhysicalScreen^.colors = 256) then gl_setrgbpalette;
  177. InitColors;
  178. end;
  179. Function ClipCoords (Var X,Y : Integer) : Boolean;
  180. { Adapt to viewport, return TRUE if still in viewport,
  181. false if outside viewport}
  182. begin
  183. X:= X + StartXViewPort;
  184. Y:= Y + StartYViewPort;
  185. ClipCoords:=Not ClipPixels;
  186. if ClipCoords then
  187. Begin
  188. ClipCoords:=(X < StartXViewPort) or (X > (StartXViewPort + ViewWidth));
  189. ClipCoords:=ClipCoords or
  190. ((Y < StartYViewPort) or (Y > (StartYViewPort + ViewHeight)));
  191. ClipCoords:=Not ClipCoords;
  192. end;
  193. end;
  194. procedure libvga_directpixelproc(X,Y: Integer);
  195. Var Color : Word;
  196. begin
  197. case CurrentWriteMode of
  198. XORPut:
  199. begin
  200. { getpixel wants local/relative coordinates }
  201. Color := GetPixel(x-StartXViewPort,y-StartYViewPort);
  202. Color := CurrentColor Xor Color;
  203. end;
  204. OrPut:
  205. begin
  206. { getpixel wants local/relative coordinates }
  207. Color := GetPixel(x-StartXViewPort,y-StartYViewPort);
  208. Color := CurrentColor Or Color;
  209. end;
  210. AndPut:
  211. begin
  212. { getpixel wants local/relative coordinates }
  213. Color := GetPixel(x-StartXViewPort,y-StartYViewPort);
  214. Color := CurrentColor And Color;
  215. end;
  216. NotPut:
  217. begin
  218. Color := Not Color;
  219. end
  220. else
  221. Color:=CurrentColor;
  222. end;
  223. gl_setpixel(x, y, Color);
  224. end;
  225. procedure libvga_putpixelproc(X,Y: Integer; Color: Word);
  226. begin
  227. If Not ClipCoords(X,Y) Then exit;
  228. gl_setpixel(x, y, Color);
  229. end;
  230. function libvga_getpixelproc (X,Y: Integer): word;
  231. begin
  232. ClipCoords(X,Y);
  233. libvga_getpixelproc:=gl_getpixel(x, y);
  234. end;
  235. procedure libvga_clrviewproc;
  236. begin
  237. gl_fillbox(StartXViewPort,StartYViewPort,ViewWidth,ViewHeight,CurrentBkColor);
  238. end;
  239. { Bitmap utilities }
  240. type
  241. PBitmap = ^TBitmap;
  242. TBitmap = record
  243. Width, Height: Integer;
  244. Data: record end;
  245. end;
  246. procedure libvga_putimageproc (X,Y: Integer; var Bitmap; BitBlt: Word);
  247. begin
  248. With TBitMap(BitMap) do
  249. gl_putbox(x, y, width, height, @Data);
  250. end;
  251. procedure libvga_getimageproc (X1,Y1,X2,Y2: Integer; Var Bitmap);
  252. begin
  253. with TBitmap(Bitmap) do
  254. begin
  255. Width := x2 - x1 + 1;
  256. Height := y2 - y1 + 1;
  257. gl_getbox(x1,y1, x2 - x1 + 1, y2 - y1 + 1, @Data);
  258. end;
  259. end;
  260. function libvga_imagesizeproc (X1,Y1,X2,Y2: Integer): longint;
  261. begin
  262. libvga_imagesizeproc := SizeOf(TBitmap) + (x2 - x1 + 1) * (y2 - y1 + 1) * PhysicalScreen^.BytesPerPixel;
  263. end;
  264. procedure libvga_hlineproc (x, x2,y : integer);
  265. begin
  266. end;
  267. procedure libvga_vlineproc (x,y,y2: integer);
  268. begin
  269. end;
  270. procedure libvga_patternlineproc (x1,x2,y: integer);
  271. begin
  272. end;
  273. procedure libvga_ellipseproc (X,Y: Integer;XRadius: word;
  274. YRadius:word; stAngle,EndAngle: word; fp: PatternLineProc);
  275. begin
  276. end;
  277. procedure libvga_lineproc (X1, Y1, X2, Y2 : Integer);
  278. begin
  279. end;
  280. procedure libvga_getscanlineproc (X1,X2,Y : integer; var data);
  281. begin
  282. end;
  283. procedure libvga_setactivepageproc (page: word);
  284. begin
  285. end;
  286. procedure libvga_setvisualpageproc (page: word);
  287. begin
  288. end;
  289. procedure libvga_savestateproc;
  290. begin
  291. end;
  292. procedure libvga_restorestateproc;
  293. begin
  294. end;
  295. procedure libvga_setrgbpaletteproc(ColorNum, RedValue, GreenValue, BlueValue: Integer);
  296. begin
  297. gl_setpalettecolor(ColorNum,RedValue,GreenValue,BlueValue);
  298. end;
  299. procedure libvga_getrgbpaletteproc (ColorNum: integer;
  300. var RedValue, GreenValue, BlueValue: Integer);
  301. Var R,G,B : longint;
  302. begin
  303. gl_getpalettecolor(ColorNum,R,G,B);
  304. RedValue:=R;
  305. GreenValue:=G;
  306. BlueValue:=B;
  307. end;
  308. {************************************************************************}
  309. {* General routines *}
  310. {************************************************************************}
  311. procedure CloseGraph;
  312. Begin
  313. If not isgraphmode then
  314. begin
  315. _graphresult := grnoinitgraph;
  316. exit
  317. end;
  318. RestoreVideoState;
  319. isgraphmode := false;
  320. end;
  321. function QueryAdapterInfo:PModeInfo;
  322. { This routine returns the head pointer to the list }
  323. { of supported graphics modes. }
  324. { Returns nil if no graphics mode supported. }
  325. { This list is READ ONLY! }
  326. var
  327. mode: TModeInfo;
  328. modeinfo : vga_modeinfo;
  329. i : longint;
  330. begin
  331. QueryAdapterInfo := ModeList;
  332. { If the mode listing already exists... }
  333. { simply return it, without changing }
  334. { anything... }
  335. if assigned(ModeList) then
  336. exit;
  337. SaveVideoState:=libvga_savevideostate;
  338. RestoreVideoState:=libvga_restorevideostate;
  339. vga_init;
  340. For I:=0 to GLastMode do
  341. begin
  342. If vga_hasmode(I) then
  343. begin
  344. ModeInfo:=vga_getmodeinfo(i)^;
  345. InitMode(Mode);
  346. With Mode do
  347. begin
  348. ModeNumber:=I;
  349. ModeName:=ModeNames[i];
  350. // Pretend we're VGA always.
  351. DriverNumber := VGA;
  352. MaxX:=ModeInfo.Width;
  353. MaxY:=ModeInfo.height;
  354. MaxColor := ModeInfo.colors;
  355. PaletteSize := MaxColor;
  356. HardwarePages := 0;
  357. // necessary hooks ...
  358. DirectPutPixel := @libvga_DirectPixelProc;
  359. GetPixel := @Libvga_GetPixelProc;
  360. PutPixel := @libvga_PutPixelProc;
  361. SetRGBPalette := @libvga_SetRGBPaletteProc;
  362. GetRGBPalette := @libvga_GetRGBPaletteProc;
  363. ClearViewPort := libvga_ClrViewProc;
  364. PutImage := @Libvga_PutImageProc;
  365. GetImage := @libvga_GetImageProc;
  366. ImageSize := @libvga_ImageSizeProc;
  367. { Add later maybe ?
  368. SetVisualPage := SetVisualPageProc;
  369. SetActivePage := SetActivePageProc;
  370. GetScanLine := @libvga_GetScanLineProc;
  371. Line := @libvga_LineProc;
  372. InternalEllipse:= @libvga_EllipseProc;
  373. PatternLine := @libvga_PatternLineProc;
  374. HLine := @libvga_HLineProc;
  375. VLine := @libvga_VLineProc;
  376. }
  377. InitMode := @libvga_InitModeProc;
  378. end;
  379. AddMode(Mode);
  380. end;
  381. end;
  382. end;
  383. {
  384. $Log$
  385. Revision 1.5 2000-01-07 16:41:42 daniel
  386. * copyright 2000
  387. Revision 1.4 1999/12/20 11:22:38 peter
  388. * modes moved to interface
  389. * integer -> smallint
  390. Revision 1.3 1999/12/11 23:41:39 jonas
  391. * changed definition of getscanlineproc to "getscanline(x1,x2,y:
  392. integer; var data);" so it can be used by getimage too
  393. * changed getimage so it uses getscanline
  394. * changed floodfill, getscanline16 and definitions in Linux
  395. include files so they use this new format
  396. + getscanlineVESA256 for 256 color VESA modes (banked)
  397. Revision 1.2 1999/11/08 00:08:43 michael
  398. * Fist working version of svgalib new graph unit
  399. * Initial implementation of ggi new graph unit
  400. Revision 1.1 1999/11/07 16:57:26 michael
  401. + Start of common graph implementation
  402. }