1#ifndef YAZE_APP_EMU_CPU_H_
2#define YAZE_APP_EMU_CPU_H_
7#include <unordered_map>
23 const std::string& instr)
43 void Reset(
bool hard =
false);
49 bool immediate,
bool accumulator_mode);
51 void UpdatePC(uint8_t instruction_length) {
PC += instruction_length; }
112 void SetZN(uint16_t value,
bool byte) {
160 uint16_t
ReadWord(uint32_t address, uint32_t address_high,
161 bool int_check =
false) {
164 uint8_t value2 =
ReadByte(address_high);
165 return value | (value2 << 8);
169 uint8_t value2 =
ReadByte(address + 1);
170 uint8_t value3 =
ReadByte(address + 2);
171 return value | (value2 << 8) | (value3 << 16);
178 void WriteWord(uint32_t address, uint32_t address_high, uint16_t value,
179 bool reversed =
false,
bool int_check =
false) {
199 if (
E)
SetSP((
SP() & 0xff) | 0x100);
201 void PushWord(uint16_t value,
bool int_check =
false) {
213 if (
E)
SetSP((
SP() & 0xff) | 0x100);
224 return (high << 16) | low;
257 uint32_t
AdrAbx(uint32_t* low,
bool write);
266 uint32_t
AdrAby(uint32_t* low,
bool write);
269 uint32_t
AdrIdx(uint32_t* low);
271 uint32_t
AdrIdp(uint32_t* low);
272 uint32_t
AdrIdy(uint32_t* low,
bool write);
273 uint32_t
AdrIdl(uint32_t* low);
274 uint32_t
AdrIly(uint32_t* low);
275 uint32_t
AdrIsy(uint32_t* low);
276 uint32_t
Immediate(uint32_t* low,
bool xFlag);
309 uint32_t
AdrAbl(uint32_t* low);
316 uint32_t
AdrAlx(uint32_t* low);
330 void BlockMove(uint16_t source, uint16_t dest, uint16_t length);
338 uint32_t
AdrDp(uint32_t* low);
347 uint32_t
AdrDpx(uint32_t* low);
355 uint32_t
AdrDpy(uint32_t* low);
413 uint32_t
AdrSr(uint32_t* low);
429 void ADC(uint16_t operand);
432 void AND(uint32_t address,
bool immediate =
false);
436 void ASL(uint16_t address);
448 void BIT(uint16_t address);
487 void CMP(uint32_t address,
bool immediate =
false);
493 void CPX(uint32_t address,
bool immediate =
false);
496 void CPY(uint32_t address,
bool immediate =
false);
499 void DEC(uint32_t address,
bool accumulator =
false);
508 void EOR(uint32_t address,
bool immediate =
false);
511 void INC(uint32_t address,
bool accumulator =
false);
520 void JMP(uint16_t address);
523 void JML(uint16_t address);
526 void JSR(uint16_t address);
529 void JSL(uint16_t address);
532 void LDA(uint16_t address,
bool immediate =
false,
bool direct_page =
false,
533 bool data_bank =
false);
536 void LDX(uint16_t address,
bool immediate =
false);
539 void LDY(uint16_t address,
bool immediate =
false);
542 void LSR(uint16_t address,
bool accumulator =
false);
554 void ORA(uint32_t low, uint32_t high);
608 void ROL(uint32_t address,
bool accumulator =
false);
611 void ROR(uint32_t address,
bool accumulator =
false);
623 void SBC(uint32_t operand,
bool immediate =
false);
638 void STA(uint32_t address);
644 void STX(uint16_t address);
647 void STY(uint16_t address);
650 void STZ(uint16_t address);
668 void TRB(uint16_t address);
671 void TSB(uint16_t address);
706 void And(uint32_t low, uint32_t high);
707 void Eor(uint32_t low, uint32_t high);
708 void Adc(uint32_t low, uint32_t high);
709 void Sbc(uint32_t low, uint32_t high);
710 void Cmp(uint32_t low, uint32_t high);
711 void Cpx(uint32_t low, uint32_t high);
712 void Cpy(uint32_t low, uint32_t high);
713 void Bit(uint32_t low, uint32_t high);
714 void Lda(uint32_t low, uint32_t high);
715 void Ldx(uint32_t low, uint32_t high);
716 void Ldy(uint32_t low, uint32_t high);
717 void Sta(uint32_t low, uint32_t high);
718 void Stx(uint32_t low, uint32_t high);
719 void Sty(uint32_t low, uint32_t high);
720 void Stz(uint32_t low, uint32_t high);
721 void Ror(uint32_t low, uint32_t high);
722 void Rol(uint32_t low, uint32_t high);
723 void Lsr(uint32_t low, uint32_t high);
724 void Asl(uint32_t low, uint32_t high);
725 void Inc(uint32_t low, uint32_t high);
726 void Dec(uint32_t low, uint32_t high);
727 void Tsb(uint32_t low, uint32_t high);
728 void Trb(uint32_t low, uint32_t high);
758 void compare(uint16_t register_value, uint16_t memory_value) {
762 uint8_t result8 =
static_cast<uint8_t
>(register_value) -
763 static_cast<uint8_t
>(memory_value);
768 result = register_value - memory_value;
A class to manage experimental feature flags.
virtual void UpdateClock(double delta)=0
void ANDAbsoluteLong(uint32_t address)
bool GetOverflowFlag() const
void SetZeroFlag(bool set)
uint16_t DirectPageIndexedY()
void SetBreakpoint(uint32_t address)
bool GetInterruptFlag() const
uint32_t DirectPageIndirectLong()
uint16_t ReadOpcodeWord(bool int_check=false)
void STA(uint32_t address)
uint32_t AbsoluteIndexedY()
void Lsr(uint32_t low, uint32_t high)
void Dec(uint32_t low, uint32_t high)
uint8_t GetInstructionLength(uint8_t opcode)
void CPX(uint32_t address, bool immediate=false)
uint32_t AdrAbx(uint32_t *low, bool write)
void UpdateClock(int delta_time)
bool GetNegativeFlag() const
void Adc(uint32_t low, uint32_t high)
void SetBreakFlag(bool set)
bool IsBreakpoint(uint32_t address)
void WriteLong(uint32_t address, uint32_t value)
void WriteWord(uint32_t address, uint32_t address_high, uint16_t value, bool reversed=false, bool int_check=false)
void SetZN(uint16_t value, bool byte)
void BlockMove(uint16_t source, uint16_t dest, uint16_t length)
uint32_t AdrIsy(uint32_t *low)
uint32_t AdrIdl(uint32_t *low)
void SetCarryFlag(bool set)
void CPY(uint32_t address, bool immediate=false)
uint16_t ReadWord(uint32_t address, uint32_t address_high, bool int_check=false)
void LogInstructions(uint16_t PC, uint8_t opcode, uint16_t operand, bool immediate, bool accumulator_mode)
void JSR(uint16_t address)
void SetDecimalFlag(bool set)
void SetSP(uint16_t value)
void TRB(uint16_t address)
void Sbc(uint32_t low, uint32_t high)
uint32_t AdrSr(uint32_t *low)
void Ror(uint32_t low, uint32_t high)
void STX(uint16_t address)
void Bit(uint32_t low, uint32_t high)
uint32_t AbsoluteLongIndexedX()
int GetAccumulatorSize() const
uint32_t ReadWordLong(uint32_t address)
memory::CpuCallbacks callbacks_
void LSR(uint16_t address, bool accumulator=false)
uint32_t StackRelativeIndirectIndexedY()
void SBC(uint32_t operand, bool immediate=false)
void DoBranch(bool check)
void EOR(uint32_t address, bool immediate=false)
void LDY(uint16_t address, bool immediate=false)
uint16_t Immediate(bool index_size=false)
uint16_t DirectPageIndexedX()
void CMP(uint32_t address, bool immediate=false)
void JSL(uint16_t address)
uint32_t AdrIdy(uint32_t *low, bool write)
void STY(uint16_t address)
uint32_t AdrAby(uint32_t *low, bool write)
void ROR(uint32_t address, bool accumulator=false)
void Reset(bool hard=false)
void Cpy(uint32_t low, uint32_t high)
void PushWord(uint16_t value, bool int_check=false)
uint32_t AdrDpx(uint32_t *low)
bool GetDecimalFlag() const
std::vector< uint32_t > breakpoints_
void ORA(uint32_t low, uint32_t high)
uint32_t Immediate(uint32_t *low, bool xFlag)
void SetFlags(uint8_t val)
uint32_t AdrAlx(uint32_t *low)
uint16_t DirectPageIndirect()
uint32_t AdrDpy(uint32_t *low)
void JMP(uint16_t address)
uint32_t AbsoluteIndexedX()
uint32_t AdrIdx(uint32_t *low)
auto mutable_log_instructions() -> bool *
void PushLong(uint32_t value)
void LDA(uint16_t address, bool immediate=false, bool direct_page=false, bool data_bank=false)
void Inc(uint32_t low, uint32_t high)
uint8_t ReadByte(uint32_t address)
void Asl(uint32_t low, uint32_t high)
uint16_t AbsoluteIndexedIndirect()
void Tsb(uint32_t low, uint32_t high)
void Cpx(uint32_t low, uint32_t high)
void SetOverflowFlag(bool set)
uint16_t PopWord(bool int_check=false)
bool GetCarryFlag() const
Cpu(memory::Memory &mem, Clock &vclock, memory::CpuCallbacks &callbacks)
bool GetBreakFlag() const
void And(uint32_t low, uint32_t high)
void Sty(uint32_t low, uint32_t high)
void JML(uint16_t address)
uint32_t AbsoluteIndirectLong()
void Ldy(uint32_t low, uint32_t high)
void ROL(uint32_t address, bool accumulator=false)
uint16_t DirectPageIndirectIndexedY()
void Cmp(uint32_t low, uint32_t high)
void compare(uint16_t register_value, uint16_t memory_value)
uint32_t AdrIly(uint32_t *low)
void set_int_delay(bool delay)
void SetIndexSize(bool set)
void Sta(uint32_t low, uint32_t high)
void SetAccumulatorSize(bool set)
void ClearBreakpoint(uint32_t address)
void AND(uint32_t address, bool immediate=false)
uint16_t DirectPageIndexedIndirectX()
void WriteByte(uint32_t address, uint8_t value)
uint32_t AdrAbl(uint32_t *low)
uint32_t Absolute(uint32_t *low)
void Ldx(uint32_t low, uint32_t high)
void SetInterruptFlag(bool set)
std::vector< InstructionEntry > instruction_log_
void ADC(uint16_t operand)
void LDX(uint16_t address, bool immediate=false)
uint32_t DirectPageIndirectLongIndexedY()
void DEC(uint32_t address, bool accumulator=false)
void PushByte(uint8_t value)
void BIT(uint16_t address)
uint32_t AdrIdp(uint32_t *low)
void Trb(uint32_t low, uint32_t high)
void SetFlag(uint8_t mask, bool set)
uint16_t AbsoluteIndirect()
void UpdatePC(uint8_t instruction_length)
void ExecuteInstruction(uint8_t opcode)
void Stz(uint32_t low, uint32_t high)
void Lda(uint32_t low, uint32_t high)
void ASL(uint16_t address)
void Eor(uint32_t low, uint32_t high)
void Rol(uint32_t low, uint32_t high)
bool GetFlag(uint8_t mask) const
uint32_t AdrDp(uint32_t *low)
void SetNegativeFlag(bool set)
void INC(uint32_t address, bool accumulator=false)
void Stx(uint32_t low, uint32_t high)
void STZ(uint16_t address)
void TSB(uint16_t address)
uint32_t GetAddress() const
uint8_t GetOpcode() const
const std::string & GetInstruction() const
InstructionEntry(uint32_t addr, uint8_t op, const std::string &ops, const std::string &instr)
const std::string & GetOperands() const
virtual uint16_t SP() const =0
virtual void SetSP(uint16_t value)=0
std::function< uint8_t(uint32_t)> read_byte
std::function< void(bool waiting)> idle
std::function< void(uint32_t, uint8_t)> write_byte