Ensure the MOS6502 unit tests run successfully to completion.

Signed-off-by: Adrian.Conlon <adrian.conlon@gmail.com>
This commit is contained in:
Adrian.Conlon 2017-09-07 00:58:56 +01:00
parent 74a62f554d
commit c472d70c5c
6 changed files with 48 additions and 43 deletions

View File

@ -72,7 +72,7 @@ namespace EightBit {
}
std::string AM_Absolute() const {
return "$" + dump_WordValue(processor.getMemory().peekWord(m_address + 1));
return "$" + dump_WordValue(processor.BUS().peekWord(m_address + 1));
}
std::string AM_ZeroPage_dump() const {

View File

@ -6,9 +6,9 @@
#include <functional>
#include <cassert>
#include "Memory.h"
#include "Processor.h"
#include "Signal.h"
#include <Bus.h>
#include <Processor.h>
#include <Signal.h>
namespace EightBit {
class MOS6502 : public Processor {
@ -41,7 +41,7 @@ namespace EightBit {
CF = Bit0, // Carry
};
MOS6502(Memory& memory);
MOS6502(Bus& bus);
Signal<MOS6502> ExecutingInstruction;
Signal<MOS6502> ExecutedInstruction;
@ -156,16 +156,16 @@ namespace EightBit {
uint8_t AM_AbsoluteX() {
Address_AbsoluteX();
m_memory.ADDRESS() = MEMPTR();
if (m_memory.ADDRESS().low == Mask8)
BUS().ADDRESS() = MEMPTR();
if (BUS().ADDRESS().low == Mask8)
++cycles;
return getByte();
}
uint8_t AM_AbsoluteY() {
Address_AbsoluteY();
m_memory.ADDRESS() = MEMPTR();
if (m_memory.ADDRESS().low == Mask8)
BUS().ADDRESS() = MEMPTR();
if (BUS().ADDRESS().low == Mask8)
++cycles;
return getByte();
}
@ -187,8 +187,8 @@ namespace EightBit {
uint8_t AM_IndirectIndexedY() {
Address_IndirectIndexedY();
m_memory.ADDRESS() = MEMPTR();
if (m_memory.ADDRESS().low == Mask8)
BUS().ADDRESS() = MEMPTR();
if (BUS().ADDRESS().low == Mask8)
++cycles;
return getByte();
}

View File

@ -43,13 +43,13 @@ std::string EightBit::Disassembly::disassemble(uint16_t current) const {
std::ostringstream output;
auto memory = processor.getMemory();
auto& bus = processor.BUS();
auto cell = memory.peek(current);
auto cell = bus.peek(current);
output << dump_ByteValue(cell);
auto byte = memory.peek(current + 1);
auto byte = bus.peek(current + 1);
uint16_t relative = processor.PC().word + 2 + (int8_t)byte;
auto aaa = (cell & 0b11100000) >> 5;
@ -322,7 +322,7 @@ std::string EightBit::Disassembly::disassemble(uint16_t current) const {
////
uint8_t EightBit::Disassembly::getByte(uint16_t address) const {
return processor.getMemory().peek(address);
return processor.BUS().peek(address);
}
////

View File

@ -1,8 +1,8 @@
#include "stdafx.h"
#include "mos6502.h"
EightBit::MOS6502::MOS6502(Memory& memory)
: Processor(memory) {
EightBit::MOS6502::MOS6502(Bus& bus)
: Processor(bus) {
m_timings = {
//// 0 1 2 3 4 5 6 7 8 9 A B C D E F
/* 0 */ 7, 6, 0, 0, 0, 4, 5, 0, 3, 2, 2, 0, 0, 4, 6, 0,
@ -60,17 +60,17 @@ void EightBit::MOS6502::triggerNMI() {
void EightBit::MOS6502::getWord(register16_t& output) {
output.low = getByte();
m_memory.ADDRESS().word++;
BUS().ADDRESS().word++;
output.high = getByte();
}
void EightBit::MOS6502::getWord(uint16_t offset, register16_t& output) {
m_memory.ADDRESS().word = offset;
BUS().ADDRESS().word = offset;
getWord(output);
}
void EightBit::MOS6502::getWord(const register16_t& offset, register16_t& output) {
m_memory.ADDRESS() = offset;
BUS().ADDRESS() = offset;
getWord(output);
}

View File

@ -9,8 +9,8 @@
Board::Board(const Configuration& configuration)
: m_configuration(configuration),
m_memory(0xffff),
m_cpu(EightBit::MOS6502(m_memory)),
m_ram(0x10000),
m_cpu(EightBit::MOS6502(*this)),
m_symbols(""),
m_disassembler(m_cpu, m_symbols),
m_profiler(m_cpu, m_disassembler, m_symbols),
@ -20,18 +20,16 @@ Board::Board(const Configuration& configuration)
void Board::initialise() {
m_memory.clear();
auto programFilename = m_configuration.getProgram();
auto programPath = m_configuration.getRomDirectory() + "\\" + m_configuration.getProgram();
auto loadAddress = m_configuration.getLoadAddress();
switch (m_configuration.getLoadMethod()) {
case Configuration::LoadMethod::Ram:
m_memory.loadRam(programPath, loadAddress);
m_ram.load(programPath, loadAddress);
break;
case Configuration::LoadMethod::Rom:
m_memory.loadRom(programPath, loadAddress);
// m_rom.load(programPath, loadAddress);
break;
}
@ -54,12 +52,12 @@ void Board::initialise() {
}
if (m_configuration.allowInput()) {
m_memory.ReadByte.connect(std::bind(&Board::Memory_ReadByte_Input, this, std::placeholders::_1));
ReadByte.connect(std::bind(&Board::Memory_ReadByte_Input, this, std::placeholders::_1));
m_cpu.ExecutedInstruction.connect(std::bind(&Board::Cpu_ExecutedInstruction_Poll, this, std::placeholders::_1));
}
if (m_configuration.allowOutput())
m_memory.WrittenByte.connect(std::bind(&Board::Memory_WrittenByte_Output, this, std::placeholders::_1));
WrittenByte.connect(std::bind(&Board::Memory_WrittenByte_Output, this, std::placeholders::_1));
m_pollCounter = 0;
m_pollInterval = m_configuration.getPollInterval();
@ -81,7 +79,7 @@ void Board::Cpu_ExecutedInstruction_StopLoop(const EightBit::MOS6502& cpu) {
auto pc = m_cpu.PC().word;
if (m_oldPC == pc) {
m_cpu.halt();
auto test = m_memory.peek(0x0200);
auto test = peek(0x0200);
std::cout << std::endl << "** Test=" << std::hex << (int)test;
} else {
m_oldPC = pc;
@ -91,7 +89,7 @@ void Board::Cpu_ExecutedInstruction_StopLoop(const EightBit::MOS6502& cpu) {
void Board::Cpu_ExecutingInstruction_Debug(const EightBit::MOS6502& cpu) {
auto address = m_cpu.PC().word;
auto cell = m_memory.peek(address);
auto cell = peek(address);
std::cout << std::hex;
std::cout << "PC=" << std::setw(4) << std::setfill('0') << address << ":";
@ -112,8 +110,8 @@ void Board::Memory_ReadByte_Input(const EightBit::AddressEventArgs& e) {
if (address == m_configuration.getInputAddress()) {
auto cell = e.getCell();
if (cell != 0) {
assert(address == m_memory.ADDRESS().word);
m_memory.write(0);
assert(address == ADDRESS().word);
write(0);
}
}
}
@ -133,5 +131,5 @@ void Board::Cpu_ExecutedInstruction_Poll(const EightBit::MOS6502& cpu) {
void Board::pollKeyboard() {
if (_kbhit())
m_memory.poke(m_configuration.getInputAddress(), _getch());
poke(m_configuration.getInputAddress(), _getch());
}

View File

@ -1,27 +1,34 @@
#pragma once
#include "Configuration.h"
#include <string>
#include "Memory.h"
#include "Configuration.h"
#include "Profiler.h"
#include "EventArgs.h"
#include "Disassembly.h"
#include "mos6502.h"
#include "Symbols.h"
#include <Ram.h>
#include <Bus.h>
#include <Profiler.h>
#include <EventArgs.h>
#include <Disassembly.h>
#include <mos6502.h>
#include <Symbols.h>
class Board {
class Board : public EightBit::Bus {
public:
Board(const Configuration& configuration);
EightBit::Memory& Memory() { return m_memory; }
EightBit::MOS6502& CPU() { return m_cpu; }
void initialise();
protected:
virtual uint8_t& reference(uint16_t address, bool& rom) {
rom = false;
return m_ram.reference(address);
}
private:
const Configuration& m_configuration;
EightBit::Memory m_memory;
EightBit::Ram m_ram;
EightBit::MOS6502 m_cpu;
EightBit::Symbols m_symbols;
EightBit::Disassembly m_disassembler;