OXYGENHUB
◆ main openmsx / src / input / MsxChar2Unicode.hh
1.4 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
e8555c89 Andy McCall 1
#ifndef MSXCHAR2UNICODE_HH
2
#define MSXCHAR2UNICODE_HH
3
4
#include <array>
5
#include <cstdint>
6
#include <functional>
7
#include <span>
8
#include <string>
9
#include <string_view>
10
#include <vector>
11
12
namespace openmsx {
13
14
class MsxChar2Unicode
15
{
16
public:
17
	explicit MsxChar2Unicode(std::string_view mappingName);
18
19
	/** TODO */
20
	[[nodiscard]] std::string msxToUtf8(
21
		std::span<const uint8_t> msx,
22
		const std::function<uint32_t(uint8_t)>& fallback) const;
23
	/** TODO */
24
	[[nodiscard]] std::vector<uint8_t> utf8ToMsx(
25
		std::string_view utf8,
26
		const std::function<uint8_t(uint32_t)>& fallback) const;
27
28
	[[nodiscard]] std::string msxToUtf8(std::span<const uint8_t> msx, char fallback) const;
29
	[[nodiscard]] std::vector<uint8_t> utf8ToMsx(std::string_view utf8, char fallback) const;
30
31
private:
32
	void parseVid(std::string_view file);
33
34
private:
35
	// LUT: msx graphical character code (as stored in VRAM) -> unicode character
36
	// Some entries are not filled in (are invalid), they contain the value -1.
37
	// There may be different (valid) entries that contain the same value.
38
	std::array<uint32_t, 256> msx2unicode;
39
40
	// Reverse LUT: unicode character -> msx graphical character
41
	struct Entry {
42
		Entry(uint32_t u, uint8_t m) : unicode(u), msx(m) {}
43
		uint32_t unicode;
44
		uint8_t msx;
45
	};
46
	// Sorted on Entry::unicode. All 'unicode' fields are unique, but
47
	// there can be different entries that have the same 'msx' field.
48
	std::vector<Entry> unicode2msx;
49
};
50
51
} // namespace openmsx
52
53
#endif