diff options
Diffstat (limited to 'kernel.soso/tty.c')
-rw-r--r-- | kernel.soso/tty.c | 66 |
1 files changed, 22 insertions, 44 deletions
diff --git a/kernel.soso/tty.c b/kernel.soso/tty.c index a9753c34..9e53c339 100644 --- a/kernel.soso/tty.c +++ b/kernel.soso/tty.c @@ -1,8 +1,7 @@ #include "tty.h" #include "alloc.h" -Tty* createTty(uint16 lineCount, uint16 columnCount, TtyFlushScreenFunction flushFunction) -{ +Tty* createTty(uint16 lineCount, uint16 columnCount, TtyFlushScreenFunction flushFunction) { Tty* tty = kmalloc(sizeof(Tty)); memset((uint8*)tty, 0, sizeof(Tty)); @@ -27,37 +26,31 @@ Tty* createTty(uint16 lineCount, uint16 columnCount, TtyFlushScreenFunction flus return tty; } -void destroyTty(Tty* tty) -{ +void destroyTty(Tty* tty) { FifoBuffer_destroy(tty->keyBuffer); kfree(tty->buffer); kfree(tty); } -void Tty_Print(Tty* tty, int row, int column, const char* text) -{ +void Tty_Print(Tty* tty, int row, int column, const char* text) { unsigned char * video = tty->buffer; video += (row * tty->columnCount + column) * 2; - while(*text != 0) - { + while(*text != 0) { *video++ = *text++; *video++ = tty->color; } } //One line -void Tty_ScrollUp(Tty* tty) -{ +void Tty_ScrollUp(Tty* tty) { unsigned char * videoLine = tty->buffer; unsigned char * videoLineNext = tty->buffer; int line = 0; int column = 0; - for (line = 0; line < tty->lineCount - 1; ++line) - { - for (column = 0; column < tty->columnCount; ++column) - { + for (line = 0; line < tty->lineCount - 1; ++line) { + for (column = 0; column < tty->columnCount; ++column) { videoLine = tty->buffer + (line * tty->columnCount + column) * 2; videoLineNext = tty->buffer + ((line + 1) * tty->columnCount + column) * 2; @@ -68,20 +61,17 @@ void Tty_ScrollUp(Tty* tty) //Last line should be empty. unsigned char * lastLine = tty->buffer + ((tty->lineCount - 1) * tty->columnCount) * 2; - for (int i = 0; i < tty->columnCount * 2; i += 2) - { + for (int i = 0; i < tty->columnCount * 2; i += 2) { lastLine[i] = 0; lastLine[i + 1] = tty->color; } } -void Tty_Clear(Tty* tty) -{ +void Tty_Clear(Tty* tty) { unsigned char * video = tty->buffer; int i = 0; - for (i = 0; i < tty->lineCount * tty->columnCount; ++i) - { + for (i = 0; i < tty->lineCount * tty->columnCount; ++i) { *video++ = 0; *video++ = tty->color; } @@ -90,17 +80,14 @@ void Tty_Clear(Tty* tty) tty->currentColumn = 0; } -void Tty_PutChar(Tty* tty, char c) -{ +void Tty_PutChar(Tty* tty, char c) { unsigned char * video = tty->buffer; - if ('\n' == c || '\r' == c) - { + if ('\n' == c || '\r' == c) { ++tty->currentLine; tty->currentColumn = 0; - if (tty->currentLine >= tty->lineCount - 0) - { + if (tty->currentLine >= tty->lineCount - 0) { --tty->currentLine; Tty_ScrollUp(tty); } @@ -108,10 +95,8 @@ void Tty_PutChar(Tty* tty, char c) Tty_MoveCursor(tty, tty->currentLine, tty->currentColumn); return; } - else if ('\b' == c) - { - if (tty->currentColumn > 0) - { + else if ('\b' == c) { + if (tty->currentColumn > 0) { --tty->currentColumn; c = '\0'; video = tty->buffer + (tty->currentLine * tty->columnCount + tty->currentColumn) * 2; @@ -120,10 +105,8 @@ void Tty_PutChar(Tty* tty, char c) Tty_MoveCursor(tty, tty->currentLine, tty->currentColumn); return; } - else if (tty->currentColumn == 0) - { - if (tty->currentLine > 0) - { + else if (tty->currentColumn == 0) { + if (tty->currentLine > 0) { --tty->currentLine; tty->currentColumn = tty->columnCount - 1; c = '\0'; @@ -136,14 +119,12 @@ void Tty_PutChar(Tty* tty, char c) } } - if (tty->currentColumn >= tty->columnCount) - { + if (tty->currentColumn >= tty->columnCount) { ++tty->currentLine; tty->currentColumn = 0; } - if (tty->currentLine >= tty->lineCount - 0) - { + if (tty->currentLine >= tty->lineCount - 0) { --tty->currentLine; Tty_ScrollUp(tty); } @@ -158,18 +139,15 @@ void Tty_PutChar(Tty* tty, char c) Tty_MoveCursor(tty, tty->currentLine, tty->currentColumn); } -void Tty_PutText(Tty* tty, const char* text) -{ +void Tty_PutText(Tty* tty, const char* text) { const char* c = text; - while (*c) - { + while (*c) { Tty_PutChar(tty, *c); ++c; } } -void Tty_MoveCursor(Tty* tty, uint16 line, uint16 column) -{ +void Tty_MoveCursor(Tty* tty, uint16 line, uint16 column) { tty->currentLine = line; tty->currentColumn = column; } |