Skip to content

Commit 8a34c30

Browse files
fix: OPL3 port read delay and remove legacy ASM tests
Simulate 1.5us hardware latency in Opl3Fm port reads. Add Opl3WriteDelayTest to verify timing. Remove OplIntegrationTests and related ASM source/binary files. Minor: add unused usings in IOPortDispatcher.cs.
1 parent 2e0c0fe commit 8a34c30

7 files changed

Lines changed: 46 additions & 569 deletions

File tree

src/Spice86.Core/Emulator/Devices/Sound/Opl3Fm.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ public override byte ReadByte(ushort port) {
178178
}
179179

180180
private byte PortRead(ushort port) {
181+
// Roughly half a microsecond
182+
// and some tests revealed it taking 1.5us to read an AdLib port.
183+
double currentTime = _clock.ElapsedTimeMs;
184+
SpinWait.SpinUntil(() => TimeSpan.FromMilliseconds(_clock.ElapsedTimeMs - currentTime) >= TimeSpan.FromMicroseconds(1.5));
181185
switch (_mode) {
182186
case OplMode.Opl2:
183187
// We allocated 4 ports, so just return -1 for the higher ones.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
namespace Spice86.Tests.Emulator.Devices.Sound;
2+
3+
using FluentAssertions;
4+
5+
using NSubstitute;
6+
7+
using Spice86.Core.Emulator.CPU;
8+
using Spice86.Core.Emulator.Devices.Sound;
9+
using Spice86.Core.Emulator.VM;
10+
using Spice86.Core.Emulator.VM.Clock;
11+
using Spice86.Shared.Interfaces;
12+
13+
using System;
14+
15+
using Xunit;
16+
17+
[Trait("Category", "Sound")]
18+
public class Opl3WriteDelayTest {
19+
20+
[Fact]
21+
public void Opl3ReadDelayIsAMicroSecondAndAHalf() {
22+
//Arrange
23+
State state = new(CpuModel.INTEL_80386);
24+
ILoggerService loggerService = Substitute.For<ILoggerService>();
25+
Opl3Fm opl3fm = new(new(OplMode.Opl3, 0x220, SbMixer: true),
26+
new SoftwareMixer(Audio.Filters.AudioEngine.Dummy,
27+
new PauseHandler(loggerService)),
28+
state,
29+
new EmulatedClock(null, DateTimeOffset.Now),
30+
new Core.Emulator.IOPorts.IOPortDispatcher(new(), state, loggerService, false),
31+
false,
32+
loggerService);
33+
34+
//Act
35+
DateTime before = DateTime.Now;
36+
_ = opl3fm.ReadByte(0x330);
37+
DateTime after = DateTime.Now;
38+
39+
//Assert
40+
(after - before).Should().BeGreaterThanOrEqualTo(TimeSpan.FromMicroseconds(1.5));
41+
}
42+
}

tests/Spice86.Tests/Emulator/Devices/Sound/OplIntegrationTests.cs

Lines changed: 0 additions & 124 deletions
This file was deleted.

0 commit comments

Comments
 (0)