-
Notifications
You must be signed in to change notification settings - Fork 2
/
console.c
176 lines (132 loc) · 3.73 KB
/
console.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/***************************************************************************
*
* Copyright (c) 1997-2022 Jeff V. Merkey
* 7260 SE Tenino St.
* Portland, Oregon 97206
* jeffmerkey@gmail.com
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the Lesser GNU Public License as published by the
* Free Software Foundation, version 2.1, or any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* Original Authorship :
* source code written by Jeff V. Merkey
*
* Original Contributors :
* Jeff V. Merkey
*
*
*
****************************************************************************
*
*
* AUTHOR : Jeff V. Merkey (jeffmerkey@gmail.com)
* FILE : CONSOLE.C
* DESCRIP : Console Abstraction Layer
* DATE : November 1, 1998
*
*
***************************************************************************/
#include "globals.h"
#if (WINDOWS_NT_UTIL)
void cls(void)
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coordScreen = { 0, 0 }; /* here's where we'll home the
cursor */
BOOL bSuccess;
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */
DWORD dwConSize; /* number of character cells in
the current buffer */
/* get the number of character cells in the current buffer */
bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
/* fill the entire screen with blanks */
bSuccess = FillConsoleOutputCharacter( hConsole, (TCHAR) ' ',
dwConSize, coordScreen, &cCharsWritten );
/* get the current text attribute */
bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
/* now set the buffer's attributes accordingly */
bSuccess = FillConsoleOutputAttribute( hConsole, csbi.wAttributes,
dwConSize, coordScreen, &cCharsWritten );
/* put the cursor at (0, 0) */
bSuccess = SetConsoleCursorPosition( hConsole, coordScreen );
return;
}
void ClearScreen(ULONG context)
{
cls();
}
void WaitForKey()
{
NWFSPrint(" Press Any Key To Continue ...");
getc(stdin);
}
ULONG Pause(void)
{
BYTE ch;
ch = getc(stdin);
if (ch == 0x27)
return 1;
return 0;
}
#endif
#if (LINUX_UTIL)
void ClearScreen(ULONG context)
{
printf("%c%c", 0x1B, 'c'); // Reset Console
}
void WaitForKey()
{
NWFSPrint(" Press Any Key To Continue ...");
getc(stdin);
}
ULONG Pause(void)
{
BYTE ch;
ch = getc(stdin);
if (ch == 0x27)
return 1;
return 0;
}
#endif
#if (DOS_UTIL)
void ClearScreen(ULONG context)
{
union REGS r;
// clear the screen
r.h.ah = 6; // scroll command
r.h.al = 0; // clear screen code
r.h.ch = 0; // start row
r.h.cl = 0; // start column
r.h.dh = 24; // end row
r.h.dl = 79; // end column
r.h.bh = 7; // blank line is blank
int86(0x10, &r, &r); // go to real mode
// goto_xy (0, 0)
r.h.ah = 2; // cursor address command
r.h.bh = 0; // code page 0
r.h.dh = 0; // x = 0
r.h.dl = 0; // y = 0
int86(0x10, &r, &r); // go to real mode
}
void WaitForKey()
{
NWFSPrint(" Press Any Key To Continue ...");
getc(stdin);
}
ULONG Pause(void)
{
BYTE ch;
ch = getc(stdin);
if (ch == 0x27)
return 1;
return 0;
}
#endif