#include #include //#define debugMod(module, str) {printf("i[%-10s] ", module); printf(str); printf("\n");} //#define debugMod1(module, str, v1) {printf("i[%-10s] ", module); printf(str, v1); printf("\n");} //#define debugMod2(module, str, v1, v2) {printf("i[%-10s] ", module); printf(str, v1, v2); printf("\n");} //#define debugMod3(module, str, v1, v2, v3) {printf("i[%-10s] ", module); printf(str, v1, v2, v3); printf("\n");} //#define debugMod4(module, str, v1, v2, v3, v4) {printf("i[%-10s] ", module); printf(str, v1, v2, v3, v4); printf("\n");} //#define debugMod5(module, str, v1, v2, v3, v4, v5) {printf("i[%-10s] ", module); printf(str, v1, v2, v3, v4, v5); printf("\n");} #define PLATFORM DESKTOP #include "../../Debug.h" #include "MBR.h" #include "fat32/FS.h" #include "AccessHelper.h" #include //class Simu { // FILE* f; //public: // Simu(const char* image) { // f = fopen(image, "rw"); // if (!f) {throw std::runtime_error("failed to open");} // } // uint32_t readSingleBlock(LBA512 addr, uint8_t* dst) { // Log::addInfo("SD", "read512(%d*512)", addr); // fseek(f, addr*512, SEEK_SET); // return fread(dst, 512, 1, f) * 512; // } // uint32_t writeSingleBlock(LBA512 addr, const uint8_t* src) { // Log::addInfo("SD", "write512(%d*512)", addr); // fseek(f, addr*512, SEEK_SET); // return fwrite(src, 512, 1, f) * 512; // } //}; class Simu { uint8_t* data; public: Simu(const char* image) { FILE* f = fopen(image, "rw"); if (!f) {throw std::runtime_error("failed to open");} fseek(f, 0L, SEEK_END); size_t size = ftell(f); fseek(f, 0L, SEEK_SET); data = (uint8_t*) malloc(size); fread(data, size, 1, f); fclose(f); } uint32_t readSingleBlock(LBA512 addr, uint8_t* dst) { Log::addInfo("SD", "read512(%d*512)", addr); memcpy(dst, data+addr*512, 512); return 512; } uint32_t writeSingleBlock(LBA512 addr, const uint8_t* src) { Log::addInfo("SD", "write512(%d*512)", addr); memcpy(data+addr*512, src, 512); return 512; } }; #include int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); ::testing::GTEST_FLAG(filter) = "*TestCreate*"; return RUN_ALL_TESTS(); // diff /tmp/ram/TETRIS.GB /apps/workspace/gbemu/tests/tetris.gb Simu simu("/tmp/ram/1.dat"); AccessHelper ah(simu); MBR> mbr(ah); if (mbr.isPresent() && mbr.isValid()) { for (int i = 0; i < 4; ++i) { std::cout << (int) mbr.getPartition(i).getType() << " - " << mbr.getPartition(i).getFirstSector() << " - " << mbr.getPartition(i).getNumSectors() << std::endl; } using FAT32FS = FAT32::FS>; FAT32FS fat(ah, mbr.getPartition(0).getFirstSector() * 512); auto callback = [] (const int percent) { std::cout << percent << std::endl; }; FAT32FS::DirIterator dir = fat.getRoot(); while(false) { FAT32::DirEntryAt dea = dir.nextUsable(); if (!dea.isValid()) {break;} if (1==0) { FAT32FS::File2 f = fat.open2(dea); if (1==0) { uint8_t* bufff = (uint8_t*) malloc(1024*1024); uint32_t read = f.read(f.getSize(), bufff, callback); std::string name = f.getName(); std::ofstream out("/tmp/ram/" + name); out.write((char*)bufff, read); out.close(); free(bufff); break; } } } //FAT32::DirEntryAt root = fat.getRoot().cur(); FAT32FS::File2 file = fat.create2("tmp1.txt"); uint8_t src[128]; file.write(128, src, [] (int percent) {} ); // diff /tmp/ram/TETRIS.GB /apps/workspace/gbemu/tests/tetris.gb // diff /tmp/ram/KIRBY1.GB /apps/workspace/gbemu/tests/Kirby\'s\ Dream\ Land\ \(USA\,\ Europe\).gb } }