tvdos kernel to support unicode print, and hangul kernel module to demo the unicode support

This commit is contained in:
minjaesong
2021-12-24 11:30:55 +09:00
parent 229cc78eb6
commit c802c46f90
8 changed files with 75 additions and 20 deletions

View File

@@ -393,7 +393,7 @@ function println(s) {
if (s === undefined)
sys.print("\n");
else
sys.println(s);
print(s+"\n");
}
function printerr(s) {
print("\x1B[31m"+s+"\x1B[m");
@@ -440,7 +440,7 @@ con.mvaddch = function(y, x, c) {
con.move(y, x); con.addch(c);
};
con.getmaxyx = function() {
return graphics.getTermDimension();
return graphics.getTermDimension(); // [rows, cols]
};
con.getyx = function() {
return graphics.getCursorYX();

View File

@@ -127,10 +127,6 @@ function toLineChar(i,p,f) {
/* 1 | 3 */out[1+dbl] = fbuf[0]
/* 3 | 5 */out[3+dbl] = fbuf[1]
// serial.println(`ipf: ${i} ${p} ${f}`)
// serial.println(out)
if (out.length > 4) {
out[0] = enc.i[out[0]]
out[1] = 0x20
@@ -151,20 +147,19 @@ function toLineChar(i,p,f) {
function printHangul(char) {
let [cy,cx] = con.getyx()
// serial.println("chars:")
// serial.println(char)
char.forEach((v,i)=>{
con.mvaddch(cy+(i%2),cx+(i/2),v)
// serial.println(v.toString(16))
con.addch(v)
if (i % 2 == 0)
con.curs_down()
else {
let c = graphics.getCursorYX();
con.move(c[0]-1,c[1]+1);
}
})
con.move(cy+(char.length%2),cx+(char.length/2))
}
let text = "동해물과 백두산이 마르고 닳도록 7비트 한글조합"
/*let text = "동해물과 백두산이 마르고 닳도록 7비트 한글조합"
//con.clear()
//con.move(1,1)
@@ -178,4 +173,24 @@ unicode.utf8toCodepoints(text).forEach(cp=>{
else {
print(String.fromCharCode(cp))
}
})
})*/
// load unicode module to the TVDOS
if (unicode.uniprint) {
unicode.uniprint.push([
c => 0xAC00 <= c && c <= 0xD7A3,
c => {
let i = ((c - 0xAC00) / 588)|0
let p = ((c - 0xAC00) / 28 % 21)|0
let f = (c - 0xAC00) % 28
printHangul(toLineChar(i,p,f))
}
])
println("조합한글 커널모듈이 로드되었습니다.")
}
else {
println("Failed to load Assembly Hangul kernel module: incompatible DOS version")
}

View File

@@ -0,0 +1 @@
println("한글 또는 조선글은 현대 한국어 또는 한국어족 언어의 표기에 쓰이는 문자로,남한과 북한,연변 지역에서 사용되는 공용 문자이다. 현대 기준 기본자음 14자와 기본모음 10자로 구성된 음소문자이며, 자음과 자음, 모음과 모음끼리 합쳐서 새로운 자형을 만들 수 있다.\n사용할때는 모아쓰기를 하여 한 글자가 1음절을 나타내는 음절문자적 특성을 지니기도 한다. 현재까지 쓰이는 다른 대부분의 문자와 달리 특정 인물이 인공적으로 만들어낸 글자이며, 따라서 창제 역사와 원리가 설명되어 있는 몇 없는 문자이기도 하다.")

View File

@@ -315,6 +315,34 @@ unicode.utf8toCodepoints = function(utf8text) {
}
return codepoints
}
// array of array: [predicate_for_coderange: (Codepoint) -> Boolean , printing_function: (Codepoint) -> Unit_that_does_screen_drawing]
// Usage: unicode.uniprint.push[(c) => 0xAC00 <= c && c <= 0xD7A3, printHalfRowHangul]
unicode.uniprint = [];
unicode.uniprint.push([c => (0 <= c && c <= 255), c => { sys.print(String.fromCodePoint(c)) }]);
// @return [predicate, printing function]
unicode.getUniprint = (c) => {
for (let k = 0; k < unicode.uniprint.length; k++) {
if (unicode.uniprint[k][0](c))
return unicode.uniprint[k]
}}
print = function(str) {
if ((typeof str === 'string' || str instanceof String) && str.length > 0) {
let cp = unicode.utf8toCodepoints(str)
let q = unicode.getUniprint(cp[0])
cp.forEach(c => {
if (q[0](c)) {
q[1](c)
}
else {
q = unicode.getUniprint(c)
q[1](c)
}
})
}
}
Object.freeze(unicode);
///////////////////////////////////////////////////////////////////////////////