aboutsummaryrefslogtreecommitdiff
path: root/devices/vga.c
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2022-11-08 17:19:45 +0200
committeraqua <aqua@iserlohn-fortress.net>2022-11-08 17:54:13 +0200
commitdbdaa77fb5924b4b9e6b374a44ef76481a38d3d2 (patch)
treeabd4daf428532ac026a538e20138907b36c795c3 /devices/vga.c
parentAdd python-sphinx docs (diff)
downloadkernel-dbdaa77fb5924b4b9e6b374a44ef76481a38d3d2.tar.xz
Add FILE struct
Diffstat (limited to 'devices/vga.c')
-rw-r--r--devices/vga.c78
1 files changed, 49 insertions, 29 deletions
diff --git a/devices/vga.c b/devices/vga.c
index 39370ba..12ac880 100644
--- a/devices/vga.c
+++ b/devices/vga.c
@@ -55,31 +55,9 @@ vga_update_cursor()
outb((pos >> 8) & 0xff, cga_dat_port);
}
-// *** Text Mode ***
-void
-vga_init()
-{
- buffer = (struct VGAEntry *)0xc03ff000;
- vga_enable_cursor(14, 15);
- vga_clear(VGA_COLOR_LIGHT_BLUE, VGA_COLOR_LIGHT_GREY);
-}
-
-void
-vga_clear(enum vga_color foreground, enum vga_color background)
-{
- for (int y = 0; y < height; ++y)
- for (int x = 0; x < width; ++x) {
- const int index = y * width + x;
- buffer[index].text = ' ';
- buffer[index].foreground = foreground;
- buffer[index].background = background;
- }
- col = row = 0;
- vga_update_cursor();
-}
-
+// *** Text Mode Output ***
void
-vga_putc(char a)
+vga_putc(const FILE *self, char a)
{
switch (a) {
case '\n':
@@ -117,16 +95,58 @@ vga_putc(char a)
}
}
-void
-vga_puts(const char *string, int len)
+int
+vga_puts(const FILE *self, const char *string, int len)
{
-
+ int written = 0;
if (len == -1)
while (*string != '\0') {
- vga_putc(*string);
+ vga_putc(self, *string);
++string;
+ ++written;
}
else
- for (int i = 0; i < len; ++i) { vga_putc(string[i]); }
+ for (int i = 0; i < len; ++i) {
+ vga_putc(self, string[i]);
+ ++written;
+ }
+ return written;
+}
+
+void
+vga_flush(const FILE *self)
+{
+ vga_update_cursor();
+}
+
+// *** Text Mode ***
+FILE vga_stream;
+
+FILE *
+vga_init()
+{
+ buffer = (struct VGAEntry *)0xc03ff000;
+ vga_enable_cursor(14, 15);
+ vga_clear(VGA_COLOR_LIGHT_BLUE, VGA_COLOR_LIGHT_GREY);
+
+ vga_stream.id = 0;
+ vga_stream.putc = &vga_putc;
+ vga_stream.puts = &vga_puts;
+ vga_stream.flush = &vga_flush;
+ return &vga_stream;
+}
+
+void
+vga_clear(enum vga_color foreground, enum vga_color background)
+{
+ for (int y = 0; y < height; ++y)
+ for (int x = 0; x < width; ++x) {
+ const int index = y * width + x;
+ buffer[index].text = ' ';
+ buffer[index].foreground = foreground;
+ buffer[index].background = background;
+ }
+ col = row = 0;
+ vga_update_cursor();
}