diff --git a/src/DiskCaddy.cpp b/src/DiskCaddy.cpp index e5998cc..e6ea56b 100644 --- a/src/DiskCaddy.cpp +++ b/src/DiskCaddy.cpp @@ -41,10 +41,11 @@ bool DiskCaddy::Insert(const FILINFO* fileInfo, bool readOnly) { if (screen) { - int y = screenPosYCaddySelections; + int x = screen->ScaleX(screenPosXCaddySelections); + int y = screen->ScaleY(screenPosYCaddySelections); snprintf(buffer, 256, "Loading %s\r\n", fileInfo->fname); - screen->PrintText(false, screenPosXCaddySelections, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), red); + screen->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), red); } u32 bytesRead; @@ -149,10 +150,11 @@ void DiskCaddy::Display() { unsigned numberOfImages = GetNumberOfImages(); unsigned caddyIndex; - int y = screenPosYCaddySelections; + int x = screen->ScaleX(screenPosXCaddySelections); + int y = screen->ScaleY(screenPosYCaddySelections); snprintf(buffer, 256, "Emulating\r\n"); - screen->PrintText(false, screenPosXCaddySelections, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), red); + screen->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), red); y += 16; for (caddyIndex = 0; caddyIndex < numberOfImages; ++caddyIndex) @@ -162,7 +164,7 @@ void DiskCaddy::Display() if (name) { snprintf(buffer, 256, "%d %s\r\n", caddyIndex + 1, name); - screen->PrintText(false, screenPosXCaddySelections, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), red); + screen->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), red); y += 16; } } @@ -173,8 +175,8 @@ void DiskCaddy::Display() void DiskCaddy::ShowSelectedImage(u32 index) { - u32 x = screenPosXCaddySelections - 16; - u32 y = screenPosYCaddySelections + 16 + 16 * index; + u32 x = screen->ScaleX(screenPosXCaddySelections) - 16; + u32 y = screen->ScaleY(screenPosYCaddySelections) + 16 + 16 * index; snprintf(buffer, 256, "*"); screen->PrintText(false, x, y, buffer, white, red); } @@ -188,8 +190,8 @@ bool DiskCaddy::Update() { if (screen) { - x = screenPosXCaddySelections - 16; - y = screenPosYCaddySelections + 16 + 16 * oldCaddyIndex; + x = screen->ScaleX(screenPosXCaddySelections) - 16; + y = screen->ScaleY(screenPosYCaddySelections) + 16 + 16 * oldCaddyIndex; snprintf(buffer, 256, " "); screen->PrintText(false, x, y, buffer, red, red); oldCaddyIndex = caddyIndex; diff --git a/src/FileBrowser.cpp b/src/FileBrowser.cpp index 123637a..9ea5bbb 100644 --- a/src/FileBrowser.cpp +++ b/src/FileBrowser.cpp @@ -98,6 +98,9 @@ FileBrowser::FileBrowser(DiskCaddy* diskCaddy, ROMs* roms, unsigned deviceID, bo , deviceID(deviceID) , displayPNGIcons(displayPNGIcons) { + maxOnScreen = (int)(38.0f * screen.GetScaleY()); + if (maxOnScreen < 1) + maxOnScreen = 1; } u32 FileBrowser::Colour(int index) @@ -216,6 +219,8 @@ void FileBrowser::RefeshDisplayForBrowsableList(FileBrowser::BrowsableList* brow if (terminal) printf("\E[2J\E[f"); + u32 maxCharacters = screen.ScaleX(80); + for (index = 0; index < maxOnScreen; ++index) { entryIndex = browsableList->offset + index; @@ -223,8 +228,8 @@ void FileBrowser::RefeshDisplayForBrowsableList(FileBrowser::BrowsableList* brow if (entryIndex < browsableList->entries.size()) { FileBrowser::BrowsableList::Entry* entry = &browsableList->entries[entryIndex]; - snprintf(buffer2, 81, "%s", entry->filImage.fname); - memset(buffer1, ' ', 80); + snprintf(buffer2, maxCharacters + 1, "%s", entry->filImage.fname); + memset(buffer1, ' ', maxCharacters); buffer1[127] = 0; strncpy(buffer1, buffer2, strlen(buffer2)); if (showSelected && browsableList->currentIndex == entryIndex) @@ -288,8 +293,9 @@ void FileBrowser::RefeshDisplay() screen.PrintText(false, 0, 0, buffer, textColour, bgColour); } + u32 offsetX = screen.ScaleX(1024 - 320); RefeshDisplayForBrowsableList(&folder, 0); - RefeshDisplayForBrowsableList(&caddySelections, 1024 - 320, false); + RefeshDisplayForBrowsableList(&caddySelections, offsetX, false); DisplayPNG(); DisplayStatusBar(); @@ -362,7 +368,9 @@ void FileBrowser::DisplayPNG() if (displayPNGIcons && folder.current) { FileBrowser::BrowsableList::Entry* current = folder.current; - DisplayPNG(current->filIcon, 1024 - 320, 426); + u32 x = screen.ScaleX(1024 - 320); + u32 y = screen.ScaleY(666) - 240; + DisplayPNG(current->filIcon, x, y); } } @@ -709,7 +717,7 @@ void FileBrowser::UpdateInputDiskCaddy() void FileBrowser::DisplayStatusBar() { u32 x = 0; - u32 y = STATUS_BAR_POSITION_Y; + u32 y = screen.ScaleY(STATUS_BAR_POSITION_Y); char bufferOut[128]; snprintf(bufferOut, 256, "LED 0 Motor 0 Track 00.0 ATN 0 DAT 0 CLK 0"); @@ -727,7 +735,7 @@ void FileBrowser::ShowDeviceAndROM() char buffer[256]; u32 textColour = RGBA(0, 0, 0, 0xff); u32 bgColour = RGBA(0xff, 0xff, 0xff, 0xff); - u32 y = STATUS_BAR_POSITION_Y; + u32 y = screen.ScaleY(STATUS_BAR_POSITION_Y); snprintf(buffer, 256, "Device %d %s \r\n", deviceID, roms->ROMNames[roms->currentROMIndex]); screen.PrintText(false, 43 * 8, y, buffer, textColour, bgColour); @@ -755,6 +763,7 @@ void FileBrowser::DisplayDiskInfo(DiskImage* diskImage, const char* filenameForI u32 usedColour = palette[VIC2_COLOUR_INDEX_RED]; u32 freeColour = palette[VIC2_COLOUR_INDEX_LGREEN]; + u32 BAMOffsetX = screen.ScaleX(400); ClearScreen(); @@ -780,7 +789,7 @@ void FileBrowser::DisplayDiskInfo(DiskImage* diskImage, const char* filenameForI if ((bamTrack + 1) != 18) blocksFree += buffer[BAM_OFFSET + bamTrack * BAM_ENTRY_SIZE]; - x = 400; + x = BAMOffsetX; for (int bit = 0; bit < DiskImage::SectorsPerTrack[bamTrack]; bit++) { u32 bits = buffer[BAM_OFFSET + 1 + (bit >> 3) + bamTrack * BAM_ENTRY_SIZE]; @@ -803,7 +812,7 @@ void FileBrowser::DisplayDiskInfo(DiskImage* diskImage, const char* filenameForI } for (; bamTrack < lastTrackUsed; ++bamTrack) { - x = 400; + x = BAMOffsetX; for (int bit = 0; bit < DiskImage::SectorsPerTrack[bamTrack]; bit++) { snprintf(bufferOut, 128, "%c", screen2petscii(87)); @@ -904,7 +913,11 @@ void FileBrowser::DisplayDiskInfo(DiskImage* diskImage, const char* filenameForI { FILINFO filIcon; if (CheckForPNG(filenameForIcon, filIcon)) - DisplayPNG(filIcon, 1024 - 320, 0); + { + x = screen.ScaleX(1024) - 320; + y = screen.ScaleY(0); + DisplayPNG(filIcon, x, y); + } } } diff --git a/src/Screen.cpp b/src/Screen.cpp index 7e881f9..d5564b6 100644 --- a/src/Screen.cpp +++ b/src/Screen.cpp @@ -41,11 +41,23 @@ static const int BitFontWth = 8; void Screen::Open(u32 widthDesired, u32 heightDesired, u32 colourDepth) { + if (widthDesired < 320) + widthDesired = 320; + if (heightDesired < 240) + heightDesired = 240; + if (widthDesired > 1024) + widthDesired = 1024; + if (heightDesired > 720) + heightDesired = 720; + rpi_mailbox_property_t* mp; //int width = 0; //int height = 0; //int depth = 0; + scaleX = (float)widthDesired / 1024.0f; + scaleY = (float)heightDesired / 768.0f; + RPI_PropertyInit(); RPI_PropertyAddTag(TAG_GET_PHYSICAL_SIZE); RPI_PropertyAddTag(TAG_GET_VIRTUAL_SIZE); @@ -230,7 +242,7 @@ void Screen::WriteChar(bool petscii, u32 x, u32 y, unsigned char c, RGBA colour) int yoffs = (y + py) * pitch; for (int px = 0; px < 8; ++px) { - if (x + px > width) + if (x + px >= width) continue; int pixel_offset = ((px + x) * (bpp >> 3)) + yoffs; @@ -244,6 +256,8 @@ void Screen::WriteChar(bool petscii, u32 x, u32 y, unsigned char c, RGBA colour) void Screen::PlotPixel(u32 x, u32 y, RGBA colour) { + if (x < 0 || y < 0 || x >= width || y >= height) + return; int pixel_offset = (x * (bpp >> 3)) + (y * pitch); (this->*Screen::plotPixelFn)(pixel_offset, colour); } diff --git a/src/Screen.h b/src/Screen.h index c64fbbf..9655e9f 100644 --- a/src/Screen.h +++ b/src/Screen.h @@ -66,6 +66,12 @@ public: u32 GetCBMFontHeight(); + float GetScaleX() const { return scaleX; } + float GetScaleY() const { return scaleY; } + + u32 ScaleX(u32 x) { return (u32)((float)x * scaleX); } + u32 ScaleY(u32 y) { return (u32)((float)y * scaleY); } + private: typedef void (Screen::*PlotPixelFunction)(u32 pixel_offset, RGBA Colour); @@ -85,6 +91,9 @@ private: u32 bpp; u32 pitch; volatile u8* framebuffer; + + float scaleX; + float scaleY; }; #endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 73c17df..c7e9c71 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -84,6 +84,7 @@ DiskCaddy diskCaddy; Pi1541 pi1541; CEMMCDevice m_EMMC; Screen screen; +Options options; const char* fileBrowserSelectedName; u8 deviceID = 8; IEC_Commands m_IEC_Commands; @@ -99,6 +100,8 @@ bool invertIECInputs = false; bool invertIECOutputs = true; bool splitIECLines = false; bool ignoreReset = false; +unsigned int screenWidth = 1024; +unsigned int screenHeight = 768; const char* termainalTextRed = "\E[31m"; const char* termainalTextNormal = "\E[0m"; @@ -279,7 +282,7 @@ void InitialiseHardware() #endif RPI_AuxMiniUartInit(115200, 8); - screen.Open(1024, 768, 16); + screen.Open(screenWidth, screenHeight, 16); RPI_PropertyInit(); RPI_PropertyAddTag(TAG_GET_MAX_CLOCK_RATE, ARM_CLK_ID); @@ -326,9 +329,9 @@ void UpdateScreen() RGBA atnColour = COLOUR_YELLOW; RGBA BkColour = FileBrowser::Colour(VIC2_COLOUR_INDEX_BLUE); - int height = 60; - int screenHeight = 768; - int screenWidthM1 = 1023; + int height = screen.ScaleY(60); + int screenHeight = screen.Height(); + int screenWidthM1 = screen.Width() - 1; int top, top2, top3; int bottom; int graphX = 0; @@ -343,7 +346,7 @@ void UpdateScreen() while (1) { bool value; - u32 y = STATUS_BAR_POSITION_Y; + u32 y = screen.ScaleY(STATUS_BAR_POSITION_Y); //RPI_UpdateTouch(); //refreshUartStatusDisplay = false; @@ -923,11 +926,6 @@ static void LoadOptions() { FIL fp; FRESULT res; - u32 widthText, heightText; - u32 widthScreen = screen.Width(); - u32 heightScreen = screen.Height(); - u32 xpos, ypos; - const char* ROMName; res = f_open(&fp, "options.txt", FA_READ); if (res == FR_OK) @@ -938,36 +936,83 @@ static void LoadOptions() SetACTLed(false); f_close(&fp); - Options options; - options.Process((char*)tempBuffer); - deviceID = (u8)options.GetDeviceID(); - DEBUG_LOG("DeviceID = %d\r\n", deviceID); + screenWidth = options.ScreenWidth(); + screenHeight = options.ScreenHeight(); + } +} - onResetChangeToStartingFolder = options.GetOnResetChangeToStartingFolder() != 0; - DEBUG_LOG("onResetChangeToStartingFolder = %d\r\n", onResetChangeToStartingFolder); +static void CheckOptions() +{ + FIL fp; + FRESULT res; - extraRAM = options.GetExtraRAM() != 0; - DEBUG_LOG("extraRAM = %d\r\n", extraRAM); + u32 widthText, heightText; + u32 widthScreen = screen.Width(); + u32 heightScreen = screen.Height(); + u32 xpos, ypos; + const char* ROMName; - disableSD2IECCommands = options.GetDisableSD2IECCommands(); - //supportUARTInput = options.GetSupportUARTInput() != 0; - graphIEC = options.GraphIEC(); + deviceID = (u8)options.GetDeviceID(); + DEBUG_LOG("DeviceID = %d\r\n", deviceID); - quickBoot = options.QuickBoot(); + onResetChangeToStartingFolder = options.GetOnResetChangeToStartingFolder() != 0; + DEBUG_LOG("onResetChangeToStartingFolder = %d\r\n", onResetChangeToStartingFolder); - displayPNGIcons = options.DisplayPNGIcons(); - soundOnGPIO = options.SoundOnGPIO(); - invertIECInputs = options.InvertIECInputs(); - invertIECOutputs = options.InvertIECOutputs(); - splitIECLines = options.SplitIECLines(); - if (!splitIECLines) - invertIECInputs = false; - ignoreReset = options.IgnoreReset(); + extraRAM = options.GetExtraRAM() != 0; + DEBUG_LOG("extraRAM = %d\r\n", extraRAM); - ROMName = options.GetRomFontName(); - if (ROMName) + disableSD2IECCommands = options.GetDisableSD2IECCommands(); + //supportUARTInput = options.GetSupportUARTInput() != 0; + graphIEC = options.GraphIEC(); + + quickBoot = options.QuickBoot(); + + displayPNGIcons = options.DisplayPNGIcons(); + soundOnGPIO = options.SoundOnGPIO(); + invertIECInputs = options.InvertIECInputs(); + invertIECOutputs = options.InvertIECOutputs(); + splitIECLines = options.SplitIECLines(); + if (!splitIECLines) + invertIECInputs = false; + ignoreReset = options.IgnoreReset(); + + ROMName = options.GetRomFontName(); + if (ROMName) + { + //DEBUG_LOG("%d Rom Name = %s\r\n", ROMIndex, ROMName); + res = f_open(&fp, ROMName, FA_READ); + if (res == FR_OK) + { + u32 bytesRead; + + screen.Clear(COLOUR_BLACK); + snprintf(tempBuffer, tempBufferSize, "Loading ROM %s\r\n", ROMName); + screen.MeasureText(false, tempBuffer, &widthText, &heightText); + xpos = (widthScreen - widthText) >> 1; + ypos = (heightScreen - heightText) >> 1; + screen.PrintText(false, xpos, ypos, tempBuffer, COLOUR_WHITE, COLOUR_RED); + + SetACTLed(true); + res = f_read(&fp, CBMFontData, CBMFont_size, &bytesRead); + SetACTLed(false); + f_close(&fp); + if (res == FR_OK && bytesRead == CBMFont_size) + { + CBMFont = CBMFontData; + } + //DEBUG_LOG("Read ROM %s from options\r\n", ROMName); + } + } + + int ROMIndex; + + for (ROMIndex = ROMs::MAX_ROMS - 1; ROMIndex >= 0; --ROMIndex) + { + roms.ROMValid[ROMIndex] = false; + const char* ROMName = options.GetRomName(ROMIndex); + if (ROMName[0]) { //DEBUG_LOG("%d Rom Name = %s\r\n", ROMIndex, ROMName); res = f_open(&fp, ROMName, FA_READ); @@ -983,67 +1028,33 @@ static void LoadOptions() screen.PrintText(false, xpos, ypos, tempBuffer, COLOUR_WHITE, COLOUR_RED); SetACTLed(true); - res = f_read(&fp, CBMFontData, CBMFont_size, &bytesRead); + res = f_read(&fp, roms.ROMImages[ROMIndex], ROMs::ROM_SIZE, &bytesRead); SetACTLed(false); - f_close(&fp); - if (res == FR_OK && bytesRead == CBMFont_size) + if (res == FR_OK && bytesRead == ROMs::ROM_SIZE) { - CBMFont = CBMFontData; + strncpy(roms.ROMNames[ROMIndex], ROMName, 255); + roms.ROMValid[ROMIndex] = true; } + f_close(&fp); //DEBUG_LOG("Read ROM %s from options\r\n", ROMName); } } + } - int ROMIndex; - - for (ROMIndex = ROMs::MAX_ROMS - 1; ROMIndex >= 0; --ROMIndex) + if (roms.ROMValid[0] == false && !(AttemptToLoadROM("d1541.rom") || AttemptToLoadROM("dos1541") || AttemptToLoadROM("d1541II") || AttemptToLoadROM("Jiffy.bin"))) + { + snprintf(tempBuffer, tempBufferSize, "No ROM file found!\r\nPlease copy a valid 1541 ROM file in the root folder of the SD card.\r\nThe file needs to be called 'dos1541'."); + screen.MeasureText(false, tempBuffer, &widthText, &heightText); + xpos = (widthScreen - widthText) >> 1; + ypos = (heightScreen - heightText) >> 1; + do { - roms.ROMValid[ROMIndex] = false; - const char* ROMName = options.GetRomName(ROMIndex); - if (ROMName[0]) - { - //DEBUG_LOG("%d Rom Name = %s\r\n", ROMIndex, ROMName); - res = f_open(&fp, ROMName, FA_READ); - if (res == FR_OK) - { - u32 bytesRead; - - screen.Clear(COLOUR_BLACK); - snprintf(tempBuffer, tempBufferSize, "Loading ROM %s\r\n", ROMName); - screen.MeasureText(false, tempBuffer, &widthText, &heightText); - xpos = (widthScreen - widthText) >> 1; - ypos = (heightScreen - heightText) >> 1; - screen.PrintText(false, xpos, ypos, tempBuffer, COLOUR_WHITE, COLOUR_RED); - - SetACTLed(true); - res = f_read(&fp, roms.ROMImages[ROMIndex], ROMs::ROM_SIZE, &bytesRead); - SetACTLed(false); - if (res == FR_OK && bytesRead == ROMs::ROM_SIZE) - { - strncpy(roms.ROMNames[ROMIndex], ROMName, 255); - roms.ROMValid[ROMIndex] = true; - } - f_close(&fp); - //DEBUG_LOG("Read ROM %s from options\r\n", ROMName); - } - } - } - - if (roms.ROMValid[0] == false && !(AttemptToLoadROM("d1541.rom") || AttemptToLoadROM("dos1541") || AttemptToLoadROM("d1541II") || AttemptToLoadROM("Jiffy.bin"))) - { - snprintf(tempBuffer, tempBufferSize, "No ROM file found!\r\nPlease copy a valid 1541 ROM file in the root folder of the SD card.\r\nThe file needs to be called 'dos1541'."); - screen.MeasureText(false, tempBuffer, &widthText, &heightText); - xpos = (widthScreen - widthText) >> 1; - ypos = (heightScreen - heightText) >> 1; - do - { - screen.Clear(COLOUR_RED); - IEC_Bus::WaitMicroSeconds(20000); - screen.PrintText(false, xpos, ypos, tempBuffer, COLOUR_WHITE, COLOUR_RED); - IEC_Bus::WaitMicroSeconds(100000); - } - while (1); + screen.Clear(COLOUR_RED); + IEC_Bus::WaitMicroSeconds(20000); + screen.PrintText(false, xpos, ypos, tempBuffer, COLOUR_WHITE, COLOUR_RED); + IEC_Bus::WaitMicroSeconds(100000); } + while (1); } } @@ -1053,16 +1064,18 @@ extern "C" { FATFS fileSystem; + disk_setEMM(&m_EMMC); + m_EMMC.Initialize(); + f_mount(&fileSystem, "", 1); + + LoadOptions(); + InitialiseHardware(); enable_MMU_and_IDCaches(); _enable_unaligned_access(); - disk_setEMM(&m_EMMC); - m_EMMC.Initialize(); write32(ARM_GPIO_GPCLR0, 0xFFFFFFFF); - f_mount(&fileSystem, "", 1); - DisplayLogo(); snprintf(tempBuffer, tempBufferSize, "Copyright(C) 2018 Stephen White"); screen.PrintText(false, 0, 200, tempBuffer, COLOUR_WHITE, COLOUR_BLACK); @@ -1095,7 +1108,7 @@ extern "C" onResetChangeToStartingFolder = false; - LoadOptions(); + CheckOptions(); IEC_Bus::SetSplitIECLines(splitIECLines); IEC_Bus::SetInvertIECInputs(invertIECInputs); @@ -1139,24 +1152,3 @@ extern "C" #endif } } - - -// Del everything in the Z:\MonCog\Builds folder -// Build a WegGL build into Z:\MonCog\Builds -// open cmd -// cd Z:\MonCog\firebase -// firebase init -// Y -// Hosting etc -// type "public" -// N -// overwrite 404 - N -// overwrite index - N -// Copy over new files -// firebase deploy - -// Eject delays -// Remove asm commeted code from IEC_Bus -// TO CHECKs -// types -// TDOO: need to display the image names as they write back \ No newline at end of file diff --git a/src/options.cpp b/src/options.cpp index 53988ab..9fb1b82 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -132,6 +132,8 @@ Options::Options(void) , invertIECOutputs(1) , splitIECLines(0) , ignoreReset(0) + , screenWidth(1024) + , screenHeight(768) { strcpy(ROMFontName, "chargen"); ROMName[0] = 0; @@ -232,6 +234,18 @@ void Options::Process(char* buffer) if ((nValue = GetDecimal(pValue)) != INVALID_VALUE) ignoreReset = nValue; } + else if (strcasecmp(pOption, "screenWidth") == 0) + { + unsigned nValue = 0; + if ((nValue = GetDecimal(pValue)) != INVALID_VALUE) + screenWidth = nValue; + } + else if (strcasecmp(pOption, "screenHeight") == 0) + { + unsigned nValue = 0; + if ((nValue = GetDecimal(pValue)) != INVALID_VALUE) + screenHeight = nValue; + } else if ((strcasecmp(pOption, "Font") == 0)) { strncpy(ROMFontName, pValue, 255); diff --git a/src/options.h b/src/options.h index 2d620b3..879b138 100644 --- a/src/options.h +++ b/src/options.h @@ -61,6 +61,9 @@ public: unsigned int InvertIECOutputs() const { return invertIECOutputs; } unsigned int IgnoreReset() const { return ignoreReset; } + unsigned int ScreenWidth() const { return screenWidth; } + unsigned int ScreenHeight() const { return screenHeight; } + static unsigned GetDecimal(char* pString); private: @@ -78,6 +81,9 @@ private: unsigned int splitIECLines; unsigned int ignoreReset; + unsigned int screenWidth; + unsigned int screenHeight; + char ROMFontName[256]; char ROMName[256]; char ROMNameSlot2[256];