diff --git a/codeCore/src/prog8/code/target/cbm/AtasciiEncoding.kt b/codeCore/src/prog8/code/target/cbm/AtasciiEncoding.kt index b0b8e154c..633978d6d 100644 --- a/codeCore/src/prog8/code/target/cbm/AtasciiEncoding.kt +++ b/codeCore/src/prog8/code/target/cbm/AtasciiEncoding.kt @@ -195,7 +195,17 @@ object AtasciiEncoding { fun encode(str: String): Result, CharConversionException> { - return Ok(str.map { encodeTable.getValue(it).toUByte() }) + val mapped = str.map { chr -> + when (chr) { + '\u0000' -> 0u + in '\u8000'..'\u80ff' -> { + // special case: take the lower 8 bit hex value directly + (chr.code - 0x8000).toUByte() + } + else -> encodeTable.getValue(chr).toUByte() + } + } + return Ok(mapped) } fun decode(bytes: List): Result { diff --git a/codeCore/src/prog8/code/target/cbm/IsoEncoding.kt b/codeCore/src/prog8/code/target/cbm/IsoEncoding.kt index e6e46ebe9..8d427c162 100644 --- a/codeCore/src/prog8/code/target/cbm/IsoEncoding.kt +++ b/codeCore/src/prog8/code/target/cbm/IsoEncoding.kt @@ -11,7 +11,17 @@ object IsoEncoding { fun encode(str: String): Result, CharConversionException> { return try { - Ok(str.toByteArray(charset).map { it.toUByte() }) + val mapped = str.map { chr -> + when (chr) { + '\u0000' -> 0u + in '\u8000'..'\u80ff' -> { + // special case: take the lower 8 bit hex value directly + (chr.code - 0x8000).toUByte() + } + else -> charset.encode(chr.toString())[0].toUByte() + } + } + Ok(mapped) } catch (ce: CharConversionException) { Err(ce) } diff --git a/compiler/res/prog8lib/virtual/textio.p8 b/compiler/res/prog8lib/virtual/textio.p8 index a8c14f676..642ccc9a5 100644 --- a/compiler/res/prog8lib/virtual/textio.p8 +++ b/compiler/res/prog8lib/virtual/textio.p8 @@ -8,7 +8,7 @@ txt { sub clear_screen() { - txt.chrout(125) + syscall1(3, "\x1b[2J\x1B[H") } sub nl() { diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 6b853b0d4..cddfd3156 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -5,6 +5,7 @@ For next release ^^^^^^^^^^^^^^^^ - simplify cx16.joystick_get2() once this cx16 rom issue is resolved: https://github.com/commanderx16/x16-rom/issues/203 Can now be resolved because the fix got merged https://github.com/commanderx16/x16-rom/pull/204 +- add unit test for the string encoders special handling of 0x0000 and 0x8000-0x80ff ... diff --git a/examples/test.p8 b/examples/test.p8 index 9dac946a1..98808c46c 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,7 +1,11 @@ %import textio +; NOTE: meant to test to virtual machine output target (use -target vitual) + main { sub start() { + txt.clear_screen() + txt.print("Welcome to a prog8 pixel shader :-)\n") syscall1(8, 0) ; enable lo res creen ubyte shifter diff --git a/virtualmachine/src/prog8/vm/Assembler.kt b/virtualmachine/src/prog8/vm/Assembler.kt index 4a0c994f5..f7ac63e36 100644 --- a/virtualmachine/src/prog8/vm/Assembler.kt +++ b/virtualmachine/src/prog8/vm/Assembler.kt @@ -193,10 +193,9 @@ class Assembler { } } 'x' -> { - // special hack 0x8000..0x80ff will be outputted verbatim without encoding try { val hex = ("" + iter.nextChar() + iter.nextChar()).toInt(16) - (0x8000 + hex).toChar() + hex.toChar() } catch (sb: StringIndexOutOfBoundsException) { throw IllegalArgumentException("invalid \\x escape sequence") } catch (nf: NumberFormatException) {