Remove unneeded final cycle checks

This commit is contained in:
Ed McCardell 2012-04-08 17:01:38 -04:00
parent 8f16b62db6
commit 59951ede01
7 changed files with 26 additions and 62 deletions

View File

@ -146,7 +146,6 @@ class CpuBase(bool strict, bool cumulative)
abstract void run(bool continuous); abstract void run(bool continuous);
abstract void stop(); abstract void stop();
static if (!cumulative) abstract bool checkFinalCycle();
abstract void resetLow(); abstract void resetLow();
abstract void nmiLow(bool signalLow); abstract void nmiLow(bool signalLow);
abstract void irqLow(bool signalLow); abstract void irqLow(bool signalLow);

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" ~
"writeFinal(primaryAddress, (flag.zero_ = flag.negative_ = " ~ "write(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" ~
"writeFinal(primaryAddress, " ~ "write(primaryAddress, " ~
action ~ "(readVal = read(primaryAddress)));\n"; action ~ "(readVal = read(primaryAddress)));\n";
} }
static string ReadNOP() static string ReadNOP()
{ {
return "readVal = readFinal(primaryAddress);\n"; return "readVal = read(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 = readFinal(programCounter++); readVal = operand1 = read(programCounter++);
flag.zero_ = accumulator & readVal; flag.zero_ = accumulator & readVal;
} }
} }

View File

@ -51,7 +51,6 @@ class Cpu(bool strict, bool cumulative) : CpuBase!(strict, cumulative)
void delegate()[256] opcodes; void delegate()[256] opcodes;
bool continueExecution; bool continueExecution;
static if (cumulative) int totalCycles; static if (cumulative) int totalCycles;
else bool finalCycle;
debug(disassemble) debug(disassemble)
@ -70,7 +69,6 @@ class Cpu(bool strict, bool cumulative) : CpuBase!(strict, cumulative)
if (signalActive) handleSignals(); if (signalActive) handleSignals();
static if (cumulative) totalCycles = 0; static if (cumulative) totalCycles = 0;
else finalCycle = false;
opcodePC = programCounter; opcodePC = programCounter;
opcode = read(programCounter++); opcode = read(programCounter++);
@ -90,14 +88,6 @@ class Cpu(bool strict, bool cumulative) : CpuBase!(strict, cumulative)
continueExecution = false; continueExecution = false;
} }
static if (!cumulative)
{
final override bool checkFinalCycle()
{
return finalCycle;
}
}
final override void resetLow() final override void resetLow()
{ {
resetActive = signalActive = true; resetActive = signalActive = true;
@ -206,28 +196,6 @@ 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
{
finalCycle = true;
tick();
}
return memoryRead(addr);
}
final void writeFinal(ushort addr, ubyte val)
{
static if (cumulative) tick(++totalCycles);
else
{
finalCycle = true;
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);
@ -596,12 +564,12 @@ class Cpu(bool strict, bool cumulative) : CpuBase!(strict, cumulative)
static string Read(string action) static string Read(string action)
{ {
return UpdateNZ(action ~ " (readVal = readFinal(primaryAddress))"); return UpdateNZ(action ~ " (readVal = read(primaryAddress))");
} }
static string Decimal(string action) static string Decimal(string action)
{ {
string code = action ~ "(readVal = readFinal(primaryAddress));\n"; string code = action ~ "(readVal = read(primaryAddress));\n";
return "if (flag.decimal) dec_" ~ code ~ return "if (flag.decimal) dec_" ~ code ~
"else hex_" ~ code; "else hex_" ~ code;
} }
@ -609,17 +577,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 = readFinal(primaryAddress)))"); ", (readVal = read(primaryAddress)))");
} }
static string Write(string action) static string Write(string action)
{ {
return "writeFinal(primaryAddress, " ~ action ~ ");\n"; return "write(primaryAddress, " ~ action ~ ");\n";
} }
static string BitTest() static string BitTest()
{ {
return "bitTest(readVal = readFinal(primaryAddress));\n"; return "bitTest(readVal = read(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" ~
"writeFinal(primaryAddress, flag.zero_ = flag.negative_ = " ~ "write(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));
writeFinal(addr, val); write(addr, val);
} }
else else
{ {
ubyte hiAddr = cast(ubyte)((baseAddress >> 8) + 1); ubyte hiAddr = cast(ubyte)((baseAddress >> 8) + 1);
writeFinal(primaryAddress, val & hiAddr); write(primaryAddress, val & hiAddr);
} }
} }
@ -122,13 +122,13 @@ class NmosUndoc(bool strict, bool cumulative) : NmosBase!(strict, cumulative)
static string ReadNOP() static string ReadNOP()
{ {
return "readVal = readFinal(primaryAddress);\n"; return "readVal = read(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" ~
"writeFinal(primaryAddress, flag.zero_ = flag.negative_ = " ~ "write(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" ~
"writeFinal(primaryAddress, " ~ "write(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" ~
"writeFinal(primaryAddress, flag.zero_ = flag.negative_ = " ~ "write(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 = readFinal(programCounter); readVal = operand1 = read(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 = readFinal(programCounter); readVal = operand1 = read(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 = readFinal(programCounter); readVal = operand1 = read(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 = readFinal(programCounter); readVal = operand1 = read(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 = readFinal(programCounter++); readVal = operand1 = read(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 = readFinal(programCounter); readVal = operand1 = read(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 = readFinal(primaryAddress); readVal = read(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 = readFinal(programCounter++); readVal = operand1 = read(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 = readFinal(programCounter++); readVal = operand1 = read(programCounter++);
if (flag.decimal) dec_subWithCarry(readVal); if (flag.decimal) dec_subWithCarry(readVal);
else hex_subWithCarry(readVal); else hex_subWithCarry(readVal);
} }

View File

@ -105,7 +105,6 @@ class Controller : Peripheral
int activeDrive; int activeDrive;
bool writeMode; bool writeMode;
bool loadRegister; bool loadRegister;
bool delegate() checkFinalCycle;
ubyte dataLatch; ubyte dataLatch;
bool isOn; bool isOn;
StopTimer drivesOffDelay; StopTimer drivesOffDelay;
@ -201,7 +200,7 @@ class Controller : Peripheral
ubyte Q6L() ubyte Q6L()
{ {
loadRegister = false; loadRegister = false;
if (isOn && checkFinalCycle()) if (isOn)
{ {
if (writeMode) if (writeMode)
{ {

View File

@ -62,7 +62,6 @@ class Peripherals_II : Peripherals
void install(CpuBase cpu, AddressDecoder decoder, Rom mainRom) void install(CpuBase cpu, AddressDecoder decoder, Rom mainRom)
{ {
auto diskController = new Controller(); auto diskController = new Controller();
diskController.checkFinalCycle = &cpu.checkFinalCycle;
cards[6] = diskController; // XXX cards[6] = diskController; // XXX
auto langCard = new LanguageCard(); auto langCard = new LanguageCard();
@ -82,7 +81,6 @@ class Peripherals_IIe : Peripherals
void install(CpuBase cpu, AddressDecoder decoder, Rom mainRom) void install(CpuBase cpu, AddressDecoder decoder, Rom mainRom)
{ {
auto diskController = new Controller(); auto diskController = new Controller();
diskController.checkFinalCycle = &cpu.checkFinalCycle;
cards[6] = diskController; // XXX cards[6] = diskController; // XXX
} }
} }