From 626737b9fa7845ae2c62007ea79af1704c245aab Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 12 Jun 2017 21:32:36 -0400 Subject: [PATCH] Started mucking about with some string conversion routines. Not finished yet. --- Storage/Data/ZX8081.cpp | 34 ++++++++++++++++++++++++++++++++++ Storage/Data/ZX8081.hpp | 4 ++++ 2 files changed, 38 insertions(+) diff --git a/Storage/Data/ZX8081.cpp b/Storage/Data/ZX8081.cpp index 7df811cc6..81d647e48 100644 --- a/Storage/Data/ZX8081.cpp +++ b/Storage/Data/ZX8081.cpp @@ -90,3 +90,37 @@ std::shared_ptr Storage::Data::ZX8081::FileFromData(const std::vector &data, bool is_zx81) { + std::wstring string; + + wchar_t zx80_map[] = { + ' ', u'\u2598', u'\u259d', u'\u2580', u'\u2596', u'\u258c', u'\u259e', u'\u259b', u'\u2588', u'\u2584', u'\u2580', '"', u'£', '$', ':', '?', + '(', ')', '>', '<', '=', '+', '-', '*', '/', ';', ',', '.', '0', '1', '2', '3', + '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', + 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' + }; + wchar_t zx81_map[] = { + ' ', u'\u2598', u'\u259d', u'\u2580', u'\u2596', u'\u258c', u'\u259e', u'\u259b', u'\u2588', u'\u2584', u'\u2580', u'£', '$', ':', '?', + '(', ')', '-', '+', '*', '/', '=', '>', '<', ';', ',', '.', '0', '1', '2', '3', + '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', + 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' + }; + wchar_t *map = is_zx81 ? zx81_map : zx80_map; + + for(uint8_t byte : data) { + string.push_back(map[byte & 0x3f]); + } + + return string; +} + +std::vector DataFromString(const std::wstring &string, bool is_zx81) { + std::vector data; + + // TODO + + return data; +} diff --git a/Storage/Data/ZX8081.hpp b/Storage/Data/ZX8081.hpp index 5003e710a..148479556 100644 --- a/Storage/Data/ZX8081.hpp +++ b/Storage/Data/ZX8081.hpp @@ -25,6 +25,10 @@ struct File { std::shared_ptr FileFromData(const std::vector &data); +std::wstring StringFromData(const std::vector &data, bool is_zx81); +std::vector DataFromString(const std::wstring &string, bool is_zx81); + + } } }