New disks can now be a G64 or a D64

This commit is contained in:
Stephen White 2019-04-28 14:48:16 +10:00
parent bf6d61d27b
commit 64291c0dfd
6 changed files with 120 additions and 54 deletions

View file

@ -208,13 +208,13 @@ bool DiskImage::OpenD64(const FILINFO* fileInfo, unsigned char* diskImage, unsig
return true;
}
bool DiskImage::WriteD64()
bool DiskImage::WriteD64(char* name)
{
if (readOnly)
return true;
FIL fp;
FRESULT res = f_open(&fp, fileInfo->fname, FA_CREATE_ALWAYS | FA_WRITE);
FRESULT res = f_open(&fp, fileInfo ? fileInfo->fname : name, FA_CREATE_ALWAYS | FA_WRITE);
if (res == FR_OK)
{
u32 bytesToWrite;
@ -790,13 +790,13 @@ static bool WriteDwords(FIL* fp, u32* values, u32 amount)
return true;
}
bool DiskImage::WriteG64()
bool DiskImage::WriteG64(char* name)
{
if (readOnly)
return true;
FIL fp;
FRESULT res = f_open(&fp, fileInfo->fname, FA_CREATE_ALWAYS | FA_WRITE);
FRESULT res = f_open(&fp, fileInfo ? fileInfo->fname : name, FA_CREATE_ALWAYS | FA_WRITE);
if (res == FR_OK)
{
u32 bytesToWrite;

View file

@ -164,6 +164,9 @@ public:
unsigned char tracksD81[HALF_TRACK_COUNT][2][MAX_TRACK_LENGTH];
};
bool WriteD64(char* name = 0);
bool WriteG64(char* name = 0);
private:
void CloseD64();
void CloseG64();
@ -172,8 +175,6 @@ private:
void CloseD71();
void CloseD81();
bool WriteD64();
bool WriteG64();
bool WriteNIB();
bool WriteNBZ();
bool WriteD71();

View file

@ -1175,7 +1175,7 @@ void FileBrowser::UpdateInputFolders()
char newFileName[64];
strncpy (newFileName, options.GetAutoBaseName(), 63);
int num = folder.FindNextAutoName( newFileName );
m_IEC_Commands.CreateD64(newFileName, "42", true);
m_IEC_Commands.CreateNewDisk(newFileName, "42", true);
FolderChanged();
}
else if (inputMappings->BrowseWriteProtect())
@ -1420,7 +1420,7 @@ void FileBrowser::DisplayDiskInfo(DiskImage* diskImage, const char* filenameForI
char name[17] = { 0 };
unsigned char buffer[260] = { 0 };
int charIndex;
u32 fontHeight = screenMain->GetFontHeight();
u32 fontHeight = screenMain->GetFontHeightDirectoryDisplay();
u32 x = 0;
u32 y = 0;
char bufferOut[128] = { 0 };

View file

@ -51,6 +51,7 @@ extern void Reboot_Pi();
extern void SwitchDrive(const char* drive);
extern int numberOfUSBMassStorageDevices;
extern void DisplayMessage(int x, int y, bool LCD, const char* message, u32 textColour, u32 backgroundColour);
#define WaitWhile(checkStatus) \
do\
@ -244,6 +245,7 @@ IEC_Commands::IEC_Commands()
C128BootSectorName = 0;
displayingDevices = false;
lowercaseBrowseModeFilenames = false;
newDiskType = DiskImage::D64;
}
void IEC_Commands::Reset(void)
@ -1171,7 +1173,7 @@ void IEC_Commands::New(void)
{
FILINFO filInfo;
int ret = CreateD64(filenameNew, ID, true);
int ret = CreateNewDisk(filenameNew, ID, true);
if (ret==0)
updateAction = REFRESH;
@ -2051,63 +2053,104 @@ void IEC_Commands::CloseFile(u8 secondary)
channel.Close();
}
int IEC_Commands::CreateD64(char* filenameNew, char* ID, bool automount)
int IEC_Commands::CreateNewDisk(char* filenameNew, char* ID, bool automount)
{
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");
DisplayMessage(240, 280, false, "Creating new disk", RGBA(0xff, 0xff, 0xff, 0xff), RGBA(0xff, 0, 0, 0xff));
DisplayMessage(0, 0, true, "Creating new disk", RGBA(0xff, 0xff, 0xff, 0xff), RGBA(0xff, 0, 0, 0xff));
switch (newDiskType)
{
case DiskImage::D64:
if (!(strstr(filenameNew, ".d64") || strstr(filenameNew, ".D64")))
strcat(filenameNew, ".d64");
break;
case DiskImage::G64:
if (!(strstr(filenameNew, ".g64") || strstr(filenameNew, ".G64")))
strcat(filenameNew, ".g64");
break;
default:
return ERROR_25_WRITE_ERROR;
break;
}
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)
unsigned char* dest = DiskImage::readBuffer;
char buffer[256];
u32 bytes;
u32 blocks;
memset(buffer, 0, sizeof(buffer));
// TODO: Should check for disk full.
for (blocks = 0; blocks < 357; ++blocks)
{
for (i = 0; i < 256; ++i)
{
if (f_write(&fpOut, buffer, 256, &bytes) != FR_OK)
break;
*dest++ = buffer[i];
}
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);
}
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);
for (i = 0; i < 256; ++i)
{
*dest++ = blankD64DIRBAM[i];
}
buffer[1] = 0xff;
//f_write(&fpOut, buffer, 256, &bytes);
for (i = 0; i < 256; ++i)
{
*dest++ = buffer[i];
}
buffer[1] = 0;
for (blocks = 0; blocks < 324; ++blocks)
{
//if (f_write(&fpOut, buffer, 256, &bytes) != FR_OK)
// break;
for (i = 0; i < 256; ++i)
{
*dest++ = buffer[i];
}
}
DiskImage diskImage;
diskImage.OpenD64((const FILINFO*)0, (unsigned char*)DiskImage::readBuffer, dest - (unsigned char*)DiskImage::readBuffer);
switch (newDiskType)
{
case DiskImage::D64:
if (!diskImage.WriteD64(filenameNew))
return ERROR_25_WRITE_ERROR;
break;
case DiskImage::G64:
if (!diskImage.WriteG64(filenameNew))
return ERROR_25_WRITE_ERROR;
break;
default:
return ERROR_25_WRITE_ERROR;
break;
}
// Mount the new disk? Shoud we do this or let them do it manually?
if (automount && f_stat(filenameNew, &filInfo) == FR_OK)
{

View file

@ -22,6 +22,7 @@
#include "iec_bus.h"
#include "ff.h"
#include "debug.h"
#include "DiskImage.h"
struct TimerMicroSeconds
{
@ -73,7 +74,7 @@ public:
u8 GetDeviceId() { return deviceID; }
void SetLowercaseBrowseModeFilenames(bool value) { lowercaseBrowseModeFilenames = value; }
void SetNewDiskType(DiskImage::DiskType type) { newDiskType = type; }
void SetAutoBootFB128(bool autoBootFB128) { this->autoBootFB128 = autoBootFB128; }
void Set128BootSectorName(const char* SectorName)
{
@ -91,7 +92,7 @@ public:
const FILINFO* GetImageSelected() const { return &filInfoSelectedImage; }
void SetStarFileName(const char* fileName) { starFileName = fileName; }
int CreateD64(char* filenameNew, char* ID, bool automount);
int CreateNewDisk(char* filenameNew, char* ID, bool automount);
void SetDisplayingDevices(bool displayingDevices) { this->displayingDevices = displayingDevices; }
@ -194,6 +195,7 @@ protected:
bool displayingDevices;
bool lowercaseBrowseModeFilenames;
DiskImage::DiskType newDiskType;
};
#endif

View file

@ -1637,6 +1637,26 @@ void UpdateFirmwareToSD()
}
}
void DisplayMessage(int x, int y, bool LCD, const char* message, u32 textColour, u32 backgroundColour)
{
char buffer[256] = { 0 };
if (!LCD)
{
x = screen.ScaleX(x);
y = screen.ScaleY(y);
screen.PrintText(false, x, y, (char*)message, textColour, backgroundColour);
}
else if (screenLCD)
{
RGBA BkColour = RGBA(0, 0, 0, 0xFF);
screenLCD->Clear(BkColour);
screenLCD->PrintText(false, x, y, (char*)message, textColour, backgroundColour);
screenLCD->SwapBuffers();
}
}
extern "C"
{
void kernel_main(unsigned int r0, unsigned int r1, unsigned int atags)