mirror of
https://github.com/TomHarte/CLK.git
synced 2024-12-27 01:31:42 +00:00
Reaching the end of the usable part of my day, decided to tidy up a little before bed with indentation that reflects a distinction between top-level entry points and mere loops.
This commit is contained in:
parent
3853966a1e
commit
73f8488150
@ -143,120 +143,117 @@ void i8272::posit_event(int event_type) {
|
|||||||
BEGIN_SECTION();
|
BEGIN_SECTION();
|
||||||
|
|
||||||
wait_for_command:
|
wait_for_command:
|
||||||
set_data_mode(Storage::Disk::MFMController::DataMode::Scanning);
|
set_data_mode(Storage::Disk::MFMController::DataMode::Scanning);
|
||||||
main_status_ &= ~(StatusCB | StatusNDM);
|
main_status_ &= ~(StatusCB | StatusNDM);
|
||||||
command_.clear();
|
command_.clear();
|
||||||
|
|
||||||
wait_for_complete_command_sequence:
|
wait_for_complete_command_sequence:
|
||||||
main_status_ |= StatusRQM;
|
main_status_ |= StatusRQM;
|
||||||
WAIT_FOR_EVENT(Event8272::CommandByte)
|
WAIT_FOR_EVENT(Event8272::CommandByte)
|
||||||
// printf(".");
|
main_status_ |= StatusCB;
|
||||||
main_status_ |= StatusCB;
|
main_status_ &= ~StatusRQM;
|
||||||
main_status_ &= ~StatusRQM;
|
|
||||||
|
|
||||||
switch(command_[0] & 0x1f) {
|
switch(command_[0] & 0x1f) {
|
||||||
case 0x06: // read data
|
case 0x06: // read data
|
||||||
if(command_.size() < 9) goto wait_for_complete_command_sequence;
|
if(command_.size() < 9) goto wait_for_complete_command_sequence;
|
||||||
goto read_data;
|
goto read_data;
|
||||||
|
|
||||||
case 0x0b: // read deleted data
|
case 0x0b: // read deleted data
|
||||||
if(command_.size() < 9) goto wait_for_complete_command_sequence;
|
if(command_.size() < 9) goto wait_for_complete_command_sequence;
|
||||||
goto read_deleted_data;
|
goto read_deleted_data;
|
||||||
|
|
||||||
case 0x05: // write data
|
case 0x05: // write data
|
||||||
if(command_.size() < 9) goto wait_for_complete_command_sequence;
|
if(command_.size() < 9) goto wait_for_complete_command_sequence;
|
||||||
goto write_data;
|
goto write_data;
|
||||||
|
|
||||||
case 0x09: // write deleted data
|
case 0x09: // write deleted data
|
||||||
if(command_.size() < 9) goto wait_for_complete_command_sequence;
|
if(command_.size() < 9) goto wait_for_complete_command_sequence;
|
||||||
goto write_deleted_data;
|
goto write_deleted_data;
|
||||||
|
|
||||||
case 0x02: // read track
|
case 0x02: // read track
|
||||||
if(command_.size() < 9) goto wait_for_complete_command_sequence;
|
if(command_.size() < 9) goto wait_for_complete_command_sequence;
|
||||||
goto read_track;
|
goto read_track;
|
||||||
|
|
||||||
case 0x0a: // read ID
|
case 0x0a: // read ID
|
||||||
if(command_.size() < 2) goto wait_for_complete_command_sequence;
|
if(command_.size() < 2) goto wait_for_complete_command_sequence;
|
||||||
goto read_id;
|
goto read_id;
|
||||||
|
|
||||||
case 0x0d: // format track
|
case 0x0d: // format track
|
||||||
if(command_.size() < 6) goto wait_for_complete_command_sequence;
|
if(command_.size() < 6) goto wait_for_complete_command_sequence;
|
||||||
goto format_track;
|
goto format_track;
|
||||||
|
|
||||||
case 0x11: // scan low
|
case 0x11: // scan low
|
||||||
if(command_.size() < 9) goto wait_for_complete_command_sequence;
|
if(command_.size() < 9) goto wait_for_complete_command_sequence;
|
||||||
goto scan_low;
|
goto scan_low;
|
||||||
|
|
||||||
case 0x19: // scan low or equal
|
case 0x19: // scan low or equal
|
||||||
if(command_.size() < 9) goto wait_for_complete_command_sequence;
|
if(command_.size() < 9) goto wait_for_complete_command_sequence;
|
||||||
goto scan_low_or_equal;
|
goto scan_low_or_equal;
|
||||||
|
|
||||||
case 0x1d: // scan high or equal
|
case 0x1d: // scan high or equal
|
||||||
if(command_.size() < 9) goto wait_for_complete_command_sequence;
|
if(command_.size() < 9) goto wait_for_complete_command_sequence;
|
||||||
goto scan_high_or_equal;
|
goto scan_high_or_equal;
|
||||||
|
|
||||||
case 0x07: // recalibrate
|
case 0x07: // recalibrate
|
||||||
if(command_.size() < 2) goto wait_for_complete_command_sequence;
|
if(command_.size() < 2) goto wait_for_complete_command_sequence;
|
||||||
goto recalibrate;
|
goto recalibrate;
|
||||||
|
|
||||||
case 0x08: // sense interrupt status
|
case 0x08: // sense interrupt status
|
||||||
goto sense_interrupt_status;
|
goto sense_interrupt_status;
|
||||||
|
|
||||||
case 0x03: // specify
|
case 0x03: // specify
|
||||||
if(command_.size() < 3) goto wait_for_complete_command_sequence;
|
if(command_.size() < 3) goto wait_for_complete_command_sequence;
|
||||||
goto specify;
|
goto specify;
|
||||||
|
|
||||||
case 0x04: // sense drive status
|
case 0x04: // sense drive status
|
||||||
if(command_.size() < 2) goto wait_for_complete_command_sequence;
|
if(command_.size() < 2) goto wait_for_complete_command_sequence;
|
||||||
goto sense_drive_status;
|
goto sense_drive_status;
|
||||||
|
|
||||||
case 0x0f: // seek
|
case 0x0f: // seek
|
||||||
if(command_.size() < 3) goto wait_for_complete_command_sequence;
|
if(command_.size() < 3) goto wait_for_complete_command_sequence;
|
||||||
goto seek;
|
goto seek;
|
||||||
|
|
||||||
default: // invalid
|
default: // invalid
|
||||||
goto invalid;
|
goto invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
read_data:
|
read_data:
|
||||||
printf("Read data, sector %02x %02x %02x %02x\n", command_[2], command_[3], command_[4], command_[5]);
|
printf("Read data, sector %02x %02x %02x %02x\n", command_[2], command_[3], command_[4], command_[5]);
|
||||||
SET_DRIVE_HEAD_MFM();
|
SET_DRIVE_HEAD_MFM();
|
||||||
cylinder_ = command_[2];
|
cylinder_ = command_[2];
|
||||||
head_ = command_[3];
|
head_ = command_[3];
|
||||||
sector_ = command_[4];
|
sector_ = command_[4];
|
||||||
size_ = command_[5];
|
size_ = command_[5];
|
||||||
|
|
||||||
index_hole_limit_ = 2;
|
index_hole_limit_ = 2;
|
||||||
find_next_sector:
|
find_next_sector:
|
||||||
FIND_HEADER();
|
FIND_HEADER();
|
||||||
if(!index_hole_limit_) goto read_data_not_found;
|
if(!index_hole_limit_) goto read_data_not_found;
|
||||||
READ_HEADER();
|
READ_HEADER();
|
||||||
// printf("Comparing with %02x\n", header_[2]);
|
if(header_[0] != cylinder_ || header_[1] != head_ || header_[2] != sector_ || header_[3] != size_) goto find_next_sector;
|
||||||
if(header_[0] != cylinder_ || header_[1] != head_ || header_[2] != sector_ || header_[3] != size_) goto find_next_sector;
|
|
||||||
|
|
||||||
|
FIND_DATA();
|
||||||
|
distance_into_section_ = 0;
|
||||||
|
set_data_mode(Reading);
|
||||||
|
|
||||||
FIND_DATA();
|
get_byte:
|
||||||
distance_into_section_ = 0;
|
WAIT_FOR_EVENT(Event::Token);
|
||||||
set_data_mode(Reading);
|
result_stack_.push_back(get_latest_token().byte_value);
|
||||||
|
distance_into_section_++;
|
||||||
|
main_status_ |= StatusRQM | StatusDIO;
|
||||||
|
WAIT_FOR_EVENT(Event8272::ResultEmpty);
|
||||||
|
main_status_ &= ~StatusRQM;
|
||||||
|
if(distance_into_section_ < (128 << size_)) goto get_byte;
|
||||||
|
|
||||||
get_byte:
|
set_data_mode(Scanning);
|
||||||
WAIT_FOR_EVENT(Event::Token);
|
goto post_st012chrn;
|
||||||
result_stack_.push_back(get_latest_token().byte_value);
|
|
||||||
distance_into_section_++;
|
|
||||||
main_status_ |= StatusRQM | StatusDIO;
|
|
||||||
WAIT_FOR_EVENT(Event8272::ResultEmpty);
|
|
||||||
main_status_ &= ~StatusRQM;
|
|
||||||
if(distance_into_section_ < (128 << size_)) goto get_byte;
|
|
||||||
|
|
||||||
set_data_mode(Scanning);
|
read_data_not_found:
|
||||||
goto return_st012chrn;
|
printf("Not found\n");
|
||||||
|
|
||||||
read_data_not_found:
|
status_[1] |= 0x4;
|
||||||
printf("Not found\n");
|
status_[0] = 0x40; // (status_[0] & ~0xc0) |
|
||||||
|
goto post_st012chrn;
|
||||||
status_[1] |= 0x4;
|
|
||||||
status_[0] = 0x40; // (status_[0] & ~0xc0) |
|
|
||||||
goto return_st012chrn;
|
|
||||||
|
|
||||||
read_deleted_data:
|
read_deleted_data:
|
||||||
printf("Read deleted data unimplemented!!\n");
|
printf("Read deleted data unimplemented!!\n");
|
||||||
@ -275,37 +272,27 @@ void i8272::posit_event(int event_type) {
|
|||||||
goto wait_for_command;
|
goto wait_for_command;
|
||||||
|
|
||||||
read_id:
|
read_id:
|
||||||
printf("Read ID\n");
|
printf("Read ID\n");
|
||||||
SET_DRIVE_HEAD_MFM();
|
SET_DRIVE_HEAD_MFM();
|
||||||
|
|
||||||
index_hole_limit_ = 2;
|
index_hole_limit_ = 2;
|
||||||
read_id_find_next_sector:
|
read_id_find_next_sector:
|
||||||
FIND_HEADER();
|
FIND_HEADER();
|
||||||
if(!index_hole_limit_) goto read_id_not_found;
|
if(!index_hole_limit_) goto read_id_not_found;
|
||||||
READ_HEADER();
|
READ_HEADER();
|
||||||
|
|
||||||
cylinder_ = header_[0];
|
cylinder_ = header_[0];
|
||||||
head_ = header_[1];
|
head_ = header_[1];
|
||||||
sector_ = header_[2];
|
sector_ = header_[2];
|
||||||
size_ = header_[3];
|
size_ = header_[3];
|
||||||
|
|
||||||
goto return_st012chrn;
|
goto post_st012chrn;
|
||||||
|
|
||||||
read_id_not_found:
|
read_id_not_found:
|
||||||
status_[1] |= 0x4;
|
status_[1] |= 0x4;
|
||||||
status_[0] = 0x40; // (status_[0] & ~0xc0) |
|
status_[0] = 0x40;
|
||||||
|
|
||||||
return_st012chrn:
|
goto post_st012chrn;
|
||||||
result_stack_.push_back(size_);
|
|
||||||
result_stack_.push_back(sector_);
|
|
||||||
result_stack_.push_back(head_);
|
|
||||||
result_stack_.push_back(cylinder_);
|
|
||||||
|
|
||||||
result_stack_.push_back(status_[2]);
|
|
||||||
result_stack_.push_back(status_[1]);
|
|
||||||
result_stack_.push_back(status_[0]);
|
|
||||||
|
|
||||||
goto post_result;
|
|
||||||
|
|
||||||
format_track:
|
format_track:
|
||||||
printf("Fromat track unimplemented!!\n");
|
printf("Fromat track unimplemented!!\n");
|
||||||
@ -325,67 +312,77 @@ void i8272::posit_event(int event_type) {
|
|||||||
|
|
||||||
recalibrate:
|
recalibrate:
|
||||||
seek:
|
seek:
|
||||||
printf((command_.size() > 2) ? "Seek\n" : "Recalibrate\n");
|
printf((command_.size() > 2) ? "Seek\n" : "Recalibrate\n");
|
||||||
if(drives_[command_[1]&3].phase != Drive::Seeking) {
|
if(drives_[command_[1]&3].phase != Drive::Seeking) {
|
||||||
status_[0] = status_[1] = status_[2] = 0;
|
status_[0] = status_[1] = status_[2] = 0;
|
||||||
drives_[command_[1]&3].phase = Drive::Seeking;
|
drives_[command_[1]&3].phase = Drive::Seeking;
|
||||||
drives_[command_[1]&3].steps_taken = 0;
|
drives_[command_[1]&3].steps_taken = 0;
|
||||||
drives_[command_[1]&3].target_head_position = (command_.size() > 2) ? command_[2] : -1;
|
drives_[command_[1]&3].target_head_position = (command_.size() > 2) ? command_[2] : -1;
|
||||||
drives_[command_[1]&3].step_rate_counter = 0;
|
drives_[command_[1]&3].step_rate_counter = 0;
|
||||||
main_status_ |= 1 << (command_[1]&3);
|
main_status_ |= 1 << (command_[1]&3);
|
||||||
}
|
}
|
||||||
goto wait_for_command;
|
goto wait_for_command;
|
||||||
|
|
||||||
sense_interrupt_status:
|
sense_interrupt_status:
|
||||||
printf("Sense interrupt status\n");
|
printf("Sense interrupt status\n");
|
||||||
// Find the first drive that is in the CompletedSeeking state and return for that;
|
// Find the first drive that is in the CompletedSeeking state and return for that;
|
||||||
// if none has done so then return a single 0x80.
|
// if none has done so then return a single 0x80.
|
||||||
{
|
{
|
||||||
int found_drive = -1;
|
int found_drive = -1;
|
||||||
for(int c = 0; c < 4; c++) {
|
for(int c = 0; c < 4; c++) {
|
||||||
if(drives_[c].phase == Drive::CompletedSeeking) {
|
if(drives_[c].phase == Drive::CompletedSeeking) {
|
||||||
found_drive = c;
|
found_drive = c;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(found_drive != -1) {
|
||||||
|
drives_[found_drive].phase = Drive::NotSeeking;
|
||||||
|
status_[0] = (uint8_t)found_drive | 0x20;
|
||||||
|
main_status_ &= ~(1 << found_drive);
|
||||||
|
|
||||||
|
result_stack_.push_back(drives_[found_drive].head_position);
|
||||||
|
result_stack_.push_back(status_[0]);
|
||||||
|
} else {
|
||||||
|
result_stack_.push_back(0x80);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(found_drive != -1) {
|
goto post_result;
|
||||||
drives_[found_drive].phase = Drive::NotSeeking;
|
|
||||||
status_[0] = (uint8_t)found_drive | 0x20;
|
|
||||||
main_status_ &= ~(1 << found_drive);
|
|
||||||
|
|
||||||
result_stack_.push_back(drives_[found_drive].head_position);
|
|
||||||
result_stack_.push_back(status_[0]);
|
|
||||||
} else {
|
|
||||||
result_stack_.push_back(0x80);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
goto post_result;
|
|
||||||
|
|
||||||
specify:
|
specify:
|
||||||
printf("Specify\n");
|
step_rate_time_ = command_[1] &0xf0; // i.e. 16 to 240m
|
||||||
step_rate_time_ = command_[1] &0xf0; // i.e. 16 to 240m
|
head_unload_time_ = command_[1] & 0x0f; // i.e. 1 to 16ms
|
||||||
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
|
||||||
head_load_time_ = command_[2] & ~1; // i.e. 2 to 254 ms in increments of 2ms
|
dma_mode_ = !(command_[2] & 1);
|
||||||
dma_mode_ = !(command_[2] & 1);
|
goto wait_for_command;
|
||||||
goto wait_for_command;
|
|
||||||
|
|
||||||
sense_drive_status:
|
sense_drive_status:
|
||||||
printf("Sense drive status unimplemented!!\n");
|
printf("Sense drive status unimplemented!!\n");
|
||||||
// result_stack_.push_back(status_[3]);
|
goto wait_for_command;
|
||||||
goto post_result;
|
|
||||||
|
|
||||||
invalid:
|
invalid:
|
||||||
// A no-op, causing the FDC to go back into standby mode.
|
// A no-op, causing the FDC to go back into standby mode.
|
||||||
goto wait_for_command;
|
goto wait_for_command;
|
||||||
|
|
||||||
|
post_st012chrn:
|
||||||
|
result_stack_.push_back(size_);
|
||||||
|
result_stack_.push_back(sector_);
|
||||||
|
result_stack_.push_back(head_);
|
||||||
|
result_stack_.push_back(cylinder_);
|
||||||
|
|
||||||
|
result_stack_.push_back(status_[2]);
|
||||||
|
result_stack_.push_back(status_[1]);
|
||||||
|
result_stack_.push_back(status_[0]);
|
||||||
|
|
||||||
|
goto post_result;
|
||||||
|
|
||||||
post_result:
|
post_result:
|
||||||
// Set ready to send data to the processor, no longer in non-DMA execution phase.
|
// Set ready to send data to the processor, no longer in non-DMA execution phase.
|
||||||
main_status_ |= StatusRQM | StatusDIO;
|
main_status_ |= StatusRQM | StatusDIO;
|
||||||
main_status_ &= ~StatusNDM;
|
main_status_ &= ~StatusNDM;
|
||||||
|
|
||||||
WAIT_FOR_EVENT(Event8272::ResultEmpty);
|
WAIT_FOR_EVENT(Event8272::ResultEmpty);
|
||||||
main_status_ &= ~StatusDIO;
|
main_status_ &= ~StatusDIO;
|
||||||
goto wait_for_command;
|
goto wait_for_command;
|
||||||
|
|
||||||
END_SECTION()
|
END_SECTION()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user