home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 9.ddi / TVSRC.ZIP / DRIVERS.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  8.6 KB  |  236 lines

  1. /*------------------------------------------------------------------------*/
  2. /* filename - drivers.cpp                                                 */
  3. /*                                                                        */
  4. /* function(s)                                                            */
  5. /*        moveBuf  --   moves a buffer of char/attribute pairs            */
  6. /*        moveChar --   sets a buffer with a char/attribute pair          */
  7. /*        moveCStr --   moves a char array into a buffer & adds an        */
  8. /*                      attribute to each char                            */
  9. /*------------------------------------------------------------------------*/
  10.  
  11. /*------------------------------------------------------------------------*/
  12. /*                                                                        */
  13. /*    Turbo Vision -  Version 1.0                                         */
  14. /*                                                                        */
  15. /*                                                                        */
  16. /*    Copyright (c) 1991 by Borland International                         */
  17. /*    All Rights Reserved.                                                */
  18. /*                                                                        */
  19. /*------------------------------------------------------------------------*/
  20.  
  21. #define Uses_TDrawBuffer
  22. #include <tv.h>
  23.  
  24. #if !defined( __DOS_H )
  25. #include <Dos.h>
  26. #endif  // __DOS_H
  27.  
  28. #pragma warn -asc
  29.  
  30. /*------------------------------------------------------------------------*/
  31. /*                                                                        */
  32. /*  TDrawBuffer::moveBuf                                                  */
  33. /*                                                                        */
  34. /*  arguments:                                                            */
  35. /*                                                                        */
  36. /*      indent - character position within the buffer where the data      */
  37. /*               is to go                                                 */
  38. /*                                                                        */
  39. /*      source - far pointer to an array of character/attribute pairs     */
  40. /*                                                                        */
  41. /*      attr   - attribute to be used for all characters (0 to retain     */
  42. /*               the attribute from 'source')                             */
  43. /*                                                                        */
  44. /*      count   - number of character/attribute pairs to move             */
  45. /*                                                                        */
  46. /*------------------------------------------------------------------------*/
  47.  
  48. void TDrawBuffer::moveBuf( ushort indent, const void far *source,
  49.                            ushort attr, ushort count )
  50.  
  51. {
  52. asm {
  53.     MOV     CX,count
  54.     JCXZ    __5
  55.     PUSH    DS
  56.     }
  57.  
  58.     _ES = FP_SEG( &data[indent] );
  59.     _DI = FP_OFF( &data[indent] );
  60.  
  61.     _DS = FP_SEG( source );
  62.     _SI = FP_OFF( source );
  63.  
  64. asm {
  65.     MOV     AH,[BYTE PTR attr]
  66.     CLD
  67.     OR      AH,AH
  68.     JE      __3
  69.     }
  70. __1:
  71. asm {
  72.     LODSB
  73.     STOSW
  74.     LOOP    __1
  75.     JMP     __4
  76.     }
  77. __2:
  78. asm INC     DI
  79. __3:
  80. asm {
  81.     STOSB
  82.     LOOP    __2
  83.     }
  84. __4:
  85. asm POP     DS
  86. __5:
  87.         ;
  88. }
  89.  
  90. /*------------------------------------------------------------------------*/
  91. /*                                                                        */
  92. /*  TDrawBuffer::moveChar                                                 */
  93. /*                                                                        */
  94. /*  arguments:                                                            */
  95. /*                                                                        */
  96. /*      indent  - character position within the buffer where the data     */
  97. /*                is to go                                                */
  98. /*                                                                        */
  99. /*      c       - character to be put into the buffer                     */
  100. /*                                                                        */
  101. /*      attr    - attribute to be put into the buffer                     */
  102. /*                                                                        */
  103. /*      count   - number of character/attribute pairs to put into the     */
  104. /*                buffer                                                  */
  105. /*                                                                        */
  106. /*------------------------------------------------------------------------*/
  107.  
  108. void TDrawBuffer::moveChar( ushort indent, char c, ushort attr, ushort count )
  109. {
  110. asm {
  111.     MOV     CX,count
  112.     JCXZ    __4
  113.     }
  114.  
  115.     _ES = FP_SEG( &data[indent] );
  116.     _DI = FP_OFF( &data[indent] );
  117.  
  118. asm {
  119.     MOV     AL,c
  120.     MOV     AH,[BYTE PTR attr]
  121.     CLD
  122.     OR      AL,AL
  123.     JE      __1
  124.     OR      AH,AH
  125.     JE      __3
  126.     REP     STOSW
  127.     JMP     __4
  128.     }
  129. __1:
  130. asm MOV     AL,AH
  131. __2:
  132. asm INC     DI
  133. __3:
  134. asm STOSB
  135. asm LOOP    __2
  136. __4:
  137.     ;
  138. }
  139.  
  140. /*------------------------------------------------------------------------*/
  141. /*                                                                        */
  142. /*  TDrawBuffer::moveCStr                                                 */
  143. /*                                                                        */
  144. /*  arguments:                                                            */
  145. /*                                                                        */
  146. /*      indent  - character position within the buffer where the data     */
  147. /*                is to go                                                */
  148. /*                                                                        */
  149. /*      str     - pointer to a 0-terminated string of characters to       */
  150. /*                be moved into the buffer                                */
  151. /*                                                                        */
  152. /*      attrs   - pair of text attributes to be put into the buffer       */
  153. /*                with each character in the string.  Initially the       */
  154. /*                low byte is used, and a '~' in the string toggles       */
  155. /*                between the low byte and the high byte.                 */
  156. /*                                                                        */
  157. /*------------------------------------------------------------------------*/
  158.  
  159. void TDrawBuffer::moveCStr( ushort indent, const char far *str, ushort attrs )
  160. {
  161. asm {
  162.     PUSH    DS
  163.     LDS     SI,str
  164.     CLD
  165.     }
  166.  
  167.     _ES = FP_SEG( &data[indent] );
  168.     _DI = FP_OFF( &data[indent] );
  169.  
  170. asm {
  171.     MOV     BX,attrs
  172.     MOV     AH,BL
  173.     }
  174. __1:
  175. asm {
  176.     LODSB
  177.     CMP     AL,'~'
  178.     JE      __2
  179.     CMP     AL,0
  180.     JE      __3
  181.     STOSW
  182.     JMP     __1
  183.     }
  184. __2:
  185. asm XCHG    AH,bH
  186. asm JMP     __1
  187. __3:
  188. asm POP     DS
  189. }
  190.  
  191. /*------------------------------------------------------------------------*/
  192. /*                                                                        */
  193. /*  TDrawBuffer::moveStr                                                  */
  194. /*                                                                        */
  195. /*  arguments:                                                            */
  196. /*                                                                        */
  197. /*      indent  - character position within the buffer where the data     */
  198. /*                is to go                                                */
  199. /*                                                                        */
  200. /*      str     - pointer to a 0-terminated string of characters to       */
  201. /*                be moved into the buffer                                */
  202. /*                                                                        */
  203. /*      attr    - text attribute to be put into the buffer with each      */
  204. /*                character in the string.                                */
  205. /*                                                                        */
  206. /*------------------------------------------------------------------------*/
  207.  
  208. void TDrawBuffer::moveStr( ushort indent, const char far *str, ushort attr )
  209. {
  210. asm {
  211.     PUSH    DS
  212.     LDS     SI,str
  213.     CLD
  214.     }
  215.  
  216.     _ES = FP_SEG( &data[indent] );
  217.     _DI = FP_OFF( &data[indent] );
  218.  
  219. asm {
  220.     MOV     BX,attr
  221.     MOV     AH,BL
  222.     }
  223. __1:
  224. asm {
  225.     LODSB
  226.     CMP     AL,0
  227.     JE      __2
  228.     STOSW
  229.     JMP     __1
  230.     }
  231. __2:
  232. asm POP     DS
  233. }
  234.  
  235. #pragma warn .asc
  236.