From 98c242def30ae70f327323d65485b41bdbd151b4 Mon Sep 17 00:00:00 2001 From: alekseiplusplus Date: Wed, 5 Apr 2023 22:23:17 +1000 Subject: reworking instructions, added assembler.c --- instruction.h | 85 ++++++++++++++++++++++++----------------------------------- 1 file changed, 34 insertions(+), 51 deletions(-) (limited to 'instruction.h') diff --git a/instruction.h b/instruction.h index b296e0c..2c4c3a2 100644 --- a/instruction.h +++ b/instruction.h @@ -1,68 +1,44 @@ -//void fXXX(ADDRESSING addr, int val) - -// Considering making instruction functions return an int of -// how many cycles passed - -struct instruction_data { - int length = 0; - int cycles = 0; -}; - -int getLength(Addressing addr){ - switch(addr){ - case eAbsolute: case eAbsoluteIndexedX: case eAbsoluteIndexedY: - return 3; - case eAccumulator: - return 1; - default: - return 2; - } -} + +// array/map of pointers which all point +// to the functions which the index corresponds to. +// use that like a sort of map +AddData idata; //Instruction Data + // Load and Store Instructions +// the load and store instructions are currently +// used to express how data structures will work eventually. -instruction_data fLDA(Addressing addr, address val){ - instruction_data d; d.length = getLength(addr); - acc = fAddressing(addr, val); - return d; +void fLDA(Addressing addr, address val){ idata = fAddress(addr, val); + acc = idata.val; } -instruction_data fLDX(Addressing addr, address val){ - instruction_data d; d.length = getLength(addr); - X = fAddressing(addr, val); - return d; +void fLDX(Addressing addr, address val){ idata = fAddress(addr, val); + X = idata.value; } -instruction_data fLDY(Addressing addr, address val){ - instruction_data d; d.length = getLength(addr); - Y = fAddressing(addr, val); - return d; +void fLDY(Addressing addr, address val){ idata = fAddress(addr, val); + Y = idata.value; } -instruction_data fSTA(Addressing addr, address val){ - instruction_data d; d.length = getLength(addr); - Memory[(fAddressing(addr, val))] = acc; - return d; +void fSTA(Addressing addr, address val){ idata = fAddress(addr, val); + Memory[idata.value] = acc; } -instruction_data fSTX(Addressing addr, address val){ - instruction_data d; d.length = getLength(addr); - Memory[(fAddressing(addr, val))] = X; - return d; +void fSTX(Addressing addr, address val){ idata = fAddress(addr, val); + Memory[idata.value] = X; } -instruction_data fSTY(Addressing addr, address val){ - instruction_data d; d.length = getLength(addr); - Memory[(fAddressing(addr, val))] = Y; - return d; +void fSTY(Addressing addr, address val){ idata = fAddress(addr, val); + Memory[idata.value] = Y; } // Arithmetic Instructions instruction_data fADC(Addressing addr, address val){ instruction_data d; d.length = getLength(addr); - int buffer = acc + fAddressing(addr, val); + int buffer = acc + fAddress(addr, val); setFlagV(buffer, acc); if (buffer > 255){ @@ -71,13 +47,13 @@ instruction_data fADC(Addressing addr, address val){ flagClear(flag_C); } - acc += fAddressing(addr, val); + acc += fAddress(addr, val); setFlagN(acc); setFlagZ(acc); } instruction_data fSBC(Addressing addr, address val){ - int buffer = acc - fAddressing(addr, val); + int buffer = acc - fAddress(addr, val); setFlagV(buffer, acc); if (buffer < 0){ @@ -85,7 +61,7 @@ instruction_data fSBC(Addressing addr, address val){ }else{ flagClear(flag_C); } - acc -= fAddressing(addr, val); + acc -= fAddress(addr, val); setFlagN(acc); setFlagZ(acc); } @@ -131,19 +107,19 @@ instruction_data fDEY(){ // Logical Instructions instruction_data fAND(Addressing addr, address val){ - acc = acc & fAddressing(addr, val); + acc = acc & fAddress(addr, val); setFlagN(); setFlagZ(acc); } instruction_data fORA(Addressing addr, address val){ - acc = acc | fAddressing(addr, val); + acc = acc | fAddress(addr, val); setFlagN(); setFlagZ(acc); } instruction_data fEOR(Addressing addr, address val){ - acc = acc ^ fAddressing(addr, val); + acc = acc ^ fAddress(addr, val); setFlagN(acc); setFlagZ(acc); } @@ -364,6 +340,13 @@ instruction_data fBRK(){ + + + + + + + /* void runInstruction(int code, int val){ switch(code){ -- cgit v1.2.3