- Update address of Free Software Foundation.
[reactos.git] / reactos / boot / freeldr / freeldr / arch / i386 / pccons.c
1 /* $Id$
2 *
3 * FreeLoader
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include <freeldr.h>
21
22 #define TEXTMODE_BUFFER 0xb8000
23 #define TEXTMODE_BUFFER_SIZE 0x8000
24
25 #define TEXT_COLS 80
26 #define TEXT_LINES 25
27
28 VOID
29 PcConsPutChar(int Ch)
30 {
31 REGS Regs;
32
33 /* If we are displaying a CR '\n' then do a LF also */
34 if ('\n' == Ch)
35 {
36 /* Display the LF */
37 PcConsPutChar('\r');
38 }
39
40 /* If we are displaying a TAB '\t' then display 8 spaces ' ' */
41 if ('\t' == Ch)
42 {
43 /* Display the 8 spaces ' ' */
44 PcConsPutChar(' ');
45 PcConsPutChar(' ');
46 PcConsPutChar(' ');
47 PcConsPutChar(' ');
48 PcConsPutChar(' ');
49 PcConsPutChar(' ');
50 PcConsPutChar(' ');
51 PcConsPutChar(' ');
52 return;
53 }
54
55 /* Int 10h AH=0Eh
56 * VIDEO - TELETYPE OUTPUT
57 *
58 * AH = 0Eh
59 * AL = character to write
60 * BH = page number
61 * BL = foreground color (graphics modes only)
62 */
63 Regs.b.ah = 0x0E;
64 Regs.b.al = Ch;
65 Regs.w.bx = 1;
66 Int386(0x10, &Regs, &Regs);
67 }
68
69 BOOLEAN
70 PcConsKbHit(VOID)
71 {
72 REGS Regs;
73
74 /* Int 16h AH=01h
75 * KEYBOARD - CHECK FOR KEYSTROKE
76 *
77 * AH = 01h
78 * Return:
79 * ZF set if no keystroke available
80 * ZF clear if keystroke available
81 * AH = BIOS scan code
82 * AL = ASCII character
83 */
84 Regs.b.ah = 0x01;
85 Int386(0x16, &Regs, &Regs);
86
87 return 0 == (Regs.x.eflags & I386FLAG_ZF);
88 }
89
90 int
91 PcConsGetCh(void)
92 {
93 REGS Regs;
94 static BOOLEAN ExtendedKey = FALSE;
95 static char ExtendedScanCode = 0;
96
97 /* If the last time we were called an
98 * extended key was pressed then return
99 * that keys scan code. */
100 if (ExtendedKey)
101 {
102 ExtendedKey = FALSE;
103 return ExtendedScanCode;
104 }
105
106 /* Int 16h AH=00h
107 * KEYBOARD - GET KEYSTROKE
108 *
109 * AH = 00h
110 * Return:
111 * AH = BIOS scan code
112 * AL = ASCII character
113 */
114 Regs.b.ah = 0x00;
115 Int386(0x16, &Regs, &Regs);
116
117 /* Check for an extended keystroke */
118 if (0 == Regs.b.al)
119 {
120 ExtendedKey = TRUE;
121 ExtendedScanCode = Regs.b.ah;
122 }
123
124 /* Return keystroke */
125 return Regs.b.al;
126 }
127
128 /* EOF */