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)
|
|
|
|
{
|
2017-12-04 02:19:17 +00:00
|
|
|
cpu->P &= ~CARRY;
|
2017-12-02 19:05:53 +00:00
|
|
|
if (oper & 0x80) {
|
|
|
|
cpu->P |= CARRY;
|
|
|
|
}
|
|
|
|
|
2017-12-04 02:19:17 +00:00
|
|
|
oper <<= 1;
|
|
|
|
|
2017-12-02 19:05:53 +00:00
|
|
|
if (cpu->last_addr) {
|
|
|
|
vm_segment_set(cpu->memory, cpu->last_addr, oper);
|
|
|
|
} else {
|
|
|
|
cpu->A = oper;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_INST(bit)
|
|
|
|
{
|
2017-12-04 02:19:17 +00:00
|
|
|
cpu->P &= ~NEGATIVE;
|
2017-12-02 19:05:53 +00:00
|
|
|
if (oper & NEGATIVE) {
|
|
|
|
cpu->P |= NEGATIVE;
|
|
|
|
}
|
|
|
|
|
2017-12-04 02:19:17 +00:00
|
|
|
cpu->P &= ~OVERFLOW;
|
2017-12-02 19:05:53 +00:00
|
|
|
if (oper & OVERFLOW) {
|
|
|
|
cpu->P |= OVERFLOW;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oper & cpu->A) {
|
|
|
|
cpu->P &= ~ZERO;
|
2017-12-04 02:19:17 +00:00
|
|
|
} else {
|
|
|
|
cpu->P |= ZERO;
|
2017-12-02 19:05:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_INST(eor)
|
|
|
|
{
|
|
|
|
cpu->A ^= oper;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_INST(lsr)
|
|
|
|
{
|
2017-12-04 02:19:17 +00:00
|
|
|
cpu->P &= ~CARRY;
|
2017-12-02 19:05:53 +00:00
|
|
|
if (oper & 0x01) {
|
|
|
|
cpu->P |= CARRY;
|
|
|
|
}
|
|
|
|
|
2017-12-04 02:19:17 +00:00
|
|
|
oper >>= 1;
|
|
|
|
|
2017-12-02 19:05:53 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|