2017-08-05 23:45:52 +00:00
|
|
|
//
|
|
|
|
// i8272.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 05/08/2017.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2017 Thomas Harte. All rights reserved.
|
2017-08-05 23:45:52 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "i8272.hpp"
|
|
|
|
|
2018-06-19 02:37:19 +00:00
|
|
|
#include "../../Outputs/Log.hpp"
|
2017-08-06 02:26:59 +00:00
|
|
|
|
2024-01-19 19:16:13 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
Log::Logger<Log::Source::i8272> logger;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-08-14 12:38:00 +00:00
|
|
|
using namespace Intel::i8272;
|
2017-08-05 23:45:52 +00:00
|
|
|
|
2017-09-11 02:56:05 +00:00
|
|
|
i8272::i8272(BusHandler &bus_handler, Cycles clock_rate) :
|
|
|
|
Storage::Disk::MFMController(clock_rate),
|
2017-10-18 02:11:01 +00:00
|
|
|
bus_handler_(bus_handler) {
|
2020-05-10 03:00:39 +00:00
|
|
|
posit_event(int(Event8272::CommandByte));
|
2020-05-30 23:31:17 +00:00
|
|
|
|
|
|
|
// TODO: implement DMA, etc. I have a vague intention to implement the IBM PC
|
|
|
|
// one day, that should help to force that stuff.
|
|
|
|
(void)bus_handler_;
|
2017-08-06 13:45:16 +00:00
|
|
|
}
|
|
|
|
|
2020-05-10 01:22:51 +00:00
|
|
|
ClockingHint::Preference i8272::preferred_clocking() const {
|
2018-05-28 03:17:06 +00:00
|
|
|
const auto mfm_controller_preferred_clocking = Storage::Disk::MFMController::preferred_clocking();
|
|
|
|
if(mfm_controller_preferred_clocking != ClockingHint::Preference::None) return mfm_controller_preferred_clocking;
|
|
|
|
return is_sleeping_ ? ClockingHint::Preference::None : ClockingHint::Preference::JustInTime;
|
2017-08-20 16:05:00 +00:00
|
|
|
}
|
|
|
|
|
2017-08-06 13:45:16 +00:00
|
|
|
void i8272::run_for(Cycles cycles) {
|
|
|
|
Storage::Disk::MFMController::run_for(cycles);
|
2017-08-06 19:22:07 +00:00
|
|
|
|
2017-08-20 14:43:53 +00:00
|
|
|
if(is_sleeping_) return;
|
|
|
|
|
2017-08-06 19:22:07 +00:00
|
|
|
// check for an expired timer
|
2017-08-06 16:36:18 +00:00
|
|
|
if(delay_time_ > 0) {
|
2019-10-30 02:36:29 +00:00
|
|
|
if(cycles.as_integral() >= delay_time_) {
|
2017-08-06 16:36:18 +00:00
|
|
|
delay_time_ = 0;
|
2020-05-10 03:00:39 +00:00
|
|
|
posit_event(int(Event8272::Timer));
|
2017-08-06 16:36:18 +00:00
|
|
|
} else {
|
2019-10-30 02:36:29 +00:00
|
|
|
delay_time_ -= cycles.as_integral();
|
2017-08-06 16:36:18 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-06 19:22:07 +00:00
|
|
|
|
|
|
|
// update seek status of any drives presently seeking
|
2017-08-14 13:45:39 +00:00
|
|
|
if(drives_seeking_) {
|
2017-08-20 14:43:53 +00:00
|
|
|
int drives_left = drives_seeking_;
|
2017-08-07 16:12:59 +00:00
|
|
|
for(int c = 0; c < 4; c++) {
|
|
|
|
if(drives_[c].phase == Drive::Seeking) {
|
2019-10-30 02:36:29 +00:00
|
|
|
drives_[c].step_rate_counter += cycles.as_integral();
|
|
|
|
auto steps = drives_[c].step_rate_counter / (8000 * step_rate_time_);
|
2017-08-07 16:12:59 +00:00
|
|
|
drives_[c].step_rate_counter %= (8000 * step_rate_time_);
|
|
|
|
while(steps--) {
|
|
|
|
// Perform a step.
|
|
|
|
int direction = (drives_[c].target_head_position < drives_[c].head_position) ? -1 : 1;
|
2024-01-19 19:16:13 +00:00
|
|
|
logger.info().append("Target %d versus believed %d", drives_[c].target_head_position, drives_[c].head_position);
|
2017-09-12 01:25:26 +00:00
|
|
|
select_drive(c);
|
2018-05-07 03:17:36 +00:00
|
|
|
get_drive().step(Storage::Disk::HeadPosition(direction));
|
2017-08-14 14:37:39 +00:00
|
|
|
if(drives_[c].target_head_position >= 0) drives_[c].head_position += direction;
|
2017-08-07 16:12:59 +00:00
|
|
|
|
|
|
|
// Check for completion.
|
2017-09-12 01:25:26 +00:00
|
|
|
if(seek_is_satisfied(c)) {
|
2017-08-07 16:12:59 +00:00
|
|
|
drives_[c].phase = Drive::CompletedSeeking;
|
2017-08-14 13:45:39 +00:00
|
|
|
drives_seeking_--;
|
2017-08-07 16:12:59 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-08-06 19:22:07 +00:00
|
|
|
}
|
2017-08-20 14:43:53 +00:00
|
|
|
|
|
|
|
drives_left--;
|
|
|
|
if(!drives_left) break;
|
2017-08-06 19:22:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-08-12 13:36:21 +00:00
|
|
|
|
|
|
|
// check for any head unloads
|
|
|
|
if(head_timers_running_) {
|
2017-08-20 02:06:56 +00:00
|
|
|
int timers_left = head_timers_running_;
|
2017-08-20 14:32:09 +00:00
|
|
|
for(int c = 0; c < 8; c++) {
|
|
|
|
int drive = (c >> 1);
|
|
|
|
int head = c&1;
|
|
|
|
|
|
|
|
if(drives_[drive].head_unload_delay[head] > 0) {
|
2019-10-30 02:36:29 +00:00
|
|
|
if(cycles.as_integral() >= drives_[drive].head_unload_delay[head]) {
|
2017-08-20 14:32:09 +00:00
|
|
|
drives_[drive].head_unload_delay[head] = 0;
|
|
|
|
drives_[drive].head_is_loaded[head] = false;
|
|
|
|
head_timers_running_--;
|
|
|
|
} else {
|
2019-10-30 02:36:29 +00:00
|
|
|
drives_[drive].head_unload_delay[head] -= cycles.as_integral();
|
2017-08-12 13:36:21 +00:00
|
|
|
}
|
2017-08-20 14:32:09 +00:00
|
|
|
timers_left--;
|
|
|
|
if(!timers_left) break;
|
2017-08-12 13:36:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-08-20 14:43:53 +00:00
|
|
|
|
2017-09-16 00:26:41 +00:00
|
|
|
// check for busy plus ready disabled
|
|
|
|
if(is_executing_ && !get_drive().get_is_ready()) {
|
2020-05-10 03:00:39 +00:00
|
|
|
posit_event(int(Event8272::NoLongerReady));
|
2017-09-16 00:26:41 +00:00
|
|
|
}
|
|
|
|
|
2017-08-20 14:43:53 +00:00
|
|
|
is_sleeping_ = !delay_time_ && !drives_seeking_ && !head_timers_running_;
|
2018-05-28 03:17:06 +00:00
|
|
|
if(is_sleeping_) update_clocking_observer();
|
2017-08-06 13:45:16 +00:00
|
|
|
}
|
|
|
|
|
2020-01-05 18:40:02 +00:00
|
|
|
void i8272::write(int address, uint8_t value) {
|
2017-08-06 16:36:18 +00:00
|
|
|
// don't consider attempted sets to the status register
|
2017-08-06 02:26:59 +00:00
|
|
|
if(!address) return;
|
|
|
|
|
2017-08-06 16:36:18 +00:00
|
|
|
// if not ready for commands, do nothing
|
2023-11-26 20:04:01 +00:00
|
|
|
if(!status_.get(MainStatus::DataReady) || status_.get(MainStatus::DataIsToProcessor)) return;
|
2017-08-06 02:26:59 +00:00
|
|
|
|
2017-08-13 16:50:07 +00:00
|
|
|
if(expects_input_) {
|
|
|
|
input_ = value;
|
|
|
|
has_input_ = true;
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(MainStatus::DataReady, false);
|
2017-08-13 16:50:07 +00:00
|
|
|
} else {
|
|
|
|
// accumulate latest byte in the command byte sequence
|
|
|
|
command_.push_back(value);
|
2020-05-10 03:00:39 +00:00
|
|
|
posit_event(int(Event8272::CommandByte));
|
2017-08-13 16:50:07 +00:00
|
|
|
}
|
2017-08-05 23:45:52 +00:00
|
|
|
}
|
|
|
|
|
2020-01-05 18:40:02 +00:00
|
|
|
uint8_t i8272::read(int address) {
|
2017-08-06 02:26:59 +00:00
|
|
|
if(address) {
|
2017-08-07 00:17:12 +00:00
|
|
|
if(result_stack_.empty()) return 0xff;
|
|
|
|
uint8_t result = result_stack_.back();
|
|
|
|
result_stack_.pop_back();
|
2020-05-10 03:00:39 +00:00
|
|
|
if(result_stack_.empty()) posit_event(int(Event8272::ResultEmpty));
|
2017-08-07 00:17:12 +00:00
|
|
|
|
2017-08-06 16:55:57 +00:00
|
|
|
return result;
|
2017-08-06 02:26:59 +00:00
|
|
|
} else {
|
2023-11-26 20:04:01 +00:00
|
|
|
return status_.main();
|
2017-08-06 02:26:59 +00:00
|
|
|
}
|
2017-08-05 23:45:52 +00:00
|
|
|
}
|
2017-08-06 13:45:16 +00:00
|
|
|
|
2017-08-06 16:36:18 +00:00
|
|
|
#define BEGIN_SECTION() switch(resume_point_) { default:
|
|
|
|
#define END_SECTION() }
|
|
|
|
|
2017-08-12 13:44:01 +00:00
|
|
|
#define MS_TO_CYCLES(x) x * 8000
|
2020-05-10 03:00:39 +00:00
|
|
|
#define WAIT_FOR_EVENT(mask) resume_point_ = __LINE__; interesting_event_mask_ = int(mask); return; case __LINE__:
|
|
|
|
#define WAIT_FOR_TIME(ms) resume_point_ = __LINE__; interesting_event_mask_ = int(Event8272::Timer); delay_time_ = MS_TO_CYCLES(ms); is_sleeping_ = false; update_clocking_observer(); case __LINE__: if(delay_time_) return;
|
2017-08-06 16:36:18 +00:00
|
|
|
|
2017-08-07 00:32:46 +00:00
|
|
|
#define PASTE(x, y) x##y
|
|
|
|
#define CONCAT(x, y) PASTE(x, y)
|
|
|
|
|
2017-08-06 22:06:20 +00:00
|
|
|
#define FIND_HEADER() \
|
2017-08-15 20:05:10 +00:00
|
|
|
set_data_mode(DataMode::Scanning); \
|
2020-05-10 03:00:39 +00:00
|
|
|
CONCAT(find_header, __LINE__): WAIT_FOR_EVENT(int(Event::Token) | int(Event::IndexHole)); \
|
|
|
|
if(event_type == int(Event::IndexHole)) { index_hole_limit_--; } \
|
2017-08-07 00:32:46 +00:00
|
|
|
else if(get_latest_token().type == Token::ID) goto CONCAT(header_found, __LINE__); \
|
|
|
|
\
|
|
|
|
if(index_hole_limit_) goto CONCAT(find_header, __LINE__); \
|
2017-11-12 21:34:51 +00:00
|
|
|
CONCAT(header_found, __LINE__): (void)0;\
|
2017-08-07 00:32:46 +00:00
|
|
|
|
2017-08-07 00:40:29 +00:00
|
|
|
#define FIND_DATA() \
|
2017-08-15 20:05:10 +00:00
|
|
|
set_data_mode(DataMode::Scanning); \
|
2020-05-10 03:00:39 +00:00
|
|
|
CONCAT(find_data, __LINE__): WAIT_FOR_EVENT(int(Event::Token) | int(Event::IndexHole)); \
|
|
|
|
if(event_type == int(Event::Token)) { \
|
2017-08-16 00:16:56 +00:00
|
|
|
if(get_latest_token().type == Token::Byte || get_latest_token().type == Token::Sync) goto CONCAT(find_data, __LINE__); \
|
2017-08-16 00:12:01 +00:00
|
|
|
}
|
2017-08-07 00:40:29 +00:00
|
|
|
|
2017-08-06 22:06:20 +00:00
|
|
|
#define READ_HEADER() \
|
2017-08-07 00:40:29 +00:00
|
|
|
distance_into_section_ = 0; \
|
2017-08-15 20:05:10 +00:00
|
|
|
set_data_mode(DataMode::Reading); \
|
2017-08-07 00:32:46 +00:00
|
|
|
CONCAT(read_header, __LINE__): WAIT_FOR_EVENT(Event::Token); \
|
2017-08-07 00:40:29 +00:00
|
|
|
header_[distance_into_section_] = get_latest_token().byte_value; \
|
|
|
|
distance_into_section_++; \
|
2017-08-07 16:37:22 +00:00
|
|
|
if(distance_into_section_ < 6) goto CONCAT(read_header, __LINE__); \
|
2017-08-15 20:05:10 +00:00
|
|
|
|
2017-08-07 00:32:46 +00:00
|
|
|
#define SET_DRIVE_HEAD_MFM() \
|
2023-11-24 23:24:58 +00:00
|
|
|
active_drive_ = command_.target().drive; \
|
|
|
|
active_head_ = command_.target().head; \
|
2017-09-12 01:25:26 +00:00
|
|
|
select_drive(active_drive_); \
|
2017-10-07 01:45:12 +00:00
|
|
|
get_drive().set_head(active_head_); \
|
2023-11-24 23:24:58 +00:00
|
|
|
set_is_double_density(command_.target().mfm);
|
2017-08-06 22:06:20 +00:00
|
|
|
|
2017-08-15 20:05:10 +00:00
|
|
|
#define WAIT_FOR_BYTES(n) \
|
|
|
|
distance_into_section_ = 0; \
|
|
|
|
CONCAT(wait_bytes, __LINE__): WAIT_FOR_EVENT(Event::Token); \
|
|
|
|
if(get_latest_token().type == Token::Byte) distance_into_section_++; \
|
|
|
|
if(distance_into_section_ < (n)) goto CONCAT(wait_bytes, __LINE__);
|
|
|
|
|
2017-08-12 13:36:21 +00:00
|
|
|
#define LOAD_HEAD() \
|
|
|
|
if(!drives_[active_drive_].head_is_loaded[active_head_]) { \
|
|
|
|
drives_[active_drive_].head_is_loaded[active_head_] = true; \
|
|
|
|
WAIT_FOR_TIME(head_load_time_); \
|
|
|
|
} else { \
|
|
|
|
if(drives_[active_drive_].head_unload_delay[active_head_] > 0) { \
|
|
|
|
drives_[active_drive_].head_unload_delay[active_head_] = 0; \
|
|
|
|
head_timers_running_--; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SCHEDULE_HEAD_UNLOAD() \
|
2017-08-12 16:53:45 +00:00
|
|
|
if(drives_[active_drive_].head_is_loaded[active_head_]) {\
|
|
|
|
if(drives_[active_drive_].head_unload_delay[active_head_] == 0) { \
|
|
|
|
head_timers_running_++; \
|
2017-08-20 14:43:53 +00:00
|
|
|
is_sleeping_ = false; \
|
2018-05-28 03:17:06 +00:00
|
|
|
update_clocking_observer(); \
|
2017-08-12 16:53:45 +00:00
|
|
|
} \
|
|
|
|
drives_[active_drive_].head_unload_delay[active_head_] = MS_TO_CYCLES(head_unload_time_);\
|
|
|
|
}
|
2017-08-12 13:36:21 +00:00
|
|
|
|
2017-08-06 23:25:44 +00:00
|
|
|
void i8272::posit_event(int event_type) {
|
2020-05-10 03:00:39 +00:00
|
|
|
if(event_type == int(Event::IndexHole)) index_hole_count_++;
|
|
|
|
if(event_type == int(Event8272::NoLongerReady)) {
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(Status0::NotReady);
|
2017-09-16 00:26:41 +00:00
|
|
|
goto abort;
|
|
|
|
}
|
2017-08-06 23:25:44 +00:00
|
|
|
if(!(interesting_event_mask_ & event_type)) return;
|
|
|
|
interesting_event_mask_ &= ~event_type;
|
2017-08-06 16:36:18 +00:00
|
|
|
|
|
|
|
BEGIN_SECTION();
|
|
|
|
|
2017-08-07 11:27:00 +00:00
|
|
|
// Resets busy and non-DMA execution, clears the command buffer, sets the data mode to scanning and flows
|
|
|
|
// into wait_for_complete_command_sequence.
|
2017-08-06 16:36:18 +00:00
|
|
|
wait_for_command:
|
2017-08-13 16:50:07 +00:00
|
|
|
expects_input_ = false;
|
2017-08-07 02:14:18 +00:00
|
|
|
set_data_mode(Storage::Disk::MFMController::DataMode::Scanning);
|
2023-11-29 03:34:34 +00:00
|
|
|
status_.set(MainStatus::CommandInProgress, false);
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(MainStatus::InNonDMAExecution, false);
|
2017-08-07 02:14:18 +00:00
|
|
|
command_.clear();
|
2017-08-06 16:36:18 +00:00
|
|
|
|
2017-08-07 11:27:00 +00:00
|
|
|
// Sets the data request bit, and waits for a byte. Then sets the busy bit. Continues accepting bytes
|
|
|
|
// until it has a quantity that make up an entire command, then resets the data request bit and
|
|
|
|
// branches to that command.
|
2017-08-06 16:36:18 +00:00
|
|
|
wait_for_complete_command_sequence:
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(MainStatus::DataReady, true);
|
|
|
|
status_.set(MainStatus::DataIsToProcessor, false);
|
2017-08-07 02:14:18 +00:00
|
|
|
WAIT_FOR_EVENT(Event8272::CommandByte)
|
|
|
|
|
2023-11-24 23:24:58 +00:00
|
|
|
if(!command_.has_command()) {
|
|
|
|
goto wait_for_complete_command_sequence;
|
|
|
|
}
|
2023-11-26 20:04:01 +00:00
|
|
|
|
|
|
|
status_.begin(command_);
|
2023-11-25 23:10:49 +00:00
|
|
|
if(command_.has_geometry()) {
|
2023-11-24 23:24:58 +00:00
|
|
|
cylinder_ = command_.geometry().cylinder;
|
|
|
|
head_ = command_.geometry().head;
|
|
|
|
sector_ = command_.geometry().sector;
|
|
|
|
size_ = command_.geometry().size;
|
2017-08-15 02:27:31 +00:00
|
|
|
}
|
2017-08-14 14:37:39 +00:00
|
|
|
|
|
|
|
// If this is not clearly a command that's safe to carry out in parallel to a seek, end all seeks.
|
2023-11-26 20:29:08 +00:00
|
|
|
is_access_command_ = command_.is_access();
|
2017-08-14 14:37:39 +00:00
|
|
|
|
2017-08-16 01:49:10 +00:00
|
|
|
if(is_access_command_) {
|
|
|
|
for(int c = 0; c < 4; c++) {
|
|
|
|
if(drives_[c].phase == Drive::Seeking) {
|
|
|
|
drives_[c].phase = Drive::NotSeeking;
|
|
|
|
drives_seeking_--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Establishes the drive and head being addressed, and whether in double density mode; populates the internal
|
|
|
|
// cylinder, head, sector and size registers from the command stream.
|
2017-09-16 00:26:41 +00:00
|
|
|
is_executing_ = true;
|
2023-11-26 20:04:01 +00:00
|
|
|
if(!dma_mode_) {
|
|
|
|
status_.set(MainStatus::InNonDMAExecution, true);
|
|
|
|
}
|
2017-08-16 01:49:10 +00:00
|
|
|
SET_DRIVE_HEAD_MFM();
|
|
|
|
LOAD_HEAD();
|
2017-09-13 00:43:53 +00:00
|
|
|
if(!get_drive().get_is_ready()) {
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(Status0::NotReady);
|
2017-09-13 00:43:53 +00:00
|
|
|
goto abort;
|
|
|
|
}
|
2017-08-16 01:49:10 +00:00
|
|
|
}
|
|
|
|
|
2017-08-14 14:37:39 +00:00
|
|
|
// Jump to the proper place.
|
2023-11-24 23:24:58 +00:00
|
|
|
switch(command_.command()) {
|
|
|
|
case Command::ReadData:
|
|
|
|
case Command::ReadDeletedData:
|
2017-08-12 17:01:17 +00:00
|
|
|
goto read_data;
|
2017-08-07 02:14:18 +00:00
|
|
|
|
2023-11-24 23:24:58 +00:00
|
|
|
case Command::WriteData:
|
|
|
|
case Command::WriteDeletedData:
|
2017-08-13 16:50:07 +00:00
|
|
|
goto write_data;
|
2017-08-07 02:14:18 +00:00
|
|
|
|
2023-11-24 23:24:58 +00:00
|
|
|
case Command::ReadTrack: goto read_track;
|
|
|
|
case Command::ReadID: goto read_id;
|
|
|
|
case Command::FormatTrack: goto format_track;
|
2017-08-15 15:06:10 +00:00
|
|
|
|
2023-11-24 23:24:58 +00:00
|
|
|
case Command::ScanLow: goto scan_low;
|
|
|
|
case Command::ScanLowOrEqual: goto scan_low_or_equal;
|
|
|
|
case Command::ScanHighOrEqual: goto scan_high_or_equal;
|
2017-08-15 15:06:10 +00:00
|
|
|
|
2023-11-24 23:24:58 +00:00
|
|
|
case Command::Recalibrate: goto recalibrate;
|
|
|
|
case Command::Seek: goto seek;
|
2017-08-15 15:06:10 +00:00
|
|
|
|
2023-11-24 23:24:58 +00:00
|
|
|
case Command::SenseInterruptStatus: goto sense_interrupt_status;
|
|
|
|
case Command::Specify: goto specify;
|
|
|
|
case Command::SenseDriveStatus: goto sense_drive_status;
|
2017-08-15 15:06:10 +00:00
|
|
|
|
|
|
|
default: goto invalid;
|
2017-08-07 02:14:18 +00:00
|
|
|
}
|
2017-08-06 16:36:18 +00:00
|
|
|
|
2017-08-13 16:50:07 +00:00
|
|
|
// Decodes drive, head and density, loads the head, loads the internal cylinder, head, sector and size registers,
|
|
|
|
// and searches for a sector that meets those criteria. If one is found, inspects the instruction in use and
|
|
|
|
// jumps to an appropriate handler.
|
|
|
|
read_write_find_header:
|
2017-08-07 02:14:18 +00:00
|
|
|
|
2017-08-07 11:27:00 +00:00
|
|
|
// Sets a maximum index hole limit of 2 then performs a find header/read header loop, continuing either until
|
|
|
|
// the index hole limit is breached or a sector is found with a cylinder, head, sector and size equal to the
|
|
|
|
// values in the internal registers.
|
2017-08-16 00:12:01 +00:00
|
|
|
index_hole_limit_ = 2;
|
2024-01-19 19:16:13 +00:00
|
|
|
// logger.info().append("Seeking " << PADDEC(0) << cylinder_ << " " << head_ " " << sector_ << " " << size_);
|
2017-08-07 02:14:18 +00:00
|
|
|
find_next_sector:
|
|
|
|
FIND_HEADER();
|
2017-08-12 20:36:37 +00:00
|
|
|
if(!index_hole_limit_) {
|
|
|
|
// Two index holes have passed wihout finding the header sought.
|
2024-01-19 19:16:13 +00:00
|
|
|
// logger.info().append("Not found");
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(Status1::NoData);
|
2017-08-16 00:12:01 +00:00
|
|
|
goto abort;
|
2017-08-12 20:36:37 +00:00
|
|
|
}
|
2017-08-16 00:12:01 +00:00
|
|
|
index_hole_count_ = 0;
|
2024-01-19 19:16:13 +00:00
|
|
|
// logger.info().append("Header");
|
2017-08-07 02:14:18 +00:00
|
|
|
READ_HEADER();
|
2017-08-16 00:12:01 +00:00
|
|
|
if(index_hole_count_) {
|
|
|
|
// This implies an index hole was sighted within the header. Error out.
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(Status1::EndOfCylinder);
|
2017-08-16 00:12:01 +00:00
|
|
|
goto abort;
|
|
|
|
}
|
2017-08-12 20:36:37 +00:00
|
|
|
if(get_crc_generator().get_value()) {
|
|
|
|
// This implies a CRC error in the header; mark as such but continue.
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(Status1::DataError);
|
2017-08-12 20:36:37 +00:00
|
|
|
}
|
2024-01-19 19:16:13 +00:00
|
|
|
// logger.info().append("Considering %02x %02x %02x %02x [%04x]", header_[0], header_[1], header_[2], header_[3], get_crc_generator().get_value());
|
2017-08-07 02:14:18 +00:00
|
|
|
if(header_[0] != cylinder_ || header_[1] != head_ || header_[2] != sector_ || header_[3] != size_) goto find_next_sector;
|
|
|
|
|
2017-08-13 16:50:07 +00:00
|
|
|
// Branch to whatever is supposed to happen next
|
2024-01-19 19:16:13 +00:00
|
|
|
// logger.info().append("Proceeding");
|
2023-11-24 23:24:58 +00:00
|
|
|
switch(command_.command()) {
|
|
|
|
default:
|
|
|
|
case Command::ReadData:
|
|
|
|
case Command::ReadDeletedData:
|
2017-08-13 16:50:07 +00:00
|
|
|
goto read_data_found_header;
|
|
|
|
|
2023-11-24 23:24:58 +00:00
|
|
|
case Command::WriteData: // write data
|
|
|
|
case Command::WriteDeletedData: // write deleted data
|
2017-08-13 16:50:07 +00:00
|
|
|
goto write_data_found_header;
|
|
|
|
}
|
|
|
|
|
2017-08-15 15:06:10 +00:00
|
|
|
|
2017-08-13 16:50:07 +00:00
|
|
|
// Performs the read data or read deleted data command.
|
|
|
|
read_data:
|
2024-01-19 19:16:13 +00:00
|
|
|
// logger.info().append("Read [deleted] data [%02x %02x %02x %02x ... %02x %02x]",
|
|
|
|
// command_[2],
|
|
|
|
// command_[3],
|
|
|
|
// command_[4],
|
|
|
|
// command_[5],
|
|
|
|
// command_[6],
|
|
|
|
// command_[8]);
|
2017-08-13 16:50:07 +00:00
|
|
|
read_next_data:
|
|
|
|
goto read_write_find_header;
|
|
|
|
|
2017-08-12 17:01:17 +00:00
|
|
|
// Finds the next data block and sets data mode to reading, setting an error flag if the on-disk deleted
|
|
|
|
// flag doesn't match the sort the command was looking for.
|
2017-08-13 16:50:07 +00:00
|
|
|
read_data_found_header:
|
2017-08-07 02:14:18 +00:00
|
|
|
FIND_DATA();
|
2023-11-26 20:04:01 +00:00
|
|
|
// TODO: should Status2::DeletedControlMark be cleared?
|
2020-05-10 03:00:39 +00:00
|
|
|
if(event_type == int(Event::Token)) {
|
2017-08-16 00:12:01 +00:00
|
|
|
if(get_latest_token().type != Token::Data && get_latest_token().type != Token::DeletedData) {
|
2018-05-13 19:34:31 +00:00
|
|
|
// Something other than a data mark came next, impliedly an ID or index mark.
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(Status1::MissingAddressMark);
|
|
|
|
status_.set(Status2::MissingDataAddressMark);
|
2017-08-16 00:12:01 +00:00
|
|
|
goto abort; // TODO: or read_next_data?
|
2017-08-12 20:36:37 +00:00
|
|
|
} else {
|
2023-11-24 23:24:58 +00:00
|
|
|
if((get_latest_token().type == Token::Data) != (command_.command() == Command::ReadData)) {
|
|
|
|
if(!command_.target().skip_deleted) {
|
2017-08-16 00:12:01 +00:00
|
|
|
// SK is not set; set the error flag but read this sector before finishing.
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(Status2::DeletedControlMark);
|
2017-08-16 00:12:01 +00:00
|
|
|
} else {
|
|
|
|
// SK is set; skip this sector.
|
|
|
|
goto read_next_data;
|
|
|
|
}
|
|
|
|
}
|
2017-08-12 20:36:37 +00:00
|
|
|
}
|
2017-08-16 00:12:01 +00:00
|
|
|
} else {
|
|
|
|
// An index hole appeared before the data mark.
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(Status1::EndOfCylinder);
|
2017-08-16 00:12:01 +00:00
|
|
|
goto abort; // TODO: or read_next_data?
|
2017-08-12 20:36:37 +00:00
|
|
|
}
|
2017-08-14 16:42:48 +00:00
|
|
|
|
|
|
|
distance_into_section_ = 0;
|
2017-08-07 02:14:18 +00:00
|
|
|
set_data_mode(Reading);
|
|
|
|
|
2017-08-07 11:27:00 +00:00
|
|
|
// Waits for the next token, then supplies it to the CPU by: (i) setting data request and direction; and (ii) resetting
|
|
|
|
// data request once the byte has been taken. Continues until all bytes have been read.
|
|
|
|
//
|
2017-08-14 16:42:48 +00:00
|
|
|
// TODO: consider DTL.
|
2017-08-14 18:34:56 +00:00
|
|
|
read_data_get_byte:
|
2020-05-10 03:00:39 +00:00
|
|
|
WAIT_FOR_EVENT(int(Event::Token) | int(Event::IndexHole));
|
|
|
|
if(event_type == int(Event::Token)) {
|
2017-08-16 00:12:01 +00:00
|
|
|
result_stack_.push_back(get_latest_token().byte_value);
|
|
|
|
distance_into_section_++;
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(MainStatus::DataReady, true);
|
|
|
|
status_.set(MainStatus::DataIsToProcessor, true);
|
2020-05-10 03:00:39 +00:00
|
|
|
WAIT_FOR_EVENT(int(Event8272::ResultEmpty) | int(Event::Token) | int(Event::IndexHole));
|
2017-08-16 00:12:01 +00:00
|
|
|
}
|
2017-08-12 20:36:37 +00:00
|
|
|
switch(event_type) {
|
2020-05-10 03:00:39 +00:00
|
|
|
case int(Event8272::ResultEmpty): // The caller read the byte in time; proceed as normal.
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(MainStatus::DataReady, false);
|
2017-08-14 18:34:56 +00:00
|
|
|
if(distance_into_section_ < (128 << size_)) goto read_data_get_byte;
|
2017-08-12 20:36:37 +00:00
|
|
|
break;
|
2020-05-10 03:00:39 +00:00
|
|
|
case int(Event::Token): // The caller hasn't read the old byte yet and a new one has arrived
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(Status1::OverRun);
|
2017-08-16 00:12:01 +00:00
|
|
|
goto abort;
|
2017-08-12 20:36:37 +00:00
|
|
|
break;
|
2020-05-10 03:00:39 +00:00
|
|
|
case int(Event::IndexHole):
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(Status1::EndOfCylinder);
|
2017-08-16 00:12:01 +00:00
|
|
|
goto abort;
|
2017-08-12 20:36:37 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-08-07 02:14:18 +00:00
|
|
|
|
2017-08-12 20:36:37 +00:00
|
|
|
// read CRC, without transferring it, then check it
|
2017-08-07 16:37:22 +00:00
|
|
|
WAIT_FOR_EVENT(Event::Token);
|
|
|
|
WAIT_FOR_EVENT(Event::Token);
|
2017-08-12 20:36:37 +00:00
|
|
|
if(get_crc_generator().get_value()) {
|
|
|
|
// This implies a CRC error in the sector; mark as such and temrinate.
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(Status1::DataError);
|
|
|
|
status_.set(Status2::DataCRCError);
|
2017-08-16 00:12:01 +00:00
|
|
|
goto abort;
|
2017-08-12 20:36:37 +00:00
|
|
|
}
|
2017-08-07 16:37:22 +00:00
|
|
|
|
2017-08-12 20:36:37 +00:00
|
|
|
// check whether that's it: either the final requested sector has been read, or because
|
|
|
|
// a sector that was [/wasn't] marked as deleted when it shouldn't [/should] have been
|
2023-11-26 20:04:01 +00:00
|
|
|
if(sector_ != command_.geometry().end_of_track && !status_.get(Status2::DeletedControlMark)) {
|
2017-08-10 15:11:26 +00:00
|
|
|
sector_++;
|
|
|
|
goto read_next_data;
|
|
|
|
}
|
|
|
|
|
2017-08-07 11:27:00 +00:00
|
|
|
// For a final result phase, post the standard ST0, ST1, ST2, C, H, R, N
|
2017-08-07 02:14:18 +00:00
|
|
|
goto post_st012chrn;
|
|
|
|
|
2017-08-06 16:36:18 +00:00
|
|
|
write_data:
|
2024-01-19 19:16:13 +00:00
|
|
|
// logger.info().append("Write [deleted] data [%02x %02x %02x %02x ... %02x %02x]",
|
|
|
|
// command_[2],
|
|
|
|
// command_[3],
|
|
|
|
// command_[4],
|
|
|
|
// command_[5],
|
|
|
|
// command_[6],
|
|
|
|
// command_[8]);
|
2017-08-14 16:53:18 +00:00
|
|
|
|
2017-09-12 01:25:26 +00:00
|
|
|
if(get_drive().get_is_read_only()) {
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(Status1::NotWriteable);
|
2017-08-16 00:12:01 +00:00
|
|
|
goto abort;
|
2017-08-14 16:53:18 +00:00
|
|
|
}
|
2017-08-06 16:36:18 +00:00
|
|
|
|
2017-08-13 16:50:07 +00:00
|
|
|
write_next_data:
|
|
|
|
goto read_write_find_header;
|
|
|
|
|
|
|
|
write_data_found_header:
|
2017-08-15 20:05:10 +00:00
|
|
|
WAIT_FOR_BYTES(get_is_double_density() ? 22 : 11);
|
|
|
|
begin_writing(true);
|
2017-08-13 16:50:07 +00:00
|
|
|
|
2023-11-24 23:24:58 +00:00
|
|
|
write_id_data_joiner(command_.command() == Command::WriteDeletedData, true);
|
2017-08-13 16:50:07 +00:00
|
|
|
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(MainStatus::DataIsToProcessor, false);
|
|
|
|
status_.set(MainStatus::DataReady, true);
|
2017-08-13 16:50:07 +00:00
|
|
|
expects_input_ = true;
|
|
|
|
distance_into_section_ = 0;
|
|
|
|
|
|
|
|
write_loop:
|
|
|
|
WAIT_FOR_EVENT(Event::DataWritten);
|
|
|
|
if(!has_input_) {
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(Status1::OverRun);
|
2017-08-16 00:12:01 +00:00
|
|
|
goto abort;
|
2017-08-13 16:50:07 +00:00
|
|
|
}
|
|
|
|
write_byte(input_);
|
|
|
|
has_input_ = false;
|
|
|
|
distance_into_section_++;
|
|
|
|
if(distance_into_section_ < (128 << size_)) {
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(MainStatus::DataReady, true);
|
2017-08-13 16:50:07 +00:00
|
|
|
goto write_loop;
|
|
|
|
}
|
|
|
|
|
2024-01-19 19:16:13 +00:00
|
|
|
logger.info().append("Wrote %d bytes", distance_into_section_);
|
2017-08-13 22:05:19 +00:00
|
|
|
write_crc();
|
2017-08-13 16:50:07 +00:00
|
|
|
expects_input_ = false;
|
|
|
|
WAIT_FOR_EVENT(Event::DataWritten);
|
2017-09-15 02:30:40 +00:00
|
|
|
end_writing();
|
2017-08-13 16:50:07 +00:00
|
|
|
|
2023-11-24 23:24:58 +00:00
|
|
|
if(sector_ != command_.geometry().end_of_track) {
|
2017-08-15 14:50:28 +00:00
|
|
|
sector_++;
|
|
|
|
goto write_next_data;
|
|
|
|
}
|
|
|
|
|
2017-08-13 16:50:07 +00:00
|
|
|
goto post_st012chrn;
|
2017-08-06 16:36:18 +00:00
|
|
|
|
2017-08-07 11:27:00 +00:00
|
|
|
// Performs the read ID command.
|
2017-08-06 16:36:18 +00:00
|
|
|
read_id:
|
2017-08-07 11:27:00 +00:00
|
|
|
// Establishes the drive and head being addressed, and whether in double density mode.
|
2024-01-19 19:16:13 +00:00
|
|
|
// logger.info().append("Read ID [%02x %02x]", command_[0], command_[1]);
|
2017-08-07 00:32:46 +00:00
|
|
|
|
2017-08-07 11:27:00 +00:00
|
|
|
// Sets a maximum index hole limit of 2 then waits either until it finds a header mark or sees too many index holes.
|
|
|
|
// If a header mark is found, reads in the following bytes that produce a header. Otherwise branches to data not found.
|
2017-08-07 02:14:18 +00:00
|
|
|
index_hole_limit_ = 2;
|
|
|
|
FIND_HEADER();
|
2017-08-12 20:36:37 +00:00
|
|
|
if(!index_hole_limit_) {
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(Status1::MissingAddressMark);
|
2017-08-16 00:12:01 +00:00
|
|
|
goto abort;
|
2017-08-12 20:36:37 +00:00
|
|
|
}
|
2017-08-07 02:14:18 +00:00
|
|
|
READ_HEADER();
|
2017-08-07 00:32:46 +00:00
|
|
|
|
2017-08-07 11:27:00 +00:00
|
|
|
// Sets internal registers from the discovered header and posts the standard ST0, ST1, ST2, C, H, R, N.
|
2017-08-07 02:14:18 +00:00
|
|
|
cylinder_ = header_[0];
|
|
|
|
head_ = header_[1];
|
|
|
|
sector_ = header_[2];
|
|
|
|
size_ = header_[3];
|
2017-08-07 00:32:46 +00:00
|
|
|
|
2017-08-07 02:14:18 +00:00
|
|
|
goto post_st012chrn;
|
2017-08-07 00:32:46 +00:00
|
|
|
|
2017-08-14 18:34:56 +00:00
|
|
|
// Performs read track.
|
|
|
|
read_track:
|
2024-01-19 19:16:13 +00:00
|
|
|
// logger.info().append("Read track [%02x %02x %02x %02x]"
|
|
|
|
// command_[2],
|
|
|
|
// command_[3],
|
|
|
|
// command_[4],
|
|
|
|
// command_[5]);
|
2017-08-14 18:34:56 +00:00
|
|
|
|
|
|
|
// Wait for the index hole.
|
|
|
|
WAIT_FOR_EVENT(Event::IndexHole);
|
|
|
|
|
|
|
|
sector_ = 0;
|
|
|
|
index_hole_limit_ = 2;
|
|
|
|
|
|
|
|
// While not index hole again, stream all sector contents until EOT sectors have been read.
|
|
|
|
read_track_next_sector:
|
|
|
|
FIND_HEADER();
|
|
|
|
if(!index_hole_limit_) {
|
|
|
|
if(!sector_) {
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(Status1::MissingAddressMark);
|
2017-08-16 00:12:01 +00:00
|
|
|
goto abort;
|
2017-08-14 18:34:56 +00:00
|
|
|
} else {
|
|
|
|
goto post_st012chrn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
READ_HEADER();
|
|
|
|
|
|
|
|
FIND_DATA();
|
|
|
|
distance_into_section_ = 0;
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(MainStatus::DataIsToProcessor, true);
|
2017-08-14 18:34:56 +00:00
|
|
|
read_track_get_byte:
|
|
|
|
WAIT_FOR_EVENT(Event::Token);
|
|
|
|
result_stack_.push_back(get_latest_token().byte_value);
|
|
|
|
distance_into_section_++;
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(MainStatus::DataReady, true);
|
2017-08-14 18:34:56 +00:00
|
|
|
// TODO: other possible exit conditions; find a way to merge with the read_data version of this.
|
2020-05-10 03:00:39 +00:00
|
|
|
WAIT_FOR_EVENT(int(Event8272::ResultEmpty));
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(MainStatus::DataReady, false);
|
2017-08-14 18:34:56 +00:00
|
|
|
if(distance_into_section_ < (128 << header_[2])) goto read_track_get_byte;
|
|
|
|
|
|
|
|
sector_++;
|
2023-11-24 23:24:58 +00:00
|
|
|
if(sector_ < command_.geometry().end_of_track) goto read_track_next_sector;
|
2017-08-14 18:34:56 +00:00
|
|
|
|
|
|
|
goto post_st012chrn;
|
|
|
|
|
|
|
|
// Performs format [/write] track.
|
2017-08-06 16:36:18 +00:00
|
|
|
format_track:
|
2024-01-19 19:16:13 +00:00
|
|
|
logger.info().append("Format track");
|
2017-09-12 01:25:26 +00:00
|
|
|
if(get_drive().get_is_read_only()) {
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(Status1::NotWriteable);
|
2017-08-16 00:12:01 +00:00
|
|
|
goto abort;
|
2017-08-14 16:53:18 +00:00
|
|
|
}
|
|
|
|
|
2017-08-13 22:05:19 +00:00
|
|
|
// Wait for the index hole.
|
|
|
|
WAIT_FOR_EVENT(Event::IndexHole);
|
2017-08-15 20:05:10 +00:00
|
|
|
index_hole_count_ = 0;
|
|
|
|
begin_writing(true);
|
2017-08-13 22:05:19 +00:00
|
|
|
|
|
|
|
// Write start-of-track.
|
2017-08-14 20:03:35 +00:00
|
|
|
write_start_of_track();
|
2017-08-13 22:05:19 +00:00
|
|
|
WAIT_FOR_EVENT(Event::DataWritten);
|
|
|
|
sector_ = 0;
|
|
|
|
|
|
|
|
format_track_write_sector:
|
2017-08-14 20:03:35 +00:00
|
|
|
write_id_joiner();
|
2017-08-13 22:05:19 +00:00
|
|
|
|
|
|
|
// Write the sector header, obtaining its contents
|
|
|
|
// from the processor.
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(MainStatus::DataIsToProcessor, false);
|
|
|
|
status_.set(MainStatus::DataReady, true);
|
2017-08-13 22:05:19 +00:00
|
|
|
expects_input_ = true;
|
|
|
|
distance_into_section_ = 0;
|
|
|
|
format_track_write_header:
|
2020-05-10 03:00:39 +00:00
|
|
|
WAIT_FOR_EVENT(int(Event::DataWritten) | int(Event::IndexHole));
|
2017-08-15 20:05:10 +00:00
|
|
|
switch(event_type) {
|
2020-05-10 03:00:39 +00:00
|
|
|
case int(Event::IndexHole):
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(Status1::OverRun);
|
2017-08-16 00:12:01 +00:00
|
|
|
goto abort;
|
2017-08-15 20:05:10 +00:00
|
|
|
break;
|
2020-05-10 03:00:39 +00:00
|
|
|
case int(Event::DataWritten):
|
2017-08-15 20:05:10 +00:00
|
|
|
header_[distance_into_section_] = input_;
|
|
|
|
write_byte(input_);
|
|
|
|
has_input_ = false;
|
|
|
|
distance_into_section_++;
|
|
|
|
if(distance_into_section_ < 4) {
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(MainStatus::DataReady, true);
|
2017-08-15 20:05:10 +00:00
|
|
|
goto format_track_write_header;
|
|
|
|
}
|
|
|
|
break;
|
2017-08-13 22:05:19 +00:00
|
|
|
}
|
2017-08-15 20:05:10 +00:00
|
|
|
|
2024-01-19 19:16:13 +00:00
|
|
|
logger.info().append("W: %02x %02x %02x %02x, %04x",
|
|
|
|
header_[0], header_[1], header_[2], header_[3], get_crc_generator().get_value());
|
2017-08-13 22:05:19 +00:00
|
|
|
write_crc();
|
|
|
|
|
|
|
|
// Write the sector body.
|
2017-08-15 20:05:10 +00:00
|
|
|
write_id_data_joiner(false, false);
|
2023-11-24 23:24:58 +00:00
|
|
|
write_n_bytes(128 << command_.format_specs().bytes_per_sector, command_.format_specs().filler);
|
2017-08-13 22:05:19 +00:00
|
|
|
write_crc();
|
|
|
|
|
|
|
|
// Write the prescribed gap.
|
2023-11-24 23:24:58 +00:00
|
|
|
write_n_bytes(command_.format_specs().gap3_length, get_is_double_density() ? 0x4e : 0xff);
|
2017-08-13 22:05:19 +00:00
|
|
|
|
|
|
|
// Consider repeating.
|
|
|
|
sector_++;
|
2023-11-24 23:24:58 +00:00
|
|
|
if(sector_ < command_.format_specs().sectors_per_track && !index_hole_count_)
|
2017-08-13 22:05:19 +00:00
|
|
|
goto format_track_write_sector;
|
|
|
|
|
|
|
|
// Otherwise, pad out to the index hole.
|
|
|
|
format_track_pad:
|
2017-08-14 17:03:17 +00:00
|
|
|
write_byte(get_is_double_density() ? 0x4e : 0xff);
|
2020-05-10 03:00:39 +00:00
|
|
|
WAIT_FOR_EVENT(int(Event::DataWritten) | int(Event::IndexHole));
|
|
|
|
if(event_type != int(Event::IndexHole)) goto format_track_pad;
|
2017-08-13 22:05:19 +00:00
|
|
|
|
2017-09-15 02:30:40 +00:00
|
|
|
end_writing();
|
2017-08-13 22:05:19 +00:00
|
|
|
|
|
|
|
cylinder_ = header_[0];
|
|
|
|
head_ = header_[1];
|
|
|
|
sector_ = header_[2] + 1;
|
|
|
|
size_ = header_[3];
|
|
|
|
|
|
|
|
goto post_st012chrn;
|
2017-08-06 16:36:18 +00:00
|
|
|
|
|
|
|
scan_low:
|
2024-01-19 19:16:13 +00:00
|
|
|
logger.error().append("Scan low unimplemented!!");
|
2017-08-06 16:36:18 +00:00
|
|
|
goto wait_for_command;
|
|
|
|
|
|
|
|
scan_low_or_equal:
|
2024-01-19 19:16:13 +00:00
|
|
|
logger.error().append("Scan low or equal unimplemented!!");
|
2017-08-06 16:36:18 +00:00
|
|
|
goto wait_for_command;
|
|
|
|
|
|
|
|
scan_high_or_equal:
|
2024-01-19 19:16:13 +00:00
|
|
|
logger.error().append("Scan high or equal unimplemented!!");
|
2017-08-06 16:36:18 +00:00
|
|
|
goto wait_for_command;
|
|
|
|
|
2017-08-07 11:27:00 +00:00
|
|
|
// Performs both recalibrate and seek commands. These commands occur asynchronously, so the actual work
|
|
|
|
// occurs in ::run_for; this merely establishes that seeking should be ongoing.
|
2017-08-06 16:36:18 +00:00
|
|
|
recalibrate:
|
2017-08-07 01:52:52 +00:00
|
|
|
seek:
|
2017-08-14 13:45:39 +00:00
|
|
|
{
|
2023-11-24 23:24:58 +00:00
|
|
|
const int drive = command_.target().drive;
|
2017-09-12 01:25:26 +00:00
|
|
|
select_drive(drive);
|
2017-08-14 13:45:39 +00:00
|
|
|
|
|
|
|
// Increment the seeking count if this drive wasn't already seeking.
|
|
|
|
if(drives_[drive].phase != Drive::Seeking) {
|
|
|
|
drives_seeking_++;
|
2017-08-20 14:43:53 +00:00
|
|
|
is_sleeping_ = false;
|
2018-05-28 03:17:06 +00:00
|
|
|
update_clocking_observer();
|
2017-08-14 13:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set currently seeking, with a step to occur right now (yes, it sounds like jamming these
|
|
|
|
// in could damage your drive motor).
|
2017-08-07 14:31:32 +00:00
|
|
|
drives_[drive].phase = Drive::Seeking;
|
2017-08-14 13:45:39 +00:00
|
|
|
drives_[drive].step_rate_counter = 8000 * step_rate_time_;
|
2017-08-07 14:31:32 +00:00
|
|
|
drives_[drive].steps_taken = 0;
|
2017-08-12 16:52:36 +00:00
|
|
|
drives_[drive].seek_failed = false;
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.start_seek(command_.target().drive);
|
2017-08-07 14:31:32 +00:00
|
|
|
|
2017-08-14 13:45:39 +00:00
|
|
|
// If this is a seek, set the processor-supplied target location; otherwise it is a recalibrate,
|
|
|
|
// which means resetting the current state now but aiming to hit '-1' (which the stepping code
|
|
|
|
// up in run_for understands to mean 'keep going until track 0 is active').
|
2023-11-24 23:24:58 +00:00
|
|
|
if(command_.command() != Command::Recalibrate) {
|
|
|
|
drives_[drive].target_head_position = command_.seek_target();
|
2024-01-19 19:16:13 +00:00
|
|
|
logger.info().append("Seek to %d", command_.seek_target());
|
2017-08-14 13:45:39 +00:00
|
|
|
} else {
|
|
|
|
drives_[drive].target_head_position = -1;
|
|
|
|
drives_[drive].head_position = 0;
|
2024-01-19 19:16:13 +00:00
|
|
|
logger.info().append("Recalibrate");
|
2017-08-14 13:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether any steps are even needed; if not then mark as completed already.
|
2017-09-12 01:25:26 +00:00
|
|
|
if(seek_is_satisfied(drive)) {
|
2017-08-07 14:31:32 +00:00
|
|
|
drives_[drive].phase = Drive::CompletedSeeking;
|
2017-08-14 13:45:39 +00:00
|
|
|
drives_seeking_--;
|
2017-08-07 14:31:32 +00:00
|
|
|
}
|
2017-08-07 02:14:18 +00:00
|
|
|
}
|
|
|
|
goto wait_for_command;
|
2017-08-06 16:36:18 +00:00
|
|
|
|
2017-08-07 11:27:00 +00:00
|
|
|
// Performs sense interrupt status.
|
2017-08-06 16:36:18 +00:00
|
|
|
sense_interrupt_status:
|
2024-01-19 19:16:13 +00:00
|
|
|
logger.info().append("Sense interrupt status");
|
2017-08-07 02:14:18 +00:00
|
|
|
{
|
2017-08-07 11:27:00 +00:00
|
|
|
// Find the first drive that is in the CompletedSeeking state.
|
2017-08-07 02:14:18 +00:00
|
|
|
int found_drive = -1;
|
|
|
|
for(int c = 0; c < 4; c++) {
|
|
|
|
if(drives_[c].phase == Drive::CompletedSeeking) {
|
|
|
|
found_drive = c;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-08-07 11:27:00 +00:00
|
|
|
|
|
|
|
// If a drive was found, return its results. Otherwise return a single 0x80.
|
2017-08-07 02:14:18 +00:00
|
|
|
if(found_drive != -1) {
|
|
|
|
drives_[found_drive].phase = Drive::NotSeeking;
|
2023-11-29 14:45:45 +00:00
|
|
|
status_.set_status0(uint8_t(found_drive | uint8_t(Status0::SeekEnded)));
|
2023-11-29 04:18:22 +00:00
|
|
|
// status_.end_sense_interrupt_status(found_drive, 0);
|
2023-11-29 14:45:45 +00:00
|
|
|
// status_.set(Status0::SeekEnded);
|
2017-08-07 02:14:18 +00:00
|
|
|
|
2017-09-16 02:59:26 +00:00
|
|
|
result_stack_ = { drives_[found_drive].head_position, status_[0]};
|
2017-08-07 02:14:18 +00:00
|
|
|
} else {
|
2017-09-16 02:59:26 +00:00
|
|
|
result_stack_ = { 0x80 };
|
2017-08-06 19:22:07 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-07 02:14:18 +00:00
|
|
|
goto post_result;
|
2017-08-06 16:36:18 +00:00
|
|
|
|
2017-08-07 11:27:00 +00:00
|
|
|
// Performs specify.
|
2017-08-06 16:36:18 +00:00
|
|
|
specify:
|
2017-08-07 11:27:00 +00:00
|
|
|
// Just store the values, and terminate the command.
|
2024-01-19 19:16:13 +00:00
|
|
|
logger.info().append("Specify");
|
2023-11-24 23:24:58 +00:00
|
|
|
step_rate_time_ = command_.specify_specs().step_rate_time;
|
|
|
|
head_unload_time_ = command_.specify_specs().head_unload_time;
|
|
|
|
head_load_time_ = command_.specify_specs().head_load_time;
|
2017-08-13 23:25:57 +00:00
|
|
|
|
2017-08-14 13:04:22 +00:00
|
|
|
if(!head_unload_time_) head_unload_time_ = 16;
|
2017-08-13 23:25:57 +00:00
|
|
|
if(!head_load_time_) head_load_time_ = 2;
|
2023-11-24 23:24:58 +00:00
|
|
|
dma_mode_ = command_.specify_specs().use_dma;
|
2017-08-07 02:14:18 +00:00
|
|
|
goto wait_for_command;
|
2017-08-06 16:36:18 +00:00
|
|
|
|
|
|
|
sense_drive_status:
|
2024-01-19 19:16:13 +00:00
|
|
|
logger.info().append("Sense drive status");
|
2017-08-09 00:30:54 +00:00
|
|
|
{
|
2023-11-24 23:24:58 +00:00
|
|
|
int drive = command_.target().drive;
|
2017-09-12 01:25:26 +00:00
|
|
|
select_drive(drive);
|
2023-11-29 14:49:05 +00:00
|
|
|
result_stack_ = {
|
2020-05-10 03:00:39 +00:00
|
|
|
uint8_t(
|
2023-11-24 23:24:58 +00:00
|
|
|
(command_.drive_head()) | // drive and head number
|
|
|
|
0x08 | // single sided
|
2017-09-16 02:59:26 +00:00
|
|
|
(get_drive().get_is_track_zero() ? 0x10 : 0x00) |
|
|
|
|
(get_drive().get_is_ready() ? 0x20 : 0x00) |
|
|
|
|
(get_drive().get_is_read_only() ? 0x40 : 0x00)
|
|
|
|
)
|
|
|
|
};
|
2017-08-09 00:30:54 +00:00
|
|
|
}
|
|
|
|
goto post_result;
|
2017-08-06 16:36:18 +00:00
|
|
|
|
2017-08-07 11:27:00 +00:00
|
|
|
// Performs any invalid command.
|
2017-08-06 16:36:18 +00:00
|
|
|
invalid:
|
2017-08-12 13:36:21 +00:00
|
|
|
// A no-op, but posts ST0 (but which ST0?)
|
2017-09-16 02:59:26 +00:00
|
|
|
result_stack_ = {0x80};
|
2017-08-07 11:35:41 +00:00
|
|
|
goto post_result;
|
2017-08-07 02:14:18 +00:00
|
|
|
|
2017-08-16 00:12:01 +00:00
|
|
|
// Sets abnormal termination of the current command and proceeds to an ST0, ST1, ST2, C, H, R, N result phase.
|
|
|
|
abort:
|
2017-09-16 00:26:41 +00:00
|
|
|
end_writing();
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(Status0::AbnormalTermination);
|
2017-08-16 00:12:01 +00:00
|
|
|
goto post_st012chrn;
|
|
|
|
|
2017-08-07 11:27:00 +00:00
|
|
|
// Posts ST0, ST1, ST2, C, H, R and N as a result phase.
|
2017-08-07 02:14:18 +00:00
|
|
|
post_st012chrn:
|
2017-08-12 13:36:21 +00:00
|
|
|
SCHEDULE_HEAD_UNLOAD();
|
|
|
|
|
2017-09-16 02:59:26 +00:00
|
|
|
result_stack_ = {size_, sector_, head_, cylinder_, status_[2], status_[1], status_[0]};
|
2017-08-07 02:14:18 +00:00
|
|
|
|
|
|
|
goto post_result;
|
2017-08-06 16:36:18 +00:00
|
|
|
|
2018-05-13 19:34:31 +00:00
|
|
|
// Posts whatever is in result_stack_ as a result phase. Be aware that it is a stack, so the
|
2017-08-07 11:27:00 +00:00
|
|
|
// last thing in it will be returned first.
|
2017-08-06 16:55:57 +00:00
|
|
|
post_result:
|
2024-01-19 19:16:13 +00:00
|
|
|
// {
|
|
|
|
// auto line = logger.info();
|
|
|
|
// line.append("Result to %02x, main %02x", command_[0] & 0x1f, main_status_);
|
|
|
|
// for(std::size_t c = 0; c < result_stack_.size(); c++) {
|
|
|
|
// line.append(" %02x", result_stack_[result_stack_.size() - 1 - c]);
|
|
|
|
// }
|
2023-11-24 23:24:58 +00:00
|
|
|
// }
|
2017-08-13 22:51:06 +00:00
|
|
|
|
2017-08-07 02:14:18 +00:00
|
|
|
// Set ready to send data to the processor, no longer in non-DMA execution phase.
|
2017-09-16 00:26:41 +00:00
|
|
|
is_executing_ = false;
|
2023-11-26 20:04:01 +00:00
|
|
|
status_.set(MainStatus::InNonDMAExecution, false);
|
|
|
|
status_.set(MainStatus::DataReady, true);
|
|
|
|
status_.set(MainStatus::DataIsToProcessor, true);
|
2017-08-06 23:48:17 +00:00
|
|
|
|
2020-01-05 18:40:02 +00:00
|
|
|
// The actual stuff of unwinding result_stack_ is handled by ::read; wait
|
2017-08-07 11:27:00 +00:00
|
|
|
// until the processor has read all result bytes.
|
2017-08-07 02:14:18 +00:00
|
|
|
WAIT_FOR_EVENT(Event8272::ResultEmpty);
|
2017-08-07 11:27:00 +00:00
|
|
|
|
|
|
|
// Reset data direction and end the command.
|
2017-08-07 02:14:18 +00:00
|
|
|
goto wait_for_command;
|
2017-08-06 16:55:57 +00:00
|
|
|
|
2017-08-06 16:36:18 +00:00
|
|
|
END_SECTION()
|
2017-08-06 13:45:16 +00:00
|
|
|
}
|
2017-08-07 14:31:32 +00:00
|
|
|
|
2017-09-12 01:25:26 +00:00
|
|
|
bool i8272::seek_is_satisfied(int drive) {
|
|
|
|
return (drives_[drive].target_head_position == drives_[drive].head_position) ||
|
|
|
|
(drives_[drive].target_head_position == -1 && get_drive().get_is_track_zero());
|
2017-08-07 14:31:32 +00:00
|
|
|
}
|
2017-08-14 12:38:00 +00:00
|
|
|
|
2020-05-30 04:37:06 +00:00
|
|
|
void i8272::set_dma_acknowledge(bool) {
|
2017-08-14 12:38:00 +00:00
|
|
|
}
|
|
|
|
|
2020-05-30 04:37:06 +00:00
|
|
|
void i8272::set_terminal_count(bool) {
|
2017-08-14 12:38:00 +00:00
|
|
|
}
|
2017-08-14 13:04:22 +00:00
|
|
|
|
2020-05-30 04:37:06 +00:00
|
|
|
void i8272::set_data_input(uint8_t) {
|
2017-08-14 13:04:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t i8272::get_data_output() {
|
|
|
|
return 0xff;
|
|
|
|
}
|