home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / DVI_MGR / dvimgr_s.lzh / dvimgr / bitmap.h < prev    next >
Text File  |  1993-08-06  |  2KB  |  65 lines

  1. /***********************************************************************
  2. With non-segmented memory, we  just allocate the bitmap  as a large  2-D
  3. array.  Access to elements is  concealed in the macro BITMAP(y,x)  which
  4. returns the address  of the word  at the (y,x)  position.  On  segmented
  5. memory machines (Intel iAPX) this can  still be done if the bitmap  fits
  6. in one  segment,  and  SEGMEM  will have  been  defined  accordingly  in
  7. dvixxx.c.
  8.  
  9. For segmented memories, not all compilers support pointer addressing  of
  10. objects larger than a segment, so we implement the bitmap as a vector of
  11. pointers to  raster  lines,  each of  which  is  allocated  dynamically.
  12. Element access is again  concealed in BITMAP(y,x), but  the code has  to
  13. ensure that no pointer is ever advanced outside of a raster line.   This
  14. affects  functions   makechar()  and   prtbmap().   Bitmap   access   in
  15. dispchar(), fillrect(), and  prxbmap() is already  restricted to  single
  16. raster lines, so no changes are necessary there.
  17.  
  18. getbmap() handles the  necessary allocation  for either  of these,  so
  19. devinit() in each dvixxx remains ignorant of the details.
  20. ***********************************************************************/
  21.  
  22. #if    SEGMEM
  23.  
  24. UNSIGN32* bitmap[YBIT] =
  25. {
  26.     (UNSIGN32*)NULL    /* only first entry need be initialized */
  27. };
  28. #if    IBM_PC_MICROSOFT
  29. #define BITMAP(y,x) ((UNSIGN32*)normaddr(bitmap[y],(x)<<2))
  30. #define FP_SEG(fp) (*((unsigned *)&(fp) + 1))
  31. #define FP_OFF(fp) (*((unsigned *)&(fp)))
  32.  
  33. char*
  34. normaddr(p,byte_offset) /* return address p+byte_offset */
  35. char *p;
  36. int byte_offset;    /* byte_offset may be positive or negative */
  37. {
  38.     long address;
  39.     char *q;
  40.  
  41.     /* Reconstruct 32-bit address from SEGMENT*16 + OFFSET + byte_offset */
  42.  
  43.     address = (long)FP_SEG(p);    /* long <- unsigned by zero extend */
  44.     address <<= 4;        /* segment real memory address */
  45.     address += (long)FP_OFF(p);    /* *p real memory address */
  46.     address += (long)byte_offset;/* *(p+byte_offset) real memory address */
  47.  
  48.     /* Renormalize address to OFFSET in 0..15 */
  49.  
  50.     FP_OFF(q) = (unsigned)(address & 0x0f);
  51.     FP_SEG(q) = (unsigned)(address >> 4);
  52.  
  53.     return (q);
  54. }
  55. #else /* NOT IBM_PC_MICROSOFT */
  56. #define BITMAP(y,x) (bitmap[y] + (UNSIGN16)(x))
  57. #endif /* IBM_PC_MICROSOFT */
  58.  
  59. #else /* NOT SEGMEM */
  60.  
  61. UNSIGN32* bitmap = (UNSIGN32*)NULL;
  62. #define BITMAP(y,x) (bitmap + ((UNSIGN32)XBIT*(UNSIGN32)(y)) + (UNSIGN32)(x))
  63.  
  64. #endif /* SEGMEM */
  65.