modes.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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(TModeInfo));
  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(TModeInfo));
  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(TModeInfo),#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. procedure cleanmode;far;
  78. {********************************************************}
  79. { Procedure CleanMode() }
  80. {--------------------------------------------------------}
  81. { This routine deallocates the mode list. }
  82. { It is called as an exit procedure ONLY. }
  83. {********************************************************}
  84. var
  85. list: PModeInfo;
  86. tmp : PModeInfo;
  87. begin
  88. list := ModeList;
  89. { go to the end of the list }
  90. while assigned(list) do
  91. begin
  92. tmp := list;
  93. list:=list^.next;
  94. dispose(tmp);
  95. end;
  96. end;
  97. {-----------------------------------------------------------------------}
  98. { External routines }
  99. {-----------------------------------------------------------------------}
  100. function GetModeName(ModeNumber: integer): string;
  101. {********************************************************}
  102. { Function GetModeName() }
  103. {--------------------------------------------------------}
  104. { Checks the known video list, and returns ModeName }
  105. { string. On error returns an empty string. }
  106. {********************************************************}
  107. var
  108. mode: PModeInfo;
  109. begin
  110. mode:=nil;
  111. GetModeName:='';
  112. { only search in the current driver modes ... }
  113. mode:=SearchMode(IntCurrentDriver,ModeNumber);
  114. if assigned(mode) then
  115. GetModeName:=Mode^.ModeName
  116. else
  117. _GraphResult := grInvalidMode;
  118. end;
  119. function GetGraphMode: Integer;
  120. begin
  121. GetGraphMode := IntCurrentMode;
  122. end;
  123. function GetMaxMode: word;
  124. { I know , i know, this routine is very slow, and it would }
  125. { be much easier to sort the linked list of possible modes }
  126. { instead of doing this, but I'm lazy!! And anyways, the }
  127. { speed of the routine here is not that important.... }
  128. var
  129. i: word;
  130. mode: PModeInfo;
  131. begin
  132. mode:=nil;
  133. i:=0;
  134. repeat
  135. inc(i);
  136. { mode 0 always exists... }
  137. { start search at 1.. }
  138. mode:=SearchMode(IntCurrentDriver,i);
  139. until not assigned(mode);
  140. GetMaxMode:=i;
  141. end;
  142. procedure GetModeRange(GraphDriver: Integer; var LoMode,
  143. HiMode: Integer);
  144. var
  145. i : integer;
  146. mode : PModeInfo;
  147. begin
  148. LoMode:=-1;
  149. HiMode:=-1;
  150. mode := nil;
  151. { First search if the graphics driver is supported .. }
  152. { since mode zero is always supported.. if that driver }
  153. { is supported it should return something... }
  154. mode := SearchMode(GraphDriver, 0);
  155. { driver not supported...}
  156. if not assigned(mode) then exit;
  157. { now it exists... find highest available mode... }
  158. LoMode := 0;
  159. mode:=nil;
  160. i:=-1;
  161. repeat
  162. inc(i);
  163. { start search at 0.. }
  164. mode:=SearchMode(GraphDriver,i);
  165. until not assigned(mode);
  166. HiMode := i-1;
  167. end;
  168. procedure SetGraphMode(mode: Integer);
  169. var
  170. modeinfo: PModeInfo;
  171. begin
  172. { check if the mode exists... }
  173. modeinfo := searchmode(IntcurrentDriver,mode);
  174. if not assigned(modeinfo) then
  175. begin
  176. _GraphResult := grInvalidMode;
  177. exit;
  178. end;
  179. { reset all hooks...}
  180. DefaultHooks;
  181. { arccall not reset - tested against VGA BGI driver }
  182. { Setup all hooks if none, keep old defaults...}
  183. { required hooks - returns error if no hooks to these }
  184. { routines. }
  185. if assigned(modeinfo^.DirectPutPixel) then
  186. DirectPutPixel := modeinfo^.DirectPutPixel
  187. else
  188. begin
  189. _Graphresult := grInvalidMode;
  190. exit;
  191. end;
  192. if assigned(modeinfo^.PutPixel) then
  193. PutPixel := modeinfo^.PutPixel
  194. else
  195. begin
  196. _Graphresult := grInvalidMode;
  197. exit;
  198. end;
  199. if assigned(modeinfo^.GetPixel) then
  200. GetPixel := modeinfo^.GetPixel
  201. else
  202. begin
  203. _Graphresult := grInvalidMode;
  204. exit;
  205. end;
  206. if assigned(modeinfo^.SetRGBPalette) then
  207. SetRGBPalette := modeinfo^.SetRGBPalette
  208. else
  209. begin
  210. _Graphresult := grInvalidMode;
  211. exit;
  212. end;
  213. if assigned(modeinfo^.GetRGBPalette) then
  214. GetRGBPalette := modeinfo^.GetRGBPalette
  215. else
  216. begin
  217. _Graphresult := grInvalidMode;
  218. exit;
  219. end;
  220. { optional hooks. }
  221. if assigned(modeinfo^.ClearViewPort) then
  222. ClearViewPort := modeinfo^.ClearViewPort;
  223. if assigned(modeinfo^.PutImage) then
  224. PutImage := modeinfo^.PutImage;
  225. if assigned(modeinfo^.GetImage) then
  226. GetImage := modeinfo^.GetImage;
  227. if assigned(modeinfo^.ImageSize) then
  228. ImageSize := modeinfo^.ImageSize;
  229. if assigned(modeinfo^.GetScanLine) then
  230. GetScanLine := modeinfo^.GetScanLine;
  231. if assigned(modeinfo^.Line) then
  232. Line := modeinfo^.Line;
  233. if assigned(modeinfo^.InternalEllipse) then
  234. InternalEllipse := modeinfo^.InternalEllipse;
  235. if assigned(modeinfo^.PatternLine) then
  236. PatternLine := modeinfo^.PatternLine;
  237. if assigned(modeinfo^.HLine) then
  238. Hline := modeinfo^.Hline;
  239. if assigned(modeinfo^.Vline) then
  240. VLine := modeinfo^.VLine;
  241. if assigned(modeInfo^.SetVisualPage) then
  242. SetVisualPage := modeInfo^.SetVisualPage;
  243. if assigned(modeInfo^.SetActivePage) then
  244. SetActivePage := modeInfo^.SetActivePage;
  245. IntCurrentMode := modeinfo^.ModeNumber;
  246. IntCurrentDriver := modeinfo^.DriverNumber;
  247. XAspect := modeinfo^.XAspect;
  248. YAspect := modeinfo^.YAspect;
  249. MaxX := modeinfo^.MaxX;
  250. MaxY := modeinfo^.MaxY;
  251. HardwarePages := modeInfo^.HardwarePages;
  252. MaxColor := modeinfo^.MaxColor;
  253. PaletteSize := modeinfo^.PaletteSize;
  254. { is this a direct color mode? }
  255. DirectColor := modeinfo^.DirectColor;
  256. { now actually initialize the video mode...}
  257. { check first if the routine exists }
  258. if not assigned(modeinfo^.InitMode) then
  259. begin
  260. _GraphResult := grInvalidMode;
  261. exit;
  262. end;
  263. modeinfo^.InitMode;
  264. if _GraphResult <> grOk then exit;
  265. { It is very important that this call be made }
  266. { AFTER the other variables have been setup. }
  267. { Since it calls some routines which rely on }
  268. { those variables. }
  269. SetActivePage(0);
  270. SetVisualPage(0);
  271. GraphDefaults;
  272. SetViewPort(0,0,MaxX,MaxY,TRUE);
  273. end;
  274. procedure RestoreCrtMode;
  275. {********************************************************}
  276. { Procedure RestoreCRTMode() }
  277. {--------------------------------------------------------}
  278. { Returns to the video mode which was set before the }
  279. { InitGraph. Hardware state is set to the old values. }
  280. {--------------------------------------------------------}
  281. { NOTE: - }
  282. { - }
  283. {********************************************************}
  284. begin
  285. RestoreVideoState;
  286. end;
  287. {
  288. $Log$
  289. Revision 1.7 1999-07-12 13:27:14 jonas
  290. + added Log and Id tags
  291. * added first FPC support, only VGA works to some extend for now
  292. * use -dasmgraph to use assembler routines, otherwise Pascal
  293. equivalents are used
  294. * use -dsupportVESA to support VESA (crashes under FPC for now)
  295. * only dispose vesainfo at closegrph if a vesa card was detected
  296. * changed int32 to longint (int32 is not declared under FPC)
  297. * changed the declaration of almost every procedure in graph.inc to
  298. "far;" becquse otherwise you can't assign them to procvars under TP
  299. real mode (but unexplainable "data segnment too large" errors prevent
  300. it from working under real mode anyway)
  301. }