2 meinOS - A unix-like x86 microkernel operating system
3 Copyright (C) 2008 Janosch Gräf <janosch.graef@gmx.net>
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 3 of the License, or
8 (at your option) any later version.
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.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
29 vga_text_video
= (vga_text_char_t
*)VGA_TEXT_ADDRESS
;
30 vga_text_set_hwcursor(0,VGA_TEXT_HEIGHT
+1);
35 * Clears VGA text screen
37 void vga_text_clear() {
38 vga_text_cursor
.x
= 0;
39 vga_text_cursor
.y
= 0;
40 vga_text_cursor
.color
= VGA_TEXT_COLOR_DEFAULT
;
41 // trick: just set whole screen with bg color as bg and front color
42 memset(vga_text_video
,(vga_text_cursor
.color
&0xF0)|(vga_text_cursor
.color
>>4),VGA_TEXT_SIZE
);
46 * Moves VGA text hardware cursor
47 * @param x New X position
48 * @param y New Y position
50 void vga_text_set_hwcursor(int x
,int y
) {
51 int off
= y
*VGA_TEXT_WIDTH
+x
;
60 * Set color of next chars
63 void vga_text_setcolor(vga_text_color_t color
) {
64 vga_text_cursor
.color
= color
;
68 * Prints character to VGA text screen
70 void vga_text_printchar(char chr
) {
71 if (chr
=='\b') vga_text_cursor
.x
= vga_text_cursor
.x
>0?vga_text_cursor
.x
-1:vga_text_cursor
.x
;
72 else if (chr
=='\r') vga_text_cursor
.x
= 0;
75 vga_text_cursor
.x
= 0;
77 else if (chr
=='\f') vga_text_clear();
78 else if (chr
=='\t') vga_text_cursor
.x
= vga_text_cursor
.x
= vga_text_cursor
.x
>0?(vga_text_cursor
.x
/VGA_TEXT_TABSIZE
+1)*VGA_TEXT_TABSIZE
:0;
79 else if (isprint(chr
)) {
80 int off
= vga_text_cursor
.x
+vga_text_cursor
.y
*VGA_TEXT_WIDTH
;
81 if (off
==0x3FD) asm("hlt"::"a"(0xD00FC0DE));
82 vga_text_video
[off
].chr
= chr
;
83 vga_text_video
[off
].attr
= vga_text_cursor
.color
;
90 if (vga_text_cursor
.x
>=VGA_TEXT_WIDTH
) {
91 vga_text_cursor
.x
= 0;
94 if (vga_text_cursor
.y
>=VGA_TEXT_HEIGHT
) {
95 memmove(vga_text_video
,vga_text_video
+VGA_TEXT_WIDTH
,VGA_TEXT_WIDTH
*(VGA_TEXT_HEIGHT
-1)*VGA_TEXT_BPC
);
96 memset(vga_text_video
+VGA_TEXT_WIDTH
*(VGA_TEXT_HEIGHT
-1),(vga_text_cursor
.color
&0xF0)|(vga_text_cursor
.color
>>4),VGA_TEXT_WIDTH
*VGA_TEXT_BPC
);
97 vga_text_cursor
.y
= VGA_TEXT_HEIGHT
-1;
102 #define COM_PORT 0x3f8 /* COM1 */
103 #define BAUDRATE 9600
105 int baud
= 115200/BAUDRATE
;
107 outb(COM_PORT
+1,0x00); // no interrupts
108 outb(COM_PORT
+3,0x80); // dlab
109 outb(COM_PORT
+0,baud
); // Baudrate (low)
110 outb(COM_PORT
+1,baud
>>8); // Baudrate (high)
111 outb(COM_PORT
+3,0x03); // 8 Bits, 1 stopbit
112 outb(COM_PORT
+2,0xC7);
113 outb(COM_PORT
+4,0x0B);
115 int is_transmit_empty() {
116 return inb(COM_PORT
+5)&0x20;
118 void com_send(char a
) {
119 while (!is_transmit_empty());
123 #define BOCHS_PORT 0xE9
124 void bochs_send(char a
) {