home *** CD-ROM | disk | FTP | other *** search
/ WarCraft 2000 - Nuclear Epidemic / W2000.nrg / SOURCE.War2000 / Ddini.cpp < prev    next >
C/C++ Source or Header  |  1998-08-31  |  16KB  |  622 lines

  1. /***********************************************************************
  2.  *Direct Draw initialisation module                    
  3.  *
  4.  * This module creates the Direct Draw object with the primary surface
  5.  * and a backbuffer and sets 800x600x8 display mode.
  6.  *
  7.  ***********************************************************************/
  8. #define __ddini_cpp_
  9. #include "ddini.h"
  10. #include "ResFile.h"
  11. #include "FastDraw.h"
  12. #include "mode.h"
  13. #include "MapDiscr.h"
  14. #include "fog.h"
  15. #include "GSound.h"
  16. void SERROR();
  17. void SERROR1();
  18. void SERROR2();
  19. void PropCopy();
  20. void InitRLCWindows();
  21. //#define COPYSCR
  22. const int InitLx=1024;
  23. const int InitLy=768;
  24. int RealLx;
  25. int RealLy;
  26. int SCRSizeX;
  27. int SCRSizeY;
  28. int RSCRSizeX;
  29. int RSCRSizeY;
  30. int COPYSizeX;
  31. int Pitch;
  32. LPDIRECTDRAW            lpDD;           // DirectDraw object
  33. LPDIRECTDRAWSURFACE     lpDDSPrimary;   // DirectDraw primary surface
  34. LPDIRECTDRAWSURFACE     lpDDSBack;      // DirectDraw back surface
  35. BOOL                    bActive;        // is application active?
  36. BOOL                    CurrentSurface; //=FALSE if backbuffer
  37.                                         // is active (Primary surface is visible)
  38.                                         //=TRUE if  primary surface is active
  39.                                         // (but backbuffer is visible)
  40. BOOL                    DDError;        //=FALSE if Direct Draw works normally 
  41. DDSURFACEDESC           ddsd;
  42. PALETTEENTRY            GPal[256];
  43. LPDIRECTDRAWPALETTE     lpDDPal;
  44. BOOL                    DDDebug;
  45. extern bool PalDone;
  46. extern word PlayerMenuMode;
  47. typedef struct zzz{            
  48.     BITMAPINFO bmp;
  49.     PALETTEENTRY XPal[255];
  50. };
  51. zzz xxt;
  52. //typedef byte barr[ScreenSizeX*ScreenSizeY];
  53. void* offScreenPtr;
  54. /*
  55.  * Flipping Pages
  56.  */
  57. void FlipPages(void)
  58. {
  59.     if (DDDebug){
  60.         if(PlayerMenuMode!=1){
  61.         //    ProcessFog();
  62.         //    ShowFoggedBattle();
  63.         };
  64.         HDC WH=GetWindowDC(hwnd);
  65.         //memcpy(xxt.XPal,&GPal[1],sizeof xxt.XPal);
  66.         for(int i=0;i<256;i++){
  67.             xxt.bmp.bmiColors[i].rgbRed=GPal[i].peRed;
  68.             xxt.bmp.bmiColors[i].rgbBlue=GPal[i].peBlue;
  69.             xxt.bmp.bmiColors[i].rgbGreen=GPal[i].peGreen;
  70.         };
  71.         xxt.bmp.bmiHeader.biSize=sizeof BITMAPINFOHEADER;
  72.         xxt.bmp.bmiHeader.biWidth=SCRSizeX;
  73.         xxt.bmp.bmiHeader.biHeight=-SCRSizeY;
  74.         xxt.bmp.bmiHeader.biPlanes=1;
  75.         xxt.bmp.bmiHeader.biBitCount=8;
  76.         xxt.bmp.bmiHeader.biCompression=BI_RGB;
  77.         xxt.bmp.bmiHeader.biSizeImage=0;
  78.         int z=StretchDIBits(WH,0,0,COPYSizeX,RSCRSizeY,
  79.             0,MaxSizeY-RSCRSizeY,COPYSizeX,RSCRSizeY,RealScreenPtr,&xxt.bmp,
  80.             DIB_RGB_COLORS,SRCCOPY);
  81.         //StretchDIBits(WH,smapx,smapy,smaplx*32,smaply*32,
  82.         //    smapx,smapy,smaplx*32,smaply*32,RealScreenPtr,&xxt.bmp,
  83.         //    DIB_RGB_COLORS,SRCCOPY);
  84.         return;
  85.     };    
  86. #ifdef COPYSCR
  87.     /*__asm{
  88.         push    esi
  89.         push    edi
  90.         mov        esi,ScreenPtr
  91.         mov        edi,RealScreenPtr
  92.         mov        ecx,120000
  93.         cld
  94.         rep        movsd
  95.         pop        edi
  96.         pop        esi
  97.     }*/
  98.     if(PlayerMenuMode==1){
  99.         int ofs=0;
  100.         int    lx=COPYSizeX>>2;
  101.         int    ly=SCRSizeY;
  102.         int    addOf=SCRSizeX-(lx<<2);
  103.         int RaddOf=RSCRSizeX-(lx<<2);
  104.         __asm{
  105.             push    esi
  106.             push    edi    
  107.             mov        esi,ScreenPtr
  108.             mov        edi,RealScreenPtr
  109.             add        esi,ofs
  110.             add        edi,ofs
  111.             cld
  112.             mov        eax,ly
  113. xxx:
  114.             mov        ecx,lx
  115.             rep        movsd
  116.             add        esi,addOf
  117.             add        edi,RaddOf
  118.             dec        eax
  119.             jnz        xxx
  120.         };
  121.         return;
  122.     };
  123.     /*__asm{
  124.         push    esi
  125.         push    edi
  126.     };
  127.     ProcessFog();
  128.     ShowFoggedBattle();
  129.     __asm{
  130.         pop        edi
  131.         pop        esi
  132.     };*/
  133.     int ofs=smapx+smapy*SCRSizeX;
  134.     int ofs1=smapx+smapy*RSCRSizeX;
  135.     int    lx=smaplx<<3;
  136.     int    ly=smaply<<5;
  137.     int    addOf=SCRSizeX-(lx<<2);
  138.     int RaddOf=RSCRSizeX-(lx<<2);;
  139.     __asm{
  140.         push    esi
  141.         push    edi
  142.         mov        esi,ScreenPtr
  143.         mov        edi,RealScreenPtr
  144.         add        esi,ofs
  145.         add        edi,ofs1
  146.         cld
  147.         mov        eax,ly
  148. xxxx:
  149.         mov        ecx,lx
  150.         rep        movsd
  151.         add        esi,addOf
  152.         add        edi,RaddOf
  153.         dec        eax
  154.         jnz        xxxx
  155.     };
  156.     ofs=minix+miniy*SCRSizeX;
  157.     ofs1=minix+miniy*RSCRSizeX;
  158.     lx=msx>>3;
  159.     ly=msy>>1;
  160.     addOf=SCRSizeX-(lx<<2);
  161.     RaddOf=RSCRSizeX-(lx<<2);
  162.     __asm{
  163.         push    esi
  164.         push    edi
  165.         mov        esi,ScreenPtr
  166.         mov        edi,RealScreenPtr
  167.         add        esi,ofs
  168.         add        edi,ofs1
  169.         cld
  170.         mov        eax,ly
  171. yyy:
  172.         mov        ecx,lx
  173.         rep        movsd
  174.         add        esi,addOf
  175.         add        edi,RaddOf
  176.         dec        eax
  177.         jnz        yyy
  178.     };
  179.     //PropCopy();
  180.     return;
  181. #else
  182.  
  183.     if(DDDebug) return;
  184.     CurrentSurface=!CurrentSurface;
  185.     while( 1 )
  186.     {
  187.         HRESULT ddrval;
  188.         ddrval = lpDDSPrimary->Flip( NULL, 0 );
  189.         if( ddrval == DD_OK )
  190.         {
  191.             break;
  192.         }
  193.         if( ddrval == DDERR_SURFACELOST )
  194.         {
  195.             ddrval = lpDDSPrimary->Restore();
  196.             if( ddrval != DD_OK )
  197.             {
  198.                 break;
  199.             }
  200.         }
  201.         if( ddrval != DDERR_WASSTILLDRAWING )
  202.         {
  203.                 break;
  204.         }
  205.     }
  206. #endif
  207. }
  208. /*
  209.  * Getting Screen Pointer
  210.  *
  211.  * You will ge the pointer to the invisible area of the screen
  212.  * i.e, if primary surface is visible, then you will obtain the
  213.  * pointer to the backbuffer.
  214.  * You must call UnlockSurface() to allow Windows draw on the screen
  215.  */
  216. void LockSurface(void)
  217. {
  218.     if (DDDebug)
  219.     {
  220.         ScreenPtr=(void*)(int(offScreenPtr)+MaxSizeX*32);
  221.         ddsd.lpSurface=ScreenPtr;
  222.         RealScreenPtr=ScreenPtr;
  223.         return;
  224.     }
  225.     if (DDError)  return;
  226. #ifdef COPYSCR
  227.     if (lpDDSPrimary->Lock(NULL,&ddsd,
  228.                                 DDLOCK_SURFACEMEMORYPTR|
  229.                                 DDLOCK_WAIT,NULL)!=DD_OK) DDError=true ;
  230.     RSCRSizeX=ddsd.lPitch;
  231. #else
  232.     if (lpDDSBack->Lock(NULL,&ddsd,
  233.                                 DDLOCK_SURFACEMEMORYPTR|
  234.                                 DDLOCK_WAIT,NULL)!=DD_OK) DDError=true ;
  235.     RSCRSizeX=ddsd.lPitch;
  236. #endif
  237. #ifdef COPYSCR
  238.     ScreenPtr=(void*)(int(offScreenPtr)+MaxSizeX*32);
  239.     //ddsd.lpSurface=ScreenPtr;
  240.     RealScreenPtr=ScreenPtr;
  241.     RealScreenPtr=ddsd.lpSurface;
  242. #else
  243.     ScreenPtr=ddsd.lpSurface;
  244. #endif
  245. }
  246. /*
  247.  *  Unlocking the surface 
  248.  *
  249.  *  You must unlock the Video memory for Windows to work properly
  250.  */
  251. void UnlockSurface(void)
  252. {
  253.     if(DDDebug) return;
  254.     if (DDError)  return;
  255.     //Back Buffer is active
  256. #ifdef COPYSCR
  257.     if (lpDDSPrimary->Unlock(NULL)!=DD_OK) DDError=true ;
  258. #else
  259.     if (lpDDSBack->Unlock(NULL)!=DD_OK) DDError=true ;
  260. #endif
  261. }
  262. /*
  263.  * Getting then DC of the active (invisible) area of the screen
  264.  */
  265. HDC GetSDC(void)
  266. {
  267.     if(DDDebug) return 0;
  268.     HDC hdc;
  269.     if (DDError) return 0;
  270.     if (CurrentSurface)
  271.     {
  272.         //Back Buffer is active
  273.         if (lpDDSPrimary->GetDC(&hdc)!=DD_OK) DDError=true ;
  274.     }else
  275.     {
  276.         //Primary Surface is active
  277.         if (lpDDSBack->GetDC(&hdc)!=DD_OK) DDError=true;
  278.     }
  279.     return hdc;
  280. }
  281. /*
  282.  * Timer Callback 
  283.  */
  284. BOOL CreateDDObjects(HWND hwnd)
  285. {
  286.     HRESULT ddrval;
  287.     DDSCAPS ddscaps;
  288.     char    buf[256];
  289.     DDError=false;
  290.     CurrentSurface=true;
  291.     if (DDDebug)
  292.     {
  293.         
  294.         DDError=false;
  295.         SCRSizeX=MaxSizeX;
  296.         SCRSizeY=MaxSizeY;
  297.         COPYSizeX=RealLx;
  298.         RSCRSizeX=RealLx;
  299.         RSCRSizeY=RealLy;
  300.         ScrHeight=SCRSizeY;
  301.         ScrWidth=SCRSizeX;
  302.         InitRLCWindows();
  303.         WindX=0;
  304.         WindY=0;
  305.         WindLx=SCRSizeX;
  306.         WindLy=SCRSizeY;
  307.         WindX1=WindLx-1;
  308.         WindY1=WindLy-1;
  309.         BytesPerPixel=1;
  310.         offScreenPtr=(malloc(SCRSizeX*(SCRSizeY+32*4)));
  311.         return true;
  312.     }
  313. #ifdef COPYSCR
  314.     offScreenPtr=offScreenPtr=(malloc(MaxSizeX*(MaxSizeY+32*4)));
  315. #endif
  316.     ddrval = DirectDrawCreate( NULL, &lpDD, NULL );
  317.     if( ddrval == DD_OK )
  318.     {
  319.         // Get exclusive mode
  320.         ddrval = lpDD->SetCooperativeLevel( hwnd,
  321.                                 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN );
  322.         if(ddrval == DD_OK )
  323.         {
  324.             ddrval = lpDD->SetDisplayMode(RealLx,RealLy,8); //COPYSizeX,RSCRSizeY, 8 );
  325.             if( ddrval == DD_OK )
  326.             {
  327.                 // Create the primary surface with 1 back buffer
  328.                 ddsd.dwSize = sizeof( ddsd );
  329.                 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
  330.                 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
  331.                                       DDSCAPS_FLIP | 
  332.                                       DDSCAPS_COMPLEX;
  333.                 ddsd.dwBackBufferCount = 1;
  334.                 ddrval = lpDD->CreateSurface( &ddsd, &lpDDSPrimary, NULL );
  335.                 if( ddrval == DD_OK )
  336.                 {
  337.                     // Get a pointer to the back buffer
  338.                     ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
  339.                     ddrval = lpDDSPrimary->GetAttachedSurface(&ddscaps, 
  340.                                                           &lpDDSBack);
  341.                     if (ddrval==DD_OK)
  342.                     {
  343.                         DDError=false;
  344.                         SCRSizeX=MaxSizeX;
  345.                         SCRSizeY=MaxSizeY;
  346.                         RSCRSizeX=RealLx;//ddsd.lPitch;
  347.                         Pitch=ddsd.lPitch;
  348.                         COPYSizeX=RealLx;
  349.                         RSCRSizeY=RealLy;
  350.                         ScrHeight=SCRSizeY;
  351.                         ScrWidth=SCRSizeX;
  352.                         WindX=0;
  353.                         WindY=0;
  354.                         WindLx=SCRSizeX;
  355.                         WindLy=SCRSizeY;
  356.                         WindX1=WindLx-1;
  357.                         WindY1=WindLy-1;
  358.                         BytesPerPixel=1;
  359.                         return true;
  360.                     }
  361.                         // Create a timer to flip the pages
  362.                       /*  if( SetTimer( hwnd, TIMER_ID, 50, NULL ) )
  363.                         {
  364.                              return TRUE;
  365.                         }*/
  366.                 }
  367.             }
  368.         }
  369.     }
  370.     wsprintf(buf, "Direct Draw Init Failed (%08lx)\n", ddrval );
  371.     MessageBox( hwnd, buf, "ERROR", MB_OK );
  372.     return false;
  373. }
  374. BOOL CreateRGBDDObjects(HWND hwnd)
  375. {
  376.     HRESULT ddrval;
  377.     DDSCAPS ddscaps;
  378.     char    buf[256];
  379.     DDError=false;
  380.     CurrentSurface=true;
  381.     if (DDDebug)
  382.     {
  383.         
  384.         DDError=false;
  385.         SCRSizeX=MaxSizeX;
  386.         SCRSizeY=MaxSizeY;
  387.         COPYSizeX=RealLx;
  388.         RSCRSizeX=RealLx;
  389.         RSCRSizeY=RealLy;
  390.         ScrHeight=SCRSizeY;
  391.         ScrWidth=SCRSizeX;
  392.         InitRLCWindows();
  393.         WindX=0;
  394.         WindY=0;
  395.         WindLx=SCRSizeX;
  396.         WindLy=SCRSizeY;
  397.         WindX1=WindLx-1;
  398.         WindY1=WindLy-1;
  399.         BytesPerPixel=1;
  400.         offScreenPtr=(malloc(SCRSizeX*(SCRSizeY+32*4)));
  401.         return true;
  402.     }
  403. #ifdef COPYSCR
  404.     offScreenPtr=offScreenPtr=(malloc(MaxSizeX*(MaxSizeY+32*4)));
  405. #endif
  406.     ddrval = DirectDrawCreate( NULL, &lpDD, NULL );
  407.     if( ddrval == DD_OK )
  408.     {
  409.         // Get exclusive mode
  410.         ddrval = lpDD->SetCooperativeLevel( hwnd,
  411.                                 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN );
  412.         if(ddrval == DD_OK )
  413.         {
  414.             ddrval = lpDD->SetDisplayMode(800,600,32); //COPYSizeX,RSCRSizeY, 8 );
  415.             if( ddrval == DD_OK )
  416.             {
  417.                 // Create the primary surface with 1 back buffer
  418.                 ddsd.dwSize = sizeof( ddsd );
  419.                 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
  420.                 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
  421.                                       DDSCAPS_FLIP | 
  422.                                       DDSCAPS_COMPLEX;
  423.                 ddsd.dwBackBufferCount = 1;
  424.                 ddrval = lpDD->CreateSurface( &ddsd, &lpDDSPrimary, NULL );
  425.                 if( ddrval == DD_OK )
  426.                 {
  427.                     // Get a pointer to the back buffer
  428.                     ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
  429.                     ddrval = lpDDSPrimary->GetAttachedSurface(&ddscaps, 
  430.                                                           &lpDDSBack);
  431.                     if (ddrval==DD_OK)
  432.                     {
  433.                         DDError=false;
  434.                         SCRSizeX=MaxSizeX;
  435.                         SCRSizeY=MaxSizeY;
  436.                         RSCRSizeX=RealLx;//ddsd.lPitch;
  437.                         Pitch=ddsd.lPitch;
  438.                         COPYSizeX=RealLx;
  439.                         RSCRSizeY=RealLy;
  440.                         ScrHeight=SCRSizeY;
  441.                         ScrWidth=SCRSizeX;
  442.                         WindX=0;
  443.                         WindY=0;
  444.                         WindLx=SCRSizeX;
  445.                         WindLy=SCRSizeY;
  446.                         WindX1=WindLx-1;
  447.                         WindY1=WindLy-1;
  448.                         BytesPerPixel=1;
  449.                         return true;
  450.                     }
  451.                         // Create a timer to flip the pages
  452.                       /*  if( SetTimer( hwnd, TIMER_ID, 50, NULL ) )
  453.                         {
  454.                              return TRUE;
  455.                         }*/
  456.                 }
  457.             }
  458.         }
  459.     }
  460.     wsprintf(buf, "Direct Draw Init Failed (%08lx)\n", ddrval );
  461.     MessageBox( hwnd, buf, "ERROR", MB_OK );
  462.     return false;
  463. }
  464. BOOL CreateRGB640DDObjects(HWND hwnd)
  465. {
  466.     HRESULT ddrval;
  467.     DDSCAPS ddscaps;
  468.     char    buf[256];
  469.     DDError=false;
  470.     CurrentSurface=true;
  471.     if (DDDebug)
  472.     {
  473.         
  474.         DDError=false;
  475.         SCRSizeX=MaxSizeX;
  476.         SCRSizeY=MaxSizeY;
  477.         COPYSizeX=RealLx;
  478.         RSCRSizeX=RealLx;
  479.         RSCRSizeY=RealLy;
  480.         ScrHeight=SCRSizeY;
  481.         ScrWidth=SCRSizeX;
  482.         InitRLCWindows();
  483.         WindX=0;
  484.         WindY=0;
  485.         WindLx=SCRSizeX;
  486.         WindLy=SCRSizeY;
  487.         WindX1=WindLx-1;
  488.         WindY1=WindLy-1;
  489.         BytesPerPixel=1;
  490.         offScreenPtr=(malloc(SCRSizeX*(SCRSizeY+32*4)));
  491.         return true;
  492.     }
  493. #ifdef COPYSCR
  494.     offScreenPtr=offScreenPtr=(malloc(MaxSizeX*(MaxSizeY+32*4)));
  495. #endif
  496.     ddrval = DirectDrawCreate( NULL, &lpDD, NULL );
  497.     if( ddrval == DD_OK )
  498.     {
  499.         // Get exclusive mode
  500.         ddrval = lpDD->SetCooperativeLevel( hwnd,
  501.                                 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN );
  502.         if(ddrval == DD_OK )
  503.         {
  504.             ddrval = lpDD->SetDisplayMode(640,480,24); //COPYSizeX,RSCRSizeY, 8 );
  505.             if( ddrval == DD_OK )
  506.             {
  507.                 // Create the primary surface with 1 back buffer
  508.                 ddsd.dwSize = sizeof( ddsd );
  509.                 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
  510.                 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
  511.                                       DDSCAPS_FLIP | 
  512.                                       DDSCAPS_COMPLEX;
  513.                 ddsd.dwBackBufferCount = 1;
  514.                 ddrval = lpDD->CreateSurface( &ddsd, &lpDDSPrimary, NULL );
  515.                 if( ddrval == DD_OK )
  516.                 {
  517.                     // Get a pointer to the back buffer
  518.                     ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
  519.                     ddrval = lpDDSPrimary->GetAttachedSurface(&ddscaps, 
  520.                                                           &lpDDSBack);
  521.                     if (ddrval==DD_OK)
  522.                     {
  523.                         DDError=false;
  524.                         SCRSizeX=MaxSizeX;
  525.                         SCRSizeY=MaxSizeY;
  526.                         RSCRSizeX=RealLx;//ddsd.lPitch;
  527.                         Pitch=ddsd.lPitch;
  528.                         COPYSizeX=RealLx;
  529.                         RSCRSizeY=RealLy;
  530.                         ScrHeight=SCRSizeY;
  531.                         ScrWidth=SCRSizeX;
  532.                         WindX=0;
  533.                         WindY=0;
  534.                         WindLx=SCRSizeX;
  535.                         WindLy=SCRSizeY;
  536.                         WindX1=WindLx-1;
  537.                         WindY1=WindLy-1;
  538.                         BytesPerPixel=1;
  539.                         return true;
  540.                     }
  541.                         // Create a timer to flip the pages
  542.                       /*  if( SetTimer( hwnd, TIMER_ID, 50, NULL ) )
  543.                         {
  544.                              return TRUE;
  545.                         }*/
  546.                 }
  547.             }
  548.         }
  549.     }
  550.     wsprintf(buf, "Direct Draw Init Failed (%08lx)\n", ddrval );
  551.     MessageBox( hwnd, buf, "ERROR", MB_OK );
  552.     return false;
  553. }
  554. /*   Direct Draw palette loading*/
  555. void LoadPalette(LPCSTR lpFileName)
  556. {
  557.     //if (DDDebug) return;
  558.     if (DDError) return;
  559.     ResFile pf=RReset(lpFileName);
  560.     memset(&GPal,0,1024);
  561.     if (pf!=INVALID_HANDLE_VALUE)
  562.     {
  563.         for(int i=0;i<256;i++){
  564.             RBlockRead(pf,&GPal[i],3);
  565.             //RBlockRead(pf,&xx.bmp.bmiColors[i],3);
  566.         };
  567.         RClose(pf);
  568.         if(!DDDebug){
  569.             if(!PalDone){
  570.                 lpDD->CreatePalette(DDPCAPS_8BIT,&GPal[0],&lpDDPal,NULL);
  571.                 PalDone=true;
  572.                 lpDDSPrimary->SetPalette(lpDDPal);
  573.                 //lpDDSBack->SetPalette(lpDDPal);
  574.             }else{
  575.                 lpDDPal->SetEntries(0,0,256,GPal);
  576.             };
  577.             //lpDDSPrimary->SetPalette(lpDDPal);
  578.             //lpDDSBack->SetPalette(lpDDPal);
  579.         };
  580.     }
  581.  
  582. }
  583.     
  584. /*     Closing all Direct Draw objects
  585.  *
  586.  * This procedure must be called before the program terminates,
  587.  * otherwise Windows can occur some problems.
  588.  */
  589.  
  590. void FreeDDObjects( void )
  591. {
  592.     if (DDDebug)
  593.     {
  594.         free(offScreenPtr);
  595.         return;
  596.     }
  597.     if( lpDD != NULL )
  598.     {
  599.         /*if( lpDDSBack != NULL )
  600.         {
  601.             lpDDSBack->Release();
  602.             lpDDSBack = NULL;
  603.         };*/
  604.  
  605.         if( lpDDSPrimary != NULL )
  606.         {
  607.             lpDDSPrimary->Release();
  608.             lpDDSPrimary = NULL;
  609.         };
  610.                 lpDD->Release();
  611.         lpDD = NULL;
  612.     }
  613. }
  614. void SetDebugMode()
  615. {
  616.     DDDebug=true;
  617. }
  618. void NoDebugMode()
  619. {
  620.     DDDebug=false;
  621. }
  622.