Many changes:
[Marmot.git] / panic.c
blobeb7980f7cf2b54428fa03a0cabd2a1c72e3fdabc
1 /*
2 * panic.c --
4 * Panic - print a message to the screen and bail.
5 */
7 #include <marmot.h>
9 static char *types[] = {
10 "Assertion failed:",
11 "Unimplemented feature:",
12 "Miscellaneous failure:"
17 * formatDec --
19 * Limited decimal number formatter that only handles unsigned
20 * numbers less than 10,000,000.
23 void
24 formatDec(char s[], uint64 n)
26 uint64 p, k;
28 if (n >= 10000000) {
29 return;
32 for (p = 0; n; p++) {
33 s[p] = '0' + n % 10;
34 n /= 10;
37 for (k = 0; k < p / 2; k++) {
38 char c;
39 c = s[k];
40 s[k] = s[p - k - 1];
41 s[p - k - 1] = c;
45 void
46 Bug(uint64 type, char *cond, char *file, uint64 line)
48 Point p0, p1;
49 uint64 maxStr = ((uint64)xResolution - 8) / 8;
50 char lineStr[] = {'L', 'i', 'n', 'e', ':', ' ', 0, 0, 0, 0, 0, 0, 0, 0};
53 * Bug message looks like:
55 * Type message:
56 * cond
57 * file
58 * Line line
60 * Type message can be:
62 * BUG_ASSERT Assertion failed
63 * BUG_UNIMPL Unimplemented feature
64 * BUG_MISC Miscellaneous failure
68 p0.x = 0;
69 p0.y = 0;
70 p1.x = 1280;
71 p1.y = 4 * 16 + 5 * 4;
72 ColorRectangle(COLOR_RED, p0, p1);
74 p0.x = 4;
75 p0.y = 4;
76 PrintMessage(COLOR_BLACK, p0, types[type]);
78 p0.y += 20;
79 if (strlen(cond) > maxStr) {
80 cond[maxStr - 1] = '\0';
82 PrintMessage(COLOR_BLACK, p0, cond);
84 p0.y += 20;
85 if (strlen(file) > maxStr) {
86 file[maxStr - 1] = '\0';
88 PrintMessage(COLOR_BLACK, p0, file);
90 p0.y += 20;
91 formatDec(lineStr + 6, line);
92 PrintMessage(COLOR_BLACK, p0, lineStr);
94 cli();
95 asm("hlt");