| 1 |
#ifndef DISPLAYMODE_HH |
| 2 |
#define DISPLAYMODE_HH |
| 3 |
|
| 4 |
#include "one_of.hh" |
| 5 |
|
| 6 |
#include <cstdint> |
| 7 |
|
| 8 |
namespace openmsx { |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
class DisplayMode |
| 17 |
{ |
| 18 |
private: |
| 19 |
constexpr explicit DisplayMode(uint8_t mode_) : mode(mode_) {} |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
uint8_t mode = 0; |
| 25 |
|
| 26 |
public: |
| 27 |
static constexpr uint8_t GRAPHIC1 = 0x00; |
| 28 |
static constexpr uint8_t TEXT1 = 0x01; |
| 29 |
static constexpr uint8_t MULTICOLOR = 0x02; |
| 30 |
static constexpr uint8_t GRAPHIC2 = 0x04; |
| 31 |
static constexpr uint8_t TEXT1Q = 0x05; |
| 32 |
static constexpr uint8_t MULTIQ = 0x06; |
| 33 |
static constexpr uint8_t GRAPHIC3 = 0x08; |
| 34 |
static constexpr uint8_t TEXT2 = 0x09; |
| 35 |
static constexpr uint8_t GRAPHIC4 = 0x0C; |
| 36 |
static constexpr uint8_t GRAPHIC5 = 0x10; |
| 37 |
static constexpr uint8_t GRAPHIC6 = 0x14; |
| 38 |
static constexpr uint8_t GRAPHIC7 = 0x1C; |
| 39 |
|
| 40 |
|
| 41 |
static constexpr uint8_t REG0_MASK = 0x0E; |
| 42 |
|
| 43 |
|
| 44 |
static constexpr uint8_t REG1_MASK = 0x18; |
| 45 |
|
| 46 |
|
| 47 |
static constexpr uint8_t REG25_MASK = 0x18; |
| 48 |
|
| 49 |
|
| 50 |
static constexpr uint8_t YJK = 0x20; |
| 51 |
|
| 52 |
|
| 53 |
static constexpr uint8_t YAE = 0x40; |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
constexpr DisplayMode() = default; |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
constexpr DisplayMode(uint8_t reg0, uint8_t reg1, uint8_t reg25) { |
| 66 |
if ((reg25 & 0x08) == 0) reg25 = 0; |
| 67 |
mode = uint8_t( |
| 68 |
((reg25 & 0x18) << 2) | |
| 69 |
((reg0 & 0x0E) << 1) | |
| 70 |
((reg1 & 0x08) >> 2) | |
| 71 |
((reg1 & 0x10) >> 4)); |
| 72 |
} |
| 73 |
|
| 74 |
[[nodiscard]] constexpr DisplayMode updateReg25(uint8_t reg25) const { |
| 75 |
if ((reg25 & 0x08) == 0) reg25 = 0; |
| 76 |
return DisplayMode(uint8_t(getBase() | ((reg25 & 0x18) << 2))); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
constexpr void reset() { |
| 82 |
*this = DisplayMode(); |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
[[nodiscard]] constexpr bool operator==(const DisplayMode&) const = default; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
[[nodiscard]] constexpr uint8_t getByte() const { |
| 94 |
return mode; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
constexpr void setByte(uint8_t mode_) { |
| 99 |
mode = mode_; |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
[[nodiscard]] constexpr uint8_t getBase() const { |
| 108 |
return mode & 0x1F; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
[[nodiscard]] constexpr bool isV9938Mode() const { |
| 115 |
return (mode & 0x18) != 0; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
[[nodiscard]] constexpr bool isTextMode() const { |
| 123 |
return getBase() == one_of(TEXT1, TEXT2, TEXT1Q); |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
[[nodiscard]] constexpr bool isBitmapMode() const { |
| 131 |
return getBase() >= 0x0C; |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
[[nodiscard]] constexpr bool isPlanar() const { |
| 141 |
|
| 142 |
return (mode & 0x14) == 0x14; |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
[[nodiscard]] constexpr bool isSpriteNarrow() const { |
| 148 |
|
| 149 |
return mode == GRAPHIC5; |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
[[nodiscard]] constexpr int getSpriteMode(bool isMSX1) const { |
| 159 |
switch (getBase()) { |
| 160 |
case GRAPHIC1: case MULTICOLOR: case GRAPHIC2: |
| 161 |
return 1; |
| 162 |
case MULTIQ: |
| 163 |
return isMSX1 ? 1 : 0; |
| 164 |
case GRAPHIC3: case GRAPHIC4: case GRAPHIC5: |
| 165 |
case GRAPHIC6: case GRAPHIC7: |
| 166 |
return 2; |
| 167 |
case TEXT1: case TEXT1Q: case TEXT2: |
| 168 |
default: |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
return 0; |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
[[nodiscard]] constexpr unsigned getLineWidth() const { |
| 181 |
|
| 182 |
|
| 183 |
return mode == one_of(TEXT2, GRAPHIC5, GRAPHIC6) |
| 184 |
? 512 |
| 185 |
: 256; |
| 186 |
} |
| 187 |
}; |
| 188 |
|
| 189 |
} |
| 190 |
|
| 191 |
#endif |