git://scm.lunaixsky.com
/
lunaix-os.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
update readme
[lunaix-os.git]
/
lunaix-os
/
kernel
/
tty
/
tty.c
diff --git
a/lunaix-os/kernel/tty/tty.c
b/lunaix-os/kernel/tty/tty.c
index 2629c747f96b1dae44324895d09675ed18a315c4..325595edbef5db11f0780fc87a19c46df937cacc 100644
(file)
--- a/
lunaix-os/kernel/tty/tty.c
+++ b/
lunaix-os/kernel/tty/tty.c
@@
-1,21
+1,31
@@
#include <libc/string.h>
#include <lunaix/tty/tty.h>
#include <libc/string.h>
#include <lunaix/tty/tty.h>
+#include <lunaix/constants.h>
#include <stdint.h>
#define TTY_WIDTH 80
#define TTY_HEIGHT 25
#include <stdint.h>
#define TTY_WIDTH 80
#define TTY_HEIGHT 25
-vga_attribute*
buffer = (vga_attribute*)0xB8000
;
+vga_attribute*
tty_vga_buffer = (vga_attribute*)VGA_BUFFER_PADDR
;
-vga_attribute theme_color = VGA_COLOR_BLACK;
+vga_attribute t
ty_t
heme_color = VGA_COLOR_BLACK;
uint32_t tty_x = 0;
uint16_t tty_y = 0;
uint32_t tty_x = 0;
uint16_t tty_y = 0;
+void tty_init(void* vga_buf) {
+ tty_vga_buffer = (vga_attribute*)vga_buf;
+ tty_clear();
+}
+
+void tty_set_buffer(void* vga_buf) {
+ tty_vga_buffer = (vga_attribute*)vga_buf;
+}
+
void
tty_set_theme(vga_attribute fg, vga_attribute bg)
{
void
tty_set_theme(vga_attribute fg, vga_attribute bg)
{
- theme_color = (bg << 4 | fg) << 8;
+ t
ty_t
heme_color = (bg << 4 | fg) << 8;
}
void
}
void
@@
-27,11
+37,12
@@
tty_put_char(char chr)
break;
case '\n':
tty_y++;
break;
case '\n':
tty_y++;
+ // fall through
case '\r':
tty_x = 0;
break;
default:
case '\r':
tty_x = 0;
break;
default:
- *(
buffer + tty_x + tty_y * TTY_WIDTH) = (
theme_color | chr);
+ *(
tty_vga_buffer + tty_x + tty_y * TTY_WIDTH) = (tty_
theme_color | chr);
tty_x++;
break;
}
tty_x++;
break;
}
@@
-58,18
+69,18
@@
void
tty_scroll_up()
{
size_t last_line = TTY_WIDTH * (TTY_HEIGHT - 1);
tty_scroll_up()
{
size_t last_line = TTY_WIDTH * (TTY_HEIGHT - 1);
- memcpy(
buffer, buffer + TTY_WIDTH, last_line
);
+ memcpy(
tty_vga_buffer, tty_vga_buffer + TTY_WIDTH, last_line * 2
);
for (size_t i = 0; i < TTY_WIDTH; i++) {
for (size_t i = 0; i < TTY_WIDTH; i++) {
- *(
buffer + i + last_line) =
theme_color;
+ *(
tty_vga_buffer + i + last_line) = tty_
theme_color;
}
}
- tty_y = tty_y == 0 ? 0 :
tty_y
- 1;
+ tty_y = tty_y == 0 ? 0 :
TTY_HEIGHT
- 1;
}
void
tty_clear()
{
for (uint32_t i = 0; i < TTY_WIDTH * TTY_HEIGHT; i++) {
}
void
tty_clear()
{
for (uint32_t i = 0; i < TTY_WIDTH * TTY_HEIGHT; i++) {
- *(
buffer + i) =
theme_color;
+ *(
tty_vga_buffer + i) = tty_
theme_color;
}
tty_x = 0;
tty_y = 0;
}
tty_x = 0;
tty_y = 0;