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

View File

@ -102,6 +102,8 @@ if (__traits(compiles, {
} }
bool keepRunning; bool keepRunning;
bool signalActive;
bool resetLow;
final void run(bool continuous) final void run(bool continuous)
{ {
@ -115,25 +117,42 @@ if (__traits(compiles, {
} }
do do
{ {
version(Cumulative) version(Cumulative) { static if (!opArray) cycles = 1; }
{ else { clock.tick(); }
static if (!opArray) cycles = 1; if (signalActive) handleSignals();
}
else
{
clock.tick();
}
// XXX check signals, NMI/IRQ delays, etc.
opcode = memory.read(PC++); opcode = memory.read(PC++);
mixin(OpExecute(_chip)); mixin(OpExecute(_chip));
} while (keepRunning); } 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)); version(OpDelegates) mixin (OpMethods(_chip));
} }
enum ushort IRQ_VECTOR = 0xFFFE; enum ushort IRQ_VECTOR = 0xFFFE;
enum ushort RESET_VECTOR = 0xFFFC;
//alias Cpu!("6502", false, false) T1; //alias Cpu!("6502", false, false) T1;