48 sp = (sp & 0xff) | 0x100;
105 uint8_t instruction_length = 0;
106 uint16_t cache_pc =
PC;
107 uint32_t operand = 0;
108 bool immediate =
false;
113 uint32_t vector = (
E) ? 0xfffe : 0xffe6;
126 uint32_t high =
AdrIdx(&low);
131 uint32_t vector = (
E) ? 0xfff4 : 0xffe4;
144 uint32_t high =
AdrSr(&low);
150 uint32_t high =
AdrDp(&low);
156 uint32_t high =
AdrDp(&low);
162 uint32_t high =
AdrDp(&low);
168 uint32_t high =
AdrIdl(&low);
188 A = (
A & 0xff00) | ((
A << 1) & 0xff);
221 uint32_t high =
AdrAbl(&low);
231 uint32_t high =
AdrIdy(&low,
false);
237 uint32_t high =
AdrIdp(&low);
243 uint32_t high =
AdrIsy(&low);
249 uint32_t high =
AdrDp(&low);
255 uint32_t high =
AdrDpx(&low);
261 uint32_t high =
AdrDpx(&low);
267 uint32_t high =
AdrIly(&low);
278 uint32_t high =
AdrAby(&low,
false);
285 A = (
A & 0xff00) | ((
A + 1) & 0xff);
305 uint32_t high =
AdrAbx(&low,
false);
311 uint32_t high =
AdrAbx(&low,
true);
317 uint32_t high =
AdrAlx(&low);
330 uint32_t high =
AdrIdx(&low);
346 uint32_t high =
AdrSr(&low);
352 uint32_t high =
AdrDp(&low);
358 uint32_t high =
AdrDp(&low);
364 uint32_t high =
AdrDp(&low);
370 uint32_t high =
AdrIdl(&low);
392 A = (
A & 0xff00) | (result & 0xff);
427 uint32_t high =
AdrAbl(&low);
437 uint32_t high =
AdrIdy(&low,
false);
443 uint32_t high =
AdrIdp(&low);
449 uint32_t high =
AdrIsy(&low);
455 uint32_t high =
AdrDpx(&low);
461 uint32_t high =
AdrDpx(&low);
467 uint32_t high =
AdrDpx(&low);
473 uint32_t high =
AdrIly(&low);
484 uint32_t high =
AdrAby(&low,
false);
491 A = (
A & 0xff00) | ((
A - 1) & 0xff);
506 uint32_t high =
AdrAbx(&low,
false);
512 uint32_t high =
AdrAbx(&low,
false);
518 uint32_t high =
AdrAbx(&low,
true);
524 uint32_t high =
AdrAlx(&low);
539 uint32_t high =
AdrIdx(&low);
550 uint32_t high =
AdrSr(&low);
576 uint32_t high =
AdrDp(&low);
582 uint32_t high =
AdrDp(&low);
588 uint32_t high =
AdrIdl(&low);
612 A = (
A & 0xff00) | ((
A >> 1) & 0x7f);
643 uint32_t high =
AdrAbl(&low);
653 uint32_t high =
AdrIdy(&low,
false);
659 uint32_t high =
AdrIdp(&low);
665 uint32_t high =
AdrIsy(&low);
691 uint32_t high =
AdrDpx(&low);
697 uint32_t high =
AdrDpx(&low);
703 uint32_t high =
AdrIly(&low);
714 uint32_t high =
AdrAby(&low,
false);
743 uint32_t high =
AdrAbx(&low,
false);
749 uint32_t high =
AdrAbx(&low,
true);
755 uint32_t high =
AdrAlx(&low);
769 uint32_t high =
AdrIdx(&low);
781 uint32_t high =
AdrSr(&low);
787 uint32_t high =
AdrDp(&low);
793 uint32_t high =
AdrDp(&low);
799 uint32_t high =
AdrDp(&low);
805 uint32_t high =
AdrIdl(&low);
832 A = (
A & 0xff00) | ((
A >> 1) & 0x7f) | (C << 7);
834 A = (
A >> 1) | (C << 15);
867 uint32_t high =
AdrAbl(&low);
877 uint32_t high =
AdrIdy(&low,
false);
883 uint32_t high =
AdrIdp(&low);
889 uint32_t high =
AdrIsy(&low);
895 uint32_t high =
AdrDpx(&low);
901 uint32_t high =
AdrDpx(&low);
907 uint32_t high =
AdrDpx(&low);
913 uint32_t high =
AdrIly(&low);
924 uint32_t high =
AdrAby(&low,
false);
950 ((
PB << 16) | ((adr +
X + 1) & 0xffff)),
true);
955 uint32_t high =
AdrAbx(&low,
false);
961 uint32_t high =
AdrAbx(&low,
true);
967 uint32_t high =
AdrAlx(&low);
977 uint32_t high =
AdrIdx(&low);
989 uint32_t high =
AdrSr(&low);
995 uint32_t high =
AdrDp(&low);
1001 uint32_t high =
AdrDp(&low);
1007 uint32_t high =
AdrDp(&low);
1013 uint32_t high =
AdrIdl(&low);
1041 A = (
A & 0xff00) | (
X & 0xff);
1074 uint32_t high =
AdrAbl(&low);
1084 uint32_t high =
AdrIdy(&low,
true);
1090 uint32_t high =
AdrIdp(&low);
1096 uint32_t high =
AdrIsy(&low);
1102 uint32_t high =
AdrDpx(&low);
1108 uint32_t high =
AdrDpx(&low);
1114 uint32_t high =
AdrDpy(&low);
1120 uint32_t high =
AdrIly(&low);
1127 A = (
A & 0xff00) | (
Y & 0xff);
1136 uint32_t high =
AdrAby(&low,
true);
1163 uint32_t high =
AdrAbx(&low,
true);
1169 uint32_t high =
AdrAbx(&low,
true);
1175 uint32_t high =
AdrAlx(&low);
1187 uint32_t high =
AdrIdx(&low);
1199 uint32_t high =
AdrSr(&low);
1205 uint32_t high =
AdrDp(&low);
1211 uint32_t high =
AdrDp(&low);
1217 uint32_t high =
AdrDp(&low);
1223 uint32_t high =
AdrIdl(&low);
1281 uint32_t high =
AdrAbl(&low);
1291 uint32_t high =
AdrIdy(&low,
false);
1297 uint32_t high =
AdrIdp(&low);
1303 uint32_t high =
AdrIsy(&low);
1309 uint32_t high =
AdrDpx(&low);
1315 uint32_t high =
AdrDpx(&low);
1321 uint32_t high =
AdrDpy(&low);
1327 uint32_t high =
AdrIly(&low);
1338 uint32_t high =
AdrAby(&low,
false);
1364 uint32_t high =
AdrAbx(&low,
false);
1370 uint32_t high =
AdrAbx(&low,
false);
1376 uint32_t high =
AdrAby(&low,
false);
1382 uint32_t high =
AdrAlx(&low);
1394 uint32_t high =
AdrIdx(&low);
1407 uint32_t high =
AdrSr(&low);
1413 uint32_t high =
AdrDp(&low);
1419 uint32_t high =
AdrDp(&low);
1425 uint32_t high =
AdrDp(&low);
1431 uint32_t high =
AdrIdl(&low);
1487 uint32_t high =
AdrAbl(&low);
1497 uint32_t high =
AdrIdy(&low,
false);
1503 uint32_t high =
AdrIdp(&low);
1509 uint32_t high =
AdrIsy(&low);
1515 uint32_t high =
AdrDp(&low);
1521 uint32_t high =
AdrDpx(&low);
1527 uint32_t high =
AdrDpx(&low);
1533 uint32_t high =
AdrIly(&low);
1544 uint32_t high =
AdrAby(&low,
false);
1566 PC =
ReadWord(adr, ((adr + 1) & 0xffff),
false);
1573 uint32_t high =
AdrAbx(&low,
false);
1579 uint32_t high =
AdrAbx(&low,
true);
1585 uint32_t high =
AdrAlx(&low);
1597 uint32_t high =
AdrIdx(&low);
1610 uint32_t high =
AdrSr(&low);
1616 uint32_t high =
AdrDp(&low);
1622 uint32_t high =
AdrDp(&low);
1628 uint32_t high =
AdrDp(&low);
1634 uint32_t high =
AdrIdl(&low);
1660 uint8_t low =
A & 0xff;
1661 uint8_t high =
A >> 8;
1662 A = (low << 8) | high;
1689 uint32_t high =
AdrAbl(&low);
1699 uint32_t high =
AdrIdy(&low,
false);
1705 uint32_t high =
AdrIdp(&low);
1711 uint32_t high =
AdrIsy(&low);
1721 uint32_t high =
AdrDpx(&low);
1727 uint32_t high =
AdrDpx(&low);
1733 uint32_t high =
AdrIly(&low);
1744 uint32_t high =
AdrAby(&low,
false);
1774 uint16_t value =
ReadWord((
PB << 16) | ((adr +
X) & 0xffff),
1775 (
PB << 16) | ((adr +
X + 1) & 0xffff),
true);
1781 uint32_t high =
AdrAbx(&low,
false);
1787 uint32_t high =
AdrAbx(&low,
true);
1793 uint32_t high =
AdrAlx(&low);
1799 LogInstructions(cache_pc, opcode, operand, immediate, accumulator_mode);
1806 bool immediate,
bool accumulator_mode) {
1807 if (
flags()->kLogInstructions) {
1808 std::ostringstream oss;
1809 oss <<
"$" << std::uppercase << std::setw(2) << std::setfill(
'0')
1810 <<
static_cast<int>(
PB) <<
":" << std::hex <<
PC <<
": 0x"
1811 << std::setw(2) << std::setfill(
'0') << std::hex
1821 std::ostringstream oss_ops;
1823 if (accumulator_mode) {
1824 oss_ops << std::hex << std::setw(2) << std::setfill(
'0')
1825 <<
static_cast<int>(operand);
1827 oss_ops << std::hex << std::setw(4) << std::setfill(
'0')
1828 <<
static_cast<int>(operand);
1830 ops = oss_ops.str();
1833 oss << ops << std::endl;
1839 std::cout <<
"\033[1;36m"
1840 <<
"$" << std::uppercase << std::setw(2) << std::setfill(
'0')
1841 <<
static_cast<int>(
PB) <<
":" << std::hex <<
PC;
1842 std::cout <<
" \033[1;32m"
1843 <<
": 0x" << std::hex << std::uppercase << std::setw(2)
1844 << std::setfill(
'0') <<
static_cast<int>(opcode) <<
" ";
1854 if (accumulator_mode) {
1855 std::cout << std::hex << std::setw(2) << std::setfill(
'0') << operand;
1857 std::cout << std::hex << std::setw(4) << std::setfill(
'0')
1858 <<
static_cast<int>(operand);
1861 bool x_indexing, y_indexing;
1862 auto x_indexed_instruction_opcodes = {0x15, 0x16, 0x17, 0x55, 0x56,
1863 0x57, 0xD5, 0xD6, 0xD7, 0xF5,
1865 auto y_indexed_instruction_opcodes = {0x19, 0x97, 0x1D, 0x59, 0x5D, 0x99,
1866 0x9D, 0xB9, 0xD9, 0xDD, 0xF9, 0xFD};
1867 if (std::find(x_indexed_instruction_opcodes.begin(),
1868 x_indexed_instruction_opcodes.end(),
1869 opcode) != x_indexed_instruction_opcodes.end()) {
1874 if (std::find(y_indexed_instruction_opcodes.begin(),
1875 y_indexed_instruction_opcodes.end(),
1876 opcode) != y_indexed_instruction_opcodes.end()) {
1892 std::cout << std::right;
1893 std::cout <<
"\033[1;33m"
1894 <<
" A:" << std::hex << std::setw(2) << std::setfill(
'0')
1895 <<
static_cast<int>(
A);
1896 std::cout <<
" X:" << std::hex << std::setw(2) << std::setfill(
'0')
1897 <<
static_cast<int>(
X);
1898 std::cout <<
" Y:" << std::hex << std::setw(2) << std::setfill(
'0')
1899 <<
static_cast<int>(
Y);
1900 std::cout <<
" S:" << std::hex << std::setw(2) << std::setfill(
'0')
1901 <<
static_cast<int>(
status);
1902 std::cout <<
" DB:" << std::hex << std::setw(2) << std::setfill(
'0')
1903 <<
static_cast<int>(
DB);
1904 std::cout <<
" D:" << std::hex << std::setw(2) << std::setfill(
'0')
1905 <<
static_cast<int>(
D);
1906 std::cout <<
" SP:" << std::hex << std::setw(4) << std::setfill(
'0')
1909 std::cout << std::endl;
bool GetOverflowFlag() const
void SetZeroFlag(bool set)
uint16_t ReadOpcodeWord(bool int_check=false)
void Lsr(uint32_t low, uint32_t high)
void Dec(uint32_t low, uint32_t high)
uint32_t AdrAbx(uint32_t *low, bool write)
bool GetNegativeFlag() const
void Adc(uint32_t low, uint32_t high)
void SetZN(uint16_t value, bool byte)
uint32_t AdrIsy(uint32_t *low)
uint32_t AdrIdl(uint32_t *low)
void SetCarryFlag(bool set)
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 SetDecimalFlag(bool set)
void SetSP(uint16_t value)
void Sbc(uint32_t low, uint32_t high)
uint32_t AdrSr(uint32_t *low)
void Ror(uint32_t low, uint32_t high)
void Bit(uint32_t low, uint32_t high)
int GetAccumulatorSize() const
memory::CpuCallbacks callbacks_
void DoBranch(bool check)
uint32_t AdrIdy(uint32_t *low, bool write)
uint32_t AdrAby(uint32_t *low, bool write)
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)
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)
uint32_t AdrDpy(uint32_t *low)
uint32_t AdrIdx(uint32_t *low)
void Inc(uint32_t low, uint32_t high)
uint8_t ReadByte(uint32_t address)
void Asl(uint32_t low, uint32_t high)
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
void And(uint32_t low, uint32_t high)
void Sty(uint32_t low, uint32_t high)
void Ldy(uint32_t low, uint32_t high)
void Cmp(uint32_t low, uint32_t high)
uint32_t AdrIly(uint32_t *low)
void Sta(uint32_t low, uint32_t high)
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 PushByte(uint8_t value)
uint32_t AdrIdp(uint32_t *low)
void Trb(uint32_t low, uint32_t high)
void ExecuteInstruction(uint8_t opcode)
void Stz(uint32_t low, uint32_t high)
void Lda(uint32_t low, uint32_t high)
void Eor(uint32_t low, uint32_t high)
void Rol(uint32_t low, uint32_t high)
uint32_t AdrDp(uint32_t *low)
void Stx(uint32_t low, uint32_t high)
const std::unordered_map< uint8_t, std::string > opcode_to_mnemonic
std::function< void(bool waiting)> idle