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