video.inc 4.6 KB

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