add sdcard to raspi BE kernel
[AROS.git] / rom / kernel / _displayalert.c
blob49e822ae485b6185e86a5e10b2dc7d9d6e2c1c09
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 */
8 #include <kernel_base.h>
9 #include <kernel_debug.h>
11 #define ALERT_WIDTH 80
13 static inline void PrintChars(char c, ULONG n, struct KernelBase *KernelBase)
15 while (n--)
16 krnPutC(c, KernelBase);
20 * This function calculates length of line.
21 * It's similar to strlen(), but stops also at LF and FF codes.
23 static inline int linelen(const char *str)
25 int l;
27 for (l = 0; str[l] && str[l] != '\n' && str[l] != 0x0F; l++);
28 return l;
31 static const char *PrintCentered(const char *str, struct KernelBase *KernelBase)
33 int len = linelen(str);
34 int i;
35 ULONG s;
37 if (len > (ALERT_WIDTH - 2))
38 len = (ALERT_WIDTH - 2);
40 s = ALERT_WIDTH - 2 - len;
42 krnPutC('#', KernelBase);
43 if (s & 1)
44 krnPutC(' ', KernelBase);
45 s >>= 1;
46 PrintChars(' ', s, KernelBase);
48 for (i = 0; i < len; i++)
49 krnPutC(*str++, KernelBase);
51 PrintChars(' ', s, KernelBase);
52 krnPutC('#', KernelBase);
53 krnPutC('\n', KernelBase);
55 return str;
58 static inline void PrintFrame(struct KernelBase *KernelBase)
60 PrintChars('#', ALERT_WIDTH, KernelBase);
61 krnPutC('\n', KernelBase);
65 * This entry point just displays the message. It doesn't make any decisions
66 * what to do next.
67 * Because of this it misses 'code' argument.
68 * The kernel can use it internally, for displaying messages about
69 * critical startup failures.
71 void krnDisplayAlert(const char *text, struct KernelBase *KernelBase)
73 unsigned int i;
75 /* Make sure that the output starts from a new line */
76 krnPutC('\n', KernelBase);
78 PrintFrame(KernelBase);
80 /* Print first three lines (title, task and error) centered */
81 for (i = 0; i < 3; i++)
83 text = PrintCentered(text, KernelBase);
85 if (*text == 0) /* Handle early NULL terminator */
86 break;
88 text++; /* Skip a newline */
91 PrintFrame(KernelBase);
93 /* Print the rest of alert text (if any) */
94 if (*text)
96 while (*text)
97 krnPutC(*text++, KernelBase);
99 krnPutC('\n', KernelBase);
100 PrintFrame(KernelBase);