|
@@ -81,7 +81,7 @@ void update_cursor(void) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-__uint64_t printf(const char *s, ...) {
|
|
|
|
|
|
|
+__uint64_t printf(char color, const char *s, ...) {
|
|
|
/* l: character puts (no '%') */
|
|
/* l: character puts (no '%') */
|
|
|
__uint64_t i, l;
|
|
__uint64_t i, l;
|
|
|
/* if prev character is '%', state = '%' */
|
|
/* if prev character is '%', state = '%' */
|
|
@@ -96,8 +96,8 @@ __uint64_t printf(const char *s, ...) {
|
|
|
state = 0;
|
|
state = 0;
|
|
|
newlines = 0;
|
|
newlines = 0;
|
|
|
|
|
|
|
|
- /* argno = 2 because first argument is 's' */
|
|
|
|
|
- for (i = 0, l = 0, argno = 2; s[i]; i++) {
|
|
|
|
|
|
|
+ /* argno = 3 because first argument is 's' */
|
|
|
|
|
+ for (i = 0, l = 0, argno = 3; s[i]; i++) {
|
|
|
c = s[i];
|
|
c = s[i];
|
|
|
/* check state */
|
|
/* check state */
|
|
|
if (!state) {
|
|
if (!state) {
|
|
@@ -115,7 +115,7 @@ __uint64_t printf(const char *s, ...) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
else {
|
|
|
- putc(c);
|
|
|
|
|
|
|
+ putc(c, color);
|
|
|
l++;
|
|
l++;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -126,42 +126,42 @@ __uint64_t printf(const char *s, ...) {
|
|
|
/* it's a formater */
|
|
/* it's a formater */
|
|
|
else {
|
|
else {
|
|
|
if (c == 'd') {
|
|
if (c == 'd') {
|
|
|
- l += printint((int) get_arg(int, argno), 10, 1);
|
|
|
|
|
|
|
+ l += printint((int) get_arg(int, argno), 10, 1, color);
|
|
|
argno++;
|
|
argno++;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
else if (c == 'x') {
|
|
else if (c == 'x') {
|
|
|
/* `x` is 64-bits, I think it's */
|
|
/* `x` is 64-bits, I think it's */
|
|
|
- l += printint((long) get_arg(long, argno), 16, 0);
|
|
|
|
|
|
|
+ l += printint((long) get_arg(long, argno), 16, 0, color);
|
|
|
argno++;
|
|
argno++;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
else if (c == 'p') {
|
|
else if (c == 'p') {
|
|
|
/* zeros at high bits should display, not like `%x` or `%d` */
|
|
/* zeros at high bits should display, not like `%x` or `%d` */
|
|
|
- l += printptr((__uint64_t) get_arg(__uint64_t, argno), 16);
|
|
|
|
|
|
|
+ l += printptr((__uint64_t) get_arg(__uint64_t, argno), 16, color);
|
|
|
argno++;
|
|
argno++;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
/* put a byte */
|
|
/* put a byte */
|
|
|
else if (c == 'b') {
|
|
else if (c == 'b') {
|
|
|
- l += printptr((__uint64_t) get_arg(__uint32_t, argno), 2);
|
|
|
|
|
|
|
+ l += printptr((__uint64_t) get_arg(__uint32_t, argno), 2, color);
|
|
|
argno++;
|
|
argno++;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* put a word */
|
|
/* put a word */
|
|
|
else if (c == 'w') {
|
|
else if (c == 'w') {
|
|
|
- l += printptr((__uint64_t) get_arg(__uint32_t, argno), 4);
|
|
|
|
|
|
|
+ l += printptr((__uint64_t) get_arg(__uint32_t, argno), 4, color);
|
|
|
argno++;
|
|
argno++;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
else if (c == 'l') {
|
|
else if (c == 'l') {
|
|
|
- l += printptr((__uint64_t) get_arg(__uint32_t, argno), 8);
|
|
|
|
|
|
|
+ l += printptr((__uint64_t) get_arg(__uint32_t, argno), 8, color);
|
|
|
argno++;
|
|
argno++;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
else if (c == 'q') {
|
|
else if (c == 'q') {
|
|
|
- l += printptr((__uint64_t) get_arg(__uint64_t, argno), 16);
|
|
|
|
|
|
|
+ l += printptr((__uint64_t) get_arg(__uint64_t, argno), 16, color);
|
|
|
argno++;
|
|
argno++;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -176,7 +176,7 @@ __uint64_t printf(const char *s, ...) {
|
|
|
|
|
|
|
|
/* put while end of fmt_s */
|
|
/* put while end of fmt_s */
|
|
|
while (*fmt_s) {
|
|
while (*fmt_s) {
|
|
|
- putc(*fmt_s);
|
|
|
|
|
|
|
+ putc(*fmt_s, color);
|
|
|
fmt_s++;
|
|
fmt_s++;
|
|
|
l++;
|
|
l++;
|
|
|
}
|
|
}
|
|
@@ -184,21 +184,21 @@ __uint64_t printf(const char *s, ...) {
|
|
|
|
|
|
|
|
else if (c == 'c') {
|
|
else if (c == 'c') {
|
|
|
/* `char` aligned to `int` in GCC */
|
|
/* `char` aligned to `int` in GCC */
|
|
|
- putc((char) get_arg(int, argno));
|
|
|
|
|
|
|
+ putc((char) get_arg(int, argno), color);
|
|
|
argno++;
|
|
argno++;
|
|
|
l++;
|
|
l++;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
else if (c == '%') {
|
|
else if (c == '%') {
|
|
|
/* put % on screen */
|
|
/* put % on screen */
|
|
|
- putc(c);
|
|
|
|
|
|
|
+ putc(c, color);
|
|
|
l++;
|
|
l++;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
else {
|
|
|
/* don't forget to put % */
|
|
/* don't forget to put % */
|
|
|
- putc('%');
|
|
|
|
|
- putc(c);
|
|
|
|
|
|
|
+ putc('%', color);
|
|
|
|
|
+ putc(c, color);
|
|
|
l++;
|
|
l++;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -232,11 +232,8 @@ __uint64_t printf(const char *s, ...) {
|
|
|
|
|
|
|
|
static char digits[] = {"0123456789abcdef"};
|
|
static char digits[] = {"0123456789abcdef"};
|
|
|
|
|
|
|
|
-int printk(char txt){
|
|
|
|
|
- printint(txt);
|
|
|
|
|
- return 0
|
|
|
|
|
-}
|
|
|
|
|
-__uint64_t printint(long n, int base, int sign) {
|
|
|
|
|
|
|
+
|
|
|
|
|
+__uint64_t printint(long n, int base, int sign, char color) {
|
|
|
char buf[32];
|
|
char buf[32];
|
|
|
/* neg: x < 0 && signed interger */
|
|
/* neg: x < 0 && signed interger */
|
|
|
int i, neg, j;
|
|
int i, neg, j;
|
|
@@ -265,7 +262,7 @@ __uint64_t printint(long n, int base, int sign) {
|
|
|
|
|
|
|
|
j = i;
|
|
j = i;
|
|
|
while (--j >= 0)
|
|
while (--j >= 0)
|
|
|
- putc(buf[j]);
|
|
|
|
|
|
|
+ putc(buf[j], color);
|
|
|
|
|
|
|
|
return i;
|
|
return i;
|
|
|
}
|
|
}
|
|
@@ -273,7 +270,7 @@ __uint64_t printint(long n, int base, int sign) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-__uint64_t printptr(__uint64_t p, int width) {
|
|
|
|
|
|
|
+__uint64_t printptr(__uint64_t p, int width, char color) {
|
|
|
int i;
|
|
int i;
|
|
|
|
|
|
|
|
for (i = width - 1; i >= 0; i--) {
|
|
for (i = width - 1; i >= 0; i--) {
|
|
@@ -285,7 +282,7 @@ __uint64_t printptr(__uint64_t p, int width) {
|
|
|
else
|
|
else
|
|
|
c += '0';
|
|
c += '0';
|
|
|
|
|
|
|
|
- putc(c);
|
|
|
|
|
|
|
+ putc(c, color);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return width;
|
|
return width;
|