From 77dec203477d9fbe6520c1f50ee681ab2a9f60f4 Mon Sep 17 00:00:00 2001 From: Stephen White Date: Sun, 22 Jul 2018 15:19:58 +1000 Subject: [PATCH 1/9] Fixed compatability problem with CaliforniaGames CaliforniaGames does not like being started with the heads directly over track 18.0. --- src/Drive.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Drive.cpp b/src/Drive.cpp index 23f902c..c3942b3 100644 --- a/src/Drive.cpp +++ b/src/Drive.cpp @@ -352,7 +352,7 @@ Drive::Drive() : m_pVIA(0) void Drive::Reset() { - headTrackPos = 34; // Start with the head over track 18 + headTrackPos = 0; // Start with the head over track 19 (Very later Vorpal ie Cakifornia Games) need to have had the last head movement -ve CLOCK_SEL_AB = 3; // Track 18 will use speed zone 3 (encoder/decoder (ie UE7Counter) clocked at 1.2307Mhz) UpdateHeadSectorPosition(); lastHeadDirection = 0; @@ -390,8 +390,9 @@ void Drive::DumpTrack(unsigned track) void Drive::OnPortOut(void* pThis, unsigned char status) { Drive* pDrive = (Drive*)pThis; + if (pDrive->motor) + pDrive->MoveHead(status & 3); pDrive->motor = (status & 4) != 0; - pDrive->MoveHead(status & 3); pDrive->CLOCK_SEL_AB = ((status >> 5) & 3); pDrive->LED = (status & 8) != 0; } From 70fddc97c5b0315a99bcc1289d067c6f1c1b5060 Mon Sep 17 00:00:00 2001 From: Stephen White Date: Sun, 22 Jul 2018 18:43:08 +1000 Subject: [PATCH 2/9] Button 5 can be used to change device ID. Whilst in browse mode, holding button 5 (ie Insert) and pressing one of the other buttons will change the device ID. Button 1 = 8, 2 = 9, 3 = 10 and 4 = 11. --- src/FileBrowser.cpp | 260 ++++++++++++++++++++++++------------------ src/FileBrowser.h | 1 + src/InputMappings.cpp | 9 +- src/InputMappings.h | 3 + 4 files changed, 162 insertions(+), 111 deletions(-) diff --git a/src/FileBrowser.cpp b/src/FileBrowser.cpp index 739c8da..3e92ce5 100644 --- a/src/FileBrowser.cpp +++ b/src/FileBrowser.cpp @@ -385,6 +385,7 @@ FileBrowser::FileBrowser(DiskCaddy* diskCaddy, ROMs* roms, u8* deviceID, bool di , roms(roms) , deviceID(deviceID) , displayPNGIcons(displayPNGIcons) + , buttonChangedDevice(false) , screenMain(screenMain) , screenLCD(screenLCD) , scrollHighlightRate(scrollHighlightRate) @@ -820,128 +821,167 @@ void FileBrowser::UpdateInputFolders() Keyboard* keyboard = Keyboard::Instance(); InputMappings* inputMappings = InputMappings::Instance(); - if (folder.entries.size() > 0) + if (IEC_Bus::GetInputButtonHeld(4)) { - //u32 numberOfEntriesMinus1 = folder.entries.size() - 1; - bool dirty = false; - if (inputMappings->BrowseSelect()) { - FileBrowser::BrowsableList::Entry* current = folder.current; - if (current) - { - if (current->filImage.fattrib & AM_DIR) - { - if (strcmp(current->filImage.fname, "..") == 0) - { - PopFolder(); - } - else if (strcmp(current->filImage.fname, ".") != 0) - { - f_chdir(current->filImage.fname); - RefreshFolderEntries(); - } - dirty = true; - } - else - { - if (strcmp(current->filImage.fname, "..") == 0) - { - PopFolder(); - } - else if (DiskImage::IsDiskImageExtention(current->filImage.fname)) - { - DiskImage::DiskType diskType = DiskImage::GetDiskImageTypeViaExtention(current->filImage.fname); - - // Should also be able to create a LST file from all the images currently selected in the caddy - if (diskType == DiskImage::LST) - { - selectionsMade = SelectLST(current->filImage.fname); - } - else - { - // Add the current selected - AddToCaddy(current); - selectionsMade = FillCaddyWithSelections(); - } - - if (selectionsMade) - lastSelectionName = current->filImage.fname; - - dirty = true; - } - } - } + DEBUG_LOG("DEv8\r\n"); + GlobalSetDeviceID(8); + ShowDeviceAndROM(); + buttonChangedDevice = true; } - else if (inputMappings->BrowseDone()) + else if (inputMappings->BrowseUp()) { - selectionsMade = FillCaddyWithSelections(); + DEBUG_LOG("DEv9\r\n"); + GlobalSetDeviceID(9); + ShowDeviceAndROM(); + buttonChangedDevice = true; + } + else if (inputMappings->BrowseDown()) + { + GlobalSetDeviceID(10); + ShowDeviceAndROM(); + buttonChangedDevice = true; } - //else if (keyboard->KeyPressed(KEY_TAB)) - //{ - // state = State_DiskCaddy; - // dirty = true; - //} else if (inputMappings->BrowseBack()) { - PopFolder(); - dirty = true; + GlobalSetDeviceID(11); + ShowDeviceAndROM(); + buttonChangedDevice = true; } - else if (inputMappings->Exit()) - { - ClearSelections(); - dirty = true; - } - else if (inputMappings->BrowseInsert()) - { - FileBrowser::BrowsableList::Entry* current = folder.current; - if (current) - { - dirty = AddToCaddy(current); - } - } - else if (inputMappings->BrowseNewD64()) - { - char newFileName[64]; - strncpy (newFileName, options.GetAutoBaseName(), 63); - int num = folder.FindNextAutoName( newFileName ); - m_IEC_Commands.CreateD64(newFileName, "42", true); - FolderChanged(); - } - else - { - unsigned keySetIndex; - for (keySetIndex = 0; keySetIndex < 11; ++keySetIndex) - { - unsigned keySetIndexBase = keySetIndex * 3; - if (keyboard->KeyPressed(FileBrowser::SwapKeys[keySetIndexBase]) - || keyboard->KeyPressed(FileBrowser::SwapKeys[keySetIndexBase + 1]) - || keyboard->KeyPressed(FileBrowser::SwapKeys[keySetIndexBase + 2])) - { - if ( (keySetIndex < ROMs::MAX_ROMS) && (roms->ROMValid[keySetIndex]) ) - { - roms->currentROMIndex = keySetIndex; - roms->lastManualSelectedROMIndex = keySetIndex; - DEBUG_LOG("Swap ROM %d %s\r\n", keySetIndex, roms->ROMNames[keySetIndex]); - ShowDeviceAndROM(); - } - else if ( (keySetIndex >= 7) && (keySetIndex <= 10 ) ) - { - GlobalSetDeviceID( keySetIndex+1 ); - ShowDeviceAndROM(); - } - } - } - - dirty = folder.CheckBrowseNavigation(); - } - - if (dirty) RefeshDisplay(); } else { - if (inputMappings->BrowseBack()) - PopFolder(); + if (folder.entries.size() > 0) + { + //u32 numberOfEntriesMinus1 = folder.entries.size() - 1; + bool dirty = false; + + if (inputMappings->BrowseSelect()) + { + FileBrowser::BrowsableList::Entry* current = folder.current; + if (current) + { + if (current->filImage.fattrib & AM_DIR) + { + if (strcmp(current->filImage.fname, "..") == 0) + { + PopFolder(); + } + else if (strcmp(current->filImage.fname, ".") != 0) + { + f_chdir(current->filImage.fname); + RefreshFolderEntries(); + } + dirty = true; + } + else + { + if (strcmp(current->filImage.fname, "..") == 0) + { + PopFolder(); + } + else if (DiskImage::IsDiskImageExtention(current->filImage.fname)) + { + DiskImage::DiskType diskType = DiskImage::GetDiskImageTypeViaExtention(current->filImage.fname); + + // Should also be able to create a LST file from all the images currently selected in the caddy + if (diskType == DiskImage::LST) + { + selectionsMade = SelectLST(current->filImage.fname); + } + else + { + // Add the current selected + AddToCaddy(current); + selectionsMade = FillCaddyWithSelections(); + } + + if (selectionsMade) + lastSelectionName = current->filImage.fname; + + dirty = true; + } + } + } + } + else if (inputMappings->BrowseDone()) + { + selectionsMade = FillCaddyWithSelections(); + } + //else if (keyboard->KeyPressed(KEY_TAB)) + //{ + // state = State_DiskCaddy; + // dirty = true; + //} + else if (inputMappings->BrowseBack()) + { + PopFolder(); + dirty = true; + } + else if (inputMappings->Exit()) + { + ClearSelections(); + dirty = true; + } + else if (inputMappings->BrowseInsert()) + { + if (buttonChangedDevice) + { + buttonChangedDevice = false; + } + else + { + FileBrowser::BrowsableList::Entry* current = folder.current; + if (current) + { + dirty = AddToCaddy(current); + } + } + } + else if (inputMappings->BrowseNewD64()) + { + char newFileName[64]; + strncpy (newFileName, options.GetAutoBaseName(), 63); + int num = folder.FindNextAutoName( newFileName ); + m_IEC_Commands.CreateD64(newFileName, "42", true); + FolderChanged(); + } + else + { + unsigned keySetIndex; + for (keySetIndex = 0; keySetIndex < 11; ++keySetIndex) + { + unsigned keySetIndexBase = keySetIndex * 3; + if (keyboard->KeyPressed(FileBrowser::SwapKeys[keySetIndexBase]) + || keyboard->KeyPressed(FileBrowser::SwapKeys[keySetIndexBase + 1]) + || keyboard->KeyPressed(FileBrowser::SwapKeys[keySetIndexBase + 2])) + { + if ( (keySetIndex < ROMs::MAX_ROMS) && (roms->ROMValid[keySetIndex]) ) + { + roms->currentROMIndex = keySetIndex; + roms->lastManualSelectedROMIndex = keySetIndex; + DEBUG_LOG("Swap ROM %d %s\r\n", keySetIndex, roms->ROMNames[keySetIndex]); + ShowDeviceAndROM(); + } + else if ( (keySetIndex >= 7) && (keySetIndex <= 10 ) ) + { + GlobalSetDeviceID( keySetIndex+1 ); + ShowDeviceAndROM(); + } + } + } + + dirty = folder.CheckBrowseNavigation(); + } + + if (dirty) RefeshDisplay(); + } + else + { + if (inputMappings->BrowseBack()) + PopFolder(); + } } } diff --git a/src/FileBrowser.h b/src/FileBrowser.h index 7893b22..68da5e1 100644 --- a/src/FileBrowser.h +++ b/src/FileBrowser.h @@ -230,6 +230,7 @@ private: ROMs* roms; u8* deviceID; bool displayPNGIcons; + bool buttonChangedDevice; BrowsableList caddySelections; diff --git a/src/InputMappings.cpp b/src/InputMappings.cpp index 5c2b83b..17c0d1a 100644 --- a/src/InputMappings.cpp +++ b/src/InputMappings.cpp @@ -33,6 +33,8 @@ unsigned InputMappings::directDiskSwapRequest = 0; InputMappings::InputMappings() : keyboardBrowseLCDScreen(false) + , insertButtonPressedPrev(false) + , insertButtonPressed(false) { } @@ -47,8 +49,13 @@ bool InputMappings::CheckButtonsBrowseMode() SetButtonFlag(DOWN_FLAG); else if (IEC_Bus::GetInputButtonPressed(3)) SetButtonFlag(BACK_FLAG); - else if (IEC_Bus::GetInputButtonPressed(4)) + //else if (IEC_Bus::GetInputButtonPressed(4)) + // SetButtonFlag(INSERT_FLAG); + + insertButtonPressed = !IEC_Bus::GetInputButtonReleased(4); + if (insertButtonPressedPrev && !insertButtonPressed) SetButtonFlag(INSERT_FLAG); + insertButtonPressedPrev = insertButtonPressed; return buttonFlags != 0; } diff --git a/src/InputMappings.h b/src/InputMappings.h index 19a5d64..e884681 100644 --- a/src/InputMappings.h +++ b/src/InputMappings.h @@ -50,6 +50,9 @@ protected: bool keyboardBrowseLCDScreen; + bool insertButtonPressedPrev; + bool insertButtonPressed; + //inline void SetUartFlag(unsigned flag) { uartFlags |= flag; } //inline bool UartFlag(unsigned flag) { return (uartFlags & flag) != 0; } inline void SetKeyboardFlag(unsigned flag) { keyboardFlags |= flag; } From 9cdc0da63bed2fe0aa1cfd6813aabfc4419fdf01 Mon Sep 17 00:00:00 2001 From: Stephen White Date: Sun, 22 Jul 2018 18:47:03 +1000 Subject: [PATCH 3/9] Button 5 can be used to change device ID. --- src/iec_bus.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/iec_bus.h b/src/iec_bus.h index 0ca9705..53aa5af 100644 --- a/src/iec_bus.h +++ b/src/iec_bus.h @@ -582,9 +582,10 @@ public: } static bool GetInputButtonPressed(int buttonIndex) { return InputButton[buttonIndex] && !InputButtonPrev[buttonIndex]; } - static bool GetInputButtonReleased(int buttonIndex) { return !InputButton[buttonIndex] && InputButtonPrev[buttonIndex]; } + static bool GetInputButtonReleased(int buttonIndex) { return InputButton[buttonIndex] == false; } static bool GetInputButton(int buttonIndex) { return InputButton[buttonIndex]; } static bool GetInputButtonRepeating(int buttonIndex) { return inputRepeat[buttonIndex] != inputRepeatPrev[buttonIndex]; } + static bool GetInputButtonHeld(int buttonIndex) { return inputRepeatThreshold[buttonIndex] >= INPUT_BUTTON_DEBOUNCE_THRESHOLD + (INPUT_BUTTON_REPEAT_THRESHOLD * 2); } static bool OutputLED; static bool OutputSound; From 5fda5024f7aa38cf746ca56f385f2777c6522f40 Mon Sep 17 00:00:00 2001 From: Stephen White Date: Sun, 22 Jul 2018 18:52:35 +1000 Subject: [PATCH 4/9] Incremented build version. --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 9a3b4b4..ad9bcd8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -46,7 +46,7 @@ extern "C" #include "ssd_logo.h" unsigned versionMajor = 1; -unsigned versionMinor = 8; +unsigned versionMinor = 9; // When the emulated CPU starts we execute the first million odd cycles in non-real-time (ie as fast as possible so the emulated 1541 becomes responsive to CBM-Browser asap) // During these cycles the CPU is executing the ROM self test routines (these do not need to be cycle accurate) From 5f8b1731552507eaade0c8e72c05baf18514322b Mon Sep 17 00:00:00 2001 From: penfold42 Date: Thu, 26 Jul 2018 11:06:21 +1000 Subject: [PATCH 5/9] LCD type is now an enum --- src/ScreenLCD.cpp | 2 +- src/ScreenLCD.h | 3 ++- src/main.cpp | 2 +- src/options.cpp | 8 +++++--- src/options.h | 12 ++++++++++-- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/ScreenLCD.cpp b/src/ScreenLCD.cpp index bde0a30..b389c6e 100644 --- a/src/ScreenLCD.cpp +++ b/src/ScreenLCD.cpp @@ -23,7 +23,7 @@ #include "debug.h" #include "ssd_logo.h" -void ScreenLCD::Open(u32 widthDesired, u32 heightDesired, u32 colourDepth, int BSCMaster, int LCDAddress, int LCDFlip, int LCDType) +void ScreenLCD::Open(u32 widthDesired, u32 heightDesired, u32 colourDepth, int BSCMaster, int LCDAddress, int LCDFlip, LCD_MODEL LCDType) { bpp = 1; diff --git a/src/ScreenLCD.h b/src/ScreenLCD.h index dc68275..b81d114 100644 --- a/src/ScreenLCD.h +++ b/src/ScreenLCD.h @@ -21,6 +21,7 @@ #include "ScreenBase.h" #include "SSD1306.h" +#include "options.h" class ScreenLCD : public ScreenBase { @@ -32,7 +33,7 @@ public: { } - void Open(u32 width, u32 height, u32 colourDepth, int BSCMaster, int LCDAddress, int LCDFlip, int LCDType); + void Open(u32 width, u32 height, u32 colourDepth, int BSCMaster, int LCDAddress, int LCDFlip, LCD_MODEL LCDType); void ClearArea(u32 x1, u32 y1, u32 x2, u32 y2, RGBA colour); void Clear(RGBA colour); diff --git a/src/main.cpp b/src/main.cpp index ad9bcd8..4747440 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -365,7 +365,7 @@ void InitialiseLCD() int i2cLcdOnContrast = options.I2CLcdOnContrast(); int i2cLcdDimContrast = options.I2CLcdDimContrast(); int i2cLcdDimTime = options.I2CLcdDimTime(); - int i2cLcdModel = options.I2CLcdModel(); + LCD_MODEL i2cLcdModel = options.I2CLcdModel(); if (i2cLcdModel) { diff --git a/src/options.cpp b/src/options.cpp index 5fa487e..62550b2 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -145,7 +145,7 @@ Options::Options(void) , i2cScan(0) , i2cLcdFlip(0) , i2cLcdOnContrast(127) - , i2cLcdModel(0) + , i2cLcdModel(LCD_UNKNOWN) , scrollHighlightRate(0.125f) , keyboardBrowseLCDScreen(0) { @@ -241,9 +241,11 @@ void Options::Process(char* buffer) { strncpy(LCDName, pValue, 255); if (strcasecmp(pValue, "ssd1306_128x64") == 0) - i2cLcdModel = 1306; + i2cLcdModel = LCD_1306_128x64; + else if (strcasecmp(pValue, "ssd1306_128x32") == 0) + i2cLcdModel = LCD_1306_128x32; else if (strcasecmp(pValue, "sh1106_128x64") == 0) - i2cLcdModel = 1106; + i2cLcdModel = LCD_1106_128x64; } else if ((strcasecmp(pOption, "ROM") == 0) || (strcasecmp(pOption, "ROM1") == 0)) diff --git a/src/options.h b/src/options.h index 22a8931..f408b36 100644 --- a/src/options.h +++ b/src/options.h @@ -19,6 +19,13 @@ #ifndef OPTIONS_H #define OPTIONS_H +typedef enum { + LCD_UNKNOWN, + LCD_1306_128x64, + LCD_1306_128x32, + LCD_1106_128x64, +} LCD_MODEL; + class TextParser { public: @@ -77,7 +84,7 @@ public: inline unsigned int I2CLcdOnContrast() const { return i2cLcdOnContrast; } inline unsigned int I2CLcdDimContrast() const { return i2cLcdDimContrast; } inline unsigned int I2CLcdDimTime() const { return i2cLcdDimTime; } - inline unsigned int I2CLcdModel() const { return i2cLcdModel; } + inline LCD_MODEL I2CLcdModel() const { return i2cLcdModel; } inline const char* GetLcdLogoName() const { return LcdLogoName; } @@ -123,7 +130,8 @@ private: unsigned int i2cLcdOnContrast; unsigned int i2cLcdDimContrast; unsigned int i2cLcdDimTime; - unsigned int i2cLcdModel; +// unsigned int i2cLcdModel; + LCD_MODEL i2cLcdModel = LCD_UNKNOWN; float scrollHighlightRate; From ee175ec1fd36a405d225e1d371fe5d6b40c0a4b4 Mon Sep 17 00:00:00 2001 From: penfold42 Date: Thu, 26 Jul 2018 11:34:59 +1000 Subject: [PATCH 6/9] LCD_1306_128x32 now sets com pins correctly clean up stb compiler warning --- src/SSD1306.cpp | 13 ++++++++----- src/SSD1306.h | 2 +- src/options.h | 7 +------ src/stb_image.h | 4 ++++ src/types.h | 6 ++++++ 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/SSD1306.cpp b/src/SSD1306.cpp index 8f20f1a..8db861c 100644 --- a/src/SSD1306.cpp +++ b/src/SSD1306.cpp @@ -27,7 +27,7 @@ extern "C" unsigned char frame[SSD1306_128x64_BYTES]; -SSD1306::SSD1306(int BSCMaster, u8 address, int flip, int type) +SSD1306::SSD1306(int BSCMaster, u8 address, int flip, LCD_MODEL type) : BSCMaster(BSCMaster) , address(address) , type(type) @@ -61,7 +61,10 @@ void SSD1306::InitHardware() } SendCommand(SSD1306_CMD_SET_COM_PINS); // 0xDA Layout and direction - SendCommand(0x12); + if (type == LCD_1306_128x32) + SendCommand(0x02); + else + SendCommand(0x12); SetContrast(GetContrast()); @@ -86,7 +89,7 @@ void SSD1306::InitHardware() Home(); - if (type != 1106) + if (type != LCD_1106_128x64) SendCommand(SSD1306_CMD_DEACTIVATE_SCROLL); // 0x2E } @@ -120,7 +123,7 @@ void SSD1306::MoveCursorByte(u8 row, u8 col) if (col > 127) { col = 127; } if (row > 7) { row = 7; } - if (type == 1106) + if (type == LCD_1106_128x64) col += 2; // sh1106 uses columns 2..129 SendCommand(SSD1306_CMD_SET_PAGE | row); // 0xB0 page address @@ -183,7 +186,7 @@ void SSD1306::SetContrast(u8 value) contrast = value; SendCommand(SSD1306_CMD_SET_CONTRAST_CONTROL); SendCommand(value); - if (type == 1306) + if (type != LCD_1106_128x64) // dont fiddle vcomdeselect on 1106 displays SetVCOMDeselect( value >> 8); } diff --git a/src/SSD1306.h b/src/SSD1306.h index f1ea8d9..08314fa 100644 --- a/src/SSD1306.h +++ b/src/SSD1306.h @@ -76,7 +76,7 @@ class SSD1306 public: // 128x32 0x3C // 128x64 0x3D or 0x3C (if SA0 is grounded) - SSD1306(int BSCMaster = 1, u8 address = 0x3C, int flip = 0, int type=1306); + SSD1306(int BSCMaster = 1, u8 address = 0x3C, int flip = 0, LCD_MODEL type=LCD_UNKNOWN); void PlotCharacter(int x, int y, char ascii, bool inverse); void PlotText(int x, int y, char* str, bool inverse); diff --git a/src/options.h b/src/options.h index f408b36..24dd1e9 100644 --- a/src/options.h +++ b/src/options.h @@ -19,12 +19,7 @@ #ifndef OPTIONS_H #define OPTIONS_H -typedef enum { - LCD_UNKNOWN, - LCD_1306_128x64, - LCD_1306_128x32, - LCD_1106_128x64, -} LCD_MODEL; +#include "types.h" class TextParser { diff --git a/src/stb_image.h b/src/stb_image.h index a056138..dc83749 100644 --- a/src/stb_image.h +++ b/src/stb_image.h @@ -892,12 +892,14 @@ static int stbi__mad3sizes_valid(int a, int b, int c, int add) stbi__addsizes_valid(a*b*c, add); } +#ifndef STBI_NO_LINEAR // returns 1 if "a*b*c*d + add" has no negative terms/factors and doesn't overflow static int stbi__mad4sizes_valid(int a, int b, int c, int d, int add) { return stbi__mul2sizes_valid(a, b) && stbi__mul2sizes_valid(a*b, c) && stbi__mul2sizes_valid(a*b*c, d) && stbi__addsizes_valid(a*b*c*d, add); } +#endif // mallocs with size overflow checking static void *stbi__malloc_mad2(int a, int b, int add) @@ -912,11 +914,13 @@ static void *stbi__malloc_mad3(int a, int b, int c, int add) return stbi__malloc(a*b*c + add); } +#ifndef STBI_NO_LINEAR static void *stbi__malloc_mad4(int a, int b, int c, int d, int add) { if (!stbi__mad4sizes_valid(a, b, c, d, add)) return NULL; return stbi__malloc(a*b*c*d + add); } +#endif // stbi__err - error // stbi__errpf - error returning pointer to float diff --git a/src/types.h b/src/types.h index 253092b..22aa7dc 100644 --- a/src/types.h +++ b/src/types.h @@ -9,5 +9,11 @@ typedef unsigned long long u64; typedef signed long long s64; +typedef enum { + LCD_UNKNOWN, + LCD_1306_128x64, + LCD_1306_128x32, + LCD_1106_128x64, +} LCD_MODEL; #endif From 78e20ae4bbad384c5ed63b0d1ec6e318c886dbaf Mon Sep 17 00:00:00 2001 From: penfold42 Date: Thu, 26 Jul 2018 12:19:35 +1000 Subject: [PATCH 7/9] swap pages for SSD1306 128x32 displays --- src/SSD1306.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/SSD1306.cpp b/src/SSD1306.cpp index 8db861c..9b997ac 100644 --- a/src/SSD1306.cpp +++ b/src/SSD1306.cpp @@ -154,6 +154,13 @@ void SSD1306::RefreshRows(u32 start, u32 amountOfRows) void SSD1306::RefreshPage(u32 page) { + // x32 displays use lower half (pages 2 and 3) + if (type == LCD_1306_128x32) + { + page = page+2; // 0,1 -> 2,3 + page = page%4; // and wrap it so 2,3 -> 0,1 + } + int i; int start = page*128; int end = page*128 + 128; From f0ee85d022c704401b75cdef11090cce211636cd Mon Sep 17 00:00:00 2001 From: penfold42 Date: Thu, 26 Jul 2018 13:28:37 +1000 Subject: [PATCH 8/9] implement height and width --- src/SSD1306.cpp | 27 ++++++++++++++++----------- src/SSD1306.h | 4 +++- src/ScreenLCD.cpp | 6 +++--- src/main.cpp | 16 ++++++++++------ 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/SSD1306.cpp b/src/SSD1306.cpp index 9b997ac..24cbf70 100644 --- a/src/SSD1306.cpp +++ b/src/SSD1306.cpp @@ -27,12 +27,14 @@ extern "C" unsigned char frame[SSD1306_128x64_BYTES]; -SSD1306::SSD1306(int BSCMaster, u8 address, int flip, LCD_MODEL type) +SSD1306::SSD1306(int BSCMaster, u8 address, int width, int height, int flip, LCD_MODEL type) : BSCMaster(BSCMaster) , address(address) , type(type) , flip(flip) , contrast(127) + , width(width) + , height(height) { RPI_I2CInit(BSCMaster, 1); @@ -45,7 +47,7 @@ void SSD1306::InitHardware() SendCommand(SSD1306_CMD_DISPLAY_OFF); // 0xAE SendCommand(SSD1306_CMD_MULTIPLEX_RATIO); // 0xA8 - SendCommand(0x3F); // SSD1306_LCDHEIGHT - 1 + SendCommand(height-1); // SSD1306_LCDHEIGHT - 1 SendCommand(SSD1306_CMD_SET_DISPLAY_OFFSET); // 0xD3 Vertical scroll position SendCommand(0x00); // no Offset @@ -118,15 +120,15 @@ void SSD1306::Home() MoveCursorByte(0, 0); } -void SSD1306::MoveCursorByte(u8 row, u8 col) +void SSD1306::MoveCursorByte(u8 page, u8 col) { - if (col > 127) { col = 127; } - if (row > 7) { row = 7; } + if (col > width-1) { col = width-1; } + if (page > height/8-1) { page = height/8-1; } if (type == LCD_1106_128x64) col += 2; // sh1106 uses columns 2..129 - SendCommand(SSD1306_CMD_SET_PAGE | row); // 0xB0 page address + SendCommand(SSD1306_CMD_SET_PAGE | page); // 0xB0 page address SendCommand(SSD1306_CMD_SET_COLUMN_LOW | (col & 0xf)); // 0x00 column address lower bits SendCommand(SSD1306_CMD_SET_COLUMN_HIGH | (col >> 4)); // 0x10 column address upper bits } @@ -134,7 +136,7 @@ void SSD1306::MoveCursorByte(u8 row, u8 col) void SSD1306::RefreshScreen() { int i; - for (i = 0; i < 8; i++) + for (i = 0; i < height/8; i++) { RefreshPage(i); } @@ -154,16 +156,19 @@ void SSD1306::RefreshRows(u32 start, u32 amountOfRows) void SSD1306::RefreshPage(u32 page) { + if (page >= height/8) + return; + // x32 displays use lower half (pages 2 and 3) if (type == LCD_1306_128x32) { - page = page+2; // 0,1 -> 2,3 - page = page%4; // and wrap it so 2,3 -> 0,1 + page = page+4; // 0,1,2,3 -> 4,5,6,7 + page = page%4; // and wrap it so 4,5 -> 0,1 } int i; - int start = page*128; - int end = page*128 + 128; + int start = page*width; + int end = start + width; MoveCursorByte(page, 0); for (i = start; i < end; i++) diff --git a/src/SSD1306.h b/src/SSD1306.h index 08314fa..9390f0a 100644 --- a/src/SSD1306.h +++ b/src/SSD1306.h @@ -76,7 +76,7 @@ class SSD1306 public: // 128x32 0x3C // 128x64 0x3D or 0x3C (if SA0 is grounded) - SSD1306(int BSCMaster = 1, u8 address = 0x3C, int flip = 0, LCD_MODEL type=LCD_UNKNOWN); + SSD1306(int BSCMaster = 1, u8 address = 0x3C, int width = 128, int height = 64, int flip = 0, LCD_MODEL type=LCD_UNKNOWN); void PlotCharacter(int x, int y, char ascii, bool inverse); void PlotText(int x, int y, char* str, bool inverse); @@ -110,6 +110,8 @@ protected: int type; int flip; int contrast; + int width; + int height; }; #endif diff --git a/src/ScreenLCD.cpp b/src/ScreenLCD.cpp index b389c6e..591422c 100644 --- a/src/ScreenLCD.cpp +++ b/src/ScreenLCD.cpp @@ -29,8 +29,8 @@ void ScreenLCD::Open(u32 widthDesired, u32 heightDesired, u32 colourDepth, int B if (widthDesired < 128) widthDesired = 128; - if (heightDesired < 64) - heightDesired = 64; + if (heightDesired < 32) + heightDesired = 32; if (widthDesired > 128) widthDesired = 128; if (heightDesired > 64) @@ -39,7 +39,7 @@ void ScreenLCD::Open(u32 widthDesired, u32 heightDesired, u32 colourDepth, int B width = widthDesired; height = heightDesired; - ssd1306 = new SSD1306(BSCMaster, LCDAddress, LCDFlip, LCDType); + ssd1306 = new SSD1306(BSCMaster, LCDAddress, width, height, LCDFlip, LCDType); ssd1306->ClearScreen(); ssd1306->RefreshScreen(); ssd1306->DisplayOn(); diff --git a/src/main.cpp b/src/main.cpp index 4747440..e80ed26 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -369,20 +369,24 @@ void InitialiseLCD() if (i2cLcdModel) { + int width = 128; + int height = 64; + if (i2cLcdModel == LCD_1306_128x32) + height = 32; screenLCD = new ScreenLCD(); - screenLCD->Open(128, 64, 1, i2cBusMaster, i2cLcdAddress, i2cLcdFlip, i2cLcdModel); + screenLCD->Open(width, height, 1, i2cBusMaster, i2cLcdAddress, i2cLcdFlip, i2cLcdModel); screenLCD->SetContrast(i2cLcdOnContrast); screenLCD->ClearInit(0); // sh1106 needs this bool logo_done = false; - if (strcasecmp(options.GetLcdLogoName(), "1541ii") == 0) + if ( (height == 64) && (strcasecmp(options.GetLcdLogoName(), "1541ii") == 0) ) { screenLCD->PlotRawImage(logo_ssd_1541ii, 0, 0, 128, 64); snprintf(tempBuffer, tempBufferSize, "Pi1541 V%d.%02d", versionMajor, versionMinor); screenLCD->PrintText(0, 16, 0, tempBuffer, 0xffffffff); logo_done = true; } - else if (strcasecmp(options.GetLcdLogoName(), "1541classic") == 0) + else if (( height == 64) && (strcasecmp(options.GetLcdLogoName(), "1541classic") == 0) ) { screenLCD->PlotRawImage(logo_ssd_1541classic, 0, 0, 128, 64); logo_done = true; @@ -398,7 +402,7 @@ void InitialiseLCD() u32 bytesRead; f_read(&fp, LcdLogoFile, LCD_LOGO_MAX_SIZE, &bytesRead); f_close(&fp); - screenLCD->PlotRawImage(LcdLogoFile, 0, 0, 128, 64); + screenLCD->PlotRawImage(LcdLogoFile, 0, 0, 128, height); logo_done = true; } } @@ -406,8 +410,8 @@ void InitialiseLCD() if (!logo_done) { snprintf(tempBuffer, tempBufferSize, "Pi1541 V%d.%02d", versionMajor, versionMinor); - int x = (128 - 8*strlen(tempBuffer) ) /2; - int y = (64-16)/2; + int x = (width - 8*strlen(tempBuffer) ) /2; + int y = (height-16)/2; screenLCD->PrintText(0, x, y, tempBuffer, 0x0); } screenLCD->RefreshScreen(); From 2f023ab756af6b1b0a72dfab3008e7c269aa7067 Mon Sep 17 00:00:00 2001 From: penfold42 Date: Thu, 26 Jul 2018 14:57:57 +1000 Subject: [PATCH 9/9] Compiler warnings width and height to PlotRawImage --- src/SSD1306.cpp | 4 ++-- src/SSD1306.h | 6 +++--- src/main.cpp | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/SSD1306.cpp b/src/SSD1306.cpp index 24cbf70..9e6728a 100644 --- a/src/SSD1306.cpp +++ b/src/SSD1306.cpp @@ -27,7 +27,7 @@ extern "C" unsigned char frame[SSD1306_128x64_BYTES]; -SSD1306::SSD1306(int BSCMaster, u8 address, int width, int height, int flip, LCD_MODEL type) +SSD1306::SSD1306(int BSCMaster, u8 address, unsigned width, unsigned height, int flip, LCD_MODEL type) : BSCMaster(BSCMaster) , address(address) , type(type) @@ -135,7 +135,7 @@ void SSD1306::MoveCursorByte(u8 page, u8 col) void SSD1306::RefreshScreen() { - int i; + unsigned i; for (i = 0; i < height/8; i++) { RefreshPage(i); diff --git a/src/SSD1306.h b/src/SSD1306.h index 9390f0a..6ab245f 100644 --- a/src/SSD1306.h +++ b/src/SSD1306.h @@ -76,7 +76,7 @@ class SSD1306 public: // 128x32 0x3C // 128x64 0x3D or 0x3C (if SA0 is grounded) - SSD1306(int BSCMaster = 1, u8 address = 0x3C, int width = 128, int height = 64, int flip = 0, LCD_MODEL type=LCD_UNKNOWN); + SSD1306(int BSCMaster = 1, u8 address = 0x3C, unsigned width = 128, unsigned height = 64, int flip = 0, LCD_MODEL type=LCD_UNKNOWN); void PlotCharacter(int x, int y, char ascii, bool inverse); void PlotText(int x, int y, char* str, bool inverse); @@ -110,8 +110,8 @@ protected: int type; int flip; int contrast; - int width; - int height; + unsigned width; + unsigned height; }; #endif diff --git a/src/main.cpp b/src/main.cpp index e80ed26..5e34d83 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -381,14 +381,14 @@ void InitialiseLCD() bool logo_done = false; if ( (height == 64) && (strcasecmp(options.GetLcdLogoName(), "1541ii") == 0) ) { - screenLCD->PlotRawImage(logo_ssd_1541ii, 0, 0, 128, 64); + screenLCD->PlotRawImage(logo_ssd_1541ii, 0, 0, width, height); snprintf(tempBuffer, tempBufferSize, "Pi1541 V%d.%02d", versionMajor, versionMinor); screenLCD->PrintText(0, 16, 0, tempBuffer, 0xffffffff); logo_done = true; } else if (( height == 64) && (strcasecmp(options.GetLcdLogoName(), "1541classic") == 0) ) { - screenLCD->PlotRawImage(logo_ssd_1541classic, 0, 0, 128, 64); + screenLCD->PlotRawImage(logo_ssd_1541classic, 0, 0, width, height); logo_done = true; } else if (f_stat(options.GetLcdLogoName(), &filLcdIcon) == FR_OK && filLcdIcon.fsize <= LCD_LOGO_MAX_SIZE) @@ -402,7 +402,7 @@ void InitialiseLCD() u32 bytesRead; f_read(&fp, LcdLogoFile, LCD_LOGO_MAX_SIZE, &bytesRead); f_close(&fp); - screenLCD->PlotRawImage(LcdLogoFile, 0, 0, 128, height); + screenLCD->PlotRawImage(LcdLogoFile, 0, 0, width, height); logo_done = true; } }