OXYGENHUB
◆ main openmsx / src / video / CharacterConverter.hh
2.6 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef CHARACTERCONVERTER_HH
2
#define CHARACTERCONVERTER_HH
3
4
#include <cstdint>
5
#include <span>
6
7
namespace openmsx {
8
9
class VDP;
10
class VDPVRAM;
11
class DisplayMode;
12
13
14
/** Utility class for converting VRAM contents to host pixels.
15
  */
16
class CharacterConverter
17
{
18
public:
19
	using Pixel = uint32_t;
20
21
	/** Create a new bitmap scanline converter.
22
	  * @param vdp The VDP of which the VRAM will be converted.
23
	  * @param palFg Pointer to 16-entries array that specifies
24
	  *   VDP foreground color index to host pixel mapping.
25
	  *   This is kept as a pointer, so any changes to the palette
26
	  *   are immediately picked up by convertLine.
27
	  * @param palBg Pointer to 16-entries array that specifies
28
	  *   VDP background color index to host pixel mapping.
29
	  *   This is kept as a pointer, so any changes to the palette
30
	  *   are immediately picked up by convertLine.
31
	  */
32
	CharacterConverter(VDP& vdp, std::span<const Pixel, 16> palFg, std::span<const Pixel, 16> palBg);
33
34
	/** Convert a line of V9938 VRAM to 256 or 512 host pixels.
35
	  * Call this method in non-planar display modes (Graphic4 and Graphic5).
36
	  * @param buf Buffer where host pixels will be written to.
37
	  *            Depending on the screen mode, the buffer must contain at
38
	  *            least 256 or 512 pixels, but more is allowed (the extra
39
	  *            pixels aren't touched).
40
	  * @param line Display line number [0..255].
41
	  */
42
	void convertLine(std::span<Pixel> buf, int line) const;
43
44
	/** Select the display mode to use for scanline conversion.
45
	  * @param mode The new display mode.
46
	  */
47
	void setDisplayMode(DisplayMode mode);
48
49
private:
50
	inline void renderText1   (std::span<Pixel, 256> buf, int line) const;
51
	inline void renderText1Q  (std::span<Pixel, 256> buf, int line) const;
52
	inline void renderText2   (std::span<Pixel, 512> buf, int line) const;
53
	inline void renderGraphic1(std::span<Pixel, 256> buf, int line) const;
54
	inline void renderGraphic2(std::span<Pixel, 256> buf, int line) const;
55
	inline void renderMulti   (std::span<Pixel, 256> buf, int line) const;
56
	inline void renderMultiQ  (std::span<Pixel, 256> buf, int line) const;
57
	inline void renderBogus   (std::span<Pixel, 256> buf) const;
58
	inline void renderBlank   (std::span<Pixel, 256> buf) const;
59
	inline void renderMultiHelper(Pixel* pixelPtr, int line,
60
	                       unsigned mask, unsigned patternQuarter) const;
61
62
	[[nodiscard]] std::span<const uint8_t, 32> getNamePtr(int line, int scroll) const;
63
64
private:
65
	VDP& vdp;
66
	VDPVRAM& vram;
67
68
	std::span<const Pixel, 16> palFg;
69
	std::span<const Pixel, 16> palBg;
70
71
	unsigned modeBase = 0; // not strictly needed, but avoids Coverity warning
72
};
73
74
} // namespace openmsx
75
76
#endif