rename memory.h to Memory.h
authorFrantišek Kučera <franta-hg@frantovo.cz>
Mon, 25 Dec 2017 00:34:27 +0100
changeset 3278c4d6b53499
parent 31 b997cbf9e30b
child 33 ff150572e8c0
rename memory.h to Memory.h
c++/rgb-assembler/Command.h
c++/rgb-assembler/Memory.h
c++/rgb-assembler/commands/End.h
c++/rgb-assembler/commands/IncrementDecrement.h
c++/rgb-assembler/memory.h
c++/rgb-assembler/nbproject/configurations.xml
c++/rgb-assembler/rgb-assembler.cpp
     1.1 --- a/c++/rgb-assembler/Command.h	Mon Dec 25 00:24:07 2017 +0100
     1.2 +++ b/c++/rgb-assembler/Command.h	Mon Dec 25 00:34:27 2017 +0100
     1.3 @@ -19,7 +19,7 @@
     1.4  #pragma once
     1.5  
     1.6  #include "types.h"
     1.7 -#include "memory.h"
     1.8 +#include "Memory.h"
     1.9  
    1.10  class Command {
    1.11  public:
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/c++/rgb-assembler/Memory.h	Mon Dec 25 00:34:27 2017 +0100
     2.3 @@ -0,0 +1,106 @@
     2.4 +/**
     2.5 + * RGB assembler
     2.6 + * Copyright © 2017 František Kučera (frantovo.cz)
     2.7 + *
     2.8 + * This program is free software: you can redistribute it and/or modify
     2.9 + * it under the terms of the GNU General Public License as published by
    2.10 + * the Free Software Foundation, either version 3 of the License, or
    2.11 + * (at your option) any later version.
    2.12 + *
    2.13 + * This program is distributed in the hope that it will be useful,
    2.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    2.16 + * GNU General Public License for more details.
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License
    2.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
    2.20 + */
    2.21 +
    2.22 +#pragma once
    2.23 +
    2.24 +#include "types.h"
    2.25 +
    2.26 +const address_t MEMORY_SIZE = 1024;
    2.27 +
    2.28 +class Memory {
    2.29 +private:
    2.30 +
    2.31 +	template<typename T> T logMemoryError(const address_t &index) {
    2.32 +		wprintf(L"memory error: index = %d, sizeof(T) = %d, MEMORY_SIZE = %d\n", index, sizeof (T), MEMORY_SIZE);
    2.33 +		// TODO: return error value or throw exception
    2.34 +		return T();
    2.35 +	}
    2.36 +	octet_t * memory;
    2.37 +	address_t index;
    2.38 +
    2.39 +public:
    2.40 +
    2.41 +	Memory() {
    2.42 +		memory = (octet_t*) malloc(MEMORY_SIZE);
    2.43 +		index = 0;
    2.44 +	}
    2.45 +
    2.46 +	virtual ~Memory() {
    2.47 +		free(memory);
    2.48 +		memory = nullptr;
    2.49 +	}
    2.50 +
    2.51 +	/**
    2.52 +	 * Reads data on given position in memory and increments the index (position).
    2.53 +	 * @return value found at current position
    2.54 +	 */
    2.55 +	template<typename T> T read() {
    2.56 +		// TODO: map higher memory to static hardcoded areas or peripherals
    2.57 +		if (index + sizeof (T) <= MEMORY_SIZE) {
    2.58 +			T * value = reinterpret_cast<T*> (memory + index);
    2.59 +			index += sizeof (T);
    2.60 +			return *value;
    2.61 +		} else {
    2.62 +			return logMemoryError<T>(index);
    2.63 +		}
    2.64 +	}
    2.65 +
    2.66 +	/**
    2.67 +	 * Writes data to current position in memory and increments the index (position).
    2.68 +	 * @param value value to be written at given position
    2.69 +	 */
    2.70 +	template<typename T> T write(const T value) {
    2.71 +		if (index + sizeof (T) <= MEMORY_SIZE) {
    2.72 +			T * m = reinterpret_cast<T*> (memory + index);
    2.73 +			*m = value;
    2.74 +			index += sizeof (value);
    2.75 +		} else {
    2.76 +			return logMemoryError<T>(index);
    2.77 +		}
    2.78 +	}
    2.79 +
    2.80 +	void setIndex(address_t &index) {
    2.81 +		this->index = index;
    2.82 +	}
    2.83 +
    2.84 +	address_t getIndex() {
    2.85 +		return index;
    2.86 +	}
    2.87 +
    2.88 +	/**
    2.89 +	 * FIXME: rename
    2.90 +	 * @return 
    2.91 +	 */
    2.92 +	bool isInside() {
    2.93 +		return index < MEMORY_SIZE;
    2.94 +	}
    2.95 +	
    2.96 +	/**
    2.97 +	 * FIXME: rename, refactor
    2.98 +	 */
    2.99 +	void start() {
   2.100 +		index = 0;
   2.101 +	}
   2.102 +
   2.103 +	/**
   2.104 +	 * FIXME: rename, refactor
   2.105 +	 */
   2.106 +	void finish() {
   2.107 +		index = MEMORY_SIZE;
   2.108 +	}
   2.109 +};
     3.1 --- a/c++/rgb-assembler/commands/End.h	Mon Dec 25 00:24:07 2017 +0100
     3.2 +++ b/c++/rgb-assembler/commands/End.h	Mon Dec 25 00:34:27 2017 +0100
     3.3 @@ -23,7 +23,7 @@
     3.4  #include <thread>
     3.5  
     3.6  #include "../Command.h"
     3.7 -#include "../memory.h"
     3.8 +#include "../Memory.h"
     3.9  
    3.10  using namespace std;
    3.11  
     4.1 --- a/c++/rgb-assembler/commands/IncrementDecrement.h	Mon Dec 25 00:24:07 2017 +0100
     4.2 +++ b/c++/rgb-assembler/commands/IncrementDecrement.h	Mon Dec 25 00:34:27 2017 +0100
     4.3 @@ -23,7 +23,7 @@
     4.4  #include <thread>
     4.5  
     4.6  #include "../Command.h"
     4.7 -#include "../memory.h"
     4.8 +#include "../Memory.h"
     4.9  
    4.10  using namespace std;
    4.11  
     5.1 --- a/c++/rgb-assembler/memory.h	Mon Dec 25 00:24:07 2017 +0100
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,106 +0,0 @@
     5.4 -/**
     5.5 - * RGB assembler
     5.6 - * Copyright © 2017 František Kučera (frantovo.cz)
     5.7 - *
     5.8 - * This program is free software: you can redistribute it and/or modify
     5.9 - * it under the terms of the GNU General Public License as published by
    5.10 - * the Free Software Foundation, either version 3 of the License, or
    5.11 - * (at your option) any later version.
    5.12 - *
    5.13 - * This program is distributed in the hope that it will be useful,
    5.14 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.15 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    5.16 - * GNU General Public License for more details.
    5.17 - *
    5.18 - * You should have received a copy of the GNU General Public License
    5.19 - * along with this program. If not, see <http://www.gnu.org/licenses/>.
    5.20 - */
    5.21 -
    5.22 -#pragma once
    5.23 -
    5.24 -#include "types.h"
    5.25 -
    5.26 -const address_t MEMORY_SIZE = 1024;
    5.27 -
    5.28 -class Memory {
    5.29 -private:
    5.30 -
    5.31 -	template<typename T> T logMemoryError(const address_t &index) {
    5.32 -		wprintf(L"memory error: index = %d, sizeof(T) = %d, MEMORY_SIZE = %d\n", index, sizeof (T), MEMORY_SIZE);
    5.33 -		// TODO: return error value or throw exception
    5.34 -		return T();
    5.35 -	}
    5.36 -	octet_t * memory;
    5.37 -	address_t index;
    5.38 -
    5.39 -public:
    5.40 -
    5.41 -	Memory() {
    5.42 -		memory = (octet_t*) malloc(MEMORY_SIZE);
    5.43 -		index = 0;
    5.44 -	}
    5.45 -
    5.46 -	virtual ~Memory() {
    5.47 -		free(memory);
    5.48 -		memory = nullptr;
    5.49 -	}
    5.50 -
    5.51 -	/**
    5.52 -	 * Reads data on given position in memory and increments the index (position).
    5.53 -	 * @return value found at current position
    5.54 -	 */
    5.55 -	template<typename T> T read() {
    5.56 -		// TODO: map higher memory to static hardcoded areas or peripherals
    5.57 -		if (index + sizeof (T) <= MEMORY_SIZE) {
    5.58 -			T * value = reinterpret_cast<T*> (memory + index);
    5.59 -			index += sizeof (T);
    5.60 -			return *value;
    5.61 -		} else {
    5.62 -			return logMemoryError<T>(index);
    5.63 -		}
    5.64 -	}
    5.65 -
    5.66 -	/**
    5.67 -	 * Writes data to current position in memory and increments the index (position).
    5.68 -	 * @param value value to be written at given position
    5.69 -	 */
    5.70 -	template<typename T> T write(const T value) {
    5.71 -		if (index + sizeof (T) <= MEMORY_SIZE) {
    5.72 -			T * m = reinterpret_cast<T*> (memory + index);
    5.73 -			*m = value;
    5.74 -			index += sizeof (value);
    5.75 -		} else {
    5.76 -			return logMemoryError<T>(index);
    5.77 -		}
    5.78 -	}
    5.79 -
    5.80 -	void setIndex(address_t &index) {
    5.81 -		this->index = index;
    5.82 -	}
    5.83 -
    5.84 -	address_t getIndex() {
    5.85 -		return index;
    5.86 -	}
    5.87 -
    5.88 -	/**
    5.89 -	 * FIXME: rename
    5.90 -	 * @return 
    5.91 -	 */
    5.92 -	bool isInside() {
    5.93 -		return index < MEMORY_SIZE;
    5.94 -	}
    5.95 -	
    5.96 -	/**
    5.97 -	 * FIXME: rename, refactor
    5.98 -	 */
    5.99 -	void start() {
   5.100 -		index = 0;
   5.101 -	}
   5.102 -
   5.103 -	/**
   5.104 -	 * FIXME: rename, refactor
   5.105 -	 */
   5.106 -	void finish() {
   5.107 -		index = MEMORY_SIZE;
   5.108 -	}
   5.109 -};
     6.1 --- a/c++/rgb-assembler/nbproject/configurations.xml	Mon Dec 25 00:24:07 2017 +0100
     6.2 +++ b/c++/rgb-assembler/nbproject/configurations.xml	Mon Dec 25 00:34:27 2017 +0100
     6.3 @@ -12,7 +12,7 @@
     6.4        <itemPath>commands/IncrementDecrement.h</itemPath>
     6.5        <itemPath>commands/Sleep.h</itemPath>
     6.6        <itemPath>commands.h</itemPath>
     6.7 -      <itemPath>memory.h</itemPath>
     6.8 +      <itemPath>Memory.h</itemPath>
     6.9        <itemPath>types.h</itemPath>
    6.10      </logicalFolder>
    6.11      <logicalFolder name="ResourceFiles"
    6.12 @@ -66,7 +66,7 @@
    6.13        </item>
    6.14        <item path="commands/Sleep.h" ex="false" tool="3" flavor2="0">
    6.15        </item>
    6.16 -      <item path="memory.h" ex="false" tool="3" flavor2="0">
    6.17 +      <item path="Memory.h" ex="false" tool="3" flavor2="0">
    6.18        </item>
    6.19        <item path="rgb-assembler.cpp" ex="false" tool="1" flavor2="0">
    6.20        </item>
    6.21 @@ -110,7 +110,7 @@
    6.22        </item>
    6.23        <item path="commands/Sleep.h" ex="false" tool="3" flavor2="0">
    6.24        </item>
    6.25 -      <item path="memory.h" ex="false" tool="3" flavor2="0">
    6.26 +      <item path="Memory.h" ex="false" tool="3" flavor2="0">
    6.27        </item>
    6.28        <item path="rgb-assembler.cpp" ex="false" tool="1" flavor2="0">
    6.29        </item>
     7.1 --- a/c++/rgb-assembler/rgb-assembler.cpp	Mon Dec 25 00:24:07 2017 +0100
     7.2 +++ b/c++/rgb-assembler/rgb-assembler.cpp	Mon Dec 25 00:34:27 2017 +0100
     7.3 @@ -24,7 +24,7 @@
     7.4  #include <unordered_map>
     7.5  
     7.6  #include "types.h"
     7.7 -#include "memory.h"
     7.8 +#include "Memory.h"
     7.9  #include "Command.h"
    7.10  #include "commands.h"
    7.11  #include "commands/Goto.h"