openMSX
ImGuiCharacter.cc
Go to the documentation of this file.
1#include "ImGuiCharacter.hh"
2
3#include "ImGuiCpp.hh"
4#include "ImGuiManager.hh"
5#include "ImGuiPalette.hh"
6#include "ImGuiUtils.hh"
7
8#include "DisplayMode.hh"
9#include "MSXMotherBoard.hh"
10#include "VDP.hh"
11#include "VDPVRAM.hh"
12
13#include "one_of.hh"
14#include "ranges.hh"
15#include "view.hh"
16
17#include <imgui.h>
18
19namespace openmsx {
20
21using namespace std::literals;
22
23void ImGuiCharacter::save(ImGuiTextBuffer& buf)
24{
25 savePersistent(buf, *this, persistentElements);
26}
27
28void ImGuiCharacter::loadLine(std::string_view name, zstring_view value)
29{
30 loadOnePersistent(name, value, *this, persistentElements);
31}
32
33void ImGuiCharacter::initHexDigits()
34{
35 smallHexDigits = gl::Texture(false, false); // no interpolation, no wrapping
36
37 // font definition: 16 glyphs 0-9 A-F, each 5 x 8 pixels
38 static constexpr int charWidth = 5;
39 static constexpr int charHeight = 8;
40 static constexpr int totalWidth = 16 * charWidth;
41 static constexpr int totalSize = totalWidth * charHeight;
42 static constexpr std::string_view glyphs =
43 " ... ... ................................................ ........ .........."
44 ".MMM...M. .MMM..MMM..M.M..MMM..MMM..MMM..MMM..MMM..MMM..MM....MM..MM...MMM..MMM."
45 ".M.M..MM. ...M....M..M.M..M....M......M..M.M..M.M..M.M..M.M..M....M.M..M....M..."
46 ".M.M...M. .MM..MMM..M.M..MMM..MMM. .M..MMM..MMM..MMM..MM...M. .M.M..MMM..MMM."
47 ".M.M. .M. .M.. ...M..MMM....M..M.M. .M..M.M....M..M.M..M.M..M. .M.M..M....M..."
48 ".M.M. .M. .M......M....M....M..M.M. .M..M.M....M..M.M..M.M..M....M.M..M....M. "
49 ".MMM. .M. .MMM..MMM. .M..MMM..MMM. .M..MMM..MMM..M.M..MM....MM..MM...MMM..M. "
50 " ... ... .......... ............. ...................... ........ ........ ";
51 static_assert(glyphs.size() == totalSize);
52
53 // transform to 32-bit RGBA
54 std::array<uint32_t, totalSize> pixels;
55 for (auto [c, p] : view::zip_equal(glyphs, pixels)) {
56 p = (c == ' ') ? ImColor(0.0f, 0.0f, 0.0f, 0.0f) // transparent
57 : (c == '.') ? ImColor(0.0f, 0.0f, 0.0f, 0.7f) // black semi-transparent outline
58 : ImColor(1.0f, 1.0f, 1.0f, 0.7f); // white semi-transparent
59 }
60
61 // and upload as a texture
62 smallHexDigits.bind();
63 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, totalWidth, charHeight, 0,
64 GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
65}
66
68{
69 if (!show || !motherBoard) return;
70 ImGui::SetNextWindowSize({686, 886}, ImGuiCond_FirstUseEver);
71 im::Window("Tile viewer", &show, [&]{
72 auto* vdp = dynamic_cast<VDP*>(motherBoard->findDevice("VDP")); // TODO name based OK?
73 if (!vdp) return;
74 const auto& vram = vdp->getVRAM().getData();
75
76 int vdpMode = [&] {
77 auto base = vdp->getDisplayMode().getBase();
78 if (base == DisplayMode::TEXT1) return TEXT40;
79 if (base == DisplayMode::TEXT2) return TEXT80;
80 if (base == DisplayMode::GRAPHIC1) return SCR1;
81 if (base == DisplayMode::GRAPHIC2) return SCR2;
82 if (base == DisplayMode::GRAPHIC3) return SCR4;
83 if (base == DisplayMode::MULTICOLOR) return SCR3;
84 return OTHER;
85 }();
86 auto modeToStr = [](int mode) {
87 if (mode == TEXT40) return "screen 0, width 40";
88 if (mode == TEXT80) return "screen 0, width 80";
89 if (mode == SCR1) return "screen 1";
90 if (mode == SCR2) return "screen 2";
91 if (mode == SCR3) return "screen 3";
92 if (mode == SCR4) return "screen 4";
93 if (mode == OTHER) return "non-character";
94 assert(false); return "ERROR";
95 };
96 auto patMult = [](int mode) { return 1 << (mode == one_of(SCR2, SCR4) ? 13 : 11); };
97 auto colMult = [](int mode) { return 1 << (mode == one_of(SCR2, SCR4) ? 13 :
98 mode == TEXT80 ? 9 : 6); };
99 auto namMult = [](int mode) { return 1 << (mode == TEXT80 ? 12 : 10); };
100 int vdpFgCol = vdp->getForegroundColor() & 15;
101 int vdpBgCol = vdp->getBackgroundColor() & 15;
102 int vdpFgBlink = vdp->getBlinkForegroundColor() & 15;
103 int vdpBgBlink = vdp->getBlinkBackgroundColor() & 15;
104 bool vdpBlink = vdp->getBlinkState();
105 int vdpPatBase = vdp->getPatternTableBase() & ~(patMult(vdpMode) - 1);
106 int vdpColBase = vdp->getColorTableBase() & ~(colMult(vdpMode) - 1);
107 int vdpNamBase = vdp->getNameTableBase() & ~(namMult(vdpMode) - 1);
108 int vdpLines = vdp->getNumberOfLines();
109 int vdpColor0 = vdp->getTransparency() ? vdpBgCol
110 : 16; // no replacement
111
112 im::TreeNode("Settings", ImGuiTreeNodeFlags_DefaultOpen, [&]{
113 static const char* const color0Str = "0\0001\0002\0003\0004\0005\0006\0007\0008\0009\00010\00011\00012\00013\00014\00015\000none\000";
114 im::Group([&]{
115 ImGui::RadioButton("Use VDP settings", &manual, 0);
116 im::Disabled(manual != 0, [&]{
117 ImGui::AlignTextToFramePadding();
118 ImGui::StrCat("Screen mode: ", modeToStr(vdpMode));
119 ImGui::AlignTextToFramePadding();
120 ImGui::StrCat("Foreground color: ", vdpFgCol);
121 ImGui::AlignTextToFramePadding();
122 ImGui::StrCat("Background color: ", vdpBgCol);
123 ImGui::AlignTextToFramePadding();
124 ImGui::StrCat("Foreground blink color: ", vdpFgBlink);
125 ImGui::AlignTextToFramePadding();
126 ImGui::StrCat("Background blink color: ", vdpBgBlink);
127 ImGui::AlignTextToFramePadding();
128 ImGui::StrCat("Blink: ", vdpBlink ? "enabled" : "disabled");
129 ImGui::AlignTextToFramePadding();
130 ImGui::StrCat("Pattern table: 0x", hex_string<5>(vdpPatBase));
131 ImGui::AlignTextToFramePadding();
132 ImGui::StrCat("Color table: 0x", hex_string<5>(vdpColBase));
133 ImGui::AlignTextToFramePadding();
134 ImGui::StrCat("Name table: 0x", hex_string<5>(vdpNamBase));
135 ImGui::AlignTextToFramePadding();
136 ImGui::StrCat("Visible rows: ", (vdpLines == 192) ? "24" : "26.5");
137 ImGui::AlignTextToFramePadding();
138 ImGui::StrCat("Replace color 0: ", getComboString(vdpColor0, color0Str));
139 });
140 });
141 ImGui::SameLine();
142 im::Group([&]{
143 ImGui::RadioButton("Manual override", &manual, 1);
144 im::Disabled(manual != 1, [&]{
145 im::ItemWidth(ImGui::GetFontSize() * 9.0f, [&]{
146 ImGui::Combo("##mode", &manualMode, "screen 0,40\000screen 0,80\000screen 1\000screen 2\000screen 3\000screen 4\000");
147 static const char* const range0_15 = "0\0001\0002\0003\0004\0005\0006\0007\0008\0009\00010\00011\00012\00013\00014\00015\000";
148 im::Disabled(manualMode != one_of(TEXT40, TEXT80), [&]{
149 ImGui::Combo("##fgCol", &manualFgCol, range0_15);
150 ImGui::Combo("##bgCol", &manualBgCol, range0_15);
151 });
152 im::Disabled(manualMode != TEXT80, [&]{
153 ImGui::Combo("##fgBlink", &manualFgBlink, range0_15);
154 ImGui::Combo("##bgBlink", &manualBgBlink, range0_15);
155 ImGui::Combo("##blink", &manualBlink, "disabled\000enabled\000");
156 });
157 comboHexSequence<5>("##pattern", &manualPatBase, patMult(manualMode));
158 im::Disabled(manualMode == one_of(TEXT40, SCR3), [&]{
159 comboHexSequence<5>("##color", &manualColBase, colMult(manualMode));
160 });
161 comboHexSequence<5>("##name", &manualNamBase, namMult(manualMode));
162 ImGui::Combo("##rows", &manualRows, "24\00026.5\00032\000");
163 ImGui::Combo("##Color 0 replacement", &manualColor0, color0Str);
164 });
165 });
166 });
167
168 ImGui::SameLine();
169 ImGui::Dummy(ImVec2(25, 1));
170 ImGui::SameLine();
171 im::Group([&]{
172 ImGui::SetNextItemWidth(ImGui::GetFontSize() * 10.0f);
173 ImGui::Combo("Palette", &manager.palette->whichPalette, "VDP\000Custom\000Fixed\000");
174 if (ImGui::Button("Open palette editor")) {
175 manager.palette->window.raise();
176 }
177 ImGui::Separator();
178 ImGui::SetNextItemWidth(ImGui::GetFontSize() * 3.0f);
179 ImGui::Combo("Zoom", &zoom, "1x\0002x\0003x\0004x\0005x\0006x\0007x\0008x\000");
180 ImGui::Checkbox("grid", &grid);
181 ImGui::SameLine();
182 im::Disabled(!grid, [&]{
183 ImGui::ColorEdit4("Grid color", gridColor.data(),
184 ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_AlphaBar);
185 });
186 ImGui::Checkbox("Name table overlay", &nameTableOverlay);
187 });
188 });
189 int manualLines = (manualRows == 0) ? 192
190 : (manualRows == 1) ? 212
191 : 256;
192
193 int mode = manual ? manualMode : vdpMode;
194 if (mode == SCR4) mode = SCR2;
195
196 int patBase = manual ? manualPatBase : vdpPatBase;
197 int colBase = manual ? manualColBase : vdpColBase;
198 int namBase = manual ? manualNamBase : vdpNamBase;
199 int lines = manual ? manualLines : vdpLines;
200 int color0 = manual ? manualColor0 : vdpColor0;
201
202 assert((patBase % patMult(mode)) == 0);
203 assert((colBase % colMult(mode)) == 0);
204 assert((namBase % namMult(mode)) == 0);
205
206 std::array<uint32_t, 16> palette;
207 auto msxPalette = manager.palette->getPalette(vdp);
208 ranges::transform(msxPalette, palette.data(),
209 [](uint16_t msx) { return ImGuiPalette::toRGBA(msx); });
210 if (color0 < 16) palette[0] = palette[color0];
211
212 auto fgCol = manual ? manualFgCol : vdpFgCol;
213 auto bgCol = manual ? manualBgCol : vdpBgCol;
214 auto fgBlink = manual ? manualFgBlink : vdpFgBlink;
215 auto bgBlink = manual ? manualBgBlink : vdpBgBlink;
216 auto blink = manual ? bool(manualBlink) : vdpBlink;
217
218 bool narrow = mode == TEXT80;
219 int zx = (1 + zoom) * (narrow ? 1 : 2);
220 int zy = (1 + zoom) * 2;
221 gl::vec2 zm{float(zx), float(zy)};
222
223 // Render the patterns to a texture, we need this both to display the name-table and the pattern-table
224 auto patternTexSize = [&]() -> gl::ivec2 {
225 if (mode == TEXT40) return {192, 64}; // 8 rows of 32 characters, each 6x8 pixels
226 if (mode == TEXT80) return {192, 128}; // 8 rows of 32 characters, each 6x8 pixels, x2 for blink
227 if (mode == SCR1) return {256, 64}; // 8 rows of 32 characters, each 8x8 pixels
228 if (mode == SCR2) return {256, lines == 192 ? 192 : 256}; // 8 rows of 32 characters, each 8x8 pixels, all this 3 or 4 times
229 if (mode == SCR3) return { 64, 64}; // 8 rows of 32 characters, each 2x2 pixels, all this 4 times
230 return {1, 1}; // OTHER -> dummy
231 }();
232 auto patternTexChars = [&]() -> gl::vec2 {
233 if (mode == SCR3) return {32.0f, 32.0f};
234 if (mode == SCR2) return {32.0f, lines == 192 ? 24.0f : 32.0f};
235 if (mode == TEXT80) return {32.0f, 16.0f};
236 return {32.0f, 8.0f};
237 }();
238 auto recipPatTexChars = recip(patternTexChars);
239 auto patternDisplaySize = [&]() -> gl::ivec2 {
240 if (mode == TEXT40) return {192, 64};
241 if (mode == TEXT80) return {192, 128};
242 if (mode == SCR2) return {256, lines == 192 ? 192 : 256};
243 if (mode == SCR3) return {256, 256};
244 return {256, 64}; // SCR1, OTHER
245 }();
246 std::array<uint32_t, 256 * 256> pixels; // max size for SCR2
247 renderPatterns(mode, vram, palette, fgCol, bgCol, fgBlink, bgBlink, patBase, colBase, lines, pixels);
248 if (!patternTex.get()) {
249 patternTex = gl::Texture(false, false); // no interpolation, no wrapping
250 }
251 patternTex.bind();
252 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, patternTexSize.x, patternTexSize.y, 0,
253 GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
254
255 // create grid texture
256 auto charWidth = mode == one_of(TEXT40, TEXT80) ? 6 : 8;
257 auto charSize = gl::vec2{float(charWidth), 8.0f};
258 auto charZoom = zm * charSize;
259 auto zoomCharSize = gl::vec2(narrow ? 6.0f : 12.0f, 12.0f) * charSize; // hovered size
260 if (grid) {
261 auto gColor = ImGui::ColorConvertFloat4ToU32(gridColor);
262 auto gridWidth = charWidth * zx;
263 auto gridHeight = 8 * zy;
264 for (auto y : xrange(gridHeight)) {
265 auto* line = &pixels[y * gridWidth];
266 for (auto x : xrange(gridWidth)) {
267 line[x] = (x == 0 || y == 0) ? gColor : 0;
268 }
269 }
270 if (!gridTex.get()) {
271 gridTex = gl::Texture(false, true); // no interpolation, with wrapping
272 }
273 gridTex.bind();
274 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, gridWidth, gridHeight, 0,
275 GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
276 }
277 if (nameTableOverlay && !smallHexDigits.get()) {
278 initHexDigits();
279 }
280
281 ImGui::Separator();
282 im::TreeNode("Pattern Table", ImGuiTreeNodeFlags_DefaultOpen, [&]{
283 auto size = gl::vec2(patternDisplaySize) * zm;
284 im::Child("##pattern", {0, size.y}, 0, ImGuiWindowFlags_HorizontalScrollbar, [&]{
285 auto pos1 = ImGui::GetCursorPos();
286 gl::vec2 scrnPos = ImGui::GetCursorScreenPos();
287 ImGui::Image(patternTex.getImGui(), size);
288 bool hovered = ImGui::IsItemHovered() && (mode != OTHER);
289 ImGui::SameLine();
290 im::Group([&]{
291 if (hovered) {
292 auto gridPos = trunc((gl::vec2(ImGui::GetIO().MousePos) - scrnPos) / charZoom);
293 ImGui::StrCat("Pattern: ", gridPos.x + 32 * gridPos.y);
294 auto uv1 = gl::vec2(gridPos) * recipPatTexChars;
295 auto uv2 = uv1 + recipPatTexChars;
296 auto pos2 = ImGui::GetCursorPos();
297 ImGui::Image(patternTex.getImGui(), zoomCharSize, uv1, uv2);
298 if (grid) {
299 ImGui::SetCursorPos(pos2);
300 ImGui::Image(gridTex.getImGui(),
301 zoomCharSize, {}, charSize);
302 }
303 } else {
304 ImGui::Dummy(zoomCharSize);
305 }
306 });
307 if (grid) {
308 ImGui::SetCursorPos(pos1);
309 ImGui::Image(gridTex.getImGui(), size,
310 {}, patternTexChars);
311 }
312 });
313 });
314 ImGui::Separator();
315 im::TreeNode("Name Table", ImGuiTreeNodeFlags_DefaultOpen, [&]{
316 float rows = float(lines) * (1.0f / 8.0f); // 24, 26.5 or 32
317 auto columns = [&] {
318 if (mode == TEXT40) return 40;
319 if (mode == TEXT80) return 80;
320 return 32;
321 }();
322 auto charsSize = gl::vec2(float(columns), rows); // (x * y) number of characters
323 auto msxSize = charSize * charsSize; // (x * y) number of MSX pixels
324 auto hostSize = msxSize * zm; // (x * y) number of host pixels
325
326 im::Child("##name", {0.0f, hostSize.y}, 0, ImGuiWindowFlags_HorizontalScrollbar, [&]{
327 gl::vec2 scrnPos = ImGui::GetCursorScreenPos();
328 auto* drawList = ImGui::GetWindowDrawList();
329
330 auto getPattern = [&](unsigned column, unsigned row) {
331 auto block = [&]() -> unsigned {
332 if (mode == TEXT80 && blink) {
333 auto colPat = vram[colBase + 10 * row + (column / 8)];
334 return (colPat & (0x80 >> (column % 8))) ? 1 : 0;
335 }
336 if (mode == SCR2) return row / 8;
337 if (mode == SCR3) return row % 4;
338 return 0;
339 }();
340 return vram[namBase + columns * row + column] + 256 * block;
341 };
342 auto getPatternUV = [&](unsigned pattern) -> std::pair<gl::vec2, gl::vec2> {
343 auto patRow = pattern / 32;
344 auto patCol = pattern % 32;
345 gl::vec2 uv1 = gl::vec2{float(patCol), float(patRow)} * recipPatTexChars;
346 gl::vec2 uv2 = uv1 + recipPatTexChars;
347 return {uv1, uv2};
348 };
349
350 if (mode == OTHER) {
351 drawList->AddRectFilled(scrnPos, scrnPos + hostSize, getColor(imColor::GRAY));
352 } else {
353 auto rowsCeil = int(ceilf(rows));
354 auto numChars = rowsCeil * columns;
355 drawList->PushClipRect(scrnPos, scrnPos + hostSize, true);
356 drawList->PushTextureID(patternTex.getImGui());
357 drawList->PrimReserve(6 * numChars, 4 * numChars);
358 for (auto row : xrange(rowsCeil)) {
359 for (auto column : xrange(columns)) {
360 gl::vec2 p1 = scrnPos + charZoom * gl::vec2{float(column), float(row)};
361 gl::vec2 p2 = p1 + charZoom;
362 auto pattern = getPattern(column, row);
363 auto [uv1, uv2] = getPatternUV(pattern);
364 drawList->PrimRectUV(p1, p2, uv1, uv2, 0xffffffff);
365 }
366 }
367 drawList->PopTextureID();
368 if (nameTableOverlay) {
369 drawList->PushTextureID(smallHexDigits.getImGui());
370 drawList->PrimReserve(12 * numChars, 8 * numChars);
371 static constexpr gl::vec2 digitSize{5.0f, 8.0f};
372 static constexpr float texDigitWidth = 1.0f / 16.0f;
373 static constexpr gl::vec2 texDigitSize{texDigitWidth, 1.0f};
374 auto digitOffset = narrow ? gl::vec2{0.0f, digitSize.y} : gl::vec2{digitSize.x, 0.0f};
375 for (auto row : xrange(rowsCeil)) {
376 for (auto column : xrange(columns)) {
377 gl::vec2 p1 = scrnPos + charZoom * gl::vec2{float(column), float(row)};
378 gl::vec2 p2 = p1 + digitOffset;
379 auto pattern = getPattern(column, row);
380 gl::vec2 uv1{narrow_cast<float>(pattern >> 4) * texDigitWidth, 0.0f};
381 gl::vec2 uv2{(pattern & 15) * texDigitWidth, 0.0f};
382 drawList->PrimRectUV(p1, p1 + digitSize, uv1, uv1 + texDigitSize, 0xffffffff);
383 drawList->PrimRectUV(p2, p2 + digitSize, uv2, uv2 + texDigitSize, 0xffffffff);
384 }
385 }
386 drawList->PopTextureID();
387 }
388 drawList->PopClipRect();
389 }
390
391 auto pos1 = ImGui::GetCursorPos();
392 ImGui::Dummy(hostSize);
393 bool hovered = ImGui::IsItemHovered() && (mode != OTHER);
394 ImGui::SameLine();
395 im::Group([&]{
396 if (hovered) {
397 auto gridPos = trunc((gl::vec2(ImGui::GetIO().MousePos) - scrnPos) / charZoom);
398 ImGui::StrCat("Column: ", gridPos.x, " Row: ", gridPos.y);
399 auto pattern = getPattern(gridPos.x, gridPos.y);
400 ImGui::StrCat("Pattern: ", pattern);
401 auto [uv1, uv2] = getPatternUV(pattern);
402 auto pos2 = ImGui::GetCursorPos();
403 ImGui::Image(patternTex.getImGui(), zoomCharSize, uv1, uv2);
404 if (grid) {
405 ImGui::SetCursorPos(pos2);
406 ImGui::Image(gridTex.getImGui(),
407 zoomCharSize, {}, charSize);
408 }
409 } else {
410 gl::vec2 textSize = ImGui::CalcTextSize("Column: 31 Row: 23"sv);
411 ImGui::Dummy(max(zoomCharSize, textSize));
412 }
413 });
414 if (grid) {
415 ImGui::SetCursorPos(pos1);
416 ImGui::Image(gridTex.getImGui(), hostSize, {}, charsSize);
417 }
418 });
419 });
420 });
421}
422
423static void draw6(uint8_t pattern, uint32_t fgCol, uint32_t bgCol, std::span<uint32_t, 6> out)
424{
425 out[0] = (pattern & 0x80) ? fgCol : bgCol;
426 out[1] = (pattern & 0x40) ? fgCol : bgCol;
427 out[2] = (pattern & 0x20) ? fgCol : bgCol;
428 out[3] = (pattern & 0x10) ? fgCol : bgCol;
429 out[4] = (pattern & 0x08) ? fgCol : bgCol;
430 out[5] = (pattern & 0x04) ? fgCol : bgCol;
431}
432
433static void draw8(uint8_t pattern, uint32_t fgCol, uint32_t bgCol, std::span<uint32_t, 8> out)
434{
435 out[0] = (pattern & 0x80) ? fgCol : bgCol;
436 out[1] = (pattern & 0x40) ? fgCol : bgCol;
437 out[2] = (pattern & 0x20) ? fgCol : bgCol;
438 out[3] = (pattern & 0x10) ? fgCol : bgCol;
439 out[4] = (pattern & 0x08) ? fgCol : bgCol;
440 out[5] = (pattern & 0x04) ? fgCol : bgCol;
441 out[6] = (pattern & 0x02) ? fgCol : bgCol;
442 out[7] = (pattern & 0x01) ? fgCol : bgCol;
443}
444
445void ImGuiCharacter::renderPatterns(int mode, std::span<const uint8_t> vram, std::span<const uint32_t, 16> palette,
446 int fgCol, int bgCol, int fgBlink, int bgBlink,
447 int patBase, int colBase, int lines, std::span<uint32_t> output)
448{
449 switch (mode) {
450 case TEXT40:
451 case TEXT80: {
452 auto fg = palette[fgCol];
453 auto bg = palette[bgCol];
454 auto fgB = palette[fgBlink];
455 auto bgB = palette[bgBlink];
456 for (auto row : xrange(8)) {
457 for (auto column : xrange(32)) {
458 auto patNum = 32 * row + column;
459 auto addr = patBase + 8 * patNum;
460 for (auto y : xrange(8)) {
461 auto pattern = vram[addr + y];
462 auto out = subspan<6>(output, (8 * row + y) * 192 + 6 * column);
463 draw6(pattern, fg, bg, out);
464 if (mode == TEXT80) {
465 auto out2 = subspan<6>(output, (64 + 8 * row + y) * 192 + 6 * column);
466 draw6(pattern, fgB, bgB, out2);
467 }
468 }
469 }
470 }
471 break;
472 }
473 case SCR1:
474 for (auto row : xrange(8)) {
475 for (auto group : xrange(4)) { // 32 columns, split in 4 groups of 8
476 auto color = vram[colBase + 4 * row + group];
477 auto fg = palette[color >> 4];
478 auto bg = palette[color & 15];
479 for (auto subColumn : xrange(8)) {
480 auto column = 8 * group + subColumn;
481 auto patNum = 32 * row + column;
482 auto addr = patBase + 8 * patNum;
483 for (auto y : xrange(8)) {
484 auto pattern = vram[addr + y];
485 auto out = subspan<8>(output, (8 * row + y) * 256 + 8 * column);
486 draw8(pattern, fg, bg, out);
487 }
488 }
489 }
490 }
491 break;
492 case SCR2:
493 for (auto row : xrange((lines == 192 ? 3 : 4) * 8)) {
494 for (auto column : xrange(32)) {
495 auto patNum = 32 * row + column;
496 auto patAddr = patBase + 8 * patNum;
497 auto colAddr = colBase + 8 * patNum;
498 for (auto y : xrange(8)) {
499 auto pattern = vram[patAddr + y];
500 auto color = vram[colAddr + y];
501 auto fg = palette[color >> 4];
502 auto bg = palette[color & 15];
503 auto out = subspan<8>(output, (8 * row + y) * 256 + 8 * column);
504 draw8(pattern, fg, bg, out);
505 }
506 }
507 }
508 break;
509 case SCR3:
510 for (auto group : xrange(4)) {
511 for (auto row : xrange(8)) {
512 for (auto column : xrange(32)) {
513 auto patNum = 32 * row + column;
514 auto patAddr = patBase + 8 * patNum + 2 * group;
515 for (auto y : xrange(2)) {
516 auto out = subspan<2>(output, (16 * group + 2 * row + y) * 64 + 2 * column);
517 auto pattern = vram[patAddr + y];
518 out[0] = palette[pattern >> 4];
519 out[1] = palette[pattern & 15];
520 }
521 }
522 }
523 }
524 break;
525 default:
526 output[0] = getColor(imColor::GRAY);
527 break;
528 }
529}
530
531} // namespace openmsx
Most basic/generic texture: only contains a texture ID.
Definition GLUtil.hh:39
void bind() const
Makes this texture the active GL texture.
Definition GLUtil.hh:84
GLuint get() const
Returns the underlying openGL handler id.
Definition GLUtil.hh:73
void * getImGui() const
Return as a 'void*' (needed for 'Dear ImGui').
Definition GLUtil.hh:77
void paint(MSXMotherBoard *motherBoard) override
void save(ImGuiTextBuffer &buf) override
void loadLine(std::string_view name, zstring_view value) override
std::unique_ptr< ImGuiPalette > palette
ImGuiManager & manager
Definition ImGuiPart.hh:30
MSXDevice * findDevice(std::string_view name)
Find a MSXDevice by name.
std::span< const uint8_t > getData() const
Only used by debugger.
Definition VDPVRAM.hh:560
Unified implementation of MSX Video Display Processors (VDPs).
Definition VDP.hh:66
VDPVRAM & getVRAM()
Get the VRAM object for this VDP.
Definition VDP.hh:161
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
void StrCat(Ts &&...ts)
Definition ImGuiUtils.hh:43
auto CalcTextSize(std::string_view str)
Definition ImGuiUtils.hh:37
vecN< 2, float > vec2
Definition gl_vec.hh:178
void Window(const char *name, bool *p_open, ImGuiWindowFlags flags, std::invocable<> auto next)
Definition ImGuiCpp.hh:63
bool TreeNode(const char *label, ImGuiTreeNodeFlags flags, std::invocable<> auto next)
Definition ImGuiCpp.hh:326
void ItemWidth(float item_width, std::invocable<> auto next)
Definition ImGuiCpp.hh:224
void Child(const char *str_id, const ImVec2 &size, ImGuiChildFlags child_flags, ImGuiWindowFlags window_flags, std::invocable<> auto next)
Definition ImGuiCpp.hh:110
void Disabled(bool b, std::invocable<> auto next)
Definition ImGuiCpp.hh:530
void Group(std::invocable<> auto next)
Definition ImGuiCpp.hh:256
This file implemented 3 utility functions:
Definition Autofire.cc:11
bool loadOnePersistent(std::string_view name, zstring_view value, C &c, const std::tuple< Elements... > &tup)
void savePersistent(ImGuiTextBuffer &buf, C &c, const std::tuple< Elements... > &tup)
ImU32 getColor(imColor col)
const char * getComboString(int item, const char *itemsSeparatedByZeros)
auto transform(InputRange &&range, OutputIter out, UnaryOperation op)
Definition ranges.hh:269
Definition view.hh:15
constexpr To narrow(From from) noexcept
Definition narrow.hh:37
constexpr auto xrange(T e)
Definition xrange.hh:132