opindex interface to memory

This commit is contained in:
edmccard 2012-04-27 13:09:32 -04:00
parent 9691526fc1
commit aa55b972e0
4 changed files with 23 additions and 12 deletions

View File

@ -1053,7 +1053,7 @@ string ReadOp(string var)
string ReadRaw(string addr)
{
return Attr("memory") ~ ".read(" ~ addr ~")";
return Attr("memory") ~ "[" ~ addr ~"]";
}
string ReadWordBasic(string type, string var, string addr1, string addr2)
@ -1106,20 +1106,20 @@ string Tick()
string Peek(string addr)
{
return Tick() ~
If!(strict)(Attr("memory") ~ ".read(" ~ addr ~");\n");
If!(strict)(Attr("memory") ~ "[" ~ addr ~ "];\n");
}
string Poke(string addr, string val)
{
return Tick() ~
If!(strict)(
Attr("memory") ~ ".write(" ~ addr ~ ", " ~ val ~ ");\n");
Attr("memory") ~ "[" ~ addr ~ "] = " ~ val ~ ";\n");
}
string Write(string addr, string val)
{
return Tick() ~
Attr("memory") ~ ".write(" ~ addr ~ ", " ~ val ~ ");\n";
Attr("memory") ~ "[" ~ addr ~ "] = " ~ val ~ ";\n";
}
string IncPC()

View File

@ -81,8 +81,8 @@ public:
final class Cpu(string chip, MEM, CLK)
if (__traits(compiles, {
MEM m; ubyte val; ushort addr;
val = m.read(addr);
m.write(addr, val);
val = m[addr];
m[addr] = val;
CLK c; int cycles;
version(Cumulative) c.tick(cycles);
else c.tick();
@ -166,7 +166,7 @@ if (__traits(compiles, {
static if (_chip == "6502") { idelay = ndelay = false; }
version(Cumulative) { cycles = 1; }
else { clock.tick(); }
opcode = memory.read(PC++);
opcode = memory[PC++];
mixin(OpExecute(_chip));
} while (keepRunning);
}

View File

@ -13,7 +13,7 @@ final class BreakRunner
this.mem = &mem;
}
final ubyte read(ushort addr)
final ubyte opIndex(ushort addr)
{
if (addr == 0xfffe)
{
@ -27,9 +27,10 @@ final class BreakRunner
else return mem.read(addr);
}
final void write(ushort addr, ubyte val)
final ubyte opIndexAssign(ubyte val, ushort addr)
{
mem.write(addr, val);
return val;
}
static if (cumulative) { final void tick(int) {} }

View File

@ -35,10 +35,7 @@ template isCMOS(T)
class TestIO
{
ubyte delegate(ushort) dread;
ubyte read(ushort addr) { return dread(addr); }
void delegate(ushort, ubyte) dwrite;
void write(ushort addr, ubyte val) { dwrite(addr, val); }
static if (cumulative)
{
@ -50,6 +47,19 @@ class TestIO
void delegate() dtick;
void tick() { dtick(); }
}
ubyte opIndex(ushort i1) const
{
auto addr = cast(ushort)i1;
return dread(addr);
}
ubyte opIndexAssign(ubyte val, ushort i1)
{
auto addr = cast(ushort)i1;
dwrite(addr, val);
return val;
}
}