update
[midnight-commander.git] / os2 / cons.handler.os2.c
blob8f04ff2d06cb8db8bf6960fa51e6420425febfb2
1 /* Client interface for General purpose OS/2 console save/restore server.
2 1997 Alexander Dong <ado@software-ag.de>
3 Having the same interface as its Linux counterpart:
4 Copyright (C) 1994 Janne Kukonlehto <jtklehto@stekt.oulu.fi>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <config.h>
23 #ifndef __os2__
24 #error This file is for OS/2 operating systems.
25 #else
27 #define INCL_BASE
28 #define INCL_NOPM
29 #define INCL_VIO
30 #define INCL_KBD
31 #define INCL_DOS
32 #define INCL_SUB
33 #define INCL_DOSERRORS
35 #include <os2.h>
37 #include "tty.h"
38 #include "util.h"
39 #include "win.h"
40 #include "cons.saver.h"
42 signed char console_flag = 1;
43 static unsigned char *scr_buffer;
44 static unsigned char *pointer;
46 static int GetScrRows();
47 static int GetScrCols();
49 static int GetScrRows()
51 VIOMODEINFO pvMode = {80};
52 unsigned int hVio = 0;
53 VioGetMode(&pvMode, hVio);
54 return (pvMode.row ? pvMode.row: 25);
57 static int GetScrCols()
59 VIOMODEINFO pvMode = {80};
60 unsigned int hVio = 0;
61 VioGetMode(&pvMode, hVio);
62 return (pvMode.col ? pvMode.col: 80);
65 void show_console_contents (int starty, unsigned char begin_line, unsigned char end_line)
67 int col = GetScrCols();
68 int row = GetScrRows();
69 int n;
70 register int z;
72 pointer = scr_buffer;
73 for (z=0; z<(begin_line * col); z++) {
74 pointer++; pointer++;
76 n = (end_line - begin_line + 1) * col;
77 VioWrtCellStr((PCH) pointer, (USHORT) n, begin_line, 0, 0);
78 return; /* .ado */
81 void handle_console (unsigned char action)
83 static int col;
84 static int row;
85 int n;
87 switch (action) {
88 case CONSOLE_INIT: /* Initialize */
89 col = GetScrCols();
90 row = GetScrRows();
91 scr_buffer = (unsigned char *) malloc(col * row * 2); /* short values */
92 n = col * row * 2;
93 VioReadCellStr((PCH) scr_buffer, (USHORT *) &n, 0, 0, 0); /* Just save it */
94 break;
95 case CONSOLE_DONE:
96 free(scr_buffer);
97 break;
98 case CONSOLE_SAVE: /* Save the screen */
99 n = col * row * 2;
100 VioReadCellStr((PCH) scr_buffer, (USHORT *) &n, 0, 0, 0);
101 break;
102 case CONSOLE_RESTORE:
103 n = col * row * 2;
104 VioWrtCellStr ((PCH) scr_buffer, (USHORT) n, 0, 0, 0); /* Write it back */
105 break;
106 default:
107 /* This is not possible, but if we are here, just save the screen */
108 handle_console(CONSOLE_SAVE);
109 break;
111 return; /* .ado */
114 #endif // !__os2__