APU.hpp
Go to the documentation of this file.
//
// Created by Melefo on 24/01/2020.
//
#ifndef COMSQUARE_APU_HPP
#define COMSQUARE_APU_HPP
#include <memory>
#include "../DSP/DSP.hpp"
#include "../Memory/IMemory.hpp"
namespace ComSquare::APU
{
struct InternalRegisters {
uint8_t x;
union {
struct {
uint8_t a;
uint8_t y;
};
uint16_t ya;
};
uint8_t sp;
union {
struct {
uint8_t pcl;
uint8_t pch;
};
uint16_t pc;
};
union psw {
bool n : 1;
bool v : 1;
bool p : 1;
bool b : 1;
bool h : 1;
bool i : 1;
bool z : 1;
bool c : 1;
};
};
struct Registers
{
uint8_t unknown;
uint8_t ctrlreg;
uint8_t dspregAddr;
uint8_t dspregData;
uint8_t port0;
uint8_t port1;
uint8_t port2;
uint8_t port3;
uint8_t regmem1;
uint8_t regmem2;
uint8_t timer0;
uint8_t timer1;
uint8_t timer2;
uint8_t counter0;
uint8_t counter1;
uint8_t counter2;
};
class APU : public Memory::IMemory {
private:
Registers _registers{};
InternalRegisters _internalRegisters{};
std::shared_ptr<DSP::DSP> _dsp;
public:
explicit APU();
uint8_t read(uint24_t addr) override;
void write(uint24_t addr, uint8_t data) override;
bool update();
};
}
#endif //COMSQUARE_APU_HPP
ComSquare::APU::InternalRegisters::psw::h
bool h
Half carry flag.
Definition: APU.hpp:53
ComSquare::APU::Registers::port0
uint8_t port0
Port 0 register.
Definition: APU.hpp:77
ComSquare::APU::APU::_internalRegisters
InternalRegisters _internalRegisters
Internal registers of the CPU (accessible from the bus via addr $4200 to $421F).
Definition: APU.hpp:111
ComSquare::APU::InternalRegisters::psw
Program Status Word register.
Definition: APU.hpp:43
ComSquare::APU::InternalRegisters::pcl
uint8_t pcl
Definition: APU.hpp:36
ComSquare::APU::Registers::regmem2
uint8_t regmem2
Another Regular Memory register.
Definition: APU.hpp:88
ComSquare::APU::Registers::dspregData
uint8_t dspregData
DSP Register data register.
Definition: APU.hpp:74
ComSquare::APU::InternalRegisters::y
uint8_t y
The Y Index register.
Definition: APU.hpp:25
ComSquare::APU::APU::_dsp
std::shared_ptr< DSP::DSP > _dsp
The DSP component used to produce sound.
Definition: APU.hpp:114
ComSquare::APU::Registers::counter1
uint8_t counter1
Counter-1 register.
Definition: APU.hpp:100
ComSquare::APU::InternalRegisters::psw::z
bool z
Zero flag.
Definition: APU.hpp:57
ComSquare::APU::Registers::regmem1
uint8_t regmem1
Regular Memory register.
Definition: APU.hpp:86
ComSquare::APU::InternalRegisters::sp
uint8_t sp
The Stack pointer register.
Definition: APU.hpp:31
ComSquare::APU::InternalRegisters
Definition: APU.hpp:14
ComSquare::APU::InternalRegisters::x
uint8_t x
The X index register.
Definition: APU.hpp:17
ComSquare::APU::Registers::port1
uint8_t port1
Port 1 register.
Definition: APU.hpp:79
ComSquare::APU::Registers::counter0
uint8_t counter0
Counter-0 register.
Definition: APU.hpp:98
ComSquare::APU
Definition: APU.cpp:9
ComSquare::APU::InternalRegisters::psw::v
bool v
Overflow flag.
Definition: APU.hpp:47
ComSquare::APU::Registers::port2
uint8_t port2
Port 2 register.
Definition: APU.hpp:81
ComSquare::APU::APU::read
uint8_t read(uint24_t addr) override
Read from the internal APU register.
Definition: APU.cpp:14
uint24_t
unsigned uint24_t
Definition: Ints.hpp:8
ComSquare::APU::Registers::unknown
uint8_t unknown
An undocumented register.
Definition: APU.hpp:66
ComSquare::Memory::IMemory
Common interface implemented by all components mapping memory.
Definition: IMemory.hpp:16
ComSquare::APU::Registers::ctrlreg
uint8_t ctrlreg
Control Register register.
Definition: APU.hpp:69
ComSquare::APU::APU::update
bool update()
Definition: APU.cpp:93
ComSquare::APU::Registers::timer2
uint8_t timer2
Timer-2 register.
Definition: APU.hpp:95
ComSquare::APU::Registers::port3
uint8_t port3
Port 3 register.
Definition: APU.hpp:83
ComSquare::APU::InternalRegisters::psw::b
bool b
Break flag.
Definition: APU.hpp:51
ComSquare::APU::InternalRegisters::psw::c
bool c
Carry flag.
Definition: APU.hpp:59
ComSquare::APU::InternalRegisters::psw::p
bool p
Direct page flag.
Definition: APU.hpp:49
ComSquare::APU::InternalRegisters::ya
uint16_t ya
Definition: APU.hpp:27
ComSquare::APU::APU::APU
APU()
Definition: APU.cpp:11
ComSquare::APU::APU::_registers
Registers _registers
All the registers of the APU CPU.
Definition: APU.hpp:109
ComSquare::APU::Registers::counter2
uint8_t counter2
Counter-2 register.
Definition: APU.hpp:102
ComSquare::APU::APU::write
void write(uint24_t addr, uint8_t data) override
Write data to the internal APU register.
Definition: APU.cpp:46
ComSquare::APU::APU
Definition: APU.hpp:106
ComSquare::APU::Registers
Definition: APU.hpp:63
ComSquare::APU::InternalRegisters::a
uint8_t a
The Accumulator register.
Definition: APU.hpp:23
ComSquare::APU::InternalRegisters::psw::n
bool n
Negative flag.
Definition: APU.hpp:45
ComSquare::APU::Registers::timer1
uint8_t timer1
Timer-1 register.
Definition: APU.hpp:93
ComSquare::APU::InternalRegisters::pc
uint16_t pc
Definition: APU.hpp:39
ComSquare::APU::InternalRegisters::pch
uint8_t pch
Definition: APU.hpp:37
ComSquare::APU::Registers::dspregAddr
uint8_t dspregAddr
DSP Register Address register.
Definition: APU.hpp:72
ComSquare::APU::InternalRegisters::psw::i
bool i
Interrupt enabled flag.
Definition: APU.hpp:55
ComSquare::APU::Registers::timer0
uint8_t timer0
Timer-0 register.
Definition: APU.hpp:91