diff options
Diffstat (limited to 'applesystem.h')
-rw-r--r-- | applesystem.h | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/applesystem.h b/applesystem.h index f561d36..4cff655 100644 --- a/applesystem.h +++ b/applesystem.h @@ -1,3 +1,6 @@ +// applesystem.h +// Core elements of the 6502 CPU, and flag manipulation. + typedef unsigned char byte; typedef unsigned short address; byte acc, X, Y, P, S = 0x00; @@ -5,7 +8,7 @@ address PC = 0x0000; register byte Memory[4096]; // TO DO. Add expansion capability to memory. // FLAGS -const byte flag_N = 0x80; // Negative (Note that byte cast is necessary here only) +const byte flag_N = 0x80; // Negative const byte flag_V = 0x40; // Overflow const byte flag_B = 0x10; // BRK command const byte flag_D = 0x08; // Decimal mode @@ -56,14 +59,14 @@ byte fromBCD(byte x){ return (a + b); } -// Set particular flags -// Functions which quickly set specific flags that are straightforward checks, and are repeated often. + +// Functions which perform reusable routines for finding if a specific flag should be set. + void setFlagN(byte x){ - if (x ^ flag_N == flag_N){ + if (x & flag_N == flag_N) setFlag(flag_N, 1); - }else{ //not sure if this should be present, I think it is + else setFlag(flag_N, 0); - } } //Perform prior to any changes @@ -76,22 +79,29 @@ void setFlagV(byte x, byte y){ else setFlag(flag_V, 0); } } + /*void setFlagB(){ //WORK ON setFlag(flag_B, 1); }*/ //Dont really need since its dependent on the BRK insturction + /*void setFlagD(){ setFlag(flag_D, 1); }*/ -void setFlagI(){ //WORK ON + +/*void setFlagI(){ //WORK ON setFlag(flag_Z, 1); -} +}*/ + void setFlagZ(int x){ - if (x == 0) { + if (x == 0) setFlag(flag_Z, 1); - } + else + setFlag(flag_Z, 0); } + //Only 6 instructions, 2 not including stack instructions, use the carry flag. -/*void setFlagC(){ // NOTE. Must make setFlagC functional with independence. Look into carrying on 6502 +// Need to look further into implementation details for this. +/*void setFlagC(){ setFlag(flag_Z, 1); }*/ |