c++/rgb-assembler/rgb-assembler.cpp
changeset 20 b9ceffdcaf14
parent 19 17785b69430d
child 21 ae4a9092e1a8
     1.1 --- a/c++/rgb-assembler/rgb-assembler.cpp	Sat Dec 23 20:13:24 2017 +0100
     1.2 +++ b/c++/rgb-assembler/rgb-assembler.cpp	Sat Dec 23 23:24:51 2017 +0100
     1.3 @@ -3,18 +3,19 @@
     1.4  #include <wchar.h>
     1.5  #include <locale.h>
     1.6  #include <cstring>
     1.7 -
     1.8 +#include <unordered_map>
     1.9  #include <chrono>
    1.10  #include <thread>
    1.11  
    1.12  #include "types.h"
    1.13 +#include "memory.h"
    1.14 +#include "Command.h"
    1.15 +#include "commands/Goto.h"
    1.16  
    1.17  using namespace std;
    1.18  
    1.19  // TODO: strong typedefs http://www.boost.org/doc/libs/1_61_0/libs/serialization/doc/strong_typedef.html ?
    1.20  
    1.21 -const address_t MEMORY_SIZE = 1024;
    1.22 -
    1.23  /**
    1.24   * Skip to the given address.
    1.25   * parameter: address_t
    1.26 @@ -71,46 +72,6 @@
    1.27  
    1.28  // TODO: more commands, better numbers
    1.29  
    1.30 -template<typename T> T logMemoryError(const address_t &index) {
    1.31 -	wprintf(L"memory error: index = %d, sizeof(T) = %d, MEMORY_SIZE = %d\n", index, sizeof (T), MEMORY_SIZE);
    1.32 -	// TODO: return error value or throw exception
    1.33 -	return T();
    1.34 -}
    1.35 -
    1.36 -/**
    1.37 - * Reads data on given position in memory and increments the index (position).
    1.38 - * 
    1.39 - * @param memory array of bytes / octets
    1.40 - * @param index offset in same units as memory type
    1.41 - * @return value found at given position
    1.42 - */
    1.43 -template<typename T> T read(octet_t * memory, address_t &index) {
    1.44 -	// TODO: map higher memory to static hardcoded areas or peripherals
    1.45 -	if (index + sizeof (T) <= MEMORY_SIZE) {
    1.46 -		T * value = reinterpret_cast<T*> (memory + index);
    1.47 -		index += sizeof (T);
    1.48 -		return *value;
    1.49 -	} else {
    1.50 -		return logMemoryError<T>(index);
    1.51 -	}
    1.52 -}
    1.53 -
    1.54 -/**
    1.55 - * Writes data to given position in memory and increments the index (position).
    1.56 - * @param memory array of bytes / octets
    1.57 - * @param index offset in same units as memory type
    1.58 - * @param value value to be written at given position
    1.59 - */
    1.60 -template<typename T> T write(octet_t * memory, address_t &index, const T value) {
    1.61 -	if (index + sizeof (T) <= MEMORY_SIZE) {
    1.62 -		T * m = reinterpret_cast<T*> (memory + index);
    1.63 -		*m = value;
    1.64 -		index += sizeof (value);
    1.65 -	} else {
    1.66 -		return logMemoryError<T>(index);
    1.67 -	}
    1.68 -}
    1.69 -
    1.70  int main(int argc, char* argv[]) {
    1.71  
    1.72  	setlocale(LC_ALL, "");