Undo overeager removal of readFinal/writeFinal

(without the checks for final cycle, they are still needed to know
when to call tick in cumulative mode)
This commit is contained in:
edmccard 2012-04-08 20:17:42 -04:00
parent 59951ede01
commit b0ae43067c
4 changed files with 45 additions and 25 deletions

View File

@ -104,20 +104,20 @@ class Cmos(bool strict, bool cumulative) : Cpu!(strict, cumulative)
static string RMW(string action) static string RMW(string action)
{ {
return "peek(primaryAddress);\n" ~ return "peek(primaryAddress);\n" ~
"write(primaryAddress, (flag.zero_ = flag.negative_ = " ~ "writeFinal(primaryAddress, (flag.zero_ = flag.negative_ = " ~
action ~ "(readVal = read(primaryAddress))));\n"; action ~ "(readVal = read(primaryAddress))));\n";
} }
static string TestModify(string action) static string TestModify(string action)
{ {
return "peek(primaryAddress);\n" ~ return "peek(primaryAddress);\n" ~
"write(primaryAddress, " ~ "writeFinal(primaryAddress, " ~
action ~ "(readVal = read(primaryAddress)));\n"; action ~ "(readVal = read(primaryAddress)));\n";
} }
static string ReadNOP() static string ReadNOP()
{ {
return "readVal = read(primaryAddress);\n"; return "readVal = readFinal(primaryAddress);\n";
} }
static string ManualAddress(string name, int[] opcodes, static string ManualAddress(string name, int[] opcodes,
@ -260,7 +260,7 @@ class Cmos(bool strict, bool cumulative) : Cpu!(strict, cumulative)
/* BIT #$$ */ /* BIT #$$ */
void opcode89() void opcode89()
{ {
readVal = operand1 = read(programCounter++); readVal = operand1 = readFinal(programCounter++);
flag.zero_ = accumulator & readVal; flag.zero_ = accumulator & readVal;
} }
} }

View File

@ -196,6 +196,26 @@ class Cpu(bool strict, bool cumulative) : CpuBase!(strict, cumulative)
static if (strict) memoryWrite(addr, val); static if (strict) memoryWrite(addr, val);
} }
final ubyte readFinal(ushort addr)
{
static if (cumulative) tick(++totalCycles);
else
{
tick();
}
return memoryRead(addr);
}
final void writeFinal(ushort addr, ubyte val)
{
static if (cumulative) tick(++totalCycles);
else
{
tick();
}
memoryWrite(addr, val);
}
final ushort readWord(ushort addrLo, ushort addrHi) final ushort readWord(ushort addrLo, ushort addrHi)
{ {
ushort word = read(addrLo); ushort word = read(addrLo);
@ -564,12 +584,12 @@ class Cpu(bool strict, bool cumulative) : CpuBase!(strict, cumulative)
static string Read(string action) static string Read(string action)
{ {
return UpdateNZ(action ~ " (readVal = read(primaryAddress))"); return UpdateNZ(action ~ " (readVal = readFinal(primaryAddress))");
} }
static string Decimal(string action) static string Decimal(string action)
{ {
string code = action ~ "(readVal = read(primaryAddress));\n"; string code = action ~ "(readVal = readFinal(primaryAddress));\n";
return "if (flag.decimal) dec_" ~ code ~ return "if (flag.decimal) dec_" ~ code ~
"else hex_" ~ code; "else hex_" ~ code;
} }
@ -577,17 +597,17 @@ class Cpu(bool strict, bool cumulative) : CpuBase!(strict, cumulative)
static string Compare(string action) static string Compare(string action)
{ {
return UpdateNZ("compare(" ~ action ~ return UpdateNZ("compare(" ~ action ~
", (readVal = read(primaryAddress)))"); ", (readVal = readFinal(primaryAddress)))");
} }
static string Write(string action) static string Write(string action)
{ {
return "write(primaryAddress, " ~ action ~ ");\n"; return "writeFinal(primaryAddress, " ~ action ~ ");\n";
} }
static string BitTest() static string BitTest()
{ {
return "bitTest(readVal = read(primaryAddress));\n"; return "bitTest(readVal = readFinal(primaryAddress));\n";
} }
mixin(SimpleOpcode("CLC", "18", "flag.carry = false")); mixin(SimpleOpcode("CLC", "18", "flag.carry = false"));

View File

@ -37,7 +37,7 @@ class NmosBase(bool strict, bool cumulative) : Cpu!(strict, cumulative)
static string RMW(string action) static string RMW(string action)
{ {
return "poke(primaryAddress, (readVal = read(primaryAddress)));\n" ~ return "poke(primaryAddress, (readVal = read(primaryAddress)));\n" ~
"write(primaryAddress, flag.zero_ = flag.negative_ = " ~ "writeFinal(primaryAddress, flag.zero_ = flag.negative_ = " ~
action ~ "(readVal));\n"; action ~ "(readVal));\n";
} }

View File

@ -54,12 +54,12 @@ class NmosUndoc(bool strict, bool cumulative) : NmosBase!(strict, cumulative)
val = val & hiAddr; val = val & hiAddr;
ushort addr = (badAddress == primaryAddress) ? primaryAddress : ushort addr = (badAddress == primaryAddress) ? primaryAddress :
((val << 8) | (primaryAddress & 0xFF)); ((val << 8) | (primaryAddress & 0xFF));
write(addr, val); writeFinal(addr, val);
} }
else else
{ {
ubyte hiAddr = cast(ubyte)((baseAddress >> 8) + 1); ubyte hiAddr = cast(ubyte)((baseAddress >> 8) + 1);
write(primaryAddress, val & hiAddr); writeFinal(primaryAddress, val & hiAddr);
} }
} }
@ -122,13 +122,13 @@ class NmosUndoc(bool strict, bool cumulative) : NmosBase!(strict, cumulative)
static string ReadNOP() static string ReadNOP()
{ {
return "readVal = read(primaryAddress);\n"; return "readVal = readFinal(primaryAddress);\n";
} }
static string RMW_Read(string action1, string action2) static string RMW_Read(string action1, string action2)
{ {
return "poke(primaryAddress, (readVal = read(primaryAddress)));\n" ~ return "poke(primaryAddress, (readVal = read(primaryAddress)));\n" ~
"write(primaryAddress, flag.zero_ = flag.negative_ = " ~ "writeFinal(primaryAddress, flag.zero_ = flag.negative_ = " ~
"(writeVal = " ~ action1 ~ "(readVal)));\n" ~ "(writeVal = " ~ action1 ~ "(readVal)));\n" ~
action2 ~ " writeVal;\n"; action2 ~ " writeVal;\n";
} }
@ -136,7 +136,7 @@ class NmosUndoc(bool strict, bool cumulative) : NmosBase!(strict, cumulative)
static string RMW_Compare(string action1, string action2) static string RMW_Compare(string action1, string action2)
{ {
return "poke(primaryAddress, (readVal = read(primaryAddress)));\n" ~ return "poke(primaryAddress, (readVal = read(primaryAddress)));\n" ~
"write(primaryAddress, " ~ "writeFinal(primaryAddress, " ~
"(writeVal = " ~ action1 ~ "(readVal)));\n" ~ "(writeVal = " ~ action1 ~ "(readVal)));\n" ~
"flag.zero_ = flag.negative_ = " ~ "flag.zero_ = flag.negative_ = " ~
"compare(" ~ action2 ~ ", writeVal);\n"; "compare(" ~ action2 ~ ", writeVal);\n";
@ -145,7 +145,7 @@ class NmosUndoc(bool strict, bool cumulative) : NmosBase!(strict, cumulative)
static string RMW_Decimal(string action1, string action2) static string RMW_Decimal(string action1, string action2)
{ {
return "poke(primaryAddress, (readVal = read(primaryAddress)));\n" ~ return "poke(primaryAddress, (readVal = read(primaryAddress)));\n" ~
"write(primaryAddress, flag.zero_ = flag.negative_ = " ~ "writeFinal(primaryAddress, flag.zero_ = flag.negative_ = " ~
"(writeVal = " ~ action1 ~ "(readVal)));\n" ~ "(writeVal = " ~ action1 ~ "(readVal)));\n" ~
"if (flag.decimal) dec_" ~ action2 ~ "(writeVal);\n" ~ "if (flag.decimal) dec_" ~ action2 ~ "(writeVal);\n" ~
"else hex_" ~ action2 ~ "(writeVal);\n"; "else hex_" ~ action2 ~ "(writeVal);\n";
@ -209,7 +209,7 @@ class NmosUndoc(bool strict, bool cumulative) : NmosBase!(strict, cumulative)
/* ANC #$$ */ /* ANC #$$ */
override void opcode0B() override void opcode0B()
{ {
readVal = operand1 = read(programCounter); readVal = operand1 = readFinal(programCounter);
flag.zero_ = flag.negative_ = (accumulator = readVal); flag.zero_ = flag.negative_ = (accumulator = readVal);
flag.carry = (flag.negative_ > 0x7F); flag.carry = (flag.negative_ > 0x7F);
} }
@ -217,7 +217,7 @@ class NmosUndoc(bool strict, bool cumulative) : NmosBase!(strict, cumulative)
/* ANC #$$ */ /* ANC #$$ */
override void opcode2B() override void opcode2B()
{ {
readVal = operand1 = read(programCounter); readVal = operand1 = readFinal(programCounter);
flag.zero_ = flag.negative_ = (accumulator = readVal); flag.zero_ = flag.negative_ = (accumulator = readVal);
flag.carry = (flag.negative_ > 0x7F); flag.carry = (flag.negative_ > 0x7F);
} }
@ -225,7 +225,7 @@ class NmosUndoc(bool strict, bool cumulative) : NmosBase!(strict, cumulative)
/* ALR #$$ */ /* ALR #$$ */
override void opcode4B() override void opcode4B()
{ {
readVal = operand1 = read(programCounter); readVal = operand1 = readFinal(programCounter);
flag.zero_ = flag.negative_ = flag.zero_ = flag.negative_ =
(accumulator = shiftRight(accumulator & readVal)); (accumulator = shiftRight(accumulator & readVal));
} }
@ -233,7 +233,7 @@ class NmosUndoc(bool strict, bool cumulative) : NmosBase!(strict, cumulative)
/* ARR #$$ */ /* ARR #$$ */
override void opcode6B() override void opcode6B()
{ {
readVal = operand1 = read(programCounter); readVal = operand1 = readFinal(programCounter);
ubyte val = readVal & accumulator; ubyte val = readVal & accumulator;
if (flag.decimal) { if (flag.decimal) {
ubyte temp = cast(ubyte)((val >> 1) + (flag.carry ? 0x80 : 0)); ubyte temp = cast(ubyte)((val >> 1) + (flag.carry ? 0x80 : 0));
@ -263,7 +263,7 @@ class NmosUndoc(bool strict, bool cumulative) : NmosBase!(strict, cumulative)
override void opcode8B() override void opcode8B()
{ {
// unstable // unstable
readVal = operand1 = read(programCounter++); readVal = operand1 = readFinal(programCounter++);
version(Atari8Bit) version(Atari8Bit)
{ {
@ -316,7 +316,7 @@ class NmosUndoc(bool strict, bool cumulative) : NmosBase!(strict, cumulative)
/* LAX #$$ */ /* LAX #$$ */
override void opcodeAB() override void opcodeAB()
{ {
readVal = operand1 = read(programCounter); readVal = operand1 = readFinal(programCounter);
version(Commodore128) version(Commodore128)
{ {
@ -341,7 +341,7 @@ class NmosUndoc(bool strict, bool cumulative) : NmosBase!(strict, cumulative)
override void opcodeBB() override void opcodeBB()
{ {
addrAbsoluteY(false); addrAbsoluteY(false);
readVal = read(primaryAddress); readVal = readFinal(primaryAddress);
flag.zero_ = flag.negative_ = flag.zero_ = flag.negative_ =
(xIndex = accumulator = (stackPointer & readVal)); (xIndex = accumulator = (stackPointer & readVal));
@ -350,7 +350,7 @@ class NmosUndoc(bool strict, bool cumulative) : NmosBase!(strict, cumulative)
/* SBX #$$ */ /* SBX #$$ */
override void opcodeCB() override void opcodeCB()
{ {
readVal = operand1 = read(programCounter++); readVal = operand1 = readFinal(programCounter++);
xIndex &= accumulator; xIndex &= accumulator;
flag.zero_ = flag.negative_ = compare(xIndex, readVal); flag.zero_ = flag.negative_ = compare(xIndex, readVal);
} }
@ -358,7 +358,7 @@ class NmosUndoc(bool strict, bool cumulative) : NmosBase!(strict, cumulative)
/* SBC #$$ */ /* SBC #$$ */
override void opcodeEB() override void opcodeEB()
{ {
readVal = operand1 = read(programCounter++); readVal = operand1 = readFinal(programCounter++);
if (flag.decimal) dec_subWithCarry(readVal); if (flag.decimal) dec_subWithCarry(readVal);
else hex_subWithCarry(readVal); else hex_subWithCarry(readVal);
} }