Beispiel #1
0
        public GameObjectPropertyTable(Machine machine, int startingAddress)
        {
            if (machine == null)
            {
                throw new ArgumentNullException(nameof(machine));
            }

            this.machine = machine;

            var location   = machine.Memory.SpanAt(startingAddress);
            var textLength = location.Bytes[0] * 2;

            var decoder = new ZStringDecoder(machine);

            Description = decoder.Decode(location.Forward(1)).Text;

            Properties = new Dictionary <int, GameObjectProperty>();
            var propertyEntry = machine.Memory.MemoryAt(startingAddress + textLength + 1);

            while (propertyEntry.Bytes.Span[0] != 0)
            {
                var property         = new GameObjectProperty(machine, propertyEntry);
                var nextEntryAddress = propertyEntry.Address + property.Size + 1;

                if (machine.Version > 3)
                {
                    throw new NotImplementedException("Need to adjust prope entry size for 2 size bytes senario");
                }

                Properties.Add(property.Number, property);

                propertyEntry = machine.Memory.MemoryAt(nextEntryAddress);
            }
        }
Beispiel #2
0
        public DecodedString Decode(SpanLocation location)
        {
            var decoder = new ZStringDecoder(machine);
            var result  = decoder.Decode(location);

            return(result);
        }
Beispiel #3
0
        public void AbbreviationsMakeSense()
        {
            using var file = File.OpenRead(@"Data\ZORK1.DAT");
            var logger  = NullLoggerFactory.GetLogger();
            var machine = new Machine(logger, new SolveZorkInputStream());

            machine.Load(file);

            logger.Error($"ABBREVIATIONS");
            var decoder = new ZStringDecoder(machine);

            for (var index = 1; index <= 3; index++)
            {
                for (var number = 0; number < 32; number++)
                {
                    var offset = (32 * (index - 1)) + (number * 2);
                    logger.Error($"For [{index}][{number}] the offset is {offset}");

                    var ppAbbreviation = machine.Memory.WordAt(Header.ABBREVIATIONS);
                    logger.Error($"For [{index}][{number}] the ppointer is {ppAbbreviation:X}");

                    var pAbbreviation = machine.Memory.WordAddressAt(ppAbbreviation + offset);
                    logger.Error($"For [{index}][{number}] the pointer is {pAbbreviation:X}");

                    var location = machine.Memory.SpanAt(pAbbreviation);
                    var result   = decoder.Decode(location).Text;

                    logger.Error($"Abbreviation [{index}][{number}] : {result}");
                }
            }
        }
Beispiel #4
0
        public void PrintPaddr(SpanLocation location)
        {
            var address       = Operands[0].Value;
            var unpacked      = machine.Memory.Unpack(address);
            var stringDecoder = new ZStringDecoder(machine);
            var text          = stringDecoder.Decode(machine.Memory.SpanAt(unpacked));

            machine.Output.Write(Text);

            log.Debug($"\tPrintPaddr @ {unpacked:X}");
            machine.SetPC(location.Address + Size);
        }
        public void CanDecodePairOfHands()
        {
            using var file = File.OpenRead(@"Data\ZORK1.DAT");
            var logger  = NullLoggerFactory.GetLogger();
            var machine = new Machine(logger, new SolveZorkInputStream());

            machine.Load(file);

            var decoder = new ZStringDecoder(machine);

            Assert.Equal("pair of hands", decoder.Decode(machine.Memory.SpanAt(0xBB9)).Text);
        }
        public void CanDecodeTenBit()
        {
            using var file = File.OpenRead(@"Data\ZORK1.DAT");
            var logger  = NullLoggerFactory.GetLogger();
            var machine = new Machine(logger, new SolveZorkInputStream());

            machine.Load(file);

            var decoder = new ZStringDecoder(machine);
            var result  = decoder.Decode(machine.Memory.SpanAt(0x5908)).Text;

            Assert.Equal(">", result);
        }