Ypsilon.Emulation.Processor.YCPU.ReadMemInt16 C# (CSharp) Method

ReadMemInt16() public method

Reads a 16-bit value from the address specified.
public ReadMemInt16 ( ushort address, SegmentIndex segment ) : ushort
address ushort
segment SegmentIndex
return ushort
        public ushort ReadMemInt16(ushort address, SegmentIndex segment)
        {
            Segment s = GetSegment(segment);
            if (s == null)
                throw new Exception("Unknown segment referenced in DebugReadMemory");
            if ((address & 0x0001) == 0x0001) {
                // This read is not 16-bit aligned. Two memory accesses needed.
                Cycles += 2;
                byte byte0 = s[address];
                byte byte1 = s[(ushort)(address + 1)];
                return (ushort)((byte1 << 8) + byte0);
            }
            else {
                // This read is 16-bit aligned. Only one memory access is needed.
                Cycles += 1;
                byte byte0 = s[address];
                byte byte1 = s[(ushort)(address + 1)];
                return (ushort)((byte1 << 8) + byte0);
            }
        }