Exemplo n.º 1
0
 public static void RotateLeft(IRegister <byte> target, IFlags flags)
 {
     target.Value   = (byte)((target.Value << 1) | (target.Value >> 7));
     flags.Zero     = target.Value == 0;
     flags.Subtract = flags.HalfCarry = false;
     flags.Carry    = target.GetBit(0);
 }
Exemplo n.º 2
0
 public static void ShiftRightLogical(IRegister <byte> target, IFlags flags)
 {
     flags.Carry    = target.GetBit(0);
     target.Value   = (byte)(target.Value >> 1);
     flags.Subtract = flags.HalfCarry = false;
     flags.Zero     = target.Value == 0;
 }
Exemplo n.º 3
0
        public static void DecimalAdjust(IRegister <byte> target, IFlags flags)
        {
            int reg = target.Value;

            if (flags.Subtract)
            {
                if (flags.HalfCarry)
                {
                    reg -= 0x06;
                }
                if (flags.Carry)
                {
                    reg -= 0x60;
                }
            }
            else
            {
                if (flags.HalfCarry || (reg & 0xF) > 0x9)
                {
                    reg += 0x06;
                }
                if (flags.Carry || (reg & 0xFF0) > 0x90)
                {
                    reg        += 0x60;
                    flags.Carry = true;
                }
            }

            target.Value    = (byte)reg;
            flags.HalfCarry = false;
            flags.Zero      = target.Value == 0;
        }
Exemplo n.º 4
0
 public static void And(IRegister <byte> target, byte operand, IFlags flags)
 {
     target.Value    = (byte)(target.Value & operand);
     flags.Zero      = target.Value == 0;
     flags.HalfCarry = true;
     flags.Subtract  = flags.Carry = false;
 }
Exemplo n.º 5
0
        // TODO: RETI

        private static bool ShouldJump(JumpCondition condition, IFlags flags)
        {
            return((condition == JumpCondition.Carry && flags.Carry) ||
                   (condition == JumpCondition.NoCarry && !flags.Carry) ||
                   (condition == JumpCondition.Zero && flags.Zero) ||
                   (condition == JumpCondition.NotZero && !flags.Zero));
        }
Exemplo n.º 6
0
 public FormattedText(IFlags flags, IElementFrameFactory frameFactory, ITextScoper textScoper)
 {
     this.text       = string.Empty;
     this.flags      = flags;
     this.frame      = frameFactory.Create(flags);
     this.textScoper = textScoper;
 }
Exemplo n.º 7
0
 public static void Compare(IReadonlyRegister <byte> target, byte operand, IFlags flags)
 {
     flags.Zero      = target.Value == operand;
     flags.Subtract  = true;
     flags.Carry     = target.Value < operand;
     flags.HalfCarry = (target.Value & 0xF) < (operand & 0xF);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Takes the remaining text that fits the flag, until a limit by the maxLength, removing that text from the buffer.
        /// </summary>
        /// <returns></returns>
        public string Take(IDimensionConstraint constraint, IFlags flags)
        {
            this.ThrowIfBufferIsEmpty();

            if (constraint.MaxWidth == null)
            {
                throw new Exception("A max width must be provided in the constraint.");
            }

            var first = this.elements.First();

            if (first.Flags == null || (flags != null && !first.Flags.Equals(flags)))
            {
                return(null);
            }

            var text = this.textScoper.GetFittingText(first.Flags.Font, first.Flags.FontSize, first.Text, (double)constraint.MaxWidth);

            if (text == first.Text)
            {
                this.elements.RemoveAt(0);
            }
            else if (text != String.Empty)
            {
                this.elements[0] = new BufferElement()
                {
                    Text  = Strings.strsubutf8(first.Text, Strings.strlenutf8(text)),
                    Flags = first.Flags,
                };
            }
            return(text);
        }
Exemplo n.º 9
0
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <object> GetAsync(this IFlags operations, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.GetWithHttpMessagesAsync(null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Exemplo n.º 10
0
 private void AssertFlags(IFlags expected, IFlags actual)
 {
     Assert.AreEqual(expected.Zero, actual.Zero);
     Assert.AreEqual(expected.Subtract, actual.Subtract);
     Assert.AreEqual(expected.HalfCarry, actual.HalfCarry);
     Assert.AreEqual(expected.Carry, actual.Carry);
 }
Exemplo n.º 11
0
 public static void RotateRight(IRegister <byte> target, IFlags flags)
 {
     flags.Carry    = target.GetBit(0);
     target.Value   = (byte)(target.Value >> 1 | target.Value << 7);
     flags.Subtract = flags.HalfCarry = false;
     flags.Zero     = target.Value == 0;
 }
Exemplo n.º 12
0
 public static void ShiftLeft(IRegister <byte> target, IFlags flags)
 {
     flags.Carry    = target.GetBit(7);
     target.Value   = (byte)(target.Value << 1);
     flags.Subtract = flags.HalfCarry = false;
     flags.Zero     = target.Value == 0;
 }
Exemplo n.º 13
0
 public Cpu(IRandomAccessMemory memory, IRegisters registers, IFlags flags,
            IEmulatorInstructionFactory instructionFactory)
 {
     Memory    = memory ?? throw new ArgumentNullException(nameof(memory));
     Registers = registers;
     this.instructionFactory = instructionFactory;
     Flags = flags;
 }
Exemplo n.º 14
0
        public Line(IFlags flags, IElementFactory elementFactory) : base(flags)
        {
            this.frame = (IFrame)Global.FrameProvider.CreateFrame(FrameType.Frame, GenerateFrameName("GHD_DocumentLine"));

            // TODO: Identify where to anchor children
            //this.FirstChild.Object.Region.SetParent(this.frame);
            //this.FirstChild.Object.Region.SetPoint(FramePoint.BOTTOMLEFT, this.frame, FramePoint.BOTTOMLEFT);
        }
Exemplo n.º 15
0
        public static void Increment(IRegister <byte> target, IFlags flags)
        {
            var old = target.Value;

            target.Value++;
            flags.Zero      = target.Value == 0;
            flags.Subtract  = false;
            flags.HalfCarry = (((old & 0xF) + 1) & 0x10) != 0;
        }
Exemplo n.º 16
0
        public static void Decrement(IRegister <byte> target, IFlags flags)
        {
            var old = target.Value;

            target.Value--;
            flags.Zero      = target.Value == 0;
            flags.Subtract  = true;
            flags.HalfCarry = (old & 0xF) < 1; // TODO check this flag
        }
Exemplo n.º 17
0
        public static void Add(IRegister <ushort> target, sbyte operand, IFlags flags)
        {
            var old = target.Value;

            target.Value    = (ushort)(target.Value + operand);
            flags.Subtract  = false;
            flags.Carry     = target.Value < old;
            flags.HalfCarry = (((old & 0xFFF) + (operand & 0xFFF)) & 0x1000) != 0;
        }
Exemplo n.º 18
0
        public static void ShiftRightArithmetic(IRegister <byte> target, IFlags flags)
        {
            flags.Carry = target.GetBit(0);
            var msbMask = target.Value & 0x80;

            target.Value   = (byte)((target.Value >> 1) | msbMask);
            flags.Subtract = flags.HalfCarry = false;
            flags.Zero     = target.Value == 0;
        }
Exemplo n.º 19
0
        public static void RotateRightThroughCarry(IRegister <byte> target, IFlags flags)
        {
            var carry = flags.Carry ? 1 : 0;

            flags.Carry    = target.GetBit(0);
            target.Value   = (byte)(carry << 7 | target.Value >> 1);
            flags.Subtract = flags.HalfCarry = false;
            flags.Zero     = target.Value == 0;
        }
Exemplo n.º 20
0
        public static void RotateLeftThroughCarry(IRegister <byte> target, IFlags flags)
        {
            var carry = flags.Carry ? 1 : 0;

            flags.Carry    = target.GetBit(7);
            target.Value   = (byte)((target.Value << 1) | carry);
            flags.Subtract = flags.HalfCarry = false;
            flags.Zero     = target.Value == 0;
        }
Exemplo n.º 21
0
        public static void Add(IRegister <byte> target, byte operand, IFlags flags)
        {
            var old = target.Value;

            target.Value   += operand;
            flags.Zero      = target.Value == 0;
            flags.Subtract  = false;
            flags.Carry     = target.Value < old;
            flags.HalfCarry = (((old & 0xF) + (operand & 0xF)) & 0x10) != 0;
        }
Exemplo n.º 22
0
        public static void Subtract(IRegister <byte> target, byte operand, IFlags flags)
        {
            var old = target.Value;

            target.Value   -= operand;
            flags.Zero      = target.Value == 0;
            flags.Subtract  = true;
            flags.Carry     = old < operand;
            flags.HalfCarry = (old & 0xF) < (operand & 0xF);
        }
Exemplo n.º 23
0
        public FormattedTextFrame(IFlags flags)
        {
            var name = GenerateFrameName();

            this.frame = (IFrame)Global.FrameProvider.CreateFrame(FrameType.Frame, name);
            this.label = this.frame.CreateFontString(name + "Label", Layer.BORDER);
            this.label.SetAllPoints(this.frame);
            this.frame.SetHeight(flags.FontSize);
            this.label.SetFont(flags.Font, flags.FontSize);
            this.label.SetJustifyH(JustifyH.LEFT);
        }
Exemplo n.º 24
0
        public static void AddPlusCarry(IRegister <byte> target, byte operand, IFlags flags)
        {
            var carry = flags.Carry ? 1 : 0;
            var old   = target.Value;

            target.Value   += (byte)(operand + carry);
            flags.Zero      = target.Value == 0;
            flags.Subtract  = false;
            flags.Carry     = ((old + operand + carry) & 0x100) != 0;
            flags.HalfCarry = (((old & 0xF) + (operand & 0xF) + carry) & 0x10) != 0;
        }
Exemplo n.º 25
0
        public static void ChangeFlag(IFlags flags, FlagType type, object details)
        {
            switch (type)
            {
            case FlagType.Alignment:
                flags.Alignment = (Alignment)Enum.Parse(typeof(Alignment), (string)details);
                break;

            case FlagType.BackgroundColor:
                if (details == null)
                {
                    flags.BackgroundColor = null;
                    return;
                }
                if (!(details is Color))
                {
                    throw new Exception("Expected Color as BackgroundColor");
                }
                flags.BackgroundColor = (Color)details;
                break;

            case FlagType.Bold:
                flags.Bold = (bool)details;
                break;

            case FlagType.Color:
                if (!(details is Color))
                {
                    throw new Exception("Expected Color as Color");
                }
                flags.Color = (Color)details;
                break;

            case FlagType.Font:
                flags.Font = (string)details;
                break;

            case FlagType.FontSize:
                flags.FontSize = (int)details;
                break;

            case FlagType.Strikethrough:
                flags.Strikethrough = (bool)details;
                break;

            case FlagType.UnderLine:
                flags.UnderLine = (bool)details;
                break;

            default:
                throw new Exception("Unknown flag type: " + type);
            }
        }
Exemplo n.º 26
0
 public bool Equals(IFlags other)
 {
     return
         (this.Bold == other.Bold &&
          this.Strikethrough == other.Strikethrough &&
          this.UnderLine == other.UnderLine &&
          this.Alignment == other.Alignment &&
          this.BackgroundColor.Equals(other.BackgroundColor) &&
          this.Color.Equals(other.Color) &&
          this.Font == other.Font &&
          this.FontSize == other.FontSize);
 }
Exemplo n.º 27
0
        public static void SubtractMinusCarry(IRegister <byte> target, byte operand, IFlags flags)
        {
            var carry = (byte)(flags.Carry ? 1 : 0);
            var old   = target.Value;

            target.Value   -= operand;
            target.Value   -= carry;
            flags.Zero      = target.Value == 0;
            flags.Subtract  = true;
            flags.Carry     = old < (operand + carry);
            flags.HalfCarry = (old & 0xF) < ((operand & 0xF) + carry);
        }
Exemplo n.º 28
0
        public Page(IFlags flags, IPageProperties properties, IElementFactory elementFactory) : base(flags)
        {
            this.flags          = flags;
            this.properties     = properties;
            this.elementFactory = elementFactory;
            this.frame          = (IFrame)Global.FrameProvider.CreateFrame(FrameType.Frame, GenerateFrameName("GHD_DocumentPage"));
            this.frame.SetWidth(this.properties.Width);
            this.frame.SetHeight(this.properties.Height);

            var texture = this.frame.CreateTexture();

            texture.SetAllPoints(this.frame);
            texture.SetTexture(0.1, 0.1, 0.1);

            this.AppendChild(elementFactory.CreateLine(flags));
            this.FirstChild.Object.Region.SetPoint(FramePoint.TOPLEFT, this.frame, FramePoint.TOPLEFT, this.properties.EdgeLeft, -this.properties.EdgeTop);
        }
Exemplo n.º 29
0
        /// <summary>
        /// Peeks the remaining text that fits the flag, until a limit by the maxLength.
        /// </summary>
        /// <param name="constraint">The constraints the text must fit.</param>
        /// <param name="flags">The flags the text must fit.</param>
        /// <returns>The peeked text.</returns>
        public string Peek(IDimensionConstraint constraint, IFlags flags)
        {
            this.ThrowIfBufferIsEmpty();

            if (constraint.MaxWidth == null)
            {
                throw new Exception("A max width must be provided in the constraint.");
            }


            var first = this.elements.First();

            if (first.Flags == null || (flags != null && !first.Flags.Equals(flags)))
            {
                return(null);
            }

            return(this.textScoper.GetFittingText(first.Flags.Font, first.Flags.FontSize, first.Text, (double)constraint.MaxWidth));
        }
Exemplo n.º 30
0
        /// <summary>
        /// Appends a text with a given set of flags to the buffer. Intended for the remaining text in a text element when inserting inside a text element.
        /// </summary>
        /// <param name="text"></param>
        /// <param name="flags"></param>
        public void Append(string text, IFlags flags)
        {
            if (this.elements.Any())
            {
                var last = this.elements[this.elements.Count - 1];
                if (last.Flags != null && last.Flags.Equals(flags))
                {
                    last.Text += text;
                    this.elements[this.elements.Count - 1] = last;
                    return;
                }
            }

            this.elements.Add(new BufferElement()
            {
                Text  = text,
                Flags = flags,
            });
        }