1
0
mirror of https://github.com/livingcomputermuseum/ContrAlto.git synced 2026-04-26 12:08:41 +00:00

Tweaks to ALU, CPU, Memory

This commit is contained in:
Josh Dersch
2015-08-21 17:12:28 -07:00
parent f1ffcb0547
commit 9c3ee3afac
3 changed files with 120 additions and 39 deletions

View File

@@ -14,12 +14,12 @@ namespace Contralto.CPU
{
static ALU()
{
_lastCarry = 0;
_carry = 0;
}
public int Carry
public static int Carry
{
get { return _lastCarry; }
get { return _carry; }
}
public static ushort Execute(AluFunction fn, ushort bus, ushort t)
@@ -28,59 +28,59 @@ namespace Contralto.CPU
switch (fn)
{
case AluFunction.Bus:
_lastCarry = 0; // M = 1
_carry = 0; // M = 1
r = bus;
break;
case AluFunction.T:
_lastCarry = 0; // M = 1
_carry = 0; // M = 1
r= t;
break;
case AluFunction.BusOrT:
_lastCarry = 0; // M = 1
_carry = 0; // M = 1
r = (bus | t);
break;
case AluFunction.BusAndT:
case AluFunction.AluBusAndT:
_lastCarry = 0; // M = 1
_carry = 0; // M = 1
r = (bus & t);
break;
case AluFunction.BusXorT:
_lastCarry = 0; // M = 1
_carry = 0; // M = 1
r = (bus ^ t);
break;
case AluFunction.BusPlus1:
r = bus + 1;
_lastCarry = (r > 0xffff) ? 1 : 0;
_carry = (r > 0xffff) ? 1 : 0;
break;
case AluFunction.BusMinus1:
r = bus - 1;
_lastCarry = (r < 0) ? 1 : 0;
_carry = (r < 0) ? 1 : 0;
break;
case AluFunction.BusPlusT:
r = bus + t;
_lastCarry = (r > 0xffff) ? 1 : 0;
_carry = (r > 0xffff) ? 1 : 0;
break;
case AluFunction.BusMinusT:
r = bus - t;
_lastCarry = (r < 0) ? 1 : 0;
_carry = (r < 0) ? 1 : 0;
break;
case AluFunction.BusMinusTMinus1:
r = bus - t - 1;
_lastCarry = (r < 0) ? 1 : 0;
_carry = (r < 0) ? 1 : 0;
break;
case AluFunction.BusPlusTPlus1:
r = bus + t + 1;
_lastCarry = (r > 0xffff) ? 1 : 0;
_carry = (r > 0xffff) ? 1 : 0;
break;
case AluFunction.BusPlusSkip:
@@ -88,7 +88,7 @@ namespace Contralto.CPU
case AluFunction.BusAndNotT:
r = bus & (~t);
_lastCarry = 0;
_carry = 0;
break;
default:
@@ -98,6 +98,6 @@ namespace Contralto.CPU
return (ushort)r;
}
private static int _lastCarry;
private static int _carry;
}
}

View File

@@ -43,8 +43,6 @@ namespace Contralto.CPU
_currentTask = _nextTask;
_nextTask = null;
// test
_l = ConstantMemory.ConstantROM[0];
}
public void ExecuteNext()
@@ -141,7 +139,20 @@ namespace Contralto.CPU
ushort busData = 0; // from BUS
ushort aluData = 0; // from ALU
bool nextTask = false;
ushort nextModifier = 0; // for branches (OR'd into NEXT field)
ushort nextModifier = 0; // for branches (OR'd into NEXT field)
//
// Wait for memory state machine if a memory operation is requested by this instruction and
// the memory isn't ready yet.
//
if ((instruction.BS == BusSource.ReadMD ||
instruction.F1 == SpecialFunction1.LoadMAR ||
instruction.F2 == SpecialFunction2.StoreMD)
&& !MemoryBus.Ready())
{
// Suspend operation for this cycle.
return false;
}
// Select BUS data.
if (instruction.F1 != SpecialFunction1.Constant &&
@@ -168,6 +179,7 @@ namespace Contralto.CPU
break;
case BusSource.ReadMD:
// TODO: wait for MD if not ready.
busData = MemoryBus.ReadMD();
break;
@@ -301,7 +313,7 @@ namespace Contralto.CPU
break;
case SpecialFunction2.StoreMD:
MemoryBus.StoreMD(busData);
MemoryBus.LoadMD(busData);
break;
case SpecialFunction2.Constant:
@@ -345,7 +357,7 @@ namespace Contralto.CPU
_cpu._l = aluData;
// Save ALUC0 for use in the next ALUCY special function.
_cpu._aluC0 = ALU.Carry;
_cpu._aluC0 = (ushort)ALU.Carry;
}
// Do shifter