1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
/*
** SCRNSAVE.C - Save and restore text screen portably
**
** public domain demo by Bob Stout
*/
#include <stdlib.h>
/*
** Stuff from SNIPPETS courtesy of Jim Nutt
**
** Notes: VIOopen() is called redundantly to assure that the video
** information is always initialized. These multiple calls are benign.
**
** Because of using VIO.OBJ, this *must* be compiled in large model!
*/
#include "vio.h"
/*
** Save the current text screen
**
** Arguments: None
**
** Returns: Pointer to saved screen buffer, NULL if insufficient heap
*/
unsigned short *savescreen(void)
{
unsigned short *vbuf;
VIOopen();
if (NULL == (vbuf = malloc(VIOcolumns() * VIOrows() * 2)))
return NULL;
VIOgetra(0, 0, VIOcolumns() - 1, VIOrows() - 1, (int _far *)vbuf);
return vbuf;
}
/*
** Restore a screen previously saved by savescreen()
**
** Arguments: Buffer containing the screen to restore
**
** Returns: Nothing
**
** WARNING: No error checking done to verify same screen size and mode!
*/
void restorescreen(unsigned short *vbuf)
{
VIOopen();
VIOputr(0, 0, VIOcolumns(), VIOrows(), (int _far *)vbuf);
free(vbuf);
}
#ifdef TEST
#include <stdio.h>
#include <conio.h>
int main(void)
{
unsigned short *vbuf;
VIOopen();
if (NULL == (vbuf = savescreen()))
{
puts("Unable to save screen");
return EXIT_FAILURE;
}
VIOclear(0, 0, VIOcolumns(), VIOrows());
puts("Hit any key to exit");
getch();
restorescreen(vbuf);
VIOclose();
return EXIT_SUCCESS;
}
#endif /* TEST */
|