Read RAW data from the current track and surface
| 628 | |
| 629 | // Read RAW data from the current track and surface |
| 630 | GWResponse GreaseWeazleInterface::checkForDisk(bool force) { |
| 631 | if (force) |
| 632 | if (!checkPins()) return GWResponse::drError; |
| 633 | |
| 634 | if (m_pinDskChangeAvailable) { |
| 635 | return m_diskInDrive ? GWResponse::drOK : GWResponse::drNoDiskInDrive; |
| 636 | } |
| 637 | |
| 638 | if (force) { |
| 639 | GWReadFlux header; |
| 640 | header.ticks = 0; |
| 641 | header.max_index = 2; |
| 642 | header.max_index_linger = 0; |
| 643 | |
| 644 | bool alreadySpun = m_motorIsEnabled; |
| 645 | if (!alreadySpun) |
| 646 | if (enableMotor(true, false) != GWResponse::drOK) return GWResponse::drOK; |
| 647 | |
| 648 | selectDrive(true); |
| 649 | |
| 650 | // Write request |
| 651 | Ack response = Ack::Okay; |
| 652 | if (!sendCommand(Cmd::ReadFlux, (void*)&header, sizeof(header), response)) { |
| 653 | selectDrive(false); |
| 654 | if (response == Ack::BadCommand) return GWResponse::drError; |
| 655 | return GWResponse::drOK; |
| 656 | } |
| 657 | |
| 658 | for (;;) { |
| 659 | // Read a single byte |
| 660 | unsigned char byte; |
| 661 | if (m_comPort.read(&byte, 1)) |
| 662 | if (byte == 0) break; |
| 663 | }; |
| 664 | |
| 665 | // Check for errors |
| 666 | response = Ack::Okay; |
| 667 | sendCommand(Cmd::GetFluxStatus, nullptr, 0, response); |
| 668 | if (response == Ack::BadCommand) return GWResponse::drError; |
| 669 | selectDrive(false); |
| 670 | |
| 671 | if (!alreadySpun) enableMotor(false, false); |
| 672 | |
| 673 | m_diskInDrive = response != Ack::NoIndex; |
| 674 | } |
| 675 | return m_diskInDrive ? GWResponse::drOK : GWResponse::drNoDiskInDrive; |
| 676 | } |
| 677 | |
| 678 | // Read a bit from the MFM data provided |
| 679 | inline int readBit(const unsigned char* buffer, const unsigned int maxLength, int& pos, int& bit) { |