Example #1
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);
 }
Example #2
0
        private void opREAD(operand b, operand a)
        {
            var value = Executor.Read();
               Console.WriteLine(value.ToString());

               ushort _b = readValue(b);
               writeValue(b, (ushort) value);
        }
Example #3
0
        private void Tick()
        {
            //TODO

               _Cycles++;

               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
               {
                   //TODO: DICTIONARY
                   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;
                    }
               }
               else // Basic opcodes
               {
                   new Operation(Actions[Tick_opcode]).Invoke(Tick_opB, Tick_opA);

               }
               _state = ProcessorState.newInst;
               return;
               }
        }
Example #4
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);
 }
Example #5
0
 //sets b to a, then increases I and J by 1
 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);
 }
Example #6
0
 private void opXOR(operand b, operand a)
 {
     ushort _a = readValue(a);
        ushort _b = readValue(b);
        writeValue(b, (ushort)(_b ^ _a));
 }
Example #7
0
 //performs next instruction only if b!=a
 private void opIFN(operand b, operand a)
 {
     ushort _a = readValue(a);
        ushort _b = readValue(b);
        if (!(_b != _a)) skipNext();
 }
Example #8
0
 private void opSET(operand b, operand a)
 {
     ushort _a = readValue(a);
        ushort _b = readValue(b);
        writeValue(b, _a);
 }
Example #9
0
 //sets IA to a
 private void opIAS(operand a)
 {
     ushort _a = readValue(a);
        _IA = _a;
 }
Example #10
0
 //performs next instruction only if (b&a)==0
 private void opIFC(operand b, operand a)
 {
     ushort _a = readValue(a);
        ushort _b = readValue(b);
        if (!((_b & _a) == 0)) skipNext();
 }
Example #11
0
 /*
 * if a is nonzero, interrupts will be added to the queue
 instead of triggered. if a is zero, interrupts will be
 triggered as normal again
 */
 private void opIAQ(operand a)
 {
     ushort _a = readValue(a);
        _IntEnabled = (_a == 0);
 }
Example #12
0
 //sets a to IA
 private void opIAG(operand a)
 {
     ushort _a = readValue(a);
        writeValue(a, _IA);
 }
Example #13
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);
        }
 }
Example #14
0
 //disables interrupt queueing, pops A from the stack, then pops PC from the stack
 private void opRFI(operand a)
 {
     ushort _a = readValue(a);
        _Register[_A] = stackPOP();
        _PC = stackPOP();
        _IntEnabled = true;
 }
Example #15
0
 //performs next instruction only if b<a (signed)
 private void opIFU(operand b, operand a)
 {
     short _a = (short)readValue(a);
        short _b = (short)readValue(b);
        if (!(_b < _a)) skipNext();
 }
Example #16
0
 //sets b to b-a+EX, sets EX to 0xFFFF if there is an under flow, 0x0001 if there's an overflow, 0x0 otherwise
 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;
        else
        _EX = (ushort)0x0000u;
 }
Example #17
0
 //triggers a software interrupt with message a
 private void opINT(operand a)
 {
     ushort _a = readValue(a);
        if (_IA == 0) return;
        _IntQueue.Enqueue(_a);
 }
Example #18
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);
 }
Example #19
0
 /*
 * NON BASIC OPERATIONS
 */
 //pushes the address of the next instruction to the stack, then sets PC to a
 private void opJSR(operand a)
 {
     ushort _a = readValue(a);
        stackPUSH(_PC);
        _PC = _a;
 }
Example #20
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;
 }
Example #21
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);
 }
Example #22
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());
 }
Example #23
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));
        }
 }
Example #24
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());
 }
Example #25
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;
        }