twoapple-reboot/test/d6502/benchmark.d

70 lines
1.5 KiB
D
Raw Permalink Normal View History

2012-04-17 11:01:58 +00:00
import std.datetime, std.stdio;
import test.d6502.base, test.d6502.cpu;
final class BreakRunner
{
TestMemory* mem;
bool* keepRunning;
this(ref TestMemory mem)
{
this.mem = &mem;
}
2012-04-27 17:09:32 +00:00
final ubyte opIndex(ushort addr)
2012-04-17 11:01:58 +00:00
{
if (addr == 0xfffe)
{
*keepRunning = false;
return 0x00;
}
else if (addr == 0xffff)
{
return 0x80;
}
else return mem.read(addr);
}
2012-04-27 17:09:32 +00:00
final ubyte opIndexAssign(ubyte val, ushort addr)
2012-04-17 11:01:58 +00:00
{
mem.write(addr, val);
2012-04-27 17:09:32 +00:00
return val;
2012-04-17 11:01:58 +00:00
}
static if (cumulative) { final void tick(int) {} }
else { final void tick() {} }
}
void run_benchmark(T)()
if (isCpu!T)
{
auto mem = decimal_test_mem!T();
auto runner = new BreakRunner(mem);
auto cpu = new T(runner, runner);
runner.keepRunning = &cpu.keepRunning;
setPC(cpu, 0x8000);
cpu.run(true);
if (mem[0x8003])
{
// TODO: check data block to find out what failed exactly
throw new TestException("failed decimal mode " ~ T.stringof);
}
}
void main()
{
2012-04-24 20:21:32 +00:00
auto nmosExpected = (61886766.0 / 1020484.0) * 1000;
auto cmosExpected = (64508206.0 / 1020484.0) * 1000;
auto r1 = benchmark!(
run_benchmark!(CPU!("6502", BreakRunner, BreakRunner)))(1);
writeln("NMOS: ", nmosExpected / r1[0].to!("msecs", int));
auto r2 = benchmark!(
2012-04-17 11:01:58 +00:00
run_benchmark!(CPU!("65C02", BreakRunner, BreakRunner)))(1);
2012-04-24 20:21:32 +00:00
writeln("CMOS: ", cmosExpected / r2[0].to!("msecs", int));
2012-04-17 11:01:58 +00:00
}