Merge pull request #118 from gbouille/CaddyDisplayBug

Correct a bug on displaying caddy content when using 8bit height font
This commit is contained in:
Stephen White 2018-12-31 07:58:38 +11:00 committed by GitHub
commit 03b3f9f38c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 373 additions and 375 deletions

View File

@ -1,375 +1,373 @@
// Pi1541 - A Commodore 1541 disk drive emulator // Pi1541 - A Commodore 1541 disk drive emulator
// Copyright(C) 2018 Stephen White // Copyright(C) 2018 Stephen White
// //
// This file is part of Pi1541. // This file is part of Pi1541.
// //
// Pi1541 is free software : you can redistribute it and/or modify // Pi1541 is free software : you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// Pi1541 is distributed in the hope that it will be useful, // Pi1541 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Pi1541. If not, see <http://www.gnu.org/licenses/>. // along with Pi1541. If not, see <http://www.gnu.org/licenses/>.
#include "DiskCaddy.h" #include "DiskCaddy.h"
#include "debug.h" #include "debug.h"
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include "ff.h" #include "ff.h"
extern "C" extern "C"
{ {
#include "rpi-gpio.h" // For SetACTLed #include "rpi-gpio.h" // For SetACTLed
} }
static const u32 screenPosXCaddySelections = 240; static const u32 screenPosXCaddySelections = 240;
static const u32 screenPosYCaddySelections = 280; static const u32 screenPosYCaddySelections = 280;
static char buffer[256] = { 0 }; static char buffer[256] = { 0 };
static u32 white = RGBA(0xff, 0xff, 0xff, 0xff); static u32 white = RGBA(0xff, 0xff, 0xff, 0xff);
static u32 red = RGBA(0xff, 0, 0, 0xff); static u32 red = RGBA(0xff, 0, 0, 0xff);
#define LCDFONTHEIGHT 16 bool DiskCaddy::Empty()
{
bool DiskCaddy::Empty() int x;
{ int y;
int x; int index;
int y; bool anyDirty = false;
int index;
bool anyDirty = false; for (index = 0; index < (int)disks.size(); ++index)
{
for (index = 0; index < (int)disks.size(); ++index) if (disks[index].IsDirty())
{ {
if (disks[index].IsDirty()) anyDirty = true;
{ if (screen)
anyDirty = true; {
if (screen) x = screen->ScaleX(screenPosXCaddySelections);
{ y = screen->ScaleY(screenPosYCaddySelections);
x = screen->ScaleX(screenPosXCaddySelections);
y = screen->ScaleY(screenPosYCaddySelections); snprintf(buffer, 256, "Saving %s\r\n", disks[index].GetName());
screen->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), red);
snprintf(buffer, 256, "Saving %s\r\n", disks[index].GetName()); }
screen->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), red);
} if (screenLCD)
{
if (screenLCD) RGBA BkColour = RGBA(0, 0, 0, 0xFF);
{ screenLCD->Clear(BkColour);
RGBA BkColour = RGBA(0, 0, 0, 0xFF); x = 0;
screenLCD->Clear(BkColour); y = 0;
x = 0;
y = 0; snprintf(buffer, 256, "Saving");
screenLCD->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), BkColour);
snprintf(buffer, 256, "Saving"); y += screenLCD->GetFontHeight();
screenLCD->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), BkColour); snprintf(buffer, 256, "%s ", disks[index].GetName());
y += LCDFONTHEIGHT; screenLCD->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), red);
snprintf(buffer, 256, "%s ", disks[index].GetName()); screenLCD->SwapBuffers();
screenLCD->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), red); }
screenLCD->SwapBuffers(); }
} disks[index].Close();
} }
disks[index].Close();
} if (anyDirty)
{
if (anyDirty) if (screen)
{ {
if (screen) x = screen->ScaleX(screenPosXCaddySelections);
{ y = screen->ScaleY(screenPosYCaddySelections);
x = screen->ScaleX(screenPosXCaddySelections);
y = screen->ScaleY(screenPosYCaddySelections); snprintf(buffer, 256, "Saving Complete \r\n");
screen->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), red);
snprintf(buffer, 256, "Saving Complete \r\n"); }
screen->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), red);
} if (screenLCD)
{
if (screenLCD) RGBA BkColour = RGBA(0, 0, 0, 0xFF);
{ screenLCD->Clear(BkColour);
RGBA BkColour = RGBA(0, 0, 0, 0xFF); x = 0;
screenLCD->Clear(BkColour); y = 0;
x = 0;
y = 0; snprintf(buffer, 256, "Saving");
screenLCD->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), BkColour);
snprintf(buffer, 256, "Saving"); y += screenLCD->GetFontHeight();
screenLCD->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), BkColour); snprintf(buffer, 256, "Complete ");
y += LCDFONTHEIGHT; screenLCD->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), red);
snprintf(buffer, 256, "Complete "); screenLCD->SwapBuffers();
screenLCD->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), red); }
screenLCD->SwapBuffers(); }
}
} disks.clear();
selectedIndex = 0;
disks.clear(); return anyDirty;
selectedIndex = 0; }
return anyDirty;
} bool DiskCaddy::Insert(const FILINFO* fileInfo, bool readOnly)
{
bool DiskCaddy::Insert(const FILINFO* fileInfo, bool readOnly) int x;
{ int y;
int x; bool success;
int y; FIL fp;
bool success; FRESULT res = f_open(&fp, fileInfo->fname, FA_READ);
FIL fp; if (res == FR_OK)
FRESULT res = f_open(&fp, fileInfo->fname, FA_READ); {
if (res == FR_OK) if (screen)
{ {
if (screen) x = screen->ScaleX(screenPosXCaddySelections);
{ y = screen->ScaleY(screenPosYCaddySelections);
x = screen->ScaleX(screenPosXCaddySelections);
y = screen->ScaleY(screenPosYCaddySelections); snprintf(buffer, 256, "Loading %s\r\n", fileInfo->fname);
screen->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), red);
snprintf(buffer, 256, "Loading %s\r\n", fileInfo->fname); }
screen->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), red);
} if (screenLCD)
{
if (screenLCD) RGBA BkColour = RGBA(0, 0, 0, 0xFF);
{ screenLCD->Clear(BkColour);
RGBA BkColour = RGBA(0, 0, 0, 0xFF); x = 0;
screenLCD->Clear(BkColour); y = 0;
x = 0;
y = 0; snprintf(buffer, 256, "Loading");
screenLCD->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), BkColour);
snprintf(buffer, 256, "Loading"); y += screenLCD->GetFontHeight();
screenLCD->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), BkColour); snprintf(buffer, 256, "%s ", fileInfo->fname);
y += LCDFONTHEIGHT; screenLCD->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), red);
snprintf(buffer, 256, "%s ", fileInfo->fname); screenLCD->SwapBuffers();
screenLCD->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), red); }
screenLCD->SwapBuffers();
} u32 bytesRead;
SetACTLed(true);
u32 bytesRead; f_read(&fp, DiskImage::readBuffer, READBUFFER_SIZE, &bytesRead);
SetACTLed(true); SetACTLed(false);
f_read(&fp, DiskImage::readBuffer, READBUFFER_SIZE, &bytesRead); f_close(&fp);
SetACTLed(false);
f_close(&fp); DiskImage::DiskType diskType = DiskImage::GetDiskImageTypeViaExtention(fileInfo->fname);
switch (diskType)
DiskImage::DiskType diskType = DiskImage::GetDiskImageTypeViaExtention(fileInfo->fname); {
switch (diskType) case DiskImage::D64:
{ success = InsertD64(fileInfo, (unsigned char*)DiskImage::readBuffer, bytesRead, readOnly);
case DiskImage::D64: break;
success = InsertD64(fileInfo, (unsigned char*)DiskImage::readBuffer, bytesRead, readOnly); case DiskImage::G64:
break; success = InsertG64(fileInfo, (unsigned char*)DiskImage::readBuffer, bytesRead, readOnly);
case DiskImage::G64: break;
success = InsertG64(fileInfo, (unsigned char*)DiskImage::readBuffer, bytesRead, readOnly); case DiskImage::NIB:
break; success = InsertNIB(fileInfo, (unsigned char*)DiskImage::readBuffer, bytesRead, readOnly);
case DiskImage::NIB: break;
success = InsertNIB(fileInfo, (unsigned char*)DiskImage::readBuffer, bytesRead, readOnly); case DiskImage::NBZ:
break; success = InsertNBZ(fileInfo, (unsigned char*)DiskImage::readBuffer, bytesRead, readOnly);
case DiskImage::NBZ: break;
success = InsertNBZ(fileInfo, (unsigned char*)DiskImage::readBuffer, bytesRead, readOnly); case DiskImage::D81:
break; success = InsertD81(fileInfo, (unsigned char*)DiskImage::readBuffer, bytesRead, readOnly);
case DiskImage::D81: break;
success = InsertD81(fileInfo, (unsigned char*)DiskImage::readBuffer, bytesRead, readOnly); default:
break; success = false;
default: break;
success = false; }
break; if (success)
} {
if (success) DEBUG_LOG("Mounted into caddy %s - %d\r\n", fileInfo->fname, bytesRead);
{ }
DEBUG_LOG("Mounted into caddy %s - %d\r\n", fileInfo->fname, bytesRead); }
} else
} {
else DEBUG_LOG("Failed to open %s\r\n", fileInfo->fname);
{ success = false;
DEBUG_LOG("Failed to open %s\r\n", fileInfo->fname); }
success = false;
} oldCaddyIndex = 0;
oldCaddyIndex = 0; return success;
}
return success;
} bool DiskCaddy::InsertD64(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly)
{
bool DiskCaddy::InsertD64(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly) DiskImage diskImage;
{ if (diskImage.OpenD64(fileInfo, diskImageData, size))
DiskImage diskImage; {
if (diskImage.OpenD64(fileInfo, diskImageData, size)) diskImage.SetReadOnly(readOnly);
{ disks.push_back(diskImage);
diskImage.SetReadOnly(readOnly); selectedIndex = disks.size() - 1;
disks.push_back(diskImage); return true;
selectedIndex = disks.size() - 1; }
return true; return false;
} }
return false;
} bool DiskCaddy::InsertG64(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly)
{
bool DiskCaddy::InsertG64(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly) DiskImage diskImage;
{ if (diskImage.OpenG64(fileInfo, diskImageData, size))
DiskImage diskImage; {
if (diskImage.OpenG64(fileInfo, diskImageData, size)) diskImage.SetReadOnly(readOnly);
{ disks.push_back(diskImage);
diskImage.SetReadOnly(readOnly); //DEBUG_LOG("Disks size = %d\r\n", disks.size());
disks.push_back(diskImage); selectedIndex = disks.size() - 1;
//DEBUG_LOG("Disks size = %d\r\n", disks.size()); return true;
selectedIndex = disks.size() - 1; }
return true; return false;
} }
return false;
} bool DiskCaddy::InsertNIB(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly)
{
bool DiskCaddy::InsertNIB(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly) DiskImage diskImage;
{ if (diskImage.OpenNIB(fileInfo, diskImageData, size))
DiskImage diskImage; {
if (diskImage.OpenNIB(fileInfo, diskImageData, size)) // At the moment we cannot write out NIB files.
{ diskImage.SetReadOnly(true);// readOnly);
// At the moment we cannot write out NIB files. disks.push_back(diskImage);
diskImage.SetReadOnly(true);// readOnly); selectedIndex = disks.size() - 1;
disks.push_back(diskImage); return true;
selectedIndex = disks.size() - 1; }
return true; return false;
} }
return false;
} bool DiskCaddy::InsertNBZ(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly)
{
bool DiskCaddy::InsertNBZ(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly) DiskImage diskImage;
{ if (diskImage.OpenNBZ(fileInfo, diskImageData, size))
DiskImage diskImage; {
if (diskImage.OpenNBZ(fileInfo, diskImageData, size)) // At the moment we cannot write out NIB files.
{ diskImage.SetReadOnly(true);// readOnly);
// At the moment we cannot write out NIB files. disks.push_back(diskImage);
diskImage.SetReadOnly(true);// readOnly); selectedIndex = disks.size() - 1;
disks.push_back(diskImage); return true;
selectedIndex = disks.size() - 1; }
return true; return false;
} }
return false;
} bool DiskCaddy::InsertD81(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly)
{
bool DiskCaddy::InsertD81(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly) DiskImage diskImage;
{ if (diskImage.OpenD81(fileInfo, diskImageData, size))
DiskImage diskImage; {
if (diskImage.OpenD81(fileInfo, diskImageData, size)) diskImage.SetReadOnly(readOnly);
{ disks.push_back(diskImage);
diskImage.SetReadOnly(readOnly); selectedIndex = disks.size() - 1;
disks.push_back(diskImage); return true;
selectedIndex = disks.size() - 1; }
return true; return false;
} }
return false;
} void DiskCaddy::Display()
{
void DiskCaddy::Display() unsigned numberOfImages = GetNumberOfImages();
{ unsigned caddyIndex;
unsigned numberOfImages = GetNumberOfImages(); int x;
unsigned caddyIndex; int y;
int x; if (screen)
int y; {
if (screen) x = screen->ScaleX(screenPosXCaddySelections);
{ y = screen->ScaleY(screenPosYCaddySelections);
x = screen->ScaleX(screenPosXCaddySelections);
y = screen->ScaleY(screenPosYCaddySelections); snprintf(buffer, 256, "Emulating\r\n");
screen->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), red);
snprintf(buffer, 256, "Emulating\r\n"); y += 16;
screen->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), red);
y += 16; for (caddyIndex = 0; caddyIndex < numberOfImages; ++caddyIndex)
{
for (caddyIndex = 0; caddyIndex < numberOfImages; ++caddyIndex) DiskImage* image = GetImage(caddyIndex);
{ const char* name = image->GetName();
DiskImage* image = GetImage(caddyIndex); if (name)
const char* name = image->GetName(); {
if (name) snprintf(buffer, 256, "%d %s\r\n", caddyIndex + 1, name);
{ screen->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), red);
snprintf(buffer, 256, "%d %s\r\n", caddyIndex + 1, name); y += 16;
screen->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), red); }
y += 16; }
} }
}
} if (screenLCD)
{
if (screenLCD) RGBA BkColour = RGBA(0, 0, 0, 0xFF);
{ screenLCD->Clear(BkColour);
RGBA BkColour = RGBA(0, 0, 0, 0xFF); }
screenLCD->Clear(BkColour); ShowSelectedImage(0);
} }
ShowSelectedImage(0);
} void DiskCaddy::ShowSelectedImage(u32 index)
{
void DiskCaddy::ShowSelectedImage(u32 index) u32 x;
{ u32 y;
u32 x; if (screen)
u32 y; {
if (screen) x = screen->ScaleX(screenPosXCaddySelections) - 16;
{ y = screen->ScaleY(screenPosYCaddySelections) + 16 + 16 * index;
x = screen->ScaleX(screenPosXCaddySelections) - 16; snprintf(buffer, 256, "*");
y = screen->ScaleY(screenPosYCaddySelections) + 16 + 16 * index; screen->PrintText(false, x, y, buffer, white, red);
snprintf(buffer, 256, "*"); }
screen->PrintText(false, x, y, buffer, white, red); if (screenLCD)
} {
if (screenLCD) unsigned numberOfImages = GetNumberOfImages();
{ unsigned numberOfDisplayedImages = screenLCD->Height()/screenLCD->GetFontHeight()-1;
unsigned numberOfImages = GetNumberOfImages(); unsigned caddyIndex;
unsigned numberOfDisplayedImages = screenLCD->Height()/LCDFONTHEIGHT-1;
unsigned caddyIndex; RGBA BkColour = RGBA(0, 0, 0, 0xFF);
//screenLCD->Clear(BkColour);
RGBA BkColour = RGBA(0, 0, 0, 0xFF); x = 0;
//screenLCD->Clear(BkColour); y = 0;
x = 0;
y = 0; snprintf(buffer, 256, " D %d/%d %c "
, index + 1
snprintf(buffer, 256, " D %d/%d %c " , numberOfImages
, index + 1 , GetImage(index)->GetReadOnly() ? 'R' : ' '
, numberOfImages );
, GetImage(index)->GetReadOnly() ? 'R' : ' ' screenLCD->PrintText(false, x, y, buffer, 0, RGBA(0xff, 0xff, 0xff, 0xff));
); y += screenLCD->GetFontHeight();
screenLCD->PrintText(false, x, y, buffer, 0, RGBA(0xff, 0xff, 0xff, 0xff));
y += LCDFONTHEIGHT; if (numberOfImages > numberOfDisplayedImages && index > numberOfDisplayedImages-1)
{
if (numberOfImages > numberOfDisplayedImages && index > numberOfDisplayedImages-1) if (numberOfImages - index < numberOfDisplayedImages)
{ caddyIndex = numberOfImages - numberOfDisplayedImages;
if (numberOfImages - index < numberOfDisplayedImages) else
caddyIndex = numberOfImages - numberOfDisplayedImages; caddyIndex = index;
else }
caddyIndex = index; else
} {
else caddyIndex = 0;
{ }
caddyIndex = 0;
} for (; caddyIndex < numberOfImages; ++caddyIndex)
{
for (; caddyIndex < numberOfImages; ++caddyIndex) DiskImage* image = GetImage(caddyIndex);
{ const char* name = image->GetName();
DiskImage* image = GetImage(caddyIndex); if (name)
const char* name = image->GetName(); {
if (name) memset(buffer, ' ', screenLCD->Width()/screenLCD->GetFontWidth());
{ screenLCD->PrintText(false, x, y, buffer, BkColour, BkColour);
memset(buffer, ' ', screenLCD->Width()/screenLCD->GetFontWidth()); snprintf(buffer, 256, "%d %s", caddyIndex + 1, name);
screenLCD->PrintText(false, x, y, buffer, BkColour, BkColour); screenLCD->PrintText(false, x, y, buffer, 0, caddyIndex == index ? RGBA(0xff, 0xff, 0xff, 0xff) : BkColour);
snprintf(buffer, 256, "%d %s", caddyIndex + 1, name); y += screenLCD->GetFontHeight();
screenLCD->PrintText(false, x, y, buffer, 0, caddyIndex == index ? RGBA(0xff, 0xff, 0xff, 0xff) : BkColour); }
y += LCDFONTHEIGHT; if (y >= screenLCD->Height())
} break;
if (y >= screenLCD->Height()) }
break; screenLCD->SwapBuffers();
} }
screenLCD->SwapBuffers(); }
}
} bool DiskCaddy::Update()
{
bool DiskCaddy::Update() u32 y;
{ u32 x;
u32 y; u32 caddyIndex = GetSelectedIndex();
u32 x; if (caddyIndex != oldCaddyIndex)
u32 caddyIndex = GetSelectedIndex(); {
if (caddyIndex != oldCaddyIndex) if (screen)
{ {
if (screen) x = screen->ScaleX(screenPosXCaddySelections) - 16;
{ y = screen->ScaleY(screenPosYCaddySelections) + 16 + 16 * oldCaddyIndex;
x = screen->ScaleX(screenPosXCaddySelections) - 16; snprintf(buffer, 256, " ");
y = screen->ScaleY(screenPosYCaddySelections) + 16 + 16 * oldCaddyIndex; screen->PrintText(false, x, y, buffer, red, red);
snprintf(buffer, 256, " "); oldCaddyIndex = caddyIndex;
screen->PrintText(false, x, y, buffer, red, red); ShowSelectedImage(oldCaddyIndex);
oldCaddyIndex = caddyIndex; }
ShowSelectedImage(oldCaddyIndex);
} if (screenLCD)
{
if (screenLCD)
{ }
} return true;
}
return true; return false;
} }
return false;
}