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