home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / CD32 / CD32_Support / examples / cdgsxl / Display.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-27  |  15.4 KB  |  656 lines

  1. /*************
  2.  
  3.     Display.c
  4.     W.D.L 930330
  5.  
  6. **************/
  7.  
  8. /*
  9.  * COPYRIGHT: Unless otherwise noted, all files are Copyright (c) 1993-1999
  10.  * Amiga, Inc.  All rights reserved.
  11.  *
  12.  * DISCLAIMER: This software is provided "as is".  No representations or
  13.  * warranties are made with respect to the accuracy, reliability, performance,
  14.  * currentness, or operation of this software, and all use is at your own risk.
  15.  * Neither Amiga nor the authors assume any responsibility or liability
  16.  * whatsoever with respect to your use of this software.
  17.  */
  18.  
  19. // Tab size is 8!
  20.  
  21. #include <exec/types.h>
  22. #include <exec/memory.h>
  23. #include <intuition/intuition.h>
  24. #include <intuition/intuitionbase.h>
  25. #include <graphics/gfx.h>
  26. #include <graphics/gfxbase.h>
  27. #include <graphics/gfxmacros.h>
  28. #include <graphics/videocontrol.h>
  29.  
  30. #include <hardware/custom.h>
  31. #include <hardware/intbits.h>
  32.  
  33. #include <clib/exec_protos.h>
  34. #include <clib/intuition_protos.h>
  35. #include <clib/graphics_protos.h>
  36. #include <clib/macros.h>
  37.  
  38. #include <pragmas/exec_pragmas.h>
  39. #include <pragmas/intuition_pragmas.h>
  40. #include <pragmas/graphics_pragmas.h>
  41.  
  42. #include <string.h>    // for setmem()
  43. #include "stdio.h"
  44.  
  45. #include "cdxl/cdxlob.h"
  46. #include "cdxl/runcdxl.h"
  47.  
  48. #include "cdxl/debugsoff.h"
  49.  
  50.     // Uncomment to get debug output turned on
  51. #define KPRINTF
  52. //#include "cdxl/debugson.h"
  53.  
  54.  
  55. IMPORT struct ExecBase        * SysBase;
  56. IMPORT struct GfxBase        * GfxBase;
  57. IMPORT struct IntuitionBase    * IntuitionBase;
  58. IMPORT struct Custom          far custom;
  59.  
  60. ULONG          smartgfx = 0x12345678;
  61. IMPORT BOOL      DoScreen;
  62.  
  63. struct Screen    * CDXLScreen;
  64. struct Window    * CDXLWindow;
  65.  
  66. VOID CloseDisplay( DISP_DEF * disp_def );
  67. int kprintf(const char *, ...);
  68. int DoILBM( UBYTE * filename, DISP_DEF * disp_def );
  69. VOID    CopRoutine( VOID );    // In CopRoutine.a
  70.  
  71.  
  72. struct Interrupt CopInt;
  73. struct UCopList    * old_ucl,ucl;
  74. BOOL    CopIntAdded;
  75. BYTE    CopSigBit = -1;
  76. ULONG    CopSignal;
  77.  
  78. STATIC USHORT chip InvisiblePointer[]= {0x0000,0x0000,0x0000,0x0000,0x0000,0x0000};
  79.  
  80. /*
  81.  * Data that gets passed into our copper interrupt routine.
  82.  */
  83. typedef    struct IntData {
  84.     struct Task    * Task;
  85.     ULONG      SigMask;
  86.  
  87. } INTDATA;
  88.  
  89. INTDATA CopIntData;
  90.  
  91. /*
  92.  * Set up the data that will get sent into the copper interrupt.
  93.  */
  94. SetUpIntData( INTDATA * intdata )
  95. {
  96.     if ( ( CopSigBit = AllocSignal(-1) ) != -1 ) {
  97.     CopSignal = intdata->SigMask = (1L << CopSigBit);
  98.     intdata->Task = FindTask( NULL );
  99.     return( TRUE );
  100.     }
  101.  
  102.     return( FALSE );
  103.  
  104. } // SetUpIntData()
  105.  
  106.  
  107. /*
  108.  * Add a copper interrupt that will signal us to call ChangeVPBitMap().
  109.  */
  110. VOID
  111. AddCopInt( DISP_DEF * disp_def, struct UCopList * ucl, struct Interrupt * copint, INTDATA * intdata )
  112. {
  113.     setmem( ucl, sizeof ( *ucl ), 0 );
  114.  
  115.     CINIT ( ucl, 50 );
  116.     CMOVE ( ucl, custom.intena, (INTF_SETCLR|INTF_COPER) );
  117.     CWAIT ( ucl, 0, 0 );
  118. //    CWAIT ( ucl, disp_def->Height, 0 );
  119.     CMOVE ( ucl, custom.intreq, (INTF_SETCLR|INTF_COPER) );
  120.     CEND ( ucl );
  121.  
  122.     old_ucl = disp_def->vp->UCopIns;
  123.     disp_def->vp->UCopIns = ucl;
  124.  
  125.     copint->is_Node.ln_Type = NT_INTERRUPT;
  126.     copint->is_Node.ln_Pri = 100;
  127.     copint->is_Node.ln_Name = "";
  128.     copint->is_Data = intdata;
  129.     copint->is_Code = CopRoutine;
  130.  
  131.     AddIntServer( INTB_COPER, copint );
  132.  
  133.     CopIntAdded = TRUE;
  134.  
  135.     if ( disp_def->Flags & DISP_SCREEN ) {
  136.     RethinkDisplay();
  137.     }
  138.  
  139. } // AddCopInt()
  140.  
  141.  
  142. ULONG
  143. GetModeID( DISP_DEF * disp_def )
  144. {
  145.     /* Check that the ModeID can handle doublebuffering.
  146.      * If not, then find the best ModeID that can.
  147.      */
  148.     struct DisplayInfo    disp;
  149.     ULONG        ModeID = disp_def->ModeID;
  150.  
  151.     D(PRINTF("GetModeID ENTERED with ModeID= 0x%lx\n",ModeID);)
  152.  
  153.     if ( GetDisplayInfoData(NULL, (UBYTE *)&disp, sizeof(struct DisplayInfo), DTAG_DISP, ModeID) ) {
  154.     D(PRINTF("GetModeID 1\n");)
  155.  
  156.     if ( !(disp.PropertyFlags & DIPF_IS_DBUFFER) ) {
  157.  
  158.         D(PRINTF("GetModeID 2\n");)
  159.  
  160.         ModeID = BestModeID(BIDTAG_NominalWidth, disp_def->Width,
  161.         BIDTAG_NominalHeight, disp_def->Height,
  162.         BIDTAG_Depth, disp_def->Depth,
  163.         /* Keep the DIPF_ properties of the original
  164.          * ModeID, but ensure we have DBUFFER
  165.          * properties too.
  166.          */
  167.         BIDTAG_SourceID, ModeID,
  168.         BIDTAG_DIPFMustHave, DIPF_IS_DBUFFER,
  169.         TAG_END);
  170.     }
  171.     }
  172.  
  173.     D(PRINTF("GetModeID END with ModeID= 0x%lx\n",ModeID);)
  174.  
  175.     return( disp_def->ModeID = ModeID );
  176.  
  177. } // GetModeID()
  178.  
  179.  
  180. ULONG __asm OpenWorkBenchPatch(void)
  181. {
  182.     return(0);
  183.  
  184. } // OpenWorkBenchPatch()
  185.  
  186.  
  187. VOID
  188. CloseScreenQuiet( struct Screen * sc, BOOL quiet )
  189. {
  190.     APTR OWB;
  191.  
  192.     D(PRINTF("CloseScreenQuiet() quiet= %ld\n",quiet);)
  193.  
  194.     if ( quiet )
  195.     OWB = SetFunction((struct Library *)IntuitionBase, -0xd2, (APTR)OpenWorkBenchPatch);
  196.  
  197.     CloseScreen( sc );
  198.  
  199.     if ( quiet )
  200.     SetFunction((struct Library *)IntuitionBase, -0xd2, OWB);
  201.  
  202. } // CloseScreenQuiet()
  203.  
  204.  
  205. /*
  206.  * Open a screen and a window as defined by disp_def. Optionally
  207.  * load an ILBM file into background.
  208.  */
  209. ScrWinOpen( DISP_DEF * disp_def, UBYTE * ilbmfile )
  210. {
  211.     ULONG        tag;
  212.     ULONG        flags,ErrorCode = 0;
  213.     struct ColorSpec    initialcolors[] =
  214.             {
  215.                 {0,0,0,0},
  216.                 {-1,0,0,0}
  217.             };
  218.  
  219.     GetModeID( disp_def );
  220.  
  221.     D(PRINTF("ScrWinOpen() ENTERED with ModeID= %ld, Width= %ld, Height= %ld\n",
  222.     disp_def->ModeID,disp_def->Width,disp_def->Height);)
  223.  
  224.     /*
  225.      * If we are opening a full sized screen as opposed to a screen
  226.      * that is just the size of the CDXL dimensions.
  227.      */
  228.     if ( disp_def->Flags & DISP_ALLOCBM ) {
  229.     flags = BMF_CLEAR|BMF_DISPLAYABLE;
  230.  
  231.     if ( disp_def->Flags & DISP_INTERLEAVED )
  232.         flags |= BMF_INTERLEAVED;
  233.  
  234.     D(PRINTF("ScrWinOpen() Allocating bm[0]\n");)
  235.  
  236.     if (!(disp_def->bm[0] = (struct BitMap *)AllocBitMap( disp_def->Width,
  237.      disp_def->Height, disp_def->Depth, flags, NULL )) ) {
  238.  
  239.         D(PRINTF("Could NOT AllocBitMap() 1\n");)
  240.         disp_def->bm[1] = NULL;
  241.         return( RC_NO_MEM );
  242.     }
  243.  
  244.     D(PRINTF("ScrWinOpen() Allocating bm[1]\n");)
  245.  
  246.     if (!(disp_def->bm[1] = (struct BitMap *)AllocBitMap( disp_def->Width,
  247.      disp_def->Height, disp_def->Depth, flags, NULL )) ) {
  248.  
  249.         D(PRINTF("Could NOT AllocBitMap() 2\n");)
  250.  
  251.         FreeBitMap( disp_def->bm[0] );
  252.         disp_def->bm[0] = NULL;
  253.  
  254.         return( RC_NO_MEM );
  255.     }
  256.     tag = TAG_IGNORE;
  257.     } else {
  258.     tag = SA_Left;
  259.     }
  260.  
  261.     D(PRINTF("ScrWinOpen() disp_def->Top= %ld, Left= %ld, Height= %ld, Width= %ld\n",
  262.     disp_def->Top,disp_def->Left,disp_def->Height,disp_def->Width);)
  263.  
  264.     if ( CDXLScreen = OpenScreenTags(NULL,
  265. //    SA_Top,        600,        // To make sure it is hidden
  266.     SA_Top,        disp_def->Top,
  267.     SA_Left,    disp_def->Left,
  268.     SA_Width,    disp_def->Width,
  269.     SA_Height,    disp_def->Height,
  270.     SA_Depth,    disp_def->Depth,
  271.     SA_BitMap,    disp_def->bm[0],
  272.     SA_DisplayID,    disp_def->ModeID,
  273.     SA_Interleaved,    (disp_def->Flags & DISP_INTERLEAVED) ? TRUE : FALSE,
  274.     SA_ShowTitle,    FALSE,
  275.     SA_Quiet,    TRUE,
  276.     SA_Behind,    TRUE,
  277.     SA_Colors,    initialcolors,
  278.     SA_ErrorCode,    &ErrorCode,
  279.     tag,        disp_def->Left,
  280.     TAG_DONE) )
  281.     {
  282.  
  283.     D(PRINTF("Got Screen Top= %ld, Left= %ld, Height= %ld, Width= %ld\ndisp_def->Left= %ld, Top= %ld\n",
  284.         CDXLScreen->TopEdge,CDXLScreen->LeftEdge,
  285.         CDXLScreen->Height,CDXLScreen->Width,disp_def->Left,disp_def->Top);)
  286.  
  287.     D(PRINTF("BitMap.Rows= %ld, BitMap->Rows= %ld, BMA_HEIGHT= %ld\ndisp_def->Height= %ld, bm[0]->rows= %ld, BMA_HEIGHT= %ld\n",
  288.         CDXLScreen->BitMap.Rows,CDXLScreen->RastPort.BitMap->Rows,
  289.         GetBitMapAttr( CDXLScreen->RastPort.BitMap, BMA_HEIGHT),
  290.         disp_def->Height,disp_def->bm[0]->Rows,
  291.         GetBitMapAttr( disp_def->bm[0], BMA_HEIGHT) );)
  292.  
  293.     VideoControlTags( CDXLScreen->ViewPort.ColorMap,
  294.         VC_IntermediateCLUpdate,FALSE,
  295.         TAG_END);
  296.  
  297.     VideoControlTags( CDXLScreen->ViewPort.ColorMap,
  298.         VC_IntermediateCLUpdate_Query,&smartgfx,TAG_END);
  299.  
  300.     smartgfx=(smartgfx==0x12345678)?0:-1;
  301.     D(PRINTF("\nsmartgfx= '%ls'\n\n",
  302.         smartgfx ? "SMART" : "DUMB" );)
  303.  
  304.     if ( CDXLWindow = OpenWindowTags( NULL,
  305.         WA_Width,        CDXLScreen->Width,
  306.         WA_Height,        CDXLScreen->Height,
  307.         WA_IDCMP,        NULL,    //IDCMP_MOUSEBUTTONS,
  308.         WA_Flags,        BACKDROP | BORDERLESS | RMBTRAP,
  309.         WA_Activate,    TRUE,
  310.         WA_CustomScreen,    CDXLScreen,
  311.         TAG_DONE) ) {
  312.  
  313.         if ( disp_def->Flags & DISP_NOPOINTER )
  314.         SetPointer( CDXLWindow, InvisiblePointer, 1, 1, 0, 0 );
  315.  
  316.         disp_def->vp = &CDXLScreen->ViewPort;
  317.  
  318.         if ( disp_def->dbuf = AllocDBufInfo( disp_def->vp ) ) {
  319.  
  320.         if ( (disp_def->Flags & DISP_BACKGROUND) && ilbmfile && *ilbmfile ) {
  321.  
  322.             if ( DoILBM( ilbmfile, disp_def ) )
  323.             printf("Could not open '%ls'\n",ilbmfile);
  324.         }
  325.  
  326.         /*
  327.          * Add the copper interrupt.
  328.          */
  329.         if ( SetUpIntData( &CopIntData ) ) {
  330.             AddCopInt( disp_def, &ucl, &CopInt, &CopIntData );
  331. //            ScreenPosition( CDXLScreen, SPOS_ABSOLUTE, CDXLScreen->LeftEdge, 0, 0, 0);
  332.             ScreenPosition( CDXLScreen, SPOS_ABSOLUTE, disp_def->Left, disp_def->Top, 0, 0);
  333.             ScreenToFront( CDXLScreen );
  334.             return( RC_OK );
  335.         }
  336.         }
  337.         if ( disp_def->dbuf ) {
  338.         FreeDBufInfo( disp_def->dbuf );
  339.         }
  340.         CloseWindow( CDXLWindow );
  341.     }
  342.  
  343.     CloseScreenQuiet( CDXLScreen, (disp_def->Flags & DISP_PATCH_OPENWB) ?
  344.         TRUE : FALSE );
  345.     CDXLScreen = NULL;
  346.  
  347.     if ( disp_def->Flags & DISP_ALLOCBM ) {
  348.         FreeBitMap( disp_def->bm[0] );
  349.         FreeBitMap( disp_def->bm[1] );
  350.         disp_def->bm[0] = disp_def->bm[1] = NULL;
  351.     }
  352.     return( RC_NO_WIN );
  353.     } else {
  354.     D(PRINTF("ScrWinOpen() Could NOT open screen ErrorCode= %ld\n",ErrorCode);)
  355.     }
  356.  
  357.     if ( disp_def->Flags & DISP_ALLOCBM ) {
  358.     FreeBitMap( disp_def->bm[0] );
  359.     FreeBitMap( disp_def->bm[1] );
  360.     disp_def->bm[0] = disp_def->bm[1] = NULL;
  361.     }
  362.  
  363.     return( RC_NO_SC );
  364.  
  365. } // ScrWinOpen()
  366.  
  367.  
  368.  
  369. /*********
  370.  
  371.  View Stuff
  372.  
  373. **********/
  374.  
  375. struct View          View,* OldView;
  376. struct ViewPort       ViewPort;
  377. struct RasInfo          RasInfo;
  378. struct MonitorInfo      Monitor;
  379. struct ColorMap        * CMap;
  380. struct ViewPortExtra    * Vpx;
  381. struct ViewExtra    * Vx;
  382.  
  383.  
  384. /*
  385.  * Allocate a ViewExtra and attempt to obtain a MonitorInfo. Use
  386.  * the info from the MonitorInfo to set the ViewExtra->Monitor and
  387.  * set the view's Dx and DyOffset.
  388.  */
  389. struct ViewExtra *
  390. GetVX( struct View * view, ULONG ModeID )
  391. {
  392.     struct ViewExtra    * vx;
  393.  
  394.     if ( vx = GfxNew( VIEW_EXTRA_TYPE ) ) {
  395.     if ( GetDisplayInfoData( NULL, (UBYTE *)&Monitor, sizeof(Monitor), DTAG_MNTR, ModeID ) ) {
  396.         vx->Monitor = Monitor.Mspc;
  397.         view->DxOffset = Monitor.ViewPosition.x;
  398.         view->DyOffset = Monitor.ViewPosition.y;
  399.     }
  400.     }
  401.  
  402.     return( vx );
  403.  
  404. } // GetVX()
  405.  
  406.  
  407. /*
  408.  * Open a view as defined by disp_def. Optionally
  409.  * load an ILBM file into background.
  410.  */
  411. ViewOpen( DISP_DEF * disp_def, UBYTE * ilbmfile )
  412. {
  413.     ULONG         flags;
  414.     struct DimensionInfo diminfo;
  415.  
  416.     GetModeID( disp_def );
  417.  
  418.     /*
  419.      * If we are opening a full sized display as opposed to one
  420.      * that is just the size of the CDXL dimensions.
  421.      */
  422.     if ( disp_def->Flags & DISP_ALLOCBM ) {
  423.     flags = BMF_CLEAR|BMF_DISPLAYABLE;
  424.  
  425.     if ( disp_def->Flags & DISP_INTERLEAVED )
  426.         flags |= BMF_INTERLEAVED;
  427.  
  428.     if (!(disp_def->bm[0] = (struct BitMap *)AllocBitMap( disp_def->Width,
  429.      disp_def->Height, disp_def->Depth, flags, NULL )) ) {
  430.  
  431.         D(PRINTF("Could NOT AllocBitMap() 1\n");)
  432.         return( RC_NO_MEM );
  433.     }
  434.  
  435.     if (!(disp_def->bm[1] = (struct BitMap *)AllocBitMap( disp_def->Width,
  436.      disp_def->Height, disp_def->Depth, flags, disp_def->bm[0] )) ) {
  437.  
  438.         D(PRINTF("Could NOT AllocBitMap() 2\n");)
  439.         FreeBitMap( disp_def->bm[0] );
  440.         disp_def->bm[0] = NULL;
  441.         return( RC_NO_MEM );
  442.     }
  443.     }
  444.  
  445.     if ( CMap = GetColorMap( MAX ( (disp_def->Depth<<1), 256 ) ) ) {
  446.     InitView( &View );
  447.     InitVPort( &ViewPort );
  448.  
  449.     ViewPort.ColorMap = CMap;
  450.     ViewPort.DHeight = disp_def->Height;
  451.     ViewPort.DWidth = disp_def->Width;
  452.     ViewPort.Modes = disp_def->ModeID;
  453.     ViewPort.RasInfo = &RasInfo;
  454.     RasInfo.BitMap = disp_def->bm[0];
  455.     ViewPort.Next = View.ViewPort;
  456.     View.ViewPort = &ViewPort;
  457.  
  458.     if ( Vx = GetVX( &View, disp_def->ModeID ) ) {
  459.         GfxAssociate(&View,Vx);
  460.         View.Modes |= EXTEND_VSTRUCT;
  461.     }
  462.  
  463.     D(PRINTF("\nViewOpen() DxOffset= %ld, DyOffset= %ld, Left= %ld, Top= %ld\n",
  464.         View.DxOffset,View.DyOffset,disp_def->Left,disp_def->Top);)
  465.  
  466.     if ( 1 || !(disp_def->Flags & DISP_ALLOCBM ) ) {
  467.  
  468.         View.DxOffset += disp_def->Left;
  469.         View.DyOffset += disp_def->Top;
  470.     }
  471.  
  472.     D(PRINTF("ViewOpen() DxOffset= %ld, DyOffset= %ld, Left= %ld, Top= %ld\n",
  473.         View.DxOffset,View.DyOffset,disp_def->Left,disp_def->Top);)
  474.  
  475.     if ( Vpx = GfxNew(VIEWPORT_EXTRA_TYPE) ) {
  476.  
  477.         if( GetDisplayInfoData( NULL,(UBYTE *)&diminfo,
  478.         sizeof (diminfo), DTAG_DIMS, disp_def->ModeID) )
  479.             {
  480.  
  481. //        Vpx->DisplayClip = diminfo.MaxOScan;
  482.         Vpx->DisplayClip = diminfo.VideoOScan;
  483.  
  484.         }
  485.  
  486.         VideoControlTags(
  487.         CMap,VTAG_VIEWPORTEXTRA_SET,Vpx,
  488.         VTAG_ATTACH_CM_SET,&ViewPort,
  489.         VTAG_NORMAL_DISP_SET,FindDisplayInfo( disp_def->ModeID ),
  490.         VTAG_COERCE_DISP_SET,FindDisplayInfo( disp_def->ModeID ),
  491.         VC_IntermediateCLUpdate,0,
  492.         VC_IntermediateCLUpdate_Query,&smartgfx,
  493.         TAG_END
  494.         );
  495.  
  496.         smartgfx = ( smartgfx == 0x12345678 ) ? 0 : -1;
  497.         D(PRINTF("\nsmartgfx= '%ls'\n\n",
  498.         smartgfx ? "SMART" : "DUMB" );)
  499.  
  500.         disp_def->vp = &ViewPort;
  501.  
  502.         if ( SetUpIntData( &CopIntData ) ) {
  503.         AddCopInt( disp_def, &ucl, &CopInt, &CopIntData );
  504.         MakeVPort( &View, &ViewPort );
  505.         MrgCop( &View );
  506.  
  507.         if ( disp_def->dbuf = AllocDBufInfo( disp_def->vp ) ) {
  508.             if ( (disp_def->Flags & DISP_BACKGROUND) && ilbmfile && *ilbmfile ) {
  509.  
  510.             if ( DoILBM( ilbmfile, disp_def ) )
  511.                 printf("Could not open '%ls'\n",ilbmfile);
  512.             }
  513.  
  514.             OldView = GfxBase->ActiView;
  515.             LoadView( &View );
  516.  
  517.             return( RC_OK );
  518.         }
  519.         }
  520.         CloseDisplay( disp_def );
  521.         return( RC_NO_MEM );
  522.     }
  523.  
  524.     FreeColorMap( CMap );
  525.     CMap = NULL;
  526.     }
  527.  
  528.     if ( disp_def->Flags & DISP_ALLOCBM ) {
  529.     FreeBitMap( disp_def->bm[0] );
  530.     FreeBitMap( disp_def->bm[1] );
  531.     disp_def->bm[0] = disp_def->bm[1] = NULL;
  532.     }
  533.  
  534.     return( RC_NO_MEM );
  535.  
  536. } // ViewOpen()
  537.  
  538.  
  539. /*
  540.  * Open either a screen or a view.
  541.  */
  542. OpenDisplay( DISP_DEF * disp_def, UBYTE * ilbmfile )
  543. {
  544.     D(PRINTF("OpenDisplay() disp_def->Top= %ld\n",disp_def->Top);)
  545.  
  546.     if ( disp_def->Flags & DISP_SCREEN ) {
  547.     return( ScrWinOpen( disp_def, ilbmfile ) );
  548.     } else {
  549.     return( ViewOpen( disp_def, ilbmfile ) );
  550.     }
  551.  
  552. } // OpenDisplay()
  553.  
  554.  
  555. /*
  556.  *  Close screen or view.
  557.  */
  558. VOID
  559. CloseDisplay( DISP_DEF * disp_def )
  560. {
  561.  
  562.     if ( CopIntAdded ) {
  563.     RemIntServer( INTB_COPER, &CopInt );
  564.     disp_def->vp->UCopIns = old_ucl;
  565.     RethinkDisplay();
  566.     FreeCopList( ucl.FirstCopList );
  567.     CopIntAdded = FALSE;
  568.     }
  569.  
  570.     if ( CopSigBit != -1 ) {
  571.     FreeSignal( CopSigBit );
  572.     CopSigBit = -1;
  573.     }
  574.  
  575.     if ( disp_def->dbuf )
  576.     FreeDBufInfo( disp_def->dbuf );
  577.  
  578.     /*
  579.      * Close the screen and window.
  580.      */
  581.     if ( disp_def->Flags & DISP_SCREEN ) {
  582.     if ( CDXLWindow ) {
  583.         CloseWindow( CDXLWindow );
  584.         CDXLWindow = NULL;
  585.     }
  586.  
  587.     if ( CDXLScreen ) {
  588.         CloseScreenQuiet( CDXLScreen, (disp_def->Flags & DISP_PATCH_OPENWB) ?
  589.         TRUE : FALSE );
  590.         CDXLScreen = NULL;
  591.     }
  592.     } else {
  593.     /*
  594.      * We had a view not a screen.
  595.      */
  596.     if ( OldView ) {
  597.         LoadView( OldView );
  598.         OldView = NULL;
  599.     }
  600.  
  601.     if ( View.ViewPort )
  602.         FreeVPortCopLists( View.ViewPort );
  603.  
  604.     if ( Vpx ) {
  605.         GfxFree( Vpx );
  606.         Vpx = NULL;
  607.     }
  608.  
  609.     if ( Vx ) {
  610.         GfxFree( Vx );
  611.         Vx = NULL;
  612.     }
  613.  
  614.     if ( View.LOFCprList ) {
  615.         FreeCprList( View.LOFCprList );
  616.         View.LOFCprList = NULL;
  617.     }
  618.  
  619.     if ( CMap ) {
  620.         FreeColorMap( CMap );
  621.         CMap = NULL;
  622.     }
  623.     }
  624.  
  625.     /*
  626.      * If we allocated these bitmaps with AllocBitMap(),
  627.      * free them with FreeBitMap().
  628.      */
  629.     if ( disp_def->Flags & DISP_ALLOCBM ) {
  630.     if ( disp_def->bm[0] )
  631.         FreeBitMap( disp_def->bm[0] );
  632.  
  633.     if ( disp_def->bm[1] )
  634.         FreeBitMap( disp_def->bm[1] );
  635.     }
  636.  
  637. } // CloseDisplay()
  638.  
  639.  
  640. VOID
  641. Display2Front( DISP_DEF * disp_def )
  642. {
  643.     if ( disp_def->Flags & DISP_SCREEN ) {
  644.     if ( CDXLScreen )
  645.         ScreenToFront( CDXLScreen );
  646.  
  647.     } else {
  648.     if ( View.LOFCprList ) {
  649.         OldView = GfxBase->ActiView;
  650.         LoadView( &View );
  651.     }
  652.     }
  653.  
  654. } // Display2Front()
  655.  
  656.