modes.inc 13 KB

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