LCD Driver, some teensy code, SDCard code, MBR/FAT32
This commit is contained in:
66
ext/sd/main.cpp
Normal file
66
ext/sd/main.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
|
||||
#include "MBR.h"
|
||||
#include "fat32/FS.h"
|
||||
|
||||
class Simu {
|
||||
FILE* f;
|
||||
public:
|
||||
|
||||
Simu(const char* image) {
|
||||
f = fopen(image, "rb");
|
||||
if (!f) {throw std::runtime_error("failed to open");}
|
||||
}
|
||||
|
||||
uint32_t read(uint32_t addr, uint32_t size, uint8_t* dst) {
|
||||
fseek(f, addr, SEEK_SET);
|
||||
return fread(dst, size, 1, f) * size;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
int main(void) {
|
||||
|
||||
// diff /tmp/ram/TETRIS.GB /apps/workspace/gbemu/tests/tetris.gb
|
||||
|
||||
Simu simu("/tmp/ram/1.dat");
|
||||
|
||||
MBR<Simu> mbr(simu);
|
||||
std::cout << mbr.isPresent() << std::endl;
|
||||
std::cout << mbr.isValid() << std::endl;
|
||||
|
||||
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<Simu>;
|
||||
|
||||
FAT32FS fat(simu, mbr.getPartition(0).getFirstSector() * 512);
|
||||
std::cout << "valid: " << fat.isValid() << std::endl;
|
||||
|
||||
FAT32FS::DirIterator dir = fat.getRoot();
|
||||
while(dir.hasNext()) {
|
||||
FAT32::DirEntry de = dir.next();
|
||||
std::cout << de.getName() << std::endl;
|
||||
FAT32FS::File f = fat.open(de);
|
||||
|
||||
uint8_t* bufff = (uint8_t*) malloc(1024*1024);
|
||||
uint32_t read = f.read(f.getSize(), bufff);
|
||||
|
||||
std::string name = de.getName();
|
||||
std::ofstream out("/tmp/ram/" + name);
|
||||
out.write((char*)bufff, read);
|
||||
out.close();
|
||||
|
||||
}
|
||||
|
||||
// diff /tmp/ram/TETRIS.GB /apps/workspace/gbemu/tests/tetris.gb
|
||||
// diif /tmp/ram/KIRBY1.GB /apps/workspace/gbemu/tests/Kirby\'s\ Dream\ Land\ \(USA\,\ Europe\).gb
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user