// SPDX-License-Identifier: GPL-3.0-or-later #include "CoreChecks.h" #include "../../src/core/MachineHost.h" #include "../../src/core/MachineSession.h" #include "../../src/core/Event.h" #include "../../src/core/KeyboardMatrix.h" #include "../../src/core/tcc1014mmu.h" #include #include #include "../../src/core/tcc1014registers.h" using namespace VCC::Mac; namespace { void require(bool ok, const char* message) { if (!ok) throw std::runtime_error(message); } template void rejects(F operation, const char* message) { bool threw = false; try { operation(); } catch (const std::exception&) { threw = true; } require(threw, message); } } void CheckSessionLifecycle() { for (auto processor : {Processor::MC6809, Processor::HD6309}) { MachineSession machine; require(machine.snapshot().state == RunState::Empty, "Session starts empty"); machine.pause(); machine.advance(); machine.shutdown(); rejects([&] { machine.resume(); }, "Empty session cannot run"); rejects([&] { machine.reset(); }, "Empty session cannot reset"); machine.loadDiagnostic(processor); auto initial = machine.snapshot(); require(initial.state == RunState::Paused && initial.cpu.PC == 0x8000 && !initial.frame, "Load owns a paused machine at its ROM reset vector"); machine.advance(); require(machine.snapshot().cycles == 0, "Paused machine performs no execution"); machine.resume(); machine.advance(); machine.pause(); auto paused = machine.snapshot(); require(paused.frames == 1 && paused.cycles > 0 && paused.frame, "One running frame is published"); require(paused.cpu.PC == 0x8000 || paused.cpu.PC == 0x8003, "Authored ROM guest executes both CPU engines"); machine.advance(); require(machine.snapshot().cycles == paused.cycles, "Pause freezes machine clock"); machine.resume(); machine.advance(); require(machine.snapshot().frames == 2, "Resume continues the existing machine"); machine.shutdown(); machine.shutdown(); require(machine.snapshot().state == RunState::Empty && !Get_mem_pointer() && VCC::gEvents.GetSize() == 0, "Shutdown releases RAM and scheduled work"); machine.loadDiagnostic(processor); machine.resume(); machine.advance(); require(machine.snapshot().frames == 1, "Reload after shutdown starts cleanly"); } } void CheckSessionReset() { MachineSession machine; machine.loadDiagnostic(); machine.resume(); machine.advance(); const auto first = machine.snapshot(); machine.reset(); auto reset = machine.snapshot(); require(reset.state == RunState::Running && reset.frames == 0 && reset.cycles == 0 && !reset.frame && reset.generation > first.generation && reset.cpu.PC == 0x8000, "Cold reset invalidates frames and preserves running intent"); machine.advance(); require(machine.snapshot().frame->pixels == first.frame->pixels && machine.snapshot().cycles == first.cycles, "Cold reset reproduces the initial guest frame and cycles"); machine.pause(); machine.reset(); require(machine.snapshot().state == RunState::Paused, "Paused reset remains paused"); } void CheckSessionFrameOwnership() { MachineSession machine; machine.loadDiagnostic(); machine.resume(); machine.advance(); const auto saved = machine.snapshot().frame; const auto pixels = saved->pixels; require(saved->activeArea.x==0 && saved->activeArea.y==50 && saved->activeArea.width==640 && saved->activeArea.height==384, "Published diagnostic frame includes its active raster bounds"); require(pixels.size() == 640 * 480 && pixels[50 * 640] == 0xff0000 && pixels[50 * 640 + 80] == 0x00ff00, "Published frame owns expected packed RGB pixels"); machine.advance(); require(machine.snapshot().frame != saved && saved->number == 1, "Publication creates a separate immutable frame"); machine.reset(); machine.shutdown(); require(saved->pixels == pixels && saved->activeArea.width==640 && saved->activeArea.height==384, "UI-retained pixels and bounds outlive reset and shutdown"); } void CheckSessionExclusion() { MachineSession second; { MachineSession first; first.loadDiagnostic(); first.resume(); rejects([&] { second.loadDiagnostic(); }, "Second machine cannot replace active global hosts"); first.advance(); require(first.snapshot().frames == 1 && second.snapshot().state == RunState::Empty, "Rejected ownership leaves first machine intact"); } require(!Get_mem_pointer() && VCC::gEvents.GetSize() == 0, "Destructor tears down active machine"); second.loadDiagnostic(); second.resume(); second.advance(); require(second.snapshot().frames == 1, "Ownership is released on destruction"); } void CheckSessionRomValidation() { MachineSession machine; machine.loadDiagnostic(); machine.resume(); machine.advance(); const auto before = machine.snapshot(); rejects([&] { machine.load({}); }, "Empty ROM is rejected"); rejects([&] { machine.load(std::vector(0x8001)); }, "Oversized ROM is rejected"); require(machine.snapshot().frame == before.frame && machine.snapshot().state == RunState::Running, "Invalid input preserves loaded machine"); std::vector rom(0x8000, 0x12); rom[0] = 0x20; rom[1] = 0xfe; rom[0x7ffe] = 0x80; rom[0x7fff] = 0; machine.load(rom); rom[0] = 0; // The session must own the submitted bytes. machine.resume(); machine.advance(); require(machine.snapshot().cpu.PC == 0x8000 && machine.snapshot().frames == 1, "Session copies caller-owned ROM bytes before execution"); } void CheckSessionKeyboard() { using VCC::Mac::ScanKeyboard; for (unsigned row = 0; row < 7; ++row) for (unsigned column = 0; column < 8; ++column) { const auto key = std::uint64_t{1} << (row * 8 + column); require(ScanKeyboard(key, ~(1 << column)) == (0x7f & ~(1 << row)), "Every key scans its own row/column"); require(ScanKeyboard(key, 0xff) == 0x7f, "Deselected columns do not report keys"); } MachineSession machine; machine.loadDiagnostic(); machine.resume(); // Real PIA data-direction/control registers, then select CoCo column 1. MemWrite8(0xff, 0xff02); MemWrite8(4, 0xff03); MemWrite8(4, 0xff01); MemWrite8(0xfd, 0xff02); machine.setKeyboard(std::uint64_t{1} << 1); // A require((MemRead8(0xff00) & 0x7f) == 0x7e, "Native key reaches actual PIA scan"); machine.pause(); require((MemRead8(0xff00) & 0x7f) == 0x7f, "Pause releases keys"); machine.setKeyboard(std::uint64_t{1} << 1); machine.resume(); require((MemRead8(0xff00) & 0x7f) == 0x7f, "Paused input cannot become stuck on resume"); machine.setKeyboard(std::uint64_t{1} << 1); machine.setKeyboard(0); require((MemRead8(0xff00) & 0x7f) == 0x7f, "Focus loss releases keys through the same input boundary"); } void CheckSessionSoftReset() { MachineSession empty; rejects([&] { empty.softReset(); }, "Empty session cannot soft reset"); for (auto processor : {Processor::MC6809, Processor::HD6309}) { MachineSession machine; machine.loadDiagnostic(processor); machine.resume(); machine.advance(); auto* ram = Get_mem_pointer(); for (unsigned bank = 0; bank < 64; ++bank) ram[bank * 8192 + 1234] = bank ^ 0x5a; const std::vector savedRAM(ram, ram + 0x80000); const auto saved = machine.snapshot(); const auto savedPixels = saved.frame->pixels; machine.setKeyboard(std::uint64_t{1} << 1); GimeWrite(0x95, 1); GimeWrite(0x91, 0x20); // leave fast-timer callbacks pending Set_MmuEnabled(1); SetMmuRegister(0, 3); machine.softReset(); const auto reset = machine.snapshot(); require(Get_mem_pointer() == ram && std::equal(savedRAM.begin(), savedRAM.end(), ram), "Soft reset retains the complete RAM allocation byte-for-byte before guest execution"); require(reset.state == RunState::Running && reset.cpu.PC == 0x8000 && (reset.cpu.CC & 0x50) == 0x50, "Soft reset restarts the selected CPU at its ROM vector with interrupts masked"); require(reset.generation > saved.generation && reset.frames == 0 && reset.cycles == 0 && !reset.frame, "Soft reset invalidates published frames and restarts counters"); require(!GetMMUState().Enabled && GetMMUState().Task0[0] == 56, "Soft reset restores default mapping"); require(VCC::gEvents.GetSize() == 5, "Soft reset replaces raster/timer callbacks"); require(saved.frame->pixels == savedPixels, "Retained display frame survives soft reset unchanged"); MemWrite8(0xff, 0xff02); MemWrite8(4, 0xff03); MemWrite8(4, 0xff01); MemWrite8(0xfd, 0xff02); require((MemRead8(0xff00) & 0x7f) == 0x7f, "Soft reset releases keyboard state"); machine.advance(); require(machine.snapshot().frames == 1, "Execution resumes after soft reset"); machine.pause(); machine.softReset(); machine.advance(); require(machine.snapshot().state == RunState::Paused && machine.snapshot().cycles == 0, "Soft reset while paused does not execute guest code"); machine.softReset(); require(VCC::gEvents.GetSize() == 5, "Repeated soft resets do not duplicate scheduled work"); } } void CheckSessionVideoOutput() { for (auto cpu : {Processor::MC6809, Processor::HD6309}) { MachineSession machine; machine.setVideoOutput(VideoOutput::Composite); // chosen before loading std::vector rom(32768, 0x12); rom[0] = 0x20; rom[1] = 0xfe; rom[32766] = 0x80; rom[32767] = 0; machine.load(rom, cpu); machine.resume(); auto pattern = [&] { std::fill_n(Get_mem_pointer(), 6144, 0x55); VCC::Machine().VideoWrite(VCC::VideoRegister::Compatibility, 1); VCC::Machine().VideoWrite(VCC::VideoRegister::Mode, 0); VCC::Machine().VideoWrite(VCC::VideoRegister::VdgMode, 7); VCC::Machine().VideoWrite(VCC::VideoRegister::VdgMode2, 31); }; auto render = [&] { machine.advance(); machine.takeAudio(); machine.advance(); machine.takeAudio(); return machine.snapshot().frame; }; auto colored = [](const auto& frame) { return std::any_of(frame->pixels.begin(), frame->pixels.end(), [](auto p) { return ((p >> 16) & 255) != ((p >> 8) & 255) || ((p >> 8) & 255) != (p & 255); }); }; pattern(); const auto composite = render(); require(colored(composite), "Alternating PMODE 4 pixels produce NTSC artifact colors"); machine.pause(); const auto before = machine.snapshot(); machine.setVideoOutput(VideoOutput::RGB); const auto switched = machine.snapshot(); require(switched.cycles == before.cycles && switched.frames == before.frames && switched.generation == before.generation && switched.cpu.PC == before.cpu.PC && switched.state == RunState::Paused, "Changing display does not execute or reset the guest"); machine.resume(); require(!colored(render()), "RGB keeps the same PMODE 4 pattern monochrome"); machine.setVideoOutput(VideoOutput::CompositeAlternate); const auto alternate = render(); require(colored(alternate) && alternate->pixels != composite->pixels, "Alternate phase changes artifact colors"); VCC::Machine().VideoWrite(VCC::VideoRegister::Mode, 0x10); require(!colored(render()), "The guest monochrome bit still suppresses composite artifacts"); VCC::Machine().VideoWrite(VCC::VideoRegister::Mode, 0x20); require(render()->pixels == alternate->pixels, "Guest phase writes do not undo an explicit phase selection"); machine.setVideoOutput(VideoOutput::Composite); require(render()->pixels == composite->pixels, "Switching back reproduces the selected colors"); machine.setVideoOutput(VideoOutput::CompositeAlternate); machine.softReset(); pattern(); require(render()->pixels == alternate->pixels, "Soft reset retains the color phase"); machine.reset(); pattern(); require(render()->pixels == alternate->pixels, "Cold reset retains the color phase"); machine.load(rom, cpu); machine.resume(); pattern(); require(render()->pixels == alternate->pixels, "ROM replacement retains display preferences"); rejects([&] { machine.setVideoOutput(static_cast(99)); }, "Invalid display mode is rejected"); require(machine.snapshot().videoOutput == VideoOutput::CompositeAlternate, "Invalid choice preserves current output"); } } void CheckMachineMemorySettings() { const unsigned pages[] = {16, 64, 256, 1024}; for (auto cpu : {Processor::MC6809, Processor::HD6309}) { MachineSession machine; for (unsigned ram = 0; ram < 4; ++ram) { MachineConfiguration config; config.processor = cpu; config.ram = ram; machine.configure(config); machine.loadDiagnostic(cpu); require(GetRamConfiguration() == ram, "Selected RAM reaches the retained MMU"); // Exercise the first and last physical bank through the guest MMU, // including the extra prefix bits of the 8 MiB expansion. MmuSetMapType(1); Set_MmuEnabled(1); SetDistoRamBank(0); SetMmuRegister(0, 0); MemWrite8(0x39, 0x0100); SetDistoRamBank(ram == 3 ? 0x30 : 0); SetMmuRegister(0, static_cast(pages[ram] - 1)); MemWrite8(0xa6, 0x0100); require(Get_mem_pointer()[(pages[ram]-1)*8192+256] == 0xa6, "Highest supported bank is independently writable"); SetDistoRamBank(0); SetMmuRegister(0, 0); require(MemRead8(0x0100) == 0x39, "Expanded bank writes must not alias the first bank"); machine.softReset(); require(Get_mem_pointer()[256] == 0x39 && machine.snapshot().configuration.ram == ram, "Soft reset preserves memory and configuration"); machine.resume(); machine.advance(); machine.takeAudio(); require(machine.snapshot().frames == 1, "Both CPUs render with every memory size"); machine.reset(); require(Get_mem_pointer()[256] != 0x39 && machine.snapshot().state == RunState::Running, "Cold reset clears RAM and preserves running state"); } auto before = machine.snapshot(); auto config = before.configuration; config.processor = cpu == Processor::MC6809 ? Processor::HD6309 : Processor::MC6809; machine.configure(config); require(machine.snapshot().generation == before.generation + 1 && machine.snapshot().cpu.PC == 0x8000, "CPU change restarts the selected engine at the reset vector"); machine.pause(); before = machine.snapshot(); config.ram = 0; machine.configure(config); require(machine.snapshot().state == RunState::Paused && machine.snapshot().generation > before.generation, "RAM change preserves pause state"); } } void CheckMachinePresentationSettings() { MachineSession machine; machine.loadDiagnostic(); machine.resume(); machine.advance(); auto before = machine.snapshot(); const auto retained = before.frame; const auto pixels = retained->pixels; auto config = before.configuration; config.frameInterval = 6; config.overclock = 2; machine.configure(config); require(machine.snapshot().generation == before.generation && machine.snapshot().cycles == before.cycles, "Timing-only configuration does not reset or execute the CPU"); unsigned samples = 0; // Change to a narrower mode while the UI still owns the preceding image. MemWrite8(0, 0xff99); for (unsigned frame = 2; frame <= 6; ++frame) { machine.advance(); samples += machine.takeAudio().size(); require(machine.snapshot().frames == frame && machine.snapshot().frame == retained, "Skipped presentation retains a stable frame while guest frames advance"); require(machine.snapshot().frame->activeArea.width == 640, "Skipped presentation retains bounds belonging to its pixels"); } require(samples > 3600, "Every skipped display frame still produces audio"); machine.advance(); machine.takeAudio(); require(machine.snapshot().frame->number == 7 && retained->pixels == pixels, "Next presentation is published without mutating an earlier frame"); require(machine.snapshot().frame->activeArea.x == 64 && machine.snapshot().frame->activeArea.width == 512, "New presentation uses only its own bounds, excluding skipped wider frames"); before = machine.snapshot(); for (unsigned bad : {0u, 7u, 999u}) { auto invalid = config; invalid.frameInterval = bad; rejects([&] { machine.configure(invalid); }, "Reject unsupported presentation intervals"); } auto invalid = config; invalid.ram = 4; rejects([&] { machine.configure(invalid); }, "Reject unsupported RAM before resetting"); invalid = config; invalid.processor = static_cast(99); rejects([&] { machine.configure(invalid); }, "Reject unsupported CPU before resetting"); for (unsigned bad : {0u, 17u, 999u}) { invalid = config; invalid.overclock = bad; rejects([&] { machine.configure(invalid); }, "Reject unsupported overclock before resetting"); } require(machine.snapshot().generation == before.generation && machine.snapshot().frame == before.frame, "Rejected settings leave the machine intact"); machine.pause(); machine.reset(); require(machine.snapshot().configuration.frameInterval == 6 && machine.snapshot().configuration.overclock == 2, "Cold reset retains live timing settings"); } void CheckSessionAutomaticBoot() { MachineSession machine; rejects([&] { machine.requestNitros9Boot(); }, "Cannot boot an empty machine"); machine.loadDiagnostic();machine.requestNitros9Boot(); for(unsigned i=0;i<610;++i)machine.advance(); require(machine.nitros9BootPending(), "Paused frames never consume boot deadline"); machine.resume();machine.setKeyboard(0); require(machine.nitros9BootPending(), "Focus release does not cancel boot"); machine.setKeyboard(1); require(!machine.nitros9BootPending(), "Real input cancels boot"); machine.requestNitros9Boot();machine.softReset(); require(!machine.nitros9BootPending(), "Soft reset cancels boot"); machine.requestNitros9Boot();machine.reset(); require(!machine.nitros9BootPending(), "Cold reset cancels boot"); machine.requestNitros9Boot(); rejects([&] { for(unsigned i=0;i<600;++i)machine.advance(); }, "Missing RGBDOS has a bounded boot timeout"); require(!machine.nitros9BootPending() && machine.snapshot().state==RunState::Paused, "Failed boot releases keys and pauses without an injection retry"); machine.requestNitros9Boot();machine.shutdown(); require(!machine.nitros9BootPending(), "Shutdown cancels boot"); } void CheckSessionClipboard() { MachineSession m; rejects([&]{ m.paste({2}); }, "Empty machine rejects paste"); rejects([&]{ m.copyScreenText(); }, "Empty machine rejects copy"); m.loadDiagnostic(); rejects([&]{ m.paste({2}); }, "Paused machine rejects paste"); rejects([&]{ m.copyScreenText(); }, "Graphics cannot masquerade as text"); m.resume(); rejects([&]{ m.paste({0}); }, "Invalid chord rejected before typing"); rejects([&]{ m.paste(std::vector(65537,2)); }, "Bounded queue"); m.paste({2,2,std::uint64_t{1}<<48}); rejects([&]{ m.paste({4}); }, "Never append an unrelated paste"); for(unsigned i=0;i<7;++i) { m.setKeyboard(0); m.advance(); } require(m.pasteRemaining()==3, "Focus releases do not truncate held keys"); m.advance();require(m.pasteRemaining()==2,"Character includes release gap"); for(unsigned i=0;i<8;++i)m.advance(); for(unsigned i=0;i<35;++i)m.advance(); require(m.pasteRemaining()==1,"Return gives interpreter processing time"); m.advance();require(!m.pasteRemaining(),"Queue ends and releases keys"); m.paste({2,4});m.setKeyboard(8);require(!m.pasteRemaining(),"Real input cancels paste"); m.paste({2});m.pause();require(!m.pasteRemaining(),"Pause cancels remaining input"); m.resume();m.paste({2});m.softReset();require(!m.pasteRemaining(),"Soft reset cancels paste"); m.paste({2});m.reset();require(!m.pasteRemaining(),"Cold reset cancels paste"); m.requestNitros9Boot();rejects([&]{m.paste({2});},"Boot input has exclusive ownership"); m.setKeyboard(2);m.paste({2});m.cancelPaste();require(!m.pasteRemaining(),"Explicit cancellation"); // A relocated, attributed, 80-column hardware text screen, independent of CPU mapping. MemWrite8(0,0xff90); MemWrite8(3,0xff98); MemWrite8(0x15,0xff99); MemWrite8(2,0xff9d); MemWrite8(0,0xff9e); auto* ram=Get_mem_pointer();std::fill(ram+0x1000,ram+0x2000,32); ram[0x1000]='A';ram[0x1001]=0xff;ram[0x1002]='B'; m.advance();auto text=m.copyScreenText(); require(text.rfind("AB",0)==0,"Copy uses physical video address and skips attributes"); m.paste({2});m.shutdown();require(!m.pasteRemaining(),"Shutdown clears pending paste"); } void CheckGraphicsPreviewModes() { using Mode = DebugGraphicsMode; MachineSession machine; machine.loadDiagnostic(); constexpr std::uint32_t base = 0x1000; // An authored ROM has no boot-time palette setup. Give its color indices // distinct values and ensure a capture picks up the pending register writes. for (unsigned i = 0; i < 16; ++i) GimeWrite(0xb0 + i, i * 4); // The same eight bits decode differently as one-, two- and four-bit pixels. machine.debuggerWriteMemory(base, {0x99, 0x00}); struct Case { Mode mode; unsigned width, height, bits; }; for (const Case test : {Case{Mode::PMODE0, 128, 96, 1}, {Mode::PMODE1, 128, 96, 2}, {Mode::PMODE2, 128, 192, 1}, {Mode::PMODE3, 128, 192, 2}, {Mode::PMODE4, 256, 192, 1}, {Mode::HSCREEN1, 320, 192, 2}, {Mode::HSCREEN2, 320, 192, 4}, {Mode::HSCREEN3, 640, 192, 1}, {Mode::HSCREEN4, 640, 192, 2}}) { const auto page = machine.debuggerGraphicsPreview(false, false, base, test.mode); const unsigned perByte = 8 / test.bits, rowBytes = test.width / perByte; require(page.width == test.width && page.height == test.height && page.pixels.size() == test.width * test.height, "Graphics preview dimensions"); require(page.bytesPerRow == rowBytes && page.bytes.size() == rowBytes * test.height && page.byteAddresses.size() == page.bytes.size(), "Graphics preview row pitch"); const auto mask = (1u << test.bits) - 1; for (unsigned x = 0; x < perByte; ++x) { const auto pixel = page.pixelInfo(x, 0); require(pixel.byteIndex == 0 && page.bytes[pixel.byteIndex] == 0x99 && pixel.mask == (mask << (8 - test.bits*(x+1))), "Graphics preview bit significance"); } const auto corner = page.pixelInfo(test.width-1, test.height-1); require(page.byteAddresses[corner.byteIndex] == base + rowBytes*test.height - 1 && corner.mask == mask, "Graphics preview bottom right address and mask"); require(page.pixels[0] != page.pixels[perByte], "A set color index must change the rendered pixel"); rejects([&] { page.pixelInfo(test.width, 0); }, "Out-of-range preview pixel accepted"); } // Semigraphics bytes share text RAM; see all four quadrants and the lower-right // corner of a character. Glyph pixels identify the whole character byte. machine.debuggerWriteMemory(base, {0x99, 0x41}); const auto sg = machine.debuggerGraphicsPreview(false, false, base, Mode::SG4); require(sg.width == 256 && sg.height == 192 && sg.bytes.size() == 512 && sg.semigraphics, "SG4 mixes 32 by 16 character and graphics cells"); require(sg.pixelInfo(1, 1).mask == 8 && sg.pixelInfo(5, 1).mask == 4 && sg.pixelInfo(1, 7).mask == 2 && sg.pixelInfo(5, 7).mask == 1 && sg.pixelInfo(7, 11).byteIndex == 0, "SG4 bit order and repeated scanlines"); require(sg.pixels[1] == sg.pixels[7*256+5] && sg.pixels[1] != sg.pixels[5], "SG4 diagonal blocks follow their geometry"); const auto glyph = sg.pixelInfo(9, 5); require(glyph.byteIndex == 1 && glyph.mask == 0xff, "Text glyph identifies its character byte"); } void CheckGraphicsPreviewColorSets() { using Register = VCC::VideoRegister; using Mode = DebugGraphicsMode; MachineSession machine; machine.setVideoOutput(VideoOutput::RGB); machine.loadDiagnostic(); auto& host = VCC::Machine(); host.VideoWrite(Register::Compatibility, 1); host.VideoWrite(Register::Mode, 0); // With all pixels at color index zero, the two CSS banks select blue and red. std::fill_n(Get_mem_pointer(), 6144, 0); for (auto i : {0, 8}) GimeWrite(0xb0 + i, 9); for (auto i : {4, 10}) GimeWrite(0xb0 + i, 36); machine.resume(); struct Layout { Mode mode; unsigned sam, pia; }; for (const Layout layout : {Layout{Mode::PMODE0, 3, 22}, {Mode::PMODE1, 4, 24}, {Mode::PMODE2, 5, 26}, {Mode::PMODE3, 6, 28}, {Mode::PMODE4, 6, 30}}) { host.VideoWrite(Register::VdgMode, layout.sam); for (const bool alternate : {false, true, false}) { // A SCREEN color-set switch toggles only the PIA's CSS bit. host.VideoWrite(Register::VdgMode2, layout.pia | unsigned(alternate)); machine.advance(); machine.advance(); const auto frame = machine.snapshot().frame; const auto area = frame->activeArea; require(area.x > 0 && area.width == 512, "Expected a border beside the active PMODE scanline"); const unsigned offset = (area.y + area.height / 2) * Frame::width + area.x; require(frame->pixels[offset - 1] == (alternate ? 0xffffffu : 0x00ff00u), "CSS-only switch must update the live RGB border"); const auto current = machine.debuggerGraphicsPreview(true, true, 0, layout.mode); const auto address = machine.debuggerGraphicsPreview(false, true, current.address, layout.mode, alternate); const unsigned expected = alternate ? 0xff0000 : 0x0000ff; require(frame->pixels[offset] == expected && current.pixels.front() == expected && current.pixels == address.pixels, "CSS bank must agree in live RGB, current page, and address preview"); } } }