mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +00:00
Have Console::write() directly call vga_putch.
This commit is contained in:
parent
a70bfb87d5
commit
fc88368582
Notes:
sideshowbarker
2024-07-19 18:45:54 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/fc883685820
5 changed files with 18 additions and 23 deletions
|
@ -25,16 +25,18 @@ ssize_t Console::read(byte* buffer, size_t bufferSize)
|
|||
return 0;
|
||||
}
|
||||
|
||||
extern int kprintfFromConsole(const char*, ...);
|
||||
void Console::putChar(char ch)
|
||||
{
|
||||
vga_putch(nullptr, ch);
|
||||
}
|
||||
|
||||
ssize_t Console::write(const byte* data, size_t size)
|
||||
{
|
||||
if (!size)
|
||||
return 0;
|
||||
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
kprintfFromConsole("%c", data[i]);
|
||||
}
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
putChar(data[i]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,8 @@ public:
|
|||
virtual ssize_t write(const byte* data, size_t size) override;
|
||||
|
||||
private:
|
||||
void putChar(char);
|
||||
|
||||
byte m_rows { 25 };
|
||||
byte m_columns { 80 };
|
||||
byte m_cursorRow { 0 };
|
||||
|
|
|
@ -10,8 +10,6 @@
|
|||
PRIVATE BYTE *vga_mem = 0L;
|
||||
PRIVATE BYTE current_attr = 0x07;
|
||||
|
||||
PRIVATE volatile WORD soft_cursor;
|
||||
|
||||
template<typename PutChFunc> static int printNumber(PutChFunc, char*&, DWORD);
|
||||
template<typename PutChFunc> static int printHex(PutChFunc, char*&, DWORD, BYTE fields);
|
||||
template<typename PutChFunc> static int printSignedNumber(PutChFunc, char*&, int);
|
||||
|
@ -21,20 +19,22 @@ static void console_putch(char*, char ch)
|
|||
Console::the().write((byte*)&ch, 1);
|
||||
}
|
||||
|
||||
static void vga_putch(char*, char ch)
|
||||
void vga_putch(char*, char ch)
|
||||
{
|
||||
WORD soft_cursor = vga_get_cursor();
|
||||
WORD row;
|
||||
|
||||
switch (ch) {
|
||||
case '\n':
|
||||
row = soft_cursor / 80;
|
||||
if (row == 23) {
|
||||
memcpy( vga_mem, vga_mem + 160, 160 * 23 );
|
||||
memset( vga_mem + (160 * 23), 0, 160 );
|
||||
memcpy(vga_mem, vga_mem + 160, 160 * 23);
|
||||
memset(vga_mem + (160 * 23), 0, 160);
|
||||
soft_cursor = row * 80;
|
||||
} else {
|
||||
soft_cursor = (row + 1) * 80;
|
||||
}
|
||||
vga_set_cursor(soft_cursor);
|
||||
return;
|
||||
default:
|
||||
vga_mem[soft_cursor * 2] = ch;
|
||||
|
@ -47,6 +47,8 @@ static void vga_putch(char*, char ch)
|
|||
memset(vga_mem + (160 * 23), 0, 160);
|
||||
soft_cursor = 23 * 80;
|
||||
}
|
||||
|
||||
vga_set_cursor(soft_cursor);
|
||||
}
|
||||
|
||||
template<typename PutChFunc>
|
||||
|
@ -54,8 +56,6 @@ int kprintfInternal(PutChFunc putch, char* buffer, const char*& fmt, char*& ap)
|
|||
{
|
||||
const char *p;
|
||||
|
||||
soft_cursor = vga_get_cursor();
|
||||
|
||||
int ret = 0;
|
||||
char* bufptr = buffer;
|
||||
|
||||
|
@ -134,17 +134,6 @@ int kprintf(const char* fmt, ...)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int kprintfFromConsole(const char* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
soft_cursor = vga_get_cursor();
|
||||
int ret = kprintfInternal(vga_putch, nullptr, fmt, ap);
|
||||
vga_set_cursor(soft_cursor);
|
||||
va_end(ap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void buffer_putch(char*& bufptr, char ch)
|
||||
{
|
||||
*bufptr++ = ch;
|
||||
|
|
|
@ -8,6 +8,7 @@ void vga_set_attr(BYTE);
|
|||
void vga_set_cursor(WORD);
|
||||
void vga_set_cursor(BYTE row, BYTE column);
|
||||
WORD vga_get_cursor();
|
||||
void vga_putch(char*, char);
|
||||
|
||||
int kprintf(const char *fmt, ...);
|
||||
int ksprintf(char* buf, const char *fmt, ...);
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <ELFLoader/ELFLoader.h>
|
||||
#include "Console.h"
|
||||
|
||||
//#define TEST_VFS
|
||||
//#define TEST_ELF_LOADER
|
||||
//#define TEST_CRASHY_USER_PROCESSES
|
||||
|
||||
|
@ -163,7 +164,7 @@ void init()
|
|||
|
||||
Disk::initialize();
|
||||
|
||||
#if CHECK_VFS
|
||||
#ifdef TEST_VFS
|
||||
auto vfs = make<VirtualFileSystem>();
|
||||
|
||||
auto dev_zero = make<ZeroDevice>();
|
||||
|
|
Loading…
Reference in a new issue