separate CreateD64 into separate function

This commit is contained in:
penfold42 2018-07-19 12:48:22 +10:00
parent 1090e509a1
commit 23a2acf510
2 changed files with 78 additions and 56 deletions

View file

@ -1099,70 +1099,24 @@ void IEC_Commands::New(void)
if (ParseFilenames((char*)channel.buffer, filenameNew, ID))
{
FILINFO filInfo;
FRESULT res;
char* ptr;
int i;
//bool g64 = false;
//if (strstr(filenameNew, ".g64") || strstr(filenameNew, ".G64"))
// g64 = true;
//else
if(!(strstr(filenameNew, ".d64") || strstr(filenameNew, ".D64")))
strcat(filenameNew, ".d64");
res = f_stat(filenameNew, &filInfo);
if (res == FR_NO_FILE)
{
FIL fpOut;
res = f_open(&fpOut, filenameNew, FA_CREATE_ALWAYS | FA_WRITE);
if (res == FR_OK)
{
char buffer[256];
u32 bytes;
u32 blocks;
int ret = CreateD64(filenameNew, ID);
memset(buffer, 0, sizeof(buffer));
// TODO: Should check for disk full.
for (blocks = 0; blocks < 357; ++blocks)
{
if (f_write(&fpOut, buffer, 256, &bytes) != FR_OK)
break;
}
ptr = (char*)&blankD64DIRBAM[DISKNAME_OFFSET_IN_DIR_BLOCK];
int len = strlen(filenameNew);
for (i = 0; i < len; ++i)
{
*ptr++ = ascii2petscii(filenameNew[i]);
}
for (; i < 18; ++i)
{
*ptr++ = 0xa0;
}
for (i = 0; i < 2; ++i)
{
*ptr++ = ascii2petscii(ID[i]);
}
f_write(&fpOut, blankD64DIRBAM, 256, &bytes);
buffer[1] = 0xff;
f_write(&fpOut, buffer, 256, &bytes);
buffer[1] = 0;
for (blocks = 0; blocks < 324; ++blocks)
{
if (f_write(&fpOut, buffer, 256, &bytes) != FR_OK)
break;
}
f_close(&fpOut);
// Mount the new disk? Shoud we do this or let them do it manually?
if (f_stat(filenameNew, &filInfo) == FR_OK)
{
DIR dir;
Enter(dir, filInfo);
}
if (ret==0)
{
// Mount the new disk? Shoud we do this or let them do it manually?
if (f_stat(filenameNew, &filInfo) == FR_OK)
{
DIR dir;
Enter(dir, filInfo);
}
}
else
{
Error(ERROR_63_FILE_EXISTS);
Error(ret);
}
}
}
@ -1926,3 +1880,68 @@ void IEC_Commands::CloseFile(u8 secondary)
channel.Close();
}
int IEC_Commands::CreateD64(char* filenameNew, char* ID)
{
FILINFO filInfo;
FRESULT res;
char* ptr;
int i;
//bool g64 = false;
//if (strstr(filenameNew, ".g64") || strstr(filenameNew, ".G64"))
// g64 = true;
//else
if(!(strstr(filenameNew, ".d64") || strstr(filenameNew, ".D64")))
strcat(filenameNew, ".d64");
res = f_stat(filenameNew, &filInfo);
if (res == FR_NO_FILE)
{
FIL fpOut;
res = f_open(&fpOut, filenameNew, FA_CREATE_ALWAYS | FA_WRITE);
if (res == FR_OK)
{
char buffer[256];
u32 bytes;
u32 blocks;
memset(buffer, 0, sizeof(buffer));
// TODO: Should check for disk full.
for (blocks = 0; blocks < 357; ++blocks)
{
if (f_write(&fpOut, buffer, 256, &bytes) != FR_OK)
break;
}
ptr = (char*)&blankD64DIRBAM[DISKNAME_OFFSET_IN_DIR_BLOCK];
int len = strlen(filenameNew);
for (i = 0; i < len; ++i)
{
*ptr++ = ascii2petscii(filenameNew[i]);
}
for (; i < 18; ++i)
{
*ptr++ = 0xa0;
}
for (i = 0; i < 2; ++i)
{
*ptr++ = ascii2petscii(ID[i]);
}
f_write(&fpOut, blankD64DIRBAM, 256, &bytes);
buffer[1] = 0xff;
f_write(&fpOut, buffer, 256, &bytes);
buffer[1] = 0;
for (blocks = 0; blocks < 324; ++blocks)
{
if (f_write(&fpOut, buffer, 256, &bytes) != FR_OK)
break;
}
f_close(&fpOut);
}
return(ERROR_00_OK);
}
else
{
return(ERROR_63_FILE_EXISTS);
}
}

View file

@ -128,6 +128,8 @@ protected:
void CloseAllChannels();
void SendError();
int CreateD64(char* filenameNew, char* ID);
bool Enter(DIR& dir, FILINFO& filInfo);
bool FindFirst(DIR& dir, const char* matchstr, FILINFO& filInfo);
@ -169,3 +171,4 @@ protected:
const char* starFileName;
};
#endif