#include "rom.h" #include #include namespace rom { uint8_t *data = NULL; int size = 0; uint16_t mask = 0xffff; void load(const char* filename) { if (data) free(data); size = 0; FILE* f = fopen(filename, "rb"); if (f) { fseek(f, 0, SEEK_END); size = ftell(f); fseek(f, 0, SEEK_SET); data = (uint8_t*)malloc(size); fread(data, size, 1, f); fclose(f); if (size <= 4096) mask = size-1; // [TODO] Gestionar ROMs mes grans de 4K } } uint8_t read(uint16_t address) { return data[address & mask]; } void write(uint16_t address, uint8_t value) { data[address & mask] = value; } namespace debug { const memDebugInfo getInfo(uint16_t address) { return {"ROM", mdtROM, uint16_t(0x1000 | (address & mask))}; } } }