unsafe void InitMemoryDomains()
        {
            List <MemoryDomain> mm = new List <MemoryDomain>();

            for (int i = 0; ; i++)
            {
                IntPtr data     = IntPtr.Zero;
                int    size     = 0;
                bool   writable = false;
                IntPtr name     = IntPtr.Zero;

                if (!LibQuickNES.qn_get_memory_area(Context, i, ref data, ref size, ref writable, ref name))
                {
                    break;
                }

                if (data != IntPtr.Zero && size > 0 && name != IntPtr.Zero)
                {
                    mm.Add(MemoryDomain.FromIntPtr(Marshal.PtrToStringAnsi(name), size, MemoryDomain.Endian.Little, data, writable));
                }
            }
            // add system bus
            mm.Add(new MemoryDomain
                   (
                       "System Bus",
                       0x10000,
                       MemoryDomain.Endian.Unknown,
                       delegate(long addr)
            {
                if (addr < 0 || addr >= 0x10000)
                {
                    throw new ArgumentOutOfRangeException();
                }

                return(LibQuickNES.qn_peek_prgbus(Context, (int)addr));
            },
                       delegate(long addr, byte val)
            {
                if (addr < 0 || addr >= 0x10000)
                {
                    throw new ArgumentOutOfRangeException();
                }

                LibQuickNES.qn_poke_prgbus(Context, (int)addr, val);
            }
                   ));

            _memoryDomains = new MemoryDomainList(mm);
            (ServiceProvider as BasicServiceProvider).Register <IMemoryDomains>(_memoryDomains);
        }
Пример #2
0
        unsafe void InitMemoryDomains()
        {
            List <MemoryDomain> mm = new List <MemoryDomain>();

            for (int i = 0; ; i++)
            {
                IntPtr data     = IntPtr.Zero;
                int    size     = 0;
                bool   writable = false;
                IntPtr name     = IntPtr.Zero;

                if (!LibQuickNES.qn_get_memory_area(Context, i, ref data, ref size, ref writable, ref name))
                {
                    break;
                }

                if (data != IntPtr.Zero && size > 0 && name != IntPtr.Zero)
                {
                    byte *p = (byte *)data;

                    mm.Add(new MemoryDomain
                           (
                               Marshal.PtrToStringAnsi(name),
                               size,
                               MemoryDomain.Endian.Unknown,
                               delegate(int addr)
                    {
                        if (addr < 0 || addr >= size)
                        {
                            throw new ArgumentOutOfRangeException();
                        }
                        return(p[addr]);
                    },
                               delegate(int addr, byte val)
                    {
                        if (!writable)
                        {
                            return;
                        }
                        if (addr < 0 || addr >= size)
                        {
                            throw new ArgumentOutOfRangeException();
                        }
                        p[addr] = val;
                    }
                           ));
                }
            }
            // add system bus
            mm.Add(new MemoryDomain
                   (
                       "System Bus",
                       0x10000,
                       MemoryDomain.Endian.Unknown,
                       delegate(int addr)
            {
                if (addr < 0 || addr >= 0x10000)
                {
                    throw new ArgumentOutOfRangeException();
                }
                return(LibQuickNES.qn_peek_prgbus(Context, addr));
            },
                       delegate(int addr, byte val)
            {
                if (addr < 0 || addr >= 0x10000)
                {
                    throw new ArgumentOutOfRangeException();
                }
                LibQuickNES.qn_poke_prgbus(Context, addr, val);
            }
                   ));
            MemoryDomains = new MemoryDomainList(mm, 0);
        }