mirror of
https://github.com/irmen/prog8.git
synced 2025-04-09 15:38:49 +00:00
added ATASCII encoding table for atari
This commit is contained in:
parent
530e109433
commit
c5504c6657
@ -15,8 +15,8 @@ import prog8.compilerinterface.*
|
||||
class AtariTarget: ICompilationTarget, IStringEncoding by Encoder, IMemSizer {
|
||||
override val name = NAME
|
||||
override val machine = AtariMachineDefinition()
|
||||
override val supportedEncodings = setOf(Encoding.ISO) // TODO
|
||||
override val defaultEncoding = Encoding.ISO // TODO
|
||||
override val supportedEncodings = setOf(Encoding.ATASCII)
|
||||
override val defaultEncoding = Encoding.ATASCII
|
||||
override val defaultLauncherType = LauncherType.NONE
|
||||
|
||||
companion object {
|
||||
|
@ -2,6 +2,7 @@ package prog8.codegen.target
|
||||
|
||||
import com.github.michaelbull.result.fold
|
||||
import prog8.ast.base.FatalAstException
|
||||
import prog8.codegen.target.cbm.AtasciiEncoding
|
||||
import prog8.codegen.target.cbm.IsoEncoding
|
||||
import prog8.codegen.target.cbm.PetsciiEncoding
|
||||
import prog8.compilerinterface.Encoding
|
||||
@ -13,6 +14,7 @@ internal object Encoder: IStringEncoding {
|
||||
Encoding.PETSCII -> PetsciiEncoding.encodePetscii(str, true)
|
||||
Encoding.SCREENCODES -> PetsciiEncoding.encodeScreencode(str, true)
|
||||
Encoding.ISO -> IsoEncoding.encode(str)
|
||||
Encoding.ATASCII -> AtasciiEncoding.encode(str)
|
||||
else -> throw FatalAstException("unsupported encoding $encoding")
|
||||
}
|
||||
return coded.fold(
|
||||
@ -25,6 +27,7 @@ internal object Encoder: IStringEncoding {
|
||||
Encoding.PETSCII -> PetsciiEncoding.decodePetscii(bytes, true)
|
||||
Encoding.SCREENCODES -> PetsciiEncoding.decodeScreencode(bytes, true)
|
||||
Encoding.ISO -> IsoEncoding.decode(bytes)
|
||||
Encoding.ATASCII -> AtasciiEncoding.decode(bytes)
|
||||
else -> throw FatalAstException("unsupported encoding $encoding")
|
||||
}
|
||||
return decoded.fold(
|
||||
|
204
codeGenTargets/src/prog8/codegen/target/cbm/AtasciiEncoding.kt
Normal file
204
codeGenTargets/src/prog8/codegen/target/cbm/AtasciiEncoding.kt
Normal file
@ -0,0 +1,204 @@
|
||||
package prog8.codegen.target.cbm
|
||||
|
||||
import com.github.michaelbull.result.Ok
|
||||
import com.github.michaelbull.result.Result
|
||||
import java.io.CharConversionException
|
||||
|
||||
object AtasciiEncoding {
|
||||
|
||||
private val decodeTable: CharArray = charArrayOf(
|
||||
// $00
|
||||
'♥',
|
||||
'├',
|
||||
'\uf130', // 🮇 0x02 -> RIGHT ONE QUARTER BLOCK (CUS)
|
||||
'┘',
|
||||
'┤',
|
||||
'┐',
|
||||
'╱',
|
||||
'╲',
|
||||
'◢',
|
||||
'▗',
|
||||
'◣',
|
||||
'▝',
|
||||
'▘',
|
||||
'\uf132', // 🮂 0x1d -> UPPER ONE QUARTER BLOCK (CUS)
|
||||
'▂',
|
||||
'▖',
|
||||
|
||||
// $10
|
||||
'♣',
|
||||
'┌',
|
||||
'─',
|
||||
'┼',
|
||||
'•',
|
||||
'▄',
|
||||
'▎',
|
||||
'┬',
|
||||
'┴',
|
||||
'▌',
|
||||
'└',
|
||||
'\u001b', // $1b = escape
|
||||
'\ufffe', // UNDEFINED CHAR. $1c = cursor up
|
||||
'\ufffe', // UNDEFINED CHAR. $1d = cursor down
|
||||
'\ufffe', // UNDEFINED CHAR. $1e = cursor left
|
||||
'\ufffe', // UNDEFINED CHAR. $1f = cursor right
|
||||
|
||||
// $20
|
||||
' ',
|
||||
'!',
|
||||
'"',
|
||||
'#',
|
||||
'$',
|
||||
'%',
|
||||
'&',
|
||||
'\'',
|
||||
'(',
|
||||
')',
|
||||
'*',
|
||||
'+',
|
||||
',',
|
||||
'-',
|
||||
'.',
|
||||
'/',
|
||||
|
||||
// $30
|
||||
'0',
|
||||
'1',
|
||||
'2',
|
||||
'3',
|
||||
'4',
|
||||
'5',
|
||||
'6',
|
||||
'7',
|
||||
'8',
|
||||
'9',
|
||||
':',
|
||||
';',
|
||||
'<',
|
||||
'=',
|
||||
'>',
|
||||
'?',
|
||||
|
||||
// $40
|
||||
'@',
|
||||
'A',
|
||||
'B',
|
||||
'C',
|
||||
'D',
|
||||
'E',
|
||||
'F',
|
||||
'G',
|
||||
'H',
|
||||
'I',
|
||||
'J',
|
||||
'K',
|
||||
'L',
|
||||
'M',
|
||||
'N',
|
||||
'O',
|
||||
|
||||
// $50
|
||||
'P',
|
||||
'Q',
|
||||
'R',
|
||||
'S',
|
||||
'T',
|
||||
'U',
|
||||
'V',
|
||||
'W',
|
||||
'X',
|
||||
'Y',
|
||||
'Z',
|
||||
'[',
|
||||
'\\',
|
||||
']',
|
||||
'^',
|
||||
'_',
|
||||
|
||||
// $60
|
||||
'♦',
|
||||
'a',
|
||||
'b',
|
||||
'c',
|
||||
'd',
|
||||
'e',
|
||||
'f',
|
||||
'g',
|
||||
'h',
|
||||
'i',
|
||||
'j',
|
||||
'k',
|
||||
'l',
|
||||
'm',
|
||||
'n',
|
||||
'o',
|
||||
|
||||
// $70
|
||||
'p',
|
||||
'q',
|
||||
'r',
|
||||
's',
|
||||
't',
|
||||
'u',
|
||||
'v',
|
||||
'w',
|
||||
'x',
|
||||
'y',
|
||||
'z',
|
||||
'♠',
|
||||
'|',
|
||||
'\u000c', // $7d -> FORM FEED (CLEAR SCREEN)
|
||||
'\u0008', // $7e -> BACKSPACE
|
||||
'\u0009', // $7f -> TAB
|
||||
|
||||
// $80-$ff are reversed video characters + various special characters.
|
||||
'\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe',
|
||||
'\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe',
|
||||
// $90
|
||||
'\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe',
|
||||
'\ufffe',
|
||||
'\ufffe',
|
||||
'\ufffe',
|
||||
'\n', // $9b -> EOL/RETURN
|
||||
'\ufffe', // UNDEFINED $9c = DELETE LINE
|
||||
'\ufffe', // UNDEFINED $9d = INSERT LINE
|
||||
'\ufffe', // UNDEFINED $9e = CLEAR TAB STOP
|
||||
'\ufffe', // UNDEFINED $9f = SET TAB STOP
|
||||
// $a0
|
||||
'\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe',
|
||||
'\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe',
|
||||
// $b0
|
||||
'\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe',
|
||||
'\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe',
|
||||
// $c0
|
||||
'\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe',
|
||||
'\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe',
|
||||
// $d0
|
||||
'\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe',
|
||||
'\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe',
|
||||
// $e0
|
||||
'\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe',
|
||||
'\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe',
|
||||
// $f0
|
||||
'\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe', '\ufffe',
|
||||
'\ufffe',
|
||||
'\ufffe',
|
||||
'\ufffe',
|
||||
'\ufffe',
|
||||
'\ufffe',
|
||||
'\u0007', // $fd = bell/beep
|
||||
'\u007f', // $fe = DELETE
|
||||
'\ufffe' // UNDEFINED $ff = INSERT
|
||||
)
|
||||
|
||||
private val encodeTable = decodeTable.withIndex().associate{it.value to it.index}
|
||||
|
||||
|
||||
fun encode(str: String): Result<List<UByte>, CharConversionException> {
|
||||
return Ok(str.map { encodeTable.getValue(it).toUByte() })
|
||||
}
|
||||
|
||||
fun decode(bytes: List<UByte>): Result<String, CharConversionException> {
|
||||
return Ok(bytes.map { decodeTable[it.toInt()] }.joinToString(""))
|
||||
}
|
||||
}
|
@ -159,7 +159,7 @@ object PetsciiEncoding {
|
||||
'\uf105', // 0x90 -> BLACK COLOR SWITCH (CUS)
|
||||
'\uf11e', // 0x91 -> CURSOR UP (CUS)
|
||||
'\uf11b', // 0x92 -> REVERSE VIDEO OFF (CUS)
|
||||
'\u000c', // 0x93 -> FORM FEED
|
||||
'\u000c', // 0x93 -> FORM FEED (CLEAR SCREEN)
|
||||
'\uf121', // 0x94 -> INSERT (CUS)
|
||||
'\uf106', // 0x95 -> BROWN COLOR SWITCH (CUS)
|
||||
'\uf107', // 0x96 -> LIGHT RED COLOR SWITCH (CUS)
|
||||
@ -195,7 +195,7 @@ object PetsciiEncoding {
|
||||
'\u258e', // ▎ 0xB4 -> LEFT ONE QUARTER BLOCK
|
||||
'\u258d', // ▍ 0xB5 -> LEFT THREE EIGTHS BLOCK
|
||||
'\uf131', // 0xB6 -> RIGHT THREE EIGHTHS BLOCK (CUS)
|
||||
'\uf132', // 0xB7 -> UPPER ONE QUARTER BLOCK (CUS)
|
||||
'\uf132', // 🮂 0xB7 -> UPPER ONE QUARTER BLOCK (CUS)
|
||||
'\uf133', // 0xB8 -> UPPER THREE EIGHTS BLOCK (CUS)
|
||||
'\u2583', // ▃ 0xB9 -> LOWER THREE EIGHTHS BLOCK
|
||||
'\u2713', // ✓ 0xBA -> CHECK MARK
|
||||
@ -246,7 +246,7 @@ object PetsciiEncoding {
|
||||
'\u2595', // ▕ 0xE7 -> RIGHT ONE EIGHTH BLOCK
|
||||
'\uf12f', // 0xE8 -> LOWER HALF BLOCK MEDIUM SHADE (CUS)
|
||||
'\uf13a', // 0xE9 -> MEDIUM SHADE SLASHED RIGHT (CUS)
|
||||
'\uf130', // 0xEA -> RIGHT ONE QUARTER BLOCK (CUS)
|
||||
'\uf130', // 🮇 0xEA -> RIGHT ONE QUARTER BLOCK (CUS)
|
||||
'\u251c', // ├ 0xEB -> BOX DRAWINGS LIGHT VERTICAL AND RIGHT
|
||||
'\u2597', // ▗ 0xEC -> QUADRANT LOWER RIGHT
|
||||
'\u2514', // └ 0xED -> BOX DRAWINGS LIGHT UP AND RIGHT
|
||||
@ -418,7 +418,7 @@ object PetsciiEncoding {
|
||||
'\uf105', // 0x90 -> BLACK COLOR SWITCH (CUS)
|
||||
'\uf11e', // 0x91 -> CURSOR UP (CUS)
|
||||
'\uf11b', // 0x92 -> REVERSE VIDEO OFF (CUS)
|
||||
'\u000c', // 0x93 -> FORM FEED
|
||||
'\u000c', // 0x93 -> FORM FEED (CLEAR SCREEN)
|
||||
'\uf121', // 0x94 -> INSERT (CUS)
|
||||
'\uf106', // 0x95 -> BROWN COLOR SWITCH (CUS)
|
||||
'\uf107', // 0x96 -> LIGHT RED COLOR SWITCH (CUS)
|
||||
|
@ -9,19 +9,15 @@
|
||||
txt {
|
||||
|
||||
const ubyte DEFAULT_WIDTH = 40
|
||||
const ubyte DEFAULT_HEIGHT = 25
|
||||
const ubyte DEFAULT_HEIGHT = 24
|
||||
|
||||
|
||||
sub clear_screen() {
|
||||
txt.chrout(147) ; TODO
|
||||
}
|
||||
|
||||
sub home() {
|
||||
txt.chrout(19) ; TODO
|
||||
txt.chrout(125)
|
||||
}
|
||||
|
||||
sub nl() {
|
||||
txt.chrout(155)
|
||||
txt.chrout('\n')
|
||||
}
|
||||
|
||||
sub spc() {
|
||||
|
@ -9,6 +9,7 @@ import io.kotest.matchers.shouldBe
|
||||
import io.kotest.matchers.string.shouldContain
|
||||
import prog8.codegen.target.C64Target
|
||||
import prog8.codegen.target.Cx16Target
|
||||
import prog8.codegen.target.cbm.AtasciiEncoding
|
||||
import prog8.codegen.target.cbm.IsoEncoding
|
||||
import prog8.codegen.target.cbm.PetsciiEncoding
|
||||
import prog8tests.helpers.ErrorReporterForTests
|
||||
@ -182,6 +183,20 @@ class TestStringEncodings: FunSpec({
|
||||
}
|
||||
}
|
||||
|
||||
context("atari") {
|
||||
test("atascii encoding") {
|
||||
AtasciiEncoding.encode("a") shouldBe Ok(listOf<UByte>(97u))
|
||||
AtasciiEncoding.encode("A") shouldBe Ok(listOf<UByte>(65u))
|
||||
AtasciiEncoding.encode("\n") shouldBe Ok(listOf<UByte>(155u))
|
||||
}
|
||||
|
||||
test("atascii decoding") {
|
||||
AtasciiEncoding.decode(listOf<UByte>(97u)) shouldBe Ok("a")
|
||||
AtasciiEncoding.decode(listOf<UByte>(65u)) shouldBe Ok("A")
|
||||
AtasciiEncoding.decode(listOf<UByte>(155u)) shouldBe Ok("\n")
|
||||
}
|
||||
}
|
||||
|
||||
context("iso") {
|
||||
test("iso accepts iso-characters") {
|
||||
val result = IsoEncoding.encode("a_~ëç")
|
||||
|
@ -4,6 +4,7 @@ enum class Encoding(val prefix: String) {
|
||||
DEFAULT("default"), // depends on compilation target
|
||||
PETSCII("petscii"), // c64/c128/cx16
|
||||
SCREENCODES("sc"), // c64/c128/cx16
|
||||
ATASCII("atascii"), // atari
|
||||
ISO("iso") // cx16
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ main {
|
||||
txt.nl()
|
||||
}
|
||||
|
||||
txt.waitkey()
|
||||
txt.waitkey()
|
||||
}
|
||||
|
||||
uword fib_prev = 0
|
||||
|
@ -5,9 +5,9 @@
|
||||
; hello world test for Atari 8-bit
|
||||
|
||||
main {
|
||||
sub start() {
|
||||
sub start() {
|
||||
txt.print("Hello, World!")
|
||||
txt.nl()
|
||||
txt.waitkey()
|
||||
txt.nl()
|
||||
txt.waitkey()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,14 @@
|
||||
|
||||
main {
|
||||
sub start() {
|
||||
txt.print("Hello!\nWorld\n")
|
||||
ubyte cc
|
||||
for cc in 32 to 124 {
|
||||
txt.chrout(cc)
|
||||
}
|
||||
txt.waitkey()
|
||||
|
||||
txt.clear_screen()
|
||||
txt.print("\nHello!\nWorld\n")
|
||||
|
||||
repeat {
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user