Correct page addressing and NOP handler

This commit is contained in:
Tony Di Nucci 2019-04-28 13:16:57 +01:00
parent 7474f56ac6
commit 7e4457f66f
5 changed files with 60 additions and 1 deletions

View File

@ -2,7 +2,11 @@
namespace emu_6502 {
inline uint16_t Memory::get_page_offset(uint8_t page) {
return page * 0xFF;
uint16_t address = page * 0xFF;
if (page > 0)
address += 1;
return address;
}
Memory::Memory() {

View File

@ -0,0 +1,7 @@
#include "system-opcode-handler-container.h"
namespace emu_6502 {
SystemOpcodeHandlerContainer::SystemOpcodeHandlerContainer() {
handlers.insert({Op::NOP, [](Machine&) {}});
}
}

View File

@ -0,0 +1,21 @@
#ifndef INC_6502_EMULATOR_SYSTEM_OPCODE_HANDLER_CONTAINER_H
#define INC_6502_EMULATOR_SYSTEM_OPCODE_HANDLER_CONTAINER_H
#include "opcode-handler-container.h"
namespace emu_6502 {
class SystemOpcodeHandlerContainer : public OpcodeHandlerContainer {
private:
enum Op {
NOP = 0xEA
};
public:
SystemOpcodeHandlerContainer();
SystemOpcodeHandlerContainer(const SystemOpcodeHandlerContainer& other) = delete;
SystemOpcodeHandlerContainer operator=(const SystemOpcodeHandlerContainer& other) = delete;
};
}
#endif //INC_6502_EMULATOR_SYSTEM_OPCODE_HANDLER_CONTAINER_H

View File

@ -9,6 +9,7 @@
#include "handler/stack-opcode-handler-container.h"
#include "handler/branch-opcode-handler-container.h"
#include "handler/jump-opcode-handler-container.h"
#include "handler/system-opcode-handler-container.h"
#include "../utils.h"
namespace emu_6502 {
@ -24,6 +25,7 @@ namespace emu_6502 {
handler_containers.push_back(make_unique<StackOpcodeHandlerContainer>());
handler_containers.push_back(make_unique<BranchOpcodeHandlerContainer>());
handler_containers.push_back(make_unique<JumpOpcodeHandlerContainer>());
handler_containers.push_back(make_unique<SystemOpcodeHandlerContainer>());
init_handlers();
}

View File

@ -0,0 +1,25 @@
#include "gtest/gtest.h"
#include "test-utils.h"
using namespace std;
using namespace emu_6502;
const uint8_t NOP = 0xEA;
const uint8_t LDA_IMM = 0xA9;
TEST(SystemOpcodeHandlerContainer, NOP) {
auto machine = create_machine({NOP, NOP, NOP, NOP});
machine->execute();
ASSERT_TRUE(are_flags_set(machine->get_cpu().get_ps(), RegisterFlagSet{}));
ASSERT_EQ(0x604, machine->get_cpu().get_pc().get_value());
}
TEST(SystemOpcodeHandlerContainer, NOP2) {
auto machine = create_machine({NOP, NOP, NOP, LDA_IMM, 0x35, NOP});
machine->execute();
ASSERT_EQ(0x35, machine->get_cpu().get_a().get_value());
ASSERT_TRUE(are_flags_set(machine->get_cpu().get_ps(), RegisterFlagSet{}));
ASSERT_EQ(0x606, machine->get_cpu().get_pc().get_value());
}