mirror of
https://github.com/tdinucci/6502-emulator.git
synced 2024-11-27 02:49:50 +00:00
Correct page addressing and NOP handler
This commit is contained in:
parent
7474f56ac6
commit
7e4457f66f
@ -2,7 +2,11 @@
|
|||||||
|
|
||||||
namespace emu_6502 {
|
namespace emu_6502 {
|
||||||
inline uint16_t Memory::get_page_offset(uint8_t page) {
|
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() {
|
Memory::Memory() {
|
||||||
|
7
src/opcode/handler/system-opcode-handler-container.cpp
Normal file
7
src/opcode/handler/system-opcode-handler-container.cpp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "system-opcode-handler-container.h"
|
||||||
|
|
||||||
|
namespace emu_6502 {
|
||||||
|
SystemOpcodeHandlerContainer::SystemOpcodeHandlerContainer() {
|
||||||
|
handlers.insert({Op::NOP, [](Machine&) {}});
|
||||||
|
}
|
||||||
|
}
|
21
src/opcode/handler/system-opcode-handler-container.h
Normal file
21
src/opcode/handler/system-opcode-handler-container.h
Normal 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
|
@ -9,6 +9,7 @@
|
|||||||
#include "handler/stack-opcode-handler-container.h"
|
#include "handler/stack-opcode-handler-container.h"
|
||||||
#include "handler/branch-opcode-handler-container.h"
|
#include "handler/branch-opcode-handler-container.h"
|
||||||
#include "handler/jump-opcode-handler-container.h"
|
#include "handler/jump-opcode-handler-container.h"
|
||||||
|
#include "handler/system-opcode-handler-container.h"
|
||||||
#include "../utils.h"
|
#include "../utils.h"
|
||||||
|
|
||||||
namespace emu_6502 {
|
namespace emu_6502 {
|
||||||
@ -24,6 +25,7 @@ namespace emu_6502 {
|
|||||||
handler_containers.push_back(make_unique<StackOpcodeHandlerContainer>());
|
handler_containers.push_back(make_unique<StackOpcodeHandlerContainer>());
|
||||||
handler_containers.push_back(make_unique<BranchOpcodeHandlerContainer>());
|
handler_containers.push_back(make_unique<BranchOpcodeHandlerContainer>());
|
||||||
handler_containers.push_back(make_unique<JumpOpcodeHandlerContainer>());
|
handler_containers.push_back(make_unique<JumpOpcodeHandlerContainer>());
|
||||||
|
handler_containers.push_back(make_unique<SystemOpcodeHandlerContainer>());
|
||||||
|
|
||||||
init_handlers();
|
init_handlers();
|
||||||
}
|
}
|
||||||
|
25
test/system-opcode-handler-test.cpp
Normal file
25
test/system-opcode-handler-test.cpp
Normal 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());
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user