-include $(sources:.cpp=.d)
.PHONY: libs
libs:
-# $(MAKE) -C instr all
+ $(MAKE) -C instr all
$(sources:.cpp=.o):
$(CC) $(CPPFLAGS) -c -o ${@} ${@:.o=.cpp}
.PHONY:clean
clean:
rm -rf $(PROG) $(sources:.cpp=.o) $(sources:.cpp=.d)
-# $(MAKE) -C instr clean
+ $(MAKE) -C instr clean
.PHONY: run
run: $(PROG)
void CCpu::updateFlags(CDat val) {
this->m_Z = (val == 0);
this->m_S = ((val >> (BIT_LEN-1)) & 0x1);
- this->m_C = false;
- this->m_O = false;
+/* this->m_C = false;
+ this->m_O = false; */
}
void CCpu::updateFlags(CDatd val, CDat a, CDat b) {
CDat CCpu::getRegister(const int addr) const
{
- return m_reg.get(addr);
+ return m_reg.getDirect(addr);
}
void CCpu::setRegister(const int addr, CDat data)
{
- m_reg.set(addr, data);
+ m_reg.setDirect(addr, data);
}
CDat CCpu::getRAM(const int addr) const
void setNextPC(CDat);
CDat getFlags() const;
+ /* will only change zero and sign */
void updateFlags(CDat);
+ /* will change all flags */
void updateFlags(CDatd, CDat, CDat);
+ /* will change all flags */
void updateFlags(bool z, bool o, bool c, bool s);
typedef __UINT32_TYPE__ CDat;
typedef __UINT64_TYPE__ CDatd;
-#define BIT_LEN 32
-static_assert(sizeof(CDat) == 4, "The size of the datatype for int is NOT 4 bytes (32 Bit!)");
-static_assert(sizeof(CDatd) > 4, "The size of the datatype for double int is NOT bigger than 4 bytes (32 Bit!)");
+#define BYTE_COUNT 4
+
+#define BIT_LEN (BYTE_COUNT * 8)
+static_assert(sizeof(CDat) == BYTE_COUNT, "The size of the datatype for int is NOT 4 bytes (32 Bit!)");
+static_assert(sizeof(CDatd) > BYTE_COUNT, "The size of the datatype for double int is NOT bigger than 4 bytes (32 Bit!)");
#endif
throw out_of_range(error.str());
}
- MEMORY_ADDRESS temp = address;
+ MEMORY_ADDRESS temp = (address & (~(BYTE_COUNT-1))) / BYTE_COUNT;
auto iter = m_memory.begin();
while(temp > 0) {
++iter;
template <typename T>
T CMem<T>::get(const MEMORY_ADDRESS address) const
+{
+ if(address >= MAX_MEMORY) {
+ stringstream error;
+ error << "memoryaddress " << address << " out of range";
+ throw out_of_range(error.str());
+ }
+ MEMORY_ADDRESS temp = (address & (~(BYTE_COUNT-1))) / BYTE_COUNT;
+ return m_memory[temp];
+}
+
+template <typename T>
+void CMem<T>::setDirect(const MEMORY_ADDRESS address, const T data)
+{
+ if(address >= MAX_MEMORY) {
+ stringstream error;
+ error << "memoryaddress " << address << " out of range";
+ throw out_of_range(error.str());
+ }
+
+ MEMORY_ADDRESS temp = address;
+ auto iter = m_memory.begin();
+ while(temp > 0) {
+ ++iter;
+ temp--;
+ }
+
+ iter = m_memory.insert(iter, data);
+ ++iter;
+ m_memory.erase(iter);
+}
+
+template <typename T>
+T CMem<T>::getDirect(const MEMORY_ADDRESS address) const
{
if(address >= MAX_MEMORY) {
stringstream error;
const int MAX_MEMORY;
std::vector<T> m_memory;
public:
+ /* aligns to BIT_LEN words, aka. does calc direct memorycell from address */
void set(const MEMORY_ADDRESS address, const T data);
T get(const MEMORY_ADDRESS address) const;
+
+ /* doesn't align, user has to do */
+ void setDirect(const MEMORY_ADDRESS address, const T data);
+ T getDirect(const MEMORY_ADDRESS address) const;
CMem(int size) : MAX_MEMORY(size), m_memory(size) {};
};
throw out_of_range(error.str());
}
- MEMORY_ADDRESS temp = address;
+ MEMORY_ADDRESS temp = (address & (~(BYTE_COUNT-1))) / BYTE_COUNT;
auto iter = m_memory.begin();
while(temp > 0) {
++iter;
error << "memoryaddress " << address << " out of range";
throw out_of_range(error.str());
}
- return m_memory[address];
+ MEMORY_ADDRESS temp = (address & (~(BYTE_COUNT-1))) / BYTE_COUNT;
+ return m_memory[temp];
}
template <typename T>
class CPMem
{
private:
- //MAX_MEMORY-1 zugreifbare Speicherzellen
+ //MAX_MEMORY-1 zugreifbare Speicherzellen aus BYTE_COUNT Bytes
+ //adressierung erfolgt aber byteweise
const int MAX_MEMORY;
std::vector<T> m_memory;
public:
void set(const MEMORY_ADDRESS address, const T data);
//retuniert referenz eines cdat objekts mit dem Wert von address
T get(const MEMORY_ADDRESS address) const;
+ T getByte(const MEMORY_ADDRESS address) const;
CPMem(int size) : MAX_MEMORY(size), m_memory(size, NULL) {};
~CPMem();
};
CDat stackd = global_cpu->getRAM(stackp);
cout << "Stack pointer: " << stackp << " @stackpointer: " << stackd << endl;
cout << "PSW: 0x" << std::hex << setw(8) << setfill('0') << global_cpu->getFlags() << std::dec << endl;
+ cout << "cur PC: 0x" << std::hex << setw(8) << setfill('0') << global_cpu->getCurPC() << " next PC: 0x" << setw(8) << setfill('0') << global_cpu->getNextPC() << std::dec << endl;
}
case 2:
case 3:
cerr << "ignoring labels and comments for now" << endl;
+ break;
default:
cerr << "i was to lazy to implement the other format types for now" << endl;
}
Completers.push_back(CompleterElement("quit", &doExit, "Exits program"));
Completers.push_back(CompleterElement("exit", &doExit, "Exits program"));
Completers.push_back(CompleterElement("step [count]",&execStep, "Runs [count] ticks. if count is not given one tick is executed."));
- Completers.push_back(CompleterElement("dre [s] [e]",&printReg, "Prints registers. if s is given, only register s is printed. if s and e are given the registers from s to e are printed. if omitted all registers a printed."));
- Completers.push_back(CompleterElement("dra [s] [e]",&printRAM, "Prints RAM. if s is given, only RAM-Addr. s is printed. if s and e are given the RAM-Addrs from s to e are printed. if omitted the first 16 RAM-Addrs are printed."));
- Completers.push_back(CompleterElement("dpr [s] [e]",&printPROG, "Prints program. if s is given, only Prog-Addr. s is printed. if s and e are given the Prog-Addrs from s to e are printed. if omitted the first 16 Prog-Addrs are printed."));
+ Completers.push_back(CompleterElement("dreg [s] [e]",&printReg, "Prints registers. if s is given, only register s is printed. if s and e are given the registers from s to e are printed. if omitted all registers a printed."));
+ Completers.push_back(CompleterElement("ddata [s] [e]",&printRAM, "Prints RAM. if s is given, only RAM-Addr. s is printed. if s and e are given the RAM-Addrs from s to e are printed. if omitted the first 16 RAM-Addrs are printed."));
+ Completers.push_back(CompleterElement("dprog [s] [e]",&printPROG, "Prints program. if s is given, only Prog-Addr. s is printed. if s and e are given the Prog-Addrs from s to e are printed. if omitted the first 16 Prog-Addrs are printed."));
Completers.push_back(CompleterElement("break addr",&setBreak, "Sets a breakpoint for address addr."));
Completers.push_back(CompleterElement("run",&execRun, "Runs till next breakpoint or end of program."));
Completers.push_back(CompleterElement("setpc [num]",&setPC, "Sets PC to num. if num is omitted 0 is used."));
std::string name;
short m_ra, m_rb, m_rd;
bool m_c, m_d, m_hl, m_f, m_s;
- int m_imm;
+ CDat m_imm;
short m_cond;
boost::dynamic_bitset<> argbits;
Iinstr() : opcode(0), name(""), m_ra(0), m_rb(0), m_rd(0), m_c(0), m_d(0), m_hl(0), m_f(0), m_s(0), m_imm(0), m_cond(ALWAYS), argbits(32) {}
- int generate16ImmFill(const int value) const {
- int i = value;
+ CDat generate16ImmFill(const CDat value) const {
+ CDat i = value;
if(m_hl == true && m_f == true) {
i <<= 16;
i |= 0x0000FFFF;
return i;
}
- int generate16ImmSign(const int value) const {
- int i = value;
+ CDat generate16ImmSign(const CDat value) const {
+ CDat i = value;
if(m_hl == true) {
i <<= 16;
}
return i;
}
- int generate12ImmSign(const int value) const {
- int i = value;
+ CDat generate12ImmSign(const CDat value) const {
+ CDat i = value;
if(m_s == true && (i & 0x0800) != 0) {
i |= 0xFFFFF000;
}
return i;
}
- int generate15ImmSign(const int value) const {
- int i = value;
+ CDat generate15ImmSign(const CDat value) const {
+ CDat i = value;
if(m_s == true && (i & 0x4000) != 0) {
i |= 0xFFFF8000;
}
$(MAKE) -C instr clean
.PHONY: run
-run: $(PROG)
+run: all
./$(PROG) sum.dthex
%.d: %.cpp