Esempio n. 1
0
 public Core(int _id, Processor prnt)
 {
     _coreId           = _id;
     parent            = prnt;
     instructionsCache = new InstructionCache(4);
     dataCache         = new DataCache(4);
 }
Esempio n. 2
0
        protected SimInstruction GetInstruction(ulong address)
        {
            SimInstruction instruction = null;

            InstructionCache.TryGetValue(address, out instruction);

            return(instruction);
        }
Esempio n. 3
0
        public ZRoutineTable(Story story, InstructionCache cache = null)
        {
            this.story           = story;
            this.cache           = cache ?? new InstructionCache(8192);
            this.routines        = new IntegerMap <ZRoutine>(8192);
            this.sortedAddresses = new List <int>();

            Add(story.MainRoutineAddress, "Main");
        }
Esempio n. 4
0
        public static ZRoutine Create(int address, byte[] memory, InstructionCache cache = null, string name = null)
        {
            var version = memory.ReadByte(0);

            var startAddress = address;
            var locals       = ReadLocals(ref address, memory, version);
            var instructions = ReadInstructions(address, memory, cache);

            return(new ZRoutine(startAddress, instructions, locals, name));
        }
Esempio n. 5
0
        private static Instruction[] ReadInstructions(int address, byte[] memory, InstructionCache cache)
        {
            var reader           = new InstructionReader(address, memory, cache);
            var instructions     = new List <Instruction>();
            var lastKnownAddress = address;

            while (true)
            {
                var i = reader.NextInstruction();

                instructions.Add(i);

                if ((i.Opcode.IsReturn || i.Opcode.IsQuit) && reader.Address > lastKnownAddress)
                {
                    break;
                }
                else if (i.Opcode.IsJump)
                {
                    var jumpOffset  = (short)i.Operands[0].Value;
                    var jumpAddress = reader.Address + jumpOffset - 2;
                    if (jumpAddress > lastKnownAddress)
                    {
                        lastKnownAddress = jumpAddress;
                    }

                    if (reader.Address > lastKnownAddress)
                    {
                        break;
                    }
                }
                else if (i.HasBranch && i.Branch.Kind == BranchKind.Address)
                {
                    var branchAddress = reader.Address + i.Branch.Offset - 2;
                    if (branchAddress > lastKnownAddress)
                    {
                        lastKnownAddress = branchAddress;
                    }
                }
            }

            return(instructions.ToArray());
        }
Esempio n. 6
0
        private Story(byte[] memory)
        {
            this.memory               = memory;
            this.version              = Header.ReadVersion(memory);
            this.serialNumber         = Header.ReadSerialNumber(memory);
            this.releaseNumber        = Header.ReadReleaseNumber(memory);
            this.checksum             = Header.ReadChecksum(memory);
            this.actualChecksum       = Header.CalculateChecksum(memory);
            this.routinesOffset       = Header.ReadRoutinesOffset(memory);
            this.stringsOffset        = Header.ReadStringsOffset(memory);
            this.instructionCache     = new InstructionCache((memory.Length - Header.ReadStaticMemoryBase(memory)) / 8);
            this.ztext                = new ZText(memory);
            this.memoryMap            = new MemoryMap(memory);
            this.informData           = new InformData(memory, this.memoryMap, ztext);
            this.objectTable          = new ZObjectTable(memory, ztext);
            this.globalVariablesTable = new GlobalVariablesTable(memory);
            this.dictionary           = new ZDictionary(this, ztext);
            this.mainRoutineAddress   = Header.ReadMainRoutineAddress(memory);

            RegisterInterpreter(new DefaultInterpreter());
        }
Esempio n. 7
0
 public void AddInstruction(ulong address, SimInstruction instruction)
 {
     //Debug.Assert(!InstructionCache.ContainsKey(address), instruction.ToString());
     InstructionCache.Add(address, instruction);
 }