[Contents] [Index] [Help] [Retrace] [Browse <] [Browse >]

The preceding sample program provides a way of exiting gracefully with the
cleanup() subroutine.  This function returns to the memory manager all
dynamically-allocated memory chunks.  Notice the calls to FreeRaster() and
FreeColorMap(). These calls correspond directly to the allocation calls
AllocRaster() and GetColorMap() located in the body of the program. Now
look at the calls within cleanup() to FreeVPortCopLists() and
FreeCprList(). When you call MakeVPort(), the graphics system dynamically
allocates some space to hold intermediate instructions from which a final
Copper instruction list is created. When you call MrgCop(), these
intermediate Copper lists are merged together into the final Copper list,
which is then given to the hardware for interpretation. It is this list
that provides the stable display on the screen, split into separate
ViewPorts with their own colors and resolutions and so on.

When your program completes, you must see that it returns all of the
memory resources that it used so that those memory areas are again
available to the system for reassignment to other tasks.  Therefore, if
you use the routines MakeVPort() or MrgCop(), you must also arrange to use
FreeCprList() (pointing to each of those lists in the View structure) and
FreeVPortCopLists() (pointing to the ViewPort that is about to be
deallocated).  If your View is interlaced, you will also have to call
FreeCprList(&view.SHFCprList) because an interlaced view has a separate
Copper list for each of the two fields displayed. Do not confuse
FreeVPortCopLists() with FreeCprList(). The former works on intermediate
Copper lists for a specific ViewPort, the latter directly on a hardware
Copper list from the View.

As a final caveat, notice that when you do free everything, the memory
manager or other programs may immediately change the contents of the freed
memory.  Therefore, if the Copper is still executing an instruction stream
(as a result of a previous LoadView()) when you free that memory, the
display will malfunction. Once another View has been installed via
LoadView(), do a WaitTOF() for the new View to begin displaying, and then
you can begin freeing up your resources.  WaitTOF() waits for the vertical
blanking period to begin and all vertical blank interrupts to complete
before returning to the caller. The routine WaitBOVP() (for
"WaitBottomOfViewPort") busy waits until the vertical beam reaches the
bottom of the specified ViewPort before returning to the caller.  This
means no other tasks run until this function returns.