From b21b04efeb84ad2190cb7f6e9fbbe117e7c36542 Mon Sep 17 00:00:00 2001 From: Karol Stasiak Date: Mon, 6 Apr 2020 03:16:51 +0200 Subject: [PATCH] Some fixes to encconv. Added two more functions. --- docs/stdlib/encconv.md | 12 ++++++++++++ include/encconv.mfk | 34 ++++++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/docs/stdlib/encconv.md b/docs/stdlib/encconv.md index c5a8c421..c0024902 100644 --- a/docs/stdlib/encconv.md +++ b/docs/stdlib/encconv.md @@ -53,6 +53,18 @@ Destructively converts a null-terminated string from the `scr` encoding into the Available only if `from_screencode` is available. +#### void pstr_to_screencode(pointer) + +Destructively converts a length-prefixed string from the `default` encoding into the `scr` encoding. + +Available only if `to_screencode` is available. + +#### void pstr_from_screencode(pointer) + +Destructively converts a length-prefixed string from the `scr` encoding into the `default` encoding. + +Available only if `from_screencode` is available. + #### byte petscii_to_petscr(byte) Converts a byte from PETSCII to a CBM screencode. diff --git a/include/encconv.mfk b/include/encconv.mfk index c0f2aa39..aa627f75 100644 --- a/include/encconv.mfk +++ b/include/encconv.mfk @@ -1,24 +1,26 @@ #if ENCODING_SAME #if ARCH_6502 -inline byte __byte_identity(byte register(a) value) { ? rts } -inline void __pointer_to_void(pointer register(ax) value) { ? rts } +inline asm byte __byte_identity(byte register(a) value) { ? rts } +inline asm void __pointer_to_void(pointer register(ax) value) { ? rts } #elseif ARCH_I80 #pragma zilog_syntax -inline byte __byte_identity(byte register(a) value) { ? ret } -inline void __pointer_to_void(pointer register(hl) value) { ? ret } +inline asm byte __byte_identity(byte register(a) value) { ? ret } +inline asm void __pointer_to_void(pointer register(hl) value) { ? ret } #elseif ARCH_M6809 -inline byte __byte_identity(byte register(b) value) { ? rts } -inline void __pointer_to_void(pointer register(d) value) { ? rts } +inline asm byte __byte_identity(byte register(b) value) { ? rts } +inline asm void __pointer_to_void(pointer register(d) value) { ? rts } #else -inline byte __byte_identity(byte register(a) value) = a -inline void __pointer_to_void(pointer register(a) value) { } +inline byte __byte_identity(byte value) = a +inline void __pointer_to_void(pointer value) { } #endif alias from_screencode = __byte_identity alias to_screencode = __byte_identity alias strz_from_screencode = __pointer_to_void alias strz_to_screencode = __pointer_to_void +alias pstr_from_screencode = __pointer_to_void +alias pstr_to_screencode = __pointer_to_void #elseif ENCCONV_SUPPORTED @@ -80,6 +82,22 @@ void strz_to_screencode(pointer p) { p += 1 } } + +void pstr_from_screencode(pointer p) { + byte i, l + l = p[0] + for i,1,parallelto,l { + p[i] = from_screencode(p[i]) + } +} +void pstr_to_screencode(pointer p) { + byte i, l + l = p[0] + for i,1,parallelto,l { + p[i] = to_screencode(p[i]) + } +} + #endif #endif // ENCODING_SAME/ENCCONV_SUPPORTED