]> git.ipfire.org Git - u-boot.git/blob - board/MAI/bios_emulator/scitech/src/pm/tests/restore.c
* Code cleanup:
[u-boot.git] / board / MAI / bios_emulator / scitech / src / pm / tests / restore.c
1 /****************************************************************************
2 *
3 * SciTech OS Portability Manager Library
4 *
5 * ========================================================================
6 *
7 * The contents of this file are subject to the SciTech MGL Public
8 * License Version 1.0 (the "License"); you may not use this file
9 * except in compliance with the License. You may obtain a copy of
10 * the License at http://www.scitechsoft.com/mgl-license.txt
11 *
12 * Software distributed under the License is distributed on an
13 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * rights and limitations under the License.
16 *
17 * The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
18 *
19 * The Initial Developer of the Original Code is SciTech Software, Inc.
20 * All Rights Reserved.
21 *
22 * ========================================================================
23 *
24 * Language: ANSI C
25 * Environment: Linux/QNX
26 *
27 * Description: Program to restore the console state state from a previously
28 * saved state if the program crashed while the console
29 * was in graphics mode.
30 *
31 ****************************************************************************/
32
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include "pmapi.h"
36
37 void setVideoMode(int mode)
38 {
39 RMREGS r;
40
41 r.x.ax = mode;
42 PM_int86(0x10, &r, &r);
43 }
44
45 int main(void)
46 {
47 PM_HWND hwndConsole;
48 ulong stateSize;
49 void *stateBuf;
50 FILE *f;
51
52 /* Write the saved console state buffer to disk */
53 if ((f = fopen("/etc/pmsave.dat","rb")) == NULL) {
54 printf("Unable to open /etc/pmsave.dat for reading!\n");
55 return -1;
56 }
57 fread(&stateSize,1,sizeof(stateSize),f);
58 if (stateSize != PM_getConsoleStateSize()) {
59 printf("Size mismatch in /etc/pmsave.dat!\n");
60 return -1;
61 }
62 if ((stateBuf = PM_malloc(stateSize)) == NULL) {
63 printf("Unable to allocate console state buffer!\n");
64 return -1;
65 }
66 fread(stateBuf,1,stateSize,f);
67 fclose(f);
68
69 /* Open the console */
70 hwndConsole = PM_openConsole(0,0,0,0,0,true);
71
72 /* Forcibly set 80x25 text mode using the BIOS */
73 setVideoMode(0x3);
74
75 /* Restore the previous console state */
76 PM_restoreConsoleState(stateBuf,0);
77 PM_closeConsole(hwndConsole);
78 PM_free(stateBuf);
79 printf("Console state successfully restored from /etc/pmsave.dat\n");
80 return 0;
81 }