home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / mouse / lib / ega / demo / mmcega.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  3.1 KB  |  120 lines

  1. /*----------------------------------------------------------------------*/
  2. /* REFERENCE -- Test of cegam()             IN mmcega.c    */
  3. /*                                    */
  4. /* This program tests the function cegam(), which is an interface    */
  5. /* between medium model MSC 3.0 (or higher) 'C' programs, and the EGA    */
  6. /* Register Interface.                            */
  7. /*                                    */
  8. /* To create mmcega.exe:                        */
  9. /*                MSC  /AM MMCEGA;            */
  10. /*                LINK MMCEGA,,,..\EGA            */
  11. /*             or:                        */
  12. /*                MAKE MMCEGA.MAK                */
  13. /*----------------------------------------------------------------------*/
  14. #include <stdio.h>
  15. #include <dos.h>
  16.  
  17. #define ega(a,b,c,d,e)    cegam(a,b,c,d,e)
  18. #define FALSE    0
  19. #define NOT    !
  20. #define TRUE    NOT FALSE
  21.  
  22.  
  23. main()
  24. {
  25.     int ah, bx, cx, dx, es;
  26.     char buf[2];
  27.     
  28.     ah = 0xfa;
  29.     bx = 0;
  30.     
  31.     ega(&ah, &bx, &cx, &dx, &es);
  32.     
  33.     if (!bx)
  34.     {
  35.     printf("\nEGA Driver not found");
  36.     return;
  37.     }
  38.     printf("\nEGA Driver found, version ");
  39.     movedata(es, bx, getds(), buf, 2);
  40.  
  41.     printf("%1d.%2d", buf[0], buf[1]);
  42.     
  43.     printf("\nRead/Write Range functions (F2, F3) ");
  44.     if (test_range())    printf("PASSED");
  45.     else        printf("FAILED");
  46.     printf("\n\n\n");
  47. }
  48.  
  49.  
  50. test_range()
  51. {
  52.     int ah, bx, cx, dx, es;
  53.     int *bxp;
  54.     static char org_buf[2] = {0xAA, 0xAA};
  55.     static char wr_buf[2] = {0xBB, 0xBB};
  56.     static char rd_buf[2] = {0xCC, 0xCC};
  57.     int old_map_mask;
  58.     int old_misc_reg;
  59.  
  60.     /* read the cursor location high and low registers */
  61.     
  62.     ah  = 0xF2;        /* read range    */
  63.     cx  = 0x0e00;    /* start at reg 14    */
  64.     cx |= 0x0002;    /* 2 reg to read    */
  65.     dx  = 0x0000;    /* crt controller    */
  66.     es  = getds();    /* current data segment */
  67.     
  68.     ega(&ah, org_buf, &cx, &dx, &es);
  69.     
  70.     wr_buf[0] = 0xee;
  71.     wr_buf[1] = 0xff;
  72.  
  73.     ah = 0xF3;        /* write range        */
  74.     cx = 0x0e02;    /* start at e, write 2    */
  75.     dx = 0;        /* crt controller    */
  76.     es = getds();
  77.     
  78.     ega(&ah, wr_buf, &cx, &dx, &es);
  79.     
  80.     ah = 0xF2;        /* read range    */
  81.     cx = 0x0e02;    /* start at e , read 2    */
  82.     dx = 0;
  83.     es = getds();
  84.     
  85.     ega(&ah, rd_buf, &cx, &dx, &es);
  86.  
  87.     /* restore original values */
  88.         
  89.     ah = 0xF3;        /* write range        */
  90.     cx = 0x0e02;    /* start at e, write 2    */
  91.     dx = 0;        /* crt controller    */
  92.     es = getds();
  93.     ega(&ah, org_buf, &cx, &dx, &es);
  94.     
  95.     if (rd_buf[0] != wr_buf[0])
  96.     return FALSE;
  97.     if (rd_buf[1] != wr_buf[1])
  98.     return FALSE;
  99.     
  100.     return TRUE;
  101. }
  102.  
  103.  
  104. getds()
  105. /*----------------------------------------------------------------------*/
  106. /* METHOD  -- Returns the current data segment.                */
  107. /*----------------------------------------------------------------------*/
  108. /* RETURNS -- Current code segment.                    */
  109. /*----------------------------------------------------------------------*/
  110. /* GLOBAL EFFECTS -- none.                        */
  111. /*----------------------------------------------------------------------*/
  112. /* REVISION  1.00 is:  Original version.                */
  113. /*----------------------------------------------------------------------*/
  114. {
  115.     struct SREGS segregs;
  116.     
  117.     segread(&segregs);
  118.     return segregs.ds;
  119. }
  120.