From 7e0f021a9aec35fd8e6725e87e3313b101d26f5e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Jan 2008 11:37:44 +0100 Subject: Initial import (2.0.2-6) --- reference/C/CONTRIB/SNIP/scrnsave.c | 79 +++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100755 reference/C/CONTRIB/SNIP/scrnsave.c (limited to 'reference/C/CONTRIB/SNIP/scrnsave.c') diff --git a/reference/C/CONTRIB/SNIP/scrnsave.c b/reference/C/CONTRIB/SNIP/scrnsave.c new file mode 100755 index 0000000..9d65e80 --- /dev/null +++ b/reference/C/CONTRIB/SNIP/scrnsave.c @@ -0,0 +1,79 @@ +/* +** SCRNSAVE.C - Save and restore text screen portably +** +** public domain demo by Bob Stout +*/ + +#include + +/* +** 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 +#include + +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 */ -- cgit v1.2.3-54-g00ecf