Skip to content

Commit

Permalink
SBC and ADC Flags
Browse files Browse the repository at this point in the history
  • Loading branch information
duckboycool committed Nov 23, 2021
1 parent a0607f9 commit 9d5d45b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion 6502.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "ops.h"

#define VERSIONSTRING "v0.2.3-dev"
#define VERSIONSTRING "v0.3.0-beta"

// Function to get ascii representation of memory for printout
string ascii(byte2 memaddr, int size) {
Expand Down
12 changes: 8 additions & 4 deletions ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,11 @@ void RTS() {
}

void ADC(byte val) {
set_nz(a = a + val + sr.c);
short sum = (signed char)a + (signed char)val;
sr.c = (val + sr.c + a > 0xFF);
sr.v = sum < -0x80 || sum >= 0x80;

sr.c = (val + sr.c > a);
set_nz(a = a + val + sr.c);
}

void ROR(byte& addr) {
Expand Down Expand Up @@ -391,9 +393,11 @@ void CPX(byte val) {
}

void SBC(byte val) {
set_nz(a = a - val - !sr.c);
short dif = (signed char)a - (signed char)val;
sr.c = (a >= val + !sr.c);
sr.v = dif < -0x80 || dif >= 0x80;

sr.c = (- val - !sr.c < a);
set_nz(a = a - val - !sr.c);
}

void INC(byte& addr) {
Expand Down

0 comments on commit 9d5d45b

Please sign in to comment.