Пример #1
0
 private void opJSR(operand a)
 {
     ushort _a = readValue(a);
     stackPUSH(_PC);
     _PC = _a;
 }
Пример #2
0
 private void opXOR(operand b, operand a)
 {
     ushort _a = readValue(a);
     ushort _b = readValue(b);
     writeValue(b,(ushort)(_b ^ _a));
 }
Пример #3
0
 public void Tick()
 {
     _Cycles++;
     foreach (Ie16Hardware hw in _Hardware)
     {
         hw.Tick();
     }
     if (--_CycleDebt == 0)
     {
         _CycleDebt--;
         return;
     }
     if (_IntEnabled && _IntQueue.Count > 0)
     {
         stackPUSH(_PC);
         stackPUSH(_A);
         _PC = _IA;
         _Register[_A] = _IntQueue.Dequeue();
         _IntEnabled = false;
     }
     if(_state == ProcessorState.newInst)
     {
         Tick_inst = nextWord();
         Tick_opcode = (ushort)(Tick_inst & (ushort)0x001fu);
         Tick_b = (ushort)((Tick_inst & (ushort)0x03e0u) >> 5);
         Tick_a = (ushort)((Tick_inst & (ushort)0xfc00u) >> 10);
         _state = ProcessorState.readOpA;
         _CycleDebt = operandCycles(Tick_a);
         if (_CycleDebt > 0) return;
     }
     if(_state == ProcessorState.readOpA)
     {
         Tick_opA = parseOperand(Tick_a);
         if (Tick_opcode == 0) // Non-basic opcodes
         {
             _state = ProcessorState.executeInst;
         }
         else
         {
             _CycleDebt = operandCycles(Tick_b);
             _state = ProcessorState.readOpB;
         }
         if(_CycleDebt > 0) return;
     }
     if(_state == ProcessorState.readOpB)
     {
         Tick_opB = parseOperand(Tick_b);
         _state = ProcessorState.executeInst;
         _CycleDebt = opcodeCycles(Tick_a, Tick_opcode);
         if(_CycleDebt > 0) return;
     }
     if(_state == ProcessorState.executeInst)
     {
         if (Tick_opcode == 0) // Non-basic opcodes
         {
             switch (Tick_b)
             {
                 case 0x01:
                     opJSR(Tick_opA);
                     break;
                 case 0x08:
                     opINT(Tick_opA);
                     break;
                 case 0x09:
                     opIAG(Tick_opA);
                     break;
                 case 0x0a:
                     opIAS(Tick_opA);
                     break;
                 case 0x0b:
                     opRFI(Tick_opA);
                     break;
                 case 0x0c:
                     opIAQ(Tick_opA);
                     break;
                 case 0x10:
                     opHWN(Tick_opA);
                     break;
                 case 0x11:
                     opHWQ(Tick_opA);
                     break;
                 case 0x12:
                     opHWI(Tick_opA);
                     break;
             }
         }
         else // Basic opcodes
         {
             switch (Tick_opcode)
             {
                 case 0x01:
                     opSET(Tick_opB, Tick_opA);
                     break;
                 case 0x02:
                     opADD(Tick_opB, Tick_opA);
                     break;
                 case 0x03:
                     opSUB(Tick_opB, Tick_opA);
                     break;
                 case 0x04:
                     opMUL(Tick_opB, Tick_opA);
                     break;
                 case 0x05:
                     opMLI(Tick_opB, Tick_opA);
                     break;
                 case 0x06:
                     opDIV(Tick_opB, Tick_opA);
                     break;
                 case 0x07:
                     opDVI(Tick_opB, Tick_opA);
                     break;
                 case 0x08:
                     opMOD(Tick_opB, Tick_opA);
                     break;
                 case 0x09:
                     opMDI(Tick_opB, Tick_opA);
                     break;
                 case 0x0a:
                     opAND(Tick_opB, Tick_opA);
                     break;
                 case 0x0b:
                     opBOR(Tick_opB, Tick_opA);
                     break;
                 case 0x0c:
                     opXOR(Tick_opB, Tick_opA);
                     break;
                 case 0x0d:
                     opSHR(Tick_opB, Tick_opA);
                     break;
                 case 0x0e:
                     opASR(Tick_opB, Tick_opA);
                     break;
                 case 0x0f:
                     opSHL(Tick_opB, Tick_opA);
                     break;
                 case 0x10:
                     opIFB(Tick_opB, Tick_opA);
                     break;
                 case 0x11:
                     opIFC(Tick_opB, Tick_opA);
                     break;
                 case 0x12:
                     opIFE(Tick_opB, Tick_opA);
                     break;
                 case 0x13:
                     opIFN(Tick_opB, Tick_opA);
                     break;
                 case 0x14:
                     opIFG(Tick_opB, Tick_opA);
                     break;
                 case 0x15:
                     opIFA(Tick_opB, Tick_opA);
                     break;
                 case 0x16:
                     opIFL(Tick_opB, Tick_opA);
                     break;
                 case 0x17:
                     opIFU(Tick_opB, Tick_opA);
                     break;
                 case 0x1a:
                     opADX(Tick_opB, Tick_opA);
                     break;
                 case 0x1b:
                     opSBX(Tick_opB, Tick_opA);
                     break;
                 case 0x1e:
                     opSTI(Tick_opB, Tick_opA);
                     break;
                 case 0x1f:
                     opSTD(Tick_opB, Tick_opA);
                     break;
             }
         }
         _state = ProcessorState.newInst;
         return;
     }
 }
Пример #4
0
 private void opSET(operand b, operand a)
 {
     ushort _a = readValue(a);
     ushort _b = readValue(b);
     writeValue(b, _a);
 }
Пример #5
0
 private void opSTI(operand b, operand a)
 {
     ushort _a = readValue(a);
     ushort _b = readValue(b);
     uint v = (uint)(_b - _a + _EX);
     writeValue(b, _a);
     _Register[_I] = (ushort)(_Register[_I] + 0x0001u);
     _Register[_J] = (ushort)(_Register[_J] + 0x0001u);
 }
Пример #6
0
 private void opMOD(operand b, operand a)
 {
     ushort _a = readValue(a);
     ushort _b = readValue(b);
     if (_a == 0)
     {
         writeValue(b, 0);
     }
     else
     {
         writeValue(b, (ushort)(_a % _b));
     }
 }
Пример #7
0
 private void opRFI(operand a)
 {
     ushort _a = readValue(a);
     _Register[_A] = stackPOP();
     _PC = stackPOP();
     _IntEnabled = true;
 }
Пример #8
0
 private void opHWQ(operand a)
 {
     ushort _a = readValue(a);
     if(_Hardware.Count>_a)
     {
         Ie16Hardware hw = _Hardware[_a];
         _Register[_A] = (ushort)(hw.HardwareID&0x0000ffff);
         _Register[_B] = (ushort)((hw.HardwareID>>16)&0x0000ffff);
         _Register[_C] = hw.HardwareVersion;
         _Register[_X] = (ushort)(hw.Manufacturer&0x0000ffff);
         _Register[_Y] = (ushort)((hw.Manufacturer>>16)&0x0000ffff);
     }
 }
Пример #9
0
 private void opIAG(operand a)
 {
     ushort _a = readValue(a);
     writeValue(a, _IA);
 }
Пример #10
0
 private void opHWI(operand a)
 {
     ushort _a = readValue(a);
     if (_Hardware.Count > _a)
     {
         Ie16Hardware hw = _Hardware[_a];
         hw.Interrupt(_a);
     }
 }
Пример #11
0
 private void opHWN(operand a)
 {
     ushort _a = readValue(a);
     writeValue(a, (ushort) _Hardware.Count);
 }
Пример #12
0
 private void opDVI(operand b, operand a)
 {
     short _a = (short)readValue(a);
     short _b = (short)readValue(b);
     if (_a == 0)
     {
         writeValue(b, 0);
     }
     else
     {
         writeValue(b, (ushort)(_b / _a));
         _EX = (ushort)(((_b << 16) / _a) & 0xffff);
     }
 }
Пример #13
0
 private void opASR(operand b, operand a)
 {
     short _a = (short)readValue(a);
     short _b = (short)readValue(b);
     writeValue(b, (ushort)(_b >> _a));
     _EX = (ushort)(((_b << 16) >> _a) & 0xffff);
 }
Пример #14
0
 private void opADD(operand b, operand a)
 {
     ushort _a = readValue(a);
     ushort _b = readValue(b);
     writeValue(b, (ushort)(_b +_a));
     if ((_b + _a) > 0xffff) _EX = (ushort)0x0001u;
 }
Пример #15
0
 private void opMDI(operand b, operand a)
 {
     short _a = (short)readValue(a);
     short _b = (short)readValue(b);
     if (_a == 0)
     {
         writeValue(b, 0);
     }
     else
     {
         writeValue(b, (ushort)(_a % _b));
     }
 }
Пример #16
0
 private void opIAQ(operand a)
 {
     ushort _a = readValue(a);
     _IntEnabled = (_a == 0);
 }
Пример #17
0
 private void opMLI(operand b, operand a)
 {
     short _a = (short)readValue(a);
     short _b = (short)readValue(b);
     writeValue(b, (ushort)(_b * _a));
     _EX = (ushort)(((_b * _a) >> 16) & 0xffff);
 }
Пример #18
0
 private void opIAS(operand a)
 {
     ushort _a = readValue(a);
     _IA = _a;
 }
Пример #19
0
 private void opMUL(operand b, operand a)
 {
     ushort _a = readValue(a);
     ushort _b = readValue(b);
     writeValue(b, (ushort)(_b * _a));
     _EX = (ushort)(((_b*_a)>>16)&0xffff);
 }
Пример #20
0
 private void opIFC(operand b, operand a)
 {
     ushort _a = readValue(a);
     ushort _b = readValue(b);
     if (!((_b & _a) == 0)) skipNext();
 }
Пример #21
0
 private void opSBX(operand b, operand a)
 {
     ushort _a = readValue(a);
     ushort _b = readValue(b);
     uint v = (uint)(_b - _a + _EX);
     writeValue(b, (ushort)(v & 0xffffu));
     if (v > 0x0000ffffu) _EX = (ushort)0xffffu;
 }
Пример #22
0
 private void opIFN(operand b, operand a)
 {
     ushort _a = readValue(a);
     ushort _b = readValue(b);
     if (!(_b != _a)) skipNext();
 }
Пример #23
0
 private void opSHR(operand b, operand a)
 {
     ushort _a = readValue(a);
     ushort _b = readValue(b);
     writeValue(b, (ushort)(_b >> _a));
     _EX = (ushort)(((_b << 16) >> _a) & 0xffff);
 }
Пример #24
0
 private void opIFU(operand b, operand a)
 {
     short _a = (short)readValue(a);
     short _b = (short)readValue(b);
     if (!(_b < _a)) skipNext();
 }
Пример #25
0
 private void opSUB(operand b, operand a)
 {
     ushort _a = readValue(a);
     ushort _b = readValue(b);
     writeValue(b, (ushort)(_b - _a));
     if ((_b - _a) < 0) _EX = (ushort)0xffffu;
 }
Пример #26
0
 private void opINT(operand a)
 {
     ushort _a = readValue(a);
     if(_IA == 0) return;
     _IntQueue.Enqueue(_a);
 }
Пример #27
0
 private ushort readValue(operand op)
 {
     if (op._type == operand.REG)
         return _Register[op._value];
     if (op._type == operand.RAM)
         return _RAM[op._value];
     if (op._type == operand.LIT)
         return op._value;
     if (op._type == operand.STK)
         return stackPOP();
     switch (op._type)
     {
         case operand.PC:
             return _PC;
         case operand.SP:
             return _SP;
         case operand.EX:
             return _EX;
     }
     throw new Exception("Invalid op._type: " + op._type.ToString());
 }
Пример #28
0
 private void writeValue(operand op, ushort data)
 {
     if (op._type == operand.REG)
     {
         _Register[op._value] = data;
         return;
     }
     if (op._type == operand.RAM)
     {
         _RAM[op._value] = data;
         return;
     }
     if (op._type == operand.LIT)
     {
         _RAM[op._value] = data;
         return;
     }
     if (op._type == operand.STK)
     {
         stackPUSH(data);
         return;
     }
     switch (op._type)
     {
         case operand.PC:
             _PC = data;
             return;
         case operand.SP:
             _SP = data;
             return;
         case operand.EX:
             _EX = data;
             return;
     }
     throw new Exception("Invalid op._type: " + op._type.ToString());
 }