2019-08-11 03:53:52 +00:00
|
|
|
//
|
|
|
|
// ncr5380.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 10/08/2019.
|
|
|
|
// Copyright © 2019 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ncr5380_hpp
|
|
|
|
#define ncr5380_hpp
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
2019-08-22 03:22:58 +00:00
|
|
|
#include "../../Storage/MassStorage/SCSI/SCSI.hpp"
|
2019-08-14 03:09:11 +00:00
|
|
|
|
|
|
|
|
2019-08-11 03:53:52 +00:00
|
|
|
namespace NCR {
|
|
|
|
namespace NCR5380 {
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Models the NCR 5380, a SCSI interface chip.
|
|
|
|
*/
|
2019-09-19 00:17:47 +00:00
|
|
|
class NCR5380 final: public SCSI::Bus::Observer {
|
2019-08-11 03:53:52 +00:00
|
|
|
public:
|
2019-08-25 21:03:41 +00:00
|
|
|
NCR5380(SCSI::Bus &bus, int clock_rate);
|
2019-08-14 03:09:11 +00:00
|
|
|
|
2019-08-11 03:53:52 +00:00
|
|
|
/*! Writes @c value to @c address. */
|
2019-09-14 17:48:33 +00:00
|
|
|
void write(int address, uint8_t value, bool dma_acknowledge = false);
|
2019-08-11 03:53:52 +00:00
|
|
|
|
|
|
|
/*! Reads from @c address. */
|
2019-09-14 17:48:33 +00:00
|
|
|
uint8_t read(int address, bool dma_acknowledge = false);
|
2019-08-12 00:55:20 +00:00
|
|
|
|
2022-08-23 19:05:36 +00:00
|
|
|
/*! @returns The SCSI ID assigned to this device. */
|
|
|
|
size_t scsi_id();
|
|
|
|
|
2022-08-31 19:33:48 +00:00
|
|
|
/*! @return @c true if DMA request is active; @c false otherwise. */
|
|
|
|
bool dma_request();
|
|
|
|
|
|
|
|
/*! Signals DMA acknowledge with a simultaneous read. */
|
|
|
|
uint8_t dma_acknowledge();
|
|
|
|
|
|
|
|
/*! Signals DMA acknowledge with a simultaneous write. */
|
|
|
|
void dma_acknowledge(uint8_t);
|
|
|
|
|
2019-08-12 00:55:20 +00:00
|
|
|
private:
|
2019-08-25 21:03:41 +00:00
|
|
|
SCSI::Bus &bus_;
|
2019-08-18 03:43:42 +00:00
|
|
|
|
|
|
|
const int clock_rate_;
|
2019-08-14 03:09:11 +00:00
|
|
|
size_t device_id_;
|
|
|
|
|
|
|
|
SCSI::BusState bus_output_ = SCSI::DefaultBusState;
|
2019-09-03 03:14:37 +00:00
|
|
|
SCSI::BusState expected_phase_ = SCSI::DefaultBusState;
|
2019-08-12 00:55:20 +00:00
|
|
|
uint8_t mode_ = 0xff;
|
2019-08-14 03:09:11 +00:00
|
|
|
uint8_t initiator_command_ = 0xff;
|
|
|
|
uint8_t data_bus_ = 0xff;
|
2019-09-03 03:14:37 +00:00
|
|
|
uint8_t target_command_ = 0xff;
|
2019-08-14 03:09:11 +00:00
|
|
|
bool test_mode_ = false;
|
|
|
|
bool assert_data_bus_ = false;
|
2019-08-25 02:47:11 +00:00
|
|
|
bool dma_request_ = false;
|
2019-09-03 03:14:37 +00:00
|
|
|
bool dma_acknowledge_ = false;
|
2022-09-15 20:14:14 +00:00
|
|
|
bool end_of_dma_ = false;
|
2019-08-16 03:14:40 +00:00
|
|
|
|
2022-09-15 20:24:06 +00:00
|
|
|
bool irq_ = false;
|
2022-09-15 20:34:06 +00:00
|
|
|
bool phase_mismatch_ = false;
|
2022-09-15 20:24:06 +00:00
|
|
|
|
2019-08-16 03:14:40 +00:00
|
|
|
enum class ExecutionState {
|
|
|
|
None,
|
2019-09-19 00:17:47 +00:00
|
|
|
WaitingForBusy,
|
2019-08-16 03:14:40 +00:00
|
|
|
WatchingBusy,
|
2019-08-25 02:47:11 +00:00
|
|
|
PerformingDMA,
|
2019-08-16 03:14:40 +00:00
|
|
|
} state_ = ExecutionState::None;
|
2019-09-14 17:48:33 +00:00
|
|
|
enum class DMAOperation {
|
|
|
|
Ready,
|
2019-09-15 19:03:06 +00:00
|
|
|
Send,
|
|
|
|
TargetReceive,
|
|
|
|
InitiatorReceive
|
2019-09-14 17:48:33 +00:00
|
|
|
} dma_operation_ = DMAOperation::Ready;
|
2019-08-16 03:14:40 +00:00
|
|
|
bool lost_arbitration_ = false, arbitration_in_progress_ = false;
|
|
|
|
|
|
|
|
void set_execution_state(ExecutionState state);
|
2019-09-03 03:14:37 +00:00
|
|
|
|
2022-09-15 20:14:14 +00:00
|
|
|
SCSI::BusState target_output() const;
|
2019-09-03 03:14:37 +00:00
|
|
|
void update_control_output();
|
2019-09-19 00:17:47 +00:00
|
|
|
|
|
|
|
void scsi_bus_did_change(SCSI::Bus *, SCSI::BusState new_state, double time_since_change) final;
|
2022-09-15 20:14:14 +00:00
|
|
|
bool phase_matches() const;
|
2019-08-11 03:53:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* ncr5380_hpp */
|