Exemplo n.º 1
0
        private void LoadBits()
        {
            BaseStream.Position = BaseStream.Length - sizeof(int);

            byte[] bytArrayLength = new byte[sizeof(int)];
            BaseStream.Read(bytArrayLength, 0, bytArrayLength.Length);
            int intBytesLength = BitConverter.ToInt32(bytArrayLength, 0);

            if (intBytesLength > 0)
            {
                BaseStream.Position = BaseStream.Length - intBytesLength - sizeof(int);

                byte[] bytBitsData = new byte[intBytesLength];
                BaseStream.Read(bytBitsData, 0, bytBitsData.Length);

                BitArray objBitArray  = new BitArray(bytBitsData);
                bool[]   objBoolArray = new bool[objBitArray.Count];
                objBitArray.CopyTo(objBoolArray, 0);

                Bits.Clear();
                Bits.AddRange(objBoolArray);

                BaseStream.SetLength(BaseStream.Length - intBytesLength - sizeof(int));
                BaseStream.Position = 0;
            }
            else
            {
                BaseStream.SetLength(BaseStream.Length - sizeof(int));
                BaseStream.Position = 0;
            }
        }
Exemplo n.º 2
0
 public void clear_throws_with_ulong_and_sizeof_ulong()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() =>
     {
         ulong value = 0;
         Bits.Clear(value, sizeof(ulong) * ByteSize);
     });
 }
Exemplo n.º 3
0
 public void clear_throws_with_ulong_and_minus_one()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() =>
     {
         ulong value = 0;
         Bits.Clear(value, -1);
     });
 }
Exemplo n.º 4
0
 public void clear_throws_with_byte_and_sizeof_byte()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() =>
     {
         byte value = 0;
         Bits.Clear(value, sizeof(byte) * ByteSize);
     });
 }
Exemplo n.º 5
0
        public void clear_ulong_bits_and_verify_result()
        {
            ulong value    = 0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111;
            ulong expected = 0b0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000;

            for (int i = 0; i < sizeof(ulong) * ByteSize; i++)
            {
                Assert.False(Bits.IsClear(value, i));
                value = Bits.Clear(value, i);
                Assert.True(Bits.IsClear(value, i));
            }

            Assert.Equal(expected, value);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Registers a Z-Machine interpreter with this story.
        /// </summary>
        /// <param name="interpreter"></param>
        public void RegisterInterpreter(IInterpreter interpreter)
        {
            if (interpreter == null)
            {
                throw new ArgumentNullException("interpreter");
            }

            if (this.interpreter != null && !(this.interpreter is DefaultInterpreter))
            {
                throw new InvalidOperationException("Interpreter has already been registered.");
            }

            this.interpreter = interpreter;

            if (version >= 4)
            {
                memory.WriteByte(0x1e, (byte)interpreter.Target);
                memory.WriteByte(0x1f, interpreter.Version);
            }

            memory.WriteByte(0x32, interpreter.StandardRevisionMajorVersion);
            memory.WriteByte(0x33, interpreter.StandardRevisionMinorVersion);

            // Set various flags
            byte flags1 = memory.ReadByte(0x01);

            if (this.version <= 3)
            {
                // Only set this flag if the status line is NOT available
                flags1 = interpreter.SupportsStatusLine ? Bits.Clear(flags1, 4) : Bits.Set(flags1, 4);
                flags1 = interpreter.SupportsScreenSplitting ? Bits.Set(flags1, 5) : Bits.Set(flags1, 5);
                flags1 = interpreter.IsDefaultFontVariablePitch ? Bits.Set(flags1, 6) : Bits.Set(flags1, 6);
            }
            else // this.version >= 4
            {
                if (this.version >= 5)
                {
                    flags1 = interpreter.SupportsColor ? Bits.Set(flags1, 0) : Bits.Clear(flags1, 0);
                }

                if (this.version == 6)
                {
                    flags1 = interpreter.SupportsPictureDisplay ? Bits.Set(flags1, 1) : Bits.Clear(flags1, 1);
                    flags1 = interpreter.SupportsSoundEffects ? Bits.Set(flags1, 5) : Bits.Clear(flags1, 5);
                }

                flags1 = interpreter.SupportsBoldFont ? Bits.Set(flags1, 2) : Bits.Clear(flags1, 2);
                flags1 = interpreter.SupportsItalicFont ? Bits.Set(flags1, 3) : Bits.Clear(flags1, 3);
                flags1 = interpreter.SupportsFixedWidthFont ? Bits.Set(flags1, 4) : Bits.Clear(flags1, 4);
                flags1 = interpreter.SupportsTimedKeyboardInput ? Bits.Set(flags1, 7) : Bits.Clear(flags1, 7);
            }

            memory.WriteByte(0x01, flags1);

            ushort flags2 = memory.ReadWord(0x10);

            if (this.version >= 5)
            {
                flags2 = interpreter.SupportsPictureDisplay ? flags2 : Bits.Clear(flags2, 3);
                flags2 = interpreter.SupportsUndo ? flags2 : Bits.Clear(flags2, 4);
                flags2 = interpreter.SupportsMouse ? flags2 : Bits.Clear(flags2, 5);
                flags2 = interpreter.SupportsSoundEffects ? flags2 : Bits.Clear(flags2, 7);

                if (this.version == 6)
                {
                    flags2 = interpreter.SupportsMenus ? flags2 : Bits.Clear(flags2, 8);
                }
            }

            memory.WriteWord(0x10, flags2);
        }