Beispiel #1
0
        /// <summary>
        /// Spins through the <see cref="InstructionCollection"/> and creates an array of bytes
        /// that is then copied into Memory by <see cref="OS.createProcess"/>
        /// </summary>
        /// <returns>Array of bytes representing the <see cref="Program"/> in memory</returns>
        unsafe public byte[] GetMemoryImage()
        {
            ArrayList arrayListInstr = new ArrayList();

            foreach (Instruction instr in instructions)
            {
                // Instructions are one byte
                arrayListInstr.Add((byte)instr.OpCode);

                // Params are Four Bytes
                if (instr.Param1 != uint.MaxValue)
                {
                    byte[] paramBytes = CPU.UIntToBytes(instr.Param1);
                    for (int i = 0; i < paramBytes.Length; i++)
                    {
                        arrayListInstr.Add(paramBytes[i]);
                    }
                }

                if (instr.Param2 != uint.MaxValue)
                {
                    byte[] paramBytes = CPU.UIntToBytes(instr.Param2);
                    for (int i = 0; i < paramBytes.Length; i++)
                    {
                        arrayListInstr.Add(paramBytes[i]);
                    }
                }
            }

            // Create and array of bytes and return the instructions in it
            arrayListInstr.TrimToSize();
            byte[] arrayInstr = new byte[arrayListInstr.Count];
            arrayListInstr.CopyTo(arrayInstr);
            return(arrayInstr);
        }
Beispiel #2
0
 /// <summary>
 /// Sets a 4 byte unsigned integer (typically an opCode param) to memory
 /// </summary>
 /// <param name="processid">The calling processid</param>
 /// <param name="processIndex">The address in memory from the Process's point of view</param>
 /// <param name="avalue">The new value</param>
 public void setUIntAt(uint processid, uint processIndex, uint avalue)
 {
     setBytesAt(processid, processIndex, CPU.UIntToBytes(avalue));
 }