コード例 #1
0
ファイル: TextInputTests.cs プロジェクト: OdeToCode/Blazork
        public void CanPopulateParseBuffer()
        {
            using var file = File.OpenRead(@"Data\ZORK1.DAT");
            var logger  = NullLoggerFactory.GetLogger();
            var machine = new Machine(logger, new SolveZorkInputStream());

            machine.Load(file);

            var textBytes = new byte[37];

            textBytes[0] = (byte)textBytes.Length;

            var textMemory = new MemoryLocation(1, textBytes.AsMemory());
            var textBuffer = new TextBuffer(textMemory);

            textBuffer.Write("open mailbox");

            var dictionary = new ParseDictionary(machine);

            textBuffer.Tokenize(dictionary);

            var parseBytes = new byte[128];

            parseBytes[0] = (byte)parseBytes.Length;

            var parseMemory = new MemoryLocation(1, parseBytes.AsMemory());
            var parseBuffer = new ParseBuffer(parseMemory);

            parseBuffer.Populate(textBuffer, dictionary);

            Assert.Equal(2, parseBytes[0]);
            Assert.Equal(0x46, parseBytes[1]);
            Assert.Equal(0x88, parseBytes[2]);
            Assert.Equal(0x04, parseBytes[3]);
            Assert.Equal(0x01, parseBytes[4]);
        }
コード例 #2
0
        public void Read(SpanLocation location)
        {
            if (machine.Version > 0x03)
            {
                throw new NotImplementedException("Not for v3+ yet");
            }

            var textBufferAddress  = Operands[0].Value;
            var parseBufferAddress = Operands[1].Value;


            var textBuffer  = new TextBuffer(machine.Memory.MemoryAt(textBufferAddress));
            var parseBuffer = new ParseBuffer(machine.Memory.MemoryAt(parseBufferAddress));
            var dictionary  = machine.GetDictionary();

            var input = machine.Input.Read();

            textBuffer.Write(input);
            textBuffer.Tokenize(dictionary);
            parseBuffer.Populate(textBuffer, dictionary);

            log.Verbose($"Read OP");
            machine.SetPC(location.Address + Size);
        }