85 uint16_t
adr = 0xffde - (2 * (
opcode >> 4));
162 uint16_t dst =
dp_dp(&src);
191 uint8_t result =
A + (val ^ 0xff) + 1;
192 PSW.
Z = (result == 0);
193 PSW.
N = (result & 0x80);
229 uint16_t dst =
dp_imm(&src);
242 uint16_t value =
read(low) - 1;
243 write(low, value & 0xff);
244 value +=
read(high) << 8;
245 write(high, value >> 8);
247 PSW.
N = value & 0x8000;
306 uint16_t dst =
dp_dp(&src);
332 uint8_t val =
read(
dp()) ^ 0xff;
334 uint8_t result =
A + val + 1;
364 uint16_t dst =
dp_imm(&src);
377 uint16_t value =
read(low) + 1;
378 write(low, value & 0xff);
379 value +=
read(high) << 8;
380 write(high, value >> 8);
382 PSW.
N = value & 0x8000;
391 bool newC =
A & 0x80;
445 uint16_t dst =
dp_dp(&src);
473 uint8_t result =
A + (val ^ 0xff) + 1;
474 PSW.
Z = (result == 0);
475 PSW.
N = (result & 0x80);
509 uint16_t dst =
dp_imm(&src);
522 uint16_t value =
read_word(low) ^ 0xffff;
523 uint16_t ya =
A | (
Y << 8);
524 int result = ya + value + 1;
525 PSW.
C = result > 0xffff;
526 PSW.
Z = (result & 0xffff) == 0;
527 PSW.
N = result & 0x8000;
584 uint16_t dst =
dp_dp(&src);
610 uint8_t result =
read(
adr) - 1;
643 uint16_t dst =
dp_imm(&src);
656 uint8_t vall =
read(low);
658 uint16_t value = vall | (
read(high) << 8);
659 uint16_t ya =
A | (
Y << 8);
660 int result = ya + value;
661 PSW.
V = (ya & 0x8000) == (value & 0x8000) &&
662 (value & 0x8000) != (result & 0x8000);
663 PSW.
H = ((ya & 0xfff) + (value & 0xfff)) > 0xfff;
664 PSW.
C = result > 0xffff;
665 PSW.
Z = (result & 0xffff) == 0;
666 PSW.
N = result & 0x8000;
678 A = (
A >> 1) | (
PSW.
C << 7);
729 uint16_t dst =
dp_dp(&src);
760 uint16_t dst =
dp_imm(&val);
787 uint16_t dst =
dp_imm(&src);
800 uint8_t vall =
read(low);
802 uint16_t value = (vall | (
read(high) << 8)) ^ 0xffff;
803 uint16_t ya =
A | (
Y << 8);
804 int result = ya + value + 1;
805 PSW.
V = (ya & 0x8000) == (value & 0x8000) &&
806 (value & 0x8000) != (result & 0x8000);
807 PSW.
H = ((ya & 0xfff) + (value & 0xfff) + 1) > 0xfff;
808 PSW.
C = result > 0xffff;
809 PSW.
Z = (result & 0xffff) == 0;
810 PSW.
N = result & 0x8000;
836 PSW.
H = (
X & 0xf) <= (
Y & 0xf);
837 int yva = (
Y << 8) |
A;
839 for (
int i = 0;
i < 9;
i++) {
841 yva |= (yva & 0x20000) ? 1 : 0;
843 if (yva >= x) yva ^= 1;
844 if (yva & 1) yva -= x;
859 A = (
A >> 4) | (
A << 4);
892 uint16_t dst =
dp_dp(&src);
948 uint16_t dst =
dp_imm(&src);
961 uint8_t vall =
read(low);
963 uint16_t val = vall | (
read(high) << 8);
967 PSW.
N = val & 0x8000;
990 if (
A > 0x99 || !
PSW.
C) {
994 if ((
A & 0xf) > 9 || !
PSW.
H) {
1042 uint8_t result = (
read(
adr) & (~(1 << bit))) | (
PSW.
C << bit);
1068 uint16_t result =
A *
Y;
1071 PSW.
Z = ((
Y & 0xFFFF) == 0);
1072 PSW.
N = (
Y & 0x8000);
1119 uint16_t high =
dp_word(&low);
1132 PSW.
Z = ((
Y & 0xFFFF) == 0);
1133 PSW.
N = (
Y & 0x8000);
1144 uint8_t val =
read(
dpx()) ^ 0xff;
1146 uint8_t result =
A + val + 1;
1153 if (
A > 0x99 ||
PSW.
C) {
1157 if ((
A & 0xf) > 9 ||
PSW.
H) {
1197 uint8_t result =
read(
adr) ^ (1 << bit);
1257 uint16_t dst =
dp_dp(&val);
1268 PSW.
Z = ((
Y & 0xFFFF) == 0);
1269 PSW.
N = (
Y & 0x8000);
1275 PSW.
Z = ((
Y & 0xFFFF) == 0);
1276 PSW.
N = (
Y & 0x8000);
1294 throw std::runtime_error(
"Unknown SPC opcode: " + std::to_string(
opcode));
1302 std::stringstream log_entry_stream;
1303 log_entry_stream <<
"\033[1;36m$" << std::hex << std::setw(4)
1304 << std::setfill(
'0') << initial_pc <<
"\033[0m";
1305 log_entry_stream <<
" \033[1;32m" << std::hex << std::setw(2)
1306 << std::setfill(
'0') <<
static_cast<int>(
opcode) <<
"\033[0m"
1307 <<
" \033[1;35m" << std::setw(18) << std::left
1308 << std::setfill(
' ') << mnemonic <<
"\033[0m";
1310 log_entry_stream <<
" \033[1;33mA: " << std::hex << std::setw(2)
1311 << std::setfill(
'0') << std::right << static_cast<int>(
A)
1313 log_entry_stream <<
" \033[1;33mX: " << std::hex << std::setw(2)
1314 << std::setfill(
'0') << std::right << static_cast<int>(
X)
1316 log_entry_stream <<
" \033[1;33mY: " << std::hex << std::setw(2)
1317 << std::setfill(
'0') << std::right << static_cast<int>(
Y)
1319 std::string log_entry = log_entry_stream.str();
1321 std::cerr << log_entry << std::endl;
const std::unordered_map< uint8_t, std::string > spc_opcode_map
void ANDM(uint16_t dest, uint8_t operand)
uint16_t dp_word(uint16_t *low)
void push_word(uint16_t value)
void EORM(uint16_t dest, uint8_t operand)
uint16_t dp_dp(uint8_t *src)
void LogInstruction(uint16_t initial_pc, uint8_t opcode)
void ExecuteInstructions(uint8_t opcode)
void ROL(uint16_t operand)
void DEC(uint16_t operand)
Flags ByteToFlags(uint8_t byte)
void CMPM(uint16_t dst, uint8_t value)
uint16_t read_word(uint16_t address)
void SBCM(uint16_t &dest, uint8_t operand)
uint8_t FlagsToByte(Flags flags)
void Reset(bool hard=false)
void ADCM(uint16_t &dest, uint8_t operand)
void push_byte(uint8_t value)
uint8_t abs_bit(uint16_t *adr)
uint16_t ind_ind(uint8_t *srcVal)
void ASL(uint16_t operand)
uint16_t dp_imm(uint8_t *srcVal)
void write(uint16_t address, uint8_t value)
void DoBranch(uint8_t value, bool check)
void ORM(uint16_t dest, uint8_t operand)
uint16_t ReadOpcodeWord()
uint8_t read(uint16_t address)
std::function< void(bool)> idle