1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-06-24 15:29:32 +00:00
erc-c/src/mos6502.exec.c

68 lines
1.4 KiB
C
Raw Normal View History

2017-12-02 19:05:53 +00:00
/*
* mos6502.exec.c
2017-12-09 04:12:31 +00:00
*
* These instructions concern program execution; things like JMP, JSR,
* BRK, and so forth.
2017-12-02 19:05:53 +00:00
*/
#include "mos6502.h"
#include "mos6502.enums.h"
2017-12-07 00:01:13 +00:00
/*
* The BRK instruction will set the interrupt bit; will push the current
* PC address to the stack; and will advance the counter by 2 positions.
*/
2017-12-02 19:05:53 +00:00
DEFINE_INST(brk)
{
cpu->P |= INTERRUPT;
mos6502_push_stack(cpu, cpu->PC);
cpu->PC += 2;
}
2017-12-07 00:01:13 +00:00
/*
* A jump is straight forward; whatever the effective address is, that
* is now the new value of the PC register.
*/
2017-12-02 19:05:53 +00:00
DEFINE_INST(jmp)
{
cpu->PC = cpu->last_addr;
}
2017-12-07 00:01:13 +00:00
/*
* Meanwhile, a JSR (or jump to subroutine) is a little more nuanced. We
* record our current position, plus two, to the stack, and jump the
* effective address.
*/
2017-12-02 19:05:53 +00:00
DEFINE_INST(jsr)
{
mos6502_push_stack(cpu, cpu->PC + 2);
cpu->PC = cpu->last_addr;
}
2017-12-07 00:01:13 +00:00
/*
* The NOP instruction is short for no-operation. It does nothing except
* waste cycles (which happens elsewhere).
*/
2017-12-02 19:05:53 +00:00
DEFINE_INST(nop)
{
// do nothing
}
2017-12-07 00:01:13 +00:00
/*
* Here we return from an interrupt, which effectively resets the PC
* register to the last value on the stack.
*/
2017-12-02 19:05:53 +00:00
DEFINE_INST(rti)
{
cpu->PC = mos6502_pop_stack(cpu);
}
2017-12-07 00:01:13 +00:00
/*
* The RTS instruction (return from subroutine) works the same as the
* RTI instruction, which may or may not be a misconception on my part.
*/
2017-12-02 19:05:53 +00:00
DEFINE_INST(rts)
{
cpu->PC = mos6502_pop_stack(cpu);
}