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

  1. /**
  2. *
  3. * Name        viads -- Convert screen location into memory address
  4. *
  5. * Synopsis    pstruct = viads(row,col,pads);
  6. *
  7. *        ADS *pstruct    Returned value of pads,
  8. *                or NIL if error.
  9. *        int  row    Row (0 = top of screen)
  10. *        int  col    Column (0 = left edge)
  11. *        ADS *pads    Pointer to ADS structure to receive
  12. *                computed address.
  13. *
  14. * Description    This function computes the physical address in video
  15. *        memory of the specified location on the current display
  16. *        page.  (The current display page is defined by the
  17. *        global variable b_curpage.)
  18. *
  19. *        An error will occur and NIL will be returned as the
  20. *        value of the function if the screen is not in a standard
  21. *        text mode (0, 1, 2, 3, or 7), or if row or col is beyond
  22. *        the edge of the screen.
  23. *
  24. * Returns    pstruct     Returned pointer to the ADS structure
  25. *                which contains the computed address,
  26. *                or NIL if an error occurred.
  27. *        *pads        ADS structure containing the computed
  28. *                address.
  29. *
  30. * Version    3.0  (C)Copyright Blaise Computing Inc. 1986
  31. *
  32. **/
  33.  
  34. #include <bscreen.h>
  35. #include <bvideo.h>
  36.  
  37. ADS *viads(row,col,pads)
  38. int  row,col;
  39. ADS *pads;
  40. {
  41.     int mode,columns,act_page;
  42.     static ADS CRT_LEN_ads = {0x44c,0};  /* Address of BIOS variable  */
  43.                       /* CRT_LEN which contains       */
  44.                       /* length of video page          */
  45.  
  46.     int pg_len = 0;
  47.     ADS pg_len_ads;              /* Address of pg_len          */
  48.  
  49.     scmode(&mode,&columns,&act_page);
  50.     if ((mode > 3 && mode != 7)       /* Quit if graphics mode or     */
  51.     || col <  0              /* if col or row out of range   */
  52.     || col >= columns
  53.     || row <  0
  54.     || row >= scrows())
  55.     return NIL;
  56.  
  57.     pads->s = ((mode == 7) ? 0xb000 : 0xb800); /* Start of screen     */
  58.                            /* buffer          */
  59.     pads->r = ((row * columns) + col) * 2;
  60.  
  61.     if (b_curpage)
  62.     {
  63.     utabsptr((char *) &pg_len,&pg_len_ads);
  64.     utslmove(&CRT_LEN_ads,&pg_len_ads,2);  /* Extract page length */
  65.     pads->r += b_curpage * pg_len;
  66.     }                      /* Note:    pg_len may be          */
  67.                       /* incorrect for Monochrome     */
  68.                       /* Adapter but that should have */
  69.                       /* no effect since b_curpage    */
  70.                       /* should be 0.              */
  71.     return pads;
  72. }
  73.