2017-07-05 16:46:02 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "Board.h"
|
|
|
|
#include "Disassembly.h"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <iomanip>
|
2017-07-08 00:04:20 +00:00
|
|
|
#include <assert.h>
|
2017-07-05 16:46:02 +00:00
|
|
|
|
|
|
|
Board::Board(const Configuration& configuration)
|
2018-11-18 13:52:43 +00:00
|
|
|
: m_configuration(configuration) {}
|
2017-07-05 16:46:02 +00:00
|
|
|
|
2019-01-14 02:10:17 +00:00
|
|
|
void Board::raisePOWER() {
|
|
|
|
EightBit::Bus::raisePOWER();
|
|
|
|
CPU().raisePOWER();
|
|
|
|
CPU().raiseRESET();
|
|
|
|
CPU().raiseINT();
|
|
|
|
CPU().raiseNMI();
|
|
|
|
CPU().raiseSO();
|
|
|
|
CPU().raiseRDY();
|
2018-11-11 16:48:44 +00:00
|
|
|
}
|
|
|
|
|
2019-01-14 02:10:17 +00:00
|
|
|
void Board::lowerPOWER() {
|
|
|
|
CPU().lowerPOWER();
|
|
|
|
EightBit::Bus::lowerPOWER();
|
2018-11-11 16:48:44 +00:00
|
|
|
}
|
|
|
|
|
2017-07-05 16:46:02 +00:00
|
|
|
void Board::initialise() {
|
|
|
|
|
2017-07-17 09:16:15 +00:00
|
|
|
auto programFilename = m_configuration.getProgram();
|
2018-01-06 23:26:34 +00:00
|
|
|
auto programPath = m_configuration.getRomDirectory() + "/" + m_configuration.getProgram();
|
2017-07-17 09:16:15 +00:00
|
|
|
auto loadAddress = m_configuration.getLoadAddress();
|
2018-11-18 13:52:43 +00:00
|
|
|
m_ram.load(programPath, loadAddress.word);
|
|
|
|
|
|
|
|
// Disassembly output
|
|
|
|
if (m_configuration.isDebugMode())
|
|
|
|
CPU().ExecutingInstruction.connect([this] (EightBit::MOS6502& cpu) {
|
|
|
|
const auto address = cpu.PC();
|
|
|
|
const auto cell = peek(address);
|
|
|
|
|
|
|
|
std::cout << std::hex;
|
|
|
|
std::cout << "PC=" << std::setw(4) << std::setfill('0') << address << ":";
|
|
|
|
std::cout << "P=" << m_disassembler.dump_Flags(CPU().P()) << ", ";
|
|
|
|
std::cout << std::setw(2) << std::setfill('0');
|
|
|
|
std::cout << "A=" << (int)CPU().A() << ", ";
|
|
|
|
std::cout << "X=" << (int)CPU().X() << ", ";
|
|
|
|
std::cout << "Y=" << (int)CPU().Y() << ", ";
|
|
|
|
std::cout << "S=" << (int)CPU().S() << "\t";
|
|
|
|
|
|
|
|
std::cout << m_disassembler.disassemble(address.word);
|
|
|
|
|
|
|
|
std::cout << "\n";
|
|
|
|
});
|
|
|
|
|
|
|
|
// Loop detected stop condition
|
|
|
|
CPU().ExecutedInstruction.connect([this] (EightBit::MOS6502& cpu) {
|
|
|
|
const auto pc = cpu.PC();
|
|
|
|
if (m_oldPC != pc) {
|
|
|
|
m_oldPC = pc;
|
|
|
|
} else {
|
2019-01-14 02:10:17 +00:00
|
|
|
lowerPOWER();
|
2018-11-18 13:52:43 +00:00
|
|
|
auto test = peek(0x0200);
|
|
|
|
std::cout << std::endl << "** Test=" << std::hex << (int)test;
|
|
|
|
}
|
|
|
|
});
|
2017-07-08 00:04:20 +00:00
|
|
|
|
2018-08-25 11:09:26 +00:00
|
|
|
poke(0x00, 0x4c);
|
2018-10-14 19:39:09 +00:00
|
|
|
CPU().pokeWord(1, m_configuration.getStartAddress());
|
2017-07-05 16:46:02 +00:00
|
|
|
}
|