Example #1
0
void CPU::Update()
{
	const int MAXCYCLES = 70221;
	int cyclesThisUpdate = 0;

	while (cyclesThisUpdate < MAXCYCLES)
	{

		if (shouldDisableInterrupts)
		{
			interruptMasterEnable = false;
			shouldDisableInterrupts = false;
		}

		if (shouldEnableInterrupts)
		{
			interruptMasterEnable = true;
			shouldEnableInterrupts = false;
		}

		Instruction *instruction = InvokeInstruction(ReadByte(PC));
		int cycles = instruction->GetDuration();

		cyclesThisUpdate += cycles;
		UpdateTimers(cycles);
		UpdateGraphics(cycles);
		HandleInterrupts();
	}
}
void CPUWrapper::TestJump(int opcode)
{
	if (testType == IMM_8)
	{
		lastImm8Arg = processor->ReadImm8Arg();
	}
	else if (testType == IMM_16)
	{
		lastImm16Arg = processor->ReadImm16Arg();
	}

	Instruction *instruction = processor->instructions[opcode];
	instruction->Call();

	assert(instruction->GetDuration() == expectedCyclesVarying);
	assert(PC() == expectedPC);

	CheckFlags();
}
void CPUWrapper::TestInstruction(int opcode)
{
	ushort oldPC = PC();

	if (testType == IMM_8)
	{
		lastImm8Arg = processor->ReadImm8Arg();
	}
	else if (testType == IMM_16)
	{
		lastImm16Arg = processor->ReadImm16Arg();
	}

	Instruction *instruction = processor->instructions[opcode];
	instruction->Call();

	assert(instruction->GetDuration() == expectedCycles[opcode]);
	assert(oldPC + expectedPCAdvance[opcode] == PC());

	CheckFlags();
}