vesa.pas 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. {
  2. This file is part of the PinGUI - Platform Independent GUI Project
  3. Copyright (c) 1999 by Berczi Gabor
  4. VESA support routines
  5. See the file COPYING.GUI, 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. unit VESA;
  12. {$ifdef DEBUG}
  13. {$define TESTGRAPHIC}
  14. {$endif DEBUG}
  15. interface
  16. uses
  17. Dos,
  18. Objects,Strings,WUtils;
  19. const
  20. { Video Mode Attributes mask constants }
  21. vesa_vma_CanBeSetInCurrentConfig = $0001;
  22. vesa_vma_OptionalBlockPresent = $0002;
  23. vesa_vma_BIOSSupport = $0004;
  24. vesa_vma_ColorMode = $0008; { else mono }
  25. vesa_vma_GraphicsMode = $0010; { else text }
  26. { -- VBE 2.0 --- }
  27. vesa_vma_VGACompatibleMode = $0020;
  28. vesa_vma_VGACompWindowedAvail = $0040;
  29. vesa_vma_LinearFrameBufferAvail = $0080;
  30. { Windows Attributes mask constants }
  31. vesa_wa_Present = $0001;
  32. vesa_wa_Readable = $0002;
  33. vesa_wa_Writeable = $0004;
  34. { Memory Model value constants }
  35. vesa_mm_Text = $0000;
  36. vesa_mm_CGAGraphics = $0001;
  37. vesa_mm_HerculesGraphics = $0002;
  38. vesa_mm_4planePlanar = $0003;
  39. vesa_mm_PackedPixel = $0004;
  40. vesa_mm_NonChain4_256color = $0005;
  41. vesa_mm_DirectColor = $0006;
  42. vesa_mm_YUV = $0007;
  43. { Memory Window value constants }
  44. vesa_mw_WindowA = $0000;
  45. vesa_mw_WindowB = $0001;
  46. type
  47. tregisters=registers;
  48. PtrRec16 = record
  49. Ofs,Seg: word;
  50. end;
  51. TVESAInfoBlock = packed record
  52. Signature : longint; { 'VESA' }
  53. Version : word;
  54. OEMString : PString;
  55. Capabilities : longint;
  56. VideoModeList: PWordArray;
  57. TotalMemory : word; { in 64KB blocks }
  58. Fill : array[1..236] of byte;
  59. VBE2Fill : array[1..256] of byte;
  60. end;
  61. TVESAModeInfoBlock = packed record
  62. Attributes : word;
  63. WinAAttrs : byte;
  64. WinBAttrs : byte;
  65. Granularity : word;
  66. Size : word;
  67. ASegment : word;
  68. BSegment : word;
  69. FuncPtr : pointer;
  70. BytesPerLine : word;
  71. { optional }
  72. XResolution : word;
  73. YResolution : word;
  74. XCharSize : byte;
  75. YCharSize : byte;
  76. NumberOfPlanes : byte;
  77. BitsPerPixel : byte;
  78. NumberOfBanks : byte;
  79. MemoryModel : byte;
  80. BankSize : byte;
  81. NumberOfImagePages: byte;
  82. Reserved : byte;
  83. { direct color fields }
  84. RedMaskSize : byte;
  85. RedFieldPosition: byte;
  86. GreenMaskSize : byte;
  87. GreenFieldPosition: byte;
  88. BlueMaskSize : byte;
  89. BlueFieldPosition: byte;
  90. ReservedMaskSize: byte;
  91. ReservedPosition: byte;
  92. DirectColorModeInfo: byte;
  93. { --- VBE 2.0 optional --- }
  94. LinearFrameAddr : longint;
  95. OffScreenAddr : longint;
  96. OffScreenSize : word;
  97. Reserved2 : array[1..216-(4+4+2)] of byte;
  98. end;
  99. TVESAModeList = record
  100. Count : word;
  101. Modes : array[1..256] of word;
  102. end;
  103. function VESAInit: boolean;
  104. function VESAGetInfo(var B: TVESAInfoBlock): boolean;
  105. function VESAGetModeInfo(Mode: word; var B: TVESAModeInfoBlock): boolean;
  106. function VESAGetModeList(var B: TVESAModeList): boolean;
  107. function VESASearchMode(XRes,YRes,BPX: word; LFB: boolean; var Mode: word; var ModeInfo: TVESAModeInfoBlock): boolean;
  108. function VESAGetOemString: string;
  109. function VESASetMode(Mode: word): boolean;
  110. function VESAGetMode(var Mode: word): boolean;
  111. function VESASelectMemoryWindow(Window: byte; Position: word): boolean;
  112. function VESAReturnMemoryWindow(Window: byte; var Position: word): boolean;
  113. function RegisterVesaVideoMode(Mode : word) : boolean;
  114. Procedure FreeVesaModes;
  115. implementation
  116. uses
  117. video, mouse,
  118. {$ifdef TESTGRAPHIC}
  119. graph,
  120. {$endif TESTGRAPHIC}
  121. pmode;
  122. type
  123. PVesaVideoMode = ^TVesaVideoMode;
  124. TVesaVideoMode = record
  125. {Col,Row : word;
  126. Color : boolean;}
  127. V : TVideoMode;
  128. Mode : word;
  129. IsGraphic : boolean;
  130. { zero based vesa specific driver count }
  131. VideoIndex : word;
  132. Next : PVesaVideoMode;
  133. end;
  134. CursorBitMap = Record
  135. width,height,size : longint;
  136. colors : array[0..8*8-1] of word;
  137. end;
  138. const
  139. VesaVideoModeHead : PVesaVideoMode = nil;
  140. VesaRegisteredModes : word = 0;
  141. {$ifdef TESTGRAPHIC}
  142. IsGraphicMode : boolean = false;
  143. GraphDriver : integer = 0;
  144. GraphMode : Integer = 0;
  145. FirstCallAfterSetVesaMode : boolean = false;
  146. LastCursorX : word = $ffff;
  147. LastCursorY : word = $ffff;
  148. LastCursorType : word = crHidden;
  149. var
  150. UnderLineImage : CursorBitMap;
  151. BlockImage : CursorBitMap;
  152. HalfBlockImage : CursorBitMap;
  153. {$endif TESTGRAPHIC}
  154. Var
  155. SysGetVideoModeCount : function : word;
  156. SysSetVideoMode : function (Const VideoMode : TVideoMode) : boolean;
  157. SysGetVideoModeData : function (Index : Word; Var Data : TVideoMode) : boolean;
  158. SysUpdateScreen : procedure(Force : Boolean);
  159. SysDoneVideo : procedure;
  160. SysInitVideo : procedure;
  161. SysSetCursorPos : procedure(NewCursorX, NewCursorY: Word);
  162. SysSetCursorType : procedure(NewCurosrType : word);
  163. function VESAGetInfo(var B: TVESAInfoBlock): boolean;
  164. var r: registers;
  165. OK: boolean;
  166. M: MemPtr;
  167. begin
  168. StrToMem('VBE2',B.Signature);
  169. GetDosMem(M,SizeOf(B));
  170. M.MoveDataTo(B,sizeof(B));
  171. r.ah:=$4f; r.al:=0;
  172. r.es:=M.DosSeg; r.di:=M.DosOfs;
  173. realintr($10,r);
  174. M.MoveDataFrom(sizeof(B),B);
  175. FreeDosMem(M);
  176. OK:=(r.ax=$004f){ and (MemToStr(B.Signature,4)='VESA')};
  177. VESAGetInfo:=OK;
  178. end;
  179. function VESAGetModeList(var B: TVESAModeList): boolean;
  180. var OK: boolean;
  181. VI: TVESAInfoBlock;
  182. begin
  183. FillChar(B,SizeOf(B),0);
  184. OK:=VESAGetInfo(VI);
  185. if OK then
  186. begin
  187. OK:=MoveDosToPM(VI.VideoModeList,@B.Modes,sizeof(B.Modes));
  188. if OK then
  189. while (B.Modes[B.Count+1]<>$ffff) and (B.Count<High(B.Modes)) do
  190. Inc(B.Count);
  191. end;
  192. VESAGetModeList:=OK;
  193. end;
  194. function VESASearchMode(XRes,YRes,BPX: word; LFB: boolean; var Mode: word; var ModeInfo: TVESAModeInfoBlock): boolean;
  195. var B: TVESAModeList;
  196. OK: boolean;
  197. I: integer;
  198. MI: TVESAModeInfoBlock;
  199. begin
  200. OK:=VESAGetModeList(B);
  201. I:=1; Mode:=0;
  202. repeat
  203. OK:=VESAGetModeInfo(B.Modes[I],MI);
  204. if OK and (MI.XResolution=XRes) and (MI.YResolution=YRes) and
  205. (MI.BitsPerPixel=BPX) and
  206. ((LFB=false) or ((MI.Attributes and vesa_vma_LinearFrameBufferAvail)<>0)) then
  207. begin Mode:=B.Modes[I]; ModeInfo:=MI; end;
  208. Inc(I);
  209. until (OK=false) or (I>=B.Count) or (Mode<>0);
  210. OK:=Mode<>0;
  211. VESASearchMode:=OK;
  212. end;
  213. function VESAGetOemString: string;
  214. var OK: boolean;
  215. VI: TVESAInfoBlock;
  216. S: array[0..256] of char;
  217. begin
  218. FillChar(S,SizeOf(S),0);
  219. OK:=VESAGetInfo(VI);
  220. if OK then
  221. OK:=MoveDosToPM(VI.OemString,@S,sizeof(S));
  222. VESAGetOemString:=StrPas(@S);
  223. end;
  224. function VESAGetModeInfo(Mode: word; var B: TVESAModeInfoBlock): boolean;
  225. var r : registers;
  226. M : MemPtr;
  227. OK: boolean;
  228. begin
  229. r.ah:=$4f; r.al:=$01; r.cx:=Mode;
  230. GetDosMem(M,sizeof(B));
  231. r.es:=M.DosSeg; r.di:=M.DosOfs; {r.ds:=r.es;}
  232. realintr($10,r);
  233. M.MoveDataFrom(sizeof(B),B);
  234. FreeDosMem(M);
  235. OK:=(r.ax=$004f);
  236. VESAGetModeInfo:=OK;
  237. end;
  238. function RegisterVesaVideoMode(Mode : word) : boolean;
  239. var B: TVESAModeInfoBlock;
  240. VH : PVesaVideoMode;
  241. DoAdd : boolean;
  242. begin
  243. if not VESAGetModeInfo(Mode,B) then
  244. RegisterVesaVideoMode:=false
  245. else
  246. begin
  247. VH:=VesaVideoModeHead;
  248. DoAdd:=true;
  249. RegisterVesaVideoMode:=false;
  250. while assigned(VH) do
  251. begin
  252. if VH^.mode=mode then
  253. DoAdd:=false;
  254. VH:=VH^.next;
  255. end;
  256. if DoAdd then
  257. begin
  258. New(VH);
  259. VH^.next:=VesaVideoModeHead;
  260. VH^.mode:=mode;
  261. VH^.IsGraphic:=(B.Attributes and vesa_vma_GraphicsMode)<>0;
  262. VH^.v.color:=(B.Attributes and vesa_vma_ColorMode)<>0;
  263. if VH^.IsGraphic then
  264. begin
  265. VH^.v.col:=B.XResolution div 8;
  266. VH^.v.row:=B.YResolution div 8;
  267. end
  268. else
  269. begin
  270. VH^.v.col:=B.XResolution;
  271. VH^.v.row:=B.YResolution;
  272. end;
  273. VH^.VideoIndex:=VesaRegisteredModes;
  274. Inc(VesaRegisteredModes);
  275. RegisterVesaVideoMode:=true;
  276. VesaVideoModeHead:=VH;
  277. end;
  278. end;
  279. end;
  280. function VESASetMode(Mode: word): boolean;
  281. var r: registers;
  282. OK: boolean;
  283. begin
  284. r.ah:=$4f; r.al:=$02; r.bx:=Mode;
  285. dos.intr($10,r);
  286. OK:=(r.ax=$004f);
  287. VESASetMode:=OK;
  288. end;
  289. function VESAGetMode(var Mode: word): boolean;
  290. var r : registers;
  291. OK: boolean;
  292. begin
  293. r.ah:=$4f; r.al:=$03;
  294. dos.intr($10,r);
  295. OK:=(r.ax=$004f);
  296. if OK then Mode:=r.bx;
  297. VESAGetMode:=OK;
  298. end;
  299. function VESASelectMemoryWindow(Window: byte; Position: word): boolean;
  300. var r : registers;
  301. OK : boolean;
  302. begin
  303. r.ah:=$4f; r.al:=$05; r.bh:=0; r.bl:=Window; r.dx:=Position;
  304. dos.intr($10,r);
  305. OK:=(r.ax=$004f);
  306. VESASelectMemoryWindow:=OK;
  307. end;
  308. function VESAReturnMemoryWindow(Window: byte; var Position: word): boolean;
  309. var r : registers;
  310. OK : boolean;
  311. begin
  312. r.ah:=$4f; r.al:=$05; r.bh:=1; r.bl:=Window;
  313. dos.intr($10,r);
  314. OK:=(r.ax=$004f);
  315. if OK then Position:=r.dx;
  316. VESAReturnMemoryWindow:=OK;
  317. end;
  318. function VESAInit: boolean;
  319. var OK: boolean;
  320. VI: TVESAInfoBlock;
  321. begin
  322. OK:=VESAGetInfo(VI);
  323. if OK then
  324. VESAInit:=OK;
  325. end;
  326. Function VesaGetVideoModeData (Index : Word; Var Data : TVideoMode) : boolean;
  327. Var
  328. PrevCount : word;
  329. VH : PVesaVideoMode;
  330. begin
  331. PrevCount:=SysGetVideoModeCount();
  332. VesaGetVideoModeData:=(Index<PrevCount);
  333. If VesaGetVideoModeData then
  334. begin
  335. VesaGetVideoModeData:=SysGetVideoModeData(Index,Data);
  336. exit;
  337. end;
  338. VesaGetVideoModeData:=(Index-PrevCount)<VesaRegisteredModes;
  339. If VesaGetVideoModeData then
  340. begin
  341. VH:=VesaVideoModeHead;
  342. while assigned(VH) and (VH^.VideoIndex<>Index-PrevCount) do
  343. VH:=VH^.next;
  344. if assigned(VH) then
  345. Data:=VH^.v
  346. else
  347. VesaGetVideoModeData:=false;
  348. end;
  349. end;
  350. function SetVESAMode(const VideoMode: TVideoMode): Boolean;
  351. var
  352. res : boolean;
  353. VH : PVesaVideoMode;
  354. begin
  355. res:=false;
  356. VH:=VesaVideoModeHead;
  357. while assigned(VH) do
  358. begin
  359. if (VideoMode.col=VH^.v.col) and
  360. (VideoMode.row=VH^.v.row) and
  361. (VideoMode.color=VH^.v.color) then
  362. begin
  363. {$ifdef TESTGRAPHIC}
  364. if VH^.IsGraphic then
  365. begin
  366. if IsGraphicMode then
  367. CloseGraph;
  368. GraphDriver:=Graph.Vesa;
  369. if (VideoMode.col = 100) and (VideoMode.row = 75) then
  370. GraphMode:=m800x600x256
  371. else if (VideoMode.col = 80) and (VideoMode.row = 60) then
  372. GraphMode:=m640x480x256
  373. else if (VideoMode.col = 128) and (VideoMode.row = 96) then
  374. GraphMode:=m1024x768x256
  375. else
  376. GraphMode:=Graph.Detect;
  377. InitGraph(GraphDriver,GraphMode,'');
  378. res:=(GraphResult=grOK);
  379. if not res then
  380. begin
  381. SetVesaMode:=false;
  382. exit;
  383. end;
  384. end
  385. else
  386. {$endif TESTGRAPHIC}
  387. res:=VESASetMode(VH^.mode);
  388. if res then
  389. begin
  390. ScreenWidth:=VideoMode.Col;
  391. ScreenHeight:=VideoMode.Row;
  392. ScreenColor:=VideoMode.Color;
  393. {$ifdef TESTGRAPHIC}
  394. IsGraphicMode:=VH^.IsGraphic;
  395. FirstCallAfterSetVesaMode:=true;
  396. LastCursorX:=$ffff;
  397. LastCursorY:=$ffff;
  398. LastCursorType:=crHidden;
  399. if IsGraphicMode then
  400. DoCustomMouse(false)
  401. else
  402. {$endif TESTGRAPHIC}
  403. DoCustomMouse(true);
  404. end;
  405. end;
  406. if res then
  407. begin
  408. SetVesaMode:=true;
  409. exit;
  410. end;
  411. VH:=VH^.next;
  412. end;
  413. SetVESAMode:=SysSetVideoMode(VideoMode);
  414. end;
  415. procedure VesaSetCursorPos(NewCursorX, NewCursorY: Word);
  416. begin
  417. {$ifdef TESTGRAPHIC}
  418. if not IsGraphicMode then
  419. {$endif TESTGRAPHIC}
  420. begin
  421. SysSetCursorPos(NewCursorX,NewCursorY);
  422. exit;
  423. end;
  424. {$ifdef TESTGRAPHIC}
  425. if (NewCursorX<>LastCursorX) or (NewCursorY<>LastCursorY) then
  426. begin
  427. Case GetCursorType of
  428. crHidden : ;
  429. crUnderLine :
  430. Begin
  431. PutImage(LastCursorX*8,LastCursorY*8+7,UnderLineImage,XORPut);
  432. PutImage(NewCursorX*8,NewCursorY*8+7,UnderLineImage,XORPut);
  433. End;
  434. crBlock :
  435. Begin
  436. PutImage(LastCursorX*8,LastCursorY*8,BlockImage,XORPut);
  437. PutImage(NewCursorX*8,NewCursorY*8,BlockImage,XORPut);
  438. End;
  439. crHalfBlock :
  440. Begin
  441. PutImage(LastCursorX*8,LastCursorY*8+4,HalfBlockImage,XORPut);
  442. PutImage(NewCursorX*8,NewCursorY*8+4,HalfBlockImage,XORPut);
  443. End;
  444. end;
  445. LastCursorX:=NewCursorX;
  446. LastCursorY:=NewCursorY;
  447. end;
  448. {$endif TESTGRAPHIC}
  449. end;
  450. procedure VesaSetCursorType(NewType : Word);
  451. begin
  452. {$ifdef TESTGRAPHIC}
  453. if not IsGraphicMode then
  454. {$endif TESTGRAPHIC}
  455. begin
  456. SysSetCursorType(NewType);
  457. exit;
  458. end;
  459. {$ifdef TESTGRAPHIC}
  460. if (NewType<>LastCursorType) then
  461. begin
  462. Case LastCursorType of
  463. crHidden : ;
  464. crUnderLine :
  465. Begin
  466. PutImage(LastCursorX*8,LastCursorY*8+7,UnderLineImage,XORPut);
  467. End;
  468. crBlock :
  469. Begin
  470. PutImage(LastCursorX*8,LastCursorY*8,BlockImage,XORPut);
  471. End;
  472. crHalfBlock :
  473. Begin
  474. PutImage(LastCursorX*8,LastCursorY*8+4,HalfBlockImage,XORPut);
  475. End;
  476. end;
  477. SysSetCursorType(NewType);
  478. Case NewType of
  479. crHidden : ;
  480. crUnderLine :
  481. Begin
  482. PutImage(LastCursorX*8,LastCursorY*8+7,UnderLineImage,XORPut);
  483. End;
  484. crBlock :
  485. Begin
  486. PutImage(LastCursorX*8,LastCursorY*8,BlockImage,XORPut);
  487. End;
  488. crHalfBlock :
  489. Begin
  490. PutImage(LastCursorX*8,LastCursorY*8+4,HalfBlockImage,XORPut);
  491. End;
  492. end;
  493. LastCursorType:=NewType;
  494. end;
  495. {$endif TESTGRAPHIC}
  496. end;
  497. procedure VesaUpdateScreen(Force: Boolean);
  498. {$ifdef TESTGRAPHIC}
  499. var
  500. StoreDrawTextBackground,
  501. MustUpdate : boolean;
  502. x,y : longint;
  503. w, prevcolor,
  504. prevbkcolor, StoreCursorType : word;
  505. Color,BkCol,Col : byte;
  506. Ch : char;
  507. {$endif TESTGRAPHIC}
  508. begin
  509. {$ifdef TESTGRAPHIC}
  510. if not IsGraphicMode then
  511. {$endif TESTGRAPHIC}
  512. begin
  513. SysUpdateScreen(Force);
  514. exit;
  515. end;
  516. {$ifdef TESTGRAPHIC}
  517. if FirstCallAfterSetVesaMode then
  518. begin
  519. { Make sure to redraw all }
  520. Fillchar(OldVideoBuf^,VideoBufSize,#0);
  521. FirstCallAfterSetVesaMode:=false;
  522. end;
  523. if not force then
  524. begin
  525. MustUpdate:=false;
  526. asm
  527. movl VideoBuf,%esi
  528. movl OldVideoBuf,%edi
  529. movl VideoBufSize,%ecx
  530. shrl $2,%ecx
  531. repe
  532. cmpsl
  533. setne MustUpdate
  534. end;
  535. end;
  536. StoreDrawTextBackground:=DrawTextBackground;
  537. DrawTextBackground:=true;
  538. if Force or MustUpdate then
  539. begin
  540. PrevColor:=GetColor;
  541. PrevBkColor:=GetBkColor;
  542. for y:=0 to ScreenHeight-1 do
  543. for x:=0 to Screenwidth-1 do
  544. begin
  545. w:=VideoBuf^[x+y*ScreenWidth];
  546. if Force or
  547. (w<>OldVideoBuf^[x+y*ScreenWidth]) then
  548. Begin
  549. Color:=w shr 8;
  550. Ch:=chr(w and $ff);
  551. Col:=Color and $f;
  552. if (Col = 0) and (GetMaxColor=255) then
  553. Col:=255;
  554. SetColor(Col);
  555. BkCol:=(Color shr 4) and 7;
  556. if (BkCol = 0) and (GetMaxColor=255) then
  557. BkCol:=255;
  558. SetBkColor(BkCol);
  559. if (x=LastCursorX) and (Y=LastCursorY) then
  560. begin
  561. StoreCursorType:=LastCursorType;
  562. VesaSetCursorType(crHidden);
  563. end;
  564. OutTextXY(x*8,y*8,Ch);
  565. if (x=LastCursorX) and (Y=LastCursorY) then
  566. VesaSetCursorType(StoreCursorType);
  567. if not force then
  568. OldVideoBuf^[x+y*ScreenWidth]:=w;
  569. End;
  570. end;
  571. if Force then
  572. move(videobuf^,oldvideobuf^,
  573. VideoBufSize);
  574. SetColor(PrevColor);
  575. SetBkColor(GetBkColor);
  576. end;
  577. DrawTextBackground:=StoreDrawTextBackground;
  578. {$endif TESTGRAPHIC}
  579. end;
  580. procedure VesaDoneVideo;
  581. begin
  582. {$ifdef TESTGRAPHIC}
  583. if IsGraphicMode then
  584. begin
  585. CloseGraph;
  586. IsGraphicMode:=false;
  587. end;
  588. {$endif TESTGRAPHIC}
  589. SysDoneVideo();
  590. end;
  591. procedure VesaInitVideo;
  592. begin
  593. {$ifdef TESTGRAPHIC}
  594. if IsGraphicMode then
  595. begin
  596. SysInitVideo();
  597. InitGraph(GraphDriver,GraphMode,'');
  598. end
  599. else
  600. {$endif TESTGRAPHIC}
  601. SysInitVideo();
  602. end;
  603. Function VesaGetVideoModeCount : Word;
  604. begin
  605. VesaGetVideoModeCount:=SysGetVideoModeCount()+VesaRegisteredModes;
  606. end;
  607. Procedure FreeVesaModes;
  608. var
  609. VH : PVesaVideoMode;
  610. begin
  611. VH:=VesaVideoModeHead;
  612. While assigned(VH) do
  613. begin
  614. VesaVideoModeHead:=VH^.Next;
  615. FreeMem(VH,Sizeof(TVesaVideoMode));
  616. VH:=VesaVideoModeHead;
  617. end;
  618. end;
  619. Var
  620. Driver : TVideoDriver;
  621. {$ifdef TESTGRAPHIC}
  622. i : longint;
  623. {$endif TESTGRAPHIC}
  624. BEGIN
  625. { Get the videodriver to be used }
  626. GetVideoDriver (Driver);
  627. { Change needed functions }
  628. SysGetVideoModeCount:=Driver.GetVideoModeCount;
  629. Driver.GetVideoModeCount:=@VesaGetVideoModeCount;
  630. SysGetVideoModeData:=Driver.GetVideoModeData;
  631. Driver.GetVideoModeData:=@VesaGetVideoModeData;
  632. SysSetVideoMode:=Driver.SetVideoMode;
  633. Driver.SetVideoMode:=@SetVESAMode;
  634. SysSetCursorPos:=Driver.SetCursorPos;
  635. Driver.SetCursorPos:=@VESASetCursorPos;
  636. SysSetCursorType:=Driver.SetCursorType;
  637. Driver.SetCursorType:=@VESASetCursorType;
  638. SysUpdateScreen:=Driver.UpdateScreen;
  639. Driver.UpdateScreen:=@VesaUpdateScreen;
  640. SysDoneVideo:=Driver.DoneDriver;
  641. Driver.DoneDriver:=@VesaDoneVideo;
  642. SysInitVideo:=Driver.InitDriver;
  643. Driver.InitDriver:=@VesaInitVideo;
  644. {$ifdef TESTGRAPHIC}
  645. BlockImage.width:=7;
  646. BlockImage.height:=7;
  647. For i:=0 to 8*8-1 do
  648. BlockImage.colors[i]:=White;
  649. HalfBlockImage:=BlockImage;
  650. HalfBlockImage.height:=3;
  651. UnderLineImage:=BlockImage;
  652. UnderLineImage.height:=0;
  653. {$endif TESTGRAPHIC}
  654. SetVideoDriver (Driver);
  655. END.