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

  1. /*------------------------------------------------------------*/
  2. /* filename -       tscreen.cpp                               */
  3. /*                                                            */
  4. /* function(s)                                                */
  5. /*                  TScreen member functions                  */
  6. /*------------------------------------------------------------*/
  7.  
  8. /*------------------------------------------------------------*/
  9. /*                                                            */
  10. /*    Turbo Vision -  Version 1.0                             */
  11. /*                                                            */
  12. /*                                                            */
  13. /*    Copyright (c) 1991 by Borland International             */
  14. /*    All Rights Reserved.                                    */
  15. /*                                                            */
  16. /*------------------------------------------------------------*/
  17.  
  18. #define Uses_TScreen
  19. #define Uses_TEvent
  20. #include <tv.h>
  21.  
  22. #if !defined( __DOS_H )
  23. #include <dos.h>
  24. #endif  // __DOS_H
  25.  
  26. #ifdef PROTECT
  27. ushort far * near TDisplay::equipment = (ushort far *)MK_FP( biosSeg, 0x10 );
  28. uchar far * near TDisplay::crtInfo = (uchar far *)MK_FP( biosSeg, 0x87 );
  29. uchar far * near TDisplay::crtRows = (uchar far *)MK_FP( biosSeg, 0x84 );
  30. #else
  31. ushort far * near TDisplay::equipment = (ushort far *)MK_FP( 0x40, 0x10 );
  32. uchar far * near TDisplay::crtInfo = (uchar far *)MK_FP( 0x40, 0x87 );
  33. uchar far * near TDisplay::crtRows = (uchar far *)MK_FP( 0x40, 0x84 );
  34. #endif
  35.  
  36. ushort near TScreen::startupMode = 0xFFFF;
  37. ushort near TScreen::startupCursor = 0;
  38. ushort near TScreen::screenMode = 0;
  39. uchar near TScreen::screenWidth = 0;
  40. uchar near TScreen::screenHeight = 0;
  41. Boolean near TScreen::hiResScreen = False;
  42. Boolean near TScreen::checkSnow = True;
  43. uchar far * near TScreen::screenBuffer = 0;
  44. ushort near TScreen::cursorLines = 0;
  45.  
  46. #ifdef PROTECT
  47.  
  48. extern "C"
  49.     extern char _protected;
  50.  
  51. #pragma warn -asc
  52.  
  53. static ushort protGetRows(void)
  54. {
  55.     _AX = 0x1130;
  56.     _BH = 0;
  57.     _DL = 0;
  58.  
  59.     if (_protected)
  60.     {
  61.     asm {
  62.         PUSH ES
  63.         PUSH DS
  64.         PUSH DI
  65.         PUSH SI
  66.         PUSHF
  67.         PUSH DX
  68.         PUSH CX
  69.         PUSH BX
  70.         PUSH AX
  71.  
  72.         MOV  DX,SP
  73.         PUSH SS
  74.         POP  DS     /* DS:DX points to the MSB */
  75.         MOV  BX, 8      /* only AX - DX can be changed */
  76.         MOV  AX, 0E310h /* call int 10H in real mode */
  77.         INT  21h
  78.  
  79.         POP  AX
  80.         POP  BX
  81.         POP  CX
  82.         POP  CX
  83.         POPF        /* flags and below were not modified by E3 */
  84.         POP  SI
  85.         POP  DI
  86.         POP  DS
  87.         POP  ES
  88.     }
  89.     }
  90.     else
  91.     {
  92.     asm INT 10h
  93.     }
  94.     if (_DL == 0)
  95.         _DL = 24;
  96.     return _DL + 1;
  97. }
  98.  
  99. #pragma warn .asc
  100.  
  101. #endif
  102.  
  103. ushort TDisplay::getCursorType()
  104. {
  105.     _AH = 3;
  106.     _BH = 0;
  107.     videoInt();
  108.     return _CX;
  109. }
  110.  
  111. void TDisplay::setCursorType( ushort ct )
  112. {
  113.     _AH = 1;
  114.     _CX = ct;
  115.     videoInt();
  116. }
  117.  
  118. void TDisplay::clearScreen( uchar w, uchar h )
  119. {
  120.     _BH = 0x07;
  121.     _CX = 0;
  122.     _DL = w;
  123.     _DH = h - 1;
  124.     _AX = 0x0600;
  125.     videoInt();
  126. }
  127.  
  128. #pragma warn -asc
  129.  
  130. void TDisplay::videoInt()
  131. {
  132.     asm {
  133.         PUSH    BP
  134.         PUSH    ES
  135.         INT     10h
  136.         POP     ES
  137.         POP     BP
  138.     }
  139. }
  140.  
  141. #pragma warn .asc
  142.  
  143. ushort TDisplay::getRows()
  144. {
  145. #ifdef PROTECT
  146.     return protGetRows();
  147. #else
  148.     _AX = 0x1130;
  149.     _BH = 0;
  150.     _DL = 0;
  151.     videoInt();
  152.     if( _DL == 0 )
  153.         _DL = 24;
  154.     return _DL + 1;
  155. #endif
  156. }
  157.  
  158. ushort TDisplay::getCols()
  159. {
  160.     _AH = 0x0F;
  161.     videoInt();
  162.     return _AH;
  163. }
  164.  
  165. ushort TDisplay::getCrtMode()
  166. {
  167.     _AH = 0x0F;
  168.     videoInt();
  169.     ushort mode = _AL;
  170.     if( getRows() > 25 )
  171.         mode |= smFont8x8;
  172.     return mode;
  173. }
  174.  
  175. void TDisplay::setCrtMode( ushort mode )
  176. {
  177.     *equipment &= 0xFFCF;
  178.     *equipment |= (mode == smMono) ? 0x30 : 0x20;
  179.     *crtInfo &= 0x00FE;
  180.  
  181.    
  182.     _AH = 0;
  183.     _AL = mode;
  184.     videoInt();
  185.  
  186.  
  187.     if( (mode & smFont8x8) != 0 )
  188.         {
  189.         _AX = 0x1112;
  190.         _BL = 0;
  191.         videoInt();
  192.  
  193.         if( getRows() > 25 )
  194.             {
  195.             *crtInfo |= 1;
  196.  
  197.             _AH = 1;
  198.             _CX = 0x0607;
  199.             videoInt();
  200.  
  201.             _AH = 0x12;
  202.             _BL = 0x20;
  203.             videoInt();
  204.             }
  205.         }
  206. }
  207.  
  208. TScreen::TScreen()
  209. {
  210.     startupMode = getCrtMode();
  211.     startupCursor = getCursorType();
  212.     setCrtData();
  213. }
  214.  
  215. void TScreen::resume()
  216. {
  217.     startupMode = getCrtMode();
  218.     startupCursor = getCursorType();
  219.     if (screenMode != startupMode)
  220.        setCrtMode( screenMode );
  221.     setCrtData();
  222. }
  223.  
  224. TScreen::~TScreen()
  225. {
  226.     suspend();
  227. }
  228.  
  229. void TScreen::suspend()
  230. {
  231.     if( startupMode != screenMode )
  232.         setCrtMode( startupMode );
  233.     clearScreen();
  234.     setCursorType( startupCursor );
  235. }
  236.  
  237. ushort TScreen::fixCrtMode( ushort mode )
  238. {
  239.     _AX = mode;
  240.     if( _AL != smMono && _AL != smCO80 && _AL != smBW80 )
  241.         _AL = smCO80;
  242.     return _AX;
  243. }
  244.  
  245. void TScreen::setCrtData()
  246. {
  247.     screenMode = getCrtMode();
  248.     screenWidth = getCols();
  249.     screenHeight = getRows();
  250.     hiResScreen = Boolean(screenHeight > 25);
  251.  
  252.     if( screenMode == smMono )
  253.         {
  254. #ifdef PROTECT
  255.     screenBuffer = (uchar far *)MK_FP( monoSeg, 0 );
  256. #else
  257.     screenBuffer = (uchar far *)MK_FP( 0xB000, 0 );
  258. #endif
  259.         checkSnow = False;
  260.         }
  261.     else
  262.         {
  263. #ifdef PROTECT
  264.     screenBuffer = (uchar far *)MK_FP( colrSeg, 0 );
  265. #else
  266.     screenBuffer = (uchar far *)MK_FP( 0xB800, 0 );
  267. #endif
  268.         if( hiResScreen )
  269.             checkSnow = False;
  270.         }
  271.  
  272.     cursorLines = getCursorType();
  273.     setCursorType( 0x2000 );
  274.  
  275. }
  276.  
  277. void TScreen::clearScreen()
  278. {
  279.     TDisplay::clearScreen( screenWidth, screenHeight );
  280. }
  281.  
  282. void TScreen::setVideoMode( ushort mode )
  283. {
  284.     setCrtMode( fixCrtMode( mode ) );
  285.     setCrtData();
  286. }
  287.