2017-12-02 19:05:53 +00:00
|
|
|
/*
|
|
|
|
* mos6502.loadstor.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mos6502.h"
|
|
|
|
#include "mos6502.enums.h"
|
|
|
|
|
2017-12-07 00:01:13 +00:00
|
|
|
/*
|
|
|
|
* The LDA instruction will assign ("load") an operand into the
|
|
|
|
* accumulator.
|
|
|
|
*/
|
2017-12-02 19:05:53 +00:00
|
|
|
DEFINE_INST(lda)
|
|
|
|
{
|
|
|
|
mos6502_modify_status(cpu, ZERO | NEGATIVE, oper);
|
|
|
|
cpu->A = oper;
|
|
|
|
}
|
|
|
|
|
2017-12-07 00:01:13 +00:00
|
|
|
/*
|
|
|
|
* Similar to LDA, except targeting X.
|
|
|
|
*/
|
2017-12-02 19:05:53 +00:00
|
|
|
DEFINE_INST(ldx)
|
|
|
|
{
|
|
|
|
mos6502_modify_status(cpu, ZERO | NEGATIVE, oper);
|
|
|
|
cpu->X = oper;
|
|
|
|
}
|
|
|
|
|
2017-12-07 00:01:13 +00:00
|
|
|
/*
|
|
|
|
* Again similar to LDA, except with Y.
|
|
|
|
*/
|
2017-12-02 19:05:53 +00:00
|
|
|
DEFINE_INST(ldy)
|
|
|
|
{
|
|
|
|
mos6502_modify_status(cpu, ZERO | NEGATIVE, oper);
|
|
|
|
cpu->Y = oper;
|
|
|
|
}
|
|
|
|
|
2017-12-07 00:01:13 +00:00
|
|
|
/*
|
|
|
|
* This instruction will "push" the A register onto the stack.
|
|
|
|
*/
|
2017-12-02 19:05:53 +00:00
|
|
|
DEFINE_INST(pha)
|
|
|
|
{
|
|
|
|
mos6502_push_stack(cpu, cpu->A);
|
|
|
|
}
|
|
|
|
|
2017-12-07 00:01:13 +00:00
|
|
|
/*
|
|
|
|
* Similar to above, but will push the P register.
|
|
|
|
*/
|
2017-12-02 19:05:53 +00:00
|
|
|
DEFINE_INST(php)
|
|
|
|
{
|
|
|
|
mos6502_push_stack(cpu, cpu->P);
|
|
|
|
}
|
|
|
|
|
2017-12-07 00:01:13 +00:00
|
|
|
/*
|
|
|
|
* Here we pop the stack (or "pull" it), and assign to the accumulator.
|
|
|
|
*/
|
2017-12-02 19:05:53 +00:00
|
|
|
DEFINE_INST(pla)
|
|
|
|
{
|
|
|
|
cpu->A = mos6502_pop_stack(cpu);
|
|
|
|
}
|
|
|
|
|
2017-12-07 00:01:13 +00:00
|
|
|
/*
|
|
|
|
* Again we pop from the stack, but assign to the P register.
|
|
|
|
*/
|
2017-12-02 19:05:53 +00:00
|
|
|
DEFINE_INST(plp)
|
|
|
|
{
|
|
|
|
cpu->P = mos6502_pop_stack(cpu);
|
|
|
|
}
|
|
|
|
|
2017-12-07 00:01:13 +00:00
|
|
|
/*
|
|
|
|
* The STA instruction assigns the value of the accumulator to a given
|
|
|
|
* address in memory. (That is to say, it "stores" it.)
|
|
|
|
*/
|
2017-12-02 19:05:53 +00:00
|
|
|
DEFINE_INST(sta)
|
|
|
|
{
|
|
|
|
vm_segment_set(cpu->memory, cpu->last_addr, cpu->A);
|
|
|
|
}
|
|
|
|
|
2017-12-07 00:01:13 +00:00
|
|
|
/*
|
|
|
|
* Similar to STA, but drawing from the X register.
|
|
|
|
*/
|
2017-12-02 19:05:53 +00:00
|
|
|
DEFINE_INST(stx)
|
|
|
|
{
|
|
|
|
vm_segment_set(cpu->memory, cpu->last_addr, cpu->X);
|
|
|
|
}
|
|
|
|
|
2017-12-07 00:01:13 +00:00
|
|
|
/*
|
|
|
|
* And, again, similar to STA, but with the Y register.
|
|
|
|
*/
|
2017-12-02 19:05:53 +00:00
|
|
|
DEFINE_INST(sty)
|
|
|
|
{
|
|
|
|
vm_segment_set(cpu->memory, cpu->last_addr, cpu->Y);
|
|
|
|
}
|
|
|
|
|
2017-12-07 00:01:13 +00:00
|
|
|
/*
|
|
|
|
* The TAX instruction taxes no one but your patience for my puns. What
|
|
|
|
* it does do is transfer the contents of the A register to X.
|
|
|
|
*/
|
2017-12-02 19:05:53 +00:00
|
|
|
DEFINE_INST(tax)
|
|
|
|
{
|
|
|
|
mos6502_modify_status(cpu, ZERO | NEGATIVE, cpu->A);
|
|
|
|
cpu->X = cpu->A;
|
|
|
|
}
|
|
|
|
|
2017-12-07 00:01:13 +00:00
|
|
|
/*
|
|
|
|
* This transfers from A to Y.
|
|
|
|
*/
|
2017-12-02 19:05:53 +00:00
|
|
|
DEFINE_INST(tay)
|
|
|
|
{
|
|
|
|
mos6502_modify_status(cpu, ZERO | NEGATIVE, cpu->A);
|
|
|
|
cpu->Y = cpu->A;
|
|
|
|
}
|
|
|
|
|
2017-12-07 00:01:13 +00:00
|
|
|
/*
|
|
|
|
* Transfer the stack pointer (S register) to X.
|
|
|
|
*/
|
2017-12-02 19:05:53 +00:00
|
|
|
DEFINE_INST(tsx)
|
|
|
|
{
|
|
|
|
mos6502_modify_status(cpu, ZERO | NEGATIVE, cpu->S);
|
|
|
|
cpu->X = cpu->S;
|
|
|
|
}
|
|
|
|
|
2017-12-07 00:01:13 +00:00
|
|
|
/*
|
|
|
|
* Transfer the X register to A.
|
|
|
|
*/
|
2017-12-02 19:05:53 +00:00
|
|
|
DEFINE_INST(txa)
|
|
|
|
{
|
|
|
|
mos6502_modify_status(cpu, ZERO | NEGATIVE, cpu->X);
|
|
|
|
cpu->A = cpu->X;
|
|
|
|
}
|
|
|
|
|
2017-12-07 00:01:13 +00:00
|
|
|
/*
|
|
|
|
* Transfer the X register to S.
|
|
|
|
*/
|
2017-12-02 19:05:53 +00:00
|
|
|
DEFINE_INST(txs)
|
|
|
|
{
|
|
|
|
mos6502_modify_status(cpu, ZERO | NEGATIVE, cpu->X);
|
|
|
|
cpu->S = cpu->X;
|
|
|
|
}
|
|
|
|
|
2017-12-07 00:01:13 +00:00
|
|
|
/*
|
|
|
|
* Transfer the Y register to A.
|
|
|
|
*/
|
2017-12-02 19:05:53 +00:00
|
|
|
DEFINE_INST(tya)
|
|
|
|
{
|
|
|
|
mos6502_modify_status(cpu, ZERO | NEGATIVE, cpu->Y);
|
|
|
|
cpu->A = cpu->Y;
|
|
|
|
}
|