commit 9391ec7577f2bb11f7ab6f91cd6681a3d4659fbf
Author: Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Tue Jan 3 15:21:34 2023 -0600
Commit: Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Tue Jan 3 15:21:34 2023 -0600
Parse audio control codes
---
source/printHelper.cpp | 15 +++++++++++++--
test/printHelperTests.cpp | 15 +++++++++++++++
2 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/source/printHelper.cpp b/source/printHelper.cpp
index 90fc26c..b8c23b9 100644
--- a/source/printHelper.cpp
+++ b/source/printHelper.cpp
@@ -93,6 +93,7 @@ int print(std::string str, int x, int y, uint8_t c) {
_ph_mem->drawState.text_x = x;
_ph_mem->drawState.text_y = y;
+ int length = str.length();
int homeX = x;
int homeY = y;
int tabStopWidth = 4;
@@ -104,6 +105,7 @@ int print(std::string str, int x, int y, uint8_t c) {
uint8_t bgColor = 0;
uint8_t fgColor = _ph_mem->drawState.color;
uint8_t charBytes[8];
+ uint8_t audioStrBytes[32];
uint8_t printMode = _ph_mem->hwState.printAttributes;
@@ -128,7 +130,7 @@ int print(std::string str, int x, int y, uint8_t c) {
int rhsWrap = -1;
- for (size_t n = 0; n < str.length(); n++) {
+ for (size_t n = 0; n < length; n++) {
uint8_t ch = str[n];
framesToPause = framesBetweenChars;
if (ch == 1) { // "\*{p0}" repeat the next character p0 times
@@ -322,7 +324,16 @@ int print(std::string str, int x, int y, uint8_t c) {
}
}
- else if (ch == 12) { //"\f{p0}" draw text with this foreground color
+ else if (ch == 7) { // "\a" audio command
+ uint8_t nextChar = str[++n];
+ int audioStrIdx = 0;
+ while (nextChar != 32 && n < length) {
+ audioStrBytes[audioStrIdx++] = nextChar;
+ nextChar = str[++n];
+ }
+ //todo: generate audio stuff and play
+ }
+ else if (ch == 12) { //"\f{p0}" draw text with this foreground color
uint8_t fgColChar = str[++n];
fgColor = p0CharToNum(fgColChar);
_ph_graphics->color(fgColor);
diff --git a/test/printHelperTests.cpp b/test/printHelperTests.cpp
index c42413c..f37fdd6 100644
--- a/test/printHelperTests.cpp
+++ b/test/printHelperTests.cpp
@@ -737,6 +737,21 @@ TEST_CASE("Print helper functions") {
CHECK_EQ(memory->drawState.text_y, 9);
}
+ SUBCASE("p8scii audio control codes not printed(\\a)") {
+ graphics->cls();
+
+ print("\x07""aceg :", 0, 0);
+
+ std::vector<coloredPoint> expectedPoints = {
+ {1, 0, 0},
+ {1, 1, 6},
+ {1, 2, 0},
+ {1, 3, 6},
+ {1, 4, 0},
+ };
+
+ checkPoints(graphics, expectedPoints);
+ }
delete stubHost;