home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 4.ddi / C / GRINIT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-08-05  |  4.3 KB  |  146 lines

  1. /**
  2. *
  3. * Name        grinit -- Initialize graphics (or text) mode
  4. *
  5. * Synopsis    rmode = grinit(res,palette,backgrd);
  6. *
  7. *        int rmode      Returned video mode or -1 if error
  8. *        int res       Graphics mode
  9. *                   0 - Synonym for mode 3
  10. *                   1 - Synonym for mode 4
  11. *                   2 - Synonym for mode 6
  12. *                   3 - 80x25 color text mode
  13. *                   4 - 320x200 4-color (2 palettes)
  14. *                   5 - 320x200 b/w on Color Display
  15. *                   6 - 640x200 b/w on Color Display
  16. *            (EGA only)      13 - 320x200 16-color
  17. *            (EGA only)      14 - 640x200 16-color
  18. *            (EGA only)      15 - 640x350 Monochrome Display
  19. *            (EGA only)      16 - 640x350 4 or 16 of 64 colors
  20. *                    (Enhanced Color Display only)
  21. *        int palette      Foreground palette for mode 4:
  22. *                  0 - green/red/yellow
  23. *                  1 - cyan/magenta/white
  24. *                  2 - Palette 0 with high intensity
  25. *                    background
  26. *                  3 - Palette 1 with high intensity
  27. *                    background
  28. *        int backgrd      For mode 3, the border color;
  29. *                  for mode 4, the background color;
  30. *                  for other modes, ignored.
  31. *
  32. * Description    This function initializes the graphics mode by making a
  33. *        call to SCRESET, and then sets the palette (or possibly
  34. *        the border color) with calls to the BIOS.  The external
  35. *        variable b_home (the home plotting position) is
  36. *        initialized.  The maximum coordinate values (b_maxx and
  37. *        b_maxy) are also set.  In keeping with the IBM
  38. *        definitions, the point coordinates are (x,y), where x=0
  39. *        is the leftmost column and y=0 is the top row.
  40. *
  41. *        An error occurs if a suitable adapter is not installed.
  42. *        In that event, no reset occurs, the value of the
  43. *        function is -1, and the values of the external variables
  44. *        are undefined.
  45. *
  46. * Returns    rmode          The video mode set, or -1 if error.
  47. *        b_home          Initialized to {0,0}.
  48. *        b_maxx          Initialized to number of dot columns
  49. *                  on the screen.
  50. *        b_maxy          Initialized to number of dot rows
  51. *                  on the screen.
  52. *
  53. * Version    3.0 (C)Copyright Blaise Computing Inc.    1983, 1984, 1986
  54. *
  55. **/
  56.  
  57. #include <bgraph.h>
  58. #include <bscreen.h>
  59.  
  60. PT  b_home = {0,0};              /* Home plotting position       */
  61. int b_maxx = 0,               /* Maximum coordinate values    */
  62.     b_maxy = 0;               /* plus one.              */
  63.  
  64. int grinit(res,palette,backgrd)
  65. int res,palette,backgrd;
  66. {
  67.     int ax,bx,cx,dx,flags;          /* General registers for BIOS   */
  68.     int mode;                  /* Returned video mode          */
  69.  
  70.     /* Initialize everything.  Notice that b_maxx and b_maxy are set  */
  71.     /* to one more than the maximum value so that modular arithmetic  */
  72.     /* will wrap around for points plotted "off the screen."          */
  73.  
  74.     b_home.x =
  75.     b_home.y = 0;
  76.  
  77.     switch (res)
  78.     {
  79.     case 0:
  80.     case 3:               /* 80x25 color text mode          */
  81.         if (3 == (mode = screset(3)))
  82.         {
  83.         ax = 0x0b00;          /* Set up border color.          */
  84.         bx = utbyword(0,backgrd % 16);
  85.         bios(16,&ax,&bx,&cx,&dx,&flags);
  86.         }
  87.         break;
  88.  
  89.     case 1:
  90.     case 4:               /* 320x200 4-color (2 palettes) */
  91.         if (4 == (mode = screset(4)))
  92.         {
  93.         b_maxx     = 320;
  94.         b_maxy     = 200;
  95.         backgrd &= 0x000f;    /* Set the background color     */
  96.         if (palette > 1)      /* Set the high intensity bit   */
  97.            backgrd |= 0x0010; /* for palettes 2 and 3.          */
  98.         palette &= 0x0001;    /* Set the palette .....          */
  99.         ax = 0x0b00;
  100.         bx = utbyword(1,palette);
  101.         bios(16,&ax,&bx,&cx,&dx,&flags);
  102.                       /* Now the background and pos-  */
  103.                       /* sibly the high intensity bit */
  104.         ax = 0x0b00;
  105.         bx = utbyword(0,backgrd);
  106.         bios(16,&ax,&bx,&cx,&dx,&flags);
  107.         }
  108.         break;
  109.  
  110.     case 2:
  111.         res = 6;
  112.     case 6:               /* 640x200 b/w              */
  113.     case 14:              /* 640x200 color              */
  114.         if (res == (mode = screset(res)))
  115.         {
  116.         b_maxx = 640;
  117.         b_maxy = 200;
  118.         }
  119.         break;
  120.  
  121.     case 5:               /* 320x200 b/w on Color Display */
  122.     case 13:              /* 320x200 16-color          */
  123.         if (res == (mode = screset(res)))
  124.         {
  125.         b_maxx = 320;
  126.         b_maxy = 200;
  127.         }
  128.         break;
  129.  
  130.     case 15:              /* 640x350 Monochrome Display   */
  131.     case 16:              /* 640x350 4 or 16 of 64 colors */
  132.         if (res == (mode = screset(res)))
  133.         {
  134.         b_maxx = 640;
  135.         b_maxy = 350;
  136.         }
  137.         break;
  138.  
  139.     default:              /* Unknown value of res          */
  140.         mode = -1;
  141.         break;
  142.     }
  143.  
  144.     return(mode);
  145. }
  146.