public int GetNextInstructionCost(Core core)
 {
     _core = core;
     _mem = core.Data;
     _ip = core.InstructionPointer;
     _instr = _mem[_ip];
     return GetNextInstructionCost();
 }
 public void ExecuteMultiple(Core core, Core target, int numInstructions)
 {
     SetContext(core, target);
     while (numInstructions-- > 0)
     {
         _ip = Execute();
         _instr = _mem[_ip];
     }
     core.InstructionPointer = _ip;
 }
Example #3
0
 public void Compile(Core core)
 {
     foreach (KeyValuePair<byte, Instruction> kv in _memMap)
     {
         byte location = kv.Key;
         Instruction instr = kv.Value;
         core.Memory[location++] = instr.InstructionWord;
         if (instr.HasParam)
             core.Memory[location++] = instr.ParamWord;
     }
 }
Example #4
0
 public bool MatchIdentity(Core core)
 {
     for (byte location = Identity.Min; location < Identity.Max; location++)
     {
         if (_memMap.ContainsKey(location))
         {
             Instruction instr = _memMap[location];
             if (core.Memory[location] != instr.InstructionWord)
                 return false;
         }
     }
     return true;
 }
 public void ConsumeOneEnergy(Core core, Core target)
 {
     //spend this energy!
     SetContext(core, target);
     if(core.Energy > 0)
     {
         core.Charge++;
         core.Energy--;
     }
     if(core.Charge >= GetNextInstructionCost())
     {
         core.InstructionPointer = Execute();
         core.Charge = 0;
     }
 }
Example #6
0
        public StatusFlags GetStatusFlags(Core core)
        {
            StatusFlags flags = StatusFlags.None;
            ushort instr = core.Memory[core.InstructionPointer];
            if ((instr & 0xFE00) == (int)Opcode.ISC)
                flags = StatusFlags.Yellow;
            else if ((instr & 0xFE00) == (int)Opcode.DSC)
                flags = StatusFlags.Yellow;
            else if ((instr & 0xFE00) == (int)Opcode.ISE)
                flags = StatusFlags.Blue;
            else if ((instr & 0xFE00) == (int)Opcode.BST)
                flags = StatusFlags.Green;
            else if ((instr & 0xFE00) == (int)Opcode.WKN)
                flags = StatusFlags.Red;

            return flags;
        }
 public void ConsumeEnergyUntilExecute(Core core, Core target)
 {
     //spend this energy!
     SetContext(core, target);
     int cost = GetNextInstructionCost();
     if (core.Energy > 0)
     {
         int available = core.Energy;
         int needed = Math.Max(1, cost - core.Charge);
         int spent = Math.Min(needed, available);
         core.Charge = (byte)(core.Charge + spent);
         core.Energy = (byte)(core.Energy - spent);
     }
     if (core.Charge >= cost)
     {
         core.InstructionPointer = Execute();
         core.Charge = 0;
     }
 }
Example #8
0
 public Core GetTargetOf(Core core)
 {
     int x, y;
     Indexer<Entry> c = new Indexer<Entry>(_entries, _width, ClampMode.Repeat);
     c.Find(e => e.Core == core, out x, out y);
     switch (core.Target)
     {
         case Core.Focus.Up:
             return c[y - 1, x].Core;
         case Core.Focus.Right:
             return c[y, x + 1].Core;
         case Core.Focus.Down:
             return c[y + 1, x].Core;
         case Core.Focus.Left:
             return c[y, x - 1].Core;
         default:
             return core;
     }
 }
 public void Base64CoreEncoding()
 {
     Core core = new Core();
     string s = core.Encode();
     core.Decode(s);
 }
 public void Execute(Core core, Core target)
 {
     SetContext(core, target);
     core.Charge = 0;
     core.InstructionPointer = Execute();
 }
 private void SetContext(Core core, Core target)
 {
     _core = core;
     _target = target;
     _mem = core.Data;
     _tgt = target.Data;
     _ip = core.InstructionPointer;
     _instr = _mem[_ip];
 }
Example #12
0
 public void RenderBasic(Core core, Color color)
 {
     //Clear
     Graphics gfx = Graphics.FromImage(_bitmap);
     gfx.Clear(Color.Transparent);
     Rectangle r = new Rectangle(0, 0, _baseSrc.Width, _baseSrc.Height);
     Rectangle r2 = r;
     r2.Inflate(-2, -2);
     gfx.FillRectangle(new SolidBrush(color), r2);
     gfx.DrawImage(_baseSrc, r, r, GraphicsUnit.Pixel);
     //Render Memory
     int i = 0;
     for (int y = 0; y < 16; y++)
         for (int x = 0; x < 16; x++)
         {
             int data = core.Memory[i++];
             _bitmap.SetPixel(5 + x * K, y * K + 5, Palette[(data & 0xF000) >> 12]);
             _bitmap.SetPixel(6 + x * K, y * K + 5, Palette[(data & 0xF00) >> 8]);
             _bitmap.SetPixel(5 + x * K, y * K + 6, Palette[(data & 0xF0) >> 4]);
             _bitmap.SetPixel(6 + x * K, y * K + 6, Palette[data & 0xF]);
         }
 }
Example #13
0
 public void Render(Core core, int chargeGoal, StatusFlags status, Color gridColor)
 {
     //Clear
     Graphics gfx = Graphics.FromImage(_bitmap);
     gfx.Clear(Color.Transparent);
     Rectangle r = new Rectangle(0, 0, _lowSrc.Width, _lowSrc.Height);
     Rectangle r2 = r;
     r2.Inflate(-2, -2);
     gfx.FillRectangle(new SolidBrush(gridColor), r2);
     gfx.DrawImage(_lowSrc, r, r, GraphicsUnit.Pixel);
     //Render Memory
     int i = 0;
     for (int y = 0; y < 16; y++)
         for (int x = 0; x < 16; x++)
         {
             int data = core.Memory[i++];
             _bitmap.SetPixel(5 + x * K, y * K + 7, Palette[(data & 0xF000) >> 12]);
             _bitmap.SetPixel(6 + x * K, y * K + 7, Palette[(data & 0xF00) >> 8]);
             _bitmap.SetPixel(5 + x * K, y * K + 8, Palette[(data & 0xF0) >> 4]);
             _bitmap.SetPixel(6 + x * K, y * K + 8, Palette[data & 0xF]);
         }
     //Render Energy-Levels
     RenderVEnergyBar(core.Energy, 0);
     RenderVEnergyBar(core.Shield, 52);
     RenderHEnergyBar(core.Charge, chargeGoal, 53);
     //Render IP
     int px = 5 + K * (core.InstructionPointer % 16);
     int py = 7 + K * (core.InstructionPointer / 16);
     //Color instrColor = Palette[(core.Memory[core.InstructionPointer] & 0xF000) >> 12];
     //Pen pen = new Pen(instrColor);
     Pen pen = new Pen(InstructionFrameColor);
     gfx.DrawRectangle(pen, new Rectangle(px - 1, py - 1, 3, 3));
     //pen = new Pen(Color.FromArgb(32, Color.White));
     //Graphics.FromImage(_bitmap).DrawRectangle(pen, new Rectangle(px - 2, py - 2, 5, 5));
     RenderStatus(status);
 }
Example #14
0
 public void Unload(Core core)
 {
     foreach (KeyValuePair<byte, Instruction> kv in _memMap)
     {
         byte location = kv.Key;
         Instruction instr = kv.Value;
         core.Memory[location++] = 0;
         if (instr.HasParam)
             core.Memory[location++] = 0;
     }
 }