Exemplo n.º 1
0
        public static CartridgeCrt FromBytes(byte[] data)
        {
            var crt = new CartridgeCrt {
                Header = CrtHeader.FromBytes(data)
            };

            var offset = 0x40;

            while (offset < data.Length)
            {
                var chip = CrtChip.FromBytes(data.Skip(offset).ToArray());
                crt.Chips.Add(chip);
                offset += (int)chip.ChipLength;
            }

            return(crt);
        }
Exemplo n.º 2
0
        public static CrtChip FromBytes(byte[] data)
        {
            var c = new CrtChip();

            c.Identifier = Encoding.ASCII.GetString(data, 0, 0x04);

            if (c.Identifier.ToUpper() != "CHIP")
            {
                throw new FileFormatException(".CRT CHIP-packet identifier is not correct.");
            }

            c.ChipLength = BitConverter.ToUInt32(data.Skip(0x04).Take(sizeof(UInt32)).Reverse().ToArray(), 0);
            c.ChipType   = (CrtChipType)BitConverter.ToUInt16(data.Skip(0x08).Take(sizeof(UInt16)).Reverse().ToArray(), 0);
            c.Bank       = BitConverter.ToUInt16(data.Skip(0x0A).Take(sizeof(UInt16)).Reverse().ToArray(), 0);
            c.Address    = BitConverter.ToUInt16(data.Skip(0x0C).Take(sizeof(UInt16)).Reverse().ToArray(), 0);
            c.Length     = BitConverter.ToUInt16(data.Skip(0x0E).Take(sizeof(UInt16)).Reverse().ToArray(), 0);

            c.Data = data.Skip(0x10).Take(c.Length).ToArray();

            return(c);
        }