Skip to content

Commit ae36a09

Browse files
committed
Code tidyup and added diskflashback "kick"
1 parent 27321cb commit ae36a09

File tree

4 files changed

+35
-46
lines changed

4 files changed

+35
-46
lines changed

ArduinoFloppyReader/ArduinoFloppyReader/ArduinoFloppyReader.vcxproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
<PrecompiledHeader>NotUsing</PrecompiledHeader>
9292
<WarningLevel>Level3</WarningLevel>
9393
<Optimization>Disabled</Optimization>
94-
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
94+
<PreprocessorDefinitions>DISKFLASHBACK_KILL;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
9595
<SDLCheck>false</SDLCheck>
9696
</ClCompile>
9797
<Link>
@@ -104,7 +104,7 @@
104104
<PrecompiledHeader>NotUsing</PrecompiledHeader>
105105
<WarningLevel>Level3</WarningLevel>
106106
<Optimization>Disabled</Optimization>
107-
<PreprocessorDefinitions>_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
107+
<PreprocessorDefinitions>DISKFLASHBACK_KILL;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
108108
<SDLCheck>true</SDLCheck>
109109
</ClCompile>
110110
<Link>
@@ -119,7 +119,7 @@
119119
<Optimization>MaxSpeed</Optimization>
120120
<FunctionLevelLinking>true</FunctionLevelLinking>
121121
<IntrinsicFunctions>true</IntrinsicFunctions>
122-
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
122+
<PreprocessorDefinitions>DISKFLASHBACK_KILL;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
123123
<SDLCheck>true</SDLCheck>
124124
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
125125
</ClCompile>
@@ -137,7 +137,7 @@
137137
<Optimization>MaxSpeed</Optimization>
138138
<FunctionLevelLinking>true</FunctionLevelLinking>
139139
<IntrinsicFunctions>true</IntrinsicFunctions>
140-
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
140+
<PreprocessorDefinitions>DISKFLASHBACK_KILL;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
141141
<SDLCheck>true</SDLCheck>
142142
</ClCompile>
143143
<Link>

ArduinoFloppyReader/ArduinoFloppyReaderWin/ArduinoFloppyReaderWin.vcxproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
<PrecompiledHeader>Use</PrecompiledHeader>
100100
<WarningLevel>Level3</WarningLevel>
101101
<Optimization>Disabled</Optimization>
102-
<PreprocessorDefinitions>_WINSOCK_DEPRECATED_NO_WARNINGS;USING_MFC;WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions);_WIN32_WINNT=0x0601</PreprocessorDefinitions>
102+
<PreprocessorDefinitions>DISKFLASHBACK_KILL;_WINSOCK_DEPRECATED_NO_WARNINGS;USING_MFC;WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions);_WIN32_WINNT=0x0601</PreprocessorDefinitions>
103103
<SDLCheck>true</SDLCheck>
104104
<LanguageStandard>stdcpp17</LanguageStandard>
105105
</ClCompile>
@@ -123,7 +123,7 @@
123123
<PrecompiledHeader>Use</PrecompiledHeader>
124124
<WarningLevel>Level3</WarningLevel>
125125
<Optimization>Disabled</Optimization>
126-
<PreprocessorDefinitions>_WINSOCK_DEPRECATED_NO_WARNINGS;_WINDOWS;_DEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions);_WIN32_WINNT=0x0601</PreprocessorDefinitions>
126+
<PreprocessorDefinitions>DISKFLASHBACK_KILL;_WINSOCK_DEPRECATED_NO_WARNINGS;_WINDOWS;_DEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions);_WIN32_WINNT=0x0601</PreprocessorDefinitions>
127127
<SDLCheck>true</SDLCheck>
128128
<LanguageStandard>stdcpp17</LanguageStandard>
129129
</ClCompile>
@@ -148,7 +148,7 @@
148148
<Optimization>MaxSpeed</Optimization>
149149
<FunctionLevelLinking>true</FunctionLevelLinking>
150150
<IntrinsicFunctions>true</IntrinsicFunctions>
151-
<PreprocessorDefinitions>_WINSOCK_DEPRECATED_NO_WARNINGS;USING_MFC;WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions);_WIN32_WINNT=0x0601</PreprocessorDefinitions>
151+
<PreprocessorDefinitions>DISKFLASHBACK_KILL;_WINSOCK_DEPRECATED_NO_WARNINGS;USING_MFC;WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions);_WIN32_WINNT=0x0601</PreprocessorDefinitions>
152152
<SDLCheck>true</SDLCheck>
153153
<LanguageStandard>stdcpp17</LanguageStandard>
154154
</ClCompile>
@@ -176,7 +176,7 @@
176176
<Optimization>MaxSpeed</Optimization>
177177
<FunctionLevelLinking>true</FunctionLevelLinking>
178178
<IntrinsicFunctions>true</IntrinsicFunctions>
179-
<PreprocessorDefinitions>_WINSOCK_DEPRECATED_NO_WARNINGS;_WINDOWS;NDEBUG;%(PreprocessorDefinitions);_WIN32_WINNT=0x0601</PreprocessorDefinitions>
179+
<PreprocessorDefinitions>DISKFLASHBACK_KILL;_WINSOCK_DEPRECATED_NO_WARNINGS;_WINDOWS;NDEBUG;%(PreprocessorDefinitions);_WIN32_WINNT=0x0601</PreprocessorDefinitions>
180180
<SDLCheck>true</SDLCheck>
181181
<LanguageStandard>stdcpp17</LanguageStandard>
182182
</ClCompile>

ArduinoFloppyReader/lib/ArduinoInterface.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,15 @@ DiagnosticResponse ArduinoInterface::internalOpenPort(const std::wstring& portNa
501501
return response;
502502
}
503503

504+
#ifdef DISKFLASHBACK_KILL
505+
#ifdef _WIN32
506+
void releaseVirtualDrives(bool release, int controllerType) {
507+
HWND remoteWindow = FindWindow(L"VIRTUALDRIVE_CONTROLLER_CLASS", L"DiskFlashback Tray Control");
508+
if (remoteWindow) SendMessage(remoteWindow, WM_USER + 2, (controllerType & 0x7FFF) | (release ? 0 : 0x8000), (LPARAM)GetCurrentProcessId());
509+
}
510+
#endif
511+
#endif
512+
504513
// Attempts to open the reader running on the COM port number provided. Port MUST support 2M baud
505514
DiagnosticResponse ArduinoInterface::openPort(const std::wstring& portName, bool enableCTSflowcontrol) {
506515
m_lastCommand = LastCommand::lcOpenPort;
@@ -509,6 +518,12 @@ DiagnosticResponse ArduinoInterface::openPort(const std::wstring& portName, bool
509518
// Quickly force streaming to be aborted
510519
m_abortStreaming = true;
511520

521+
#ifdef DISKFLASHBACK_KILL
522+
#ifdef _WIN32
523+
releaseVirtualDrives(true, 0);
524+
#endif
525+
#endif
526+
512527
std::string versionString;
513528
m_lastError = internalOpenPort(portName, enableCTSflowcontrol, true, versionString, m_comPort);
514529
if (m_lastError != DiagnosticResponse::drOK) return m_lastError;
@@ -582,6 +597,12 @@ void ArduinoInterface::closePort() {
582597
m_isWriteProtected = false;
583598
m_diskInDrive = false;
584599
m_lastCommand = old;
600+
#ifdef DISKFLASHBACK_KILL
601+
#ifdef _WIN32
602+
releaseVirtualDrives(false, 0);
603+
#endif
604+
#endif
605+
585606
}
586607

587608
// Returns true if the track actually contains some data, else its considered blank or unformatted

FloppyDriveController.sketch/FloppyDriveController.sketch.ino

+6-38
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* DrawBridge a.k.a ArduinoFloppyReader (and writer)
22
*
3-
* Copyright (C) 2017-2022 Robert Smith (@RobSmithDev)
3+
* Copyright (C) 2017-2024 Robert Smith (@RobSmithDev)
44
* https://amiga.robsmithdev.co.uk
55
*
66
* This sketch is free software; you can redistribute it and/or
@@ -74,8 +74,7 @@
7474
Created ASM version for DrawBridge Plus! Classic gets a more accurate version but couldnt get the code stable
7575
v1.9.24 More Accurate PLL for both DrawBridge Classic and Plus!
7676
v1.9.25 Added support for tracks 82 and 83
77-
Fixed compiler warnings
78-
v1.9.26 Added support to read the state of BOD, just incase the device resets due to motor surges!
77+
Tidied up the code to remove warnings
7978
8079
*/
8180

@@ -219,6 +218,9 @@ bool disktypeHD = 0;
219218
// Center position reading HD disks in DB classic mode (this is TIMING_OVERHEAD+DB_CLASSIC_HD_MIDDLE) - this was checked to give the best result with jitter
220219
#define DB_CLASSIC_HD_MIDDLE -2
221220

221+
222+
223+
222224
// 256 byte circular buffer - don't change this, we abuse the unsigned char to overflow back to zero!
223225
#define SERIAL_BUFFER_SIZE 256
224226
#define SERIAL_BUFFER_START (SERIAL_BUFFER_SIZE - 16)
@@ -357,29 +359,11 @@ void setup() {
357359
PCMSK2 = 0;
358360
PCMSK1 = 0;
359361
EIMSK&=~B00000011; // disable INT0/1 interrupt mask
360-
361-
// see what reset us
362-
powerResetDetect();
363362

364363
// Setup the USART
365364
prepSerialInterface();
366365
}
367366

368-
// see what reset us - we keep a bitmask of all the reset reasons just incase we externally reset the device and miss one.
369-
void powerResetDetect() {
370-
// Get reset reasons. We don't care about power on reset
371-
unsigned char reason = MCUSR & (bit(WDRF) | bit(BORF) | bit(EXTRF));
372-
unsigned char lastReason;
373-
EEPROM.get(12, lastReason);
374-
375-
// New reset state detected
376-
if (reason | lastReason != lastReason) EEPROM.set(12, lastReason | reason);
377-
378-
// Clear reset flags
379-
MCUSR |= bit(BORF) | bit(PORF) | bit(EXTRF) | bit(WDRF);
380-
}
381-
382-
383367
// Refresh bools after eeprom has been written to
384368
void refreshEEPROMSettings() {
385369
// Has this hardware been updated? - If you can't connect pin12 to GND because you want to use the ISP headers, then see https://amiga.robsmithdev.co.uk/isp
@@ -412,8 +396,6 @@ void refreshEEPROMSettings() {
412396
EEPROM.get(10, b1);
413397
EEPROM.get(11, b2);
414398
alwaysIndexAlignWrites = (((b1 == 0x69) && (b2 == 0x61)));
415-
416-
// note EEPROM 12 is reserved for reset detect
417399

418400
}
419401

@@ -3385,7 +3367,6 @@ void testDiskDensity() {
33853367
PCMSK2 = bit(PCINT20);
33863368

33873369
unsigned int overflows = 0;
3388-
33893370
unsigned int HDPulses = 0;
33903371
unsigned int DDPulses = 0;
33913372
unsigned char counter;
@@ -3543,7 +3524,7 @@ void loop() {
35433524
(alwaysIndexAlignWrites ? FLAGS_INDEX_ALIGN_MODE : 0)
35443525
);
35453526
writeByteToUART(0); // RFU
3546-
writeByteToUART(26); // build number
3527+
writeByteToUART(25); // build number
35473528
break;
35483529

35493530
// Command "." means go back to track 0
@@ -3732,19 +3713,6 @@ void loop() {
37323713

37333714
case 'E': readEpromValue(); break;
37343715
case 'e': writeEpromValue(); break;
3735-
3736-
// Reset reasons
3737-
case 'B': writeByteToUART('1');
3738-
unsigned char lastReason;
3739-
EEPROM.get(12, lastReason);
3740-
writeByteToUART(lastReason);
3741-
break;
3742-
3743-
// Clear reset reasons
3744-
case 'b': writeByteToUART('1');
3745-
EEPROM.set(12, 0);
3746-
break;
3747-
37483716

37493717
// We don't recognise the command!
37503718
default:

0 commit comments

Comments
 (0)