2017-01-18 14:45:28 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "emulation.h"
|
|
|
|
|
2017-01-20 21:26:13 +00:00
|
|
|
/* AND - logical AND */
|
2017-01-20 09:41:56 +00:00
|
|
|
void
|
2017-01-22 10:07:19 +00:00
|
|
|
emul_and(rk65c02emu_t *e, void *id, instruction_t *i)
|
2017-01-20 09:41:56 +00:00
|
|
|
{
|
2017-01-23 13:45:46 +00:00
|
|
|
e->regs.A &= (instruction_data_read_1(e, (instrdef_t *) id, i));
|
2017-01-20 09:41:56 +00:00
|
|
|
|
|
|
|
instruction_status_adjust_zero(e, e->regs.A);
|
|
|
|
instruction_status_adjust_negative(e, e->regs.A);
|
|
|
|
}
|
|
|
|
|
2017-01-22 12:50:04 +00:00
|
|
|
/* CLC - clear carry flag */
|
|
|
|
void
|
|
|
|
emul_clc(rk65c02emu_t *e, void *id, instruction_t *i)
|
|
|
|
{
|
|
|
|
e->regs.P &= ~P_CARRY;
|
|
|
|
}
|
|
|
|
|
2017-01-22 21:35:50 +00:00
|
|
|
/* DNX - decrement X */
|
|
|
|
void
|
|
|
|
emul_dex(rk65c02emu_t *e, void *id, instruction_t *i)
|
|
|
|
{
|
|
|
|
e->regs.X--;
|
|
|
|
|
|
|
|
instruction_status_adjust_zero(e, e->regs.X);
|
|
|
|
instruction_status_adjust_negative(e, e->regs.X);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DNY - decrement Y */
|
|
|
|
void
|
|
|
|
emul_dey(rk65c02emu_t *e, void *id, instruction_t *i)
|
|
|
|
{
|
|
|
|
e->regs.Y--;
|
|
|
|
|
|
|
|
instruction_status_adjust_zero(e, e->regs.Y);
|
|
|
|
instruction_status_adjust_negative(e, e->regs.Y);
|
|
|
|
}
|
|
|
|
|
2017-01-23 13:53:05 +00:00
|
|
|
/* EOR - logical exclusive OR */
|
|
|
|
void
|
|
|
|
emul_eor(rk65c02emu_t *e, void *id, instruction_t *i)
|
|
|
|
{
|
|
|
|
e->regs.A ^= instruction_data_read_1(e, (instrdef_t *) id, i);
|
|
|
|
|
|
|
|
instruction_status_adjust_zero(e, e->regs.A);
|
|
|
|
instruction_status_adjust_negative(e, e->regs.A);
|
|
|
|
}
|
|
|
|
|
2017-01-22 12:07:21 +00:00
|
|
|
/* INX - increment X */
|
|
|
|
void
|
|
|
|
emul_inx(rk65c02emu_t *e, void *id, instruction_t *i)
|
|
|
|
{
|
|
|
|
e->regs.X++;
|
|
|
|
|
|
|
|
instruction_status_adjust_zero(e, e->regs.X);
|
|
|
|
instruction_status_adjust_negative(e, e->regs.X);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* INY - increment Y */
|
|
|
|
void
|
|
|
|
emul_iny(rk65c02emu_t *e, void *id, instruction_t *i)
|
|
|
|
{
|
|
|
|
e->regs.Y++;
|
|
|
|
|
|
|
|
instruction_status_adjust_zero(e, e->regs.Y);
|
|
|
|
instruction_status_adjust_negative(e, e->regs.Y);
|
|
|
|
}
|
|
|
|
|
2017-01-20 21:26:13 +00:00
|
|
|
/* LDA - load to accumulator */
|
2017-01-18 21:37:00 +00:00
|
|
|
void
|
2017-01-22 10:07:19 +00:00
|
|
|
emul_lda(rk65c02emu_t *e, void *id, instruction_t *i)
|
2017-01-18 21:37:00 +00:00
|
|
|
{
|
2017-01-22 10:07:19 +00:00
|
|
|
e->regs.A = instruction_data_read_1(e, (instrdef_t *) id, i);
|
2017-01-19 09:59:35 +00:00
|
|
|
|
2017-01-20 09:41:56 +00:00
|
|
|
instruction_status_adjust_zero(e, e->regs.A);
|
|
|
|
instruction_status_adjust_negative(e, e->regs.A);
|
2017-01-18 21:37:00 +00:00
|
|
|
}
|
|
|
|
|
2017-01-23 13:38:50 +00:00
|
|
|
/* LDX - load to X */
|
|
|
|
void
|
|
|
|
emul_ldx(rk65c02emu_t *e, void *id, instruction_t *i)
|
|
|
|
{
|
|
|
|
e->regs.X = instruction_data_read_1(e, (instrdef_t *) id, i);
|
|
|
|
|
|
|
|
instruction_status_adjust_zero(e, e->regs.X);
|
|
|
|
instruction_status_adjust_negative(e, e->regs.X);
|
|
|
|
}
|
|
|
|
|
2017-01-23 13:43:54 +00:00
|
|
|
/* LDY - load to Y */
|
|
|
|
void
|
|
|
|
emul_ldy(rk65c02emu_t *e, void *id, instruction_t *i)
|
|
|
|
{
|
|
|
|
e->regs.Y = instruction_data_read_1(e, (instrdef_t *) id, i);
|
|
|
|
|
|
|
|
instruction_status_adjust_zero(e, e->regs.Y);
|
|
|
|
instruction_status_adjust_negative(e, e->regs.Y);
|
|
|
|
}
|
|
|
|
|
2017-01-20 21:26:13 +00:00
|
|
|
/* NOP - do nothing */
|
2017-01-18 14:45:28 +00:00
|
|
|
void
|
2017-01-22 10:07:19 +00:00
|
|
|
emul_nop(rk65c02emu_t *e, void *id, instruction_t *i)
|
2017-01-18 14:45:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-01-23 13:53:05 +00:00
|
|
|
/* ORA - logical inclusive OR */
|
|
|
|
void
|
|
|
|
emul_ora(rk65c02emu_t *e, void *id, instruction_t *i)
|
|
|
|
{
|
|
|
|
e->regs.A |= instruction_data_read_1(e, (instrdef_t *) id, i);
|
|
|
|
|
|
|
|
instruction_status_adjust_zero(e, e->regs.A);
|
|
|
|
instruction_status_adjust_negative(e, e->regs.A);
|
|
|
|
}
|
|
|
|
|
2017-01-20 21:26:13 +00:00
|
|
|
/* PHA - push accumulator to stack */
|
|
|
|
void
|
2017-01-22 10:07:19 +00:00
|
|
|
emul_pha(rk65c02emu_t *e, void *id, instruction_t *i)
|
2017-01-20 21:26:13 +00:00
|
|
|
{
|
|
|
|
stack_push(e, e->regs.A);
|
|
|
|
}
|
|
|
|
|
2017-01-22 22:01:24 +00:00
|
|
|
/* PHP - push processor flags to stack */
|
|
|
|
void
|
|
|
|
emul_php(rk65c02emu_t *e, void *id, instruction_t *i)
|
|
|
|
{
|
|
|
|
stack_push(e, e->regs.P);
|
|
|
|
}
|
|
|
|
|
2017-01-20 21:26:13 +00:00
|
|
|
/* PLA - pull from stack to accumulator */
|
|
|
|
void
|
2017-01-22 10:07:19 +00:00
|
|
|
emul_pla(rk65c02emu_t *e, void *id, instruction_t *i)
|
2017-01-20 21:26:13 +00:00
|
|
|
{
|
|
|
|
e->regs.A = stack_pop(e);
|
|
|
|
|
|
|
|
instruction_status_adjust_zero(e, e->regs.A);
|
|
|
|
instruction_status_adjust_negative(e, e->regs.A);
|
|
|
|
}
|
|
|
|
|
2017-01-22 22:01:24 +00:00
|
|
|
/* PLA - pull from stack to processor flags */
|
|
|
|
void
|
|
|
|
emul_plp(rk65c02emu_t *e, void *id, instruction_t *i)
|
|
|
|
{
|
|
|
|
e->regs.P = stack_pop(e) | P_UNDEFINED;
|
|
|
|
}
|
|
|
|
|
2017-01-22 12:50:04 +00:00
|
|
|
/* SEC - set the carry flag */
|
|
|
|
void
|
|
|
|
emul_sec(rk65c02emu_t *e, void *id, instruction_t *i)
|
|
|
|
{
|
|
|
|
e->regs.P |= P_CARRY;
|
|
|
|
}
|
|
|
|
|
2017-01-20 21:26:13 +00:00
|
|
|
/* STP - stop the processor */
|
2017-01-18 16:18:19 +00:00
|
|
|
void
|
2017-01-22 10:07:19 +00:00
|
|
|
emul_stp(rk65c02emu_t *e, void *id, instruction_t *i)
|
2017-01-18 16:18:19 +00:00
|
|
|
{
|
|
|
|
e->state = STOPPED;
|
|
|
|
}
|
2017-01-18 21:37:00 +00:00
|
|
|
|
2017-01-23 14:02:21 +00:00
|
|
|
/* STA - store accumulator */
|
|
|
|
void
|
|
|
|
emul_sta(rk65c02emu_t *e, void *id, instruction_t *i)
|
|
|
|
{
|
|
|
|
instruction_data_write_1(e, id, i, e->regs.A);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* STX - store X */
|
|
|
|
void
|
|
|
|
emul_stx(rk65c02emu_t *e, void *id, instruction_t *i)
|
|
|
|
{
|
|
|
|
instruction_data_write_1(e, id, i, e->regs.X);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* STY - store Y */
|
|
|
|
void
|
|
|
|
emul_sty(rk65c02emu_t *e, void *id, instruction_t *i)
|
|
|
|
{
|
|
|
|
instruction_data_write_1(e, id, i, e->regs.Y);
|
|
|
|
}
|
|
|
|
|
2017-01-21 20:46:35 +00:00
|
|
|
/* STZ - store zero */
|
|
|
|
void
|
2017-01-22 10:07:19 +00:00
|
|
|
emul_stz(rk65c02emu_t *e, void *id, instruction_t *i)
|
2017-01-21 20:46:35 +00:00
|
|
|
{
|
2017-01-22 10:07:19 +00:00
|
|
|
instruction_data_write_1(e, id, i, 0);
|
2017-01-21 20:46:35 +00:00
|
|
|
}
|
|
|
|
|
2017-01-23 13:38:50 +00:00
|
|
|
/* TAX - transfer accumulator to X */
|
|
|
|
void
|
|
|
|
emul_tax(rk65c02emu_t *e, void *id, instruction_t *i)
|
|
|
|
{
|
|
|
|
e->regs.X = e->regs.A;
|
|
|
|
|
|
|
|
instruction_status_adjust_zero(e, e->regs.X);
|
|
|
|
instruction_status_adjust_negative(e, e->regs.X);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TAY - transfer accumulator to Y */
|
|
|
|
void
|
|
|
|
emul_tay(rk65c02emu_t *e, void *id, instruction_t *i)
|
|
|
|
{
|
|
|
|
e->regs.Y = e->regs.A;
|
|
|
|
|
|
|
|
instruction_status_adjust_zero(e, e->regs.Y);
|
|
|
|
instruction_status_adjust_negative(e, e->regs.Y);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TSX - transfer stack pointer to X */
|
|
|
|
void
|
|
|
|
emul_tsx(rk65c02emu_t *e, void *id, instruction_t *i)
|
|
|
|
{
|
|
|
|
e->regs.X = e->regs.SP;
|
|
|
|
|
|
|
|
instruction_status_adjust_zero(e, e->regs.X);
|
|
|
|
instruction_status_adjust_negative(e, e->regs.X);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TXA - transfer X to accumulator */
|
|
|
|
void
|
|
|
|
emul_txa(rk65c02emu_t *e, void *id, instruction_t *i)
|
|
|
|
{
|
|
|
|
e->regs.A = e->regs.X;
|
|
|
|
|
|
|
|
instruction_status_adjust_zero(e, e->regs.A);
|
|
|
|
instruction_status_adjust_negative(e, e->regs.A);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TXS - transfer X to stack pointer */
|
|
|
|
void
|
|
|
|
emul_txs(rk65c02emu_t *e, void *id, instruction_t *i)
|
|
|
|
{
|
|
|
|
e->regs.SP = e->regs.X;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TYA - transfer Y to accumulator */
|
|
|
|
void
|
|
|
|
emul_tya(rk65c02emu_t *e, void *id, instruction_t *i)
|
|
|
|
{
|
|
|
|
e->regs.A = e->regs.Y;
|
|
|
|
|
|
|
|
instruction_status_adjust_zero(e, e->regs.A);
|
|
|
|
instruction_status_adjust_negative(e, e->regs.A);
|
|
|
|
}
|
|
|
|
|