modes.inc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1993,99 by the Free Pascal development team
  5. This include implements video mode management.
  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. {-----------------------------------------------------------------------}
  13. { Internal routines }
  14. {-----------------------------------------------------------------------}
  15. procedure addmode(mode: TModeInfo);
  16. {********************************************************}
  17. { Procedure AddMode() }
  18. {--------------------------------------------------------}
  19. { This routine adds <mode> to the list of recognized }
  20. { modes. Duplicates are allowed. }
  21. {********************************************************}
  22. var
  23. list: PModeInfo;
  24. newlst : PModeInfo;
  25. begin
  26. if not assigned(ModeList) then
  27. begin
  28. new(ModeList);
  29. move(mode, ModeList^, sizeof(Mode));
  30. end
  31. else
  32. begin
  33. list := ModeList;
  34. { go to the end of the list }
  35. while assigned(list^.next) do
  36. list:=list^.next;
  37. new(NewLst);
  38. list^.next := NewLst;
  39. move(mode, NewLst^, sizeof(Mode));
  40. end;
  41. end;
  42. procedure initmode(var mode: TModeInfo);
  43. {********************************************************}
  44. { Procedure InitMode() }
  45. {--------------------------------------------------------}
  46. { This routine initialized the mode to default values. }
  47. {********************************************************}
  48. begin
  49. FillChar(mode,sizeof(Mode),#0);
  50. end;
  51. function searchmode(ReqDriver : integer; reqmode: integer): PModeInfo;
  52. {********************************************************}
  53. { Procedure SearchMode() }
  54. {--------------------------------------------------------}
  55. { This routine searches the list of recognized modes, }
  56. { and tries to find the <reqmode> in the <reqdriver> }
  57. { return nil if not found, otherwise returns the found }
  58. { structure. }
  59. {********************************************************}
  60. var
  61. list: PModeInfo;
  62. begin
  63. {$ifdef logging}
  64. LogLn('Searching for driver '+strf(reqdriver)+' and mode '+strf(reqmode));
  65. {$endif logging}
  66. searchmode := nil;
  67. list := ModeList;
  68. { go to the end of the list }
  69. while assigned(list) do
  70. begin
  71. {$ifdef logging}
  72. Log('Found driver '+strf(list^.DriverNumber)+
  73. ' and mode $'+hexstr(list^.ModeNumber,4)+'... ');
  74. {$endif logging}
  75. if (list^.DriverNumber = ReqDriver) and
  76. (list^.ModeNumber = ReqMode) then
  77. begin
  78. {$ifdef logging}
  79. LogLn('Accepted!');
  80. {$endif logging}
  81. searchmode := list;
  82. exit;
  83. end;
  84. {$ifdef logging}
  85. LogLn('Rejected.');
  86. {$endif logging}
  87. list:=list^.next;
  88. end;
  89. end;
  90. {-----------------------------------------------------------------------}
  91. { External routines }
  92. {-----------------------------------------------------------------------}
  93. function GetModeName(ModeNumber: integer): string;
  94. {********************************************************}
  95. { Function GetModeName() }
  96. {--------------------------------------------------------}
  97. { Checks the known video list, and returns ModeName }
  98. { string. On error returns an empty string. }
  99. {********************************************************}
  100. var
  101. mode: PModeInfo;
  102. begin
  103. mode:=nil;
  104. GetModeName:='';
  105. { only search in the current driver modes ... }
  106. mode:=SearchMode(IntCurrentDriver,ModeNumber);
  107. if assigned(mode) then
  108. GetModeName:=Mode^.ModeName
  109. else
  110. _GraphResult := grInvalidMode;
  111. end;
  112. function GetGraphMode: Integer;
  113. begin
  114. GetGraphMode := IntCurrentMode;
  115. end;
  116. function GetMaxMode: word;
  117. { I know , i know, this routine is very slow, and it would }
  118. { be much easier to sort the linked list of possible modes }
  119. { instead of doing this, but I'm lazy!! And anyways, the }
  120. { speed of the routine here is not that important.... }
  121. var
  122. i: word;
  123. mode: PModeInfo;
  124. begin
  125. mode:=nil;
  126. i:=0;
  127. repeat
  128. inc(i);
  129. { mode 0 always exists... }
  130. { start search at 1.. }
  131. mode:=SearchMode(IntCurrentDriver,i);
  132. until not assigned(mode);
  133. GetMaxMode:=i;
  134. end;
  135. procedure GetModeRange(GraphDriver: Integer; var LoMode,
  136. HiMode: Integer);
  137. var
  138. i : integer;
  139. mode : PModeInfo;
  140. begin
  141. LoMode:=-1;
  142. HiMode:=-1;
  143. mode := nil;
  144. { First search if the graphics driver is supported .. }
  145. { since mode zero is always supported.. if that driver }
  146. { is supported it should return something... }
  147. mode := SearchMode(GraphDriver, 0);
  148. { driver not supported...}
  149. if not assigned(mode) then exit;
  150. { now it exists... find highest available mode... }
  151. LoMode := 0;
  152. mode:=nil;
  153. i:=-1;
  154. repeat
  155. inc(i);
  156. { start search at 0.. }
  157. mode:=SearchMode(GraphDriver,i);
  158. until not assigned(mode);
  159. HiMode := i-1;
  160. end;
  161. procedure SetGraphMode(mode: Integer);
  162. var
  163. modeinfo: PModeInfo;
  164. begin
  165. { check if the mode exists... }
  166. modeinfo := searchmode(IntcurrentDriver,mode);
  167. if not assigned(modeinfo) then
  168. begin
  169. {$ifdef logging}
  170. LogLn('Mode setting failed in setgraphmode pos 1');
  171. {$endif logging}
  172. _GraphResult := grInvalidMode;
  173. exit;
  174. end;
  175. { reset all hooks...}
  176. DefaultHooks;
  177. { arccall not reset - tested against VGA BGI driver }
  178. { Setup all hooks if none, keep old defaults...}
  179. { required hooks - returns error if no hooks to these }
  180. { routines. }
  181. if assigned(modeinfo^.DirectPutPixel) then
  182. DirectPutPixel := modeinfo^.DirectPutPixel
  183. else
  184. begin
  185. {$ifdef logging}
  186. LogLn('Mode setting failed in setgraphmode pos 2');
  187. {$endif logging}
  188. _Graphresult := grInvalidMode;
  189. exit;
  190. end;
  191. if assigned(modeinfo^.PutPixel) then
  192. PutPixel := modeinfo^.PutPixel
  193. else
  194. begin
  195. {$ifdef logging}
  196. LogLn('Mode setting failed in setgraphmode pos 3');
  197. {$endif logging}
  198. _Graphresult := grInvalidMode;
  199. exit;
  200. end;
  201. if assigned(modeinfo^.GetPixel) then
  202. GetPixel := modeinfo^.GetPixel
  203. else
  204. begin
  205. {$ifdef logging}
  206. LogLn('Mode setting failed in setgraphmode pos 4');
  207. {$endif logging}
  208. _Graphresult := grInvalidMode;
  209. exit;
  210. end;
  211. if assigned(modeinfo^.SetRGBPalette) then
  212. SetRGBPalette := modeinfo^.SetRGBPalette
  213. else
  214. begin
  215. {$ifdef logging}
  216. LogLn('Mode setting failed in setgraphmode pos 5');
  217. {$endif logging}
  218. _Graphresult := grInvalidMode;
  219. exit;
  220. end;
  221. if assigned(modeinfo^.GetRGBPalette) then
  222. GetRGBPalette := modeinfo^.GetRGBPalette
  223. else
  224. begin
  225. {$ifdef logging}
  226. LogLn('Mode setting failed in setgraphmode pos 6');
  227. {$endif logging}
  228. _Graphresult := grInvalidMode;
  229. exit;
  230. end;
  231. { optional hooks. }
  232. if assigned(modeinfo^.ClearViewPort) then
  233. ClearViewPort := modeinfo^.ClearViewPort;
  234. if assigned(modeinfo^.PutImage) then
  235. PutImage := modeinfo^.PutImage;
  236. if assigned(modeinfo^.GetImage) then
  237. GetImage := modeinfo^.GetImage;
  238. if assigned(modeinfo^.ImageSize) then
  239. ImageSize := modeinfo^.ImageSize;
  240. if assigned(modeinfo^.GetScanLine) then
  241. GetScanLine := modeinfo^.GetScanLine;
  242. if assigned(modeinfo^.Line) then
  243. Line := modeinfo^.Line;
  244. if assigned(modeinfo^.InternalEllipse) then
  245. InternalEllipse := modeinfo^.InternalEllipse;
  246. if assigned(modeinfo^.PatternLine) then
  247. PatternLine := modeinfo^.PatternLine;
  248. if assigned(modeinfo^.HLine) then
  249. Hline := modeinfo^.Hline;
  250. if assigned(modeinfo^.Vline) then
  251. VLine := modeinfo^.VLine;
  252. if assigned(modeInfo^.SetVisualPage) then
  253. SetVisualPage := modeInfo^.SetVisualPage;
  254. if assigned(modeInfo^.SetActivePage) then
  255. SetActivePage := modeInfo^.SetActivePage;
  256. IntCurrentMode := modeinfo^.ModeNumber;
  257. IntCurrentDriver := modeinfo^.DriverNumber;
  258. XAspect := modeinfo^.XAspect;
  259. YAspect := modeinfo^.YAspect;
  260. MaxX := modeinfo^.MaxX;
  261. MaxY := modeinfo^.MaxY;
  262. HardwarePages := modeInfo^.HardwarePages;
  263. MaxColor := modeinfo^.MaxColor;
  264. PaletteSize := modeinfo^.PaletteSize;
  265. { is this a direct color mode? }
  266. DirectColor := modeinfo^.DirectColor;
  267. { now actually initialize the video mode...}
  268. { check first if the routine exists }
  269. if not assigned(modeinfo^.InitMode) then
  270. begin
  271. {$ifdef logging}
  272. LogLn('Mode setting failed in setgraphmode pos 7');
  273. {$endif logging}
  274. _GraphResult := grInvalidMode;
  275. exit;
  276. end;
  277. modeinfo^.InitMode;
  278. if _GraphResult <> grOk then exit;
  279. isgraphmode := true;
  280. { It is very important that this call be made }
  281. { AFTER the other variables have been setup. }
  282. { Since it calls some routines which rely on }
  283. { those variables. }
  284. SetActivePage(0);
  285. SetVisualPage(0);
  286. GraphDefaults;
  287. SetViewPort(0,0,MaxX,MaxY,TRUE);
  288. end;
  289. procedure RestoreCrtMode;
  290. {********************************************************}
  291. { Procedure RestoreCRTMode() }
  292. {--------------------------------------------------------}
  293. { Returns to the video mode which was set before the }
  294. { InitGraph. Hardware state is set to the old values. }
  295. {--------------------------------------------------------}
  296. { NOTE: - }
  297. { - }
  298. {********************************************************}
  299. begin
  300. isgraphmode := false;
  301. RestoreVideoState;
  302. end;
  303. {
  304. $Log$
  305. Revision 1.13 1999-11-28 16:13:55 jonas
  306. * corrected misplacement of call to initvars in initgraph
  307. + some extra debugging commands (for -dlogging) in the mode functions
  308. Revision 1.12 1999/09/28 13:56:31 jonas
  309. * reordered some local variables (first 4 byte vars, then 2 byte vars
  310. etc)
  311. * font data is now disposed in exitproc, exitproc is now called
  312. GraphExitProc (was CleanModes) and resides in graph.pp instead of in
  313. modes.inc
  314. Revision 1.11 1999/09/26 13:31:07 jonas
  315. * changed name of modeinfo variable to vesamodeinfo and fixed
  316. associated errors (fillchar(modeinfo,sizeof(tmodeinfo),#0) instead
  317. of sizeof(TVesamodeinfo) etc)
  318. * changed several sizeof(type) to sizeof(varname) to avoid similar
  319. errors in the future
  320. Revision 1.10 1999/09/24 22:52:39 jonas
  321. * optimized patternline a bit (always use hline when possible)
  322. * isgraphmode stuff cleanup
  323. * vesainfo.modelist now gets disposed in cleanmode instead of in
  324. closegraph (required moving of some declarations from vesa.inc to
  325. new vesah.inc)
  326. * queryadapter gets no longer called from initgraph (is called from
  327. initialization of graph unit)
  328. * bugfix for notput in 32k and 64k vesa modes
  329. * a div replaced by / in fillpoly
  330. Revision 1.9 1999/09/22 13:13:36 jonas
  331. * renamed text.inc -> gtext.inc to avoid conflict with system unit
  332. * fixed textwidth
  333. * isgraphmode now gets properly updated, so mode restoring works
  334. again
  335. Revision 1.8 1999/09/18 22:21:11 jonas
  336. + hlinevesa256 and vlinevesa256
  337. + support for not/xor/or/andput in vesamodes with 32k/64k colors
  338. * lots of changes to avoid warnings under FPC
  339. Revision 1.7 1999/07/12 13:27:14 jonas
  340. + added Log and Id tags
  341. * added first FPC support, only VGA works to some extend for now
  342. * use -dasmgraph to use assembler routines, otherwise Pascal
  343. equivalents are used
  344. * use -dsupportVESA to support VESA (crashes under FPC for now)
  345. * only dispose vesainfo at closegrph if a vesa card was detected
  346. * changed int32 to longint (int32 is not declared under FPC)
  347. * changed the declaration of almost every procedure in graph.inc to
  348. "far;" becquse otherwise you can't assign them to procvars under TP
  349. real mode (but unexplainable "data segnment too large" errors prevent
  350. it from working under real mode anyway)
  351. }