/* 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 #define CHAR_SIZE_W 8 #define CHAR_SIZE_H 16 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 (y>320){ y=0; x++; //memset(FB_ADDR,0,320); } if (c == '\n') { /* it's '\n', but we use '\r\n' */ x = 0; y += CHAR_SIZE_H; return; } if (c == '\r') { x = 0; return; } if (c == ' ') { x += CHAR_SIZE_W; 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 += CHAR_SIZE_W; if (x >= VGA_X) { x = 0; y += CHAR_SIZE_H; /* but y will > Y_LINES */ } return; } void print(__uint8_t fg, __uint8_t bg, char *s) { for (; *s; s++) putc(*s, fg, bg); return; }