CHAPTER 4
from one physical screen to another, unless you call Vsync()
before Setscreen(). Some users report that these glitches may
be eliminated by making sure the high-order word of the
start address is the same for both screens (both screens are in
the same, even 64K block of memory).
The following sample program (Program 4-1) gives a
simple demonstration of page flipping. It sets up a second
block of screen memory, writes a screenful of one character
to that memory block, and then writes a screenful of a secî™…
ond character to the default screen memory area. When the
user presses the space bar, the program toggles the display
between the two screen areas. The program terminates when
the user presses the q key.
Program 4-1. XSCREEN.C
/**********************************************/
/* */
/* XSCREEN.C — Demonstrates use of the * /
/ * the XBIOS screen functions for "page */
/* flipping". */
/* */
/**********************************************/
#include <osbind.h> /* For macro definitions */
#define CON 2 /* device number of console keyboard */
main()
{
long block, altscr, oldscr, screen;
char ch=0;
block = Malloc(0x7E00L); /* allocate a second screen buffer * /
altscr = (block+256)SOxOOFFFFOO; / * align to page boundary */
oldscr = Physbase(); /* find 1st (default) screen addr */
Setscreen(altscr,-1L,-1L); /* set 2nd logical screen */
fill('X'); /* fill it with X's */
Setscreen(oldscr,-1L,-1L); /* change back to 1st logical screen */
fill('+'); /* fill it with +'s */
while(ch != 'q') /* until 'q' is pressed * /
(
ch = Bconin(CON); / * wait for a key */
if (ch==' ') /* if it's the space bar */
{
if (altscr == PhysbaseO) /* toggle physical screen */
screen - oldscr;
else screen = altscr;
Vsync();
Setscreen(-1L,screen,-1L);
)
)
Setscreen(oldscr,oldscr,-1L); /* at end, restore screens * /
Mfree(block); /* and de-allocate memory */
70