gpt4 book ai didi

内核终端中的光标

转载 作者:行者123 更新时间:2023-12-04 18:48:23 26 4
gpt4 key购买 nike

我正在尝试编辑此内核。 c、不支持游标。我写了超过 25 行,它没有显示超过 25 行,我不能上下查看其余部分。这是整个代码,除了主要功能。

uint8_t make_color(enum vga_color fg, enum vga_color bg) {
return fg | bg << 4;}
static const size_t VGA_WIDTH = 80;
static const size_t VGA_HEIGHT = 25;

uint16_t make_vgaentry(char c, uint8_t color) {
uint16_t c16 = c;
uint16_t color16 = color;
return c16 | color16 << 8;}

size_t strlen(const char* str) {
size_t ret = 0;

while ( str[ret] != 0 )
ret++;
return ret;}
static const size_t VGA_WIDTH = 80;
static const size_t VGA_HEIGHT = 25;

size_t terminal_row;
size_t terminal_column;
uint8_t terminal_color;
uint16_t* terminal_buffer;
void terminal_initialize() {
terminal_row = 0;
terminal_column = 0;
terminal_color = make_color(COLOR_LIGHT_GREY, COLOR_BLACK);
terminal_buffer = (uint16_t*) 0xB8000;

for (size_t y = 0; y < VGA_HEIGHT; y++) {
for (size_t x = 0; x < VGA_WIDTH; x++) {
const size_t index = y * VGA_WIDTH + x;
terminal_buffer[index] = make_vgaentry(' ',
terminal_color);
}}}
void terminal_setcolor(uint8_t color) {
terminal_color = color;
}

void terminal_putentryat(char c, uint8_t color, size_t x, size_t y)
{
const size_t index = y * VGA_WIDTH + x;
if(y>VGA_HEIGHT){
size_t index = (VGA_HEIGHT - 1) * VGA_WIDTH;
for(size_t x = 0; x < VGA_WIDTH; ++x)
{
terminal_buffer[index + x] = vga_entry(' ', terminal_color);
}
}
else
terminal_buffer[index] = make_vgaentry(c, color);}
void terminal_putchar(char c) {
terminal_putentryat(c, terminal_color, terminal_column,
terminal_row);
if (++terminal_column == VGA_WIDTH) {
terminal_column = 0;
if (++terminal_row == VGA_HEIGHT)
terminal_row = 0;}
else if (c == '\n')
{
terminal_row = terminal_row + 1;
terminal_column = 0;
}
}
void terminal_writestring(const char* data) {
size_t datalen = strlen(data);
for (size_t i = 0; i < datalen; i++)
terminal_putchar(data[i]);}
我需要像终端中的那样逐行滚动。

最佳答案

void terminal_scrollUp(void)
{
for (size_t y = 1; y < VGA_HEIGHT; y++)
{
for (size_t x = 0; x < VGA_WIDTH; x++)
{
const size_t index = y * VGA_WIDTH + x;
terminal_buffer[index - VGA_WIDTH] = terminal_buffer[index];
}
}
for(size_t col = 0; col < VGA_WIDTH; col++)
{
terminal_putentryat(' ', terminal_color, col, VGA_HEIGHT - 1);
}
}

void terminal_putchar(char c)
{
terminal_putentryat(c, terminal_color, terminal_column, terminal_row);
if (++terminal_column == VGA_WIDTH || c == '\n')
{
terminal_column = 0;
if(terminal_row == VGA_HEIGHT - 1)
{
terminal_scrollUp();
}
else
{
terminal_row++;
}
}
}

关于内核终端中的光标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70124028/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com