Remove building with NOCRYPTO option
[minix3.git] / minix / kernel / arch / i386 / direct_tty_utils.c
blob5c577c26d69bf75a5f49378cdab733dd0d95d00f
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"
10 /* Give non-zero values to avoid them in BSS */
11 static int print_line = 1, print_col = 1;
13 #include <sys/video.h>
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)
19 void direct_put_char(char c, int line, int col)
21 int offset = VIDOFFSET(line, col);
22 video_mem[offset] = c;
23 video_mem[offset+1] = 0x07; /* grey-on-black */
26 static char direct_get_char(int line, int col)
28 return video_mem[VIDOFFSET(line, col)];
31 void direct_cls(void)
33 /* Clear screen */
34 int i,j;
36 for(i = 0; i < MULTIBOOT_CONSOLE_COLS; i++)
37 for(j = 0; j < MULTIBOOT_CONSOLE_LINES; j++)
38 direct_put_char(' ', j, i);
40 print_line = print_col = 0;
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);
49 static void direct_scroll_up(int lines)
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);
60 print_line-= lines;
63 void direct_print_char(char c)
65 while (print_line >= MULTIBOOT_CONSOLE_LINES)
66 direct_scroll_up(1);
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;
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;
88 direct_put_char(c, print_line, print_col++);
90 if (print_col >= MULTIBOOT_CONSOLE_COLS) {
91 print_line++;
92 print_col = 0;
95 while (print_line >= MULTIBOOT_CONSOLE_LINES)
96 direct_scroll_up(1);
99 void direct_print(const char *str)
101 while (*str) {
102 direct_print_char(*str);
103 str++;
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 */
113 int direct_read_char(unsigned char *ch)
115 unsigned long sb;
117 sb = inb(KB_STATUS);
119 if (!(sb & KB_OUT_FULL)) {
120 return 0;
123 inb(KEYBD);
125 if (!(sb & KB_AUX_BYTE))
126 return 1;
128 return 0;