コード例 #1
0
        /// <summary>
        /// Implements the IN and OUT instructions.
        /// </summary>
        /// <remarks>
        /// For further details refer to the picoComputer documentation.
        /// </remarks>
        /// <param name="isIn">If true executes IN, otherwise OUT.</param>
        protected void InOut(bool isIn)
        {
            ushort address = GetAddress(Instruction[1]);
            ushort count   = 1;

            if ((Instruction[2] & 0x8) == 0)
            {
                count = (ushort)((Instruction[2] << 4) | Instruction[3]);
            }
            else
            {
                if (Instruction[2] != 0x8)
                {
                    throw new InvalidInstructionRuntimeException(new ushort[] { IR }, (ushort)(Data.PC - 1));
                }
                count = Data[GetAddress(Instruction[3])];
            }
            if (isIn)
            {
                try
                {
                    IODevice.Read(address, count, Data);
                }
                catch (Exception)
                {
                    throw new InvalidInputRuntimeException(new ushort[] { IR }, (ushort)(Data.PC - 1));
                }
            }
            else             // Out
            {
                IODevice.Write(address, count, Data);
            }
        }
コード例 #2
0
 /// <summary>
 /// Implements the STOP instruction.
 /// </summary>
 /// <remarks>
 /// For further details refer to the picoComputer documentation.
 /// Throws a NormalTerminationRuntimeException to terminate the program.
 /// </remarks>
 protected void Stop()
 {
     for (int i = 1; i <= 3; i++)
     {
         if (Instruction[i] != 0)
         {
             IODevice.Write(GetAddress(Instruction[i]), 1, Data);
         }
     }
     throw new NormalTerminationRuntimeException(new ushort[] { IR }, (ushort)(Data.PC - 1));
 }