openMSX
MsxChar2Unicode.hh
Go to the documentation of this file.
1 #ifndef MSXCHAR2UNICODE_HH
2 #define MSXCHAR2UNICODE_HH
3 
4 #include <cstdint>
5 #include <functional>
6 #include <span>
7 #include <string>
8 #include <string_view>
9 #include <vector>
10 
11 namespace openmsx {
12 
14 {
15 public:
16  MsxChar2Unicode(std::string_view mappingName);
17 
19  [[nodiscard]] std::string msxToUtf8(
20  std::span<const uint8_t> msx,
21  std::function<uint32_t(uint8_t)> fallback) const;
23  [[nodiscard]] std::vector<uint8_t> utf8ToMsx(
24  std::string_view utf8,
25  std::function<uint8_t(uint32_t)> fallback) const;
26 
27 private:
28  void parseVid(std::string_view file);
29 
30 private:
31  // LUT: msx graphical character code (as stored in VRAM) -> unicode character
32  // Some entries are not filled in (are invalid), they contain the value -1.
33  // There may be different (valid) entries that contain the same value.
34  uint32_t msx2unicode[256];
35 
36  // Reverse LUT: unicode character -> msx graphical character
37  struct Entry {
38  Entry(uint32_t u, uint8_t m) : unicode(u), msx(m) {}
39  uint32_t unicode;
40  uint8_t msx;
41  };
42  // Sorted on Entry::unicode. All 'unicode' fields are unique, but
43  // there can be different entries that have the same 'msx' field.
44  std::vector<Entry> unicode2msx;
45 };
46 
47 } // namespace openmsx
48 
49 #endif
std::string msxToUtf8(std::span< const uint8_t > msx, std::function< uint32_t(uint8_t)> fallback) const
TODO.
std::vector< uint8_t > utf8ToMsx(std::string_view utf8, std::function< uint8_t(uint32_t)> fallback) const
TODO.
MsxChar2Unicode(std::string_view mappingName)
This file implemented 3 utility functions:
Definition: Autofire.cc:9