1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 21:48:13 +00:00

Have Console::write() directly call vga_putch.

This commit is contained in:
Andreas Kling 2018-10-21 22:11:46 +02:00
parent a70bfb87d5
commit fc88368582
5 changed files with 18 additions and 23 deletions

View file

@ -25,16 +25,18 @@ ssize_t Console::read(byte* buffer, size_t bufferSize)
return 0; 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) ssize_t Console::write(const byte* data, size_t size)
{ {
if (!size) if (!size)
return 0; return 0;
for (size_t i = 0; i < size; ++i) { for (size_t i = 0; i < size; ++i)
kprintfFromConsole("%c", data[i]); putChar(data[i]);
}
return 0; return 0;
} }

View file

@ -13,6 +13,8 @@ public:
virtual ssize_t write(const byte* data, size_t size) override; virtual ssize_t write(const byte* data, size_t size) override;
private: private:
void putChar(char);
byte m_rows { 25 }; byte m_rows { 25 };
byte m_columns { 80 }; byte m_columns { 80 };
byte m_cursorRow { 0 }; byte m_cursorRow { 0 };

View file

@ -10,8 +10,6 @@
PRIVATE BYTE *vga_mem = 0L; PRIVATE BYTE *vga_mem = 0L;
PRIVATE BYTE current_attr = 0x07; PRIVATE BYTE current_attr = 0x07;
PRIVATE volatile WORD soft_cursor;
template<typename PutChFunc> static int printNumber(PutChFunc, char*&, DWORD); 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 printHex(PutChFunc, char*&, DWORD, BYTE fields);
template<typename PutChFunc> static int printSignedNumber(PutChFunc, char*&, int); 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); 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; WORD row;
switch (ch) { switch (ch) {
case '\n': case '\n':
row = soft_cursor / 80; row = soft_cursor / 80;
if (row == 23) { if (row == 23) {
memcpy( vga_mem, vga_mem + 160, 160 * 23 ); memcpy(vga_mem, vga_mem + 160, 160 * 23);
memset( vga_mem + (160 * 23), 0, 160 ); memset(vga_mem + (160 * 23), 0, 160);
soft_cursor = row * 80; soft_cursor = row * 80;
} else { } else {
soft_cursor = (row + 1) * 80; soft_cursor = (row + 1) * 80;
} }
vga_set_cursor(soft_cursor);
return; return;
default: default:
vga_mem[soft_cursor * 2] = ch; vga_mem[soft_cursor * 2] = ch;
@ -47,6 +47,8 @@ static void vga_putch(char*, char ch)
memset(vga_mem + (160 * 23), 0, 160); memset(vga_mem + (160 * 23), 0, 160);
soft_cursor = 23 * 80; soft_cursor = 23 * 80;
} }
vga_set_cursor(soft_cursor);
} }
template<typename PutChFunc> template<typename PutChFunc>
@ -54,8 +56,6 @@ int kprintfInternal(PutChFunc putch, char* buffer, const char*& fmt, char*& ap)
{ {
const char *p; const char *p;
soft_cursor = vga_get_cursor();
int ret = 0; int ret = 0;
char* bufptr = buffer; char* bufptr = buffer;
@ -134,17 +134,6 @@ int kprintf(const char* fmt, ...)
return ret; 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) static void buffer_putch(char*& bufptr, char ch)
{ {
*bufptr++ = ch; *bufptr++ = ch;

View file

@ -8,6 +8,7 @@ void vga_set_attr(BYTE);
void vga_set_cursor(WORD); void vga_set_cursor(WORD);
void vga_set_cursor(BYTE row, BYTE column); void vga_set_cursor(BYTE row, BYTE column);
WORD vga_get_cursor(); WORD vga_get_cursor();
void vga_putch(char*, char);
int kprintf(const char *fmt, ...); int kprintf(const char *fmt, ...);
int ksprintf(char* buf, const char *fmt, ...); int ksprintf(char* buf, const char *fmt, ...);

View file

@ -26,6 +26,7 @@
#include <ELFLoader/ELFLoader.h> #include <ELFLoader/ELFLoader.h>
#include "Console.h" #include "Console.h"
//#define TEST_VFS
//#define TEST_ELF_LOADER //#define TEST_ELF_LOADER
//#define TEST_CRASHY_USER_PROCESSES //#define TEST_CRASHY_USER_PROCESSES
@ -163,7 +164,7 @@ void init()
Disk::initialize(); Disk::initialize();
#if CHECK_VFS #ifdef TEST_VFS
auto vfs = make<VirtualFileSystem>(); auto vfs = make<VirtualFileSystem>();
auto dev_zero = make<ZeroDevice>(); auto dev_zero = make<ZeroDevice>();