/* Copyright (C) 2021 Rain */ /* This file is part of XNIX. */ /* XNIX is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) and later version. */ /* XNIX is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ /* You should have received a copy of the GNU General Public License along with XNIX. If not, see . */ #include #include #include #include #include #include int printk(__uint32_t fg, __uint32_t bg, char *s, ...) { va_list args; int i; /* I think 256 is enough in kernel */ /* too long, return it. */ if (s[255]) return 0; static char buffer[256] = {0}; va_start(args, s); /* it maybe overflow, but that's in .data section and we did check. */ i = vsprintf(buffer, s, args); print(fg, bg, buffer); va_end(args); return i; } static int x = 0, y = 0; void putc(char c, __uint32_t fg, __uint32_t bg) { if (c == '\n') { /* it's '\n', but we use '\r\n' */ x = 0; y += 16; return; } if (c == '\r') { x = 0; return; } if (c == ' ') { x += 8; return; } struct psf_header *psf = (struct psf_header *) &font_start; /* * yeah, it's very ugly. but it just get address of this glyph, and check * 'c' is really in this font. * */ __uint8_t *glyph = (__uint8_t *) &font_start + psf->header_size + (c > 0 && c < psf->glyphs_count ? c : 0) * psf->glyph_size; /* okay, now we put it on the screen */ int i; int mask; char d; for (i = 0; i < 16; i++) { __uint32_t *addr; int j; addr = FB_ADDR + VGA_X * (y + i) + x; mask = 0x0100; d = glyph[i]; for (j = 0; j < 8; j++) { mask >>= 1; if (d & mask) addr[j] = fg; else addr[j] = bg; } } x += 8; if (x >= VGA_X) { x = 0; y += 16; /* but y will > Y_LINES */ } return; } void print(__uint32_t fg, __uint32_t bg, char *s) { for (; *s; s++) putc(*s, fg, bg); return; }