From c1d5bf8ab7648418fa7120ea4868205f3cf7e857 Mon Sep 17 00:00:00 2001 From: alekseiplusplus Date: Mon, 8 May 2023 09:49:43 +1000 Subject: instructions done, plus minor changes --- src/cpu/addressing.h | 2 ++ src/cpu/instructions/definitions.h | 36 +++++++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 9 deletions(-) (limited to 'src/cpu') diff --git a/src/cpu/addressing.h b/src/cpu/addressing.h index 0969025..29fa87c 100644 --- a/src/cpu/addressing.h +++ b/src/cpu/addressing.h @@ -33,6 +33,8 @@ typedef struct AddData{ //Holds address of current instruction. void* current_instruction; +#define getInstructionLength(c) fAddressGetLength(*getInstructionTableAddressing(c)) + int fAddressGetLength(Addressing addr){ switch(addr){ case eAbsolute: case eAbsoluteIndexedX: case eAbsoluteIndexedY: diff --git a/src/cpu/instructions/definitions.h b/src/cpu/instructions/definitions.h index 937ca10..98345c5 100644 --- a/src/cpu/instructions/definitions.h +++ b/src/cpu/instructions/definitions.h @@ -2,7 +2,8 @@ // Definition of all instruction functions, handling effect of instruction and flags. AddData idata; - +#define GET_STACK getMemory(0x01FF - S) +#define SET_STACK(z) setMemory(0x01FF - S, z) /* TO DO @@ -280,40 +281,50 @@ void fTXS(Addressing addr, address val){ idata = fAddress(addr, val); } void fPHA(Addressing addr, address val){ idata = fAddress(addr, val); - setMemory(0x01FF-S, acc); + SET_STACK(acc); S++; } void fPHP(Addressing addr, address val){ idata = fAddress(addr, val); - setMemory(0x01FF-S, P); + SET_STACK(P); S++; } void fPLA(Addressing addr, address val){ idata = fAddress(addr, val); S--; - acc = getMemory(0x01FF-S); + acc = GET_STACK; } void fPLP(Addressing addr, address val){ idata = fAddress(addr, val); S--; - P = getMemory(0x01FF-S); + P = GET_STACK; } // Subroutine Instructions // NEED TO FINISH THESE void fJSR(Addressing addr, address val){ idata = fAddress(addr, val); - Memory[0x01FF-S] = (idata.add-1); + SET_STACK(((PC-1) & 0xFF00) >> 8); + S++; + SET_STACK((PC-1) & 0x00FF); S++; PC = idata.add; } void fRTS(Addressing addr, address val){ idata = fAddress(addr, val); - + S--; + PC = (address)(GET_STACK + 1); + S--; + PC += ((address)(GET_STACK)) << 8; } void fRTI(Addressing addr, address val){ idata = fAddress(addr, val); - + S--; + P = GET_STACK; //NEED TO FIX + S--; + PC = (address)(GET_STACK); + S--; + PC += (address)(GET_STACK << 8); } // Set/Reset Insutrctions @@ -352,7 +363,14 @@ void fNOP(Addressing addr, address val){ idata = fAddress(addr, val); } void fBRK(Addressing addr, address val){ idata = fAddress(addr, val); - flagSet(flag_B); + SET_STACK((((PC+2) & 0xFF00) >> 8)); + S++; + SET_STACK((PC+2) & 0x00FF); + S++; + SET_STACK(P); + S++; + PC = (address)(getMemory(0xFFFE)); + PC += ((address)(getMemory(0xFFFF)) << 8); } #ifdef ILLEGAL -- cgit v1.2.3