OXYGENHUB
◆ main openmsx / src / video / v9990 / V9990SDLRasterizer.hh
4.5 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef V9990SDLRASTERIZER_HH
2
#define V9990SDLRASTERIZER_HH
3
4
#include "V9990BitmapConverter.hh"
5
#include "V9990PxConverter.hh"
6
#include "V9990Rasterizer.hh"
7
8
#include "Observer.hh"
9
10
#include <array>
11
#include <cstdint>
12
#include <memory>
13
14
namespace openmsx {
15
16
class Display;
17
class V9990;
18
class V9990VRAM;
19
class RawFrame;
20
class OutputSurface;
21
class RenderSettings;
22
class Setting;
23
class PostProcessor;
24
25
/** Rasterizer using SDL.
26
  */
27
class V9990SDLRasterizer final : public V9990Rasterizer
28
                               , private Observer<Setting>
29
{
30
public:
31
	using Pixel = uint32_t;
32
33
	V9990SDLRasterizer(
34
		V9990& vdp, Display& display, OutputSurface& screen,
35
		std::unique_ptr<PostProcessor> postProcessor);
36
	V9990SDLRasterizer(const V9990SDLRasterizer&) = delete;
37
	V9990SDLRasterizer(V9990SDLRasterizer&&) = delete;
38
	V9990SDLRasterizer& operator=(const V9990SDLRasterizer&) = delete;
39
	V9990SDLRasterizer& operator=(V9990SDLRasterizer&&) = delete;
40
	~V9990SDLRasterizer() override;
41
42
	// Rasterizer interface:
43
	[[nodiscard]] PostProcessor* getPostProcessor() const override;
44
	[[nodiscard]] bool isActive() override;
45
	void reset() override;
46
	void frameStart() override;
47
	void frameEnd(EmuTime time) override;
48
	void setDisplayMode(V9990DisplayMode displayMode) override;
49
	void setColorMode(V9990ColorMode colorMode) override;
50
	void setPalette(int index, uint8_t r, uint8_t g, uint8_t b, bool ys) override;
51
	void setSuperimpose(bool enabled) override;
52
	void drawBorder(int fromX, int fromY, int limitX, int limitY) override;
53
	void drawDisplay(int fromX, int fromY, int toX, int toY,
54
	                 int displayX,
55
	                 int displayY, int displayYA, int displayYB) override;
56
	[[nodiscard]] bool isRecording() const override;
57
58
	/** Fill the palettes.
59
	  */
60
	void preCalcPalettes();
61
	void resetPalette();
62
63
	void drawP1Mode(int fromX, int fromY, int displayX,
64
	                int displayY, int displayYA, int displayYB,
65
	                int displayWidth, int displayHeight, bool drawSprites);
66
	void drawP2Mode(int fromX, int fromY, int displayX,
67
	                int displayY, int displayYA,
68
	                int displayWidth, int displayHeight, bool drawSprites);
69
	void drawBxMode(int fromX, int fromY, int displayX,
70
	                int displayY, int displayYA,
71
	                int displayWidth, int displayHeight, bool drawSprites);
72
73
	// Observer<Setting>
74
	void update(const Setting& setting) noexcept override;
75
76
private:
77
	/** screen width for SDLLo
78
	  */
79
	static constexpr int SCREEN_WIDTH  = 320;
80
81
	/** screen height for SDLLo
82
	  */
83
	static constexpr int SCREEN_HEIGHT = 240;
84
85
	/** The VDP of which the video output is being rendered.
86
	  */
87
	V9990& vdp;
88
89
	/** The VRAM whose contents are rendered.
90
	  */
91
	V9990VRAM& vram;
92
93
	/** The surface which is visible to the user.
94
	  */
95
	OutputSurface& screen;
96
97
	/** The next frame as it is delivered by the VDP, work in progress.
98
	  */
99
	std::unique_ptr<RawFrame> workFrame;
100
101
	/** The current renderer settings (gamma, brightness, contrast)
102
	  */
103
	RenderSettings& renderSettings;
104
105
	/** Line to render at top of display.
106
	  * After all, our screen is 240 lines while display is 262 or 313.
107
	  */
108
	int lineRenderTop;
109
110
	/** First display column to draw.  Since the width of the VDP lines <=
111
	  * the screen width, colZero is <= 0. The non-displaying parts of the
112
	  * screen will be filled as border.
113
	  */
114
	int colZero;
115
116
	/** The current screen mode
117
	  */
118
	V9990DisplayMode displayMode = V9990DisplayMode::P1; // dummy value
119
	V9990ColorMode   colorMode   = V9990ColorMode::PP; //   avoid UMR
120
121
	/** Palette containing the complete V9990 Color space
122
	  */
123
	std::array<Pixel, 32768> palette32768;
124
125
	/** The 256 color palette. A fixed subset of the palette32768.
126
	  */
127
	std::array<Pixel, 256> palette256;         // from index to host Pixel color
128
	std::array<int16_t, 256> palette256_32768; // from index to 15bpp V9990 color
129
	// invariant: palette256[i] == palette32768[palette256_32768[i]]
130
131
	/** The 64 palette entries of the VDP - a subset of the palette32768.
132
	  * These are colors influenced by the palette IO ports and registers
133
	  */
134
	std::array<Pixel, 64> palette64;         // from index to host Pixel color
135
	std::array<int16_t, 64> palette64_32768; // from index to 15bpp V9990 color
136
	// invariant: palette64[i] == palette32768[palette64_32768[i]]
137
138
	/** The video post processor which displays the frames produced by this
139
	  *  rasterizer.
140
	  */
141
	const std::unique_ptr<PostProcessor> postProcessor;
142
143
	V9990BitmapConverter bitmapConverter;
144
	V9990P1Converter p1Converter;
145
	V9990P2Converter p2Converter;
146
};
147
148
} // namespace openmsx
149
150
#endif