43 lines
709 B
C++
43 lines
709 B
C++
#pragma once
|
|
|
|
#define PLATFORM DESKTOP
|
|
|
|
#include "../Types.h"
|
|
|
|
struct TestDevice {
|
|
|
|
size_t size;
|
|
uint8_t* buf;
|
|
|
|
TestDevice(size_t size) : size(size) {
|
|
buf = (uint8_t*) malloc(size);
|
|
memset(buf, 0, size);
|
|
}
|
|
|
|
~TestDevice() {
|
|
free(buf);
|
|
}
|
|
|
|
void toFile(const std::string& name) {
|
|
FILE* f = fopen(name.c_str(), "w+");
|
|
fwrite(buf, size, 1, f);
|
|
fclose(f);
|
|
}
|
|
|
|
/** read a 512 byte block into dst */
|
|
bool readBlock(LBA512 addr, uint8_t* dst) {
|
|
memcpy(dst, buf+addr*512, 512);
|
|
return true;
|
|
}
|
|
|
|
bool writeBlock(LBA512 addr, const uint8_t* src) {
|
|
memcpy(buf+addr*512, src, 512);
|
|
return true;
|
|
}
|
|
|
|
void reset(uint8_t val) {
|
|
for (uint32_t i = 0; i < sizeof(buf); ++i) {buf[i] = val;}
|
|
}
|
|
|
|
};
|