Publish VCC Plus OSS source distribution for 3.6.2 build 60
This commit is contained in:
commit
c652a5276d
1192 files changed
+272368
No files matched your search
@@ -0,0 +1,209 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#include "CoreChecks.h"
|
||||
#include "../../src/core/MachineSession.h"
|
||||
#include "../../src/core/AudioBuffer.h"
|
||||
#include "../../src/devices/Orchestra90Device.h"
|
||||
#include "../../src/core/FramePacing.h"
|
||||
#include "../../src/core/mc6821.h"
|
||||
#include "../../src/core/tcc1014mmu.h"
|
||||
#include <stdexcept>
|
||||
#include <cmath>
|
||||
#include <thread>
|
||||
#include <algorithm>
|
||||
using namespace VCC::Mac;
|
||||
namespace {
|
||||
void require(bool v,const char* text) { if(!v) throw std::runtime_error(text); }
|
||||
template<class F> void rejects(F f) { bool rejected=false; try { f(); } catch(const std::exception&) { rejected=true; } require(rejected,"Malformed cassette must be rejected"); }
|
||||
}
|
||||
void CheckAudioBuffer() {
|
||||
auto s=ConvertDAC(0x4000c000); require(s.left==0.5f && s.right==-0.5f,"Explicit signed PCM and stereo order");
|
||||
AudioBuffer ring; ring.gain=1;
|
||||
StereoSample input[2]={{.25f,-.5f},{.5f,-.25f}};
|
||||
float left[4],right[4]; ring.write(input,2); ring.read(left,right,4);
|
||||
require(left[0]==.25f && right[1]==-.25f && left[3]==0 && ring.underruns==2,"Bounded render fills underruns with silence");
|
||||
std::vector<StereoSample> full(9000,{1,-1}); ring.write(full.data(),full.size());
|
||||
require(ring.size()==8192 && ring.overruns==808,"Audio overflow bounded and counted");
|
||||
require(ring.submitted==9002 && ring.signalSamples==8194,"Diagnostics count submitted and accepted nonzero samples independently of gain");
|
||||
ring.clear(); ring.gain=0; ring.write(input,2); ring.read(left,right,2);
|
||||
require(left[0]==0 && right[1]==0 && ring.size()==0,"Mute still consumes audio clock");
|
||||
ring.gain=1;
|
||||
std::thread producer([&] { for(unsigned i=0;i<100000;++i) { while(ring.size()>=4000) std::this_thread::yield(); StereoSample value{float(i),-float(i)}; ring.write(&value,1); } });
|
||||
bool ordered=true;
|
||||
for(unsigned i=0;i<100000;++i) { while(!ring.size()) std::this_thread::yield(); ring.read(left,right,1); ordered &= left[0]==float(i) && right[0]==-float(i); }
|
||||
producer.join(); require(ordered,"Concurrent audio preserves order across wraparound");
|
||||
// Model an 80 ms producer stall while the device continues reading every 10 ms.
|
||||
// The previous 50 ms target would underrun during this interval.
|
||||
AudioBuffer reserve; reserve.gain = 1;
|
||||
std::vector<StereoSample> frame(739, {.25f, -.25f});
|
||||
while (reserve.size() < audioTargetSamples) reserve.write(frame.data(), frame.size());
|
||||
float blockLeft[441], blockRight[441];
|
||||
for (unsigned block = 0; block < 8; ++block) {
|
||||
reserve.read(blockLeft, blockRight, 441);
|
||||
require(blockLeft[440] == .25f && blockRight[440] == -.25f, "Audio reserve survives an 80 ms producer stall");
|
||||
}
|
||||
require(reserve.underruns == 0 && reserve.maximumRequest == 441, "Stall recovery preserves samples and records callback demand");
|
||||
while (reserve.size() < audioTargetSamples) reserve.write(frame.data(), frame.size());
|
||||
require(reserve.overruns == 0 && reserve.size() < audioTargetSamples + frame.size(), "Refill stays bounded to the target plus one guest frame");
|
||||
}
|
||||
void CheckAudioScheduling() {
|
||||
for(auto cpu:{Processor::MC6809,Processor::HD6309}) {
|
||||
MachineSession machine; machine.loadDiagnostic(cpu); machine.resume();
|
||||
pia1_write(4,0x21); pia1_write(12,0x23); pia1_write(128,0x20);
|
||||
unsigned samples=0;
|
||||
for(unsigned i=0;i<60;++i) { machine.advance(); auto a=machine.takeAudio(); samples+=a.size(); require(!a.empty() && a[0].left==.25f,"Real PIA DAC reaches audio frames"); }
|
||||
require(samples>44300 && samples<44400,"44.1 kHz audio follows nominal emulated NTSC time");
|
||||
machine.pause(); machine.advance(); require(machine.takeAudio().empty(),"Pause generates no samples");
|
||||
machine.softReset(); require(GetDACSample()==0 && GetCasSample()==0,"Reset clears PIA sound latches");
|
||||
machine.resume(); machine.advance(); require(machine.takeAudio().size()<800,"Reset schedules one sampler, not duplicate callbacks");
|
||||
}
|
||||
}
|
||||
void CheckAudioRouting() {
|
||||
struct SpeakerSource final : VCC::Devices::CartridgeDevice {
|
||||
std::uint16_t value = 0x8080;
|
||||
void reset() override { }
|
||||
void horizontalSync(VCC::Devices::DeviceHost&) override { }
|
||||
std::uint8_t readMemory(std::uint16_t) const override { return 0xff; }
|
||||
std::uint8_t readPort(std::uint8_t, VCC::Devices::DeviceHost&) override { return 0; }
|
||||
void writePort(std::uint8_t, std::uint8_t, VCC::Devices::DeviceHost&) override { }
|
||||
bool hasCartridgeAudioOutput() const override { return true; }
|
||||
std::uint16_t audio() const override { return value; }
|
||||
};
|
||||
for (auto cpu : {Processor::MC6809, Processor::HD6309}) {
|
||||
MachineSession machine;
|
||||
auto speaker = std::make_shared<SpeakerSource>();
|
||||
auto orchestra = std::make_shared<VCC::Devices::Orchestra90Device>();
|
||||
machine.cartridges().configure({nullptr, speaker, orchestra, nullptr, nullptr}, true, 4);
|
||||
machine.loadDiagnostic(cpu); machine.resume();
|
||||
auto mux = [&](unsigned selection) {
|
||||
pia0_write(0x34 | ((selection & 1) << 3), 0x01);
|
||||
pia0_write(0x34 | ((selection & 2) << 2), 0x03);
|
||||
};
|
||||
auto sample = [&](float left, float right, const char* reason) {
|
||||
machine.takeAudio(); machine.advance(); const auto pcm = machine.takeAudio();
|
||||
require(!pcm.empty() && std::all_of(pcm.begin(), pcm.end(), [&](auto value) {
|
||||
return value.left == left && value.right == right;
|
||||
}), reason);
|
||||
};
|
||||
pia1_write(0x34, 0x21); pia1_write(0x34, 0x23);
|
||||
// Joystick conversion writes the DAC while the sound gate is closed.
|
||||
pia1_write(252, 0x20);
|
||||
for (unsigned repeat = 0; repeat < 3; ++repeat) for (unsigned selection = 0; selection < 4; ++selection) {
|
||||
mux(selection); speaker->value = repeat == 0 ? 0x8080 : 0x10f0;
|
||||
sample(0, 0, "Disabled analog sound must remain silent through joystick-style mux changes");
|
||||
}
|
||||
pia1_write(0x3c, 0x23); mux(0);
|
||||
sample(126/256.0f, 126/256.0f, "Re-enabling sound reads the current DAC latch");
|
||||
speaker->value = 0x4080; mux(2);
|
||||
sample(-.25f, 0, "Cartridge SND is centered and selected only on its analog input");
|
||||
speaker->value = 0;
|
||||
sample(-.5f, -.5f, "A cartridge zero sample is a valid negative peak, not absence");
|
||||
speaker->value = 0x8080;
|
||||
sample(0, 0, "An idle cartridge midpoint is silence");
|
||||
mux(3); sample(0, 0, "Unused analog mux input is grounded");
|
||||
// The stopped cassette has midpoint128, even with a cartridge installed.
|
||||
mux(1); sample(0, 0, "Stopped tape does not leak cartridge sound");
|
||||
machine.cartridges().writePort(0x7a, 64); machine.cartridges().writePort(0x7b, 192);
|
||||
pia1_write(0x34, 0x23);
|
||||
for (unsigned selection = 0; selection < 4; ++selection) {
|
||||
mux(selection); sample(.25f, .75f, "External Orchestra-90 stereo bypasses the speaker gate and mux");
|
||||
}
|
||||
machine.cartridges().writePort(0x7a, 0); machine.cartridges().writePort(0x7b, 0);
|
||||
// Configure the one-bit output and check that it is independent too.
|
||||
pia1_write(0x30, 0x23); pia1_write(2, 0x22); pia1_write(0x34, 0x23); pia1_write(2, 0x22);
|
||||
sample(.5f, .5f, "Single-bit sound remains audible with the analog gate closed");
|
||||
machine.cartridges().writePort(0x7a, 255); machine.cartridges().writePort(0x7b, 0);
|
||||
mux(0); pia1_write(0x3c, 0x23);
|
||||
sample(1.0f, 254/256.0f, "Combined sources saturate instead of wrapping signed PCM");
|
||||
}
|
||||
}
|
||||
void CheckCassetteImages() {
|
||||
CassetteDeck deck; deck.mount({0x55,0x3c,0xa5},TapeFormat::CAS); deck.play();
|
||||
for(unsigned i=0;i<1000;++i) require(deck.tick(0)==128,"Motor gates tape movement");
|
||||
require(deck.snapshot().position==0,"Motor-off playback preserves position"); deck.motor(true);
|
||||
for(unsigned i=0;i<32000;++i) deck.tick(0);
|
||||
require(deck.snapshot().mode==TapeMode::Stopped && deck.snapshot().position==3,"CAS playback ends without wrapping");
|
||||
deck.seek(1000); require(deck.snapshot().position==3,"Seeking clamps to end of tape");
|
||||
deck.seek(1); require(deck.snapshot().position==1 && deck.snapshot().mode==TapeMode::Stopped,"Seeking stops at selected byte");
|
||||
deck.rewind(); require(deck.exportImage()==std::vector<std::uint8_t>({0x55,0x3c,0xa5}),"CAS export retains original bytes");
|
||||
rejects([&]{deck.mount({1,2,3},TapeFormat::WAV);});
|
||||
require(deck.exportImage().size()==3,"Failed mount leaves old tape intact");
|
||||
deck.record(TapeFormat::WAV); deck.motor(true);
|
||||
for(unsigned i=0;i<101;++i) deck.tick(i*2);
|
||||
auto wav=deck.exportImage(); require(deck.snapshot().dirty,"Export does not mark an unsaved recording as saved");
|
||||
deck.markSaved(); require(!deck.snapshot().dirty,"Successful save clears dirty state");
|
||||
require(wav.size()==146 && wav[40]==101,"WAV header sizes include odd-byte padding correctly");
|
||||
deck.mount(wav,TapeFormat::WAV); deck.play();
|
||||
for(unsigned i=0;i<101;++i) require(deck.tick(0)==i*2,"WAV recording reloads sample-exactly");
|
||||
auto truncated=wav; truncated.resize(30); rejects([&]{deck.mount(truncated,TapeFormat::WAV);});
|
||||
auto bad=wav; bad[22]=3; rejects([&]{deck.mount(bad,TapeFormat::WAV);});
|
||||
auto chunked=wav; chunked.insert(chunked.begin()+12,{'J','U','N','K',2,0,0,0,0,0}); chunked[4]+=10;
|
||||
deck.mount(chunked,TapeFormat::WAV); require(deck.snapshot().length==101,"WAV parser walks unknown chunks");
|
||||
// Independent PCM fixtures: stereo extrema at 22.05 kHz, each repeated twice
|
||||
// by the 44.1 kHz tape input. Exercise sign extension and float conversion.
|
||||
for(unsigned bits:{8,16,24,32}) for(unsigned encoding:{1,3}) {
|
||||
if(encoding==3 && bits!=32) continue;
|
||||
std::vector<std::uint8_t> fixture(44,0);
|
||||
auto put=[&](unsigned offset,std::uint32_t value,unsigned width) {
|
||||
for(unsigned j=0;j<width;++j) fixture[offset+j]=(value>>(8*j))&255;
|
||||
};
|
||||
const char* riff="RIFF"; const char* wave="WAVEfmt "; const char* data="data";
|
||||
std::copy_n(riff,4,fixture.begin()); std::copy_n(wave,8,fixture.begin()+8); std::copy_n(data,4,fixture.begin()+36);
|
||||
unsigned align=bits/8*2;
|
||||
put(16,16,4); put(20,encoding,2); put(22,2,2); put(24,22050,4);
|
||||
put(28,22050*align,4); put(32,align,2); put(34,bits,2); put(40,align*3,4); put(4,36+align*3,4);
|
||||
for(unsigned level=0;level<3;++level) for(unsigned channel=0;channel<2;++channel) {
|
||||
std::uint32_t sample=encoding==3 ? (level==0 ? 0xbf800000u : level==1 ? 0 : 0x3f800000u) :
|
||||
bits==8 ? (level==0 ? 0 : level==1 ? 128 : 255) :
|
||||
level==0 ? (std::uint32_t(1)<<(bits-1)) : level==1 ? 0 : (std::uint32_t(1)<<(bits-1))-1;
|
||||
for(unsigned j=0;j<bits/8;++j) fixture.push_back((sample>>(8*j))&255);
|
||||
}
|
||||
deck.mount(fixture,TapeFormat::WAV); deck.play();
|
||||
for(unsigned expected:{0,0,128,128,255,255}) require(deck.tick(0)==expected,"PCM/float stereo conversion and sample-rate normalization");
|
||||
if(encoding==3) { fixture[46]=0xc0; fixture[47]=0x7f; rejects([&]{deck.mount(fixture,TapeFormat::WAV);}); }
|
||||
}
|
||||
for(std::size_t n=0;n<wav.size();++n) {
|
||||
auto prefix=std::vector<std::uint8_t>(wav.begin(),wav.begin()+n);
|
||||
rejects([&]{deck.mount(prefix,TapeFormat::WAV);});
|
||||
}
|
||||
deck.eject(); rejects([&]{deck.play();});
|
||||
}
|
||||
void CheckCassetteMachine() {
|
||||
MachineSession machine; machine.loadDiagnostic();
|
||||
auto& deck=machine.cassette(); deck.mount({0x55,0xaa},TapeFormat::CAS); deck.setFast(true); deck.play();
|
||||
pia1_write(12,0x21); // actual PIA motor and data-register selection
|
||||
require(deck.snapshot().motor && deck.fastLoading(),"PIA motor connects to CAS transport");
|
||||
for(unsigned i=0;i<30000;++i) deck.tick(0);
|
||||
for(unsigned bit=0;bit<8;++bit) {
|
||||
require((pia1_read(0x20)&1)==1 && SafeMemRead8(0x83)==((0x55>>bit)&1?10:20),"Fast load supplies ROM pulse width");
|
||||
require((pia1_read(0x20)&1)==0,"Fast load alternates half bits");
|
||||
}
|
||||
require(deck.snapshot().position==1,"Fast load advances exactly one byte");
|
||||
machine.softReset(); require(!deck.snapshot().motor && deck.snapshot().position==1,"Soft reset stops motor and retains media position");
|
||||
machine.reset(); require(machine.cassette().snapshot().length==2,"Cold reset retains mounted tape");
|
||||
|
||||
// Tape is a mono speaker source. The two Orchestra-90 jacks are external.
|
||||
deck.record(TapeFormat::WAV);
|
||||
deck.motor(true);
|
||||
for (unsigned i = 0; i < 4096; ++i) deck.tick(160);
|
||||
deck.mount(deck.exportImage(), TapeFormat::WAV);
|
||||
deck.play();
|
||||
deck.motor(true);
|
||||
pia0_write(12, 0x01);
|
||||
pia0_write(4, 0x03);
|
||||
pia1_write(0x3c, 0x23); // explicitly enable the selected analog source
|
||||
require(GetMuxState() == PIA_MUX_CASSETTE, "Tape input selected");
|
||||
machine.resume();
|
||||
machine.advance();
|
||||
auto tapeOnly = machine.takeAudio();
|
||||
require(!tapeOnly.empty() && std::all_of(tapeOnly.begin(), tapeOnly.end(), [](auto sample) {
|
||||
return sample.left == .125f && sample.right == .125f;
|
||||
}), "Tape monitor plays its mono input on both channels");
|
||||
machine.cartridges().install(std::make_unique<VCC::Devices::Orchestra90Device>());
|
||||
machine.cartridges().writePort(0x7a, 32);
|
||||
machine.cartridges().writePort(0x7b, 160);
|
||||
machine.advance();
|
||||
auto mixed = machine.takeAudio();
|
||||
require(!mixed.empty() && std::all_of(mixed.begin(), mixed.end(), [](auto sample) {
|
||||
return sample.left == .25f && sample.right == .75f;
|
||||
}), "External left and right DACs remain audible alongside a playing tape");
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#include "CoreChecks.h"
|
||||
#include "../../src/core/BasicProgram.h"
|
||||
#include "../../src/core/MachineSession.h"
|
||||
#include <stdexcept>
|
||||
#include <functional>
|
||||
#include <algorithm>
|
||||
using namespace VCC::Mac;
|
||||
namespace {
|
||||
void require(bool yes, const char* why) { if (!yes) throw std::runtime_error(why); }
|
||||
void rejects(const std::function<void()>& call) {
|
||||
try { call(); } catch (const std::exception&) { return; }
|
||||
throw std::runtime_error("Malformed BASIC input was accepted");
|
||||
}
|
||||
std::vector<BasicToken> dictionary() {
|
||||
return {{"GO",0x81},{"REM",0x82},{"'",0x83},{"ELSE",0x84},{"IF",0x85},{"DATA",0x86},{"PRINT",0x87},
|
||||
{"END",0x8a},{"TO",0xa5},{"THEN",0xa7},{"+",0xab},{"*",0xad},{"=",0xb3},
|
||||
{"HSCREEN",0xe4},{"LEFT$",0x9c,true}};
|
||||
}
|
||||
}
|
||||
void CheckBasicProgramTokens() {
|
||||
const auto dict = dictionary();
|
||||
const std::string source = "50 HSCREEN 0\n30 ? LEFT$(\"PRINT:REM\",2)\n10 REM PRINT remains text\n20 DATA PRINT,\"X:Y\":PRINT6*7\n40 IF A=1 THEN ?1 ELSE ?2 'PRINT\n60 XPRINT=1\n";
|
||||
const auto encoded = BasicProgram::encode(source, 0x2601, 0x7000, dict);
|
||||
const auto decoded = BasicProgram::decode(encoded, 0x2601, dict);
|
||||
require(decoded.find("10 REM PRINT remains text\n20 DATA PRINT,\"X:Y\":PRINT6*7") == 0, "BASIC sorting, REM or DATA changed");
|
||||
require(decoded.find("30 PRINT LEFT$(\"PRINT:REM\",2)") != std::string::npos, "Function/PRINT shortcut changed");
|
||||
require(decoded.find("40 IF A=1 THEN PRINT1 ELSE PRINT2 'PRINT") != std::string::npos, "ELSE/apostrophe did not roundtrip");
|
||||
require(decoded.find("60 XPRINT=1") != std::string::npos, "Embedded keyword in identifier changed");
|
||||
require(BasicProgram::encode(decoded,0x2601,0x7000,dict) == encoded, "BASIC decode/encode is not byte stable");
|
||||
std::vector<BasicSourceLocation> locations;
|
||||
require(BasicProgram::encode(source,0x2601,0x7000,dict,&locations) == encoded, "Debug mapping changed program bytes");
|
||||
require(!locations.empty(), "Missing BASIC source map");
|
||||
for (const auto& location : locations) {
|
||||
require(location.address >= 0x2605 && location.address < 0x2601 + encoded.size(), "Source map address outside program");
|
||||
require(location.length > 0 && location.offset + location.length <= source.size(), "Source map span outside editor");
|
||||
const auto token = encoded[location.address - 0x2601];
|
||||
if (token == 0x87) require(source.substr(location.offset, location.length) == "PRINT" || source.substr(location.offset, location.length) == "?", "PRINT map misses original spelling");
|
||||
}
|
||||
require(BasicProgram::decode(BasicProgram::encode("\n\r\n",0x2601,0x7000,dict),0x2601,dict).empty(), "Empty BASIC program failed");
|
||||
require(BasicProgram::decode(BasicProgram::encode("10 print \"Mixed Case\"\r\n",0x2601,0x7000,dict),0x2601,dict) == "10 PRINT \"Mixed Case\"\n", "Case normalization changed a string");
|
||||
}
|
||||
void CheckBasicProgramValidation() {
|
||||
const auto dict = dictionary();
|
||||
for (const auto& bad : {"PRINT 1", "64000 PRINT1", "10 PRINT1\n10 PRINT2", "10 PRINT\x01", "10 PRINT \xc3\xa9"})
|
||||
rejects([&] { BasicProgram::encode(bad,0x2601,0x7000,dict); });
|
||||
rejects([&] { BasicProgram::encode("10 REM " + std::string(250,'X'),0x2601,0x7000,dict); });
|
||||
rejects([&] { BasicProgram::encode("10 PRINT1",0x2601,0x2608,dict); });
|
||||
auto encoded = BasicProgram::encode("10 PRINT1\n20 END",0x2601,0x7000,dict);
|
||||
auto bad = encoded; bad[0]=0;bad[1]=1;
|
||||
rejects([&] { BasicProgram::decode(bad,0x2601,dict); });
|
||||
bad=encoded;bad.back()=1;
|
||||
rejects([&] { BasicProgram::decode(bad,0x2601,dict); });
|
||||
bad=encoded;bad[4]=0xfe;
|
||||
rejects([&] { BasicProgram::decode(bad,0x2601,dict); });
|
||||
const auto disk = BasicProgram::exportImage(encoded,"hello",BasicExportFormat::Disk);
|
||||
require(disk.size()==161280, "BASIC export disk geometry differs");
|
||||
constexpr unsigned fat=(17*18+1)*256, entry=(17*18+2)*256;
|
||||
require(std::string(disk.begin()+entry,disk.begin()+entry+11)=="HELLO BAS" && disk[entry+11]==0 && disk[entry+12]==0,
|
||||
"BASIC export directory metadata differs");
|
||||
require(disk[0]==0xff && ((unsigned(disk[1])<<8)|disk[2])==encoded.size() &&
|
||||
std::equal(encoded.begin(),encoded.end(),disk.begin()+3), "BASIC disk file differs from SAVE binary layout");
|
||||
require(disk[fat]==0xc1 && disk[fat+1]==0xff && disk[entry+15]==encoded.size()+3, "BASIC disk allocation differs");
|
||||
// Exercise exact-sector size and a file spanning multiple granules.
|
||||
for (std::size_t size : {std::size_t(253),std::size_t(4608)}) {
|
||||
std::vector<std::uint8_t> payload(size,0); auto image=BasicProgram::exportImage(payload,"BOUNDARY",BasicExportFormat::Disk);
|
||||
const auto length=size+3, count=(length+2303)/2304;
|
||||
require(image[entry+14]*256+image[entry+15]==(length-1)%256+1, "Last-sector length is wrong");
|
||||
for(std::size_t g=0;g<count;++g) require(image[fat+g]==(g+1<count?g+1:0xc0+((length-g*2304)+255)/256), "Granule chain is wrong");
|
||||
}
|
||||
const auto tape=BasicProgram::exportImage(encoded,"hello",BasicExportFormat::Cassette);
|
||||
std::vector<std::uint8_t> recovered; std::size_t at=0; unsigned blocks=0; bool eof=false;
|
||||
while(at<tape.size()) {
|
||||
while(at<tape.size() && tape[at]==0x55) ++at;
|
||||
require(at+4<=tape.size() && tape[at++]==0x3c, "Cassette block marker missing");
|
||||
const auto type=tape[at++], length=tape[at++]; unsigned sum=type+length;
|
||||
require(at+length+2<=tape.size(), "Cassette block truncated");
|
||||
if(type==0) require(length==15 && std::string(tape.begin()+at,tape.begin()+at+8)=="HELLO " && tape[at+8]==0 && tape[at+9]==0 && tape[at+10]==0,"Cassette BASIC name metadata differs");
|
||||
else if(type==1) recovered.insert(recovered.end(),tape.begin()+at,tape.begin()+at+length);
|
||||
else { require(type==0xff && length==0, "Cassette EOF differs"); eof=true; }
|
||||
for(unsigned i=0;i<length;++i)sum+=tape[at++];
|
||||
require(tape[at++]==(sum&255) && tape[at++]==0x55,"Cassette checksum/trailer differs"); ++blocks;
|
||||
if(eof)break;
|
||||
}
|
||||
require(eof && at==tape.size() && blocks==3 && recovered==encoded,"Cassette payload did not roundtrip");
|
||||
for(const auto& name:{"","LONGERTHAN8","A.BAS","HI THERE","../A","CAFÉ"}) rejects([&]{BasicProgram::exportImage(encoded,name,BasicExportFormat::Disk);});
|
||||
rejects([&]{BasicProgram::exportImage({},"HELLO",BasicExportFormat::Cassette);});
|
||||
rejects([&]{BasicProgram::exportImage(std::vector<std::uint8_t>(0x5900,0),"HELLO",BasicExportFormat::Disk);});
|
||||
rejects([&]{BasicProgram::exportImage({0,1},"HELLO",BasicExportFormat::Cassette);});
|
||||
rejects([&]{BasicProgram::exportImage(encoded,"HELLO",static_cast<BasicExportFormat>(99));});
|
||||
// Decoder guardrails use synthetic RAM, independent of proprietary ROMs.
|
||||
std::vector<std::uint8_t> memory(0x8000,0);
|
||||
auto word = [&](unsigned at, unsigned v) { memory[at] = v >> 8; memory[at+1] = v & 255; };
|
||||
word(0x19,0x2601); word(0x1b,0x2610); word(0x1d,0x2617); word(0x1f,0x2617); word(0x21,0x7000);
|
||||
memory[0x2610]='A'; memory[0x2612]=0x81; memory[0x2613]=0xc0; // -1.5
|
||||
require(BasicProgram::inspect(memory).at(0).value=="-1.5", "BASIC numeric format differs");
|
||||
memory[0x2611]=0x80; memory[0x2612]=3; word(0x2614,0x4000);
|
||||
memory[0x4000]='a'; memory[0x4001]=0; memory[0x4002]=255;
|
||||
require(BasicProgram::inspect(memory).at(0).value=="\"a\\x00\\xFF\"", "String escaping or flag differs");
|
||||
word(0x2614,0xff00);
|
||||
require(BasicProgram::inspect(memory).at(0).value.find("Unavailable") == 0,"String device address accepted");
|
||||
memory[0x2612]=0;
|
||||
require(BasicProgram::inspect(memory).at(0).value=="\"\"", "Empty string dereferenced an unused pointer");
|
||||
auto saved=memory;
|
||||
for (unsigned ptr : {0x1bu,0x1du,0x1fu,0x21u}) { word(ptr,0xffff); rejects([&]{ BasicProgram::inspect(memory); }); memory=saved; }
|
||||
word(0x1d,0x2618); rejects([&]{ BasicProgram::inspect(memory); }); memory=saved;
|
||||
// Array descriptor: two dimensions (source order 2,3), six elements.
|
||||
word(0x1f,0x2617+39); memory[0x2617]='M'; word(0x2619,39); memory[0x261b]=2;
|
||||
word(0x261c,3); word(0x261e,2);
|
||||
auto array=BasicProgram::inspect(memory).at(1);
|
||||
require(array.dimensions==std::vector<unsigned>({2,3}) && array.elements.size()==6,"Array dimensions are not in source order");
|
||||
saved=memory;
|
||||
for(unsigned badsize : {0u,8u,38u,40u,65535u}) { word(0x2619,badsize); rejects([&]{ BasicProgram::inspect(memory); }); memory=saved; }
|
||||
for(unsigned rank : {0u,3u,255u}) { memory[0x261b]=rank; rejects([&]{ BasicProgram::inspect(memory); }); memory=saved; }
|
||||
for(unsigned length : {0u,65535u}) { word(0x261c,length); rejects([&]{ BasicProgram::inspect(memory); }); memory=saved; }
|
||||
rejects([&]{ BasicProgram::inspect(std::vector<std::uint8_t>(2)); });
|
||||
MachineSession machine;
|
||||
rejects([&] { machine.basicReadSource(); }); rejects([&] { machine.basicLoadSource("10 PRINT1",true); });
|
||||
machine.loadDiagnostic();
|
||||
const auto before=machine.snapshot();
|
||||
rejects([&] { machine.basicLoadSource("10 PRINT1",true); });
|
||||
require(machine.snapshot().cpu.PC == before.cpu.PC && machine.snapshot().cycles == before.cycles, "Rejected BASIC load changed diagnostic execution");
|
||||
}
|
||||
@@ -0,0 +1,523 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#include "CoreChecks.h"
|
||||
#include "../../src/core/BinaryImage.h"
|
||||
#include "../../src/core/MachineSession.h"
|
||||
#include "../../src/core/MachineHost.h"
|
||||
#include "../../src/devices/FD502/Fd502Device.h"
|
||||
#include "../../src/core/tcc1014mmu.h"
|
||||
#include "../../src/core/Event.h"
|
||||
#include <algorithm>
|
||||
using namespace VCC::Mac;
|
||||
namespace {
|
||||
void require(bool ok, const char* message) { if (!ok) throw std::runtime_error(message); }
|
||||
template<class F> void rejects(F operation) {
|
||||
bool rejected = false;
|
||||
try { operation(); } catch (const std::exception&) { rejected = true; }
|
||||
require(rejected, "Invalid binary must be rejected");
|
||||
}
|
||||
using Bytes = std::vector<std::uint8_t>;
|
||||
void block(Bytes& file, std::uint16_t address, const Bytes& bytes) {
|
||||
file.insert(file.end(), {0, std::uint8_t(bytes.size() >> 8), std::uint8_t(bytes.size()),
|
||||
std::uint8_t(address >> 8), std::uint8_t(address)});
|
||||
file.insert(file.end(), bytes.begin(), bytes.end());
|
||||
}
|
||||
void finish(Bytes& file, std::uint16_t entry = 0x3000) {
|
||||
file.insert(file.end(), {255,0,0,std::uint8_t(entry >> 8),std::uint8_t(entry)});
|
||||
}
|
||||
Bytes program() {
|
||||
Bytes file; block(file, 0x3000, {0x86,0x6b,0xb7,0x50,0,0x20,0xfe}); // LDA #$6B; STA $5000; BRA *
|
||||
finish(file); return file;
|
||||
}
|
||||
void checkPausedGraphicsBuffers(Processor processor) {
|
||||
MachineSession machine; machine.loadDiagnostic(processor); machine.pause();
|
||||
machine.setVideoOutput(VideoOutput::RGB);
|
||||
auto* ram = Get_mem_pointer();
|
||||
constexpr unsigned address = 0x10000, length = 160 * 192;
|
||||
std::fill_n(ram + address, length, 0x22);
|
||||
const auto before = machine.snapshot();
|
||||
const Bytes original(ram, ram + GetMMUState().RAMBytes);
|
||||
const DebugGraphicsBuffer back{"back", address, DebugGraphicsMode::HSCREEN2};
|
||||
const auto capture = machine.debuggerGraphicsCapture(back);
|
||||
const auto after = machine.snapshot();
|
||||
require(capture.declared && capture.declaredIdentifier == "back" && capture.displayed.address == 0 &&
|
||||
capture.declared->address == address && capture.displayed.width == 320 && capture.displayed.height == 192 &&
|
||||
capture.displayed.bytesPerRow == 160 && capture.declared->bytes == Bytes(length, 0x22),
|
||||
"Paused graphics capture identifies the actual display and explicitly declared physical buffer on both CPUs");
|
||||
require(capture.displayed.palette == capture.declared->palette && capture.displayed.pixels.front() != capture.declared->pixels.front() &&
|
||||
capture.declared->pixels.front() == 0x00ff00,
|
||||
"Declared preview renders its actual bytes using the same captured palette rather than duplicating the display image");
|
||||
require(capture.displayed.generation == capture.declared->generation && capture.displayed.cycles == capture.declared->cycles &&
|
||||
before.generation == after.generation && before.cycles == after.cycles && before.frames == after.frames &&
|
||||
before.cpu.PC == after.cpu.PC && before.frame == after.frame &&
|
||||
std::equal(original.begin(), original.end(), ram),
|
||||
"Paired captures do not execute the guest, publish a new raster frame or change RAM");
|
||||
const auto withoutBack = machine.debuggerGraphicsCapture();
|
||||
require(!withoutBack.declared && withoutBack.displayed.pixels == capture.displayed.pixels,
|
||||
"A displayed-only stopped preview needs no inferred back buffer");
|
||||
std::fill_n(ram + address, length, 0x33);
|
||||
const auto changed = machine.debuggerGraphicsCapture(back);
|
||||
require(capture.declared->bytes.front() == 0x22 && changed.declared->bytes.front() == 0x33 &&
|
||||
capture.declared->pixels.front() != changed.declared->pixels.front(),
|
||||
"Graphics snapshots own immutable bytes and reflect later authored buffer updates only in a new snapshot");
|
||||
// Guest video writes can select another page before a raster is published.
|
||||
// The fresh preview identifies this register selection, never a guessed
|
||||
// provenance for the previous published Frame.
|
||||
VCC::Machine().VideoWrite(VCC::VideoRegister::Offset, address / 8);
|
||||
const auto selected = machine.debuggerGraphicsCapture();
|
||||
require(selected.displayed.address == address && selected.displayed.bytes.front() == 0x33 &&
|
||||
machine.snapshot().frame == before.frame && machine.snapshot().cycles == before.cycles,
|
||||
"Current video-register selection is distinct from published-frame history without advancing the guest");
|
||||
rejects([&] { machine.debuggerGraphicsCapture(DebugGraphicsBuffer{"outside", GetMMUState().RAMBytes - 1, DebugGraphicsMode::HSCREEN2}); });
|
||||
rejects([&] { machine.debuggerGraphicsCapture(DebugGraphicsBuffer{"invalid", 0, static_cast<DebugGraphicsMode>(255)}); });
|
||||
require(machine.snapshot().state == RunState::Paused && machine.snapshot().cycles == before.cycles,
|
||||
"Rejected buffer ranges and formats preserve paused execution state");
|
||||
machine.resume();
|
||||
rejects([&] { machine.debuggerGraphicsCapture(back); });
|
||||
require(machine.snapshot().state == RunState::Running && machine.snapshot().cycles == before.cycles,
|
||||
"A paired capture requires an explicit pause and cannot pause or advance a running machine");
|
||||
}
|
||||
void checkCurrentGimeCanvases(Processor processor) {
|
||||
MachineSession machine; machine.loadDiagnostic(processor); machine.pause();
|
||||
machine.setVideoOutput(VideoOutput::RGB);
|
||||
auto* ram = Get_mem_pointer();
|
||||
const auto ramSize = GetMMUState().RAMBytes;
|
||||
const auto writeVideo = [](VCC::VideoRegister reg, unsigned value) { VCC::Machine().VideoWrite(reg, value); };
|
||||
writeVideo(VCC::VideoRegister::Compatibility, 0);
|
||||
writeVideo(VCC::VideoRegister::Mode, 0x80);
|
||||
writeVideo(VCC::VideoRegister::HorizontalOffset, 0xfe); // 256-byte pitch, pan 252, horizontal row wrap.
|
||||
for (const auto height : {225u, 192u}) {
|
||||
const unsigned front = height == 225 ? 0 : 0x40000, back = height == 225 ? 0x20000 : 0x50000;
|
||||
std::fill_n(ram + front, 65536, 0x11); std::fill_n(ram + back, 65536, 0x22);
|
||||
// Distinguish the last four bytes of a row from its wrapped beginning.
|
||||
ram[front + 4096 + 252] = 0x33; ram[front + 4096] = 0x44;
|
||||
ram[back + 4096 + 252] = 0x22; ram[back + 4096] = 0x11;
|
||||
writeVideo(VCC::VideoRegister::Resolution, height == 225 ? 0x7e : 0x1e);
|
||||
writeVideo(VCC::VideoRegister::Offset, (front + 4096) / 8);
|
||||
const std::vector<DebugGraphicsBuffer> canvases{
|
||||
{"front", front, DebugGraphicsMode::CurrentGime, false, 65536},
|
||||
{"back", back, DebugGraphicsMode::CurrentGime, false, 65536}};
|
||||
const auto before = machine.snapshot();
|
||||
const Bytes memory(ram, ram + ramSize);
|
||||
const auto capture = machine.debuggerGraphicsCapture(canvases[1], canvases);
|
||||
const auto& a = capture.displayed; const auto& b = *capture.declared;
|
||||
require(a.width == 320 && a.height == height && b.width == 320 && b.height == height &&
|
||||
a.bytesPerRow == 160 && a.rowStrideBytes == 256 && b.rowStrideBytes == 256 &&
|
||||
a.horizontalOffsetBytes == 252 && b.horizontalOffsetBytes == 252 &&
|
||||
a.canvasIdentifier == "front" && b.canvasIdentifier == "back" &&
|
||||
a.canvasAddress == front && b.canvasAddress == back && a.canvasBytes == 65536 && b.canvasBytes == 65536 &&
|
||||
a.viewportOffset == 4096 && b.viewportOffset == 4096 &&
|
||||
a.videoOrigin == front + 4096 && b.videoOrigin == back + 4096,
|
||||
"Custom GIME previews preserve actual 225/192-row geometry, pitch, pan and viewport offset on both CPUs");
|
||||
require(a.address == front + 4096 + 252 && b.address == back + 4096 + 252 &&
|
||||
a.byteAddresses[3] == front + 4096 + 255 && a.byteAddresses[4] == front + 4096 &&
|
||||
b.byteAddresses[4] == back + 4096 && a.byteAddresses[160] == front + 4096 + 256 + 252 &&
|
||||
a.bytes.front() == 0x33 && a.bytes[4] == 0x44 && b.bytes.front() == 0x22 && b.bytes[4] == 0x11 &&
|
||||
a.pixels.front() == 0x0000ff && b.pixels.front() == 0x00ff00 &&
|
||||
a.pixels[8] != a.pixels.front() && a.palette == b.palette,
|
||||
"Custom GIME previews render live physical samples with real 256-byte horizontal wrap and palette");
|
||||
const auto after = machine.snapshot();
|
||||
require(a.generation == b.generation && a.cycles == b.cycles && before.generation == after.generation &&
|
||||
before.cycles == after.cycles && before.frames == after.frames && before.cpu.PC == after.cpu.PC &&
|
||||
before.debuggerMappingFingerprint == after.debuggerMappingFingerprint && before.frame == after.frame &&
|
||||
std::equal(memory.begin(), memory.end(), ram),
|
||||
"Custom paired previews do not advance either guest CPU, change RAM/MMU or publish a frame");
|
||||
writeVideo(VCC::VideoRegister::Offset, (back + 4096) / 8);
|
||||
const auto flipped = machine.debuggerGraphicsCapture(canvases[0], canvases);
|
||||
require(flipped.displayed.canvasIdentifier == "back" && flipped.displayed.pixels == b.pixels &&
|
||||
flipped.declared->canvasIdentifier == "front" && flipped.declared->pixels == a.pixels &&
|
||||
capture.displayed.bytes.front() == 0x33,
|
||||
"A live canvas flip selects its real declared identity and rebases the other immutable viewport");
|
||||
rejects([&] { machine.debuggerGraphicsCapture(canvases[0]); });
|
||||
auto invalid = canvases; invalid[0].canvasBytes = 61440;
|
||||
rejects([&] { machine.debuggerGraphicsCapture(invalid[0], invalid); });
|
||||
invalid = canvases; invalid[0].physicalAddress += 4096;
|
||||
rejects([&] { machine.debuggerGraphicsCapture(invalid[0], invalid); });
|
||||
invalid = canvases; invalid[0].physicalAddress = ramSize;
|
||||
rejects([&] { machine.debuggerGraphicsCapture(invalid[0], invalid); });
|
||||
invalid = canvases; invalid[0].canvasBytes = 0;
|
||||
rejects([&] { machine.debuggerGraphicsCapture(invalid[0], invalid); });
|
||||
invalid = canvases; invalid[1].physicalAddress = front;
|
||||
rejects([&] { machine.debuggerGraphicsCapture(invalid[0], invalid); });
|
||||
invalid = canvases; invalid[1].canvasBytes = 8192;
|
||||
rejects([&] { machine.debuggerGraphicsCapture(invalid[1], invalid); });
|
||||
writeVideo(VCC::VideoRegister::Offset, (front + 0xf000) / 8);
|
||||
rejects([&] { machine.debuggerGraphicsCapture(canvases[1], canvases); });
|
||||
const std::vector<DebugGraphicsBuffer> allRam{{"whole", 0, DebugGraphicsMode::CurrentGime, false, ramSize}};
|
||||
writeVideo(VCC::VideoRegister::Offset, (ramSize - 4096) / 8);
|
||||
rejects([&] { machine.debuggerGraphicsCapture(allRam[0], allRam); });
|
||||
require(machine.snapshot().cycles == before.cycles && std::equal(memory.begin(), memory.end(), ram),
|
||||
"Out-of-canvas raster addresses are refused without inventing vertical wrapping or mutating the guest");
|
||||
writeVideo(VCC::VideoRegister::Offset, front / 8);
|
||||
writeVideo(VCC::VideoRegister::Mode, 0); // A future graphics canvas can currently contain BASIC text.
|
||||
const auto text = machine.debuggerGraphicsCapture(std::nullopt, canvases);
|
||||
require(text.displayed.text && text.displayed.canvasIdentifier.empty(),
|
||||
"Text registers inside a declared canvas are not falsely identified as a live graphics canvas");
|
||||
rejects([&] { machine.debuggerGraphicsCapture(canvases[1], canvases); });
|
||||
writeVideo(VCC::VideoRegister::Mode, 0x80);
|
||||
}
|
||||
}
|
||||
void checkBankedDevelopment(Processor processor) {
|
||||
MachineSession machine; machine.loadDiagnostic(processor);
|
||||
MmuSetMapType(1); Set_MmuEnabled(1); SetMmuRegister(0, 0); SetMmuRegister(2, 2);
|
||||
auto* ram = Get_mem_pointer();
|
||||
const Bytes a{0x12,0x20,0xfe}, b{0x12,0x12,0x20,0xfe};
|
||||
std::copy(a.begin(), a.end(), ram + 2 * 8192);
|
||||
std::copy(b.begin(), b.end(), ram + 3 * 8192);
|
||||
std::copy(a.begin(), a.end(), ram + 4 * 8192); // Identical code in an unqualified bank.
|
||||
const std::vector<DebugBankedModule> modules{
|
||||
{"a", {{2,2}}, {{0x4000,a}}},
|
||||
{"b", {{2,3}}, {{0x4000,b}}}
|
||||
};
|
||||
machine.debuggerSetPC(0x4000);
|
||||
machine.debuggerArmBankedDevelopmentBreakpoints({0x4000}, modules);
|
||||
const auto armed = machine.snapshot();
|
||||
require(armed.debuggerBankedDevelopment && armed.debuggerDevelopmentAttached,
|
||||
"Banked attachment verifies the current module without requiring overlapping overlays simultaneously");
|
||||
machine.resume(); machine.advance();
|
||||
require(machine.snapshot().state == RunState::Paused && machine.snapshot().cpu.PC == 0x4000,
|
||||
"Bank-qualified source stop fires before the mapped instruction on both CPUs");
|
||||
SetMmuRegister(2, 3);
|
||||
require(machine.snapshot().debuggerDevelopmentAttached && machine.snapshot().debuggerBankedDevelopment &&
|
||||
machine.snapshot().debuggerMappingFingerprint != armed.debuggerMappingFingerprint,
|
||||
"Expected overlay switch preserves banked attachment despite a changed flat fingerprint");
|
||||
ram[3 * 8192 + 1] = 0x39;
|
||||
require(!machine.snapshot().debuggerDevelopmentAttached,
|
||||
"Banked source identity checks complete module code beyond a coincidentally matching current opcode");
|
||||
ram[3 * 8192 + 1] = 0x12;
|
||||
SetMmuRegister(2, 4);
|
||||
require(!machine.snapshot().debuggerDevelopmentAttached && machine.snapshot().debuggerBankedDevelopment,
|
||||
"Identical bytes in a different physical RAM page cannot claim source identity");
|
||||
machine.debuggerSetPC(0x4000); machine.resume(); machine.advance();
|
||||
require(machine.snapshot().state == RunState::Running,
|
||||
"Conditional source point ignores a matching opcode in the wrong physical bank");
|
||||
machine.pause(); machine.debuggerClearDevelopmentBreakpoints();
|
||||
auto qualified = modules;
|
||||
qualified[0].breakpointAddresses = std::vector<std::uint16_t>{0x4000};
|
||||
qualified[1].breakpointAddresses = std::vector<std::uint16_t>{};
|
||||
SetMmuRegister(2, 3); machine.debuggerSetPC(0x4000);
|
||||
machine.debuggerArmBankedDevelopmentBreakpoints({0x4000}, qualified);
|
||||
require(machine.snapshot().debuggerDevelopmentAttached,
|
||||
"A module without selected source stops remains available for source inspection and stepping");
|
||||
machine.resume(); machine.advance();
|
||||
require(machine.snapshot().state == RunState::Running,
|
||||
"A source breakpoint in overlay a does not stop overlay b at the same logical address and opcode");
|
||||
machine.pause(); SetMmuRegister(2, 2); machine.debuggerSetPC(0x4000);
|
||||
machine.resume(); machine.advance();
|
||||
require(machine.snapshot().state == RunState::Paused && machine.snapshot().cpu.PC == 0x4000,
|
||||
"The selected module's source point still stops in its physical bank");
|
||||
machine.debuggerSetBreakpoints({0x4567});
|
||||
machine.debuggerArmBankedDevelopmentBreakpoints({}, modules);
|
||||
require(machine.snapshot().debuggerBankedDevelopment && machine.snapshot().debuggerDevelopmentAttached &&
|
||||
machine.debuggerSnapshot().breakpoints == std::vector<std::uint16_t>{0x4567},
|
||||
"Inspect-only bank attachment preserves module evidence and independent manual breakpoints");
|
||||
machine.resume(); machine.advance(); machine.pause();
|
||||
require(machine.snapshot().debuggerDevelopmentAttached,
|
||||
"Pause after continuing without source stops can still inspect verified banked code");
|
||||
machine.debuggerClearDevelopmentBreakpoints(); machine.debuggerSetBreakpoints({});
|
||||
qualified[0].breakpointAddresses = std::vector<std::uint16_t>{0x4001};
|
||||
rejects([&] { machine.debuggerArmBankedDevelopmentBreakpoints({0x4000}, qualified); });
|
||||
qualified[0].breakpointAddresses = std::vector<std::uint16_t>{};
|
||||
rejects([&] { machine.debuggerArmBankedDevelopmentBreakpoints({0x4000}, qualified); });
|
||||
require(!machine.snapshot().debuggerBankedDevelopment,
|
||||
"Unqualified points cannot replace a valid source-breakpoint configuration");
|
||||
SetMmuRegister(2, 4);
|
||||
machine.debuggerSetBreakpoints({0x4000});
|
||||
machine.debuggerArmBankedDevelopmentBreakpoints({0x4000}, modules);
|
||||
machine.debuggerSetPC(0x4000); machine.resume(); machine.advance();
|
||||
require(machine.snapshot().state == RunState::Paused && !machine.snapshot().debuggerDevelopmentAttached,
|
||||
"An independently owned manual point still stops in an unqualified bank");
|
||||
machine.debuggerClearDevelopmentBreakpoints();
|
||||
require(machine.debuggerSnapshot().breakpoints == std::vector<std::uint16_t>{0x4000},
|
||||
"Clearing banked source stops preserves independently owned manual points");
|
||||
machine.debuggerSetBreakpoints({});
|
||||
rejects([&] { machine.debuggerArmBankedDevelopmentBreakpoints({0x4000}, {{"bad",{{1,2}},modules[0].guards}}); });
|
||||
rejects([&] { machine.debuggerArmBankedDevelopmentBreakpoints({0x4000}, {{"bad",{{2,64}},modules[0].guards}}); });
|
||||
rejects([&] { machine.debuggerArmBankedDevelopmentBreakpoints({0x4000}, {modules[0],modules[0]}); });
|
||||
auto ambiguous = modules[0]; ambiguous.identifier = "ambiguous";
|
||||
rejects([&] { machine.debuggerArmBankedDevelopmentBreakpoints({0x4000}, {modules[0],ambiguous}); });
|
||||
require(!machine.snapshot().debuggerBankedDevelopment && machine.debuggerSnapshot().breakpoints.empty(),
|
||||
"Invalid banked configurations leave breakpoint ownership unchanged");
|
||||
|
||||
// A resident thunk selects overlay b while stepping. Logical instruction
|
||||
// addresses overlap with overlay a, including their first identical opcode.
|
||||
const Bytes thunk{0x86,0x03,0xb7,0xff,0xa2,0x7e,0x40,0x00};
|
||||
std::copy(thunk.begin(), thunk.end(), ram + 0x1000);
|
||||
auto steppingModules = modules;
|
||||
steppingModules.push_back({"resident",{{0,0}},{{0x1000,thunk}}});
|
||||
SetMmuRegister(2, 2); machine.debuggerSetPC(0x1000);
|
||||
machine.debuggerArmBankedDevelopmentBreakpoints({0x1000}, steppingModules);
|
||||
const std::vector<DebugSourceInstruction> instructions{
|
||||
{0x1000,1,{0x86,0x03},"resident"},{0x1002,1,{0xb7,0xff,0xa2},"resident"},{0x1005,1,{0x7e,0x40,0x00},"resident"},
|
||||
{0x4000,10,{0x12},"a"},{0x4001,11,{0x20,0xfe},"a"},
|
||||
{0x4000,20,{0x12},"b"},{0x4001,21,{0x12},"b"},{0x4002,22,{0x20,0xfe},"b"}
|
||||
};
|
||||
const auto start = machine.snapshot();
|
||||
rejects([&] { machine.debuggerStepSource(SourceStepMode::Into, instructions, start.generation,
|
||||
start.debuggerProgramRevision, start.debuggerMappingFingerprint + 1, start.cpu.PC); });
|
||||
machine.debuggerStepSource(SourceStepMode::Into, instructions, start.generation,
|
||||
start.debuggerProgramRevision, start.debuggerMappingFingerprint, start.cpu.PC);
|
||||
machine.advance();
|
||||
require(machine.snapshot().state == RunState::Paused && machine.snapshot().cpu.PC == 0x4000 &&
|
||||
GetMMUState().Effective[2].SourceStart == 3 * 8192 && machine.snapshot().debuggerDevelopmentAttached &&
|
||||
machine.debuggerSnapshot().stopReason == "C source location reached",
|
||||
"Banked C step follows a verified resident bank switch and selects the matching overlay source");
|
||||
machine.debuggerClearDevelopmentBreakpoints();
|
||||
require(!machine.snapshot().debuggerBankedDevelopment, "Explicit detach clears bank-qualified mode");
|
||||
}
|
||||
void checkAssemblyInstructionBoundary(Processor processor) {
|
||||
MachineSession machine;
|
||||
machine.loadDiagnostic(processor);
|
||||
machine.debuggerConfigureBreakpoints({0x4567}, {0x3f02});
|
||||
Bytes binary;
|
||||
block(binary, 0x3f00, {0x86,0x8f,0xb7,0x04,0x00,0x20,0xfe});
|
||||
finish(binary, 0x3f00);
|
||||
const std::vector<DebugCodeGuard> guards{
|
||||
{0x3f00,{0x86,0x8f}}, {0x3f02,{0xb7,0x04,0x00}}, {0x3f05,{0x20,0xfe}}
|
||||
};
|
||||
const auto before = machine.snapshot();
|
||||
auto launch = [&](const std::vector<std::uint16_t>& points, const std::vector<DebugCodeGuard>& code,
|
||||
bool pause, bool hitachi, const Snapshot& expected) {
|
||||
machine.launchAssembly(binary, points, code, pause, hitachi, expected.generation, expected.debuggerProgramRevision, expected.debuggerMappingFingerprint);
|
||||
};
|
||||
MemWrite8(0x41, 0x0400);
|
||||
if (processor == Processor::MC6809) rejects([&] { launch({}, guards, true, true, before); });
|
||||
rejects([&] { launch({0x3f01}, guards, true, false, before); });
|
||||
rejects([&] { launch({}, {{0x3f02,{0xb7,0x04,0x01}}}, true, false, before); });
|
||||
require(machine.snapshot().cpu.PC == before.cpu.PC && machine.snapshot().debuggerProgramRevision == before.debuggerProgramRevision,
|
||||
"A rejected assembly launch preserves execution and ownership");
|
||||
launch({0x3f02}, guards, true, false, before);
|
||||
auto entry = machine.snapshot();
|
||||
require(entry.state == RunState::Paused && entry.cpu.PC == 0x3f00 && entry.cycles == before.cycles,
|
||||
"Debug from Entry stops before running any instruction");
|
||||
machine.controlAssembly(false, entry);
|
||||
machine.advance();
|
||||
auto store = machine.snapshot();
|
||||
require(store.state == RunState::Paused && store.cpu.PC == 0x3f02 && MemRead8(0x0400) == 0x41,
|
||||
"Assembly source breakpoint stops before the screen store");
|
||||
machine.controlAssembly(true, store);
|
||||
require(machine.snapshot().cpu.PC == 0x3f05 && MemRead8(0x0400) == 0x8f,
|
||||
"Step executes the store once");
|
||||
rejects([&] { machine.controlAssembly(true, store); });
|
||||
machine.updateAssembly({}, machine.snapshot());
|
||||
require(machine.debuggerSnapshot().disabledBreakpoints == std::vector<std::uint16_t>{0x3f02},
|
||||
"Removing an assembly point restores a disabled manual point");
|
||||
launch({}, guards, false, false, machine.snapshot());
|
||||
const auto repeated = machine.snapshot();
|
||||
machine.clearAssembly(entry);
|
||||
machine.advance();
|
||||
require(machine.snapshot().state == RunState::Running && machine.snapshot().debuggerDevelopmentAttached &&
|
||||
machine.snapshot().cpu.PC == 0x3f05, "Repeat run has no implicit breakpoint or stale ownership");
|
||||
const auto live = machine.snapshot();
|
||||
rejects([&] { machine.pauseAssembly(entry); });
|
||||
auto after = machine.snapshot();
|
||||
require(after.state == RunState::Running && after.cpu.PC == live.cpu.PC && after.cycles == live.cycles &&
|
||||
after.debuggerAssemblyAttached, "A queued Pause from the previous program leaves the new owner running");
|
||||
machine.pauseAssembly(repeated);
|
||||
after = machine.snapshot();
|
||||
require(after.state == RunState::Paused && after.cpu.PC == live.cpu.PC && after.cycles == live.cycles,
|
||||
"Pause honors the current owner after its guest has advanced");
|
||||
MemWrite8(0x12, 0x3f00);
|
||||
rejects([&] { machine.controlAssembly(true, machine.snapshot()); });
|
||||
require(!machine.snapshot().debuggerDevelopmentAttached, "Changed instruction bytes invalidate source stepping");
|
||||
machine.clearAssembly(machine.snapshot());
|
||||
require(machine.debuggerSnapshot().breakpoints == std::vector<std::uint16_t>{0x4567}, "Manual breakpoint survives source detach");
|
||||
}
|
||||
|
||||
}
|
||||
void CheckBinaryParsing() {
|
||||
Bytes file; block(file,0x1234,{1,2,3}); block(file,0xabcd,{}); block(file,0x1235,{4,5}); finish(file,0x7fff);
|
||||
const auto image = BinaryImage::parse(file);
|
||||
require(image.entry==0x7fff && image.blocks.size()==3, "Multi-record parser preserves entry and record order");
|
||||
require(image.blocks[0].address==0x1234 && image.blocks[0].bytes==Bytes({1,2,3}) &&
|
||||
image.blocks[1].address==0xabcd && image.blocks[1].bytes.empty() && image.blocks[2].bytes==Bytes({4,5}),
|
||||
"Headers are big-endian and zero-length/overlapping records are retained");
|
||||
Bytes jump; finish(jump,1); require(BinaryImage::parse(jump).blocks.empty(), "A transfer-only file retains the Windows jump behavior");
|
||||
Bytes large; block(large,0,Bytes(65535,0x5a)); finish(large);
|
||||
require(BinaryImage::parse(large).blocks[0].bytes.size()==65535, "Maximum 16-bit block length is accepted");
|
||||
}
|
||||
void CheckBinaryValidation() {
|
||||
const auto good = program();
|
||||
for (std::size_t size=0; size<good.size(); ++size)
|
||||
rejects([&] { BinaryImage::parse({good.begin(),good.begin()+size}); });
|
||||
for (unsigned type : {1u,2u,254u}) {
|
||||
auto bad=good; bad[0]=type; rejects([&] { BinaryImage::parse(bad); });
|
||||
}
|
||||
for (unsigned address : {0u,0x8000u,0xffffu}) {
|
||||
Bytes bad; finish(bad,address); rejects([&] { BinaryImage::parse(bad); });
|
||||
}
|
||||
auto bad=good; bad[bad.size()-3]=1; rejects([&] { BinaryImage::parse(bad); });
|
||||
bad=good; bad.push_back(0); rejects([&] { BinaryImage::parse(bad); });
|
||||
rejects([&] { BinaryImage::parse(Bytes(BinaryImage::maxBytes+1)); });
|
||||
// A valid first block followed by bad input must not reach memory or I/O.
|
||||
for (auto cpu : {Processor::MC6809,Processor::HD6309}) {
|
||||
MachineSession machine; machine.loadDiagnostic(cpu); machine.resume(); machine.advance();
|
||||
Bytes bytes; block(bytes,0x5000,{0x77}); block(bytes,0xffdf,{0}); bytes.push_back(9);
|
||||
const auto before=machine.snapshot(); const auto memory=Get_mem_pointer();
|
||||
const Bytes saved(memory,memory+0x80000); const auto events=VCC::gEvents.GetSize();
|
||||
rejects([&] { machine.quickLoad(bytes); });
|
||||
require(std::equal(saved.begin(),saved.end(),memory) && !MemCheckWrite(0x8000), "Late invalid header preserves all RAM and mapped I/O state");
|
||||
const auto after=machine.snapshot();
|
||||
require(after.state==before.state && after.cpu.PC==before.cpu.PC && after.cycles==before.cycles &&
|
||||
after.frame==before.frame && events==VCC::gEvents.GetSize(), "Rejected binary preserves execution and scheduled events");
|
||||
}
|
||||
}
|
||||
void CheckBinarySession() {
|
||||
MachineSession empty; rejects([&] { empty.quickLoad(program()); });
|
||||
for (auto cpu : {Processor::MC6809,Processor::HD6309}) {
|
||||
for (bool running : {false,true}) {
|
||||
MachineSession machine; machine.loadDiagnostic(cpu); machine.resume(); machine.advance();
|
||||
auto disk=std::make_shared<VCC::Devices::Fd502Device>(Bytes(8192));
|
||||
disk->mount(0,VCC::Devices::DiskImage::blank());
|
||||
machine.cartridges().configure({nullptr,nullptr,nullptr,nullptr,disk},true,4);
|
||||
machine.cassette().mount({0x55,0x3c},TapeFormat::CAS);
|
||||
MemWrite8(0xa5,0x6000); if (!running) machine.pause();
|
||||
MemWrite8(0xff,0xff02); MemWrite8(4,0xff03); MemWrite8(4,0xff01); MemWrite8(0xfd,0xff02);
|
||||
machine.setKeyboard(std::uint64_t{1}<<1);
|
||||
const auto before=machine.snapshot(); const auto events=VCC::gEvents.GetSize();
|
||||
machine.quickLoad(program()); const auto loaded=machine.snapshot();
|
||||
require(loaded.cpu.PC==0x3000 && loaded.state==RunState::Running, "Quick-load starts selected CPU at the execution record");
|
||||
require(MemRead8(0x6000)==0xa5 && loaded.frames==before.frames && loaded.cycles==before.cycles &&
|
||||
loaded.generation==before.generation && events==VCC::gEvents.GetSize(), "Quick-load retains unrelated memory, timing and machine identity");
|
||||
require(disk->image(0) && disk->image(0)->dirty() && machine.cassette().snapshot().mounted &&
|
||||
machine.cartridges().physicalSlot()==4, "Quick-load retains dirty floppy, cassette and cartridge assignments");
|
||||
require((MemRead8(0xff00)&0x7f)==0x7f, "Quick-load releases held keys");
|
||||
machine.advance(); require(MemRead8(0x5000)==0x6b && machine.snapshot().cpu.PC==0x3005, "Loaded program executes on both CPU engines");
|
||||
}
|
||||
}
|
||||
}
|
||||
void CheckBinaryMappedWrites() {
|
||||
checkPausedGraphicsBuffers(Processor::MC6809);
|
||||
checkPausedGraphicsBuffers(Processor::HD6309);
|
||||
checkCurrentGimeCanvases(Processor::MC6809);
|
||||
checkCurrentGimeCanvases(Processor::HD6309);
|
||||
checkBankedDevelopment(Processor::MC6809);
|
||||
checkBankedDevelopment(Processor::HD6309);
|
||||
checkAssemblyInstructionBoundary(Processor::MC6809);
|
||||
checkAssemblyInstructionBoundary(Processor::HD6309);
|
||||
for (auto cpu : {Processor::MC6809, Processor::HD6309}) {
|
||||
MachineSession machine; machine.loadDiagnostic(cpu);
|
||||
machine.debuggerConfigureBreakpoints({0x4500}, {0x3005});
|
||||
machine.debuggerLoadBinary(program(), 0x3005);
|
||||
machine.advance();
|
||||
rejects([&] { machine.debuggerContinueFromEntry(0x3000); });
|
||||
require(machine.snapshot().state == RunState::Paused && machine.snapshot().cpu.PC == 0x3005,
|
||||
"Continuing a different source stop preserves the actual stop");
|
||||
machine.debuggerContinueFromEntry(0x3005);
|
||||
machine.advance();
|
||||
require(machine.snapshot().state == RunState::Running && machine.snapshot().debuggerDevelopmentAttached &&
|
||||
machine.snapshot().cpu.PC == 0x3005, "Play continues through its one-time entry and retains the C program identity");
|
||||
require(machine.debuggerSnapshot().breakpoints == std::vector<std::uint16_t>{0x4500} &&
|
||||
machine.debuggerSnapshot().disabledBreakpoints == std::vector<std::uint16_t>{0x3005},
|
||||
"The one-time C entry preserves independently configured manual breakpoints");
|
||||
machine.debuggerConfigureBreakpoints({0x4500}, {0x3005});
|
||||
machine.debuggerLoadBinary(program(), std::vector<std::uint16_t>{0x3000,0x3005});
|
||||
machine.advance(); require(machine.snapshot().state == RunState::Paused && machine.snapshot().cpu.PC == 0x3000,
|
||||
"Multiple development points stop before the first instruction on both CPUs");
|
||||
require(machine.snapshot().debuggerDevelopmentAttached, "Atomic quickload attaches its verified source epoch");
|
||||
machine.resume(); machine.advance();
|
||||
require(machine.snapshot().state == RunState::Paused && machine.snapshot().cpu.PC == 0x3005,
|
||||
"Continuing passes only the current point and can stop in another source file");
|
||||
machine.debuggerClearDevelopmentBreakpoints();
|
||||
auto state = machine.debuggerSnapshot();
|
||||
require(state.breakpoints == std::vector<std::uint16_t>{0x4500} && state.disabledBreakpoints == std::vector<std::uint16_t>{0x3005},
|
||||
"Clearing development points preserves manual points and restores temporarily enabled ones");
|
||||
require(!machine.snapshot().debuggerDevelopmentAttached, "Explicit detach clears source attachment");
|
||||
|
||||
// Guards cover code beyond the selected instruction, so a coincidentally
|
||||
// matching opcode in an earlier loader cannot be mistaken for the program.
|
||||
const std::vector<DebugCodeGuard> guards{{0x3000,{0x86,0x6b}}, {0x3002,{0xb7,0x50,0}}, {0x3005,{0x20,0xfe}}, {0x6000,{0x39}}};
|
||||
machine.debuggerSetPC(0x3000);
|
||||
machine.debuggerArmDevelopmentBreakpoints({}, guards);
|
||||
require(!machine.snapshot().debuggerDevelopmentAttached,
|
||||
"Empty flat inspection guards do not invent an attachment before a verified stop");
|
||||
machine.debuggerArmDevelopmentBreakpoints({0x3000}, guards);
|
||||
const auto before = machine.snapshot(); machine.resume(); machine.advance();
|
||||
require(machine.snapshot().state == RunState::Running && !machine.snapshot().debuggerDevelopmentAttached,
|
||||
"Disk-source points ignore boot code until every expected code range is loaded");
|
||||
machine.pause(); MemWrite8(0x39,0x6000); machine.debuggerSetPC(0x3000);
|
||||
machine.resume(); machine.advance();
|
||||
require(machine.snapshot().state == RunState::Paused && machine.snapshot().cpu.PC == 0x3000 &&
|
||||
machine.snapshot().debuggerDevelopmentAttached && machine.snapshot().generation == before.generation &&
|
||||
machine.snapshot().debuggerProgramRevision == before.debuggerProgramRevision,
|
||||
"Disk-loaded exact code attaches and stops without quickload or resetting the machine");
|
||||
const std::vector<DebugCodeGuard> mergedGuards{{0x3000,{0x86,0x6b,0xb7,0x50,0,0x20,0xfe}}, {0x6000,{0x39}}};
|
||||
machine.debuggerArmDevelopmentBreakpoints({}, mergedGuards);
|
||||
require(machine.snapshot().debuggerDevelopmentAttached,
|
||||
"Empty inspection preserves verified mapping when only guard segmentation changes");
|
||||
machine.resume(); machine.advance(); machine.pause();
|
||||
require(machine.snapshot().debuggerDevelopmentAttached && machine.snapshot().cpu.PC == 0x3005,
|
||||
"Flat continue removes selected stops while retaining verified code identity");
|
||||
MemWrite8(0x12,0x6000);
|
||||
require(!machine.snapshot().debuggerDevelopmentAttached,
|
||||
"Paused capture rejects guest-modified executable bytes without debugger writes");
|
||||
MemWrite8(0x39,0x6000); machine.debuggerSetPC(0x3000);
|
||||
machine.debuggerArmDevelopmentBreakpoints({0x3000}, guards); machine.resume(); machine.advance();
|
||||
require(machine.snapshot().debuggerDevelopmentAttached,
|
||||
"A new verified stop can re-establish exact flat code and runtime mapping");
|
||||
machine.debuggerWriteMemory(0x6000,{0x12});
|
||||
require(!machine.snapshot().debuggerDevelopmentAttached && machine.debuggerSnapshot().breakpoints == std::vector<std::uint16_t>{0x4500},
|
||||
"Debugger writes cancel conditional source points and preserve manual points");
|
||||
machine.debuggerConfigureBreakpoints({0x3000,0x4500}, {0x3005});
|
||||
machine.debuggerSetPC(0x3000); machine.debuggerArmDevelopmentBreakpoints({0x3000}, guards);
|
||||
machine.resume(); machine.advance();
|
||||
require(machine.snapshot().state == RunState::Paused && !machine.snapshot().debuggerDevelopmentAttached,
|
||||
"An independently enabled manual breakpoint still stops before disk code is loaded");
|
||||
machine.debuggerClearDevelopmentBreakpoints();
|
||||
require(machine.debuggerSnapshot().breakpoints == std::vector<std::uint16_t>({0x3000,0x4500}),
|
||||
"A shared manual breakpoint is never claimed by the development feature");
|
||||
rejects([&] { machine.debuggerArmDevelopmentBreakpoints({0x3001}, guards); });
|
||||
rejects([&] { machine.debuggerArmDevelopmentBreakpoints({0x3000}, {{0x3000,{0x12}}, {0x3000,{0x12}}}); });
|
||||
rejects([&] { machine.debuggerArmDevelopmentBreakpoints({0xff00}, {{0xff00,{0x12}}}); });
|
||||
machine.debuggerArmDevelopmentBreakpoints({0x3002}, guards); machine.softReset();
|
||||
require(!machine.snapshot().debuggerDevelopmentAttached &&
|
||||
machine.debuggerSnapshot().breakpoints == std::vector<std::uint16_t>({0x3000,0x4500}),
|
||||
"Reset drops pending development points without erasing user breakpoints");
|
||||
}
|
||||
// The development loader is stricter than legacy quickload: two logical
|
||||
// spans must not overwrite the same physical RAM through MMU aliases.
|
||||
for (auto cpu : {Processor::MC6809,Processor::HD6309}) {
|
||||
MachineSession machine; machine.loadDiagnostic(cpu);
|
||||
const auto original = machine.snapshot();
|
||||
Set_MmuEnabled(1); SetMmuRegister(0,3); SetMmuRegister(1,3);
|
||||
const auto remapped = machine.snapshot();
|
||||
require(original.debuggerMappingFingerprint != remapped.debuggerMappingFingerprint,
|
||||
"Source provenance detects active MMU remapping without a reset");
|
||||
SetMmuRegister(9,12); // Task 1 is inactive.
|
||||
require(machine.snapshot().debuggerMappingFingerprint == remapped.debuggerMappingFingerprint,
|
||||
"Inactive-task register edits do not change effective source mapping");
|
||||
machine.debuggerSetBreakpoints({0x4500});
|
||||
Bytes image; block(image,0x0100,{0x12}); block(image,0x2100,{0x39}); finish(image,0x0100);
|
||||
auto* ram = Get_mem_pointer(); const auto previousByte = ram[3*8192+0x100];
|
||||
rejects([&] { machine.debuggerLoadBinary(image,0x0100); });
|
||||
require(ram[3*8192+0x100] == previousByte && machine.snapshot().debuggerProgramRevision == remapped.debuggerProgramRevision &&
|
||||
machine.debuggerSnapshot().breakpoints == std::vector<std::uint16_t>{0x4500},
|
||||
"Rejected aliased development image preserves RAM, breakpoints and provenance epoch");
|
||||
SetMmuRegister(1,4);
|
||||
machine.debuggerLoadBinary(image,0x0100);
|
||||
const auto loaded = machine.snapshot();
|
||||
require(loaded.debuggerProgramRevision > remapped.debuggerProgramRevision && loaded.generation == remapped.generation,
|
||||
"Successful development load changes program provenance without restarting machine");
|
||||
machine.pause(); machine.debuggerStep();
|
||||
require(machine.snapshot().debuggerProgramRevision == loaded.debuggerProgramRevision,
|
||||
"Pause and instruction stepping preserve program provenance");
|
||||
machine.debuggerWriteMemory(0x2100,{0x12});
|
||||
require(machine.snapshot().debuggerProgramRevision > loaded.debuggerProgramRevision,
|
||||
"Explicit debugger memory edits invalidate a loaded C source map");
|
||||
}
|
||||
for (auto cpu : {Processor::MC6809,Processor::HD6309}) {
|
||||
MachineSession machine; machine.loadDiagnostic(cpu);
|
||||
Set_MmuEnabled(1); SetMmuRegister(0,3); SetMmuRegister(1,9);
|
||||
Bytes file; block(file,0x1ffe,{1,2,3,4}); block(file,0x1fff,{9}); finish(file);
|
||||
machine.quickLoad(file);
|
||||
auto* ram=Get_mem_pointer();
|
||||
require(ram[3*8192+8190]==1 && ram[3*8192+8191]==9 && ram[9*8192]==3 && ram[9*8192+1]==4,
|
||||
"Ordered overlapping loads follow MMU mapping across a bank boundary");
|
||||
// Ordered I/O writes can change the mapping before a later data record.
|
||||
file.clear(); block(file,0xffa0,{5}); block(file,0x123,{0x7a}); block(file,0xffdf,{0});
|
||||
block(file,0x8000,{0x66}); block(file,0xfffe,{0x11,0x22,0x33,0x44}); finish(file);
|
||||
machine.quickLoad(file);
|
||||
require(GetMMUState().Task0[0]==5 && ram[5*8192+0x123]==0x7a && MemRead8(0x8000)==0x66,
|
||||
"Quick-load preserves live I/O writes and RAM under a disabled ROM overlay");
|
||||
require(MemRead8(0)==0x33 && MemRead8(1)==0x44, "Records wrap at the 16-bit address boundary");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#include "../../src/devices/DriveWireDevice.h"
|
||||
#include <algorithm>
|
||||
#include "CoreChecks.h"
|
||||
#include "../../src/devices/Ramdisk/memboard.h"
|
||||
#include "../../src/devices/ssc/tms7000.h"
|
||||
#include "../../src/devices/ssc/ssc_core.h"
|
||||
#include <array>
|
||||
#include <stdexcept>
|
||||
|
||||
static void require(bool condition, const char* message) {
|
||||
if (!condition) throw std::runtime_error(message);
|
||||
}
|
||||
|
||||
void CheckRamDisk() {
|
||||
require(!InitMemBoard(), "RAM disk allocation failed");
|
||||
// Same offset and bank values as the Windows guest probe.
|
||||
WritePort(0x40, 0x34); WritePort(0x41, 0x12);
|
||||
for (unsigned char bank = 0; bank < 8; ++bank) {
|
||||
WritePort(0x42, bank); WriteArray(17 + bank);
|
||||
}
|
||||
for (unsigned char bank = 0; bank < 8; ++bank) {
|
||||
WritePort(0x42, bank);
|
||||
require(ReadArray() == 17 + bank, "RAM disk bank data aliases another bank");
|
||||
require(ReadArray() == 17 + bank, "RAM disk read unexpectedly advances address");
|
||||
}
|
||||
// High address bits are masked to three bits by the hardware contract.
|
||||
WritePort(0x42, 0xff);
|
||||
require(ReadArray() == 24, "RAM disk bank mask differs");
|
||||
WritePort(0x40, 0xff); WritePort(0x41, 0xff);
|
||||
WriteArray(0xa5);
|
||||
require(ReadArray() == 0xa5, "Last RAM disk byte is inaccessible");
|
||||
require(!InitMemBoard(), "RAM disk reinitialization failed");
|
||||
require(ReadArray() == 0, "RAM disk address zero did not reset");
|
||||
WritePort(0x40, 0xff); WritePort(0x41, 0xff); WritePort(0x42, 7);
|
||||
require(ReadArray() == 0, "RAM disk reinitialization did not clear last byte");
|
||||
}
|
||||
|
||||
void CheckMicrocontroller() {
|
||||
std::array<uint8_t, 4096> rom{};
|
||||
rom.fill(0xff);
|
||||
rom[0] = 0xb3; // INC A
|
||||
rom[1] = 0xe0; rom[2] = 0xfd; // JMP back
|
||||
rom[4094] = 0xf0; rom[4095] = 0;
|
||||
ssc::Tms7000 cpu;
|
||||
cpu.LoadRom(rom.data(), rom.size()); cpu.Reset();
|
||||
require(cpu.PC() == 0xf000, "TMS7000 big-endian reset vector failed");
|
||||
const auto initial = cpu.PeekReg(0);
|
||||
int cycles = 0;
|
||||
for (int i = 0; i < 50; ++i) cycles += cpu.Execute(360);
|
||||
require(cycles == 18000, "TMS7000 cycle accounting differs");
|
||||
require(cpu.PC() == 0xf000, "TMS7000 branch target differs");
|
||||
require(cpu.PeekReg(0) == uint8_t(initial + 1500), "TMS7000 increment/wrap failed");
|
||||
}
|
||||
|
||||
void CheckCartridgeBus() {
|
||||
ssc::SscCore core;
|
||||
core.Reset();
|
||||
// An unaddressed cartridge must stay silent for MPI disk reads.
|
||||
for (int port = 0; port < 256; ++port)
|
||||
if (port != 0x7d && port != 0x7e)
|
||||
require(core.ReadPort(uint8_t(port)) == 0, "SSC intercepts another device's port");
|
||||
require(core.ReadPort(0x7d) == 0xff, "SSC control-port read differs");
|
||||
require((core.ReadPort(0x7e) & 0x80) != 0, "SSC initially busy");
|
||||
core.WritePort(0x7e, 0x55);
|
||||
require((core.ReadPort(0x7e) & 0x80) == 0, "SSC command did not assert busy");
|
||||
core.WritePort(0x7d, 0);
|
||||
require((core.ReadPort(0x7e) & 0x80) != 0, "SSC reset edge did not clear busy");
|
||||
}
|
||||
|
||||
namespace {
|
||||
using VCC::Devices::DriveWireDevice;
|
||||
using VCC::Devices::DriveWireTransport;
|
||||
|
||||
struct EchoWire final : DriveWireTransport {
|
||||
State status = State::connecting;
|
||||
std::deque<std::uint8_t> echo;
|
||||
State state() override { return status; }
|
||||
std::size_t read(std::uint8_t* bytes, std::size_t limit) override {
|
||||
std::size_t count = std::min(limit, echo.size());
|
||||
for (std::size_t i = 0; i < count; ++i) { bytes[i] = echo.front(); echo.pop_front(); }
|
||||
return count;
|
||||
}
|
||||
bool write(const std::uint8_t* bytes, std::size_t size) override {
|
||||
echo.insert(echo.end(), bytes, bytes + size);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void CheckDriveWireProtocol() {
|
||||
DriveWireDevice dw;
|
||||
std::vector<EchoWire*> sockets;
|
||||
dw.setFactory([&](const std::string& host, std::uint16_t port) {
|
||||
require(host == "localhost" && port == 2323, "Wrong DriveWire TCP destination");
|
||||
auto socket = std::make_unique<EchoWire>();
|
||||
sockets.push_back(socket.get());
|
||||
return socket;
|
||||
});
|
||||
auto send = [&](std::initializer_list<std::uint8_t> bytes) {
|
||||
for (auto byte : bytes) dw.writePort(0x42, byte);
|
||||
};
|
||||
auto receive = [&](const std::vector<std::uint8_t>& expected) {
|
||||
for (auto byte : expected) {
|
||||
require(dw.readPort(0x41) == 2 && dw.readPort(0x41) == 2, "Becker polling consumed a byte");
|
||||
require(dw.readPort(0x42) == byte, "DriveWire response mismatch");
|
||||
}
|
||||
require(dw.readPort(0x41) == 0 && dw.readPort(0x42) == 0, "Unexpected trailing DriveWire response");
|
||||
};
|
||||
auto fast = [&](std::uint8_t channel, const std::string& data) {
|
||||
for (auto c : data) send({std::uint8_t(0x80 + channel), std::uint8_t(c)});
|
||||
};
|
||||
auto response = [&](std::uint8_t channel, const std::string& text) {
|
||||
send({0x43}); receive({std::uint8_t(17 + channel), std::uint8_t(text.size())});
|
||||
send({0x63, channel, std::uint8_t(text.size())}); receive({text.begin(), text.end()});
|
||||
};
|
||||
|
||||
// Only data-register writes feed packets. DWINIT responds after both bytes.
|
||||
dw.writePort(0x41, 0x43); send({0x5a}); receive({}); send({1}); receive({4});
|
||||
fast(0, "tcp connect localhost 2323\r");
|
||||
require(sockets.empty(), "Unopened DriveWire channel connected");
|
||||
|
||||
send({0x45, 0, 0xc4, 0, 0x29}); // driver Init and per-path SS.Open
|
||||
send({0xc4, 0, 0x28});
|
||||
for (unsigned i = 0; i < 26; ++i) send({0xff}); // opaque SS.ComSt descriptor
|
||||
fast(0, "TCP CONNECT localhost 2323\r");
|
||||
require(sockets.size() == 1, "Expected exactly one outbound connection");
|
||||
send({0x43}); receive({0, 0}); // socket handshaking
|
||||
sockets[0]->status = DriveWireTransport::State::connected;
|
||||
response(0, "SUCCESS\n\r");
|
||||
send({0xc4, 0, 0x29}); // duplicate open must preserve an active stream
|
||||
send({0x64, 0, 3, 0, 0xff, 0x43}); // preserve arbitrary bytes, including opcodes
|
||||
send({0x43}); receive({17, 3}); send({0x63, 0, 2}); receive({0, 0xff});
|
||||
send({0x43}); receive({1, 0x43});
|
||||
send({0xc3, 0, 0x7f}); sockets[0]->status = DriveWireTransport::State::closed;
|
||||
send({0x43}); receive({1, 0x7f}); // preserve bytes received just before EOF
|
||||
send({0x43}); receive({16, 0}); send({0x43}); receive({0, 0});
|
||||
|
||||
send({0x45, 2}); fast(2, "tcp listen 8080\r");
|
||||
response(2, "FAIL 203\n\r");
|
||||
send({0x43}); receive({16, 2});
|
||||
send({0x45, 2}); fast(2, "tcp connect localhost 99999\r");
|
||||
response(2, "FAIL 203\n\r");
|
||||
send({0x43}); receive({16, 2});
|
||||
require(sockets.size() == 1, "Invalid or inbound command created a socket");
|
||||
|
||||
send({0x45, 2}); fast(2, "tcp connect localhost 2323\r");
|
||||
sockets.back()->status = DriveWireTransport::State::failed;
|
||||
response(2, "FAIL 246\n\r");
|
||||
send({0x43}); receive({16, 2});
|
||||
|
||||
// Reset cancels an in-flight connection and restores byte framing.
|
||||
send({0x45, 2}); fast(2, "tcp connect localhost 2323\r");
|
||||
send({0xff, 0x43}); receive({0, 0});
|
||||
send({0x45, 2}); fast(2, "tcp connect localhost 2323\r");
|
||||
require(sockets.size() == 4, "Connection did not reopen after reset");
|
||||
sockets.back()->status = DriveWireTransport::State::connected;
|
||||
response(2, "SUCCESS\n\r");
|
||||
send({0xc5, 2, 0x43}); receive({0, 0});
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
void CheckDriveWireProtocol();
|
||||
void CheckRamDisk();
|
||||
void CheckMicrocontroller();
|
||||
void CheckCartridgeBus();
|
||||
int smoke_cpu();
|
||||
int smoke_sp0256();
|
||||
int smoke_ay8913();
|
||||
int smoke_ssc_core();
|
||||
void Check6809Execution();
|
||||
void Check6309Execution();
|
||||
void Check6809Interrupts();
|
||||
void Check6309Interrupts();
|
||||
void Check6309Native();
|
||||
void CheckCpuDebugHooks();
|
||||
void CheckEventScheduler();
|
||||
void CheckMmuMapping();
|
||||
void CheckMmuRomAndVectors();
|
||||
void CheckMmuLifecycle();
|
||||
void CheckGimeRegisters();
|
||||
void CheckPiaRegisters();
|
||||
void CheckPiaInterrupts();
|
||||
void CheckMappedCpuExecution();
|
||||
void CheckVideoPixels();
|
||||
void CheckVideoModes();
|
||||
void CheckRasterTiming();
|
||||
void CheckGimeTimers();
|
||||
void CheckVideoLifecycle();
|
||||
void CheckFrameStops();
|
||||
void CheckRasterPixels();
|
||||
|
||||
void CheckSessionLifecycle();
|
||||
void CheckSessionReset();
|
||||
void CheckSessionFrameOwnership();
|
||||
void CheckSessionExclusion();
|
||||
void CheckSessionRomValidation();
|
||||
void CheckSessionKeyboard();
|
||||
void CheckSessionAutomaticBoot();
|
||||
void CheckRomBoot(const char* path); // optional user-ROM integration check
|
||||
void CheckSessionSoftReset();
|
||||
|
||||
void CheckAudioBuffer();
|
||||
void CheckAudioScheduling();
|
||||
void CheckAudioRouting();
|
||||
void CheckCassetteImages();
|
||||
void CheckCassetteMachine();
|
||||
void CheckDiskImages();
|
||||
void CheckFloppyCommands();
|
||||
void CheckFloppyTransfers();
|
||||
void CheckFloppyProtection();
|
||||
void CheckBuiltinDeviceBus();
|
||||
void CheckFloppySession();
|
||||
void CheckDiskRom(const char* systemPath, const char* diskPath); // optional supplied-ROM integration
|
||||
|
||||
void CheckHardDiskRom(const char* systemPath, const char* rgbPath, const char* imagePath, const char* dataPath = nullptr); // optional supplied-image integration
|
||||
|
||||
void CheckBinaryParsing();
|
||||
void CheckBinaryValidation();
|
||||
void CheckBinarySession();
|
||||
void CheckBinaryMappedWrites();
|
||||
|
||||
void CheckJoystickComparator();
|
||||
void CheckJoystickRamps();
|
||||
void CheckJoystickSession();
|
||||
|
||||
void CheckFramePacing();
|
||||
void CheckAudioProgress();
|
||||
void CheckAcceleratedTiming();
|
||||
|
||||
void CheckSessionVideoOutput();
|
||||
void CheckGraphicsPreviewModes();
|
||||
void CheckGraphicsPreviewColorSets();
|
||||
void CheckGraphicsPreviewRom(const char* systemPath, const char* diskPath, const char* programPath);
|
||||
|
||||
void CheckMachineMemorySettings();
|
||||
void CheckMachinePresentationSettings();
|
||||
void CheckConfiguredOverclock();
|
||||
|
||||
void CreateStarterMedia(const char* systemPath, const char* diskPath, const char* output);
|
||||
|
||||
void CreateHardBasicMedia(const char*, const char*, const char*, const char*);
|
||||
|
||||
void CheckSessionClipboard();
|
||||
void CheckClipboardRom(const char* path);
|
||||
|
||||
void CheckOrchestraRom(const char* systemPath, const char* orchestraPath, const char* outputPrefix);
|
||||
|
||||
void CheckSpeechSoundRom(const char* systemPath, const char* picPath, const char* speechPath, const char* outputPrefix);
|
||||
|
||||
void CheckBasicProgramTokens();
|
||||
void CheckBasicProgramValidation();
|
||||
void CheckBasicProgramRom(const char* systemPath, const char* diskPath);
|
||||
@@ -0,0 +1,311 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#include "CoreChecks.h"
|
||||
#include "../../src/core/CpuHost.h"
|
||||
#include "../../src/core/CpuMemory.h"
|
||||
#include "../../src/core/Event.h"
|
||||
#include "../../src/core/mc6809.h"
|
||||
#include "../../src/core/hd6309.h"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <initializer_list>
|
||||
#include <functional>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
// Test-only bus and joystick clock. These must never be linked into the app:
|
||||
// there is no ROM protection, MMU, GIME, I/O decoding, or peripheral emulation.
|
||||
namespace {
|
||||
std::array<unsigned char, 65536> memory;
|
||||
unsigned char mapType;
|
||||
struct FlatBus final : VCC::CpuMemoryBus {
|
||||
std::function<void(unsigned short)> beforeRead;
|
||||
unsigned char Read(unsigned short address) override {
|
||||
if (beforeRead) beforeRead(address);
|
||||
return memory[address];
|
||||
}
|
||||
void Write(unsigned char value, unsigned short address) override { memory[address] = value; }
|
||||
void SelectMap(unsigned char type) override { mapType = type; }
|
||||
};
|
||||
void require(bool condition, const char* message) {
|
||||
if (!condition) throw std::runtime_error(message);
|
||||
}
|
||||
struct Hooks final : VCC::CpuDebugHooks {
|
||||
bool halted = false, stepping = false, enabled = false, tracing = false;
|
||||
std::vector<VCC::CPUState> before, after;
|
||||
std::vector<unsigned char> requested, serviced, executing;
|
||||
bool IsHalted() const override { return halted; }
|
||||
bool IsStepping() const override { return stepping; }
|
||||
void Halt() override { halted = true; stepping = false; }
|
||||
bool IsTracingEnabled() const override { return enabled; }
|
||||
bool IsTracing() const override { return tracing; }
|
||||
void TraceStart() override { tracing = true; }
|
||||
void TraceCaptureBefore(long, const VCC::CPUState& s) override { before.push_back(s); }
|
||||
void TraceCaptureAfter(long, const VCC::CPUState& s) override { after.push_back(s); }
|
||||
void TraceCaptureInterruptRequest(unsigned char irq, long, const VCC::CPUState&) override { requested.push_back(irq); }
|
||||
void TraceCaptureInterruptServicing(unsigned char irq, long, const VCC::CPUState&) override { serviced.push_back(irq); }
|
||||
void TraceCaptureInterruptExecuting(unsigned char irq, long, const VCC::CPUState&) override { executing.push_back(irq); }
|
||||
};
|
||||
struct Cpu {
|
||||
void (*init)();
|
||||
void (*reset)();
|
||||
int (*exec)(int);
|
||||
VCC::CPUState (*state)();
|
||||
void (*assertIRQ)(InterruptSource, Interrupt);
|
||||
void (*clearIRQ)(InterruptSource, Interrupt);
|
||||
void (*breakpoints)(const std::vector<unsigned short>&);
|
||||
void (*triggers)(const std::vector<unsigned short>&);
|
||||
};
|
||||
const Cpu m6809 {MC6809Init, MC6809Reset, MC6809Exec, MC6809GetState,
|
||||
MC6809AssertInterupt, MC6809DeAssertInterupt, MC6809SetBreakpoints, MC6809SetTraceTriggers};
|
||||
const Cpu h6309 {HD6309Init, HD6309Reset, HD6309Exec, HD6309GetState,
|
||||
HD6309AssertInterupt, HD6309DeAssertInterupt, HD6309SetBreakpoints, HD6309SetTraceTriggers};
|
||||
|
||||
struct Fixture {
|
||||
const Cpu& cpu;
|
||||
Hooks hooks;
|
||||
FlatBus bus;
|
||||
explicit Fixture(const Cpu& c) : cpu(c) {
|
||||
VCC::SetCpuMemoryBus(&bus);
|
||||
memory.fill(0);
|
||||
mapType = 255;
|
||||
VCC::gEvents.Reset();
|
||||
VCC::SetCpuDebugHooks(&hooks);
|
||||
cpu.init();
|
||||
cpu.breakpoints({}); cpu.triggers({});
|
||||
MemWrite16(0x4000, 0xfffe);
|
||||
cpu.reset();
|
||||
}
|
||||
~Fixture() {
|
||||
cpu.breakpoints({}); cpu.triggers({});
|
||||
VCC::SetCpuDebugHooks(nullptr);
|
||||
VCC::SetCpuMemoryBus(nullptr);
|
||||
VCC::gEvents.Reset();
|
||||
}
|
||||
void load(std::initializer_list<unsigned char> bytes, unsigned short address = 0x4000) {
|
||||
std::copy(bytes.begin(), bytes.end(), memory.begin() + address);
|
||||
}
|
||||
int instruction() { return 1 - cpu.exec(1); }
|
||||
};
|
||||
|
||||
void execution(const Cpu& cpu) {
|
||||
Fixture f(cpu);
|
||||
auto s = cpu.state();
|
||||
require(s.PC == 0x4000 && s.CC == 0x50 && s.A == 0 && s.B == 0 &&
|
||||
s.X == 0 && s.Y == 0 && s.U == 0 && s.S == 0 && s.DP == 0 && !s.IsNative6309,
|
||||
"CPU reset registers/vector/masks");
|
||||
require(mapType == 0, "CPU reset selects map zero");
|
||||
// Authored guest fixture: docs/macos/reference/cpu6809.asm, no ROM needed.
|
||||
f.load({0x1a,0x50,0x10,0xce,0x70,0x00,0x8e,0x41,0x00,0x4f,
|
||||
0xc6,0x10,0x4c,0xa7,0x80,0x5a,0x26,0xfa,0x20,0xfe});
|
||||
cpu.breakpoints({0x4012});
|
||||
f.hooks.enabled = true;
|
||||
const int cycles = 1000 - cpu.exec(1000);
|
||||
s = cpu.state();
|
||||
require(f.hooks.halted && s.PC == 0x4012 && s.A == 16 && s.B == 0 &&
|
||||
s.X == 0x4110 && s.S == 0x7000, "CPU guest loop final registers/breakpoint");
|
||||
for (unsigned i = 0; i < 16; ++i)
|
||||
require(memory[0x4100+i] == i+1, "CPU guest loop indexed stores");
|
||||
require(f.hooks.before.size() == 69 && f.hooks.after.size() == 69,
|
||||
"CPU guest loop executes 69 instructions");
|
||||
require(cycles == 222 && VCC::gEvents.GetClocks() == 222*16,
|
||||
"CPU guest loop cycle budget and scheduler clocks");
|
||||
|
||||
f.hooks.halted = false; cpu.breakpoints({}); cpu.reset();
|
||||
f.load({0x86,0x7f,0x8b,0x01,0x8b,0x80,0x80,0x01});
|
||||
require(f.instruction() == 2, "LDA immediate cycles");
|
||||
f.instruction(); s = cpu.state();
|
||||
require(s.A == 0x80 && (s.CC & 0x2f) == 0x2a, "ADDA signed overflow/half-carry flags");
|
||||
f.instruction(); s = cpu.state();
|
||||
require(s.A == 0 && (s.CC & 0x2f) == 0x07, "ADDA unsigned carry/zero/overflow flags");
|
||||
f.instruction(); s = cpu.state();
|
||||
require(s.A == 0xff && (s.CC & 0x0f) == 0x09, "SUBA borrow/negative flags");
|
||||
|
||||
cpu.reset();
|
||||
f.load({0xcc,0x12,0x34,0xfd,0xff,0xff}); // LDD #$1234; STD $FFFF
|
||||
f.instruction(); f.instruction();
|
||||
require(memory[0xffff] == 0x12 && memory[0] == 0x34, "CPU big-endian word store wraps bus address");
|
||||
}
|
||||
|
||||
// A changing peripheral flag must be sampled during TST, before instruction
|
||||
// completion/IRQ entry. An all-at-the-end tick starves polling loops whenever
|
||||
// the IRQ handler acknowledges the same flag. No proprietary guest code needed.
|
||||
void testOperandTiming(const Cpu& cpu) {
|
||||
for (unsigned mode = 0; mode < 4; ++mode) {
|
||||
// Direct, ,X, extended, and 8-bit indexed offset (extra EA cycle).
|
||||
const unsigned cycles = mode == 2 || mode == 3 ? 7 : 6;
|
||||
const unsigned readCycle = cycles - 2;
|
||||
for (unsigned edge = 1; edge <= cycles; ++edge) {
|
||||
Fixture f(cpu);
|
||||
f.load({0x86,0x42,0x1f,0x8b,0x8e,0x42,0x00,0x1a,0x03}); // DP=$42, X=$4200; set V/C
|
||||
for (unsigned n = 0; n < 4; ++n) f.instruction();
|
||||
if (mode == 0) f.load({0x0d,0x00}, 0x4009);
|
||||
if (mode == 1) f.load({0x6d,0x84}, 0x4009);
|
||||
if (mode == 2) f.load({0x7d,0x42,0x00}, 0x4009);
|
||||
if (mode == 3) f.load({0x6d,0x88,0x01}, 0x4009);
|
||||
const unsigned address = mode == 3 ? 0x4201 : 0x4200;
|
||||
const auto start = VCC::gEvents.GetClocks();
|
||||
unsigned reads = 0;
|
||||
f.bus.beforeRead = [&](unsigned short a) {
|
||||
if (a == address) {
|
||||
++reads;
|
||||
require(VCC::gEvents.GetClocks() - start == readCycle * 16,
|
||||
"TST samples operand after addressing/data cycles, before trailing cycles");
|
||||
}
|
||||
};
|
||||
// Place the edge just before the cycle boundary (scheduler intervals are half-open).
|
||||
VCC::gEvents.Queue(edge * 16 - 1, [&] { memory[address] = 0x80; }, 1);
|
||||
require(f.instruction() == cycles, "TST retains total instruction timing");
|
||||
require(reads == 1 && memory[address] == 0x80, "TST reads exactly once and advances pending events");
|
||||
require((cpu.state().CC & 0x0f) == (edge <= readCycle ? 0x09 : 0x05),
|
||||
"TST sees only edges before operand sampling, clears V and preserves C");
|
||||
}
|
||||
Fixture f(cpu);
|
||||
f.load({0x10,0xce,0x70,0x00,0x86,0x42,0x1f,0x8b,0x8e,0x42,0x00,0x1c,0xaf});
|
||||
for (unsigned n = 0; n < 5; ++n) f.instruction(); // LDS, LDA, TFR, LDX, ANDCC
|
||||
unsigned short passed = 0;
|
||||
if (mode == 0) { f.load({0x0d,0x00,0x2a,0xfc,0x12}, 0x400d); passed = 0x4011; }
|
||||
if (mode == 1) { f.load({0x6d,0x84,0x2a,0xfc,0x12}, 0x400d); passed = 0x4011; }
|
||||
if (mode == 2) { f.load({0x7d,0x42,0x00,0x2a,0xfb,0x12}, 0x400d); passed = 0x4012; }
|
||||
if (mode == 3) { f.load({0x6d,0x88,0x01,0x2a,0xfb,0x12}, 0x400d); passed = 0x4012; }
|
||||
const unsigned address = mode == 3 ? 0x4201 : 0x4200;
|
||||
f.load({0xb6,0x43,0x00,0x3b}, 0x5000); // IRQ: read peripheral acknowledge; RTI
|
||||
MemWrite16(0x5000, 0xfff8);
|
||||
unsigned acknowledgements = 0;
|
||||
f.bus.beforeRead = [&](unsigned short a) {
|
||||
if (a == 0x4300) {
|
||||
++acknowledgements;
|
||||
memory[address] = 0;
|
||||
cpu.clearIRQ(IS_PIA0_VSYNC, INT_IRQ);
|
||||
}
|
||||
};
|
||||
VCC::gEvents.Queue(2 * 16, [&] {
|
||||
memory[address] = 0x80;
|
||||
cpu.assertIRQ(IS_PIA0_VSYNC, INT_IRQ);
|
||||
}, 1);
|
||||
cpu.breakpoints({passed});
|
||||
cpu.exec(200);
|
||||
require(f.hooks.halted && cpu.state().PC == passed && acknowledgements == 1 &&
|
||||
memory[address] == 0 && cpu.state().S == 0x7000,
|
||||
"TST polling exits after IRQ acknowledges flag and RTI restores sampled condition codes");
|
||||
}
|
||||
}
|
||||
|
||||
void interrupts(const Cpu& cpu) {
|
||||
for (auto irq : {INT_IRQ, INT_FIRQ, INT_NMI}) {
|
||||
Fixture f(cpu);
|
||||
f.load({0x10,0xce,0x70,0x00,0x1c,0xaf,0x12}); // LDS; ANDCC clears I/F; NOP
|
||||
f.load({0x3b}, 0x5000); // RTI
|
||||
const unsigned short vector = irq == INT_IRQ ? 0xfff8 : irq == INT_FIRQ ? 0xfff6 : 0xfffc;
|
||||
MemWrite16(0x5000, vector);
|
||||
f.instruction(); f.instruction();
|
||||
const auto before = cpu.state();
|
||||
f.hooks.tracing = true;
|
||||
cpu.breakpoints({0x5000});
|
||||
const auto source = irq == INT_NMI ? IS_NMI : IS_GIME;
|
||||
cpu.assertIRQ(source, irq);
|
||||
if (irq != INT_NMI) {
|
||||
// Independent sources share a line; clearing one must not clear the other.
|
||||
cpu.assertIRQ(IS_PIA0_HSYNC, irq);
|
||||
cpu.clearIRQ(source, irq);
|
||||
}
|
||||
cpu.exec(100);
|
||||
const auto handler = cpu.state();
|
||||
const unsigned frameBytes = irq == INT_FIRQ ? 3 : 12;
|
||||
require(f.hooks.halted && handler.PC == 0x5000 && handler.S == 0x7000-frameBytes,
|
||||
"CPU interrupt vector and stack frame");
|
||||
require(MemRead16(0x6ffe) == before.PC, "CPU interrupt stacked return address");
|
||||
require((memory[handler.S] & 0x80) == (irq == INT_FIRQ ? 0 : 0x80),
|
||||
"CPU interrupt entire-state flag");
|
||||
require(f.hooks.serviced == std::vector<unsigned char>{static_cast<unsigned char>(irq)} &&
|
||||
f.hooks.executing == f.hooks.serviced && !f.hooks.requested.empty(),
|
||||
"CPU interrupt debug callbacks");
|
||||
cpu.clearIRQ(source, irq);
|
||||
if (irq != INT_NMI) cpu.clearIRQ(IS_PIA0_HSYNC, irq);
|
||||
cpu.breakpoints({}); f.hooks.halted = false;
|
||||
f.instruction();
|
||||
const auto restored = cpu.state();
|
||||
require(restored.PC == before.PC && restored.S == before.S &&
|
||||
restored.A == before.A && restored.B == before.B &&
|
||||
(restored.CC & 0x7f) == (before.CC & 0x7f), "CPU RTI restores interrupted state");
|
||||
}
|
||||
// Reset masks IRQ/FIRQ; reset also clears previously asserted sources.
|
||||
for (auto irq : {INT_IRQ, INT_FIRQ}) {
|
||||
Fixture f(cpu);
|
||||
f.load({0x12,0x12});
|
||||
cpu.assertIRQ(IS_GIME, irq);
|
||||
f.instruction();
|
||||
require(cpu.state().PC == 0x4001, "CPU masks IRQ/FIRQ after reset");
|
||||
cpu.reset();
|
||||
f.load({0x1c,0xaf,0x12});
|
||||
f.instruction(); f.instruction();
|
||||
require(cpu.state().PC == 0x4003, "CPU reset clears interrupt sources");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Check6809Execution() { execution(m6809); }
|
||||
void Check6309Execution() { execution(h6309); }
|
||||
void Check6809Interrupts() { interrupts(m6809); testOperandTiming(m6809); }
|
||||
void Check6309Interrupts() { interrupts(h6309); testOperandTiming(h6309); }
|
||||
|
||||
void Check6309Native() {
|
||||
Fixture f(h6309);
|
||||
// LDMD #1; LDQ #$12345678; STQ $4200; NOP.
|
||||
f.load({0x11,0x3d,0x01,0xcd,0x12,0x34,0x56,0x78,0x10,0xfd,0x42,0x00,0x12});
|
||||
f.instruction();
|
||||
require(h6309.state().IsNative6309, "6309 enters native mode");
|
||||
f.instruction();
|
||||
auto s = h6309.state();
|
||||
require(s.A == 0x12 && s.B == 0x34 && s.E == 0x56 && s.F == 0x78,
|
||||
"6309 LDQ register byte order");
|
||||
f.instruction();
|
||||
require(MemRead16(0x4200) == 0x1234 && MemRead16(0x4202) == 0x5678,
|
||||
"6309 STQ memory byte order");
|
||||
require(f.instruction() == 1, "6309 native NOP timing");
|
||||
h6309.reset(); f.load({0x12});
|
||||
require(!h6309.state().IsNative6309 && f.instruction() == 2,
|
||||
"6309 reset restores emulation mode timing");
|
||||
}
|
||||
|
||||
void CheckCpuDebugHooks() {
|
||||
for (const auto& cpu : {m6809, h6309}) {
|
||||
Fixture f(cpu);
|
||||
f.load({0x12,0x12,0x12,0x12});
|
||||
cpu.triggers({0x4001}); cpu.breakpoints({0x4003});
|
||||
f.hooks.enabled = true;
|
||||
cpu.exec(100);
|
||||
require(f.hooks.halted && f.hooks.before.size() == 2 && f.hooks.after.size() == 2 &&
|
||||
f.hooks.before.front().PC == 0x4001 && f.hooks.after.back().PC == 0x4003,
|
||||
"CPU trace trigger starts at requested instruction and stops before breakpoint");
|
||||
require(cpu.exec(10) == 10 && cpu.state().PC == 0x4003,
|
||||
"CPU halt consumes no cycles/instructions");
|
||||
f.hooks.halted = false; f.hooks.stepping = true;
|
||||
require(f.instruction() == 2 && cpu.state().PC == 0x4004 && f.hooks.halted,
|
||||
"CPU debugger single-step advances exactly one instruction");
|
||||
}
|
||||
}
|
||||
|
||||
void CheckEventScheduler() {
|
||||
VCC::Event event;
|
||||
event.Tick(1);
|
||||
require(event.GetClocks() == 16, "Event constructor initializes default clock rate");
|
||||
event.Reset();
|
||||
std::vector<int> order;
|
||||
event.Queue(32, [&] { order.push_back(2); event.Queue(1, [&] { order.push_back(3); }); });
|
||||
event.Queue(16, [&] { order.push_back(1); });
|
||||
event.Tick(1);
|
||||
require(order.empty(), "Events at exact tick boundary remain queued");
|
||||
event.Tick(2);
|
||||
require(order == std::vector<int>({1,2,3}) && event.GetClocks() == 48,
|
||||
"Events run in clock order including reentrant queue");
|
||||
event.Queue(32, [&] { order.push_back(4); }, 1);
|
||||
event.ReQueue(16, [&] { order.push_back(5); }, 1);
|
||||
event.Queue(16, [&] { order.push_back(6); }, 2);
|
||||
event.Erase(2); event.Rebase(); event.Tick(2);
|
||||
require(order.back() == 5 && order.size() == 4 && event.GetSize() == 0,
|
||||
"Event reschedule/erase/rebase preserves remaining delays");
|
||||
event.SetClocksPerCycle(8); event.SetOverclock(2); event.Rebase(); event.Tick(2);
|
||||
require(event.GetClocks() == 8, "Event overclock and cycle rate apply at rebase");
|
||||
event.Reset(); event.Rebase(); event.Tick(1);
|
||||
require(event.GetClocks() == 16, "Event reset clears requested rate/overclock");
|
||||
}
|
||||
@@ -0,0 +1,453 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Authored fixtures only; no ROM or disk content from external releases.
|
||||
#include "CoreChecks.h"
|
||||
#include "../../src/devices/FD502/Fd502Device.h"
|
||||
#include "../../src/core/MachineSession.h"
|
||||
#include "../../src/core/tcc1014mmu.h"
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
using namespace VCC::Devices;
|
||||
namespace {
|
||||
void require(bool ok, const char* message) { if (!ok) throw std::runtime_error(message); }
|
||||
template<class F> void rejects(F f, const char* message) {
|
||||
bool rejected = false; try { f(); } catch (const std::exception&) { rejected = true; }
|
||||
require(rejected, message);
|
||||
}
|
||||
struct Host final : DeviceHost { unsigned nmis = 0; void cartridgeNmi() override { ++nmis; } };
|
||||
struct Rig {
|
||||
Host host;
|
||||
Fd502Device fdc{std::vector<std::uint8_t>(8192, 0x42)};
|
||||
void w(unsigned p, unsigned v) { fdc.writePort(p, v, host); }
|
||||
std::uint8_t r(unsigned p) { return fdc.readPort(p, host); }
|
||||
void tick(unsigned count = 1) { while (count--) fdc.horizontalSync(host); }
|
||||
void finish() {
|
||||
for (unsigned n = 0; n < 200000 && fdc.snapshot().busy; ++n) tick();
|
||||
require(!fdc.snapshot().busy, "Controller operation must finish within bounded scanlines");
|
||||
}
|
||||
};
|
||||
DiskImage fixture(DiskGeometry g = {}) {
|
||||
auto disk = DiskImage::blank(g);
|
||||
for (unsigned t = 0; t < g.tracks; ++t)
|
||||
for (unsigned side = 0; side < g.sides; ++side)
|
||||
for (unsigned s = g.firstSector; s < g.firstSector + g.sectors; ++s) {
|
||||
std::vector<std::uint8_t> bytes(g.sectorBytes());
|
||||
for (unsigned i = 0; i < bytes.size(); ++i) bytes[i] = t * 7 + side * 31 + s + i;
|
||||
require(disk.writeSector(t, side, s, bytes), "Author test sector");
|
||||
}
|
||||
disk.markSaved(); return disk;
|
||||
}
|
||||
std::vector<std::uint8_t> trackStream(unsigned track, unsigned side) {
|
||||
std::vector<std::uint8_t> bytes;
|
||||
for (unsigned s = 1; s <= 18; ++s) {
|
||||
bytes.insert(bytes.end(), 12, 0x4e);
|
||||
bytes.insert(bytes.end(), {0xfe, std::uint8_t(track), std::uint8_t(side), std::uint8_t(s), 1, 0xf7});
|
||||
bytes.insert(bytes.end(), 12, 0x4e); bytes.push_back(0xfb);
|
||||
bytes.insert(bytes.end(), 256, std::uint8_t(s)); bytes.push_back(0xf7);
|
||||
}
|
||||
bytes.resize(6272, 0x4e); return bytes;
|
||||
}
|
||||
using Bytes = std::vector<std::uint8_t>;
|
||||
|
||||
// 0xcdb4 is the CCITT seed after three MFM A1 sync bytes; FM starts at 0xffff.
|
||||
std::uint16_t testCRC(const Bytes& bytes, std::size_t offset, std::size_t count, std::uint16_t crc = 0xcdb4) {
|
||||
for (std::size_t i = offset; i < offset + count; ++i) {
|
||||
crc ^= static_cast<std::uint16_t>(bytes[i]) << 8;
|
||||
for (unsigned bit = 0; bit < 8; ++bit)
|
||||
crc = (crc & 0x8000) ? (crc << 1) ^ 0x1021 : crc << 1;
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
// A 128-byte deleted sector followed by a 256-byte sector, both claiming
|
||||
// cylinder 7 on physical head position 0.
|
||||
Bytes dmkFixture() {
|
||||
constexpr unsigned trackBytes = 6400;
|
||||
Bytes bytes(16 + trackBytes, 0x4e);
|
||||
std::fill_n(bytes.begin(), 16 + 128, 0);
|
||||
bytes[1] = 1; bytes[2] = trackBytes & 255; bytes[3] = trackBytes >> 8; bytes[4] = 0x10;
|
||||
auto record = [&](unsigned id, unsigned slot, unsigned sectorID, unsigned lengthCode, std::uint8_t mark) {
|
||||
bytes[16 + slot*2] = id & 255;
|
||||
bytes[17 + slot*2] = 0x80 | (id >> 8);
|
||||
const unsigned address = 16 + id;
|
||||
auto putCRC = [&](unsigned at, unsigned size) {
|
||||
const auto crc = testCRC(bytes, at, size);
|
||||
bytes[at+size] = crc >> 8;
|
||||
bytes[at+size+1] = crc & 255;
|
||||
};
|
||||
std::fill_n(bytes.begin()+address-3, 3, 0xa1);
|
||||
bytes[address] = 0xfe;
|
||||
bytes[address+1] = 7; bytes[address+2] = 0;
|
||||
bytes[address+3] = sectorID; bytes[address+4] = lengthCode;
|
||||
putCRC(address, 5);
|
||||
const unsigned dam = address + 32;
|
||||
std::fill_n(bytes.begin()+dam-3, 3, 0xa1);
|
||||
bytes[dam] = mark;
|
||||
const unsigned size = 128u << lengthCode;
|
||||
std::fill_n(bytes.begin()+dam+1, size, sectorID);
|
||||
putCRC(dam, size+1);
|
||||
};
|
||||
record(160, 0, 6, 0, 0xf8);
|
||||
record(480, 1, 2, 1, 0xfb);
|
||||
return bytes;
|
||||
}
|
||||
Bytes readCommand(Rig& r, unsigned cmd, unsigned count) {
|
||||
r.w(0x48, cmd);
|
||||
Bytes result;
|
||||
for (unsigned i = 0; i < count; ++i) result.push_back(r.r(0x4b));
|
||||
r.tick(10); // completion after the final data byte
|
||||
return result;
|
||||
}
|
||||
void checkDmkTransfers() {
|
||||
Rig r;
|
||||
auto original = dmkFixture();
|
||||
r.fdc.mount(0, DiskImage::load(original));
|
||||
r.w(0x40, 0x29);
|
||||
auto first = readCommand(r, 0xc0, 6);
|
||||
auto second = readCommand(r, 0xc0, 6);
|
||||
require(first == Bytes(original.begin()+177, original.begin()+183) &&
|
||||
second == Bytes(original.begin()+497, original.begin()+503),
|
||||
"DMK READ ADDRESS reports both real ID records, lengths, CRCs and on-disk ordering");
|
||||
require(readCommand(r, 0xe0, 6272) == Bytes(original.begin()+144, original.end()),
|
||||
"DMK READ TRACK returns the raw revolution without the container pointer table");
|
||||
|
||||
r.w(0x4a, 6);
|
||||
r.w(0x48, 0x80); r.r(0x4b);
|
||||
require(r.r(0x48) == 0x10, "Wrong logical cylinder cannot match a DMK sector");
|
||||
r.w(0x49, 7);
|
||||
require(readCommand(r, 0x80, 128) == Bytes(128, 6) && r.r(0x48) == 0x20,
|
||||
"DMK returns stored length and deleted-data mark after a complete read");
|
||||
|
||||
r.w(0x4a, 2);
|
||||
r.w(0x48, 0xa1); // write deleted data mark
|
||||
for (unsigned i = 0; i < 256; ++i) r.w(0x4b, 0xa5);
|
||||
r.tick(10);
|
||||
require(r.r(0x48) == 0 && r.fdc.image(0)->dirty(), "DMK write completed");
|
||||
auto expected = original;
|
||||
constexpr unsigned dam = 16 + 480 + 32;
|
||||
expected[dam] = 0xf8;
|
||||
std::fill_n(expected.begin()+dam+1, 256, 0xa5);
|
||||
const auto crc = testCRC(expected, dam, 257);
|
||||
expected[dam+257] = crc >> 8; expected[dam+258] = crc & 255;
|
||||
require(expected == r.fdc.image(0)->bytes(), "DMK write updates only the mark, data and CRC");
|
||||
expected[dam+258] ^= 1;
|
||||
r.fdc.mount(0, DiskImage::load(expected), true);
|
||||
r.w(0x4a, 2);
|
||||
require(readCommand(r, 0x80, 256) == Bytes(256, 0xa5) && r.r(0x48) == 0x28,
|
||||
"A deleted DMK sector with a bad data CRC returns the bytes and WD status");
|
||||
|
||||
// Formatting synthesizes fresh ID pointers inside this track only.
|
||||
r.w(0x49, 0);
|
||||
r.w(0x48, 0xf0);
|
||||
for (auto b : trackStream(0, 0)) r.w(0x4b, b);
|
||||
r.tick(10);
|
||||
require(r.r(0x48) == 0 && DiskImage::load(r.fdc.image(0)->bytes()).readSector(0, 0, 18) == Bytes(256, 18),
|
||||
"DMK formatted via WRITE TRACK reopens with its new sectors");
|
||||
|
||||
original[0] = 0xff;
|
||||
r.fdc.mount(0, DiskImage::load(original), true);
|
||||
r.fdc.setWriteProtected(0, false); // software override cannot clear the format protection
|
||||
r.w(0x48, 0xf0);
|
||||
require(r.r(0x48) == 0x50 && !r.fdc.image(0)->dirty(), "DMK header protects format commands");
|
||||
}
|
||||
|
||||
void checkFmAndDamagedRecords() {
|
||||
auto bytes = dmkFixture();
|
||||
std::fill(bytes.begin()+16, bytes.end(), 0);
|
||||
bytes[16] = 160; // pointer with bit 15 clear: a single-density record in double-rate storage
|
||||
auto storeDoubled = [&](unsigned offset, Bytes field) {
|
||||
const auto crc = testCRC(field, 0, field.size(), 0xffff);
|
||||
field.push_back(crc >> 8); field.push_back(crc & 255);
|
||||
for (auto value : field) {
|
||||
bytes[16 + offset++] = value;
|
||||
bytes[16 + offset++] = value;
|
||||
}
|
||||
};
|
||||
storeDoubled(160, {0xfe, 0, 0, 1, 1});
|
||||
// A copy-protected track (as in Shamus) can put an extra table pointer
|
||||
// between a real ID and its data. Its malformed ID must not hide that data.
|
||||
bytes[18] = 178;
|
||||
storeDoubled(178, {0xfe, 9, 8, 7, 3});
|
||||
bytes[16 + 178 + 10] ^= 1; bytes[16 + 178 + 11] ^= 1;
|
||||
Bytes data(257, 0xe5); data.front() = 0xfb;
|
||||
storeDoubled(200, data);
|
||||
Rig r;
|
||||
r.fdc.mount(0, DiskImage::load(bytes));
|
||||
r.w(0x40, 0x29); r.w(0x4a, 1);
|
||||
readCommand(r, 0xc0, 6); // first, valid FM address
|
||||
const auto badAddress = readCommand(r, 0xc0, 6);
|
||||
require(badAddress[0] == 9 && badAddress[2] == 7 && r.r(0x48) == 8,
|
||||
"DMK READ ADDRESS delivers the original bytes and signals a bad address CRC");
|
||||
require(readCommand(r, 0x80, 256) == Bytes(256, 0xe5) && r.r(0x48) == 0,
|
||||
"Mixed-density DMK decodes doubled FM bytes and their CRC");
|
||||
r.w(0x4a, 1); r.w(0x48, 0xa0);
|
||||
for (unsigned i = 0; i < 256; ++i) r.w(0x4b, i);
|
||||
r.tick(10);
|
||||
for (unsigned i = 0; i < 256; ++i) data[1+i] = i;
|
||||
storeDoubled(200, data);
|
||||
require(r.fdc.image(0)->bytes() == bytes, "FM write updates both copies of each data and CRC byte");
|
||||
|
||||
// Actual protected disks may have tracks without readable IDs. Their raw
|
||||
// revolutions must survive and a corrupt pointer cannot alias the next track.
|
||||
bytes[16] = 0xff; bytes[17] = 0xbf;
|
||||
r.fdc.mount(0, DiskImage::load(bytes), true);
|
||||
r.w(0x4a, 1); r.w(0x48, 0x80); r.r(0x4b);
|
||||
require(r.r(0x48) == 0x10 && !r.fdc.image(0)->dirty(), "Invalid ID pointer fails safely");
|
||||
require(readCommand(r, 0xe0, 6272) == Bytes(bytes.begin()+144, bytes.end()),
|
||||
"Track bytes remain readable without valid IDs");
|
||||
bytes.pop_back();
|
||||
rejects([&] { DiskImage::load(bytes); }, "Truncated DMK track image is rejected");
|
||||
}
|
||||
void checkVdkTransfers() {
|
||||
Rig r;
|
||||
Bytes bytes(12 + 2 * 18 * 256, 0);
|
||||
bytes[0] = 'd'; bytes[1] = 'k'; bytes[2] = 12; bytes[4] = 0x10; bytes[5] = 0x10;
|
||||
bytes[8] = 1; bytes[9] = 2;
|
||||
const auto last = bytes.size() - 256;
|
||||
std::fill(bytes.begin()+last, bytes.end(), 0x3d);
|
||||
r.fdc.mount(0, DiskImage::load(bytes));
|
||||
r.w(0x40, 0x69); r.w(0x4a, 18);
|
||||
require(readCommand(r, 0x80, 256) == Bytes(256, 0x3d), "VDK second-side sector is addressed after its header");
|
||||
r.w(0x4a, 18); r.w(0x48, 0xa0);
|
||||
for (unsigned i = 0; i < 256; ++i) r.w(0x4b, 0x5c);
|
||||
r.tick(10);
|
||||
std::fill(bytes.begin()+last, bytes.end(), 0x5c);
|
||||
require(r.r(0x48) == 0 && bytes == r.fdc.image(0)->bytes(), "VDK write retains header and other sectors");
|
||||
r.w(0x48, 0xe0); r.r(0x4b);
|
||||
require(r.r(0x48) == 0x10, "VDK sector images do not fabricate raw track data");
|
||||
bytes[10] = 1;
|
||||
r.fdc.mount(0, DiskImage::load(bytes), true);
|
||||
r.w(0x48, 0xa0);
|
||||
require(r.r(0x48) == 0x50 && !r.fdc.image(0)->dirty(), "VDK header protects sector writes");
|
||||
|
||||
// Genuine VDKs may retain optional disk names/metadata after byte 12.
|
||||
bytes.insert(bytes.begin() + 12, {'C', 'O', 'C', 'O'});
|
||||
bytes[2] = 16;
|
||||
const auto extended = DiskImage::load(bytes);
|
||||
require(extended.bytes() == bytes && extended.readSector(0, 1, 18) == Bytes(256, 0x5c),
|
||||
"Extended VDK headers preserve bytes and offset sector data correctly");
|
||||
bytes[8] = 2;
|
||||
rejects([&] { DiskImage::load(bytes); }, "VDK cylinder count must match its payload");
|
||||
|
||||
bytes.erase(bytes.begin() + 12, bytes.begin() + 16);
|
||||
std::fill_n(bytes.begin(), 12, 0);
|
||||
bytes[9] = 2;
|
||||
const auto windows = DiskImage::load(bytes);
|
||||
require(windows.format() == DiskFormat::VDK && windows.geometry().tracks == 1 &&
|
||||
windows.readSector(0, 1, 18) == Bytes(256, 0x5c),
|
||||
"Windows VCC legacy VDK side-count-only header preserves payload offsets");
|
||||
}
|
||||
void checkCreatedTrackFormats() {
|
||||
for (auto kind : {DiskFormat::VDK, DiskFormat::DMK}) {
|
||||
const auto created = DiskImage::blank(DiskGeometry{}, kind);
|
||||
auto disk = DiskImage::load(created.bytes());
|
||||
require(disk.format() == kind && disk.geometry().tracks == 35 && disk.geometry().sides == 1 &&
|
||||
!disk.dirty(), "New VDK and DMK media export with recognized header and geometry");
|
||||
Rig r;
|
||||
r.fdc.mount(0, std::move(disk));
|
||||
r.w(0x40, 0x29);
|
||||
r.w(0x48, 0xf0);
|
||||
for (auto byte : trackStream(0, 0)) r.w(0x4b, byte);
|
||||
r.tick(10);
|
||||
const auto formatted = DiskImage::load(r.fdc.image(0)->bytes());
|
||||
require(r.r(0x48) == 0 && formatted.format() == kind &&
|
||||
formatted.readSector(0, 0, 1) == Bytes(256, 1) &&
|
||||
formatted.readSector(0, 0, 18) == Bytes(256, 18),
|
||||
"Guest formatting on a newly created disk produces readable sectors after reopening");
|
||||
}
|
||||
}
|
||||
}
|
||||
void CheckDiskImages() {
|
||||
checkCreatedTrackFormats();
|
||||
auto disk = fixture();
|
||||
require(disk.bytes().size() == 161280 && !disk.dirty(), "Standard 35-track headerless DSK size");
|
||||
auto signatureCollision = disk.bytes();
|
||||
signatureCollision[0] = 'd'; signatureCollision[1] = 'k';
|
||||
require(DiskImage::load(signatureCollision).format() == DiskFormat::JVC,
|
||||
"Headerless DSK first-sector data may begin with the VDK signature");
|
||||
auto reopened = DiskImage::load(disk.bytes());
|
||||
require(reopened.readSector(34, 0, 18) == disk.readSector(34, 0, 18), "Last sector survives export/reload");
|
||||
require(reopened.readSector(35, 0, 1).empty() && reopened.readSector(0, 1, 1).empty() &&
|
||||
reopened.readSector(0, 0, 0).empty() && reopened.readSector(0, 0, 19).empty(), "Out-of-geometry reads cannot alias adjacent tracks");
|
||||
for (unsigned size = 0; size <= 3; ++size) {
|
||||
auto image = fixture({3, 2, 9, size, 0});
|
||||
auto copy = DiskImage::load(image.bytes());
|
||||
require(copy.geometry().sides == 2 && copy.geometry().sectorBytes() == (128u << size) &&
|
||||
copy.readSector(2, 1, 8) == image.readSector(2, 1, 8), "JVC variable sector size, sides and first sector");
|
||||
}
|
||||
// One-, two- and three-byte JVC headers use defaults for absent fields.
|
||||
for (unsigned n = 1; n <= 3; ++n) {
|
||||
std::vector<std::uint8_t> bytes{18, 1, 1}; bytes.resize(n);
|
||||
bytes.insert(bytes.end(), disk.bytes().begin(), disk.bytes().end());
|
||||
require(DiskImage::load(bytes).geometry().tracks == 35, "Partial JVC header defaults");
|
||||
}
|
||||
auto os9 = DiskImage::blank({40, 2, 18, 1, 1}).bytes(); os9.erase(os9.begin(), os9.begin() + 4);
|
||||
os9[0] = 0; os9[1] = 5; os9[2] = 160; os9[3] = 18; os9[16] = 1; // 1,440 sectors
|
||||
require(DiskImage::load(os9).format() == DiskFormat::OS9 && DiskImage::load(os9).geometry().sides == 2,
|
||||
"OS-9 descriptor selects two sides only when total sectors match the file");
|
||||
for (auto bytes : {std::vector<std::uint8_t>{}, std::vector<std::uint8_t>(17),
|
||||
std::vector<std::uint8_t>(4607), std::vector<std::uint8_t>(161280 + 16)})
|
||||
rejects([&] { DiskImage::load(bytes); }, "Malformed or unsupported containers rejected");
|
||||
auto bad = DiskImage::blank({2, 2, 18, 1, 1}).bytes(); bad[2] = 255;
|
||||
rejects([&] { DiskImage::load(bad); }, "Invalid size code rejected before shifting");
|
||||
bad[2] = 1; bad[0] = 0;
|
||||
rejects([&] { DiskImage::load(bad); }, "Zero sector divisor rejected");
|
||||
rejects([&] { DiskImage::blank({257, 1, 18, 1, 1}); }, "Excessive tracks rejected");
|
||||
rejects([&] { DiskImage::blank({1, 1, 1, 0, 1}); }, "Ambiguous half-block JVC payload rejected");
|
||||
rejects([&] { DiskImage::load(std::vector<std::uint8_t>(DiskImage::maxBytes + 1)); }, "Oversized image rejected");
|
||||
auto readonly = DiskImage::load(disk.bytes(), true); auto original = readonly.bytes();
|
||||
require(!readonly.writeSector(0, 0, 1, std::vector<std::uint8_t>(256)) && readonly.bytes() == original && !readonly.dirty(),
|
||||
"Protected writes do not alter any byte");
|
||||
auto stream = trackStream(0, 0);
|
||||
auto malformed = stream; malformed.back() = 0xfe;
|
||||
require(!reopened.formatTrack(0, 0, malformed) && reopened.bytes() == disk.bytes(), "Malformed formatting is atomic");
|
||||
require(reopened.formatTrack(0, 0, stream) && reopened.dirty() &&
|
||||
reopened.readSector(0, 0, 18) == std::vector<std::uint8_t>(256, 18), "Valid write-track stream updates sectors");
|
||||
}
|
||||
void CheckFloppyCommands() {
|
||||
Rig r; r.fdc.mount(0, fixture()); r.w(0x40, 0x29);
|
||||
r.w(0x4b, 3); r.w(0x48, 0x10);
|
||||
r.tick(99); require(r.fdc.snapshot().head == 0 && r.fdc.snapshot().busy, "Seek honors settle and step delay");
|
||||
r.finish(); require(r.r(0x49) == 3 && r.fdc.snapshot().head == 3 && r.host.nmis == 1, "Seek and gated completion NMI");
|
||||
r.w(0x48, 0x40); r.finish();
|
||||
require(r.r(0x49) == 3 && r.fdc.snapshot().head == 4, "STEP IN without update keeps track register");
|
||||
r.w(0x48, 0x70); r.finish(); require(r.r(0x49) == 2 && r.fdc.snapshot().head == 3, "STEP OUT updates the register independently of physical position");
|
||||
r.w(0x48, 0); r.finish(); require(r.r(0x49) == 0 && (r.r(0x48) & 4), "RESTORE reports track zero");
|
||||
r.w(0x40, 1); r.w(0x4b, 2); r.w(0x48, 0x10); r.tick(500);
|
||||
require(r.fdc.snapshot().busy && r.fdc.snapshot().head == 0, "Motor-off freezes seek");
|
||||
const auto nmis = r.host.nmis; r.w(0x40, 9); r.finish();
|
||||
require(r.host.nmis == nmis && r.fdc.snapshot().head == 2, "Completion NMI disabled by density/control bit");
|
||||
r.w(0x48, 0xd8); require(r.host.nmis == nmis + 1, "Forced NMI bypasses control mask");
|
||||
r.w(0x48, 0xd0); require(r.host.nmis == nmis + 1, "Force termination without interrupt");
|
||||
r.w(0x40, 0x48); require(r.fdc.snapshot().drive == 3 && r.fdc.snapshot().side == 0, "Fourth single-sided drive select");
|
||||
r.w(0x40, 0x49); require(r.fdc.snapshot().drive == 0 && r.fdc.snapshot().side == 1, "Bit six selects side when another drive is selected");
|
||||
r.w(0x40, 0x0f); require(r.fdc.snapshot().drive == 2, "Upstream drive-select priority");
|
||||
r.w(0x40, 8); r.w(0x48, 0x80); require(r.r(0x48) == 0x10, "Absent drive returns record not found");
|
||||
}
|
||||
void CheckFloppyTransfers() {
|
||||
checkDmkTransfers();
|
||||
checkFmAndDamagedRecords();
|
||||
checkVdkTransfers();
|
||||
Rig r; auto disk = fixture({2, 2, 18, 1, 1});
|
||||
const auto expected = disk.readSector(0, 1, 18);
|
||||
r.fdc.mount(0, std::move(disk)); r.w(0x40, 0x69); r.w(0x4a, 18); r.w(0x48, 0x80);
|
||||
std::vector<std::uint8_t> got; for (unsigned i = 0; i < 256; ++i) got.push_back(r.r(0x4b));
|
||||
require(got == expected && r.host.nmis == 0, "Second-side sector data, completion deferred beyond last byte");
|
||||
r.r(0x4b); require(!r.fdc.snapshot().busy && r.host.nmis == 1 && r.r(0x48) == 0, "Read completion delivers one NMI");
|
||||
r.w(0x4a, 2); r.w(0x48, 0xa0); r.tick(5); require(r.r(0x48) & 2, "Write DRQ after initial delay");
|
||||
for (unsigned i = 0; i < 256; ++i) r.w(0x4b, i ^ 0xa5);
|
||||
r.tick(6);
|
||||
auto changed = r.fdc.image(0)->readSector(0, 1, 2);
|
||||
for (unsigned i = 0; i < 256; ++i) require(changed[i] == (i ^ 0xa5), "Written sector bytes");
|
||||
require(r.r(0x48) == 0 && r.fdc.image(0)->dirty(), "Completed write commits once without false lost-data flag");
|
||||
auto copy = DiskImage::load(r.fdc.image(0)->bytes()); require(copy.readSector(0, 1, 2) == changed, "Written sector reopens");
|
||||
r.w(0x4a, 17); r.w(0x48, 0x90);
|
||||
for (unsigned s = 17; s <= 18; ++s)
|
||||
for (unsigned i = 0; i < 256; ++i) require(r.r(0x4b) == copy.readSector(0, 1, s)[i], "Multi-sector data stream");
|
||||
r.r(0x4b); require(r.r(0x48) == 0x10 && r.r(0x4a) == 19, "Multi-sector terminates at track boundary without aliasing");
|
||||
r.w(0x4a, 17); r.w(0x48, 0xb0);
|
||||
for (unsigned i = 0; i < 512; ++i) r.w(0x4b, i < 256 ? 0xa5 : 0x5a);
|
||||
r.tick(10); require(r.r(0x48) == 0x10 && r.fdc.image(0)->readSector(0, 1, 18) == std::vector<std::uint8_t>(256, 0x5a),
|
||||
"Multi-sector write commits last valid sector then stops");
|
||||
require(r.fdc.image(0)->readSector(0, 1, 17) == std::vector<std::uint8_t>(256, 0xa5), "Multi-sector write preserves first sector payload");
|
||||
r.w(0x4a, 1); r.w(0x48, 0x80); r.finish();
|
||||
require(r.r(0x48) == 4, "Unserviced transfer reports lost data");
|
||||
r.w(0x48, 0xc0); std::vector<std::uint8_t> id;
|
||||
for (unsigned i = 0; i < 6; ++i) id.push_back(r.r(0x4b)); r.r(0x4b);
|
||||
require(id[0] == 0 && id[1] == 1 && id[2] >= 1 && id[2] <= 18 && id[3] == 1, "Read address returns valid geometry");
|
||||
r.w(0x40, 0x29); r.w(0x48, 0xf0);
|
||||
for (auto b : trackStream(0, 0)) r.w(0x4b, b); r.tick(10);
|
||||
require(r.r(0x48) == 0 && r.fdc.image(0)->readSector(0, 0, 1) == std::vector<std::uint8_t>(256, 1), "Write-track formats selected side");
|
||||
}
|
||||
void CheckFloppyProtection() {
|
||||
Rig r; auto disk = fixture(); const auto original = disk.bytes();
|
||||
r.fdc.mount(0, DiskImage::load(original, true)); r.w(0x40, 0x29); r.w(0x4a, 1);
|
||||
for (unsigned command : {0xa0, 0xb0, 0xf0}) {
|
||||
r.w(0x48, command); for (unsigned i = 0; i < 300; ++i) r.w(0x4b, 0);
|
||||
require(r.r(0x48) == 0x50 && r.fdc.image(0)->bytes() == original && !r.fdc.image(0)->dirty(), "Protected controller writes leave source intact");
|
||||
}
|
||||
r.fdc.mount(0, fixture()); r.w(0x4a, 1); r.w(0x48, 0xa0);
|
||||
for (unsigned i = 0; i < 100; ++i) r.w(0x4b, 0);
|
||||
rejects([&] { r.fdc.eject(0); }, "Busy eject rejected");
|
||||
r.w(0x48, 0xd0); require(r.fdc.image(0)->bytes() == original, "Force interrupt drops incomplete sector");
|
||||
r.w(0x48, 0xa0); r.w(0x4b, 0); r.w(0x40, 0x2a);
|
||||
require(r.r(0x48) == 0x10 && r.fdc.image(0)->bytes() == original, "Drive switch aborts buffered transfer");
|
||||
r.w(0x40, 0x29); r.w(0x4a, 0); r.w(0x48, 0xa0); r.w(0x4b, 0);
|
||||
require(r.r(0x48) == 0x10 && r.fdc.image(0)->bytes() == original, "Sector zero cannot overwrite image header");
|
||||
r.w(0x4a, 1); r.w(0x48, 0xa0); for (unsigned i = 0; i < 256; ++i) r.w(0x4b, 0x77); r.tick(10);
|
||||
rejects([&] { r.fdc.eject(0); }, "Dirty eject requires explicit discard");
|
||||
rejects([&] { r.fdc.mount(0, fixture()); }, "Dirty replacement requires explicit discard");
|
||||
const auto changed = r.fdc.image(0)->bytes(); r.fdc.reset();
|
||||
require(r.fdc.image(0)->bytes() == changed && r.fdc.image(0)->dirty() && !r.fdc.snapshot().motor, "Reset preserves dirty media and stops motor");
|
||||
r.fdc.markSaved(0); r.fdc.eject(0); require(!r.fdc.image(0), "Saved image can eject");
|
||||
r.fdc.mount(0, DiskImage::blank()); r.fdc.eject(0, true);
|
||||
rejects([&] { r.fdc.eject(4); }, "Invalid drive index rejected");
|
||||
for (unsigned drive = 0; drive < 4; ++drive) {
|
||||
auto image = fixture(); image.writeSector(0, 0, 1, std::vector<std::uint8_t>(256, drive + 10)); image.markSaved();
|
||||
r.fdc.mount(drive, std::move(image));
|
||||
}
|
||||
for (unsigned drive = 0; drive < 4; ++drive) {
|
||||
r.w(0x40, (drive == 3 ? 0x40 : 1u << drive) | 8); r.w(0x4a, 1); r.w(0x48, 0x80);
|
||||
require(r.r(0x4b) == drive + 10, "Four mounted drives route independently"); r.w(0x48, 0xd0);
|
||||
}
|
||||
// Arbitrary port/command sequences must stay bounded even without media.
|
||||
for (unsigned i = 0; i < 4096; ++i) { r.w(0x40 + i % 16, (i * 73) & 255); r.tick(); r.r(0x40 + i % 16); }
|
||||
}
|
||||
void CheckBuiltinDeviceBus() {
|
||||
Host first, second; CartridgeBus bus;
|
||||
require(bus.readMemory(0xc000) == 0xff && bus.readPort(0x48) == 0 && bus.audio() == 0, "Empty cartridge bus values");
|
||||
rejects([&] { bus.install(makeDevice(DeviceKind::FD502, {})); }, "Missing disk ROM rejected");
|
||||
bus.install(makeDevice(DeviceKind::FD502, std::vector<std::uint8_t>(8192, 0x55)));
|
||||
require(bus.readMemory(0xc000) == 0x55 && bus.readMemory(0xdfff) == 0x55 && bus.readMemory(0xe000) == 0xff, "ROM map and 16 KiB padding");
|
||||
bus.connect(&first); bus.writePort(0x48, 0xd8); require(first.nmis == 1, "Interrupt reaches current host");
|
||||
bus.connect(nullptr); bus.writePort(0x48, 0xd8); bus.horizontalSync(); require(first.nmis == 1, "Detach prevents callbacks into old host");
|
||||
bus.connect(&second); bus.writePort(0x48, 0xd8); require(second.nmis == 1 && first.nmis == 1, "Reconnection isolates host lifetime");
|
||||
for (unsigned port = 0; port < 256; ++port) {
|
||||
if (port == 0x40 || (port >= 0x48 && port <= 0x4b)) continue;
|
||||
bus.writePort(port, 0xff); require(bus.readPort(port) == 0, "Unowned ports remain inert");
|
||||
}
|
||||
Fd502Device other(std::vector<std::uint8_t>(8192));
|
||||
bus.writePort(0x49, 10); require(other.readPort(0x49, first) == 0, "Controllers have no shared mutable state");
|
||||
bus.install(nullptr); bus.writePort(0x48, 0xd8); require(second.nmis == 1, "Removal detaches device");
|
||||
}
|
||||
void CheckFloppySession() {
|
||||
using namespace VCC::Mac;
|
||||
for (auto cpu : {Processor::MC6809, Processor::HD6309}) {
|
||||
MachineSession machine;
|
||||
auto device = makeDevice(DeviceKind::FD502, std::vector<std::uint8_t>(8192, 0x42));
|
||||
auto* fdc = static_cast<Fd502Device*>(device.get()); fdc->mount(0, fixture());
|
||||
machine.cartridges().install(std::move(device));
|
||||
std::vector<std::uint8_t> rom(32768, 0x12);
|
||||
const std::uint8_t program[] = {0x10,0xce,0x70,0x00,0x20,0xfe}; // LDS #$7000; BRA self
|
||||
std::copy(std::begin(program), std::end(program), rom.begin());
|
||||
rom[0x100] = 0x7c; rom[0x101] = 0x40; rom[0x102] = 1; rom[0x103] = 0x3b; // INC $4001; RTI
|
||||
rom[0x7ffc] = 0x81; rom[0x7ffd] = 0; rom[0x7ffe] = 0x80; rom[0x7fff] = 0;
|
||||
machine.load(rom, cpu); machine.resume(); machine.advance();
|
||||
require(MemRead8(0xc000) == 0x42, "Mapped cartridge ROM reaches guest MMU");
|
||||
require(fdc->snapshot().ticks >= 262 && fdc->snapshot().ticks <= 263, "One controller tick per raster scanline");
|
||||
MemWrite8(0, 0x4001); MemWrite8(0x29, 0xff40); MemWrite8(1, 0xff4a); MemWrite8(0x80, 0xff48);
|
||||
for (unsigned i = 0; i < 256; ++i) require(MemRead8(0xff4b) == std::uint8_t(1 + i), "Mapped disk port data");
|
||||
MemRead8(0xff4b); machine.advance();
|
||||
require(MemRead8(0x4001) == 1, "Controller completion NMI serviced by both CPU engines");
|
||||
machine.pause(); const auto ticks = fdc->snapshot().ticks; machine.advance();
|
||||
require(fdc->snapshot().ticks == ticks, "Pause freezes controller timing");
|
||||
machine.softReset(); require(fdc->image(0) && !fdc->snapshot().busy && !fdc->snapshot().motor, "Soft reset retains media and cancels controller");
|
||||
machine.reset(); require(machine.cartridges().current() == fdc && fdc->image(0), "Cold reset retains device ownership and disk");
|
||||
CartridgeBus::Slots slots;
|
||||
slots[4] = makeDevice(DeviceKind::FD502, std::vector<std::uint8_t>(8192));
|
||||
slots[1] = makeDevice(DeviceKind::RamDisk, {});
|
||||
machine.cartridges().configure(slots, true, 4);
|
||||
machine.setDriveWireFactory([](const std::string&, std::uint16_t) -> std::unique_ptr<DriveWireTransport> {
|
||||
throw std::logic_error("DriveWire initialization must not open a socket");
|
||||
});
|
||||
MemWrite8(0x5a, 0xff42); MemWrite8(0, 0xff42); // DWINIT
|
||||
require(MemRead8(0xff41) == 2, "FD-502 exposes the pending Becker response");
|
||||
MemWrite8(0x30, 0xff7f); // ROM slot 4, I/O slot 1
|
||||
MemWrite8(3, 0xff42); MemWrite8(0xa6, 0xff43);
|
||||
require(MemRead8(0xff41) == 0 && MemRead8(0xff43) == 0xa6, "RAM disk owns its overlapping I/O addresses");
|
||||
MemWrite8(0x33, 0xff7f);
|
||||
require(MemRead8(0xff42) == 4, "Re-selecting the FD-502 returns the pending DriveWire response");
|
||||
MemWrite8(0x5a, 0xff42); MemWrite8(0, 0xff42);
|
||||
machine.setDriveWireFactory({}); require(MemRead8(0xff41) == 0, "Disabling networking drops pending replies");
|
||||
machine.shutdown(); machine.cartridges().writePort(0x48, 0xd8); // no dangling callback
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#include "CoreChecks.h"
|
||||
#include "../../src/core/JoystickState.h"
|
||||
#include "../../src/core/MachineSession.h"
|
||||
#include "../../src/core/MachineHost.h"
|
||||
#include "../../src/core/mc6821.h"
|
||||
#include "../../src/core/CpuMemory.h"
|
||||
#include "../../src/core/mc6809.h"
|
||||
#include "../../src/core/hd6309.h"
|
||||
extern int JS_Ramp_Clock;
|
||||
#include <stdexcept>
|
||||
using namespace VCC::Mac;
|
||||
namespace { void require(bool condition) { if (!condition) throw std::runtime_error("Joystick input contract failed"); } }
|
||||
void CheckJoystickComparator() {
|
||||
JoystickState state;
|
||||
state.set(0, 0, 16383, 3, 0); state.set(1, 1000, 2000, 3, 0);
|
||||
require(state.scan(0x7f, 0, 0, 0, false) == 0x70); // zero never compares high
|
||||
require(state.scan(0x7f, 1, 16383, 0, false) == 0xf0);
|
||||
require(state.scan(0x7f, 2, 1001, 0, false) == 0x70);
|
||||
require(state.scan(0x7f, 3, 2000, 0, false) == 0xf0);
|
||||
state.release(); require(state.scan(0x7f, 0, 8192, 0, false) == 0x7f);
|
||||
require(state.scan(0x7e, 0, 8191, 0, false) == 0xfe); // retain keyboard row
|
||||
state.set(0, 99999, 99999, 255, 99);
|
||||
require(state.ports[0].x == 16383 && state.ports[0].mode == 3 && state.ports[0].buttons == 3);
|
||||
}
|
||||
void CheckJoystickRamps() {
|
||||
for (bool fast : {false, true}) {
|
||||
JoystickState state; int clock = 123;
|
||||
state.set(0, 0, 16383, 0, 2);
|
||||
state.start(true, 1, 0, clock); require(clock == 123);
|
||||
state.start(true, 2, 0, clock); require(clock == 0);
|
||||
const int threshold = fast ? 1200 : 600;
|
||||
require(state.scan(0x7f, 0, 0, threshold, fast) == 0x7f);
|
||||
require(state.scan(0x7f, 0, 0, threshold + 1, fast) == 0xff);
|
||||
state.start(true, 2, 1, clock);
|
||||
const int max = (1200 + ((16383 * 37) >> 6)) / (fast ? 1 : 2);
|
||||
require(state.scan(0x7f, 1, 0, max, fast) == 0x7f);
|
||||
require(state.scan(0x7f, 1, 0, max + 1, fast) == 0xff);
|
||||
state.set(1, 0, 0, 0, 3); state.start(false, 0, 2, clock);
|
||||
require(state.scan(0x7f, 2, 0, 800, fast) == 0x7f);
|
||||
require(state.scan(0x7f, 2, 0, 801, fast) == 0xff);
|
||||
}
|
||||
}
|
||||
void CheckJoystickSession() {
|
||||
for (auto cpu : {Processor::MC6809, Processor::HD6309}) {
|
||||
MachineSession machine; machine.loadDiagnostic(cpu); machine.resume();
|
||||
machine.setJoystick(0, 0, 0, 3, 0); machine.setJoystick(1, 0, 0, 3, 0);
|
||||
require(VCC::Machine().KeyboardScan(0xff) == 0x70);
|
||||
// Exercise the real PIA start/comparator and retained CPU cycle counter.
|
||||
MemWrite8(4, 0xff01); MemWrite8(4, 0xff03); MemWrite8(0xff, 0xff02);
|
||||
MemWrite8(4, 0xff21);
|
||||
// PA2..PA7 alone set the threshold, including at an exact six-bit boundary.
|
||||
machine.setJoystick(0, 26u << 8, 0, 0, 0);
|
||||
for (unsigned lowBits = 0; lowBits < 4; ++lowBits) {
|
||||
MemWrite8((26 << 2) | lowBits, 0xff20);
|
||||
require((MemRead8(0xff00) & 0x80) != 0);
|
||||
MemWrite8((27 << 2) | lowBits, 0xff20);
|
||||
require((MemRead8(0xff00) & 0x80) == 0);
|
||||
}
|
||||
machine.setJoystick(0, 0, 0, 0, 2);
|
||||
MemWrite8(2, 0xff20); require(JS_Ramp_Clock == 0);
|
||||
require((MemRead8(0xff00) & 0x80) == 0);
|
||||
// Authored RAM loop; neither CPU needs a proprietary ROM for this check.
|
||||
MemWrite8(0x20, 0x2000); MemWrite8(0xfe, 0x2001);
|
||||
if (cpu == Processor::MC6809) { MC6809ForcePC(0x2000); MC6809Exec(700); }
|
||||
else { HD6309ForcePC(0x2000); HD6309Exec(700); }
|
||||
require(JS_Ramp_Clock > 600 && (MemRead8(0xff00) & 0x80) != 0);
|
||||
machine.setJoystick(0, 0, 0, 0, 3); MemWrite8(0, 0xff00);
|
||||
require(JS_Ramp_Clock == 0 && (MemRead8(0xff00) & 0x80) == 0);
|
||||
JS_Ramp_Clock = 801; require((MemRead8(0xff00) & 0x80) != 0);
|
||||
machine.pause(); require((VCC::Machine().KeyboardScan(0xff) & 15) == 15);
|
||||
machine.setJoystick(0, 0, 0, 3, 0); require((VCC::Machine().KeyboardScan(0xff) & 15) == 15);
|
||||
machine.resume(); machine.setJoystick(0, 0, 0, 3, 0); machine.softReset();
|
||||
require((VCC::Machine().KeyboardScan(0xff) & 15) == 15);
|
||||
machine.setJoystick(0, 0, 0, 3, 0); machine.reset();
|
||||
require((VCC::Machine().KeyboardScan(0xff) & 15) == 15);
|
||||
|
||||
// Normal guest instructions configure the PIA and stop immediately
|
||||
// before reading it. Resume must apply the complete host input before
|
||||
// that first instruction, not one CPU slice later.
|
||||
const std::vector<uint8_t> code = {
|
||||
0x86,0x04, 0xb7,0xff,0x01, 0xb7,0xff,0x03, 0xb7,0xff,0x21,
|
||||
0x86,0xff, 0xb7,0xff,0x02, 0x86,0x80, 0xb7,0xff,0x20,
|
||||
0xb6,0xff,0x00, 0xb7,0x30,0x00, 0x20,0xfe
|
||||
};
|
||||
std::vector<uint8_t> binary = {0, 0, uint8_t(code.size()), 0x20, 0};
|
||||
binary.insert(binary.end(), code.begin(), code.end());
|
||||
binary.insert(binary.end(), {0xff, 0, 0, 0x20, 0});
|
||||
machine.debuggerLoadBinary(binary, std::vector<uint16_t>{0x2015, 0x201b});
|
||||
machine.advance();
|
||||
require(machine.snapshot().state == RunState::Paused && machine.snapshot().cpu.PC == 0x2015);
|
||||
const std::array<JoystickInputSnapshot, 2> inputs = {{{16383, 1234, 1, 0}, {0, 8191, 2, 0}}};
|
||||
machine.resumeWithInput(1, inputs);
|
||||
const auto held = machine.snapshot();
|
||||
require(held.keyboardHeld && held.joysticks[0].x == 16383 && held.joysticks[0].y == 1234 &&
|
||||
held.joysticks[0].buttons == 1 && held.joysticks[1].buttons == 2);
|
||||
machine.advance();
|
||||
const auto stopped = machine.snapshot();
|
||||
require(stopped.state == RunState::Paused && stopped.cpu.PC == 0x201b);
|
||||
const auto readback = machine.debuggerSnapshot(0x3000, 1);
|
||||
require(readback.memoryAvailable[0] && (readback.memory[0] & 0x81) == 0x80);
|
||||
machine.releaseInputs();
|
||||
const auto released = machine.snapshot();
|
||||
require(!released.keyboardHeld && released.state == stopped.state && released.cpu.PC == stopped.cpu.PC &&
|
||||
released.frames == stopped.frames && released.cycles == stopped.cycles && released.generation == stopped.generation);
|
||||
for (const auto& port : released.joysticks) require(port.x == 8191 && port.y == 8191 && port.buttons == 0);
|
||||
require(held.keyboardHeld && held.joysticks[0].buttons == 1); // The prior snapshot is an immutable value.
|
||||
auto invalid = inputs; invalid[1].x = 16384;
|
||||
try { machine.resumeWithInput(0, invalid); require(false); } catch (const std::invalid_argument&) {}
|
||||
require(machine.snapshot().state == RunState::Paused && machine.snapshot().cycles == stopped.cycles);
|
||||
|
||||
// A pending interrupt can stop at a different breakpoint inside the
|
||||
// first resumed slice. Preserve the actual input applied before that
|
||||
// slice even though pausing correctly neutralizes the live controls.
|
||||
std::vector<uint8_t> rom(32768, 0x12);
|
||||
rom[0x7ff8] = 0x21; rom[0x7ff9] = 0; // IRQ vector -> authored RAM handler
|
||||
rom[0x7ffe] = 0x20; rom[0x7fff] = 0;
|
||||
machine.load(rom, cpu);
|
||||
const std::vector<uint8_t> interruptBinary = {
|
||||
0,0,9,0x20,0, 0x10,0xce,0x70,0,0x1c,0xaf,0x12,0x20,0xfe,
|
||||
0,0,1,0x21,0, 0x3b, 0xff,0,0,0x20,0
|
||||
};
|
||||
machine.debuggerLoadBinary(interruptBinary, std::vector<uint16_t>{0x2006, 0x2100});
|
||||
machine.advance();
|
||||
require(machine.snapshot().state == RunState::Paused && machine.snapshot().cpu.PC == 0x2006);
|
||||
VCC::Machine().AssertInterrupt(IS_GIME, INT_IRQ);
|
||||
const auto staged = machine.resumeWithInput(1, inputs);
|
||||
const auto interrupted = machine.snapshot();
|
||||
require(staged.state == RunState::Running && staged.keyboardHeld && staged.joysticks[0].buttons == 1 &&
|
||||
staged.joysticks[0].x == 16383 && staged.joysticks[1].buttons == 2);
|
||||
require(interrupted.state == RunState::Paused && interrupted.cpu.PC == 0x2100 && !interrupted.keyboardHeld);
|
||||
for (const auto& port : interrupted.joysticks) require(port.x == 8191 && port.y == 8191 && port.buttons == 0);
|
||||
VCC::Machine().ClearInterrupt(IS_GIME, INT_IRQ);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#include "TestMachine.h"
|
||||
using namespace VCCTest;
|
||||
|
||||
void CheckMmuMapping() {
|
||||
const unsigned sizes[] = {0x20000, 0x80000, 0x200000, 0x800000};
|
||||
const unsigned masks[] = {15, 63, 255, 1023};
|
||||
for (unsigned char config = 0; config < 4; ++config) {
|
||||
MachineFixture f(config);
|
||||
const auto base = config == 0 ? 8 : 56;
|
||||
auto state = GetMMUState();
|
||||
require(!state.Enabled && state.ActiveTask == 0 && state.Task0[0] == base &&
|
||||
state.Task1[7] == base + 7, "MMU reset maps upper 64 KiB for both tasks");
|
||||
for (unsigned p = 0; p < sizes[config] / 8192; ++p) {
|
||||
SetMem(p * 8192 + 0x123, p & 255);
|
||||
SetMem(p * 8192 + 0x124, p >> 8);
|
||||
}
|
||||
f.write(0xffdf, 0); // SAM all-RAM mode
|
||||
require(MemRead8(0x123) == base, "MMU disabled mapping");
|
||||
f.write(0xffa0, 5); f.write(0xffa8, 9); f.write(0xff90, 0x40);
|
||||
require(MemRead8(0x123) == 5, "MMU task zero mapping via GIME register");
|
||||
f.write(0xff91, 1);
|
||||
require(MemRead8(0x123) == 9, "MMU task one mapping via GIME register");
|
||||
f.write(0x123, 0x55);
|
||||
require(GetMem(9 * 8192 + 0x123) == 0x55 && GetMem(5 * 8192 + 0x123) == 5,
|
||||
"MMU tasks isolate physical writes");
|
||||
f.write(0xff91, 0); f.write(0xffa0, 0xff);
|
||||
require(GetMMUState().Task0[0] == (255 & masks[config]), "MMU installed RAM bank mask");
|
||||
f.write(0xff9b, 0x30); f.write(0xffa0, 0xab);
|
||||
const auto page = config == 3 ? 0x3ab : (0xab & masks[config]);
|
||||
require(GetMMUState().Task0[0] == page && MemRead8(0x123) == (page & 255) &&
|
||||
MemRead8(0x124) == (page >> 8), "MMU extended bank prefix");
|
||||
std::array<unsigned char, 8192> snapshot;
|
||||
GetMMUPage(page, snapshot);
|
||||
require(snapshot[0x123] == (page & 255), "MMU debugger physical page snapshot");
|
||||
f.write(0xff90, 0); // disabled mapping independent of selected task
|
||||
require(MemRead8(0x123) == base, "MMU disable restores fixed map");
|
||||
}
|
||||
}
|
||||
|
||||
void CheckMmuRomAndVectors() {
|
||||
for (unsigned char config = 0; config < 4; ++config) {
|
||||
MachineFixture f(config);
|
||||
const auto vectorPage = config == 0 ? 15 : 63;
|
||||
const unsigned char expected[4][4] = {
|
||||
{0xa0,0xa1,0xc0,0xc1}, {0xa0,0xa1,0xc0,0xc1},
|
||||
{0xa0,0xa1,0xa2,0xa3}, {0xc2,0xc3,0xc0,0xc1}
|
||||
};
|
||||
for (unsigned char map = 0; map < 4; ++map) {
|
||||
f.write(0xff90, map);
|
||||
for (unsigned bank = 0; bank < 4; ++bank) {
|
||||
const auto address = 0x8000 + bank * 8192;
|
||||
require(MemRead8(address) == expected[map][bank], "MMU internal/cartridge ROM selection");
|
||||
f.write(address, 0x17);
|
||||
require(MemRead8(address) == expected[map][bank] && !MemCheckWrite(address), "MMU ROM writes are blocked");
|
||||
}
|
||||
require(MemRead16(0xfffe) == 0x4000, "SAM vectors always read internal ROM");
|
||||
}
|
||||
f.write(0xffdf, 0);
|
||||
f.write(0x8000, 0x17);
|
||||
require(MemRead8(0x8000) == 0x17 && MemCheckWrite(0x8000), "SAM all-RAM enables writes behind ROM");
|
||||
f.write(0xffde, 0);
|
||||
require(MemRead8(0x8000) == 0xc2, "SAM restores selected ROM overlay");
|
||||
f.write(0xffdf, 0); f.write(0xff90, 0x40); f.write(0xffa7, 1);
|
||||
SetMem(8192 + 0x1e00, 0x11); SetMem(vectorPage * 8192 + 0x1e00, 0x22);
|
||||
require(MemRead8(0xfe00) == 0x11, "FE00 follows mapped page with RAM vectors disabled");
|
||||
f.write(0xff90, 0x48);
|
||||
require(MemRead8(0xfe00) == 0x22, "RAM vector window bypasses MMU mapping");
|
||||
f.write(0xfe00, 0x33);
|
||||
require(GetMem(vectorPage * 8192 + 0x1e00) == 0x33 && GetMem(8192 + 0x1e00) == 0x11,
|
||||
"RAM vector write reaches fixed physical page");
|
||||
}
|
||||
}
|
||||
|
||||
void CheckMmuLifecycle() {
|
||||
MachineFixture f;
|
||||
auto* original = Get_mem_pointer();
|
||||
require(original[0] == 255 && original[3] == 255 && original[4] == 0 && original[7] == 0,
|
||||
"MMU retains upstream power-on RAM pattern");
|
||||
require(!MmuInit(4) && Get_mem_pointer() == original, "MMU rejects invalid RAM size without losing machine");
|
||||
f.host.romFailure = true; f.host.rom.fill(0x17);
|
||||
require(!MmuInit(0) && Get_mem_pointer() == original && GetRamConfiguration() == 1,
|
||||
"MMU failed ROM load preserves prior allocation/configuration");
|
||||
LoadRom();
|
||||
require(Getint_rom_pointer()[0] == 0xa0, "Failed ROM reload leaves current ROM intact");
|
||||
std::array<unsigned char, 8192> page;
|
||||
GetMMUPage(std::numeric_limits<std::size_t>::max(), page);
|
||||
require(std::all_of(page.begin(), page.end(), [](auto v) { return v == 255; }), "Invalid debugger page is bounded");
|
||||
f.host.romFailure = false;
|
||||
require(MmuInit(0) && GetRamConfiguration() == 0, "MMU can reinitialize to another RAM size");
|
||||
require(MemRead8(0xfffe) == 0x17, "SAM reads replacement ROM without stale pointer");
|
||||
MmuShutdown(); MmuShutdown();
|
||||
require(!Get_mem_pointer() && !Getint_rom_pointer() && MemRead8(0) == 255 &&
|
||||
SafeMemRead8(0xff00) == 0 && GetMem(0) == 0 && !MemCheckWrite(0), "MMU teardown and inspection are safe");
|
||||
}
|
||||
|
||||
void CheckGimeRegisters() {
|
||||
MachineFixture f(1, true);
|
||||
f.write(0x4000, 0xc0); f.write(0x4001, 0x40);
|
||||
MC6809ForcePC(0x4001); HD6309ForcePC(0x4000);
|
||||
f.write(0xffa0, 5);
|
||||
require(MemRead8(0xffa0) == 0xc5, "GIME floating bus uses selected 6309, not inactive 6809");
|
||||
f.write(0xffb3, 0xff);
|
||||
require(MemRead8(0xffb3) == 0xff && std::get<0>(f.host.video.back()) == VCC::VideoRegister::Palette &&
|
||||
std::get<1>(f.host.video.back()) == 63 && std::get<2>(f.host.video.back()) == 3, "GIME palette masks data and forwards index");
|
||||
f.write(0xff95, 0x34); f.write(0xff94, 0xf2); f.write(0xff91, 0x20);
|
||||
require(f.host.timer == std::vector<std::pair<VCC::TimerRegister, unsigned int>>{
|
||||
{VCC::TimerRegister::Reload, 0x34}, {VCC::TimerRegister::Restart, 0x234},
|
||||
{VCC::TimerRegister::ClockSource, 0x20}}, "GIME timer reload/restart/source forwarding");
|
||||
f.write(0xff9d, 0x12); f.write(0xff9e, 0x34);
|
||||
require(std::get<0>(f.host.video.back()) == VCC::VideoRegister::Offset &&
|
||||
std::get<1>(f.host.video.back()) == 0x1234, "GIME video offset combines bytes");
|
||||
f.write(0xff96, 0xff); f.write(0xffd9, 0);
|
||||
require(f.host.turbo == 1 && f.host.speed == 1, "GIME/SAM speed outputs");
|
||||
f.write(0xffd8, 0); require(f.host.speed == 0, "SAM normal speed output");
|
||||
f.write(0xffc1, 0); f.write(0xffc5, 0); f.write(0xffc7, 0);
|
||||
require(VDG_Modes() == 5 && VDG_Offset() == 1, "SAM bit-addressed video controls");
|
||||
f.write(0xff40, 0x12);
|
||||
require(MemRead8(0xff40) == 0x5a && f.host.cartWrites == 1 && f.host.cartValue == 0x12,
|
||||
"Unowned I/O ports route to cartridge host");
|
||||
|
||||
f.write(0xff90, 0x30); f.write(0xff92, 8); f.write(0xff93, 16);
|
||||
GimeAssertVertInterupt(); GimeAssertHorzInterupt();
|
||||
require(f.host.lines[IS_GIME] == (Bit(INT_IRQ) | Bit(INT_FIRQ)), "GIME independently asserts IRQ and FIRQ");
|
||||
require(SafeMemRead8(0xff92) == 8 && (f.host.lines[IS_GIME] & Bit(INT_IRQ)), "Debugger GIME read does not acknowledge IRQ");
|
||||
require(MemRead8(0xff92) == 8 && f.host.lines[IS_GIME] == Bit(INT_FIRQ), "GIME IRQ read acknowledges only IRQ");
|
||||
require(MemRead8(0xff93) == 16 && !f.host.lines[IS_GIME], "GIME FIRQ read acknowledges FIRQ");
|
||||
GimeAssertVertInterupt(); GimeAssertHorzInterupt(); GimeRegistersReset();
|
||||
require(!f.host.lines[IS_GIME], "GIME reset clears asserted CPU lines");
|
||||
}
|
||||
|
||||
void CheckPiaRegisters() {
|
||||
MachineFixture f;
|
||||
f.write(0xff02, 0x0f); // PIA0 B direction
|
||||
require(MemRead8(0xff02) == 0x0f, "PIA direction register access");
|
||||
f.write(0xff03, 4); f.write(0xff02, 5); f.write(0xff01, 4);
|
||||
require(MemRead8(0xff00) == 0x7e && f.host.columns == 0xf5, "PIA keyboard scan respects output direction");
|
||||
f.write(0xff00, 0); require(f.host.joystickStarts == 1, "PIA starts CCMax joystick measurement");
|
||||
f.write(0xff20, 0xff); f.write(0xff21, 4); f.write(0xff23, 8);
|
||||
f.write(0xff20, 0xfe);
|
||||
require(f.host.printerBit == 1 && f.host.joystickStarts == 2, "PIA serial and Tandy outputs");
|
||||
require(DACState() == (63u << 8), "PIA six-bit DAC is at full scale with serial output high");
|
||||
require(GetDACSample() == ((126u * 128u) << 16 | (126u * 128u)), "PIA DAC stereo sample");
|
||||
f.write(0xff23, 0); f.write(0xff20, 0xfc);
|
||||
require(GetCasSample() == 0xfc, "PIA cassette output selection");
|
||||
f.write(0xff21, 12); require(f.host.motor == 1, "PIA cassette motor output");
|
||||
f.host.fastTape = true; f.host.tapeBit = 1;
|
||||
require((MemRead8(0xff20) & 1) == 1, "PIA fast cassette input");
|
||||
f.host.fastTape = false; SetCassetteSample(0);
|
||||
require((MemRead8(0xff20) & 1) == 0, "PIA sampled cassette input");
|
||||
f.write(0xff01, 12); f.write(0xff03, 12);
|
||||
require(GetMuxState() == 3, "PIA analog mux selection");
|
||||
}
|
||||
|
||||
void CheckPiaInterrupts() {
|
||||
MachineFixture f;
|
||||
f.write(0xff01, 5); f.write(0xff03, 7); // HS falling, VS rising
|
||||
irq_hs(RISING); require(!f.host.lines[IS_PIA0_HSYNC], "PIA ignores opposite HS edge");
|
||||
irq_hs(FALLING); irq_fs(RISING);
|
||||
require((MemRead8(0xff01) & 128) && (MemRead8(0xff03) & 128), "PIA control reads retain interrupt flags");
|
||||
require(f.host.lines[IS_PIA0_HSYNC] && f.host.lines[IS_PIA0_VSYNC], "PIA HS/VS IRQ sources coexist");
|
||||
(void)SafeMemRead8(0xff00);
|
||||
require(f.host.lines[IS_PIA0_HSYNC], "Debugger PIA read has no acknowledge side effect");
|
||||
(void)MemRead8(0xff00);
|
||||
require(!f.host.lines[IS_PIA0_HSYNC] && f.host.lines[IS_PIA0_VSYNC], "PIA data read acknowledges only its source");
|
||||
f.write(0xff23, 5); AssertCart();
|
||||
require(f.host.lines[IS_PIA1_CART] == Bit(INT_FIRQ), "PIA cartridge FIRQ");
|
||||
(void)MemRead8(0xff22); require(!f.host.lines[IS_PIA1_CART], "PIA cartridge data read acknowledges FIRQ");
|
||||
irq_hs(FALLING); AssertCart(); PiaReset();
|
||||
require(!f.host.lines[IS_PIA0_HSYNC] && !f.host.lines[IS_PIA0_VSYNC] && !f.host.lines[IS_PIA1_CART],
|
||||
"PIA reset clears its CPU interrupt sources");
|
||||
}
|
||||
|
||||
void CheckMappedCpuExecution() {
|
||||
for (bool use6309 : {false, true}) {
|
||||
MachineFixture f(1, use6309);
|
||||
const std::vector<unsigned char> program = {
|
||||
0x10,0xce,0x70,0x00, // LDS #$7000
|
||||
0x86,0x42,0xb7,0xff,0x90, // enable MMU, internal ROM
|
||||
0x86,0x05,0xb7,0xff,0xa0, // task 0 page 0 = physical page 5
|
||||
0x86,0xa5,0xb7,0x01,0x23, // write through task 0
|
||||
0x86,0x06,0xb7,0xff,0xa8, // task 1 page 0 = physical page 6
|
||||
0x86,0x01,0xb7,0xff,0x91, // select task 1
|
||||
0x86,0x5a,0xb7,0x01,0x23, // write through task 1
|
||||
0x86,0x00,0xb7,0xff,0x91, // select task 0
|
||||
0xb6,0x01,0x23, // read original task 0 value
|
||||
0x1c,0xaf,0x12 // unmask interrupts; NOP
|
||||
};
|
||||
for (unsigned i = 0; i < program.size(); ++i) f.write(0x4000+i, program[i]);
|
||||
const unsigned short stop = 0x4000 + program.size() - 3;
|
||||
auto exec = use6309 ? HD6309Exec : MC6809Exec;
|
||||
auto breakpoints = use6309 ? HD6309SetBreakpoints : MC6809SetBreakpoints;
|
||||
breakpoints({stop});
|
||||
const auto cycles = 1000 - exec(1000);
|
||||
require(f.debugger.halted && f.host.CpuState().PC == stop && f.host.CpuState().A == 0xa5 &&
|
||||
GetMem(5*8192+0x123) == 0xa5 && GetMem(6*8192+0x123) == 0x5a,
|
||||
"CPU executes guest bank switching through actual MMU/GIME/I/O");
|
||||
require(cycles > 0 && VCC::gEvents.GetClocks() == cycles*16u, "Mapped CPU advances scheduler");
|
||||
breakpoints({}); f.debugger.halted = false; exec(1); // ANDCC
|
||||
f.write(0x5000, 0x3b); // IRQ handler: RTI
|
||||
f.write(0xff95, 1); f.write(0xff90, 0x62); f.write(0xff92, 0x20);
|
||||
GimeAssertTimerInterupt(); breakpoints({0x5000}); exec(100);
|
||||
require(f.debugger.halted && f.host.CpuState().PC == 0x5000 && f.host.CpuState().S == 0x6ff4,
|
||||
"GIME IRQ reaches selected CPU through real SAM vector and mapped stack");
|
||||
require(MemRead8(0xff92) == 0x20, "Guest acknowledges GIME timer IRQ");
|
||||
breakpoints({}); f.debugger.halted = false; exec(1);
|
||||
require(f.host.CpuState().PC == stop+2 && f.host.CpuState().S == 0x7000,
|
||||
"CPU RTI restores guest after mapped IRQ");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,787 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Optional integration check: user supplies the ROM; no ROM bytes live here.
|
||||
#include "CoreChecks.h"
|
||||
#include "../../src/devices/FD502/Fd502Device.h"
|
||||
#include "../../src/devices/HardDisk/HardDiskDevice.h"
|
||||
#include "../../src/devices/Orchestra90Device.h"
|
||||
#include "../../src/devices/SpeechSoundDevice.h"
|
||||
#include "../../src/core/MachineSession.h"
|
||||
#include "../../src/core/tcc1014mmu.h"
|
||||
#include <fstream>
|
||||
#include <limits>
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
namespace {
|
||||
void frames(VCC::Mac::MachineSession& machine, unsigned count) {
|
||||
while (count--) machine.advance();
|
||||
}
|
||||
std::string screen() {
|
||||
std::string text;
|
||||
for (unsigned i = 0; i < 512; ++i) {
|
||||
const unsigned c = SafeMemRead8(0x400 + i) & 0x3f;
|
||||
text += static_cast<char>(c < 32 ? c + 64 : c);
|
||||
if (i % 32 == 31) text += '\n';
|
||||
}
|
||||
return text;
|
||||
}
|
||||
std::uint64_t key(char c) {
|
||||
unsigned bit;
|
||||
if (c >= 'A' && c <= 'Z') bit = c - '@';
|
||||
else if (c >= '0' && c <= '9') bit = 32 + c - '0';
|
||||
else if (c == ',') bit = 44;
|
||||
else if (c == '/') bit = 47;
|
||||
else if (c == '>') return (std::uint64_t{1} << 46) | (std::uint64_t{1} << 55);
|
||||
else if (c == '"') return (std::uint64_t{1} << 34) | (std::uint64_t{1} << 55);
|
||||
else if (c == ' ') bit = 31;
|
||||
else if (c == '\r') bit = 48;
|
||||
else if (c == '*') return (std::uint64_t{1} << 42) | (std::uint64_t{1} << 55);
|
||||
else throw std::logic_error("Unsupported authored probe character");
|
||||
return std::uint64_t{1} << bit;
|
||||
}
|
||||
}
|
||||
namespace {
|
||||
void type(VCC::Mac::MachineSession& machine, const std::string& text) {
|
||||
for (char c : text) {
|
||||
machine.setKeyboard(key(c)); frames(machine, 4);
|
||||
machine.setKeyboard(0); frames(machine, 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace {
|
||||
// Direct Run from either workspace must supply a callable entry and leave BASIC
|
||||
// responsive after RTS, including when rerunning from inside an earlier build.
|
||||
void checkWorkspaceReturn(VCC::Mac::MachineSession& machine) {
|
||||
const std::vector<std::uint8_t> program{0, 0, 2, 0x3f, 0, 0x12, 0x39, 0xff, 0, 0, 0x3f, 0}; // NOP, RTS
|
||||
const auto word = [](unsigned at) { return (SafeMemRead8(at) << 8) | SafeMemRead8(at + 1); };
|
||||
const auto stack = word(0x21) - 2;
|
||||
const auto before = machine.snapshot();
|
||||
machine.launchAssembly(program, {}, {}, true, false, before.generation, before.debuggerProgramRevision,
|
||||
before.debuggerMappingFingerprint);
|
||||
const auto entry = machine.snapshot();
|
||||
if (entry.cpu.PC != 0x3f00 || entry.cpu.S != stack || entry.cpu.DP || (entry.cpu.CC & 0x50) ||
|
||||
word(stack) != 0xac73)
|
||||
throw std::runtime_error("Assembly Direct Run did not establish the BASIC return frame");
|
||||
|
||||
machine.debuggerStep();
|
||||
if (machine.snapshot().cpu.PC != 0x3f01) throw std::runtime_error("Assembly Direct Run missed its next instruction");
|
||||
auto overlap = program;
|
||||
overlap.insert(overlap.end() - 5, {0, 0, 1, std::uint8_t(stack >> 8), std::uint8_t(stack), 0});
|
||||
try {
|
||||
machine.debuggerLoadBinary(overlap, 0x3f00);
|
||||
throw std::runtime_error("A development image overwrote BASIC's return frame");
|
||||
} catch (const std::invalid_argument&) {}
|
||||
if (word(stack) != 0xac73 || machine.snapshot().cpu.PC != 0x3f01 ||
|
||||
machine.snapshot().debuggerProgramRevision != entry.debuggerProgramRevision)
|
||||
throw std::runtime_error("Rejected development image changed the session");
|
||||
|
||||
machine.debuggerLoadBinary(program, 0x3f00);
|
||||
if (machine.snapshot().cpu.S != stack) throw std::runtime_error("Rerunning a development image nested its stack");
|
||||
machine.debuggerClearDevelopmentBreakpoints();
|
||||
machine.resume(); frames(machine, 60);
|
||||
type(machine, "PRINT 8*9\r"); frames(machine, 30);
|
||||
if (screen().find(" 72 ") == std::string::npos)
|
||||
throw std::runtime_error("BASIC did not accept a new command after the workspace program returned");
|
||||
}
|
||||
void pasteText(VCC::Mac::MachineSession& machine, const std::string& text) {
|
||||
std::vector<std::uint64_t> chords;
|
||||
for(char c:text) {
|
||||
if(c>='a' && c<='z') chords.push_back(key(c-'a'+'A'));
|
||||
else if(c>='A' && c<='Z') chords.push_back(key(c) | (std::uint64_t{1}<<55));
|
||||
else chords.push_back(key(c));
|
||||
}
|
||||
machine.paste(chords);
|
||||
for(unsigned n=0;machine.pasteRemaining() && n<20000;++n)machine.advance();
|
||||
if(machine.pasteRemaining())throw std::runtime_error("Paced text did not complete");
|
||||
}
|
||||
}
|
||||
void CheckRomBoot(const char* path) {
|
||||
std::ifstream file(path, std::ios::binary);
|
||||
std::vector<std::uint8_t> bytes(32769);
|
||||
file.read(reinterpret_cast<char*>(bytes.data()), bytes.size());
|
||||
if (file.gcount() != 32768) throw std::runtime_error("ROM check needs a readable 32 KiB system ROM");
|
||||
bytes.resize(32768);
|
||||
for (auto processor : {VCC::Mac::Processor::MC6809, VCC::Mac::Processor::HD6309}) {
|
||||
VCC::Mac::MachineSession machine; machine.load(bytes, processor); machine.resume(); frames(machine, 300);
|
||||
if (screen().find("OK") == std::string::npos) throw std::runtime_error("ROM did not reach BASIC");
|
||||
checkWorkspaceReturn(machine);
|
||||
type(machine, "10 PRINT 6*7\rRUN\r");
|
||||
frames(machine, 60);
|
||||
if (screen().find(" 42 ") == std::string::npos) throw std::runtime_error("BASIC keyboard/program check did not print 42");
|
||||
machine.pause(); const auto before = machine.snapshot(); frames(machine, 5);
|
||||
if (machine.snapshot().cycles != before.cycles) throw std::runtime_error("Paused ROM continued executing");
|
||||
machine.resume(); type(machine, "CLS\r");
|
||||
machine.softReset(); frames(machine, 300);
|
||||
type(machine, "LIST\r"); frames(machine, 20);
|
||||
if (screen().find("PRINT 6*7") == std::string::npos)
|
||||
throw std::runtime_error("Soft reset lost the BASIC program");
|
||||
type(machine, "CLS\rRUN\r"); frames(machine, 60);
|
||||
if (screen().find(" 42 ") == std::string::npos)
|
||||
throw std::runtime_error("Preserved BASIC program did not run after soft reset");
|
||||
machine.pause(); machine.softReset(); frames(machine, 5);
|
||||
if (machine.snapshot().cycles != 0 || machine.snapshot().state != VCC::Mac::RunState::Paused)
|
||||
throw std::runtime_error("Paused soft reset executed guest code");
|
||||
machine.resume(); frames(machine, 300); type(machine, "CLS\rRUN\r"); frames(machine, 60);
|
||||
if (screen().find(" 42 ") == std::string::npos)
|
||||
throw std::runtime_error("Paused soft reset lost the BASIC program");
|
||||
type(machine, "SOUND100,10\r");
|
||||
bool sound=false;
|
||||
for(unsigned i=0;i<120;++i) {
|
||||
machine.advance();
|
||||
for(auto sample:machine.takeAudio()) if(sample.left!=0 || sample.right!=0) sound=true;
|
||||
}
|
||||
if(!sound) throw std::runtime_error("BASIC SOUND produced no audio samples");
|
||||
for(auto format:{VCC::Mac::TapeFormat::CAS,VCC::Mac::TapeFormat::WAV}) {
|
||||
auto& tape=machine.cassette(); tape.record(format);
|
||||
type(machine, "CSAVE\"TEST\"\r"); frames(machine,1800);
|
||||
auto saved=tape.exportImage();
|
||||
if(saved.size()<100 || tape.snapshot().motor) throw std::runtime_error("BASIC CSAVE did not finish recording");
|
||||
tape.mount(saved,format); tape.setFast(false); tape.play();
|
||||
type(machine,"NEW\rCLS\rCLOAD\r"); frames(machine,2400);
|
||||
type(machine,"LIST\rRUN\r"); frames(machine,60);
|
||||
if(screen().find(" 42 ")==std::string::npos) {
|
||||
std::fprintf(stderr,"Tape load screen:\n%s\n",screen().c_str());
|
||||
throw std::runtime_error(format==VCC::Mac::TapeFormat::CAS ? "CAS round trip failed" : "WAV round trip failed");
|
||||
}
|
||||
if(format==VCC::Mac::TapeFormat::CAS) {
|
||||
tape.rewind(); tape.setFast(true); tape.play();
|
||||
type(machine,"NEW\rCLS\rCLOAD\r"); frames(machine,1200);
|
||||
type(machine,"RUN\r"); frames(machine,60);
|
||||
if(screen().find(" 42 ")==std::string::npos) throw std::runtime_error("Fast CAS round trip failed");
|
||||
}
|
||||
}
|
||||
std::printf("PASS: BASIC SOUND, CAS/WAV CSAVE/CLOAD, fast CAS (%s)\n",
|
||||
processor == VCC::Mac::Processor::MC6809 ? "6809" : "6309");
|
||||
machine.reset(); machine.resume(); frames(machine, 300);
|
||||
if (screen().find("OK") == std::string::npos || screen().find(" 42 ") != std::string::npos)
|
||||
throw std::runtime_error("Cold reset did not return to a clean BASIC prompt");
|
||||
std::printf("PASS: supplied ROM BASIC boot, keyboard program, pause, soft/cold reset (%s)\n",
|
||||
processor == VCC::Mac::Processor::MC6809 ? "6809" : "6309");
|
||||
// Two authored BIN data blocks: clear text RAM, then execute a program
|
||||
// that writes BIN OK to the display. No assembled binary is bundled.
|
||||
std::vector<std::uint8_t> binary{0,2,0,4,0}; binary.insert(binary.end(),512,0x60);
|
||||
std::vector<std::uint8_t> code;
|
||||
const std::string message = "BIN OK";
|
||||
for (unsigned i=0;i<message.size();++i)
|
||||
code.insert(code.end(),{0x86,std::uint8_t((message[i]&63)|64),0xb7,4,std::uint8_t(i)});
|
||||
code.insert(code.end(),{0x20,0xfe});
|
||||
binary.insert(binary.end(),{0,0,std::uint8_t(code.size()),0x30,0});
|
||||
binary.insert(binary.end(),code.begin(),code.end()); binary.insert(binary.end(),{255,0,0,0x30,0});
|
||||
const auto rawStack = machine.snapshot().cpu.S;
|
||||
machine.quickLoad(binary);
|
||||
if (machine.snapshot().cpu.S != rawStack) throw std::runtime_error("Raw BIN quickload changed the stack");
|
||||
frames(machine,10);
|
||||
if (screen().find(message)==std::string::npos) throw std::runtime_error("Quick-loaded BIN did not execute after BASIC boot");
|
||||
std::printf("PASS: supplied ROM with multi-block BIN quick-load (%s)\n",
|
||||
processor == VCC::Mac::Processor::MC6809 ? "6809" : "6309");
|
||||
}
|
||||
// Machine Settings matrix: a real ROM must also boot and run BASIC with
|
||||
// all retained RAM sizes. No media, generated captures, or ROM data is saved.
|
||||
for (auto processor : {VCC::Mac::Processor::MC6809, VCC::Mac::Processor::HD6309}) {
|
||||
for (unsigned ram = 0; ram < 4; ++ram) {
|
||||
VCC::Mac::MachineSession machine;
|
||||
VCC::Mac::MachineConfiguration settings;
|
||||
settings.processor = processor; settings.ram = ram; settings.frameInterval = 6;
|
||||
machine.configure(settings); machine.load(bytes, processor); machine.resume(); frames(machine, 300);
|
||||
if (screen().find("OK") == std::string::npos) throw std::runtime_error("Configured RAM did not boot BASIC");
|
||||
type(machine, "CLS\rPRINT 6*7\r"); frames(machine, 20);
|
||||
if (screen().find(" 42 ") == std::string::npos) throw std::runtime_error("Configured RAM did not run BASIC");
|
||||
std::printf("PASS: supplied ROM machine settings (%s, RAM choice %u, present every 6 frames)\n",
|
||||
processor == VCC::Mac::Processor::MC6809 ? "6809" : "6309", ram);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Optional disk BASIC integration. Both ROMs are supplied by the user; every
|
||||
// disk byte is authored here, and the source files are opened read-only.
|
||||
void CheckDiskRom(const char* systemPath, const char* diskPath) {
|
||||
using namespace VCC::Devices;
|
||||
auto readRom = [](const char* path, unsigned size) {
|
||||
std::ifstream file(path, std::ios::binary);
|
||||
std::vector<std::uint8_t> bytes(size + 1);
|
||||
file.read(reinterpret_cast<char*>(bytes.data()), bytes.size());
|
||||
if (file.gcount() != size) throw std::runtime_error("Disk check needs a 32 KiB system ROM and 8 KiB disk ROM");
|
||||
bytes.resize(size); return bytes;
|
||||
};
|
||||
const auto systemRom = readRom(systemPath, 32768), diskRom = readRom(diskPath, 8192);
|
||||
auto checkScreen = [](const char* expected, const char* operation) {
|
||||
const auto text = screen();
|
||||
if (text.find(expected) == std::string::npos || text.find("ERROR") != std::string::npos) {
|
||||
std::fprintf(stderr, "%s screen:\n%s\n", operation, text.c_str());
|
||||
throw std::runtime_error(operation);
|
||||
}
|
||||
};
|
||||
auto checkFormat = [&](auto cpu, DiskFormat format, const char* formatName) {
|
||||
VCC::Mac::MachineSession machine;
|
||||
auto device = makeDevice(DeviceKind::FD502, diskRom);
|
||||
auto* fdc = static_cast<Fd502Device*>(device.get());
|
||||
fdc->mount(0, DiskImage::blank({}, format));
|
||||
machine.cartridges().install(std::move(device)); machine.load(systemRom, cpu); machine.resume();
|
||||
frames(machine, 300); checkScreen("DISK EXTENDED", "Disk BASIC boot");
|
||||
type(machine, "CLS\rDSKINI0\r"); frames(machine, 6000);
|
||||
checkScreen("OK", "DSKINI formatting");
|
||||
if (fdc->snapshot().busy) throw std::runtime_error("DSKINI left the controller busy");
|
||||
type(machine, "10 PRINT 6*7\rSAVE\"TEST\"\r"); frames(machine, 1200);
|
||||
checkScreen("OK", "BASIC disk SAVE");
|
||||
type(machine, "CLS\rDIR\r"); frames(machine, 300); checkScreen("TEST", "Directory after SAVE");
|
||||
const auto saved = fdc->image(0)->bytes();
|
||||
fdc->markSaved(0); fdc->eject(0); fdc->mount(0, DiskImage::load(saved));
|
||||
machine.reset(); frames(machine, 300);
|
||||
type(machine, "CLS\rLOAD\"TEST\"\r"); frames(machine, 1200);
|
||||
type(machine, "LIST\rRUN\r"); frames(machine, 60);
|
||||
checkScreen("PRINT 6*7", "Reloaded disk program LIST"); checkScreen(" 42 ", "Reloaded disk program RUN");
|
||||
if (fdc->image(0)->bytes() != saved) throw std::runtime_error("Reading changed the disk image");
|
||||
fdc->mount(0, DiskImage::load(saved, true));
|
||||
type(machine, "CLS\rSAVE\"BLOCK\"\r"); frames(machine, 600);
|
||||
if (screen().find("?WP ERROR") == std::string::npos || fdc->image(0)->bytes() != saved)
|
||||
throw std::runtime_error("Write-protected SAVE must report WP ERROR and preserve disk bytes");
|
||||
std::printf("PASS: Disk BASIC DSKINI, SAVE, DIR, eject/reopen, cold boot, LOAD/LIST/RUN and write protection (%s, %s)\n",
|
||||
formatName,
|
||||
cpu == VCC::Mac::Processor::MC6809 ? "6809" : "6309");
|
||||
};
|
||||
for (auto cpu : {VCC::Mac::Processor::MC6809, VCC::Mac::Processor::HD6309}) {
|
||||
checkFormat(cpu, DiskFormat::JVC, "DSK");
|
||||
checkFormat(cpu, DiskFormat::DMK, "DMK");
|
||||
checkFormat(cpu, DiskFormat::VDK, "VDK");
|
||||
}
|
||||
}
|
||||
|
||||
// Optional reference-image check. All writes stay in an owned memory copy;
|
||||
// supplied system ROM, RGBDOS ROM and NitrOS-9 VHD are opened read-only.
|
||||
void CheckHardDiskRom(const char* systemPath, const char* rgbPath, const char* imagePath, const char* dataPath) {
|
||||
using namespace VCC::Devices;
|
||||
auto read = [](const char* path, std::size_t limit) {
|
||||
std::ifstream file(path, std::ios::binary | std::ios::ate);
|
||||
auto length = file.tellg();
|
||||
if (!file || length <= 0 || std::uint64_t(length) > limit) throw std::runtime_error("Invalid supplied hard-disk fixture");
|
||||
std::vector<std::uint8_t> bytes(static_cast<std::size_t>(length)); file.seekg(0);
|
||||
if (!file.read(reinterpret_cast<char*>(bytes.data()), bytes.size())) throw std::runtime_error("Unable to read supplied hard-disk fixture");
|
||||
return bytes;
|
||||
};
|
||||
const auto system = read(systemPath,32768), rgb = read(rgbPath,16384), original = read(imagePath,HardDiskImage::maxBytes);
|
||||
// Read a standard OS-9 RBF file descriptor and its segment list. Used only
|
||||
// for independent verification of the guest's on-disk result.
|
||||
auto fileBytes = [](const std::vector<std::uint8_t>& disk, std::uint32_t descriptor) {
|
||||
const auto fd = std::size_t(descriptor) * 256;
|
||||
if (fd + 256 > disk.size()) throw std::runtime_error("RBF descriptor outside image");
|
||||
std::uint32_t size = 0; for (unsigned i=9;i<13;++i) size = (size<<8)|disk[fd+i];
|
||||
if (size > HardDiskImage::maxBytes) throw std::runtime_error("RBF file size outside limit");
|
||||
std::vector<std::uint8_t> result;
|
||||
for (unsigned entry=16; entry+5<=256 && result.size()<size; entry+=5) {
|
||||
std::uint32_t sector = (disk[fd+entry]<<16)|(disk[fd+entry+1]<<8)|disk[fd+entry+2];
|
||||
unsigned count = (disk[fd+entry+3]<<8)|disk[fd+entry+4];
|
||||
if (!count) break;
|
||||
auto start=std::size_t(sector)*256, length=std::min(std::size_t(count)*256,std::size_t(size)-result.size());
|
||||
if (start+length > disk.size()) throw std::runtime_error("RBF segment outside image");
|
||||
result.insert(result.end(),disk.begin()+start,disk.begin()+start+length);
|
||||
}
|
||||
if (result.size()!=size) throw std::runtime_error("Incomplete RBF file");
|
||||
return result;
|
||||
};
|
||||
for (auto cpu : {VCC::Mac::Processor::MC6809,VCC::Mac::Processor::HD6309}) {
|
||||
VCC::Mac::MachineSession machine;
|
||||
auto hard = std::make_shared<HardDiskDevice>(); hard->mount(0,HardDiskImage(original));
|
||||
if (dataPath) hard->mount(1,HardDiskImage(read(dataPath,HardDiskImage::maxBytes)));
|
||||
auto floppy = std::make_shared<Fd502Device>(rgb);
|
||||
machine.cartridges().configure({nullptr,hard,nullptr,nullptr,floppy},true,4);
|
||||
machine.load(system,cpu);
|
||||
if (dataPath) machine.requestNitros9Boot();
|
||||
machine.resume();
|
||||
try { frames(machine,600); } catch (...) { std::fprintf(stderr,"Boot screen:\n%s\n",screen().c_str()); throw; }
|
||||
if (!dataPath && screen().find("HARD DISK BASIC")==std::string::npos) throw std::runtime_error("RGBDOS did not boot");
|
||||
if (!dataPath) type(machine,"DOS255\r");
|
||||
frames(machine,3600);
|
||||
if (machine.nitros9BootPending()) throw std::runtime_error("Automatic boot still pending");
|
||||
type(machine,"ECHO VCCPORTCHECK >/H0/VCCMACTEST\r"); frames(machine,600);
|
||||
const auto& result = hard->image(0)->bytes();
|
||||
auto root = (result[8]<<16)|(result[9]<<8)|result[10]; auto entries = fileBytes(result,root);
|
||||
bool found = false;
|
||||
for (std::size_t i=0;i+32<=entries.size();i+=32) {
|
||||
if (!entries[i]) continue;
|
||||
std::string name;
|
||||
for (unsigned j=0;j<29;++j) { auto c=entries[i+j]; name += char(c&127); if(c&128) break; }
|
||||
if (name!="vccmactest") continue;
|
||||
auto fd = (entries[i+29]<<16)|(entries[i+30]<<8)|entries[i+31];
|
||||
auto bytes = fileBytes(result,fd); auto text = std::string(bytes.begin(),bytes.end());
|
||||
if (text.find("vccportcheck")==std::string::npos) throw std::runtime_error("NitrOS-9 file contents mismatch");
|
||||
// Reopen the serialized image independently and read the same file.
|
||||
HardDiskImage reopened(result);
|
||||
if (fileBytes(reopened.bytes(),fd)!=bytes) throw std::runtime_error("Hard disk reopen mismatch");
|
||||
found = true; break;
|
||||
}
|
||||
if (!found || !hard->image(0)->dirty()) throw std::runtime_error("NitrOS-9 did not create its test file");
|
||||
if (dataPath) {
|
||||
pasteText(machine,"echo sharedportcheck >/h1/vccmactest\r"); frames(machine,600);
|
||||
// Interleave reads from HD0 with writes to HD1; this catches a
|
||||
// driver that selects a unit once instead of on every transfer.
|
||||
pasteText(machine,"dir /dd/games >/h1/catalog\r"); frames(machine,600);
|
||||
const auto shared = hard->image(1)->bytes();
|
||||
const auto before = read(dataPath,HardDiskImage::maxBytes);
|
||||
if (!std::equal(before.begin()+0x5a000*256,before.end(),shared.begin()+0x5a000*256))
|
||||
throw std::runtime_error("OS-9 write modified BASIC volumes");
|
||||
auto root1=(shared[8]<<16)|(shared[9]<<8)|shared[10]; auto directory=fileBytes(shared,root1);
|
||||
bool written=false, catalog=false;
|
||||
for (std::size_t i=0;i+32<=directory.size();i+=32) {
|
||||
if (!directory[i]) continue;
|
||||
std::string name;
|
||||
for(unsigned j=0;j<29;++j) { auto c=directory[i+j];name+=char(c&127);if(c&128)break; }
|
||||
if(name!="vccmactest" && name!="catalog")continue;
|
||||
auto fd=(directory[i+29]<<16)|(directory[i+30]<<8)|directory[i+31];
|
||||
auto bytes=fileBytes(shared,fd);
|
||||
if(name=="catalog") {
|
||||
std::string listing(bytes.begin(),bytes.end());
|
||||
std::transform(listing.begin(),listing.end(),listing.begin(),[](unsigned char c) { return c >= 'A' && c <= 'Z' ? c+32 : c; });
|
||||
catalog=listing.find("rogue")!=std::string::npos;
|
||||
continue;
|
||||
}
|
||||
if(std::string(bytes.begin(),bytes.end()).find("sharedportcheck")==std::string::npos)
|
||||
throw std::runtime_error("Shared HD1 write content mismatch");
|
||||
HardDiskImage reopened(shared);
|
||||
if(fileBytes(reopened.bytes(),fd)!=bytes)throw std::runtime_error("Shared HD1 reopen mismatch");
|
||||
written=true;
|
||||
}
|
||||
if(!written || !catalog)throw std::runtime_error("NitrOS-9 HD1 write or cross-drive catalogue read failed");
|
||||
std::printf("PASS: automatic DOS 255, shared OS-9 HD1 write/reopen, BASIC volumes unchanged\n");
|
||||
}
|
||||
std::printf("PASS: RGBDOS, NitrOS-9 boot, guest file creation and raw-image reopen (%s)\n",cpu==VCC::Mac::Processor::MC6809?"6809":"6309");
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
void installPlanetSource(VCC::Mac::MachineSession& machine) {
|
||||
// Packaging and the documented regeneration commands run from the checkout.
|
||||
std::ifstream file("examples/basic/planet.bas");
|
||||
if (!file) throw std::runtime_error("Cannot open examples/basic/planet.bas; run from the repository root");
|
||||
std::string source{std::istreambuf_iterator<char>(file), {}};
|
||||
machine.basicLoadSource(source, false);
|
||||
frames(machine, 30);
|
||||
}
|
||||
|
||||
void runPlanetStarter(VCC::Mac::MachineSession& machine, char choice) {
|
||||
type(machine, "CLS\rRUN\r");
|
||||
frames(machine, 30);
|
||||
type(machine, "3"); // An unrelated key leaves BASIC waiting at the menu.
|
||||
const auto menu = machine.copyScreenText();
|
||||
if (menu.find("What planet do you live on?\n1) Earth\n2) Mars") == std::string::npos ||
|
||||
menu.find("World!") != std::string::npos || menu.find("OK") != std::string::npos)
|
||||
throw std::runtime_error("Planet starter did not wait for a choice:\n" + menu);
|
||||
type(machine, std::string(1, choice));
|
||||
frames(machine, 30);
|
||||
const auto result = machine.copyScreenText();
|
||||
const auto greeting = result.find(choice == '1' ? "Hello Nice Blue Dot World!" : "Hello Cold Red Dot World!");
|
||||
if (greeting == std::string::npos || result.find("OK", greeting) == std::string::npos)
|
||||
throw std::runtime_error("Planet starter did not greet the player and return to BASIC:\n" + result);
|
||||
type(machine, "WIDTH 32\r"); // The disk command probes use the 32-column BASIC display.
|
||||
}
|
||||
}
|
||||
|
||||
// Reproducible starter media, authored through real BASIC and independently
|
||||
// reloaded on both CPUs. Only the caller-supplied output directory is written.
|
||||
void CreateStarterMedia(const char* systemPath, const char* diskPath, const char* output) {
|
||||
using namespace VCC::Devices;
|
||||
using namespace VCC::Mac;
|
||||
auto read = [](const char* path, std::size_t size) {
|
||||
std::ifstream f(path, std::ios::binary);
|
||||
std::vector<std::uint8_t> data(size + 1);
|
||||
f.read(reinterpret_cast<char*>(data.data()), data.size());
|
||||
if (std::size_t(f.gcount()) != size) throw std::runtime_error("Starter media requires a 32 KiB system and 8 KiB disk ROM");
|
||||
data.resize(size); return data;
|
||||
};
|
||||
auto expect = [](const char* text) {
|
||||
if (screen().find(text) == std::string::npos || screen().find("ERROR") != std::string::npos)
|
||||
throw std::runtime_error(std::string("Starter verification failed: ") + text + "\n" + screen());
|
||||
};
|
||||
const auto system = read(systemPath,32768), rom = read(diskPath,8192);
|
||||
std::vector<std::uint8_t> disk, tape;
|
||||
{
|
||||
MachineSession m; auto fdc=std::make_shared<Fd502Device>(rom);
|
||||
fdc->mount(0,DiskImage::blank());
|
||||
m.cartridges().configure({nullptr,nullptr,nullptr,nullptr,fdc},true,4);
|
||||
m.load(system);m.resume();frames(m,300);expect("DISK EXTENDED");
|
||||
type(m,"CLS\rDSKINI0\r");frames(m,6000);expect("OK");
|
||||
installPlanetSource(m);
|
||||
type(m,"SAVE\"HELLO\"\r");frames(m,1200);expect("OK");
|
||||
type(m,"CLS\rDIR\r");frames(m,120);expect("HELLO");disk=fdc->image(0)->bytes();
|
||||
m.cassette().record(TapeFormat::CAS);type(m,"CSAVE\"HELLO\"\r");frames(m,1800);
|
||||
if(m.cassette().snapshot().motor) throw std::runtime_error("Starter CSAVE did not finish");
|
||||
tape=m.cassette().exportImage();
|
||||
}
|
||||
for(auto cpu:{Processor::MC6809,Processor::HD6309}) {
|
||||
MachineSession m;auto fdc=std::make_shared<Fd502Device>(rom);fdc->mount(0,DiskImage::load(disk));
|
||||
m.cartridges().configure({nullptr,nullptr,nullptr,nullptr,fdc},true,4);
|
||||
m.cassette().mount(tape,TapeFormat::CAS);m.load(system,cpu);m.resume();frames(m,300);
|
||||
expect("DISK EXTENDED");expect("OK");
|
||||
if(m.cassette().snapshot().mode!=TapeMode::Stopped || m.cassette().snapshot().position!=0)
|
||||
throw std::runtime_error("Starter cassette must remain stopped at launch");
|
||||
type(m,"CLS\rLIST\r");frames(m,60);
|
||||
if(!m.basicReadSource().empty())
|
||||
throw std::runtime_error("Starter program was loaded automatically");
|
||||
type(m,"LOAD\"HELLO\"\r");frames(m,1200);
|
||||
runPlanetStarter(m,'1');
|
||||
runPlanetStarter(m,'2');
|
||||
type(m,"NEW\rCLS\r");m.cassette().play();type(m,"CLOAD\"HELLO\"\r");frames(m,3600);
|
||||
runPlanetStarter(m,'1');
|
||||
runPlanetStarter(m,'2');
|
||||
if(fdc->image(0)->bytes()!=disk) throw std::runtime_error("Starter disk changed on read");
|
||||
std::printf("PASS: starter Disk BASIC, no auto-load, disk LOAD/RUN, cassette CLOAD/RUN (%s)\n",cpu==Processor::MC6809?"6809":"6309");
|
||||
}
|
||||
auto write=[&](const char* name,const std::vector<std::uint8_t>& data) {
|
||||
std::ofstream f(std::string(output)+"/"+name,std::ios::binary|std::ios::trunc);
|
||||
f.write(reinterpret_cast<const char*>(data.data()),data.size());
|
||||
if(!f)throw std::runtime_error("Could not write starter media");
|
||||
};
|
||||
write("Hello World.dsk",disk);write("Hello World.cas",tape);
|
||||
}
|
||||
|
||||
|
||||
// Authored BASIC-only hard-disk template. Reserved OS-9 space is zero-filled;
|
||||
// no downloaded disk contents or operating system are redistributed.
|
||||
void CreateHardBasicMedia(const char* systemPath, const char* rgbPath, const char* floppyPath, const char* output) {
|
||||
using namespace VCC::Devices;
|
||||
using namespace VCC::Mac;
|
||||
auto read=[](const char* path, std::size_t size) {
|
||||
std::ifstream f(path,std::ios::binary); std::vector<std::uint8_t> data(size+1);
|
||||
f.read(reinterpret_cast<char*>(data.data()),data.size());
|
||||
if(std::size_t(f.gcount())!=size) throw std::runtime_error("Unexpected hard BASIC input size");
|
||||
data.resize(size);return data;
|
||||
};
|
||||
auto expect=[](const char* text) {
|
||||
if(screen().find(text)==std::string::npos || screen().find("ERROR")!=std::string::npos)
|
||||
throw std::runtime_error(std::string("Hard BASIC verification failed: ")+text+"\n"+screen());
|
||||
};
|
||||
const auto system=read(systemPath,32768), rgb=read(rgbPath,8192), floppy=read(floppyPath,161280);
|
||||
constexpr std::size_t offset=0x5a000*256, volume=161280;
|
||||
std::vector<std::uint8_t> image(offset+256*volume,0), blank, hello;
|
||||
{
|
||||
MachineSession m;auto hd=std::make_shared<HardDiskDevice>();hd->mount(0,HardDiskImage(image));
|
||||
auto fd=std::make_shared<Fd502Device>(rgb);fd->mount(0,DiskImage::load(floppy));
|
||||
m.cartridges().configure({nullptr,hd,nullptr,nullptr,fd},true,4);
|
||||
m.load(system);m.resume();frames(m,600);expect("HARD DISK BASIC");
|
||||
type(m,"CLS\rDSKINI0\r");frames(m,60);type(m,"Y");frames(m,1200);expect("OK");
|
||||
const auto& formatted=hd->image(0)->bytes();
|
||||
blank.assign(formatted.begin()+offset,formatted.begin()+offset+volume);
|
||||
installPlanetSource(m);
|
||||
type(m,"SAVE\"HELLO\"\r");frames(m,1200);expect("OK");
|
||||
const auto& saved=hd->image(0)->bytes();
|
||||
hello.assign(saved.begin()+offset,saved.begin()+offset+volume);
|
||||
std::copy(hello.begin(),hello.end(),image.begin()+offset);
|
||||
for(unsigned i=1;i<256;++i) std::copy(blank.begin(),blank.end(),image.begin()+offset+i*volume);
|
||||
}
|
||||
for(auto cpu:{Processor::MC6809,Processor::HD6309}) {
|
||||
MachineSession m;auto hd=std::make_shared<HardDiskDevice>();hd->mount(0,HardDiskImage(image));
|
||||
auto fd=std::make_shared<Fd502Device>(rgb);fd->mount(0,DiskImage::load(floppy));
|
||||
m.cartridges().configure({nullptr,hd,nullptr,nullptr,fd},true,4);
|
||||
m.load(system,cpu);m.resume();frames(m,600);expect("HARD DISK BASIC");
|
||||
type(m,"CLS\rLIST\r");frames(m,60);expect("OK");
|
||||
if(!m.basicReadSource().empty())
|
||||
throw std::runtime_error("Hard BASIC must not load/run a program at boot");
|
||||
const auto hdReads = hd->readEvents(0);
|
||||
const auto fdReads = fd->readEvents(0);
|
||||
type(m,"DIR\rLOAD\"HELLO\"\r");frames(m,600);expect("OK");
|
||||
runPlanetStarter(m,'1');
|
||||
runPlanetStarter(m,'2');
|
||||
if(hd->readEvents(0)==hdReads || fd->readEvents(0)!=fdReads)
|
||||
throw std::runtime_error("RGBDOS did not read the starter from HD0");
|
||||
const auto afterHD = hd->readEvents(0);
|
||||
type(m,"NEW\rDRIVE OFF\rLOAD\"HELLO\"\r");frames(m,1200);expect("OK");
|
||||
runPlanetStarter(m,'1');
|
||||
if(fd->readEvents(0)==fdReads || hd->readEvents(0)!=afterHD)
|
||||
throw std::runtime_error("DRIVE OFF did not read the starter from FD0");
|
||||
const auto afterFD = fd->readEvents(0);
|
||||
type(m,"NEW\rDRIVE ON\rLOAD\"HELLO\"\r");frames(m,600);
|
||||
runPlanetStarter(m,'2');
|
||||
if(hd->readEvents(0)==afterHD || fd->readEvents(0)!=afterFD)
|
||||
throw std::runtime_error("DRIVE ON did not return to HD0");
|
||||
if(fd->image(0)->bytes()!=floppy || hd->image(0)->bytes()!=image)
|
||||
throw std::runtime_error("Reading starters altered their images");
|
||||
type(m,"CLS\rDRIVE255\rSAVE\"CHECK\"\r");frames(m,600);expect("OK");
|
||||
auto saved=hd->image(0)->bytes();hd->eject(0,true);hd->mount(0,HardDiskImage(saved));
|
||||
type(m,"NEW\rLOAD\"CHECK\"\r");frames(m,600);
|
||||
runPlanetStarter(m,'2');
|
||||
if(saved==image || !std::equal(image.begin(),image.begin()+offset+255*volume,saved.begin()))
|
||||
throw std::runtime_error("Last virtual disk SAVE altered other volumes");
|
||||
std::printf("PASS: Hard BASIC boot/no auto-load, HD/floppy LOAD/RUN, DRIVE OFF/ON, volume 255 SAVE/reopen (%s)\n",cpu==Processor::MC6809?"6809":"6309");
|
||||
}
|
||||
auto write=[&](const char* name,const std::vector<std::uint8_t>& data) {
|
||||
std::ofstream f(std::string(output)+"/"+name,std::ios::binary|std::ios::trunc);
|
||||
f.write(reinterpret_cast<const char*>(data.data()),data.size());
|
||||
if(!f)throw std::runtime_error("Could not write authored hard BASIC template");
|
||||
};
|
||||
write("Blank Disk.dsk",blank);write("Hello Hard Disk.dsk",hello);
|
||||
}
|
||||
|
||||
void CheckClipboardRom(const char* path) {
|
||||
std::ifstream file(path,std::ios::binary);
|
||||
std::vector<std::uint8_t> rom((std::istreambuf_iterator<char>(file)),{});
|
||||
for(auto cpu:{VCC::Mac::Processor::MC6809,VCC::Mac::Processor::HD6309}) {
|
||||
VCC::Mac::MachineSession m;m.load(rom,cpu);m.resume();frames(m,300);
|
||||
auto paste=[&](const std::string& text) {
|
||||
std::vector<std::uint64_t> keys;
|
||||
for(char c:text) {
|
||||
auto chord=key(c);
|
||||
if(c>='A' && c<='Z')chord|=std::uint64_t{1}<<55; // Native clipboard uppercase mapping.
|
||||
keys.push_back(chord);
|
||||
}
|
||||
m.paste(keys);
|
||||
for(unsigned n=0;m.pasteRemaining() && n<20000;++n)m.advance();
|
||||
if(m.pasteRemaining())throw std::runtime_error("Paste did not finish");
|
||||
frames(m,30);
|
||||
};
|
||||
paste("10 PRINT 6*7\r20 PRINT 7*7\r");
|
||||
paste("20 PRINT 8*8\rCLS\rRUN\r");
|
||||
auto text=m.copyScreenText();
|
||||
if(text.find(" 42")==std::string::npos || text.find(" 64")==std::string::npos || text.find(" 49")!=std::string::npos)
|
||||
throw std::runtime_error("BASIC merge/copy did not preserve or replace lines: "+text);
|
||||
paste("NEW\r10 PRINT 9*9\rCLS\rRUN\r");text=m.copyScreenText();
|
||||
if(text.find(" 81")==std::string::npos || text.find(" 42")!=std::string::npos)
|
||||
throw std::runtime_error("BASIC replacement/copy failed: "+text);
|
||||
// Verify the safe entry limit through the actual interpreter.
|
||||
std::string line="30 REM "+std::string(242,'A'); // exactly 249 characters
|
||||
paste(line+"\r");
|
||||
paste("CLS\rLIST 30\r");text=m.copyScreenText();
|
||||
if(text.find("30 REM")==std::string::npos || std::count(text.begin(),text.end(),'A')!=242)
|
||||
throw std::runtime_error("Boundary BASIC line failed: "+text);
|
||||
std::printf("PASS: paced BASIC merge/replace, 249-character boundary, copy screen (%s)\n",cpu==VCC::Mac::Processor::MC6809?"6809":"6309");
|
||||
}
|
||||
}
|
||||
|
||||
// Optional private-ROM integration; generated PCM is a local listening artifact.
|
||||
void CheckOrchestraRom(const char* systemPath, const char* orchestraPath, const char* outputPrefix) {
|
||||
auto read = [](const char* path, std::size_t size) {
|
||||
std::ifstream f(path, std::ios::binary); std::vector<std::uint8_t> b(size+1);
|
||||
f.read(reinterpret_cast<char*>(b.data()), b.size());
|
||||
if (std::size_t(f.gcount()) != size) throw std::runtime_error("Unexpected Orchestra reference ROM size");
|
||||
b.resize(size); return b;
|
||||
};
|
||||
auto system = read(systemPath,32768), rom = read(orchestraPath,8192);
|
||||
for (auto cpu : {VCC::Mac::Processor::MC6809, VCC::Mac::Processor::HD6309}) {
|
||||
VCC::Mac::MachineSession m;
|
||||
m.cartridges().configure({nullptr,std::make_shared<VCC::Devices::Orchestra90Device>(rom),nullptr,nullptr,nullptr},true,1);
|
||||
m.load(system,cpu); m.resume(); frames(m,300);
|
||||
type(m," "); frames(m,60); // Dismiss the copyright screen, per manual page 8.
|
||||
if (screen().find("WILLIAM TELL") == std::string::npos) {
|
||||
std::fprintf(stderr,"%s",screen().c_str()); throw std::runtime_error("Orchestra ROM did not reach its demonstration screen");
|
||||
}
|
||||
type(m,"S\r"); frames(m,600); m.takeAudio();
|
||||
type(m,"P\r"); m.takeAudio();
|
||||
std::vector<VCC::Mac::StereoSample> pcm;
|
||||
for (unsigned i=0;i<3600;++i) { m.advance(); auto part=m.takeAudio(); pcm.insert(pcm.end(),part.begin(),part.end()); }
|
||||
float minL=1,maxL=-1,minR=1,maxR=-1; unsigned different=0;
|
||||
for(auto v:pcm) { minL=std::min(minL,v.left);maxL=std::max(maxL,v.left);minR=std::min(minR,v.right);maxR=std::max(maxR,v.right);different+=v.left!=v.right; }
|
||||
if(maxL-minL<.05f || maxR-minR<.05f || different<1000) throw std::runtime_error("Demonstration did not produce independent stereo music");
|
||||
std::string path=std::string(outputPrefix)+(cpu==VCC::Mac::Processor::MC6809 ? "-6809.wav" : "-6309.wav");
|
||||
if (pcm.size() > (std::numeric_limits<std::uint32_t>::max() - 36u) / 4u)
|
||||
throw std::runtime_error("Listening capture exceeds the WAV size limit");
|
||||
const auto dataBytes = static_cast<std::uint32_t>(pcm.size() * 4u);
|
||||
std::ofstream out(path,std::ios::binary);
|
||||
auto word=[&](std::uint32_t v,unsigned n){while(n--){out.put(v&255);v>>=8;}};
|
||||
out.write("RIFF",4);word(36u+dataBytes,4);out.write("WAVEfmt ",8);word(16,4);word(1,2);word(2,2);
|
||||
word(44100,4);word(44100*4,4);word(4,2);word(16,2);out.write("data",4);word(dataBytes,4);
|
||||
for(auto v:pcm) {word(std::uint16_t(std::int16_t(v.left*32767)),2);word(std::uint16_t(std::int16_t(v.right*32767)),2);}
|
||||
if(!out)throw std::runtime_error("Could not write private listening capture");
|
||||
std::printf("Orchestra %s: %zu stereo samples, %u differing channels, ranges %.3f/%.3f; %s\n",cpu==VCC::Mac::Processor::MC6809 ? "6809" : "6309",pcm.size(),different,maxL-minL,maxR-minR,path.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// Authored guest sends documented SSC command bytes, polling BUSY before each.
|
||||
void CheckSpeechSoundRom(const char* systemPath, const char* picPath, const char* speechPath, const char* outputPrefix) {
|
||||
using namespace VCC::Mac;
|
||||
auto read=[](const char* path,std::size_t size){
|
||||
std::ifstream f(path,std::ios::binary);std::vector<std::uint8_t> b(size+1);
|
||||
f.read(reinterpret_cast<char*>(b.data()),b.size());
|
||||
if(std::size_t(f.gcount())!=size)throw std::runtime_error("Unexpected Speech/Sound reference ROM size");
|
||||
b.resize(size);return b;
|
||||
};
|
||||
auto system=read(systemPath,32768),rom=read(picPath,4096),speech=read(speechPath,2048);
|
||||
rom.insert(rom.end(),speech.begin(),speech.end());
|
||||
for(auto cpu:{Processor::MC6809,Processor::HD6309}) {
|
||||
MachineSession m;auto device=std::make_shared<VCC::Devices::SpeechSoundDevice>(rom);
|
||||
m.cartridges().configure({nullptr,nullptr,device,nullptr,nullptr},true,4);
|
||||
m.load(system,cpu);m.resume();frames(m,60);m.takeAudio();
|
||||
auto send=[&](const std::vector<std::uint8_t>& bytes){
|
||||
const auto end=0x3040+bytes.size();
|
||||
// Authored guest explicitly selects cartridge SND and enables the
|
||||
// analog mux, just as physical Speech/Sound software must do.
|
||||
std::vector<std::uint8_t> code{0xb6,0xff,0x01,0x84,0xf7,0xb7,0xff,0x01,
|
||||
0xb6,0xff,0x03,0x8a,0x08,0xb7,0xff,0x03,
|
||||
0xb6,0xff,0x23,0x8a,0x08,0xb7,0xff,0x23,0x8e,0x30,0x40,0x8c,std::uint8_t(end>>8),std::uint8_t(end),
|
||||
0x27,12,0xe6,0x80,0xb6,0xff,0x7e,0x2a,0xfb,0xf7,0xff,0x7e,0x20,0xef,0x20,0xfe};
|
||||
code.resize(64,0x12);code.insert(code.end(),bytes.begin(),bytes.end());
|
||||
std::vector<std::uint8_t> binary{0,0,std::uint8_t(code.size()),0x30,0};
|
||||
binary.insert(binary.end(),code.begin(),code.end());binary.insert(binary.end(),{0xff,0,0,0x30,0});
|
||||
m.quickLoad(binary);
|
||||
};
|
||||
std::string phrase="HELLO FROM YOUR COLOR COMPUTER. \r";
|
||||
send({phrase.begin(),phrase.end()});
|
||||
std::vector<StereoSample> pcm;
|
||||
for(unsigned i=0;i<600;++i){m.advance();auto part=m.takeAudio();pcm.insert(pcm.end(),part.begin(),part.end());}
|
||||
if(device->diagnostics().CommandCount()!=phrase.size() || device->diagnostics().AldSpeechCount()<5 || device->diagnostics().CpuIllegalCount()!=0)
|
||||
throw std::runtime_error("Speech firmware failed command/phoneme execution");
|
||||
float low=1,high=-1;
|
||||
for(auto sample:pcm){low=std::min(low,sample.left);high=std::max(high,sample.left);if(sample.left!=sample.right)throw std::runtime_error("SSC must be mono on both output channels");}
|
||||
if(high-low<.05f)throw std::runtime_error("Speech produced no signal");
|
||||
std::string path=std::string(outputPrefix)+(cpu==Processor::MC6809?"-6809.wav":"-6309.wav");
|
||||
if (pcm.size() > (std::numeric_limits<std::uint32_t>::max() - 36u) / 4u)
|
||||
throw std::runtime_error("Listening capture exceeds the WAV size limit");
|
||||
const auto dataBytes = static_cast<std::uint32_t>(pcm.size() * 4u);
|
||||
std::ofstream out(path,std::ios::binary);
|
||||
auto word=[&](std::uint32_t v,unsigned n){while(n--){out.put(v&255);v>>=8;}};
|
||||
out.write("RIFF",4);word(36u+dataBytes,4);out.write("WAVEfmt ",8);word(16,4);word(1,2);word(2,2);
|
||||
word(44100,4);word(44100*4,4);word(4,2);word(16,2);out.write("data",4);word(dataBytes,4);
|
||||
// Capture the actual signed native PCM without introducing a DC offset.
|
||||
for(auto v:pcm){word(std::uint16_t(std::int16_t(std::clamp(v.left,-1.0f,1.0f)*32767)),2);word(std::uint16_t(std::int16_t(std::clamp(v.right,-1.0f,1.0f)*32767)),2);}
|
||||
if(!out)throw std::runtime_error("Could not write speech listening capture");
|
||||
const auto ay=device->diagnostics().AyWriteCount();
|
||||
send({0xaf,0,100,1,0,7,62,8,15,0xff});
|
||||
float musicLow=1,musicHigh=-1;
|
||||
for(unsigned i=0;i<60;++i){m.advance();for(auto v:m.takeAudio()){musicLow=std::min(musicLow,v.left);musicHigh=std::max(musicHigh,v.left);}}
|
||||
if(device->diagnostics().AyWriteCount()<ay+4 || musicHigh-musicLow<.05f)throw std::runtime_error("SSC music registers produced no tone");
|
||||
send({0});frames(m,30);
|
||||
std::printf("PASS SSC %s: %zu speech samples, %u phonemes, range %.3f; AY tone range %.3f; %s\n",cpu==Processor::MC6809?"6809":"6309",pcm.size(),device->diagnostics().AldSpeechCount(),high-low,musicHigh-musicLow,path.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// Direct-memory BASIC transfers must match bytes produced by the ROM itself.
|
||||
void CheckBasicProgramRom(const char* systemPath, const char* diskPath) {
|
||||
auto read = [](const char* path) {
|
||||
std::ifstream stream(path, std::ios::binary);
|
||||
if (!stream) throw std::runtime_error("Unable to open BASIC integration ROM");
|
||||
return std::vector<std::uint8_t>((std::istreambuf_iterator<char>(stream)), {});
|
||||
};
|
||||
const auto system=read(systemPath), disk=read(diskPath);
|
||||
for (auto cpu : {VCC::Mac::Processor::MC6809,VCC::Mac::Processor::HD6309}) {
|
||||
VCC::Mac::MachineSession m;
|
||||
auto floppy = std::make_shared<VCC::Devices::Fd502Device>(disk);
|
||||
m.cartridges().configure({nullptr,nullptr,nullptr,nullptr,floppy},true,4);
|
||||
m.load(system,cpu);m.resume();frames(m,300);
|
||||
type(m,"10 PRINT 6*7\r20 END\r");frames(m,30);
|
||||
auto program = [&] {
|
||||
unsigned start=(SafeMemRead8(0x19)<<8)|SafeMemRead8(0x1a), end=(SafeMemRead8(0x1b)<<8)|SafeMemRead8(0x1c);
|
||||
std::vector<std::uint8_t> bytes;
|
||||
for(unsigned p=start;p<end;++p) bytes.push_back(SafeMemRead8(p));
|
||||
return bytes;
|
||||
};
|
||||
const auto oracle=program();
|
||||
m.pause();const auto before=m.snapshot();
|
||||
m.basicLoadSource("10 PRINT 6*7\n20 END\n",false);
|
||||
if(program()!=oracle || m.snapshot().cycles!=before.cycles || m.snapshot().state!=VCC::Mac::RunState::Paused)
|
||||
throw std::runtime_error("Direct BASIC bytes differ from ROM or paused load executed instructions");
|
||||
if(m.basicReadSource()!="10 PRINT 6*7\n20 END\n") throw std::runtime_error("BASIC source readback differs");
|
||||
m.basicLoadSource("10 PRINT 6*7\n20 END\n",true);frames(m,180);
|
||||
if(screen().find(" 42 ")==std::string::npos || m.pasteRemaining() || m.snapshot().generation!=before.generation)
|
||||
throw std::runtime_error("Direct BASIC Run did not execute without reset or paste");
|
||||
const auto exportBefore=m.snapshot();
|
||||
std::string exportSource="10 REM EXPORTED SOURCE\n20 PRINT 6*7\n30 END\n";
|
||||
for(unsigned line=40;line<240;line+=10)exportSource+=std::to_string(line)+" REM "+std::string(180,'X')+"\n";
|
||||
const auto exportedDisk=m.basicExportSource(exportSource,"HELLO",VCC::Mac::BasicExportFormat::Disk);
|
||||
const auto exportedTape=m.basicExportSource(exportSource,"HELLO",VCC::Mac::BasicExportFormat::Cassette);
|
||||
if(m.snapshot().cycles!=exportBefore.cycles || m.snapshot().cpu.PC!=exportBefore.cpu.PC || program()!=oracle)
|
||||
throw std::runtime_error("BASIC export changed running machine state");
|
||||
floppy->mount(0,VCC::Devices::DiskImage::load(exportedDisk));
|
||||
type(m,"NEW\rCLS\rLOAD\"HELLO\"\r");frames(m,1200);
|
||||
if(m.basicReadSource()!=exportSource) throw std::runtime_error("Exported DSK did not LOAD identical BASIC source: "+screen());
|
||||
type(m,"RUN\r");frames(m,60);
|
||||
if(screen().find(" 42 ")==std::string::npos)throw std::runtime_error("Exported DSK program did not execute");
|
||||
type(m,"NEW\rCLS\r");m.cassette().mount(exportedTape,VCC::Mac::TapeFormat::CAS);m.cassette().setFast(false);m.cassette().play();
|
||||
type(m,"CLOAD\"HELLO\"\r");frames(m,3600);
|
||||
if(m.basicReadSource()!=exportSource)throw std::runtime_error("Exported CAS did not CLOAD identical BASIC source: "+screen());
|
||||
type(m,"RUN\r");frames(m,60);
|
||||
if(screen().find(" 42 ")==std::string::npos)throw std::runtime_error("Exported CAS program did not execute");
|
||||
const auto stable=m.basicReadSource();
|
||||
bool rejected=false;
|
||||
try {m.basicLoadSource("10 PRINT1\n10 PRINT2",true);}catch(const std::exception&){rejected=true;}
|
||||
if(!rejected || m.basicReadSource()!=stable) throw std::runtime_error("Rejected BASIC source changed RAM");
|
||||
m.basicLoadSource("10 GOTO10",true);frames(m,10);
|
||||
rejected=false;try{m.basicLoadSource("10 END",true);}catch(const std::exception&){rejected=true;}
|
||||
if(!rejected || m.basicReadSource()!="10 GOTO10\n") throw std::runtime_error("Running BASIC program was replaced");
|
||||
std::printf("PASS: BASIC token oracle, paused Load/Read/Run, disk LOAD/cassette CLOAD multi-block exports, output, and atomic rejection (%s)\n",cpu==VCC::Mac::Processor::MC6809?"6809":"6309");
|
||||
}
|
||||
}
|
||||
|
||||
void CheckGraphicsPreviewRom(const char* systemPath, const char* diskPath, const char* programPath) {
|
||||
using namespace VCC::Mac;
|
||||
using Mode = DebugGraphicsMode;
|
||||
auto read = [](const char* path) {
|
||||
std::ifstream input(path, std::ios::binary);
|
||||
if (!input) throw std::runtime_error(std::string("Unable to open ") + path);
|
||||
return std::vector<std::uint8_t>((std::istreambuf_iterator<char>(input)), {});
|
||||
};
|
||||
const auto system = read(systemPath), disk = read(diskPath), sourceBytes = read(programPath);
|
||||
const std::string program(sourceBytes.begin(), sourceBytes.end());
|
||||
auto expect = [](bool condition, const char* message) {
|
||||
if (!condition) throw std::runtime_error(message);
|
||||
};
|
||||
for (auto cpu : {Processor::MC6809, Processor::HD6309}) {
|
||||
MachineSession machine;
|
||||
auto floppy = std::make_shared<VCC::Devices::Fd502Device>(disk);
|
||||
machine.cartridges().configure({nullptr, nullptr, nullptr, nullptr, floppy}, true, 4);
|
||||
machine.load(system, cpu);
|
||||
machine.resume();
|
||||
frames(machine, 300);
|
||||
machine.basicLoadSource(program, true, {40, 50, 60});
|
||||
auto stop = [&](int line) {
|
||||
for (unsigned i = 0; i < 300 && machine.snapshot().state == RunState::Running; ++i)
|
||||
machine.advance();
|
||||
const auto stopped = machine.snapshot();
|
||||
if (stopped.basicStoppedLine != line || stopped.state != RunState::Paused || !stopped.frame)
|
||||
throw std::runtime_error("Two-page program did not stop before line " + std::to_string(line));
|
||||
return stopped;
|
||||
};
|
||||
auto current = [&] { return machine.debuggerGraphicsPreview(true, false, 0, Mode::SG4); };
|
||||
// These are Disk BASIC's legacy pages 1 and 3 in the default memory map.
|
||||
// A PMODE 1 bitmap occupies two consecutive 1,536-byte pages.
|
||||
constexpr unsigned first = 0x0e00, second = 0x1a00;
|
||||
auto mapped = [&](unsigned address) { return machine.debuggerGraphicsPreview(false, false, address, Mode::PMODE1); };
|
||||
auto compareToFrame = [&](const DebugGraphicsPreview& preview, const Snapshot& stopped) {
|
||||
expect(preview.width == 128 && preview.height == 96 && preview.bytesPerRow == 32 &&
|
||||
preview.pixels.size() == 128*96 && preview.modeName == "PMODE 1", "Wrong active PMODE 1 layout");
|
||||
const auto& frame = *stopped.frame;
|
||||
const auto r = frame.activeArea;
|
||||
expect(r.width == 512 && r.height == 384, "Unexpected live PMODE raster geometry");
|
||||
for (unsigned y = 0; y < 96; ++y)
|
||||
for (unsigned x = 0; x < 128; ++x)
|
||||
expect(frame.pixels[(r.y+y*4)*Frame::width + r.x+x*4] == preview.pixels[y*128+x],
|
||||
"Current-page colors differ from the actual published video frame");
|
||||
};
|
||||
|
||||
const auto beforeDraw = stop(40);
|
||||
const auto front = current(), hiddenBlank = mapped(second);
|
||||
compareToFrame(front, beforeDraw);
|
||||
expect(front.physical && front.pixels == mapped(first).pixels && front.bytes == mapped(first).bytes,
|
||||
"Mapped page 1 does not match displayed RAM");
|
||||
expect(front.pixels[10*128+10] != front.pixels[0], "First page is missing its square");
|
||||
expect(std::all_of(hiddenBlank.bytes.begin(), hiddenBlank.bytes.end(), [](auto b) { return b == 0xff; }),
|
||||
"The selected drawing page should still be clear");
|
||||
|
||||
machine.basicContinue(program);
|
||||
const auto beforeFlip = stop(50);
|
||||
const auto stillFront = current(), hiddenDrawing = mapped(second);
|
||||
compareToFrame(stillFront, beforeFlip);
|
||||
expect(front.pixels == stillFront.pixels && front.address == stillFront.address &&
|
||||
beforeDraw.frame->pixels == beforeFlip.frame->pixels, "Drawing to hidden page affected the displayed screen");
|
||||
for (unsigned y = 0; y < 96; ++y) {
|
||||
for (unsigned x = 0; x < 128; ++x) {
|
||||
const bool changed = hiddenDrawing.pixels[y*128+x] != hiddenBlank.pixels[y*128+x];
|
||||
expect(changed == (x >= 80 && x < 112 && y >= 32 && y < 64),
|
||||
"The hidden square must occupy exactly its BASIC coordinates");
|
||||
}
|
||||
}
|
||||
const auto selected = hiddenDrawing.pixelInfo(81, 32);
|
||||
expect(hiddenDrawing.byteAddresses[selected.byteIndex] == 0x1e14 &&
|
||||
hiddenDrawing.bytes[selected.byteIndex] == 0xaa && selected.mask == 0x30,
|
||||
"Wrong mapped byte or bits for a pixel in the hidden drawing");
|
||||
expect(machine.snapshot().cycles == beforeFlip.cycles && machine.snapshot().cpu.PC == beforeFlip.cpu.PC,
|
||||
"Preview moved the stopped CPU");
|
||||
|
||||
machine.basicContinue(program);
|
||||
const auto afterFlip = stop(60);
|
||||
const auto displayed = current();
|
||||
compareToFrame(displayed, afterFlip);
|
||||
expect(displayed.address == front.address + second - first &&
|
||||
displayed.bytes == hiddenDrawing.bytes && displayed.pixels == hiddenDrawing.pixels &&
|
||||
mapped(first).pixels == front.pixels, "SCREEN did not reveal the untouched second page");
|
||||
std::printf("PASS: PMODE 1 two-page preview, 1,024 hidden changed pixels, $1E14 bits 5–4, "
|
||||
"and SCREEN page flip (%s)\n", cpu == Processor::MC6809 ? "6809" : "6309");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,430 @@
|
||||
// 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 <stdexcept>
|
||||
#include <algorithm>
|
||||
#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<class F> 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<std::uint8_t>(0x8001)); }, "Oversized ROM is rejected");
|
||||
require(machine.snapshot().frame == before.frame && machine.snapshot().state == RunState::Running,
|
||||
"Invalid input preserves loaded machine");
|
||||
std::vector<std::uint8_t> 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<unsigned char> 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<std::uint8_t> 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<VideoOutput>(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<unsigned char>(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<Processor>(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<std::uint64_t>(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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
#pragma once
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#include "CoreChecks.h"
|
||||
#include "../../src/core/MachineHost.h"
|
||||
#include "../../src/core/CpuHost.h"
|
||||
#include "../../src/core/CpuMemory.h"
|
||||
#include "../../src/core/tcc1014mmu.h"
|
||||
#include "../../src/core/tcc1014registers.h"
|
||||
#include "../../src/core/mc6821.h"
|
||||
#include "../../src/core/mc6809.h"
|
||||
#include "../../src/core/hd6309.h"
|
||||
#include "../../src/core/Event.h"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
namespace VCCTest {
|
||||
inline void require(bool ok, const char* message) {
|
||||
if (!ok) throw std::runtime_error(message);
|
||||
}
|
||||
// Explicit test replacements for components not extracted yet. The real MMU,
|
||||
// port decoder, GIME/SAM and PIA implementations are linked from VCCCore.
|
||||
struct Host : VCC::MachineHost {
|
||||
bool use6309 = false, romFailure = false, fastTape = false;
|
||||
unsigned char keyboard = 0x7e, columns = 0, tapeBit = 1, motor = 0;
|
||||
unsigned char turbo = 0, speed = 0, printerBit = 0, cartPort = 0, cartValue = 0;
|
||||
unsigned short cartAudio = 0;
|
||||
unsigned joystickStarts = 0, cartReads = 0, cartWrites = 0;
|
||||
std::array<unsigned char, IS_MAX> lines{};
|
||||
std::array<unsigned char, 0x8000> rom{};
|
||||
std::vector<std::tuple<VCC::VideoRegister, unsigned int, unsigned char>> video;
|
||||
std::vector<std::pair<VCC::TimerRegister, unsigned int>> timer;
|
||||
Host() {
|
||||
for (unsigned page = 0; page < 4; ++page)
|
||||
std::fill_n(rom.begin() + page * 8192, 8192, 0xa0 + page);
|
||||
rom[0x7ffe] = 0x40; rom[0x7fff] = 0x00;
|
||||
rom[0x7ff8] = 0x50; rom[0x7ff9] = 0x00;
|
||||
}
|
||||
bool LoadInternalRom(unsigned char* dest, std::size_t size) override {
|
||||
require(size == rom.size(), "ROM provider capacity");
|
||||
std::copy(rom.begin(), rom.end(), dest);
|
||||
return !romFailure;
|
||||
}
|
||||
unsigned char CartridgeRead(unsigned short address) override { return 0xc0 + address / 8192; }
|
||||
unsigned char CartridgePortRead(unsigned char port) override { ++cartReads; cartPort = port; return 0x5a; }
|
||||
void CartridgePortWrite(unsigned char port, unsigned char value) override { ++cartWrites; cartPort = port; cartValue = value; }
|
||||
unsigned short CartridgeAudio() override { return cartAudio; }
|
||||
void VideoWrite(VCC::VideoRegister reg, unsigned int value, unsigned char index) override { video.emplace_back(reg, value, index); }
|
||||
void TimerWrite(VCC::TimerRegister reg, unsigned int value) override { timer.emplace_back(reg, value); }
|
||||
void SetTurbo(unsigned char value) override { turbo = value; }
|
||||
void SetCpuSpeed(unsigned char value) override { speed = value; }
|
||||
VCC::CPUState CpuState() override { return use6309 ? HD6309GetState() : MC6809GetState(); }
|
||||
void AssertInterrupt(InterruptSource source, Interrupt interrupt) override {
|
||||
lines[source] |= Bit(interrupt);
|
||||
if (use6309) HD6309AssertInterupt(source, interrupt); else MC6809AssertInterupt(source, interrupt);
|
||||
}
|
||||
void ClearInterrupt(InterruptSource source, Interrupt interrupt) override {
|
||||
lines[source] &= BitMask(interrupt);
|
||||
if (use6309) HD6309DeAssertInterupt(source, interrupt); else MC6809DeAssertInterupt(source, interrupt);
|
||||
}
|
||||
unsigned char KeyboardScan(unsigned char value) override { columns = value; return keyboard; }
|
||||
void JoystickStart(bool, unsigned char) override { ++joystickStarts; }
|
||||
bool TapeFastLoad() override { return fastTape; }
|
||||
unsigned char TapeInputBit() override { return tapeBit; }
|
||||
void TapeMotor(unsigned char value) override { motor = value; }
|
||||
void PrinterBit(unsigned char value) override { printerBit = value; }
|
||||
};
|
||||
struct Debugger final : VCC::CpuDebugHooks {
|
||||
bool halted = false;
|
||||
bool IsHalted() const override { return halted; }
|
||||
void Halt() override { halted = true; }
|
||||
};
|
||||
struct MachineFixture {
|
||||
Host host;
|
||||
Debugger debugger;
|
||||
explicit MachineFixture(unsigned char config = 1, bool use6309 = false) {
|
||||
host.use6309 = use6309;
|
||||
VCC::SetCpuMemoryBus(nullptr);
|
||||
VCC::SetMachineHost(&host);
|
||||
VCC::SetCpuDebugHooks(&debugger);
|
||||
MC6809Init(); HD6309Init();
|
||||
if (!MmuInit(config)) {
|
||||
VCC::SetMachineHost(nullptr); VCC::SetCpuDebugHooks(nullptr);
|
||||
throw std::runtime_error("Initialize synthetic machine ROM/RAM");
|
||||
}
|
||||
mc6883_reset(); GimeRegistersReset(); PiaReset();
|
||||
MC6809Reset(); HD6309Reset();
|
||||
MC6809SetBreakpoints({}); HD6309SetBreakpoints({});
|
||||
MC6809SetTraceTriggers({}); HD6309SetTraceTriggers({});
|
||||
VCC::gEvents.Reset();
|
||||
}
|
||||
~MachineFixture() {
|
||||
MC6809SetBreakpoints({}); HD6309SetBreakpoints({});
|
||||
MmuShutdown();
|
||||
VCC::SetCpuDebugHooks(nullptr); VCC::SetMachineHost(nullptr);
|
||||
VCC::gEvents.Reset();
|
||||
}
|
||||
void write(unsigned short address, unsigned char value) { MemWrite8(value, address); }
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#include "CoreChecks.h"
|
||||
#include "../../src/core/FramePacing.h"
|
||||
#include "../../src/core/MachineSession.h"
|
||||
#include "../../src/core/tcc1014mmu.h"
|
||||
#include <cmath>
|
||||
#include <stdexcept>
|
||||
using namespace VCC::Mac;
|
||||
namespace {
|
||||
void require(bool value, const char* message) { if (!value) throw std::runtime_error(message); }
|
||||
}
|
||||
void CheckFramePacing() {
|
||||
using namespace std::chrono;
|
||||
FramePacer pacer;
|
||||
const auto origin = FramePacer::Clock::time_point{};
|
||||
// Irregular host callbacks for thirty simulated minutes; no wall-clock wait.
|
||||
auto elapsed = nanoseconds::zero();
|
||||
std::uint64_t frames = 0;
|
||||
for (unsigned i = 0; elapsed < minutes(30); ++i) {
|
||||
if (pacer.ready(origin + elapsed)) ++frames;
|
||||
elapsed += microseconds(1000 + (i % 7) * 500);
|
||||
}
|
||||
const double expected = duration<double>(elapsed).count() * masterClockHz / clocksPerFrame;
|
||||
require(std::abs(double(frames) - expected) < 1.1, "Irregular host ticks must not accumulate frame drift");
|
||||
auto late = origin + hours(1);
|
||||
require(pacer.ready(late) && !pacer.ready(late), "Long stall must not replay a backlog of frames");
|
||||
require(!pacer.ready(late + frameInterval - nanoseconds(1)) && pacer.ready(late + frameInterval),
|
||||
"Late wake establishes a full new frame interval");
|
||||
pacer.reset();
|
||||
require(pacer.ready(late) && !pacer.ready(late), "Resume resets stale deadlines without double execution");
|
||||
// Short lateness is caught up, preserving average speed rather than dropping time.
|
||||
pacer.reset(); pacer.ready(origin);
|
||||
unsigned catchup = 0;
|
||||
while (pacer.ready(origin + frameInterval * 3)) ++catchup;
|
||||
require(catchup == 3, "Short host jitter retains scheduled guest frames");
|
||||
}
|
||||
void CheckAudioProgress() {
|
||||
using namespace std::chrono;
|
||||
AudioProgress progress;
|
||||
const auto start = AudioProgress::Clock::time_point{};
|
||||
require(!progress.stalled(start, 0) && !progress.stalled(start + milliseconds(999), 0), "Audio startup has a bounded grace period");
|
||||
require(progress.stalled(start + seconds(1), 0), "A live graph with no consumption must be detected");
|
||||
require(!progress.stalled(start + seconds(2), 1), "Sample consumption clears a stalled interval");
|
||||
require(!progress.stalled(start + milliseconds(2999), 1) && progress.stalled(start + seconds(3), 1), "Watchdog follows the last progress, not graph age");
|
||||
progress.reset();
|
||||
require(!progress.stalled(start + hours(1), 1), "Pause/device restart discards the previous watchdog deadline");
|
||||
|
||||
AudioProgress startup;
|
||||
require(!startup.stalled(start, 0), "Prefill may precede the first output graph");
|
||||
// A slow host may spend longer than the watchdog interval creating its
|
||||
// first graph. That setup time cannot count as a stalled render callback.
|
||||
const auto graphReady = start + seconds(2);
|
||||
startup.reset();
|
||||
require(!startup.stalled(graphReady, 0), "A newly started graph gets its own progress deadline");
|
||||
require(!startup.stalled(graphReady + milliseconds(999), 0), "Slow startup retains the normal consumption grace period");
|
||||
require(startup.stalled(graphReady + seconds(1), 0), "Startup reset must not disable or extend the live-graph watchdog");
|
||||
require(!startup.stalled(graphReady + milliseconds(1100), 4410), "Real output consumption clears the startup stall");
|
||||
}
|
||||
void CheckAcceleratedTiming() {
|
||||
for (auto cpu : {Processor::MC6809, Processor::HD6309}) {
|
||||
MachineSession machine;
|
||||
// Authored BRA-to-self ROM gives an independently known three-cycle loop.
|
||||
std::vector<std::uint8_t> rom(32768, 0x12);
|
||||
rom[0] = 0x20; rom[1] = 0xfe; rom[0x7ffe] = 0x80; rom[0x7fff] = 0;
|
||||
machine.load(rom, cpu); machine.resume();
|
||||
for (unsigned multiplier : {1u, 2u, 4u, 2u, 1u}) {
|
||||
MemWrite8(multiplier == 4 ? 1 : 0, 0xff96);
|
||||
MemWrite8(0, multiplier == 1 ? 0xffd8 : 0xffd9);
|
||||
machine.advance(); machine.takeAudio(); // settle a transition within a scanline
|
||||
const auto before = machine.snapshot();
|
||||
unsigned samples = 0;
|
||||
for (unsigned frame = 0; frame < 60; ++frame) { machine.advance(); samples += machine.takeAudio().size(); }
|
||||
const auto after = machine.snapshot();
|
||||
const auto cycles = after.cycles - before.cycles;
|
||||
require(after.frames - before.frames == 60 && after.cpu.PC == 0x8000, "Accelerated guest must execute complete frames");
|
||||
require(std::abs(double(cycles) - 60.0 * clocksPerFrame / 16 * multiplier) <= 3,
|
||||
"Mapped normal/double/turbo switches must change CPU throughput by 1/2/4");
|
||||
require(samples > 44300 && samples < 44400, "CPU acceleration must not accelerate audio or raster time");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CheckConfiguredOverclock() {
|
||||
for (auto cpu : {Processor::MC6809, Processor::HD6309}) {
|
||||
MachineSession machine;
|
||||
std::vector<std::uint8_t> rom(32768, 0x12);
|
||||
rom[0] = 0x20; rom[1] = 0xfe; rom[0x7ffe] = 0x80; rom[0x7fff] = 0;
|
||||
machine.load(rom, cpu); machine.resume();
|
||||
for (unsigned factor : {1u, 3u, 16u, 1u}) {
|
||||
auto config = machine.snapshot().configuration; config.overclock = factor;
|
||||
machine.configure(config);
|
||||
for (unsigned speed : {1u, 2u, 4u}) {
|
||||
MemWrite8(speed == 4 ? 1 : 0, 0xff96);
|
||||
MemWrite8(0, speed == 1 ? 0xffd8 : 0xffd9);
|
||||
machine.advance(); machine.takeAudio();
|
||||
const auto before = machine.snapshot(); unsigned samples = 0;
|
||||
for (unsigned i = 0; i < 6; ++i) { machine.advance(); samples += machine.takeAudio().size(); }
|
||||
const auto after = machine.snapshot();
|
||||
// Retained Windows timing uses 1/256 master-clock resolution;
|
||||
// non-power-of-two multipliers quantize the clock divider.
|
||||
const unsigned divider = speed == 1 ? 4096 : 2048 / (factor * (speed / 2));
|
||||
const auto expected = 6.0 * clocksPerFrame * 256 / divider;
|
||||
require(std::abs(double(after.cycles - before.cycles) - expected) <= 3,
|
||||
"Configured overclock matches Windows guest-gated throughput including turbo");
|
||||
require(samples >= 4432 && samples <= 4434 && after.frames - before.frames == 6,
|
||||
"Overclock preserves complete video frames and 44.1 kHz guest audio");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,315 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#include "TestMachine.h"
|
||||
#include "../../src/core/VideoHost.h"
|
||||
#include "../../src/core/VideoRegisters.h"
|
||||
#include "../../src/core/FrameRunner.h"
|
||||
#include "../../src/core/tcc1014graphics.h"
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
using namespace VCCTest;
|
||||
|
||||
namespace {
|
||||
constexpr unsigned width = 640, height = 480, guard = 16;
|
||||
constexpr unsigned sentinel = 0xdeadbeef;
|
||||
struct GraphicsHost final : Host, VCC::VideoHost {
|
||||
GimeGpu* gpu = nullptr;
|
||||
VCC::VideoState surface;
|
||||
std::vector<unsigned int> pixels = std::vector<unsigned int>(width * height + 2 * guard, sentinel);
|
||||
bool ntsc = false;
|
||||
VCC::VideoRect active;
|
||||
void ActiveVideoArea(int x,int y,int w,int h) override { active.include(x,y,w,h,surface.WindowSize); }
|
||||
unsigned horizontalFalls = 0, horizontalRises = 0;
|
||||
std::vector<std::pair<int, size_t>> vertical;
|
||||
GraphicsHost() {
|
||||
surface.BitDepth = 3;
|
||||
surface.PTRsurface32 = pixels.data() + guard;
|
||||
surface.SurfacePitch = width;
|
||||
surface.WindowSize = {width, height};
|
||||
ClearSurface();
|
||||
}
|
||||
VCC::VideoState& Surface() override { return surface; }
|
||||
void ClearSurface() override { std::fill_n(surface.PTRsurface32, width * height, 0); }
|
||||
bool UseNtscArtifacts() const override { return ntsc; }
|
||||
void VideoWrite(VCC::VideoRegister reg, unsigned int value, unsigned char index) override {
|
||||
VCC::ApplyVideoRegister(*gpu, reg, value, index);
|
||||
}
|
||||
void TimerWrite(VCC::TimerRegister reg, unsigned int value) override {
|
||||
VCC::ApplyTimerRegister(*gpu, reg, value);
|
||||
}
|
||||
unsigned int pixel(unsigned x, unsigned y) const { return pixels[guard + y*width + x]; }
|
||||
void checkGuards() const {
|
||||
require(std::all_of(pixels.begin(), pixels.begin()+guard, [](auto v) { return v == sentinel; }) &&
|
||||
std::all_of(pixels.end()-guard, pixels.end(), [](auto v) { return v == sentinel; }),
|
||||
"Renderer stays inside 640x480 surface");
|
||||
}
|
||||
};
|
||||
struct GraphicsFixture {
|
||||
GraphicsHost host;
|
||||
Debugger debugger;
|
||||
GimeGpu gpu;
|
||||
explicit GraphicsFixture(bool scheduled = false, bool use6309 = false) :
|
||||
gpu(scheduled ? GimeGpu::SyncFunction([this](int level) {
|
||||
if (level) ++host.horizontalRises; else ++host.horizontalFalls;
|
||||
irq_hs(level);
|
||||
}) : GimeGpu::SyncFunction{},
|
||||
scheduled ? GimeGpu::SyncFunction([this](int level) {
|
||||
host.vertical.emplace_back(level, VCC::gEvents.GetClocks()); irq_fs(level);
|
||||
}) : GimeGpu::SyncFunction{}) {
|
||||
host.gpu = &gpu; host.use6309 = use6309;
|
||||
VCC::SetMachineHost(&host); VCC::SetVideoHost(&host);
|
||||
VCC::SetCpuDebugHooks(&debugger); VCC::SetCpuMemoryBus(nullptr);
|
||||
VCC::gEvents.Reset();
|
||||
MC6809Init(); HD6309Init();
|
||||
require(MmuInit(1) != nullptr, "Graphics fixture RAM/ROM allocation");
|
||||
host.surface.RamBuffer = Get_mem_pointer();
|
||||
host.surface.WRamBuffer = reinterpret_cast<unsigned short*>(Get_mem_pointer());
|
||||
std::fill_n(Get_mem_pointer(), 0x80000, 0);
|
||||
GimeRegistersReset(); PiaReset(); mc6883_reset();
|
||||
MC6809Reset(); HD6309Reset();
|
||||
MC6809SetBreakpoints({}); HD6309SetBreakpoints({});
|
||||
gpu.GimeReset(); gpu.SetMonitorType(1); gpu.SetDefaultPalette();
|
||||
}
|
||||
~GraphicsFixture() {
|
||||
gpu.StopEvents(); VCC::gEvents.Reset(); MmuShutdown();
|
||||
MC6809SetBreakpoints({}); HD6309SetBreakpoints({});
|
||||
VCC::SetCpuDebugHooks(nullptr); VCC::SetVideoHost(nullptr); VCC::SetMachineHost(nullptr);
|
||||
}
|
||||
void clockTicks() { VCC::gEvents.SetClocksPerCycle(1); VCC::gEvents.Rebase(); }
|
||||
void renderLine(unsigned line = 0) {
|
||||
host.surface.LineCounter = line;
|
||||
gpu.UpdateScreen32(&host.surface);
|
||||
}
|
||||
void loopProgram() {
|
||||
MemWrite8(0x20, 0x4000); MemWrite8(0xfe, 0x4001); // BRA $4000
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void CheckVideoPixels() {
|
||||
GraphicsFixture f;
|
||||
// 320-pixel, 4-bpp RGB graphics. Pixel pairs are doubled to 640 pixels.
|
||||
f.gpu.SetGimeVmode(0x80); f.gpu.SetGimeVres(0x1e);
|
||||
f.gpu.SetGimePalette(1, 36); // full red
|
||||
f.gpu.SetGimePalette(2, 18); // full green
|
||||
f.gpu.SetGimePalette(3, 9); // full blue
|
||||
f.gpu.SetGimePalette(4, 63); // white
|
||||
Get_mem_pointer()[0] = 0x12; Get_mem_pointer()[1] = 0x34;
|
||||
f.renderLine();
|
||||
const unsigned expected[] = {0xff0000,0xff0000,0x00ff00,0x00ff00,0x0000ff,0x0000ff,0xffffff,0xffffff};
|
||||
const auto y = f.gpu.VertCenter * 2;
|
||||
for (unsigned x = 0; x < 8; ++x)
|
||||
require(f.host.pixel(x,y) == expected[x] && f.host.pixel(x,y+1) == expected[x],
|
||||
"RGB pixel byte order, nibble order and 2x scaling");
|
||||
f.gpu.SetScanLines(1); f.renderLine();
|
||||
for (unsigned x = 0; x < 8; ++x)
|
||||
require(f.host.pixel(x,y) == expected[x] && f.host.pixel(x,y+1) == 0, "Scanline option leaves alternating row black");
|
||||
f.gpu.SetScanLines(0); f.gpu.SetGimeBoarderColor(63);
|
||||
f.gpu.SetGimeVres(0x18); // 128 bytes at 1 bpp derives an unsupported 1024-pixel row
|
||||
f.renderLine(10);
|
||||
require(std::all_of(f.host.pixels.begin()+guard, f.host.pixels.end()-guard,
|
||||
[](auto pixel) { return pixel == 0; }), "Unsupported wide layout leaves framebuffer intact");
|
||||
f.host.checkGuards();
|
||||
// Explicit raster metadata is independent of green/black content. Both
|
||||
// resolutions and a mixed-width frame are represented without clipping.
|
||||
for (unsigned resolution : {0u, 0x1eu, 0x3eu, 0x5eu}) {
|
||||
f.host.active = {}; f.gpu.SetGimeVmode(0x80); f.gpu.SetGimeVres(resolution);
|
||||
for (unsigned row=0;row<f.gpu.LinesperScreen;++row) f.renderLine(row);
|
||||
const auto area=f.host.active;
|
||||
require(area.x==f.gpu.HorzCenter && area.y==f.gpu.VertCenter*2 &&
|
||||
area.width==640-2*f.gpu.HorzCenter && area.height==f.gpu.LinesperScreen*2,
|
||||
"Published active raster follows resolution, not pixel colors");
|
||||
}
|
||||
f.host.active = {};f.gpu.SetGimeVres(0);f.renderLine(0);
|
||||
f.gpu.SetGimeVres(0x1e);f.renderLine(191);
|
||||
require(f.host.active.x==0 && f.host.active.width==640 && f.host.active.y==50 && f.host.active.height==384,
|
||||
"Mixed-width raster retains the union of active rows");
|
||||
}
|
||||
|
||||
void CheckVideoModes() {
|
||||
GraphicsFixture f;
|
||||
std::fill_n(Get_mem_pointer(), 0x80000, 0x55);
|
||||
// Sweep register combinations over every active row, including
|
||||
// legacy text/semigraphics, PMODE variants, CoCo 3 text and all depths.
|
||||
for (unsigned compat = 0; compat < 2; ++compat) {
|
||||
f.gpu.SetCompatMode(compat);
|
||||
const unsigned modes = compat ? 8 : 16;
|
||||
const unsigned resolutions = compat ? 32 : 128;
|
||||
for (unsigned mode = 0; mode < modes; ++mode) {
|
||||
if (compat) f.gpu.SetGimeVdgMode(mode);
|
||||
else f.gpu.SetGimeVmode((mode & 8 ? 0x80 : 0) | (mode & 7));
|
||||
for (unsigned res = 0; res < resolutions; ++res) {
|
||||
if (compat) f.gpu.SetGimeVdgMode2(res);
|
||||
else f.gpu.SetGimeVres(res);
|
||||
f.host.ClearSurface();
|
||||
for (unsigned line = 0; line < f.gpu.LinesperScreen; ++line) f.renderLine(line);
|
||||
f.host.checkGuards();
|
||||
}
|
||||
}
|
||||
}
|
||||
// Exercise the composite artifact path separately from the RGB sweep.
|
||||
f.host.ntsc = true; f.gpu.SetMonitorType(0); f.gpu.SetCompatMode(1);
|
||||
f.gpu.SetGimeVdgMode(7); f.gpu.SetGimeVdgMode2(31);
|
||||
f.gpu.SetGimeBoarderColor(63); // Select the white-border composite artifact path.
|
||||
f.renderLine(); f.host.checkGuards();
|
||||
|
||||
// Exercise a 128 KiB address mask inside this 512 KiB test allocation.
|
||||
// The bytes beyond the mask retain 0x55, making an unwrapped read visible.
|
||||
constexpr unsigned mask = 0x1ffff, wrappedStart = mask - 7, contiguousStart = 0x400;
|
||||
f.gpu.SetVidMask(mask);
|
||||
auto* ram = Get_mem_pointer();
|
||||
for (unsigned i = 0; i < 160; ++i) {
|
||||
const auto value = static_cast<unsigned char>(i * 37 + 3);
|
||||
ram[(wrappedStart + i) & mask] = ram[contiguousStart + i] = value;
|
||||
}
|
||||
auto renderedRow = [&](unsigned start) {
|
||||
f.gpu.NewStartofVidram = start;
|
||||
f.renderLine();
|
||||
const auto* row = f.host.surface.PTRsurface32 + 2 * f.gpu.VertCenter * width;
|
||||
return std::vector<unsigned int>(row, row + width);
|
||||
};
|
||||
require(f.gpu.BoarderColor32 == 0xffffff && f.gpu.BytesperRow == 32 &&
|
||||
renderedRow(wrappedStart) == renderedRow(contiguousStart),
|
||||
"PMODE 4 composite row wraps individual RAM reads at the installed capacity");
|
||||
|
||||
// 80 columns with attributes: the fourth attribute is the last physical
|
||||
// byte, and the fifth character and attribute must both come from low RAM.
|
||||
f.gpu.SetCompatMode(0); f.gpu.SetGimeVmode(3); f.gpu.SetGimeVres(0x15);
|
||||
require(f.gpu.ExtendedText == 2 && f.gpu.BytesperRow == 80 &&
|
||||
renderedRow(wrappedStart) == renderedRow(contiguousStart),
|
||||
"CoCo 3 text and attribute pairs wrap at the installed RAM capacity");
|
||||
}
|
||||
|
||||
void CheckRasterTiming() {
|
||||
for (bool use6309 : {false,true}) {
|
||||
GraphicsFixture f(true, use6309);
|
||||
f.loopProgram();
|
||||
auto execute = use6309 ? HD6309Exec : MC6809Exec;
|
||||
auto first = VCC::RunFrame(f.gpu, execute, 20000);
|
||||
require(first.reason == VCC::FrameStop::Complete && first.cycles == 14994,
|
||||
"First raster frame completes after 263 lines with instruction overshoot");
|
||||
require(f.host.horizontalFalls == 263 && f.host.horizontalRises == 263,
|
||||
"Raster emits one HSYNC pulse per 912-clock line");
|
||||
auto second = VCC::RunFrame(f.gpu, execute, 20000);
|
||||
require(second.reason == VCC::FrameStop::Complete && second.cycles == 14991 &&
|
||||
f.host.horizontalFalls == 526, "Subsequent frame preserves 239856-clock period");
|
||||
require(f.host.vertical.size() >= 2 && f.host.vertical[0].first == 0 && f.host.vertical[1].first == 1 &&
|
||||
f.host.vertical[1].second - f.host.vertical[0].second == 4*912,
|
||||
"VSYNC pulse lasts four scanlines");
|
||||
f.host.checkGuards();
|
||||
}
|
||||
}
|
||||
|
||||
void CheckRasterPixels() {
|
||||
GraphicsFixture f(true);
|
||||
f.loopProgram();
|
||||
f.gpu.SetGimeVmode(0x80); f.gpu.SetGimeVres(0x1e);
|
||||
f.gpu.SetGimePalette(1, 36); f.gpu.SetGimePalette(2, 18);
|
||||
f.gpu.SetGimePalette(3, 9); f.gpu.SetGimePalette(4, 63);
|
||||
f.gpu.SetGimeBoarderColor(9);
|
||||
for (unsigned y = 0; y < 192; ++y)
|
||||
for (unsigned x = 0; x < 160; ++x) {
|
||||
const auto color = (x / 20) % 4 + 1;
|
||||
Get_mem_pointer()[y*160+x] = (color << 4) | color;
|
||||
}
|
||||
require(VCC::RunFrame(f.gpu, MC6809Exec, 20000).reason == VCC::FrameStop::Complete,
|
||||
"CPU-driven color-bar frame completes");
|
||||
const unsigned colors[] = {0xff0000,0x00ff00,0x0000ff,0xffffff};
|
||||
for (unsigned y = 50; y < 434; ++y)
|
||||
for (unsigned x = 0; x < 640; ++x)
|
||||
require(f.host.pixel(x,y) == colors[(x/80)%4], "Full raster RGB bars preserve placement and pixels");
|
||||
require(f.host.pixel(0,0) == 0x0000ff && f.host.pixel(639,477) == 0x0000ff,
|
||||
"Raster draws top and bottom border");
|
||||
|
||||
// The first scheduled frame established the mode and the red first bar.
|
||||
// A guest palette write is visible to a paused snapshot before HSYNC
|
||||
// consumes it for the live raster.
|
||||
const auto livePixels = f.host.pixels;
|
||||
const auto clock = VCC::gEvents.GetClocks();
|
||||
const auto lineClock = f.gpu.GetLineStartClock();
|
||||
const auto hsyncs = f.host.horizontalFalls;
|
||||
f.gpu.SetGimePalette(1, 54); // red + green = yellow
|
||||
require(f.gpu.Palette32Bit[1] == colors[0], "Palette write is queued for the beam");
|
||||
std::vector<std::uint32_t> snapshot;
|
||||
const auto area = f.gpu.RenderSnapshot32(f.host.surface, snapshot);
|
||||
require(snapshot.size() == width * height && area.x == 0 && area.y == 50 &&
|
||||
area.width == width && area.height == 384, "Detached color bars cover the established active raster");
|
||||
for (unsigned y : {50u, 433u}) {
|
||||
require(snapshot[y * width] == 0xffff00 && snapshot[y * width + 80] == colors[1],
|
||||
"Detached raster applies the queued palette to the whole bar");
|
||||
}
|
||||
require(f.host.pixels == livePixels && f.gpu.Palette32Bit[1] == colors[0],
|
||||
"Detached render preserves all live pixels and the pending palette write");
|
||||
require(VCC::gEvents.GetClocks() == clock && f.gpu.GetLineStartClock() == lineClock &&
|
||||
f.host.horizontalFalls == hsyncs, "Detached render leaves the scheduler and beam at the stop");
|
||||
|
||||
const auto next = VCC::RunFrame(f.gpu, MC6809Exec, 20000);
|
||||
require(next.reason == VCC::FrameStop::Complete && next.cycles == 14991 &&
|
||||
f.host.horizontalFalls == hsyncs + 263, "The next scheduled frame retains its normal period");
|
||||
require(f.gpu.Palette32Bit[1] == 0xffff00 && f.host.pixel(0, 50) == 0xffff00 &&
|
||||
f.host.pixel(0, 433) == 0xffff00, "Regular rendering consumes the queued write and redraws the bar");
|
||||
f.host.checkGuards();
|
||||
}
|
||||
|
||||
void CheckGimeTimers() {
|
||||
GraphicsFixture f(true);
|
||||
f.clockTicks();
|
||||
GimeWrite(0x90, 0x20); GimeWrite(0x95, 1); GimeWrite(0x92, 0x20);
|
||||
GimeWrite(0x91, 0x20); // fast clock; restart at +8, period (1+2)*4
|
||||
VCC::gEvents.Tick(36);
|
||||
require(!f.host.lines[IS_GIME], "Fast timer respects delayed IRQ and exclusive event boundary");
|
||||
VCC::gEvents.Tick(1);
|
||||
require(GimeRead(0x92) == 0x20, "Fast timer IRQ occurs after reload and issue delay");
|
||||
VCC::gEvents.Tick(12);
|
||||
require(GimeRead(0x92) == 0x20, "Short-period timer retains overlapping delayed IRQs");
|
||||
GimeWrite(0x94, 0); GimeWrite(0x95, 0); GimeWrite(0x94, 0);
|
||||
VCC::gEvents.Tick(100); (void)GimeRead(0x92);
|
||||
VCC::gEvents.Tick(100);
|
||||
require(GimeRead(0x92) == 0, "Zero timer stops retriggering");
|
||||
|
||||
// Reset and run the line-clock source, including the initial decrement.
|
||||
VCC::gEvents.Reset(); f.clockTicks(); f.gpu.GimeReset(); GimeRegistersReset();
|
||||
GimeWrite(0x90, 0x20); GimeWrite(0x95, 1); GimeWrite(0x94, 0); GimeWrite(0x92, 0x20);
|
||||
VCC::gEvents.Tick(2736);
|
||||
require(!f.host.lines[IS_GIME], "Line timer waits for the third decrement and next HSYNC");
|
||||
VCC::gEvents.Tick(1);
|
||||
require(GimeRead(0x92) == 0x20, "Line-clock timer fires at HSYNC after reaching zero");
|
||||
}
|
||||
|
||||
void CheckVideoLifecycle() {
|
||||
GraphicsFixture f(true);
|
||||
f.clockTicks();
|
||||
f.gpu.SetGimeBoarderColor(63);
|
||||
GimeWrite(0x95, 1); GimeWrite(0x91, 0x20);
|
||||
f.gpu.GimeReset();
|
||||
require(VCC::gEvents.GetSize() == 4, "GPU reset replaces callbacks instead of duplicating raster/timers");
|
||||
VCC::gEvents.Tick(913);
|
||||
require(f.host.horizontalFalls == 1, "Repeated GPU reset leaves a single raster clock");
|
||||
f.gpu.StopEvents();
|
||||
require(VCC::gEvents.GetSize() == 0, "GPU stop cancels all owned work");
|
||||
VCC::gEvents.Tick(10000);
|
||||
require(f.host.horizontalFalls == 1, "Stopped GPU produces no further callbacks");
|
||||
{
|
||||
GimeGpu transient([](int) {}, [](int) {});
|
||||
transient.GimeReset(); // deliberately rely on lifetime guard, not StopEvents
|
||||
}
|
||||
VCC::gEvents.Tick(10000);
|
||||
require(VCC::gEvents.GetSize() == 0, "Destroyed GPU callbacks expire without dereferencing it");
|
||||
}
|
||||
|
||||
void CheckFrameStops() {
|
||||
GraphicsFixture f(true);
|
||||
f.loopProgram();
|
||||
MC6809SetBreakpoints({0x4000});
|
||||
auto result = VCC::RunFrame(f.gpu, MC6809Exec, 20000);
|
||||
require(result.reason == VCC::FrameStop::Halted && result.cycles == 0,
|
||||
"Frame runner returns immediately when CPU hits a breakpoint");
|
||||
MC6809SetBreakpoints({}); f.debugger.halted = false;
|
||||
result = VCC::RunFrame(f.gpu, MC6809Exec, 100);
|
||||
require(result.reason == VCC::FrameStop::Budget && result.cycles == 102,
|
||||
"Frame runner bounds work with final instruction overshoot");
|
||||
result = VCC::RunFrame(f.gpu, MC6809Exec, 20000);
|
||||
require(result.reason == VCC::FrameStop::Complete && result.cycles == 14892,
|
||||
"Partial frame resumes without restarting the raster");
|
||||
result = VCC::RunFrame(f.gpu, [](int budget) { return budget; }, 100);
|
||||
require(result.reason == VCC::FrameStop::Stalled, "Frame runner detects a CPU that makes no progress");
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#include "CoreChecks.h"
|
||||
#include <cstdio>
|
||||
#include <exception>
|
||||
#include <cstring>
|
||||
int main(int argc, char** argv) {
|
||||
if (argc == 5 && std::strcmp(argv[1], "--graphics-rom") == 0) {
|
||||
try { CheckGraphicsPreviewRom(argv[2], argv[3], argv[4]); return 0; }
|
||||
catch (const std::exception& error) { std::fprintf(stderr, "FAIL: %s\n", error.what()); return 1; }
|
||||
}
|
||||
if (argc == 4 && std::strcmp(argv[1], "--basic-rom") == 0) {
|
||||
try { CheckBasicProgramRom(argv[2],argv[3]); return 0; }
|
||||
catch(const std::exception& e) { std::fprintf(stderr,"FAIL: %s\n",e.what()); return 1; }
|
||||
}
|
||||
if (argc == 6 && std::strcmp(argv[1], "--speech-rom") == 0) {
|
||||
try { CheckSpeechSoundRom(argv[2],argv[3],argv[4],argv[5]); return 0; }
|
||||
catch(const std::exception& e) { std::fprintf(stderr,"%s\n",e.what()); return 1; }
|
||||
}
|
||||
if (argc == 5 && std::strcmp(argv[1], "--orchestra-rom") == 0) {
|
||||
try { CheckOrchestraRom(argv[2],argv[3],argv[4]); return 0; }
|
||||
catch(const std::exception& error) { std::fprintf(stderr,"FAIL: %s\n",error.what()); return 1; }
|
||||
}
|
||||
if (argc == 3 && std::strcmp(argv[1], "--clipboard-rom") == 0) {
|
||||
try { CheckClipboardRom(argv[2]); return 0; }
|
||||
catch(const std::exception& error) { std::fprintf(stderr,"FAIL: %s\n",error.what()); return 1; }
|
||||
}
|
||||
if (argc == 6 && std::strcmp(argv[1], "--nitros9-profile") == 0) {
|
||||
try { CheckHardDiskRom(argv[2],argv[3],argv[4],argv[5]); return 0; }
|
||||
catch(const std::exception& error) { std::fprintf(stderr,"FAIL: %s\n",error.what()); return 1; }
|
||||
}
|
||||
if (argc == 6 && std::strcmp(argv[1], "--hard-basic-media") == 0) {
|
||||
try { CreateHardBasicMedia(argv[2],argv[3],argv[4],argv[5]); return 0; }
|
||||
catch(const std::exception& error) { std::fprintf(stderr,"FAIL: %s\n",error.what()); return 1; }
|
||||
}
|
||||
if (argc == 5 && std::strcmp(argv[1], "--starter-media") == 0) {
|
||||
try { CreateStarterMedia(argv[2],argv[3],argv[4]); return 0; }
|
||||
catch(const std::exception& error) { std::fprintf(stderr,"FAIL: %s\n",error.what()); return 1; }
|
||||
}
|
||||
if (argc != 1 && !(argc == 3 && std::strcmp(argv[1], "--rom") == 0) &&
|
||||
!(argc == 4 && std::strcmp(argv[1], "--disk-rom") == 0) &&
|
||||
!(argc == 5 && std::strcmp(argv[1], "--hard-disk") == 0)) {
|
||||
std::fprintf(stderr, "Usage: VCCCoreChecks [--rom /path/to/coco3.rom | --disk-rom /path/to/coco3.rom /path/to/disk11.rom | --hard-disk /path/to/coco3.rom /path/to/rgbdos.rom /path/to/NitrOS9.vhd]\n"); return 2;
|
||||
}
|
||||
const char* current = "startup";
|
||||
try {
|
||||
const struct { const char* name; void (*run)(); } checks[] = {
|
||||
{"DriveWireProtocol", CheckDriveWireProtocol},
|
||||
{"BasicProgramTokens", CheckBasicProgramTokens},
|
||||
{"BasicProgramValidation", CheckBasicProgramValidation},
|
||||
{"SessionClipboard", CheckSessionClipboard},
|
||||
{"FramePacing", CheckFramePacing},
|
||||
{"AudioProgress", CheckAudioProgress},
|
||||
{"AcceleratedTiming", CheckAcceleratedTiming},
|
||||
{"MachineMemorySettings", CheckMachineMemorySettings},
|
||||
{"MachinePresentationSettings", CheckMachinePresentationSettings},
|
||||
{"ConfiguredOverclock", CheckConfiguredOverclock},
|
||||
{"BinaryParsing", CheckBinaryParsing},
|
||||
{"BinaryValidation", CheckBinaryValidation},
|
||||
{"BinarySession", CheckBinarySession},
|
||||
{"BinaryMappedWrites", CheckBinaryMappedWrites},
|
||||
{"DiskImages", CheckDiskImages},
|
||||
{"FloppyCommands", CheckFloppyCommands},
|
||||
{"FloppyTransfers", CheckFloppyTransfers},
|
||||
{"FloppyProtection", CheckFloppyProtection},
|
||||
{"BuiltinDeviceBus", CheckBuiltinDeviceBus},
|
||||
{"FloppySession", CheckFloppySession},
|
||||
{"AudioBuffer", CheckAudioBuffer},
|
||||
{"AudioScheduling", CheckAudioScheduling},
|
||||
{"AudioRouting", CheckAudioRouting},
|
||||
{"CassetteImages", CheckCassetteImages},
|
||||
{"CassetteMachine", CheckCassetteMachine},
|
||||
{"SessionSoftReset", CheckSessionSoftReset},
|
||||
{"SessionKeyboard", CheckSessionKeyboard},
|
||||
{"SessionAutomaticBoot", CheckSessionAutomaticBoot},
|
||||
{"JoystickComparator", CheckJoystickComparator},
|
||||
{"JoystickRamps", CheckJoystickRamps},
|
||||
{"JoystickSession", CheckJoystickSession},
|
||||
{"SessionVideoOutput", CheckSessionVideoOutput},
|
||||
{"GraphicsPreviewModes", CheckGraphicsPreviewModes},
|
||||
{"GraphicsPreviewColorSets", CheckGraphicsPreviewColorSets},
|
||||
{"SessionLifecycle", CheckSessionLifecycle},
|
||||
{"SessionReset", CheckSessionReset},
|
||||
{"SessionFrameOwnership", CheckSessionFrameOwnership},
|
||||
{"SessionExclusion", CheckSessionExclusion},
|
||||
{"SessionRomValidation", CheckSessionRomValidation},
|
||||
{"VideoPixels", CheckVideoPixels},
|
||||
{"VideoModes", CheckVideoModes},
|
||||
{"RasterTiming", CheckRasterTiming},
|
||||
{"RasterPixels", CheckRasterPixels},
|
||||
{"GimeTimers", CheckGimeTimers},
|
||||
{"VideoLifecycle", CheckVideoLifecycle},
|
||||
{"FrameStops", CheckFrameStops},
|
||||
{"MmuMapping", CheckMmuMapping},
|
||||
{"MmuRomAndVectors", CheckMmuRomAndVectors},
|
||||
{"MmuLifecycle", CheckMmuLifecycle},
|
||||
{"GimeRegisters", CheckGimeRegisters},
|
||||
{"PiaRegisters", CheckPiaRegisters},
|
||||
{"PiaInterrupts", CheckPiaInterrupts},
|
||||
{"MappedCpuExecution", CheckMappedCpuExecution},
|
||||
{"6809 execution", Check6809Execution}, {"6309 execution", Check6309Execution},
|
||||
{"6809 interrupts", Check6809Interrupts}, {"6309 interrupts", Check6309Interrupts},
|
||||
{"6309 native mode", Check6309Native}, {"CPU debugger", CheckCpuDebugHooks},
|
||||
{"event scheduler", CheckEventScheduler}, {"RAM disk", CheckRamDisk},
|
||||
{"SSC microcontroller", CheckMicrocontroller}, {"SSC bus", CheckCartridgeBus}
|
||||
};
|
||||
for (const auto& check : checks) {
|
||||
current = check.name;
|
||||
check.run();
|
||||
std::printf("PASS: %s\n", current);
|
||||
}
|
||||
current = "existing SSC suites";
|
||||
if (smoke_cpu() || smoke_sp0256() || smoke_ay8913() || smoke_ssc_core()) return 1;
|
||||
std::printf("All %zu core checks passed.\n", sizeof(checks) / sizeof(checks[0]) + 4);
|
||||
if (argc == 5) { current = "supplied hard disk integration"; CheckHardDiskRom(argv[2], argv[3], argv[4]); }
|
||||
if (argc == 4) { current = "supplied disk ROM integration"; CheckDiskRom(argv[2], argv[3]); }
|
||||
if (argc == 3) { current = "supplied ROM integration"; CheckRomBoot(argv[2]); }
|
||||
return 0;
|
||||
} catch (const std::exception& error) {
|
||||
std::fprintf(stderr, "FAIL [%s]: %s\n", current, error.what());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user