video.inc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. {
  2. System independent low-level video interface for tp7
  3. $Id$
  4. }
  5. { use a buffer, just like linux,go32v2 }
  6. {$define use_buf}
  7. var
  8. VideoSeg : word;
  9. OldVideoBuf : PVideoBuf;
  10. { internal function, which is by default available under FPC }
  11. procedure fillword(var buf;len,w:word);assembler;
  12. asm
  13. les di,buf
  14. mov cx,len
  15. mov ax,w
  16. rep stosw
  17. end;
  18. procedure InitVideo;
  19. begin
  20. asm
  21. mov ah,0fh
  22. int 10h
  23. mov [ScreenColor],1
  24. test al,1 { even modes are colored }
  25. jne @ColorOn
  26. mov [ScreenColor],0
  27. @ColorOn:
  28. cmp al,7 { 7 mono mode }
  29. mov dx,SegB800
  30. jne @@1
  31. mov [ScreenColor],0
  32. mov dx,SegB000
  33. @@1:
  34. {$ifdef use_buf}
  35. mov videoseg,dx
  36. {$else}
  37. mov [word ptr VideoBuf+0], 0
  38. mov [word ptr VideoBuf+2], dx
  39. {$endif}
  40. xchg al,ah
  41. xor ah,ah
  42. mov [ScreenWidth],ax
  43. mov bx,40h
  44. mov cx,ax { cx:=ax, pipeline ok }
  45. mov es,bx
  46. shl cx,1
  47. mov ax,[word ptr es:04ch] { Size of videobuf }
  48. xor dx,dx
  49. div cx
  50. mov [ScreenHeight],ax
  51. mov ah,03h
  52. xor bh,bh
  53. int 10h
  54. mov [CursorLines], cl
  55. xor ax,ax
  56. mov al,dl
  57. mov [CursorX],ax
  58. mov al,dh
  59. mov [CursorY],ax
  60. end;
  61. {$ifdef use_buf}
  62. VideoBufSize:=ScreenWidth*ScreenHeight*2;
  63. GetMem(VideoBuf,VideoBufSize);
  64. GetMem(OldVideoBuf,VideoBufSize);
  65. {$endif}
  66. ClearScreen;
  67. end;
  68. procedure DoneVideo;
  69. begin
  70. ClearScreen;
  71. SetCursorType(crUnderLine);
  72. SetCursorPos(0,0);
  73. {$ifdef use_buf}
  74. FreeMem(VideoBuf,VideoBufSize);
  75. FreeMem(OldVideoBuf,VideoBufSize);
  76. VideoBufSize:=0;
  77. {$endif}
  78. end;
  79. function GetCapabilities: Word;
  80. begin
  81. GetCapabilities := $3F;
  82. end;
  83. procedure SetCursorPos(NewCursorX, NewCursorY: Word); assembler;
  84. asm
  85. mov ah,02h
  86. xor bh,bh
  87. mov dh,[byte ptr NewCursorY]
  88. mov dl,[byte ptr NewCursorX]
  89. int 10h
  90. mov [byte ptr CursorY],dh
  91. mov [byte ptr CursorX],dl
  92. end;
  93. function GetCursorType: Word; assembler;
  94. asm
  95. mov ah,03h
  96. xor bh,bh
  97. int 10h
  98. mov ax,crHidden
  99. cmp cx,2000h
  100. je @@1
  101. mov ax,crBlock
  102. cmp ch,00h
  103. je @@1
  104. mov ax,crHalfBlock
  105. mov bl,[CursorLines]
  106. shr bl,1
  107. cmp ch,bl
  108. jbe @@1
  109. mov ax,crUnderline
  110. @@1:
  111. end;
  112. procedure SetCursorType(NewType: Word); assembler;
  113. asm
  114. mov ah,01h
  115. mov bx,[NewType]
  116. mov cx,2000h
  117. cmp bx,crHidden
  118. je @@1
  119. mov ch,[CursorLines]
  120. mov cl,ch
  121. shr ch,1
  122. cmp bx,crHalfBlock
  123. je @@1
  124. mov ch,0
  125. cmp bx,crBlock
  126. je @@1
  127. mov cl,[CursorLines]
  128. mov ch,cl
  129. dec ch
  130. @@1:
  131. int 10h
  132. end;
  133. procedure ClearScreen;
  134. begin
  135. FillWord(VideoBuf^,VideoBufSize shr 1,$0720);
  136. {$ifdef use_buf}
  137. UpdateScreen(true);
  138. {$endif}
  139. end;
  140. procedure UpdateScreen(Force: Boolean);
  141. {$ifdef use_buf}
  142. var
  143. SwapPtr : PVideoBuf;
  144. {$endif}
  145. begin
  146. if LockUpdateScreen<>0 then
  147. exit;
  148. {$ifdef use_buf}
  149. if not force then
  150. begin
  151. asm
  152. mov cx,word ptr VideoBufSize
  153. shr cx,1
  154. les di,OldVideoBuf
  155. push ds
  156. lds si,VideoBuf
  157. repe cmpsw
  158. pop ds
  159. or cx,cx
  160. jz @@10
  161. mov force,1
  162. @@10:
  163. end;
  164. end;
  165. if force then
  166. begin
  167. move(videobuf^,ptr(videoseg,0)^,VideoBufSize);
  168. move(videobuf^,oldvideobuf^,VideoBufSize);
  169. end;
  170. {$endif}
  171. end;
  172. function DefaultVideoModeSelector(const VideoMode: TVideoMode; Params: Longint): Boolean; assembler;
  173. asm
  174. mov ax,[word ptr Params+0]
  175. mov bx,[word ptr Params+2]
  176. push bp
  177. int 10h
  178. pop bp
  179. mov al,1
  180. end;
  181. procedure RegisterVideoModes;
  182. begin
  183. RegisterVideoMode(40, 25, False, DefaultVideoModeSelector, $00000000);
  184. RegisterVideoMode(40, 25, True, DefaultVideoModeSelector, $00000001);
  185. RegisterVideoMode(80, 25, False, DefaultVideoModeSelector, $00000002);
  186. RegisterVideoMode(80, 25, True, DefaultVideoModeSelector, $00000003);
  187. end;
  188. {
  189. $Log$
  190. Revision 1.2 2000-07-13 11:32:27 michael
  191. + removed logs
  192. }