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
|
|
|
{
|
|
|
|
uint8_t rv;
|
|
|
|
|
2017-01-22 10:07:19 +00:00
|
|
|
rv = e->regs.A & (instruction_data_read_1(e, (instrdef_t *) id, i));
|
2017-01-20 09:41:56 +00:00
|
|
|
e->regs.A = rv;
|
|
|
|
|
|
|
|
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-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-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-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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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 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-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
|
|
|
}
|
|
|
|
|