Add cpu reset.

This commit is contained in:
edmccard 2012-04-14 06:33:56 -04:00
parent 581fe45c89
commit 23b0a96c1c
2 changed files with 37 additions and 18 deletions

View File

@ -495,7 +495,7 @@ string Nop(int mode)
if (mode == IMP || mode == NP1 || mode == NP8)
return "";
else
return PreAccess() ~
return Tick() ~
ReadRaw("address") ~ ";\n";
}
@ -1013,7 +1013,7 @@ string CheckShortcut(string base, string addr, string chip, int exCyc)
string ReadInto(string var, string action, string addr)
{
return PreAccess() ~
return Tick() ~
var ~ " " ~ action ~ " " ~ ReadRaw("(" ~ addr ~ ")") ~ ";\n";
}
@ -1074,27 +1074,27 @@ string ReadWordOp(string var)
return ReadWordOp("", var);
}
string PreAccess()
string Tick()
{
return If!(cumulative)("++cycles;\n", Attr("clock") ~ ".tick();\n");
}
string Peek(string addr)
{
return PreAccess() ~
return Tick() ~
If!(strict)(Attr("memory") ~ ".read(" ~ addr ~");\n");
}
string Poke(string addr, string val)
{
return PreAccess() ~
return Tick() ~
If!(strict)(
Attr("memory") ~ ".write(" ~ addr ~ ", " ~ val ~ ");\n");
}
string Write(string addr, string val)
{
return PreAccess() ~
return Tick() ~
Attr("memory") ~ ".write(" ~ addr ~ ", " ~ val ~ ");\n";
}
@ -1118,7 +1118,7 @@ string PullStatus()
{
return Peek(STACK) ~
IncSP() ~
PreAccess() ~
Tick() ~
Attr("statusFromByte") ~ "(" ~
ReadRaw(STACK) ~ ");\n";
}
@ -1151,13 +1151,13 @@ string PullPC()
string LoadLoByte(string type, string var, string addr)
{
return PreAccess() ~
return Tick() ~
Local(type, var) ~ " = " ~ ReadRaw(addr) ~ ";\n";
}
string LoadHiByte(string var, string addr)
{
return PreAccess() ~
return Tick() ~
var ~ " |= (" ~ ReadRaw(addr) ~ " << 8);\n";
}

View File

@ -102,6 +102,8 @@ if (__traits(compiles, {
}
bool keepRunning;
bool signalActive;
bool resetLow;
final void run(bool continuous)
{
@ -115,25 +117,42 @@ if (__traits(compiles, {
}
do
{
version(Cumulative)
{
static if (!opArray) cycles = 1;
}
else
{
clock.tick();
}
// XXX check signals, NMI/IRQ delays, etc.
version(Cumulative) { static if (!opArray) cycles = 1; }
else { clock.tick(); }
if (signalActive) handleSignals();
opcode = memory.read(PC++);
mixin(OpExecute(_chip));
} while (keepRunning);
}
// TODO: irq/nmi
void handleSignals()
{
if (resetLow) doReset();
// XXX fix when more than one signal
signalActive = resetLow;
}
void doReset()
{
mixin(Tick() ~ Tick() ~
Peek(STACK) ~ DecSP() ~
Peek(STACK) ~ DecSP() ~
Peek(STACK) ~ DecSP());
I = true;
resetLow = false;
mixin(ReadWord(_PC, "RESET_VECTOR") ~
Done());
}
version(OpDelegates) mixin (OpMethods(_chip));
}
enum ushort IRQ_VECTOR = 0xFFFE;
enum ushort RESET_VECTOR = 0xFFFC;
//alias Cpu!("6502", false, false) T1;