Added missing files
This commit is contained in:
parent
6ffeb46732
commit
0c40609b50
2 changed files with 93 additions and 0 deletions
54
EventHandler.h
Normal file
54
EventHandler.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
#include "stdafx.h"
|
||||
|
||||
template<typename TypeA, typename TypeB>
|
||||
class Tuple
|
||||
{
|
||||
public:
|
||||
TypeA A;
|
||||
TypeB B;
|
||||
Tuple(TypeA A, TypeB B) : A(A), B(B) { }
|
||||
};
|
||||
|
||||
template<typename ObjectType, typename... Types>
|
||||
class EventHandler
|
||||
{
|
||||
typedef void(ObjectType::*Func)(Types...);
|
||||
typedef Tuple<Func, ObjectType*> Handler;
|
||||
|
||||
private:
|
||||
std::list<Handler*> _handlerList;
|
||||
Handler *_singleHandler = nullptr;
|
||||
uint16_t _handlerCount = 0;
|
||||
|
||||
public:
|
||||
void RegisterHandler(ObjectType *instance, Func handler) {
|
||||
this->_handlerList.push_back(new Handler(handler, instance));
|
||||
_singleHandler = this->_handlerList.size() == 1 ? this->_handlerList.front() : nullptr;
|
||||
_handlerCount++;
|
||||
}
|
||||
|
||||
void CallHandler(Handler handler, Types... types) {
|
||||
Func callback = handler.A;
|
||||
ObjectType *instance = handler.B;
|
||||
(instance->*callback)(types...);
|
||||
}
|
||||
|
||||
void operator+=(Func handler) {
|
||||
this->RegisterHandler(handler);
|
||||
}
|
||||
|
||||
void operator()(Types... types) {
|
||||
if(_handlerCount > 0 && _singleHandler != nullptr) {
|
||||
Func callback = _singleHandler->A;
|
||||
ObjectType *instance = _singleHandler->B;
|
||||
(instance->*callback)(types...);
|
||||
} /*else {
|
||||
for(Handler handler : this->_handlerList) {
|
||||
Func callback = handler.A;
|
||||
ObjectType *instance = handler.B;
|
||||
(instance->*callback)(types...);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
};
|
39
Memory.h
Normal file
39
Memory.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include "stdafx.h"
|
||||
#include "EventHandler.h"
|
||||
|
||||
class IMemoryHandler
|
||||
{
|
||||
public:
|
||||
virtual void MemoryRead(uint16_t aa) = 0;
|
||||
virtual void MemoryWrite(uint16_t aa) = 0;
|
||||
};
|
||||
|
||||
class MemoryManager
|
||||
{
|
||||
private:
|
||||
EventHandler<IMemoryHandler, uint16_t> _readHandler;
|
||||
EventHandler<IMemoryHandler, uint16_t> _writeHandler;
|
||||
uint8_t *_memory = nullptr;
|
||||
|
||||
public:
|
||||
MemoryManager(uint8_t *memory) : _memory(memory) { }
|
||||
EventHandler<IMemoryHandler, uint16_t> *OnMemoryRead() { return &_readHandler; }
|
||||
EventHandler<IMemoryHandler, uint16_t> *OnMemoryWrite() { return &_writeHandler; }
|
||||
|
||||
uint8_t Read(uint16_t addr) {
|
||||
//_readHandler(addr);
|
||||
return _memory[addr];
|
||||
}
|
||||
|
||||
uint16_t ReadWord(uint16_t addr) {
|
||||
uint8_t lo = Read(addr);
|
||||
uint8_t hi = Read(addr+1);
|
||||
return lo | hi << 8;
|
||||
}
|
||||
|
||||
void Write(uint16_t addr, uint8_t value) {
|
||||
//_writeHandler(addr);
|
||||
_memory[addr] = value;
|
||||
}
|
||||
};
|
||||
|
Loading…
Add table
Reference in a new issue