From 58c78935c7115a184198e84314ba7f48d4f28991 Mon Sep 17 00:00:00 2001 From: WickedJack99 Date: Fri, 29 Apr 2022 01:48:03 +0200 Subject: [PATCH] ? --- bin/Control/MyControlView.class | Bin 10953 -> 10945 bytes bin/Model/Microcontroller/EEPROM.class | Bin 2826 -> 2818 bytes ...Bitmask.class => INSTRUCTIONDECODER.class} | Bin 4125 -> 4135 bytes bin/Model/Microcontroller/PIC.class | Bin 13418 -> 13406 bytes bin/Model/Microcontroller/PROGRAMMEMORY.class | Bin 1652 -> 1670 bytes .../{RUNTIMER.class => TIME.class} | Bin 2184 -> 2172 bytes bin/Model/MyModel.class | Bin 4287 -> 4293 bytes src/Model/Microcontroller/EEPROM.java | 2 +- .../{Bitmask.java => INSTRUCTIONDECODER.java} | 884 +++++++++--------- src/Model/Microcontroller/PIC.java | 8 +- src/Model/Microcontroller/PROGRAMMEMORY.java | 22 +- .../{RUNTIMER.java => TIME.java} | 4 +- src/Model/MyModel.java | 6 +- 13 files changed, 463 insertions(+), 463 deletions(-) rename bin/Model/Microcontroller/{Bitmask.class => INSTRUCTIONDECODER.class} (80%) rename bin/Model/Microcontroller/{RUNTIMER.class => TIME.class} (84%) rename src/Model/Microcontroller/{Bitmask.java => INSTRUCTIONDECODER.java} (94%) mode change 100755 => 100644 rename src/Model/Microcontroller/{RUNTIMER.java => TIME.java} (98%) diff --git a/bin/Control/MyControlView.class b/bin/Control/MyControlView.class index e2e9bbc404e33175d23f15d2b615109a15efbc63..1d271ca09050e2dc6829cf99fe877fbcef21431a 100644 GIT binary patch delta 44 ycmX>ZdN6c@CNHDhYdNOo_CNHDXm50oLb_VlbV~FR}!(=i}3&_0BFAmZvX%Q delta 33 ocmZn?>k`{w#wa3IoLb_VlbV~FR}$f$=9*eil%KoViSYm@0K75_lmGw# diff --git a/bin/Model/Microcontroller/Bitmask.class b/bin/Model/Microcontroller/INSTRUCTIONDECODER.class similarity index 80% rename from bin/Model/Microcontroller/Bitmask.class rename to bin/Model/Microcontroller/INSTRUCTIONDECODER.class index 505541bfc8216f455027520c4dc33f2b472150ab..41b84e78f469059f3b16899010ee2a52da584d4b 100644 GIT binary patch delta 130 zcmbQMuv|gl)W2Q(7#J9A8CI|}FflS{OcW3k^7IQ12?})%@$~m|adq~0aSfWNo5rN& z1C*1&l(S}J5Kl=>&QD35c*LHcFSQ~yxwItJIX^cyF)wAaBI9-zVR1}dn;)>+asdFX Cc_!Zg delta 120 zcmZ3kFjqm~)W2Q(7#J9A8CI|}FflU7P81MhcgifuO)SoyXpzPw?*kN&gbG+QGRP-o zmiPkYTvC(sQ&Nj2Ub2^y&4h4Lobz*Y6Z2Alyv*X_%=|px#O&0f%?ga$SvYv0CTxDi HYRd%x27M?J diff --git a/bin/Model/Microcontroller/PIC.class b/bin/Model/Microcontroller/PIC.class index 524a73769fd80bba71cd004b2273d04de11edfb8..a7a9224ad87f1e44bc6871e73949383d0a121e21 100644 GIT binary patch delta 52 zcmaEraW7-S14fyN55-wRJbhg^F}g4_N=ff$?3=9mm3@PjkOpFXt69vRrLOgw4H|hm5GRgSBxSJO;N;9!?f@C%y IWj@RT0QXN29RL6T delta 72 zcmew(&><*r>ff$?3=9mm3@PjkOpFY269vRLf`s{_xrxQulOJ)+;FnLzEb#?$TvC(sQ&Nj2H*z{K%1`Fw o5{IjL%~{2$G>KD^BPi4_#M9R`XmT@`CZin4B)HJ#<6Qq(0i>`XL;wH) diff --git a/src/Model/Microcontroller/EEPROM.java b/src/Model/Microcontroller/EEPROM.java index 4114e1e..ad9f80e 100644 --- a/src/Model/Microcontroller/EEPROM.java +++ b/src/Model/Microcontroller/EEPROM.java @@ -17,7 +17,7 @@ public class EEPROM { oFile = new File("./eeprom.dat"); } - public void setElementXOfEepromToY(int iX, int iY) { + public void setElementXToY(int iX, int iY) { aiEeprom[iX] = iY; } diff --git a/src/Model/Microcontroller/Bitmask.java b/src/Model/Microcontroller/INSTRUCTIONDECODER.java old mode 100755 new mode 100644 similarity index 94% rename from src/Model/Microcontroller/Bitmask.java rename to src/Model/Microcontroller/INSTRUCTIONDECODER.java index 2e735ab..1cd122c --- a/src/Model/Microcontroller/Bitmask.java +++ b/src/Model/Microcontroller/INSTRUCTIONDECODER.java @@ -1,443 +1,443 @@ -package Model.Microcontroller; - -public class Bitmask { - /** - * Decides which PIC-command-method to call. - * @param iCommandAsIntToMask - * @param oPIC - */ - public int bitMaskDecoderAndExecuteCommand(int iCommandAsIntToMask, PIC oPIC) { - //System.out.println("Command " + Integer.toHexString(iCommandAsIntToMask)); - //Return-value will be -1 if command can't be read. - int iDecodedCommand = -1; - - //Command that was overhanded is written into "command" - int iCommand = iCommandAsIntToMask; - - //Bitmask to get the destination-bit - int iDestinationBitBitmask = 0b00000010000000; - //Destination-bit - int iDestinationBit = (iDestinationBitBitmask & iCommand) >> 7; - - //Bitmask to get the register-file-adress - int iRegisterFileAddressBitmask = 0b00000001111111; - //Register-file-adress - int iRegisterFileAddress = (iRegisterFileAddressBitmask & iCommand); - - //Bitmask to get bitaddress - int iBitaddressBitmask = 0b00001110000000; - //Bitaddress - int iBitaddress = (iBitaddressBitmask & iCommand) >> 7; - - //Bitmask to get eight last k's - int iEightKBitmask = 0b00000011111111; - int iEightK = (iEightKBitmask & iCommand); - - //Bitmask to get eleven last k's - int iElevenKBitmask = 0b00011111111111; - int iElevenK = (iElevenKBitmask & iCommand); - - //Bitmask to get TRIS-register TRIS instruction not used - //int tRISRegisterBitmask = 0b000000000111; - //int tRISRegisterAddress = (tRISRegisterBitmask & command); - - if ((0b10000000000000 & iCommand) == 0b10000000000000) { - //1x xxxx xxxx xxxx - if ((0b01000000000000 & iCommand) == 0b01000000000000) { - //11 xxxx xxxx xxxx - if ((0b00100000000000 & iCommand) == 0b00100000000000) { - //11 1xxx xxxx xxxx - if ((0b00010000000000 & iCommand) == 0b00010000000000) { - //11 11xx xxxx xxxx - if ((0b00001000000000 & iCommand) == 0b00001000000000) { - //11 111x xxxx xxxx - iDecodedCommand = 22; //ADDLW - } else { - //11 110x xxxx xxxx - iDecodedCommand = 33; //SUBLW - } - } else { - //11 10xx xxxx xxxx - if ((0b00001000000000 & iCommand) == 0b00001000000000) { - //11 101x xxxx xxxx - if ((0b00000100000000 & iCommand) == 0b00000100000000) { - //11 1011 xxxx xxxx - } else { - //11 1010 xxxx xxxx - iDecodedCommand = 34; //XORLW - } - } else { - //11 100x xxxx xxxx - if ((0b00000100000000 & iCommand) == 0b00000100000000) { - //11 1001 xxxx xxxx - iDecodedCommand = 23; //ANDLW - } else { - //11 1000 xxxx xxxx - iDecodedCommand = 27; //IORLW - } - } - } - } else { - //11 0xxx xxxx xxxx - if ((0b00010000000000 & iCommand) == 0b00010000000000) { - //11 01xx xxxx xxxx - iDecodedCommand = 30; //RETLW - } else { - //11 00xx xxxx xxxx - iDecodedCommand = 28; //MOVLW - } - } - } else { - //10 xxxx xxxx xxxx - if ((0b00100000000000 & iCommand) == 0b00100000000000) { - //10 1xxx xxxx xxxx - iDecodedCommand = 26; //GOTO - } else { - //10 0xxx xxxx xxxx - iDecodedCommand = 24; //CALL - } - } - } else if ((0b01000000000000 & iCommand) == 0b01000000000000) { - //01 xxxx xxxx xxxx - if ((0b00100000000000 & iCommand) == 0b00100000000000) { - //01 1xxx xxxx xxxx - if ((0b00010000000000 & iCommand) == 0b00010000000000) { - //01 11xx xxxx xxxx - iDecodedCommand = 21; //BTFSS - } else { - //01 10xx xxxx xxxx - iDecodedCommand = 20; //BTFSC - } - } else { - //01 0xxx xxxx xxxx - if ((0b00010000000000 & iCommand) == 0b00010000000000) { - //01 01xx xxxx xxxx - iDecodedCommand = 19; //BSF - } else { - //01 00xx xxxx xxxx - iDecodedCommand = 18; //BCF - } - } - } else if ((0b00100000000000 & iCommand) == 0b00100000000000) { - //00 1xxx xxxx xxxx - if ((0b00010000000000 & iCommand) == 0b00010000000000) { - //00 11xx xxxx xxxx - if ((0b00001000000000 & iCommand) == 0b00001000000000) { - //00 111x xxxx xxxx - if ((0b00000100000000 & iCommand) == 0b00000100000000) { - //00 1111 xxxx xxxx - iDecodedCommand = 8; //INCFSZ - } else { - //00 1110 xxxx xxxx - iDecodedCommand = 16; //SWAPF - } - } else { - //00 110x xxxx xxxx - if ((0b00000100000000 & iCommand) == 0b00000100000000) { - //00 1101 xxxx xxxx - iDecodedCommand = 13; //RLF - } else { - //00 1100 xxxx xxxx - iDecodedCommand = 14; //RRF - } - } - } else { - //00 10xx xxxx xxxx - if ((0b00001000000000 & iCommand) == 0b00001000000000) { - //00 101x xxxx xxxx - if ((0b00000100000000 & iCommand) == 0b00000100000000) { - //00 1011 xxxx xxxx - iDecodedCommand = 6; //DECFSZ - } else { - //00 1010 xxxx xxxx - iDecodedCommand = 7; //INCF - } - } else { - //00 100x xxxx xxxx - if ((0b00000100000000 & iCommand) == 0b00000100000000) { - //00 1001 xxxx xxxx - iDecodedCommand = 4; //COMF - } else { - //00 1000 xxxx xxxx - iDecodedCommand = 10; //MOVF - } - } - } - } else if ((0b00010000000000 & iCommand) == 0b00010000000000) { - //00 01xx xxxx xxxx - if ((0b00001000000000 & iCommand) == 0b00001000000000) { - //00 011x xxxx xxxx - if ((0b00000100000000 & iCommand) == 0b00000100000000) { - //00 0111 xxxx xxxx - iDecodedCommand = 0; //ADDWF - } else { - //00 0110 xxxx xxxx - iDecodedCommand = 17; //XORWF - } - } else { - //00 010x xxxx xxxx - if ((0b00000100000000 & iCommand) == 0b00000100000000) { - //00 0101 xxxx xxxx - iDecodedCommand = 1; //ANDWF - } else { - //00 0100 xxxx xxxx - iDecodedCommand = 9; //IORWF - } - } - } else if ((0b00001000000000 & iCommand) == 0b00001000000000) { - //00 001x xxxx xxxx - if ((0b00000100000000 & iCommand) == 0b00000100000000) { - //00 0011 xxxx xxxx - iDecodedCommand = 5; //DECF - } else { - //00 0010 xxxx xxxx - iDecodedCommand = 15; //SUBWF - } - } else if ((0b00000100000000 & iCommand) == 0b00000100000000) { - //00 0001 xxxx xxxx - if ((0b00000010000000 & iCommand) == 0b00000010000000) { - //00 0001 1xxx xxxx - iDecodedCommand = 2; //CLRF - } else { - //00 0001 0xxx xxxx - iDecodedCommand = 3; //CLRW - } - } else if ((0b00000001000000 & iCommand) == 0b00000001000000) { - //00 0000 01xx xxxx - if ((0b00000000100000 & iCommand) == 0b00000000100000) { - //00 0000 011x xxxx - if ((0b00000000010000 & iCommand) == 0b00000000010000) { - //00 0000 0111 xxxx - } else { - //00 0000 0110 xxxx - if ((0b00000000001000 & iCommand) == 0b00000000001000) { - //00 0000 0110 1xxx - } else { - //00 0000 0110 0xxx - if ((0b00000000000100 & iCommand) == 0b00000000000100) { - //00 0000 0110 01xx - if ((0b00000000000010 & iCommand) == 0b00000000000010) { - //00 0000 0110 011x - } else { - //00 0000 0110 010x - if ((0b00000000000001 & iCommand) == 0b00000000000001) { - //00 0000 0110 0101 - } else { - //00 0000 0110 0100 - iDecodedCommand = 25; //CLRWDT - } - } - } else { - //00 0000 0110 00xx - if ((0b00000000000010 & iCommand) == 0b00000000000010) { - //00 0000 0110 001x - if ((0b00000000000001 & iCommand) == 0b00000000000001) { - //00 0000 0110 0011 - iDecodedCommand = 32; //SLEEP - } else { - //00 0000 0110 0010 - iDecodedCommand = 35; //OPTION - } - } - } - } - } - } - } else if ((0b00000010000000 & iCommand) == 0b00000010000000) { - //00 0000 1xxx xxxx - iDecodedCommand = 11; //MOVWF - } else if ((0b00000000001000 & iCommand) == 0b00000000001000) { - //00 0000 0000 1xxx - if ((0b00000000000100 & iCommand) == 0b00000000000100) { - //00 0000 0000 11xx - } else { - //00 0000 0000 10xx - if ((0b00000000000010 & iCommand) == 0b00000000000010) { - //00 0000 0000 101x - } else { - //00 0000 0000 100x - if ((0b00000000000001 & iCommand) == 0b00000000000001) { - //00 0000 0000 1001 - iDecodedCommand = 29; //RETFIE - } else { - //00 0000 0000 1000 - iDecodedCommand = 31; //RETURN - } - } - } - } else if ((0b00000001100000 & iCommand) == iCommand) { - //00 0000 0xx0 0000 - iDecodedCommand = 12; //NOP - } - iDecodedCommandDecissionMaker(iDecodedCommand, oPIC, iDestinationBit, iRegisterFileAddress, iBitaddress, iEightK, iElevenK); - - return iDecodedCommand; - } - - public void iDecodedCommandDecissionMaker(int iDecodedCommand, PIC oPIC, int iDestinationBit, int iRegisterFileAddress, int iBitaddress, int iEightK, int iElevenK) { - switch (iDecodedCommand) { - case -1: { - System.out.println("Command doesn't exist."); - }break; - - case 0: { - oPIC.ADDWF(iDestinationBit, iRegisterFileAddress); - }break; - - case 1: { - oPIC.ANDWF(iDestinationBit, iRegisterFileAddress); - }break; - - case 2: { - oPIC.CLRF(iRegisterFileAddress); - }break; - - case 3: { - oPIC.CLRW(); - }break; - - case 4: { - oPIC.COMF(iDestinationBit, iRegisterFileAddress); - }break; - - case 5: { - oPIC.DECF(iDestinationBit, iRegisterFileAddress); - }break; - - case 6: { - oPIC.DECFSZ(iDestinationBit, iRegisterFileAddress); - }break; - - case 7: { - oPIC.INCF(iDestinationBit, iRegisterFileAddress); - }break; - - case 8: { - oPIC.INCFSZ(iDestinationBit, iRegisterFileAddress); - }break; - - case 9: { - oPIC.IORWF(iDestinationBit, iRegisterFileAddress); - }break; - - case 10: { - oPIC.MOVF(iDestinationBit, iRegisterFileAddress); - }break; - - case 11: { - oPIC.MOVWF(iRegisterFileAddress); - }break; - - case 12: { - oPIC.NOP(); - }break; - - case 13: { - oPIC.RLF(iDestinationBit, iRegisterFileAddress); - }break; - - case 14: { - oPIC.RRF(iDestinationBit, iRegisterFileAddress); - }break; - - case 15: { - oPIC.SUBWF(iDestinationBit, iRegisterFileAddress); - }break; - - case 16: { - oPIC.SWAPF(iDestinationBit, iRegisterFileAddress); - }break; - - case 17: { - oPIC.XORWF(iDestinationBit, iRegisterFileAddress); - }break; - - case 18: { - oPIC.BCF(iBitaddress, iRegisterFileAddress); - }break; - - case 19: { - oPIC.BSF(iBitaddress, iRegisterFileAddress); - }break; - - case 20: { - oPIC.BTFSC(iBitaddress, iRegisterFileAddress); - }break; - - case 21: { - oPIC.BTFSS(iBitaddress, iRegisterFileAddress); - }break; - - case 22: { - oPIC.ADDLW(iEightK); - }break; - - case 23: { - oPIC.ANDLW(iEightK); - }break; - - case 24: { - oPIC.CALL(iElevenK); - }break; - - case 25: { - //watchdogThread.setTime(0); - oPIC.CLRWDT(); - }break; - - case 26: { - oPIC.GOTO(iElevenK); - }break; - - case 27: { - oPIC.IORLW(iEightK); - }break; - - case 28: { - oPIC.MOVLW(iEightK); - }break; - - case 29: { - oPIC.RETFIE(); - }break; - - case 30: { - oPIC.RETLW(iEightK); - }break; - - case 31: { - oPIC.RETURN(); - }break; - - case 32: { - oPIC.SLEEP(); - }break; - - case 33: { - oPIC.SUBLW(iEightK); - }break; - - case 34: { - oPIC.XORLW(iEightK); - }break; - - case 35: { - /** - * To maintain upward compatibility - * with future PIC16CXX products, - * do not use this instruction. - */ - oPIC.OPTION(); - }break; - - case 36: { - /** - * To maintain upward compatibility - * with future PIC16CXX products, - * do not use this instruction. - */ - oPIC.TRIS(); - }break; - } - } +package Model.Microcontroller; + +public class INSTRUCTIONDECODER { + /** + * Decides which PIC-command-method to call. + * @param iCommandAsIntToMask + * @param oPIC + */ + public int decodeAndExecuteCommand(int iCommandAsIntToMask, PIC oPIC) { + //System.out.println("Command " + Integer.toHexString(iCommandAsIntToMask)); + //Return-value will be -1 if command can't be read. + int iDecodedCommand = -1; + + //Command that was overhanded is written into "command" + int iCommand = iCommandAsIntToMask; + + //Bitmask to get the destination-bit + int iDestinationBitBitmask = 0b00000010000000; + //Destination-bit + int iDestinationBit = (iDestinationBitBitmask & iCommand) >> 7; + + //Bitmask to get the register-file-adress + int iRegisterFileAddressBitmask = 0b00000001111111; + //Register-file-adress + int iRegisterFileAddress = (iRegisterFileAddressBitmask & iCommand); + + //Bitmask to get bitaddress + int iBitaddressBitmask = 0b00001110000000; + //Bitaddress + int iBitaddress = (iBitaddressBitmask & iCommand) >> 7; + + //Bitmask to get eight last k's + int iEightKBitmask = 0b00000011111111; + int iEightK = (iEightKBitmask & iCommand); + + //Bitmask to get eleven last k's + int iElevenKBitmask = 0b00011111111111; + int iElevenK = (iElevenKBitmask & iCommand); + + //Bitmask to get TRIS-register TRIS instruction not used + //int tRISRegisterBitmask = 0b000000000111; + //int tRISRegisterAddress = (tRISRegisterBitmask & command); + + if ((0b10000000000000 & iCommand) == 0b10000000000000) { + //1x xxxx xxxx xxxx + if ((0b01000000000000 & iCommand) == 0b01000000000000) { + //11 xxxx xxxx xxxx + if ((0b00100000000000 & iCommand) == 0b00100000000000) { + //11 1xxx xxxx xxxx + if ((0b00010000000000 & iCommand) == 0b00010000000000) { + //11 11xx xxxx xxxx + if ((0b00001000000000 & iCommand) == 0b00001000000000) { + //11 111x xxxx xxxx + iDecodedCommand = 22; //ADDLW + } else { + //11 110x xxxx xxxx + iDecodedCommand = 33; //SUBLW + } + } else { + //11 10xx xxxx xxxx + if ((0b00001000000000 & iCommand) == 0b00001000000000) { + //11 101x xxxx xxxx + if ((0b00000100000000 & iCommand) == 0b00000100000000) { + //11 1011 xxxx xxxx + } else { + //11 1010 xxxx xxxx + iDecodedCommand = 34; //XORLW + } + } else { + //11 100x xxxx xxxx + if ((0b00000100000000 & iCommand) == 0b00000100000000) { + //11 1001 xxxx xxxx + iDecodedCommand = 23; //ANDLW + } else { + //11 1000 xxxx xxxx + iDecodedCommand = 27; //IORLW + } + } + } + } else { + //11 0xxx xxxx xxxx + if ((0b00010000000000 & iCommand) == 0b00010000000000) { + //11 01xx xxxx xxxx + iDecodedCommand = 30; //RETLW + } else { + //11 00xx xxxx xxxx + iDecodedCommand = 28; //MOVLW + } + } + } else { + //10 xxxx xxxx xxxx + if ((0b00100000000000 & iCommand) == 0b00100000000000) { + //10 1xxx xxxx xxxx + iDecodedCommand = 26; //GOTO + } else { + //10 0xxx xxxx xxxx + iDecodedCommand = 24; //CALL + } + } + } else if ((0b01000000000000 & iCommand) == 0b01000000000000) { + //01 xxxx xxxx xxxx + if ((0b00100000000000 & iCommand) == 0b00100000000000) { + //01 1xxx xxxx xxxx + if ((0b00010000000000 & iCommand) == 0b00010000000000) { + //01 11xx xxxx xxxx + iDecodedCommand = 21; //BTFSS + } else { + //01 10xx xxxx xxxx + iDecodedCommand = 20; //BTFSC + } + } else { + //01 0xxx xxxx xxxx + if ((0b00010000000000 & iCommand) == 0b00010000000000) { + //01 01xx xxxx xxxx + iDecodedCommand = 19; //BSF + } else { + //01 00xx xxxx xxxx + iDecodedCommand = 18; //BCF + } + } + } else if ((0b00100000000000 & iCommand) == 0b00100000000000) { + //00 1xxx xxxx xxxx + if ((0b00010000000000 & iCommand) == 0b00010000000000) { + //00 11xx xxxx xxxx + if ((0b00001000000000 & iCommand) == 0b00001000000000) { + //00 111x xxxx xxxx + if ((0b00000100000000 & iCommand) == 0b00000100000000) { + //00 1111 xxxx xxxx + iDecodedCommand = 8; //INCFSZ + } else { + //00 1110 xxxx xxxx + iDecodedCommand = 16; //SWAPF + } + } else { + //00 110x xxxx xxxx + if ((0b00000100000000 & iCommand) == 0b00000100000000) { + //00 1101 xxxx xxxx + iDecodedCommand = 13; //RLF + } else { + //00 1100 xxxx xxxx + iDecodedCommand = 14; //RRF + } + } + } else { + //00 10xx xxxx xxxx + if ((0b00001000000000 & iCommand) == 0b00001000000000) { + //00 101x xxxx xxxx + if ((0b00000100000000 & iCommand) == 0b00000100000000) { + //00 1011 xxxx xxxx + iDecodedCommand = 6; //DECFSZ + } else { + //00 1010 xxxx xxxx + iDecodedCommand = 7; //INCF + } + } else { + //00 100x xxxx xxxx + if ((0b00000100000000 & iCommand) == 0b00000100000000) { + //00 1001 xxxx xxxx + iDecodedCommand = 4; //COMF + } else { + //00 1000 xxxx xxxx + iDecodedCommand = 10; //MOVF + } + } + } + } else if ((0b00010000000000 & iCommand) == 0b00010000000000) { + //00 01xx xxxx xxxx + if ((0b00001000000000 & iCommand) == 0b00001000000000) { + //00 011x xxxx xxxx + if ((0b00000100000000 & iCommand) == 0b00000100000000) { + //00 0111 xxxx xxxx + iDecodedCommand = 0; //ADDWF + } else { + //00 0110 xxxx xxxx + iDecodedCommand = 17; //XORWF + } + } else { + //00 010x xxxx xxxx + if ((0b00000100000000 & iCommand) == 0b00000100000000) { + //00 0101 xxxx xxxx + iDecodedCommand = 1; //ANDWF + } else { + //00 0100 xxxx xxxx + iDecodedCommand = 9; //IORWF + } + } + } else if ((0b00001000000000 & iCommand) == 0b00001000000000) { + //00 001x xxxx xxxx + if ((0b00000100000000 & iCommand) == 0b00000100000000) { + //00 0011 xxxx xxxx + iDecodedCommand = 5; //DECF + } else { + //00 0010 xxxx xxxx + iDecodedCommand = 15; //SUBWF + } + } else if ((0b00000100000000 & iCommand) == 0b00000100000000) { + //00 0001 xxxx xxxx + if ((0b00000010000000 & iCommand) == 0b00000010000000) { + //00 0001 1xxx xxxx + iDecodedCommand = 2; //CLRF + } else { + //00 0001 0xxx xxxx + iDecodedCommand = 3; //CLRW + } + } else if ((0b00000001000000 & iCommand) == 0b00000001000000) { + //00 0000 01xx xxxx + if ((0b00000000100000 & iCommand) == 0b00000000100000) { + //00 0000 011x xxxx + if ((0b00000000010000 & iCommand) == 0b00000000010000) { + //00 0000 0111 xxxx + } else { + //00 0000 0110 xxxx + if ((0b00000000001000 & iCommand) == 0b00000000001000) { + //00 0000 0110 1xxx + } else { + //00 0000 0110 0xxx + if ((0b00000000000100 & iCommand) == 0b00000000000100) { + //00 0000 0110 01xx + if ((0b00000000000010 & iCommand) == 0b00000000000010) { + //00 0000 0110 011x + } else { + //00 0000 0110 010x + if ((0b00000000000001 & iCommand) == 0b00000000000001) { + //00 0000 0110 0101 + } else { + //00 0000 0110 0100 + iDecodedCommand = 25; //CLRWDT + } + } + } else { + //00 0000 0110 00xx + if ((0b00000000000010 & iCommand) == 0b00000000000010) { + //00 0000 0110 001x + if ((0b00000000000001 & iCommand) == 0b00000000000001) { + //00 0000 0110 0011 + iDecodedCommand = 32; //SLEEP + } else { + //00 0000 0110 0010 + iDecodedCommand = 35; //OPTION + } + } + } + } + } + } + } else if ((0b00000010000000 & iCommand) == 0b00000010000000) { + //00 0000 1xxx xxxx + iDecodedCommand = 11; //MOVWF + } else if ((0b00000000001000 & iCommand) == 0b00000000001000) { + //00 0000 0000 1xxx + if ((0b00000000000100 & iCommand) == 0b00000000000100) { + //00 0000 0000 11xx + } else { + //00 0000 0000 10xx + if ((0b00000000000010 & iCommand) == 0b00000000000010) { + //00 0000 0000 101x + } else { + //00 0000 0000 100x + if ((0b00000000000001 & iCommand) == 0b00000000000001) { + //00 0000 0000 1001 + iDecodedCommand = 29; //RETFIE + } else { + //00 0000 0000 1000 + iDecodedCommand = 31; //RETURN + } + } + } + } else if ((0b00000001100000 & iCommand) == iCommand) { + //00 0000 0xx0 0000 + iDecodedCommand = 12; //NOP + } + executeCommand(iDecodedCommand, oPIC, iDestinationBit, iRegisterFileAddress, iBitaddress, iEightK, iElevenK); + + return iDecodedCommand; + } + + public void executeCommand(int iDecodedCommand, PIC oPIC, int iDestinationBit, int iRegisterFileAddress, int iBitaddress, int iEightK, int iElevenK) { + switch (iDecodedCommand) { + case -1: { + System.out.println("Command doesn't exist."); + }break; + + case 0: { + oPIC.ADDWF(iDestinationBit, iRegisterFileAddress); + }break; + + case 1: { + oPIC.ANDWF(iDestinationBit, iRegisterFileAddress); + }break; + + case 2: { + oPIC.CLRF(iRegisterFileAddress); + }break; + + case 3: { + oPIC.CLRW(); + }break; + + case 4: { + oPIC.COMF(iDestinationBit, iRegisterFileAddress); + }break; + + case 5: { + oPIC.DECF(iDestinationBit, iRegisterFileAddress); + }break; + + case 6: { + oPIC.DECFSZ(iDestinationBit, iRegisterFileAddress); + }break; + + case 7: { + oPIC.INCF(iDestinationBit, iRegisterFileAddress); + }break; + + case 8: { + oPIC.INCFSZ(iDestinationBit, iRegisterFileAddress); + }break; + + case 9: { + oPIC.IORWF(iDestinationBit, iRegisterFileAddress); + }break; + + case 10: { + oPIC.MOVF(iDestinationBit, iRegisterFileAddress); + }break; + + case 11: { + oPIC.MOVWF(iRegisterFileAddress); + }break; + + case 12: { + oPIC.NOP(); + }break; + + case 13: { + oPIC.RLF(iDestinationBit, iRegisterFileAddress); + }break; + + case 14: { + oPIC.RRF(iDestinationBit, iRegisterFileAddress); + }break; + + case 15: { + oPIC.SUBWF(iDestinationBit, iRegisterFileAddress); + }break; + + case 16: { + oPIC.SWAPF(iDestinationBit, iRegisterFileAddress); + }break; + + case 17: { + oPIC.XORWF(iDestinationBit, iRegisterFileAddress); + }break; + + case 18: { + oPIC.BCF(iBitaddress, iRegisterFileAddress); + }break; + + case 19: { + oPIC.BSF(iBitaddress, iRegisterFileAddress); + }break; + + case 20: { + oPIC.BTFSC(iBitaddress, iRegisterFileAddress); + }break; + + case 21: { + oPIC.BTFSS(iBitaddress, iRegisterFileAddress); + }break; + + case 22: { + oPIC.ADDLW(iEightK); + }break; + + case 23: { + oPIC.ANDLW(iEightK); + }break; + + case 24: { + oPIC.CALL(iElevenK); + }break; + + case 25: { + //watchdogThread.setTime(0); + oPIC.CLRWDT(); + }break; + + case 26: { + oPIC.GOTO(iElevenK); + }break; + + case 27: { + oPIC.IORLW(iEightK); + }break; + + case 28: { + oPIC.MOVLW(iEightK); + }break; + + case 29: { + oPIC.RETFIE(); + }break; + + case 30: { + oPIC.RETLW(iEightK); + }break; + + case 31: { + oPIC.RETURN(); + }break; + + case 32: { + oPIC.SLEEP(); + }break; + + case 33: { + oPIC.SUBLW(iEightK); + }break; + + case 34: { + oPIC.XORLW(iEightK); + }break; + + case 35: { + /** + * To maintain upward compatibility + * with future PIC16CXX products, + * do not use this instruction. + */ + oPIC.OPTION(); + }break; + + case 36: { + /** + * To maintain upward compatibility + * with future PIC16CXX products, + * do not use this instruction. + */ + oPIC.TRIS(); + }break; + } + } } \ No newline at end of file diff --git a/src/Model/Microcontroller/PIC.java b/src/Model/Microcontroller/PIC.java index 7520f5c..437076a 100755 --- a/src/Model/Microcontroller/PIC.java +++ b/src/Model/Microcontroller/PIC.java @@ -17,7 +17,7 @@ public class PIC { private RAM Ram; private STACK Stack; private int WRegister; - private RUNTIMER Runtimer; + private TIME Runtimer; private ALU ArithmeticLogicUnit; private EEPROM Eeprom; private int iStateMachineWriteEeprom = 0; @@ -27,7 +27,7 @@ public class PIC { ProgramMemory = new PROGRAMMEMORY(); Ram = new RAM(); Stack = new STACK(); - Runtimer = new RUNTIMER(Ram); + Runtimer = new TIME(Ram); WRegister = 0; ArithmeticLogicUnit = new ALU(); Eeprom = new EEPROM(); @@ -36,7 +36,7 @@ public class PIC { public synchronized void resetPIC() { Ram = new RAM(); Stack = new STACK(); - Runtimer = new RUNTIMER(Ram); + Runtimer = new TIME(Ram); WRegister = 0; } @@ -86,7 +86,7 @@ public class PIC { return Stack; } - public synchronized RUNTIMER getRuntimer() { + public synchronized TIME getRuntimer() { return Runtimer; } diff --git a/src/Model/Microcontroller/PROGRAMMEMORY.java b/src/Model/Microcontroller/PROGRAMMEMORY.java index a1353fa..3c7d2e3 100644 --- a/src/Model/Microcontroller/PROGRAMMEMORY.java +++ b/src/Model/Microcontroller/PROGRAMMEMORY.java @@ -5,22 +5,22 @@ package Model.Microcontroller; */ /** - * Electrical Eraseable Programmable Read Only Memory of the PIC (Programmspeicher) + * ProgramMemory of the PIC (Programmspeicher) */ public class PROGRAMMEMORY { - private int[][] eeprom; - private int eepromLength = 1024; + private int[][] aiiProgramMemory; + private int iProgramMemoryLength = 1024; private int[] aiProgramLines; public PROGRAMMEMORY() { - eeprom = new int[eepromLength][2]; + aiiProgramMemory = new int[iProgramMemoryLength][2]; } public PROGRAMMEMORY(int iLength) { - eeprom = new int[iLength][2]; + aiiProgramMemory = new int[iLength][2]; } /** @@ -56,7 +56,7 @@ public class PROGRAMMEMORY public int getElement(int index) { int returnValue = -1; if (index >= 0 && index < 1024) { - returnValue = eeprom[index][0]; + returnValue = aiiProgramMemory[index][0]; } return returnValue; } @@ -69,16 +69,16 @@ public class PROGRAMMEMORY public int getIndex(int iIndex) { int returnValue = -1; if (iIndex >= 0 && iIndex < 1024) { - returnValue = eeprom[iIndex][1]; + returnValue = aiiProgramMemory[iIndex][1]; } return returnValue; } /** - * Returns length of EEPROM + * Returns length of ProgramMemory */ public int getLengthProgramMemory() { - return eepromLength; + return iProgramMemoryLength; } /** @@ -90,7 +90,7 @@ public class PROGRAMMEMORY public boolean setElementXToValueY(int index, int value) { boolean bSetWorked = false; if ((index >= 0) && (index < 1024)) { - eeprom[index][0] = value; + aiiProgramMemory[index][0] = value; bSetWorked = true; } return bSetWorked; @@ -105,7 +105,7 @@ public class PROGRAMMEMORY public boolean setElementXToIndexY(int iElement, int iIndex) { boolean bSetWorked = false; if ((iElement >= 0) && (iElement < 1024)) { - eeprom[iElement][1] = iIndex; + aiiProgramMemory[iElement][1] = iIndex; bSetWorked = true; } return bSetWorked; diff --git a/src/Model/Microcontroller/RUNTIMER.java b/src/Model/Microcontroller/TIME.java similarity index 98% rename from src/Model/Microcontroller/RUNTIMER.java rename to src/Model/Microcontroller/TIME.java index 1009afb..2c98da6 100644 --- a/src/Model/Microcontroller/RUNTIMER.java +++ b/src/Model/Microcontroller/TIME.java @@ -1,6 +1,6 @@ package Model.Microcontroller; -public class RUNTIMER { +public class TIME { private double dRuntime; private double dMaxWatchdog; private double dOldMaxWatchdog; @@ -11,7 +11,7 @@ public class RUNTIMER { private RAM oRam; - public RUNTIMER(RAM oRam) { + public TIME(RAM oRam) { dWatchdogTimer = dMaxWatchdog = dOldMaxWatchdog = 18000; this.oRam = oRam; } diff --git a/src/Model/MyModel.java b/src/Model/MyModel.java index 67ad768..a0c35c5 100644 --- a/src/Model/MyModel.java +++ b/src/Model/MyModel.java @@ -2,7 +2,7 @@ package Model; import java.util.concurrent.ConcurrentLinkedQueue; -import Model.Microcontroller.Bitmask; +import Model.Microcontroller.INSTRUCTIONDECODER; import Model.Microcontroller.PIC; public class MyModel extends Thread { @@ -137,9 +137,9 @@ public class MyModel extends Thread { } private void step() { - Bitmask oBitmask = new Bitmask(); + INSTRUCTIONDECODER oBitmask = new INSTRUCTIONDECODER(); //Makes one step through the eeprom. - oBitmask.bitMaskDecoderAndExecuteCommand(oPIC.getEeprom().getElement(oPIC.getRam().get_Programcounter()), oPIC); + oBitmask.decodeAndExecuteCommand(oPIC.getEeprom().getElement(oPIC.getRam().get_Programcounter()), oPIC); //Update view qDataToView.add(oPIC); }