using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Interop;

namespace TwoMbit
{
    public class Memory
    {
        uint size;
        byte[] data;
        GCHandle gchandle;

        public Memory()
        {
            size = 0;
            data = null;
        }

        public Memory(uint size)
        {
            map(new byte[size], size);
        }

        public void map(byte[] data, uint size)
        {
            this.data = data;
            this.size = size;
        }

        public byte[] getData()
        {
            return data;
        }

        public uint getSize()
        {
            return size;
        }

        public byte read(uint addr)
        {
            return data[addr];
        }

        public void write(uint addr, byte value)
        {
            data[addr] = value;
        }

        public void pinning() {
            gchandle = GCHandle.Alloc(data, GCHandleType.Pinned);
        }

        public void unpinning() {
            gchandle.Free();
        }
    }
}
