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 
7 namespace openmsx {
8 
16 {
17 private:
18  constexpr explicit DisplayMode(byte mode_) : mode(mode_) {}
23  byte mode = 0;
24 
25 public:
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 = ((reg25 & 0x18) << 2) // YAE YJK
69  | ((reg0 & 0x0E) << 1) // M5..M3
70  | ((reg1 & 0x08) >> 2) // M2
71  | ((reg1 & 0x10) >> 4); // M1
72  }
73 
74  constexpr DisplayMode updateReg25(byte reg25) const {
75  if ((reg25 & 0x08) == 0) reg25 = 0; // If YJK is off, ignore YAE.
76  return DisplayMode(getBase() | ((reg25 & 0x18) << 2));
77  }
78 
81  constexpr void reset() {
82  *this = DisplayMode();
83  }
84 
87  constexpr bool operator==(const DisplayMode& otherMode) const {
88  return mode == otherMode.mode;
89  }
90 
93  constexpr bool operator!=(const DisplayMode& otherMode) const {
94  return mode != otherMode.mode;
95  }
96 
101  constexpr byte getByte() const {
102  return mode;
103  }
104 
106  constexpr void setByte(byte mode_) {
107  mode = mode_;
108  }
109 
115  constexpr byte getBase() const {
116  return mode & 0x1F;
117  }
118 
122  constexpr bool isV9938Mode() const {
123  return (mode & 0x18) != 0;
124  }
125 
130  constexpr bool isTextMode() const {
131  return getBase() == one_of(TEXT1, TEXT2, TEXT1Q);
132  }
133 
138  constexpr bool isBitmapMode() const {
139  return getBase() >= 0x0C;
140  }
141 
148  constexpr bool isPlanar() const {
149  // TODO: Is the display mode check OK? Profile undefined modes.
150  return (mode & 0x14) == 0x14;
151  }
152 
155  constexpr bool isSpriteNarrow() const {
156  // TODO: Check what happens to sprites in Graphic5 + YJK/YAE.
157  return mode == GRAPHIC5;
158  }
159 
166  constexpr int getSpriteMode(bool isMSX1) const {
167  switch (getBase()) {
168  case GRAPHIC1: case MULTICOLOR: case GRAPHIC2:
169  return 1;
170  case MULTIQ: // depends on VDP type
171  return isMSX1 ? 1 : 0;
172  case GRAPHIC3: case GRAPHIC4: case GRAPHIC5:
173  case GRAPHIC6: case GRAPHIC7:
174  return 2;
175  case TEXT1: case TEXT1Q: case TEXT2:
176  default: // and all other (bogus) modes
177  // Verified on real V9958: none of the bogus modes
178  // show sprites.
179  // TODO check on TMSxxxx
180  return 0;
181  }
182  }
183 
188  constexpr unsigned getLineWidth() const {
189  // Note: Testing "mode" instead of "base mode" ensures that YJK
190  // modes are treated as 256 pixels wide.
191  return mode == one_of(TEXT2, GRAPHIC5, GRAPHIC6)
192  ? 512
193  : 256;
194  }
195 };
196 
197 } // namespace openmsx
198 
199 #endif
one_of.hh
openmsx.hh
openmsx::DisplayMode::REG0_MASK
static constexpr byte REG0_MASK
Bits of VDP register 0 that encode part of the display mode.
Definition: DisplayMode.hh:42
openmsx::DisplayMode::isV9938Mode
constexpr bool isV9938Mode() const
Was this mode introduced by the V9938?
Definition: DisplayMode.hh:122
openmsx::DisplayMode::GRAPHIC3
@ GRAPHIC3
Definition: DisplayMode.hh:33
openmsx::DisplayMode::isSpriteNarrow
constexpr bool isSpriteNarrow() const
Are sprite pixels narrow?
Definition: DisplayMode.hh:155
openmsx::DisplayMode::REG1_MASK
static constexpr byte REG1_MASK
Bits of VDP register 1 that encode part of the display mode.
Definition: DisplayMode.hh:45
openmsx::DisplayMode::setByte
constexpr void setByte(byte mode_)
Used for de-serialization.
Definition: DisplayMode.hh:106
openmsx::DisplayMode::GRAPHIC6
@ GRAPHIC6
Definition: DisplayMode.hh:37
openmsx::DisplayMode::GRAPHIC2
@ GRAPHIC2
Definition: DisplayMode.hh:30
openmsx::DisplayMode::isPlanar
constexpr bool isPlanar() const
Is VRAM "planar" in the current display mode? Graphic 6 and 7 spread their bytes over two VRAM ICs,...
Definition: DisplayMode.hh:148
openmsx::DisplayMode::YJK
static constexpr byte YJK
Encoding of YJK flag.
Definition: DisplayMode.hh:51
openmsx::DisplayMode::TEXT2
@ TEXT2
Definition: DisplayMode.hh:34
openmsx::DisplayMode::getBase
constexpr byte getBase() const
Get the base dispay mode as an integer: M5..M1 combined.
Definition: DisplayMode.hh:115
openmsx::DisplayMode::reset
constexpr void reset()
Bring the display mode to its initial state.
Definition: DisplayMode.hh:81
openmsx::DisplayMode::GRAPHIC7
@ GRAPHIC7
Definition: DisplayMode.hh:38
openmsx::DisplayMode::TEXT1
@ TEXT1
Definition: DisplayMode.hh:28
openmsx::DisplayMode
Represents a VDP display mode.
Definition: DisplayMode.hh:15
openmsx::DisplayMode::DisplayMode
constexpr DisplayMode()=default
Create the initial display mode.
one_of
Definition: one_of.hh:7
openmsx::DisplayMode::GRAPHIC5
@ GRAPHIC5
Definition: DisplayMode.hh:36
openmsx::DisplayMode::GRAPHIC1
@ GRAPHIC1
Definition: DisplayMode.hh:27
openmsx::DisplayMode::MULTIQ
@ MULTIQ
Definition: DisplayMode.hh:32
openmsx::DisplayMode::isTextMode
constexpr bool isTextMode() const
Is the current mode a text mode? Text1 and Text2 are text modes.
Definition: DisplayMode.hh:130
openmsx::DisplayMode::MULTICOLOR
@ MULTICOLOR
Definition: DisplayMode.hh:29
openmsx::DisplayMode::operator==
constexpr bool operator==(const DisplayMode &otherMode) const
Equals operator.
Definition: DisplayMode.hh:87
openmsx::DisplayMode::DisplayMode
constexpr DisplayMode(byte reg0, byte reg1, byte reg25)
Create a specific display mode.
Definition: DisplayMode.hh:66
openmsx::DisplayMode::getSpriteMode
constexpr int getSpriteMode(bool isMSX1) const
Get the sprite mode of this display mode.
Definition: DisplayMode.hh:166
openmsx::DisplayMode::GRAPHIC4
@ GRAPHIC4
Definition: DisplayMode.hh:35
openmsx::DisplayMode::REG25_MASK
static constexpr byte REG25_MASK
Bits of VDP register 25 that encode part of the display mode.
Definition: DisplayMode.hh:48
openmsx::DisplayMode::TEXT1Q
@ TEXT1Q
Definition: DisplayMode.hh:31
openmsx::DisplayMode::YAE
static constexpr byte YAE
Encoding of YAE flag.
Definition: DisplayMode.hh:54
openmsx::DisplayMode::getByte
constexpr byte getByte() const
Get the dispay mode as a byte: YAE YJK M5..M1 combined.
Definition: DisplayMode.hh:101
openmsx::DisplayMode::isBitmapMode
constexpr bool isBitmapMode() const
Is the current mode a bitmap mode? Graphic4 and higher are bitmap modes.
Definition: DisplayMode.hh:138
openmsx::DisplayMode::operator!=
constexpr bool operator!=(const DisplayMode &otherMode) const
Does-not-equal operator.
Definition: DisplayMode.hh:93
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::DisplayMode::updateReg25
constexpr DisplayMode updateReg25(byte reg25) const
Definition: DisplayMode.hh:74
openmsx::DisplayMode::getLineWidth
constexpr unsigned getLineWidth() const
Get number of pixels on a display line in this mode.
Definition: DisplayMode.hh:188