Ejemplo n.º 1
0
 protected virtual void InitializeRound()
 {
     core = new EngineInstruction[coreSize];
     for (int a = 0; a < coreSize; a++)
     {
         core[a] = new EngineInstruction(a, null);
     }
 }
Ejemplo n.º 2
0
        protected virtual void InitializeCycle(int Ip)
        {
            ResetCache();
            int nextInstructionAddress = NextInstructionAddress;

            if (nextInstructionAddress != -1)
            {
                lastInstruction = new EngineInstruction(core[nextInstructionAddress], nextInstructionAddress);
            }
        }
 public EngineEvent(EngineInstruction executedInstruction, int cycles, int cyclesLeft, int ip, EngineWarrior warrior, StepResult prevStepResult)
 {
     ExecutedInstruction = executedInstruction;
     Cycles              = cycles;
     CyclesLeft          = cyclesLeft;
     Ip                  = ip;
     Warrior             = warrior;
     PrevStepResult      = prevStepResult;
     instructionsChanged = new Stack <EngineInstruction>();
 }
Ejemplo n.º 4
0
 public EngineInstruction(IInstruction src, int address, IRunningWarrior owner)
 {
     Operation     = src.Operation;
     Modifier      = src.Modifier;
     ModeA         = src.ModeA;
     ValueA        = src.ValueA;
     ModeB         = src.ModeB;
     ValueB        = src.ValueB;
     Address       = address;
     OriginalOwner = owner;
     if (src is EngineInstruction)
     {
         EngineInstruction ei = (EngineInstruction)src;
         OriginalInstruction = ei.OriginalInstruction;
     }
     else
     {
         OriginalInstruction = src;
     }
 }
Ejemplo n.º 5
0
 public EngineInstruction(IInstruction src, int address)
 {
     Operation = src.Operation;
     Modifier  = src.Modifier;
     ModeA     = src.ModeA;
     ValueA    = src.ValueA;
     ModeB     = src.ModeB;
     ValueB    = src.ValueB;
     Address   = address;
     if (src is EngineInstruction)
     {
         EngineInstruction ei = (EngineInstruction)src;
         OriginalInstruction = ei.OriginalInstruction;
         OriginalOwner       = ei.OriginalOwner;
     }
     else
     {
         OriginalInstruction = src;
         OriginalOwner       = null;
     }
 }
Ejemplo n.º 6
0
 private void Load(EngineWarrior warrior)
 {
     //copy warrior to core
     for (int a = 0; a < warrior.Length; a++)
     {
         IInstruction instruction = warrior[a];
         if (instruction.ValueA >= coreSize || instruction.ValueA < 0 ||
             instruction.ValueB >= coreSize || instruction.ValueB < 0)
         {
             throw new RulesException("operand value out of core size");
         }
         if (instruction.Operation == Operation.LDP || instruction.Operation == Operation.STP)
         {
             if (!rules.EnablePSpace)
             {
                 throw new RulesException("Current rules don't support p-space operations");
             }
         }
         int addr = mod(warrior.LoadAddress + a);
         core[addr] = new EngineInstruction(instruction, addr, warrior);
     }
 }
Ejemplo n.º 7
0
 public EngineEvent(EngineInstruction executedInstruction, int cycles, int cyclesLeft, int ip, EngineWarrior warrior, StepResult prevStepResult)
 {
     ExecutedInstruction = executedInstruction;
     Cycles = cycles;
     CyclesLeft = cyclesLeft;
     Ip = ip;
     Warrior = warrior;
     PrevStepResult = prevStepResult;
     instructionsChanged = new Stack<EngineInstruction>();
 }
Ejemplo n.º 8
0
 public virtual IRunningInstruction this[int address]
 {
     get { return(core[mod(address)]); }
     set { core[mod(address)] = new EngineInstruction(value, address); }
 }
Ejemplo n.º 9
0
        public StepResult PrevStep()
        {
            if (!CanStepBack)
            {
                throw new InvalidOperationException("Cannot step back now");
            }
            EngineEvent e = History.Pop();

            cycle      = e.Cycles;
            cyclesLeft = e.CyclesLeft;
            int lastTask      = e.Warrior.Tasks.Count;
            int liveLastRound = liveWarriors.Count;

            if (e.Died)
            {
                lastTask++;
                if (warriors.Count == 0)
                {
                    liveLastRound++;
                }
            }
            if (e.Split)
            {
                lastTask--;
            }

            // refill live warriors queue
            Queue <EngineWarrior> nlive = new Queue <EngineWarrior>();

            nlive.Enqueue(e.Warrior);
            for (int w = 0; w < liveLastRound - 1; w++)
            {
                nlive.Enqueue(liveWarriors.Dequeue());
            }
            liveWarriors = nlive;

            //refill tasks queue
            Queue <int> ntasks = new Queue <int>();

            ntasks.Enqueue(e.Ip);
            for (int t = 0; t < lastTask - 1; t++)
            {
                ntasks.Enqueue(e.Warrior.Tasks.Dequeue());
            }
            e.Warrior.Tasks = ntasks;

            //rollback core
            while (e.instructionsChanged.Count > 0)
            {
                EngineInstruction ei = e.instructionsChanged.Pop();
                core[ei.Address].Operation           = ei.Operation;
                core[ei.Address].Modifier            = ei.Modifier;
                core[ei.Address].ModeA               = ei.ModeA;
                core[ei.Address].ModeB               = ei.ModeB;
                core[ei.Address].ValueA              = ei.ValueA;
                core[ei.Address].ValueB              = ei.ValueB;
                core[ei.Address].OriginalOwner       = ei.OriginalOwner;
                core[ei.Address].OriginalInstruction = ei.OriginalInstruction;

                CoreEventRecord evnt = CoreEvents[ei.Address];
                evnt.Event              = InstructionEvent.None;
                evnt.Cycle              = cycle;
                evnt.Touched            = null;
                evnt.Executed           = null;
                evnt.Read               = null;
                evnt.Died               = null;
                evnt.WrittenData        = null;
                evnt.WrittenInstruction = null;
                evnt.Version            = ++version;
                evnt.Level              = CoreEventsLevel.Clean;
            }

            if (e.PSpaceAddress != -1)
            {
                PSpaces[e.Warrior.WarriorIndex][e.PSpaceAddress] = e.PSpaceValue;
            }

            lastStepResult = e.PrevStepResult;
            return(e.PrevStepResult);
        }
Ejemplo n.º 10
0
        public void Load(EngineWarrior warrior, int loadAddress)
        {
            warrior.LoadAddress = loadAddress;

            //copy warrior to core
            for (int a = 0; a < warrior.Length; a++)
            {
                IInstruction instruction = warrior[a];
                if (instruction.ValueA >= coreSize || instruction.ValueA < 0 ||
                    instruction.ValueB >= coreSize || instruction.ValueB < 0 )
                {
                    throw new RulesException("operand value out of core size");
                }
                if (instruction.Operation == Operation.LDP || instruction.Operation == Operation.STP)
                {
                    if (!rules.EnablePSpace)
                    {
                        throw new RulesException("Current rules don't support p-space operations");
                    }
                }
                int addr = mod(loadAddress + a);
                core[addr] = new EngineInstruction(instruction, addr, warrior);
            }
        }
Ejemplo n.º 11
0
 protected virtual void InitializeRound()
 {
     core = new EngineInstruction[coreSize];
     for (int a = 0; a < coreSize; a++)
     {
         core[a] = new EngineInstruction(a, null);
     }
 }
Ejemplo n.º 12
0
 public virtual IRunningInstruction this[int address]
 {
     get { return core[mod(address)]; }
     set { core[mod(address)] = new EngineInstruction(value, address); }
 }