CPUMEM

class library is included before the main function like this:

#include "cpumem.h"


CPUMEM::CPUMEM() is the constructor and automatically creates memory of the correct size, 64k (65536 elements, 0-65535), and type 1 byte (8-bits) for the 8085. The constructor is called automatically as the object is being instantiated.
An object of the type CPUMEM is instatiated like this:

//Instantiates an object of type CPUMEM
CPUMEM cpumemory;


CPUMEM::~CPUMEM() is the destructor and automatically deallocates the memory which was created when an object of type CPUMEM when an object of this type goes out of scope.

unsigned char& CPUMEM::operator[](unsigned short int address) is a depricated member function. It uses overloaded operators to make the code that calls this method look like an array. Do NOT use it.

unsigned char CPUMEM::read(unsigned short int address) is the member function that is used to read the 8-bit (unsigned char) value at a specific address.
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::write(unsigned short int address, unsigned char value) is the member function that is used to write an 8-bit value to a specific address.
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, 0xff);


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.h"

CPUMEM::CPUMEM()
{
        memadd = new unsigned char[65536];
}

CPUMEM::~CPUMEM()
{
        delete[] memadd;
}

unsigned char& CPUMEM::operator[](unsigned short int address)
{
        return memadd[address];
}

unsigned char CPUMEM::read(unsigned short int address)
{
        return *(memadd + address);
}

void CPUMEM::write(unsigned short int address, unsigned char value)
{
        *(memadd + address) = value;
}


memtest.cc

#include <cstdio>
#include "cpumem.h"
const int MEM_MAX = 65535;
int main()
{
        CPUMEM datamemory;
        for (int temp = 0x00; temp <= MEM_MAX; temp++) datamemory.write(temp, 255);
        for(int temp = 0x00; temp <= MEM_MAX; temp++) printf("Memory address %x contains the value %x\n", temp, datamemory.read(temp));
        return(0);
}


Makefile

CXX = g++ $(CXXFLAGS) $(INC) $(LIBS)
AR = ar
CXXFLAGS = -Wall
INC = -I ../../include/
LIBS =
SRC = cpumem.cc memtest.cc
OBJ = $(SRC:.cc=.o)
BIN = memtest
all: $(SRC) $(BIN)

debug: CXX += -DDEBUG -g
debug: DEBUG = debug
debug: $(SRC) $(BIN)

$(BIN): $(OBJ)
ifneq ($(MAKECMDGOALS),debug)
        @printf "[CC]  %-20s ... " "$(BIN)"
        @$(CXX) -o $(BIN) $(OBJ) && echo "SUCCESS" || echo "FAIL"
else
        $(CXX) -o $(BIN) $(OBJ)
endif

.cc.o:
ifneq ($(MAKECMDGOALS),debug)
        @printf "[B]   %-20s ... " "$<"
        @$(CXX) -c $< && echo "OK" || echo "FAIL"
else
        $(CXX) -c $<
endif

clean:
        rm -f *.o $(BIN) core

default: $(BIN)