Added a string class to be able to easily print unicode strings
This commit is contained in:
parent
c9afbf876b
commit
b6333e7174
7 changed files with 123 additions and 8 deletions
|
@ -4,6 +4,7 @@
|
|||
#include <stdint.h>
|
||||
#include <output.hpp>
|
||||
#include <multiboot.h>
|
||||
#include <string.hpp>
|
||||
#define SCREEN_WIDTH 64
|
||||
#define SCREEN_HEIGHT 48
|
||||
namespace MTGosHAL {
|
||||
|
@ -52,7 +53,9 @@ namespace MTGosHAL {
|
|||
auto putChar(char c) -> void;
|
||||
int base;
|
||||
public:
|
||||
auto putChar(unsigned short c) -> void;
|
||||
auto puts(const char *s) -> void;
|
||||
auto puts(String &) -> void;
|
||||
Screen(): fg(FG_color::WHITE), bg(BG_color::BLACK), base(10) {
|
||||
}
|
||||
Screen(struct multiboot_info* mb_info): Screen() {init(mb_info);}
|
||||
|
|
|
@ -82,7 +82,8 @@ namespace MTGosHAL {
|
|||
uint8_t buf[512];
|
||||
disk.readSector(disk.getDriveNumByName("ATA0m1"),0,buf);
|
||||
out << (char*)buf;
|
||||
sti();
|
||||
out << "こんにちは、ユニコード。\nЗдравствуй, Юникод.\nΓεια σου, Γιούνικοντ.\n안녕하세요, 유니코드.\n"_s;
|
||||
//sti();
|
||||
for(;;);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
int x=0, y=0;
|
||||
namespace MTGosHAL {
|
||||
auto Screen::putChar(char c) -> void {
|
||||
putChar((unsigned short)c);
|
||||
}
|
||||
auto Screen::putChar(unsigned short c) -> void {
|
||||
switch(c) {
|
||||
case '\n':
|
||||
x=0; y++;
|
||||
|
@ -28,10 +31,10 @@ namespace MTGosHAL {
|
|||
default:
|
||||
for(int lx=0;lx<16;lx++) {
|
||||
for(int ly=0;ly<16;ly++) {
|
||||
if(font[(int)((uint8_t)c)][ly]&(1<<(16-lx))) {
|
||||
lfb[(x*16+lx)+(y*16+ly)*1024]=0xFFFFFF;//static_cast<uint32_t>(fg);
|
||||
if(font[(int)(c)][ly]&(1<<(16-lx))) {
|
||||
lfb[(x*16+lx)+(y*16+ly)*1024]=static_cast<uint32_t>(fg);
|
||||
} else {
|
||||
lfb[(x*16+lx)+(y*16+ly)*1024]=0x000000;//static_cast<uint32_t>(bg);
|
||||
lfb[(x*16+lx)+(y*16+ly)*1024]=static_cast<uint32_t>(bg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +49,7 @@ namespace MTGosHAL {
|
|||
}
|
||||
auto Screen::clrscr() -> void {
|
||||
for(int p=0;p<1024*786;p++) {
|
||||
lfb[p]=0x000000;//static_cast<uint32_t>(bg);
|
||||
lfb[p]=static_cast<uint32_t>(bg);
|
||||
}
|
||||
x=y=0;
|
||||
}
|
||||
|
@ -58,7 +61,7 @@ namespace MTGosHAL {
|
|||
}
|
||||
for(int ly=786-16;ly<786;ly++) {
|
||||
for(int lx=0;lx<1024;lx++) {
|
||||
lfb[lx+ly*1024]=0x000000;//static_cast<uint32_t>(bg);
|
||||
lfb[lx+ly*1024]=static_cast<uint32_t>(bg);
|
||||
}
|
||||
}
|
||||
y--;
|
||||
|
@ -105,8 +108,12 @@ namespace MTGosHAL {
|
|||
bool wide_char=width[i].width==0x10;
|
||||
if(wide_char) {
|
||||
CHR16* chr=(CHR16*)((char*)(&chr_begin[hwcount]));
|
||||
for(int j=0;j<16;j++)
|
||||
::font[i][j]=chr->rows[j];
|
||||
for(int j=0;j<16;j++) {
|
||||
uint16_t tmp=chr->rows[j]&0xFF;
|
||||
tmp <<= 8;
|
||||
tmp += chr->rows[j]>>8;
|
||||
::font[i][j]=tmp;
|
||||
}
|
||||
hwcount+=2;
|
||||
} else {
|
||||
for(int j=0;j<16;j++)
|
||||
|
@ -176,4 +183,9 @@ namespace MTGosHAL {
|
|||
puts(output);
|
||||
return *this;
|
||||
}
|
||||
auto Screen::puts(String& output) -> void {
|
||||
for(size_t i=0;i<output.size();i++) {
|
||||
putChar((uint16_t)output[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
16
kernel/kernel/include/string.hpp
Normal file
16
kernel/kernel/include/string.hpp
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include <stdint.h>
|
||||
#include <pmm.hpp>
|
||||
class String {
|
||||
private:
|
||||
uint32_t *arr;
|
||||
size_t length;
|
||||
String() {}
|
||||
public:
|
||||
String(const char*);
|
||||
String(String &);
|
||||
~String();
|
||||
auto operator=(String &) -> String &;
|
||||
auto size() -> size_t;
|
||||
auto operator[](int) -> uint32_t;
|
||||
};
|
||||
String &operator""_s(const char *str, size_t len);
|
|
@ -3,6 +3,7 @@
|
|||
#include <base.hpp>
|
||||
#include <stdint.h>
|
||||
#include <output.hpp>
|
||||
#include <string.hpp>
|
||||
#define SCREEN_WIDTH 128
|
||||
#define SCREEN_HEIGHT 96
|
||||
namespace MTGosHAL {
|
||||
|
@ -51,7 +52,9 @@ namespace MTGosHAL {
|
|||
int base;
|
||||
auto putChar(char c) -> void;
|
||||
public:
|
||||
auto putChar(unsigned short c) -> void;
|
||||
auto puts(const char *s) -> void;
|
||||
auto puts(String &) -> void;
|
||||
Screen(): fg(FG_color::WHITE), bg(BG_color::BLACK), base(10) {
|
||||
}
|
||||
template <typename T>
|
||||
|
|
80
kernel/kernel/stdstring.cpp
Normal file
80
kernel/kernel/stdstring.cpp
Normal file
|
@ -0,0 +1,80 @@
|
|||
#include <string.hpp>
|
||||
#include <string.h>
|
||||
String::String(const char* ch) {
|
||||
const unsigned char* c=(const unsigned char*)ch;
|
||||
int len=0;
|
||||
for(size_t i=0;i<strlen(ch);i++,len++) {
|
||||
int p=i;
|
||||
if(c[p]<0x80) {
|
||||
} else if((c[p]&0xFC)==0xFC)
|
||||
i+=5;
|
||||
else if((c[p]&0xF8)==0xF8)
|
||||
i+=4;
|
||||
else if((c[p]&0xF0)==0xF0)
|
||||
i+=3;
|
||||
else if((c[p]&0xE0)==0xE0)
|
||||
i+=2;
|
||||
else if((c[p]&0xC0)==0xC0)
|
||||
i++;
|
||||
}
|
||||
length=len;
|
||||
arr=new uint32_t[len];
|
||||
int p=0;
|
||||
for(int i=0;i<len;i++) {
|
||||
uint32_t chr=0;
|
||||
if(c[p]<0x80)
|
||||
chr=c[p++];
|
||||
else if((c[p]&0xFC)==0xFC) {
|
||||
chr=(c[p++]&1)<<30;
|
||||
chr+=(c[p++]&0x3F)<<24;
|
||||
chr+=(c[p++]&0x3F)<<18;
|
||||
chr+=(c[p++]&0x3F)<<12;
|
||||
chr+=(c[p++]&0x3F)<<6;
|
||||
chr+=c[p++]&0x3F;
|
||||
}else if((c[p]&0xF8)==0xF8) {
|
||||
chr=(c[p++]&3)<<24;
|
||||
chr+=(c[p++]&0x3F)<<18;
|
||||
chr+=(c[p++]&0x3F)<<12;
|
||||
chr+=(c[p++]&0x3F)<<6;
|
||||
chr+=c[p++]&0x3F;
|
||||
}else if((c[p]&0xF0)==0xF0) {
|
||||
chr=(c[p++]&0x07)<<18;
|
||||
chr+=(c[p++]&0x3F)<<12;
|
||||
chr+=(c[p++]&0x3F)<<6;
|
||||
chr+=c[p++]&0x3F;
|
||||
}else if((c[p]&0xE0)==0xE0) {
|
||||
chr=(c[p++]&0x0F)<<12;
|
||||
chr+=(c[p++]&0x3F)<<6;
|
||||
chr+=c[p++]&0x3F;
|
||||
}else if((c[p]&0xC0)==0xC0) {
|
||||
chr=(c[p++]&0x1F)<<6;
|
||||
chr+=c[p++]&0x3F;
|
||||
}
|
||||
arr[i]=chr;
|
||||
}
|
||||
}
|
||||
String::String(String&other) {
|
||||
*this=other;
|
||||
}
|
||||
auto String::operator=(String&other) -> String& {
|
||||
length=other.size();
|
||||
arr=new uint32_t(length);
|
||||
for(size_t i=0;i<length;i++) {
|
||||
arr[i]=other.arr[i];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
String::~String() {
|
||||
delete arr;
|
||||
}
|
||||
auto String::size() -> size_t {
|
||||
return length;
|
||||
}
|
||||
auto String::operator[](int i) -> uint32_t {
|
||||
if((size_t)(i)<length)
|
||||
return arr[i];
|
||||
return 0;
|
||||
}
|
||||
String &operator""_s(const char *str, size_t len) {
|
||||
return *(new String(str));
|
||||
}
|
BIN
kernel/libhal.a
BIN
kernel/libhal.a
Binary file not shown.
Loading…
Reference in a new issue