1#ifndef YAZE_APP_EMU_CPU_H_
2#define YAZE_APP_EMU_CPU_H_
7#include <unordered_map>
24 const std::string& instr)
44 void Reset(
bool hard =
false);
50 bool immediate,
bool accumulator_mode);
52 void UpdatePC(uint8_t instruction_length) {
PC += instruction_length; }
113 void SetZN(uint16_t value,
bool byte) {
161 uint16_t
ReadWord(uint32_t address, uint32_t address_high,
162 bool int_check =
false) {
165 uint8_t value2 =
ReadByte(address_high);
166 return value | (value2 << 8);
170 uint8_t value2 =
ReadByte(address + 1);
171 uint8_t value3 =
ReadByte(address + 2);
172 return value | (value2 << 8) | (value3 << 16);
179 void WriteWord(uint32_t address, uint32_t address_high, uint16_t value,
180 bool reversed =
false,
bool int_check =
false) {
200 if (
E)
SetSP((
SP() & 0xff) | 0x100);
202 void PushWord(uint16_t value,
bool int_check =
false) {
214 if (
E)
SetSP((
SP() & 0xff) | 0x100);
225 return (high << 16) | low;
258 uint32_t
AdrAbx(uint32_t* low,
bool write);
267 uint32_t
AdrAby(uint32_t* low,
bool write);
270 uint32_t
AdrIdx(uint32_t* low);
272 uint32_t
AdrIdp(uint32_t* low);
273 uint32_t
AdrIdy(uint32_t* low,
bool write);
274 uint32_t
AdrIdl(uint32_t* low);
275 uint32_t
AdrIly(uint32_t* low);
276 uint32_t
AdrIsy(uint32_t* low);
277 uint32_t
Immediate(uint32_t* low,
bool xFlag);
310 uint32_t
AdrAbl(uint32_t* low);
317 uint32_t
AdrAlx(uint32_t* low);
331 void BlockMove(uint16_t source, uint16_t dest, uint16_t length);
339 uint32_t
AdrDp(uint32_t* low);
348 uint32_t
AdrDpx(uint32_t* low);
356 uint32_t
AdrDpy(uint32_t* low);
414 uint32_t
AdrSr(uint32_t* low);
430 void ADC(uint16_t operand);
433 void AND(uint32_t address,
bool immediate =
false);
437 void ASL(uint16_t address);
449 void BIT(uint16_t address);
488 void CMP(uint32_t address,
bool immediate =
false);
494 void CPX(uint32_t address,
bool immediate =
false);
497 void CPY(uint32_t address,
bool immediate =
false);
500 void DEC(uint32_t address,
bool accumulator =
false);
509 void EOR(uint32_t address,
bool immediate =
false);
512 void INC(uint32_t address,
bool accumulator =
false);
521 void JMP(uint16_t address);
524 void JML(uint16_t address);
527 void JSR(uint16_t address);
530 void JSL(uint16_t address);
533 void LDA(uint16_t address,
bool immediate =
false,
bool direct_page =
false,
534 bool data_bank =
false);
537 void LDX(uint16_t address,
bool immediate =
false);
540 void LDY(uint16_t address,
bool immediate =
false);
543 void LSR(uint16_t address,
bool accumulator =
false);
555 void ORA(uint32_t low, uint32_t high);
609 void ROL(uint32_t address,
bool accumulator =
false);
612 void ROR(uint32_t address,
bool accumulator =
false);
624 void SBC(uint32_t operand,
bool immediate =
false);
639 void STA(uint32_t address);
645 void STX(uint16_t address);
648 void STY(uint16_t address);
651 void STZ(uint16_t address);
669 void TRB(uint16_t address);
672 void TSB(uint16_t address);
707 void And(uint32_t low, uint32_t high);
708 void Eor(uint32_t low, uint32_t high);
709 void Adc(uint32_t low, uint32_t high);
710 void Sbc(uint32_t low, uint32_t high);
711 void Cmp(uint32_t low, uint32_t high);
712 void Cpx(uint32_t low, uint32_t high);
713 void Cpy(uint32_t low, uint32_t high);
714 void Bit(uint32_t low, uint32_t high);
715 void Lda(uint32_t low, uint32_t high);
716 void Ldx(uint32_t low, uint32_t high);
717 void Ldy(uint32_t low, uint32_t high);
718 void Sta(uint32_t low, uint32_t high);
719 void Stx(uint32_t low, uint32_t high);
720 void Sty(uint32_t low, uint32_t high);
721 void Stz(uint32_t low, uint32_t high);
722 void Ror(uint32_t low, uint32_t high);
723 void Rol(uint32_t low, uint32_t high);
724 void Lsr(uint32_t low, uint32_t high);
725 void Asl(uint32_t low, uint32_t high);
726 void Inc(uint32_t low, uint32_t high);
727 void Dec(uint32_t low, uint32_t high);
728 void Tsb(uint32_t low, uint32_t high);
729 void Trb(uint32_t low, uint32_t high);
759 void compare(uint16_t register_value, uint16_t memory_value) {
763 uint8_t result8 =
static_cast<uint8_t
>(register_value) -
764 static_cast<uint8_t
>(memory_value);
769 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