diff cos/kernel/video.c @ 24:d8627924d40d

Split up in more files and reboot command
author windel
date Fri, 02 Dec 2011 14:00:02 +0100
parents 5dd47d6eebac
children
line wrap: on
line diff
--- a/cos/kernel/video.c	Thu Dec 01 21:42:59 2011 +0100
+++ b/cos/kernel/video.c	Fri Dec 02 14:00:02 2011 +0100
@@ -18,8 +18,25 @@
    outb(0x3D5, cursorLocation & 0xFF);
 }
 
-void
-clear_screen()
+void set_cursor(int newrow, int newcol)
+{
+   row = newrow;
+   col = newcol;
+   move_cursor();
+}
+
+void get_cursor(int *therow, int *thecol)
+{
+   *therow = row;
+   *thecol = col;
+}
+
+void set_color(int forecolor, int backcolor)
+{
+   video_color = forecolor | (backcolor << 4);
+}
+
+void clear_screen()
 {
 	unsigned char *vidmem = (unsigned char *) VIDMEM;
 	int loop;
@@ -30,45 +47,48 @@
 	}
 }
 
-void
-init_screen()
+void init_screen()
 {
-	row = col = 0;
 	clear_screen();
-   move_cursor();
+   set_cursor(0, 0);
 }
 
-
-static void
-scroll_screen()
+static void scroll_screen()
 {
-	unsigned short* v;
+	uint8_t* v;
 	int i;
-	int n = SCREEN_SIZE;
 	
-	for (v = (unsigned short*) VIDMEM, i = 0; i < n; i++ ) {
-		*v = *(v + NUM_COLS);
+   // Shift all lines one up:
+	v = (uint8_t*)VIDMEM;
+	for (i = 0; i < SCREEN_SIZE; i++ )
+   {
+		*v = *(v + NUM_COLS*2);
+		++v;
+		*v = *(v + NUM_COLS*2);
 		++v;
 	}
 
-	for (v = (unsigned short*) VIDMEM + n, i = 0; i < NUM_COLS; i++) {
-		*v++ = (video_color << 8) & 0x20;
+   // Clear new line:
+   v = (uint8_t*)VIDMEM + SCREEN_SIZE * 2 - NUM_COLS * 2;
+	for (i = 0; i < NUM_COLS; i++) 
+   {
+      *v++ = ' ';
+		*v++ = video_color;
 	}
 }
 
-static void
-new_line()
+static void new_line()
 {
 	++row;
 	col = 0;
-	if (row == NUM_ROWS) {
+	if (row == NUM_ROWS) 
+   {
 		scroll_screen();
 		row = NUM_ROWS - 1;
 	}
 }
 
-static void
-clear_to_EOL()
+static void clear_to_EOL()
 {
 	int loop;
 	unsigned char *v = (unsigned char *) ((uint64_t)(VIDMEM + row * NUM_COLS * 2 + col * 2));
@@ -79,8 +99,7 @@
 	}
 }
 
-static void
-print_char(int c)
+static void print_char(int c)
 {
 	unsigned char *v = (unsigned char *) ((uint64_t)(VIDMEM + row * NUM_COLS * 2 + col * 2));
 
@@ -101,10 +120,10 @@
    move_cursor();
 }
 
-void
-print_string(const char *s)
+void print_string(const char *s)
 {
-	while (*s != '\0') {
+	while (*s != '\0') 
+   {
 		print_char(*s++);
 	}
 }