mirror of
https://github.com/AxioDL/kabufuda.git
synced 2025-06-24 07:23:33 +00:00
Better block allocation handling
This commit is contained in:
parent
6892853a14
commit
3121f67f4d
@ -94,17 +94,19 @@ uint16_t BlockAllocationTable::allocateBlocks(uint16_t count, uint16_t maxBlocks
|
|||||||
if (freeBlock != 0xFFFF)
|
if (freeBlock != 0xFFFF)
|
||||||
{
|
{
|
||||||
uint16_t tmpCount = count;
|
uint16_t tmpCount = count;
|
||||||
while ((count--) > 0)
|
while ((count--) > 0 && freeBlock != 0xFFFF)
|
||||||
{
|
{
|
||||||
m_map[(freeBlock - FSTBlocks)] = 0xFFFF;
|
m_map[(freeBlock - FSTBlocks)] = 0xFFFF;
|
||||||
if (count != 0)
|
if (count != 0)
|
||||||
{
|
{
|
||||||
m_map[(freeBlock - FSTBlocks)] = nextFreeBlock(maxBlocks - FSTBlocks, m_lastAllocated + 1);
|
m_map[(freeBlock - FSTBlocks)] = nextFreeBlock(maxBlocks - FSTBlocks, freeBlock + 1);
|
||||||
freeBlock = m_map[(freeBlock - FSTBlocks)];
|
freeBlock = m_map[(freeBlock - FSTBlocks)];
|
||||||
}
|
}
|
||||||
m_lastAllocated = freeBlock;
|
|
||||||
}
|
}
|
||||||
|
if (freeBlock == 0xFFFF)
|
||||||
|
return 0xFFFF;
|
||||||
|
|
||||||
|
m_lastAllocated = freeBlock;
|
||||||
m_freeBlocks -= tmpCount;
|
m_freeBlocks -= tmpCount;
|
||||||
}
|
}
|
||||||
return firstBlock;
|
return firstBlock;
|
||||||
|
@ -186,6 +186,8 @@ ECardResult Card::createFile(const char* filename, size_t size,
|
|||||||
{
|
{
|
||||||
handleOut.reset();
|
handleOut.reset();
|
||||||
|
|
||||||
|
if (size <= 0)
|
||||||
|
return ECardResult::FATAL_ERROR;
|
||||||
if (strlen(filename) > 32)
|
if (strlen(filename) > 32)
|
||||||
return ECardResult::NAMETOOLONG;
|
return ECardResult::NAMETOOLONG;
|
||||||
if (m_currentDir->getFile(m_game, m_maker, filename))
|
if (m_currentDir->getFile(m_game, m_maker, filename))
|
||||||
@ -198,7 +200,7 @@ ECardResult Card::createFile(const char* filename, size_t size,
|
|||||||
|
|
||||||
_updateDirAndBat();
|
_updateDirAndBat();
|
||||||
File* f = m_currentDir->getFirstFreeFile(m_game, m_maker, filename);
|
File* f = m_currentDir->getFirstFreeFile(m_game, m_maker, filename);
|
||||||
uint16_t block = m_currentBat->allocateBlocks(neededBlocks, m_maxBlock);
|
uint16_t block = m_currentBat->allocateBlocks(neededBlocks, m_maxBlock - FSTBlocks);
|
||||||
if (f && block != 0xFFFF)
|
if (f && block != 0xFFFF)
|
||||||
{
|
{
|
||||||
f->m_modifiedTime = uint32_t(getGCTime());
|
f->m_modifiedTime = uint32_t(getGCTime());
|
||||||
|
@ -4,54 +4,27 @@
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
kabufuda::Card mc{_S("test.USA.raw"), "GM8E", "01"};
|
kabufuda::Card mc{_S("test.USA.raw"), "GM8E", "01"};
|
||||||
if (!mc)
|
mc.format(kabufuda::ECardSlot::SlotA, kabufuda::ECardSize::Card2043Mb);
|
||||||
mc.format(kabufuda::ECardSlot::SlotA, kabufuda::ECardSize::Card2043Mb);
|
|
||||||
uint64_t a = 0;
|
uint64_t a = 0;
|
||||||
mc.getSerial(a);
|
mc.getSerial(a);
|
||||||
|
|
||||||
kabufuda::Card mc2{_S("test2.USA.raw"), "GM8E", "01"};
|
|
||||||
if (!mc2)
|
|
||||||
mc2.format(kabufuda::ECardSlot::SlotA, kabufuda::ECardSize::Card2043Mb);
|
|
||||||
|
|
||||||
std::unique_ptr<kabufuda::IFileHandle> f;
|
std::unique_ptr<kabufuda::IFileHandle> f;
|
||||||
mc.openFile("MetroidPrime A", f);
|
mc.openFile("MetroidPrime A", f);
|
||||||
if (!f)
|
for (uint32_t i = 0; i < 127; i++)
|
||||||
{
|
{
|
||||||
mc.createFile("MetroidPrime A", kabufuda::BlockSize, f);
|
char name[32] = {'\0'};
|
||||||
|
sprintf(name, "Metroid Prime %i", i);
|
||||||
|
kabufuda::ECardResult res = mc.createFile(name, kabufuda::BlockSize, f);
|
||||||
|
if (res == kabufuda::ECardResult::INSSPACE || res == kabufuda::ECardResult::NOFILE)
|
||||||
|
break;
|
||||||
|
|
||||||
mc.setPublic(f, true);
|
mc.setPublic(f, true);
|
||||||
mc.setCanCopy(f, true);
|
mc.setCanCopy(f, true);
|
||||||
mc.setCanMove(f, true);
|
mc.setCanMove(f, true);
|
||||||
}
|
mc.setCommentAddress(f, 0);
|
||||||
|
mc.write(f, "Test\0", strlen("Test") + 1);
|
||||||
|
mc.seek(f, 32, kabufuda::SeekOrigin::Begin);
|
||||||
if (f)
|
mc.write(f, "Test\0", strlen("Test") + 1);
|
||||||
{
|
|
||||||
mc.setBannerFormat(f, kabufuda::EImageFormat::C8);
|
|
||||||
mc.setIconFormat(f, 0, kabufuda::EImageFormat::C8);
|
|
||||||
mc.setIconSpeed(f, 0, kabufuda::EAnimationSpeed::Middle);
|
|
||||||
|
|
||||||
mc.seek(f, 4, kabufuda::SeekOrigin::Begin);
|
|
||||||
mc.setCommentAddress(f, 4);
|
|
||||||
|
|
||||||
std::string comment("Metroid Prime PC Edition");
|
|
||||||
mc.write(f, comment.c_str(), comment.length());
|
|
||||||
mc.seek(f, 32 - comment.length(), kabufuda::SeekOrigin::Current);
|
|
||||||
comment = "Metroid Prime PC Is Cool";
|
|
||||||
mc.write(f, comment.c_str(), comment.length());
|
|
||||||
mc.seek(f, 32 - comment.length(), kabufuda::SeekOrigin::Current);
|
|
||||||
mc.setImageAddress(f, mc.tell(f));
|
|
||||||
|
|
||||||
if (mc.copyFileTo(f, mc2))
|
|
||||||
printf("Copy succeeded!\n");
|
|
||||||
else
|
|
||||||
printf("Copy failed...\n");
|
|
||||||
|
|
||||||
std::unique_ptr<kabufuda::IFileHandle> it = mc.firstFile();
|
|
||||||
while (it)
|
|
||||||
{
|
|
||||||
printf("%.4s%.2s-%s\n", mc.gameId(it), mc.maker(it), mc.getFilename(it));
|
|
||||||
it = mc.nextFile(it);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user