Skip to content

Commit 4a8e2a1

Browse files
Allow cpm to be run without a terminal
Allow CPM to be used in a pipe, reading from standard input and writing to standard output. Useful to test Z80 programs in automated tests.
1 parent cff63fd commit 4a8e2a1

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
**/*.o
2+
cpm
3+
cpmtool
4+
nbproject/*

main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ static FILE *logfile = NULL;
5454
#endif
5555
static struct termio rawterm, oldterm; /* for raw terminal I/O */
5656
#endif
57+
static int have_term = 1; /* FALSE if terminal initialization failed */
5758

5859

5960
static void dumptrace(z80info *z80);
@@ -78,6 +79,7 @@ char *jgets(char *s, int len, FILE *f)
7879
void
7980
resetterm(void)
8081
{
82+
if (have_term)
8183
tcsetattr(fileno(stdin), TCSADRAIN, &oldterm);
8284
}
8385

@@ -90,6 +92,7 @@ resetterm(void)
9092
void
9193
setterm(void)
9294
{
95+
if (have_term)
9396
tcsetattr(fileno(stdin), TCSADRAIN, &rawterm);
9497
}
9598

@@ -105,9 +108,10 @@ initterm(void)
105108
{
106109
if (tcgetattr(fileno(stdin), &oldterm))
107110
{
108-
fprintf(stderr, "Sorry, Must be using a terminal.\n");
109-
exit(1);
111+
fprintf(stderr, "Sorry, terminal not found, using cooked mode.\n");
112+
have_term = 0;
110113
}
114+
else {
111115
rawterm = oldterm;
112116
rawterm.c_iflag &= ~(ICRNL | IXON | IXOFF | INLCR | ICRNL);
113117
rawterm.c_lflag &= ~(ICANON | ECHO);

0 commit comments

Comments
 (0)