2024-01-13 00:00:11 +03:00
|
|
|
|
/**
|
|
|
|
|
* log.c
|
|
|
|
|
* Функции отладки
|
|
|
|
|
*
|
|
|
|
|
* Функционал отладки
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <arch.h>
|
|
|
|
|
#include <fb.h>
|
|
|
|
|
#include <lock.h>
|
|
|
|
|
#include <log.h>
|
|
|
|
|
#include <mem.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <tool.h>
|
|
|
|
|
|
2024-01-21 19:26:01 +03:00
|
|
|
|
static char start_buffer[1024];
|
2024-01-13 00:00:11 +03:00
|
|
|
|
static char *log_buffer;
|
|
|
|
|
static uint64_t fb_pos_x = 4;
|
|
|
|
|
static uint64_t fb_pos_y = 0;
|
|
|
|
|
static uint64_t buf_pos = 0;
|
2024-01-21 19:26:01 +03:00
|
|
|
|
static uint64_t buf_max = 1024;
|
2024-01-21 22:00:56 +03:00
|
|
|
|
static lock_t log_lock = LOCK_INIT;
|
2024-01-13 18:23:29 +03:00
|
|
|
|
|
2024-01-14 14:53:31 +03:00
|
|
|
|
#define FONT_WIDTH 6 + 1
|
|
|
|
|
#define FONT_HEIGHT 8 + 1
|
|
|
|
|
|
2024-01-13 18:23:29 +03:00
|
|
|
|
void redraw_screen( );
|
2024-01-13 00:00:11 +03:00
|
|
|
|
|
|
|
|
|
// Получение кода символа в таблице
|
|
|
|
|
static inline uint32_t analyze(char glyth) {
|
|
|
|
|
return ((uint8_t)glyth - 32) * 8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Вывод символа по координатам
|
|
|
|
|
static void print_char(uint64_t x, uint64_t y, char glyth) {
|
2024-09-16 21:42:02 +03:00
|
|
|
|
uint32_t glyth_index = analyze(glyth);
|
2024-01-13 00:00:11 +03:00
|
|
|
|
for (uint64_t i = 0; i < FONT_6X8_SLIM_CHAR_HEIGHT; i++) {
|
2024-09-16 21:42:02 +03:00
|
|
|
|
fb_print_bits(x, y + i, font_6x8_slim[glyth_index + i]);
|
2024-01-13 00:00:11 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-14 14:53:31 +03:00
|
|
|
|
void log_dump_buffer( ) {
|
|
|
|
|
for (uint64_t i = 0; i < buf_pos; i++) { com_write_byte(log_buffer[i]); }
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-13 18:23:29 +03:00
|
|
|
|
static void log_fb_putchar(char c) {
|
2024-01-13 00:00:11 +03:00
|
|
|
|
if (c == '\0' || fb_init_status < 1) { return; }
|
2024-09-16 21:42:02 +03:00
|
|
|
|
|
|
|
|
|
if (c == '\r') {
|
|
|
|
|
log_buffer[--buf_pos] = 0;
|
|
|
|
|
} else if (c == '\t') {
|
2024-01-13 00:00:11 +03:00
|
|
|
|
fb_pos_x += FONT_6X8_SLIM_CHAR_WIDTH * 4;
|
|
|
|
|
} else if (c == '\n') {
|
|
|
|
|
fb_pos_x = 4;
|
|
|
|
|
fb_pos_y += FONT_6X8_SLIM_CHAR_HEIGHT + 1;
|
|
|
|
|
} else {
|
|
|
|
|
if (fb_pos_x >= SCREEN_WIDTH) {
|
2024-01-14 14:53:31 +03:00
|
|
|
|
fb_pos_x = 4;
|
2024-01-13 00:00:11 +03:00
|
|
|
|
fb_pos_y += FONT_6X8_SLIM_CHAR_HEIGHT + 1;
|
|
|
|
|
}
|
2024-01-14 14:53:31 +03:00
|
|
|
|
|
|
|
|
|
if (fb_pos_y + FONT_6X8_SLIM_CHAR_HEIGHT >= SCREEN_HEIGHT) {
|
|
|
|
|
// Дошли до нижнего края экрана
|
2024-09-16 21:42:02 +03:00
|
|
|
|
while (log_buffer[0] != '\n') { tool_memmove(log_buffer, log_buffer + 1, --buf_pos); }
|
|
|
|
|
tool_memmove(log_buffer, log_buffer + 1, --buf_pos);
|
2024-01-13 18:23:29 +03:00
|
|
|
|
redraw_screen( );
|
2024-01-14 14:53:31 +03:00
|
|
|
|
return;
|
2024-01-13 18:23:29 +03:00
|
|
|
|
}
|
2024-01-14 14:53:31 +03:00
|
|
|
|
|
2024-01-13 00:00:11 +03:00
|
|
|
|
print_char(fb_pos_x, fb_pos_y, c);
|
|
|
|
|
fb_pos_x += FONT_6X8_SLIM_CHAR_WIDTH;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-13 18:23:29 +03:00
|
|
|
|
void redraw_screen( ) {
|
|
|
|
|
// Перерисовка экрана
|
2024-09-16 21:42:02 +03:00
|
|
|
|
hal_memset_32(SCREEN_BUFFER, DARK_GREEN, SCREEN_WIDTH * SCREEN_HEIGHT);
|
2024-01-13 18:23:29 +03:00
|
|
|
|
|
|
|
|
|
fb_pos_x = 4;
|
|
|
|
|
fb_pos_y = 0;
|
|
|
|
|
|
|
|
|
|
for (uint64_t i = 0; i < buf_pos; i++) { log_fb_putchar(log_buffer[i]); }
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-13 00:00:11 +03:00
|
|
|
|
void log_putchar(char c) {
|
|
|
|
|
log_buffer[buf_pos] = c;
|
|
|
|
|
com_write_byte(c);
|
|
|
|
|
|
|
|
|
|
if (buf_pos + 1 == buf_max) {
|
|
|
|
|
// Смещение буфера на 1 символ влево
|
|
|
|
|
for (uint64_t i = 0; i < buf_max - 1; i++) { log_buffer[i] = log_buffer[i + 1]; }
|
|
|
|
|
|
|
|
|
|
if (fb_init_status < 1) { return; }
|
2024-01-13 18:23:29 +03:00
|
|
|
|
redraw_screen( );
|
2024-01-13 00:00:11 +03:00
|
|
|
|
} else {
|
|
|
|
|
buf_pos++;
|
2024-01-13 18:23:29 +03:00
|
|
|
|
|
|
|
|
|
if (fb_init_status < 1) { return; }
|
|
|
|
|
log_fb_putchar(c);
|
2024-01-13 00:00:11 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Вывод текстового сообщения
|
|
|
|
|
void log_printf(char *str, ...) {
|
2024-01-21 22:00:56 +03:00
|
|
|
|
LOCK(log_lock);
|
2024-01-13 00:00:11 +03:00
|
|
|
|
va_list args;
|
|
|
|
|
va_start(args, str);
|
|
|
|
|
tool_format(&log_putchar, str, args);
|
2024-09-16 21:42:02 +03:00
|
|
|
|
|
2024-01-21 22:00:56 +03:00
|
|
|
|
lock_release(log_lock);
|
2024-01-13 00:00:11 +03:00
|
|
|
|
va_end(args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void log_init_mem( ) {
|
2024-01-21 22:00:56 +03:00
|
|
|
|
LOCK(log_lock);
|
2024-01-13 00:00:11 +03:00
|
|
|
|
log_buffer = mem_alloc(((SCREEN_WIDTH - 4) / FONT_WIDTH) * (SCREEN_HEIGHT / FONT_HEIGHT));
|
2024-01-21 19:26:01 +03:00
|
|
|
|
tool_memcpy(log_buffer, start_buffer, buf_max);
|
2024-01-13 00:00:11 +03:00
|
|
|
|
buf_max = ((SCREEN_WIDTH - 4) / FONT_WIDTH) * (SCREEN_HEIGHT / FONT_HEIGHT);
|
2024-01-21 19:26:01 +03:00
|
|
|
|
LOG("Размер буффера: %u символов\n", buf_max);
|
2024-09-17 21:29:52 +03:00
|
|
|
|
LOG("%ux%u %u\n", width, height, bpp);
|
2024-01-21 19:26:01 +03:00
|
|
|
|
redraw_screen( );
|
2024-01-21 22:00:56 +03:00
|
|
|
|
lock_release(log_lock);
|
2024-01-13 00:00:11 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void log_init( ) {
|
2024-01-14 15:28:26 +03:00
|
|
|
|
log_buffer = (char *)&start_buffer;
|
2024-01-13 00:00:11 +03:00
|
|
|
|
}
|