public static void WriteWords(Stream stream, int wordCount, IFullWord[] writeWords) { MixByte[] writeBytes = new MixByte[writeWords.Length * (FullWord.ByteCount + 1)]; int byteIndex = 0; foreach (IFullWord currentWord in writeWords) { writeBytes[byteIndex++] = currentWord.Sign.ToChar(); foreach (MixByte currentByte in currentWord) { writeBytes[byteIndex++] = currentByte; } } WriteBytes(stream, wordCount, writeBytes); }
int GetAddress() { MixByte[] addressBytes = new MixByte[MixInstruction.AddressByteCount]; for (int i = 0; i < MixInstruction.AddressByteCount; i++) { addressBytes[i] = mInstructionWord[i]; } var address = (int)Word.BytesToLong(addressBytes); if (mInstructionWord.Sign.IsNegative()) { address = -address; } return(address); }
static MixByte[] processReadText(string readText, int resultByteCount) { MixByte[] readBytes = new MixByte[resultByteCount]; int readByteCount = (readText == null) ? 0 : Math.Min(readText.Length, resultByteCount); int index = 0; for (; index < readByteCount; index++) { readBytes[index] = readText[index]; } for (; index < readBytes.Length; index++) { readBytes[index] = 0; } return(readBytes); }
public static MixByte[] ReadBytes(Stream stream, int wordCount) { byte[] buffer = new byte[wordCount * (FullWord.ByteCount + 1)]; int readByteCount = 0; readByteCount = stream.Read(buffer, 0, buffer.Length); MixByte[] readBytes = new MixByte[buffer.Length]; for (int index = 0; index < readByteCount; index++) { readBytes[index] = buffer[index]; } for (int index = readByteCount; index < readBytes.Length; index++) { readBytes[index] = 0; } return(readBytes); }
public ValueChangedEventArgs(MixByte oldValue, MixByte newValue) { OldValue = oldValue; NewValue = newValue; }
public static Word.Signs ToSign(this MixByte b) => ((char)b).ToSign();
/// <summary> /// Method for performing SLAX, SRAX, SLC and SRC instructions /// </summary> public static bool ShiftAX(ModuleBase module, MixInstruction.Instance instance) { var indexedAddress = module.Registers.GetIndexedAddress(instance.AddressValue, instance.Index); if (indexedAddress < 0) { module.ReportRuntimeError("Indexed value must be nonnegative: " + indexedAddress); return(false); } Register rA = module.Registers.RA; Register rX = module.Registers.RX; int shiftCount = indexedAddress % (FullWordRegister.RegisterByteCount * 2); if (shiftCount == 0) { return(true); } switch (instance.MixInstruction.FieldSpec.MixByteValue.ByteValue) { case slaxField: if (shiftCount < FullWordRegister.RegisterByteCount) { ShiftRegistersLeft((FullWordRegister)rA, (FullWordRegister)rX, shiftCount); } else { shiftCount -= FullWordRegister.RegisterByteCount; for (int i = shiftCount; i < FullWordRegister.RegisterByteCount; i++) { rA[i - shiftCount] = rX[i]; } for (int i = FullWordRegister.RegisterByteCount - shiftCount; i < FullWordRegister.RegisterByteCount; i++) { rA[i] = 0; } shiftCount = FullWordRegister.RegisterByteCount; } for (int i = FullWordRegister.RegisterByteCount - shiftCount; i < FullWordRegister.RegisterByteCount; i++) { rX[i] = 0; } break; case sraxField: if (shiftCount < FullWordRegister.RegisterByteCount) { ShiftRegistersRight((FullWordRegister)rA, (FullWordRegister)rX, shiftCount); } else { shiftCount -= FullWordRegister.RegisterByteCount; for (int i = (FullWordRegister.RegisterByteCount - shiftCount) - 1; i >= 0; i--) { rX[i + shiftCount] = rA[i]; } for (int i = shiftCount - 1; i >= 0; i--) { rX[i] = 0; } shiftCount = FullWordRegister.RegisterByteCount; } for (int i = shiftCount - 1; i >= 0; i--) { rA[i] = 0; } break; case slcField: if (shiftCount < FullWordRegister.RegisterByteCount) { MixByte[] shiftedBytes = new MixByte[shiftCount]; for (int i = 0; i < shiftCount; i++) { shiftedBytes[i] = rA[i]; } ShiftRegistersLeft((FullWordRegister)rA, (FullWordRegister)rX, shiftCount); for (int i = 0; i < shiftCount; i++) { rX[(rX.ByteCount - shiftCount) + i] = shiftedBytes[i]; } } else { shiftCount -= FullWordRegister.RegisterByteCount; MixByte[] numArray = new MixByte[FullWordRegister.RegisterByteCount - shiftCount]; for (int i = shiftCount; i < FullWordRegister.RegisterByteCount; i++) { numArray[i - shiftCount] = rA[i]; } for (int i = 1; i <= shiftCount; i++) { rA[FullWordRegister.RegisterByteCount - i] = rA[shiftCount - i]; } for (int i = shiftCount; i < FullWordRegister.RegisterByteCount; i++) { rA[i - shiftCount] = rX[i]; } for (int i = 1; i <= shiftCount; i++) { rX[FullWordRegister.RegisterByteCount - i] = rX[shiftCount - i]; } for (int i = 0; i < numArray.Length; i++) { rX[i] = numArray[i]; } } return(true); case srcField: if (shiftCount < FullWordRegister.RegisterByteCount) { MixByte[] shiftBytes = new MixByte[shiftCount]; for (int i = 0; i < shiftCount; i++) { shiftBytes[i] = rX[(rX.ByteCount - shiftCount) + i]; } ShiftRegistersRight((FullWordRegister)rA, (FullWordRegister)rX, shiftCount); for (int i = 0; i < shiftCount; i++) { rA[i] = shiftBytes[i]; } } else { shiftCount -= FullWordRegister.RegisterByteCount; MixByte[] shiftBytes = new MixByte[FullWordRegister.RegisterByteCount - shiftCount]; for (int i = 0; i < shiftBytes.Length; i++) { shiftBytes[i] = rX[i]; } for (int i = 0; i < shiftCount; i++) { rX[i] = rX[(FullWordRegister.RegisterByteCount - shiftCount) + i]; } for (int i = shiftCount; i < FullWordRegister.RegisterByteCount; i++) { rX[i] = rA[i - shiftCount]; } for (int i = 0; i < shiftCount; i++) { rA[i] = rA[(FullWordRegister.RegisterByteCount - shiftCount) + i]; } for (int i = shiftCount; i < FullWordRegister.RegisterByteCount; i++) { rA[i] = shiftBytes[i - shiftCount]; } } break; } return(true); }