2021-11-27

Cursor in kernel terminal

I'm trying to edit this kernel. c, it doesn't support cursor. I wrote over 25 lines, and it doesn't show more than 25 and I can't go up or down to see the rest. here is the whole code, except the main function.

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]);}

i need to have scrolling like the one in the terminal, line by line.



from Recent Questions - Stack Overflow https://ift.tt/315Rzwb
https://ift.tt/eA8V8J

No comments:

Post a Comment