add a missing section header table index conversion
[tangerine.git] / arch / x86_64-pc / bootstrap / screen.c
blob4593201e8c73fba676b7d6cc9fde1e2e253c5208
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: screen support functions ripped from the 32-bit native target.
6 */
8 #undef __save_flags
9 #undef __restore_flags
10 #undef __cli
11 #undef __sti
13 #define __save_flags(x) __asm__ __volatile__("pushfl ; popl %0":"=g" (x): /* no input */)
14 #define __restore_flags(x) __asm__ __volatile__("pushl %0 ; popfl": /* no output */ :"g" (x):"memory", "cc")
15 #define __cli() __asm__ __volatile__("cli": : :"memory")
16 #define __sti() __asm__ __volatile__("sti": : :"memory")
18 static int x,y, dead;
20 struct scr
22 unsigned char sign;
23 unsigned char attr;
26 static struct scr *view = (struct scr *)0xb8000;
28 void clr()
30 unsigned long flags;
31 int i;
33 __save_flags(flags);
34 __cli();
36 if (!dead) for (i=0; i<80*25; i++)
38 view[i].sign = ' ';
39 view[i].attr = 7;
41 x=0;
42 y=0;
44 __restore_flags(flags);
47 void Putc(char chr)
49 unsigned long flags;
51 __save_flags(flags);
52 __cli();
53 if (chr == 3) /* die / CTRL-C / "signal" */
55 dead = 1;
57 else if (!dead)
59 asm volatile ("out %b0,%w1"::"a"(chr),"Nd"(0x3f8));
60 if (chr)
62 if (chr == 10)
64 x = 0;
65 y++;
67 else
69 int i = 80*y+x;
70 view[i].sign = chr;
71 x++;
72 if (x == 80)
74 x = 0;
75 y++;
79 if (y>24)
81 int i;
82 y=24;
84 for (i=0; i<80*24; i++)
85 view[i].sign = view[i+80].sign;
86 for (i=80*24; i<80*25; i++)
87 view[i].sign = ' ';
90 __restore_flags(flags);
93 /* Convert the integer D to a string and save the string in BUF. If
94 BASE is equal to 'd', interpret that D is decimal, and if BASE is
95 equal to 'x', interpret that D is hexadecimal. */
96 static void __itoa (char *buf, int base, int d)
98 char *p = buf;
99 char *p1, *p2;
100 unsigned long ud = d;
101 int divisor = 10;
103 /* If %d is specified and D is minus, put `-' in the head. */
104 if (base == 'd' && d < 0)
106 *p++ = '-';
107 buf++;
108 ud = -d;
110 else if (base == 'x')
111 divisor = 16;
112 else if (base == 'p')
114 int i;
115 for (i=0; i<8; i++)
117 char v = (d >> (28-i*4)) & 0xf;
118 *p++ = (v < 10) ? v + '0' : v + 'A' - 10;
120 *p=0;
121 return;
124 /* Divide UD by DIVISOR until UD == 0. */
127 int remainder = ud % divisor;
129 *p++ = (remainder < 10) ? remainder + '0' : remainder + 'a' - 10;
131 while (ud /= divisor);
133 /* Terminate BUF. */
134 *p = 0;
136 /* Reverse BUF. */
137 p1 = buf;
138 p2 = p - 1;
139 while (p1 < p2)
141 char tmp = *p1;
142 *p1 = *p2;
143 *p2 = tmp;
144 p1++;
145 p2--;
149 void kprintf(const char *format, ...)
151 unsigned long *ptr = (unsigned long *)&format + 1;
152 int c;
153 char buf[20];
155 while ((c = *format++) != 0)
157 if (c != '%')
158 Putc(c);
159 else
161 char *p;
163 c = *format++;
164 switch (c)
166 case 'd':
167 case 'u':
168 case 'x':
169 case 'p':
170 __itoa (buf, c, (int)*ptr++);
171 p = buf;
172 goto string;
173 break;
175 case 's':
176 p = (char*)*ptr++;
177 if (! p)
178 p = "(null)";
180 string:
181 while (*p)
182 Putc(*p++);
183 break;
185 default:
186 Putc((char)*ptr++);
187 break;