1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-11-24 14:32:08 +00:00
erc-c/src/mos6502.bits.c

111 lines
1.4 KiB
C
Raw Normal View History

2017-12-02 19:05:53 +00:00
/*
* mos6502.bits.c
*/
#include "mos6502.h"
#include "mos6502.enums.h"
DEFINE_INST(and)
{
cpu->A &= oper;
}
DEFINE_INST(asl)
{
oper <<= 1;
if (oper & 0x80) {
cpu->P |= CARRY;
}
if (cpu->last_addr) {
vm_segment_set(cpu->memory, cpu->last_addr, oper);
} else {
cpu->A = oper;
}
}
DEFINE_INST(bit)
{
if (oper & NEGATIVE) {
cpu->P |= NEGATIVE;
}
if (oper & OVERFLOW) {
cpu->P |= OVERFLOW;
}
if (oper & cpu->A) {
cpu->P |= ZERO;
} else {
cpu->P &= ~ZERO;
}
}
DEFINE_INST(eor)
{
cpu->A ^= oper;
}
DEFINE_INST(lsr)
{
oper >>= 1;
if (oper & 0x01) {
cpu->P |= CARRY;
}
if (cpu->last_addr) {
vm_segment_set(cpu->memory, cpu->last_addr, oper);
} else {
cpu->A = oper;
}
}
DEFINE_INST(ora)
{
cpu->A |= oper;
}
DEFINE_INST(rol)
{
CARRY_BIT();
if (oper & 0x80) {
carry = 1;
}
oper <<= 1;
if (carry) {
oper |= 0x01;
}
if (cpu->last_addr) {
vm_segment_set(cpu->memory, cpu->last_addr, oper);
} else {
cpu->A = oper;
}
}
DEFINE_INST(ror)
{
CARRY_BIT();
if (oper & 0x01) {
carry = 1;
}
oper >>= 1;
if (carry) {
oper |= 0x80;
}
if (cpu->last_addr) {
vm_segment_set(cpu->memory, cpu->last_addr, oper);
} else {
cpu->A = oper;
}
}