openMSX
DisplayMode.hh
Go to the documentation of this file.
1#ifndef DISPLAYMODE_HH
2#define DISPLAYMODE_HH
3
4#include "openmsx.hh"
5#include "one_of.hh"
6
7namespace openmsx {
8
16{
17private:
18 constexpr explicit DisplayMode(byte mode_) : mode(mode_) {}
23 byte mode = 0;
24
25public:
26 enum {
27 GRAPHIC1 = 0x00, // Graphic 1
28 TEXT1 = 0x01, // Text 1
29 MULTICOLOR = 0x02, // Multicolor
30 GRAPHIC2 = 0x04, // Graphic 2
31 TEXT1Q = 0x05, // !!
32 MULTIQ = 0x06, // !!
33 GRAPHIC3 = 0x08, // Graphic 3
34 TEXT2 = 0x09, // Text 2
35 GRAPHIC4 = 0x0C, // Graphic 4
36 GRAPHIC5 = 0x10, // Graphic 5
37 GRAPHIC6 = 0x14, // Graphic 6
38 GRAPHIC7 = 0x1C // Graphic 7
39 };
40
42 static constexpr byte REG0_MASK = 0x0E;
43
45 static constexpr byte REG1_MASK = 0x18;
46
48 static constexpr byte REG25_MASK = 0x18;
49
51 static constexpr byte YJK = 0x20;
52
54 static constexpr byte YAE = 0x40;
55
58 constexpr DisplayMode() = default;
59
66 constexpr DisplayMode(byte reg0, byte reg1, byte reg25) {
67 if ((reg25 & 0x08) == 0) reg25 = 0; // If YJK is off, ignore YAE.
68 mode = byte(
69 ((reg25 & 0x18) << 2) | // YAE YJK
70 ((reg0 & 0x0E) << 1) | // M5..M3
71 ((reg1 & 0x08) >> 2) | // M2
72 ((reg1 & 0x10) >> 4)); // M1
73 }
74
75 [[nodiscard]] constexpr DisplayMode updateReg25(byte reg25) const {
76 if ((reg25 & 0x08) == 0) reg25 = 0; // If YJK is off, ignore YAE.
77 return DisplayMode(byte(getBase() | ((reg25 & 0x18) << 2)));
78 }
79
82 constexpr void reset() {
83 *this = DisplayMode();
84 }
85
88 [[nodiscard]] constexpr bool operator==(const DisplayMode&) const = default;
89
94 [[nodiscard]] constexpr byte getByte() const {
95 return mode;
96 }
97
99 constexpr void setByte(byte mode_) {
100 mode = mode_;
101 }
102
108 [[nodiscard]] constexpr byte getBase() const {
109 return mode & 0x1F;
110 }
111
115 [[nodiscard]] constexpr bool isV9938Mode() const {
116 return (mode & 0x18) != 0;
117 }
118
123 [[nodiscard]] constexpr bool isTextMode() const {
124 return getBase() == one_of(TEXT1, TEXT2, TEXT1Q);
125 }
126
131 [[nodiscard]] constexpr bool isBitmapMode() const {
132 return getBase() >= 0x0C;
133 }
134
141 [[nodiscard]] constexpr bool isPlanar() const {
142 // TODO: Is the display mode check OK? Profile undefined modes.
143 return (mode & 0x14) == 0x14;
144 }
145
148 [[nodiscard]] constexpr bool isSpriteNarrow() const {
149 // TODO: Check what happens to sprites in Graphic5 + YJK/YAE.
150 return mode == GRAPHIC5;
151 }
152
159 [[nodiscard]] constexpr int getSpriteMode(bool isMSX1) const {
160 switch (getBase()) {
161 case GRAPHIC1: case MULTICOLOR: case GRAPHIC2:
162 return 1;
163 case MULTIQ: // depends on VDP type
164 return isMSX1 ? 1 : 0;
165 case GRAPHIC3: case GRAPHIC4: case GRAPHIC5:
166 case GRAPHIC6: case GRAPHIC7:
167 return 2;
168 case TEXT1: case TEXT1Q: case TEXT2:
169 default: // and all other (bogus) modes
170 // Verified on real V9958: none of the bogus modes
171 // show sprites.
172 // TODO check on TMSxxxx
173 return 0;
174 }
175 }
176
181 [[nodiscard]] constexpr unsigned getLineWidth() const {
182 // Note: Testing "mode" instead of "base mode" ensures that YJK
183 // modes are treated as 256 pixels wide.
184 return mode == one_of(TEXT2, GRAPHIC5, GRAPHIC6)
185 ? 512
186 : 256;
187 }
188};
189
190} // namespace openmsx
191
192#endif
Represents a VDP display mode.
constexpr bool isSpriteNarrow() const
Are sprite pixels narrow?
constexpr DisplayMode updateReg25(byte reg25) const
constexpr byte getBase() const
Get the base display mode as an integer: M5..M1 combined.
constexpr void setByte(byte mode_)
Used for de-serialization.
constexpr bool isPlanar() const
Is VRAM "planar" in the current display mode? Graphic 6 and 7 spread their bytes over two VRAM ICs,...
constexpr unsigned getLineWidth() const
Get number of pixels on a display line in this mode.
constexpr bool operator==(const DisplayMode &) const =default
Equals operator.
constexpr bool isBitmapMode() const
Is the current mode a bitmap mode? Graphic4 and higher are bitmap modes.
constexpr DisplayMode()=default
Create the initial display mode.
static constexpr byte REG25_MASK
Bits of VDP register 25 that encode part of the display mode.
constexpr bool isV9938Mode() const
Was this mode introduced by the V9938?
static constexpr byte YAE
Encoding of YAE flag.
constexpr DisplayMode(byte reg0, byte reg1, byte reg25)
Create a specific display mode.
constexpr void reset()
Bring the display mode to its initial state.
static constexpr byte REG1_MASK
Bits of VDP register 1 that encode part of the display mode.
constexpr bool isTextMode() const
Is the current mode a text mode? Text1 and Text2 are text modes.
static constexpr byte YJK
Encoding of YJK flag.
constexpr byte getByte() const
Get the display mode as a byte: YAE YJK M5..M1 combined.
constexpr int getSpriteMode(bool isMSX1) const
Get the sprite mode of this display mode.
static constexpr byte REG0_MASK
Bits of VDP register 0 that encode part of the display mode.
This file implemented 3 utility functions:
Definition Autofire.cc:11
uint8_t byte
8 bit unsigned integer
Definition openmsx.hh:26