1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-12-01 00:49:46 +00:00
erc-c/src/mos6502.branch.c

82 lines
1.3 KiB
C
Raw Normal View History

2017-12-02 19:05:53 +00:00
/*
* mos6502.branch.c
*/
#include "mos6502.h"
#include "mos6502.enums.h"
2017-12-07 00:01:13 +00:00
/*
* This is just a minor convenience macro to wrap the logic we use in
* branch situations, which is if `cond` is true, then we set the
* program counter to the last effective address.
*/
2017-12-02 19:05:53 +00:00
#define JUMP_IF(cond) \
if (cond) cpu->PC = cpu->last_addr
2017-12-07 00:01:13 +00:00
/*
* Branch if the carry flag is clear.
*/
2017-12-02 19:05:53 +00:00
DEFINE_INST(bcc)
{
JUMP_IF(~cpu->P & CARRY);
}
2017-12-07 00:01:13 +00:00
/*
* Branch if carry is set.
*/
2017-12-02 19:05:53 +00:00
DEFINE_INST(bcs)
{
JUMP_IF(cpu->P & CARRY);
}
2017-12-07 00:01:13 +00:00
/*
* Branch if the zero flag is set (that is, if our last instruction
* resulted in something being _equal to zero_).
*/
2017-12-02 19:05:53 +00:00
DEFINE_INST(beq)
{
JUMP_IF(cpu->P & ZERO);
}
2017-12-07 00:01:13 +00:00
/*
* Branch if the negative ("minus") flag is set.
*/
2017-12-02 19:05:53 +00:00
DEFINE_INST(bmi)
{
JUMP_IF(cpu->P & NEGATIVE);
}
2017-12-07 00:01:13 +00:00
/*
* Branch if the zero flag is not set; which is to say, that the last
* operation was _not equal_ to zero.
*/
2017-12-02 19:05:53 +00:00
DEFINE_INST(bne)
{
JUMP_IF(~cpu->P & ZERO);
}
2017-12-07 00:01:13 +00:00
/*
* Branch if the negative flag is not set (meaning the last operation
* was "plus", which includes zero).
*/
2017-12-02 19:05:53 +00:00
DEFINE_INST(bpl)
{
JUMP_IF(~cpu->P & NEGATIVE);
}
2017-12-07 00:01:13 +00:00
/*
* Branch if the overflow bit is clear.
*/
2017-12-02 19:05:53 +00:00
DEFINE_INST(bvc)
{
JUMP_IF(~cpu->P & OVERFLOW);
}
2017-12-07 00:01:13 +00:00
/*
* Branch if the overflow bit is set.
*/
2017-12-02 19:05:53 +00:00
DEFINE_INST(bvs)
{
JUMP_IF(cpu->P & OVERFLOW);
}