#include extern uint32_t T2_5, T3_5; /**************************************************************************/ /*! @brief Instantiate an MFM-formatted floppy @param floppy An Adafruit_Floppy object that has the pins defined @param format What kind of format we will be parsing out - we DO NOT autodetect! */ /**************************************************************************/ Adafruit_MFM_Floppy::Adafruit_MFM_Floppy(Adafruit_Floppy *floppy, adafruit_floppy_disk_t format) { _floppy = floppy; _format = format; // different formats have different 'hardcoded' sectors and tracks if (_format == IBMPC1440K) { _sectors_per_track = MFM_IBMPC1440K_SECTORS_PER_TRACK; _tracks_per_side = FLOPPY_IBMPC_HD_TRACKS; T2_5 = T2_5_IBMPC_HD; T3_5 = T3_5_IBMPC_HD; } else if (_format == IBMPC360K) { _sectors_per_track = MFM_IBMPC360K_SECTORS_PER_TRACK; _tracks_per_side = FLOPPY_IBMPC_DD_TRACKS; T2_5 = T2_5_IBMPC_DD; T3_5 = T3_5_IBMPC_DD; } } /**************************************************************************/ /*! @brief Initialize and spin up the floppy drive @returns True if we were able to spin up and detect an index track */ /**************************************************************************/ bool Adafruit_MFM_Floppy::begin(void) { if (!_floppy) return false; _floppy->begin(); // now's the time to tweak settings if (_format == IBMPC360K) { _floppy->step_delay_us = 65000UL; // lets make it max 65ms not 10ms? _floppy->settle_delay_ms = 50; // 50ms not 15 } _floppy->select(true); return _floppy->spin_motor(true); } /**************************************************************************/ /*! @brief Spin down and deselect the motor and drive @returns True always */ /**************************************************************************/ bool Adafruit_MFM_Floppy::end(void) { _floppy->spin_motor(false); _floppy->select(false); return true; } /**************************************************************************/ /*! @brief Quick calculator for expected max capacity @returns Size of the drive in bytes */ /**************************************************************************/ uint32_t Adafruit_MFM_Floppy::size(void) { return (uint32_t)_tracks_per_side * FLOPPY_HEADS * _sectors_per_track * MFM_BYTES_PER_SECTOR; } /**************************************************************************/ /*! @brief Read one track's worth of data and MFM decode it @param track track number, 0 to whatever is the max tracks for the given @param head which side to read, false for side 1, true for side 2 format during instantiation (e.g. 40 for DD, 80 for HD) @returns Number of sectors captured, or -1 if we couldn't seek */ /**************************************************************************/ int32_t Adafruit_MFM_Floppy::readTrack(uint8_t track, bool head) { // Serial.printf("\tSeeking track %d head %d...", track, head); if (!_floppy->goto_track(track)) { // Serial.println("failed to seek to track"); return -1; } _floppy->side(head); // Serial.println("done!"); uint32_t captured_sectors = _floppy->read_track_mfm(track_data, _sectors_per_track, track_validity); /* Serial.print("Captured %d sectors", captured_sectors); Serial.print("Validity: "); for(size_t i=0; i