~williamvds/microlator

eb2b80148a000aecc674c8aeb2aeb451f882133a — williamvds 3 years ago 1de8691
Add microlator namespace
4 files changed, 24 insertions(+), 8 deletions(-)

M src/cpu.cpp
M src/cpu.hpp
M test/nestest.hpp
M test/testCPU.cpp
M src/cpu.cpp => src/cpu.cpp +10 -2
@@ 5,12 5,12 @@

#include "cpu.hpp"

namespace {

constexpr auto u8Max = 0xffU;
constexpr auto u8Modulo = 0x100U;
constexpr auto u16Upper = 0xff00U;

using F = Flags::Index;

constexpr auto toU8(auto value) {
	return static_cast<uint8_t>(value);
}


@@ 44,6 44,12 @@ constexpr auto wrapToByte(size_t value) -> uint8_t {
	return toU8(value % u8Modulo);
}

} // namespace

namespace microlator {

using F = Flags::Index;

constexpr void ValueStore::write(uint8_t newValue) noexcept {
	assert(type != Type::Implicit
		&& type != Type::Value);


@@ 681,3 687,5 @@ constexpr auto CPU::getInstructions() -> Instructions {
		{                 }, {&C::oSBC, M::AbsX}, {&C::oINC, M::AbsX}, {},
	}};
}

} // namespace microlator

M src/cpu.hpp => src/cpu.hpp +4 -0
@@ 5,6 5,8 @@
#include <functional>
#include <span>

namespace microlator {

class CPU;

enum class AddressMode {


@@ 259,3 261,5 @@ constexpr ValueStore::ValueStore(CPU& cpu)
constexpr auto ValueStore::get() const noexcept -> uint16_t {
	return value;
}

} // namespace microlator

M test/nestest.hpp => test/nestest.hpp +3 -1
@@ 7,13 7,15 @@

#include "cpu.hpp"

namespace emu = microlator;

struct cpuState {
	uint16_t pc;
	const char *dis;
	uint8_t a;
	uint8_t x;
	uint8_t y;
	Flags p;
	emu::Flags p;
	uint8_t sp;
	uint16_t ppuX;
	uint16_t ppuY;

M test/testCPU.cpp => test/testCPU.cpp +7 -5
@@ 6,10 6,12 @@
#include "cpu.hpp"
#include "nestest.hpp"

namespace emu = microlator;

namespace Catch {
	template<>
	struct StringMaker<Flags> {
		static auto convert(const Flags& value) -> std::string {
	struct StringMaker<emu::Flags> {
		static auto convert(const emu::Flags& value) -> std::string {
			constexpr auto flags = std::to_array<char>({
				'C', 'Z', 'I', 'D', 'B', '-', 'V', 'N'
			});


@@ 19,7 21,7 @@ namespace Catch {
			for (size_t i = 0; i <= flags.size(); i++) {
				size_t bit = flags.size() - i;
				os <<
					(value.test(static_cast<Flags::Index>(bit))
					(value.test(static_cast<emu::Flags::Index>(bit))
					? flags.at(bit)
					: ' ');
			}


@@ 31,14 33,14 @@ namespace Catch {
} // namespace Catch

TEST_CASE("CPU can execute", "[cpu]") {
	auto cpu = CPU();
	auto cpu = emu::CPU();
	cpu.step();

	REQUIRE(cpu.pc == 0x601);
}

TEST_CASE("CPU passes nestest", "[cpu]") {
	auto cpu = CPU();
	auto cpu = emu::CPU();
	cpu.loadProgram(nestestProgram, 0x8000);
	cpu.loadProgram(nestestProgram, 0xC000);