diff options
author | alekseiplusplus <alekseijeaves@protonmail.com> | 2023-07-27 11:36:01 +1000 |
---|---|---|
committer | alekseiplusplus <alekseijeaves@protonmail.com> | 2023-07-27 11:36:01 +1000 |
commit | 9a6188f821b11b69fff3d3a303dbfcce2e52e6f4 (patch) | |
tree | b06aa0d876b19cca281cbc26db9086ab7241d6bd /src/cpu/6502.h | |
parent | b158eaeb489bce502198e844593b38a2f5f5b9ee (diff) |
refactoring of src/cpu/
Diffstat (limited to 'src/cpu/6502.h')
-rw-r--r-- | src/cpu/6502.h | 107 |
1 files changed, 35 insertions, 72 deletions
diff --git a/src/cpu/6502.h b/src/cpu/6502.h index 66526fd..c455e57 100644 --- a/src/cpu/6502.h +++ b/src/cpu/6502.h @@ -1,10 +1,10 @@ // 6502.h -// Core elements of the 6502 CPU +// Main elements of the 6502 CPU -typedef unsigned char - byte; -typedef unsigned short - address; +#ifndef CPU_6502_H +#define CPU_6502_H + +#include"core.h" byte acc, X, Y, P, S = 0x00; address PC = 0x0000; @@ -20,89 +20,52 @@ byte* ROM; #define flag_Z 0x02 // Zero #define flag_C 0x01 // Carry -byte getFlag(byte flag) { - return ((P & flag) == flag) ? 1 : 0; -} - -void setFlag(byte flag, int x) { - if (x == 1){ - if ((P & flag) == 0x0) P += flag; - }else if (x == 0){ - if ((P & flag) == flag) P -= flag; - } - else{ - fprintf(stderr, "setFlag() passed arg neither 0 or 1"); - } -} +byte getFlag(byte flag); +// Get the value of a flag. -void flagSet(byte flag){ - P |= flag; -} +void setFlag(byte flag, int x); +// Set a flag with some value. -void flagClear(byte flag){ - P &= ~flag; -} +void flagSet(byte flag); +// Sets some flag. +void flagClear(byte flag); +// Clears some flag. // Functions which perform reusable routines for finding if a specific flag should be set. -void setFlagN(byte x){ - if (x & flag_N == flag_N) - setFlag(flag_N, 1); - else - setFlag(flag_N, 0); -} +void setFlagN(byte x); //Perform prior to any changes -void setFlagV(byte x, byte y){ - if ((x & flag_N) == (y & flag_N)){ - if (((x + y) & (flag_N ^ 0xFF)) > 0x7F) setFlag(flag_V, 1); - else setFlag(flag_V, 0); - }else{ - if (((x - y) & (flag_N ^ 0xFF)) > 0x7F) setFlag(flag_V, 1); - 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 - setFlag(flag_Z, 1); -}*/ - -void setFlagZ(int x){ - if (x == 0) - setFlag(flag_Z, 1); - else - setFlag(flag_Z, 0); -} +void setFlagV(byte x, byte y); -//Only 6 instructions, 2 not including stack instructions, use the carry flag. -// Need to look further into implementation details for this. -/*void setFlagC(){ - setFlag(flag_Z, 1); -}*/ +//void setFlagB(); +//May not need since its dependent on the BRK insturction +//void setFlagD(); +//Might not be necessary. -// Memory Manipulation +//void setFlagI(); +//Need to work on. -// Are to be defined by the system to handle special cases. - -byte getMemory(address x); -void setMemory(address x, byte y); +void setFlagZ(int x); +//void setFlagC(); +//Only 6 instructions, 2 not including stack instructions, use the carry flag. +// The following two may be better defined within apple.c +//byte getMemory(address x); +// Retrieve value from the computers address space. +// It is important not to directly access the memory array because some value hold special meaning. +//void setMemory(address x, byte y); +// Set a piece of memory to some value. +byte getStack(); +// Get top value of the stack. +void setStack(byte z); +// Set top value of the stack. -#include"addressing.h" -#include"instructions/definitions.h" -#include"instructions/table.h"
\ No newline at end of file +#endif
\ No newline at end of file |