From bfda781576743103b5daed5eadebf1cd8bdd87f7 Mon Sep 17 00:00:00 2001 From: Josh Dersch Date: Wed, 23 Mar 2016 16:48:56 -0700 Subject: [PATCH] Fixed disk controller logic (really disk timing logic) so that disk can run at 100% speed (rather than 50% speed). Changed endian-ness for ethernet packet words to match 3mbit bridge. (Similar changes also made to IFS). Removed some dead code. --- Contralto.sln | 3 ++ Contralto/Disk/allgames.dsk | Bin 2601648 -> 2601648 bytes Contralto/IO/DiabloDrive.cs | 57 +++++++++++----------- Contralto/IO/DiskController.cs | 38 +++++++-------- Contralto/IO/EthernetController.cs | 8 +-- Contralto/IO/HostEthernetEncapsulation.cs | 20 ++++---- Contralto/IO/UDPEncapsulation.cs | 14 +++--- Contralto/Scheduler.cs | 25 +++++----- 8 files changed, 85 insertions(+), 80 deletions(-) diff --git a/Contralto.sln b/Contralto.sln index d5d444c..06a43cd 100644 --- a/Contralto.sln +++ b/Contralto.sln @@ -8,6 +8,9 @@ EndProject Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "ContraltoSetup", "ContraltoSetup\ContraltoSetup.wixproj", "{47BBC195-80C5-43F3-B691-7D27B0803B84}" EndProject Global + GlobalSection(Performance) = preSolution + HasPerformanceSessions = true + EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Debug|x64 = Debug|x64 diff --git a/Contralto/Disk/allgames.dsk b/Contralto/Disk/allgames.dsk index da8bc5c661d1042c0b597729b230735646f6b252..16f95c5f22795f0901aa5e3f9cdc15053c15a7ed 100644 GIT binary patch delta 234 zcmW;BxebC)0Dxg0B8nm&;C7SM1@PAR}>nNZI10|GU zq5=z5)KEu5X1;yji(P!u^>*xT)wMi7?1PBiuc<}J(}sg4T4 .28 * 30 * 10000 * (1 + (0.7/30)) = 85959.9999nsec; 86usec. + // + private static ulong _seclateDuration = (ulong)(86.0 * Conversion.UsecToNsec * _scale); private bool _seclateEnable; private bool _seclate; private Event _seclateEvent; diff --git a/Contralto/IO/EthernetController.cs b/Contralto/IO/EthernetController.cs index ea1634f..34e7618 100644 --- a/Contralto/IO/EthernetController.cs +++ b/Contralto/IO/EthernetController.cs @@ -413,7 +413,7 @@ namespace Contralto.IO // // Read the packet length (in words) (first word of the packet as provided by the sending emulator). Convert to bytes. // - _incomingPacketLength = ((_incomingPacket.ReadByte()) | (_incomingPacket.ReadByte() << 8)) * 2; + _incomingPacketLength = ((_incomingPacket.ReadByte() << 8) | (_incomingPacket.ReadByte())) * 2; // Add one word to the count for the checksum. // NOTE: This is not provided by the sending emulator and is not computed here either. @@ -427,8 +427,8 @@ namespace Contralto.IO if (_incomingPacketLength > _incomingPacket.Length || (_incomingPacketLength % 2) != 0) { - throw new InvalidOperationException( - String.Format("Invalid 3mbit packet length header ({0} vs {1}.", _incomingPacketLength, _incomingPacket.Length)); + throw new InvalidOperationException( + String.Format("Invalid 3mbit packet length header ({0} vs {1}.", _incomingPacketLength, _incomingPacket.Length)); } Log.Write(LogComponent.EthernetPacket, "Accepting incoming packet (length {0}).", _incomingPacketLength); @@ -454,7 +454,7 @@ namespace Contralto.IO if (_incomingPacketLength >= 2) { // Stuff 1 word into the FIFO, if we run out of data to send then we clear _iBusy further down. - ushort nextWord = (ushort)((_incomingPacket.ReadByte()) | (_incomingPacket.ReadByte() << 8)); + ushort nextWord = (ushort)((_incomingPacket.ReadByte() << 8) | (_incomingPacket.ReadByte())); _fifo.Enqueue(nextWord); _incomingPacketLength -= 2; diff --git a/Contralto/IO/HostEthernetEncapsulation.cs b/Contralto/IO/HostEthernetEncapsulation.cs index 3ff7821..a9785a1 100644 --- a/Contralto/IO/HostEthernetEncapsulation.cs +++ b/Contralto/IO/HostEthernetEncapsulation.cs @@ -108,25 +108,25 @@ namespace Contralto.IO // First two bytes include the length of the 3mbit packet; since 10mbit packets have a minimum length of 46 // bytes, and 3mbit packets have no minimum length this is necessary so the receiver can pull out the // correct amount of data. - // - packetBytes[0] = (byte)(length); - packetBytes[1] = (byte)((length) >> 8); + // + packetBytes[0] = (byte)((length) >> 8); + packetBytes[1] = (byte)(length); // // Do this annoying dance to stuff the ushorts into bytes because this is C#. // for (int i = 0; i < length; i++) - { - packetBytes[i * 2 + 2] = (byte)(packet[i]); - packetBytes[i * 2 + 3] = (byte)(packet[i] >> 8); + { + packetBytes[i * 2 + 2] = (byte)(packet[i] >> 8); + packetBytes[i * 2 + 3] = (byte)(packet[i]); } // // Grab the source and destination host addresses from the packet we're sending // and build 10mbit versions. // - byte destinationHost = packetBytes[3]; - byte sourceHost = packetBytes[2]; + byte destinationHost = packetBytes[2]; + byte sourceHost = packetBytes[3]; Log.Write(LogComponent.HostNetworkInterface, "Sending packet; source {0} destination {1}, length {2} words.", Conversion.ToOctal(sourceHost), @@ -162,9 +162,7 @@ namespace Contralto.IO // // Filter out packets intended for the emulator, forward them on, drop everything else. // - if ((int)p.Ethernet.EtherType == _3mbitFrameType && // encapsulated 3mbit frames - ((p.Ethernet.Destination.ToValue() & 0xffffffffff00) == _10mbitMACPrefix || // addressed to any emulator OR - p.Ethernet.Destination.ToValue() == _10mbitBroadcast) && // broadcast + if ((int)p.Ethernet.EtherType == _3mbitFrameType && // encapsulated 3mbit frames (p.Ethernet.Source.ToValue() != (UInt48)(_10mbitMACPrefix | Configuration.HostAddress))) // and not sent by this emulator { Log.Write(LogComponent.HostNetworkInterface, "Received encapsulated 3mbit packet."); diff --git a/Contralto/IO/UDPEncapsulation.cs b/Contralto/IO/UDPEncapsulation.cs index 1e6b426..9cd6956 100644 --- a/Contralto/IO/UDPEncapsulation.cs +++ b/Contralto/IO/UDPEncapsulation.cs @@ -120,22 +120,22 @@ namespace Contralto.IO // First two bytes include the length of the 3mbit packet; since 10mbit packets have a minimum length of 46 // bytes, and 3mbit packets have no minimum length this is necessary so the receiver can pull out the // correct amount of data. - // - packetBytes[0] = (byte)(length); - packetBytes[1] = (byte)((length) >> 8); + // + packetBytes[0] = (byte)((length) >> 8); + packetBytes[1] = (byte)(length); // // Do this annoying dance to stuff the ushorts into bytes because this is C#. // for (int i = 0; i < length; i++) - { - packetBytes[i * 2 + 2] = (byte)(packet[i]); - packetBytes[i * 2 + 3] = (byte)(packet[i] >> 8); + { + packetBytes[i * 2 + 2] = (byte)(packet[i] >> 8); + packetBytes[i * 2 + 3] = (byte)(packet[i]); } Log.Write(LogType.Verbose, LogComponent.HostNetworkInterface, "Sending packet via UDP; source {0} destination {1}, length {2} words.", - Conversion.ToOctal(packetBytes[2]), Conversion.ToOctal(packetBytes[3]), + Conversion.ToOctal(packetBytes[2]), length); _udpClient.Send(packetBytes, packetBytes.Length, _broadcastEndpoint); diff --git a/Contralto/Scheduler.cs b/Contralto/Scheduler.cs index c18e2c4..c62a5b0 100644 --- a/Contralto/Scheduler.cs +++ b/Contralto/Scheduler.cs @@ -143,23 +143,17 @@ namespace Contralto { get { - if (_queue.Count > 0) - { - return _queue.First.Value; - } - else - { - return null; - } + return _top; } } public void Push(Event e) { // Degenerate case: list is empty or new entry is earlier than the head of the list. - if (_queue.Count == 0 || _queue.First.Value.TimestampNsec >= e.TimestampNsec) + if (_queue.Count == 0 || _top.TimestampNsec >= e.TimestampNsec) { _queue.AddFirst(e); + _top = e; return; } @@ -189,20 +183,29 @@ namespace Contralto public Event Pop() { - Event e = _queue.First.Value; + Event e = _top; _queue.RemoveFirst(); + _top = _queue.First.Value; + return e; } public void Remove(Event e) { - _queue.Remove(e); + _queue.Remove(e); + _top = _queue.First.Value; + } /// /// TODO: provide more optimal data structure here once profiling can be done. /// private LinkedList _queue; + + /// + /// The Top of the queue (null if queue is empty). + /// + private Event _top; } }