home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / pascal / rehack / graphics / display.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-26  |  5.8 KB  |  208 lines

  1. //---------------------------------------------------------------------------
  2. //
  3. //      File:           DISPLAY.CPP
  4. //      Path:           ...\REHACK\graphics
  5. //      Version:                1.1
  6. //      Author:         Dave Boynton
  7. //      CIS Id:         71043,317
  8. //      Created On:     6/26/93
  9. //      Modified On:    7/25/93
  10. //      Description:    display class methods for mode 13h, 320x200 256c
  11. //      Tabs:           4
  12. //
  13. //---------------------------------------------------------------------------
  14. // copyright (c) 1993 by the GAMERS Forum, Rehack project team.
  15. // All rights reserved.
  16. #include <dos.h>
  17. #include <mem.h>
  18. #include "bitmap.hpp"
  19. #include "display.hpp"
  20.  
  21. //----------------------------- DisplayManager ---------------------------
  22. //DisplayManager display(0);    //wait for retraces, refuse direct bitmaps
  23. //DisplayManager display(1);    //don't do retraces, allow direct bitmaps
  24. #pragma argsused
  25. DisplayManager::DisplayManager(word flags)
  26. {
  27.    size.x=getWidth(); size.y=getHeight();
  28.    videoSegment=0xA000U; // bad news for extenders! But seriously, if an
  29.                          // extender is used, this line needs to be changed
  30.                          // to map a selector to 0xA0000000UL, size 64k.
  31.    bounds.topLeft.x=0;
  32.    bounds.topLeft.y=0;
  33.    bounds.bottomRight.x=getWidth();
  34.    bounds.bottomRight.y=getHeight();
  35.  
  36.    if ( (flags & 0x01) == 0x01 )
  37.       retrace=false; //modern SVGA cards aren't as touchy, don't need it.
  38.              // but I'm leaving it up to main() to decide.
  39.    else
  40.       retrace=true;
  41. }
  42.  
  43. // put src's viewPort onto the screen, relative to it's ownerBounds, using
  44. // the full size of the viewPort.
  45. void DisplayManager::putBitmap(Bitmap * src)
  46. {
  47.     if ( src->directFlag )
  48.         return;
  49.  
  50.     word sizeX, sizeY;
  51.     sizeX=src->viewPort.bottomRight.x - src->viewPort.topLeft.x;
  52.     sizeY=src->viewPort.bottomRight.y - src->viewPort.topLeft.y;
  53.  
  54.     putBitmap(src, (src->ownerBounds.topLeft.x + src->viewPort.topLeft.x),
  55.                    (src->ownerBounds.topLeft.y + src->viewPort.topLeft.y),
  56.                    sizeX, sizeY);
  57. }
  58.  
  59. // put src's viewPort onto the screen, at offset "at", using the full size
  60. // of the viewPort. I haven't tested this one with anything yet; not sure
  61. // if it's even useful.
  62. void DisplayManager::putBitmap(Bitmap * src, const Point &at)
  63. {
  64.     if ( src->directFlag )
  65.         return;
  66.  
  67.     word sizeX, sizeY;
  68.     sizeX=src->viewPort.bottomRight.x - src->viewPort.topLeft.x;
  69.     sizeY=src->viewPort.bottomRight.y - src->viewPort.topLeft.y;
  70.  
  71.     putBitmap(src, at.x, at.y, sizeX, sizeY);
  72. }
  73.  
  74. // put src's viewPort onto the display, using screen offset xoff,yoff
  75. // and size xsize, ysize.
  76. void DisplayManager::putBitmap(Bitmap * src,int xoff,int yoff, int xsize, int ysize)
  77. {
  78.     if ( src->directFlag )
  79.         return;
  80.  
  81.     if ( (xoff+xsize) > size.x )
  82.         xsize=size.x - xoff;
  83.  
  84.     if ( (yoff+ysize) > size.y )
  85.         ysize=size.y - yoff;
  86.  
  87.     if ( ( ysize < 1 ) || ( xsize < 1 ) )
  88.         return;
  89.  
  90.     word srcWidth=src->localBounds.bottomRight.x - src->localBounds.topLeft.x;
  91.     word destWidth=size.x;
  92.  
  93.     byte * srcPtr=    (src->viewPort.topLeft.y * srcWidth) +
  94.                     src->viewPort.topLeft.x + src->bits;
  95.     byte * destPtr=(byte *) MK_FP(videoSegment,(yoff*destWidth + xoff));
  96.  
  97.     int i;
  98.     for (i=src->viewPort.topLeft.y; i<src->viewPort.bottomRight.y; i++)
  99.     {
  100.         memcpy(destPtr, srcPtr, xsize);
  101.         srcPtr+= srcWidth;
  102.         destPtr+= destWidth;
  103.     }
  104. }
  105.  
  106. void DisplayManager::putBitmap(Bitmap *src, const Rect &destRect)
  107. {
  108.     byte * destPtr;
  109.     byte * srcPtr;
  110.     word srcWidth, destWidth;
  111.     Rect srcRect,    // subset of src->viewPort
  112.         copyRect,    // subset of bounds & destRect
  113.         copySize;    // 0,0 based copy size
  114.  
  115.     if ( src->directFlag )
  116.         return;
  117.  
  118.     copyRect= destRect & bounds; // display bounds
  119.     destWidth=size.x;
  120.  
  121.     copySize=(copyRect - copyRect.topLeft) &
  122.              (src->viewPort - src->viewPort.topLeft);
  123.     srcWidth=src->localBounds.bottomRight.x - src->localBounds.topLeft.x;
  124.  
  125.     srcPtr=(src->viewPort.topLeft.y * srcWidth) + src->viewPort.topLeft.x +
  126.             src->bits;
  127.     destPtr=(byte *) MK_FP(videoSegment,
  128.             (copyRect.topLeft.y*destWidth + copyRect.topLeft.x));
  129.  
  130.     int i;
  131.     for (i=src->viewPort.topLeft.y; i<src->viewPort.bottomRight.y; i++)
  132.     {
  133.         memcpy(destPtr, srcPtr, destWidth);
  134.         srcPtr+= srcWidth;
  135.         destPtr+= destWidth;
  136.     }
  137. }
  138.  
  139. // get a direct Bitmap of the full screen. This could be static, except for
  140. // the use of videoSegment, which must be initialized first.
  141. Bitmap * DisplayManager::getDirectBitmap(void)
  142. {
  143.     Bitmap * fullscreen = new Bitmap(size.x, size.y, true);
  144.  
  145.     fullscreen->bits=(byte *) MK_FP(videoSegment,0);
  146.     return fullscreen;
  147. }
  148.  
  149. // Calls video interrupt to set graphics adaptor to mode
  150. void DisplayManager::setMode(const int mode)
  151. {
  152.     union REGS inregs, outregs;
  153.  
  154.     inregs.h.ah = 0x00;
  155.     inregs.h.al = mode;
  156.     int86(0x10, &inregs, &outregs);
  157. }
  158.  
  159. // setpalette()
  160. // Sets all 256 VGA color registers to RGB values in colregs[]
  161. // (asm unnecessary for this function! will be changed!)
  162. void DisplayManager::setPalette(const byte *palette)
  163. {
  164.     union REGS inregs, outregs;
  165.     struct SREGS segregs;
  166.  
  167.     inregs.h.ah = 0x10;
  168.     inregs.h.al = 0x12;
  169.     inregs.x.bx = 0;
  170.     inregs.x.cx = 0xff;
  171.     segregs.es=FP_SEG(palette);
  172.     inregs.x.dx = FP_OFF(palette);
  173.     int86x(0x10, &inregs, &outregs, &segregs);
  174. }
  175.  
  176. // Loop to delay until next vertical blank
  177. void DisplayManager::waitForVerticalRetrace(void)
  178. {
  179.     while ((inport(0x3da)&8)==0);
  180. }
  181.  
  182. void DisplayManager::blankScreen(void)
  183. {
  184.     union REGS inregs, outregs;
  185.  
  186.     inregs.x.ax = 0x1201;
  187.     inregs.h.bl = 0x36;
  188.     int86(0x10, &inregs, &outregs);
  189. }
  190.  
  191. void DisplayManager::unblankScreen(void)
  192. {
  193.     union REGS inregs, outregs;
  194.  
  195.     inregs.x.ax = 0x1200;
  196.     inregs.h.bl = 0x36;
  197.     int86(0x10, &inregs, &outregs);
  198. }
  199.  
  200. // replaces __assertfail, used by <assert.h>, which doesn't expect to be
  201. // in graphics mode.
  202. void DisplayManager::assertfail( char *__msg, char *__cond,
  203.                                 char *__file, int __line)
  204. {
  205.     DisplayManager::setMode(3);
  206.     ::__assertfail(__msg,__cond,__file,__line);
  207. }
  208.