mirror of
https://github.com/TomHarte/CLK.git
synced 2024-12-26 09:29:45 +00:00
Added a bunch of comments, and ensured that the data request bit remains set for the entire period that command bytes are accepted.
This commit is contained in:
parent
73f8488150
commit
d90e35e5bd
@ -142,89 +142,116 @@ void i8272::posit_event(int event_type) {
|
||||
|
||||
BEGIN_SECTION();
|
||||
|
||||
// Resets busy and non-DMA execution, clears the command buffer, sets the data mode to scanning and flows
|
||||
// into wait_for_complete_command_sequence.
|
||||
wait_for_command:
|
||||
set_data_mode(Storage::Disk::MFMController::DataMode::Scanning);
|
||||
main_status_ &= ~(StatusCB | StatusNDM);
|
||||
command_.clear();
|
||||
|
||||
// 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.
|
||||
wait_for_complete_command_sequence:
|
||||
main_status_ |= StatusRQM;
|
||||
WAIT_FOR_EVENT(Event8272::CommandByte)
|
||||
main_status_ |= StatusCB;
|
||||
main_status_ &= ~StatusRQM;
|
||||
|
||||
switch(command_[0] & 0x1f) {
|
||||
case 0x06: // read data
|
||||
if(command_.size() < 9) goto wait_for_complete_command_sequence;
|
||||
main_status_ &= ~StatusRQM;
|
||||
goto read_data;
|
||||
|
||||
case 0x0b: // read deleted data
|
||||
if(command_.size() < 9) goto wait_for_complete_command_sequence;
|
||||
main_status_ &= ~StatusRQM;
|
||||
goto read_deleted_data;
|
||||
|
||||
case 0x05: // write data
|
||||
if(command_.size() < 9) goto wait_for_complete_command_sequence;
|
||||
main_status_ &= ~StatusRQM;
|
||||
goto write_data;
|
||||
|
||||
case 0x09: // write deleted data
|
||||
if(command_.size() < 9) goto wait_for_complete_command_sequence;
|
||||
main_status_ &= ~StatusRQM;
|
||||
goto write_deleted_data;
|
||||
|
||||
case 0x02: // read track
|
||||
if(command_.size() < 9) goto wait_for_complete_command_sequence;
|
||||
main_status_ &= ~StatusRQM;
|
||||
goto read_track;
|
||||
|
||||
case 0x0a: // read ID
|
||||
if(command_.size() < 2) goto wait_for_complete_command_sequence;
|
||||
main_status_ &= ~StatusRQM;
|
||||
goto read_id;
|
||||
|
||||
case 0x0d: // format track
|
||||
if(command_.size() < 6) goto wait_for_complete_command_sequence;
|
||||
main_status_ &= ~StatusRQM;
|
||||
goto format_track;
|
||||
|
||||
case 0x11: // scan low
|
||||
if(command_.size() < 9) goto wait_for_complete_command_sequence;
|
||||
main_status_ &= ~StatusRQM;
|
||||
goto scan_low;
|
||||
|
||||
case 0x19: // scan low or equal
|
||||
if(command_.size() < 9) goto wait_for_complete_command_sequence;
|
||||
main_status_ &= ~StatusRQM;
|
||||
goto scan_low_or_equal;
|
||||
|
||||
case 0x1d: // scan high or equal
|
||||
if(command_.size() < 9) goto wait_for_complete_command_sequence;
|
||||
main_status_ &= ~StatusRQM;
|
||||
goto scan_high_or_equal;
|
||||
|
||||
case 0x07: // recalibrate
|
||||
if(command_.size() < 2) goto wait_for_complete_command_sequence;
|
||||
main_status_ &= ~StatusRQM;
|
||||
goto recalibrate;
|
||||
|
||||
case 0x08: // sense interrupt status
|
||||
main_status_ &= ~StatusRQM;
|
||||
goto sense_interrupt_status;
|
||||
|
||||
case 0x03: // specify
|
||||
if(command_.size() < 3) goto wait_for_complete_command_sequence;
|
||||
main_status_ &= ~StatusRQM;
|
||||
goto specify;
|
||||
|
||||
case 0x04: // sense drive status
|
||||
if(command_.size() < 2) goto wait_for_complete_command_sequence;
|
||||
main_status_ &= ~StatusRQM;
|
||||
goto sense_drive_status;
|
||||
|
||||
case 0x0f: // seek
|
||||
if(command_.size() < 3) goto wait_for_complete_command_sequence;
|
||||
main_status_ &= ~StatusRQM;
|
||||
goto seek;
|
||||
|
||||
default: // invalid
|
||||
main_status_ &= ~StatusRQM;
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
// Performs the read data command.
|
||||
read_data:
|
||||
printf("Read data, sector %02x %02x %02x %02x\n", command_[2], command_[3], command_[4], command_[5]);
|
||||
|
||||
// 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.
|
||||
SET_DRIVE_HEAD_MFM();
|
||||
cylinder_ = command_[2];
|
||||
head_ = command_[3];
|
||||
sector_ = command_[4];
|
||||
size_ = command_[5];
|
||||
|
||||
// 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.
|
||||
index_hole_limit_ = 2;
|
||||
find_next_sector:
|
||||
FIND_HEADER();
|
||||
@ -232,10 +259,16 @@ void i8272::posit_event(int event_type) {
|
||||
READ_HEADER();
|
||||
if(header_[0] != cylinder_ || header_[1] != head_ || header_[2] != sector_ || header_[3] != size_) goto find_next_sector;
|
||||
|
||||
// Finds the next data block and sets data mode to reading.
|
||||
FIND_DATA();
|
||||
distance_into_section_ = 0;
|
||||
set_data_mode(Reading);
|
||||
|
||||
// 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.
|
||||
//
|
||||
// TODO: signal if the CPU is too slow and missed a byte; at the minute it'll just silently miss. Also allow for other
|
||||
// ways that sector size might have been specified.
|
||||
get_byte:
|
||||
WAIT_FOR_EVENT(Event::Token);
|
||||
result_stack_.push_back(get_latest_token().byte_value);
|
||||
@ -245,9 +278,11 @@ void i8272::posit_event(int event_type) {
|
||||
main_status_ &= ~StatusRQM;
|
||||
if(distance_into_section_ < (128 << size_)) goto get_byte;
|
||||
|
||||
set_data_mode(Scanning);
|
||||
// For a final result phase, post the standard ST0, ST1, ST2, C, H, R, N
|
||||
goto post_st012chrn;
|
||||
|
||||
// Execution reaches here if two index holes were discovered before a matching sector — i.e. the data wasn't found.
|
||||
// In that case set appropriate error flags and post the results.
|
||||
read_data_not_found:
|
||||
printf("Not found\n");
|
||||
|
||||
@ -271,16 +306,21 @@ void i8272::posit_event(int event_type) {
|
||||
printf("Read track unimplemented!!\n");
|
||||
goto wait_for_command;
|
||||
|
||||
// Performs the read ID command.
|
||||
read_id:
|
||||
// Establishes the drive and head being addressed, and whether in double density mode.
|
||||
printf("Read ID\n");
|
||||
SET_DRIVE_HEAD_MFM();
|
||||
|
||||
// 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.
|
||||
index_hole_limit_ = 2;
|
||||
read_id_find_next_sector:
|
||||
FIND_HEADER();
|
||||
if(!index_hole_limit_) goto read_id_not_found;
|
||||
if(!index_hole_limit_) goto read_data_not_found;
|
||||
READ_HEADER();
|
||||
|
||||
// Sets internal registers from the discovered header and posts the standard ST0, ST1, ST2, C, H, R, N.
|
||||
cylinder_ = header_[0];
|
||||
head_ = header_[1];
|
||||
sector_ = header_[2];
|
||||
@ -288,12 +328,6 @@ void i8272::posit_event(int event_type) {
|
||||
|
||||
goto post_st012chrn;
|
||||
|
||||
read_id_not_found:
|
||||
status_[1] |= 0x4;
|
||||
status_[0] = 0x40;
|
||||
|
||||
goto post_st012chrn;
|
||||
|
||||
format_track:
|
||||
printf("Fromat track unimplemented!!\n");
|
||||
goto wait_for_command;
|
||||
@ -310,9 +344,16 @@ void i8272::posit_event(int event_type) {
|
||||
printf("Scan high or equal unimplemented!!\n");
|
||||
goto wait_for_command;
|
||||
|
||||
// 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.
|
||||
recalibrate:
|
||||
seek:
|
||||
printf((command_.size() > 2) ? "Seek\n" : "Recalibrate\n");
|
||||
|
||||
// Declines to act if a seek is already ongoing; otherwise resets all status registers, sets the drive
|
||||
// into seeking mode, sets the drive's main status seeking bit, and sets the target head position: for
|
||||
// a recalibrate the target is -1 and ::run_for knows that -1 means the terminal condition is the drive
|
||||
// returning that its at track zero, and that it should reset the drive's current position once reached.
|
||||
if(drives_[command_[1]&3].phase != Drive::Seeking) {
|
||||
status_[0] = status_[1] = status_[2] = 0;
|
||||
drives_[command_[1]&3].phase = Drive::Seeking;
|
||||
@ -323,11 +364,11 @@ void i8272::posit_event(int event_type) {
|
||||
}
|
||||
goto wait_for_command;
|
||||
|
||||
// Performs sense interrupt status.
|
||||
sense_interrupt_status:
|
||||
printf("Sense interrupt status\n");
|
||||
// Find the first drive that is in the CompletedSeeking state and return for that;
|
||||
// if none has done so then return a single 0x80.
|
||||
{
|
||||
// Find the first drive that is in the CompletedSeeking state.
|
||||
int found_drive = -1;
|
||||
for(int c = 0; c < 4; c++) {
|
||||
if(drives_[c].phase == Drive::CompletedSeeking) {
|
||||
@ -335,6 +376,8 @@ void i8272::posit_event(int event_type) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If a drive was found, return its results. Otherwise return a single 0x80.
|
||||
if(found_drive != -1) {
|
||||
drives_[found_drive].phase = Drive::NotSeeking;
|
||||
status_[0] = (uint8_t)found_drive | 0x20;
|
||||
@ -348,7 +391,9 @@ void i8272::posit_event(int event_type) {
|
||||
}
|
||||
goto post_result;
|
||||
|
||||
// Performs specify.
|
||||
specify:
|
||||
// Just store the values, and terminate the command.
|
||||
step_rate_time_ = command_[1] &0xf0; // i.e. 16 to 240m
|
||||
head_unload_time_ = command_[1] & 0x0f; // i.e. 1 to 16ms
|
||||
head_load_time_ = command_[2] & ~1; // i.e. 2 to 254 ms in increments of 2ms
|
||||
@ -359,10 +404,12 @@ void i8272::posit_event(int event_type) {
|
||||
printf("Sense drive status unimplemented!!\n");
|
||||
goto wait_for_command;
|
||||
|
||||
// Performs any invalid command.
|
||||
invalid:
|
||||
// A no-op, causing the FDC to go back into standby mode.
|
||||
goto wait_for_command;
|
||||
|
||||
// Posts ST0, ST1, ST2, C, H, R and N as a result phase.
|
||||
post_st012chrn:
|
||||
result_stack_.push_back(size_);
|
||||
result_stack_.push_back(sector_);
|
||||
@ -375,12 +422,18 @@ void i8272::posit_event(int event_type) {
|
||||
|
||||
goto post_result;
|
||||
|
||||
// Posts whatever is in result_stack_ as a result phase. Be aware that it is a stack — the
|
||||
// last thing in it will be returned first.
|
||||
post_result:
|
||||
// Set ready to send data to the processor, no longer in non-DMA execution phase.
|
||||
main_status_ |= StatusRQM | StatusDIO;
|
||||
main_status_ &= ~StatusNDM;
|
||||
|
||||
// The actual stuff of unwinding result_stack_ is handled by ::get_register; wait
|
||||
// until the processor has read all result bytes.
|
||||
WAIT_FOR_EVENT(Event8272::ResultEmpty);
|
||||
|
||||
// Reset data direction and end the command.
|
||||
main_status_ &= ~StatusDIO;
|
||||
goto wait_for_command;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user