mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-12-22 09:30:32 +00:00
Tidy up some C++ a little
Signed-off-by: Adrian Conlon <adrian.conlon@gmail.com>
This commit is contained in:
parent
79adce86bd
commit
2fa9ffd1e3
@ -3,19 +3,20 @@
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
#include <Device.h>
|
||||
|
||||
#include "GameController.h"
|
||||
#include "SDLWrapper.h"
|
||||
|
||||
class Configuration;
|
||||
|
||||
namespace Gaming {
|
||||
|
||||
class GameController;
|
||||
|
||||
class Game : public EightBit::Device {
|
||||
public:
|
||||
Game();
|
||||
@ -28,10 +29,10 @@ namespace Gaming {
|
||||
virtual float fps() const = 0;
|
||||
virtual bool useVsync() const = 0;
|
||||
|
||||
virtual int windowWidth() const noexcept { return displayWidth() * displayScale(); }
|
||||
virtual int windowHeight() const noexcept { return displayHeight() * displayScale(); }
|
||||
virtual int displayWidth() const noexcept { return rasterWidth(); }
|
||||
virtual int displayHeight() const noexcept { return rasterHeight(); }
|
||||
virtual int windowWidth() const noexcept;
|
||||
virtual int windowHeight() const noexcept;
|
||||
virtual int displayWidth() const noexcept;
|
||||
virtual int displayHeight() const noexcept;
|
||||
virtual int displayScale() const noexcept = 0;
|
||||
virtual int rasterWidth() const noexcept = 0;
|
||||
virtual int rasterHeight() const noexcept = 0;
|
||||
@ -67,19 +68,8 @@ namespace Gaming {
|
||||
|
||||
void toggleFullscreen();
|
||||
|
||||
std::shared_ptr<GameController> gameController(const int which) const {
|
||||
const auto i = m_gameControllers.find(which);
|
||||
if (i == m_gameControllers.cend())
|
||||
throw std::runtime_error("Unknown controller");
|
||||
return i->second;
|
||||
}
|
||||
|
||||
int mappedController(const SDL_JoystickID which) const {
|
||||
const auto i = m_mappedControllers.find(which);
|
||||
if (i == m_mappedControllers.cend())
|
||||
throw std::runtime_error("Unknown joystick");
|
||||
return i->second;
|
||||
}
|
||||
std::shared_ptr<GameController> gameController(int which) const;
|
||||
int mappedController(const SDL_JoystickID which) const;
|
||||
|
||||
int chooseControllerIndex(int who) const;
|
||||
std::shared_ptr<GameController> chooseController(int who) const;
|
||||
|
@ -1,5 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace Gaming {
|
||||
class SDLWrapper final {
|
||||
public:
|
||||
|
@ -1,12 +1,30 @@
|
||||
#include "stdafx.h"
|
||||
#include "Game.h"
|
||||
|
||||
#include "GameController.h"
|
||||
|
||||
namespace Gaming {
|
||||
|
||||
Game::Game() {}
|
||||
|
||||
Game::~Game() {}
|
||||
|
||||
int Game::windowWidth() const noexcept {
|
||||
return displayWidth() * displayScale();
|
||||
}
|
||||
|
||||
int Game::windowHeight() const noexcept {
|
||||
return displayHeight() * displayScale();
|
||||
}
|
||||
|
||||
int Game::displayWidth() const noexcept {
|
||||
return rasterWidth();
|
||||
}
|
||||
|
||||
int Game::displayHeight() const noexcept {
|
||||
return rasterHeight();
|
||||
}
|
||||
|
||||
void Game::raisePOWER() {
|
||||
|
||||
Device::raisePOWER();
|
||||
@ -168,6 +186,20 @@ void Game::addJoystick(SDL_Event& e) {
|
||||
SDL_Log("Joystick device %d added (%zd controllers)", which, m_gameControllers.size());
|
||||
}
|
||||
|
||||
std::shared_ptr<GameController> Game::gameController(const int which) const {
|
||||
const auto i = m_gameControllers.find(which);
|
||||
if (i == m_gameControllers.cend())
|
||||
throw std::runtime_error("Unknown controller");
|
||||
return i->second;
|
||||
}
|
||||
|
||||
int Game::mappedController(const SDL_JoystickID which) const {
|
||||
const auto i = m_mappedControllers.find(which);
|
||||
if (i == m_mappedControllers.cend())
|
||||
throw std::runtime_error("Unknown joystick");
|
||||
return i->second;
|
||||
}
|
||||
|
||||
// -1 if no controllers, otherwise index
|
||||
int Game::chooseControllerIndex(const int who) const {
|
||||
const auto count = m_gameControllers.size();
|
||||
|
@ -32,15 +32,15 @@ namespace EightBit {
|
||||
Signal<MOS6502> ExecutedInstruction;
|
||||
|
||||
int execute() final;
|
||||
int step() final;
|
||||
[[nodiscard]] int step() final;
|
||||
|
||||
auto& X() { return x; }
|
||||
auto& Y() { return y; }
|
||||
auto& A() { return a; }
|
||||
auto& S() { return s; }
|
||||
[[nodiscard]] auto& X() { return x; }
|
||||
[[nodiscard]] auto& Y() { return y; }
|
||||
[[nodiscard]] auto& A() { return a; }
|
||||
[[nodiscard]] auto& S() { return s; }
|
||||
|
||||
auto& P() { return p; }
|
||||
const auto& P() const { return p; }
|
||||
[[nodiscard]] auto& P() { return p; }
|
||||
[[nodiscard]] const auto& P() const { return p; }
|
||||
|
||||
DECLARE_PIN_INPUT(NMI)
|
||||
DECLARE_PIN_INPUT(SO)
|
||||
@ -49,21 +49,21 @@ namespace EightBit {
|
||||
DECLARE_PIN_OUTPUT(RW)
|
||||
|
||||
protected:
|
||||
virtual void handleRESET() final;
|
||||
virtual void handleINT() final;
|
||||
void handleRESET() final;
|
||||
void handleINT() final;
|
||||
|
||||
virtual void busWrite() final;
|
||||
virtual uint8_t busRead() final;
|
||||
void busWrite() final;
|
||||
[[nodiscard]] uint8_t busRead() final;
|
||||
|
||||
virtual uint8_t sub(uint8_t operand, uint8_t data, int borrow = 0);
|
||||
uint8_t sbc(uint8_t operand, uint8_t data);
|
||||
uint8_t sub_b(uint8_t operand, uint8_t data, int borrow);
|
||||
uint8_t sub_d(uint8_t operand, uint8_t data, int borrow);
|
||||
[[nodiscard]] virtual uint8_t sub(uint8_t operand, uint8_t data, int borrow = 0);
|
||||
[[nodiscard]] uint8_t sbc(uint8_t operand, uint8_t data);
|
||||
[[nodiscard]] uint8_t sub_b(uint8_t operand, uint8_t data, int borrow);
|
||||
[[nodiscard]] uint8_t sub_d(uint8_t operand, uint8_t data, int borrow);
|
||||
|
||||
virtual uint8_t add(uint8_t operand, uint8_t data, int carry = 0);
|
||||
uint8_t adc(uint8_t operand, uint8_t data);
|
||||
uint8_t add_b(uint8_t operand, uint8_t data, int carry);
|
||||
uint8_t add_d(uint8_t operand, uint8_t data, int carry);
|
||||
[[nodiscard]] virtual uint8_t add(uint8_t operand, uint8_t data, int carry = 0);
|
||||
[[nodiscard]] uint8_t adc(uint8_t operand, uint8_t data);
|
||||
[[nodiscard]] uint8_t add_b(uint8_t operand, uint8_t data, int carry);
|
||||
[[nodiscard]] uint8_t add_d(uint8_t operand, uint8_t data, int carry);
|
||||
|
||||
private:
|
||||
const uint8_t IRQvector = 0xfe; // IRQ vector
|
||||
@ -75,25 +75,25 @@ namespace EightBit {
|
||||
|
||||
void interrupt();
|
||||
|
||||
virtual void push(uint8_t value) final;
|
||||
virtual uint8_t pop() final;
|
||||
void push(uint8_t value) final;
|
||||
[[nodiscard]] uint8_t pop() final;
|
||||
|
||||
// Dummy stack push, used during RESET
|
||||
void dummyPush(uint8_t value);
|
||||
|
||||
// Addressing modes
|
||||
|
||||
register16_t Address_Absolute();
|
||||
uint8_t Address_ZeroPage();
|
||||
register16_t Address_ZeroPageIndirect();
|
||||
register16_t Address_Indirect();
|
||||
uint8_t Address_ZeroPageX();
|
||||
uint8_t Address_ZeroPageY();
|
||||
std::pair<register16_t, uint8_t> Address_AbsoluteX();
|
||||
std::pair<register16_t, uint8_t> Address_AbsoluteY();
|
||||
register16_t Address_IndexedIndirectX();
|
||||
std::pair<register16_t, uint8_t> Address_IndirectIndexedY();
|
||||
register16_t Address_relative_byte();
|
||||
[[nodiscard]] register16_t Address_Absolute();
|
||||
[[nodiscard]] uint8_t Address_ZeroPage();
|
||||
[[nodiscard]] register16_t Address_ZeroPageIndirect();
|
||||
[[nodiscard]] register16_t Address_Indirect();
|
||||
[[nodiscard]] uint8_t Address_ZeroPageX();
|
||||
[[nodiscard]] uint8_t Address_ZeroPageY();
|
||||
[[nodiscard]] std::pair<register16_t, uint8_t> Address_AbsoluteX();
|
||||
[[nodiscard]] std::pair<register16_t, uint8_t> Address_AbsoluteY();
|
||||
[[nodiscard]] register16_t Address_IndexedIndirectX();
|
||||
[[nodiscard]] std::pair<register16_t, uint8_t> Address_IndirectIndexedY();
|
||||
[[nodiscard]] register16_t Address_relative_byte();
|
||||
|
||||
// Addressing modes, read
|
||||
|
||||
@ -121,19 +121,19 @@ namespace EightBit {
|
||||
|
||||
// Flag checking
|
||||
|
||||
auto interruptMasked() const { return P() & IF; }
|
||||
auto decimal() const { return P() & DF; }
|
||||
[[nodiscard]] auto interruptMasked() const { return P() & IF; }
|
||||
[[nodiscard]] auto decimal() const { return P() & DF; }
|
||||
|
||||
auto negative() const { return P() & NF; }
|
||||
auto zero() const { return P() & ZF; }
|
||||
auto overflow() const { return P() & VF; }
|
||||
auto carry() const { return P() & CF; }
|
||||
[[nodiscard]] auto negative() const { return P() & NF; }
|
||||
[[nodiscard]] auto zero() const { return P() & ZF; }
|
||||
[[nodiscard]] auto overflow() const { return P() & VF; }
|
||||
[[nodiscard]] auto carry() const { return P() & CF; }
|
||||
|
||||
// Miscellaneous
|
||||
|
||||
void branch(int condition);
|
||||
|
||||
auto through(const uint8_t data) {
|
||||
[[nodiscard]] auto through(const uint8_t data) {
|
||||
adjustNZ(data);
|
||||
return data;
|
||||
}
|
||||
@ -146,20 +146,20 @@ namespace EightBit {
|
||||
|
||||
// Instruction implementations
|
||||
|
||||
uint8_t andr(uint8_t operand, uint8_t data);
|
||||
uint8_t asl(uint8_t value);
|
||||
[[nodiscard]] uint8_t andr(uint8_t operand, uint8_t data);
|
||||
[[nodiscard]] uint8_t asl(uint8_t value);
|
||||
void bit(uint8_t operand, uint8_t data);
|
||||
void cmp(uint8_t first, uint8_t second);
|
||||
uint8_t dec(uint8_t value);
|
||||
uint8_t eorr(uint8_t operand, uint8_t data);
|
||||
uint8_t inc(uint8_t value);
|
||||
[[nodiscard]] uint8_t dec(uint8_t value);
|
||||
[[nodiscard]] uint8_t eorr(uint8_t operand, uint8_t data);
|
||||
[[nodiscard]] uint8_t inc(uint8_t value);
|
||||
void jsr();
|
||||
uint8_t lsr(uint8_t value);
|
||||
uint8_t orr(uint8_t operand, uint8_t data);
|
||||
[[nodiscard]] uint8_t lsr(uint8_t value);
|
||||
[[nodiscard]] uint8_t orr(uint8_t operand, uint8_t data);
|
||||
void php();
|
||||
void plp();
|
||||
uint8_t rol(uint8_t operand);
|
||||
uint8_t ror(uint8_t operand);
|
||||
[[nodiscard]] uint8_t rol(uint8_t operand);
|
||||
[[nodiscard]] uint8_t ror(uint8_t operand);
|
||||
void rti();
|
||||
void rts();
|
||||
|
||||
|
@ -25,20 +25,17 @@ void Board::lowerPOWER() {
|
||||
}
|
||||
|
||||
void Board::initialise() {
|
||||
//CPU().ExecutingInstruction.connect(std::bind(&Board::Cpu_ExecutingInstruction_Debug, this, std::placeholders::_1));
|
||||
//CPU().ExecutedInstruction.connect(std::bind(&Board::Cpu_ExecutedInstruction_Debug, this, std::placeholders::_1));
|
||||
CPU().ExecutingInstruction.connect([this](EightBit::mc6809& cpu) {
|
||||
m_disassembleAt = CPU().PC();
|
||||
m_ignoreDisassembly = m_disassembler.ignore();
|
||||
});
|
||||
|
||||
CPU().ExecutedInstruction.connect([this](EightBit::mc6809& cpu) {
|
||||
if (!m_ignoreDisassembly)
|
||||
std::cout << m_disassembler.trace(m_disassembleAt) << " " << std::endl;
|
||||
});
|
||||
}
|
||||
|
||||
EightBit::MemoryMapping Board::mapping(uint16_t) {
|
||||
return { m_ram, 0x0000, 0xffff, EightBit::MemoryMapping::AccessLevel::ReadWrite };
|
||||
}
|
||||
|
||||
void Board::Cpu_ExecutingInstruction_Debug(EightBit::mc6809&) {
|
||||
m_disassembleAt = CPU().PC();
|
||||
m_ignoreDisassembly = m_disassembler.ignore();
|
||||
}
|
||||
|
||||
void Board::Cpu_ExecutedInstruction_Debug(EightBit::mc6809&) {
|
||||
if (!m_ignoreDisassembly)
|
||||
std::cout << m_disassembler.trace(m_disassembleAt) << " " << std::endl;
|
||||
}
|
||||
|
@ -5,19 +5,19 @@
|
||||
#include <mc6809.h>
|
||||
#include <Disassembly.h>
|
||||
|
||||
class Board : public EightBit::Bus {
|
||||
class Board final : public EightBit::Bus {
|
||||
public:
|
||||
Board();
|
||||
|
||||
EightBit::mc6809& CPU() { return m_cpu; }
|
||||
|
||||
virtual void raisePOWER() final;
|
||||
virtual void lowerPOWER() final;
|
||||
void raisePOWER() final;
|
||||
void lowerPOWER() final;
|
||||
|
||||
protected:
|
||||
virtual void initialise() final;
|
||||
void initialise() final;
|
||||
|
||||
virtual EightBit::MemoryMapping mapping(uint16_t address) final;
|
||||
EightBit::MemoryMapping mapping(uint16_t address) final;
|
||||
|
||||
private:
|
||||
EightBit::Ram m_ram = 0x10000; // 0000 - FFFF, 64K RAM
|
||||
@ -27,7 +27,4 @@ private:
|
||||
// The m_disassembleAt and m_ignoreDisassembly are used to skip pin events
|
||||
EightBit::register16_t m_disassembleAt = 0x0000;
|
||||
bool m_ignoreDisassembly = false;
|
||||
|
||||
void Cpu_ExecutingInstruction_Debug(EightBit::mc6809&);
|
||||
void Cpu_ExecutedInstruction_Debug(EightBit::mc6809&);
|
||||
};
|
||||
|
@ -10,42 +10,42 @@ namespace EightBit {
|
||||
public:
|
||||
mc6850();
|
||||
|
||||
// +--------+----------------------------------------------------------------------------------+
|
||||
// | | Buffer address |
|
||||
// | +------------------+------------------+--------------------+-----------------------+
|
||||
// | | _ | _ | _ | _ |
|
||||
// | Data | RS * R/W | RS * R/W | RS * R/W | RS * R/W |
|
||||
// | Bus | (high)(low) | (high)(high) | (low)(low) | (low)(low) |
|
||||
// | Line | Transmit | Receive | | |
|
||||
// | Number | Data | Data | Control | Status |
|
||||
// | | Register | Register | register | register |
|
||||
// | +------------------+------------------+--------------------+-----------------------+
|
||||
// | | (Write only) + (Read only) + (Write only) | (Read only) |
|
||||
// +--------+------------------+------------------+--------------------+-----------------------+
|
||||
// | 0 | Data bit 0* | Data bit 0 | Counter divide | Receive data register |
|
||||
// | | | | select 1 (CR0) | full (RDRF) |
|
||||
// +--------+------------------+------------------+--------------------+-----------------------+
|
||||
// | 1 | Data bit 1 | Data bit 1 | Counter divide | Transmit data register|
|
||||
// | | | | select 2 (CR1) | empty (TDRE) |
|
||||
// +--------+------------------+------------------+--------------------+-----------------------+
|
||||
// | 2 | Data bit 2 | Data bit 2 | Word select 1 | Data carrier detect |
|
||||
// | | | | (CR2) | (DCD active) |
|
||||
// +--------+------------------+------------------+--------------------+-----------------------+
|
||||
// | 3 | Data bit 3 | Data bit 3 | Word select 1 | Clear to send |
|
||||
// | | | | (CR3) | (CTS active) |
|
||||
// +--------+------------------+------------------+--------------------+-----------------------+
|
||||
// | 4 | Data bit 4 | Data bit 4 | Word select 1 | Framing error |
|
||||
// | | | | (CR4) | (FE) |
|
||||
// +--------+------------------+------------------+--------------------+-----------------------+
|
||||
// | 5 | Data bit 5 | Data bit 5 | Transmit control 1 | Receiver overrun |
|
||||
// | | | | (CR5) | (OVRN) |
|
||||
// +--------+------------------+------------------+--------------------+-----------------------+
|
||||
// | 6 | Data bit 6 | Data bit 6 | Transmit control 2 | Parity error (PE) |
|
||||
// | | | | (CR6) | |
|
||||
// +--------+------------------+------------------+--------------------+-----------------------+
|
||||
// | 7 | Data bit 7*** | Data bit 7** | Receive interrupt | Interrupt request |
|
||||
// | | | | enable (CR7) | (IRQ active) |
|
||||
// +--------+------------------+------------------+--------------------+-----------------------+
|
||||
// +--------+----------------------------------------------------------------------------------+
|
||||
// | | Buffer address |
|
||||
// | +------------------+------------------+--------------------+-----------------------+
|
||||
// | | _ | _ | _ | _ |
|
||||
// | Data | RS * R/W | RS * R/W | RS * R/W | RS * R/W |
|
||||
// | Bus | (high)(low) | (high)(high) | (low)(low) | (low)(low) |
|
||||
// | Line | Transmit | Receive | | |
|
||||
// | Number | Data | Data | Control | Status |
|
||||
// | | Register | Register | Register | register |
|
||||
// | +------------------+------------------+--------------------+-----------------------+
|
||||
// | | (Write only) | (Read only) | (Write only) | (Read only) |
|
||||
// +--------+------------------+------------------+--------------------+-----------------------+
|
||||
// | 0 | Data bit 0* | Data bit 0 | Counter divide | Receive data register |
|
||||
// | | | | select 1 (CR0) | full (RDRF) |
|
||||
// +--------+------------------+------------------+--------------------+-----------------------+
|
||||
// | 1 | Data bit 1 | Data bit 1 | Counter divide | Transmit data register|
|
||||
// | | | | select 2 (CR1) | empty (TDRE) |
|
||||
// +--------+------------------+------------------+--------------------+-----------------------+
|
||||
// | 2 | Data bit 2 | Data bit 2 | Word select 1 | Data carrier detect |
|
||||
// | | | | (CR2) | (DCD active) |
|
||||
// +--------+------------------+------------------+--------------------+-----------------------+
|
||||
// | 3 | Data bit 3 | Data bit 3 | Word select 1 | Clear to send |
|
||||
// | | | | (CR3) | (CTS active) |
|
||||
// +--------+------------------+------------------+--------------------+-----------------------+
|
||||
// | 4 | Data bit 4 | Data bit 4 | Word select 1 | Framing error |
|
||||
// | | | | (CR4) | (FE) |
|
||||
// +--------+------------------+------------------+--------------------+-----------------------+
|
||||
// | 5 | Data bit 5 | Data bit 5 | Transmit control 1 | Receiver overrun |
|
||||
// | | | | (CR5) | (OVRN) |
|
||||
// +--------+------------------+------------------+--------------------+-----------------------+
|
||||
// | 6 | Data bit 6 | Data bit 6 | Transmit control 2 | Parity error (PE) |
|
||||
// | | | | (CR6) | |
|
||||
// +--------+------------------+------------------+--------------------+-----------------------+
|
||||
// | 7 | Data bit 7*** | Data bit 7** | Receive interrupt | Interrupt request |
|
||||
// | | | | enable (CR7) | (IRQ active) |
|
||||
// +--------+------------------+------------------+--------------------+-----------------------+
|
||||
// * Leading bit = LSB = Bit 0
|
||||
// ** Data bit will be zero in 7-bit plus parity modes
|
||||
// *** Data bit is "don't care" in 7-bit plus parity modes
|
||||
@ -84,7 +84,7 @@ namespace EightBit {
|
||||
// CR5 and CR6
|
||||
enum TransmitterControl {
|
||||
ReadyLowInterruptDisabled = 0b00,
|
||||
ReadyLowInterruptEnabled = 0b01,
|
||||
ReadyLowInterruptEnabled = 0b01,
|
||||
ReadyHighInterruptDisabled = 0b10,
|
||||
ReadyLowInterruptDisabledTransmitBreak = 0b11,
|
||||
};
|
||||
@ -284,10 +284,10 @@ namespace EightBit {
|
||||
bool m_statusRead = false;
|
||||
|
||||
// Control registers
|
||||
CounterDivideSelect m_counterDivide = One;
|
||||
WordSelect m_wordSelect = SevenEvenTwo;
|
||||
TransmitterControl m_transmitControl = ReadyLowInterruptDisabled;
|
||||
ReceiveControl m_receiveControl = ReceiveInterruptDisable;
|
||||
CounterDivideSelect m_counterDivide = CounterDivideSelect::One;
|
||||
WordSelect m_wordSelect = WordSelect::SevenEvenTwo;
|
||||
TransmitterControl m_transmitControl = TransmitterControl::ReadyLowInterruptDisabled;
|
||||
ReceiveControl m_receiveControl = ReceiveControl::ReceiveInterruptDisable;
|
||||
|
||||
// Status registers
|
||||
bool m_statusRDRF = false;
|
||||
|
@ -15,7 +15,7 @@ namespace EightBit {
|
||||
static std::string state(Z80& cpu);
|
||||
std::string disassemble(Z80& cpu);
|
||||
|
||||
static std::string flag(uint8_t value, int flag, const std::string& represents);
|
||||
static std::string flag(uint8_t value, int flag, std::string represents);
|
||||
static std::string flags(uint8_t value);
|
||||
static std::string hex(uint8_t value);
|
||||
static std::string hex(uint16_t value);
|
||||
|
@ -726,7 +726,7 @@ void EightBit::Disassembler::disassembleOther(
|
||||
}
|
||||
}
|
||||
|
||||
std::string EightBit::Disassembler::flag(uint8_t value, int flag, const std::string& represents) {
|
||||
std::string EightBit::Disassembler::flag(uint8_t value, int flag, const std::string represents) {
|
||||
std::ostringstream output;
|
||||
output << (value & flag ? represents : "-");
|
||||
return output.str();
|
||||
|
@ -103,7 +103,7 @@ namespace EightBit {
|
||||
|
||||
virtual ~Device() = default;
|
||||
|
||||
[[nodiscard]] bool powered() noexcept { return raised(POWER()); }
|
||||
[[nodiscard]] bool powered() const noexcept { return raised(POWER()); }
|
||||
|
||||
DECLARE_PIN_INPUT(POWER)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user