summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralekseiplusplus <alekseijeaves@protonmail.com>2023-03-27 17:19:36 +1100
committeralekseiplusplus <alekseijeaves@protonmail.com>2023-03-27 17:19:36 +1100
commitcd50e11648971a3fbdc3936839f4a5401e3a9d29 (patch)
tree4bec70a901d854932bd61af79a2d5eea58f56f2a
parent38c238150e9707fed0b9e8602e24bf91a7ffe4e3 (diff)
More instructions, misc system details
-rw-r--r--applesystem.h9
-rw-r--r--instruction.h161
2 files changed, 165 insertions, 5 deletions
diff --git a/applesystem.h b/applesystem.h
index ea9b322..9b3dd1c 100644
--- a/applesystem.h
+++ b/applesystem.h
@@ -1,10 +1,13 @@
typedef unsigned char byte;
-byte acc, X, Y, S, P = 0x00;
+typedef unsigned short address;
+byte acc, X, Y, P = 0x00;
+unsigned short S = 0x0000;
byte Memory[4096]; // TO DO. Add expansion capability to memory.
/*
To Do.
+ Find variables better passed as pointers instead
+ + Clean up this messy code
*/
@@ -32,10 +35,6 @@ void setFlag(byte flag, int x) { //OVERLOAD TO ACCEPT INT AS WELL
}
}
-void toggleFlag(byte flag) {
- P = ((P & flag) == flag) ? (P + flag) : (P - flag);
-}
-
// BCD
byte toBCD(byte x){
diff --git a/instruction.h b/instruction.h
index 054e629..a5cc2b9 100644
--- a/instruction.h
+++ b/instruction.h
@@ -60,8 +60,41 @@ void fSBC(Addressing addr, int val){
//Increment and Decrement Instructions
+void fINC(Addressing addr, int val){
+ Memory[x]++;
+ setFlagD(Memory[x]);
+ setFlagZ(Memory[x]);
+}
+
+void fINX(){
+ X++;
+ setFlagD(X);
+ setFlagZ(X);
+}
+
+void fINY(){
+ Y++;
+ setFlagD(Y);
+ setFlagZ(Y);
+}
+
+void fDEC(Addressing addr, int val){
+ Memory[x]--;
+ setFlagD(Memory[x]);
+ setFlagZ(Memory[x]);
+}
+void fDEX(){
+ X--;
+ setFlagD(X);
+ setFlagZ(X);
+}
+void fDEY(){
+ Y--;
+ setFlagD(Y);
+ setFlagZ(Y);
+}
// Logical Instructions
@@ -85,12 +118,94 @@ void fEOR(Addressing addr, int val){
// Jump, Branch, Compare, and Test Bits
+void fJMP(int val){
+ S = val;
+}
+
+void fBCC(signed char val){
+ if (getFlag(flag_C) == 0) S += val;
+}
+
+void fBCS(signed char val){
+ if (getFlag(flag_C) == 1) S += val;
+}
+
+void fBEQ(signed char val){
+ if (getFlag(flag_Z) == 1) S += val;
+}
+
+void fBNE(signed char val){
+ if (getFlag(flag_Z) == 0) S += val;
+}
+
+void fBMI(signed char val){
+ if (getFlag(flag_N) == 1) S += val;
+}
+
+void fBPL(signed char val){
+ if (getFlag(flag_N) == 0) S += val;
+}
+
+void fBVS(signed char val){
+ if (getFlag(flag_V) == 1) S += val;
+}
+
+void fBVC(signed char val){
+ if (getFlag(flag_V) == 0) S += val;
+}
+
+void fCMP(address val){
+ if (acc < Memory[val]){
+ setFlag(flag_N, 1); setFlag(flag_Z, 0); setFlag(flag_C, 0);
+ }if (acc == Memory[val]){
+ setFlag(flag_N, 0); setFlag(flag_Z, 1); setFlag(flag_C, 0);
+ }if (acc > Memory[val]){
+ setFlag(flag_N, 0); setFlag(flag_Z, 0); setFlag(flag_C, 1);
+ }
+}
+void fCPX(address val){
+ if (X < Memory[val]){
+ setFlag(flag_N, 1); setFlag(flag_Z, 0); setFlag(flag_C, 0);
+ }if (X == Memory[val]){
+ setFlag(flag_N, 0); setFlag(flag_Z, 1); setFlag(flag_C, 0);
+ }if (X > Memory[val]){
+ setFlag(flag_N, 0); setFlag(flag_Z, 0); setFlag(flag_C, 1);
+ }
+}
+void fCPY(address val){
+ if (Y < Memory[val]){
+ setFlag(flag_N, 1); setFlag(flag_Z, 0); setFlag(flag_C, 0);
+ }if (Y == Memory[val]){
+ setFlag(flag_N, 0); setFlag(flag_Z, 1); setFlag(flag_C, 0);
+ }if (Y > Memory[val]){
+ setFlag(flag_N, 0); setFlag(flag_Z, 0); setFlag(flag_C, 1);
+ }
+}
+void fBIT(address val){
+ setFlag(flag_N, (Memory[val] & flag_N));
+ setFlag(flag_V, (Memory[val] & flag_V));
+ if (((Memory[val] & flag_N) & (Memory[val] & flag_V)) == 0) {
+ setFlag(flag_Z, 1);
+ } else {
+ setFlag(flag_Z, 0);
+ }
+}
// Shift and Rotate Instructions
+/* ASL - Accumulator Shift Left
+ LSR - Logical Shift Right
+ ROL - ROtate Left
+ ROR - ROtate Right
+
+ Z is set if the result it zero. N is set if bit 7 is 1. It is
+ always reset on LSR. Remember that ASL A is equal to multiplying by
+ two and that LSR is equal to dividing by two.*/
+
+
void fASL(Addressing addr, int val){
setFlag(flag_C, (val & 0x80));
acc = (val << 1);
@@ -98,9 +213,55 @@ void fASL(Addressing addr, int val){
setFlagZ(acc);
}
+/* Use these instructions to move things around in the accumulator or
+ memory. The net effects are (where C is the carry flag):
+
+
+ +-+-+-+-+-+-+-+-+
+ C <- |7|6|5|4|3|2|1|0| <- 0 ASL
+ +-+-+-+-+-+-+-+-+
+
+ +-+-+-+-+-+-+-+-+
+ 0 -> |7|6|5|4|3|2|1|0| -> C LSR
+ +-+-+-+-+-+-+-+-+
+
+ +-+-+-+-+-+-+-+-+
+ C <- |7|6|5|4|3|2|1|0| <- C ROL
+ +-+-+-+-+-+-+-+-+
+
+ +-+-+-+-+-+-+-+-+
+ C -> |7|6|5|4|3|2|1|0| -> C ROR
+ +-+-+-+-+-+-+-+-+
+*/
+
// Transfer Instructions
+void fTAX(){
+ X = acc;
+ setFlagN(X);
+ setFlagZ(X);
+}
+
+void fTAY(){
+ Y = acc;
+ setFlagN(Y);
+ setFlagZ(Y);
+}
+
+void fTXA(){
+ acc = X;
+ setFlagN(acc);
+ setFlagZ(acc);
+}
+
+void fTYA(){
+ acc = Y;
+ setFlagN(acc);
+ setFlagZ(acc);
+}
+
+
// Stack Instructions
// Subroutine Instructions