1- /* ArduinoFloppyReader
1+ /* ArduinoFloppyReader (and writer)
22*
33* Copyright (C) 2017 Robert Smith (@RobSmithDev)
44* http://amiga.robsmithdev.co.uk
1717* License along with this program; if not see http://www.gnu.org/licenses/
1818*/
1919
20- // ////////////////////////////////////////////////////////////////////////////////////////
21- // Example console application for reading floppy drives //
22- // ////////////////////////////////////////////////////////////////////////////////////////
20+ // //////////////////////////////////////////////////////////////////////////////////////////
21+ // Example console application for reading and writing floppy disks to and from ADF files //
22+ // //////////////////////////////////////////////////////////////////////////////////////////
2323
2424
2525#include " stdafx.h"
@@ -30,53 +30,100 @@ using namespace ArduinoFloppyReader;
3030
3131ADFWriter writer;
3232
33+ // Read an ADF file and write it to disk
34+ void adf2Disk (wchar_t * argv[], bool verify) {
35+ printf (" \n Write disk from ADF mode\n\n " );
36+ if (!verify) printf (" WARNING: It is STRONGLY recommended to write with verify support turned on.\r\n\r\n " );
37+
38+ ADFResult result = writer.ADFToDisk (argv[2 ],verify, [](const int currentTrack, const DiskSurface currentSide, bool isVerifyError) ->WriteResponse {
39+ if (isVerifyError) {
40+ char input;
41+ do {
42+ printf (" \r Disk write verify error on track %i, %s side. [R]etry, [S]kip, [A]bort? " , currentTrack, (currentSide == DiskSurface::dsUpper) ? " Upper" : " Lower" );
43+ input = toupper (getchar ());
44+ } while ((input != ' R' ) && (input != ' S' ) && (input != ' A' ));
45+
46+ switch (input) {
47+ case ' R' : return WriteResponse::wrRetry;
48+ case ' I' : return WriteResponse::wrSkipBadChecksums;
49+ case ' A' : return WriteResponse::wrAbort;
50+ }
51+ }
52+ printf (" \r Writing Track %i, %s side " , currentTrack, (currentSide == DiskSurface::dsUpper) ? " Upper" : " Lower" );
53+ return WriteResponse::wrContinue;
54+ });
55+
56+ switch (result) {
57+ case adfrComplete: printf (" \r ADF file written to disk " ); break ;
58+ case adfrCompletedWithErrors: printf (" \r ADF file written to disk but there were errors during verification " ); break ;
59+ case adfrAborted: printf (" \r Writing ADF file to disk " ); break ;
60+ case adfrFileError: printf (" \r Error opening ADF file. " ); break ;
61+ case adfrDriveError: printf (" \r Error communicating with the Arduino interface. " ); break ;
62+ case adfrDiskWriteProtected: printf (" \r Error, disk is write protected! " ); break ;
63+ }
64+ }
65+
66+ // Read a disk and save it to ADF files
67+ void disk2ADF (wchar_t * argv[]) {
68+ printf (" \n Create ADF from disk mode\n\n " );
69+
70+ ADFResult result = writer.DiskToADF (argv[2 ], 80 , [](const int currentTrack, const DiskSurface currentSide, const int retryCounter, const int sectorsFound, const int badSectorsFound) ->WriteResponse {
71+ if (retryCounter > 20 ) {
72+ char input;
73+ do {
74+ printf (" \r Disk has checksum errors/missing data. [R]etry, [I]gnore, [A]bort? " );
75+ input = toupper (getchar ());
76+ } while ((input != ' R' ) && (input != ' I' ) && (input != ' A' ));
77+ switch (input) {
78+ case ' R' : return WriteResponse::wrRetry;
79+ case ' I' : return WriteResponse::wrSkipBadChecksums;
80+ case ' A' : return WriteResponse::wrAbort;
81+ }
82+ }
83+ printf (" \r Reading Track %i, %s side (retry: %i) - Got %i/11 sectors (%i bad found) " , currentTrack, (currentSide == DiskSurface::dsUpper) ? " Upper" : " Lower" , retryCounter, sectorsFound, badSectorsFound);
84+ return WriteResponse::wrContinue;
85+ });
86+
87+ switch (result) {
88+ case adfrComplete: printf (" \r ADF file created with valid checksums. " ); break ;
89+ case adfrAborted: printf (" \r ADF file aborted. " ); break ;
90+ case adfrFileError: printf (" \r Error creating ADF file. " ); break ;
91+ case adfrFileIOError: printf (" \r Error writing to ADF file. " ); break ;
92+ case adfrCompletedWithErrors: printf (" \r ADF file created with partial success. " ); break ;
93+ case adfrDriveError: printf (" \r Error communicating with the Arduino interface. " ); break ;
94+ }
95+ }
96+
3397int wmain (int argc, wchar_t * argv[], wchar_t *envp[])
3498{
35- printf (" Arduino Amiga Floppydisk Reader, Copyright (C) 2017 Robert Smith\r\n " );
99+ printf (" Arduino Amiga ADF Floppy disk Reader/Writer , Copyright (C) 2017 Robert Smith\r\n " );
36100 printf (" Full sourcecode and documentation at http://amiga.robsmithdev.co.uk\r\n " );
37101 printf (" This is free software licenced under the GNU General Public Licence V3\r\n\r\n " );
38102
39103 if (argc < 3 ) {
40- printf (" Usage:\r\n " );
41- printf (" ArduinoFloppyReader COMPORT OutputFilename.ADF\r\n\r\n " );
104+ printf (" Usage:\r\n\n " );
105+ printf (" To read a disk to an ADF file:\r\n " );
106+ printf (" ArduinoFloppyReader COMPORT OutputFilename.ADF [READ]\r\n\r\n " );
107+ printf (" To write an ADF file to disk:\r\n " );
108+ printf (" ArduinoFloppyReader COMPORT InputFilename.ADF WRITE [VERIFY]\r\n\r\n " );
42109 return 0 ;
43110 }
44-
45- writer.openDevice (_wtoi (argv[1 ]));
46- if (writer.analyseDisk ([](int progress) -> bool {
47- printf (" \r Analysing Disk. %i %% complete" , progress);
48- return true ;
49- }
50- ) == AnalysisResult::arComplete)
51- {
52-
53- ADFResult result = writer.writeADF (argv[2 ], 80 , [](const int currentTrack, const DiskSurface currentSide, const int retryCounter, const int sectorsFound, const int badSectorsFound) ->WriteResponse {
54- if (retryCounter > 15 ) {
55- char input;
56- do {
57- printf (" \r Disk has checksum errors/missing data. [R]etry, [I]gnore, [A]bort? " );
58- input = toupper (getchar ());
59- } while ((input != ' R' ) && (input != ' I' ) && (input != ' A' ));
60- switch (input) {
61- case ' R' : break ;
62- case ' I' : return WriteResponse::wrSkipBadChecksums;
63- case ' A' : return WriteResponse::wrAbort;
64- }
65- }
66- printf (" \r Reading Track %i, %s side (retry: %i) - Got %i/11 sectors (%i bad found) " , currentTrack, (currentSide == DiskSurface::dsUpper) ? " Upper" : " Lower" , retryCounter, sectorsFound, badSectorsFound);
67- return WriteResponse::wrContinue;
68- });
69-
70- switch (result) {
71- case adfrComplete: printf (" \r ADF file created with valid checksums. " ); break ;
72- case adfrAborted: printf (" \r ADF file aborted. " ); break ;
73- case adfrFileError: printf (" \r Error creating ADF file. " ); break ;
74- case adfrFileIOError: printf (" \r Error writing to ADF file. " ); break ;
75- case adfrCompletedWithErrors: printf (" \r ADF file created with partial success. " ); break ;
76- case adfrDriveError: printf (" \r Error communicating with the Arduino interface. " ); break ;
77- }
111+
112+ bool writeMode = false ;
113+ bool verify = false ;
114+ if (argc > 3 ) {
115+ _wcsupr (argv[3 ]);
116+ writeMode = wcscmp (argv[3 ], L" WRITE" ) == 0 ;
78117 }
79- else printf (" \r\n\r\n Error reading disk!\r\n " );
118+ if (argc > 4 ) {
119+ _wcsupr (argv[4 ]);
120+ verify = wcscmp (argv[4 ], L" VERIFY" ) == 0 ;
121+ }
122+
123+ writer.openDevice (_wtoi (argv[1 ]));
124+
125+ if (writeMode) adf2Disk (argv,verify); else disk2ADF (argv);
126+
80127 writer.closeDevice ();
81128
82129
0 commit comments