<commit_before>#include "CPU.h"
#include "Emulator.h"
#include "Types.h"
#include "Log.h"
#include "Random.h"
#include "Font.h"

#include <cassert>

namespace
{
using namespace Chip8;

inline int regX(const opcode_t &opcode)
{
	return ((opcode >> 8) & 0xF);
}
inline int regY(const opcode_t &opcode)
{
	return ((opcode >> 4) & 0xF);
}
}

namespace Chip8
{
CPU::CPU(Emulator *emu) : emu(emu)
{
	assert(emu != nullptr);
	reset();
}
CPU::~CPU()
{
}

void CPU::reset()
{
	pc = Memory::ROM_START;
	sp = 0;

	for (int i = 0; i < STACK_SIZE; ++i)
	{
		stack[i] = 0;
	}

	delayTimer = 0;
	soundTimer = 0;
	timeKeep = 0.f;

	I = 0;
	for (int i = 0; i < 16; ++i)
	{
		V[i] = 0;
	}
}

void CPU::step(float seconds)
{
	parseOpcode();
	tickTimers(seconds);

	emu->getSound().setInput(soundTimer > 0);
}

void CPU::parseOpcode()
{
	Memory &memory = emu->getMemory();

	opcode_t opcode = memory.read(pc);
	opcode <<= sizeof(byte_t)*8;
	opcode |= memory.read(pc+1);

	pc += sizeof(opcode_t);

	switch ((opcode >> 12) & 0xF)
	{
	case 0x0:
		switch (opcode & 0x0FFF)
		{
		case 0x0E0: emu->getDisplay().clear(); break;
		case 0x0EE: pc = pop(); break;
		default: unknownOpcode(opcode); break;<commit_msg>Slightly changed the look of a for loop<commit_after>#include "CPU.h"
#include "Emulator.h"
#include "Types.h"
#include "Log.h"
#include "Random.h"
#include "Font.h"

#include <cassert>

namespace
{
using namespace Chip8;

inline int regX(const opcode_t &opcode)
{
	return ((opcode >> 8) & 0xF);
}
inline int regY(const opcode_t &opcode)
{
	return ((opcode >> 4) & 0xF);
}
}

namespace Chip8
{
CPU::CPU(Emulator *emu) : emu(emu)
{
	assert(emu != nullptr);
	reset();
}
CPU::~CPU()
{
}

void CPU::reset()
{
	pc = Memory::ROM_START;
	sp = 0;

	for (int i = 0; i < STACK_SIZE; ++i)
	{
		stack[i] = 0;
	}

	delayTimer = 0;
	soundTimer = 0;
	timeKeep = 0.f;

	I = 0;
	for (int i = 0x0; i <= 0xF; ++i)
	{
		V[i] = 0;
	}
}

void CPU::step(float seconds)
{
	parseOpcode();
	tickTimers(seconds);

	emu->getSound().setInput(soundTimer > 0);
}

void CPU::parseOpcode()
{
	Memory &memory = emu->getMemory();

	opcode_t opcode = memory.read(pc);
	opcode <<= sizeof(byte_t)*8;
	opcode |= memory.read(pc+1);

	pc += sizeof(opcode_t);

	switch ((opcode >> 12) & 0xF)
	{
	case 0x0:
		switch (opcode & 0x0FFF)
		{
		case 0x0E0: emu->getDisplay().clear(); break;
		case 0x0EE: pc = pop(); break;
		default: unknownOpcode(opcode); break;
{'fraction_non_alphanumeric': 0.1877601998334721, 'fraction_numerical': 0.026644462947543714, 'mean_word_length': 3.9854771784232366, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2284276', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1040, 'n_words': 244}