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
|
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*/
#ifndef CONSOLE_C
#define CONSOLE_C
#include <toast.h>
/*********************************************************
* Set up the console buffer and pointer
********************************************************/
void console_init()
{
console_buffer = (char*)0xB8000;
console_pointer = 0;
}
/*********************************************************
* Update flashing cursor to match console_position
* Note: Does _NOT_ dictate the pos for next printed byte
********************************************************/
void console_update_cursor()
{
outb(0x3D4, 0x0F);
outb(0x3D5, ((console_pointer/2) & 0xFF));
outb(0x3D4, 0x0E);
outb(0x3D5, (((console_pointer/2)>>8)&0xFF));
}
/*********************************************************
* Clear the console with the current colour scheme
********************************************************/
void console_clear()
{
int console_pointer;
for (console_pointer = 0; console_pointer < 4000; console_pointer++)
{
console_buffer[console_pointer] = console_color;
console_buffer[console_pointer++] = 0;
}
//console_update_cursor();
}
/*********************************************************
* Set the console foreground and background colours
********************************************************/
void console_set_colors(uint8_t fg, uint8_t bg)
{
console_color = (bg << 4) | fg;
}
/*********************************************************
* Set the console foreground colour
********************************************************/
void console_set_color(uint8_t fg)
{
console_color &= 0xF0; // Zero-out foreground color
console_color |= fg; // Apply foreground color
}
/*********************************************************
* Print a null-terminated string to the text screen
********************************************************/
void console_print(char *string, ...)
{
uint16_t i;
for (i = 0; i < strlen(string); i++)
{
// If special char, handle appropriately
if (string[i] < 32)
{
switch (string[i])
case 10:
console_pointer = 160 + (console_pointer / 160) * 160;
} else {
console_buffer[console_pointer++] = string[i];
console_buffer[console_pointer++] = console_color;
}
}
console_update_cursor();
}
#endif
|