modes.inc 15 KB

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