Beispiel #1
0
        public void PrepareLoader()
        {
            var instruction = InstructionSet.Instance.GetInstruction(IOInstructions.INOpCode, new FieldSpec(Devices.CardReaderUnitCode));

            var instructionWord = new FullWord
            {
                [MixInstruction.OpcodeByte]    = IOInstructions.INOpCode,
                [MixInstruction.FieldSpecByte] = Devices.CardReaderUnitCode
            };
            var instance = instruction.CreateInstance(instructionWord);

            int ticksLeft = instruction.TickCount;

            while (ticksLeft-- > 0)
            {
                IncreaseTickCounter();
            }

            instance.Execute(this);

            while (mDevices[Devices.CardReaderUnitCode].Busy)
            {
                IncreaseTickCounter();
            }

            ProgramCounter = 0;

            IncreaseTickCounter();

            mRegisters.RJ.LongValue = 0;

            IncreaseTickCounter();
        }
Beispiel #2
0
        public async Task InsertWordsAsync(IDictionary <string, Description[]> words)
        {
            if (words == null)
            {
                throw new ArgumentNullException(nameof(words));
            }

            foreach (KeyValuePair <string, Description[]> wordDescriptionsPair in words)
            {
                var word = new Word {
                    Title = wordDescriptionsPair.Key
                };
                Guid wordId = await _unitOfWork.GetRepository <Word>().InsertOrUpdateAsync(word);

                IRepository <Description> descriptionRepository = _unitOfWork.GetRepository <Description>();
                IRepository <FullWord>    wordRepository        = _unitOfWork.GetRepository <FullWord>();
                foreach (Description description in wordDescriptionsPair.Value)
                {
                    Guid descriptionId = await descriptionRepository.InsertOrUpdateAsync(description);

                    FullWord fullWord = new FullWord
                    {
                        DescriptionId = descriptionId,
                        WordId        = wordId,
                    };
                    await wordRepository.InsertOrUpdateAsync(fullWord);
                }
            }

            await _unitOfWork.CommitAsync();
        }
Beispiel #3
0
        public override object Clone()
        {
            var copy = new FullWord();

            CopyTo(copy);

            return(copy);
        }
Beispiel #4
0
        public int CompareTo(FullWord toCompare)
        {
            WordField field = LoadFromFullWord(mFieldSpec, toCompare);

            long wordValue  = base.LongValue;
            long fieldValue = field.LongValue;

            return(wordValue.CompareTo(fieldValue));
        }
        //[System.Web.Http.HttpPost]
        public HttpResponseMessage Post([FromBody] VocabularyWord model)
        {
            if (UserID == null)
            {
                return(ResponseError(HttpStatusCode.Forbidden, "Log in required."));
            }
            Sql sql = new Sql("WHERE OwnerID=@0", UserID);

            int listID = 0;



            if (model.list != null && int.TryParse(model.list, out listID))
            {
                sql.Append("AND ID=@0", listID);
            }

            sql.Append("ORDER BY ID DESC");

            VocabularyList vc = VocabularyList.FirstOrDefault(sql);



            if (vc == null)
            {
                return(ResponseError(HttpStatusCode.PreconditionFailed, "No vocabulary list found."));
            }

            try
            {
                SuomenkieliRepository.AddVocabularyWord(model.word, vc.ID, UserID);
            }
            catch (Exception ex)
            {
                return(ResponseError(HttpStatusCode.InternalServerError, ex.Message));
            }


            int wordID = SuomenkieliRepository.GetWordID(model.word).GetValueOrDefault(); // This should not be null.

            FullWord fWord = SuomenkieliRepository.GetFullWord(wordID);

            string firstDef = (fWord.Definitions.Count > 0) ? fWord.Definitions.First()._Definition : "";

            ResponseWord rWord = new ResponseWord()
            {
                id = fWord.ID, word = fWord._Word, definition = firstDef
            };

            var resp = Request.CreateResponse <ResponseWord>(HttpStatusCode.OK, rWord);

            return(resp);

            //return ResponseOK(rWord);
        }
Beispiel #6
0
        /// <summary>
        /// Method for performing the STZ instruction
        /// </summary>
        public static bool StoreZero(ModuleBase module, MixInstruction.Instance instance)
        {
            var indexedAddress = InstructionHelpers.GetValidIndexedAddress(module, instance.AddressValue, instance.Index);

            if (indexedAddress != int.MinValue)
            {
                var word = new FullWord();
                WordField.LoadFromFullWord(instance.FieldSpec, word).ApplyToFullWord(module.Memory[indexedAddress]);
            }

            return(true);
        }
Beispiel #7
0
        /// <summary>
        /// Create a MIX instruction instance with the parameters contained in this object.
        /// </summary>
        /// <param name="instruction">MixInstruction to create an instance of. This method will throw an exception if this parameter is of a different instruction type.</param>
        /// <param name="status">AssemblingStatus object reflecting the current state of the assembly process</param>
        /// <returns></returns>
        public InstructionInstanceBase CreateInstance(InstructionBase instruction, AssemblingStatus status)
        {
            if (!(instruction is MixInstruction))
            {
                throw new ArgumentException("instruction must be a MixInstruction", nameof(instruction));
            }

            var mixInstruction = (MixInstruction)instruction;

            if (!AreValuesDefined(status))
            {
                return(null);
            }

            var addressMagnitude = mAddress.GetMagnitude(status.LocationCounter);
            var word             = new Word(MixInstruction.AddressByteCount);

            if (addressMagnitude > word.MaxMagnitude)
            {
                status.ReportError(LineSection.AddressField, 0, mIndexPartCharIndex, new MixAssembler.Finding.ParsingError("address value " + addressMagnitude + " invalid", (int)-word.MaxMagnitude, (int)word.MaxMagnitude));
                return(null);
            }

            word.MagnitudeLongValue = addressMagnitude;
            var fieldSpecValue = GetFieldSpecValue(status, mixInstruction);

            if (fieldSpecValue == null)
            {
                return(null);
            }

            var instructionWord = new FullWord
            {
                Sign = mAddress.GetSign(status.LocationCounter)
            };

            for (int i = 0; i < word.ByteCount; i++)
            {
                instructionWord[i] = word[i];
            }

            instructionWord[MixInstruction.IndexByte]     = (int)mIndex.GetValue(status.LocationCounter);
            instructionWord[MixInstruction.FieldSpecByte] = fieldSpecValue;
            instructionWord[MixInstruction.OpcodeByte]    = mixInstruction.Opcode;

            var instance = mixInstruction.CreateInstance(instructionWord);

            ReportInstanceErrors(status, instance);

            return(instance);
        }
Beispiel #8
0
        public void ApplyToFullWord(FullWord word)
        {
            int byteCount         = mFieldSpec.ByteCount;
            int lowBoundByteIndex = mFieldSpec.LowBoundByteIndex;

            for (int i = 0; i < byteCount; i++)
            {
                word[lowBoundByteIndex + i] = base[i];
            }

            if (mFieldSpec.IncludesSign)
            {
                word.Sign = base.Sign;
            }
        }
Beispiel #9
0
        bool AssembleInstruction(bool markErrors)
        {
            mEditMode = false;

            var instance = Assembler.Assemble(Text, MemoryAddress, out ParsedSourceLine line, Symbols, out AssemblyFindingCollection findings);

            if (instance != null && !(instance is MixInstruction.Instance))
            {
                findings.Add(new AssemblyError(0, LineSection.OpField, 0, line.OpField.Length, new ValidationError("only MIX instruction mnemonics supported")));
                instance = null;
            }

            if (markErrors && findings.Count > 0)
            {
                mUpdating = true;

                int selectionStart  = SelectionStart;
                int selectionLength = SelectionLength;

                SuspendLayout();

                base.Text = line.OpField + " " + line.AddressField;

                mCaption = GetAssemblyErrorsCaption(line, findings);
                mToolTip?.SetToolTip(this, mCaption);

                Select(selectionStart, selectionLength);
                ResumeLayout();

                mUpdating = false;
            }

            if (instance == null)
            {
                return(false);
            }

            var oldValue = new FullWord(mInstructionWord.LongValue);

            mInstructionWord.LongValue = ((MixInstruction.Instance)instance).InstructionWord.LongValue;

            Update();

            OnValueChanged(new WordEditorValueChangedEventArgs(oldValue, new FullWord(mInstructionWord.LongValue)));

            return(true);
        }
Beispiel #10
0
        public static WordField LoadFromFullWord(FieldSpec fieldSpec, FullWord word)
        {
            int fieldSpecByteCount = fieldSpec.ByteCount;

            WordField field             = new WordField(fieldSpec, fieldSpecByteCount);
            int       lowBoundByteIndex = fieldSpec.LowBoundByteIndex;

            for (int i = 0; i < fieldSpecByteCount; i++)
            {
                field[i] = word[lowBoundByteIndex + i];
            }

            if (fieldSpec.IncludesSign)
            {
                field.Sign = word.Sign;
            }

            return(field);
        }
Beispiel #11
0
        void Initialize(long recordCount, long wordsPerRecord, OpenStreamCallback openStream, CalculateBytePositionCallback calculateBytePosition, ReadWordsCallback readWords, WriteWordsCallback writeWords, CalculateRecordCountCallback calculateRecordCount)
        {
            if (mInitialized)
            {
                throw new InvalidOperationException("FileDeviceEditor has already been initialized");
            }

            mDeviceWordsPerRecord  = wordsPerRecord;
            mOpenStream            = openStream;
            mCalculateBytePosition = calculateBytePosition;
            mReadWords             = readWords;
            mWriteWords            = writeWords;
            mCalculateRecordCount  = calculateRecordCount;

            mRecordUpDown.Minimum   = 0;
            mRecordTrackBar.Minimum = 0;
            SetDeviceRecordCount(recordCount);

            mFirstWordTextBox.ClearZero = false;
            mFirstWordTextBox.MinValue  = 0L;
            mFirstWordTextBox.MaxValue  = mDeviceWordsPerRecord - 1;

            mRecordReadWords = new IFullWord[mDeviceWordsPerRecord];
            mRecordEditWords = new IFullWord[mDeviceWordsPerRecord];
            for (int i = 0; i < mDeviceWordsPerRecord; i++)
            {
                mRecordEditWords[i] = new FullWord();
            }

            mWordEditorList.MaxIndex     = (int)mDeviceWordsPerRecord - 1;
            mWordEditorList.CreateEditor = CreateWordEditor;
            mWordEditorList.LoadEditor   = LoadWordEditor;

            mChangesPending = false;

            mLoadRecordRetryCount = 0;

            ProcessSupportsAppending();
            ProcessVisibility();
        }
Beispiel #12
0
        public InstructionInstanceTextBox(IFullWord instructionWord)
        {
            if (instructionWord == null)
            {
                instructionWord = new FullWord();
            }

            mInstructionWord = instructionWord;

            UpdateLayout();

            DetectUrls       = false;
            TextChanged     += This_TextChanged;
            KeyPress        += This_KeyPress;
            KeyDown         += This_KeyDown;
            LostFocus       += This_LostFocus;
            Enter           += This_Enter;
            ReadOnlyChanged += This_ReadOnlyChanged;

            mShowAddressMenuItem = new MenuItem("Show address", ShowAddressMenuItem_Click);

            mShowIndexedAddressMenuItem = new MenuItem("Show indexed address", ShowIndexedAddressMenuItem_Click);

            mContextMenu = new ContextMenu();
            mContextMenu.MenuItems.Add(mShowAddressMenuItem);
            mContextMenu.MenuItems.Add(mShowIndexedAddressMenuItem);

            ContextMenu = mContextMenu;

            mUpdating               = false;
            mEditMode               = false;
            MemoryAddress           = 0;
            mLastRenderedMagnitude  = unrendered;
            mLastRenderedSign       = Word.Signs.Positive;
            mLastRenderedSourceLine = null;
            mNoInstructionRendered  = true;

            Update();
        }
Beispiel #13
0
        public static IValue ParseValue(string text, int sectionCharIndex, ParsingStatus status)
        {
            // split the text to parse in its W-value components
            var textParts    = text.Split(new char[] { ',' });
            int currentIndex = 0;

            var register = new FullWordRegister();
            var word     = new FullWord(0);

            // parse and apply each component to the word that contains the result
            foreach (string part in textParts)
            {
                // parse the address part...
                var braceIndex = part.IndexOf('(');
                var address    = ExpressionValue.ParseValue((braceIndex == -1) ? part : part.Substring(0, braceIndex), sectionCharIndex + currentIndex, status);
                if (address == null)
                {
                    return(null);
                }

                // ... and check if it is valid
                var addressSign      = address.GetSign(status.LocationCounter);
                var addressMagnitude = address.GetMagnitude(status.LocationCounter);
                if (addressMagnitude > register.MaxMagnitude)
                {
                    status.ReportParsingError(sectionCharIndex + currentIndex, (braceIndex == -1) ? part.Length : braceIndex, "W-value field value invalid");
                    return(null);
                }

                register.MagnitudeLongValue = addressMagnitude;
                register.Sign = addressSign;
                int fieldValue = FullWord.ByteCount;

                // if a fieldspec part is present...
                if (braceIndex >= 0)
                {
                    // ... parse its value...
                    var field = FPartValue.ParseValue(part.Substring(braceIndex), (sectionCharIndex + currentIndex) + braceIndex, status);
                    if (field == null)
                    {
                        return(null);
                    }

                    // ... and check if it is valid
                    if (field.GetValue(status.LocationCounter) != FPartValue.Default)
                    {
                        fieldValue = (int)field.GetValue(status.LocationCounter);
                    }
                }

                // use the fieldspec value to create and check an actual fieldspec
                var fieldSpec = new FieldSpec(fieldValue);
                if (!fieldSpec.IsValid)
                {
                    status.ReportParsingError((sectionCharIndex + currentIndex) + braceIndex, part.Length - braceIndex, "field must be a fieldspec");
                    return(null);
                }

                // apply the component to the word that will contain the end result
                WordField.LoadFromRegister(fieldSpec, register).ApplyToFullWord(word);
                currentIndex += part.Length + 1;
            }

            return(new NumberValue(word.Sign, word.MagnitudeLongValue));
        }
Beispiel #14
0
 public Instance(LoaderInstruction instruction, Word.Signs sign, long magnitude)
 {
     mInstruction = instruction;
     Value        = new FullWord(sign, magnitude);
 }