This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
user:jr018429:portfolio:cpumemory [2011/05/18 23:20] – jr018429 | user:jr018429:portfolio:cpumemory [2011/05/18 23:48] (current) – jr018429 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== CPUMEM ====== | ||
+ | class library is included before the main function like this:\\ | ||
+ | < | ||
+ | #include " | ||
+ | </ | ||
+ | \\ | ||
+ | CPUMEM:: | ||
+ | An object of the type CPUMEM is instatiated like this:\\ | ||
+ | \\ | ||
+ | < | ||
+ | // | ||
+ | CPUMEM cpumemory; | ||
+ | </ | ||
+ | \\ | ||
+ | CPUMEM:: | ||
+ | \\ | ||
+ | unsigned char& CPUMEM:: | ||
+ | \\ | ||
+ | unsigned char CPUMEM:: | ||
+ | The **read** member function is used like this:\\ | ||
+ | < | ||
+ | //reads 8-bit data from last memory address, 0xffff, or 65535 | ||
+ | unsigned char value = cpumemory.read(0xffff); | ||
+ | </ | ||
+ | \\ | ||
+ | void CPUMEM:: | ||
+ | The **write** member function is used like this:\\ | ||
+ | < | ||
+ | //writes the value 0xff, or 255, to the last memory address 0xffff, or 65535 | ||
+ | cpumemory.write(0xffff, | ||
+ | </ | ||
+ | \\ | ||
+ | **cpumem.h**\\ | ||
+ | < | ||
+ | #ifndef _CPUMEM_H | ||
+ | #define _CPUMEM_H | ||
+ | class CPUMEM | ||
+ | { | ||
+ | public: | ||
+ | CPUMEM(); | ||
+ | unsigned char& operator[](unsigned short int address); | ||
+ | unsigned char read(unsigned short int address); | ||
+ | void write(unsigned short int address, unsigned char value); | ||
+ | ~CPUMEM(); | ||
+ | private: | ||
+ | //unsigned short int memlngth; | ||
+ | unsigned char *memadd; | ||
+ | }; | ||
+ | #endif | ||
+ | </ | ||
+ | \\ | ||
+ | **cpumem.cc**\\ | ||
+ | < | ||
+ | #include " | ||
+ | |||
+ | CPUMEM:: | ||
+ | { | ||
+ | memadd = new unsigned char[65536]; | ||
+ | } | ||
+ | |||
+ | CPUMEM:: | ||
+ | { | ||
+ | delete[] memadd; | ||
+ | } | ||
+ | |||
+ | unsigned char& CPUMEM:: | ||
+ | { | ||
+ | return memadd[address]; | ||
+ | } | ||
+ | |||
+ | unsigned char CPUMEM:: | ||
+ | { | ||
+ | return *(memadd + address); | ||
+ | } | ||
+ | |||
+ | void CPUMEM:: | ||
+ | { | ||
+ | *(memadd + address) = value; | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | **memtest.cc**\\ | ||
+ | < | ||
+ | #include < | ||
+ | #include " | ||
+ | const int MEM_MAX = 65535; | ||
+ | int main() | ||
+ | { | ||
+ | CPUMEM datamemory; | ||
+ | for (int temp = 0x00; temp <= MEM_MAX; temp++) datamemory.write(temp, | ||
+ | for(int temp = 0x00; temp <= MEM_MAX; temp++) printf(" | ||
+ | return(0); | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | **Makefile**\\ | ||
+ | < | ||
+ | CXX = g++ $(CXXFLAGS) $(INC) $(LIBS) | ||
+ | AR = ar | ||
+ | CXXFLAGS = -Wall | ||
+ | INC = -I ../ | ||
+ | LIBS = | ||
+ | SRC = cpumem.cc memtest.cc | ||
+ | OBJ = $(SRC: | ||
+ | BIN = memtest | ||
+ | all: $(SRC) $(BIN) | ||
+ | |||
+ | debug: CXX += -DDEBUG -g | ||
+ | debug: DEBUG = debug | ||
+ | debug: $(SRC) $(BIN) | ||
+ | |||
+ | $(BIN): $(OBJ) | ||
+ | ifneq ($(MAKECMDGOALS), | ||
+ | @printf " | ||
+ | @$(CXX) -o $(BIN) $(OBJ) && echo " | ||
+ | else | ||
+ | $(CXX) -o $(BIN) $(OBJ) | ||
+ | endif | ||
+ | |||
+ | .cc.o: | ||
+ | ifneq ($(MAKECMDGOALS), | ||
+ | @printf " | ||
+ | @$(CXX) -c $< && echo " | ||
+ | else | ||
+ | $(CXX) -c $< | ||
+ | endif | ||
+ | |||
+ | clean: | ||
+ | rm -f *.o $(BIN) core | ||
+ | |||
+ | default: $(BIN) | ||
+ | </ |