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);
///////////////////////////////////////////////////////////////////////////////

View File

@@ -173,7 +173,11 @@ From the start of the memory space:
framebuffer scroll Y
896 bytes
horizontal scroll offset for scanlines
234 bytes
1 bytes
terminal configuration #0
0b 0000 000h
h: halfrow mode
233 bytes
unused
1920
mapped to font ROM
@@ -187,7 +191,6 @@ From the start of the memory space:
Text background colours
2560 bytes
Text buffer of 80x32 (7x14 character size, and yes: actual character data is on the bottom)
FI
512 bytes
Palette stored in following pattern: 0b rrrr gggg, 0b bbbb aaaa, ....
Palette number 255 is always full transparent (bits being all zero)

View File

@@ -31,6 +31,8 @@ abstract class GlassTty(val TEXT_ROWS: Int, val TEXT_COLS: Int) {
abstract var ttyBack: Int
abstract var ttyRawMode: Boolean
abstract var halfrowMode: Boolean
abstract fun putChar(x: Int, y: Int, text: Byte, foreColour: Byte = ttyFore.toByte(), backColour: Byte = ttyBack.toByte())
fun writeOut(char: Byte) {

View File

@@ -115,6 +115,8 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi
private val memTextOffset = 2L + 2560 + 2560
private val TEXT_AREA_SIZE = TEXT_COLS * TEXT_ROWS
override var halfrowMode = true//false
override var rawCursorPos: Int
get() = textArea.getShort(memTextCursorPosOffset).toInt()
set(value) { textArea.setShort(memTextCursorPosOffset, value.toShort()) }
@@ -127,7 +129,7 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi
if (newx >= TEXT_COLS) {
newx = 0
newy += 1
newy += 1 + halfrowMode.toInt()
}
else if (newx < 0) {
newx = 0
@@ -196,6 +198,7 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi
250897L -> framebufferScrollX.ushr(8).toByte()
250898L -> framebufferScrollY.toByte()
250899L -> framebufferScrollY.ushr(8).toByte()
251796L -> halfrowMode.toInt().toByte()
in 252030 until 252030+1920 -> mappedFontRom[adi- 252030]
in 250880 until 250880+1024 -> unusedArea[addr - 250880]
in 253950 until 261632 -> textArea[addr - 253950]
@@ -224,6 +227,7 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi
250897L -> framebufferScrollX = framebufferScrollX.and(0xFFFF00FF.toInt()).or(bi shl 8)
250898L -> framebufferScrollY = framebufferScrollY.and(0xFFFFFF00.toInt()).or(bi)
250899L -> framebufferScrollY = framebufferScrollY.and(0xFFFF00FF.toInt()).or(bi shl 8)
251796L -> halfrowMode = (bi and 1) == 1
in 252030 until 252030+1920 -> mappedFontRom[adi- 252030] = byte
in 250880 until 250880+1024 -> unusedArea[addr - 250880] = byte
in 253950 until 261632 -> textArea[addr - 253950] = byte
@@ -590,7 +594,7 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi
override fun crlf() {
val (_, y) = getCursorPos()
val newy = y + 1
val newy = y + 1 + halfrowMode.toInt()
setCursorPos(0, if (newy >= TEXT_ROWS) TEXT_ROWS - 1 else newy)
if (newy >= TEXT_ROWS) scrollUp(1)
}

View File

@@ -31,6 +31,8 @@ class TTY(assetsRoot: String, val vm: VM) : GlassTty(TEXT_ROWS, TEXT_COLS), Peri
override var blinkCursor = true
override var ttyRawMode = false
override var halfrowMode = false
override fun getCursorPos() = rawCursorPos % TEXT_COLS to rawCursorPos / TEXT_COLS
/**
* Think of it as a real paper tty;