modes.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1993,99 by the Free Pascal development team
  4. This include implements video mode management.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {-----------------------------------------------------------------------}
  12. { Internal routines }
  13. {-----------------------------------------------------------------------}
  14. procedure addmode(mode: TModeInfo);
  15. {********************************************************}
  16. { Procedure AddMode() }
  17. {--------------------------------------------------------}
  18. { This routine adds <mode> to the list of recognized }
  19. { modes. Duplicates are allowed. }
  20. {********************************************************}
  21. var
  22. list: PModeInfo;
  23. newlst : PModeInfo;
  24. begin
  25. if not assigned(ModeList) then
  26. begin
  27. new(ModeList);
  28. move(mode, ModeList^, sizeof(TModeInfo));
  29. end
  30. else
  31. begin
  32. list := ModeList;
  33. { go to the end of the list }
  34. while assigned(list^.next) do
  35. list:=list^.next;
  36. new(NewLst);
  37. list^.next := NewLst;
  38. move(mode, NewLst^, sizeof(TModeInfo));
  39. end;
  40. end;
  41. procedure initmode(var mode: TModeInfo);
  42. {********************************************************}
  43. { Procedure InitMode() }
  44. {--------------------------------------------------------}
  45. { This routine initialized the mode to default values. }
  46. {********************************************************}
  47. begin
  48. FillChar(mode,sizeof(TModeInfo),#0);
  49. end;
  50. function searchmode(ReqDriver : integer; reqmode: integer): PModeInfo;
  51. {********************************************************}
  52. { Procedure SearchMode() }
  53. {--------------------------------------------------------}
  54. { This routine searches the list of recognized modes, }
  55. { and tries to find the <reqmode> in the <reqdriver> }
  56. { return nil if not found, otherwise returns the found }
  57. { structure. }
  58. {********************************************************}
  59. var
  60. list: PModeInfo;
  61. begin
  62. searchmode := nil;
  63. list := ModeList;
  64. { go to the end of the list }
  65. while assigned(list) do
  66. begin
  67. if (list^.DriverNumber = ReqDriver) and
  68. (list^.ModeNumber = ReqMode) then
  69. begin
  70. searchmode := list;
  71. exit;
  72. end;
  73. list:=list^.next;
  74. end;
  75. end;
  76. procedure cleanmode;far;
  77. {********************************************************}
  78. { Procedure CleanMode() }
  79. {--------------------------------------------------------}
  80. { This routine deallocates the mode list. }
  81. { It is called as an exit procedure ONLY. }
  82. {********************************************************}
  83. var
  84. list: PModeInfo;
  85. tmp : PModeInfo;
  86. begin
  87. list := ModeList;
  88. { go to the end of the list }
  89. while assigned(list) do
  90. begin
  91. tmp := list;
  92. list:=list^.next;
  93. dispose(tmp);
  94. end;
  95. end;
  96. {-----------------------------------------------------------------------}
  97. { External routines }
  98. {-----------------------------------------------------------------------}
  99. function GetModeName(ModeNumber: integer): string;
  100. {********************************************************}
  101. { Function GetModeName() }
  102. {--------------------------------------------------------}
  103. { Checks the known video list, and returns ModeName }
  104. { string. On error returns an empty string. }
  105. {********************************************************}
  106. var
  107. mode: PModeInfo;
  108. begin
  109. mode:=nil;
  110. GetModeName:='';
  111. { only search in the current driver modes ... }
  112. mode:=SearchMode(IntCurrentDriver,ModeNumber);
  113. if assigned(mode) then
  114. GetModeName:=Mode^.ModeName
  115. else
  116. _GraphResult := grInvalidMode;
  117. end;
  118. function GetGraphMode: Integer;
  119. begin
  120. GetGraphMode := IntCurrentMode;
  121. end;
  122. function GetMaxMode: word;
  123. { I know , i know, this routine is very slow, and it would }
  124. { be much easier to sort the linked list of possible modes }
  125. { instead of doing this, but I'm lazy!! And anyways, the }
  126. { speed of the routine here is not that important.... }
  127. var
  128. i: word;
  129. mode: PModeInfo;
  130. begin
  131. mode:=nil;
  132. i:=0;
  133. repeat
  134. inc(i);
  135. { mode 0 always exists... }
  136. { start search at 1.. }
  137. mode:=SearchMode(IntCurrentDriver,i);
  138. until not assigned(mode);
  139. GetMaxMode:=i;
  140. end;
  141. procedure GetModeRange(GraphDriver: Integer; var LoMode,
  142. HiMode: Integer);
  143. var
  144. i : integer;
  145. mode : PModeInfo;
  146. begin
  147. LoMode:=-1;
  148. HiMode:=-1;
  149. mode := nil;
  150. { First search if the graphics driver is supported .. }
  151. { since mode zero is always supported.. if that driver }
  152. { is supported it should return something... }
  153. mode := SearchMode(GraphDriver, 0);
  154. { driver not supported...}
  155. if not assigned(mode) then exit;
  156. { now it exists... find highest available mode... }
  157. LoMode := 0;
  158. mode:=nil;
  159. i:=-1;
  160. repeat
  161. inc(i);
  162. { start search at 0.. }
  163. mode:=SearchMode(GraphDriver,i);
  164. until not assigned(mode);
  165. HiMode := i-1;
  166. end;
  167. procedure SetGraphMode(mode: Integer);
  168. var
  169. modeinfo: PModeInfo;
  170. begin
  171. { check if the mode exists... }
  172. modeinfo := searchmode(IntcurrentDriver,mode);
  173. if not assigned(modeinfo) then
  174. begin
  175. _GraphResult := grInvalidMode;
  176. exit;
  177. end;
  178. { reset all hooks...}
  179. DefaultHooks;
  180. { arccall not reset - tested against VGA BGI driver }
  181. { Setup all hooks if none, keep old defaults...}
  182. { required hooks - returns error if no hooks to these }
  183. { routines. }
  184. if assigned(modeinfo^.DirectPutPixel) then
  185. DirectPutPixel := modeinfo^.DirectPutPixel
  186. else
  187. begin
  188. _Graphresult := grInvalidMode;
  189. exit;
  190. end;
  191. if assigned(modeinfo^.PutPixel) then
  192. PutPixel := modeinfo^.PutPixel
  193. else
  194. begin
  195. _Graphresult := grInvalidMode;
  196. exit;
  197. end;
  198. if assigned(modeinfo^.GetPixel) then
  199. GetPixel := modeinfo^.GetPixel
  200. else
  201. begin
  202. _Graphresult := grInvalidMode;
  203. exit;
  204. end;
  205. if assigned(modeinfo^.SetRGBPalette) then
  206. SetRGBPalette := modeinfo^.SetRGBPalette
  207. else
  208. begin
  209. _Graphresult := grInvalidMode;
  210. exit;
  211. end;
  212. if assigned(modeinfo^.GetRGBPalette) then
  213. GetRGBPalette := modeinfo^.GetRGBPalette
  214. else
  215. begin
  216. _Graphresult := grInvalidMode;
  217. exit;
  218. end;
  219. { optional hooks. }
  220. if assigned(modeinfo^.ClearViewPort) then
  221. ClearViewPort := modeinfo^.ClearViewPort;
  222. if assigned(modeinfo^.PutImage) then
  223. PutImage := modeinfo^.PutImage;
  224. if assigned(modeinfo^.GetImage) then
  225. GetImage := modeinfo^.GetImage;
  226. if assigned(modeinfo^.ImageSize) then
  227. ImageSize := modeinfo^.ImageSize;
  228. if assigned(modeinfo^.GetScanLine) then
  229. GetScanLine := modeinfo^.GetScanLine;
  230. if assigned(modeinfo^.Line) then
  231. Line := modeinfo^.Line;
  232. if assigned(modeinfo^.InternalEllipse) then
  233. InternalEllipse := modeinfo^.InternalEllipse;
  234. if assigned(modeinfo^.PatternLine) then
  235. PatternLine := modeinfo^.PatternLine;
  236. if assigned(modeinfo^.HLine) then
  237. Hline := modeinfo^.Hline;
  238. if assigned(modeinfo^.Vline) then
  239. VLine := modeinfo^.VLine;
  240. if assigned(modeInfo^.SetVisualPage) then
  241. SetVisualPage := modeInfo^.SetVisualPage;
  242. if assigned(modeInfo^.SetActivePage) then
  243. SetActivePage := modeInfo^.SetActivePage;
  244. IntCurrentMode := modeinfo^.ModeNumber;
  245. IntCurrentDriver := modeinfo^.DriverNumber;
  246. XAspect := modeinfo^.XAspect;
  247. YAspect := modeinfo^.YAspect;
  248. MaxX := modeinfo^.MaxX;
  249. MaxY := modeinfo^.MaxY;
  250. MaxColor := modeinfo^.MaxColor;
  251. PaletteSize := modeinfo^.PaletteSize;
  252. { is this a direct color mode? }
  253. DirectColor := modeinfo^.DirectColor;
  254. { now actually initialize the video mode...}
  255. { check first if the routine exists }
  256. if not assigned(modeinfo^.InitMode) then
  257. begin
  258. _GraphResult := grInvalidMode;
  259. exit;
  260. end;
  261. modeinfo^.InitMode;
  262. if _GraphResult <> grOk then exit;
  263. { It is very important that this call be made }
  264. { AFTER the other variables have been setup. }
  265. { Since it calls some routines which rely on }
  266. { those variables. }
  267. SetActivePage(0);
  268. SetVisualPage(0);
  269. GraphDefaults;
  270. SetViewPort(0,0,MaxX,MaxY,TRUE);
  271. end;
  272. procedure RestoreCrtMode;
  273. {********************************************************}
  274. { Procedure RestoreCRTMode() }
  275. {--------------------------------------------------------}
  276. { Returns to the video mode which was set before the }
  277. { InitGraph. Hardware state is set to the old values. }
  278. {--------------------------------------------------------}
  279. { NOTE: - }
  280. { - }
  281. {********************************************************}
  282. begin
  283. RestoreVideoState;
  284. end;