tools/llvm: Do not build with symbols
[minix3.git] / minix / kernel / arch / i386 / direct_tty_utils.c
blobeb8364bc9f70682cfe83e03c3bac0d508fc4c2f7
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>
18 /* Give non-zero values to avoid them in BSS */
19 static int print_line = 1, print_col = 1;
21 #include <sys/video.h>
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)
27 void direct_put_char(char c, int line, int col)
29 int offset = VIDOFFSET(line, col);
30 video_mem[offset] = c;
31 video_mem[offset+1] = 0x07; /* grey-on-black */
34 static char direct_get_char(int line, int col)
36 return video_mem[VIDOFFSET(line, col)];
39 void direct_cls(void)
41 /* Clear screen */
42 int i,j;
44 for(i = 0; i < MULTIBOOT_CONSOLE_COLS; i++)
45 for(j = 0; j < MULTIBOOT_CONSOLE_LINES; j++)
46 direct_put_char(' ', j, i);
48 print_line = print_col = 0;
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);
57 static void direct_scroll_up(int lines)
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);
68 print_line-= lines;
71 void direct_print_char(char c)
73 while (print_line >= MULTIBOOT_CONSOLE_LINES)
74 direct_scroll_up(1);
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;
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;
96 direct_put_char(c, print_line, print_col++);
98 if (print_col >= MULTIBOOT_CONSOLE_COLS) {
99 print_line++;
100 print_col = 0;
103 while (print_line >= MULTIBOOT_CONSOLE_LINES)
104 direct_scroll_up(1);
107 void direct_print(const char *str)
109 while (*str) {
110 direct_print_char(*str);
111 str++;
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 */
121 int direct_read_char(unsigned char *ch)
123 unsigned long sb;
125 sb = inb(KB_STATUS);
127 if (!(sb & KB_OUT_FULL)) {
128 return 0;
131 inb(KEYBD);
133 if (!(sb & KB_AUX_BYTE))
134 return 1;
136 return 0;