From d77ecba5180473f084ebbe08be4980d5dfa2c51f Mon Sep 17 00:00:00 2001 From: Karol Stasiak Date: Fri, 31 Jul 2020 16:07:10 +0200 Subject: [PATCH] CoCo: encconv support --- docs/lang/text.md | 1 + docs/stdlib/encconv.md | 16 ++++++ include/encconv.mfk | 54 +++++++++++++++++-- include/platform/coco_rsdos.ini | 1 - src/main/scala/millfork/Platform.scala | 2 + .../parser/AbstractSourceLoadingQueue.scala | 3 ++ 6 files changed, 73 insertions(+), 4 deletions(-) diff --git a/docs/lang/text.md b/docs/lang/text.md index b5c69af7..7f33b52b 100644 --- a/docs/lang/text.md +++ b/docs/lang/text.md @@ -151,6 +151,7 @@ The exact value of `{nullchar}` is encoding-dependent: * in the `petscr` and `petscrjp` encodings it's `{xe0}`, * in the `atasciiscr` encoding it's `{xdb}`, * in the `pokemon1*` encodings it's `{x50}`, + * in the `cocoscr` encoding it's exceptionally two bytes: `{xd0}` * in the `utf16be` and `utf16le` encodings it's exceptionally two bytes: `{x00}{x00}` * in other encodings it's `{x00}` (this may be a subject to change in future versions). diff --git a/docs/stdlib/encconv.md b/docs/stdlib/encconv.md index c0024902..63e54705 100644 --- a/docs/stdlib/encconv.md +++ b/docs/stdlib/encconv.md @@ -31,6 +31,8 @@ Available only if one of the following is true: * the default encoding is `atascii`, the screen encoding is `atasciiscr`, and the platform is 6502-based +* the default encoding is `coco`, the screen encoding is `cococsr`, and the platform is 6809-based + You can test for the availability of this function using the `ENCCONV_SUPPORTED` preprocessor feature. #### byte from_screencode(byte) @@ -98,3 +100,17 @@ Reverse characters are interpreted as non-reverse characters. Available only on 6502-based platforms. +#### byte coco_to_cocoscr(byte) + +Converts a byte from Color Computer pseudo-ASCII to a Color Computer screencode. +Control characters <$20 are converted inverted punctuation. + +Available only on 6809-based platforms. + +#### byte cocoscr_to_coco(byte) + +Converts a byte from a Color Computer screencode to Color Computer pseudo-ASCII. +Inverted punctuation is converted to control characters. + +Available only on 6809-based platforms. + diff --git a/include/encconv.mfk b/include/encconv.mfk index aa627f75..82ddd0a2 100644 --- a/include/encconv.mfk +++ b/include/encconv.mfk @@ -83,6 +83,8 @@ void strz_to_screencode(pointer p) { } } +#endif + void pstr_from_screencode(pointer p) { byte i, l l = p[0] @@ -98,8 +100,6 @@ void pstr_to_screencode(pointer p) { } } -#endif - #endif // ENCODING_SAME/ENCCONV_SUPPORTED @@ -199,4 +199,52 @@ __atascii_to_atasciiscr_end: rts } -#endif \ No newline at end of file +#endif + +#if ARCH_6809 + +asm byte coco_to_cocoscr(byte register(b) char) { + cmpb #$20 + bcc __coco_to_cocoscr_40 + eorb #$20 + rts +__coco_to_cocoscr_40: + cmpb #$40 + bcc __coco_to_cocoscr_60 + eorb #$40 + rts +__coco_to_cocoscr_60: + cmpb #$60 + bcc __coco_to_cocoscr_80 + rts +__coco_to_cocoscr_80: + cmpb #$80 + bcc __coco_to_cocoscr_end + eorb #$60 +__coco_to_cocoscr_end: + rts +} + +asm byte cocoscr_to_coco(byte register(b) char) { + cmpb #$20 + bcc __cocoscr_to_coco_40 + eorb #$60 + rts +__cocoscr_to_coco_40: + cmpb #$40 + bcc __cocoscr_to_coco_60 + eorb #$20 + rts +__cocoscr_to_coco_60: + cmpb #$60 + bcc __cocoscr_to_coco_80 + rts +__cocoscr_to_coco_80: + cmpb #$80 + bcc __coco_to_cocoscr_end + eorb #$40 +__cocoscr_to_coco_end: + rts +} + +#endif diff --git a/include/platform/coco_rsdos.ini b/include/platform/coco_rsdos.ini index 40ae103a..4e5eec74 100644 --- a/include/platform/coco_rsdos.ini +++ b/include/platform/coco_rsdos.ini @@ -2,7 +2,6 @@ ; VERY EXPERIMENTAL [compilation] arch=6809 -; todo: is it ascii? encoding=coco screen_encoding=cocoscr modules=default_panic,stdlib,coco/kernal diff --git a/src/main/scala/millfork/Platform.scala b/src/main/scala/millfork/Platform.scala index 163d29b7..0aeeb1f0 100644 --- a/src/main/scala/millfork/Platform.scala +++ b/src/main/scala/millfork/Platform.scala @@ -329,6 +329,8 @@ object Platform { ("PETSCII-JP", "CBM-Screen-JP") | ("ATASCII", "ATASCII-Screen") => CpuFamily.forType(cpu) == CpuFamily.M6502 + case ("Color-Computer", "Color-Computer-Screen") => + CpuFamily.forType(cpu) == CpuFamily.M6809 case _ => codec.name == srcCodec.name }), "NULLCHAR_SAME" -> toLong(codec.stringTerminator == srcCodec.stringTerminator) diff --git a/src/main/scala/millfork/parser/AbstractSourceLoadingQueue.scala b/src/main/scala/millfork/parser/AbstractSourceLoadingQueue.scala index 35b54eb4..66c1b0bf 100644 --- a/src/main/scala/millfork/parser/AbstractSourceLoadingQueue.scala +++ b/src/main/scala/millfork/parser/AbstractSourceLoadingQueue.scala @@ -33,6 +33,9 @@ abstract class AbstractSourceLoadingQueue[T](val initialFilenames: List[String], case ("ATASCII", "ATASCII-Screen") => List(AliasDefinitionStatement("__from_screencode", "atasciiscr_to_atascii", important = false), AliasDefinitionStatement("__to_screencode", "atascii_to_atasciiscr", important = false)) + case ("Color-Computer", "Color-Computer-Screen") => + List(AliasDefinitionStatement("__from_screencode", "cocoscr_to_coco", important = false), + AliasDefinitionStatement("__to_screencode", "coco_to_cocoscr", important = false)) case _ => Nil } encodingConversionAliases