From 599873890a96d66939dcd1431a5a82410ed97d0b Mon Sep 17 00:00:00 2001 From: Dennis Ranke Date: Sun, 8 May 2022 19:47:07 +0200 Subject: [PATCH] add docs for debug output --- Cargo.lock | 2 +- Cargo.toml | 2 +- platform/Cargo.lock | 2 +- platform/Cargo.toml | 2 +- platform/src/platform.cwa | 6 +++-- site/content/docs.md | 57 ++++++++++++++++++++++++--------------- 6 files changed, 44 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2ac8515..d99bfdc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -599,7 +599,7 @@ checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" [[package]] name = "curlywas" version = "0.1.0" -source = "git+https://github.com/exoticorn/curlywas.git?rev=c22297e#c22297ea82977ac06373d629fb273a795322d788" +source = "git+https://github.com/exoticorn/curlywas.git?rev=0a0d90c#0a0d90c8013f1d7856a9b71a19d3d006300f31f9" dependencies = [ "anyhow", "ariadne", diff --git a/Cargo.toml b/Cargo.toml index 54eb4e2..026764e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ anyhow = "1" minifb = { version = "0.22", default-features = false, features = ["x11"], optional = true } notify = "4" pico-args = "0.4" -curlywas = { git = "https://github.com/exoticorn/curlywas.git", rev = "c22297e" } +curlywas = { git = "https://github.com/exoticorn/curlywas.git", rev = "0a0d90c" } wat = "1" uw8-tool = { path = "uw8-tool" } same-file = "1" diff --git a/platform/Cargo.lock b/platform/Cargo.lock index 7756edc..afc40d1 100644 --- a/platform/Cargo.lock +++ b/platform/Cargo.lock @@ -146,7 +146,7 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] name = "curlywas" version = "0.1.0" -source = "git+https://github.com/exoticorn/curlywas.git?rev=c22297e#c22297ea82977ac06373d629fb273a795322d788" +source = "git+https://github.com/exoticorn/curlywas.git?rev=0a0d90c#0a0d90c8013f1d7856a9b71a19d3d006300f31f9" dependencies = [ "anyhow", "ariadne", diff --git a/platform/Cargo.toml b/platform/Cargo.toml index 1bda5ee..f690fb4 100644 --- a/platform/Cargo.toml +++ b/platform/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -curlywas = { git="https://github.com/exoticorn/curlywas.git", rev="c22297e" } +curlywas = { git="https://github.com/exoticorn/curlywas.git", rev="0a0d90c" } uw8-tool = { path="../uw8-tool" } anyhow = "1" lodepng = "3.4" \ No newline at end of file diff --git a/platform/src/platform.cwa b/platform/src/platform.cwa index daf4946..8e93957 100644 --- a/platform/src/platform.cwa +++ b/platform/src/platform.cwa @@ -320,8 +320,10 @@ global mut controlCodeLength = 0; fn printSingleChar(char: i32) { if char >= 4 & char <= 6 { outputChannel = char - 4; - textCursorX = 0; - textCursorY = 0; + if !outputChannel { + textCursorX = 0; + textCursorY = 0; + } return; } diff --git a/site/content/docs.md b/site/content/docs.md index 601571f..d69a34f 100644 --- a/site/content/docs.md +++ b/site/content/docs.md @@ -225,30 +225,45 @@ Moving/printing past any border does not cause any special operation, the cursor Characters 0-31 are control characters and don't print by default. They take the next 0-2 following characters as parameters. Avoid the reserved control chars, they are currently NOPs but their behavior can change in later MicroW8 versions. -| Code | Parameters | Operation | -| ----- | ---------- | ------------------------------------ | -| 0 | - | Nop | -| 1 | char | Print char (including control chars) | -| 2-3 | - | Reserved | -| 4 | - | Switch to normal mode | -| 5 | - | Switch to graphics mode | -| 6 | - | Reserved | -| 7 | - | Bell / trigger sound channel 0 | -| 8 | - | Move cursor left | -| 9 | - | Move cursor right | -| 10 | - | Move cursor down | -| 11 | - | Move cursor up | -| 12 | - | do `cls(background_color)` | -| 13 | - | Move cursor to the left border | -| 14 | color | Set the background color | -| 15 | color | Set the text color | -| 16-23 | - | Reserved | -| 24 | - | Swap text/background colors | -| 25-30 | - | Reserved | -| 31 | x, y | Set cursor position (*) | +| Code | Parameters | Operation | +| ----- | ---------- | ------------------------------------------ | +| 0 | - | Nop | +| 1 | char | Print char (including control chars) | +| 2-3 | - | Reserved | +| 4 | - | Switch to normal mode, reset cursor to 0,0 | +| 5 | - | Switch to graphics mode | +| 6 | - | Switch output to (debug) console | +| 7 | - | Bell / trigger sound channel 0 | +| 8 | - | Move cursor left | +| 9 | - | Move cursor right | +| 10 | - | Move cursor down | +| 11 | - | Move cursor up | +| 12 | - | do `cls(background_color)` | +| 13 | - | Move cursor to the left border | +| 14 | color | Set the background color | +| 15 | color | Set the text color | +| 16-23 | - | Reserved | +| 24 | - | Swap text/background colors | +| 25-30 | - | Reserved | +| 31 | x, y | Set cursor position (*) | (*) In graphics mode, the x coordinate is doubled when using control char 31 to be able to cover the whole screen with one byte. +#### Debug output + +Control code 6 switches all text output (except codes 4 and 5 to switch output back to the screen) to the console. Where exactly this ends +up (if at all) is an implementation detail of the runtimes. The native dev-runtime writes the debug output to `stdout`, the web runtime to +the debug console using `console.log`. Both implementation buffer the output until they encounter a newline character (10) in the output stream. + +There may be future runtimes that ignore the debug output completely. + +In CurlyWas, a simple way to log some value might look like this: +``` +printChar('\06V: '); // switch to console out, print some prefix +printInt(some_value); +printChar('\n\4'); // newline and switch back to screen +``` + ### fn printChar(char: i32) Prints the character in the lower 8 bits of `char`. If the upper 24 bits are non-zero, right-shifts `char` by 8 bits and loops back to the beginning.