Esempio n. 1
0
        public byte[] this[uint index, int size]
        {
            get
            {
                uint     nonCachedIndex = TLB.TranslateAddress(index) & 0x1FFFFFFF;
                byte[]   result         = new byte[size];
                MemEntry Entry          = GetEntry(nonCachedIndex);

                if (Entry.ReadArray == null)
                {
                    throw new Common.Exceptions.MemoryProtectionViolation($"Memory at \"0x{index:x8}\" is not readable.");
                }

                Buffer.BlockCopy(Entry.ReadArray, (int)(nonCachedIndex - Entry.StartAddress), result, 0, size);

                Entry.ReadEvent?.Invoke();

                return(result);
            }
            set
            {
                uint     nonCachedIndex = TLB.TranslateAddress(index) & 0x1FFFFFFF;
                MemEntry Entry          = GetEntry(nonCachedIndex);

                if (Entry.WriteArray == null)
                {
                    throw new Common.Exceptions.MemoryProtectionViolation($"Memory at \"0x{index:x8}\" is not writable.");
                }

                Buffer.BlockCopy(value, 0, Entry.WriteArray, (int)(nonCachedIndex - Entry.StartAddress), size);

                Entry.WriteEvent?.Invoke();
            }
        }
Esempio n. 2
0
        private MemEntry GetEntry(uint index)
        {
            bool     FoundEntry = false;
            MemEntry Result     = new MemEntry();

            for (int i = 0; i < MemoryMap.Length; ++i)
            {
                MemEntry CurrentEntry = MemoryMap[i];
                if (index < CurrentEntry.StartAddress || index > CurrentEntry.EndAddress)
                {
                    continue;
                }

                FoundEntry = true;
                Result     = CurrentEntry;
                break;
            }

            if (!FoundEntry)
            {
                throw new Common.Exceptions.InvalidOrUnimplementedMemoryMapException($"\"0x{index:x8}\" does not pertain to any mapped memory." +
                                                                                     $"  PC: 0x{Registers.R4300.PC:x8}");
            }

            return(Result);
        }
Esempio n. 3
0
        public byte this[uint index]
        {
            get
            {
                uint     nonCachedIndex = TLB.TranslateAddress(index) & 0x1FFFFFFF;
                MemEntry Entry          = GetEntry(nonCachedIndex);

                if (Entry.ReadArray == null)
                {
                    throw new Common.Exceptions.MemoryProtectionViolation($"Memory at \"0x{index:x8}\" is not readable.");
                }

                return(Entry.ReadArray[nonCachedIndex - Entry.StartAddress]);
            }
            set
            {
                uint     nonCachedIndex = TLB.TranslateAddress(index) & 0x1FFFFFFF;
                MemEntry Entry          = GetEntry(nonCachedIndex);

                if (Entry.WriteArray == null)
                {
                    throw new Common.Exceptions.MemoryProtectionViolation($"Memory at \"0x{index:x8}\" is not writable.");
                }

                Entry.WriteArray[nonCachedIndex - Entry.StartAddress] = value;
            }
        }
Esempio n. 4
0
        internal List <MemEntry> Read()
        {
            string filepath = Path.Join(InputPath, MemListFileName);

            if (!File.Exists(filepath))
            {
                throw new BytecodeReaderException($"Memlist file not found at {filepath}");
            }

            using (BinaryReader reader = new BinaryReader(File.OpenRead(filepath)))
            {
                var memEntries = new List <MemEntry>();

                var memEntry = new MemEntry();
                while (memEntry.state != MemEntryState.END_OF_MEMLIST)
                {
                    memEntry.state = reader.ReadByte();
                    memEntry.type  = reader.ReadByte();

                    // skip the bufptr
                    reader.ReadUInt16BE();

                    memEntry.unk4       = reader.ReadUInt16BE();
                    memEntry.rankNum    = reader.ReadByte();
                    memEntry.bankId     = reader.ReadByte();
                    memEntry.bankOffset = reader.ReadUInt32BE();
                    memEntry.unkC       = reader.ReadUInt16BE();
                    memEntry.packedSize = reader.ReadUInt16BE();
                    memEntry.unk10      = reader.ReadUInt16BE();
                    memEntry.size       = reader.ReadUInt16BE();

                    memEntries.Add(memEntry);
                }

                return(memEntries);
            }
        }