vesa.pas 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. {
  2. $Id$
  3. This file is part of the PinGUI - Platform Independent GUI Project
  4. Copyright (c) 1999 by Berczi Gabor
  5. VESA support routines
  6. See the file COPYING.GUI, 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. unit VESA;
  13. interface
  14. uses
  15. Dos,
  16. Objects,Strings,WUtils;
  17. const
  18. { Video Mode Attributes mask constants }
  19. vesa_vma_CanBeSetInCurrentConfig = $0001;
  20. vesa_vma_OptionalBlockPresent = $0002;
  21. vesa_vma_BIOSSupport = $0004;
  22. vesa_vma_ColorMode = $0008; { else mono }
  23. vesa_vma_GraphicsMode = $0010; { else text }
  24. { -- VBE 2.0 --- }
  25. vesa_vma_VGACompatibleMode = $0020;
  26. vesa_vma_VGACompWindowedAvail = $0040;
  27. vesa_vma_LinearFrameBufferAvail = $0080;
  28. { Windows Attributes mask constants }
  29. vesa_wa_Present = $0001;
  30. vesa_wa_Readable = $0002;
  31. vesa_wa_Writeable = $0004;
  32. { Memory Model value constants }
  33. vesa_mm_Text = $0000;
  34. vesa_mm_CGAGraphics = $0001;
  35. vesa_mm_HerculesGraphics = $0002;
  36. vesa_mm_4planePlanar = $0003;
  37. vesa_mm_PackedPixel = $0004;
  38. vesa_mm_NonChain4_256color = $0005;
  39. vesa_mm_DirectColor = $0006;
  40. vesa_mm_YUV = $0007;
  41. { Memory Window value constants }
  42. vesa_mw_WindowA = $0000;
  43. vesa_mw_WindowB = $0001;
  44. type
  45. {$ifdef FPC}tregisters=registers;{$endif}
  46. {$ifdef TP}tregisters=registers;{$endif}
  47. PtrRec16 = record
  48. Ofs,Seg: word;
  49. end;
  50. TVESAInfoBlock = record
  51. Signature : longint; { 'VESA' }
  52. Version : word;
  53. OEMString : PString;
  54. Capabilities : longint;
  55. VideoModeList: PWordArray;
  56. TotalMemory : word; { in 64KB blocks }
  57. Fill : array[1..236] of byte;
  58. VBE2Fill : array[1..256] of byte;
  59. end;
  60. TVESAModeInfoBlock = record
  61. Attributes : word;
  62. WinAAttrs : byte;
  63. WinBAttrs : byte;
  64. Granularity : word;
  65. Size : word;
  66. ASegment : word;
  67. BSegment : word;
  68. FuncPtr : pointer;
  69. BytesPerLine : word;
  70. { optional }
  71. XResolution : word;
  72. YResolution : word;
  73. XCharSize : byte;
  74. YCharSize : byte;
  75. NumberOfPlanes : byte;
  76. BitsPerPixel : byte;
  77. NumberOfBanks : byte;
  78. MemoryModel : byte;
  79. BankSize : byte;
  80. NumberOfImagePages: byte;
  81. Reserved : byte;
  82. { direct color fields }
  83. RedMaskSize : byte;
  84. RedFieldPosition: byte;
  85. GreenMaskSize : byte;
  86. GreenFieldPosition: byte;
  87. BlueMaskSize : byte;
  88. BlueFieldPosition: byte;
  89. ReservedMaskSize: byte;
  90. ReservedPosition: byte;
  91. DirectColorModeInfo: byte;
  92. { --- VBE 2.0 optional --- }
  93. LinearFrameAddr : longint;
  94. OffScreenAddr : longint;
  95. OffScreenSize : word;
  96. Reserved2 : array[1..216-(4+4+2)] of byte;
  97. end;
  98. TVESAModeList = record
  99. Count : word;
  100. Modes : array[1..256] of word;
  101. end;
  102. function VESAInit: boolean;
  103. function VESAGetInfo(var B: TVESAInfoBlock): boolean;
  104. function VESAGetModeInfo(Mode: word; var B: TVESAModeInfoBlock): boolean;
  105. function VESAGetModeList(var B: TVESAModeList): boolean;
  106. function VESASearchMode(XRes,YRes,BPX: word; LFB: boolean; var Mode: word; var ModeInfo: TVESAModeInfoBlock): boolean;
  107. function VESAGetOemString: string;
  108. function VESASetMode(Mode: word): boolean;
  109. function VESAGetMode(var Mode: word): boolean;
  110. function VESASelectMemoryWindow(Window: byte; Position: word): boolean;
  111. function VESAReturnMemoryWindow(Window: byte; var Position: word): boolean;
  112. implementation
  113. uses pmode;
  114. function VESAGetInfo(var B: TVESAInfoBlock): boolean;
  115. var r: registers;
  116. OK: boolean;
  117. M: MemPtr;
  118. begin
  119. StrToMem('VBE2',B.Signature);
  120. GetDosMem(M,SizeOf(B));
  121. M.MoveDataTo(B,sizeof(B));
  122. r.ah:=$4f; r.al:=0;
  123. r.es:=M.DosSeg; r.di:=M.DosOfs;
  124. realintr($10,r);
  125. M.MoveDataFrom(sizeof(B),B);
  126. FreeDosMem(M);
  127. OK:=(r.ax=$004f){ and (MemToStr(B.Signature,4)='VESA')};
  128. VESAGetInfo:=OK;
  129. end;
  130. function VESAGetModeList(var B: TVESAModeList): boolean;
  131. var OK: boolean;
  132. VI: TVESAInfoBlock;
  133. begin
  134. FillChar(B,SizeOf(B),0);
  135. OK:=VESAGetInfo(VI);
  136. if OK then
  137. begin
  138. OK:=MoveDosToPM(VI.VideoModeList,@B.Modes,sizeof(B.Modes));
  139. if OK then
  140. while (B.Modes[B.Count+1]<>$ffff) and (B.Count<High(B.Modes)) do
  141. Inc(B.Count);
  142. end;
  143. VESAGetModeList:=OK;
  144. end;
  145. function VESASearchMode(XRes,YRes,BPX: word; LFB: boolean; var Mode: word; var ModeInfo: TVESAModeInfoBlock): boolean;
  146. var B: TVESAModeList;
  147. OK: boolean;
  148. I: integer;
  149. MI: TVESAModeInfoBlock;
  150. begin
  151. OK:=VESAGetModeList(B);
  152. I:=1; Mode:=0;
  153. repeat
  154. OK:=VESAGetModeInfo(B.Modes[I],MI);
  155. if OK and (MI.XResolution=XRes) and (MI.YResolution=YRes) and
  156. (MI.BitsPerPixel=BPX) and
  157. ((LFB=false) or ((MI.Attributes and vesa_vma_LinearFrameBufferAvail)<>0)) then
  158. begin Mode:=B.Modes[I]; ModeInfo:=MI; end;
  159. Inc(I);
  160. until (OK=false) or (I>=B.Count) or (Mode<>0);
  161. OK:=Mode<>0;
  162. VESASearchMode:=OK;
  163. end;
  164. function VESAGetOemString: string;
  165. var OK: boolean;
  166. VI: TVESAInfoBlock;
  167. S: array[0..256] of char;
  168. begin
  169. FillChar(S,SizeOf(S),0);
  170. OK:=VESAGetInfo(VI);
  171. if OK then
  172. OK:=MoveDosToPM(VI.OemString,@S,sizeof(S));
  173. VESAGetOemString:=StrPas(@S);
  174. end;
  175. function VESAGetModeInfo(Mode: word; var B: TVESAModeInfoBlock): boolean;
  176. var r : registers;
  177. M : MemPtr;
  178. OK: boolean;
  179. begin
  180. r.ah:=$4f; r.al:=$01; r.cx:=Mode;
  181. GetDosMem(M,sizeof(B));
  182. r.es:=M.DosSeg; r.di:=M.DosOfs; {r.ds:=r.es;}
  183. realintr($10,r);
  184. M.MoveDataFrom(sizeof(B),B);
  185. FreeDosMem(M);
  186. OK:=(r.ax=$004f);
  187. VESAGetModeInfo:=OK;
  188. end;
  189. function VESASetMode(Mode: word): boolean;
  190. var r: registers;
  191. OK: boolean;
  192. begin
  193. r.ah:=$4f; r.al:=$02; r.bx:=Mode;
  194. dos.intr($10,r);
  195. OK:=(r.ax=$004f);
  196. VESASetMode:=OK;
  197. end;
  198. function VESAGetMode(var Mode: word): boolean;
  199. var r : registers;
  200. OK: boolean;
  201. begin
  202. r.ah:=$4f; r.al:=$03;
  203. dos.intr($10,r);
  204. OK:=(r.ax=$004f);
  205. if OK then Mode:=r.bx;
  206. VESAGetMode:=OK;
  207. end;
  208. function VESASelectMemoryWindow(Window: byte; Position: word): boolean;
  209. var r : registers;
  210. OK : boolean;
  211. begin
  212. r.ah:=$4f; r.al:=$05; r.bh:=0; r.bl:=Window; r.dx:=Position;
  213. dos.intr($10,r);
  214. OK:=(r.ax=$004f);
  215. VESASelectMemoryWindow:=OK;
  216. end;
  217. function VESAReturnMemoryWindow(Window: byte; var Position: word): boolean;
  218. var r : registers;
  219. OK : boolean;
  220. begin
  221. r.ah:=$4f; r.al:=$05; r.bh:=1; r.bl:=Window;
  222. dos.intr($10,r);
  223. OK:=(r.ax=$004f);
  224. if OK then Position:=r.dx;
  225. VESAReturnMemoryWindow:=OK;
  226. end;
  227. function VESAInit: boolean;
  228. var OK: boolean;
  229. VI: TVESAInfoBlock;
  230. begin
  231. OK:=VESAGetInfo(VI);
  232. VESAInit:=OK;
  233. end;
  234. BEGIN
  235. END.
  236. {
  237. $Log$
  238. Revision 1.1 2001-08-04 11:30:25 peter
  239. * ide works now with both compiler versions
  240. Revision 1.1 2000/07/13 09:48:36 michael
  241. + Initial import
  242. Revision 1.8 2000/06/22 09:07:13 pierre
  243. * Gabor changes: see fixes.txt
  244. Revision 1.7 2000/03/21 23:22:37 pierre
  245. Gabor fixes to avoid unused vars
  246. Revision 1.6 2000/01/03 11:38:35 michael
  247. Changes from Gabor
  248. Revision 1.4 1999/04/07 21:55:58 peter
  249. + object support for browser
  250. * html help fixes
  251. * more desktop saving things
  252. * NODEBUG directive to exclude debugger
  253. Revision 1.3 1999/04/01 10:04:18 pierre
  254. * uses typo errror fixed
  255. Revision 1.2 1999/03/26 19:09:44 peter
  256. * fixed for go32v2
  257. Revision 1.1 1999/03/23 15:11:39 peter
  258. * desktop saving things
  259. * vesa mode
  260. * preferences dialog
  261. }