diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2008-01-27 11:37:44 +0100 |
---|---|---|
committer | Tobias Klauser <tklauser@xenon.tklauser.home> | 2008-01-27 11:37:44 +0100 |
commit | 7e0f021a9aec35fd8e6725e87e3313b101d26f5e (patch) | |
tree | b1cacc4b24393f517aeb4610e9e1021f954307a8 /reference/C/CONTRIB/SNIP/scrnsave.c |
Initial import (2.0.2-6)2.0.2-6
Diffstat (limited to 'reference/C/CONTRIB/SNIP/scrnsave.c')
-rwxr-xr-x | reference/C/CONTRIB/SNIP/scrnsave.c | 79 |
1 files changed, 79 insertions, 0 deletions
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 <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 */
|