1 2 #include "kernel/kernel.h" 3 #include <minix/minlib.h> 4 #include <minix/const.h> 5 #include <minix/cpufeature.h> 6 #include <minix/type.h> 7 #include <minix/com.h> 8 #include <sys/types.h> 9 #include <sys/param.h> 10 #include <machine/partition.h> 11 #include "string.h" 12 #include "arch_proto.h" 13 #include "direct_utils.h" 14 #include "serial.h" 15 #include "glo.h" 16 #include <machine/multiboot.h> 17 18 /* Give non-zero values to avoid them in BSS */ 19 static int print_line = 1, print_col = 1; 20 21 #include <sys/video.h> 22 23 extern char *video_mem; 24 #define VIDOFFSET(line, col) ((line) * MULTIBOOT_CONSOLE_COLS * 2 + (col) * 2) 25 #define VIDSIZE VIDOFFSET(MULTIBOOT_CONSOLE_LINES-1,MULTIBOOT_CONSOLE_COLS-1) 26 27 void direct_put_char(char c, int line, int col) 28 { 29 int offset = VIDOFFSET(line, col); 30 video_mem[offset] = c; 31 video_mem[offset+1] = 0x07; /* grey-on-black */ 32 } 33 34 static char direct_get_char(int line, int col) 35 { 36 return video_mem[VIDOFFSET(line, col)]; 37 } 38 39 void direct_cls(void) 40 { 41 /* Clear screen */ 42 int i,j; 43 44 for(i = 0; i < MULTIBOOT_CONSOLE_COLS; i++) 45 for(j = 0; j < MULTIBOOT_CONSOLE_LINES; j++) 46 direct_put_char(' ', j, i); 47 48 print_line = print_col = 0; 49 50 /* Tell video hardware origin is 0. */ 51 outb(C_6845+INDEX, VID_ORG); 52 outb(C_6845+DATA, 0); 53 outb(C_6845+INDEX, VID_ORG+1); 54 outb(C_6845+DATA, 0); 55 } 56 57 static void direct_scroll_up(int lines) 58 { 59 int i, j; 60 for (i = 0; i < MULTIBOOT_CONSOLE_LINES; i++ ) { 61 for (j = 0; j < MULTIBOOT_CONSOLE_COLS; j++ ) { 62 char c = 0; 63 if(i < MULTIBOOT_CONSOLE_LINES-lines) 64 c = direct_get_char(i + lines, j); 65 direct_put_char(c, i, j); 66 } 67 } 68 print_line-= lines; 69 } 70 71 void direct_print_char(char c) 72 { 73 while (print_line >= MULTIBOOT_CONSOLE_LINES) 74 direct_scroll_up(1); 75 76 #define TABWIDTH 8 77 if(c == '\t') { 78 if(print_col >= MULTIBOOT_CONSOLE_COLS - TABWIDTH) { 79 c = '\n'; 80 } else { 81 do { 82 direct_put_char(' ', print_line, print_col++); 83 } while(print_col % TABWIDTH); 84 return; 85 } 86 } 87 88 if (c == '\n') { 89 while (print_col < MULTIBOOT_CONSOLE_COLS) 90 direct_put_char(' ', print_line, print_col++); 91 print_line++; 92 print_col = 0; 93 return; 94 } 95 96 direct_put_char(c, print_line, print_col++); 97 98 if (print_col >= MULTIBOOT_CONSOLE_COLS) { 99 print_line++; 100 print_col = 0; 101 } 102 103 while (print_line >= MULTIBOOT_CONSOLE_LINES) 104 direct_scroll_up(1); 105 } 106 107 void direct_print(const char *str) 108 { 109 while (*str) { 110 direct_print_char(*str); 111 str++; 112 } 113 } 114 115 /* Standard and AT keyboard. (PS/2 MCA implies AT throughout.) */ 116 #define KEYBD 0x60 /* I/O port for keyboard data */ 117 #define KB_STATUS 0x64 /* I/O port for status on AT */ 118 #define KB_OUT_FULL 0x01 /* status bit set when keypress char pending */ 119 #define KB_AUX_BYTE 0x20 /* Auxiliary Device Output Buffer Full */ 120 121 int direct_read_char(unsigned char *ch) 122 { 123 unsigned long sb; 124 125 sb = inb(KB_STATUS); 126 127 if (!(sb & KB_OUT_FULL)) { 128 return 0; 129 } 130 131 inb(KEYBD); 132 133 if (!(sb & KB_AUX_BYTE)) 134 return 1; 135 136 return 0; 137 } 138 139