mirror of
https://github.com/TheBozos/VP2S_Recomp.git
synced 2026-12-01 07:38:48 -10:00
- 30ce84 accepts objects on the scratchpad stack. - 1f9130 (sibling of the 1f8aa0 overlap): shared 0x7f0 basis lengths, the object-pair registers for the box-pair test. - mod003 397780 keeps those registers across its virtual calls (spill, restore, moved position row). Co-Authored-By: Claude Opus 5.5 <[email protected]>
66 lines
5.2 KiB
C++
66 lines
5.2 KiB
C++
#include "native_load_progress.h"
|
|
#include "native_seed.h"
|
|
#include "bozo/ee/dispatcher.h"
|
|
#include <cstdio>
|
|
#include <cstring>
|
|
#include <limits>
|
|
#include <source_location>
|
|
#include <vector>
|
|
namespace {
|
|
void check(bool v,std::source_location at=std::source_location::current()){if(!v)throw std::runtime_error("loading assertion at "+std::to_string(at.line()));}
|
|
template<class F>void rejects(F f){bool caught=false;try{f();}catch(const std::exception &){caught=true;}check(caught);}
|
|
struct Host:bozo::ee::Host,vp2s::SeedOwner,vp2s::LoadProgressOwner {
|
|
vp2s::NativeLoadProgress progress;uint32_t seed=1;
|
|
uint32_t bootSeed()const override{return seed;}
|
|
vp2s::NativeLoadProgress &nativeLoadProgress()override{return progress;}
|
|
void libraryCall(bozo::ee::Dispatcher &,R5900Context *,uint32_t)override{throw std::runtime_error("library");}
|
|
void vu0Microprogram(bozo::ee::Dispatcher &,R5900Context *,uint32_t)override{throw std::runtime_error("VU");}
|
|
void ioRead(bozo::ee::Dispatcher &,R5900Context *,uint32_t,uint32_t,uint64_t[2])override{throw std::runtime_error("I/O");}
|
|
void ioWrite(bozo::ee::Dispatcher &,R5900Context *,uint32_t,uint32_t,const uint64_t[2])override{throw std::runtime_error("I/O");}
|
|
void fault(bozo::ee::Dispatcher &,R5900Context *,const std::string &)override{throw std::runtime_error("fault");}
|
|
};
|
|
}
|
|
int main(){try{
|
|
Host host,peer;bozo::ee::Dispatcher d(host),other(peer);auto &rt=d.runtime();std::memset(rt.memory.flat(),0,bozo::kFlatBytes);
|
|
const auto unchanged=std::vector<uint8_t>(rt.memory.flat(),rt.memory.flat()+bozo::kFlatBytes);
|
|
constexpr uint32_t stack=0x1f0000,worker=0x190000,destination=0x200000;
|
|
for(unsigned i=0;i<256;++i){
|
|
const uint64_t now=1000ull*i,period=1+i;auto &p=host.progress;
|
|
p.begin(&rt,stack,worker,destination,now,period);check(p.pendingCount()==1 && peer.progress.pendingCount()==0);
|
|
rejects([&]{p.begin(&rt,stack,worker,destination,now,period);});
|
|
check(!p.updateDue(&rt,stack,worker,destination,now+period-1));
|
|
rejects([&]{p.updateDue(&rt,stack,worker+4,destination,now+period);});
|
|
rejects([&]{p.updateDue(&rt,stack,worker,destination+128,now+period);});
|
|
check(p.updateDue(&rt,stack,worker,destination,now+period));check(!p.updateDue(&rt,stack,worker,destination,now+period));
|
|
rejects([&]{p.updateDue(&rt,stack,worker,destination,now);});
|
|
rejects([&]{p.finish(stack,worker,destination,false);});check(p.pendingCount()==1);
|
|
rejects([&]{p.finish(stack,worker+4,destination,true);});check(p.pendingCount()==1);
|
|
check(p.updateDue(&rt,stack,worker,destination,now+2*period));p.finish(stack,worker,destination,true);check(p.pendingCount()==0);
|
|
}
|
|
check(!std::memcmp(unchanged.data(),rt.memory.flat(),unchanged.size()));
|
|
rejects([&]{host.progress.begin(&rt,stack,worker,destination,0,0);});
|
|
rejects([&]{host.progress.begin(&rt,stack,worker,destination+4,0,10);});
|
|
rejects([&]{host.progress.begin(&rt,stack,worker,destination,std::numeric_limits<uint64_t>::max()-1,10);});
|
|
const uint32_t gameState=0x12345678;std::memcpy(rt.memory.ram()+0x35da00,&gameState,4);std::memcpy(other.runtime().memory.ram()+0x35da00,&gameState,4);
|
|
const auto allocationRam=std::vector<uint8_t>(rt.memory.flat(),rt.memory.flat()+bozo::kFlatBytes);
|
|
uint32_t choices=0;
|
|
for(unsigned i=0;i<1024;++i){R5900Context a{},b{};std::memset(a.r,0x71,sizeof(a.r));a.r[16].uw[0]=gameState;b=a;
|
|
const auto before=a;check(vp2s::nativeLoadProgressInstruction(&a,&rt,0x306a10)==true);
|
|
check(vp2s::nativeLoadProgressInstruction(&b,&other.runtime(),0x306a10)==true);check(a.r[17].ud[0]==b.r[17].ud[0] && a.r[17].ud[0]<16);
|
|
choices|=1u<<a.r[17].uw[0];a.r[17]=before.r[17];check(!std::memcmp(&a,&before,sizeof(a)));
|
|
}
|
|
check(choices==0xffff);choices=0;
|
|
for(unsigned i=0;i<1024;++i){R5900Context a{},b{};std::memset(a.r,0x73,sizeof(a.r));const uint32_t base=(i&2?0x70003dd0:0x1c0000)+4*(i&1);a.r[16].uw[0]=base;b=a;
|
|
const auto before=a;check(vp2s::nativeLoadProgressInstruction(&a,&rt,0x30ce84)==true);
|
|
check(vp2s::nativeLoadProgressInstruction(&b,&other.runtime(),0x30ce84)==true);const auto address=a.r[2].uw[0];
|
|
check(address==b.r[2].uw[0] && address>=base && address+0x78<=base+0x188 && (address-base)%16==0 && address-base<=0xf0);
|
|
choices|=1u<<((address-base)/16);a.r[2]=before.r[2];check(!std::memcmp(&a,&before,sizeof(a)));
|
|
}
|
|
check(choices==0xffff);R5900Context c{};rejects([&]{vp2s::nativeLoadProgressInstruction(&c,&rt,0x306a10);});
|
|
rejects([&]{vp2s::nativeLoadProgressInstruction(&c,&rt,0x30ce84);});
|
|
c.r[16].uw[0]=0x70003f00;rejects([&]{vp2s::nativeLoadProgressInstruction(&c,&rt,0x30ce84);}); // past the scratchpad
|
|
c.r[16].uw[0]=0x1ffff00;rejects([&]{vp2s::nativeLoadProgressInstruction(&c,&rt,0x30ce84);}); // past EE RAM
|
|
check(!std::memcmp(allocationRam.data(),rt.memory.flat(),allocationRam.size()));
|
|
std::puts("256 native loading schedule lifetimes and2048 deterministic allocation/record placements: no RAM/device writes, actual-completion requirement, cadence, ownership, isolation and invalid states passed");return 0;
|
|
}catch(const std::exception &e){std::fprintf(stderr,"%s\n",e.what());return 1;}}
|