Forgotten commit. Added automount.
[AROS.git] / arch / all-pc / kernel / _displayalert.c
blob3062129cb9ce9b3499b20da8a534c881eebc559a
1 #include <bootconsole.h>
2 #include <inttypes.h>
4 #include <kernel_base.h>
5 #include <kernel_debug.h>
6 #include "alert_arch.h"
8 /*
9 * Display alert on the screen using libbootconsole.
10 * Very useful for early alerts, while the display driver not started yet.
11 * In this case the user gets a nice GURU. Not painted in red yet. :)
14 static inline void PrintChars(char c, ULONG n, struct KernelBase *KernelBase)
16 while (n--)
17 krnPutC(c, KernelBase);
21 * This function calculates length of line.
22 * It's similar to strlen(), but stops also at LF and FF codes.
24 static inline int linelen(const char *str)
26 int l;
28 for (l = 0; str[l] && str[l] != '\n' && str[l] != 0x0F; l++);
29 return l;
32 static const char *PrintCentered(const char *str, struct KernelBase *KernelBase)
34 int len = linelen(str);
35 int i;
36 ULONG s;
38 if (len > (scr_Width - 2))
39 len = (scr_Width - 2);
41 s = scr_Width - 2 - len;
43 krnPutC(0xDB, KernelBase);
44 if (s & 1)
45 krnPutC(' ', KernelBase);
46 s >>= 1;
47 PrintChars(' ', s, KernelBase);
49 for (i = 0; i < len; i++)
50 krnPutC(*str++, KernelBase);
52 PrintChars(' ', s, KernelBase);
53 krnPutC(0xDB, KernelBase);
54 krnPutC('\n', KernelBase);
56 return str;
59 static inline void PrintFrame(char c, struct KernelBase *KernelBase)
61 krnPutC(0xDB, KernelBase);
62 PrintChars(c, scr_Width - 2, KernelBase);
63 krnPutC(0xDB, KernelBase);
64 krnPutC('\n', KernelBase);
67 void krnDisplayAlert(const char *text, struct KernelBase *KernelBase)
69 unsigned int i;
71 if (scr_Type == SCR_UNKNOWN)
73 /* Default alert width (for possible serial output). */
74 scr_Width = 80;
77 /* Make sure that the output starts from a new line */
78 krnPutC('\n', KernelBase);
80 PrintFrame(0xDF, KernelBase);
82 /* Print first three lines (title, task and error) centered */
83 for (i = 0; i < 3; i++)
85 text = PrintCentered(text, KernelBase);
86 if (*text == 0) /* Handle early NULL terminator */
87 break;
88 text++; /* Skip a newline */
91 PrintFrame(0xDC, KernelBase);
93 /* Print the rest of alert text (if any) */
94 if (*text)
96 PrintString(text, KernelBase);
98 /* Print a line in the bottom */
99 krnPutC('\n', KernelBase);
100 PrintChars(0xDC, scr_Width, KernelBase);
101 krnPutC('\n', KernelBase);