From df29a50738a9099361f000fcad00511e777434e5 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 31 Aug 2022 15:33:48 -0400 Subject: [PATCH] Attempt to support the DMA interface. --- Components/5380/ncr5380.cpp | 37 +++++++++++++++++++++-------- Components/5380/ncr5380.hpp | 9 +++++++ Machines/Apple/AppleII/SCSICard.cpp | 16 +++++++++++++ 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/Components/5380/ncr5380.cpp b/Components/5380/ncr5380.cpp index 7c4d14829..f6f35d13e 100644 --- a/Components/5380/ncr5380.cpp +++ b/Components/5380/ncr5380.cpp @@ -33,14 +33,10 @@ void NCR5380::write(int address, uint8_t value, bool) { switch(address & 7) { case 0: LOG("[SCSI 0] Set current SCSI bus state to " << PADHEX(2) << int(value)); - data_bus_ = value; + data_bus_ = value; if(dma_request_ && dma_operation_ == DMAOperation::Send) { -// printf("w %02x\n", value); - dma_acknowledge_ = true; - dma_request_ = false; - update_control_output(); - bus_.set_device_output(device_id_, bus_output_); + dma_acknowledge(value); } break; @@ -143,10 +139,7 @@ uint8_t NCR5380::read(int address, bool) { LOG("[SCSI 0] Get current SCSI bus state: " << PADHEX(2) << (bus_.get_state() & 0xff)); if(dma_request_ && dma_operation_ == DMAOperation::InitiatorReceive) { - dma_acknowledge_ = true; - dma_request_ = false; - update_control_output(); - bus_.set_device_output(device_id_, bus_output_); + return dma_acknowledge(); } return uint8_t(bus_.get_state()); @@ -324,3 +317,27 @@ void NCR5380::set_execution_state(ExecutionState state) { size_t NCR5380::scsi_id() { return device_id_; } + +bool NCR5380::dma_request() { + return dma_request_; +} + +uint8_t NCR5380::dma_acknowledge() { + const uint8_t bus_state = uint8_t(bus_.get_state()); + + dma_acknowledge_ = true; + dma_request_ = false; + update_control_output(); + bus_.set_device_output(device_id_, bus_output_); + + return bus_state; +} + +void NCR5380::dma_acknowledge(uint8_t value) { + data_bus_ = value; + + dma_acknowledge_ = true; + dma_request_ = false; + update_control_output(); + bus_.set_device_output(device_id_, bus_output_); +} diff --git a/Components/5380/ncr5380.hpp b/Components/5380/ncr5380.hpp index 65f01c6a9..7f51bb810 100644 --- a/Components/5380/ncr5380.hpp +++ b/Components/5380/ncr5380.hpp @@ -33,6 +33,15 @@ class NCR5380 final: public SCSI::Bus::Observer { /*! @returns The SCSI ID assigned to this device. */ size_t scsi_id(); + /*! @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); + private: SCSI::Bus &bus_; diff --git a/Machines/Apple/AppleII/SCSICard.cpp b/Machines/Apple/AppleII/SCSICard.cpp index 0c5dbd43e..f24b7115d 100644 --- a/Machines/Apple/AppleII/SCSICard.cpp +++ b/Machines/Apple/AppleII/SCSICard.cpp @@ -103,6 +103,15 @@ void SCSICard::perform_bus_operation(Select select, bool is_read, uint16_t addre } break; + case 0x8: + // DMA acknowledge. + if(is_read) { + *value = ncr5380_.dma_acknowledge(); + } else { + ncr5380_.dma_acknowledge(*value); + } + break; + case 0xa: // RAM and ROM select. if(!is_read) { @@ -114,6 +123,13 @@ void SCSICard::perform_bus_operation(Select select, bool is_read, uint16_t addre } break; + case 0xe: + // DRQ in b7. + if(is_read) { + *value = ncr5380_.dma_request() ? 0x80 : 0x00; + } + break; + default: printf("Unhandled: %04x %c %02x\n", address, is_read ? 'r' : 'w', *value); break;