-
Notifications
You must be signed in to change notification settings - Fork 12
/
argument.h
117 lines (103 loc) · 3.41 KB
/
argument.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// File: argument.h
/*
Pep9 is a virtual machine for writing machine language and assembly
language programs.
Copyright (C) 2009 J. Stanley Warford, Pepperdine University
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ARGUMENT_H
#define ARGUMENT_H
#include "asm.h"
#include "pep.h"
#include "sim.h"
// Abstract Argument class
class Argument
{
friend class Asm;
public:
virtual ~Argument() { }
virtual int getArgumentValue() = 0;
virtual QString getArgumentString() = 0;
};
// Concrete argument classes
// All methods are defined in this argument.h file.
class CharArgument: public Argument
{
friend class Asm;
private:
QString charValue;
public:
CharArgument(QString cValue) { charValue = cValue; }
int getArgumentValue() { return Asm::charStringToInt(charValue); }
QString getArgumentString() { return charValue; }
};
class DecArgument: public Argument
{
private:
int decValue;
public:
DecArgument(int dValue) { decValue = dValue; }
int getArgumentValue() { return decValue; }
QString getArgumentString() {
int temp = decValue >= 32768 ? decValue - 65536 : decValue;
return QString("%1").arg(temp);
}
};
class UnsignedDecArgument: public Argument
{
private:
int decValue;
public:
UnsignedDecArgument(int dValue) { decValue = dValue; }
int getArgumentValue() { return decValue; }
QString getArgumentString() {
return QString("%1").arg(decValue);
}
};
class HexArgument: public Argument
{
private:
int hexValue;
public:
HexArgument(int hValue) { hexValue = hValue; }
int getArgumentValue() { return hexValue; }
QString getArgumentString() { return "0x" + QString("%1").arg(hexValue, 4, 16, QLatin1Char('0')).toUpper(); }
};
class StringArgument: public Argument
{
private:
QString stringValue;
public:
StringArgument(QString sValue) { stringValue = sValue; }
int getArgumentValue() { return Asm::string2ArgumentToInt(stringValue); }
QString getArgumentString() { return stringValue; }
};
class SymbolRefArgument: public Argument
{
private:
QString symbolRefValue;
public:
SymbolRefArgument(QString sRefValue) { symbolRefValue = sRefValue; }
int getArgumentValue() {
if (symbolRefValue == "charIn") {
return Pep::symbolTable.contains("charIn") ? Pep::symbolTable.value(symbolRefValue) : 256 * Sim::Mem[Pep::dotBurnArgument - 7] + Sim::Mem[Pep::dotBurnArgument - 6];
}
else if (symbolRefValue == "charOut") {
return Pep::symbolTable.contains("charOut") ? Pep::symbolTable.value(symbolRefValue) : 256 * Sim::Mem[Pep::dotBurnArgument - 5] + Sim::Mem[Pep::dotBurnArgument - 4];
}
else {
return Pep::symbolTable.value(symbolRefValue);
}
}
QString getArgumentString() { return symbolRefValue; }
};
#endif // ARGUMENT_H