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 lines = manual ? manualLines : vdpLines;
197 int color0 = manual ? manualColor0 : vdpColor0;
198
199 VramTable patTable(vram);
200 unsigned patReg = (manual ? manualPatBase : vdp->getPatternTableBase()) >> 11;
201 patTable.setRegister(patReg, 11);
202
203 VramTable colTable(vram);
204 unsigned colReg = (manual ? manualColBase : vdp->getColorTableBase()) >> 6;
205 colTable.setRegister(colReg, 6);
206
207 VramTable namTable(vram);
208 unsigned namReg = (manual ? manualNamBase : vdp->getNameTableBase()) >> 10;
209 namTable.setRegister(namReg, 10);
210 namTable.setIndexSize((mode == TEXT80) ? 12 : 10);
211
212 std::array<uint32_t, 16> palette;
213 auto msxPalette = manager.palette->getPalette(vdp);
214 ranges::transform(msxPalette, palette.data(),
215 [](uint16_t msx) { return ImGuiPalette::toRGBA(msx); });
216 if (color0 < 16) palette[0] = palette[color0];
217
218 auto fgCol = manual ? manualFgCol : vdpFgCol;
219 auto bgCol = manual ? manualBgCol : vdpBgCol;
220 auto fgBlink = manual ? manualFgBlink : vdpFgBlink;
221 auto bgBlink = manual ? manualBgBlink : vdpBgBlink;
222 auto blink = manual ? bool(manualBlink) : vdpBlink;
223
224 bool narrow = mode == TEXT80;
225 int zx = (1 + zoom) * (narrow ? 1 : 2);
226 int zy = (1 + zoom) * 2;
227 gl::vec2 zm{float(zx), float(zy)};
228
229 // Render the patterns to a texture, we need this both to display the name-table and the pattern-table
230 auto patternTexSize = [&]() -> gl::ivec2 {
231 if (mode == TEXT40) return {192, 64}; // 8 rows of 32 characters, each 6x8 pixels
232 if (mode == TEXT80) return {192, 128}; // 8 rows of 32 characters, each 6x8 pixels, x2 for blink
233 if (mode == SCR1) return {256, 64}; // 8 rows of 32 characters, each 8x8 pixels
234 if (mode == SCR2) return {256, lines == 192 ? 192 : 256}; // 8 rows of 32 characters, each 8x8 pixels, all this 3 or 4 times
235 if (mode == SCR3) return { 64, 64}; // 8 rows of 32 characters, each 2x2 pixels, all this 4 times
236 return {1, 1}; // OTHER -> dummy
237 }();
238 auto patternTexChars = [&]() -> gl::vec2 {
239 if (mode == SCR3) return {32.0f, 32.0f};
240 if (mode == SCR2) return {32.0f, lines == 192 ? 24.0f : 32.0f};
241 if (mode == TEXT80) return {32.0f, 16.0f};
242 return {32.0f, 8.0f};
243 }();
244 auto recipPatTexChars = recip(patternTexChars);
245 auto patternDisplaySize = [&]() -> gl::ivec2 {
246 if (mode == TEXT40) return {192, 64};
247 if (mode == TEXT80) return {192, 128};
248 if (mode == SCR2) return {256, lines == 192 ? 192 : 256};
249 if (mode == SCR3) return {256, 256};
250 return {256, 64}; // SCR1, OTHER
251 }();
252 std::array<uint32_t, 256 * 256> pixels; // max size for SCR2
253 renderPatterns(mode, palette, fgCol, bgCol, fgBlink, bgBlink, patTable, colTable, lines, pixels);
254 if (!patternTex.get()) {
255 patternTex = gl::Texture(false, false); // no interpolation, no wrapping
256 }
257 patternTex.bind();
258 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, patternTexSize.x, patternTexSize.y, 0,
259 GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
260
261 // create grid texture
262 auto charWidth = mode == one_of(TEXT40, TEXT80) ? 6 : 8;
263 auto charSize = gl::vec2{float(charWidth), 8.0f};
264 auto charZoom = zm * charSize;
265 auto zoomCharSize = gl::vec2(narrow ? 6.0f : 12.0f, 12.0f) * charSize; // hovered size
266 if (grid) {
267 auto gColor = ImGui::ColorConvertFloat4ToU32(gridColor);
268 auto gridWidth = charWidth * zx;
269 auto gridHeight = 8 * zy;
270 for (auto y : xrange(gridHeight)) {
271 auto* line = &pixels[y * gridWidth];
272 for (auto x : xrange(gridWidth)) {
273 line[x] = (x == 0 || y == 0) ? gColor : 0;
274 }
275 }
276 if (!gridTex.get()) {
277 gridTex = gl::Texture(false, true); // no interpolation, with wrapping
278 }
279 gridTex.bind();
280 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, gridWidth, gridHeight, 0,
281 GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
282 }
283 if (nameTableOverlay && !smallHexDigits.get()) {
284 initHexDigits();
285 }
286
287 ImGui::Separator();
288 im::TreeNode("Pattern Table", ImGuiTreeNodeFlags_DefaultOpen, [&]{
289 auto size = gl::vec2(patternDisplaySize) * zm;
290 im::Child("##pattern", {0, size.y}, 0, ImGuiWindowFlags_HorizontalScrollbar, [&]{
291 auto pos1 = ImGui::GetCursorPos();
292 gl::vec2 scrnPos = ImGui::GetCursorScreenPos();
293 ImGui::Image(patternTex.getImGui(), size);
294 bool hovered = ImGui::IsItemHovered() && (mode != OTHER);
295 ImGui::SameLine();
296 im::Group([&]{
297 if (hovered) {
298 auto gridPos = trunc((gl::vec2(ImGui::GetIO().MousePos) - scrnPos) / charZoom);
299 ImGui::StrCat("Pattern: ", gridPos.x + 32 * gridPos.y);
300 auto uv1 = gl::vec2(gridPos) * recipPatTexChars;
301 auto uv2 = uv1 + recipPatTexChars;
302 auto pos2 = ImGui::GetCursorPos();
303 ImGui::Image(patternTex.getImGui(), zoomCharSize, uv1, uv2);
304 if (grid) {
305 ImGui::SetCursorPos(pos2);
306 ImGui::Image(gridTex.getImGui(),
307 zoomCharSize, {}, charSize);
308 }
309 } else {
310 ImGui::Dummy(zoomCharSize);
311 }
312 });
313 if (grid) {
314 ImGui::SetCursorPos(pos1);
315 ImGui::Image(gridTex.getImGui(), size,
316 {}, patternTexChars);
317 }
318 });
319 });
320 ImGui::Separator();
321 im::TreeNode("Name Table", ImGuiTreeNodeFlags_DefaultOpen, [&]{
322 float rows = float(lines) * (1.0f / 8.0f); // 24, 26.5 or 32
323 auto columns = [&] {
324 if (mode == TEXT40) return 40;
325 if (mode == TEXT80) return 80;
326 return 32;
327 }();
328 auto charsSize = gl::vec2(float(columns), rows); // (x * y) number of characters
329 auto msxSize = charSize * charsSize; // (x * y) number of MSX pixels
330 auto hostSize = msxSize * zm; // (x * y) number of host pixels
331
332 im::Child("##name", {0.0f, hostSize.y}, 0, ImGuiWindowFlags_HorizontalScrollbar, [&]{
333 gl::vec2 scrnPos = ImGui::GetCursorScreenPos();
334 auto* drawList = ImGui::GetWindowDrawList();
335
336 auto getPattern = [&](unsigned column, unsigned row) {
337 auto block = [&]() -> unsigned {
338 if (mode == TEXT80 && blink) {
339 auto colPat = colTable[10 * row + (column / 8)];
340 return (colPat & (0x80 >> (column % 8))) ? 1 : 0;
341 }
342 if (mode == SCR2) return row / 8;
343 if (mode == SCR3) return row % 4;
344 return 0;
345 }();
346 return namTable[columns * row + column] + 256 * block;
347 };
348 auto getPatternUV = [&](unsigned pattern) -> std::pair<gl::vec2, gl::vec2> {
349 auto patRow = pattern / 32;
350 auto patCol = pattern % 32;
351 gl::vec2 uv1 = gl::vec2{float(patCol), float(patRow)} * recipPatTexChars;
352 gl::vec2 uv2 = uv1 + recipPatTexChars;
353 return {uv1, uv2};
354 };
355
356 if (mode == OTHER) {
357 drawList->AddRectFilled(scrnPos, scrnPos + hostSize, getColor(imColor::GRAY));
358 } else {
359 auto rowsCeil = int(ceilf(rows));
360 auto numChars = rowsCeil * columns;
361 drawList->PushClipRect(scrnPos, scrnPos + hostSize, true);
362 drawList->PushTextureID(patternTex.getImGui());
363 drawList->PrimReserve(6 * numChars, 4 * numChars);
364 for (auto row : xrange(rowsCeil)) {
365 for (auto column : xrange(columns)) {
366 gl::vec2 p1 = scrnPos + charZoom * gl::vec2{float(column), float(row)};
367 gl::vec2 p2 = p1 + charZoom;
368 auto pattern = getPattern(column, row);
369 auto [uv1, uv2] = getPatternUV(pattern);
370 drawList->PrimRectUV(p1, p2, uv1, uv2, 0xffffffff);
371 }
372 }
373 drawList->PopTextureID();
374 if (nameTableOverlay) {
375 drawList->PushTextureID(smallHexDigits.getImGui());
376 drawList->PrimReserve(12 * numChars, 8 * numChars);
377 static constexpr gl::vec2 digitSize{5.0f, 8.0f};
378 static constexpr float texDigitWidth = 1.0f / 16.0f;
379 static constexpr gl::vec2 texDigitSize{texDigitWidth, 1.0f};
380 auto digitOffset = narrow ? gl::vec2{0.0f, digitSize.y} : gl::vec2{digitSize.x, 0.0f};
381 for (auto row : xrange(rowsCeil)) {
382 for (auto column : xrange(columns)) {
383 gl::vec2 p1 = scrnPos + charZoom * gl::vec2{float(column), float(row)};
384 gl::vec2 p2 = p1 + digitOffset;
385 auto pattern = getPattern(column, row);
386 gl::vec2 uv1{narrow_cast<float>((pattern >> 4) & 15) * texDigitWidth, 0.0f};
387 gl::vec2 uv2{narrow_cast<float>((pattern >> 0) & 15) * texDigitWidth, 0.0f};
388 drawList->PrimRectUV(p1, p1 + digitSize, uv1, uv1 + texDigitSize, 0xffffffff);
389 drawList->PrimRectUV(p2, p2 + digitSize, uv2, uv2 + texDigitSize, 0xffffffff);
390 }
391 }
392 drawList->PopTextureID();
393 }
394 drawList->PopClipRect();
395 }
396
397 auto pos1 = ImGui::GetCursorPos();
398 ImGui::Dummy(hostSize);
399 bool hovered = ImGui::IsItemHovered() && (mode != OTHER);
400 ImGui::SameLine();
401 im::Group([&]{
402 if (hovered) {
403 auto gridPos = trunc((gl::vec2(ImGui::GetIO().MousePos) - scrnPos) / charZoom);
404 ImGui::StrCat("Column: ", gridPos.x, " Row: ", gridPos.y);
405 auto pattern = getPattern(gridPos.x, gridPos.y);
406 ImGui::StrCat("Pattern: ", pattern);
407 auto [uv1, uv2] = getPatternUV(pattern);
408 auto pos2 = ImGui::GetCursorPos();
409 ImGui::Image(patternTex.getImGui(), zoomCharSize, uv1, uv2);
410 if (grid) {
411 ImGui::SetCursorPos(pos2);
412 ImGui::Image(gridTex.getImGui(),
413 zoomCharSize, {}, charSize);
414 }
415 } else {
416 gl::vec2 textSize = ImGui::CalcTextSize("Column: 31 Row: 23"sv);
417 ImGui::Dummy(max(zoomCharSize, textSize));
418 }
419 });
420 if (grid) {
421 ImGui::SetCursorPos(pos1);
422 ImGui::Image(gridTex.getImGui(), hostSize, {}, charsSize);
423 }
424 });
425 });
426 });
427}
428
429static void draw6(uint8_t pattern, uint32_t fgCol, uint32_t bgCol, std::span<uint32_t, 6> out)
430{
431 out[0] = (pattern & 0x80) ? fgCol : bgCol;
432 out[1] = (pattern & 0x40) ? fgCol : bgCol;
433 out[2] = (pattern & 0x20) ? fgCol : bgCol;
434 out[3] = (pattern & 0x10) ? fgCol : bgCol;
435 out[4] = (pattern & 0x08) ? fgCol : bgCol;
436 out[5] = (pattern & 0x04) ? fgCol : bgCol;
437}
438
439static void draw8(uint8_t pattern, uint32_t fgCol, uint32_t bgCol, std::span<uint32_t, 8> out)
440{
441 out[0] = (pattern & 0x80) ? fgCol : bgCol;
442 out[1] = (pattern & 0x40) ? fgCol : bgCol;
443 out[2] = (pattern & 0x20) ? fgCol : bgCol;
444 out[3] = (pattern & 0x10) ? fgCol : bgCol;
445 out[4] = (pattern & 0x08) ? fgCol : bgCol;
446 out[5] = (pattern & 0x04) ? fgCol : bgCol;
447 out[6] = (pattern & 0x02) ? fgCol : bgCol;
448 out[7] = (pattern & 0x01) ? fgCol : bgCol;
449}
450
451void ImGuiCharacter::renderPatterns(int mode, std::span<const uint32_t, 16> palette,
452 int fgCol, int bgCol, int fgBlink, int bgBlink,
453 VramTable& pat, VramTable& col, int lines, std::span<uint32_t> output)
454{
455 switch (mode) {
456 case TEXT40:
457 case TEXT80: {
458 pat.setIndexSize(11);
459 col.setIndexSize(9); // only matters for TEXT80
460 auto fg = palette[fgCol];
461 auto bg = palette[bgCol];
462 auto fgB = palette[fgBlink];
463 auto bgB = palette[bgBlink];
464 for (auto row : xrange(8)) {
465 for (auto column : xrange(32)) {
466 auto patNum = 32 * row + column;
467 auto offset = 8 * patNum;
468 for (auto y : xrange(8)) {
469 auto pattern = pat[offset + y];
470 auto out = subspan<6>(output, (8 * row + y) * 192 + 6 * column);
471 draw6(pattern, fg, bg, out);
472 if (mode == TEXT80) {
473 auto out2 = subspan<6>(output, (64 + 8 * row + y) * 192 + 6 * column);
474 draw6(pattern, fgB, bgB, out2);
475 }
476 }
477 }
478 }
479 break;
480 }
481 case SCR1:
482 pat.setIndexSize(11);
483 col.setIndexSize(6);
484 for (auto row : xrange(8)) {
485 for (auto group : xrange(4)) { // 32 columns, split in 4 groups of 8
486 auto color = col[4 * row + group];
487 auto fg = palette[color >> 4];
488 auto bg = palette[color & 15];
489 for (auto subColumn : xrange(8)) {
490 auto column = 8 * group + subColumn;
491 auto patNum = 32 * row + column;
492 auto offset = 8 * patNum;
493 for (auto y : xrange(8)) {
494 auto pattern = pat[offset + y];
495 auto out = subspan<8>(output, (8 * row + y) * 256 + 8 * column);
496 draw8(pattern, fg, bg, out);
497 }
498 }
499 }
500 }
501 break;
502 case SCR2:
503 pat.setIndexSize(13);
504 col.setIndexSize(13);
505 for (auto row : xrange((lines == 192 ? 3 : 4) * 8)) {
506 for (auto column : xrange(32)) {
507 auto patNum = 32 * row + column;
508 auto offset = 8 * patNum;
509 for (auto y : xrange(8)) {
510 auto pattern = pat[offset + y];
511 auto color = col[offset + y];
512 auto fg = palette[color >> 4];
513 auto bg = palette[color & 15];
514 auto out = subspan<8>(output, (8 * row + y) * 256 + 8 * column);
515 draw8(pattern, fg, bg, out);
516 }
517 }
518 }
519 break;
520 case SCR3:
521 pat.setIndexSize(11);
522 col.setIndexSize(13); // not used?
523 for (auto group : xrange(4)) {
524 for (auto row : xrange(8)) {
525 for (auto column : xrange(32)) {
526 auto patNum = 32 * row + column;
527 auto offset = 8 * patNum + 2 * group;
528 for (auto y : xrange(2)) {
529 auto out = subspan<2>(output, (16 * group + 2 * row + y) * 64 + 2 * column);
530 auto pattern = pat[offset + y];
531 out[0] = palette[pattern >> 4];
532 out[1] = palette[pattern & 15];
533 }
534 }
535 }
536 }
537 break;
538 default:
539 output[0] = getColor(imColor::GRAY);
540 break;
541 }
542}
543
544} // 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:564
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
void setRegister(unsigned value, unsigned extraLsbBits)
void setIndexSize(unsigned bits)
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:306
void ItemWidth(float item_width, std::invocable<> auto next)
Definition ImGuiCpp.hh:204
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:510
void Group(std::invocable<> auto next)
Definition ImGuiCpp.hh:236
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:271
Definition view.hh:15
constexpr To narrow(From from) noexcept
Definition narrow.hh:37
constexpr auto xrange(T e)
Definition xrange.hh:132