mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-23 03:32:32 +00:00
Avoid potential infinite read loops.
This commit is contained in:
parent
9b23984d35
commit
edef0732ac
@ -114,16 +114,15 @@ class FloppyController {
|
|||||||
decoder_.geometry().head,
|
decoder_.geometry().head,
|
||||||
decoder_.geometry().cylinder,
|
decoder_.geometry().cylinder,
|
||||||
decoder_.geometry().sector);
|
decoder_.geometry().sector);
|
||||||
// log = true;
|
|
||||||
|
|
||||||
status_.begin(decoder_);
|
status_.begin(decoder_);
|
||||||
|
|
||||||
// Search for a matching sector.
|
// Search for a matching sector.
|
||||||
auto target = decoder_.geometry();
|
auto target = decoder_.geometry();
|
||||||
// bool found_sector = false;
|
|
||||||
|
|
||||||
bool complete = false;
|
bool complete = false;
|
||||||
while(!complete) {
|
while(!complete) {
|
||||||
|
bool found_sector = false;
|
||||||
|
|
||||||
for(auto &pair: drives_[decoder_.target().drive].sectors(decoder_.target().head)) {
|
for(auto &pair: drives_[decoder_.target().drive].sectors(decoder_.target().head)) {
|
||||||
if(
|
if(
|
||||||
(pair.second.address.track == target.cylinder) &&
|
(pair.second.address.track == target.cylinder) &&
|
||||||
@ -131,19 +130,15 @@ class FloppyController {
|
|||||||
(pair.second.address.side == target.head) &&
|
(pair.second.address.side == target.head) &&
|
||||||
(pair.second.size == target.size)
|
(pair.second.size == target.size)
|
||||||
) {
|
) {
|
||||||
// found_sector = true;
|
found_sector = true;
|
||||||
// bool wrote_in_full = true;
|
bool wrote_in_full = true;
|
||||||
|
|
||||||
printf("Writing data beginning: ");
|
|
||||||
for(int c = 0; c < 128 << target.size; c++) {
|
for(int c = 0; c < 128 << target.size; c++) {
|
||||||
if(c < 8) printf("%02x ", pair.second.samples[0].data()[c]);
|
|
||||||
|
|
||||||
const auto access_result = dma_.write(2, pair.second.samples[0].data()[c]);
|
const auto access_result = dma_.write(2, pair.second.samples[0].data()[c]);
|
||||||
switch(access_result) {
|
switch(access_result) {
|
||||||
default: break;
|
default: break;
|
||||||
case AccessResult::NotAccepted:
|
case AccessResult::NotAccepted:
|
||||||
printf("FDC: DMA not permitted\n");
|
wrote_in_full = false;
|
||||||
// wrote_in_full = false;
|
|
||||||
break;
|
break;
|
||||||
case AccessResult::AcceptedWithEOP:
|
case AccessResult::AcceptedWithEOP:
|
||||||
complete = true;
|
complete = true;
|
||||||
@ -154,18 +149,23 @@ class FloppyController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
++target.sector; // TODO: multitrack?
|
if(!wrote_in_full) {
|
||||||
printf("\n");
|
status_.set(Intel::i8272::Status1::OverRun);
|
||||||
|
status_.set(Intel::i8272::Status0::AbnormalTermination);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// if(wrote_in_full) {
|
++target.sector; // TODO: multitrack?
|
||||||
// } else {
|
|
||||||
// printf("FDC: didn't write in full\n");
|
|
||||||
// // TODO: Overrun, presumably?
|
|
||||||
// }
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!found_sector) {
|
||||||
|
status_.set(Intel::i8272::Status1::EndOfCylinder);
|
||||||
|
status_.set(Intel::i8272::Status0::AbnormalTermination);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
results_.serialise(
|
results_.serialise(
|
||||||
@ -175,18 +175,6 @@ class FloppyController {
|
|||||||
decoder_.geometry().sector,
|
decoder_.geometry().sector,
|
||||||
decoder_.geometry().size);
|
decoder_.geometry().size);
|
||||||
|
|
||||||
// if(!found_sector) {
|
|
||||||
// printf("FDC: sector not found\n");
|
|
||||||
// // TODO: there's more than this, I think.
|
|
||||||
// status_.set(Intel::i8272::Status0::AbnormalTermination);
|
|
||||||
// results_.serialise(
|
|
||||||
// status_,
|
|
||||||
// decoder_.geometry().cylinder,
|
|
||||||
// decoder_.geometry().head,
|
|
||||||
// decoder_.geometry().sector,
|
|
||||||
// decoder_.geometry().size);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// TODO: what if head has changed?
|
// TODO: what if head has changed?
|
||||||
drives_[decoder_.target().drive].status = decoder_.drive_head();
|
drives_[decoder_.target().drive].status = decoder_.drive_head();
|
||||||
drives_[decoder_.target().drive].raised_interrupt = true;
|
drives_[decoder_.target().drive].raised_interrupt = true;
|
||||||
@ -281,6 +269,12 @@ class FloppyController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void set_disk(std::shared_ptr<Storage::Disk::Disk> disk, int drive) {
|
void set_disk(std::shared_ptr<Storage::Disk::Disk> disk, int drive) {
|
||||||
|
if(drives_[drive].disk) {
|
||||||
|
// TODO: drive should only transition to unready if it was ready in the first place.
|
||||||
|
drives_[drive].status = uint8_t(Intel::i8272::Status0::BecameNotReady);
|
||||||
|
drives_[drive].raised_interrupt = true;
|
||||||
|
pic_.apply_edge<6>(true);
|
||||||
|
}
|
||||||
drives_[drive].disk = disk;
|
drives_[drive].disk = disk;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -833,8 +827,8 @@ class IO {
|
|||||||
|
|
||||||
case 0x03b1: case 0x03b3: case 0x03b5: case 0x03b7:
|
case 0x03b1: case 0x03b3: case 0x03b5: case 0x03b7:
|
||||||
if constexpr (std::is_same_v<IntT, uint16_t>) {
|
if constexpr (std::is_same_v<IntT, uint16_t>) {
|
||||||
mda_.write<1>(value);
|
mda_.write<1>(uint8_t(value));
|
||||||
mda_.write<0>(value >> 8);
|
mda_.write<0>(uint8_t(value >> 8));
|
||||||
} else {
|
} else {
|
||||||
mda_.write<1>(value);
|
mda_.write<1>(value);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user