fixed warnings
[reactos.git] / rosapps / mc / pc / cons_os2.c
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>
5
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.
10
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.
15
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.
19
20 */
21
22 #include <config.h>
23
24 #ifdef __os2__
25 #define INCL_BASE
26 #define INCL_NOPM
27 #define INCL_VIO
28 #define INCL_KBD
29 #define INCL_DOS
30 #define INCL_SUB
31 #define INCL_DOSERRORS
32 #include <os2.h>
33 #endif
34
35 #include "../src/tty.h"
36 #include "../src/util.h"
37 #include "../src/win.h"
38 #include "../src/cons.saver.h"
39
40 signed char console_flag = 1;
41 static unsigned char *scr_buffer;
42 static unsigned char *pointer;
43
44 static int GetScrRows();
45 static int GetScrCols();
46
47 static int GetScrRows()
48 {
49 VIOMODEINFO pvMode = {80};
50 unsigned int hVio = 0;
51 VioGetMode(&pvMode, hVio);
52 return (pvMode.row ? pvMode.row: 25);
53 }
54
55 static int GetScrCols()
56 {
57 VIOMODEINFO pvMode = {80};
58 unsigned int hVio = 0;
59 VioGetMode(&pvMode, hVio);
60 return (pvMode.col ? pvMode.col: 80);
61 }
62
63 void show_console_contents (int starty, unsigned char begin_line, unsigned char end_line)
64 {
65 int col = GetScrCols();
66 int row = GetScrRows();
67 int n;
68 register int z;
69
70 pointer = scr_buffer;
71 for (z=0; z<(begin_line * col); z++) {
72 pointer++; pointer++;
73 }
74 n = (end_line - begin_line + 1) * col;
75 VioWrtCellStr((PCH) pointer, (USHORT) n, begin_line, 0, 0);
76 return;
77 }
78
79 void handle_console (unsigned char action)
80 {
81 static int col;
82 static int row;
83 int n;
84
85 switch (action) {
86 case CONSOLE_INIT: /* Initialize */
87 col = GetScrCols();
88 row = GetScrRows();
89 scr_buffer = (unsigned char *) malloc(col * row * 2); /* short values */
90 n = col * row * 2;
91 VioReadCellStr((PCH) scr_buffer, (USHORT *) &n, 0, 0, 0); /* Just save it */
92 break;
93 case CONSOLE_DONE:
94 free(scr_buffer);
95 break;
96 case CONSOLE_SAVE: /* Save the screen */
97 n = col * row * 2;
98 VioReadCellStr((PCH) scr_buffer, (USHORT *) &n, 0, 0, 0);
99 break;
100 case CONSOLE_RESTORE:
101 n = col * row * 2;
102 VioWrtCellStr ((PCH) scr_buffer, (USHORT) n, 0, 0, 0); /* Write it back */
103 break;
104 default:
105 /* This is not possible, but if we are here, just save the screen */
106 handle_console(CONSOLE_SAVE);
107 break;
108 }
109 return;
110 }