video.pp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Florian Klaempfl
  5. member of the Free Pascal development team
  6. Video unit for DOS
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. unit Video;
  14. interface
  15. {$i videoh.inc}
  16. var
  17. VideoSeg : word;
  18. implementation
  19. uses
  20. mouse,
  21. go32;
  22. {$i video.inc}
  23. {$ASMMODE ATT}
  24. { used to know if LastCursorType is valid }
  25. const
  26. LastCursorType : word = crUnderline;
  27. { allways set blink state again }
  28. procedure SetHighBitBlink;
  29. var
  30. regs : trealregs;
  31. begin
  32. regs.ax:=$1003;
  33. regs.bx:=$0001;
  34. realintr($10,regs);
  35. end;
  36. function BIOSGetScreenMode(var Cols,Rows: word; var Color: boolean): boolean;
  37. var r: trealregs;
  38. L: longint;
  39. LSel,LSeg: word;
  40. B: array[0..63] of byte;
  41. type
  42. TWord = word;
  43. PWord = ^TWord;
  44. var
  45. OK: boolean;
  46. begin
  47. L:=global_dos_alloc(64);
  48. LSeg:=(L shr 16);
  49. LSel:=(L and $ffff);
  50. r.ah:=$1b; r.bx:=0;
  51. r.es:=LSeg; r.di:=0;
  52. realintr($10,r);
  53. OK:=(r.al=$1b);
  54. if OK then
  55. begin
  56. dpmi_dosmemget(LSeg,0,B,64);
  57. Cols:=PWord(@B[5])^; Rows:=B[$22];
  58. Color:=PWord(@B[$27])^<>0;
  59. end;
  60. global_dos_free(LSel);
  61. BIOSGetScreenMode:=OK;
  62. end;
  63. procedure SysInitVideo;
  64. var
  65. regs : trealregs;
  66. begin
  67. VideoSeg:=$b800;
  68. if (ScreenWidth=$ffff) or (ScreenHeight=$ffff) or
  69. (ScreenWidth=0) or (ScreenHeight=0) then
  70. begin
  71. ScreenColor:=true;
  72. regs.ah:=$0f;
  73. realintr($10,regs);
  74. if (regs.al and 1)=0 then
  75. ScreenColor:=false;
  76. if regs.al=7 then
  77. begin
  78. ScreenColor:=false;
  79. VideoSeg:=$b000;
  80. end
  81. else
  82. VideoSeg:=$b800;
  83. ScreenWidth:=regs.ah;
  84. regs.ax:=$1130;
  85. regs.bx:=0;
  86. realintr($10,regs);
  87. ScreenHeight:=regs.dl+1;
  88. BIOSGetScreenMode(ScreenWidth,ScreenHeight,ScreenColor);
  89. end;
  90. regs.ah:=$03;
  91. regs.bh:=0;
  92. realintr($10,regs);
  93. CursorLines:=regs.cl;
  94. CursorX:=regs.dl;
  95. CursorY:=regs.dh;
  96. SetHighBitBlink;
  97. SetCursorType(LastCursorType);
  98. end;
  99. procedure SysDoneVideo;
  100. begin
  101. LastCursorType:=GetCursorType;
  102. ClearScreen;
  103. SetCursorType(crUnderLine);
  104. SetCursorPos(0,0);
  105. end;
  106. function SysGetCapabilities: Word;
  107. begin
  108. SysGetCapabilities := $3F;
  109. end;
  110. procedure SysSetCursorPos(NewCursorX, NewCursorY: Word);
  111. var
  112. regs : trealregs;
  113. begin
  114. regs.ah:=$02;
  115. regs.bh:=0;
  116. regs.dh:=NewCursorY;
  117. regs.dl:=NewCursorX;
  118. realintr($10,regs);
  119. CursorY:=regs.dh;
  120. CursorX:=regs.dl;
  121. end;
  122. { I don't know the maximum value for the scan line
  123. probably 7 or 15 depending on resolution !!
  124. }
  125. function SysGetCursorType: Word;
  126. var
  127. regs : trealregs;
  128. begin
  129. regs.ah:=$03;
  130. regs.bh:=0;
  131. realintr($10,regs);
  132. SysGetCursorType:=crHidden;
  133. if (regs.ch and $60)=0 then
  134. begin
  135. SysGetCursorType:=crBlock;
  136. if (regs.ch and $1f)<>0 then
  137. begin
  138. SysGetCursorType:=crHalfBlock;
  139. if regs.cl-1=(regs.ch and $1F) then
  140. SysGetCursorType:=crUnderline;
  141. end;
  142. end;
  143. end;
  144. procedure SysSetCursorType(NewType: Word);
  145. var
  146. regs : trealregs;
  147. const
  148. MaxCursorLines = 7;
  149. begin
  150. regs.ah:=$01;
  151. regs.bx:=NewType;
  152. case NewType of
  153. crHidden : regs.cx:=$2000;
  154. crHalfBlock : begin
  155. regs.ch:=MaxCursorLines shr 1;
  156. regs.cl:=MaxCursorLines;
  157. end;
  158. crBlock : begin
  159. regs.ch:=0;
  160. regs.cl:=MaxCursorLines;
  161. end;
  162. else begin
  163. regs.ch:=MaxCursorLines-1;
  164. regs.cl:=MaxCursorLines;
  165. end;
  166. end;
  167. realintr($10,regs);
  168. end;
  169. procedure SysUpdateScreen(Force: Boolean);
  170. begin
  171. if not force then
  172. begin
  173. asm
  174. pushl %esi
  175. pushl %edi
  176. movl VideoBuf,%esi
  177. movl OldVideoBuf,%edi
  178. movl VideoBufSize,%ecx
  179. shrl $2,%ecx
  180. repe
  181. cmpsl
  182. setne force
  183. popl %edi
  184. popl %esi
  185. end;
  186. end;
  187. if Force then
  188. begin
  189. dosmemput(videoseg,0,videobuf^,VideoBufSize);
  190. move(videobuf^,oldvideobuf^,VideoBufSize);
  191. end;
  192. end;
  193. Procedure DoSetVideoMode(Params: Longint);
  194. type
  195. wordrec=packed record
  196. lo,hi : word;
  197. end;
  198. var
  199. regs : trealregs;
  200. begin
  201. regs.ax:=wordrec(Params).lo;
  202. regs.bx:=wordrec(Params).hi;
  203. realintr($10,regs);
  204. end;
  205. Procedure SetVideo8x8;
  206. type
  207. wordrec=packed record
  208. lo,hi : word;
  209. end;
  210. var
  211. regs : trealregs;
  212. begin
  213. regs.ax:=3;
  214. regs.bx:=0;
  215. realintr($10,regs);
  216. regs.ax:=$1112;
  217. regs.bx:=$0;
  218. realintr($10,regs);
  219. end;
  220. Const
  221. SysVideoModeCount = 5;
  222. SysVMD : Array[0..SysVideoModeCount-1] of TVideoMode = (
  223. (Col: 40; Row : 25; Color : False),
  224. (Col: 40; Row : 25; Color : True),
  225. (Col: 80; Row : 25; Color : False),
  226. (Col: 80; Row : 25; Color : True),
  227. (Col: 80; Row : 50; Color : True)
  228. );
  229. Function SysSetVideoMode (Const Mode : TVideoMode) : Boolean;
  230. Var
  231. I : Integer;
  232. begin
  233. I:=SysVideoModeCount-1;
  234. SysSetVideoMode:=False;
  235. While (I>=0) and Not SysSetVideoMode do
  236. If (Mode.col=SysVMD[i].col) and
  237. (Mode.Row=SysVMD[i].Row) and
  238. (Mode.Color=SysVMD[i].Color) then
  239. SysSetVideoMode:=True
  240. else
  241. Dec(I);
  242. If SysSetVideoMode then
  243. begin
  244. If (I<SysVideoModeCount-1) then
  245. DoSetVideoMode(I)
  246. else
  247. SetVideo8x8;
  248. ScreenWidth:=SysVMD[I].Col;
  249. ScreenHeight:=SysVMD[I].Row;
  250. ScreenColor:=SysVMD[I].Color;
  251. DoCustomMouse(false);
  252. end;
  253. end;
  254. Function SysGetVideoModeData (Index : Word; Var Data : TVideoMode) : boolean;
  255. begin
  256. SysGetVideoModeData:=(Index<=SysVideoModeCount);
  257. If SysGetVideoModeData then
  258. Data:=SysVMD[Index];
  259. end;
  260. Function SysGetVideoModeCount : Word;
  261. begin
  262. SysGetVideoModeCount:=SysVideoModeCount;
  263. end;
  264. Const
  265. SysVideoDriver : TVideoDriver = (
  266. InitDriver : @SysInitVideo;
  267. DoneDriver : @SysDoneVideo;
  268. UpdateScreen : @SysUpdateScreen;
  269. ClearScreen : Nil;
  270. SetVideoMode : @SysSetVideoMode;
  271. GetVideoModeCount : @SysGetVideoModeCount;
  272. GetVideoModeData : @SysGetVideoModedata;
  273. SetCursorPos : @SysSetCursorPos;
  274. GetCursorType : @SysGetCursorType;
  275. SetCursorType : @SysSetCursorType;
  276. GetCapabilities : @SysGetCapabilities
  277. );
  278. initialization
  279. SetVideoDriver(SysVideoDriver);
  280. end.
  281. {
  282. $Log$
  283. Revision 1.7 2003-10-03 21:46:25 peter
  284. * stdcall fixes
  285. Revision 1.6 2002/09/07 16:01:19 peter
  286. * old logs removed and tabs fixed
  287. }