ComSquare
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
ComSquare::CPU::CPU Class Reference

The main CPU. More...

#include <CPU.hpp>

Inheritance diagram for ComSquare::CPU::CPU:
Collaboration diagram for ComSquare::CPU::CPU:

Public Member Functions

Memory::IMemoryBusgetBus ()
 Get the memory bus used by this CPU. More...
 
void setBus (Memory::IMemoryBus &bus)
 Set the memory bus used by this CPU. More...
 
 CPU (Memory::IMemoryBus &bus, Cartridge::Header &cartridgeHeader)
 Construct a new generic CPU. More...
 
 CPU (const CPU &)=default
 A default copy constructor. More...
 
CPUoperator= (const CPU &)=delete
 A CPU is not assignable. More...
 
 ~CPU () override=default
 A default destructor. More...
 
unsigned update (unsigned maxCycle)
 This function continue to execute the Cartridge code. More...
 
unsigned executeInstruction ()
 Execute a single instruction. More...
 
unsigned runDMA (unsigned maxCycles)
 Run DMA's pending transfers. More...
 
uint8_t read (uint24_t addr) override
 Read from the internal CPU register. More...
 
void write (uint24_t addr, uint8_t data) override
 Write data to the internal CPU register. More...
 
std::string getValueName (uint24_t addr) const override
 Get the name of the data at the address. More...
 
uint24_t getSize () const override
 Get the size of the data. This size can be lower than the mapped data. More...
 
std::string getName () const override
 Get the name of this accessor (used for debug purpose) More...
 
Component getComponent () const override
 Get the component of this accessor (used for debug purpose) More...
 
int RESB ()
 Reset interrupt - Called on boot and when the reset button is pressed. More...
 
- Public Member Functions inherited from ComSquare::Memory::AMemory
uint24_t getRelativeAddress (uint24_t addr) const override
 Translate an absolute address to a relative address. More...
 
void setMemoryRegion (uint24_t start, uint24_t end)
 Change starting and ending points of this mapped memory. More...
 
bool hasMemoryAt (uint24_t addr) const override
 Return true if this component has mapped the address. More...
 
 ~AMemory () override=default
 A default destructor. More...
 
- Public Member Functions inherited from ComSquare::Memory::IMemory
virtual ~IMemory ()=default
 A virtual default destructor. More...
 

Public Attributes

const Instruction instructions [0x100]
 All the instructions of the CPU. @info Instructions are indexed by their opcode. More...
 
Callback onReset
 The callback triggered on reset. More...
 
bool IsNMIRequested = false
 Is an NMI (non-maskable interrupt) requested. More...
 
bool IsIRQRequested = false
 Is an interrupt (maskable) requested. More...
 
bool IsAbortRequested = false
 Is an abort requested. More...
 
bool isDisabled = false
 True if you want to disable updates of this CPU. More...
 

Private Member Functions

uint24_t _getImmediateAddr8Bits ()
 Immediate address mode is specified with a value in 8 bits. (This functions returns the 24bit space address of the value). More...
 
uint24_t _getImmediateAddr16Bits ()
 Immediate address mode is specified with a value in 16 bits. (This functions returns the 24bit space address of the value). More...
 
uint24_t _getImmediateAddrForA ()
 Immediate address mode is specified with a value in 8 or 16 bits. The value is 16 bits if the m flag is unset. (This functions returns the 24bit space address of the value). More...
 
uint24_t _getImmediateAddrForX ()
 Immediate address mode is specified with a value in 8 or 16 bits. The value is 16 bits if the x flag is unset. (This functions returns the 24bit space address of the value). More...
 
uint24_t _getDirectAddr ()
 The destination is formed by adding the direct page register with the 8-bit address to form an effective address. (This functions returns the 24bit space address of the value). More...
 
uint24_t _getAbsoluteAddr ()
 The effective address is formed by DBR:<16-bit exp>. (This functions returns the 24bit space address of the value). More...
 
uint24_t _getAbsoluteLongAddr ()
 The effective address is the expression. (This functions returns the 24bit space address of the value). More...
 
uint24_t _getDirectIndirectIndexedYAddr ()
 The address is DBR:$(read($($Value + D)) + Y). (This functions returns the 24bit space address of the value). More...
 
uint24_t _getDirectIndirectIndexedYLongAddr ()
 This mode is like the previous addressing mode, but the difference is that rather than pulling 2 bytes from the DP address, it pulls 3 bytes to form the effective address. More...
 
uint24_t _getDirectIndirectIndexedXAddr ()
 The direct page address is calculated and added with x. 2 bytes from the dp address combined with DBR will form the effective address. More...
 
uint24_t _getDirectIndexedByXAddr ()
 The DP address is added to X to form the effective address. The effective address is always in bank 0. More...
 
uint24_t _getDirectIndexedByYAddr ()
 The DP address is added to Y to form the effective address. The effective address is always in bank 0. More...
 
uint24_t _getAbsoluteIndexedByXAddr ()
 The absolute expression is added with X and combined with DBR to form the effective address. More...
 
uint24_t _getAbsoluteIndexedByYAddr ()
 The absolute expression is added with Y and combined with DBR to form the effective address. More...
 
uint24_t _getAbsoluteIndexedByXLongAddr ()
 The effective address is formed by adding the <long exp> with X. More...
 
uint24_t _getAbsoluteIndirectAddr ()
 2 bytes are pulled from the <abs exp> to form the effective address. More...
 
uint24_t _getAbsoluteIndirectLongAddr ()
 3 bytes are pulled from the <abs exp> to form the effective address. More...
 
uint24_t _getAbsoluteIndirectIndexedByXAddr ()
 The <abs exp> is added with X, then 2 bytes are pulled from that address to form the new location. More...
 
uint24_t _getDirectIndirectAddr ()
 2 bytes are pulled from the direct page address to form the 16-bit address. It is combined with DBR to form a 24-bit effective address. More...
 
uint24_t _getDirectIndirectLongAddr ()
 3 bytes are pulled from the direct page address to form an effective address. More...
 
uint24_t _getStackRelativeAddr ()
 The stack register is added to the <8-bit exp> to form the effective address. More...
 
uint24_t _getStackRelativeIndirectIndexedYAddr ()
 The <8-bit exp> is added to S and combined with DBR to form the base address. Y is added to the base address to form the effective address. More...
 
void _push (uint8_t data)
 Push 8 bits of data to the stack. More...
 
void _push (uint16_t data)
 Push 16 bits of data to the stack. More...
 
uint8_t _pop ()
 Pop 8 bits of data from the stack. More...
 
uint16_t _pop16 ()
 Pop 16 bits of data from the stack. More...
 
uint8_t _readPC ()
 Return the data at the program bank concatenated with the program counter. It also increment the program counter (the program bank is not incremented on overflows). More...
 
void _checkInterrupts ()
 Check if an interrupt is requested and handle it. More...
 
void _runInterrupt (uint24_t nativeHandler, uint24_t emulationHandler)
 Run an interrupt (save state of the processor and jump to the interrupt handler) More...
 
uint24_t _getValueAddr (const Instruction &instruction)
 Get the parameter address of an instruction from it's addressing mode. @info The current program counter should point to the instruction's opcode + 1. More...
 
int BRK (uint24_t, AddressingMode)
 Break instruction - Causes a software break. The PC is loaded from a vector table. More...
 
int COP (uint24_t, AddressingMode)
 Co-Processor Enable instruction - Causes a software break. The PC is loaded from a vector table. More...
 
int RTI (uint24_t, AddressingMode)
 Return from Interrupt - Used to return from a interrupt handler. More...
 
int ADC (uint24_t valueAddr, AddressingMode)
 Add with carry - Adds operand to the Accumulator; adds an additional 1 if carry is set. More...
 
int STA (uint24_t addr, AddressingMode)
 Store the accumulator to memory. More...
 
int STX (uint24_t addr, AddressingMode)
 Store the index register X to memory. More...
 
int STY (uint24_t addr, AddressingMode)
 Store the index register Y to memory. More...
 
int STZ (uint24_t addr, AddressingMode)
 Store zero to the memory. More...
 
int LDA (uint24_t addr, AddressingMode)
 Load the accumulator from memory. More...
 
int LDX (uint24_t addr, AddressingMode)
 Load the X index register from memory. More...
 
int LDY (uint24_t addr, AddressingMode)
 Load the Y index register from memory. More...
 
int SEP (uint24_t valueAddr, AddressingMode)
 Set status bits. More...
 
int REP (uint24_t valueAddr, AddressingMode)
 Reset status bits. More...
 
int JSR (uint24_t addr, AddressingMode)
 Jump to subroutine. More...
 
int JSL (uint24_t addr, AddressingMode)
 Jump to subroutine (long) More...
 
int PHA (uint24_t, AddressingMode)
 Push the accumulator to the stack. More...
 
int PHB (uint24_t, AddressingMode)
 Push the data bank register to the stack. More...
 
int PHD (uint24_t, AddressingMode)
 Push the direct page register to the stack. More...
 
int PHK (uint24_t, AddressingMode)
 Push the program bank register to the stack. More...
 
int PHP (uint24_t, AddressingMode)
 Push the processor status register to the stack. More...
 
int PHX (uint24_t, AddressingMode)
 Push the x index register to the stack. More...
 
int PHY (uint24_t, AddressingMode)
 Push the y index register to the stack. More...
 
int PLA (uint24_t, AddressingMode)
 Pull the accumulator to the stack. More...
 
int PLB (uint24_t, AddressingMode)
 Pull the data bank register to the stack. More...
 
int PLD (uint24_t, AddressingMode)
 Pull the direct page register to the stack. More...
 
int PLP (uint24_t, AddressingMode)
 Pull the processor status register to the stack. More...
 
int PLX (uint24_t, AddressingMode)
 Pull the x index register to the stack. More...
 
int PLY (uint24_t, AddressingMode)
 Pull the y index register to the stack. More...
 
int CLC (uint24_t, AddressingMode)
 Clear the carry flag. More...
 
int CLI (uint24_t, AddressingMode)
 Clear the Interrupt Disable flag. More...
 
int CLD (uint24_t, AddressingMode)
 Clear the decimal flag. More...
 
int CLV (uint24_t, AddressingMode)
 Clear the overflow flag. More...
 
int SEC (uint24_t, AddressingMode)
 Set the carry Flag. More...
 
int SED (uint24_t, AddressingMode)
 Set the decimal flag. More...
 
int SEI (uint24_t, AddressingMode)
 Set the Interrupt Disable flag. More...
 
int XCE (uint24_t, AddressingMode)
 Exchange Carry and Emulation Flags. More...
 
int AND (uint24_t valueAddr, AddressingMode)
 And accumulator with memory. More...
 
int SBC (uint24_t valueAddr, AddressingMode)
 Subtract with Borrow from Accumulator. More...
 
int TAX (uint24_t, AddressingMode)
 Transfer A to X. More...
 
int TAY (uint24_t, AddressingMode)
 Transfer A to Y. More...
 
int TXS (uint24_t, AddressingMode)
 Transfer X to SP. More...
 
int INX (uint24_t, AddressingMode)
 Increment the X register. More...
 
int INY (uint24_t, AddressingMode)
 Increment the Y register. More...
 
int CPX (uint24_t valueAddr, AddressingMode)
 Compare the X register with the memory. More...
 
int CPY (uint24_t valueAddr, AddressingMode)
 Compare the Y register with the memory. More...
 
int BCC (uint24_t valueAddr, AddressingMode)
 Branch if carry clear. More...
 
int BCS (uint24_t valueAddr, AddressingMode)
 Branch if carry set. More...
 
int BEQ (uint24_t valueAddr, AddressingMode)
 Branch if equal. More...
 
int BNE (uint24_t valueAddr, AddressingMode)
 Branch if not equal. More...
 
int BMI (uint24_t valueAddr, AddressingMode)
 Branch if minus. More...
 
int BPL (uint24_t valueAddr, AddressingMode)
 Branch if plus. More...
 
int BVC (uint24_t valueAddr, AddressingMode)
 Branch if Overflow Clear. More...
 
int BVS (uint24_t valueAddr, AddressingMode)
 Branch if Overflow Set. More...
 
int BRA (uint24_t valueAddr, AddressingMode)
 Branch always. More...
 
int BRL (uint24_t valueAddr, AddressingMode)
 Branch always long. More...
 
int JMP (uint24_t valueAddr, AddressingMode)
 Jump. More...
 
int JML (uint24_t valueAddr, AddressingMode)
 Long jump. More...
 
int NOP (uint24_t, AddressingMode)
 No OP. More...
 
int DEX (uint24_t, AddressingMode)
 Decrement the X register. More...
 
int DEY (uint24_t, AddressingMode)
 Decrement the Y register. More...
 
int ORA (uint24_t valueAddr, AddressingMode mode)
 Or accumulator with memory. More...
 
int RTS (uint24_t, AddressingMode)
 Return from subroutine. More...
 
int RTL (uint24_t, AddressingMode)
 Return from subroutine long. More...
 
int CMP (uint24_t, AddressingMode)
 Compare Accumulator with Memory. More...
 
int INC (uint24_t, AddressingMode)
 Increment. More...
 
int DEC (uint24_t, AddressingMode)
 Decrement. More...
 
int EOR (uint24_t, AddressingMode)
 XOR, Exclusive OR accumulator with memory. More...
 
int TCD (uint24_t, AddressingMode)
 Transfer 16 bit A to DP. More...
 
int TCS (uint24_t, AddressingMode)
 Transfer 16 bit A to SP. More...
 
int TDC (uint24_t, AddressingMode)
 Transfer DP to 16 bit A. More...
 
int TSC (uint24_t, AddressingMode)
 Transfer DP to 16 bit A. More...
 
int TSX (uint24_t, AddressingMode)
 Transfer SP to X. More...
 
int TXA (uint24_t, AddressingMode)
 Transfer X to A. More...
 
int TYA (uint24_t, AddressingMode)
 Transfer Y to A. More...
 
int TXY (uint24_t, AddressingMode)
 Transfer X to Y. More...
 
int TYX (uint24_t, AddressingMode)
 Transfer Y to X. More...
 
int TSB (uint24_t, AddressingMode)
 Test and Set Memory Bits Against Accumulator. More...
 
int TRB (uint24_t, AddressingMode)
 Test and Reset Memory Bits Against Accumulator. More...
 
int XBA (uint24_t, AddressingMode)
 Exchange the B and A Accumulators. More...
 
int BIT (uint24_t, AddressingMode)
 Test Memory Bits against Accumulator. More...
 
int ASL (uint24_t, AddressingMode)
 Arithmetic Shift Left. More...
 
int LSR (uint24_t, AddressingMode)
 
int ROL (uint24_t, AddressingMode)
 
int ROR (uint24_t, AddressingMode)
 
int PER (uint24_t, AddressingMode)
 Push Effective PC Relative Indirect Address. More...
 
int PEI (uint24_t, AddressingMode)
 Push Effective Indirect Address. More...
 
int PEA (uint24_t, AddressingMode)
 Push Effective Absolute Address. More...
 
int STP (uint24_t, AddressingMode)
 Stop the processor. More...
 
int WAI (uint24_t, AddressingMode)
 Wait for Interrupt. More...
 
int WDM (uint24_t, AddressingMode)
 WDM Reserved for Future Expansion (used as a code breakpoint) More...
 
int MVN (uint24_t, AddressingMode)
 Block Move Next. This instruction is special: it takes parameter in the registers. More...
 
int MVP (uint24_t, AddressingMode)
 Block Move Previous. This instruction is special: it takes parameter in the registers. More...
 

Private Attributes

Registers _registers {}
 All the registers of the CPU. More...
 
InternalRegisters _internalRegisters {}
 Internal registers of the CPU (accessible from the bus via addr $4200 to $421F). More...
 
bool _isEmulationMode = true
 Is the CPU running in emulation mode (in 8bits) More...
 
bool _isStopped = false
 If the processor is stopped (using an STP instruction), the clock is stopped and no instruction will be run until a manual reset. More...
 
bool _isWaitingForInterrupt = false
 Is the processor waiting for an interrupt (if true, instructions are not run until an interrupt is requested). More...
 
std::reference_wrapper< Memory::IMemoryBus_bus
 The memory bus to use for read/write. More...
 
Cartridge::Header_cartridgeHeader
 The cartridge header (stored for interrupt vectors..) More...
 
std::array< DMA, 8 > _dmaChannels
 DMA channels witch are mapped to the bus. More...
 
bool _hasIndexCrossedPageBoundary = false
 True if an addressing mode with an iterator (x, y) has crossed the page. (Used because crossing the page boundary take one more cycle to run certain instructions). More...
 

Additional Inherited Members

- Protected Attributes inherited from ComSquare::Memory::AMemory
uint24_t _start = 0
 The starting address mapped to this component. More...
 
uint24_t _end = 0
 The last continuous address mapped to this components. For shadows, see the MemoryShadow class. More...
 

Detailed Description

The main CPU.

Constructor & Destructor Documentation

◆ CPU() [1/2]

ComSquare::CPU::CPU::CPU ( Memory::IMemoryBus bus,
Cartridge::Header cartridgeHeader 
)

Construct a new generic CPU.

Parameters
busThe memory bus to use to transfer data.
cartridgeHeaderThe header used to know interrupts, main entry point etc...

◆ CPU() [2/2]

ComSquare::CPU::CPU::CPU ( const CPU )
default

A default copy constructor.

◆ ~CPU()

ComSquare::CPU::CPU::~CPU ( )
overridedefault

A default destructor.

Member Function Documentation

◆ _checkInterrupts()

void ComSquare::CPU::CPU::_checkInterrupts ( )
private

Check if an interrupt is requested and handle it.

◆ _getAbsoluteAddr()

uint24_t ComSquare::CPU::CPU::_getAbsoluteAddr ( )
private

The effective address is formed by DBR:<16-bit exp>. (This functions returns the 24bit space address of the value).

◆ _getAbsoluteIndexedByXAddr()

uint24_t ComSquare::CPU::CPU::_getAbsoluteIndexedByXAddr ( )
private

The absolute expression is added with X and combined with DBR to form the effective address.

◆ _getAbsoluteIndexedByXLongAddr()

uint24_t ComSquare::CPU::CPU::_getAbsoluteIndexedByXLongAddr ( )
private

The effective address is formed by adding the <long exp> with X.

◆ _getAbsoluteIndexedByYAddr()

uint24_t ComSquare::CPU::CPU::_getAbsoluteIndexedByYAddr ( )
private

The absolute expression is added with Y and combined with DBR to form the effective address.

◆ _getAbsoluteIndirectAddr()

uint24_t ComSquare::CPU::CPU::_getAbsoluteIndirectAddr ( )
private

2 bytes are pulled from the <abs exp> to form the effective address.

◆ _getAbsoluteIndirectIndexedByXAddr()

uint24_t ComSquare::CPU::CPU::_getAbsoluteIndirectIndexedByXAddr ( )
private

The <abs exp> is added with X, then 2 bytes are pulled from that address to form the new location.

◆ _getAbsoluteIndirectLongAddr()

uint24_t ComSquare::CPU::CPU::_getAbsoluteIndirectLongAddr ( )
private

3 bytes are pulled from the <abs exp> to form the effective address.

◆ _getAbsoluteLongAddr()

uint24_t ComSquare::CPU::CPU::_getAbsoluteLongAddr ( )
private

The effective address is the expression. (This functions returns the 24bit space address of the value).

◆ _getDirectAddr()

uint24_t ComSquare::CPU::CPU::_getDirectAddr ( )
private

The destination is formed by adding the direct page register with the 8-bit address to form an effective address. (This functions returns the 24bit space address of the value).

◆ _getDirectIndexedByXAddr()

uint24_t ComSquare::CPU::CPU::_getDirectIndexedByXAddr ( )
private

The DP address is added to X to form the effective address. The effective address is always in bank 0.

◆ _getDirectIndexedByYAddr()

uint24_t ComSquare::CPU::CPU::_getDirectIndexedByYAddr ( )
private

The DP address is added to Y to form the effective address. The effective address is always in bank 0.

◆ _getDirectIndirectAddr()

uint24_t ComSquare::CPU::CPU::_getDirectIndirectAddr ( )
private

2 bytes are pulled from the direct page address to form the 16-bit address. It is combined with DBR to form a 24-bit effective address.

◆ _getDirectIndirectIndexedXAddr()

uint24_t ComSquare::CPU::CPU::_getDirectIndirectIndexedXAddr ( )
private

The direct page address is calculated and added with x. 2 bytes from the dp address combined with DBR will form the effective address.

◆ _getDirectIndirectIndexedYAddr()

uint24_t ComSquare::CPU::CPU::_getDirectIndirectIndexedYAddr ( )
private

The address is DBR:$(read($($Value + D)) + Y). (This functions returns the 24bit space address of the value).

◆ _getDirectIndirectIndexedYLongAddr()

uint24_t ComSquare::CPU::CPU::_getDirectIndirectIndexedYLongAddr ( )
private

This mode is like the previous addressing mode, but the difference is that rather than pulling 2 bytes from the DP address, it pulls 3 bytes to form the effective address.

◆ _getDirectIndirectLongAddr()

uint24_t ComSquare::CPU::CPU::_getDirectIndirectLongAddr ( )
private

3 bytes are pulled from the direct page address to form an effective address.

◆ _getImmediateAddr16Bits()

uint24_t ComSquare::CPU::CPU::_getImmediateAddr16Bits ( )
private

Immediate address mode is specified with a value in 16 bits. (This functions returns the 24bit space address of the value).

◆ _getImmediateAddr8Bits()

uint24_t ComSquare::CPU::CPU::_getImmediateAddr8Bits ( )
private

Immediate address mode is specified with a value in 8 bits. (This functions returns the 24bit space address of the value).

◆ _getImmediateAddrForA()

uint24_t ComSquare::CPU::CPU::_getImmediateAddrForA ( )
private

Immediate address mode is specified with a value in 8 or 16 bits. The value is 16 bits if the m flag is unset. (This functions returns the 24bit space address of the value).

◆ _getImmediateAddrForX()

uint24_t ComSquare::CPU::CPU::_getImmediateAddrForX ( )
private

Immediate address mode is specified with a value in 8 or 16 bits. The value is 16 bits if the x flag is unset. (This functions returns the 24bit space address of the value).

◆ _getStackRelativeAddr()

uint24_t ComSquare::CPU::CPU::_getStackRelativeAddr ( )
private

The stack register is added to the <8-bit exp> to form the effective address.

◆ _getStackRelativeIndirectIndexedYAddr()

uint24_t ComSquare::CPU::CPU::_getStackRelativeIndirectIndexedYAddr ( )
private

The <8-bit exp> is added to S and combined with DBR to form the base address. Y is added to the base address to form the effective address.

◆ _getValueAddr()

uint24_t ComSquare::CPU::CPU::_getValueAddr ( const Instruction instruction)
private

Get the parameter address of an instruction from it's addressing mode. @info The current program counter should point to the instruction's opcode + 1.

Returns
The address of the data to read on the instruction.

◆ _pop()

uint8_t ComSquare::CPU::CPU::_pop ( )
private

Pop 8 bits of data from the stack.

◆ _pop16()

uint16_t ComSquare::CPU::CPU::_pop16 ( )
private

Pop 16 bits of data from the stack.

◆ _push() [1/2]

void ComSquare::CPU::CPU::_push ( uint16_t  data)
private

Push 16 bits of data to the stack.

◆ _push() [2/2]

void ComSquare::CPU::CPU::_push ( uint8_t  data)
private

Push 8 bits of data to the stack.

◆ _readPC()

uint8_t ComSquare::CPU::CPU::_readPC ( )
inlineprivate

Return the data at the program bank concatenated with the program counter. It also increment the program counter (the program bank is not incremented on overflows).

◆ _runInterrupt()

void ComSquare::CPU::CPU::_runInterrupt ( uint24_t  nativeHandler,
uint24_t  emulationHandler 
)
private

Run an interrupt (save state of the processor and jump to the interrupt handler)

◆ ADC()

int ComSquare::CPU::CPU::ADC ( uint24_t  valueAddr,
AddressingMode  mode 
)
private

Add with carry - Adds operand to the Accumulator; adds an additional 1 if carry is set.

◆ AND()

int ComSquare::CPU::CPU::AND ( uint24_t  valueAddr,
AddressingMode  mode 
)
private

And accumulator with memory.

◆ ASL()

int ComSquare::CPU::CPU::ASL ( uint24_t  valueAddr,
AddressingMode  mode 
)
private

Arithmetic Shift Left.

◆ BCC()

int ComSquare::CPU::CPU::BCC ( uint24_t  valueAddr,
AddressingMode   
)
private

Branch if carry clear.

◆ BCS()

int ComSquare::CPU::CPU::BCS ( uint24_t  valueAddr,
AddressingMode   
)
private

Branch if carry set.

◆ BEQ()

int ComSquare::CPU::CPU::BEQ ( uint24_t  valueAddr,
AddressingMode   
)
private

Branch if equal.

◆ BIT()

int ComSquare::CPU::CPU::BIT ( uint24_t  valueAddr,
AddressingMode  mode 
)
private

Test Memory Bits against Accumulator.

◆ BMI()

int ComSquare::CPU::CPU::BMI ( uint24_t  valueAddr,
AddressingMode   
)
private

Branch if minus.

◆ BNE()

int ComSquare::CPU::CPU::BNE ( uint24_t  valueAddr,
AddressingMode   
)
private

Branch if not equal.

◆ BPL()

int ComSquare::CPU::CPU::BPL ( uint24_t  valueAddr,
AddressingMode   
)
private

Branch if plus.

◆ BRA()

int ComSquare::CPU::CPU::BRA ( uint24_t  valueAddr,
AddressingMode   
)
private

Branch always.

◆ BRK()

int ComSquare::CPU::CPU::BRK ( uint24_t  ,
AddressingMode   
)
private

Break instruction - Causes a software break. The PC is loaded from a vector table.

◆ BRL()

int ComSquare::CPU::CPU::BRL ( uint24_t  valueAddr,
AddressingMode   
)
private

Branch always long.

◆ BVC()

int ComSquare::CPU::CPU::BVC ( uint24_t  valueAddr,
AddressingMode   
)
private

Branch if Overflow Clear.

◆ BVS()

int ComSquare::CPU::CPU::BVS ( uint24_t  valueAddr,
AddressingMode   
)
private

Branch if Overflow Set.

◆ CLC()

int ComSquare::CPU::CPU::CLC ( uint24_t  ,
AddressingMode   
)
private

Clear the carry flag.

◆ CLD()

int ComSquare::CPU::CPU::CLD ( uint24_t  ,
AddressingMode   
)
private

Clear the decimal flag.

◆ CLI()

int ComSquare::CPU::CPU::CLI ( uint24_t  ,
AddressingMode   
)
private

Clear the Interrupt Disable flag.

◆ CLV()

int ComSquare::CPU::CPU::CLV ( uint24_t  ,
AddressingMode   
)
private

Clear the overflow flag.

◆ CMP()

int ComSquare::CPU::CPU::CMP ( uint24_t  valueAddr,
AddressingMode  mode 
)
private

Compare Accumulator with Memory.

◆ COP()

int ComSquare::CPU::CPU::COP ( uint24_t  ,
AddressingMode   
)
private

Co-Processor Enable instruction - Causes a software break. The PC is loaded from a vector table.

◆ CPX()

int ComSquare::CPU::CPU::CPX ( uint24_t  valueAddr,
AddressingMode  mode 
)
private

Compare the X register with the memory.

◆ CPY()

int ComSquare::CPU::CPU::CPY ( uint24_t  valueAddr,
AddressingMode  mode 
)
private

Compare the Y register with the memory.

◆ DEC()

int ComSquare::CPU::CPU::DEC ( uint24_t  valueAddr,
AddressingMode  mode 
)
private

Decrement.

◆ DEX()

int ComSquare::CPU::CPU::DEX ( uint24_t  ,
AddressingMode   
)
private

Decrement the X register.

◆ DEY()

int ComSquare::CPU::CPU::DEY ( uint24_t  ,
AddressingMode   
)
private

Decrement the Y register.

◆ EOR()

int ComSquare::CPU::CPU::EOR ( uint24_t  valueAddr,
AddressingMode  mode 
)
private

XOR, Exclusive OR accumulator with memory.

◆ executeInstruction()

unsigned ComSquare::CPU::CPU::executeInstruction ( )

Execute a single instruction.

Returns
The number of CPU cycles that the instruction took.

◆ getBus()

Memory::IMemoryBus& ComSquare::CPU::CPU::getBus ( )
inline

Get the memory bus used by this CPU.

◆ getComponent()

Component ComSquare::CPU::CPU::getComponent ( ) const
overridevirtual

Get the component of this accessor (used for debug purpose)

Implements ComSquare::Memory::IMemory.

◆ getName()

std::string ComSquare::CPU::CPU::getName ( ) const
overridevirtual

Get the name of this accessor (used for debug purpose)

Implements ComSquare::Memory::IMemory.

◆ getSize()

uint24_t ComSquare::CPU::CPU::getSize ( ) const
overridevirtual

Get the size of the data. This size can be lower than the mapped data.

Returns
The number of bytes inside this memory.

Implements ComSquare::Memory::IMemory.

◆ getValueName()

std::string ComSquare::CPU::CPU::getValueName ( uint24_t  addr) const
overridevirtual

Get the name of the data at the address.

Parameters
addrThe address (in local space)

Implements ComSquare::Memory::IMemory.

◆ INC()

int ComSquare::CPU::CPU::INC ( uint24_t  valueAddr,
AddressingMode  mode 
)
private

Increment.

◆ INX()

int ComSquare::CPU::CPU::INX ( uint24_t  ,
AddressingMode   
)
private

Increment the X register.

◆ INY()

int ComSquare::CPU::CPU::INY ( uint24_t  ,
AddressingMode   
)
private

Increment the Y register.

◆ JML()

int ComSquare::CPU::CPU::JML ( uint24_t  valueAddr,
AddressingMode   
)
private

Long jump.

◆ JMP()

int ComSquare::CPU::CPU::JMP ( uint24_t  valueAddr,
AddressingMode   
)
private

Jump.

◆ JSL()

int ComSquare::CPU::CPU::JSL ( uint24_t  addr,
AddressingMode   
)
private

Jump to subroutine (long)

◆ JSR()

int ComSquare::CPU::CPU::JSR ( uint24_t  addr,
AddressingMode   
)
private

Jump to subroutine.

◆ LDA()

int ComSquare::CPU::CPU::LDA ( uint24_t  addr,
AddressingMode  mode 
)
private

Load the accumulator from memory.

◆ LDX()

int ComSquare::CPU::CPU::LDX ( uint24_t  addr,
AddressingMode  mode 
)
private

Load the X index register from memory.

◆ LDY()

int ComSquare::CPU::CPU::LDY ( uint24_t  addr,
AddressingMode  mode 
)
private

Load the Y index register from memory.

◆ LSR()

int ComSquare::CPU::CPU::LSR ( uint24_t  valueAddr,
AddressingMode  mode 
)
private

◆ MVN()

int ComSquare::CPU::CPU::MVN ( uint24_t  params,
AddressingMode   
)
private

Block Move Next. This instruction is special: it takes parameter in the registers.

Parameters
X_registerSource address
Y_registerDestination address
C_register(16 bits accumulator) Length -1

◆ MVP()

int ComSquare::CPU::CPU::MVP ( uint24_t  params,
AddressingMode   
)
private

Block Move Previous. This instruction is special: it takes parameter in the registers.

Parameters
X_registerSource address (last byte)
Y_registerDestination address (last byte)
C_register(16 bits accumulator) Length -1

◆ NOP()

int ComSquare::CPU::CPU::NOP ( uint24_t  ,
AddressingMode   
)
private

No OP.

◆ operator=()

CPU& ComSquare::CPU::CPU::operator= ( const CPU )
delete

A CPU is not assignable.

◆ ORA()

int ComSquare::CPU::CPU::ORA ( uint24_t  valueAddr,
AddressingMode  mode 
)
private

Or accumulator with memory.

◆ PEA()

int ComSquare::CPU::CPU::PEA ( uint24_t  value,
AddressingMode   
)
private

Push Effective Absolute Address.

◆ PEI()

int ComSquare::CPU::CPU::PEI ( uint24_t  value,
AddressingMode   
)
private

Push Effective Indirect Address.

◆ PER()

int ComSquare::CPU::CPU::PER ( uint24_t  valueAddr,
AddressingMode   
)
private

Push Effective PC Relative Indirect Address.

◆ PHA()

int ComSquare::CPU::CPU::PHA ( uint24_t  ,
AddressingMode   
)
private

Push the accumulator to the stack.

◆ PHB()

int ComSquare::CPU::CPU::PHB ( uint24_t  ,
AddressingMode   
)
private

Push the data bank register to the stack.

◆ PHD()

int ComSquare::CPU::CPU::PHD ( uint24_t  ,
AddressingMode   
)
private

Push the direct page register to the stack.

◆ PHK()

int ComSquare::CPU::CPU::PHK ( uint24_t  ,
AddressingMode   
)
private

Push the program bank register to the stack.

◆ PHP()

int ComSquare::CPU::CPU::PHP ( uint24_t  ,
AddressingMode   
)
private

Push the processor status register to the stack.

◆ PHX()

int ComSquare::CPU::CPU::PHX ( uint24_t  ,
AddressingMode   
)
private

Push the x index register to the stack.

◆ PHY()

int ComSquare::CPU::CPU::PHY ( uint24_t  ,
AddressingMode   
)
private

Push the y index register to the stack.

◆ PLA()

int ComSquare::CPU::CPU::PLA ( uint24_t  ,
AddressingMode   
)
private

Pull the accumulator to the stack.

◆ PLB()

int ComSquare::CPU::CPU::PLB ( uint24_t  ,
AddressingMode   
)
private

Pull the data bank register to the stack.

◆ PLD()

int ComSquare::CPU::CPU::PLD ( uint24_t  ,
AddressingMode   
)
private

Pull the direct page register to the stack.

◆ PLP()

int ComSquare::CPU::CPU::PLP ( uint24_t  ,
AddressingMode   
)
private

Pull the processor status register to the stack.

◆ PLX()

int ComSquare::CPU::CPU::PLX ( uint24_t  ,
AddressingMode   
)
private

Pull the x index register to the stack.

◆ PLY()

int ComSquare::CPU::CPU::PLY ( uint24_t  ,
AddressingMode   
)
private

Pull the y index register to the stack.

◆ read()

uint8_t ComSquare::CPU::CPU::read ( uint24_t  addr)
overridevirtual

Read from the internal CPU register.

@bref The CPU's internal registers starts at $4200 and finish at $421F.

Parameters
addrThe address to read from. The address 0x0 should refer to the first byte of the register.
Exceptions
InvalidAddresswill be thrown if the address is more than $1F (the number of register).
Returns
Return the value of the register.

Implements ComSquare::Memory::IMemory.

◆ REP()

int ComSquare::CPU::CPU::REP ( uint24_t  valueAddr,
AddressingMode   
)
private

Reset status bits.

◆ RESB()

int ComSquare::CPU::CPU::RESB ( )

Reset interrupt - Called on boot and when the reset button is pressed.

Note
This also triggers the callback onReset;

◆ ROL()

int ComSquare::CPU::CPU::ROL ( uint24_t  valueAddr,
AddressingMode  mode 
)
private

◆ ROR()

int ComSquare::CPU::CPU::ROR ( uint24_t  valueAddr,
AddressingMode  mode 
)
private

◆ RTI()

int ComSquare::CPU::CPU::RTI ( uint24_t  ,
AddressingMode   
)
private

Return from Interrupt - Used to return from a interrupt handler.

◆ RTL()

int ComSquare::CPU::CPU::RTL ( uint24_t  ,
AddressingMode   
)
private

Return from subroutine long.

◆ RTS()

int ComSquare::CPU::CPU::RTS ( uint24_t  ,
AddressingMode   
)
private

Return from subroutine.

◆ runDMA()

unsigned ComSquare::CPU::CPU::runDMA ( unsigned  maxCycles)

Run DMA's pending transfers.

Parameters
maxCyclesThe maximum of cycle to run
Returns
The number of CPU cycles that elapsed

◆ SBC()

int ComSquare::CPU::CPU::SBC ( uint24_t  valueAddr,
AddressingMode  mode 
)
private

Subtract with Borrow from Accumulator.

◆ SEC()

int ComSquare::CPU::CPU::SEC ( uint24_t  ,
AddressingMode   
)
private

Set the carry Flag.

◆ SED()

int ComSquare::CPU::CPU::SED ( uint24_t  ,
AddressingMode   
)
private

Set the decimal flag.

◆ SEI()

int ComSquare::CPU::CPU::SEI ( uint24_t  ,
AddressingMode   
)
private

Set the Interrupt Disable flag.

◆ SEP()

int ComSquare::CPU::CPU::SEP ( uint24_t  valueAddr,
AddressingMode   
)
private

Set status bits.

◆ setBus()

void ComSquare::CPU::CPU::setBus ( Memory::IMemoryBus bus)

Set the memory bus used by this CPU.

Parameters
busThe bus to use.

◆ STA()

int ComSquare::CPU::CPU::STA ( uint24_t  addr,
AddressingMode  mode 
)
private

Store the accumulator to memory.

◆ STP()

int ComSquare::CPU::CPU::STP ( uint24_t  ,
AddressingMode   
)
private

Stop the processor.

◆ STX()

int ComSquare::CPU::CPU::STX ( uint24_t  addr,
AddressingMode  mode 
)
private

Store the index register X to memory.

◆ STY()

int ComSquare::CPU::CPU::STY ( uint24_t  addr,
AddressingMode  mode 
)
private

Store the index register Y to memory.

◆ STZ()

int ComSquare::CPU::CPU::STZ ( uint24_t  addr,
AddressingMode  mode 
)
private

Store zero to the memory.

◆ TAX()

int ComSquare::CPU::CPU::TAX ( uint24_t  ,
AddressingMode   
)
private

Transfer A to X.

◆ TAY()

int ComSquare::CPU::CPU::TAY ( uint24_t  ,
AddressingMode   
)
private

Transfer A to Y.

◆ TCD()

int ComSquare::CPU::CPU::TCD ( uint24_t  ,
AddressingMode   
)
private

Transfer 16 bit A to DP.

◆ TCS()

int ComSquare::CPU::CPU::TCS ( uint24_t  ,
AddressingMode   
)
private

Transfer 16 bit A to SP.

◆ TDC()

int ComSquare::CPU::CPU::TDC ( uint24_t  ,
AddressingMode   
)
private

Transfer DP to 16 bit A.

◆ TRB()

int ComSquare::CPU::CPU::TRB ( uint24_t  valueAddr,
AddressingMode  mode 
)
private

Test and Reset Memory Bits Against Accumulator.

◆ TSB()

int ComSquare::CPU::CPU::TSB ( uint24_t  valueAddr,
AddressingMode  mode 
)
private

Test and Set Memory Bits Against Accumulator.

◆ TSC()

int ComSquare::CPU::CPU::TSC ( uint24_t  ,
AddressingMode   
)
private

Transfer DP to 16 bit A.

◆ TSX()

int ComSquare::CPU::CPU::TSX ( uint24_t  ,
AddressingMode   
)
private

Transfer SP to X.

◆ TXA()

int ComSquare::CPU::CPU::TXA ( uint24_t  ,
AddressingMode   
)
private

Transfer X to A.

◆ TXS()

int ComSquare::CPU::CPU::TXS ( uint24_t  ,
AddressingMode   
)
private

Transfer X to SP.

◆ TXY()

int ComSquare::CPU::CPU::TXY ( uint24_t  ,
AddressingMode   
)
private

Transfer X to Y.

◆ TYA()

int ComSquare::CPU::CPU::TYA ( uint24_t  ,
AddressingMode   
)
private

Transfer Y to A.

◆ TYX()

int ComSquare::CPU::CPU::TYX ( uint24_t  ,
AddressingMode   
)
private

Transfer Y to X.

◆ update()

unsigned ComSquare::CPU::CPU::update ( unsigned  maxCycle)

This function continue to execute the Cartridge code.

Parameters
maxCycleThe maximum number of cycle to run.
Returns
The number of CPU cycles that elapsed

◆ WAI()

int ComSquare::CPU::CPU::WAI ( uint24_t  ,
AddressingMode   
)
private

Wait for Interrupt.

◆ WDM()

int ComSquare::CPU::CPU::WDM ( uint24_t  ,
AddressingMode   
)
private

WDM Reserved for Future Expansion (used as a code breakpoint)

◆ write()

void ComSquare::CPU::CPU::write ( uint24_t  addr,
uint8_t  data 
)
overridevirtual

Write data to the internal CPU register.

Parameters
addrThe address to write to. The address 0x0 should refer to the first byte of register.
dataThe new value of the register.
Exceptions
InvalidAddresswill be thrown if the address is more than $1F (the number of register).

Implements ComSquare::Memory::IMemory.

◆ XBA()

int ComSquare::CPU::CPU::XBA ( uint24_t  ,
AddressingMode   
)
private

Exchange the B and A Accumulators.

◆ XCE()

int ComSquare::CPU::CPU::XCE ( uint24_t  ,
AddressingMode   
)
private

Exchange Carry and Emulation Flags.

Member Data Documentation

◆ _bus

std::reference_wrapper<Memory::IMemoryBus> ComSquare::CPU::CPU::_bus
private

The memory bus to use for read/write.

◆ _cartridgeHeader

Cartridge::Header& ComSquare::CPU::CPU::_cartridgeHeader
private

The cartridge header (stored for interrupt vectors..)

◆ _dmaChannels

std::array<DMA, 8> ComSquare::CPU::CPU::_dmaChannels
private

DMA channels witch are mapped to the bus.

◆ _hasIndexCrossedPageBoundary

bool ComSquare::CPU::CPU::_hasIndexCrossedPageBoundary = false
private

True if an addressing mode with an iterator (x, y) has crossed the page. (Used because crossing the page boundary take one more cycle to run certain instructions).

◆ _internalRegisters

InternalRegisters ComSquare::CPU::CPU::_internalRegisters {}
private

Internal registers of the CPU (accessible from the bus via addr $4200 to $421F).

◆ _isEmulationMode

bool ComSquare::CPU::CPU::_isEmulationMode = true
private

Is the CPU running in emulation mode (in 8bits)

◆ _isStopped

bool ComSquare::CPU::CPU::_isStopped = false
private

If the processor is stopped (using an STP instruction), the clock is stopped and no instruction will be run until a manual reset.

◆ _isWaitingForInterrupt

bool ComSquare::CPU::CPU::_isWaitingForInterrupt = false
private

Is the processor waiting for an interrupt (if true, instructions are not run until an interrupt is requested).

◆ _registers

Registers ComSquare::CPU::CPU::_registers {}
private

All the registers of the CPU.

◆ instructions

const Instruction ComSquare::CPU::CPU::instructions[0x100]

All the instructions of the CPU. @info Instructions are indexed by their opcode.

◆ IsAbortRequested

bool ComSquare::CPU::CPU::IsAbortRequested = false

Is an abort requested.

◆ isDisabled

bool ComSquare::CPU::CPU::isDisabled = false

True if you want to disable updates of this CPU.

◆ IsIRQRequested

bool ComSquare::CPU::CPU::IsIRQRequested = false

Is an interrupt (maskable) requested.

◆ IsNMIRequested

bool ComSquare::CPU::CPU::IsNMIRequested = false

Is an NMI (non-maskable interrupt) requested.

◆ onReset

Callback ComSquare::CPU::CPU::onReset

The callback triggered on reset.


The documentation for this class was generated from the following files: