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