Screen Buffer
Volume Number: 1
Issue Number: 9
Column Tag: Modula 2 Mods
"Using the Alternate Screen Buffer
By Tom Taylor, Software Engineer, Modula-2 Corp., Provo, Ut.,
MacTutor Contributing Editor
This article discusses the "alternate screen" capabilities of the Macintosh and
presents a module that allows easy access to this facility from MacModula-2.
The Alternate Screen
As far as I know, Inside Macintosh only mentions the alternate screen buffer in
two places: in the Memory Manager Programmer's Guide and in the Segment Loader
Programmer's Guide. The Memory Manager section simply says, "There are alternate
screen and sound buffers for special applications. If you use either or both of these,
the space available for use by your application is reduced accordingly..." The alternate
screen buffer can be used for high-speed flicker free graphics or a slide show
program. For example, an application can be drawing in one screen while displaying a
different screen. The popular "Tumbling Mac" demo by Mainstay uses the alternate
screen buffer to create a high-speed flicker-free animation application. According to
figure 1, the alternate screen buffer is allocated 32768 bytes below the main screen
buffer.
Figure 1. Partial memory map showing sizes of various buffers.
The Segment Loader section mentions that the Chain and Launch traps configure
memory for the sound and screen buffers. Whenever one of these traps is called, a
parameter is passed that determines how these buffers are set up. The word (16-bit)
parameter has three possible values:
Zero - Only the main sound and screen buffers are allocated. This is the normal
situation and gives an application the most possible memory.
Negative - The alternate sound buffer and main screen buffer is allocated.
Positive - Both the alternate sound and screen buffers are allocated.
A Screen Switcher Module
Instead of building a specific program to demonstrate the alternate screen in
Modula-2, this article presents a library module that can be used in many different
programs in many different types of applications. This article will also present a
small program that uses the developed screen switcher module.
A screen switcher module should support at least four functions:
• launch a program with the alternate screen,
• copy the main screen into the alternate screen,
• change the screen back and forth between the main and alternate screens, and
• set the screen buffer to the main screen before a program exits.
Apparently, the Finder always launches a program with the main sound and
screen buffers (parameter set to 0). In order for a program to use the alternate
screen, the program must be re-launched with the appropriate parameter (-1). The
procedure LaunchWithAltScreen re-launches the program with the alternate screen if
the alternate screen is not already allocated.
Here are the Definition and Implementation modules for handling the alternate
screen:
DEFINITION MODULE ScreenSwitcher;
EXPORT QUALIFIED
LaunchWithTwoScreens,
CopyScreens,
SwitchScreens,
SetMainScreen;

PROCEDURE LaunchWithTwoScreens;
(* This procedure re-launches the
current program with the alternate
screen. If the alternate screen is
already installed, this procedure
does nothing. *)
PROCEDURE CopyScreens;
(* CopyScreens copies the main screen
into the alternate screen. *)

PROCEDURE SwitchScreens;
(* SwitchScreens alternately switches
what is being displayed from the
one screen to the other. *)

PROCEDURE SetMainScreen;
(* Sets the current screen buffer to
the main screen so that when the
program exits to the Finder