From de30a57c0c9e6186049e2659f88ee395bad25b8b Mon Sep 17 00:00:00 2001
From: Oliver Schmidt
Date: Fri, 23 Dec 2022 15:24:28 +0100
Subject: [PATCH] Added minimalistic terminal program.
So far there was no sample code at all making use of the serial drivers.
---
samples/Makefile | 8 +++++
samples/terminal.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 84 insertions(+)
create mode 100644 samples/terminal.c
diff --git a/samples/Makefile b/samples/Makefile
index 2aa637844..114bbdf6a 100644
--- a/samples/Makefile
+++ b/samples/Makefile
@@ -171,6 +171,7 @@ EXELIST_apple2 = \
multdemo \
ovrldemo \
sieve \
+ terminal \
tinyshell \
tgidemo
@@ -186,6 +187,7 @@ EXELIST_atari = \
multdemo \
ovrldemo \
sieve \
+ terminal \
tinyshell \
tgidemo
@@ -203,6 +205,7 @@ EXELIST_atmos = \
hello \
mandelbrot \
sieve \
+ terminal \
tgidemo
EXELIST_bbc = \
@@ -219,6 +222,7 @@ EXELIST_c64 = \
multdemo \
ovrldemo \
sieve \
+ terminal \
tinyshell \
tgidemo
@@ -231,6 +235,7 @@ EXELIST_c128 = \
mandelbrot \
mousedemo \
sieve \
+ terminal \
tinyshell \
tgidemo
@@ -247,6 +252,7 @@ EXELIST_cbm510 = \
gunzip65 \
hello \
mousedemo \
+ terminal \
tinyshell \
sieve
@@ -255,6 +261,7 @@ EXELIST_cbm610 = \
checkversion \
gunzip65 \
hello \
+ terminal \
tinyshell \
sieve
@@ -314,6 +321,7 @@ EXELIST_plus4 = \
enumdevdir \
gunzip65 \
hello \
+ terminal \
tinyshell \
sieve
diff --git a/samples/terminal.c b/samples/terminal.c
new file mode 100644
index 000000000..51973f7a3
--- /dev/null
+++ b/samples/terminal.c
@@ -0,0 +1,76 @@
+/*
+** Minimalistic terminal program.
+**
+** Makes use of the serial drivers.
+**
+** 2022-12-23, Oliver Schmidt (ol.sc@web.de)
+**
+*/
+
+
+
+#include
+#include
+#include
+#include
+#include
+
+
+static void check (const char* msg, unsigned char err)
+{
+ if (err == SER_ERR_OK) {
+ return;
+ }
+
+ printf ("%s:0x%02x\n", msg, err);
+ if (doesclrscrafterexit ()) {
+ cgetc ();
+ }
+ exit (1);
+}
+
+
+void main (void)
+{
+ const struct ser_params par = {
+ SER_BAUD_9600,
+ SER_BITS_8,
+ SER_STOP_1,
+ SER_PAR_NONE,
+ SER_HS_HW
+ };
+
+ check ("ser_install", ser_install (ser_static_stddrv));
+
+ check ("ser_open", ser_open (&par));
+
+ atexit ((void (*)) ser_close);
+
+ printf ("Serial Port: 9600-8-1-N RTS/CTS\n"
+ "Simple Term: Press ESC for exit\n");
+
+ while (1)
+ {
+ char chr;
+
+ if (kbhit ())
+ {
+ chr = cgetc ();
+
+ if (chr == CH_ESC) {
+ putchar ('\n');
+ return;
+ }
+
+ if (ser_put (chr) == SER_ERR_OK) {
+ putchar (chr);
+ } else {
+ putchar ('\a');
+ }
+ }
+
+ if (ser_get (&chr) == SER_ERR_OK) {
+ putchar (chr);
+ }
+ }
+}