private void opJSR(operand a) { ushort _a = readValue(a); stackPUSH(_PC); _PC = _a; }
private void opXOR(operand b, operand a) { ushort _a = readValue(a); ushort _b = readValue(b); writeValue(b,(ushort)(_b ^ _a)); }
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; } }
private void opSET(operand b, operand a) { ushort _a = readValue(a); ushort _b = readValue(b); writeValue(b, _a); }
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); }
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)); } }
private void opRFI(operand a) { ushort _a = readValue(a); _Register[_A] = stackPOP(); _PC = stackPOP(); _IntEnabled = true; }
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); } }
private void opIAG(operand a) { ushort _a = readValue(a); writeValue(a, _IA); }
private void opHWI(operand a) { ushort _a = readValue(a); if (_Hardware.Count > _a) { Ie16Hardware hw = _Hardware[_a]; hw.Interrupt(_a); } }
private void opHWN(operand a) { ushort _a = readValue(a); writeValue(a, (ushort) _Hardware.Count); }
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); } }
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); }
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; }
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)); } }
private void opIAQ(operand a) { ushort _a = readValue(a); _IntEnabled = (_a == 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); }
private void opIAS(operand a) { ushort _a = readValue(a); _IA = _a; }
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); }
private void opIFC(operand b, operand a) { ushort _a = readValue(a); ushort _b = readValue(b); if (!((_b & _a) == 0)) skipNext(); }
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; }
private void opIFN(operand b, operand a) { ushort _a = readValue(a); ushort _b = readValue(b); if (!(_b != _a)) skipNext(); }
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); }
private void opIFU(operand b, operand a) { short _a = (short)readValue(a); short _b = (short)readValue(b); if (!(_b < _a)) skipNext(); }
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; }
private void opINT(operand a) { ushort _a = readValue(a); if(_IA == 0) return; _IntQueue.Enqueue(_a); }
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()); }
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()); }