diff --git a/devices/common/scsi/mesh.cpp b/devices/common/scsi/mesh.cpp index e08614d..3c267d8 100644 --- a/devices/common/scsi/mesh.cpp +++ b/devices/common/scsi/mesh.cpp @@ -115,19 +115,11 @@ void MeshController::write(uint8_t reg_offset, uint8_t value) { case MeshReg::Sequence: perform_command(value); break; + case MeshReg::BusStatus0: + this->update_bus_status((this->bus_stat & 0xFF00U) | value); + break; case MeshReg::BusStatus1: - new_stat = value << 8; - if (new_stat != this->bus_stat) { - for (uint16_t mask = SCSI_CTRL_RST; mask >= SCSI_CTRL_SEL; mask >>= 1) { - if ((new_stat ^ this->bus_stat) & mask) { - if (new_stat & mask) - this->bus_obj->assert_ctrl_line(this->src_id, mask); - else - this->bus_obj->release_ctrl_line(this->src_id, mask); - } - } - this->bus_stat = new_stat; - } + this->update_bus_status((this->bus_stat & 0xFFU) | (value << 8)); break; case MeshReg::IntMask: this->int_mask = value; @@ -248,6 +240,36 @@ void MeshController::perform_command(const uint8_t cmd) { } } +void MeshController::update_bus_status(const uint16_t new_stat) { + uint16_t mask; + + // update the lower part (BusStatus0) + if ((new_stat ^ this->bus_stat) & 0xFF) { + for (mask = SCSI_CTRL_REQ; mask >= SCSI_CTRL_IO; mask >>= 1) { + if ((new_stat ^ this->bus_stat) & mask) { + if (new_stat & mask) + this->bus_obj->assert_ctrl_line(this->src_id, mask); + else + this->bus_obj->release_ctrl_line(this->src_id, mask); + } + } + } + + // update the upper part (BusStatus1) + if ((new_stat ^ this->bus_stat) & 0xFF00U) { + for (mask = SCSI_CTRL_RST; mask >= SCSI_CTRL_SEL; mask >>= 1) { + if ((new_stat ^ this->bus_stat) & mask) { + if (new_stat & mask) + this->bus_obj->assert_ctrl_line(this->src_id, mask); + else + this->bus_obj->release_ctrl_line(this->src_id, mask); + } + } + } + + this->bus_stat = new_stat; +} + void MeshController::step_completed() { this->int_stat |= INT_CMD_DONE; update_irq(); diff --git a/devices/common/scsi/mesh.h b/devices/common/scsi/mesh.h index 959b499..bc061df 100644 --- a/devices/common/scsi/mesh.h +++ b/devices/common/scsi/mesh.h @@ -141,6 +141,7 @@ public: protected: void reset(bool is_hard_reset); void perform_command(const uint8_t cmd); + void update_bus_status(const uint16_t new_stat); private: uint8_t chip_id;