mirror of
https://github.com/edmccard/twoapple-reboot.git
synced 2024-12-21 04:29:56 +00:00
Changed from version to static if for strict/cumulative
This commit is contained in:
parent
ea1e8f192e
commit
4b27ddbe75
@ -1,4 +1,4 @@
|
||||
COMPILE_OPTS = -c -version=CycleAccuracy -op -Jdata -I$(GTKD)/src \
|
||||
COMPILE_OPTS = -c -op -Jdata -I$(GTKD)/src \
|
||||
-I$(GTKD)/srcgl -I$(DERELICT)/import
|
||||
|
||||
LINK_OPTS = -L-lpthread -L-lGL -L-ldl -L-lX11 \
|
||||
|
@ -22,6 +22,16 @@
|
||||
|
||||
module d6502.base;
|
||||
|
||||
enum Strict : bool
|
||||
{
|
||||
no, yes
|
||||
}
|
||||
|
||||
enum Cumulative : bool
|
||||
{
|
||||
no, yes
|
||||
}
|
||||
|
||||
string hexByte(int decByte)
|
||||
{
|
||||
int highNybble = (decByte & 0xF0) >> 4;
|
||||
@ -60,8 +70,12 @@ final class StatusRegister
|
||||
}
|
||||
}
|
||||
|
||||
class CpuBase
|
||||
class CpuBase(bool strict, bool cumulative)
|
||||
{
|
||||
enum _isCpuBase = true;
|
||||
static if (strict) enum _isStrict = true;
|
||||
static if (cumulative) enum _isCumulative = true;
|
||||
|
||||
static string AbstractOpcodes()
|
||||
{
|
||||
string abstractOpcodes;
|
||||
@ -127,12 +141,12 @@ class CpuBase
|
||||
{
|
||||
string delegate(ushort addr) memoryName;
|
||||
}
|
||||
version(CycleAccuracy) void delegate() tick;
|
||||
version(CumulativeCycles) void delegate(int cycles) ticks;
|
||||
static if (cumulative) void delegate(int cycles) tick;
|
||||
else void delegate() tick;
|
||||
|
||||
abstract void run(bool continuous);
|
||||
abstract void stop();
|
||||
version(CycleAccuracy) abstract bool checkFinalCycle();
|
||||
static if (!cumulative) abstract bool checkFinalCycle();
|
||||
abstract void resetLow();
|
||||
abstract void nmiLow(bool signalLow);
|
||||
abstract void irqLow(bool signalLow);
|
||||
|
@ -25,8 +25,10 @@ module d6502.cmos;
|
||||
import d6502.base;
|
||||
import d6502.cpu;
|
||||
|
||||
class Cmos : Cpu
|
||||
class Cmos(bool strict, bool cumulative) : Cpu!(strict, cumulative)
|
||||
{
|
||||
enum _isCMOS = true;
|
||||
|
||||
this()
|
||||
{
|
||||
super();
|
||||
@ -80,7 +82,7 @@ class Cmos : Cpu
|
||||
|
||||
final void addrNone()
|
||||
{
|
||||
version(CumulativeCycles) ticks(totalCycles);
|
||||
static if (cumulative) tick(totalCycles);
|
||||
}
|
||||
|
||||
final ubyte testSet(ubyte val)
|
||||
@ -230,7 +232,7 @@ class Cmos : Cpu
|
||||
ushort vector = readWordOperand();
|
||||
peek(programCounter);
|
||||
programCounter = readWord(vector, cast(ushort)(vector + 1));
|
||||
version(CumulativeCycles) ticks(totalCycles);
|
||||
static if (cumulative) tick(totalCycles);
|
||||
}
|
||||
|
||||
/* JMP ($$$$,X) */
|
||||
@ -240,7 +242,7 @@ class Cmos : Cpu
|
||||
peek(programCounter);
|
||||
ushort vector = cast(ushort)(baseAddress + xIndex);
|
||||
programCounter = readWord(vector, cast(ushort)(vector + 1));
|
||||
version(CumulativeCycles) ticks(totalCycles);
|
||||
static if (cumulative) tick(totalCycles);
|
||||
}
|
||||
|
||||
/* BIT #$$ */
|
||||
|
@ -24,7 +24,7 @@ module d6502.cpu;
|
||||
|
||||
import d6502.base;
|
||||
|
||||
class Cpu : CpuBase
|
||||
class Cpu(bool strict, bool cumulative) : CpuBase!(strict, cumulative)
|
||||
{
|
||||
static string InitOpcodes()
|
||||
{
|
||||
@ -50,8 +50,9 @@ class Cpu : CpuBase
|
||||
|
||||
void delegate()[256] opcodes;
|
||||
bool continueExecution;
|
||||
version(CycleAccuracy) bool finalCycle;
|
||||
version(CumulativeCycles) int totalCycles;
|
||||
static if (cumulative) int totalCycles;
|
||||
else bool finalCycle;
|
||||
|
||||
|
||||
debug(disassemble)
|
||||
{
|
||||
@ -61,7 +62,7 @@ class Cpu : CpuBase
|
||||
final override void run(bool continuous)
|
||||
{
|
||||
assert ((memoryRead !is null) && (memoryWrite !is null));
|
||||
version(CycleAccuracy) assert (tick !is null);
|
||||
assert (tick !is null);
|
||||
|
||||
continueExecution = continuous;
|
||||
do
|
||||
@ -70,8 +71,8 @@ class Cpu : CpuBase
|
||||
|
||||
opcodePC = programCounter;
|
||||
opcode = read(programCounter++);
|
||||
version(CycleAccuracy) finalCycle = false;
|
||||
version(CumulativeCycles) totalCycles = 0;
|
||||
static if (cumulative) totalCycles = 0;
|
||||
else finalCycle = false;
|
||||
|
||||
/+ TODO: call sync delegate +/
|
||||
|
||||
@ -89,7 +90,7 @@ class Cpu : CpuBase
|
||||
continueExecution = false;
|
||||
}
|
||||
|
||||
version(CycleAccuracy)
|
||||
static if (!cumulative)
|
||||
{
|
||||
final override bool checkFinalCycle()
|
||||
{
|
||||
@ -148,19 +149,19 @@ class Cpu : CpuBase
|
||||
push(statusByte);
|
||||
flag.interrupt = true;
|
||||
programCounter = readWord(vector, cast(ushort)(vector + 1));
|
||||
version(CumulativeCycles) ticks(totalCycles);
|
||||
static if (cumulative) tick(totalCycles);
|
||||
}
|
||||
|
||||
void doReset()
|
||||
{
|
||||
version(CycleAccuracy)
|
||||
{
|
||||
tick(); tick();
|
||||
}
|
||||
version(CumulativeCycles)
|
||||
static if (cumulative)
|
||||
{
|
||||
totalCycles += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
tick(); tick();
|
||||
}
|
||||
|
||||
peek(STACK_BASE + stackPointer);
|
||||
--stackPointer;
|
||||
@ -174,56 +175,56 @@ class Cpu : CpuBase
|
||||
signalActive = testSignals();
|
||||
|
||||
programCounter = readWord(RESET_VECTOR, RESET_VECTOR + 1);
|
||||
version(CumulativeCycles) ticks(totalCycles);
|
||||
static if (cumulative) tick(totalCycles);
|
||||
}
|
||||
|
||||
final ubyte read(ushort addr)
|
||||
{
|
||||
version(CycleAccuracy) tick();
|
||||
version(CumulativeCycles) ++totalCycles;
|
||||
static if (cumulative) ++totalCycles;
|
||||
else tick();
|
||||
return memoryRead(addr);
|
||||
}
|
||||
|
||||
final void write(ushort addr, ubyte val)
|
||||
{
|
||||
version(CycleAccuracy) tick();
|
||||
version(CumulativeCycles) ++totalCycles;
|
||||
static if (cumulative) ++totalCycles;
|
||||
else tick();
|
||||
memoryWrite(addr, val);
|
||||
}
|
||||
|
||||
final void peek(ushort addr)
|
||||
{
|
||||
version(CycleAccuracy) tick();
|
||||
version(CumulativeCycles) ++totalCycles;
|
||||
version(StrictMemoryAccess) memoryRead(addr);
|
||||
static if (cumulative) ++totalCycles;
|
||||
else tick();
|
||||
static if (strict) memoryRead(addr);
|
||||
}
|
||||
|
||||
final void poke(ushort addr, ubyte val)
|
||||
{
|
||||
version(CycleAccuracy) tick();
|
||||
version(CumulativeCycles) ++totalCycles;
|
||||
version(StrictMemoryAccess) memoryWrite(addr, val);
|
||||
static if (cumulative) ++totalCycles;
|
||||
else tick();
|
||||
static if (strict) memoryWrite(addr, val);
|
||||
}
|
||||
|
||||
final ubyte readFinal(ushort addr)
|
||||
{
|
||||
version(CycleAccuracy)
|
||||
static if (cumulative) tick(++totalCycles);
|
||||
else
|
||||
{
|
||||
finalCycle = true;
|
||||
tick();
|
||||
}
|
||||
version(CumulativeCycles) ticks(++totalCycles);
|
||||
return memoryRead(addr);
|
||||
}
|
||||
|
||||
final void writeFinal(ushort addr, ubyte val)
|
||||
{
|
||||
version(CycleAccuracy)
|
||||
static if (cumulative) tick(++totalCycles);
|
||||
else
|
||||
{
|
||||
finalCycle = true;
|
||||
tick();
|
||||
}
|
||||
version(CumulativeCycles) ticks(++totalCycles);
|
||||
memoryWrite(addr, val);
|
||||
}
|
||||
|
||||
@ -467,7 +468,7 @@ class Cpu : CpuBase
|
||||
static string SimpleOpcode(string name, string opcode, string action)
|
||||
{
|
||||
string code = "peek(programCounter);\n";
|
||||
version(CumulativeCycles) code ~= "ticks(totalCycles);\n";
|
||||
static if (cumulative) code ~= "tick(totalCycles);\n";
|
||||
code ~= (action == "") ? "" : (action ~ ";");
|
||||
return "override void opcode" ~ opcode ~ "()\n{\n" ~ code ~ "\n}\n";
|
||||
}
|
||||
@ -480,7 +481,7 @@ class Cpu : CpuBase
|
||||
static string RegisterOpcode(string name, string opcode, string action)
|
||||
{
|
||||
string code = "peek(programCounter);\n";
|
||||
version(CumulativeCycles) code ~= "ticks(totalCycles);\n";
|
||||
static if (cumulative) code ~= "tick(totalCycles);\n";
|
||||
return "override void opcode" ~ opcode ~ "()\n{\n" ~
|
||||
code ~ UpdateNZ(action) ~ "}\n";
|
||||
}
|
||||
@ -489,7 +490,7 @@ class Cpu : CpuBase
|
||||
{
|
||||
string code = "readByteOperand();\n" ~
|
||||
"if (" ~ action ~ ") addrRelative(cast(byte)operand1);\n";
|
||||
version(CumulativeCycles) code ~= "ticks(totalCycles);\n";
|
||||
static if (cumulative) code ~= "tick(totalCycles);\n";
|
||||
return "override void opcode" ~ opcode ~ "()\n{\n" ~ code ~ "}\n";
|
||||
}
|
||||
|
||||
@ -726,7 +727,7 @@ class Cpu : CpuBase
|
||||
pushWord(programCounter);
|
||||
|
||||
finalAddress |= ((operand2 = read(programCounter)) << 8);
|
||||
version(CumulativeCycles) ticks(totalCycles);
|
||||
static if (cumulative) tick(totalCycles);
|
||||
programCounter = finalAddress;
|
||||
}
|
||||
|
||||
@ -736,14 +737,14 @@ class Cpu : CpuBase
|
||||
peek(programCounter);
|
||||
flag.fromByte(pull());
|
||||
programCounter = pullWord();
|
||||
version(CumulativeCycles) ticks(totalCycles);
|
||||
static if (cumulative) tick(totalCycles);
|
||||
}
|
||||
|
||||
/* JMP $$$$ */
|
||||
final override void opcode4C()
|
||||
{
|
||||
programCounter = readWordOperand();
|
||||
version(CumulativeCycles) ticks(totalCycles);
|
||||
static if (cumulative) tick(totalCycles);
|
||||
}
|
||||
|
||||
/* RTS */
|
||||
@ -752,7 +753,7 @@ class Cpu : CpuBase
|
||||
peek(programCounter);
|
||||
programCounter = pullWord();
|
||||
peek(programCounter);
|
||||
version(CumulativeCycles) ticks(totalCycles);
|
||||
static if (cumulative) tick(totalCycles);
|
||||
++programCounter;
|
||||
}
|
||||
}
|
||||
|
@ -24,8 +24,10 @@ module d6502.nmosbase;
|
||||
|
||||
import d6502.cpu;
|
||||
|
||||
class NmosBase : Cpu
|
||||
class NmosBase(bool strict, bool cumulative) : Cpu!(strict, cumulative)
|
||||
{
|
||||
enum _isNMOS = true;
|
||||
|
||||
this()
|
||||
{
|
||||
super();
|
||||
@ -64,6 +66,6 @@ class NmosBase : Cpu
|
||||
ushort vector = readWordOperand();
|
||||
programCounter = readWord(vector,
|
||||
(vector & 0xFF00) | cast(ubyte)(vector + 1));
|
||||
version(CumulativeCycles) ticks(totalCycles);
|
||||
static if (cumulative) tick(totalCycles);
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ module d6502.nmosundoc;
|
||||
import d6502.base;
|
||||
import d6502.nmosbase;
|
||||
|
||||
class NmosUndoc : NmosBase
|
||||
class NmosUndoc(bool strict, bool cumulative) : NmosBase!(strict, cumulative)
|
||||
{
|
||||
this()
|
||||
{
|
||||
@ -36,7 +36,7 @@ class NmosUndoc : NmosBase
|
||||
final void addrImplied()
|
||||
{
|
||||
peek(programCounter);
|
||||
version(CumulativeCycles) ticks(totalCycles);
|
||||
static if (cumulative) tick(totalCycles);
|
||||
}
|
||||
|
||||
final void strange(ubyte val)
|
||||
|
@ -26,6 +26,8 @@ import timer;
|
||||
import memory;
|
||||
import d6502.base;
|
||||
|
||||
private alias d6502.base.CpuBase!(Strict.no, Cumulative.no) CpuBase;
|
||||
|
||||
import ui.sound;
|
||||
import ui.inputevents;
|
||||
|
||||
@ -195,7 +197,7 @@ class II : System
|
||||
|
||||
CpuBase newCpu()
|
||||
{
|
||||
return new NmosUndoc();
|
||||
return new NmosUndoc!(Strict.no, Cumulative.no)();
|
||||
}
|
||||
|
||||
IO newIO()
|
||||
@ -254,7 +256,7 @@ class IIe : System
|
||||
CpuBase newCpu()
|
||||
{
|
||||
// XXX this is enhanced
|
||||
return new Cmos();
|
||||
return new Cmos!(Strict.no, Cumulative.no)();
|
||||
}
|
||||
|
||||
IO newIO()
|
||||
|
@ -25,6 +25,8 @@ module system.peripheral;
|
||||
import memory;
|
||||
import d6502.base;
|
||||
|
||||
private alias d6502.base.CpuBase!(Strict.no, Cumulative.no) CpuBase;
|
||||
|
||||
import peripheral.base;
|
||||
import peripheral.diskii;
|
||||
import peripheral.langcard;
|
||||
|
Loading…
Reference in New Issue
Block a user