From e8e0b8428b1654a4246659d4ed8949ed6900bac4 Mon Sep 17 00:00:00 2001 From: gbouille <45919242+gbouille@users.noreply.github.com> Date: Mon, 31 Dec 2018 11:05:17 +0100 Subject: [PATCH] Correct a bug on displaying caddy content when using 8bit height font (like CBM font) This time, with the correct y coordinate usage. --- src/DiskCaddy.cpp | 2 +- src/DiskCaddy.h | 212 +++++++++++++++---------------- src/FileBrowser.cpp | 4 +- src/ScreenLCD.cpp | 302 ++++++++++++++++++++++---------------------- 4 files changed, 260 insertions(+), 260 deletions(-) diff --git a/src/DiskCaddy.cpp b/src/DiskCaddy.cpp index ae243ee..0a4af94 100644 --- a/src/DiskCaddy.cpp +++ b/src/DiskCaddy.cpp @@ -298,7 +298,7 @@ void DiskCaddy::ShowSelectedImage(u32 index) if (screenLCD) { unsigned numberOfImages = GetNumberOfImages(); - unsigned numberOfDisplayedImages = screenLCD->Height()/screenLCD->GetFontHeight()-1; + unsigned numberOfDisplayedImages = (screenLCD->Height()/screenLCD->GetFontHeight())-1; unsigned caddyIndex; RGBA BkColour = RGBA(0, 0, 0, 0xFF); diff --git a/src/DiskCaddy.h b/src/DiskCaddy.h index d2036a7..e8d881f 100644 --- a/src/DiskCaddy.h +++ b/src/DiskCaddy.h @@ -1,107 +1,107 @@ -// Pi1541 - A Commodore 1541 disk drive emulator -// Copyright(C) 2018 Stephen White -// -// This file is part of Pi1541. -// -// Pi1541 is free software : you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Pi1541 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Pi1541. If not, see . - -#ifndef DISKCADDY_H -#define DISKCADDY_H - -#include -#include "DiskImage.h" -#include "Screen.h" - -class DiskCaddy -{ -public: - DiskCaddy() - : selectedIndex(0) - , screen(0) - , screenLCD(0) - { - } - - void SetScreen(Screen* screen, ScreenBase* screenLCD) { this->screen = screen; this->screenLCD = screenLCD; } - - bool Empty(); - - bool Insert(const FILINFO* fileInfo, bool readOnly); - - DiskImage* GetCurrentDisk() - { - if (selectedIndex < disks.size()) - return &disks[selectedIndex]; - - return 0; - } - - DiskImage* NextDisk() - { - selectedIndex = (selectedIndex + 1) % (u32)disks.size(); - return GetCurrentDisk(); - } - - DiskImage* PrevDisk() - { - --selectedIndex; - if ((int)selectedIndex < 0) - selectedIndex += (u32)disks.size(); - return GetCurrentDisk(); - } - - u32 GetNumberOfImages() const { return disks.size(); } - u32 GetSelectedIndex() const { return selectedIndex; } - - DiskImage* GetImage(unsigned index) { return &disks[index]; } - DiskImage* SelectImage(unsigned index) - { - if (selectedIndex != index && index < disks.size()) - { - selectedIndex = index; - return GetCurrentDisk(); - } - return 0; - } - DiskImage* SelectFirstImage() - { - if (disks.size()) - { - selectedIndex = 0; - return GetCurrentDisk(); - } - return 0; - } - - void Display(); - bool Update(); - -private: - bool InsertD64(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly); - bool InsertG64(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly); - bool InsertNIB(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly); - bool InsertNBZ(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly); - bool InsertD81(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly); - - void ShowSelectedImage(u32 index); - - std::vector disks; - u32 selectedIndex; - u32 oldCaddyIndex; - - Screen* screen; - ScreenBase* screenLCD; -}; - +// Pi1541 - A Commodore 1541 disk drive emulator +// Copyright(C) 2018 Stephen White +// +// This file is part of Pi1541. +// +// Pi1541 is free software : you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Pi1541 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Pi1541. If not, see . + +#ifndef DISKCADDY_H +#define DISKCADDY_H + +#include +#include "DiskImage.h" +#include "Screen.h" + +class DiskCaddy +{ +public: + DiskCaddy() + : selectedIndex(0) + , screen(0) + , screenLCD(0) + { + } + + void SetScreen(Screen* screen, ScreenBase* screenLCD) { this->screen = screen; this->screenLCD = screenLCD; } + + bool Empty(); + + bool Insert(const FILINFO* fileInfo, bool readOnly); + + DiskImage* GetCurrentDisk() + { + if (selectedIndex < disks.size()) + return &disks[selectedIndex]; + + return 0; + } + + DiskImage* NextDisk() + { + selectedIndex = (selectedIndex + 1) % (u32)disks.size(); + return GetCurrentDisk(); + } + + DiskImage* PrevDisk() + { + --selectedIndex; + if ((int)selectedIndex < 0) + selectedIndex += (u32)disks.size(); + return GetCurrentDisk(); + } + + u32 GetNumberOfImages() const { return disks.size(); } + u32 GetSelectedIndex() const { return selectedIndex; } + + DiskImage* GetImage(unsigned index) { return &disks[index]; } + DiskImage* SelectImage(unsigned index) + { + if (selectedIndex != index && index < disks.size()) + { + selectedIndex = index; + return GetCurrentDisk(); + } + return 0; + } + DiskImage* SelectFirstImage() + { + if (disks.size()) + { + selectedIndex = 0; + return GetCurrentDisk(); + } + return 0; + } + + void Display(); + bool Update(); + +private: + bool InsertD64(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly); + bool InsertG64(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly); + bool InsertNIB(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly); + bool InsertNBZ(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly); + bool InsertD81(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly); + + void ShowSelectedImage(u32 index); + + std::vector disks; + u32 selectedIndex; + u32 oldCaddyIndex; + + ScreenBase* screen; + ScreenBase* screenLCD; +}; + #endif \ No newline at end of file diff --git a/src/FileBrowser.cpp b/src/FileBrowser.cpp index 12a9880..e84dfc0 100644 --- a/src/FileBrowser.cpp +++ b/src/FileBrowser.cpp @@ -181,7 +181,7 @@ void FileBrowser::BrowsableListView::Refresh() entryIndex = offset + index; RefreshLine(entryIndex, x, y, /*showSelected && */list->currentIndex == entryIndex); - y += 16; + y += screen->GetFontHeight (); } screen->SwapBuffers(); @@ -248,7 +248,7 @@ void FileBrowser::BrowsableListView::RefreshHighlightScroll() int rowIndex = list->currentIndex - offset; u32 y = positionY; - y += rowIndex * 16; + y += rowIndex * screen->GetFontHeight (); RefreshLine(list->currentIndex, 0, y, true); diff --git a/src/ScreenLCD.cpp b/src/ScreenLCD.cpp index 32a4659..23a918b 100644 --- a/src/ScreenLCD.cpp +++ b/src/ScreenLCD.cpp @@ -1,152 +1,152 @@ -// Pi1541 - A Commodore 1541 disk drive emulator -// Copyright(C) 2018 Stephen White -// -// This file is part of Pi1541. -// -// Pi1541 is free software : you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Pi1541 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Pi1541. If not, see . - -#include "ScreenLCD.h" -#include -#include -#include -#include "debug.h" -#include "ssd_logo.h" - -extern unsigned char* CBMFont; - -void ScreenLCD::Open(u32 widthDesired, u32 heightDesired, u32 colourDepth, int BSCMaster, int LCDAddress, int LCDFlip, LCD_MODEL LCDType, bool luseCBMFont) -{ - bpp = 1; - - if (widthDesired < 128) - widthDesired = 128; - if (heightDesired < 32) - heightDesired = 32; - if (widthDesired > 128) - widthDesired = 128; - if (heightDesired > 64) - heightDesired = 64; - - width = widthDesired; - height = heightDesired; - useCBMFont = luseCBMFont; - - ssd1306 = new SSD1306(BSCMaster, LCDAddress, width, height, LCDFlip, LCDType); - ssd1306->ClearScreen(); - ssd1306->RefreshScreen(); - ssd1306->DisplayOn(); - - opened = true; -} - -void ScreenLCD::DrawRectangle(u32 x1, u32 y1, u32 x2, u32 y2, RGBA colour) -{ - ClipRect(x1, y1, x2, y2); -} - -void ScreenLCD::ScrollArea(u32 x1, u32 y1, u32 x2, u32 y2) -{ -} - -void ScreenLCD::Clear(RGBA colour) -{ - ssd1306->ClearScreen(); -} - -void ScreenLCD::ClearInit(RGBA colour) -{ - ssd1306->InitHardware(); - ssd1306->ClearScreen(); - ssd1306->SetContrast(ssd1306->GetContrast()); - ssd1306->DisplayOn(); -} - -void ScreenLCD::SetContrast(u8 value) -{ - ssd1306->SetContrast(value); -} - -void ScreenLCD::WriteChar(bool petscii, u32 x, u32 y, unsigned char c, RGBA colour) -{ - if (opened) - { - } -} - -void ScreenLCD::PlotPixel(u32 x, u32 y, RGBA colour) -{ -} - -void ScreenLCD::PlotImage(u32* image, int x, int y, int w, int h) -{ -} - -void ScreenLCD::PlotRawImage(const u8* image, int x, int y, int w, int h) -{ - if (x==0 && y==0 && w==128 && h==64) - { - ssd1306->PlotImage(image); - } -} - -u32 ScreenLCD::PrintText(bool petscii, u32 x, u32 y, char *ptr, RGBA TxtColour, RGBA BkColour, bool measureOnly, u32* width, u32* height) -{ - int len = 0; - ssd1306->PlotText(UseCBMFont(), petscii, x >> 3, y >> 4, ptr, (BkColour & 0xffffff) != 0); - return len; -} - -u32 ScreenLCD::MeasureText(bool petscii, char *ptr, u32* width, u32* height) -{ - return PrintText(petscii, 0, 0, ptr, 0, 0, true, width, height); -} - -u32 ScreenLCD::GetFontHeight() -{ - if (CBMFont && useCBMFont) - return 8; - else - return 16; -} - -void ScreenLCD::RefreshScreen() -{ - ssd1306->RefreshScreen(); -} - -void ScreenLCD::SwapBuffers() -{ - ssd1306->RefreshScreen(); -} - -void ScreenLCD::RefreshRows(u32 start, u32 amountOfRows) -{ - if (ssd1306) - { - if (UseCBMFont()) - ssd1306->RefreshTextRows(start, amountOfRows); - else - ssd1306->RefreshTextRows(start*2, amountOfRows*2); - } -} - -bool ScreenLCD::IsLCD() -{ - return true; -} - -bool ScreenLCD::UseCBMFont() -{ - return (CBMFont && useCBMFont); +// Pi1541 - A Commodore 1541 disk drive emulator +// Copyright(C) 2018 Stephen White +// +// This file is part of Pi1541. +// +// Pi1541 is free software : you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Pi1541 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Pi1541. If not, see . + +#include "ScreenLCD.h" +#include +#include +#include +#include "debug.h" +#include "ssd_logo.h" + +extern unsigned char* CBMFont; + +void ScreenLCD::Open(u32 widthDesired, u32 heightDesired, u32 colourDepth, int BSCMaster, int LCDAddress, int LCDFlip, LCD_MODEL LCDType, bool luseCBMFont) +{ + bpp = 1; + + if (widthDesired < 128) + widthDesired = 128; + if (heightDesired < 32) + heightDesired = 32; + if (widthDesired > 128) + widthDesired = 128; + if (heightDesired > 64) + heightDesired = 64; + + width = widthDesired; + height = heightDesired; + useCBMFont = luseCBMFont; + + ssd1306 = new SSD1306(BSCMaster, LCDAddress, width, height, LCDFlip, LCDType); + ssd1306->ClearScreen(); + ssd1306->RefreshScreen(); + ssd1306->DisplayOn(); + + opened = true; +} + +void ScreenLCD::DrawRectangle(u32 x1, u32 y1, u32 x2, u32 y2, RGBA colour) +{ + ClipRect(x1, y1, x2, y2); +} + +void ScreenLCD::ScrollArea(u32 x1, u32 y1, u32 x2, u32 y2) +{ +} + +void ScreenLCD::Clear(RGBA colour) +{ + ssd1306->ClearScreen(); +} + +void ScreenLCD::ClearInit(RGBA colour) +{ + ssd1306->InitHardware(); + ssd1306->ClearScreen(); + ssd1306->SetContrast(ssd1306->GetContrast()); + ssd1306->DisplayOn(); +} + +void ScreenLCD::SetContrast(u8 value) +{ + ssd1306->SetContrast(value); +} + +void ScreenLCD::WriteChar(bool petscii, u32 x, u32 y, unsigned char c, RGBA colour) +{ + if (opened) + { + } +} + +void ScreenLCD::PlotPixel(u32 x, u32 y, RGBA colour) +{ +} + +void ScreenLCD::PlotImage(u32* image, int x, int y, int w, int h) +{ +} + +void ScreenLCD::PlotRawImage(const u8* image, int x, int y, int w, int h) +{ + if (x==0 && y==0 && w==128 && h==64) + { + ssd1306->PlotImage(image); + } +} + +u32 ScreenLCD::PrintText(bool petscii, u32 x, u32 y, char *ptr, RGBA TxtColour, RGBA BkColour, bool measureOnly, u32* width, u32* height) +{ + int len = 0; + ssd1306->PlotText(UseCBMFont(), petscii, x >> 3, y / GetFontHeight (), ptr, (BkColour & 0xffffff) != 0); + return len; +} + +u32 ScreenLCD::MeasureText(bool petscii, char *ptr, u32* width, u32* height) +{ + return PrintText(petscii, 0, 0, ptr, 0, 0, true, width, height); +} + +u32 ScreenLCD::GetFontHeight() +{ + if (CBMFont && useCBMFont) + return 8; + else + return 16; +} + +void ScreenLCD::RefreshScreen() +{ + ssd1306->RefreshScreen(); +} + +void ScreenLCD::SwapBuffers() +{ + ssd1306->RefreshScreen(); +} + +void ScreenLCD::RefreshRows(u32 start, u32 amountOfRows) +{ + if (ssd1306) + { + if (UseCBMFont()) + ssd1306->RefreshTextRows(start, amountOfRows); + else + ssd1306->RefreshTextRows(start*2, amountOfRows*2); + } +} + +bool ScreenLCD::IsLCD() +{ + return true; +} + +bool ScreenLCD::UseCBMFont() +{ + return (CBMFont && useCBMFont); } \ No newline at end of file