Added minimalistic terminal program.

So far there was no sample code at all making use of the serial drivers.
This commit is contained in:
Oliver Schmidt 2022-12-23 15:24:28 +01:00
parent 1daa445310
commit de30a57c0c
2 changed files with 84 additions and 0 deletions

View File

@ -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

76
samples/terminal.c Normal file
View File

@ -0,0 +1,76 @@
/*
** Minimalistic terminal program.
**
** Makes use of the serial drivers.
**
** 2022-12-23, Oliver Schmidt (ol.sc@web.de)
**
*/
#include <cc65.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <serial.h>
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);
}
}
}