Пример #1
0
        /// <summary>
        /// Write an integer value to the binary rom image.
        /// </summary>
        /// <param name="mdInt">The value to write.</param>
        public void writeInt(MDInteger mdInt)
        {
            //move to the correct position
            this.setStreamPosition(this.writer.BaseStream, mdInt.Address);

            /*
             * OK, yes this is converting the number to hex before writing it.
             * This is purely done to make debugging easier. Set a breakpoint at the next for loop to see how
             * Sure, it could perform better but it's not like we're running millions of transactions through it.
             */
            String hexString      = mdInt.CurrentValue.ToString("X");
            int    length         = hexString.Length;
            int    expectedLength = mdInt.NumBytes * 2;

            while (length < expectedLength)
            {
                hexString = "0" + hexString;
                length++;
            }
            for (int index = 0; index < length; index += 2)
            {
                String substring = hexString.Substring(index, 2);
                byte   b         = Convert.ToByte(substring, 16);
                this.writer.Write(b);
            }
        }
Пример #2
0
        /// <summary>
        /// Writes the checksum value to the ROM.
        /// </summary>
        /// <param name="newChecksum">The new checksum value to store in the ROM.</param>
        public void writeChecksum(int newChecksum)
        {
            MDInteger mdInt = new MDInteger();

            mdInt.CurrentValue = newChecksum;
            mdInt.NumBytes     = 2;
            mdInt.Address      = CHECKSUM_ADDRESS;
            this.writeInt(mdInt);
        }
Пример #3
0
 /// <summary>
 /// Writes palette data to the ROM image.
 /// </summary>
 /// <param name="palette">The palette data to write, expected to contain Palette.SIZE entries.</param>
 /// <param name="offset">The address to start at.</param>
 public void writePalette(Palette palette, int offset)
 {
     for (int index = 0; index < Palette.SIZE; index++)
     {
         MDInteger mdint = new MDInteger();
         mdint.CurrentValue = palette.Entries[index].ToUInt();
         mdint.NumBytes     = 2;
         mdint.Address      = offset + (2 * index);
         this.writeInt(mdint);
     }
 }