Public Access
30 lines
509 B
C++
30 lines
509 B
C++
// In-memory EEPROM for the native tests (starts erased, all 0xFF like a new chip)
|
|||
|
|
#pragma once
|
||
|
|
|
||
|
|
#include <cstdint>
|
||
|
|
#include <cstring>
|
||
|
|
|
||
|
|
class FakeEEPROM
|
||
|
|
{
|
||
|
|
public:
|
||
|
|
uint8_t mem[1024];
|
||
|
|
|
||
|
|
FakeEEPROM() { erase(); }
|
||
|
|
void erase() { memset(mem, 0xFF, sizeof(mem)); }
|
||
|
|
|
||
|
|
template <typename T>
|
||
|
|
T &get(int addr, T &t)
|
||
|
|
{
|
||
|
|
memcpy(&t, mem + addr, sizeof(T));
|
||
|
|
return t;
|
||
|
|
}
|
||
|
|
|
||
|
|
template <typename T>
|
||
|
|
const T &put(int addr, const T &t)
|
||
|
|
{
|
||
|
|
memcpy(mem + addr, &t, sizeof(T));
|
||
|
|
return t;
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
inline FakeEEPROM EEPROM;
|