home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / VIPTR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  2.0 KB  |  66 lines

  1. /**
  2. *
  3. * Name        viptr -- Convert screen location into memory address
  4. *
  5. * Synopsis    pcell = viptr(row,col);
  6. *
  7. *        char far *pcell Computed address.
  8. *        int  row    Row (0 = top of screen)
  9. *        int  col    Column (0 = left edge)
  10. *
  11. * Description    This function computes the physical address in video
  12. *        memory of the specified location on the current display
  13. *        page.  (The current display page is defined by the
  14. *        global variable b_curpage.)
  15. *
  16. *        An error will occur and NIL will be returned as the
  17. *        value of the function if the screen is not in a standard
  18. *        text mode (0, 1, 2, 3, or 7), or if row or col is beyond
  19. *        the edge of the screen.
  20. *
  21. * Returns    pcell        The computed address, or NIL if an error
  22. *                occurred.
  23. *
  24. * Version    6.00 (C)Copyright Blaise Computing Inc.  1986,1987,1989
  25. *
  26. **/
  27.  
  28. #include <dos.h>
  29.  
  30. #include <bscreens.h>
  31. #include <bvideo.h>
  32.  
  33. int b_vifast = 0;              /* Nonzero if interference is   */
  34.                       /*  to be ignored -- use fastest*/
  35.                       /*  possible method.          */
  36.  
  37. char far *viptr(row,col)
  38. int  row,col;
  39. {
  40.     int mode,act_page,columns;
  41.  
  42. #define CRT_LEN_SEG    0x0000          /* Address of BIOS variable     */
  43. #define CRT_LEN_OFFSET    0x044c          /* CRT_LEN which contains       */
  44.                       /* length of video page          */
  45.  
  46.     scmode(&mode,&columns,&act_page);
  47.     if ((mode > 3 && mode != 7)       /* Quit if graphics mode or     */
  48.     || col <  0              /* if col or row out of range   */
  49.     || col >= columns
  50.     || row <  0
  51.     || row >= scrows())
  52.     return (char far *) NIL;
  53.  
  54.     /* Construct address:  segment is beginning of screen buffer,     */
  55.     /* offset is based on page length, page number, row, and column.  */
  56.  
  57.     /* Note:  pg_len may be incorrect for Monochrome Adapter but that */
  58.     /* should have no effect since b_curpage should be 0.          */
  59.  
  60. #define pg_len    (*uttofar(CRT_LEN_SEG,CRT_LEN_OFFSET,unsigned))
  61.  
  62.     return uttofar( ((mode == 7) ? 0xb000 : 0xb800),
  63.             ((row * columns) + col) * 2 + b_curpage * pg_len,
  64.             char);
  65. }
  66.