modes.inc 12 KB

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