Port the SB128 code to AROS.
[AROS.git] / rom / kernel / displayalert.c
blobdda63b1079ddc9b94625665291fc42523a7e8e4a
1 #include <aros/kernel.h>
2 #include <aros/libcall.h>
4 #include <kernel_base.h>
5 #include <kernel_debug.h>
7 #define ALERT_WIDTH 80
9 static inline void PrintChars(char c, ULONG n, struct KernelBase *KernelBase)
11 while (n--)
12 krnPutC(c, KernelBase);
16 * This function calculates length of line.
17 * It's similar to strlen(), but stops also at LF and FF codes.
19 static inline int linelen(const char *str)
21 int l;
23 for (l = 0; str[l] && str[l] != '\n' && str[l] != 0x0F; l++);
24 return l;
27 static const char *PrintCentered(const char *str, struct KernelBase *KernelBase)
29 int len = linelen(str);
30 int i;
31 ULONG s;
33 if (len > (ALERT_WIDTH - 2))
34 len = (ALERT_WIDTH - 2);
36 s = ALERT_WIDTH - 2 - len;
38 krnPutC('#', KernelBase);
39 if (s & 1)
40 krnPutC(' ', KernelBase);
41 s >>= 1;
42 PrintChars(' ', s, KernelBase);
44 for (i = 0; i < len; i++)
45 krnPutC(*str++, KernelBase);
47 PrintChars(' ', s, KernelBase);
48 krnPutC('#', KernelBase);
49 krnPutC('\n', KernelBase);
51 return str;
54 static inline void PrintFrame(struct KernelBase *KernelBase)
56 PrintChars('#', ALERT_WIDTH, KernelBase);
57 krnPutC('\n', KernelBase);
60 /*****************************************************************************
62 NAME */
63 #include <proto/kernel.h>
65 AROS_LH2(void, KrnDisplayAlert,
67 /* SYNOPSIS */
68 AROS_LHA(uint32_t, code, D0),
69 AROS_LHA(const char *, text, A0),
71 /* LOCATION */
72 struct KernelBase *, KernelBase, 35, Kernel)
74 /* FUNCTION
75 Inform the user about critical system failure.
77 INPUTS
78 code - Corresponding alert code.
79 text - A NULL-terminated text to print out.
81 First three lines are assumed to be a header. Some implementations
82 may print them centered inside a frame.
84 RESULT
85 None. This function is not guaranteed to return.
87 NOTES
88 This function exists for system internal purposes. Please do not
89 call it from within regular applications! In 99% of cases this function
90 will halt or reboot the machine. Certain structures in RAM, as well as
91 video hardware state, will be irreversibly destroyed.
93 'code' parameter is passed for convenience. Based on it, the system
94 can make a decision to log the alert in debug output and continue,
95 instead of displaying a message and halting.
97 This function is currently experimental. Its definition may change.
99 EXAMPLE
101 BUGS
103 SEE ALSO
105 INTERNALS
107 ******************************************************************************/
109 AROS_LIBFUNC_INIT
112 * This is a generic version that simply formats the text into debug log.
113 * It can be replaced with machine-specific implementation which can do more.
115 unsigned int i;
117 /* Make sure that the output starts from a new line */
118 krnPutC('\n', KernelBase);
120 PrintFrame(KernelBase);
122 /* Print first three lines (title, task and error) centered */
123 for (i = 0; i < 3; i++)
125 text = PrintCentered(text, KernelBase);
126 text++; /* Skip a newline */
129 PrintFrame(KernelBase);
131 /* Print the rest of alert text */
132 while (*text)
133 krnPutC(*text++, KernelBase);
135 krnPutC('\n', KernelBase);
136 PrintFrame(KernelBase);
138 AROS_LIBFUNC_EXIT