From 5ec3f59f2e5aadbf74748cb1606a7d4a923d167c Mon Sep 17 00:00:00 2001 From: Christopher Mosher Date: Mon, 21 Jan 2019 21:37:22 -0500 Subject: [PATCH] break out cassette FFWD to tone function and expose to user --- doc/cassette.asciidoc | 12 +++++++++--- doc/commands.asciidoc | 1 + src/cassettein.cpp | 20 +++++++++++++++----- src/cassettein.h | 1 + src/configep2.cpp | 4 ++++ 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/doc/cassette.asciidoc b/doc/cassette.asciidoc index e40c706..52d9336 100644 --- a/doc/cassette.asciidoc +++ b/doc/cassette.asciidoc @@ -52,9 +52,15 @@ The tape is automatically positioned at the first header tone. +cassette rewind+ -This command rewinds the tape currently on the CASSETTE IN port. -This command first positions the tape to its beginning, -and then ``fast-forwards'' to the first header tone. +This command rewinds the tape currently on the CASSETTE IN port. After rewinding +the tape, you will typically need to fast-forward to the head tone using +the +cassette tone+ command. + ++cassette tone+ + +If more than one program is stored in one WAVE file, then after loading the first +program, you may need to fast-forward to the next header tone. This command will +do just that. +cassette blank + diff --git a/doc/commands.asciidoc b/doc/commands.asciidoc index b803723..f00810a 100644 --- a/doc/commands.asciidoc +++ b/doc/commands.asciidoc @@ -170,6 +170,7 @@ The +cassette+ command performs various operations of the emulated cassette tape -------- cassette load [ ] cassette rewind +cassette tone cassette blank cassette save cassette eject { in | out } diff --git a/src/cassettein.cpp b/src/cassettein.cpp index 8e13d1d..fda0a18 100644 --- a/src/cassettein.cpp +++ b/src/cassettein.cpp @@ -157,17 +157,26 @@ void CassetteIn::rewind() { this->playing = false; note_pos(); + this->gui.setCassettePos(this->t/10,this->samp_siz); +} - - +void CassetteIn::tone() { + if (!isLoaded()) { + return; + } + note_pos(); note("FAST FORWARD TO TONE"); + this->playing = false; + const unsigned int HEAD_SAMPLES = 17; std::int_fast8_t slope_was = 0; - uint i_was = 0; - uint c_head = 0; - for (std::uint_fast32_t i = 1; i < this->samp_siz; ++i) { + std::uint_fast32_t i_was = 0; + std::uint_fast32_t c_head = 0; + + const std::uint_fast32_t start = this->t/10 > 0 ? this->t/10 : 1; + for (std::uint_fast32_t i = start; i < this->samp_siz; ++i) { std::int_fast8_t slope_is = slope(this->samp[i-1], this->samp[i]); if (slope_is) { if (slope_is != slope_was) { @@ -244,6 +253,7 @@ bool CassetteIn::load(const std::string& filePath) { this->gui.setCassetteInFile(filePath); rewind(); + tone(); return true; } diff --git a/src/cassettein.h b/src/cassettein.h index f00ed12..6a3f762 100644 --- a/src/cassettein.h +++ b/src/cassettein.h @@ -42,6 +42,7 @@ public: bool load(const std::string& filePath); void rewind(); + void tone(); virtual bool eject(); }; diff --git a/src/configep2.cpp b/src/configep2.cpp index 0c0f290..44ab78c 100644 --- a/src/configep2.cpp +++ b/src/configep2.cpp @@ -304,6 +304,10 @@ void Config::tryParseLine(const std::string& line, Memory& ram, Memory& rom, Slo { cassetteIn.rewind(); } + else if (cas == "tone") + { + cassetteIn.tone(); + } else if (cas == "blank") { std::string fcas;