From 57cd5109f0579a80e406d53f9aa20b6d3378f7df Mon Sep 17 00:00:00 2001 From: Peter Jakubco Date: Sat, 13 May 2023 07:57:01 +0200 Subject: [PATCH] [#314] cassette-player: stop --- .../device/cassette_player/TapePlaybackImpl.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/plugins/device/cassette-player/src/main/java/net/emustudio/plugins/device/cassette_player/TapePlaybackImpl.java b/plugins/device/cassette-player/src/main/java/net/emustudio/plugins/device/cassette_player/TapePlaybackImpl.java index cd6ab2b04..af1e06e3d 100644 --- a/plugins/device/cassette-player/src/main/java/net/emustudio/plugins/device/cassette_player/TapePlaybackImpl.java +++ b/plugins/device/cassette-player/src/main/java/net/emustudio/plugins/device/cassette_player/TapePlaybackImpl.java @@ -116,7 +116,7 @@ public void onBlockFlag(int flag) { @Override public void onProgram(String filename, int dataLength, int autoStart, int programLength) { - logProgramDetail(filename,"PROGRAM (start=" + autoStart + ", length=" + programLength + ")"); + logProgramDetail(filename, "PROGRAM (start=" + autoStart + ", length=" + programLength + ")"); } @Override @@ -156,6 +156,11 @@ public void onFileEnd() { try { barrier.await(); } catch (InterruptedException e) { + // cancel playing + for (int cycles : loaderSchedule.keySet()) { + tep.removeAllScheduledOnce(cycles); + } + Thread.currentThread().interrupt(); } catch (BrokenBarrierException e) { throw new RuntimeException(e); @@ -181,7 +186,7 @@ private void transmitByte(int data, String msg) { int pulseLength = ((data & mask) == 0) ? DATA_PULSE_ZERO_TSTATES : DATA_PULSE_ONE_TSTATES; schedulePulse(pulseLength, msg); // 2x according to https://sinclair.wiki.zxnet.co.uk/wiki/Spectrum_tape_interface schedulePulse(pulseLength, ""); - msg=""; + msg = ""; mask >>>= 1; } } @@ -214,8 +219,8 @@ private void playPulses() { barrier.await(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); - } catch (BrokenBarrierException e) { - throw new RuntimeException(e); + } catch (BrokenBarrierException ignored) { + } }); tep.scheduleOnceMultiple(loaderSchedule);