| 1 | // File: sim.h |
| 2 | /* |
| 3 | Pep8-1 is a virtual machine for writing machine language and assembly |
| 4 | language programs. |
| 5 | |
| 6 | Copyright (C) 2009 J. Stanley Warford, Pepperdine University |
| 7 | |
| 8 | This program is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 3 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | */ |
| 21 | |
| 22 | #ifndef SIM_H |
| 23 | #define SIM_H |
| 24 | |
| 25 | #include <QVector> |
| 26 | #include "enu.h" |
| 27 | |
| 28 | class Sim |
| 29 | { |
| 30 | public: |
| 31 | // The machine |
| 32 | static QVector<int> Mem; |
| 33 | static bool nBit, zBit, vBit, cBit; |
| 34 | static int accumulator; |
| 35 | static int indexRegister; |
| 36 | static int stackPointer; |
| 37 | static int programCounter; |
| 38 | static int instructionSpecifier; |
| 39 | static int operandSpecifier; |
| 40 | static int operand; |
| 41 | static int operandDisplayFieldWidth; |
| 42 | |
| 43 | static QString inputBuffer; |
| 44 | static QString outputBuffer; |
| 45 | |
| 46 | static QSet<int> modifiedBytes; |
| 47 | static bool trapped; |
| 48 | static bool tracingTraps; |
| 49 | |
| 50 | static Enu::EExecState executionState; |
| 51 | // State for keeping track of what actions are possible for user and machine |
| 52 | |
| 53 | static int toSignedDecimal(int value); |
| 54 | // Pre: 0 <= value < 65536 |
| 55 | // Post: -32768 <= value < 32768 is returned |
| 56 | |
| 57 | static int fromSignedDecimal(int value); |
| 58 | // Pre: -32768 <= value < 32768 |
| 59 | // Post: 0 <= value < 65536 is returned |
| 60 | |
| 61 | static int nzvcToInt(); |
| 62 | // Post: NZVC is returned in postions <4..7> of the one-byte int |
| 63 | |
| 64 | static int add(int lhs, int rhs); |
| 65 | |
| 66 | static int addAndSetNZVC(int lhs, int rhs); |
| 67 | |
| 68 | static void loadMem(QList<int> objectCodeList); |
| 69 | |
| 70 | static int readByte(int memAddr); |
| 71 | static int readWord(int memAddr); |
| 72 | static int readByteOprnd(Enu::EAddrMode addrMode); |
| 73 | static int readWordOprnd(Enu::EAddrMode addrMode); |
| 74 | |
| 75 | static void writeByte(int memAddr, int value); |
| 76 | // Pre: 0 <= value < 256 |
| 77 | // Post: Value is stored in Mem[memAddr] |
| 78 | |
| 79 | static void writeWord(int memAddr, int value); |
| 80 | // Pre: 0 <= value < 65536 |
| 81 | // Post: The high-end byte of value is stored in Mem[memAddr] |
| 82 | // and the low-end byte of value is stored in Mem[memAddr + 1] |
| 83 | |
| 84 | static void writeByteOprnd(Enu::EAddrMode addrMode, int value); |
| 85 | static void writeWordOprnd(Enu::EAddrMode addrMode, int value); |
| 86 | |
| 87 | static int cellSize(Enu::ESymbolFormat symbolFormat); |
| 88 | // This is used exclusively in the memoryTracePane/memoryCellGraphicsItem |
| 89 | // I still disagree with where this is. It should be in the MemoryCellGraphicsItem |
| 90 | // because that is what it is used for. |
| 91 | |
| 92 | static bool vonNeumannStep(QString &errorString); |
| 93 | |
| 94 | }; |
| 95 | |
| 96 | #endif // SIM_H |