| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- /* 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 <https://www.gnu.org/licenses/>.
- */
- #include <kernel/init.h>
- #include <kernel/types.h>
- #include <kernel/errno.h>
- #include <kernel/graphic.h>
- void putblock(__uint8_t color, int xs, int xe, int ys, int ye) {
- int x, y;
- char *fb = FB_ADDR;
- for (y = ys; y <= ye; y++) {
- for (x = xs; x <= xe; x++)
- fb[y * VGA_X + x] = color;
- }
-
- return;
- }
- static int x = 0, y = 0;
- void putc(char c, __uint8_t fg, __uint8_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, j;
- char *p, d, mask;
- for (i = 0; i < psf->height; i++) {
- p = FB_ADDR + (y + i) * VGA_X + x;
- d = glyph[i];
- for (j = 0; j < 8; j++) {
- mask = 0x80 >> j;
- if (d & mask)
- p[j] = fg;
- else
- p[j] = bg;
- }
- }
- x += 8;
- if (x >= VGA_X) {
- x = 0;
- y += 16;
- /* but y will > Y_LINES */
- }
- return;
- }
- void print(__uint8_t fg, __uint8_t bg, char *s) {
- for (; *s; s++)
- putc(*s, fg, bg);
- return;
- }
|