Files
cardboy/Firmware/main/src/disp_tty.cpp
2025-03-03 01:06:49 +01:00

63 lines
1.3 KiB
C++

//
// Created by Stepan Usatiuk on 26.04.2024.
//
#include "disp_tty.hpp"
#include <disp_tools.hpp>
#include "Fonts.hpp"
void FbTty::draw_char(int col, int row) {
for (int x = 0; x < 8; x++) {
for (int y = 0; y < 16; y++) {
bool color = fonts_Terminess_Powerline[_buf[col][row]][y] & (1 << (8 - x));
if (color)
DispTools::get().set_pixel(col * 8 + x, row * 16 + y);
else
DispTools::get().reset_pixel(col * 8 + x, row * 16 + y);
}
}
}
void FbTty::reset() {
_cur_col = 0;
_cur_row = 0;
}
void FbTty::putchar(char c) {
if (c == '\n') {
next_row();
return;
}
_buf[_cur_col][_cur_row] = c;
draw_char(_cur_col, _cur_row);
next_col();
}
void FbTty::putstr(const char* str) {
while (*str != 0) {
putchar(*str);
str++;
}
}
void FbTty::next_col() {
_cur_col++;
_cur_col = _cur_col % _max_col;
if (_cur_col == 0) {
next_row();
} else {
_buf[_cur_col][_cur_row] = ' ';
draw_char(_cur_col, _cur_row);
}
}
void FbTty::next_row() {
_cur_col = 0;
_cur_row++;
_cur_row = _cur_row % _max_row;
for (int i = 0; i < _max_col; i++) {
_buf[i][_cur_row] = ' ';
draw_char(i, _cur_row);
}
}