home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / CLIB2.ZIP / CRTINIT.CAS < prev    next >
Encoding:
Text File  |  1990-06-07  |  8.3 KB  |  290 lines

  1. /*---------------------------------------------------------------------------
  2.  * filename - crtinit.cas
  3.  *
  4.  * function(s)
  5.  *        system       - displays system information
  6.  *        egainstalled - checks for ega card
  7.  *        _VideoInt    - generates video interrupt
  8.  *        _c0crtinit   - initializes crt
  9.  *        _crtinit     - initializes _video variable
  10.  *        turboCrt     -
  11.  *--------------------------------------------------------------------------*/
  12.  
  13. /*[]------------------------------------------------------------[]*/
  14. /*|                                                              |*/
  15. /*|     Turbo C Run Time Library - Version 3.0                   |*/
  16. /*|                                                              |*/
  17. /*|                                                              |*/
  18. /*|     Copyright (c) 1987,1988,1990 by Borland International    |*/
  19. /*|     All Rights Reserved.                                     |*/
  20. /*|                                                              |*/
  21. /*[]------------------------------------------------------------[]*/
  22.  
  23. #define __IN_CRTINIT  /* _video.h checks whether to make extern _video decl */
  24.  
  25. #pragma inline
  26. #include <asmrules.h>
  27. #include <_video.h>
  28. #include <dos.h>
  29. #include <conio.h>
  30.  
  31. VIDEOREC _video = {0};
  32. int _Cdecl directvideo = 1;
  33.  
  34.  
  35. /*--------------------------------------------------------------------------*
  36.  
  37. Name            system - displays system information
  38.  
  39. Usage           static int near pascal system(char far *ROM,
  40.                                                      char *Copyright);
  41.  
  42. Description     displays system information.
  43.  
  44. Return value    system always returns 1.
  45.  
  46. *---------------------------------------------------------------------------*/
  47.  
  48.  
  49. /*
  50. Note:   "_video" and "__turboCrt" are used to pull in this initialization
  51.         logic whenever any of the video routines are called. Do not remove
  52.         "_video" from here unless adding "__turboCrt" to those modules.
  53.         See also additional notes near "_c0crtinit" regarding "_video".
  54.  
  55.         Also, this module needs to be put in segment "_TEXT", so that it
  56.         may be called by the startup using a NEAR call.
  57.  
  58. */
  59.  
  60. static int near pascal system(char far *ROM, char *Copyright)
  61. {
  62.         while (*Copyright)
  63.                 if (*Copyright++ != *ROM++) return 0;
  64.         return 1;
  65. }
  66.  
  67.  
  68.  
  69. /*--------------------------------------------------------------------------*
  70.  
  71. Name            egainstalled - checks for ega card
  72.  
  73. Usage           static int near pascal egainstalled(void);
  74.  
  75. Description     checks for ega card through video interrupt.
  76.  
  77. Return value    returns TRUE if an EGA card is found, FALSE otherwise.
  78.  
  79. *---------------------------------------------------------------------------*/
  80.  
  81. static int near pascal egainstalled(void)
  82. {
  83.     _AH = 0x12;
  84.     _BL = 0x10;
  85.         _VideoInt();
  86.     return (unsigned char) (_BL - 0x10);
  87. }
  88.  
  89.  
  90. /*--------------------------------------------------------------------------*
  91.  
  92. Name            _VideoInt - generates video interrupt
  93.  
  94. Usage           void _VideoInt(void);
  95.  
  96. Prototype in    _video.h
  97.  
  98. Description     generates video interrupt through dos interrupt 10.
  99.  
  100. *---------------------------------------------------------------------------*/
  101. #pragma saveregs
  102. void near _VideoInt( void )
  103.   {
  104.   /********** Turbo does this for us ************
  105.   asm push  si
  106.   asm push  di
  107.   ***********************************************/
  108.   asm push  bp
  109.   asm push  ds
  110.  
  111.   asm push  cx
  112.   asm mov   cx,40h                 /* ds = BIOS video data area */
  113.   asm mov   ds,cx
  114.   asm pop   cx
  115.  
  116.   asm cmp   ah,V_SET_MODE
  117.   asm je    SetMode
  118.   asm cmp   ah,V_GET_MODE
  119.   asm je    GetMode
  120. NormalCall:
  121.   asm int   10h
  122.   asm jmp   Exit
  123.  
  124. SetMode:
  125.   asm cmp   al,C80
  126.   asm jne   NotC80
  127.  
  128.   asm mov   ax,1a00h               /* is this an EGA? */
  129.   asm int   10h
  130.   asm cmp   al,1ah  
  131.   asm je    NotEGA
  132.   asm and   byte ptr ds:[87h],0feh /* update BIOS data area */
  133. NotEGA:
  134.   asm mov   ah,1                   /* set cursor size */
  135.   asm mov   cx,0607h
  136.   asm int   10h
  137.   asm mov   ax,C80
  138.   asm jmp   NormalCall
  139.  
  140. NotC80:
  141.   asm cmp   al,C4350
  142.   asm jne   NormalCall
  143.  
  144.   asm mov   bl,10h                 /* make sure he has an EGA/VGA */
  145.   asm mov   ah,12h
  146.   asm int   10h
  147.   asm cmp   bl,10h
  148.   asm je    Exit
  149.  
  150.   asm mov   ax,1112h               /* load 8x8 character set */
  151.   asm xor   bl,bl
  152.   asm int   10h
  153.  
  154.   asm mov   ax,1200h               /* select alternate print-screen routine */
  155.   asm mov   bl,20h
  156.   asm int   10h
  157.  
  158.   asm mov   ax,1a00h               /* is this a VGA? */
  159.   asm int   10h
  160.   asm cmp   al,1ah  
  161.   asm je    Exit
  162.  
  163.   asm or    byte ptr ds:[87h],1    /* update BIOS data area */
  164.  
  165.   asm mov   ah,1                   /* set cursor size */
  166.   asm mov   cx,0600h
  167.   asm int   10h
  168.   asm jmp   Exit
  169.  
  170. GetMode:
  171.   asm int   10h
  172.   asm cmp   al,C80
  173.   asm jne   Exit
  174.   asm push  ax
  175.  
  176.   egainstalled();
  177.  
  178.   asm or    al,al
  179.   asm pop   ax
  180.   asm jz    Exit
  181.   asm cmp   byte ptr ds:[84h],24
  182.   asm je    Exit
  183.   asm mov   al,C4350
  184.  
  185. Exit:
  186.   asm pop   ds
  187.   asm pop   bp
  188.   /********** Turbo does this for us ************
  189.   asm pop   di
  190.   asm pop   si
  191.   ***********************************************/
  192.   }
  193.  
  194.  
  195.  
  196. /*--------------------------------------------------------------------------*
  197.  
  198. Name            _c0crtinit - crt initialization routine called by startup
  199.  
  200. Usage           void _c0crtinit(void);
  201.  
  202. Description     _c0crtinit  is called  by the  startup code  to initialize
  203.                 the VIDEO structure. This module is linked if and only if
  204.                 there is at least  one of the video functions called  by
  205.                 the user program. This  is done by  having an external
  206.                 reference to __turboCrt or __Video in all video modules.
  207.  
  208.  
  209. *---------------------------------------------------------------------------*/
  210.  
  211.  
  212.         /* IMPORTANT: _video must be defined in this module,
  213.         otherwise HUGE model needs to be more careful */
  214.  
  215. void near _c0crtinit(void)
  216. {
  217. asm      PUBLIC         __turboCrt
  218. asm      __turboCrt     equ     0
  219.         _AH = V_GET_MODE;
  220.         _VideoInt();
  221.         _crtinit(_AX);          /* really only _AL */
  222.         _AH = V_RD_CHAR_ATTR;
  223.         _BH = 0;
  224.         _VideoInt();
  225.         _AH &= 0x7f;    /* strip blink bit */
  226.         _video.normattr = _AH;
  227.         _video.attribute = _AH;
  228. }
  229.  
  230. /***** 
  231. #pragma startup _c0crtinit 16
  232. ******/
  233. asm     _INIT_  SEGMENT WORD PUBLIC 'INITDATA'
  234. asm             db      0                       /* near call    */
  235. asm             db      16                      /* priority 16  */
  236. asm             dw      offset _c0crtinit
  237. asm             dw      ?
  238. asm     _INIT_  ENDS
  239.  
  240. /*--------------------------------------------------------------------------*
  241.  
  242. Name            _crtinit - initializes the _video variable
  243.  
  244. Usage           void _crtinit( uchar newmode )
  245.  
  246. Prototype in    _video.h
  247.  
  248. Description     Initializes the _video variable
  249.  
  250. *---------------------------------------------------------------------------*/
  251.  
  252.  
  253. void near _crtinit( uchar newmode )
  254.   {
  255.   _video.currmode = newmode;
  256.   _AH = V_GET_MODE;
  257.   _VideoInt();
  258.   _video.screenwidth = _AH;
  259.  
  260.   if (_AL != _video.currmode) 
  261.     {
  262.     _AL = _video.currmode;
  263.     _AH = V_SET_MODE;
  264.     _VideoInt();
  265.     _AH = V_GET_MODE;
  266.     _VideoInt();
  267.     _video.currmode = _AL;
  268.     _video.screenwidth = _AH;
  269.     if( _video.currmode == C80 )
  270.       {
  271.       if( *(char far *)MK_FP( 0x40, 0x84 ) > 24 )  _video.currmode = C4350;
  272.       }
  273.     }
  274.  
  275.   _video.graphicsmode     = (_video.currmode > C80) && 
  276.                             (_video.currmode < C4350) && 
  277.                             (_video.currmode != MONO);
  278.   _video.screenheight     = _video.currmode != C4350 ? 25 : 
  279.                             *(char far *)MK_FP( 0x40, 0x84 ) + 1;
  280.   _video.snow             = (_video.currmode != MONO) &&
  281.                             (!system((char far *)0xF000FFEAL,"COMPAQ")) &&
  282.                             (!egainstalled());
  283.   _video.displayptr.u.seg = _video.currmode == MONO ? 0xB000 : 0xB800;
  284.   _video.displayptr.u.off = 0;
  285.   _video.windowx1         = _video.windowy1 = 0;
  286.   _video.windowx2         = _video.screenwidth - 1;
  287.   _video.windowy2         = _video.screenheight - 1;
  288.   }
  289.  
  290.