Example #1
0
        public CPU(string romPath)
        {
            memory = new Memory(romPath);
            OpcodeTable.GenerateOpcodeTable();
            opcodeTable = OpcodeTable.OPCODE_TABLE;

            // Test
            //A = 0x11;
            memory[0xFF44] = 0x91;
        }
Example #2
0
 public void Tick()
 {
     if (!opcode.MoveNext())
     {
         if (OpcodeTable.ContainsKey(memory[reg.PC]))
         {
             opcode = OpcodeTable.Call(memory[reg.PC], memory, reg);
             // Fetch takes 1 cycle
             Debug.Log("\n{0:X2} - ", reg);
         }
         else
         {
             Console.Write("\nUnknown Opcode: {0:X2} at {1:X4}", memory[reg.PC], reg.PC);
             Console.Write(" - {0}", reg);
             alive = false;
         }
     }
 }
Example #3
0
        public CPU(string romPath, string savePath)
        {
            memory = new Memory(romPath);
            OpcodeTable.GenerateOpcodeTable();
            opcodeTable = OpcodeTable.OPCODE_TABLE;

            Debug.Log("\nLoading save state from file...");
            byte[] stateDump   = File.ReadAllBytes(savePath);
            int    lenCpuState = 2 + 2 + 1 + reg.Length;

            PC               = stateDump[0] | (stateDump[1] << 8);
            SP               = stateDump[2] | (stateDump[3] << 8);
            interrupts       = (stateDump[4] & 0x1) == 0x1;
            toggleInterrupts = (stateDump[4] & 0x2) == 0x2;
            Debug.Log("\nLoading register values from state dump...");
            Array.Copy(stateDump, 5, reg, 0, reg.Length);

            Debug.Log("\nCreating new array with ram dump data...");
            byte[] ramDump = new byte[stateDump.Length - lenCpuState];
            Array.Copy(stateDump, lenCpuState, ramDump, 0, ramDump.Length);
            Debug.Log("\nPassing ram dump to memory class...");
            memory.loadRAM(ramDump);
        }